From ad9d2b49de4da4ee96a465bb986adb4ecd0bd6eb Mon Sep 17 00:00:00 2001 From: Rebecca Schwantes Date: Wed, 23 Oct 2024 09:56:37 -0600 Subject: [PATCH 1/2] update aircraft pairing with no rate changing results, but cleaner code --- melodies_monet/util/tools.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/melodies_monet/util/tools.py b/melodies_monet/util/tools.py index 9f238fb0..67c20102 100644 --- a/melodies_monet/util/tools.py +++ b/melodies_monet/util/tools.py @@ -313,10 +313,25 @@ def vert_interp(ds_model,df_obs,var_name_list): var_out_list.append(out) df_model = xr.merge(var_out_list).to_dataframe().reset_index() - df_model.fillna({'pressure_model':df_model.pressure_obs},inplace=True) + for time in df_model.time.unique(): + if df_model[df_model.time == time].pressure_obs.unique() > df_model[df_model.time == time].pressure_model.max(): + df_model.fillna({'pressure_model':df_model[df_model.time == time].pressure_obs},inplace=True) + elif df_model[df_model.time == time].pressure_obs.unique() < df_model[df_model.time == time].pressure_model.min(): + df_model.fillna({'pressure_model':df_model[df_model.time == time].pressure_obs},inplace=True) + print('Warning: You are pairing obs data above the model top. This is not recommended.') + print(time) df_model.drop(labels=['x','y','z','pressure_obs','time_obs'], axis=1, inplace=True) df_model.rename(columns={'pressure_model':'pressure_obs'}, inplace=True) + #Confirm that extra digits will not break the pairing at the merge_asof step by rounding to the 8th digit + df_model.latitude = df_model.latitude.round(8) + df_model.longitude = df_model.longitude.round(8) + df_model.pressure_obs = df_model.pressure_obs.round(8) + + df_obs.latitude = df_obs.latitude.round(8) + df_obs.longitude = df_obs.longitude.round(8) + df_obs.pressure_obs = df_obs.pressure_obs.round(8) + final_df_model = merge_asof(df_obs, df_model, by=['latitude', 'longitude', 'pressure_obs'], on='time', direction='nearest') From 63a8d2a1c7d40e89098b4ffcf76e39585287a256 Mon Sep 17 00:00:00 2001 From: Rebecca Schwantes Date: Tue, 12 Nov 2024 14:12:19 -0700 Subject: [PATCH 2/2] Take out rounding correction. Will fix another way. --- melodies_monet/util/tools.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/melodies_monet/util/tools.py b/melodies_monet/util/tools.py index 67c20102..96bf5dd1 100644 --- a/melodies_monet/util/tools.py +++ b/melodies_monet/util/tools.py @@ -323,15 +323,6 @@ def vert_interp(ds_model,df_obs,var_name_list): df_model.drop(labels=['x','y','z','pressure_obs','time_obs'], axis=1, inplace=True) df_model.rename(columns={'pressure_model':'pressure_obs'}, inplace=True) - #Confirm that extra digits will not break the pairing at the merge_asof step by rounding to the 8th digit - df_model.latitude = df_model.latitude.round(8) - df_model.longitude = df_model.longitude.round(8) - df_model.pressure_obs = df_model.pressure_obs.round(8) - - df_obs.latitude = df_obs.latitude.round(8) - df_obs.longitude = df_obs.longitude.round(8) - df_obs.pressure_obs = df_obs.pressure_obs.round(8) - final_df_model = merge_asof(df_obs, df_model, by=['latitude', 'longitude', 'pressure_obs'], on='time', direction='nearest')