Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added further testing #97

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions city_metrix/layers/albedo.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion city_metrix/layers/alos_dsm.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()
)
Expand Down
3 changes: 2 additions & 1 deletion city_metrix/layers/land_surface_temperature.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down Expand Up @@ -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())
)

Expand Down
14 changes: 14 additions & 0 deletions city_metrix/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
3 changes: 2 additions & 1 deletion city_metrix/layers/nasa_dem.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()
)
Expand Down
5 changes: 3 additions & 2 deletions city_metrix/layers/ndvi_sentinel2_gee.py
Original file line number Diff line number Diff line change
@@ -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):
""""
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion city_metrix/layers/tree_canopy_height.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand All @@ -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")
)
Expand Down
3 changes: 2 additions & 1 deletion city_metrix/layers/tree_cover.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand All @@ -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')
)
Expand Down
4 changes: 3 additions & 1 deletion city_metrix/layers/world_pop.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()
)
Expand All @@ -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')
)
Expand Down
Loading