demcompare.classification_layer.classification_layer_template ============================================================= .. py:module:: demcompare.classification_layer.classification_layer_template .. autoapi-nested-parse:: Mainly contains the ClassificationLayer class. A classification_layer defines a way to classify the DEMs alti differences. Classes ------- .. autoapisummary:: demcompare.classification_layer.classification_layer_template.ClassificationLayerTemplate Module Contents --------------- .. py:class:: ClassificationLayerTemplate(name: str, classification_layer_kind: str, cfg: Dict, dem: xarray.Dataset = None) ClassificationLayer class A classification_layer defines a way to classify the DEM for the stats computation. .. py:exception:: NotEnoughDataToClassificationLayerError Bases: :py:obj:`Exception` Define a NotEnoughDataToClassificationLayerError Exception .. py:exception:: LackOfClassificationLayerDataError Bases: :py:obj:`Exception` Define a LackOfClassificationLayerDataError Exception .. py:attribute:: name .. py:attribute:: type_layer .. py:attribute:: schema :type: Dict :value: None .. py:attribute:: classes :type: collections.OrderedDict :value: None .. py:attribute:: dem :type: xarray.Dataset :value: None .. py:attribute:: cfg :type: Dict .. py:attribute:: nodata :type: Union[float, int] .. py:attribute:: no_data_location :type: numpy.ndarray :value: None .. py:attribute:: bounds :type: rasterio.coords.BoundingBox :value: None .. py:attribute:: remove_outliers :type: bool .. py:attribute:: output_dir :type: Union[str, None] .. py:attribute:: _stats_dir :type: Union[str, None] :value: None .. py:attribute:: map_image :type: Dict .. py:attribute:: classes_masks :type: Dict .. py:attribute:: outliers_free_mask :type: numpy.ndarray :value: None .. py:method:: fill_conf_and_schema(cfg: demcompare.internal_typing.ConfigType = None) -> demcompare.internal_typing.ConfigType Add default values to the dictionary if there are missing elements and define the configuration schema :param cfg: coregistration configuration :type cfg: ConfigType :return cfg: coregistration configuration updated :rtype: ConfigType .. py:method:: check_conf(cfg: demcompare.internal_typing.ConfigType = None) Check if the config is correct according to the class configuration schema raises CheckerError if configuration invalid. :param cfg: coregistration configuration :type cfg: ConfigType .. py:method:: compute_classif_stats(data: xarray.Dataset, stats_dataset: demcompare.stats_dataset.StatsDataset, metrics: List[Union[dict, str]] = None) 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 :param data: array to compute stats from :type data: xr.DataSet containing : - image : 2D (row, col) xr.DataArray float32 - georef_transform: 1D (trans_len) xr.DataArray - classification_layer_masks : 3D (row, col, indicator) xr.DataArray :param stats_dataset: StatsDataset object :type stats_dataset: StatsDataset :param metrics: metrics to be computed :type metrics: List[Union[dict, str]] :return: stats, masks, names per mode :rtype: List, List List .. py:method:: create_metrics(input_metrics: List[Union[dict, str]] = None) -> Tuple[Dict[str, demcompare.metric.Metric], List[bool]] Create metric objects and remove_outliers_list :param input_metrics: list of input metrics :type input_metrics: List of Dict and str :return: Dict with metric objects and list with outlier handling per metric :rtype: Tuple[Dict[str, Metric], List[bool]] .. py:method:: _get_outliers_free_mask(array: numpy.ndarray, nodata_value: Union[int, None] = None) -> numpy.ndarray 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. :param array: input array to get the mask from :type array: np.ndarray :param nodata_value: no data value considered. Default: None :type nodata_value: int or None :return: outliers free mask (array of True where value is no outlier) :rtype: np.ndarray .. py:method:: _create_mode_masks(alti_map: xarray.Dataset) 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 :param alti_map: alti differences :type alti_map: xr.DataSet containing : - image : 2D (row, col) xr.DataArray float32 - georef_transform: 1D (trans_len) xr.DataArray :return: list of masks, associated modes, and error_img read as array :rtype: List[np.ndarray] .. py:method:: _get_nonan_mask(array: numpy.ndarray, nodata_value: Union[int, None] = None) -> numpy.ndarray :staticmethod: Get no data and nan mask value :param array: input array to get the mask from :type array: np.ndarray :param nodata_value: no data value considered. Default: None :type nodata_value: int or None :return: nan and nodata_value if exists mask on array. :rtype: np.ndarray .. py:method:: _compute_mode_stats(dz_values: numpy.ndarray, stats_dataset: demcompare.stats_dataset.StatsDataset, mode_mask: numpy.ndarray = None, mode_name: str = None, metrics: List[Union[dict, str]] = None) -> demcompare.stats_dataset.StatsDataset Get stats for a specific mode :param dz_values: alti map :type dz_values: np.ndarray :param stats_dataset: StatsDataset object :type stats_dataset: StatsDataset :param mode_mask: boolean mask with True values for pixels to use :type mode_mask: List[bool] :param mode_name: mode name :type mode_name: str :param metrics: metrics to be computed :type metrics: List[Union[dict, str]] :return: StatsDataset with computed metrics (set_name, nbpts, %(out_of_all_pts), max, min, mean, std, rmse, ...) :rtype: StatsDataset .. py:method:: _create_class_masks() Returns a list of masks, by class. Each masks indicates which pixels belong to the class. :return: None .. py:method:: _create_labelled_map() :abstractmethod: Creates labelled map :return: None .. py:method:: stats_computation(data: numpy.ndarray, outliers_free_data: numpy.ndarray, input_metrics: List[Union[str, Dict]] = None) -> Dict Compute stats for a specific array :param data: 2D input data :type data: np.ndarray :param outliers_free_data: input outliers_free_data :type outliers_free_data: np.ndarray :param input_metrics: input metrics to use :type input_metrics: List[Union[str, Dict]] :return: dict with computed metric values :rtype: Dict .. py:method:: save_map_img(map_img: numpy.ndarray, map_support: str) Save the classification layer map to file :param map_img: input data :type map_img: np.ndarray :param map_support: map support "ref" or "sec :type map_support: str :return: None