src.eval.raster_grid_evaluator

Classes

RasterGridEvaluator(**kwargs)

class src.eval.raster_grid_evaluator.RasterGridEvaluator(**kwargs)
Author:

Alberto M. Esmoris Pena

Class to generate a raster-like 2D grid evaluating a given point cloud.

Variables:
  • plot_path (str) – The path to write the raster.

  • fnames (list of str) – The name of the features to be considered.

  • grids (list of dict) – The many grid specifications.

  • crs (str) – The coordinate reference system (CRS).

  • xres (float) – The cell size along the x-axis.

  • yres (float) – The cell size along the y-axis.

  • grid_iter_step (int) – How many rows at most must be considered per iteration when generating the raster-like grid.

  • reverse_rows (bool) – Whether to reverse the rows of the grid (True) or not (False).

  • radius_expr (str) – An expression defining the radius of the neighborhood centerd on each cell. In this expression, “l” represents the greatest cell size, i.e., \(\max \; \{\mathrm{xres}, \mathrm{yres}\}\).

  • nthreads (int) – How many threads must be used for the parallel computation of the grids of features. By default, a single thread is used (1). Also, note that -1 means as many threads as available cores.

static extract_eval_args(spec)

Extract the arguments to initialize/instantiate a

Parameters:

spec – The key-word specification containing the arguments.

Returns:

The arguments to initialize/instantiate a RasterGridEvaluator.

Return type:

dict

__init__(**kwargs)

Initialize/instantiate a RasterGridEvaluator.

Parameters:

kwargs – The attributes for the RasterGridEvaluator.

eval(pcloud)

Evaluate the point cloud as a raster-like 2D grid.

Parameters:

pcloud (PointCloud) – The point cloud to be evaluated.

Returns:

The raster grid obtained after computing the evaluation.

Return type:

RasterGridEvaluation

__call__(pcloud, **kwargs)

Evaluate with extra logic that is convenient for pipeline-based execution.

See evaluator.Evaluator.eval().

Parameters:

pcloud – The point cloud that must be evaluated through raster-like grid analysis.

digest_grids(X, F, fnames)

Generate the grids of features for the requested grid specifications.

Parameters:
  • X (np.ndarray) – The structure space matrix, i.e., matrix of point-wise coordinates.

  • F (np.ndarray) – The feature space matrix, i.e., matrix of point-wise features.

  • fnames (list of str) – The feature names, i.e., the name for each column of the feature space matrix F.

Returns:

The generated grids of features.

Return type:

list of np.ndarray

static digest_grid(X, Xi, kdt, radius, fnames, F, grid, width, height)

Generate the grid of features for a given grid specification.

Internally:

I The list of neighborhoods, where each neighborhood is

represented as a list of indices.

n_rows How many rows are being considered in the chunk to be digested.

Parameters:
  • X – The structure space representing the original point cloud or the globally filtered point cloud.

  • Xi – The points representing a chunk of the grid.

  • kdt – The KDTree representing the original structure space (X).

  • radius – The radius for the spherical neighborhoods centered at each cell of the grid.

  • fnames – The name for each column (feature) in the matrix F.

  • F – The matrix of features.

  • grid – The grid specification to be digested.

  • width – The width of the grid in number of cells.

  • height – The height of the grid in number of cells.

Returns:

The generated grid of features.

Return type:

np.ndarray

static digest_standard_grid(X, Xi, kdt, radius, fnames, F, grid, height)

Generate a grid of features for a given grid specification in the standard way. This method provides RasterGridEvaluator.digest_grid() with the standard logic to handle the general case.

See RasterGridEvaluator.digest_grid().

eval_args_from_state(state)

Obtain the arguments to call the RasterGridEvaluator form the current pipeline’s state.

Parameters:

state (SimplePipelineState) – The pipeline’s state.

Returns:

The dictionary of arguments for calling RasterGridEvaluator

Return type:

dict

