Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling a ROI when loading dem, add stats documentation #676

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vschaffn
Copy link
Contributor

@vschaffn vschaffn commented Jan 9, 2025

Resolves #602.
Completes GlacioHack/geoutils#642.
Completes GlacioHack/geoutils#638.

Description

This PR introduces the ability to use a Region of Interest (ROI) when working with xdem.DEM, which is a subclass of geoutils.Raster. This functionality allows users to focus on specific regions within the raster data without having to load or process the entire dataset. The ROI can be specified during the instantiation of a DEM object, or used during array creation. This enhancement builds on the existing ROI functionality in the Raster class and integrates it seamlessly into DEM workflows.

Changes

  1. DEM class Enhancement:
  • The DEM constructor now accepts an optional roi parameter. This allows users to define a specific region within the DEM to work on, reducing memory usage and improving performance when processing large datasets.
  • If a roi is specified, the constructor will crop the loaded DEM to the defined region, using the same approach as geoutils.Raster.
  1. Modifications in from_array():
  • The from_array() method has been updated to include the optional roi parameter, which can be passed to crop the data array to a specific region before instantiating the raster object.

Documentation

  • A section about statistics has been added to the DEM class documentation.
  • A section about the ROI has been added to the DEM class documentation.

Example

  1. Statistics:
  • Get all statistics in a dict:
dem.get_stats()
  • Get a single statistic (e.g., 'mean') as a float:
dem.get_stats("mean")
  • Get multiple statistics in a dict:
dem.get_stats(["mean", "max", "rmse"])
  • Using a custom callable statistic:
def custom_stat(data):
    return np.nansum(data > 100)  # Count the number of pixels above 100
dem.get_stats(custom_stat)

Note: as get_stats() is a raster method, it can also be used for terrain attributes:

dem.slope().get_stats()
  1. ROI:
# Initialize a DEM with a pixel-based ROI
dem = xdem.DEM(filename_dem, roi={'x': 50, 'y': 100, 'w': 400, 'h': 300})
# Initialize a DEM with a georeferenced ROI
dem = xdem.DEM(filename_dem, roi={'left': 503810, 'bottom': 8666030, 'top': 8672030, 'right': 511810, 'crs': 'EPSG:25833'})

Note

@vschaffn
Copy link
Contributor Author

Tests with the correct geoutils version with ROI:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[POC] Simplify the creation of an ROI for a user.
1 participant