|
|
|
@ -25,24 +25,25 @@ def parse_crest_toes(df_raw_features, df_profiles):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Puts profiles_features_csv into format expected by rest of analysis
|
|
|
|
|
df_crest_toes = df_raw_features.reset_index().melt(id_vars=['site_id'],
|
|
|
|
|
value_vars=['prestorm_dune_crest_x', 'prestorm_dune_toe_x',
|
|
|
|
|
'poststorm_dune_crest_x', 'poststorm_dune_toe_x'])
|
|
|
|
|
df_crest_toes['profile_type'] = df_crest_toes.variable.str.extract(r'(prestorm|poststorm)')
|
|
|
|
|
df_crest_toes['point_type'] = df_crest_toes.variable.str.extract(r'(dune_crest_x|dune_toe_x)')
|
|
|
|
|
df_crest_toes = df_crest_toes.drop(columns=['variable'])
|
|
|
|
|
df_crest_toes = df_crest_toes.sort_values('site_id')
|
|
|
|
|
df_crest_toes = df_crest_toes.set_index(['site_id', 'profile_type', 'point_type'])
|
|
|
|
|
df_crest_toes = df_raw_features.reset_index().melt(
|
|
|
|
|
id_vars=["site_id"],
|
|
|
|
|
value_vars=["prestorm_dune_crest_x", "prestorm_dune_toe_x", "poststorm_dune_crest_x", "poststorm_dune_toe_x"],
|
|
|
|
|
)
|
|
|
|
|
df_crest_toes["profile_type"] = df_crest_toes.variable.str.extract(r"(prestorm|poststorm)")
|
|
|
|
|
df_crest_toes["point_type"] = df_crest_toes.variable.str.extract(r"(dune_crest_x|dune_toe_x)")
|
|
|
|
|
df_crest_toes = df_crest_toes.drop(columns=["variable"])
|
|
|
|
|
df_crest_toes = df_crest_toes.sort_values("site_id")
|
|
|
|
|
df_crest_toes = df_crest_toes.set_index(["site_id", "profile_type", "point_type"])
|
|
|
|
|
df_crest_toes = df_crest_toes.unstack()
|
|
|
|
|
df_crest_toes.columns = df_crest_toes.columns.droplevel()
|
|
|
|
|
|
|
|
|
|
# Now let's calculate the corresponding z elevations for each of our x coordinates
|
|
|
|
|
for site_id in df_crest_toes.index.get_level_values("site_id").unique():
|
|
|
|
|
logger.info('Calculating dune toe/crest z elevations for {}'.format(site_id))
|
|
|
|
|
logger.info("Calculating dune toe/crest z elevations for {}".format(site_id))
|
|
|
|
|
|
|
|
|
|
# Get profile for this site
|
|
|
|
|
idx = pd.IndexSlice
|
|
|
|
|
df_profile = df_profiles.loc[idx[site_id, :,:], :]
|
|
|
|
|
df_profile = df_profiles.loc[idx[site_id, :, :], :]
|
|
|
|
|
|
|
|
|
|
for param in ["prestorm", "poststorm"]:
|
|
|
|
|
for loc in ["crest", "toe"]:
|
|
|
|
@ -55,13 +56,13 @@ def parse_crest_toes(df_raw_features, df_profiles):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Try get the value from the other profile if we return nan or empty dataframe
|
|
|
|
|
df_z = df_profile.loc[idx[site_id, param, x_val],:]
|
|
|
|
|
df_z = df_profile.loc[idx[site_id, param, x_val], :]
|
|
|
|
|
if df_z.empty:
|
|
|
|
|
if param == "prestorm":
|
|
|
|
|
new_param = 'poststorm'
|
|
|
|
|
new_param = "poststorm"
|
|
|
|
|
elif param == "poststorm":
|
|
|
|
|
new_param = 'prestorm'
|
|
|
|
|
z_val = df_profile.loc[idx[site_id, new_param, x_val],:].z
|
|
|
|
|
new_param = "prestorm"
|
|
|
|
|
z_val = df_profile.loc[idx[site_id, new_param, x_val], :].z
|
|
|
|
|
else:
|
|
|
|
|
z_val = df_z.z
|
|
|
|
|
|
|
|
|
@ -80,6 +81,7 @@ def parse_crest_toes(df_raw_features, df_profiles):
|
|
|
|
|
|
|
|
|
|
return df_crest_toes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_dune_crest_toes(df_sites, crest_mat, toe_mat):
|
|
|
|
|
"""
|
|
|
|
|
:param df_sites:
|
|
|
|
@ -128,7 +130,6 @@ def parse_dune_crest_toes(df_sites, crest_mat, toe_mat):
|
|
|
|
|
return df_profile_features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_waves(waves_mat):
|
|
|
|
|
"""
|
|
|
|
|
Parses the raw waves.mat file and returns a pandas dataframe
|
|
|
|
@ -426,14 +427,13 @@ def create_crest_toes(profile_features_csv, profiles_csv, output_file):
|
|
|
|
|
logger.info("Creating %s", output_file)
|
|
|
|
|
|
|
|
|
|
df_raw_features = pd.read_csv(profile_features_csv, index_col=[0])
|
|
|
|
|
df_profiles = pd.read_csv(profiles_csv, index_col=[0,1,2])
|
|
|
|
|
df_profiles = pd.read_csv(profiles_csv, index_col=[0, 1, 2])
|
|
|
|
|
df_crest_toes = parse_crest_toes(df_raw_features, df_profiles)
|
|
|
|
|
|
|
|
|
|
df_crest_toes.to_csv(output_file,float_format="%.3f")
|
|
|
|
|
df_crest_toes.to_csv(output_file, float_format="%.3f")
|
|
|
|
|
logger.info("Created %s", output_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command(short_help="create profiles.csv")
|
|
|
|
|
@click.option("--profiles-mat", required=True, help=".mat file containing beach profiles")
|
|
|
|
|
@click.option("--profiles-output-file", required=True, help="where to save profiles.csv")
|
|
|
|
@ -450,7 +450,7 @@ def create_sites_and_profiles_csv(profiles_mat, profiles_output_file, sites_outp
|
|
|
|
|
|
|
|
|
|
df_profiles.to_csv(profiles_output_file)
|
|
|
|
|
logger.info("Created %s", profiles_output_file)
|
|
|
|
|
df_sites.to_csv(sites_output_file,float_format="%.3f")
|
|
|
|
|
df_sites.to_csv(sites_output_file, float_format="%.3f")
|
|
|
|
|
logger.info("Created %s", sites_output_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|