Skip to content

Commit

Permalink
Merge pull request #144 from google:geometry_bounds
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 619939651
  • Loading branch information
Xee authors committed Mar 28, 2024
2 parents 5fe4395 + 7beabcf commit 31bfded
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
27 changes: 18 additions & 9 deletions xee/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,16 @@ def get_info(self) -> Dict[str, Any]:
rpcs.append(('projection', self.projection))

if isinstance(self.geometry, ee.Geometry):
rpcs.append(('bounds', self.geometry.bounds()))
rpcs.append(('bounds', self.geometry.bounds(1, proj=self.projection)))
else:
rpcs.append(('bounds', self.image_collection.first().geometry().bounds()))
rpcs.append(
(
'bounds',
self.image_collection.first()
.geometry()
.bounds(1, proj=self.projection),
)
)

# TODO(#29, #30): This RPC call takes the longest time to compute. This
# requires a full scan of the images in the collection, which happens on the
Expand All @@ -293,14 +300,16 @@ def get_info(self) -> Dict[str, Any]:
# client-side. Ideally, this would live behind a xarray-backend-specific
# feature flag, since it's not guaranteed that data is this consistent.
columns = ['system:id', self.primary_dim_property]
rpcs.append((
'properties',
rpcs.append(
(
self.image_collection.reduceColumns(
ee.Reducer.toList().repeat(len(columns)), columns
).get('list')
),
))
'properties',
(
self.image_collection.reduceColumns(
ee.Reducer.toList().repeat(len(columns)), columns
).get('list')
),
)
)

info = ee.List([rpc for _, rpc in rpcs]).getInfo()

Expand Down
26 changes: 26 additions & 0 deletions xee/ext_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,32 @@ def __getitem__(self, params):

self.assertEqual(getter.count, 3)

def test_geometry_bounds_with_and_without_projection(self):
image = (
ee.ImageCollection('LANDSAT/LC08/C01/T1')
.filterDate('2017-01-01', '2017-01-03')
.first()
)
point = ee.Geometry.Point(-40.2414893624401, 105.48790177216375)
distance = 311.5
scale = 5000
projection = ee.Projection('EPSG:4326', [1, 0, 0, 0, -1, 0]).atScale(scale)
image = image.reproject(projection)

geometry = point.buffer(distance, proj=projection).bounds(proj=projection)

data_store = xee.EarthEngineStore(
ee.ImageCollection(image),
projection=image.projection(),
geometry=geometry,
)
data_store_bounds = data_store.get_info['bounds']

self.assertNotEqual(geometry.bounds().getInfo(), data_store_bounds)
self.assertEqual(
geometry.bounds(1, proj=projection).getInfo(), data_store_bounds
)

def test_getitem_kwargs(self):
arr = xee.EarthEngineBackendArray('B4', self.store)
self.assertEqual(arr.store.getitem_kwargs['initial_delay'], 1500)
Expand Down

0 comments on commit 31bfded

Please sign in to comment.