mosstool.util.geo_match_pop

Geojson/shapefile format matches population

Module Contents

Functions

geo_coords

_gps_distance

GPS distance

_get_idx_range_in_bbox

Get all pixel_idx in a longitude and latitude bbox. For processing at the boundary, there are two modes: “loose” and “tight”

_get_pixel_info

Get the information of each WorldPop_pixel within the latitude and longitude range: {idx(i,j) : (Point(lon, lat), population)} Original data pixel size: lon_step: 0.0008333333, lat_step: -0.0008333333, ~ 100m * 100m

_upsample_pixels_unit

The original pixel is about 100 * 100, now it is divided equally into (100/n) * (100/n) The population is not evenly distributed among all cells, but is evenly divided by the cells covered by aoi.

_upsample_pixels_idiot_unit

The original pixel is about 100 * 100, now it is divided equally into (100/n) * (100/n) The population is divided equally among the cells

_get_poly_pop_unit

Estimate the polygonal box: take the population sum of the pixels falling inside it If aoi is too small so that no pixel falls within it, take the population of the pixel where it is located and multiply it by the area ratio of aoi to pixel.

_get_geo_pop

geo2pop

Args:

Data

API

mosstool.util.geo_match_pop.__all__

[‘geo2pop’]

mosstool.util.geo_match_pop.geo_coords(geo)
mosstool.util.geo_match_pop._gps_distance(LON1: Union[float, tuple[float, float]], LAT1: Union[float, tuple[float, float]], LON2: Optional[float] = None, LAT2: Optional[float] = None)

GPS distance

mosstool.util.geo_match_pop._get_idx_range_in_bbox(min_x: float, max_x: float, min_y: float, max_y: float, xy_bound: tuple[float, float, float, float], mode: Union[Literal[loose], Literal[tight]] = 'loose')

Get all pixel_idx in a longitude and latitude bbox. For processing at the boundary, there are two modes: “loose” and “tight”

mosstool.util.geo_match_pop._get_pixel_info(band, x_left: float, y_upper: float, x_step: float, y_step: float, bbox: tuple[float, float, float, float], padding: int = 20)

Get the information of each WorldPop_pixel within the latitude and longitude range: {idx(i,j) : (Point(lon, lat), population)} Original data pixel size: lon_step: 0.0008333333, lat_step: -0.0008333333, ~ 100m * 100m

mosstool.util.geo_match_pop._upsample_pixels_unit(partial_args: tuple[list[Any]], arg: tuple[tuple[int, float, float], tuple[tuple[int, int], tuple[shapely.geometry.Point, int]]])

The original pixel is about 100 * 100, now it is divided equally into (100/n) * (100/n) The population is not evenly distributed among all cells, but is evenly divided by the cells covered by aoi.

mosstool.util.geo_match_pop._upsample_pixels_idiot_unit(arg)

The original pixel is about 100 * 100, now it is divided equally into (100/n) * (100/n) The population is divided equally among the cells

mosstool.util.geo_match_pop._get_poly_pop_unit(partial_args: tuple[dict[tuple[int, int], tuple[shapely.geometry.Point, int]], float, float, float, float, float, float], geo_item: tuple[int, tuple[Any, tuple[float, float, float, float]]])

Estimate the polygonal box: take the population sum of the pixels falling inside it If aoi is too small so that no pixel falls within it, take the population of the pixel where it is located and multiply it by the area ratio of aoi to pixel.

mosstool.util.geo_match_pop._get_geo_pop(geos, pixel_idx2point_pop: dict[tuple[int, int], tuple[shapely.geometry.Point, int]], workers: int, x_left: float, y_upper: float, x_step: float, y_step: float, xy_gps_scale2: float, pixel_area: float, max_chunk_size: int, enable_tqdm: bool)
mosstool.util.geo_match_pop.geo2pop(geo_data: Union[geopandas.geodataframe.GeoDataFrame, geojson.FeatureCollection], pop_tif_path: str, enable_tqdm: bool = False, upsample_factor: int = 4, pop_in_aoi_factor: float = 0.7, multiprocessing_chunk_size: int = 500) Union[geopandas.geodataframe.GeoDataFrame, geojson.FeatureCollection]

Args:

  • geo_data (GeoDataFrame | FeatureCollection): polygon geo files.

  • pop_tif_path (str): path to population tif file.

  • enable_tqdm (bool): when enabled, use tqdm to show the progress bars.

  • upsample_factor (int): scaling factor for dividing the raw population data grid.

  • pop_in_aoi_factor (float): the proportion of the total population within the AOI.

  • multiprocessing_chunk_size (int): the maximum size of each multiprocessing chunk

Returns:

  • geo_data (GeoDataFrame | FeatureCollection): geo files with population.