static reduce_mean(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the mean value in the neighborhood.

Parameters:
  • F (np.ndarray) – The feature space matrix for \(m\) points with \(n_f\) features. Note that here \(n_f\) does not represent the dimensionality of the original point cloud but the one where only the requested features are considered.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel – Not considered at all.

  • target – The value that must be searched when using a binary mask, recount, or relative recount strategy.

  • th – The threshold of target cases that must be inside the cell to consider a \(1\) for the binary mask.

  • cache – The cache with pre-computed information needed for the reduction. Note that it might be None if it is not needed by the reduce strategy. Its type also depends on the strategy.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_median(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the median value in the neighborhood.

Parameters:
  • F (np.ndarray) – The feature space matrix for \(m\) points with \(n_f\) features. Note that here \(n_f\) does not represent the dimensionality of the original point cloud but the one where only the requested features are considered.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel – Not considered at all.

  • target – Not considered at all.

  • th – Not considered at all.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_min(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the min value in the neighborhood.

Parameters:
  • F (np.ndarray) – The feature space matrix for \(m\) points with \(n_f\) features. Note that here \(n_f\) does not represent the dimensionality of the original point cloud but the one where only the requested features are considered.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel – Not considered at all.

  • target – Not considered at all.

  • th – Not considered at all.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_max(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the max value in the neighborhood.

Parameters:
  • F (np.ndarray) – The feature space matrix for \(m\) points with \(n_f\) features. Note that here \(n_f\) does not represent the dimensionality of the original point cloud but the one where only the requested features are considered.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel – Not considered at all.

  • target – Not considered at all.

  • th – Not considered at all.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_binary_mask(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction yields a zero (0) if there are not enough points in the neighborhood matching the target, one (1) otherwise.

Parameters:
  • F (np.ndarray) – The feature space matrix for \(m\) points with \(n_f\) features. Note that here \(n_f\) does not represent the dimensionality of the original point cloud but the one where only the requested features are considered.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel (callable) – The relational (as a binary function) that must be applied to compare the values against the target.

  • target – The value that must be matched.

  • th – The threshold of target cases that must be inside the cell to consider a \(1\) for the binary mask.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_binary_mask_nofeats(F, I, k, rel, target, th, cache)

Reduce the given points on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction yields a zero (0) if there are not enough points in the neighborhood, one (1) otherwise.

Parameters:
  • F – Not considered at all.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel – Not considered at all.

  • target – Not considered at all.

  • th – The threshold for the number of points that must be inside the cell to consider a \(1\) for the binary mask.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_recount(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the number of points inside the cell matching the given target.

Parameters:
  • F (np.ndarray) – The feature space matrix for \(m\) points with \(n_f\) features. Note that here \(n_f\) does not represent the dimensionality of the original point cloud but the one where only the requested features are considered.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel (callable) – The relational (as a binary function) that must be applied to compare the values against the target.

  • target – The value that must be matched.

  • th – Not considered at all.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_recount_nofeats(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the number of points inside the cell.

Parameters:
  • F – Not considered at all.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel – Not considered at all.

  • target – Not considered at all.

  • th – Not considered at all.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_relative_recount(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the number of points inside the cell matching the given target, normalized by the number of points inside the cell.

Parameters:
  • F (np.ndarray) – The feature space matrix for \(m\) points with \(n_f\) features. Note that here \(n_f\) does not represent the dimensionality of the original point cloud but the one where only the requested features are considered.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel (callable) – The relational (as a binary function) that must be applied to compare the values against the target.

  • target – The value that must be matched.

  • th – Not considered at all.

  • cache – Not considered at all.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static reduce_relative_recount_nofeats(F, I, k, rel, target, th, cache)

Reduce the given features (F) on the given neighborhoods (I) for the k-th cell of the raster that corresponds with the k-th neighborhood. The reduction takes the number of points inside the cell, normalized by the max number of points inside any neighborhood.

Parameters:
  • F – Not considered at all.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • k (int) – The index representing the cell that corresponds with the \(k\)-th neighborhood.

  • rel – Not considered at all.

  • target – Not considered at all.

  • th – Not considered at all.

  • cache (int) – The max number of points inside the most populated neighborhood.

Returns:

The vector after the reduction (reductions to scalars are understood as vectors with 1 component).

Return type:

np.ndarray or list

static precompute_max_neighbors(F, I, rel, target, th)

Pre-compute the number of neighborhoods of the most populated neighborhood.

Parameters:
  • F – Not considered at all.

  • I (list of list of int) – List of neighborhoods. Each \(i\)-th neighborhood \(I_i\) is a list (i.e., mutable tuple) representing the indices of the points in the neighborhood. Note that each list inside the list can have a different number of neighbors.

  • rel – Not considered at all.

  • target – Not considered at all.

  • th – Not considered at all.

Returns:

Max number of points inside the most populated neighborhood.

Return type:

int

apply_global_filter(X, F, pcloud)

Filter the given structure and feature spaces at a global level, i.e., for all rasters and not only for a particular one.

Parameters:
  • X (np.ndarray) – The structure space matrix, i.e., matrix of point-wise coordinates.

  • F (np.ndarray or None) – The feature space matrix, i.e., matrix of point-wise features.

  • pcloud (PointCloud) – The point cloud being filtered. Note that the point cloud object will not be filtered. Nonetheless, its data is necessary to apply the filter (e.g., non evaluated features might be considered by the filter).

Returns:

The filtered structure and feature spaces.

Return type:

tuple of np.ndarray

static filter(val, cond, mask)

Apply the given conditional filter to the given mask.

Parameters:
  • val (np.ndarray) – The vector of values considered by the filter.

  • cond (dict) – The condition specification governing the filter. See the conditions argument of PointCloudSampler.filter_support_points() for further details.

  • mask (np.ndarray) – The boolean mask representing the composition of conditions that defines the full filter, at its current state.

Returns:

The updated boolean filter mask.

Return type:

np.ndarray