onstove.OnStove.create_layer#
- OnStove.create_layer(variable: str, name: str | None = None, labels: dict[str, str] | None = None, cmap: dict[str, str] | None = None, metric: str = 'mean', nodata: float | int | None = None) tuple[RasterLayer, dict[int, str], dict[int, str]] [source]#
Creates a
RasterLayer
from a column of the main GeoDataFrame (gdf
).If the data is categorical, then a rasterized version of the data is created, using integers in asscending order for the diffenrent unique categories found. A
codes
and acmap
dictionaries will be returned containing the names and color equivalent of the numbered categories.If the data is non-categorical, the source data will be rasterized into the
RasterLayer
using one of the availablemetrics
.- Parameters:
- variable: str
The column name from the
gdf
to use.- name: str, optional
The name to give to the
RasterLayer
.- labels: dictionary of str key-value pairs, optional
Dictionary with the keys-value pairs to use for the data categories. It is only used for categorical data.
>>> labels = {'Biogas and Electricity': 'Electricity and Biogas', ... 'Collected Traditional Biomass': 'Biomass', ... 'Collected Improved Biomass': 'Biomass ICS (ND)', ... 'Traditional Charcoal': 'Charcoal', ... 'Biomass Forced Draft': 'Biomass ICS (FD)', ... 'Pellets Forced Draft': 'Pellets ICS (FD)'}
- cmap: dictionary of str key-value pairs, optional
Dictionary with the colors to use for each data category. It is only used for categorical data.
>>> cmap = {'Biomass ICS (ND)': '#6F4070', ... 'LPG': '#66C5CC', ... 'Biomass': '#FFB6C1', ... 'Biomass ICS (FD)': '#af04b3', ... 'Pellets ICS (FD)': '#ef02f5', ... 'Charcoal': '#364135', ... 'Charcoal ICS': '#d4bdc5', ... 'Biogas': '#73AF48', ... 'Biogas and Biomass ICS (ND)': '#F6029E', ... 'Biogas and Biomass ICS (FD)': '#F6029E', ... 'Biogas and Pellets ICS (FD)': '#F6029E', ... 'Biogas and LPG': '#0F8554', ... 'Biogas and Biomass': '#266AA6', ... 'Biogas and Charcoal': '#3B05DF', ... 'Biogas and Charcoal ICS': '#3B59DF', ... 'Electricity': '#CC503E', ... 'Electricity and Biomass ICS (ND)': '#B497E7', ... 'Electricity and Biomass ICS (FD)': '#B497E7', ... 'Electricity and Pellets ICS (FD)': '#B497E7', ... 'Electricity and LPG': '#E17C05', ... 'Electricity and Biomass': '#FFC107', ... 'Electricity and Charcoal ICS': '#660000', ... 'Electricity and Biogas': '#f97b72', ... 'Electricity and Charcoal': '#FF0000'}
- metric: str, default ‘mean’
Metric to use to aggregate data. It is only used for non-categorical data. Available metrics:
mean
: average value between technologies used in the same cell.total
: the total value of the data accounting for all households in the cell.per_100k
: the values are calculated per 100 thousand population withing each cell.per_household
: average value per househol in each cell.
- nodata: float or int
Defines nodata values to be ignored by the function.
- Returns:
- raster: RasterLayer
The :class:RasterLayer object.
- codes: dictionary of int-str pairs
Contains the name equivalent to therasterized data (used if the data is categorical).
- cmap: dictionary of int-str pairs
A modified cmap containing the color s equivalent to the rasterized data (used if the data is categorical).