0

I want to simply regrid one dataset's lat-lon values onto another and it fails with a coordinate mismatch error. Does anyone have any tips for fixing this?

I've put the code and the cube descriptions at the end.

Thanks!

>>> esm_height = iris.load_cube('model_data/u-bl658/height.nc')
>>> ncepncar_clusters = iris.load('ncepncar/clusters.nc')
>>> foo = esm_height[0].regrid(ncepncar_clusters[0], iris.analysis.Linear())

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-40-c90265ebff43> in <module>
----> 1 foo = esm_height[0].regrid(ncepncar_clusters[0], iris.analysis.Linear())

/nesi/nobackup/niwa00013/williamsjh/miniconda3/envs/kidson2/lib/python3.8/site-packages/iris/cube.py in regrid(self, grid, scheme)
   3802         """
   3803         regridder = scheme.regridder(self, grid)
-> 3804         return regridder(self)
   3805 
   3806 

/nesi/nobackup/niwa00013/williamsjh/miniconda3/envs/kidson2/lib/python3.8/site-packages/iris/analysis/_regrid.py in __call__(self, src)
    943                                  "matching coordinate metadata.")
    944         elif src_cs is None or grid_cs is None:
--> 945             raise ValueError("The rectilinear grid coordinates of the given "
    946                              "cube and target grid must either both have "
    947                              "coordinate systems or both have no coordinate "

ValueError: The rectilinear grid coordinates of the given cube and target grid must either both have coordinate systems or both have no coordinate system but with matching coordinate metadata.

cube to be regridded cube with target grid

jonnyhtw
  • 61
  • 8

1 Answers1

3

OK with some help I've fixed this now!

It was because the coordinate reference system for both the source and target cubes were not the same.

This fixes the issue...


nzesm_height[0].coord(axis='x').coord_system
GeogCS(6371229.0)

nzesm_height[0].coord(axis='y').coord_system
GeogCS(6371229.0)

ncepncar_clusters[0].coord(axis='x').coord_system = esm_height[0].coord(axis='x').coord_system

ncepncar_clusters[0].coord(axis='y').coord_system = esm_height[0].coord(axis='y').coord_system

foo = nzesm_height[0].regrid(ncepncar_clusters[0], iris.analysis.Linear())

I hope this helps others!

jonnyhtw
  • 61
  • 8