Skip to content

Commit

Permalink
update aircraft pairing with no rate changing results, but cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
rschwant committed Oct 23, 2024
1 parent 104162a commit ad9d2b4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion melodies_monet/util/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ad9d2b4

Please sign in to comment.