Skip to content

Commit

Permalink
Merge pull request #19 from gregory-halverson-jpl/main
Browse files Browse the repository at this point in the history
fixing imports
  • Loading branch information
gregory-halverson-jpl authored Oct 29, 2024
2 parents 3580ceb + 5f81f94 commit 1805465
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rasters"
version = "1.3.0"
version = "1.3.1"
description = "raster processing toolkit"
readme = "README.md"
authors = [
Expand Down
6 changes: 4 additions & 2 deletions rasters/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
from .where import where
from .wrap_geometry import wrap_geometry
from .CRS import WGS84
from .raster_geometry import RasterGeometry
from .raster_grid import RasterGrid

if TYPE_CHECKING:
from .CRS import CRS
Expand All @@ -54,9 +56,9 @@
from .polygon import Polygon
from .multi_polygon import MultiPolygon
from .kdtree import KDTree
from .raster_geometry import RasterGeometry
# from .raster_geometry import RasterGeometry
from .raster_geolocation import RasterGeolocation
from .raster_grid import RasterGrid
# from .raster_grid import RasterGrid
from .raster import Raster
from .multi_raster import MultiRaster

Expand Down
54 changes: 41 additions & 13 deletions rasters/raster_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,48 @@ def boundary_indices(self) -> Tuple[np.ndarray, np.ndarray]:
height = self.rows
width = self.cols

# Handle empty grids
if height == 0 or width == 0:
return np.array([], dtype=np.int32), np.array([], dtype=np.int32)

# Handle single cell grid
if height == 1 and width == 1:
return np.full((1, 1), 0, dtype=np.int32), np.full((1, 1), 0, dtype=np.int32)

y_top = np.full((width,), 0, dtype=np.int32)
x_top = np.arange(width)
y_right = np.arange(1, height)
x_right = np.full((height - 1,), width - 1, dtype=np.int32)
y_bottom = np.full((width - 1,), height - 1, dtype=np.int32)
x_bottom = np.flipud(np.arange(width - 1))
y_left = np.flipud(np.arange(1, height - 1))
x_left = np.full((height - 2,), 0, dtype=np.int32)
x_indices = np.concatenate([x_top, x_right, x_bottom, x_left])
y_indices = np.concatenate([y_top, y_right, y_bottom, y_left])

return np.array([0], dtype=np.int32), np.array([0], dtype=np.int32)

y_indices = []
x_indices = []

# Top boundary (first row)
y_top = np.zeros(width, dtype=np.int32)
x_top = np.arange(width, dtype=np.int32)
y_indices.append(y_top)
x_indices.append(x_top)

if height > 1:
# Right boundary (last column, excluding the first cell to avoid duplication)
y_right = np.arange(1, height, dtype=np.int32)
x_right = np.full_like(y_right, width - 1, dtype=np.int32)
y_indices.append(y_right)
x_indices.append(x_right)

if width > 1:
# Bottom boundary (last row, excluding the last cell to avoid duplication)
y_bottom = np.full(width - 1, height - 1, dtype=np.int32)
x_bottom = np.arange(width - 2, -1, -1, dtype=np.int32)
y_indices.append(y_bottom)
x_indices.append(x_bottom)

if width > 1 and height > 2:
# Left boundary (first column, excluding the first and last cells to avoid duplication)
y_left = np.arange(height - 2, 0, -1, dtype=np.int32)
x_left = np.zeros_like(y_left, dtype=np.int32)
y_indices.append(y_left)
x_indices.append(x_left)

# Concatenate all boundary indices
y_indices = np.concatenate(y_indices) if y_indices else np.array([], dtype=np.int32)
x_indices = np.concatenate(x_indices) if x_indices else np.array([], dtype=np.int32)

return y_indices, x_indices

@property
Expand Down
2 changes: 1 addition & 1 deletion rasters/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1

0 comments on commit 1805465

Please sign in to comment.