Skip to content

Commit

Permalink
Add input checks for grid
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Jun 7, 2024
1 parent 1d2341d commit e663a36
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion geoutils/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def _grid_pointcloud(
pc: gpd.GeoDataFrame,
grid_coords: tuple[NDArrayNum, NDArrayNum],
grid_coords: tuple[NDArrayNum, NDArrayNum] = None,
data_column_name: str = "b1",
resampling: Literal["nearest", "linear", "cubic"] = "linear",
dist_nodata_pixel: float = 1.0,
Expand All @@ -32,6 +32,20 @@ def _grid_pointcloud(
expressed in number of pixels.
"""

# Input checks
if (
not isinstance(grid_coords, tuple)
or not (isinstance(grid_coords[0], np.ndarray) and grid_coords[0].ndim == 1)
or not (isinstance(grid_coords[1], np.ndarray) and grid_coords[1].ndim == 1)
):
raise TypeError("Input grid coordinates must be 1D arrays.")

diff_x = np.diff(grid_coords[0])
diff_y = np.diff(grid_coords[1])

if not all(diff_x == diff_x[0]) and all(diff_y == diff_y[0]):
raise ValueError("Grid coordinates must be regular (equally spaced, independently along X and Y).")

# 1/ Interpolate irregular point cloud on a regular grid

# Get meshgrid coordinates
Expand Down

0 comments on commit e663a36

Please sign in to comment.