From e90a88ad29beb871f026ce39201b3c3bc6e79c12 Mon Sep 17 00:00:00 2001 From: Kenn Cartier Date: Fri, 13 Dec 2024 22:35:53 -0800 Subject: [PATCH] Added further testing --- city_metrix/layers/albedo.py | 7 +++++-- city_metrix/layers/alos_dsm.py | 3 ++- city_metrix/layers/land_surface_temperature.py | 3 ++- city_metrix/layers/layer.py | 14 ++++++++++++++ city_metrix/layers/nasa_dem.py | 3 ++- city_metrix/layers/ndvi_sentinel2_gee.py | 5 +++-- city_metrix/layers/tree_canopy_height.py | 3 ++- city_metrix/layers/tree_cover.py | 3 ++- city_metrix/layers/world_pop.py | 4 +++- 9 files changed, 35 insertions(+), 10 deletions(-) diff --git a/city_metrix/layers/albedo.py b/city_metrix/layers/albedo.py index dc1780a..ff46bd0 100644 --- a/city_metrix/layers/albedo.py +++ b/city_metrix/layers/albedo.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class Albedo(Layer): """ @@ -115,7 +115,10 @@ def calc_s2_albedo(image): ## S2 MOSAIC AND ALBEDO dataset = get_masked_s2_collection(ee.Geometry.BBox(*bbox), self.start_date, self.end_date) s2_albedo = dataset.map(calc_s2_albedo) - albedo_mean = s2_albedo.reduce(ee.Reducer.mean()) + albedo_mean = (s2_albedo + .map(set_bilinear_resampling) + .reduce(ee.Reducer.mean()) + ) albedo_mean_ic = ee.ImageCollection(albedo_mean) data = get_image_collection( diff --git a/city_metrix/layers/alos_dsm.py b/city_metrix/layers/alos_dsm.py index c22df82..1e06066 100644 --- a/city_metrix/layers/alos_dsm.py +++ b/city_metrix/layers/alos_dsm.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class AlosDSM(Layer): @@ -18,6 +18,7 @@ def get_data(self, bbox): alos_dsm_ic = ee.ImageCollection(alos_dsm .filterBounds(ee.Geometry.BBox(*bbox)) + .map(set_bilinear_resampling) .select('DSM') .mean() ) diff --git a/city_metrix/layers/land_surface_temperature.py b/city_metrix/layers/land_surface_temperature.py index 93888ce..3512876 100644 --- a/city_metrix/layers/land_surface_temperature.py +++ b/city_metrix/layers/land_surface_temperature.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class LandSurfaceTemperature(Layer): """ @@ -35,6 +35,7 @@ def apply_scale_factors(image): .filterBounds(ee.Geometry.BBox(*bbox)) .map(cloud_mask) .map(apply_scale_factors) + .map(set_bilinear_resampling) .reduce(ee.Reducer.mean()) ) diff --git a/city_metrix/layers/layer.py b/city_metrix/layers/layer.py index 3d2829f..c365f64 100644 --- a/city_metrix/layers/layer.py +++ b/city_metrix/layers/layer.py @@ -323,6 +323,20 @@ def get_stats_funcs(stats_func): return [stats_func] +def set_bilinear_resampling(data): + if isinstance(data, ee.ImageCollection): + resampled = data.map(_assign_bilinear_interpolation) + else: + resampled = data.resample('bilinear') + + return resampled + + +def _assign_bilinear_interpolation(dataset): + data = dataset.resample('bilinear') + return data + + def get_image_collection( image_collection: ImageCollection, bbox: Tuple[float], diff --git a/city_metrix/layers/nasa_dem.py b/city_metrix/layers/nasa_dem.py index d3840d3..6ed3c28 100644 --- a/city_metrix/layers/nasa_dem.py +++ b/city_metrix/layers/nasa_dem.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class NasaDEM(Layer): @@ -18,6 +18,7 @@ def get_data(self, bbox): nasa_dem_elev = (ee.ImageCollection(nasa_dem) .filterBounds(ee.Geometry.BBox(*bbox)) + .map(set_bilinear_resampling) .select('elevation') .mean() ) diff --git a/city_metrix/layers/ndvi_sentinel2_gee.py b/city_metrix/layers/ndvi_sentinel2_gee.py index b31021d..16a953c 100644 --- a/city_metrix/layers/ndvi_sentinel2_gee.py +++ b/city_metrix/layers/ndvi_sentinel2_gee.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class NdviSentinel2(Layer): """" @@ -33,8 +33,9 @@ def calculate_ndvi(image): return image.addBands(ndvi) s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED") + s2_resampled = set_bilinear_resampling(s2) - ndvi = (s2 + ndvi = (s2_resampled .filterBounds(ee.Geometry.BBox(*bbox)) .filterDate(start_date, end_date) .map(calculate_ndvi) diff --git a/city_metrix/layers/tree_canopy_height.py b/city_metrix/layers/tree_canopy_height.py index f499552..881c226 100644 --- a/city_metrix/layers/tree_canopy_height.py +++ b/city_metrix/layers/tree_canopy_height.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class TreeCanopyHeight(Layer): """ @@ -20,6 +20,7 @@ def get_data(self, bbox): # aggregate time series into a single image canopy_ht_img = (canopy_ht + .map(set_bilinear_resampling) .reduce(ee.Reducer.mean()) .rename("cover_code") ) diff --git a/city_metrix/layers/tree_cover.py b/city_metrix/layers/tree_cover.py index 52fc8d6..2ee6fc8 100644 --- a/city_metrix/layers/tree_cover.py +++ b/city_metrix/layers/tree_cover.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class TreeCover(Layer): """ @@ -25,6 +25,7 @@ def get_data(self, bbox): merged_ttc = tropics.merge(non_tropics) ttc_image = (merged_ttc + .map(set_bilinear_resampling) .reduce(ee.Reducer.mean()) .rename('ttc') ) diff --git a/city_metrix/layers/world_pop.py b/city_metrix/layers/world_pop.py index 700010a..05ec363 100644 --- a/city_metrix/layers/world_pop.py +++ b/city_metrix/layers/world_pop.py @@ -1,6 +1,6 @@ import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_image_collection, set_bilinear_resampling class WorldPop(Layer): @@ -29,6 +29,7 @@ def get_data(self, bbox): dataset .filterBounds(ee.Geometry.BBox(*bbox)) .filter(ee.Filter.inList('year', [self.year])) + .map(set_bilinear_resampling) .select('population') .mean() ) @@ -53,6 +54,7 @@ def get_data(self, bbox): world_pop_group_ic = ee.ImageCollection( world_pop_age_sex_year + .map(set_bilinear_resampling) .reduce(ee.Reducer.sum()) .rename('sum_age_sex_group') )