From 557c15df1f7a67a8e16b2ebc13e396b195a45196 Mon Sep 17 00:00:00 2001 From: Chris Leaman Date: Sun, 10 Mar 2019 17:12:22 +1100 Subject: [PATCH] Enable observed impacts to be overwritten with NaN This is useful where we have a structure or rock wall and want to specify that we don't know what the observed storm regime is. In this case, we'll put a 'unknown' string in the ./data/raw/profile_features observed storm impact csv field and overwrite it with a NaN in our pandas dataframe. --- src/analysis/observed_storm_impacts.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/analysis/observed_storm_impacts.py b/src/analysis/observed_storm_impacts.py index 754cfcd..b60acbf 100644 --- a/src/analysis/observed_storm_impacts.py +++ b/src/analysis/observed_storm_impacts.py @@ -218,9 +218,21 @@ def overwrite_impacts(df_observed_impacts, df_raw_features): :param df_raw_profile_features: :return: """ - df_observed_impacts.update( - df_raw_features.rename(columns={"observed_storm_regime": "storm_regime"}) - ) + + # Get manually specified impacts from the profile features ./data/raw/ folder. Note that sites which need to be + # overwritten with a NaN, use the string 'none' in the csv. This is because when we use the df.update() command, + # it doesn't overwrite NaN values. So we'll put in the 'none' string, then overwrite that with the NaN. + + df_overwritten_impacts = df_raw_features.rename( + columns={"observed_storm_regime": "storm_regime"} + ).storm_regime.to_frame() + + df_observed_impacts.update(df_overwritten_impacts) + + # Replace 'none' with nan + df_overwritten_impacts.loc[ + df_overwritten_impacts.storm_regime == "unknown", "storm_regime" + ] = np.nan return df_observed_impacts