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

CIF-259 add HAND layer #93

Merged
Merged
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
1 change: 1 addition & 0 deletions city_metrix/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
from .glad_lulc import LandCoverHabitatChangeGlad
from .cams import Cams
from .vegetation_water_map import VegetationWaterMap
from .height_above_nearest_drainage import HeightAboveNearestDrainage
51 changes: 51 additions & 0 deletions city_metrix/layers/height_above_nearest_drainage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from dask.diagnostics import ProgressBar
import xarray as xr
import ee

from .layer import Layer, get_utm_zone_epsg, get_image_collection


class HeightAboveNearestDrainage(Layer):
"""
Attributes:
spatial_resolution: raster resolution in meters (see https://github.com/stac-extensions/raster)
default is 30, other options - 90
river_head: number of river head threshold cells
default is 1000, other options - 100, 5000
"""

def __init__(self, spatial_resolution=30, river_head=1000, **kwargs):
super().__init__(**kwargs)
self.spatial_resolution = spatial_resolution
self.river_head = river_head

def get_data(self, bbox):
if self.spatial_resolution == 30 and self.river_head == 100:
hand = ee.ImageCollection('users/gena/global-hand/hand-100')
# smoothen HAND a bit, scale varies a little in the tiles
hand = hand.mosaic().focal_mean(0.1)
elif self.spatial_resolution == 30:
hand = ee.Image(f'users/gena/GlobalHAND/30m/hand-{self.river_head}')
# smoothen HAND a bit, scale varies a little in the tiles
hand = hand.focal_mean(0.1)
elif self.spatial_resolution == 90:
hand = ee.Image(f'users/gena/GlobalHAND/90m-global/hand-{self.river_head}')
# smoothen HAND a bit, scale varies a little in the tiles
hand = hand.focal_mean(0.1)

# MOD44W.005 Land Water Mask Derived From MODIS and SRTM
swbd = ee.Image('MODIS/MOD44W/MOD44W_005_2000_02_24').select('water_mask')
swbdMask = swbd.unmask().Not().focal_median(1)

thresh = 1
HANDthresh = hand.lte(thresh).focal_max(1).focal_mode(2, 'circle', 'pixels', 5).mask(swbdMask)
HANDthresh = HANDthresh.mask(HANDthresh)

data = get_image_collection(
ee.ImageCollection(HANDthresh),
bbox,
self.spatial_resolution,
"height above nearest drainage"
).b1

return data
5 changes: 5 additions & 0 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Era5HottestDay,
EsaWorldCover,
EsaWorldCoverClass,
HeightAboveNearestDrainage,
HighLandSurfaceTemperature,
ImperviousSurface,
LandCoverGlad,
Expand Down Expand Up @@ -70,6 +71,10 @@ def test_esa_world_cover():
data = EsaWorldCover(land_cover_class=land_cover_class).get_data(BBOX)
assert np.size(data) > 0

def test_height_above_nearest_drainage():
data = HeightAboveNearestDrainage().get_data(BBOX)
assert np.size(data) > 0

def test_high_land_surface_temperature():
data = HighLandSurfaceTemperature().get_data(BBOX)
assert np.size(data) > 0
Expand Down
Loading