pandora2d.img_tools =================== .. py:module:: pandora2d.img_tools .. autoapi-nested-parse:: This module contains functions associated to raster images. Classes ------- .. autoapisummary:: pandora2d.img_tools.Datasets Functions --------- .. autoapisummary:: pandora2d.img_tools.create_datasets_from_inputs pandora2d.img_tools.check_disparities pandora2d.img_tools.check_disparity_presence pandora2d.img_tools.check_disparity_types pandora2d.img_tools.add_disparity_grid pandora2d.img_tools.get_min_max_disp_from_dicts pandora2d.img_tools.shift_disp_row_img pandora2d.img_tools.get_margins_values pandora2d.img_tools.get_roi_processing pandora2d.img_tools.remove_roi_margins pandora2d.img_tools.row_zoom_img pandora2d.img_tools.col_zoom_img pandora2d.img_tools.shift_subpix_img pandora2d.img_tools.shift_subpix_img_2d pandora2d.img_tools.get_initial_disparity pandora2d.img_tools.get_extrema_disparity pandora2d.img_tools.convert_no_data Module Contents --------------- .. py:class:: Datasets Bases: :py:obj:`NamedTuple` NamedTuple to store left and right datasets. .. py:attribute:: left :type: xarray.Dataset .. py:attribute:: right :type: xarray.Dataset .. py:function:: create_datasets_from_inputs(input_config: dict, roi: dict = None, estimation_cfg: dict = None, attributes: dict = None) -> Datasets Read image and return the corresponding xarray.DataSet :param input_config: configuration used to create dataset. :param roi: dictionary with a roi "col": {"first": , "last": }, "row": {"first": , "last": }, "margins": [, , , ] with margins : left, up, right, down :param estimation_cfg: dictionary containing estimation configuration :param attributes: dictionary with attribute parameters :return: Datasets NamedTuple with two attributes `left` and `right` each containing a xarray.DataSet containing the variables : - im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32 - col_disparity: 3D (disp, row, col) xarray.DataArray float32 - row_disparity: 3D (disp, row, col) xarray.DataArray float32 .. py:function:: check_disparities(input_config: dict) -> None Do various check against disparities properties. :param input_config: configuration used to create dataset. :raises SystemExit: If any check fails. .. py:function:: check_disparity_presence(input_config: dict) -> None Check that disparity keys are not missing from input_config. :param input_config: configuration used to create dataset. :raises SystemExit: if one or both keys are missing .. py:function:: check_disparity_types(disparity: Any) -> None Check that disparity a dictionary with keys "init" and range" where "init" is either: - an integer - a path to a grid with integer values :param disparity: disparity to check :raises SystemExit: if it does not meet requirements .. py:function:: add_disparity_grid(dataset: xarray.Dataset, col_disparity: dict, row_disparity: dict, attributes: dict = None, right: bool = False) -> xarray.Dataset Add disparity to dataset :param dataset: xarray dataset :param col_disparity: Disparity interval for columns :param row_disparity: Disparity interval for rows :param attributes: dictionary with attribute parameters :param right: indicates whether the disparity grid is added to the right dataset :return: dataset : updated dataset .. py:function:: get_min_max_disp_from_dicts(dataset: xarray.Dataset, disparity: dict, origin: pandora2d.types.Origin, step: pandora2d.types.Step, user_invalid_disp: int | float, right: bool = False) -> tuple[numpy.typing.NDArray, list, float | None] Transforms input disparity dicts with constant init into min/max disparity grids :param dataset: xarray dataset :param disparity: input disparity :param origin: origin of the grid :param step: step that separates two points in the disparity grid :param user_invalid_disp: user invalid disparity value :param right: indicates whether the disparity grid is added to the right dataset :return: 3D numpy array containing min/max disparity grids and list with disparity source .. py:function:: shift_disp_row_img(img_right: xarray.Dataset, dec_row: int) -> xarray.Dataset Return a Dataset that contains the shifted right images :param img_right: right Dataset image containing : - im : 2D (row, col) xarray.Datasat :param dec_row: the value of shifting for dispy :return: img_right_shift: Dataset containing the shifted image .. py:function:: get_margins_values(init_value: int | numpy.ndarray, range_value: int, margins: list) -> tuple[int, int] Generate the values of margins :param init_value: init value for disparity interval :param range_value: range value for disparity interval :param margins: necessary value for margins :return: Margins value .. py:function:: get_roi_processing(roi: dict, col_disparity: dict, row_disparity: dict, from_previous_run: bool = False) -> dict Return a roi which takes disparities into account. Update cfg roi with new margins. :param roi: roi in config file "col": {"first": , "last": }, "row": {"first": , "last": }, "margins": [, , , ] with margins : left, up, right, down :param col_disparity: init and range for disparities in columns. :param row_disparity: init and range for disparities in rows. :param from_previous_run: True when initial disparity grids come from a previous Pandora2D run (local coordinates); passed through to get_initial_disparity to skip ROI windowing. .. py:function:: remove_roi_margins(dataset: xarray.Dataset, cfg: dict) Remove ROI margins before saving output dataset :param dataset: dataset containing disparity row and col maps :param cfg: output configuration of the pandora2d machine .. py:function:: row_zoom_img(img: numpy.ndarray, ny: int, subpix: int, coords: xarray.Coordinates, ind: int, no_data: float | int, order: int = 1) -> xarray.Dataset Return a list that contains the shifted right images in row This method is temporary, the user can then choose the filter for this function :param img: image to shift :param ny: row number in data :param subpix: subpixel precision = (1 or pair number) :param coords: coordinates for output datasets :param ind: index of range(subpix) :param no_data: no_data value in img :param order: The order of the spline interpolation, default is 1. The order has to be in the range 0-5. :return: an array that contains the shifted right images in row .. py:function:: col_zoom_img(img: numpy.ndarray, nx: int, subpix: int, coords: xarray.Coordinates, ind: int, no_data: float | int, order: int = 1) -> xarray.Dataset Return a list that contains the shifted right images in col This method is temporary, the user can then choose the filter for this function :param img: image to shift :param nx: col number in data :param subpix: subpixel precision = (1 or pair number) :param coords: coordinates for output datasets :param ind: index of range(subpix) :param no_data: no_data value in img :param order: The order of the spline interpolation, default is 1. The order has to be in the range 0-5. :return: an array that contains the shifted right images in col .. py:function:: shift_subpix_img(img_right: xarray.Dataset, subpix: int, row: bool = True, order: int = 1) -> list[xarray.Dataset] Return an array that contains the shifted right images :param img_right: Dataset image containing the image im : 2D (row, col) xarray.Dataset :param subpix: subpixel precision = (1 or pair number) :param row: row to shift (otherwise column) :param order: The order of the spline interpolation, default is 1. The order has to be in the range 0-5. :return: an array that contains the shifted right images .. py:function:: shift_subpix_img_2d(img_right: xarray.Dataset, subpix: int, order: int = 1) -> list[xarray.Dataset] Return an array that contains the shifted right images in rows and columns :param img_right: Dataset image containing the image im : 2D (row, col) xarray.Dataset :param subpix: subpixel precision = (1 or pair number) :param column: column to shift (otherwise row) :param order: The order of the spline interpolation, default is 1. The order has to be in the range 0-5. :return: an array that contains the shifted right images .. py:function:: get_initial_disparity(disparity: dict, roi: dict | None = None, from_previous_run: bool = False) -> numpy.typing.NDArray | int Return initial disparity. When initial disparity is read from a file, nodata and infinite values are replaced by NaNs. When a ROI is provided and the raster is NOT from a previous run, only the pixels within the ROI are read, preventing border outliers from inflating the extrema used to compute ROI processing margins. When the raster comes from a previous run (``from_previous_run=True``), it is already cropped to the relevant zone in local coordinates, so the full raster is read regardless of the ROI. :param disparity: init and range for disparities in columns. :param roi: optional ROI dict with keys "row" and "col", each containing "first" and "last". :param from_previous_run: True when the disparity raster was produced by a previous Pandora2D run and is therefore stored in local (ROI-relative) coordinates. :return: initial disparity .. py:function:: get_extrema_disparity(init_value: numpy.typing.NDArray | float, range_value: int) -> tuple[int, int] Returns [min, max] disparity :param init_value: initial disparity :param range_value: disparity exploration value :return: [min disparity, max disparity] .. py:function:: convert_no_data(no_data: float | int) -> float | int If no_data is NaN or Inf, return -9999. Otherwise return no_data. :param no_data: no data value :return: updated no data value