From 9c55df6976b2d756f30069a8be9a7f904baa1257 Mon Sep 17 00:00:00 2001 From: Xee authors Date: Wed, 11 Oct 2023 11:07:50 -0700 Subject: [PATCH] Fix: Now using default ranges. Fixes #71. I've turned off range adjustments as well as the constants in the integration tests. PiperOrigin-RevId: 572627965 --- xee/ext.py | 25 +++---------------------- xee/ext_integration_test.py | 14 +++++++------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index ab22e5b..f96c365 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -231,14 +231,9 @@ def __init__( x_min_0, y_min_0, x_max_0, y_max_0 = _ee_bounds_to_bounds( self.get_info['bounds'] ) - # We add and subtract the scale to solve an off-by-one error. With this - # adjustment, we achieve parity with a pure `computePixels()` call. - x_min, y_min = self.transform(x_min_0 - self.scale_x, y_min_0) - if _bounds_are_invalid(x_min, y_min, self.scale_units == 'degree'): - x_min, y_min = self.transform(x_min_0, y_min_0) - x_max, y_max = self.transform(x_max_0, y_max_0 + self.scale_y) - if _bounds_are_invalid(x_max, y_max, self.scale_units == 'degree'): - x_max, y_max = self.transform(x_max_0, y_max_0) + # TODO(#40): Investigate data discrepancy (off-by-one) issue. + x_min, y_min = self.transform(x_min_0, y_min_0) + x_max, y_max = self.transform(x_max_0, y_max_0) self.bounds = x_min, y_min, x_max, y_max max_dtype = self._max_itemsize() @@ -579,20 +574,6 @@ def close(self) -> None: del self.image_collection -def _bounds_are_invalid(x: float, y: float, is_degrees=False) -> bool: - """Check for obviously bad x and y projection values.""" - bad_num = math.isnan(x) or math.isnan(y) or math.isinf(x) or math.isinf(y) - - invalid_degree = ( - y < -90.0 - or y > 90.0 - or x < -180.0 - or x > 360.0 # degrees could be from 0 to 360... - ) - - return bad_num or (is_degrees and invalid_degree) - - def _parse_dtype(data_type: types.DataType): """Parse a np.dtype from the 'data_type' section of ee.Image.getInfo(). diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 40a5b03..b44f0d5 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -58,14 +58,14 @@ def setUp(self): def test_creates_lat_long_array(self): arr = xee.EarthEngineBackendArray('longitude', self.lnglat_store) - self.assertEqual((1, 360, 179), arr.shape) + self.assertEqual((1, 360, 180), arr.shape) def test_can_create_object(self): arr = xee.EarthEngineBackendArray('B4', self.store) self.assertIsNotNone(arr) - self.assertEqual((64, 360, 179), arr.shape) + self.assertEqual((64, 360, 180), arr.shape) self.assertEqual(np.int32, arr.dtype) self.assertEqual('B4', arr.variable_name) @@ -261,7 +261,7 @@ def test_open_dataset__sanity_check(self): n_images=3, ) self.assertEqual( - dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 7} + dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 8} ) self.assertNotEmpty(dict(ds.coords)) self.assertEqual( @@ -271,7 +271,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.assertEqual(v.shape, (3, 15, 7)) + self.assertEqual(v.shape, (3, 15, 8)) def test_open_dataset__n_images(self): ds = self.entry.open_dataset( @@ -311,7 +311,7 @@ def test_honors_geometry(self): engine=xee.EarthEngineBackendEntrypoint, ) - self.assertEqual(ds.dims, {'time': 4248, 'lon': 42, 'lat': 34}) + self.assertEqual(ds.dims, {'time': 4248, 'lon': 41, 'lat': 35}) self.assertNotEqual(ds.dims, standard_ds.dims) def test_honors_projection(self): @@ -328,7 +328,7 @@ def test_honors_projection(self): engine=xee.EarthEngineBackendEntrypoint, ) - self.assertEqual(ds.dims, {'time': 4248, 'lon': 3600, 'lat': 1799}) + self.assertEqual(ds.dims, {'time': 4248, 'lon': 3600, 'lat': 1800}) self.assertNotEqual(ds.dims, standard_ds.dims) def test_parses_ee_url(self): @@ -345,7 +345,7 @@ def test_parses_ee_url(self): scale=25.0, # in degrees n_images=3, ) - self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 7}) + self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 8}) def test_data_sanity_check(self): # This simple test uncovered a bug with the default definition of `scale`.