utils
aggregate_climate_to_hierarchy(data: pd.DataFrame, hierarchy: pd.DataFrame) -> pd.DataFrame
Create all aggregate climate values for a given hierarchy from most-detailed data.
Parameters
data The most-detailed climate data to aggregate. hierarchy The hierarchy to aggregate the data to.
Returns
pd.DataFrame The climate data with values for all levels of the hierarchy.
Source code in src/climate_data/aggregate/utils.py
build_bounds_map(raster_template: rt.RasterArray, shape_values: list[tuple[Polygon | MultiPolygon, int]]) -> dict[int, tuple[slice, slice]]
Build a map of location IDs to buffered slices of the raster template.
Parameters
raster_template The raster template to build the bounds map for. shape_values A list of tuples where the first element is a shapely Polygon or MultiPolygon in the CRS of the raster template and the second element is the location ID of the shape.
Returns
dict[int, tuple[slice, slice]] A dictionary mapping location IDs to a tuple of slices representing the bounds of the location in the raster template. The slices are buffered by 10 pixels to ensure that the entire shape is included in the mask.
Source code in src/climate_data/aggregate/utils.py
build_location_masks(hierarchy: str, block_key: str, pm_data: PopulationModelData) -> tuple[dict[str, slice], dict[int, tuple[slice, slice, npt.NDArray[np.bool_]]]]
Build location masks for each location in the hierarchy.
Parameters
hierarchy The name of the hierarchy to build location masks for. Must be one of of the keys of the HIERARCHY_MAP constant. pm_data PopulationModelData object to load the population model data.
Returns
tuple[dict[int, tuple[slice, slice]], npt.NDArray[np.uint32]] The first element is a dictionary mapping location IDs to a tuple of slices representing the bounds of the location in the mask. This is useful for subseting the mask and data arrays before processing as downstream operations scale with the number of pixels in the mask. The second element is the mask itself, a 2D array of uint32 values where each location ID is represented by a unique integer value.
Source code in src/climate_data/aggregate/utils.py
get_bbox(raster: rt.RasterArray, crs: str | None = None) -> shapely.Polygon
Get the bounding box of a raster array.
Parameters
raster The raster array to get the bounding box of. crs The CRS to return the bounding box in. If None, the bounding box is returned in the CRS of the raster.
Returns
shapely.Polybon The bounding box of the raster in the CRS specified by the crs parameter.