JiaweiZhuang / xESMF

Universal Regridder for Geospatial Data
http://xesmf.readthedocs.io/
MIT License
269 stars 49 forks source link

Regridding to physically invalid latitudes should probably warn or raise #8

Closed spencerahill closed 6 years ago

spencerahill commented 6 years ago

I accidentally switched the lat and lon arguments for xe.grid_2d, such that the target grid had latitudes from -180 to 180 and longitudes -90 to 90. Then, using this as the target on xe.regrid led to no crash or warning; the data was in fact interpolated to latitudes spanning from -180 to 180.

I believe it would be helpful to either warn or raise an error when the latitude range is physically invalid. For longitudes, it's harder, since some arrays use (-180, 180), others use (0, 360), etc.

JiaweiZhuang commented 6 years ago

Good suggestion. For longitude you can use whatever range, even (720, 1080), since ESMF will convert spheric coordinates to Cartesian coordinates for regridding calculation. It makes sense to check the range of latitudes.


Notes for who are using the low-level ESMPy:

ESMPy Regrid object takes a keyword argumentunmapped_action.

With ESMF.Regrid(..., unmapped_action = ESMF.UnmappedAction.ERROR) ESMPy will crash if there's any region that can't be mapped. For example if lat>90. But it will also crash if the target grid is larger than the source grid. I want to let the unmapped region be 0 without crashing the routine, so I am not using this option.

In xESMF I am setting ESMF.Regrid(..., unmapped_action = ESMF.UnmappedAction.IGNORE) so ESMPy will not throw any error.

ESMPy's error message is quite incomprehensible since the program often dies in the Fortran level, so I prefer adding high-level error checking in xESMF, instead of relying on ESMPy's error information.

JiaweiZhuang commented 6 years ago

v0.1.1 now gives a warning if latitude is outside of [-90, 90]. See warn_lat_range() in backend.py