-
Notifications
You must be signed in to change notification settings - Fork 443
Closed
Labels
Area: ProjectionsPertains to projecting coordinates between coordinate systemsPertains to projecting coordinates between coordinate systemsType: BugSomething is not working like it shouldSomething is not working like it should
Milestone
Description
What went wrong?
HI! I'm working with regional climate data, CORDEX-CMIP5 and was planning to use MetPy for some of the work, it seems like a good fit for my needs. I did run into an issue when calling parse_cf() on the datasets I have. It seems it has to do with the crs that many of the CORDEX datasets have, rotated pole grid, with Y and X axes generally called rlat,standard_name = "grid_latitude" and rlon/standard_name = "grid_longitude", with unit degrees as seen in some of the examples of the CORDEX archive specification (pages 13 and 14). This issue looks similar to #1887.
Operating System
Linux
Version
1.7.0
Python Version
3.12.10
Code to Reproduce
import xarray as xr
import metpy
# Example file from CORDEX
ds = xr.open_dataset("data/tasmax_EUR-11_ICHEC-EC-EARTH_historical_r12i1p1_SMHI-RCA4_v1_day_19710101-19751231.nc")
ds.metpy.parse_cf()Errors, Traceback, and Logs
Traceback (most recent call last):
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/metpy/xarray.py", line 886, in _rebuild_coords
var = var.metpy.convert_coordinate_units(coord_name, 'meters')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/metpy/xarray.py", line 216, in convert_coordinate_units
data=self._data_array[coord].metpy.unit_array.m_as(units)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/pint/facets/plain/quantity.py", line 315, in m_as
return self.to(units).magnitude
^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/pint/facets/plain/quantity.py", line 536, in to
magnitude = self._convert_magnitude_not_inplace(other, *contexts, **ctx_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/pint/facets/plain/quantity.py", line 480, in _convert_magnitude_not_inplace
return self._REGISTRY.convert(self._magnitude, self._units, other)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/pint/facets/plain/registry.py", line 1050, in convert
return self._convert(value, src, dst, inplace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/pint/facets/context/registry.py", line 405, in _convert
return super()._convert(value, src, dst, inplace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/pint/facets/nonmultiplicative/registry.py", line 259, in _convert
return super()._convert(value, src, dst, inplace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/pint/facets/plain/registry.py", line 1085, in _convert
raise factor
pint.errors.DimensionalityError: Cannot convert from 'degree' (dimensionless) to 'meter' ([length])
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/runpy.py", line 88, in _run_code
exec(code, run_globals)
File "/home/my_user/.local/share/code-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 71, in <module>
cli.main()
File "/home/my_user/.local/share/code-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 501, in main
run()
File "/home/my_user/.local/share/code-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 351, in run_file
runpy.run_path(target, run_name="__main__")
File "/home/my_user/.local/share/code-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 310, in run_path
return _run_module_code(code, init_globals, run_name, pkg_name=pkg_name, script_name=fname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.local/share/code-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 127, in _run_module_code
_run_code(code, mod_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)
File "/home/my_user/.local/share/code-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 118, in _run_code
exec(code, run_globals)
File "/home/my_user/dev/repos/recreate_rotated_pole_grid_bug.py", line 5, in <module>
ds.metpy.parse_cf()
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/metpy/xarray.py", line 812, in parse_cf
subset = xr.merge([self.parse_cf(single_varname, coordinates=coordinates)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/metpy/xarray.py", line 875, in parse_cf
var = self._rebuild_coords(var, crs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/metpy/xarray.py", line 890, in _rebuild_coords
height = crs['perspective_point_height']
~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/my_user/.conda/envs/metpy-test/lib/python3.12/site-packages/metpy/plots/mapping.py", line 107, in __getitem__
return self._attrs[item]
~~~~~~~~~~~^^^^^^
KeyError: 'perspective_point_height'Metadata
Metadata
Assignees
Labels
Area: ProjectionsPertains to projecting coordinates between coordinate systemsPertains to projecting coordinates between coordinate systemsType: BugSomething is not working like it shouldSomething is not working like it should