diff --git a/las_outputs.py b/las_outputs.py index 1f3632c..2e3aed3 100644 --- a/las_outputs.py +++ b/las_outputs.py @@ -35,7 +35,7 @@ def remove_temp_files(directory): return None -def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits): +def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, delta_vol): csv_name = profile_name + '.csv' profiles = pd.read_csv(os.path.join(csv_output_dir, csv_name)) @@ -55,7 +55,12 @@ def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits): ax.set_xlabel('Chainage (m)', labelpad=10) ax.set_ylabel('Elevation (m AHD)', labelpad=10) - ax.legend(frameon=False, fontsize=9) + + # Show most recent volume change + ax.annotate('Most recent\nvolume change:\n{:0.1f} m$^3$/m'.format(delta_vol), + (0.1, 0.15), xycoords='axes fraction', fontsize=8, + backgroundcolor='#ffffff', linespacing=1.5) + ax.legend(edgecolor='none', facecolor='#ffffff', fontsize=9) ax.xaxis.set_minor_locator(MultipleLocator(5)) ax.yaxis.set_minor_locator(MultipleLocator(0.5)) @@ -99,9 +104,17 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu volumes.loc[profile_name, date] = volume # Save updated volumes spreadsheet + volumes = volumes[volumes.columns.sort_values()] volumes = volumes.sort_index() volumes.to_csv(csv_vol) + # Get most recent volume difference for current profile + previous_vol = volumes.loc[profile_name].values[-2] + current_vol = volumes.loc[profile_name].values[-1] + delta_vol = current_vol - previous_vol + + return delta_vol + def main(): parser = argparse.ArgumentParser() @@ -191,8 +204,11 @@ def main(): print('Updating figures...') profile_names = df['Profile'].unique() for profile_name in profile_names: - plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits) - calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volume_output_dir) + delta_vol = calculate_volumes(profile_name, survey_date, + csv_output_dir, ch_limits, + volume_output_dir) + plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, + delta_vol) # Remove temprary files remove_temp_files(tmp_dir) @@ -200,3 +216,7 @@ def main(): if __name__ == '__main__': main() + +if True: + plt.plot([], label='label') + plt.legend(facecolor='r')