Allow input files to be specified from the command line

etta-drone
Dan Howe 6 years ago
parent 8ca180f93f
commit 74c9351fe7

@ -360,7 +360,6 @@ def main():
# read the parameters file and scroll through it # read the parameters file and scroll through it
input_file = args.input_file input_file = args.input_file
input_file = 'Parameter Files/las-manipulation-survey-2.xlsx'
params_file=pd.read_excel(input_file, sheet_name="PARAMS") params_file=pd.read_excel(input_file, sheet_name="PARAMS")
for i, row in params_file.iterrows(): for i, row in params_file.iterrows():

@ -13,7 +13,9 @@
import os import os
import io import io
import re import re
import sys
import math import math
import argparse
import datetime import datetime
import subprocess import subprocess
import numpy as np import numpy as np
@ -91,7 +93,7 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu
# Get Nielsen erosion volumes # Get Nielsen erosion volumes
chainage = profiles.loc[:, current_date].dropna().index chainage = profiles.loc[:, current_date].dropna().index
elevation = profiles.loc[:, current_date].dropna().values elevation = profiles.loc[:, current_date].dropna().values
volume = neilson_volumes.volume_available(chainage, elevation, ch_min) volume = nielsen_volumes.volume_available(chainage, elevation, ch_min)
# Update spreadsheet # Update spreadsheet
volumes.loc[profile_name, date] = volume volumes.loc[profile_name, date] = volume
@ -101,74 +103,100 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu
volumes.to_csv(csv_vol) volumes.to_csv(csv_vol)
input_file = 'Parameter Files/las-manipulation-survey-2.xlsx' def main():
params_file=pd.read_excel(input_file, sheet_name="PARAMS") parser = argparse.ArgumentParser()
parser.add_argument(
for i, row in params_file.iterrows(): 'input_file',
print("Starting to process %s" % row['Beach']) metavar='PARAMS_FILE',
beach=row['Beach'] help='name of parameter file',
survey_date = row['SURVEY DATE'] default=None)
original_las = row['INPUT LAS']
classified_las_dir = row['LAS CLASSIFIED FOLDER'] # Print usage if no arguments are provided
shp_swash_dir = row['SHP SWASH FOLDER'] if len(sys.argv) == 1:
crop_heatmap_poly = row['HEATMAP CROP POLY'] parser.print_help(sys.stderr)
output_las_dir = row['LAS OUTPUT FOLDER'] sys.exit(1)
zone_MGA = row['ZONE MGA']
output_poly_dir = row['SHP RASTER FOLDER'] args = parser.parse_args()
output_tif_dir = row['TIF OUTPUT FOLDER']
cp_csv = row['INPUT CSV'] # read the parameters file and scroll through it
profile_limit_file = row['PROFILE LIMIT FILE'] input_file = args.input_file
csv_output_dir = row['CSV OUTPUT FOLDER'] params_file=pd.read_excel(input_file, sheet_name="PARAMS")
graph_loc = row['PNG OUTPUT FOLDER']
volume_output_dir = row['CSV VOLUMES FOLDER'] for i, row in params_file.iterrows():
tmp_dir = row['TMP FOLDER'] print("Starting to process %s" % row['Beach'])
beach=row['Beach']
# Get base name of input las survey_date = row['SURVEY DATE']
las_basename = os.path.splitext(os.path.basename(original_las))[0] original_las = row['INPUT LAS']
classified_las_dir = row['LAS CLASSIFIED FOLDER']
# Get name of input point cloud shp_swash_dir = row['SHP SWASH FOLDER']
input_las = os.path.join(classified_las_dir, las_basename + '.las') crop_heatmap_poly = row['HEATMAP CROP POLY']
output_las_dir = row['LAS OUTPUT FOLDER']
# Get name of swash cropping polygon zone_MGA = row['ZONE MGA']
crop_swash_poly = os.path.join(shp_swash_dir, las_basename + '.shp') output_poly_dir = row['SHP RASTER FOLDER']
output_tif_dir = row['TIF OUTPUT FOLDER']
# Crop point cloud to swash boundary cp_csv = row['INPUT CSV']
las_data = call_lastools('lasclip', input=input_las, output='-stdout', profile_limit_file = row['PROFILE LIMIT FILE']
args=['-poly', crop_swash_poly], verbose=False) csv_output_dir = row['CSV OUTPUT FOLDER']
graph_loc = row['PNG OUTPUT FOLDER']
# Apply sea-side clipping polygon volume_output_dir = row['CSV VOLUMES FOLDER']
las_data = call_lastools('lasclip', input=las_data, output='-stdout', tmp_dir = row['TMP FOLDER']
args=['-poly', crop_heatmap_poly], verbose=False)
# Get base name of input las
# Create clipping polygon for heatmap raster las_basename = os.path.splitext(os.path.basename(original_las))[0]
shp_name = os.path.join(output_poly_dir, las_basename + '.shp')
call_lastools('lasboundary', input=las_data, output=shp_name, verbose=False) # Get name of input point cloud
input_las = os.path.join(classified_las_dir, las_basename + '.las')
# Make a raster from point cloud
tif_name = os.path.join(output_tif_dir, las_basename + '.tif') # Get name of swash cropping polygon
call_lastools('blast2dem', input=las_data, output=tif_name, crop_swash_poly = os.path.join(shp_swash_dir, las_basename + '.shp')
args=['-step', 0.2], verbose=False)
# Crop point cloud to swash boundary
# Extract elevations along profiles from triangulated surface print('Cropping swash...')
df = extract_pts( las_data = call_lastools('lasclip', input=input_las, output='-stdout',
las_data, args=['-poly', crop_swash_poly], verbose=False)
cp_csv,
survey_date, # Apply sea-side clipping polygon
beach, print('Cropping back of beach...')
args=['-parse', 'sxyz', '-keep_class', '2'], las_data = call_lastools('lasclip', input=las_data, output='-stdout',
verbose=False) args=['-poly', crop_heatmap_poly], verbose=False)
# Update survey profiles # Create clipping polygon for heatmap raster
update_survey_output(df, csv_output_dir) print('Creating heat map cropping polygon...')
shp_name = os.path.join(output_poly_dir, las_basename + '.shp')
# Get landward limit of surveys call_lastools('lasboundary', input=las_data, output=shp_name, verbose=False)
ch_limits = pd.read_excel(profile_limit_file, index_col='Profile')
# Make a raster from point cloud
# Plot profiles, and save sand volumes for current beach print('Creating heat map raster...')
profile_names = df['Profile'].unique() tif_name = os.path.join(output_tif_dir, las_basename + '.tif')
for profile_name in profile_names: call_lastools('blast2dem', input=las_data, output=tif_name,
plot_profiles(profile_name, survey_date, csv_output_dir, graph_loc, ch_limits) args=['-step', 0.2], verbose=False)
calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volume_output_dir)
# Extract elevations along profiles from triangulated surface
# Remove temprary files print('Extracting profile elevations...')
remove_temp_files(tmp_dir) df = extract_pts(
las_data,
cp_csv,
survey_date,
beach,
args=['-parse', 'sxyz', '-keep_class', '2'],
verbose=False)
# Update survey profiles
update_survey_output(df, csv_output_dir)
# Get landward limit of surveys
ch_limits = pd.read_excel(profile_limit_file, index_col='Profile')
# Plot profiles, and save sand volumes for current beach
print('Updating figures...')
profile_names = df['Profile'].unique()
for profile_name in profile_names:
plot_profiles(profile_name, survey_date, csv_output_dir, graph_loc, ch_limits)
calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volume_output_dir)
# Remove temprary files
remove_temp_files(tmp_dir)
if __name__ == '__main__':
main()

Loading…
Cancel
Save