From 31c3b4960478bc80c354b6fa8b6b1fdaffe9af78 Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Sun, 25 Aug 2024 17:38:20 -0400 Subject: [PATCH 01/11] Create impervious_surface.py --- city_metrix/layers/impervious_surface.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 city_metrix/layers/impervious_surface.py diff --git a/city_metrix/layers/impervious_surface.py b/city_metrix/layers/impervious_surface.py new file mode 100644 index 00000000..dc2133a4 --- /dev/null +++ b/city_metrix/layers/impervious_surface.py @@ -0,0 +1,23 @@ +from dask.diagnostics import ProgressBar +import xarray as xr +import xee +import ee + +from .layer import Layer, get_utm_zone_epsg, get_image_collection + + +class ImperviousSurface(Layer): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + def get_data(self, bbox): + # load impervious_surface + dataset = ee.Image("Tsinghua/FROM-GLC/GAIA/v10").gt(0) # change_year_index is zero if permeable as of 2018 + imperv_surf = ee.ImageCollection(dataset + .filterBounds(ee.Geometry.BBox(*bbox)) + .select('change_year_index') + .sum() + ) + + data = get_image_collection(imperv_surf, bbox, 100, "imperv surf") + return data.change_year_index From b4c58604b1ff4573b6240fbbe2cbda00d37fd181 Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 28 Aug 2024 13:45:20 -0400 Subject: [PATCH 02/11] force image dataset to iagecollection --- city_metrix/layers/impervious_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/city_metrix/layers/impervious_surface.py b/city_metrix/layers/impervious_surface.py index dc2133a4..ee278d4d 100644 --- a/city_metrix/layers/impervious_surface.py +++ b/city_metrix/layers/impervious_surface.py @@ -12,7 +12,7 @@ def __init__(self, **kwargs): def get_data(self, bbox): # load impervious_surface - dataset = ee.Image("Tsinghua/FROM-GLC/GAIA/v10").gt(0) # change_year_index is zero if permeable as of 2018 + dataset = ee.ImageCollection(ee.Image("Tsinghua/FROM-GLC/GAIA/v10").gt(0)) # change_year_index is zero if permeable as of 2018 imperv_surf = ee.ImageCollection(dataset .filterBounds(ee.Geometry.BBox(*bbox)) .select('change_year_index') From 3b0ca2fe77995712d01fb5e0bccef9dbf9253682 Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 28 Aug 2024 13:48:44 -0400 Subject: [PATCH 03/11] added test for impervious surface --- tests/test_layers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_layers.py b/tests/test_layers.py index 83726146..c0e630ba 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -8,6 +8,7 @@ EsaWorldCover, EsaWorldCoverClass, HighLandSurfaceTemperature, + ImperviousSurface, LandsatCollection2, LandSurfaceTemperature, NasaDEM, @@ -77,6 +78,9 @@ def test_high_land_surface_temperature(): data = HighLandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) assert data.any() +def test_impervious_surface(): + data = ImperviousSurface().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) + assert data.any() def test_land_surface_temperature(): mean_lst = LandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean() From b67463af3d429fce2ca996516779386f65c75510 Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 4 Sep 2024 16:34:43 -0400 Subject: [PATCH 04/11] fix indent --- city_metrix/layers/impervious_surface.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/city_metrix/layers/impervious_surface.py b/city_metrix/layers/impervious_surface.py index ee278d4d..b213fc3e 100644 --- a/city_metrix/layers/impervious_surface.py +++ b/city_metrix/layers/impervious_surface.py @@ -7,17 +7,17 @@ class ImperviousSurface(Layer): - def __init__(self, **kwargs): - super().__init__(**kwargs) + def __init__(self, **kwargs): + super().__init__(**kwargs) def get_data(self, bbox): # load impervious_surface - dataset = ee.ImageCollection(ee.Image("Tsinghua/FROM-GLC/GAIA/v10").gt(0)) # change_year_index is zero if permeable as of 2018 - imperv_surf = ee.ImageCollection(dataset - .filterBounds(ee.Geometry.BBox(*bbox)) - .select('change_year_index') - .sum() - ) + dataset = ee.ImageCollection(ee.Image("Tsinghua/FROM-GLC/GAIA/v10").gt(0)) # change_year_index is zero if permeable as of 2018 + imperv_surf = ee.ImageCollection(dataset + .filterBounds(ee.Geometry.BBox(*bbox)) + .select('change_year_index') + .sum() + ) - data = get_image_collection(imperv_surf, bbox, 100, "imperv surf") - return data.change_year_index + data = get_image_collection(imperv_surf, bbox, 100, "imperv surf") + return data.change_year_index From d399adb8570860f408945fb63a0ce85e9785b22f Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 4 Sep 2024 16:42:05 -0400 Subject: [PATCH 05/11] fix indent --- tests/test_layers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_layers.py b/tests/test_layers.py index c0e630ba..a8ae664c 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -80,7 +80,7 @@ def test_high_land_surface_temperature(): def test_impervious_surface(): data = ImperviousSurface().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) - assert data.any() + assert data.any() def test_land_surface_temperature(): mean_lst = LandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean() From e4bbc23a11a774c4da79371912790397f7e1c81f Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 4 Sep 2024 16:49:14 -0400 Subject: [PATCH 06/11] tabs to spaces --- city_metrix/layers/impervious_surface.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/city_metrix/layers/impervious_surface.py b/city_metrix/layers/impervious_surface.py index b213fc3e..74e624d6 100644 --- a/city_metrix/layers/impervious_surface.py +++ b/city_metrix/layers/impervious_surface.py @@ -7,17 +7,17 @@ class ImperviousSurface(Layer): - def __init__(self, **kwargs): - super().__init__(**kwargs) + def __init__(self, **kwargs): + super().__init__(**kwargs) def get_data(self, bbox): # load impervious_surface - dataset = ee.ImageCollection(ee.Image("Tsinghua/FROM-GLC/GAIA/v10").gt(0)) # change_year_index is zero if permeable as of 2018 - imperv_surf = ee.ImageCollection(dataset - .filterBounds(ee.Geometry.BBox(*bbox)) - .select('change_year_index') - .sum() - ) + dataset = ee.ImageCollection(ee.Image("Tsinghua/FROM-GLC/GAIA/v10").gt(0)) # change_year_index is zero if permeable as of 2018 + imperv_surf = ee.ImageCollection(dataset + .filterBounds(ee.Geometry.BBox(*bbox)) + .select('change_year_index') + .sum() + ) - data = get_image_collection(imperv_surf, bbox, 100, "imperv surf") - return data.change_year_index + data = get_image_collection(imperv_surf, bbox, 100, "imperv surf") + return data.change_year_index From 00fa774ab292ac5e4fd0bfcfa28633c6ede54695 Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 4 Sep 2024 17:16:02 -0400 Subject: [PATCH 07/11] add class to __init__ --- city_metrix/layers/__init__.py | 1 + tests/test_layers.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/city_metrix/layers/__init__.py b/city_metrix/layers/__init__.py index ea7fa8a1..3432befd 100644 --- a/city_metrix/layers/__init__.py +++ b/city_metrix/layers/__init__.py @@ -18,3 +18,4 @@ from .alos_dsm import AlosDSM from .overture_buildings import OvertureBuildings from .nasa_dem import NasaDEM +from .impervious_surface import ImperviousSurface diff --git a/tests/test_layers.py b/tests/test_layers.py index a8ae664c..92936776 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -8,7 +8,7 @@ EsaWorldCover, EsaWorldCoverClass, HighLandSurfaceTemperature, - ImperviousSurface, + ImperviousSurface, LandsatCollection2, LandSurfaceTemperature, NasaDEM, From 4f82253020c5fb86bdb0d0d193905029f1b53c8c Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 4 Sep 2024 20:09:35 -0400 Subject: [PATCH 08/11] Update test_layers.py --- tests/test_layers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_layers.py b/tests/test_layers.py index 92936776..c2a85b35 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -78,10 +78,12 @@ def test_high_land_surface_temperature(): data = HighLandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) assert data.any() -def test_impervious_surface(): + +def test_impervious_surface_hello(): data = ImperviousSurface().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) assert data.any() + def test_land_surface_temperature(): mean_lst = LandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean() assert mean_lst From c85058c794c11a77032393f57b16ef7aa524e672 Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 4 Sep 2024 20:16:37 -0400 Subject: [PATCH 09/11] Update test_layers.py --- tests/test_layers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_layers.py b/tests/test_layers.py index c2a85b35..287c4b08 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -79,7 +79,8 @@ def test_high_land_surface_temperature(): assert data.any() -def test_impervious_surface_hello(): +def test_impervious_surface(): + from tests.fixtures.bbox_constants import BBOX_BRAZIL_LAURO_DE_FREITAS_1 data = ImperviousSurface().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) assert data.any() From f247f8d9f706773f4746d8c886c7ea418c7e2829 Mon Sep 17 00:00:00 2001 From: Ted Wong Date: Wed, 4 Sep 2024 20:35:18 -0400 Subject: [PATCH 10/11] Update test_layers.py --- tests/test_layers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_layers.py b/tests/test_layers.py index 287c4b08..882e722f 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -80,7 +80,6 @@ def test_high_land_surface_temperature(): def test_impervious_surface(): - from tests.fixtures.bbox_constants import BBOX_BRAZIL_LAURO_DE_FREITAS_1 data = ImperviousSurface().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) assert data.any() From f4745b8ecf55ba61571f9ef2860b76c786dfdc63 Mon Sep 17 00:00:00 2001 From: Chris Rowe Date: Thu, 5 Sep 2024 14:44:49 -0400 Subject: [PATCH 11/11] Use BBOX for test --- tests/test_layers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_layers.py b/tests/test_layers.py index e734811f..27cb7c5d 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -84,7 +84,7 @@ def test_high_land_surface_temperature(): def test_impervious_surface(): - data = ImperviousSurface().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1) + data = ImperviousSurface().get_data(BBOX) assert data.any()