pandora2d.common
This module contains functions allowing to save the results and the configuration of Pandora pipeline.
Attributes
Classes
Registry of classes. |
|
JSON Encoder to serialize all elements |
Functions
|
Convert disparity maps to deformation grids |
|
Convert deformation grids to disparity maps |
|
Save disparity maps into directory defined by cfg's output/path key, |
|
Save confidence maps into directory defined by cfg's output/path key, |
|
Generate a report about disparities statistics and save it to json file. |
|
Save data_vars in the output directory. |
|
Save dataset attributes in a json file |
|
Change origin in case a ROI is present and set pixel size to the matching cost step. |
|
Get step from matching cost or return default value. |
|
Set the pixel size according to the step used in calculating the matching cost. |
|
Create the dataset containing disparity maps and score maps |
|
Complete the dataset with computed disparity maps and score maps. |
|
Save config to json file in directory given by the key output/path. |
|
Get the absolute path of a given path string. If the path is not absolute, |
|
Create a copy of config with all path strings replaced by an absolute path string relative to |
|
Return True if all items in sequence are equals. |
|
Build a boolean mask indicating which elements of the input array are usable. |
|
Getting cost_volume without the margins on the disparities |
Module Contents
- class pandora2d.common.Registry(default: type[T] | None = None)[source]
Bases:
Generic[T]Registry of classes.
A class to decorate classes in order to register them with a string name.
- class pandora2d.common.AllPrimitiveEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
json.JSONEncoderJSON Encoder to serialize all elements
- default(o)[source]
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).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)
- pandora2d.common.convert_disp_to_grid(dataset: xarray.Dataset, pixel_convention: list[int]) xarray.Dataset[source]
Convert disparity maps to deformation grids
- Parameters:
dataset – disparity maps dataset
pixel_convention – initial pixel convention for grid
- pandora2d.common.convert_grid_to_disp(dataset: xarray.Dataset, pixel_convention: list[int]) xarray.Dataset[source]
Convert deformation grids to disparity maps
- Parameters:
dataset – deformation maps dataset
pixel_convention – initial pixel convention for grid
- pandora2d.common.save_disparity_maps(dataset: xarray.Dataset, cfg: dict) None[source]
Save disparity maps into directory defined by cfg’s output/path key, create it with its parents if necessary.
- Parameters:
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)
cfg – user configuration
- Returns:
None
- pandora2d.common.save_confidence_maps(dataset: xarray.Dataset, cfg: dict) None[source]
Save confidence maps into directory defined by cfg’s output/path key, create it with its parents if necessary.
- Parameters:
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)
cfg – user configuration
- Returns:
None
- pandora2d.common._save_disparity_maps_report(dataset: xarray.Dataset, output: pathlib.Path) None[source]
Generate a report about disparities statistics and save it to json file. :param dataset: disparity maps :param output: path where to save report
- pandora2d.common._save_dataset(dataset: xarray.Dataset, output: pathlib.Path) None[source]
Save data_vars in the output directory.
- Parameters:
dataset – Dataset
output – output directory
- Returns:
None
- pandora2d.common.save_attributes(dataset: xarray.Dataset, output: str | os.PathLike) None[source]
Save dataset attributes in a json file
- Parameters:
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)
output – output directory
- Returns:
None
- pandora2d.common.adjust_georeferencement(dataset: xarray.Dataset, cfg: dict) None[source]
Change origin in case a ROI is present and set pixel size to the matching cost step.
- Parameters:
dataset – dataset to configure.
cfg – configuration
- pandora2d.common.get_step(cfg: dict) tuple[int, int][source]
Get step from matching cost or return default value. :param cfg: configuration :return: row_step, col_step
- pandora2d.common.set_pixel_size(dataset: xarray.Dataset, row_step: int = 1, col_step: int = 1) None[source]
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.
- Parameters:
dataset – Data to save
row_step – step used in row
col_step – step used in column
- pandora2d.common.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[source]
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)
- pandora2d.common.complete_dataset_disp_maps(disparity_dataset: xarray.Dataset, delta_row: numpy.ndarray, delta_col: numpy.ndarray, correlation_score: numpy.ndarray) None[source]
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.
- Parameters:
disparity_dataset – initialized disparity maps dataset
delta_row – disparity map for row
delta_col – disparity map for col
correlation_score – score map
- pandora2d.common.save_config(config: dict) None[source]
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
- pandora2d.common.string_to_path(path: str, relative_to: pathlib.Path | str) pathlib.Path[source]
Get the absolute path of a given path string. If the path is not absolute, it resolves it relative to the provided
relative_topath.- Parameters:
path – The path string to convert to an absolute path.
relative_to – The base path to resolve the relative path.
- Returns:
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')
- pandora2d.common.resolve_path_in_config(config: dict, config_path: pathlib.Path) dict[source]
Create a copy of config with all path strings replaced by an absolute path string relative to config_path.
- Parameters:
config – config to modify
config_path – path to the config file.
- Returns:
The configuration with changed paths.
- pandora2d.common.all_same(iterable: collections.abc.Iterable) bool[source]
Return True if all items in sequence are equals.
- pandora2d.common.build_usable_data_mask(disp_data: numpy.typing.NDArray, nodata: float | None) numpy.typing.NDArray[numpy.bool_][source]
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
nodatavalue is provided, different from that value.- Parameters:
disp_data – Input array containing the data to be tested.
nodata – Value representing missing or invalid data. If
None, only finiteness is checked.
- Returns:
A boolean array with the same shape as
disp_data, whereTrueindicates usable data.
- pandora2d.common.get_cost_volume_without_margins(cost_volumes: xarray.Dataset) xarray.Dataset[source]
Getting cost_volume without the margins on the disparities
- Parameters:
cost_volumes – the cost volumes dataset with the data variables: - cost_volume 4D xarray.DataArray (row, col, disp_row, disp_col)
- Returns:
cost_volumes without margins