@ -23,7 +23,7 @@ def forecast_twl(
runup_function ,
runup_function ,
n_processes = MULTIPROCESS_THREADS ,
n_processes = MULTIPROCESS_THREADS ,
slope = " foreshore " ,
slope = " foreshore " ,
profile_type = ' prestorm '
profile_type = " prestorm " ,
) :
) :
# Use df_waves as a base
# Use df_waves as a base
df_twl = df_waves . copy ( )
df_twl = df_waves . copy ( )
@ -46,19 +46,20 @@ def forecast_twl(
df_twl [ " beta " ] = pd . concat ( results )
df_twl [ " beta " ] = pd . concat ( results )
elif slope == " mean " :
elif slope == " mean " :
df_temp = df_twl . join ( df_profile_features . query ( " profile_type== ' {} ' " . format ( profile_type ) ) . reset_index (
df_temp = df_twl . join (
level = ' profile_type ' )
df_profile_features . query ( " profile_type== ' {} ' " . format ( profile_type ) ) . reset_index ( level = " profile_type " ) ,
, how = " inner " )
how = " inner " ,
)
df_temp [ " mhw " ] = 0.5
df_temp [ " mhw " ] = 0.5
with Pool ( processes = n_processes ) as pool :
with Pool ( processes = n_processes ) as pool :
results = pool . starmap (
results = pool . starmap (
mean_slope_for_site_id , [ ( site_id , df_temp , df_profiles , " dune_toe_z " , " dune_toe_x " , " mhw " ) for
mean_slope_for_site_id ,
site_id in site_ids ]
[ ( site_id , df_temp , df_profiles , " dune_toe_z " , " dune_toe_x " , " mhw " ) for site_id in site_ids ] ,
)
)
df_twl [ " beta " ] = pd . concat ( results )
df_twl [ " beta " ] = pd . concat ( results )
# Estimate runup
# Estimate runup
R2 , setup , S_total , S_inc , S_ig = runup_function ( df_twl, Hs0_col = " Hs0 " , Tp_col = " Tp " , beta_col = " beta " )
R2 , setup , S_total , S_inc , S_ig = runup_function ( Hs0= df_twl [ ' Hs0 ' ] . tolist ( ) , Tp = df_twl [ " Tp " ] . tolist ( ) , beta = df_twl [ " beta " ] . tolist ( ) )
df_twl [ " R2 " ] = R2
df_twl [ " R2 " ] = R2
df_twl [ " setup " ] = setup
df_twl [ " setup " ] = setup
@ -69,13 +70,14 @@ def forecast_twl(
df_twl [ " R_low " ] = df_twl [ " tide " ] + 1.1 * df_twl [ " setup " ] - 1.1 / 2 * df_twl [ " S_total " ]
df_twl [ " R_low " ] = df_twl [ " tide " ] + 1.1 * df_twl [ " setup " ] - 1.1 / 2 * df_twl [ " S_total " ]
# Drop unneeded columns
# Drop unneeded columns
df_twl . drop ( columns = [ " E " , " Exs " , " P " , " Pxs " , " dir " ] , inplace = True , errors = " ignore " )
# df_twl.drop(columns=["E", "Exs", "P", "Pxs", "dir"], inplace=True, errors="ignore" )
return df_twl
return df_twl
def mean_slope_for_site_id ( site_id , df_twl , df_profiles , top_elevation_col , top_x_col , btm_elevation_col ,
def mean_slope_for_site_id (
profile_type = ' prestorm ' ) :
site_id , df_twl , df_profiles , top_elevation_col , top_x_col , btm_elevation_col , profile_type = " prestorm "
) :
"""
"""
Calculates the foreshore slope values a given site_id . Returns a series ( with same indicies as df_twl ) of
Calculates the foreshore slope values a given site_id . Returns a series ( with same indicies as df_twl ) of
foreshore slopes . This function is used to parallelize getting foreshore slopes as it is computationally
foreshore slopes . This function is used to parallelize getting foreshore slopes as it is computationally
@ -100,7 +102,7 @@ def mean_slope_for_site_id(site_id, df_twl, df_profiles, top_elevation_col, top_
top_elevation = row [ top_elevation_col ] ,
top_elevation = row [ top_elevation_col ] ,
btm_elevation = row [ btm_elevation_col ] ,
btm_elevation = row [ btm_elevation_col ] ,
method = " end_points " ,
method = " end_points " ,
top_x = row [ top_x_col ]
top_x = row [ top_x_col ] ,
) ,
) ,
axis = 1 ,
axis = 1 ,
)
)
@ -130,7 +132,7 @@ def foreshore_slope_for_site_id(site_id, df_twl, df_profiles):
profile_x = profile_x ,
profile_x = profile_x ,
profile_z = profile_z ,
profile_z = profile_z ,
tide = row . tide ,
tide = row . tide ,
runup_function = runup_models . sto06 _individual ,
runup_function = runup_models . sto06 ,
Hs0 = row . Hs0 ,
Hs0 = row . Hs0 ,
Tp = row . Tp ,
Tp = row . Tp ,
) ,
) ,
@ -216,16 +218,14 @@ def slope_from_profile(profile_x, profile_z, top_elevation, btm_elevation, metho
end_points = { " top " : { " z " : top_elevation } , " btm " : { " z " : btm_elevation } }
end_points = { " top " : { " z " : top_elevation } , " btm " : { " z " : btm_elevation } }
for end_type in end_points . keys ( ) :
for end_type in end_points . keys ( ) :
# Add x coordinates if they are specified
# Add x coordinates if they are specified
if top_x and end_type == ' top ' :
if top_x and end_type == " top " :
end_points [ ' top ' ] [ ' x ' ] = top_x
end_points [ " top " ] [ " x " ] = top_x
continue
continue
if btm_x and end_type == ' top ' :
if btm_x and end_type == " top " :
end_points [ ' btm ' ] [ ' x ' ] = btm_x
end_points [ " btm " ] [ " x " ] = btm_x
continue
continue
elevation = end_points [ end_type ] [ " z " ]
elevation = end_points [ end_type ] [ " z " ]
@ -306,8 +306,9 @@ def crossings(profile_x, profile_z, constant_z):
@click.option ( " --slope " , required = True , help = " " , type = click . Choice ( [ " foreshore " , " mean " ] ) )
@click.option ( " --slope " , required = True , help = " " , type = click . Choice ( [ " foreshore " , " mean " ] ) )
@click.option ( " --profile-type " , required = True , help = " " , type = click . Choice ( [ " prestorm " , " poststorm " ] ) )
@click.option ( " --profile-type " , required = True , help = " " , type = click . Choice ( [ " prestorm " , " poststorm " ] ) )
@click.option ( " --output-file " , required = True , help = " " )
@click.option ( " --output-file " , required = True , help = " " )
def create_twl_forecast ( waves_csv , tides_csv , profiles_csv , profile_features_csv , runup_function , slope ,
def create_twl_forecast (
profile_type , output_file ) :
waves_csv , tides_csv , profiles_csv , profile_features_csv , runup_function , slope , profile_type , output_file
) :
logger . info ( " Creating forecast of total water levels " )
logger . info ( " Creating forecast of total water levels " )
logger . info ( " Importing data " )
logger . info ( " Importing data " )
df_waves = pd . read_csv ( waves_csv , index_col = [ 0 , 1 ] )
df_waves = pd . read_csv ( waves_csv , index_col = [ 0 , 1 ] )
@ -323,7 +324,7 @@ def create_twl_forecast(waves_csv, tides_csv, profiles_csv, profile_features_csv
df_profile_features ,
df_profile_features ,
runup_function = getattr ( runup_models , runup_function ) ,
runup_function = getattr ( runup_models , runup_function ) ,
slope = slope ,
slope = slope ,
profile_type = profile_type
profile_type = profile_type ,
)
)
df_twl . to_csv ( output_file )
df_twl . to_csv ( output_file )