xdem icon indicating copy to clipboard operation
xdem copied to clipboard

[POC] classif step 5: high-level classification management

Open adebardo opened this issue 10 months ago • 0 comments

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:

  1. __init__() method:
    • Initialize the class with a classification_config object, which could be a dict or a JSON file.

      Example of classification_config object:

      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.tif in this example).
      • output_dir: Directory where the classification results will be saved (./output).
      • list_classifications: A list to store the instantiated classification layer objects.
  2. create_classification_layers() method:
    • Parse the classification_config dictionary and instantiate each classification layer based on its type.
    • A classification layer could be:
      • Segmentation Layer: Create a SegmentationClassificationLayer using the parameters (segmentation_mask_path, segmentation_names, etc.).
      • Slope Layer: Create a SlopeClassificationLayer using the specified slope ranges.
      • Fusion Layer: Create a FusionClassificationLayer by fusing the outputs of the specified layers.
    • Add each instantiated classification layer to list_classifications.
  3. apply_classifications() method:
    • Loop through each classification layer in list_classifications and call its apply_classification() method.
  4. 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.).

Tests

  • Write unit tests for the Classification class

adebardo avatar Mar 03 '25 08:03 adebardo