diff --git a/city_metrix/layers/world_pop.py b/city_metrix/layers/world_pop.py index d3b2aa6..a7e37d5 100644 --- a/city_metrix/layers/world_pop.py +++ b/city_metrix/layers/world_pop.py @@ -8,11 +8,13 @@ class WorldPop(Layer): """ Attributes: + year: year used for data retrieval spatial_resolution: raster resolution in meters (see https://github.com/stac-extensions/raster) """ - def __init__(self, spatial_resolution=100, **kwargs): + def __init__(self, year=2020, spatial_resolution=100, **kwargs): super().__init__(**kwargs) + self.year = year self.spatial_resolution = spatial_resolution def get_data(self, bbox): @@ -20,9 +22,9 @@ def get_data(self, bbox): dataset = ee.ImageCollection('WorldPop/GP/100m/pop') world_pop = ee.ImageCollection(dataset .filterBounds(ee.Geometry.BBox(*bbox)) - .filter(ee.Filter.inList('year', [2020])) + .filter(ee.Filter.inList('year', [self.year])) .select('population') - .sum() + .mean() ) data = get_image_collection(world_pop, bbox, self.spatial_resolution, "world pop") diff --git a/city_metrix/layers/world_pop_age_sex.py b/city_metrix/layers/world_pop_age_sex.py index 068abd6..ec3eda1 100644 --- a/city_metrix/layers/world_pop_age_sex.py +++ b/city_metrix/layers/world_pop_age_sex.py @@ -23,12 +23,12 @@ def __init__(self, agesex_classes=['M_70'], year=2020, spatial_resolution=100, * def get_data(self, bbox): # load population dataset = ee.ImageCollection('WorldPop/GP/100m/pop_age_sex') - world_pop = ee.ImageCollection(dataset - .filterBounds(ee.Geometry.BBox(*bbox)) - .filter(ee.Filter.inList('year', [self.year])) - .select(self.agesex_classes) - .sum() - ) + world_pop = dataset.filterBounds(ee.Geometry.BBox(*bbox))\ + .filter(ee.Filter.inList('year', [self.year]))\ + .select(self.agesex_classes)\ + .mean() + + world_pop = ee.ImageCollection(world_pop.reduce(ee.Reducer.sum()).rename('sum_age_sex_group')) data = get_image_collection(world_pop, bbox, self.spatial_resolution, "world pop age sex") - return data.population + return data.sum_age_sex_group