Stats module

This section explains details of stats module conception and organization.

In the following image we can find the classes that take part in demcompare’s statistics computation step, along with their relationship.

Statistics step architecture

The stats_processing_class module handles the API for the statistics computation.

The Demcompare pipeline module creates a DEM processing module object and a stats_processing_class object when statistics are to be computed.

The dem_processing object creates the input to the stats_processing_class.

The stats_processing_class object contains different classification_layer_class objects, depending on the classification layers specified in the input configuration file. Moreover, each classification_layer_class contains its own metric_class classes.

When statistics are computed, a stats_dataset_class object is obtained.

../../_images/schema_statistiques_class.png

Fig. 15 Statistics classes relationship.

Stats processing

StatsProcessing: Implemented in StatsProcessing file

The stats_processing_class class handles the statistics computation for the ouput DEM of the DEM processing module class.

The stats_processing_class class generates the different classification_layer_class objects to handle the statistics computation by class, and it also generates the stats_dataset_class output object. It also has the API to compute the different available statistics on a chosen classification layer and class.

As one can see in Demcompare pipeline module, the main demcompare module in __init__.py file uses the stats_processing_class class to perform the stats computation.

One can find here the full list of API functions available in the stats_processing_class module, as well as their description and input and output parameters: StatsProcessing API

Classification layer

The Classification Layer class in demcompare is in charge of classifying the input DEM’s pixels by classes and obtains statistics by class.

All Classification Layer classes inherit from the ClassificationLayerTemplate abstract class. Currently, segmentation, global, slope and fusion classification layers are available. For more details on the pixel classification of each classification layer type please see Statistics :

Whereas the abstract class and the class Factory are implemented in :

Each classification layer contains the input DEM classified according to the classification layer type and inputs (ie. a segmentation map for SegmentationClassification, a slope range for SlopeClassification), and handles the statistics computation with the compute_classif_stats function.

To perform the metric computation, the classification_layer_class class creates each metric_class Statistics object.

The computed metrics are stored in the input stats_dataset_class object and returned to the stats_processing_class module, which handles the API for statistics computation Statistics.

One can find here the full list of API functions available in the classification_layer_class module, as well as their description and input and output parameters: ClassificationLayer API

Metric

The Metric class in demcompare is in charge of doing a statistics computation on a given np.ndarray. All metric_class classes inherit from the MetricTemplate abstract class:

To avoid too many python files creation, and given the simplicity of some of the metric classes, they have been grouped by type in scalar_metrics.py, vector_metrics.py and matrix_2d_metrics.py:

  • Metric classes implemented in Scalar metrics file

    • Mean

    • Max

    • Min

    • Std

    • Rmse

    • Median

    • Nmad

    • Sum

    • Squared_sum

    • Percentil90

Each scalar metric computes a scalar value based on the input data.

  • Metric classes implemented in Vector metrics file

    • Cdf (Cumulative Distribution Function)

    • Pdf (Probability Density Function)

    • RatioAboveThreshold

    • SlopeOrientationHistogram

Each vector metric computes two arrays of values based on the input data.

Each matrix 2D metric computes 2D matrix of values based on the input data.

For information on how to create a new metric, please see New metric implementation.

One can find here the full list of API functions available in the classification_layer_class module, as well as their description and input and output parameters: Metric API

Stats dataset

StatsDataset: Implemented in StatsDataset file

The stats_dataset_class stores the different statistics computed for an input DEM. It is generated by the stats_processing_class and its architecture consists in a list of xr.Dataset, one for each classification_layer_class that has been used to compute the stats. It also has the API to obtain the stored statistics.

The statistics of each classification layer are stored in the xr.Dataset with the following structure:

:image: 2D (row, col) input image as xarray.DataArray,

:image_by_class: 3D (row, col, nb_classes)

    xarray.DataArray containing
    the image pixels belonging
    to each class considering the valid pixels

:image_by_class_intersection: 3D (row, col, nb_classes)

    xarray.DataArray containing
    the image pixels belonging
    to each class considering the intersection mode

:image_by_class_exclusion: 3D (row, col, nb_classes)

    xarray.DataArray containing
    the image pixels belonging
    to each class considering the exclusion mode

:attributes:

            - name : name of the classification_layer. str

            - stats_by_class : dictionary containing
              the stats per class considering the standard mode

            - stats_by_class_intersection : dictionary containing
              the stats per class considering the intersection mode

            - stats_by_class_exclusion : dictionary containing
              the stats per class considering the exclusion mode

One can find here the full list of API functions available in the stats_dataset_class module, as well as their description and input and output parameters: StatsDataset API