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

Create impervious_surface.py #66

Merged
merged 13 commits into from
Sep 6, 2024
23 changes: 23 additions & 0 deletions city_metrix/layers/impervious_surface.py
Original file line number Diff line number Diff line change
@@ -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.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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataset needs to be forced to ImageCollection to apply the filterBounds() and other functions.

AttributeError: 'Image' object has no attribute 'filterBounds'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forced dataset to be imagecollection, and added test for impervious surface. (Not 100% sure I did that right.)

.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
4 changes: 4 additions & 0 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
EsaWorldCover,
EsaWorldCoverClass,
HighLandSurfaceTemperature,
ImperviousSurface,
LandsatCollection2,
LandSurfaceTemperature,
NasaDEM,
Expand Down Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent error cause test failed


def test_land_surface_temperature():
mean_lst = LandSurfaceTemperature().get_data(BBOX_BRAZIL_LAURO_DE_FREITAS_1).mean()
Expand Down
Loading