revrt.spatial_characterization.stats.ComputableStats#
- class ComputableStats(base_stats=None, percentiles=None, fractional_stats=None)[source]#
Bases:
object
A class to represent computable statistics for zonal stats
- Parameters:
base_stats (iterable of
str
, optional) – Iterable of “base” statistics to compute (i.e. not fractional or percentile). By default,None
.percentiles (
dict
, optional) – Dictionary mapping the percentile stat name to the int or float representing the percentile that can be passed tonp.percentile()
. By default,None
.fractional_stats (iterable of
str
, optional) – One or mre stats from theFractionalStat
enum to compute. By default,None
.
Methods
computed_base_stats
(processed_raster[, ...])Compute statistics on array
computed_fractional_stats
(zone, ...[, ...])Compute fractional statistics on array
computed_percentiles
(processed_raster)Generate percentile statistics for array
from_iter
([stats])Create a ComputableStats object from an iterable of stats
lazy_pixel_count
(processed_raster)Compute pixel counts from a raster
Attributes
Dict with empty stat values
- lazy_pixel_count(processed_raster)[source]#
Compute pixel counts from a raster
The output dictionary will be empty if this stats collection does not contain any stats that require a pixel count.
- Parameters:
processed_raster (array-like) – List or array of data to compute pixel counts from. This collection can contain NaN values, which will be ignored in the final output.
- Returns:
dict
– Dictionary where keys are the unique array entries and the values are the counts for each entry. This dictionary will be empty if this stats collection does not contain any stats that require a pixel count.
- computed_base_stats(processed_raster, category_map=None, **kwargs)[source]#
Compute statistics on array
- Parameters:
processed_raster (array-like) – Array to compute statistics for. This collection can contain NaN values, which will be ignored in the final output.
category_map (
dict
, optional) – Dictionary mapping raster values to new names. If given, this mapping will be applied to the pixel count dictionary, so you can use it to map raster values to human-readable category names. By default,None
.**kwargs – Extra keyword-argument pairs to pass to statistic computation functions. Currently this is only necessary for the nodata stat, which requires the following extra parameters:
- masked_raster: Raster masked to zone, but still
containing the “nodata” value (i.e. it’s not masked out with NaNs).
- nodata: Value representing nodata that will be
counted for this statistic.
- Returns:
dict
– Dictionary of computed statistics.
- computed_fractional_stats(zone, processed_raster, transform, nodata=None, category_map=None)[source]#
Compute fractional statistics on array
- Parameters:
zone (
shapely.geometry
) – Geometry object representing the zone to compute statistics over.processed_raster (array-like) – Array to compute statistics for. This collection can contain NaN values, which will be ignored in the final output.
transform (
affine.Affine
) – Affine transform object representing the raster transformation. This is used to compute the raster shapes for statistics computations as well as the pixel area for each pixel value in the raster.nodata (
int | float
, optional) – Value representing “nodata” in the array. These values in the raster will be ignored and will not contribute to the statistics and will not be reported. By default,None
.category_map (
dict
, optional) – Optional mapping for raster values. If given, the outputs will be labeled using the categories in this mapping instead of the raster values directly. The map does not have to be exhaustive - missing values will just be reported using the raw array value. By default,None
.
- Returns:
dict
– Dictionary of computed fractional statistics. The keys are the names of the statistics in theFractionalStat
enum and the values are the computed statistics.
- computed_percentiles(processed_raster)[source]#
Generate percentile statistics for array
- Parameters:
processed_raster (array-like) – Array to compute percentiles for.
- Yields:
str
– Name of percentile statint | float
– Value representing that percentile in the array.
- classmethod from_iter(stats=None)[source]#
Create a ComputableStats object from an iterable of stats
- Parameters:
stats (
str | iterable
ofstr
, optional) – Names of all statistics to compute. Statistics must be one of the members ofStat
orFractionalStat
, or must start with thepercentile_
prefix and end with an int or float representing the percentile to compute (e.g.percentile_10.5
). If only one statistic is to be computed, you can provide it directly as a string. Otherwise, provide a list of statistic names or a string with the names separated by a space. You can also provide the string"ALL"
or"*"
to specify that all statistics should be computed. If no input, empty input, orNone
is provided, then only the base stats (“count”, “min”, “max”, “mean”) are configured. To summarize, all of the following are valid inputs:stats="*"
orstats="ALL"
orstats="All"
stats="min"
stats="min max"
stats=["min"]
stats=["min", "max", "percentile_10.5"]
By default,
None
.- Returns:
ComputableStats
– An initializedComputableStats
object.- Raises:
revrtValueError – If one or more input stats are not known.