Xee icon indicating copy to clipboard operation
Xee copied to clipboard

Xee does not provide correct data for resampled image

Open deepgabani8 opened this issue 1 year ago • 3 comments

When I use ee.data.computePixels, it returns different data for different resample methods, which it should but fetching data using xee as backend returns the same data.

Using ee.data.computePixels, which gives different data for resample methods = ['bilinear', 'bicubic'].

image = ee.Image(image_id)
image = image.resample('bilinear').reproject(crs=crs, crsTransform=crs_transform)
image = image.clip(
    ee.Geometry.Rectangle(
      [[-180, -90], [-90, -45]],
      None,
      geodesic=False,
  )
)

data = np.load(io.BytesIO(ee.data.computePixels({
    'expression': image,
    'fileFormat': 'NPY',
})))

Using Xee as the backend, which gives the same data for resample methods = ['bilinear', 'bicubic'].

image = ee.Image(image_id)
image = image.resample('bilinear').reproject(crs=crs, crsTransform=crs_transform)
geom = ee.Geometry.Rectangle(
    [[-180, -90], [-90, -45]],
    None,
    geodesic=False,
)

ds = xr.open_dataset(
  ee.ImageCollection([image]), projection = image.projection(), geometry=geom,
  engine=xee.EarthEngineBackendEntrypoint,
)

var = list(ds.data_vars)[0]
data = ds[var].data[0,:,:].T

deepgabani8 avatar Feb 26 '24 10:02 deepgabani8

Thanks for raising the issue, @deepgabani8.

Just for your information (jfyi), we internally work with asset_ids, so any manipulation made on images like these will not affect the data fetched from EE.

mahrsee1997 avatar Feb 27 '24 08:02 mahrsee1997

Actually, we have a bug/issue in the codebase: https://github.com/google/Xee/blob/main/xee/ext.py#L789C1-L797C80.

We consider 'asset_ids' at the time of processing, if we can obtain them. And we implemented this to avoid an expensive toList() operation. But it seems like it will cause issue like in your case.

mahrsee1997 avatar Feb 29 '24 10:02 mahrsee1997

This discussion on the Pangeo discourse seems really relevant.

https://discourse.pangeo.io/t/example-which-highlights-the-limitations-of-netcdf-style-coordinates-for-large-geospatial-rasters/4140

@schwehr @simon Any thoughts on how this might be related? Could the discrepancy eventually cause an issue?

alxmrs avatar Jun 15 '24 19:06 alxmrs

I think this PR in Xarray may provide a long term fix for this issue.

https://github.com/pydata/xarray/pull/9543

alxmrs avatar Oct 12 '24 14:10 alxmrs

#156 may have fixed this – needs verification.

jdbcode avatar Nov 14 '24 17:11 jdbcode

This colab script shows that Xee now produces different results for different resampling methods ('bilinear' and 'bicubic'). https://colab.research.google.com/gist/tylere/3d0548e28d8458b71142007157f8c539/template-xee-issue.ipynb Given this, I'm closing this issue.

tylere avatar Dec 11 '24 20:12 tylere