From cdca489e4ae6a80cb0f3579a5b1dae95c250ab18 Mon Sep 17 00:00:00 2001 From: Chris Leaman Date: Wed, 6 Mar 2019 16:56:47 +1100 Subject: [PATCH] Fix dune toe TWL exceedence hours Dune toe TWL exceedence hours were being left as zero if the profile didn't have a dune toe (technically correct). In these cases it's more useful to calculate the exceedence hours of the dune crest level. --- src/analysis/forecasted_storm_impacts.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/analysis/forecasted_storm_impacts.py b/src/analysis/forecasted_storm_impacts.py index 6ce742f..ca7b857 100644 --- a/src/analysis/forecasted_storm_impacts.py +++ b/src/analysis/forecasted_storm_impacts.py @@ -87,7 +87,6 @@ def twl_exceedence_time( df_profile_features, df_forecasted_twl, z_twl_col="R_high", - z_exceedence_col="dune_toe_z", ): """ Returns a dataframe of number of hours the twl exceeded a certain z elevation. @@ -100,12 +99,13 @@ def twl_exceedence_time( """ logger.info("Getting twl exceedence time") - # Get a dataframe of prestorm dune toes organised by site_id - df_dune_toes = ( - df_profile_features.query('profile_type=="prestorm"') - .reset_index("profile_type")[z_exceedence_col] - .to_frame() - ) + # Get the elevation we want to calculate the time TWL exceedes this level. + # Note it's usually dune toe, but some profiles don't have a dune toe. In these cases, use dune crest value + df_temp = df_profile_features.xs("prestorm", level="profile_type").copy() + df_temp.loc[df_temp.dune_toe_z.isnull(), "dune_toe_z"] = df_temp[ + df_temp.dune_toe_z.isnull() + ].dune_crest_z + df_dune_toes = df_temp.dune_toe_z.to_frame() # Merge dune toes into site_id df_merged = df_forecasted_twl.merge( @@ -114,10 +114,10 @@ def twl_exceedence_time( # Return the sum of hours that twl exceeded the level return ( - (df_merged[z_twl_col] >= df_merged[z_exceedence_col]) + (df_merged[z_twl_col] >= df_merged["dune_toe_z"]) .groupby("site_id") .sum() - .rename("twl_{}_exceedance_hrs".format(z_exceedence_col)) + .rename("twl_{}_exceedance_hrs".format("dune_toe_z")) .to_frame() )