-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathphenology_example.py
81 lines (65 loc) · 2.33 KB
/
phenology_example.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import logging
import os
from pathlib import Path
import pandas as pd
from shapely.geometry import Polygon
import openeo
#enable logging in requests library
logging.basicConfig(level=logging.DEBUG)
#connect with EURAC backend
session = openeo.connect("openeo.vito.be").authenticate_oidc()
#session = openeo.session("nobody", "http://localhost:5000/openeo/0.4.0")
#retrieve the list of available collections
collections = session.list_collections()
print(collections)
#create image collection
#specify process graph
#compute cloud mask
"""
cloud_mask = session.image("S2_SCENECLASSIFICATION") \
.filter_temporal("2017-03-01","2017-02-20") \
.filter_bbox(west=652000,east=672000,north=5161000,south=5181000,crs=32632) \
.apply_pixel(map_classification_to_binary)
"""
polygon = Polygon(shell= [
[
5.152158737182616,
51.18469636040683
],
[
5.15183687210083,
51.181979395425095
],
[
5.152802467346191,
51.18192559252128
],
[
5.153381824493408,
51.184588760878924
],
[
5.152158737182616,
51.18469636040683
]
])
minx,miny,maxx,maxy = polygon.bounds
#compute EVI
#https://en.wikipedia.org/wiki/Enhanced_vegetation_index
s2_radiometry = session.load_collection("TERRASCOPE_S2_TOC_V2") \
.filter_temporal("2017-01-01","2017-10-01") #\
# .filter_bbox(west=minx,east=maxx,north=maxy,south=miny,crs=4326)
B02 = s2_radiometry.band('B04')
B04 = s2_radiometry.band('B04')
B08 = s2_radiometry.band('B08')
evi_cube = (2.5 * (B08 - B04)) / ((B08 + 6.0 * B04 - 7.5 * B02) + 1.0)
def get_test_resource(relative_path):
dir = Path(os.path.dirname(os.path.realpath(__file__)))
return str(dir / relative_path)
smoothing_udf = openeo.UDF.from_file('udf/smooth_savitzky_golay.py')
#S2 radiometry at VITO already has a default mask otherwise we need a masking function
smoothed_evi = evi_cube.apply_dimension(process=smoothing_udf)
timeseries_smooth = smoothed_evi.polygonal_mean_timeseries(polygon)
timeseries_raw_dc = evi_cube.polygonal_mean_timeseries(polygon)
timeseries_raw = pd.Series(timeseries_raw_dc.execute(),name="evi_raw")
print(timeseries_raw.head(15))