-
Notifications
You must be signed in to change notification settings - Fork 1
/
tree_canopy_height.py
38 lines (30 loc) · 1.09 KB
/
tree_canopy_height.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from .layer import Layer, get_utm_zone_epsg, get_image_collection
from dask.diagnostics import ProgressBar
import xarray as xr
import xee
import ee
class TreeCanopyHeight(Layer):
"""
Attributes:
spatial_resolution: raster resolution in meters (see https://github.com/stac-extensions/raster)
"""
name = "tree_canopy_height"
NO_DATA_VALUE = 0
def __init__(self, spatial_resolution=1, **kwargs):
super().__init__(**kwargs)
self.spatial_resolution = spatial_resolution
def get_data(self, bbox):
canopy_ht = ee.ImageCollection("projects/meta-forest-monitoring-okw37/assets/CanopyHeight")
# aggregate time series into a single image
canopy_ht_img = (canopy_ht
.reduce(ee.Reducer.mean())
.rename("cover_code")
)
canopy_ht_ic = ee.ImageCollection(canopy_ht_img)
data = get_image_collection(
canopy_ht_ic,
bbox,
self.spatial_resolution,
"tree canopy height"
).cover_code
return data