Error in parcel_profile #2915
-
My spidey sense says I'm overlooking something, but maybe this really is a bug? Here's my code: from datetime import datetime, timedelta
import xarray as xr
from xarray.backends import NetCDF4DataStore
from siphon.catalog import TDSCatalog
import metpy.calc as mpcalc
def get_nam212(init_time, valid_time):
"""Obtain NAM data on the 212 grid."""
ymd = init_time.strftime('%Y%m%d')
hr = init_time.strftime('%H')
filename = f'{ymd}_{hr}00.grib2'
ds_name = 'NAM_CONUS_40km_conduit_' + filename
cat_name = ('https://thredds.ucar.edu/thredds/catalog/grib/NCEP/NAM/'
'CONUS_40km/conduit/' + ds_name + '/catalog.xml')
cat = TDSCatalog(cat_name)
ds = cat.datasets[ds_name]
ncss = ds.subset()
query = ncss.query()
query.time(valid_time).variables('all')
nc = ncss.get_data(query)
data = xr.open_dataset(NetCDF4DataStore(nc)).metpy.parse_cf()
return data
init_time = datetime(2023, 2, 7, 12)
plot_time = init_time + timedelta(hours=6)
nam = get_nam212(init_time, plot_time)
tmp = nam['Temperature_isobaric']
dwp = mpcalc.dewpoint_from_relative_humidity(tmp, nam['Relative_humidity_isobaric'])
p = tmp['isobaric2']
p_env = p[::-1]
t_env = tmp[0, ::-1, 0, 0]
d_env = dwp[0, ::-1, 0, 0]
print(p_env.shape, t_env.shape, d_env.shape)
prof = mpcalc.parcel_profile(p_env, t_env, d_env) The result is:
I'm guessing the extra level has something to do with the LCL, and indeed there is no error using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
OK, I see I am violating the "contract" of the This would make the calling side consistent, i.e., prof = mpcalc.parcel_profile(p_env, t_env, d_env)
prof2 = mpcalc.parcel_profile_with_lcl(p_env, t_env, d_env) vs. prof = mpcalc.parcel_profile(p_env, t_env[0], d_env[0])
prof2 = mpcalc.parcel_profile_with_lcl(p_env, t_env, d_env) (although the second form would still work also) |
Beta Was this translation helpful? Give feedback.
parcel_profile
doesn't take arrays for temperature and dewpoint. It wants a sequence of pressures for which the profile should be calculated, and the starting thermodynamic state for the parcel (i.e. temperature and dewpoint at pressure[0]).