Skip to content

Commit

Permalink
Total pop is sum over list of agesex classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tedw0ng committed Sep 23, 2024
1 parent ea890e4 commit e9592c5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions city_metrix/layers/world_pop_age_sex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ee

from .layer import Layer, get_utm_zone_epsg, get_image_collection
from city_metrix.layers import WorldPop


class WorldPopAgeSex(Layer):
Expand All @@ -14,19 +15,27 @@ class WorldPopAgeSex(Layer):
spatial_resolution: raster resolution in meters (see https://github.com/stac-extensions/raster)
"""

def __init__(self, agesex_classes=['M_70'], year=2020, spatial_resolution=100, **kwargs):
def __init__(self, agesex_classes=[], year=2020, spatial_resolution=100, **kwargs):
super().__init__(**kwargs)
self.agesex_classes = agesex_classes
self.year = year
self.spatial_resolution = spatial_resolution

def get_data(self, bbox):
# load population
# If no agesex classes requested, return plain WorldPop
if not self.agesex_classes:
return WorldPop().get_data(bbox)

dataset = ee.ImageCollection('WorldPop/GP/100m/pop_age_sex')
world_pop = dataset.filterBounds(ee.Geometry.BBox(*bbox))\

# Sum over agesex classes
world_pop = ee.Image(0)
for agesex_class in self.agesex_classes:
tmp = dataset.filterBounds(ee.Geometry.BBox(*bbox))\
.filter(ee.Filter.inList('year', [self.year]))\
.select(self.agesex_classes)\
.select(agesex_class)\
.mean()
world_pop = world_pop.add(tmp)

world_pop = ee.ImageCollection(world_pop.reduce(ee.Reducer.sum()).rename('sum_age_sex_group'))

Expand Down

0 comments on commit e9592c5

Please sign in to comment.