Skip to content

Commit

Permalink
Tile indexes added and slices removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabhicusp committed Jan 5, 2024
1 parent 7bb1407 commit e8f817f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions xee/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)

Expand All @@ -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
Expand All @@ -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]:
Expand Down

0 comments on commit e8f817f

Please sign in to comment.