From 9f1b80168755d85eae90f437bea3613336e24135 Mon Sep 17 00:00:00 2001 From: Chris Leaman Date: Fri, 7 Dec 2018 13:11:16 +1100 Subject: [PATCH] Add function for estimating twl exceedence time --- src/analysis/forecasted_storm_impacts.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/analysis/forecasted_storm_impacts.py b/src/analysis/forecasted_storm_impacts.py index 0ea92ec..eca4b80 100644 --- a/src/analysis/forecasted_storm_impacts.py +++ b/src/analysis/forecasted_storm_impacts.py @@ -66,6 +66,18 @@ def storm_regime(df_forecasted_impacts): return df_forecasted_impacts +def twl_exceedence_time(df_profile_features, df_forecasted_twl, z_twl_col='R_high', z_exceedence_col='dune_toe_z'): + logger.info("Getting twl exceedence time") + + df_dune_toes = df_profile_features.query('profile_type=="prestorm"').reset_index('profile_type')[ + 'dune_toe_z'].to_frame() + + df_merged = df_forecasted_twl.merge(df_dune_toes,left_on=['site_id'],right_on=['site_id']) + + return (df_merged[z_twl_col] >= df_merged[z_exceedence_col]).groupby('site_id').sum().rename( + 'twl_{}_exceedance_hrs'.format(z_exceedence_col)).to_frame() + + @click.command() @click.option("--profile-features-csv", required=True, help="") @click.option("--forecasted-twl-csv", required=True, help="") @@ -77,6 +89,11 @@ def create_forecasted_impacts(profile_features_csv, forecasted_twl_csv, output_f df_forecasted_twl = pd.read_csv(forecasted_twl_csv, index_col=[0, 1]) df_forecasted_impacts = forecasted_impacts(df_profile_features, df_forecasted_twl) + + df_forecasted_impacts = df_profile_features.merge(twl_exceedence_time(df_profile_features, df_forecasted_twl), + left_on=['site_id'], + right_on=['site_id']) + df_forecasted_impacts.to_csv(output_file) logger.info("Saved to %s", output_file) logger.info("Done!")