computing diagnostic variables

28 views
Skip to first unread message

Marco Miani

unread,
Mar 7, 2025, 1:32:54 PMMar 7
to wrfpython-talk
Hi.

I am merging a series of wrfout files, in this specific case only variables P and T:
# Load available files
ds_list = []
for f in wrf_files:
try:
ds_list.append(xr.open_dataset(f)[["P", "T"]].isel(bottom_top=0))
except FileNotFoundError:
print(f"Missing file: {f}, skipping.")

# Merge while keeping missing time steps as NaN
ds_merged = xr.concat(ds_list, dim="Time", fill_value=np.nan)


After ds_merged is completed, saved to netcdf on disk, and reopened with wrf.getvar I am failing to get T2 (air temp at 2 meters).

Variables T and P alone (as shown above in the snippet) are not sufficient to compute (internally) the diagnostic variable. My questions, if you know:

1. what are the needed variables to compute T2, so to include them in the merging?
2. Is there any better, more efficient, faster, less CPU-intesive way do merge/concat a large list of files? I am doing this because I only need a handful of variables, and only at surface level. wrf get var does not seem to offer this flexibility, xarray does. So I am doing the heavy lifting in xarray, saving to disk and reopening in wrf.

Thanks for the advice and happy coding
Marco

Will H

unread,
Apr 30, 2025, 2:21:36 AMApr 30
to wrfpython-talk, Marco Miani
My guess is it is using a combination of these two commands



But i'm not sure.  

I also see that T2 is a variable with a header that can be called with wrf.getvar

<class 'netCDF4._netCDF4.Variable'>
float32 T2(Time, south_north, west_east)
    FieldType: 104
    MemoryOrder: XY
    description: TEMP at 2 M
    units: K
    stagger:
    coordinates: XLONG XLAT XTIME
unlimited dimensions: Time
current shape = (1, 405, 435)
filling on, default _FillValue of 9.969209968386869e+36 used 

Reply all
Reply to author
Forward
0 new messages