@ -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 ( )
)