Use yaml files for loading input parameters

etta-drone
Dan Howe 6 years ago
parent 7585b7c82e
commit 83615467cb

@ -1,7 +1,9 @@
import os import os
import sys import sys
import yaml
import argparse import argparse
import subprocess import subprocess
from glob import glob
from tqdm import tqdm from tqdm import tqdm
import numpy as np import numpy as np
from scipy import interpolate from scipy import interpolate
@ -337,43 +339,29 @@ def polygon_wave_runup(xyz_1m, direction, shp_name, set_check_value, distance_ch
return None return None
def remove_temp_files(directory): def remove_temp_files(directory):
for f in os.listdir(directory): for f in os.listdir(directory):
os.unlink(os.path.join(directory, f)) os.unlink(os.path.join(directory, f))
return None return None
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'input_file',
metavar='PARAMS_FILE',
help='name of parameter file',
default=None)
# Print usage if no arguments are provided
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args() def process(yaml_file):
with open(yaml_file, 'r') as f:
params = yaml.safe_load(f)
# read the parameters file and scroll through it print("Starting to process %s" % params['BEACH'])
input_file = args.input_file input_las = params['INPUT LAS']
params_file=pd.read_excel(input_file, sheet_name="PARAMS") initial_crop_poly = params['INITIAL CROP POLY']
lasground_step = params['LASGROUND STEP']
for i, row in params_file.iterrows(): zone_MGA = params['ZONE MGA']
print("Starting to process %s" % row['BEACH']) check_value = params['CHECK VALUE']
input_las = row['INPUT LAS'] direct = params['DIRECTION']
initial_crop_poly = row['INITIAL CROP POLY'] check_distance = params['CHECK DISTANCE']
lasground_step = row['LASGROUND STEP'] las_dir = params['LAS CLASSIFIED FOLDER']
zone_MGA = row['ZONE MGA'] shp_dir = params['SHP SWASH FOLDER']
check_value = row['CHECK VALUE'] tmp_dir = params['TMP FOLDER']
direct = row['DIRECTION']
check_distance = row['CHECK DISTANCE']
las_dir = row['LAS CLASSIFIED FOLDER']
shp_dir = row['SHP SWASH FOLDER']
tmp_dir = row['TMP FOLDER']
# Get base name of input las # Get base name of input las
las_basename = os.path.splitext(os.path.basename(input_las))[0] las_basename = os.path.splitext(os.path.basename(input_las))[0]
@ -409,5 +397,38 @@ def main():
remove_temp_files(tmp_dir) remove_temp_files(tmp_dir)
def main():
example_text = """examples:
# Process single survey at specific beach
python las_manipulation.py survey-1-avoca.yaml
# Process all surveys at specific beach
python las_manipulation.py *avoca.yaml
# Process all beaches for specific survey date
python las_manipulation.py survey-1*.yaml
"""
# Set up command line arguments
parser = argparse.ArgumentParser(
epilog=example_text,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('input', help='path to yaml file(s)', nargs='*')
# Print usage if no arguments are provided
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
# Parse arguments
args = parser.parse_args()
yaml_files = []
[yaml_files.extend(glob(f)) for f in args.input]
for yaml_file in yaml_files:
process(yaml_file)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

@ -15,11 +15,13 @@ import io
import re import re
import sys import sys
import math import math
import yaml
import argparse import argparse
import datetime import datetime
import subprocess import subprocess
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from glob import glob
from cycler import cycler from cycler import cycler
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator from matplotlib.ticker import MultipleLocator
@ -166,43 +168,27 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu
return delta_vol return delta_vol
def main(): def process(yaml_file):
parser = argparse.ArgumentParser() with open(yaml_file, 'r') as f:
parser.add_argument( params = yaml.safe_load(f)
'input_file',
metavar='PARAMS_FILE', print("Starting to process %s" % params['BEACH'])
help='name of parameter file', beach = params['BEACH']
default=None) survey_date = str(params['SURVEY DATE'])
original_las = params['INPUT LAS']
# Print usage if no arguments are provided classified_las_dir = params['LAS CLASSIFIED FOLDER']
if len(sys.argv) == 1: shp_swash_dir = params['SHP SWASH FOLDER']
parser.print_help(sys.stderr) crop_heatmap_poly = params['HEATMAP CROP POLY']
sys.exit(1) output_las_dir = params['LAS OUTPUT FOLDER']
zone_MGA = params['ZONE MGA']
args = parser.parse_args() output_poly_dir = params['SHP RASTER FOLDER']
output_tif_dir = params['TIF OUTPUT FOLDER']
# read the parameters file and scroll through it cp_csv = params['INPUT CSV']
input_file = args.input_file profile_limit_file = params['PROFILE LIMIT FILE']
params_file=pd.read_excel(input_file, sheet_name="PARAMS") csv_output_dir = params['CSV OUTPUT FOLDER']
graph_loc = params['PNG OUTPUT FOLDER']
for i, row in params_file.iterrows(): volume_output_dir = params['CSV VOLUMES FOLDER']
print("Starting to process %s" % row['BEACH']) tmp_dir = params['TMP FOLDER']
beach=row['BEACH']
survey_date = str(row['SURVEY DATE'])
original_las = row['INPUT LAS']
classified_las_dir = row['LAS CLASSIFIED FOLDER']
shp_swash_dir = row['SHP SWASH FOLDER']
crop_heatmap_poly = row['HEATMAP CROP POLY']
output_las_dir = row['LAS OUTPUT FOLDER']
zone_MGA = row['ZONE MGA']
output_poly_dir = row['SHP RASTER FOLDER']
output_tif_dir = row['TIF OUTPUT FOLDER']
cp_csv = row['INPUT CSV']
profile_limit_file = row['PROFILE LIMIT FILE']
csv_output_dir = row['CSV OUTPUT FOLDER']
graph_loc = row['PNG OUTPUT FOLDER']
volume_output_dir = row['CSV VOLUMES FOLDER']
tmp_dir = row['TMP FOLDER']
# Get base name of input las # Get base name of input las
las_basename = os.path.splitext(os.path.basename(original_las))[0] las_basename = os.path.splitext(os.path.basename(original_las))[0]
@ -264,5 +250,38 @@ def main():
remove_temp_files(tmp_dir) remove_temp_files(tmp_dir)
def main():
example_text = """examples:
# Process single survey at specific beach
python las_outputs.py survey-1-avoca.yaml
# Process all surveys at specific beach
python las_outputs.py *avoca.yaml
# Process all beaches for specific survey date
python las_outputs.py survey-1*.yaml
"""
# Set up command line arguments
parser = argparse.ArgumentParser(
epilog=example_text,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('input', help='path to yaml file(s)', nargs='*')
# Print usage if no arguments are provided
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
# Parse arguments
args = parser.parse_args()
yaml_files = []
[yaml_files.extend(glob(f)) for f in args.input]
for yaml_file in yaml_files:
process(yaml_file)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save