pangeo-data / xESMF

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

xESMF regridding showing repeated values at latitude poles #133

Open trimpinm opened 3 years ago

trimpinm commented 3 years ago

I am experiencing problems when regridding on a global grid in xesmf. Everything is working as it should, except for at the poles (latitudes -90 and 90), where it shows repeated values (2.58851004e+00, 2.58851004e+00, 2.58851004e+00, ...) for each variable. I have also compared it with the CDO regridder to verify, and it showed differences of 0 at every lat/lon point, save for lats -90 and 90. Is there a fix for this?

I have attatched sample netCDF input data via zip file: test_input.zip Code:

import xarray as xr
import xesmf as xe

ds = xr.open_dataset('./test_input.nc4') 
ds = ds.transpose("time", "lat", "lon")
output_grid = xr.Dataset({'lat': (['lat'], np.arange(-90, 94, 4)),
                    'lon': (['lon'], np.arange(0, 360, 5)),
                    }
                )

regridder = xe.Regridder(ds, output_grid, 'bilinear',  periodic=True) #same problem for nearest neighbor regridding
ds_out = regridder(ds,keep_attrs=True)

print(ds_out)

You will notice, once ds_out is generated, evaluating ds_out['ZLCL'][:,0,:] or ds_out['ZLCL'][:,45,:] Will show all repeated values. These values correspond to lat = -90 and lat = 90.

huard commented 3 years ago

Thanks for the report, the example and test file. We've a bit of a backlog at the moment, will try to look into it next week.

trimpinm commented 3 years ago

Edit: Also experiencing the occasional incorrect value at longitude 0? But no problem at anti-meridian.

huard commented 3 years ago

Hi @mtrimp2,

In the input file, there is only one value for ZLCL as well at lat=90 and -90.

In [20]: set(ds.ZLCL.isel(time=0, lat=-1).data)
Out[20]: {222.90154}

which is expected because it's the pole. After interpolation, we get the same thing.

In [23]: set(ds_out.ZLCL.isel(time=0, lat=-1).data)
Out[23]: {222.9015350341797}

What value were you expecting ?

trimpinm commented 3 years ago

Okay, ZLCL turned out to not be the best example. I will take instead V50M in the same file. The values I was expecting were in reference to the results I got from CDO tool I used to do the same regridding process on the same dataset.

If, for example, I print ds['V50M'][0,45,:] (corresponding to latitude 90 at time 0), I get [-1.823932, -1.823932, -1.823932, ... , -1.823932]. Meanwhile, on the dataset generated by the CDO tool, the same calculation would yield results along the lines of [ 1.823529, 2.287396, 2.758099, 3.235638, 3.722943, 4.106732, ... , 3.545208]. I can send you the dataset generated by the CDO tool as well, if needed.

raphaeldussin commented 3 years ago

@mtrimp2 sorry we've been busing getting the new release out. Copy/paste here your cdo command and I'll give it a try. As @huard mentioned the poles are special cases and there can be different choices how to treat them. Have you tried the ignore_degenerate option of xesmf?

trimpinm commented 3 years ago

Here are the regridded datasets. ignore_degenerate yields the same results in this case, unfortunately regridded_datasets.zip

huard commented 3 years ago

V50M is a northward_wind_at_50_meters, so as you move along longitudes, what is defined as the "north" changes. I suspect this can be handled by the ESMPy PoleMethod , but I don't think this option is exposed yet in xESMF.

If someone can confirm this will actually solve your issue, would you want to submit a PR for this new feature ? We'll be happy to review and merge.

raphaeldussin commented 3 years ago

@mtrimp2 have you tried a quiver plot of remapped velocities on a polar stereographic projection?

trimpinm commented 2 years ago

It is also worth noting, that when regridding the entire dataset, many variables yield different results. I tried to find a correlation to see if there is a sole issue (for example, the northward wind at 50m), but I do not believe it to be the case. Here is a complete output from nccmp diagnostics showing the differing variables, if that is helpful lears-mini_grass_global_regrid.json_comparison_regrid_global_all_vars.txt