Skip to content

Commit

Permalink
feat: add roi in DEM class parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vschaffn committed Jan 9, 2025
1 parent 9efb4ba commit 6702cce
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xdem/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __init__(
silent: bool = True,
downsample: int = 1,
nodata: int | float | None = None,
roi: dict[str, float | int] | None = None,
) -> None:
"""
Instantiate a digital elevation model.
Expand All @@ -109,6 +110,8 @@ def __init__(
:param silent: Whether to display vertical reference parsing.
:param downsample: Downsample the array once loaded by a round factor. Default is no downsampling.
:param nodata: Nodata value to be used (overwrites the metadata). Default reads from metadata.
:param roi: Optional region of interest. Can be pixel-based (dict with keys: 'x', 'y', 'w', 'h')
or georeferenced (dict with keys: left', 'bottom', 'right', 'top', optional 'crs').
"""

self.data: NDArrayf
Expand All @@ -132,6 +135,7 @@ def __init__(
silent=silent,
downsample=downsample,
nodata=nodata,
roi=roi,
)

# Ensure DEM has only one band: self.bands can be None when data is not loaded through the Raster class
Expand Down Expand Up @@ -192,6 +196,7 @@ def from_array(
area_or_point: Literal["Area", "Point"] | None = None,
tags: dict[str, Any] = None,
cast_nodata: bool = True,
roi: dict[str, float | int] = None,
vcrs: (
Literal["Ellipsoid"] | Literal["EGM08"] | Literal["EGM96"] | str | pathlib.Path | VerticalCRS | int | None
) = None,
Expand All @@ -207,8 +212,11 @@ def from_array(
:param tags: Metadata stored in a dictionary.
:param cast_nodata: Automatically cast nodata value to the default nodata for the new array type if not
compatible. If False, will raise an error when incompatible.
:param roi: Optional region of interest. Can be pixel-based (dict with keys: 'x', 'y', 'w', 'h')
or georeferenced (dict with keys: left', 'bottom', 'right', 'top', optional 'crs').
:param vcrs: Vertical coordinate reference system.
:returns: DEM created from the provided array and georeferencing.
"""
# We first apply the from_array of the parent class
Expand All @@ -220,6 +228,7 @@ def from_array(
area_or_point=area_or_point,
tags=tags,
cast_nodata=cast_nodata,
roi=roi,
)
# Then add the vcrs to the class call (that builds on top of the parent class)
return cls(filename_or_dataset=rast, vcrs=vcrs)
Expand Down

0 comments on commit 6702cce

Please sign in to comment.