Observation values aggregation over shapes

This module processes layers of data containing geographic coordinates and observed values for a certain parameter (band) and returns records containing an identifier for a geographic shape and the value of the band aggregated over the shape.

class Record(value: Union[float, NoneType], prop: str)[source]
value: Optional[float]
prop: str
class MultiRecord(values: List[Union[float, NoneType]], prop: str)[source]
values: List[Optional[float]]
prop: str
class StatsCounter[source]
statistics = 'mean'
max_mem_used = 0
classmethod get_key_for_geography(shpfile: str, geography: Geography) Tuple[source]
classmethod prepare_stats(strategy: RasterizationStrategy, shpfile: str, affine: Affine, layer: Iterable, no_data, is_generator: bool) List[source]

Given a layer, i.e. a slice of a dataframe, and a shapefile returns an iterable of records, containing aggregated values of the observations over the shapes in the shapefile.

Parameters
  • no_data – Value taht is treated as missing value

  • strategy – Rasterization strategy to be used

  • shpfile – A path to shapefile to be used

  • affine – An optional affine transformation to be applied to the coordinates

  • layer – A slice of dataframe, containing coordinates and values

Returns

A list of statistics compute objects

classmethod process(strategy: RasterizationStrategy, shpfile: str, affine: Affine, layer: Iterable, geography: Geography, no_data=None) Iterable[Record][source]

Given a layer, i.e. a slice of a dataframe, and a shapefile returns an iterable of records, containing aggregated values of the observations over the shapes in the shapefile.

Parameters
  • no_data – Values that is treated as missing value

  • strategy – Rasterization strategy to be used

  • shpfile – A path to shapefile to be used

  • affine – An optional affine transformation to be applied to the coordinates

  • layer – A slice of dataframe, containing coordinates and values

  • geography – WHat type of geography is to be used: zip codes or counties

Returns

An iterable of records, containing an identifier of a certain shape with the aggregated value of the observation for this shape

classmethod process_layers(strategy: RasterizationStrategy, shpfile: str, affine: Affine, layers: List[Iterable], geography: Geography) Iterable[MultiRecord][source]

Given a layer, i.e. a slice of a dataframe, and a shapefile returns an iterable of records, containing aggregated values of the observations over the shapes in the shapefile.

Parameters
  • strategy – Rasterization strategy to be used

  • shpfile – A path to shapefile to be used

  • affine – An optional affine transformation to be applied to the coordinates

  • layers – A list of slices of dataframe, containing coordinates and values

  • geography – WHat type of geography is to be used: zip codes or counties

Returns

An iterable of records, containing an identifier of a certain shape with the aggregated value of the observation for this shape

classmethod process_layers_return_dict(strategy: RasterizationStrategy, shpfile: str, affine: Affine, layers: List[Iterable], geography: Geography) Dict[str, MultiRecord][source]

Given a layer, i.e. a slice of a dataframe, and a shapefile returns an iterable of records, containing aggregated values of the observations over the shapes in the shapefile.

Parameters
  • strategy – Rasterization strategy to be used

  • shpfile – A path to shapefile to be used

  • affine – An optional affine transformation to be applied to the coordinates

  • layers – A list of slices of dataframe, containing coordinates and values

  • geography – WHat type of geography is to be used: zip codes or counties

Returns

A List of records, containing an identifier of a certain shape with the aggregated value of the observation for this shape

exception AggregationError[source]
exception IncompatibleArgumentsError[source]