Skip to content

Move filter.py from xDEM to GeoUtils and integrate into raster class #699

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

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

Conversation

adebardo
Copy link
Contributor

@adebardo adebardo commented May 19, 2025

Resolves #690

I'm picking up @vschaffn's work on filter management from geoutils. I couldn't find any other way than to create a new PR. Valentin's history should be preserved.

I've tried to incorporate the other feedback, with more tests and better handling of NaNs without _nan_safe_filter.

Previous PR

Context

The current filter.py module in xDEM provides a collection of filters that are highly useful for digital elevation models (DEMs). However, these filtering utilities are not intrinsically tied to elevation data—they are generally applicable to any geospatial raster data. Given this, it makes more architectural sense for them to live in GeoUtils.

Changes

  • Moved the filter.py module from xdem/ to geoutils/filters.py.
  • Removed gaussian_filter_cv to avoid dependence on opencv.
  • Moved tests/test_filter.py in xDEM to tests/test_filters.py in GeoUtils.
  • Added a new function _nan_safe_filter common for gaussian, mean and median filter, to deal with arrays containing nan values.
  • Added a generic _filter function mapping the available filters.
  • Added the Raster.filter method that extracts the array with Nans, uses the _filter function, and rebuild the Raster data.
    Tests
  • Added new tests for the Raster.filter method.

Documentation

  • Added a filter section in raster_class.md.

Note

When this ticket is approved, a linked PR to remove filters in xDEM will be opened.

@adebardo adebardo force-pushed the 690_bis-filter branch 2 times, most recently from 972121f to 507215d Compare May 19, 2025 12:17
@rhugonnet
Copy link
Member

Great, thanks! 😄

We have a memo page to work on someone else's PR here 😉: https://github.com/GlacioHack/xdem/wiki/Work-on-someone-else's-PR)

I only have a few comments:

  • I'm not entirely sure if the current mean function works with NaNs, we should add a test checking the output exactly on a 3x3 array example, like shown in this comment: Move filter.py from xDEM to GeoUtils and integrate into raster class #691 (review). We should be able to replicate this test easily for all filters.
  • Should we make Numba an optional dependency? Not sure we want to enforce it on users. Maybe we should do the same in xDEM actually.

For next PRs, we also need to:

  • Open an issue to make the mean of the distance filter a variable,
  • Open an issue to add other filters using the "Numba" engine.
@rhugonnet
Copy link
Member

We could also easily add an NMAD filter based on Numba (just mirroring the median filter code with Numba, with the NMAD calculation instead), which would solve this 4-year old issue! GlacioHack/xdem#69

@adebardo
Copy link
Contributor Author

adebardo commented Jun 2, 2025

We could add it to our "project" once created ?

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