hazimp.aggregate
¶
Aggregating impact data into a chloropleth map.
Module Contents¶
Functions¶
|
Aggregate to geospatial boundaries using joins on attributes and save to |
|
Categorise aggregated field values into discrete intervals. |
|
Aggregate the impact data contained in a pandas.DataFrame |
Attributes¶
- hazimp.aggregate.LOGGER¶
- hazimp.aggregate.DRIVERS¶
- hazimp.aggregate.COLNAMES¶
- hazimp.aggregate.loss_categories¶
- hazimp.aggregate.aggregate_functions = ['mean', 'min', 'max']¶
- hazimp.aggregate.aggregate_label¶
- hazimp.aggregate.choropleth(dframe, boundaries, impactcode, bcode, filename, fields, categories, categorise) bool ¶
Aggregate to geospatial boundaries using joins on attributes and save to file.
- Parameters:
dframe – pandas.DataFrame containing point data to be aggregated
boundaries (str) – File name of a geospatial dataset that contains geographical boundaries to serve as aggregation boundaries
impactcode (str) – Field name in the dframe to aggregate by
bcode (str) – Corresponding field name in the geospatial dataset.
filename (str) – Destination file name. Must have a valid extension of shp, json or gpkg. See import fiona; fiona.supported_drivers for a complete list of options, but at this time only three have been implemented.
categories (boolean) – Add columns for the number of buildings in each damage state defined in the ‘Damage state’ attribute. This requires that a ‘categorise` job has been included in the pipeline, which in turn requires the bins and labels to be defined in the job configuration.
categorise (dict) – categorise job attributes
NOTE:
Presently, using `categories`=True will not do any categorisation of the mean damage index for the aggregation areas.
- Parameters:
fields (dict) – A dict with keys of valid column names (from the DataFrame) and values being lists of aggregation functions to apply to the columns.
For example:
fields = {'structural': ['mean']}
See https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#aggregation for more guidance on using aggregation with DataFrames
- hazimp.aggregate.aggregate_categorisation(aggregate, categorise: dict, fields: dict, field_name: str)¶
Categorise aggregated field values into discrete intervals.
- Parameters:
aggregate – pandas.DataFrame containing aggregated data
categorise – categorise job attributes
fields – fields to aggregate
field_name – name of categorised column
- hazimp.aggregate.aggregate_loss_atts(dframe, groupby=None, kwargs=None)¶
Aggregate the impact data contained in a pandas.DataFrame
- Parameters:
dframe – pandas.DataFrame that contains impact data
groupby (str) – A column in the DataFrame that corresponds to regions by which to aggregate data
kwargs (dict) – A dict with keys of valid column names (from the DataFrame) and values being lists of aggregation functions to apply to the columns.
For example:
kwargs = {'REPLACEMENT_VALUE': ['mean', 'sum'], 'structural': ['mean', 'std']}
See https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#aggregation for more guidance on using aggregation with DataFrames
- Returns:
A pandas.GroupBy object.