-
I am trying to use metpy.calc to calculate equivalent potential temperature for a plot of archived zarr HRRR data from NOAA's big data server on AWS. Using temperature as an example (the same is performed for pressure and dewpoint): s3 = s3fs.S3FileSystem(anon=True)
def lookup(path):
return s3fs.S3Map(path, s3=s3)
path = "hrrrzarr/sfc/20210101/20210101_00z_anl.zarr/2m_above_ground/TMP"
temp = xarray.open_mfdataset([lookup(path), lookup(f"{path}/2m_above_ground")],
engine="zarr") When I run the below code, I get the following error: theta_e = mpcalc.equivalent_potential_temperature(pres, temp, dpt)
print(theta_e) ValueError: `equivalent_potential_temperature` given arguments with incorrect units: `pressure` requires "[pressure]" but given "none", `temperature` requires "[temperature]" but given "none", `dewpoint` requires "[temperature]" but given "none"
Any variable `x` can be assigned a unit as follows:
from metpy.units import units
x = units.Quantity(x, "m/s") And so when I use the suggested correction, I get a new error: temp = units.Quantity(temp, "K")
print(temp) TypeError: Quantity cannot wrap upcast type <class 'xarray.core.dataset.Dataset'> So then I try: temp = temp.metpy.quantify() And get the original ValueError message. Anyone know how to get units attached to variables from zarr files in AWS to perform MetPy calculations? Thanks so much! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to pull out the individual temperature theta_e = mpcalc.equivalent_potential_temperature(pres, temp["TMP"], dpt)
# or
thera_e = mpcalc.equivalent_potential_temperature(pres, temp.TMP, dpt) or you can assign this DataArray to a new variable, if preferred. Using quantify here did work (and can also work on individual DataArrays) to add units, but you still have to select the specific DataArray you want to use. |
Beta Was this translation helpful? Give feedback.
You need to pull out the individual temperature
xarray.DataArray
from thetemp
xarray.Dataset
you've created. A Dataset is basically a collection of potentially multiple DataArrays, and you can access individual DataArrays within through dictionary or attribute-style notations. E.g.,or you can assign this DataArray to a new variable, if preferred. Using quantify here did work (and can also work on individual DataArrays) to add units, but you still have to select the specific DataArray you want to use.