google / Xee

An Xarray extension for Google Earth Engine
Apache License 2.0
240 stars 28 forks source link

Support added for the int datatype earth engine image. #149

Closed dabhicusp closed 5 months ago

dabhicusp commented 6 months ago

The existing code of the Xee is incapable of processing the Earth Engine images which have data of integer datatype. As illustrated in the example below, instead of yielding a "NaN" value, it produces a value that is one less than the ee_mask_value. For instance, if the ee_mask_value is set to -99990, the code will return -99989.

Ex.: Before :

image = ee.Image('USGS/GMTED2010').select('be75')
proj_4326 = ee.Projection('EPSG:4326', [1, 0, 0, 0, -1, 0]).atScale(10000)
image = image.reproject(proj_4326)
geom = ee.Geometry.Rectangle( [[-179.99, -80], [179.99, 80]], None, geodesic=False,)
ic = ee.ImageCollection([image])
ds = xarray.open_dataset(ic, projection=image.projection(), geometry=geom,
     ee_mask_value=-99999, engine='ee'
)
ds.be75.values

Result:

array([[[     0.,      0.,      0., ..., -99998., -99998., -99998.],
        [     0.,      0.,      0., ..., -99998., -99998., -99998.],
        [     0.,      0.,      0., ..., -99998., -99998., -99998.],
        ...,
        [     0.,      0.,      0., ..., -99998., -99998., -99998.],
        [     0.,      0.,      0., ..., -99998., -99998., -99998.],
        [     0.,      0.,      0., ..., -99998., -99998., -99998.]]])

After updating the code :

ic = ee.ImageCollection([image])
ds = ee_local_class.open_dataset(ic, projection=image.projection(), geometry=geom,
     ee_mask_value=-99999,
)
ds.be75.values

Result:

array([[[ 0.,  0.,  0., ..., nan, nan, nan],
        [ 0.,  0.,  0., ..., nan, nan, nan],
        [ 0.,  0.,  0., ..., nan, nan, nan],
        ...,
        [ 0.,  0.,  0., ..., nan, nan, nan],
        [ 0.,  0.,  0., ..., nan, nan, nan],
        [ 0.,  0.,  0., ..., nan, nan, nan]]])