-
Notifications
You must be signed in to change notification settings - Fork 6
/
testGeogridOptical.py
231 lines (194 loc) · 8.3 KB
/
testGeogridOptical.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env python3
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Copyright 2019 California Institute of Technology. ALL RIGHTS RESERVED.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# United States Government Sponsorship acknowledged. This software is subject to
# U.S. export control laws and regulations and has been classified as 'EAR99 NLR'
# (No [Export] License Required except when exporting to an embargoed country,
# end user, or in support of a prohibited end use). By downloading this software,
# the user agrees to comply with all applicable U.S. export laws and regulations.
# The user has the responsibility to obtain export licenses, or other export
# authority as may be required before exporting this software to any 'EAR99'
# embargoed foreign country or citizen of those countries.
#
# Authors: Piyush Agram, Yang Lei
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def cmdLineParse():
'''
Command line parser.
'''
import argparse
parser = argparse.ArgumentParser(description='Output geo grid')
parser.add_argument('-m', '--input_m', dest='indir_m', type=str, required=True,
help='Input master image file name (in GeoTIFF format and Cartesian coordinates)')
parser.add_argument('-s', '--input_s', dest='indir_s', type=str, required=True,
help='Input slave image file name (in GeoTIFF format and Cartesian coordinates)')
# parser.add_argument('-o', '--output', dest='outfile', type=str, default='geogrid.csv',
# help='Output grid mapping')
parser.add_argument('-d', '--dem', dest='demfile', type=str, required=True,
help='Input DEM')
parser.add_argument('-sx', '--dhdx', dest='dhdxfile', type=str, default="",
help='Input slope in X')
parser.add_argument('-sy', '--dhdy', dest='dhdyfile', type=str, default="",
help='Input slope in Y')
parser.add_argument('-vx', '--vx', dest='vxfile', type=str, default="",
help='Input velocity in X')
parser.add_argument('-vy', '--vy', dest='vyfile', type=str, default="",
help='Input velocity in Y')
parser.add_argument('-srx', '--srx', dest='srxfile', type=str, default="",
help='Input search range in X')
parser.add_argument('-sry', '--sry', dest='sryfile', type=str, default="",
help='Input search range in Y')
parser.add_argument('-csminx', '--csminx', dest='csminxfile', type=str, default="",
help='Input chip size min in X')
parser.add_argument('-csminy', '--csminy', dest='csminyfile', type=str, default="",
help='Input chip size min in Y')
parser.add_argument('-csmaxx', '--csmaxx', dest='csmaxxfile', type=str, default="",
help='Input chip size max in X')
parser.add_argument('-csmaxy', '--csmaxy', dest='csmaxyfile', type=str, default="",
help='Input chip size max in Y')
parser.add_argument('-ssm', '--ssm', dest='ssmfile', type=str, default="",
help='Input stable surface mask')
return parser.parse_args()
class Dummy(object):
pass
def coregisterLoadMetadata(indir_m, indir_s):
'''
Input file.
'''
import os
import numpy as np
from osgeo import gdal, osr
import struct
import re
from geogrid import GeogridOptical
# import isce
# from components.contrib.geo_autoRIFT.geogrid import GeogridOptical
obj = GeogridOptical()
x1a, y1a, xsize1, ysize1, x2a, y2a, xsize2, ysize2, trans = obj.coregister(indir_m, indir_s)
DS = gdal.Open(indir_m, gdal.GA_ReadOnly)
info = Dummy()
info.startingX = trans[0]
info.startingY = trans[3]
info.XSize = trans[1]
info.YSize = trans[5]
if re.findall("L[CO]08_",DS.GetDescription()).__len__() > 0:
nameString = os.path.basename(DS.GetDescription())
info.time = nameString.split('_')[3]
elif re.findall("L[EO]07_",DS.GetDescription()).__len__() > 0:
nameString = os.path.basename(DS.GetDescription())
info.time = nameString.split('_')[3]
elif re.findall("S2._",DS.GetDescription()).__len__() > 0:
info.time = DS.GetDescription().split('_')[2]
else:
raise Exception('Optical data NOT supported yet!')
info.numberOfLines = ysize1
info.numberOfSamples = xsize1
info.filename = indir_m
DS1 = gdal.Open(indir_s, gdal.GA_ReadOnly)
info1 = Dummy()
if re.findall("L[CO]08_",DS1.GetDescription()).__len__() > 0:
nameString1 = os.path.basename(DS1.GetDescription())
info1.time = nameString1.split('_')[3]
elif re.findall("L[EO]07_",DS1.GetDescription()).__len__() > 0:
nameString1 = os.path.basename(DS1.GetDescription())
info1.time = nameString1.split('_')[3]
elif re.findall("S2._",DS1.GetDescription()).__len__() > 0:
info1.time = DS1.GetDescription().split('_')[2]
else:
raise Exception('Optical data NOT supported yet!')
return info, info1
def runGeogrid(info, info1, dem, dhdx, dhdy, vx, vy, srx, sry, csminx, csminy, csmaxx, csmaxy, ssm, **kwargs):
'''
Wire and run geogrid.
'''
from geogrid import GeogridOptical
# import isce
# from components.contrib.geo_autoRIFT.geogrid import GeogridOptical
from osgeo import gdal
dem_info = gdal.Info(dem, format='json')
obj = GeogridOptical()
obj.startingX = info.startingX
obj.startingY = info.startingY
obj.XSize = info.XSize
obj.YSize = info.YSize
from datetime import date
import numpy as np
d0 = date(np.int(info.time[0:4]),np.int(info.time[4:6]),np.int(info.time[6:8]))
d1 = date(np.int(info1.time[0:4]),np.int(info1.time[4:6]),np.int(info1.time[6:8]))
date_dt_base = d1 - d0
obj.repeatTime = date_dt_base.total_seconds()
# obj.repeatTime = (info1.time - info.time) * 24.0 * 3600.0
obj.numberOfLines = info.numberOfLines
obj.numberOfSamples = info.numberOfSamples
obj.nodata_out = -32767
obj.chipSizeX0 = 240
obj.gridSpacingX = dem_info['geoTransform'][1]
obj.dat1name = info.filename
obj.demname = dem
obj.dhdxname = dhdx
obj.dhdyname = dhdy
obj.vxname = vx
obj.vyname = vy
obj.srxname = srx
obj.sryname = sry
obj.csminxname = csminx
obj.csminyname = csminy
obj.csmaxxname = csmaxx
obj.csmaxyname = csmaxy
obj.ssmname = ssm
obj.winlocname = "window_location.tif"
obj.winoffname = "window_offset.tif"
obj.winsrname = "window_search_range.tif"
obj.wincsminname = "window_chip_size_min.tif"
obj.wincsmaxname = "window_chip_size_max.tif"
obj.winssmname = "window_stable_surface_mask.tif"
obj.winro2vxname = "window_rdr_off2vel_x_vec.tif"
obj.winro2vyname = "window_rdr_off2vel_y_vec.tif"
##dt-varying search range scale (srs) rountine parameters
# obj.srs_dt_unity = 32
# obj.srs_max_scale = 10
# obj.srs_max_search = 20000
# obj.srs_min_search = 0
obj.runGeogrid()
run_info = {
'chipsizex0': obj.chipSizeX0,
'gridspacingx': obj.gridSpacingX,
'vxname': vx,
'vyname': vy,
'sxname': kwargs.get('dhdxs'),
'syname': kwargs.get('dhdys'),
'maskname': kwargs.get('sp'),
'xoff': obj.pOff,
'yoff': obj.lOff,
'xcount': obj.pCount,
'ycount': obj.lCount,
'dt': obj.repeatTime,
'epsg': kwargs.get('epsg'),
'XPixelSize': obj.X_res,
'YPixelSize': obj.Y_res,
'cen_lat': obj.cen_lat,
'cen_lon': obj.cen_lon,
}
return run_info
def main():
'''
Main driver.
'''
inps = cmdLineParse()
metadata_m, metadata_s = coregisterLoadMetadata(inps.indir_m, inps.indir_s)
runGeogrid(metadata_m, metadata_s, inps.demfile, inps.dhdxfile, inps.dhdyfile, inps.vxfile, inps.vyfile, inps.srxfile, inps.sryfile, inps.csminxfile, inps.csminyfile, inps.csmaxxfile, inps.csmaxyfile, inps.ssmfile)
if __name__ == '__main__':
main()