pangeo-data / xESMF

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

Interpolating onto a regular UTM grid resulting in "speckles" #284

Open obentley02 opened 11 months ago

obentley02 commented 11 months ago

Hi, I've been using xesmf inorder to regrid xarray data from one coordinate system to a regular grid in a UTM zone. Looking at the original data there is no "speckling" and if using xarray.Dataset.interp to interpolate onto the points of the regular UTM grid transformed back into the native coordinate system there is also no "speckling". I was wondering if you might know what causes this and if there is a workaround?

    # Create the 2D meshgrid
    xx, yy = np.meshgrid(x_values, y_values)

    # Create a transformer to perform the coordinate transformation
    transformer = Transformer.from_crs(epsg, 4326, always_xy=True)

    # Perform the coordinate transformation
    new_xx, new_yy = transformer.transform(xx, yy)
    ds = ds.rename({'XLAT': 'lat', 'XLON': 'lon'})

    # Step 1: Create the regridder from the source grid (latitude-longitude) to the target grid (UTM)
    regridder = xe.Regridder(ds, xr.Dataset(data_vars={},
                                            coords={'lon': (['y', 'x'], new_xx),
                                            'lat': (['y', 'x'], new_yy)}),
                            'bilinear', periodic=True)

image

aulemahal commented 11 months ago

Interesting issue! Do you think, it would be possible to provide a complete working example ? What are x_values, y_values and Transformer ? I am asking because it might be an issue with the data, or at least that there's something with the data that xESMF doesn't like.