demcompare.classification_layer.classification_layer_template
Mainly contains the ClassificationLayer class. A classification_layer defines a way to classify the DEMs alti differences.
Module Contents
Classes
ClassificationLayer class |
- class demcompare.classification_layer.classification_layer_template.ClassificationLayerTemplate(name: str, classification_layer_kind: str, cfg: Dict, dem: xarray.Dataset = None)[source]
ClassificationLayer class A classification_layer defines a way to classify the DEM for the stats computation.
- fill_conf_and_schema(cfg: demcompare.internal_typing.ConfigType = None) demcompare.internal_typing.ConfigType [source]
Add default values to the dictionary if there are missing elements and define the configuration schema
- Parameters:
cfg (ConfigType) – coregistration configuration
- Return cfg:
coregistration configuration updated
- Return type:
ConfigType
- check_conf(cfg: demcompare.internal_typing.ConfigType = None) demcompare.internal_typing.ConfigType [source]
Check if the config is correct according to the class configuration schema
raises CheckerError if configuration invalid.
- Parameters:
cfg (ConfigType) – coregistration configuration
- Return cfg:
coregistration configuration updated
- Return type:
ConfigType
- compute_classif_stats(data: xarray.Dataset, stats_dataset: demcompare.stats_dataset.StatsDataset, metrics: List[dict | str] = None)[source]
Stats are computed based on the classification layers, which define classes of pixels that classify divide the input image. Stats are computed on each classes separately.
Input dems can be classified by two maps belonging to the same classification_layer. If both maps exist, then this method produces stats based on 3 modes:
standard mode, intersection mode: where only alti errors values associated with intersection classes between both classified images are used, exclusion mode: the intersection complementary one
- Parameters:
data – array to compute stats from
stats_dataset (StatsDataset) – StatsDataset object
metrics (List[Union[dict, str]]) – metrics to be computed
- Returns:
stats, masks, names per mode
- Return type:
List, List List
- create_metrics(input_metrics: List[dict | str] = None) Tuple[Dict[str, demcompare.metric.Metric], List[bool]] [source]
Create metric objects and remove_outliers_list
- Parameters:
input_metrics (List of Dict and str) – list of input metrics
- Returns:
Dict with metric objects and list with outlier handling per metric
- Return type:
Tuple[Dict[str, Metric], List[bool]]
- _get_outliers_free_mask(array: numpy.ndarray, nodata_value: int | None = None) numpy.ndarray [source]
Get outliers free mask (array of True where value is no outlier) with values outside (mu + 3 sigma) and (mu - 3 sigma). Nan and nodata_value are not considered in mu and sigma computation.
- Parameters:
array (np.ndarray) – input array to get the mask from
nodata_value (int or None) – no data value considered. Default: None
- Returns:
outliers free mask (array of True where value is no outlier)
- Return type:
np.ndarray
- _create_mode_masks(alti_map: xarray.Dataset)[source]
Compute Masks for every required modes :
the ‘standard’ mode: nan free, nodata free mask
the ‘intersection’ mode: which is the ‘standard’ mode where only the pixels for which both sets (sec and ref) are intersection
the ‘exclusion’ mode: which is ‘intersection’ complementary
Note that ‘intersection’ and ‘exclusion’ mode masks can only be computed if len(_sets_masks)==2
- Parameters:
alti_map – alti differences
- Returns:
list of masks, associated modes, and error_img read as array
- Return type:
List[np.ndarray]
- static _get_nonan_mask(array: numpy.ndarray, nodata_value: int | None = None) numpy.ndarray [source]
Get no data and nan mask value
- Parameters:
array (np.ndarray) – input array to get the mask from
nodata_value (int or None) – no data value considered. Default: None
- Returns:
nan and nodata_value if exists mask on array.
- Return type:
np.ndarray
- _compute_mode_stats(dz_values: numpy.ndarray, stats_dataset: demcompare.stats_dataset.StatsDataset, mode_mask: numpy.ndarray = None, mode_name: str = None, metrics: List[dict | str] = None) demcompare.stats_dataset.StatsDataset [source]
Get stats for a specific mode
- Parameters:
dz_values (np.ndarray) – alti map
stats_dataset (StatsDataset) – StatsDataset object
mode_mask (List[bool]) – boolean mask with True values for pixels to use
mode_name (str) – mode name
metrics (List[Union[dict, str]]) – metrics to be computed
- Returns:
StatsDataset with computed metrics (set_name, nbpts, %(out_of_all_pts), max, min, mean, std, rmse, …)
- Return type:
- _create_class_masks()[source]
Returns a list of masks, by class. Each masks indicates which pixels belong to the class.
- Returns:
None
- stats_computation(data: numpy.ndarray, outliers_free_data: numpy.ndarray, input_metrics: List[str | Dict] = None) Dict [source]
Compute stats for a specific array
- Parameters:
data (np.ndarray) – 2D input data
outliers_free_data (np.ndarray) – input outliers_free_data
input_metrics (List[Union[str, Dict]]) – input metrics to use
- Returns:
dict with computed metric values
- Return type:
Dict