-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS2ndvi_calc.py
75 lines (59 loc) · 2.25 KB
/
S2ndvi_calc.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
#!/usr/bin/env python
import os
import argparse
import NDVICalc_functions as ndvi
def main(command_line=None):
parser = argparse.ArgumentParser('Sentinel 2: NDVI Calculation')
parser.add_argument(
'--debug',
action='store_true',
help='Print debug info'
)
subprasers = parser.add_subparsers(dest='command')
# Average NDVI Calculation on latest date (Scene)
latest = subprasers.add_parser('latest', help='calculate the average NDVI based on a latest scene available')
latest.add_argument(
'-cloudperc',
help='Percentage of cloud cover in the scene (optional)',
default= 100,
type=int,
nargs='?'
)
latest.add_argument(
'-stats',
help='descriptors to calculate (mean, median, mode, max, min, std) default -> [mean,mode,std] (optional)',
default= ['mean','median','std'],
choices=['mean', 'median', 'mode', 'max', 'min', 'std'],
nargs='+'
)
latest.add_argument(
'-geometry',
help='Study Area to analyse in GEOJSON format (optional)',
type=str,
default="./default/geometry/geometry.geojson",
nargs='?'
)
# Average NDVI Calculation on user-defined dates (Scenes)
dates = subprasers.add_parser('dates', help='calculate the average NDVI based on user-defined dates and scenes available')
args = parser.parse_args(command_line)
if args.debug:
print("debug: " + str(args))
if args.command == 'latest':
while True:
if(os.path.isfile(args.geometry) and args.geometry.endswith(".geojson") ):
print("[INFO] Geojson path validated")
else:
print("[ERROR] Please check the path given")
break
if(args.cloudperc >= 0 and args.cloudperc <= 100):
print("[INFO] Cloud Percentage validated")
else:
print("[ERROR] Cloud Percentage Parameter must be from 0 to 100")
break
print("[INFO] NDVI calculation running ...")
ndvi.calculation(args.cloudperc,args.stats,args.geometry)
break
elif args.command == 'dates':
print('Still on development')
if __name__ == '__main__':
main()