Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update aircraft pairing (no changes to results) #305

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading