RasterPop

population.rasterpop.RasterPop(self, filepath)

Prepare raster population inputs for transport analysis.

This class is suited to working with rastered population data (e.g. gridded population estimates).

Parameters

Name Type Description Default
filepath Union[str, bytes, os.PathLike] File path to population data required

Attributes

Name Type Description
pop_gdf gpd.GeoDataFrame A geopandas dataframe of the input data, with gridded geometry. This is in the same CRS as the input raster data.
centroid_gdf gpd.GeoDataFrame A geopandas dataframe of grid centroids, converted to EPSG:4326 for transport analysis.

Raises

Type Description
FileNotFoundError When filepath is not a file or can not be found.

Methods

Name Description
get_pop Get population data.
plot Plot population data.

get_pop

population.rasterpop.RasterPop.get_pop(aoi_bounds, aoi_crs=None, round=False, threshold=None, var_name='population', urban_centre_bounds=None, urban_centre_crs=None, band=1)

Get population data.

Parameters

Name Type Description Default
aoi_bounds Type[Polygon] A shapely polygon defining the boundary of the area of interest. Assumed to be in the same CRS as the rastered population data. If it is different, set aoi_crs to the CRS of this boundary. required
aoi_crs str CRS string for aoi_bounds (e.g. “EPSG:4326”), by default None which means it is assumed to have the same CRS as the population data. None
round bool Round population estimates to the nearest whole integer. False
threshold Union[int, float] Threshold population estimates, where values below the set threshold will be set to nan, by default None which means no thresholding will occur. None
var_name str The variable name, by default “population” 'population'
urban_centre_bounds Type[Polygon] Polygon defining an urban centre boundary, by default None meaning information concerning whether the grid resides within the urban centre will not be added. None
urban_centre_crs str The urban centre polygon CRS, by default None meaning this is the same CRS as the input raster data. Only used when urban_centre_bounds is set. None
band int The band to select from the raster, by default 1. 1

Returns

Type Description
gpd.GeoDataFrame A geopandas dataframe of the input data, with gridded geometry. This is in the same CRS as the input raster data.
centroid_gdf A geopandas dataframe of grid centroids, converted to EPSG:4326 for transport analysis.

plot

population.rasterpop.RasterPop.plot(which='folium', save=None, **kwargs)

Plot population data.

Parameters

Name Type Description Default
which str Package to use for plotting. Must be one of {“matplotlib”, “cartopy”, “folium”}, by default “folium”. 'folium'
save str Filepath to save file, with the file extension, by default None meaning a file will not be saved. None
kwargs dict Extra arguments passed to plotting functions to configure the plot styling. See Notes for more support. {}

Returns

Type Description
Union[folium.Map, Type[GeoAxes], plt.Axes, None] A folium map is returned when the folium backend is used. A matplotlib Axes object is returned when the matplotlib backend is used. A matplotlib/cartopy GeoAxes object is returned when the cartopy backend is used. None will be returned when saving to file.

Raises

Type Description
ValueError Unexpected value of which.
NotImplementedError When plot is called without reading data.

Notes

Calling help as follows will provide more insights on possible kwarg arguments for the valid plotting backends:

  • Folium backend: help(RasterPop._plot_folium)
  • Matplotlib backend: help(RasterPop._plot_matplotlib)
  • Cartopy backend: help(RasterPop._plot_cartopy)