utils.raster package

Submodules

utils.raster.dem_generator module

class utils.raster.dem_generator.DEMGenerator

Bases: object

Author:

Alberto M. Esmoris Pena

Class representing a Digital Elevation Model (DEM) generator for 3D point clouds.

__init__()

Initialize the DEM generator.

__call__(X, z, grid, method='linear')

Compute the DEM for the points in a 2D plane given by X and their corresponding elevation values given by z.

Parameters:
  • X – The coordinates of the points in the \((x, y)\) plane.

  • z – The point-wise elevation values.

  • grid – The points of the grid representing the domain of the DEM.

  • method – Whether "nearest", "linear", or "cubic". See SciPy griddata documentation.

Returns:

The generated grid representing the DEM.

Return type:

np.ndarray

utils.raster.grid_interpolator_2d module

class utils.raster.grid_interpolator_2d.GridInterpolator2D(domain, interpolation, iterations=1)

Bases: object

Author:

Alberto M. Esmoris Pena

Class representing an interpolator for bidimensional grids. Images are typically encoded as 2D grids with color components for each cell (pixel). The interpolation consists of two steps:

  1. Determining the cells of the grid (pixels) whose value must be

    interpolated.

  2. Interpolating those cells (pixels).

__init__(domain, interpolation, iterations=1)

Initialize the 2D grid interpolator.

Parameters:
  • domain (dict) – The specification of the domain that must be considered for interpolation.

  • interpolation (dict) – The interpolation specification.

  • iterations (int) – How many times compute the full interpolation procedure (including domain extraction at each iteration).

__call__(grid)

Interpolate the given 2D grid.

Parameters:

grid (np.ndarray) – The grid to be interpolated given as a matrix of \(M \times N\) decimal elements.

Returns:

The interpolated matrix of \(M \times N\) decimal elements.

Return type:

np.ndarray

compute_domain_mask(grid)

Compute the requested interpolation domain.

See GridInterpolator2D.compute_all_domain(), GridInterpolator2D.compute_target_domain(), GridInterpolator2D.compute_polygonal_contour_domain(), and GridInterpolator2D.compute_polygonal_contour_target_domain().

Parameters:

grid – The grid to be interpolated.

Rtype grid:

np.ndarray

Returns:

A boolean mask

Return type:

np.ndarray

compute_all_domain(grid)

Select all cells/pixels in the grid as the interpolation domain.

See GridInterpolator2D.compute_domain_mask() for a description of the input arguments and return.

compute_target_domain(grid)

Select all cells/pixels in the grid that satisfy the requested relational with respect to the given target value.

See GridInterpolator2D.compute_domain_mask() for a description of the input arguments and return.

compute_polygonal_contour_domain(grid, return_first_mask=False)

Select all cells/pixels inside the contour of the cells that satisfy the requested relational with respect to the given target value.

See GridInterpolator2D.compute_domain_mask() for a description of the input arguments and return.

Parameters:

return_first_mask (bool) – True to return the first mask computed on the input grid, False otherwise (default is False).

compute_polygonal_contour_target_domain(grid)

Select all cells/pixels inside teh contour of the cells that satisfy the requested relational with respect ot the given target value. Then, from the selected cells, preserve only those that satisfy the requested relational check.

See GridInterpolator2D.compute_domain_mask() for a description of the input arguments and return.

compute_interpolation(grid, domain_mask)

Compute the requested interpolation on the given grid considering the extracted domain mask.

Parameters:
  • grid (np.ndarray) – The grid to be interpolated which is also the grid with the reference values for the interpolation.

  • domain_mask (np.ndarray) – Boolean mask indicating with True the cells that must be interpolated.

Returns:

The updated grid (despite it is updated inplace) for fluent programming purposes.

Return type:

np.ndarray

static compute_relational_mask(grid, target_val, rel)

Compute a mask for the cells of the grid that satisfy the given relational.

Parameters:
  • grid (np.ndarray) – The grid whose cells must be considered.

  • target_val (int or float or list or str) – The target value. Use a string to specify NaN, e.g., "nan". Intervals and sets must be given as lists.

  • rel (str) – The relational to be checked. It can be "equals" (\(=\)), "not_equals" (\(\neq\)), "less_than" (\(<\)), "less_than_or_equal_to" (\(\leq\)), "greater_than" (\(>\)), "greater_than_or_equal_to" (\(\geq\)), "inside_open" (\(\in (a, b)\)), "inside_close" (\(\in [a, b]\)), "in" (\(\in\)), or "not_in" (\(\notin\)).

Returns:

The relational mask with True for selected cells and False for those that do not satisfy the relational.

Return type:

np.ndarray

compute_erosions(grid)

Compute the requested erosions in the given grid.

Parameters:

grid (np.ndarray) – Grid to be eroded. Note that it is expected to have values of 0 and 1 in its cells.

Returns:

Eroded grid.

Return type:

np.ndarray

compute_dilations(grid)

Compute the requested dilations in the given grid.

Parameters:

grid (np.ndarray) – Grid to be dilated. Note that it is expected to have values of 0 and 1 in its cells.

Returns:

Dilated grid.

Return type:

np.ndarray

Module contents

author:

Alberto M. Esmoris Pena

The raster package contains the logic for operations on rasters, e.g., interpolation of missing values or empty cells.