diff --git a/src/analysis/forecast_twl.py b/src/analysis/forecast_twl.py index 06d7bf4..1bb29c1 100644 --- a/src/analysis/forecast_twl.py +++ b/src/analysis/forecast_twl.py @@ -45,7 +45,8 @@ def forecast_twl( df_twl["beta"] = pd.concat(results) elif slope == "mean": - df_temp = df_twl.join(df_profile_features, how="inner") + df_temp = df_twl.join(df_profile_features.query("profile_type=='prestorm'").reset_index(level='profile_type') + , how="inner") df_temp["mhw"] = 0.5 with Pool(processes=n_processes) as pool: results = pool.starmap( @@ -226,7 +227,12 @@ def slope_from_profile(profile_x, profile_z, top_elevation, btm_elevation, metho end_points[end_type]["x"] = intersection_x[-1] else: # For bottom elevation, take most landward intersection that is seaward of top elevation - end_points[end_type]["x"] = [x for x in intersection_x if x > end_points["top"]["x"]][0] + end_point_btm = [x for x in intersection_x if x > end_points["top"]["x"]] + if len(end_point_btm) == 0: + # If there doesn't seem to be an intersection seaward of the top elevation, return none. + return None + else: + end_points[end_type]["x"] = end_point_btm[0] if method == "end_points": x_top = end_points["top"]["x"] @@ -286,7 +292,7 @@ def create_twl_forecast(waves_csv, tides_csv, profiles_csv, profile_features_csv df_waves = pd.read_csv(waves_csv, index_col=[0, 1]) df_tides = pd.read_csv(tides_csv, index_col=[0, 1]) df_profiles = pd.read_csv(profiles_csv, index_col=[0, 1, 2]) - df_profile_features = pd.read_csv(profile_features_csv, index_col=[0]) + df_profile_features = pd.read_csv(profile_features_csv, index_col=[0,1]) logger.info("Forecasting TWL") df_twl_foreshore_slope_sto06 = forecast_twl(