|
|
@ -32,7 +32,7 @@ def get_datestring(x):
|
|
|
|
"""Format a date integer into an ISO-8601 date string
|
|
|
|
"""Format a date integer into an ISO-8601 date string
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
x: integer representation of date string
|
|
|
|
x: unformatted date
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
formatted date string
|
|
|
|
formatted date string
|
|
|
@ -54,13 +54,20 @@ def remove_temp_files(directory):
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, delta_vol):
|
|
|
|
def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, delta_vol, survey_date):
|
|
|
|
csv_name = profile_name + '.csv'
|
|
|
|
csv_name = profile_name + '.csv'
|
|
|
|
profiles = pd.read_csv(os.path.join(csv_output_dir, csv_name))
|
|
|
|
profiles = pd.read_csv(os.path.join(csv_output_dir, csv_name))
|
|
|
|
|
|
|
|
|
|
|
|
# Remove metadata, and extract profile coordinates
|
|
|
|
# Remove metadata, and extract profile coordinates
|
|
|
|
profiles = profiles.loc[:, 'Chainage':].set_index('Chainage')
|
|
|
|
profiles = profiles.loc[:, 'Chainage':].set_index('Chainage')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Determine if current survey is the latest
|
|
|
|
|
|
|
|
current_survey_col = 'Elevation_' + survey_date
|
|
|
|
|
|
|
|
is_latest = profiles.columns[-1] == current_survey_col
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Only plot profiles up to current survey date
|
|
|
|
|
|
|
|
profiles = profiles.loc[:, :current_survey_col]
|
|
|
|
|
|
|
|
|
|
|
|
# Find landward limit of profile (behind beach)
|
|
|
|
# Find landward limit of profile (behind beach)
|
|
|
|
ch_min = ch_limits.loc[profile_name, 'Landward Limit']
|
|
|
|
ch_min = ch_limits.loc[profile_name, 'Landward Limit']
|
|
|
|
|
|
|
|
|
|
|
@ -84,9 +91,11 @@ def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, delta_vol)
|
|
|
|
ax.set_ylabel('Elevation (m AHD)', labelpad=10)
|
|
|
|
ax.set_ylabel('Elevation (m AHD)', labelpad=10)
|
|
|
|
|
|
|
|
|
|
|
|
# Show most recent volume change
|
|
|
|
# Show most recent volume change
|
|
|
|
ax.annotate('Most recent\nvolume change:\n{:0.1f} m$^3$/m'.format(delta_vol),
|
|
|
|
if delta_vol is not None:
|
|
|
|
(0.05, 0.15), xycoords='axes fraction', fontsize=9,
|
|
|
|
ax.annotate('Most recent\nvolume change:\n{:0.1f} m$^3$/m'.format(delta_vol),
|
|
|
|
backgroundcolor='#ffffff', linespacing=1.5)
|
|
|
|
(0.05, 0.15), xycoords='axes fraction', fontsize=9,
|
|
|
|
|
|
|
|
backgroundcolor='#ffffff', linespacing=1.5)
|
|
|
|
|
|
|
|
|
|
|
|
ax.legend(edgecolor='none', facecolor='#ffffff', fontsize=9)
|
|
|
|
ax.legend(edgecolor='none', facecolor='#ffffff', fontsize=9)
|
|
|
|
|
|
|
|
|
|
|
|
ax.xaxis.set_minor_locator(MultipleLocator(5))
|
|
|
|
ax.xaxis.set_minor_locator(MultipleLocator(5))
|
|
|
@ -94,8 +103,21 @@ def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, delta_vol)
|
|
|
|
ax.xaxis.grid(True, which='minor', color='k', linewidth=0.5, alpha=0.3)
|
|
|
|
ax.xaxis.grid(True, which='minor', color='k', linewidth=0.5, alpha=0.3)
|
|
|
|
ax.yaxis.grid(True,which='minor',color='k', linewidth=0.5, alpha=0.3)
|
|
|
|
ax.yaxis.grid(True,which='minor',color='k', linewidth=0.5, alpha=0.3)
|
|
|
|
|
|
|
|
|
|
|
|
png_name = os.path.join(graph_loc, profile_name + '.png')
|
|
|
|
# Save in folder with current date
|
|
|
|
plt.savefig(png_name, bbox_inches='tight', dpi=300)
|
|
|
|
png_dirs = [os.path.join(graph_loc, get_datestring(survey_date))]
|
|
|
|
|
|
|
|
if is_latest:
|
|
|
|
|
|
|
|
# Save copy in'latest' if survey is most recent
|
|
|
|
|
|
|
|
png_dirs += [os.path.join(graph_loc, 'latest')]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for png_dir in png_dirs:
|
|
|
|
|
|
|
|
# Prepare output directory
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
os.makedirs(png_dir)
|
|
|
|
|
|
|
|
except FileExistsError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
png_name = os.path.join(png_dir, profile_name + '.png')
|
|
|
|
|
|
|
|
plt.savefig(png_name, bbox_inches='tight', dpi=300)
|
|
|
|
plt.close()
|
|
|
|
plt.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -117,9 +139,6 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu
|
|
|
|
except FileNotFoundError:
|
|
|
|
except FileNotFoundError:
|
|
|
|
volumes = pd.DataFrame()
|
|
|
|
volumes = pd.DataFrame()
|
|
|
|
|
|
|
|
|
|
|
|
# Format dates
|
|
|
|
|
|
|
|
date = get_datestring(survey_date)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for current_date in profiles.columns:
|
|
|
|
for current_date in profiles.columns:
|
|
|
|
# Get Nielsen erosion volumes
|
|
|
|
# Get Nielsen erosion volumes
|
|
|
|
chainage = profiles.loc[:, current_date].dropna().index
|
|
|
|
chainage = profiles.loc[:, current_date].dropna().index
|
|
|
@ -127,7 +146,7 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu
|
|
|
|
volume = nielsen_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, 'Volume_' + survey_date] = volume
|
|
|
|
|
|
|
|
|
|
|
|
# Save updated volumes spreadsheet
|
|
|
|
# Save updated volumes spreadsheet
|
|
|
|
volumes = volumes[volumes.columns.sort_values()]
|
|
|
|
volumes = volumes[volumes.columns.sort_values()]
|
|
|
@ -135,9 +154,13 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu
|
|
|
|
volumes.to_csv(csv_vol)
|
|
|
|
volumes.to_csv(csv_vol)
|
|
|
|
|
|
|
|
|
|
|
|
# Get most recent volume difference for current profile
|
|
|
|
# Get most recent volume difference for current profile
|
|
|
|
previous_vol = volumes.loc[profile_name].values[-2]
|
|
|
|
try:
|
|
|
|
current_vol = volumes.loc[profile_name].values[-1]
|
|
|
|
previous_vol = volumes.loc[profile_name].values[-2]
|
|
|
|
delta_vol = current_vol - previous_vol
|
|
|
|
current_vol = volumes.loc[profile_name].values[-1]
|
|
|
|
|
|
|
|
delta_vol = current_vol - previous_vol
|
|
|
|
|
|
|
|
except IndexError:
|
|
|
|
|
|
|
|
# Return None if there is only one survey
|
|
|
|
|
|
|
|
delta_vol = None
|
|
|
|
|
|
|
|
|
|
|
|
return delta_vol
|
|
|
|
return delta_vol
|
|
|
|
|
|
|
|
|
|
|
@ -164,7 +187,7 @@ def main():
|
|
|
|
for i, row in params_file.iterrows():
|
|
|
|
for i, row in params_file.iterrows():
|
|
|
|
print("Starting to process %s" % row['Beach'])
|
|
|
|
print("Starting to process %s" % row['Beach'])
|
|
|
|
beach=row['Beach']
|
|
|
|
beach=row['Beach']
|
|
|
|
survey_date = row['SURVEY DATE']
|
|
|
|
survey_date = str(row['SURVEY DATE'])
|
|
|
|
original_las = row['INPUT LAS']
|
|
|
|
original_las = row['INPUT LAS']
|
|
|
|
classified_las_dir = row['LAS CLASSIFIED FOLDER']
|
|
|
|
classified_las_dir = row['LAS CLASSIFIED FOLDER']
|
|
|
|
shp_swash_dir = row['SHP SWASH FOLDER']
|
|
|
|
shp_swash_dir = row['SHP SWASH FOLDER']
|
|
|
@ -234,7 +257,7 @@ def main():
|
|
|
|
csv_output_dir, ch_limits,
|
|
|
|
csv_output_dir, ch_limits,
|
|
|
|
volume_output_dir)
|
|
|
|
volume_output_dir)
|
|
|
|
plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits,
|
|
|
|
plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits,
|
|
|
|
delta_vol)
|
|
|
|
delta_vol, survey_date)
|
|
|
|
|
|
|
|
|
|
|
|
# Remove temprary files
|
|
|
|
# Remove temprary files
|
|
|
|
remove_temp_files(tmp_dir)
|
|
|
|
remove_temp_files(tmp_dir)
|
|
|
|