From d9efe7486ef9449bbaeb516e0574455c9f2210fc Mon Sep 17 00:00:00 2001 From: vschaffn Date: Thu, 9 Jan 2025 16:27:03 +0100 Subject: [PATCH] feat: add roi in DEM class parameters --- xdem/dem.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xdem/dem.py b/xdem/dem.py index 7d6e6f26..83c9d6d7 100644 --- a/xdem/dem.py +++ b/xdem/dem.py @@ -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. @@ -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 @@ -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 @@ -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, @@ -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 @@ -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)