Skip to content

Commit

Permalink
Fix: Now using default ranges.
Browse files Browse the repository at this point in the history
Fixes #71. I've turned off range adjustments as well as the constants in the integration tests.

PiperOrigin-RevId: 572627965
  • Loading branch information
Xee authors committed Oct 11, 2023
1 parent 8e7cd85 commit 9c55df6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
25 changes: 3 additions & 22 deletions xee/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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().
Expand Down
14 changes: 7 additions & 7 deletions xee/ext_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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`.
Expand Down

0 comments on commit 9c55df6

Please sign in to comment.