Pixel displacement of image resulting from open_dataset()
Hello,
I am trying to utilize open_dataset() for Sentinel-2 imagery that has been preprocessed and is available as asset on EE.
After some index calculation on the fly, I tried to open it as usual, following the README page, aiming to open the dataset using the same projection as the imagery hosted on EE. So far these have been tried:
- Not reprojecting the image and passing its projection as a parameter to open_dataset()
mosaic = mosaic.toByte()
exporting_projection = mosaic.projection().atScale(10)
ds_1 = xarray.open_dataset(
ee.ImageCollection([mosaic]),
projection=exporting_projection,
geometry=buffer_geometry,
chunks={'time':1,'lon': 512, 'lat': 512},
engine='ee').isel(time=0)
- Clipping the mosaic and reprojecting it before passing it to open_dataset()
original_projection = ee_collection.mosaic().clip(buffer_geometry).projection().atScale(10)
mosaic = mosaic.clip(buffer_geometry).toByte().reproject(original_projection)
exporting_projection = mosaic.projection().atScale(10)
ds_1 = xarray.open_dataset(
ee.ImageCollection([mosaic]),
projection=exporting_projection,
geometry=buffer_geometry,
chunks={'time':1,'lon': 512, 'lat': 512},
engine='ee').isel(time=0)
- Not clipping the mosaic but reprojecting it before passing it to open_dataset()
original_projection = ee_collection.mosaic().clip(buffer_geometry).projection().atScale(10)
mosaic = mosaic.toByte().reproject(original_projection)
exporting_projection = mosaic.projection().atScale(10)
ds_1 = xarray.open_dataset(
ee.ImageCollection([mosaic]),
projection=exporting_projection,
geometry=buffer_geometry,
chunks={'time':1,'lon': 512, 'lat': 512},
engine='ee').isel(time=0)
- Not clipping and reprojecting the mosaic, but setting crs and scale on open_dataset()
mosaic = mosaic.toByte()
ds_1 = xarray.open_dataset(
ee.ImageCollection([mosaic]),
crs='EPSG:4326',
scale=10,
geometry=buffer_geometry,
chunks={'time':1,'lon': 512, 'lat': 512},
engine='ee').isel(time=0)
Version 0.0.15 of Xee is being used.
The error can be seen on the earth engine visualization bellow:
Original imagery
XEE open_dataset()
XEE over original imagery
Note that other data has been loaded successfully using XEE (different parameters, different datasets etc.), so it's not an issue related to installation or dependencies.
"Sentinel-2 imagery that has been preprocessed and is available as asset on EE."
Is the image or image collection asset used publicly available? This would be helpful for trying to replicate the issue you describe.
Also, it is not clear how the "Original imagery" output was created. Did you use ee.data.computePixels? If so, what parameters were used?
Closing this issue. Please reopen if you have any additional information or you're hitting this again.
Is the image or image collection asset used publicly available? This would be helpful for trying to replicate the issue you describe.
I am sorry for the delay. At the moment, the dataset is closed and is for internal use only, but was created according to the Earth Engine guide and templates.
Also, it is not clear how the "Original imagery" output was created. Did you use
ee.data.computePixels? If so, what parameters were used?
No, just a simple view of ee.Image(). Using the same parameters for both views, from the ee.Image() hosted as active in Earth Engine and the result from the XEE open_dataset(), which was loaded following standard practice
Thanks for the clarification. Without a full reproducible example, I don't see a path forward for debugging this issue.
Thanks for the clarification. Without a full reproducible example, I don't see a path forward for debugging this issue.
I may be able to send you a full example privately, in form of a Colab notebook.
Instead of a private notebook, can you demonstrate the issue with a public notebook and a public dataset? For example:
mosaic = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED").filter('2020-01-01', '2021-02-01').mosaic()
Here is a template notebook that I have been using to make it easier to reproduce issues: https://colab.research.google.com/drive/1vAgfAPhKGJd4G9ZUOzciqZ7MbqJjlMLR
Instead of a private notebook, can you demonstrate the issue with a public notebook and a public dataset? For example:
mosaic = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED").filter('2020-01-01', '2021-02-01').mosaic()Here is a template notebook that I have been using to make it easier to reproduce issues: https://colab.research.google.com/drive/1vAgfAPhKGJd4G9ZUOzciqZ7MbqJjlMLR
I’ve adapted my use case, which you can find here: Colab.
Additionally, here’s the GEE code, that shows the pixel shift between the on-the-fly image and the raster result from Colab.
I hope this helps with debugging.
I'm going to reopen the issue, given that you can still reproduce it.
I tried to understand the issue using the Colab notebook you shared, but it seems to include a lot of code that is not relevant to the issue described. For example, does the issue occur if you remove the use of Dask, GDAL, and the subprocess libraries?
Would you be willing to simplify your notebook to be a Minimal Reproducible Example (MRE)?
Also, I am proposing some changes to how open_dataset() is called that may help address this issue.
Discussions here: #217