Calculation base classes

class pyForMetrix.metrix.FileMetrics(lasfiles, silent=True, pbars=True)
__init__(lasfiles, silent=True, pbars=True)

Class to calculate metrics on a file basis

Parameters:
  • lasfileslist of input las-Files to consider. Note that the scanning (finding the points inside the plots) can be sped up siginificantly by providing .lax-Files, which can be generated e.g. using lasindex, part of the LASTools (https://rapidlasso.com/lastools/, proprietory software with free/open components).

  • silentboolean whether to print output or not

  • pbarsboolean whether to display progress bars or not

calc_custom_metrics(metrics: MetricCalculator, metric_options=None)

Calculates given metrics for points contained in the polygons given during construction of this class.

Parameters:
  • metrics – a single pyForMetrix.metricCalculators.MetricCalculator instance or a list of such classes

  • metric_options – a list of dict s with options (kwargs) for each MetricCalculator, or None.

Returns:

a pandas.DataFrame containing the metrics for each polygon in the input.

class pyForMetrix.metrix.Metrics
class pyForMetrix.metrix.PlotMetrics(lasfiles, plot_polygons, silent=True, pbars=True)
__init__(lasfiles, plot_polygons, silent=True, pbars=True)

Class to calculate metrics on a plot (polygon) basis

Parameters:
  • lasfileslist of input las-Files to consider. Note that the scanning (finding the points inside the plots) can be sped up siginificantly by providing .lax-Files, which can be generated e.g. using lasindex, part of the LASTools (https://rapidlasso.com/lastools/, proprietory software with free/open components).

  • plot_polygonsgeopandas.GeoDataFrame array containing the geometries (polygons) of interest

  • silentboolean whether to print output or not

  • pbarsboolean whether to display progress bars or not

calc_custom_metrics(metrics: MetricCalculator, metric_options=None)

Calculates given metrics for points contained in the polygons given during construction of this class.

Parameters:
  • metrics – a single pyForMetrix.metricCalculators.MetricCalculator instance or a list of such classes

  • metric_options – a list of dict s with options (kwargs) for each MetricCalculator, or None.

Returns:

a pandas.DataFrame containing the metrics for each polygon in the input.

class pyForMetrix.metrix.RasterMetrics(points, raster_size, percentiles=numpy.arange, p_zabovex=None, silent=True, pbars=True, raster_min=None, raster_max=None, origin=None)
__init__(points, raster_size, percentiles=numpy.arange, p_zabovex=None, silent=True, pbars=True, raster_min=None, raster_max=None, origin=None)

Class to calculate metrics on a raster (cell) basis.

Parameters:
  • pointsdict containing keys ‘points’ and potentially other attributes, which are :numpy:ndarray s containing the points.

  • raster_sizefloat raster cell size used for calculation

  • percentiles – deprecated

  • p_zabovex – deprecated

  • silent – deprecated

  • pbarsbool whether to show progress bars or not

  • raster_minnumpy.ndarray of shape (2,) with the minimum x/y coordinates for the raster (default: derive from point cloud)

  • raster_maxnumpy.ndarray of shape (2,) with the maximum x/y coordinates for the raster (default: derive from point cloud)

  • originnumpy.ndarray of shape (2,) with the origin x/y coordinates (pixel center) for the raster (default: same as raster_min)

calc_custom_metrics(metrics: MetricCalculator, metric_options=None)

Calculates the given metrics on the point cloud this class was initialized on.

Parameters:
  • metrics – a single pyForMetrix.metricCalculators.MetricCalculator instance or a list of such classes

  • metric_options – a list of dict`s with options (kwargs) for each `MetricCalculator, or None.

Returns:

An xarray.Dataset containing the metric(s) in a raster grid

calc_custom_metrics_parallel(metrics, n_chunks=16, n_processes=4, pbar_position=0, multiprocessing_point_threshold=10000, metric_options=None)

Calculates the given metrics on the point cloud this class was initialized on, in parallel. Parallelization is achieved by spawning multiple processes for subsets of the raster cells. Note that it might be faster to parallelize over input datasets, if they are chunked.

Parameters:
  • metrics – see calc_custom_metrics()

  • n_chunks – number of chunks to split the valid raster cells into (more chunks decrease memory usage)

  • n_processes – number of processes to work on the chunks (more processes increase memory usage)

  • pbar_position – deprecated

  • multiprocessing_point_threshold – number of raster cells at which multiprocessing should be started. For relatively small datasets, the overhead of spawning extra processes outweights the benefit. Ideal setting depends on the features that are calculated

  • metric_options – see calc_custom_metrics()

Returns:

An xarray.Dataset containing the metric(s) in a raster grid