Skip to content

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

@vschaffn

Description

@vschaffn

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.

Proposed changes

1. Migrate Code

  • Move the filter.py module from xdem/ to geoutils/filters.py.
  • Remove gaussian_filter_cv to avoid dependence on opencv.
  • Move the corresponding unit tests from tests/test_filter.py in xDEM to tests/test_filters.py in GeoUtils.
  • Adjust imports and dependencies accordingly.

2. Integrate Filters into Raster Class

Add a new method to the Raster class:

 def filter(
        self,
        method: str | Callable[..., NDArrayNum],
        inplace: bool = False,
        **kwargs: dict[str, Any]
    ) -> RasterType | None:
        """
        Apply a filter to the raster data.

        :param method: The filter to apply. Can be a string ("gaussian", "median", "mean", "max", "distance")
                       for built-in filters, or a custom callable that takes a 2D ndarray and returns one.
        :param inplace: If True, modifies the current Raster object. If False, returns a new filtered Raster.

        :return: A new Raster instance with the filtered data if `inplace=False`, otherwise None.

        :raises ValueError: If the filter name is not one of the predefined options.
        :raises TypeError: If `method` is neither a string nor a callable.
        """

This method should internally call the appropriate functions from geoutils.filters.

3. Add Documentation

  • Update the raster class documentation to include the .filter() method.
  • Update the API.

4. Testing

  • Ensure migrated tests are compatible with GeoUtils.
  • Add new tests specifically for the Raster.filter() method.

5. Remove Filters from xDEM

  • Remove xdem/filter.py entirely.
  • Delete associated tests (tests/test_filter.py).
  • Ensure no internal code or modules in xDEM are still referencing the removed filters.
  • Since the filters were not documented or exposed in the public API, no deprecation warning is necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature improvement or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions