Newer
Older
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/env python3
# Author: Cunren Liang
# Copyright 2021
import isce
import isceobj
import stdproc
from stdproc.stdproc import crossmul
import numpy as np
from isceobj.Util.Poly2D import Poly2D
import argparse
import os
import copy
import s1a_isce_utils as ut
from isceobj.Sensor.TOPS import createTOPSSwathSLCProduct
def createParser():
parser = argparse.ArgumentParser( description='bandpass filtering and resampling burst by burst SLCs ')
parser.add_argument('-m', '--reference', dest='reference', type=str, required=True,
help='Directory with reference acquisition')
parser.add_argument('-s', '--secondary', dest='secondary', type=str, required=True,
help='Directory with secondary acquisition')
parser.add_argument('-o', '--coregdir', dest='coreg', type=str, default='coreg_secondary',
help='Directory with coregistered SLCs and IFGs')
parser.add_argument('-a', '--azimuth_misreg', dest='misreg_az', type=str, default=0.0,
help='File name with the azimuth misregistration')
parser.add_argument('-r', '--range_misreg', dest='misreg_rng', type=str, default=0.0,
help='File name with the range misregistration')
parser.add_argument('--noflat', dest='noflat', action='store_true', default=False,
help='To turn off flattening. False: flattens the SLC. True: turns off flattening.')
return parser
def cmdLineParse(iargs = None):
parser = createParser()
return parser.parse_args(args=iargs)
def resampSecondary(mas, slv, rdict, outname, flatten):
'''
Resample burst by burst.
'''
azpoly = rdict['azpoly']
rgpoly = rdict['rgpoly']
azcarrpoly = rdict['carrPoly']
dpoly = rdict['doppPoly']
rngImg = isceobj.createImage()
rngImg.load(rdict['rangeOff'] + '.xml')
rngImg.setAccessMode('READ')
aziImg = isceobj.createImage()
aziImg.load(rdict['azimuthOff'] + '.xml')
aziImg.setAccessMode('READ')
inimg = isceobj.createSlcImage()
inimg.load(slv.image.filename + '.xml')
inimg.setAccessMode('READ')
rObj = stdproc.createResamp_slc()
rObj.slantRangePixelSpacing = slv.rangePixelSize
rObj.radarWavelength = slv.radarWavelength
rObj.azimuthCarrierPoly = azcarrpoly
rObj.dopplerPoly = dpoly
rObj.azimuthOffsetsPoly = azpoly
rObj.rangeOffsetsPoly = rgpoly
rObj.imageIn = inimg
width = mas.numberOfSamples
length = mas.numberOfLines
imgOut = isceobj.createSlcImage()
imgOut.setWidth(width)
imgOut.filename = outname
imgOut.setAccessMode('write')
rObj.outputWidth = width
rObj.outputLines = length
rObj.residualRangeImage = rngImg
rObj.residualAzimuthImage = aziImg
rObj.flatten = flatten
print(rObj.flatten)
rObj.resamp_slc(imageOut=imgOut)
imgOut.renderHdr()
imgOut.renderVRT()
return imgOut
def subband(burst, nout, outputfile, bw, bc, rgRef, virtual):
'''
burst: input burst object
nout: number of output files
outputfile: [value_of_out_1, value_of_out_2, value_of_out_3...] output files
bw: [value_of_out_1, value_of_out_2, value_of_out_3...] filter bandwidth divided by sampling frequency [0, 1]
bc: [value_of_out_1, value_of_out_2, value_of_out_3...] filter center frequency divided by sampling frequency
rgRef: reference range for moving center frequency to zero
virtual: True or False
'''
from isceobj.Constants import SPEED_OF_LIGHT
from isceobj.TopsProc.runIon import removeHammingWindow
from contrib.alos2proc.alos2proc import rg_filter
tmpFilename = burst.image.filename + '.tmp'
#removing window
rangeSamplingRate = SPEED_OF_LIGHT / (2.0 * burst.rangePixelSize)
if burst.rangeWindowType == 'Hamming':
removeHammingWindow(burst.image.filename, tmpFilename, burst.rangeProcessingBandwidth, rangeSamplingRate, burst.rangeWindowCoefficient, virtual=virtual)
else:
raise Exception('Range weight window type: {} is not supported yet!'.format(burst.rangeWindowType))
#subband
rg_filter(tmpFilename,
#burst.numberOfSamples,
nout,
outputfile,
bw,
bc,
129,
512,
0.1,
0,
(burst.startingRange - rgRef) / burst.rangePixelSize
)
os.remove(tmpFilename)
os.remove(tmpFilename+'.vrt')
os.remove(tmpFilename+'.xml')
def main(iargs=None):
'''
Create coregistered overlap secondarys.
'''
inps = cmdLineParse(iargs)
referenceSwathList = ut.getSwathList(inps.reference)
secondarySwathList = ut.getSwathList(inps.secondary)
swathList = list(sorted(set(referenceSwathList+secondarySwathList)))
#if os.path.abspath(inps.reference) == os.path.abspath(inps.secondary):
# print('secondary is the same as reference, only performing subband filtering')
for swath in swathList:
####Load secondary metadata
reference = ut.loadProduct( os.path.join(inps.reference , 'IW{0}.xml'.format(swath)))
secondary = ut.loadProduct( os.path.join(inps.secondary , 'IW{0}.xml'.format(swath)))
if os.path.exists(str(inps.misreg_az)):
with open(inps.misreg_az, 'r') as f:
misreg_az = float(f.readline())
else:
misreg_az = 0.0
if os.path.exists(str(inps.misreg_rng)):
with open(inps.misreg_rng, 'r') as f:
misreg_rg = float(f.readline())
else:
misreg_rg = 0.0
###Output directory for coregistered SLCs
outdir = os.path.join(inps.coreg,'IW{0}'.format(swath))
offdir = os.path.join(inps.coreg,'IW{0}'.format(swath))
os.makedirs(outdir, exist_ok=True)
####Indices w.r.t reference
burstoffset, minBurst, maxBurst = reference.getCommonBurstLimits(secondary)
secondaryBurstStart = minBurst + burstoffset
secondaryBurstEnd = maxBurst
relShifts = ut.getRelativeShifts(reference, secondary, minBurst, maxBurst, secondaryBurstStart)
print('Shifts: ', relShifts)
####Can corporate known misregistration here
apoly = Poly2D()
apoly.initPoly(rangeOrder=0,azimuthOrder=0,coeffs=[[0.]])
rpoly = Poly2D()
rpoly.initPoly(rangeOrder=0,azimuthOrder=0,coeffs=[[0.]])
#slvCoreg = createTOPSSwathSLCProduct()
slvCoreg = ut.coregSwathSLCProduct()
slvCoreg.configure()
for ii in range(minBurst, maxBurst):
outname = os.path.join(outdir, 'burst_%02d.slc'%(ii+1))
outnameLower = os.path.splitext(outname)[0]+'_lower.slc'
outnameUpper = os.path.splitext(outname)[0]+'_upper.slc'
if os.path.exists(outnameLower) and os.path.exists(outnameLower+'.vrt') and os.path.exists(outnameLower+'.xml') and \
os.path.exists(outnameUpper) and os.path.exists(outnameUpper+'.vrt') and os.path.exists(outnameUpper+'.xml'):
print('burst %02d already processed, skip...'%(ii+1))
continue
jj = secondaryBurstStart + ii - minBurst
masBurst = reference.bursts[ii]
slvBurst = secondary.bursts[jj]
#####Top burst processing
try:
offset = relShifts[jj]
except:
raise Exception('Trying to access shift for secondary burst index {0}, which may not overlap with reference'.format(jj))
####Setup initial polynomials
### If no misregs are given, these are zero
### If provided, can be used for resampling without running to geo2rdr again for fast results
rdict = {'azpoly' : apoly,
'rgpoly' : rpoly,
'rangeOff' : os.path.join(offdir, 'range_%02d.off'%(ii+1)),
'azimuthOff': os.path.join(offdir, 'azimuth_%02d.off'%(ii+1))}
###For future - should account for azimuth and range misreg here .. ignoring for now.
azCarrPoly, dpoly = secondary.estimateAzimuthCarrierPolynomials(slvBurst, offset = -1.0 * offset)
rdict['carrPoly'] = azCarrPoly
rdict['doppPoly'] = dpoly
#subband filtering
from Stack import ionParam
from isceobj.Constants import SPEED_OF_LIGHT
rangeSamplingRate = SPEED_OF_LIGHT / (2.0 * slvBurst.rangePixelSize)
ionParamObj=ionParam()
ionParamObj.configure()
lower_tmpfile = os.path.splitext(slvBurst.image.filename)[0]+'_lower_tmp.slc'
upper_tmpfile = os.path.splitext(slvBurst.image.filename)[0]+'_upper_tmp.slc'
outputfile = [lower_tmpfile, upper_tmpfile]
bw = [ionParamObj.rgBandwidthSub / rangeSamplingRate, ionParamObj.rgBandwidthSub / rangeSamplingRate]
bc = [-ionParamObj.rgBandwidthForSplit / 3.0 / rangeSamplingRate, ionParamObj.rgBandwidthForSplit / 3.0 / rangeSamplingRate]
rgRef = ionParamObj.rgRef
subband(slvBurst, 2, outputfile, bw, bc, rgRef, True)
#resampling
slvBurst.radarWavelength = ionParamObj.radarWavelengthLower
slvBurst.image.filename = lower_tmpfile
outnameSubband = outnameLower
outimg = resampSecondary(masBurst, slvBurst, rdict, outnameSubband, (not inps.noflat))
slvBurst.radarWavelength = ionParamObj.radarWavelengthUpper
slvBurst.image.filename = upper_tmpfile
outnameSubband = outnameUpper
outimg = resampSecondary(masBurst, slvBurst, rdict, outnameSubband, (not inps.noflat))
#remove original subband images
os.remove(lower_tmpfile)
os.remove(lower_tmpfile+'.vrt')
os.remove(lower_tmpfile+'.xml')
os.remove(upper_tmpfile)
os.remove(upper_tmpfile+'.vrt')
os.remove(upper_tmpfile+'.xml')
# share IW*.xml with full band images, these are no longer required.
#########################################################################################################################################
# minAz, maxAz, minRg, maxRg = ut.getValidLines(slvBurst, rdict, outname,
# misreg_az = misreg_az - offset, misreg_rng = misreg_rg)
# copyBurst = copy.deepcopy(masBurst)
# ut.adjustValidSampleLine_V2(copyBurst, slvBurst, minAz=minAz, maxAz=maxAz,
# minRng=minRg, maxRng=maxRg)
# copyBurst.image.filename = outimg.filename
# print('After: ', copyBurst.firstValidLine, copyBurst.numValidLines)
# slvCoreg.bursts.append(copyBurst)
# slvCoreg.numberOfBursts = len(slvCoreg.bursts)
# slvCoreg.source = ut.asBaseClass(secondary)
# slvCoreg.reference = reference
# ut.saveProduct(slvCoreg, outdir + '.xml')
if __name__ == '__main__':
'''
Main driver.
'''
# Main Driver
main()