From e8f817f150b9a7fb7f68deeaa23276e72b3fdc06 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 5 Jan 2024 12:12:31 +0000 Subject: [PATCH 1/4] Tile indexes added and slices removed. --- xee/ext.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 8f6399a..53a2a0e 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -541,18 +541,17 @@ def _get_primary_coordinates(self) -> List[Any]: return primary_coords def _get_tile_from_ee( - self, tile_index: Tuple[Any, Union[str, int]] - ) -> Tuple[slice, np.ndarray]: + self, tile_and_band: List[Tuple[int, int, int], str] + ) -> Tuple[int, np.ndarray]: """Get a numpy array from EE for a specific bounding box (a 'tile').""" - tile_index, band_id = tile_index + (tile_index, tile_coords_start, tile_coords_end), band_id = tile_and_band bbox = self.project( - (tile_index[0], 0, tile_index[1], 1) + (tile_coords_start, 0, tile_coords_end, 1) if band_id == 'x' - else (0, tile_index[0], 1, tile_index[1]) + else (0, tile_coords_start, 1, tile_coords_end) ) - tile_idx = slice(tile_index[0], tile_index[1]) target_image = ee.Image.pixelCoordinates(ee.Projection(self.crs_arg)) - return tile_idx, self.image_to_array( + return tile_index, self.image_to_array( target_image, grid=bbox, dtype=np.float32, bandIds=[band_id] ) @@ -565,7 +564,7 @@ def _process_coordinate_data( ) -> np.ndarray: """Process coordinate data using multithreading for longitude or latitude.""" data = [ - (tile_size * i, min(tile_size * (i + 1), end_point)) + (i, tile_size * i, min(tile_size * (i + 1), end_point) ) for i in range(tile_count) ] tiles = [None] * tile_count @@ -574,7 +573,7 @@ def _process_coordinate_data( self._get_tile_from_ee, list(zip(data, itertools.cycle([coordinate_type]))), ): - tiles[i] = arr.tolist() if coordinate_type == 'x' else arr.tolist()[0] + tiles[i] = arr.tolist()[0] if coordinate_type == 'x' else arr.tolist()[0][0] return np.concatenate(tiles) def get_variables(self) -> utils.Frozen[str, xarray.Variable]: From 98c92a5491019b2601453f574bc098fd92739e6a Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Fri, 5 Jan 2024 12:55:04 +0000 Subject: [PATCH 2/4] Lint error fixed. --- xee/ext.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index 53a2a0e..f4cd031 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -564,7 +564,7 @@ def _process_coordinate_data( ) -> np.ndarray: """Process coordinate data using multithreading for longitude or latitude.""" data = [ - (i, tile_size * i, min(tile_size * (i + 1), end_point) ) + (i, tile_size * i, min(tile_size * (i + 1), end_point)) for i in range(tile_count) ] tiles = [None] * tile_count @@ -573,7 +573,9 @@ def _process_coordinate_data( self._get_tile_from_ee, list(zip(data, itertools.cycle([coordinate_type]))), ): - tiles[i] = arr.tolist()[0] if coordinate_type == 'x' else arr.tolist()[0][0] + tiles[i] = ( + arr.tolist()[0] if coordinate_type == 'x' else arr.tolist()[0][0] + ) return np.concatenate(tiles) def get_variables(self) -> utils.Frozen[str, xarray.Variable]: From 9759d0f649ec0ed5517ed1945b870f46f8d3cff4 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Tue, 9 Jan 2024 17:15:44 +0000 Subject: [PATCH 3/4] lat. lon storing into the arr is updated. --- xee/ext.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index f4cd031..e675ca0 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -573,10 +573,8 @@ def _process_coordinate_data( self._get_tile_from_ee, list(zip(data, itertools.cycle([coordinate_type]))), ): - tiles[i] = ( - arr.tolist()[0] if coordinate_type == 'x' else arr.tolist()[0][0] - ) - return np.concatenate(tiles) + tiles[i] = arr.flatten() + return np.array(tiles) def get_variables(self) -> utils.Frozen[str, xarray.Variable]: vars_ = [(name, self.open_store_variable(name)) for name in self._bands()] From 14da6de31fdc5d2f4e42c90b71988f70cfa6f4e8 Mon Sep 17 00:00:00 2001 From: dabhicusp Date: Thu, 11 Jan 2024 04:27:23 +0000 Subject: [PATCH 4/4] nit changes done. --- xee/ext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xee/ext.py b/xee/ext.py index e675ca0..df39284 100644 --- a/xee/ext.py +++ b/xee/ext.py @@ -541,8 +541,8 @@ def _get_primary_coordinates(self) -> List[Any]: return primary_coords def _get_tile_from_ee( - self, tile_and_band: List[Tuple[int, int, int], str] - ) -> Tuple[int, np.ndarray]: + self, tile_and_band: Tuple[Tuple[int, int, int], str] + ) -> Tuple[int, np.ndarray[Any, np.dtype]]: """Get a numpy array from EE for a specific bounding box (a 'tile').""" (tile_index, tile_coords_start, tile_coords_end), band_id = tile_and_band bbox = self.project(