forked from leiyangleon/Geogrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGeogridOptical.py
More file actions
executable file
·169 lines (139 loc) · 6.17 KB
/
testGeogridOptical.py
File metadata and controls
executable file
·169 lines (139 loc) · 6.17 KB
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
#!/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 loadMetadata(indir):
'''
Input file.
'''
import os
import numpy as np
from osgeo import gdal, osr
import struct
DS = gdal.Open(indir, gdal.GA_ReadOnly)
trans = DS.GetGeoTransform()
info = Dummy()
info.startingX = trans[0]
info.startingY = trans[3]
info.XSize = trans[1]
info.YSize = trans[5]
nameString = os.path.basename(DS.GetDescription())
info.time = float(nameString.split('_')[3])
info.numberOfLines = DS.RasterYSize
info.numberOfSamples = DS.RasterXSize
info.filename = indir
return info
def runGeogrid(info, info1, dem, dhdx, dhdy, vx, vy, srx, sry, csminx, csminy, csmaxx, csmaxy, ssm):
'''
Wire and run geogrid.
'''
from geogrid import GeogridOptical
# from components.contrib.geo_autoRIFT.geogrid import GeogridOptical
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 = np.abs(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.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"
obj.runGeogrid()
if __name__ == '__main__':
'''
Main driver.
'''
inps = cmdLineParse()
metadata_m = loadMetadata(inps.indir_m)
metadata_s = loadMetadata(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)