Fix formatting

develop
Chris Leaman 6 years ago
parent 3443062d85
commit faa843ce21

@ -14,6 +14,7 @@ logger = setup_logging()
MULTIPROCESS_THREADS = int(os.environ.get("MULTIPROCESS_THREADS", 4)) MULTIPROCESS_THREADS = int(os.environ.get("MULTIPROCESS_THREADS", 4))
def forecast_twl( def forecast_twl(
df_tides, df_tides,
df_profiles, df_profiles,
@ -53,12 +54,12 @@ def forecast_twl(
# When calculating mean slope, we go from the dune toe to mhw. However, in some profiles, the dune toe is not # When calculating mean slope, we go from the dune toe to mhw. However, in some profiles, the dune toe is not
# defined. In these cases, we should go to the dune crest # defined. In these cases, we should go to the dune crest
df_temp['top_elevation'] = df_temp['dune_toe_z'] df_temp["top_elevation"] = df_temp["dune_toe_z"]
df_temp.loc[df_temp.dune_toe_z.isnull(), 'top_elevation'] = df_temp.loc[df_temp.dune_toe_z.isnull(), df_temp.loc[df_temp.dune_toe_z.isnull(), "top_elevation"] = df_temp.loc[
'dune_crest_z'] df_temp.dune_toe_z.isnull(), "dune_crest_z"
df_temp['top_x'] = df_temp['dune_toe_x'] ]
df_temp.loc[df_temp.dune_toe_x.isnull(), 'top_x'] = df_temp.loc[df_temp.dune_toe_x.isnull(), df_temp["top_x"] = df_temp["dune_toe_x"]
'dune_crest_x'] df_temp.loc[df_temp.dune_toe_x.isnull(), "top_x"] = df_temp.loc[df_temp.dune_toe_x.isnull(), "dune_crest_x"]
with Pool(processes=n_processes) as pool: with Pool(processes=n_processes) as pool:
results = pool.starmap( results = pool.starmap(
@ -66,7 +67,6 @@ def forecast_twl(
[(site_id, df_temp, df_profiles, "top_elevation", "top_x", "mhw") for site_id in site_ids], [(site_id, df_temp, df_profiles, "top_elevation", "top_x", "mhw") for site_id in site_ids],
) )
df_twl["beta"] = pd.concat(results) df_twl["beta"] = pd.concat(results)
# Estimate runup # Estimate runup

@ -154,12 +154,10 @@ def overwrite_impacts(df_observed_impacts, df_raw_features):
:param df_raw_profile_features: :param df_raw_profile_features:
:return: :return:
""" """
df_observed_impacts.update(df_raw_features.rename(columns={ df_observed_impacts.update(df_raw_features.rename(columns={"observed_storm_regime": "storm_regime"}))
'observed_storm_regime':'storm_regime'}))
return df_observed_impacts return df_observed_impacts
@click.command() @click.command()
@click.option("--profiles-csv", required=True, help="") @click.option("--profiles-csv", required=True, help="")
@click.option("--profile-features-crest-toes-csv", required=True, help="") @click.option("--profile-features-crest-toes-csv", required=True, help="")
@ -167,9 +165,9 @@ def overwrite_impacts(df_observed_impacts, df_raw_features):
@click.option("--output-file", required=True, help="") @click.option("--output-file", required=True, help="")
def create_observed_impacts(profiles_csv, profile_features_crest_toes_csv, raw_profile_features_csv, output_file): def create_observed_impacts(profiles_csv, profile_features_crest_toes_csv, raw_profile_features_csv, output_file):
profiles_csv = './data/interim/profiles.csv' profiles_csv = "./data/interim/profiles.csv"
profile_features_crest_toes_csv= './data/interim/profile_features_crest_toes.csv' profile_features_crest_toes_csv = "./data/interim/profile_features_crest_toes.csv"
raw_profile_features_csv = './data/raw/profile_features_chris_leaman/profile_features_chris_leaman.csv' raw_profile_features_csv = "./data/raw/profile_features_chris_leaman/profile_features_chris_leaman.csv"
logger.info("Creating observed wave impacts") logger.info("Creating observed wave impacts")
logger.info("Importing data") logger.info("Importing data")

@ -76,7 +76,7 @@ def R_high_to_geojson(sites_csv, profiles_csv, crest_toes_csv, impacts_csv, outp
# Take the intersection closest to the dune face. # Take the intersection closest to the dune face.
try: try:
dune_face_x = np.mean(df_crest_toes.loc[(site_id, 'prestorm'), :].x) dune_face_x = np.mean(df_crest_toes.loc[(site_id, "prestorm"), :].x)
int_x = min(int_x, key=lambda x: abs(x - dune_face_x)) int_x = min(int_x, key=lambda x: abs(x - dune_face_x))
except: except:
continue continue

@ -25,20 +25,21 @@ def parse_crest_toes(df_raw_features, df_profiles):
""" """
# Puts profiles_features_csv into format expected by rest of analysis # Puts profiles_features_csv into format expected by rest of analysis
df_crest_toes = df_raw_features.reset_index().melt(id_vars=['site_id'], df_crest_toes = df_raw_features.reset_index().melt(
value_vars=['prestorm_dune_crest_x', 'prestorm_dune_toe_x', id_vars=["site_id"],
'poststorm_dune_crest_x', 'poststorm_dune_toe_x']) 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["profile_type"] = df_crest_toes.variable.str.extract(r"(prestorm|poststorm)")
df_crest_toes = df_crest_toes.drop(columns=['variable']) df_crest_toes["point_type"] = df_crest_toes.variable.str.extract(r"(dune_crest_x|dune_toe_x)")
df_crest_toes = df_crest_toes.sort_values('site_id') df_crest_toes = df_crest_toes.drop(columns=["variable"])
df_crest_toes = df_crest_toes.set_index(['site_id', 'profile_type', 'point_type']) 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 = df_crest_toes.unstack()
df_crest_toes.columns = df_crest_toes.columns.droplevel() df_crest_toes.columns = df_crest_toes.columns.droplevel()
# Now let's calculate the corresponding z elevations for each of our x coordinates # 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(): 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 # Get profile for this site
idx = pd.IndexSlice idx = pd.IndexSlice
@ -58,9 +59,9 @@ def parse_crest_toes(df_raw_features, df_profiles):
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 df_z.empty:
if param == "prestorm": if param == "prestorm":
new_param = 'poststorm' new_param = "poststorm"
elif param == "poststorm": elif param == "poststorm":
new_param = 'prestorm' new_param = "prestorm"
z_val = df_profile.loc[idx[site_id, new_param, x_val], :].z z_val = df_profile.loc[idx[site_id, new_param, x_val], :].z
else: else:
z_val = df_z.z z_val = df_z.z
@ -80,6 +81,7 @@ def parse_crest_toes(df_raw_features, df_profiles):
return df_crest_toes return df_crest_toes
def parse_dune_crest_toes(df_sites, crest_mat, toe_mat): def parse_dune_crest_toes(df_sites, crest_mat, toe_mat):
""" """
:param df_sites: :param df_sites:
@ -128,7 +130,6 @@ def parse_dune_crest_toes(df_sites, crest_mat, toe_mat):
return df_profile_features return df_profile_features
def parse_waves(waves_mat): def parse_waves(waves_mat):
""" """
Parses the raw waves.mat file and returns a pandas dataframe Parses the raw waves.mat file and returns a pandas dataframe
@ -433,7 +434,6 @@ def create_crest_toes(profile_features_csv, profiles_csv, output_file):
logger.info("Created %s", output_file) logger.info("Created %s", output_file)
@click.command(short_help="create profiles.csv") @click.command(short_help="create profiles.csv")
@click.option("--profiles-mat", required=True, help=".mat file containing beach profiles") @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") @click.option("--profiles-output-file", required=True, help="where to save profiles.csv")

Loading…
Cancel
Save