xdem
xdem copied to clipboard
[POC] classif step 5: high-level classification management
Context
The Classification class is a high-level interface that manages the process of applying different classification layers to a DEM. This class is responsible for parsing the configuration file, instantiating the appropriate classification layers, applying them, and saving the results. The provided configuration defines different layers, each with its own parameters (segmentation, slope, fusion).
Code
In a new file (classification_manager.py), implement the Classification class, which will provide the following functionality:
-
__init__()method:-
Initialize the class with a
classification_configobject, which could be a dict or a JSON file.Example of
classification_configobject:dem_path: "dem.tif" output_dir: "./output" classification_layers: segmentation: layer_name: "dem_segmentation" segmentation_mask_path: "./segmentation_mask.tif" segmentation_names: valid: [0] KO: [1] Land: [2] NoData: [3] Outside_detector: [4] stats: ["mean", "nmad"] stats_classes: ["Land", "valid"] slope: layer_name: "dem_slope" ranges: [0, 5, 10, 25, 45] fusion: name: "dem_fusion" layers_to_fuse: ["dem_segmentation", "dem_slope"] stats: "median" stats_classes: "valid_&_slope5_10" -
Attributes:
-
dem: Initialize the DEM object (dem.tifin this example). -
output_dir: Directory where the classification results will be saved (./output). -
list_classifications: A list to store the instantiated classification layer objects.
-
-
-
create_classification_layers()method:- Parse the
classification_configdictionary and instantiate each classification layer based on its type. - A classification layer could be:
-
Segmentation Layer: Create a
SegmentationClassificationLayerusing the parameters (segmentation_mask_path,segmentation_names, etc.). -
Slope Layer: Create a
SlopeClassificationLayerusing the specified slope ranges. -
Fusion Layer: Create a
FusionClassificationLayerby fusing the outputs of the specified layers.
-
Segmentation Layer: Create a
- Add each instantiated classification layer to
list_classifications.
- Parse the
-
apply_classifications()method:- Loop through each classification layer in
list_classificationsand call itsapply_classification()method.
- Loop through each classification layer in
-
save()method:- Implement the
save()method to save the classification results for each layer. - Each classification layer will be responsible for saving its own results (classification mask, statistics, etc.).
- Implement the
Tests
- Write unit tests for the
Classificationclass