Open
Description
Context
Following the implementation of the ClassificationLayer
base class, we need to develop the SlopeClassificationLayer
. This class will handle slope-based classification of a DEM, where it calculates the slope and classifies DEM pixels into predefined slope ranges (e.g., [0, 5, 10, 25, 50, 100]
degrees).
The SlopeClassificationLayer
will inherit from the ClassificationLayer
and will implement slope-specific classification logic.
Code
In the same file (classification.py
) as the ClassificationLayer
base class, add the SlopeClassificationLayer
to define slope classification functionality.
__init__()
method:- Extend the initialization from the
ClassificationLayer
. - Include an additional attribute specific to slope classification:
ranges
: A list of slope ranges used to classify the DEM pixels into different slope categories.
- Extend the initialization from the
apply_classification()
method:- Use the
DEM.slope()
method to compute the slope. - Classify the pixels into the defined slope ranges:
- For each class, create a mask representing the slope range.
- Store the masks in the
classification
attribute, which is ageoutils.Mask
3D object, where the first dimension represents the class, and the two others represent the mask values. - Store the class names and their associated bands under the
class_names
attribute (adict[str, int]
object). Example:
- Use the
self.class_names = {"slope0_5": 0, "slope5_10": 1, ...}
Tests
- Write unit tests for the
SlopeClassificationLayer
class in a newtest_classification.py
file. - The unit tests should:
- Verify that the layer initializes properly with the provided configuration.
- Ensure that the classification logic works as expected.
- Confirm that statistics are computed as expected.
- Validate that the results are saved correctly.
Documentation
Include the necessary information in the documentation for the user.
Example: clarify the list of ranges and how to use it.