-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworsica_sentinel_script_v5_waterleak.py
114 lines (99 loc) · 4.02 KB
/
worsica_sentinel_script_v5_waterleak.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
worsica script for edge detection using opencv
Author: rjmartins
Script to run all the image processing,
This does not include running the topo-bath image generation
since it is only once made and should be manually done.
Args:
>1) ZIPFILE is the imageset name located
in the same folder as this script
>2) ROI-NAME_is a region of interest name
>3 and 4) [now deprecated] BATHYMETRY-THRESHOLD and TOPOGRAPHY-THRESHOLD are threshold
values given for bath and topography during MNDWI filtering
>5) WI_THRESHOLD is a comma separate value string that defines the threshold filtering value for each water index
>6) WATER_INDEX is a comma separate value string that defines the chosen water indexes
Usage: ./worsica_sentinel_script_v5_coastal.py [ZIPFILE] [ROI-NAME] [ROI-POLYGON] [BATHYMETRY-THRESHOLD] [TOPOGRAPHY-THRESHOLD] [WI_THRESHOLD] [WATER_INDEX]
e.g: ./worsica_sentinel_script_v5_coastal.py S2A_MSIL2A_20181229T113501_N0211_R080_T29SMC_20181229T124502
MARGEM-SUL -2 5 0.3,0.1,-0.2 mndwi,ndwi,ndwi2
"""
import sys
import os
import worsica_waterIndexes
import worsica_common_script_functions
import traceback
WORKSPACE_PATH = '.'
SCRIPT_PATH = '/usr/local/worsica_web_products'
def run_script(args):
'''
run all the image processing
'''
# resample
try:
print(WORKSPACE_PATH)
wis = args[6].split(',') # water indexes
thrs = args[5].split(',')
for wi, thr in zip(wis, thrs):
# wi proc
print('Processing ' + wi + ' now!')
print('---------------------------------------------')
print('-- 1) Start processing ' + wi + ' WATER INDEX')
print('---------------------------------------------')
worsica_common_script_functions.search_and_remove_files(
[WORKSPACE_PATH + '/' + args[2] + '/' + args[1] + '_' + wi + '.tif'])
worsica_waterIndexes.worsicaWaterIndexes(
WORKSPACE_PATH +
'/' +
args[2] +
'/' +
args[1] +
'.tif',
wi.upper(),
os.getcwd() +
'/' +
args[2])
print('Processing ' + wi + ' done!')
print('SUCCESS!')
except BaseException:
traceback.print_exc()
exit(1)
if __name__ == '__main__':
if len(sys.argv) != 7:
print(
"Usage: ./worsica_sentinel_script_v5_waterleak.py [IMAGESET_NAME_NO_ZIP_EXTENSION] [ROI-NAME] [BATHYMETRY-THRESHOLD] [TOPOGRAPHY-THRESHOLD] [WI_THRESHOLD] [WATER_INDEX]")
exit(1)
else:
if os.path.exists(WORKSPACE_PATH + '/' +
sys.argv[2] + '/' + sys.argv[1] + '_interpolated.tif'):
print('Found ' + sys.argv[1] + '_interpolated.tif')
# workaround to cleanup useless files after this step
if os.path.exists(WORKSPACE_PATH + '/' + sys.argv[2] + '/' + sys.argv[1] + '.tif'):
print('Delete the existing ' + sys.argv[1] + '.tif')
os.remove(WORKSPACE_PATH + '/' + sys.argv[2] + '/' + sys.argv[1] + '.tif')
print('Rename ' + sys.argv[1] + '_interpolated.tif to ' + sys.argv[1] + '.tif')
os.rename(
WORKSPACE_PATH +
'/' +
sys.argv[2] +
'/' +
sys.argv[1] +
'_interpolated.tif',
WORKSPACE_PATH +
'/' +
sys.argv[2] +
'/' +
sys.argv[1] +
'.tif')
run_script(sys.argv)
exit(0)
elif os.path.exists(WORKSPACE_PATH + '/' + sys.argv[2] + '/' + sys.argv[1] + '.tif'):
print('Interpolated not found. Run with ' + sys.argv[1] + '.tif')
run_script(sys.argv)
exit(0)
else:
print(
'ERROR: ' +
sys.argv[1] +
'.tif does not exist. Make sure you write the file name correctly, or check if exists.')
exit(1)