Scale figures based on beach size

etta-drone
Dan Howe 6 years ago
parent 5656b96545
commit af6f51f331

@ -28,6 +28,25 @@ import nielsen_volumes
from survey_tools import call_lastools, extract_pts, update_survey_output from survey_tools import call_lastools, extract_pts, update_survey_output
def get_datestring(x):
"""Format a date integer into an ISO-8601 date string
Args:
x: integer representation of date string
Returns:
formatted date string
Examples:
>> get_datestring(19700101)
'1970-01-01'
"""
datestr = pd.datetime.strptime(str(x), '%Y%m%d').strftime('%Y-%m-%d')
return datestr
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))
@ -45,20 +64,28 @@ def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, delta_vol)
# 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']
ax = plt.axes() # Set figure dimensions based on beach size
vertical_exag = 8
m_per_inch = 8
fig_h = profiles.dropna().values.max() / m_per_inch * vertical_exag
fig_w = (profiles.index.max() - ch_min) / m_per_inch
fig, ax = plt.subplots(figsize=(fig_w, fig_h))
for col in profiles.columns: for col in profiles.columns:
profile = profiles.loc[ch_min:, col] profile = profiles.loc[ch_min:, col]
date_str = col.split('_')[-1] date_str = col.split('_')[-1]
date = '{}-{}-{}'.format(date_str[:4], date_str[4:6], date_str[6:]) date = get_datestring(date_str)
ax.plot(profile.index, profile, label=date) ax.plot(profile.index, profile, label=date)
ax.set_aspect(vertical_exag)
ax.set_xlabel('Chainage (m)', labelpad=10) ax.set_xlabel('Chainage (m)', labelpad=10)
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), ax.annotate('Most recent\nvolume change:\n{:0.1f} m$^3$/m'.format(delta_vol),
(0.1, 0.15), xycoords='axes fraction', fontsize=8, (0.05, 0.15), xycoords='axes fraction', fontsize=9,
backgroundcolor='#ffffff', linespacing=1.5) backgroundcolor='#ffffff', linespacing=1.5)
ax.legend(edgecolor='none', facecolor='#ffffff', fontsize=9) ax.legend(edgecolor='none', facecolor='#ffffff', fontsize=9)
@ -91,8 +118,7 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu
volumes = pd.DataFrame() volumes = pd.DataFrame()
# Format dates # Format dates
date_str = str(survey_date) date = get_datestring(survey_date)
date = '{}-{}-{}'.format(date_str[:4], date_str[4:6], date_str[6:])
for current_date in profiles.columns: for current_date in profiles.columns:
# Get Nielsen erosion volumes # Get Nielsen erosion volumes
@ -216,7 +242,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()
if True:
plt.plot([], label='label')
plt.legend(facecolor='r')

Loading…
Cancel
Save