Skip to content

Commit

Permalink
Test case added.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabhicusp committed Mar 21, 2024
1 parent 53878ab commit f1be4a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 4 additions & 4 deletions xee/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,14 @@ def project(self, bbox: types.BBox) -> types.Grid:
appropriate region of data to return according to the Array's configured
projection and scale.
"""
# The origin of the image is in the top left corner. X and Y is the minimum value.
x_origin, y_origin, x_origin1, y_origin1 = self.bounds # x_min, y_min, x_max, y_max
# The origin of the image is in the top left corner.
x_min, y_min, x_max, y_max = self.bounds
x_start, y_start, x_end, y_end = bbox
width = x_end - x_start
height = y_end - y_start

translateX = x_origin if self.scale_x > 0 else x_origin1
translateY = y_origin if self.scale_y > 0 else y_origin1
translateX = x_min if self.scale_x > 0 else x_max
translateY = y_min if self.scale_y > 0 else y_max
return {
# The size of the bounding box. The affine transform and project will be
# applied, so we can think in terms of pixels.
Expand Down
24 changes: 21 additions & 3 deletions xee/ext_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,29 @@ def test_guess_can_open__image_collection(self):
# Should not be able to open a feature collection.
self.assertFalse(self.entry.guess_can_open('WRI/GPPD/power_plants'))

def test_open_dataset__sanity_check(self):
def test_open_dataset__sanity_check_with_positive_scale(self):
ds = self.entry.open_dataset(
pathlib.Path('LANDSAT') / 'LC08' / 'C01' / 'T1',
drop_variables=tuple(f'B{i}' for i in range(3, 12)),
projection = ee.Projection('EPSG:4326', [25, 0, 0, 0, -25, 0]),
scale=25.0, # in degrees
n_images=3,
)
self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 14, 'lat': 7})
self.assertNotEmpty(dict(ds.coords))
self.assertEqual(
list(ds.data_vars.keys()),
[f'B{i}' for i in range(1, 3)] + ['BQA'],
)
for v in ds.values():
self.assertIsNotNone(v.data)
self.assertTrue(v.isnull().all(), 'All values must be null!')
self.assertEqual(v.shape, (3, 14, 7))

def test_open_dataset__sanity_check_with_negative_scale(self):
ds = self.entry.open_dataset(
pathlib.Path('LANDSAT') / 'LC08' / 'C01' / 'T1',
drop_variables=tuple(f'B{i}' for i in range(3, 12)),
scale=-25.0, # in degrees
n_images=3,
)
self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 14, 'lat': 7})
Expand All @@ -323,7 +341,7 @@ def test_open_dataset__sanity_check(self):
)
for v in ds.values():
self.assertIsNotNone(v.data)
self.assertFalse(v.isnull().all(), 'All values are null!')
self.assertTrue(v.isnull().all(), 'All values must be null!')
self.assertEqual(v.shape, (3, 14, 7))

def test_open_dataset__n_images(self):
Expand Down

0 comments on commit f1be4a4

Please sign in to comment.