You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
precip in the ERA5 catalog hosted by planet os is in m (total precipitation). Wanted to convert it to mm. I could have simply multiplied it by 1,000 but was a good excuse to try this package.
import pint_xarray
import xarray as xr
ds = xr.open_mfdataset(
"s3://era5-pds/zarr/2020/01/data/precipitation_amount_1hour_Accumulation.zarr",
engine="zarr",
)
ds = ds.drop("time1_bounds")
q = ds.pint.quantify(precipitation_amount_1hour_Accumulation="m")
ValueError Traceback (most recent call last)
<ipython-input-42-fa56e0f4f598> in <module>
----> 1 q = ds.pint.quantify(precipitation_amount_1hour_Accumulation="m")
~/opt/miniconda3/envs/main/lib/python3.9/site-packages/pint_xarray/accessors.py in quantify(self, units, unit_registry, **unit_kwargs)
972
973 if invalid_units:
--> 974 raise ValueError(format_error_message(invalid_units, "parse"))
975
976 return self.ds.pipe(conversion.strip_unit_attributes).pipe(
ValueError: Cannot parse units:
-- invalid units for variable 'lat': degrees_north (attribute) (reason: 'degrees_north' is not defined in the unit registry)
-- invalid units for variable 'lon': degrees_east (attribute) (reason: 'degrees_east' is not defined in the unit registry)
From perusing the issues it's probably related to #26
You could parse for lat/lon in the ValueError: Cannot parse units and explicitly state you could try setting ds.variable.attrs["units"] = "degree" if it contains lat/lon/latitude/longitude etc. or look for degrees_[north/east/south/west].
raybellwaves
changed the title
invalid units for variable 'lat': degrees_north
Add suggestion in ValueError: Cannot parse units for lat/lon
May 30, 2021
the code in the tutorial notebook really is a workaround, and I think we'll change that to depend on cf-xarray>0.5.2 (once that is released) which provides a UnitRegistry that can parse these units (and also other cfunits like m s-2). We'll still need to figure out some issues regarding the registering of UnitRegistry objects, though.
Once again, thanks for opening these issues. pint-xarray is currently in a state where most things should work but there are still some issues that need to be fixed (both bugs and design choices), so I really appreciate the feedback.
First time dabbling with pint-xarray.
precip in the ERA5 catalog hosted by planet os is in m (total precipitation). Wanted to convert it to mm. I could have simply multiplied it by 1,000 but was a good excuse to try this package.
From perusing the issues it's probably related to #26
Tested on main as well
The text was updated successfully, but these errors were encountered: