Skip to content

Commit

Permalink
Merge pull request #51 from wri/feature/nasa_dem
Browse files Browse the repository at this point in the history
Nasa DEM
  • Loading branch information
weiqi-tori authored Jul 4, 2024
2 parents 6e3eb42 + 2702377 commit 6e2f03e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions city_metrix/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from .tree_canopy_height import TreeCanopyHeight
from .alos_dsm import AlosDSM
from .overture_buildings import OvertureBuildings
from .nasa_dem import NasaDEM
21 changes: 21 additions & 0 deletions city_metrix/layers/nasa_dem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ee
import xee
import xarray as xr

from .layer import Layer, get_image_collection


class NasaDEM(Layer):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def get_data(self, bbox):
dataset = ee.Image("NASA/NASADEM_HGT/001")
nasa_dem = ee.ImageCollection(ee.ImageCollection(dataset)
.filterBounds(ee.Geometry.BBox(*bbox))
.select('elevation')
.mean()
)
data = get_image_collection(nasa_dem, bbox, 30, "NASA DEM").elevation

return data
6 changes: 5 additions & 1 deletion tests/layers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ee

from city_metrix.layers import LandsatCollection2, Albedo, LandSurfaceTemperature, EsaWorldCover, EsaWorldCoverClass, TreeCover, AverageNetBuildingHeight, OpenStreetMap, OpenStreetMapClass, UrbanLandUse, OpenBuildings, TreeCanopyHeight, AlosDSM, SmartSurfaceLULC, OvertureBuildings
from city_metrix.layers import LandsatCollection2, Albedo, LandSurfaceTemperature, EsaWorldCover, EsaWorldCoverClass, TreeCover, AverageNetBuildingHeight, OpenStreetMap, OpenStreetMapClass, UrbanLandUse, OpenBuildings, TreeCanopyHeight, AlosDSM, SmartSurfaceLULC, OvertureBuildings, NasaDEM
from city_metrix.layers.layer import get_image_collection
from .conftest import MockLayer, MockMaskLayer, ZONES, LARGE_ZONES, MockLargeLayer, MockGroupByLayer, \
MockLargeGroupByLayer
Expand Down Expand Up @@ -116,3 +116,7 @@ def test_smart_surface_lulc():
def test_overture_buildings():
count = OvertureBuildings().get_data(SAMPLE_BBOX).count().sum()
assert count

def test_nasa_dem():
mean = NasaDEM().get_data(SAMPLE_BBOX).mean()
assert mean

0 comments on commit 6e2f03e

Please sign in to comment.