From f10732200718f8b686c1ddcef4dddec848b3ad42 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Wed, 20 Mar 2024 08:17:01 +0000 Subject: [PATCH 01/17] Origin transfer for the negative scale is added. --- xee/ext.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 9a59fe7..e043b08 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -240,7 +240,7 @@ def __init__( default_scale = self.SCALE_UNITS.get(self.scale_units, 1) if scale is None: scale = default_scale - default_transform = affine.Affine.scale(scale, -1 * scale) + default_transform = affine.Affine.scale(scale, 1 * scale) transform = affine.Affine(*proj.get('transform', default_transform)[:6]) self.scale_x, self.scale_y = transform.a, transform.e @@ -430,12 +430,21 @@ 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 is the minimum value - # and Y is the maximum value. - x_origin, _, _, y_origin = self.bounds # x_min, x_max, y_min, y_max + # The origin of the image is in the top left corner. X and Y is the minimum value. + x_origin, y_origin, _, _ = self.bounds # x_min, y_min, x_max, y_max x_start, y_start, x_end, y_end = bbox width = x_end - x_start height = y_end - y_start + translateX = ( + x_origin + self.scale_x * x_start + if self.scale_x > 0 + else x_origin + abs(self.scale_x) * x_end + ) + translateY = ( + y_origin + self.scale_y * y_start + if self.scale_y > 0 + else y_origin + abs(self.scale_y) * y_end + ) return { # The size of the bounding box. The affine transform and project will be @@ -448,8 +457,8 @@ def project(self, bbox: types.BBox) -> types.Grid: # Since the origin is in the top left corner, we want to translate # the start of the grid to the positive direction for X and the # negative direction for Y. - 'translateX': x_origin + self.scale_x * x_start, - 'translateY': y_origin + self.scale_y * y_start, + 'translateX': translateX, + 'translateY': translateY, # Define the scale for each pixel (e.g. the number of meters between # each value). 'scaleX': self.scale_x, From a8534aa3fc20d6b95106039a00b62948cdf441e1 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Thu, 21 Mar 2024 06:45:06 +0000 Subject: [PATCH 02/17] Take bound after considering above point as origin. --- xee/ext.py | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index e043b08..3c234c5 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -431,21 +431,49 @@ def project(self, bbox: types.BBox) -> types.Grid: 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, _, _ = self.bounds # x_min, y_min, x_max, y_max + print("Self.scale_x, : ", self.scale_x, self.scale_y) + print("self.bounds : ", self.bounds) + print("bbox is this : ", bbox) + x_origin, y_origin, x_origin1, y_origin1 = self.bounds # x_min, y_min, x_max, y_max x_start, y_start, x_end, y_end = bbox width = x_end - x_start height = y_end - y_start + # points consider after taking the origin from the both side. + # translateX = ( + # x_origin + self.scale_x * x_start + # if self.scale_x > 0 + # else x_origin + abs(self.scale_x) * x_end + # ) + # translateY = ( + # y_origin + self.scale_y * y_start + # if self.scale_y > 0 + # else y_origin1 + self.scale_y * y_end + # ) + + # # Points consider after taking below points as a origin + # translateX = ( + # x_origin + self.scale_x * x_start + # if self.scale_x > 0 + # else x_origin + abs(self.scale_x) * x_end + # ) + # translateY = ( + # y_origin + self.scale_y * y_start + # if self.scale_y > 0 + # else y_origin + abs(self.scale_y) * y_end + # ) + + # Points consider after taking above points as a origin translateX = ( - x_origin + self.scale_x * x_start + x_origin1 - self.scale_x * x_end if self.scale_x > 0 - else x_origin + abs(self.scale_x) * x_end + else x_origin1 + abs(self.scale_x) * x_start ) translateY = ( - y_origin + self.scale_y * y_start + y_origin1 - self.scale_y * y_end if self.scale_y > 0 - else y_origin + abs(self.scale_y) * y_end + else y_origin1 + abs(self.scale_y) * y_start ) - + print("translateY is this : ",translateX, translateY) return { # The size of the bounding box. The affine transform and project will be # applied, so we can think in terms of pixels. From 53878abc8384135247c444a99ce8aa3d7ebd28cc Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Thu, 21 Mar 2024 10:06:11 +0000 Subject: [PATCH 03/17] Logic updated. --- xee/ext.py | 42 +++---------------------------------- xee/ext_integration_test.py | 2 +- 2 files changed, 4 insertions(+), 40 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 3c234c5..041f6aa 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -431,49 +431,13 @@ def project(self, bbox: types.BBox) -> types.Grid: projection and scale. """ # The origin of the image is in the top left corner. X and Y is the minimum value. - print("Self.scale_x, : ", self.scale_x, self.scale_y) - print("self.bounds : ", self.bounds) - print("bbox is this : ", bbox) x_origin, y_origin, x_origin1, y_origin1 = self.bounds # x_min, y_min, x_max, y_max x_start, y_start, x_end, y_end = bbox width = x_end - x_start height = y_end - y_start - # points consider after taking the origin from the both side. - # translateX = ( - # x_origin + self.scale_x * x_start - # if self.scale_x > 0 - # else x_origin + abs(self.scale_x) * x_end - # ) - # translateY = ( - # y_origin + self.scale_y * y_start - # if self.scale_y > 0 - # else y_origin1 + self.scale_y * y_end - # ) - - # # Points consider after taking below points as a origin - # translateX = ( - # x_origin + self.scale_x * x_start - # if self.scale_x > 0 - # else x_origin + abs(self.scale_x) * x_end - # ) - # translateY = ( - # y_origin + self.scale_y * y_start - # if self.scale_y > 0 - # else y_origin + abs(self.scale_y) * y_end - # ) - - # Points consider after taking above points as a origin - translateX = ( - x_origin1 - self.scale_x * x_end - if self.scale_x > 0 - else x_origin1 + abs(self.scale_x) * x_start - ) - translateY = ( - y_origin1 - self.scale_y * y_end - if self.scale_y > 0 - else y_origin1 + abs(self.scale_y) * y_start - ) - print("translateY is this : ",translateX, translateY) + + translateX = x_origin if self.scale_x > 0 else x_origin1 + translateY = y_origin if self.scale_y > 0 else y_origin1 return { # The size of the bounding box. The affine transform and project will be # applied, so we can think in terms of pixels. diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 880c3e6..2190af1 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -312,7 +312,7 @@ def test_open_dataset__sanity_check(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 + projection = ee.Projection('EPSG:4326', [25, 0, 0, 0, -25, 0]), n_images=3, ) self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 14, 'lat': 7}) From f1be4a4a05aec9161709c6a93603086895f051b9 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Thu, 21 Mar 2024 13:56:09 +0000 Subject: [PATCH 04/17] Test case added. --- xee/ext.py | 8 ++++---- xee/ext_integration_test.py | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 041f6aa..1e3b528 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -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. diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 2190af1..bee2a9b 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -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}) @@ -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): From 54021209934e8a00a5c407e5bb53ab304758f184 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 22 Mar 2024 05:25:53 +0000 Subject: [PATCH 05/17] Test case updated. --- xee/ext_integration_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index bee2a9b..8c13f32 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -472,6 +472,7 @@ def test_write_projected_dataset_to_raster(self): scale=10, crs=crs, geometry=geom, + projection= ee.Projection(crs, [10, 0, 0, 0, -10, 0]) ) ds = ds.isel(time=0).transpose('Y', 'X') @@ -506,8 +507,8 @@ def test_write_dataset_to_raster(self): ds = xr.open_dataset( col, engine=xee.EarthEngineBackendEntrypoint, - scale=0.0025, geometry=geom, + projection= ee.Projection('EPSG:4326', [0.0025, 0, 0, 0, -0.0025, 0]) ) ds = ds.isel(time=0).transpose('lat', 'lon') From 0524760b761c3c608add33d639287478f1902544 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 22 Mar 2024 05:27:18 +0000 Subject: [PATCH 06/17] lint error fixed. --- xee/ext_integration_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 8c13f32..3535cd0 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -472,7 +472,7 @@ def test_write_projected_dataset_to_raster(self): scale=10, crs=crs, geometry=geom, - projection= ee.Projection(crs, [10, 0, 0, 0, -10, 0]) + projection=ee.Projection(crs, [10, 0, 0, 0, -10, 0]), ) ds = ds.isel(time=0).transpose('Y', 'X') @@ -508,7 +508,7 @@ def test_write_dataset_to_raster(self): col, engine=xee.EarthEngineBackendEntrypoint, geometry=geom, - projection= ee.Projection('EPSG:4326', [0.0025, 0, 0, 0, -0.0025, 0]) + projection=ee.Projection('EPSG:4326', [0.0025, 0, 0, 0, -0.0025, 0]), ) ds = ds.isel(time=0).transpose('lat', 'lon') From 7892aa1f83e6731c11e03337b674461a2a16d2a0 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 22 Mar 2024 05:37:43 +0000 Subject: [PATCH 07/17] lint error fixed. --- xee/ext_integration_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 3535cd0..ca36383 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -469,7 +469,6 @@ def test_write_projected_dataset_to_raster(self): ds = xr.open_dataset( col, engine=xee.EarthEngineBackendEntrypoint, - scale=10, crs=crs, geometry=geom, projection=ee.Projection(crs, [10, 0, 0, 0, -10, 0]), From 3eb809183009a948cc2283d025313d32b8993b97 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 22 Mar 2024 05:48:28 +0000 Subject: [PATCH 08/17] lint error fixed due to the pyink version upgrade. --- xee/ext.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 1e3b528..be2683e 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -312,14 +312,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() From 4d287b3c6898996b685e9498f68486c7d9369d9e Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 29 Mar 2024 06:54:51 +0000 Subject: [PATCH 09/17] Logic updated of the calculating of translateX & Y --- xee/ext.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index be2683e..7e72026 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -240,7 +240,7 @@ def __init__( default_scale = self.SCALE_UNITS.get(self.scale_units, 1) if scale is None: scale = default_scale - default_transform = affine.Affine.scale(scale, 1 * scale) + default_transform = affine.Affine.scale(scale, scale) transform = affine.Affine(*proj.get('transform', default_transform)[:6]) self.scale_x, self.scale_y = transform.a, transform.e @@ -433,13 +433,22 @@ def project(self, bbox: types.BBox) -> types.Grid: projection and scale. """ # The origin of the image is in the top left corner. - x_min, y_min, x_max, y_max = self.bounds + x_min, y_min, _, _ = self.bounds x_start, y_start, x_end, y_end = bbox width = x_end - x_start height = y_end - y_start - translateX = x_min if self.scale_x > 0 else x_max - translateY = y_min if self.scale_y > 0 else y_max + # Found the actual coordinates of the first or last point of the bbox based on the pos & neg scale in the actual image. + translateX = ( + x_min + x_start * self.scale_x + if self.scale_x > 0 + else x_min + (-1 * self.scale_x * x_end) + ) + translateY = ( + y_min + y_start * self.scale_y + if self.scale_y > 0 + else y_min + (-1 * self.scale_y * y_end) + ) return { # The size of the bounding box. The affine transform and project will be # applied, so we can think in terms of pixels. @@ -448,9 +457,6 @@ def project(self, bbox: types.BBox) -> types.Grid: 'height': height, }, 'affineTransform': { - # Since the origin is in the top left corner, we want to translate - # the start of the grid to the positive direction for X and the - # negative direction for Y. 'translateX': translateX, 'translateY': translateY, # Define the scale for each pixel (e.g. the number of meters between From c26577bab697648fe7eac997488e3c3d9743b639 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 29 Mar 2024 09:27:27 +0000 Subject: [PATCH 10/17] Testcase updated. --- xee/ext_integration_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 54aadb2..d973196 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -536,7 +536,7 @@ def test_write_projected_dataset_to_raster(self): engine=xee.EarthEngineBackendEntrypoint, crs=crs, geometry=geom, - projection=ee.Projection(crs, [10, 0, 0, 0, -10, 0]), + projection=ee.Projection('EPSG:4326', [10, 0, 0, 0, -10, 0]), ) ds = ds.isel(time=0).transpose('Y', 'X') From 1381b964eba4849f4ae1622a812fd1e3aa47c4cc Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Mon, 1 Apr 2024 06:17:51 +0000 Subject: [PATCH 11/17] Test case of negative projection is added. --- xee/ext_integration_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index d973196..3b39d3e 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -334,6 +334,24 @@ 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_with_negative_projection(self): + ds = self.entry.open_dataset( + pathlib.Path('LANDSAT') / 'LC08' / 'C01' / 'T1', + drop_variables=tuple(f'B{i}' for i in range(3, 12)), + n_images=3, + projection=ee.Projection('EPSG:4326', [25, 0, 0, 0, -25, 0]), + ) + 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 are null!') + self.assertEqual(v.shape, (3, 14, 7)) + def test_open_dataset__sanity_check_with_positive_scale(self): ds = self.entry.open_dataset( pathlib.Path('LANDSAT') / 'LC08' / 'C01' / 'T1', From aa16834280062faf99b0461b5e3bb288757aab09 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Mon, 1 Apr 2024 08:25:02 +0000 Subject: [PATCH 12/17] Logic is updated. --- xee/ext.py | 6 +++--- xee/ext_integration_test.py | 22 ++-------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index e24be30..c0b32a4 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -421,7 +421,7 @@ def project(self, bbox: types.BBox) -> types.Grid: projection and scale. """ # The origin of the image is in the top left corner. - x_min, y_min, _, _ = self.bounds + 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 @@ -430,12 +430,12 @@ def project(self, bbox: types.BBox) -> types.Grid: translateX = ( x_min + x_start * self.scale_x if self.scale_x > 0 - else x_min + (-1 * self.scale_x * x_end) + else x_max + self.scale_x * x_start ) translateY = ( y_min + y_start * self.scale_y if self.scale_y > 0 - else y_min + (-1 * self.scale_y * y_end) + else y_max + self.scale_y * y_start ) return { # The size of the bounding box. The affine transform and project will be diff --git a/xee/ext_integration_test.py b/xee/ext_integration_test.py index 3b39d3e..e2d7466 100644 --- a/xee/ext_integration_test.py +++ b/xee/ext_integration_test.py @@ -334,7 +334,7 @@ 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_with_negative_projection(self): + def test_open_dataset__sanity_check(self): ds = self.entry.open_dataset( pathlib.Path('LANDSAT') / 'LC08' / 'C01' / 'T1', drop_variables=tuple(f'B{i}' for i in range(3, 12)), @@ -349,25 +349,7 @@ def test_open_dataset__sanity_check_with_negative_projection(self): ) for v in ds.values(): self.assertIsNotNone(v.data) - self.assertTrue(v.isnull().all(), 'All values are null!') - self.assertEqual(v.shape, (3, 14, 7)) - - 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)), - 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.assertFalse(v.isnull().all(), 'All values are null!') self.assertEqual(v.shape, (3, 14, 7)) def test_open_dataset__sanity_check_with_negative_scale(self): From c8c6461d27d82ef08b50e62d3440855241cf0818 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Tue, 2 Apr 2024 17:07:08 +0000 Subject: [PATCH 13/17] comments updated. --- xee/ext.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index c0b32a4..d27f80f 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -420,23 +420,20 @@ 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_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 - # Found the actual coordinates of the first or last point of the bbox based on the pos & neg scale in the actual image. - translateX = ( - x_min + x_start * self.scale_x - if self.scale_x > 0 - else x_max + self.scale_x * x_start - ) - translateY = ( - y_min + y_start * self.scale_y - if self.scale_y > 0 - else y_max + self.scale_y * y_start - ) + # Find the actual coordinates of the first or last point of the bounding box (bbox) + # based on the positive and negative scale in the actual Earth Engine (EE) image. + # Since EE bounding boxes can be flipped (negative scale), we cannot determine + # the origin (transform translation) simply by identifying the min and max extents. + # Instead, we calculate the translation by considering the direction of scaling + # (positive or negative) along both the x and y axes. + translateX = self.scale_x * x_start + (x_min if self.scale_x > 0 else x_max) + translateY = self.scale_y * y_start + (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. From b9738be488c2287597572ab8367ece3ac7403a42 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Tue, 2 Apr 2024 17:25:59 +0000 Subject: [PATCH 14/17] line size fixed to 80. --- xee/ext.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index d27f80f..4c13ea6 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -425,12 +425,13 @@ def project(self, bbox: types.BBox) -> types.Grid: width = x_end - x_start height = y_end - y_start - # Find the actual coordinates of the first or last point of the bounding box (bbox) - # based on the positive and negative scale in the actual Earth Engine (EE) image. - # Since EE bounding boxes can be flipped (negative scale), we cannot determine - # the origin (transform translation) simply by identifying the min and max extents. - # Instead, we calculate the translation by considering the direction of scaling - # (positive or negative) along both the x and y axes. + # Find the actual coordinates of the first or last point of the bounding box + # (bbox) based on the positive and negative scale in the actual Earth Engine + # (EE) image. Since EE bounding boxes can be flipped (negative scale), we + # cannot determine the origin (transform translation) simply by identifying + # the min and max extents. Instead, we calculate the translation by + # considering the direction of scaling (positive or negative) along both + # the x and y axes. translateX = self.scale_x * x_start + (x_min if self.scale_x > 0 else x_max) translateY = self.scale_y * y_start + (y_min if self.scale_y > 0 else y_max) From d3d18177cb1deb7f0c7c8e5e8bc259a75282f650 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Tue, 2 Apr 2024 17:27:46 +0000 Subject: [PATCH 15/17] lint error fixed. --- xee/ext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 4c13ea6..2222e52 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -427,10 +427,10 @@ def project(self, bbox: types.BBox) -> types.Grid: # Find the actual coordinates of the first or last point of the bounding box # (bbox) based on the positive and negative scale in the actual Earth Engine - # (EE) image. Since EE bounding boxes can be flipped (negative scale), we + # (EE) image. Since EE bounding boxes can be flipped (negative scale), we # cannot determine the origin (transform translation) simply by identifying # the min and max extents. Instead, we calculate the translation by - # considering the direction of scaling (positive or negative) along both + # considering the direction of scaling (positive or negative) along both # the x and y axes. translateX = self.scale_x * x_start + (x_min if self.scale_x > 0 else x_max) translateY = self.scale_y * y_start + (y_min if self.scale_y > 0 else y_max) From e1566d00f16116618fff3c1d1a29a85a88af454c Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Tue, 2 Apr 2024 17:42:10 +0000 Subject: [PATCH 16/17] extreme nit fixed. --- xee/ext.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 2222e52..639c9b6 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -432,8 +432,8 @@ def project(self, bbox: types.BBox) -> types.Grid: # the min and max extents. Instead, we calculate the translation by # considering the direction of scaling (positive or negative) along both # the x and y axes. - translateX = self.scale_x * x_start + (x_min if self.scale_x > 0 else x_max) - translateY = self.scale_y * y_start + (y_min if self.scale_y > 0 else y_max) + translate_x = self.scale_x * x_start + (x_min if self.scale_x > 0 else x_max) + translate_y = self.scale_y * y_start + (y_min if self.scale_y > 0 else y_max) return { # The size of the bounding box. The affine transform and project will be @@ -443,8 +443,8 @@ def project(self, bbox: types.BBox) -> types.Grid: 'height': height, }, 'affineTransform': { - 'translateX': translateX, - 'translateY': translateY, + 'translateX': translate_x, + 'translateY': translate_y, # Define the scale for each pixel (e.g. the number of meters between # each value). 'scaleX': self.scale_x, From 5e6d5561c6d5e719dac302d83a190f786b273cd2 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Tue, 2 Apr 2024 17:44:59 +0000 Subject: [PATCH 17/17] extreme nit fixed. --- xee/ext.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 639c9b6..9ca80f5 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -432,8 +432,12 @@ def project(self, bbox: types.BBox) -> types.Grid: # the min and max extents. Instead, we calculate the translation by # considering the direction of scaling (positive or negative) along both # the x and y axes. - translate_x = self.scale_x * x_start + (x_min if self.scale_x > 0 else x_max) - translate_y = self.scale_y * y_start + (y_min if self.scale_y > 0 else y_max) + translate_x = self.scale_x * x_start + ( + x_min if self.scale_x > 0 else x_max + ) + translate_y = self.scale_y * y_start + ( + y_min if self.scale_y > 0 else y_max + ) return { # The size of the bounding box. The affine transform and project will be