Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xESMF regridding showing repeated values at latitude poles #133

Open
trimpinm opened this issue Nov 10, 2021 · 9 comments
Open

xESMF regridding showing repeated values at latitude poles #133

trimpinm opened this issue Nov 10, 2021 · 9 comments

Comments

@trimpinm
Copy link

trimpinm commented Nov 10, 2021

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
Copy link
Contributor

huard commented Nov 16, 2021

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
Copy link
Author

trimpinm commented Nov 18, 2021

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

@huard
Copy link
Contributor

huard commented Nov 22, 2021

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
Copy link
Author

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
Copy link
Contributor

@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
Copy link
Author

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

@huard
Copy link
Contributor

huard commented Nov 23, 2021

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
Copy link
Contributor

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

@trimpinm
Copy link
Author

trimpinm commented Jan 31, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants