Skip to content

[Bug]: Getting incorrect number of pixels and their X/Y coordinates or incorrect data when working in non-EPSG:4326 coordinates #226

@shahriar49

Description

@shahriar49

Bug Summary

I want to get an area from a Landsat Collection under Google Earth Engine. I set the coordinates of bounding box of 333x333 pixels (the exact numbers that match the UTM pixel bounds) one time in the UTM Zone 13 values and another time in corresponding lat/lon values and call the xr.open_dataset() function with projection set to ee.Projection(crs='EPSG:32613', transform=[30, 0, 699960, 0, -30, 4300020]). In both cases it throws an error

Traceback (most recent call last):
  File "C:\Python3.9.13\lib\contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xarray\core\utils.py", line 628, in close_on_error
    yield
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xee\ext.py", line 1153, in open_dataset
    ds = store_entrypoint.open_dataset(
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xarray\backends\store.py", line 43, in open_dataset
    vars, attrs = filename_or_obj.load()
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xarray\backends\common.py", line 221, in load
    (_decode_variable_name(k), v) for k, v in self.get_variables().items()
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xee\ext.py", line 676, in get_variables
    vars_ = [(name, self.open_store_variable(name)) for name in self._bands()]
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xee\ext.py", line 676, in <listcomp>
    vars_ = [(name, self.open_store_variable(name)) for name in self._bands()]
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xee\ext.py", line 566, in open_store_variable
    arr = EarthEngineBackendArray(name, self)
  File "C:\Users\sheydari\Python39-2\lib\site-packages\xee\ext.py", line 791, in __init__
    x_size = max(1, int(np.round((x_max - x_min) / np.abs(self.store.scale_x))))
ValueError: cannot convert float NaN to integer

If I set the projection argument to the projection object that I get from the Landsat image itself, it works but returns a dataset with incorrect number of rows and columns (several more rows and one less column) and incorrect pixel center locations (they are all off by several meters in both directions).

If I give the xr.open_dataset() function the crs and scale separately (not through the projection argument) it works in setting the dataset dimension and coordination values correctly. However, it returns the dimension names as lat and lon and crs as EPSG:4326 in xarray dataset, which is incorrect, and the dataset variables (Landsat band values) are all null.

P.S. It also works only with 'EPSG:32613' setting for crs, not with the wkt string I get from GEE's Landsat projection.

I appreciate if you look at this issue promptly.

Steps to Reproduce

You can use this code to see the behavior.

point = ee.Geometry.Point([-102.05, 38.05])
image = ee.ImageCollection("NASA/HLS/HLSL30/v002").filterDate("2018-08-01", "2018-09-01").filterBounds(point).select(['B4']).first()
projection = image.projection()
crs = 'EPSG:32613'
crsTransform = projection.getInfo()['transform']
scale = projection.nominalScale().getInfo()
BBox1 = ee.Geometry.Polygon([[[750000, 4210020],[759990, 4210020],[759990, 4220010],[750000, 4220010]]], crs, evenOdd=False)
BBox2 = ee.Geometry.Polygon([[[-102.15268713055727, 38.0034113624073], [-102.03904576692914, 38.0006026911579],
    [-102.0354189991692, 38.09052020120823],[-102.14919908937703, 38.09333791178974]]], 'EPSG:4326', evenOdd=False)
ds = xr.open_dataset(
    ee.ImageCollection([image]),
    engine='ee',
    geometry=BBox1,
    # projection=ee.Projection(crs=crs,transform=crsTransform)
    projection=projection,
    # projection=crs,
    # scale=scale
)
print(ds)

Current Behavior

Explained above.

Expected Behavior

Get the correct dimension, coordination names, and dataset values.

Relevant log output

Xee Version

0.0.19

Contact Details

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageA new issue that needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions