Add calculate_volumes() function

etta-drone
Dan Howe 6 years ago
parent 1505053090
commit d704e47ca5

@ -12,6 +12,7 @@
########################### IMPORTS ########################################### ########################### IMPORTS ###########################################
import os import os
import io import io
import re
import subprocess import subprocess
import pandas as pd import pandas as pd
import numpy as np import numpy as np
@ -147,6 +148,42 @@ def plot_profiles(profile_name, survey_date, csv_output_dir, graph_loc, ch_limit
plt.close() plt.close()
def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volume_output_dir):
csv_prof = profile_name + '.csv'
beach = re.search('.*(?=_\d)', profile_name).group()
profiles = pd.read_csv(os.path.join(csv_output_dir, csv_prof))
# Remove metadata, and extract profile coordinates
profiles = profiles.loc[:, 'Chainage':].set_index('Chainage')
# Find landward limit of profile (behind beach)
ch_min = ch_limits.loc[profile_name, 'Landward Limit']
# Open volume spreadsheet
csv_vol = os.path.join(volume_output_dir, 'volumes.csv')
try:
volumes = pd.read_csv(csv_vol, index_col=0)
except FileNotFoundError:
volumes = pd.DataFrame()
# Format dates
date_str = str(survey_date)
date = '{}-{}-{}'.format(date_str[:4], date_str[4:6], date_str[6:])
for current_date in profiles.columns:
# Get Nielsen erosion volumes
chainage = profiles.loc[:, current_date].dropna().index
elevation = profiles.loc[:, current_date].dropna().values
volume = neilson_volumes.volume_available(chainage, elevation, ch_min)
# Update spreadsheet
volumes.loc[profile_name, date] = volume
# Save updated volumes spreadsheet
volumes = volumes.sort_index()
volumes.to_csv(csv_vol)
input_file = 'Parameter Files/las-manipulation-survey-2.xlsx' 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")
@ -166,7 +203,7 @@ for i, row in params_file.iterrows():
profile_limit_file = row['PROFILE LIMIT FILE'] profile_limit_file = row['PROFILE LIMIT FILE']
csv_output_dir = row['CSV OUTPUT FOLDER'] csv_output_dir = row['CSV OUTPUT FOLDER']
graph_loc = row['PNG OUTPUT FOLDER'] graph_loc = row['PNG OUTPUT FOLDER']
volume_output = row['CSV VOLUMES FOLDER'] volume_output_dir = row['CSV VOLUMES FOLDER']
tmp_dir = row['TMP FOLDER'] tmp_dir = row['TMP FOLDER']
# Get base name of input las # Get base name of input las
@ -203,18 +240,18 @@ for i, row in params_file.iterrows():
beach, beach,
args=['-parse', 'sxyz', '-keep_class', '2'], args=['-parse', 'sxyz', '-keep_class', '2'],
verbose=False) verbose=False)
# Update survey profiles
update_survey_output(df, csv_output_dir) update_survey_output(df, csv_output_dir)
# Get landward limit of surveys # Get landward limit of surveys
ch_limits = pd.read_excel(profile_limit_file, index_col='Profile') ch_limits = pd.read_excel(profile_limit_file, index_col='Profile')
# Plot profiles of current beach # Plot profiles, and save sand volumes for current beach
profile_names = df['Profile'].unique() profile_names = df['Profile'].unique()
for profile_name in profile_names: for profile_name in profile_names:
plot_profiles(profile_name, survey_date, csv_output_dir, graph_loc, ch_limits) 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 temprary files
remove_temp_files(tmp_dir) remove_temp_files(tmp_dir)
print("doing the volume analysis")
# test=profile_plots_volume(csv_output_dir, profile_limit_file, volume_output, graph_loc)

Loading…
Cancel
Save