2019-01-16 19:40:08 +00:00
|
|
|
from coregSwathSLCProduct import coregSwathSLCProduct
|
|
|
|
import isce
|
|
|
|
import isceobj
|
|
|
|
import os
|
|
|
|
#from isceobj.Sensor.TOPS.coregSwathSLCProduct import coregSwathSLCProduct
|
|
|
|
|
|
|
|
class catalog(object):
|
2021-06-14 04:13:55 +00:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2021-06-14 04:13:55 +00:00
|
|
|
def addItem(self,*args):
|
|
|
|
print(' '.join([str(x) for x in args]))
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def loadProduct(xmlname):
|
|
|
|
'''
|
|
|
|
Load the product using Product Manager.
|
|
|
|
'''
|
|
|
|
|
|
|
|
from iscesys.Component.ProductManager import ProductManager as PM
|
|
|
|
|
|
|
|
pm = PM()
|
|
|
|
pm.configure()
|
|
|
|
|
|
|
|
obj = pm.loadProduct(xmlname)
|
|
|
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
def saveProduct( obj, xmlname):
|
2021-06-14 04:13:55 +00:00
|
|
|
'''
|
|
|
|
Save the product to an XML file using Product Manager.
|
|
|
|
'''
|
|
|
|
import shelve
|
|
|
|
import os
|
|
|
|
with shelve.open(os.path.dirname(xmlname) + '/'+ os.path.basename(xmlname) +'.data') as db:
|
|
|
|
db['data'] = obj
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2021-06-14 04:13:55 +00:00
|
|
|
from iscesys.Component.ProductManager import ProductManager as PM
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2021-06-14 04:13:55 +00:00
|
|
|
pm = PM()
|
|
|
|
pm.configure()
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2021-06-14 04:13:55 +00:00
|
|
|
pm.dumpProduct(obj, xmlname)
|
|
|
|
|
|
|
|
return None
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
def getRelativeShifts(mFrame, sFrame, minBurst, maxBurst, secondaryBurstStart):
|
2019-01-16 19:40:08 +00:00
|
|
|
'''
|
|
|
|
Estimate the relative shifts between the start of the bursts.
|
|
|
|
'''
|
|
|
|
import numpy as np
|
2020-07-02 19:40:49 +00:00
|
|
|
azReferenceOff = {}
|
|
|
|
azSecondaryOff = {}
|
2019-01-16 19:40:08 +00:00
|
|
|
azRelOff = {}
|
|
|
|
tm = mFrame.bursts[minBurst].sensingStart
|
|
|
|
dt = mFrame.bursts[minBurst].azimuthTimeInterval
|
2020-07-02 19:40:49 +00:00
|
|
|
ts = sFrame.bursts[secondaryBurstStart].sensingStart
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
for index in range(minBurst, maxBurst):
|
|
|
|
burst = mFrame.bursts[index]
|
2020-07-02 19:40:49 +00:00
|
|
|
azReferenceOff[index] = int(np.round((burst.sensingStart - tm).total_seconds() / dt))
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
burst = sFrame.bursts[secondaryBurstStart + index - minBurst]
|
|
|
|
azSecondaryOff[secondaryBurstStart + index - minBurst] = int(np.round((burst.sensingStart - ts).total_seconds() / dt))
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
azRelOff[secondaryBurstStart + index - minBurst] = azSecondaryOff[secondaryBurstStart + index - minBurst] - azReferenceOff[index]
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
return azRelOff
|
|
|
|
|
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
def adjustValidSampleLine(reference, minAz=0, maxAz=0, minRng=0, maxRng=0):
|
2019-01-16 19:40:08 +00:00
|
|
|
import numpy as np
|
|
|
|
import isce
|
|
|
|
import isceobj
|
|
|
|
# Valid region in the resampled slc based on offsets
|
|
|
|
####Adjust valid samples and first valid sample here
|
|
|
|
print ("Adjust valid samples")
|
2020-07-02 19:40:49 +00:00
|
|
|
print('Before: ', reference.firstValidSample, reference.numValidSamples)
|
2019-01-16 19:40:08 +00:00
|
|
|
print('Offsets : ', minRng, maxRng)
|
|
|
|
if (minRng > 0) and (maxRng > 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.numValidSamples -= (int(np.ceil(maxRng)) + 8)
|
|
|
|
reference.firstValidSample += 4
|
2019-01-16 19:40:08 +00:00
|
|
|
elif (minRng < 0) and (maxRng < 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidSample -= int(np.floor(minRng) - 4)
|
|
|
|
reference.numValidSamples += int(np.floor(minRng) - 8)
|
2019-01-16 19:40:08 +00:00
|
|
|
elif (minRng < 0) and (maxRng > 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidSample -= int(np.floor(minRng) - 4)
|
|
|
|
reference.numValidSamples += int(np.floor(minRng) - 8) - int(np.ceil(maxRng))
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
print('After: ', reference.firstValidSample, reference.numValidSamples)
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
###Adjust valid lines and first valid line here
|
|
|
|
print ("Adjust valid lines")
|
2020-07-02 19:40:49 +00:00
|
|
|
print('Before: ', reference.firstValidLine, reference.numValidLines)
|
2019-01-16 19:40:08 +00:00
|
|
|
print('Offsets : ', minAz, maxAz)
|
|
|
|
if (minAz > 0) and (maxAz > 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.numValidLines -= (int(np.ceil(maxAz)) + 8)
|
|
|
|
reference.firstValidLine += 4
|
2019-01-16 19:40:08 +00:00
|
|
|
elif (minAz < 0) and (maxAz < 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidLine -= int(np.floor(minAz) - 4)
|
|
|
|
reference.numValidLines += int(np.floor(minAz) - 8)
|
2019-01-16 19:40:08 +00:00
|
|
|
elif (minAz < 0) and (maxAz > 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidLine -= int(np.floor(minAz) - 4)
|
|
|
|
reference.numValidLines += int(np.floor(minAz) - 8) - int(np.ceil(maxAz))
|
|
|
|
print('After:', reference.firstValidLine, reference.numValidLines)
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
def adjustValidSampleLine_V2(reference, secondary, minAz=0, maxAz=0, minRng=0, maxRng=0):
|
2019-01-16 19:40:08 +00:00
|
|
|
import numpy as np
|
|
|
|
import isce
|
|
|
|
import isceobj
|
|
|
|
####Adjust valid samples and first valid sample here
|
|
|
|
print ("Adjust valid samples")
|
2020-07-02 19:40:49 +00:00
|
|
|
print('Before: ', reference.firstValidSample, reference.numValidSamples)
|
2019-01-16 19:40:08 +00:00
|
|
|
print('Offsets : ', minRng, maxRng)
|
|
|
|
|
2019-03-02 01:20:12 +00:00
|
|
|
if (minRng > 0) and (maxRng > 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidSample = secondary.firstValidSample - int(np.floor(maxRng)-4)
|
|
|
|
lastValidSample = reference.firstValidSample - 8 + secondary.numValidSamples
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
if lastValidSample < reference.numberOfSamples:
|
|
|
|
reference.numValidSamples = secondary.numValidSamples - 8
|
2019-01-16 19:40:08 +00:00
|
|
|
else:
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.numValidSamples = reference.numberOfSamples - reference.firstValidSample
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
elif (minRng < 0) and (maxRng < 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidSample = secondary.firstValidSample - int(np.floor(minRng) - 4)
|
|
|
|
lastValidSample = reference.firstValidSample + secondary.numValidSamples - 8
|
|
|
|
if lastValidSample < reference.numberOfSamples:
|
|
|
|
reference.numValidSamples = secondary.numValidSamples - 8
|
2019-01-16 19:40:08 +00:00
|
|
|
else:
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.numValidSamples = reference.numberOfSamples - reference.firstValidSample
|
2019-01-16 19:40:08 +00:00
|
|
|
elif (minRng < 0) and (maxRng > 0):
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidSample = secondary.firstValidSample - int(np.floor(minRng) - 4)
|
|
|
|
lastValidSample = reference.firstValidSample + secondary.numValidSamples + int(np.floor(minRng) - 8) - int(np.ceil(maxRng))
|
|
|
|
if lastValidSample < reference.numberOfSamples:
|
|
|
|
reference.numValidSamples = secondary.numValidSamples + int(np.floor(minRng) - 8) - int(np.ceil(maxRng))
|
2019-01-16 19:40:08 +00:00
|
|
|
else:
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.numValidSamples = reference.numberOfSamples - reference.firstValidSample
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidSample = np.max([0, reference.firstValidSample])
|
2019-01-30 00:23:32 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
print('After: ', reference.firstValidSample, reference.numValidSamples)
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
###Adjust valid lines and first valid line here
|
|
|
|
print ("Adjust valid lines")
|
2020-07-02 19:40:49 +00:00
|
|
|
print('Before: ', reference.firstValidLine, reference.numValidLines)
|
2019-01-16 19:40:08 +00:00
|
|
|
print('Offsets : ', minAz, maxAz)
|
|
|
|
|
|
|
|
if (minAz > 0) and (maxAz > 0):
|
|
|
|
|
2021-06-14 04:13:55 +00:00
|
|
|
reference.firstValidLine = secondary.firstValidLine - int(np.floor(maxAz) - 4)
|
|
|
|
lastValidLine = reference.firstValidLine - 8 + secondary.numValidLines
|
|
|
|
if lastValidLine < reference.numberOfLines:
|
|
|
|
reference.numValidLines = secondary.numValidLines - 8
|
|
|
|
else:
|
|
|
|
reference.numValidLines = reference.numberOfLines - reference.firstValidLine
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
elif (minAz < 0) and (maxAz < 0):
|
2021-06-14 04:13:55 +00:00
|
|
|
reference.firstValidLine = secondary.firstValidLine - int(np.floor(minAz) - 4)
|
|
|
|
lastValidLine = reference.firstValidLine + secondary.numValidLines - 8
|
|
|
|
if lastValidLine < reference.numberOfLines:
|
|
|
|
reference.numValidLines = secondary.numValidLines - 8
|
|
|
|
else:
|
|
|
|
reference.numValidLines = reference.numberOfLines - reference.firstValidLine
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
elif (minAz < 0) and (maxAz > 0):
|
2021-06-14 04:13:55 +00:00
|
|
|
reference.firstValidLine = secondary.firstValidLine - int(np.floor(minAz) - 4)
|
|
|
|
lastValidLine = reference.firstValidLine + secondary.numValidLines + int(np.floor(minAz) - 8) - int(np.ceil(maxAz))
|
|
|
|
if lastValidLine < reference.numberOfLines:
|
|
|
|
reference.numValidLines = secondary.numValidLines + int(np.floor(minAz) - 8) - int(np.ceil(maxAz))
|
|
|
|
else:
|
|
|
|
reference.numValidLines = reference.numberOfLines - reference.firstValidLine
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
return reference
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2021-06-14 04:13:55 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
def adjustCommonValidRegion(reference,secondary):
|
|
|
|
# valid lines between reference and secondary
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
reference_lastValidLine = reference.firstValidLine + reference.numValidLines - 1
|
|
|
|
reference_lastValidSample = reference.firstValidSample + reference.numValidSamples - 1
|
|
|
|
secondary_lastValidLine = secondary.firstValidLine + secondary.numValidLines - 1
|
|
|
|
secondary_lastValidSample = secondary.firstValidSample + secondary.numValidSamples - 1
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
igram_lastValidLine = min(reference_lastValidLine, secondary_lastValidLine)
|
|
|
|
igram_lastValidSample = min(reference_lastValidSample, secondary_lastValidSample)
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.firstValidLine = max(reference.firstValidLine, secondary.firstValidLine)
|
|
|
|
reference.firstValidSample = max(reference.firstValidSample, secondary.firstValidSample)
|
2019-01-16 19:40:08 +00:00
|
|
|
|
2020-06-07 03:44:00 +00:00
|
|
|
#set to 0 to avoid negative values
|
2020-07-02 19:40:49 +00:00
|
|
|
if reference.firstValidLine<0:
|
|
|
|
reference.firstValidLine=0
|
|
|
|
if reference.firstValidSample<0:
|
|
|
|
reference.firstValidSample=0
|
2020-06-07 03:44:00 +00:00
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
reference.numValidLines = igram_lastValidLine - reference.firstValidLine + 1
|
|
|
|
reference.numValidSamples = igram_lastValidSample - reference.firstValidSample + 1
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
|
2020-07-02 19:40:49 +00:00
|
|
|
def getValidLines(secondary, rdict, inname, misreg_az=0.0, misreg_rng=0.0):
|
2019-01-16 19:40:08 +00:00
|
|
|
'''
|
2020-07-02 19:40:49 +00:00
|
|
|
Looks at the reference, secondary and azimuth offsets and gets the Interferogram valid lines
|
2019-01-16 19:40:08 +00:00
|
|
|
'''
|
|
|
|
import numpy as np
|
|
|
|
import isce
|
|
|
|
import isceobj
|
|
|
|
|
|
|
|
dimg = isceobj.createSlcImage()
|
|
|
|
dimg.load(inname + '.xml')
|
|
|
|
shp = (dimg.length, dimg.width)
|
|
|
|
az = np.fromfile(rdict['azimuthOff'], dtype=np.float32).reshape(shp)
|
|
|
|
az += misreg_az
|
|
|
|
aa = np.zeros(az.shape)
|
|
|
|
aa[:,:] = az
|
|
|
|
aa[aa < -10000.0] = np.nan
|
|
|
|
amin = np.nanmin(aa)
|
|
|
|
amax = np.nanmax(aa)
|
|
|
|
|
|
|
|
rng = np.fromfile(rdict['rangeOff'], dtype=np.float32).reshape(shp)
|
|
|
|
rng += misreg_rng
|
|
|
|
rr = np.zeros(rng.shape)
|
|
|
|
rr[:,:] = rng
|
|
|
|
rr[rr < -10000.0] = np.nan
|
|
|
|
rmin = np.nanmin(rr)
|
|
|
|
rmax = np.nanmax(rr)
|
|
|
|
|
|
|
|
return amin, amax, rmin, rmax
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def asBaseClass(inobj):
|
|
|
|
'''
|
|
|
|
Return as TOPSSwathSLCProduct.
|
|
|
|
'''
|
|
|
|
from isceobj.Sensor.TOPS.TOPSSwathSLCProduct import TOPSSwathSLCProduct
|
|
|
|
|
|
|
|
|
|
|
|
def topsproduct(cobj):
|
|
|
|
obj = TOPSSwathSLCProduct()
|
|
|
|
obj.configure()
|
|
|
|
|
|
|
|
for x in obj.parameter_list:
|
|
|
|
val = getattr(cobj, x.attrname)
|
|
|
|
setattr(obj, x.attrname, val)
|
|
|
|
|
|
|
|
for x in obj.facility_list:
|
|
|
|
attrname = x.public_name
|
|
|
|
val = getattr(cobj, x.attrname)
|
|
|
|
setattr(obj, x.attrname, val)
|
|
|
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(inobj, coregSwathSLCProduct):
|
|
|
|
return topsproduct(inobj)
|
|
|
|
|
|
|
|
elif isinstance(inobj, TOPSSwathSLCProduct):
|
|
|
|
return inobj
|
|
|
|
else:
|
|
|
|
raise Exception('Cannot be converted to TOPSSwathSLCProduct')
|
|
|
|
|
2021-06-14 04:13:55 +00:00
|
|
|
|
2019-01-16 19:40:08 +00:00
|
|
|
def getSwathList(indir):
|
|
|
|
|
|
|
|
swathList = []
|
|
|
|
for x in [1,2,3]:
|
2021-06-14 04:13:55 +00:00
|
|
|
SW = os.path.join(indir,'IW{0}'.format(x))
|
|
|
|
if os.path.exists(SW):
|
|
|
|
swathList.append(x)
|
2019-01-16 19:40:08 +00:00
|
|
|
|
|
|
|
return swathList
|
|
|
|
|
|
|
|
|
|
|
|
|