pixel_main
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/idd_forecast_mbp/map_to_admin_2/pixel_main.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.
Source code in src/idd_forecast_mbp/map_to_admin_2/pixel_main.py
load_raking_shapes(full_aggregation_hierarchy: str, bounds: tuple[float, float, float, float]) -> gpd.GeoDataFrame
Load shapes for a full aggregation hierarchy within given bounds.
Parameters
full_aggregation_hierarchy The full aggregation hierarchy to load (e.g. "gbd_2021") bounds The bounds to load (xmin, ymin, xmax, ymax)
Returns
gpd.GeoDataFrame The shapes for the given hierarchy and bounds
Source code in src/idd_forecast_mbp/map_to_admin_2/pixel_main.py
to_raster(ds: xr.DataArray, no_data_value: float | int, lat_col: str = 'lat', lon_col: str = 'lon', crs: str = 'EPSG:4326') -> rt.RasterArray
Convert an xarray DataArray to a RasterArray.
Parameters
ds The xarray DataArray to convert. no_data_value The value to use for missing data. This should be consistent with the dtype of the data. lat_col The name of the latitude coordinate in the dataset. lon_col The name of the longitude coordinate in the dataset. crs The coordinate reference system of the data.
Returns
rt.RasterArray The RasterArray representation of the input data.