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
1 change: 1 addition & 0 deletions city_metrix/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
from .alos_dsm import AlosDSM
from .overture_buildings import OvertureBuildings
from .nasa_dem import NasaDEM
from .impervious_surface import ImperviousSurface
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
6 changes: 6 additions & 0 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
EsaWorldCover,
EsaWorldCoverClass,
HighLandSurfaceTemperature,
ImperviousSurface,
LandsatCollection2,
LandSurfaceTemperature,
NasaDEM,
Expand Down Expand Up @@ -82,6 +83,11 @@ def test_high_land_surface_temperature():
assert data.any()


def test_impervious_surface():
data = ImperviousSurface().get_data(BBOX)
assert data.any()


def test_land_surface_temperature():
mean_lst = LandSurfaceTemperature().get_data(BBOX).mean()
assert mean_lst
Expand Down