@ -87,7 +87,6 @@ def twl_exceedence_time(
df_profile_features ,
df_profile_features ,
df_forecasted_twl ,
df_forecasted_twl ,
z_twl_col = " R_high " ,
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 .
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 " )
logger . info ( " Getting twl exceedence time " )
# Get a dataframe of prestorm dune toes organised by site_id
# Get the elevation we want to calculate the time TWL exceedes this level.
df_dune_toes = (
# Note it's usually dune toe, but some profiles don't have a dune toe. In these cases, use dune crest value
df_profile_features . query ( ' profile_type== " prestorm " ' )
df_temp = df_profile_features . xs ( " prestorm " , level = " profile_type " ) . copy ( )
. reset_index ( " profile_type " ) [ z_exceedence_col ]
df_temp . loc [ df_temp . dune_toe_z . isnull ( ) , " dune_toe_z " ] = df_temp [
. to_frame ( )
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
# Merge dune toes into site_id
df_merged = df_forecasted_twl . merge (
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 the sum of hours that twl exceeded the level
return (
return (
( df_merged [ z_twl_col ] > = df_merged [ z_exceedence_col ] )
( df_merged [ z_twl_col ] > = df_merged [ " dune_toe_z " ] )
. groupby ( " site_id " )
. groupby ( " site_id " )
. sum ( )
. sum ( )
. rename ( " twl_ {} _exceedance_hrs " . format ( z_exceedence_col ) )
. rename ( " twl_ {} _exceedance_hrs " . format ( " dune_toe_z " ) )
. to_frame ( )
. to_frame ( )
)
)