pandora2d.common ================ .. py:module:: pandora2d.common .. autoapi-nested-parse:: This module contains functions allowing to save the results and the configuration of Pandora pipeline. Attributes ---------- .. autoapisummary:: pandora2d.common.T Classes ------- .. autoapisummary:: pandora2d.common.Registry pandora2d.common.AllPrimitiveEncoder Functions --------- .. autoapisummary:: pandora2d.common.convert_disp_to_grid pandora2d.common.convert_grid_to_disp pandora2d.common.save_disparity_maps pandora2d.common.save_confidence_maps pandora2d.common._save_disparity_maps_report pandora2d.common._save_dataset pandora2d.common.save_attributes pandora2d.common.adjust_georeferencement pandora2d.common.get_step pandora2d.common.set_pixel_size pandora2d.common.dataset_disp_maps pandora2d.common.complete_dataset_disp_maps pandora2d.common.save_config pandora2d.common.string_to_path pandora2d.common.resolve_path_in_config pandora2d.common.all_same pandora2d.common.build_usable_data_mask pandora2d.common.get_cost_volume_without_margins Module Contents --------------- .. py:data:: T .. py:class:: Registry(default: type[T] | None = None) Bases: :py:obj:`Generic`\ [\ :py:obj:`T`\ ] Registry of classes. A class to decorate classes in order to register them with a string name. .. py:attribute:: registered :type: dict[str, type[T]] .. py:attribute:: default :value: None .. py:method:: add(name: str) -> collections.abc.Callable[[type[T]], type[T]] Register a class with `name`. :param name: Name to register the decorated class with. :return: The decorated class. .. py:method:: get(name: str) -> type[T] Get the class registered as `name`. :param name: The name of the registered class to retrieve. :return: The class registered under `name` or the default class if not found. :raises KeyError: If no class is registered under `name` and no default is set. .. py:class:: AllPrimitiveEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None) Bases: :py:obj:`json.JSONEncoder` JSON Encoder to serialize all elements .. py:method:: default(o) Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) .. py:function:: convert_disp_to_grid(dataset: xarray.Dataset, pixel_convention: list[int]) -> xarray.Dataset Convert disparity maps to deformation grids :param dataset: disparity maps dataset :param pixel_convention: initial pixel convention for grid .. py:function:: convert_grid_to_disp(dataset: xarray.Dataset, pixel_convention: list[int]) -> xarray.Dataset Convert deformation grids to disparity maps :param dataset: deformation maps dataset :param pixel_convention: initial pixel convention for grid .. py:function:: save_disparity_maps(dataset: xarray.Dataset, cfg: dict) -> None Save disparity maps into directory defined by cfg's `output/path` key, create it with its parents if necessary. :param dataset: Dataset which contains: - lines : the disparity map for the lines 2D DataArray (row, col) - columns : the disparity map for the columns 2D DataArray (row, col) :param cfg: user configuration :return: None .. py:function:: save_confidence_maps(dataset: xarray.Dataset, cfg: dict) -> None Save confidence maps into directory defined by cfg's `output/path` key, create it with its parents if necessary. :param dataset: Dataset which contains: - lines : the confidence map for the lines 2D DataArray (row, col) - columns : the confidence map for the columns 2D DataArray (row, col) :param cfg: user configuration :return: None .. py:function:: _save_disparity_maps_report(dataset: xarray.Dataset, output: pathlib.Path) -> None Generate a report about disparities statistics and save it to json file. :param dataset: disparity maps :param output: path where to save report .. py:function:: _save_dataset(dataset: xarray.Dataset, output: pathlib.Path) -> None Save data_vars in the output directory. :param dataset: Dataset :param output: output directory :return: None .. py:function:: save_attributes(dataset: xarray.Dataset, output: str | os.PathLike) -> None Save dataset attributes in a json file :param dataset: Dataset which contains: - row_map : the disparity map for the lines 2D DataArray (row, col) - col_map : the disparity map for the columns 2D DataArray (row, col) :param output: output directory :return: None .. py:function:: adjust_georeferencement(dataset: xarray.Dataset, cfg: dict) -> None Change origin in case a ROI is present and set pixel size to the matching cost step. :param dataset: dataset to configure. :param cfg: configuration .. py:function:: get_step(cfg: dict) -> tuple[int, int] Get step from matching cost or return default value. :param cfg: configuration :return: row_step, col_step .. py:function:: set_pixel_size(dataset: xarray.Dataset, row_step: int = 1, col_step: int = 1) -> None Set the pixel size according to the step used in calculating the matching cost. This ensures that all pixels are well geo-referenced in case a step is applied. :param dataset: Data to save :param row_step: step used in row :param col_step: step used in column .. py:function:: dataset_disp_maps(coords: xarray.Coordinates, dataset_validity: xarray.Dataset, attributes: dict = None, dtype: numpy.typing.DTypeLike = np.float32, cost_volume_confidence_step: bool = False) -> xarray.Dataset Create the dataset containing disparity maps and score maps :param coords: disparity maps coordinates :param dataset_validity: xr.Dataset containing validity information :param attributes: disparity map for col :param dtype: dtype of the dataset :param cost_volume_confidence_step: whether there is a cost volume confidence step in the pipeline or not :return: dataset: Dataset with the empty disparity maps and score with the data variables : - row_map 2D xarray.DataArray (row, col) - col_map 2D xarray.DataArray (row, col) - score 2D xarray.DataArray (row, col) .. py:function:: complete_dataset_disp_maps(disparity_dataset: xarray.Dataset, delta_row: numpy.ndarray, delta_col: numpy.ndarray, correlation_score: numpy.ndarray) -> None Complete the dataset with computed disparity maps and score maps. If a cost volume confidence step is present in the pipeline, the confidence measure is filled during the corresponding step. :param disparity_dataset: initialized disparity maps dataset :param delta_row: disparity map for row :param delta_col: disparity map for col :param correlation_score: score map .. py:function:: save_config(config: dict) -> None Save config to json file in directory given by the key `output/path`. Create file tree if it does not exist, :param config: configuration to save .. py:function:: string_to_path(path: str, relative_to: pathlib.Path | str) -> pathlib.Path Get the absolute path of a given path string. If the path is not absolute, it resolves it relative to the provided ``relative_to`` path. :param path: The path string to convert to an absolute path. :param relative_to: The base path to resolve the relative path. :return: The absolute path of the given path string. :Example: >>> string_to_path('/absolute/path', Path('/home/user')) PosixPath('/absolute/path') >>> string_to_path('relative/path', Path('/home/user')) PosixPath('/home/user/relative/path') >>> string_to_path('~/mydir', Path('/home/user')) PosixPath('/home/user/mydir') .. py:function:: resolve_path_in_config(config: dict, config_path: pathlib.Path) -> dict Create a copy of config with all path strings replaced by an absolute path string relative to config_path. :param config: config to modify :param config_path: path to the config file. :return: The configuration with changed paths. .. py:function:: all_same(iterable: collections.abc.Iterable) -> bool Return True if all items in sequence are equals. .. py:function:: build_usable_data_mask(disp_data: numpy.typing.NDArray, nodata: float | None) -> numpy.typing.NDArray[numpy.bool_] Build a boolean mask indicating which elements of the input array are usable. An element is considered usable if it is finite (not NaN or infinite) and, when a ``nodata`` value is provided, different from that value. :param disp_data: Input array containing the data to be tested. :param nodata: Value representing missing or invalid data. If ``None``, only finiteness is checked. :return: A boolean array with the same shape as ``disp_data``, where ``True`` indicates usable data. .. py:function:: get_cost_volume_without_margins(cost_volumes: xarray.Dataset) -> xarray.Dataset Getting cost_volume without the margins on the disparities :param cost_volumes: the cost volumes dataset with the data variables: - cost_volume 4D xarray.DataArray (row, col, disp_row, disp_col) :return: cost_volumes without margins