diff --git a/SConstruct b/SConstruct index 8e653fe..a979b3c 100644 --- a/SConstruct +++ b/SConstruct @@ -216,43 +216,12 @@ else: ### End of GPU branch-specific modifications -file = '__init__.py' -if not os.path.exists(file): - fout = open(file,"w") - fout.write("#!/usr/bin/env python3") - fout.close() - -env.Install(inst,file) -try: - from subprocess import check_output - svn_revision = check_output('svnversion').strip() or 'Unknown' - if sys.version_info[0] == 3: - svn_revision = svn_revision.decode('utf-8') -except ImportError: - try: - import popen2 - stdout, stdin, stderr = popen2.popen3('svnversion') - svn_revision = stdout.read().strip() - if stderr.read(): - raise Exception - except Exception: - svn_revision = 'Unknown' -except OSError: - svn_revision = 'Unknown' +env.Install(inst, '__init__.py') +env.Install(inst, 'release_history.py') if not os.path.exists(inst): os.makedirs(inst) -fvers = open(os.path.join(inst,'version.py'),'w') - -from release_history import release_version, release_svn_revision, release_date -fvers_lines = ["release_version = '"+release_version+"'\n", - "release_svn_revision = '"+release_svn_revision+"'\n", - "release_date = '"+release_date+"'\n", - "svn_revision = '"+svn_revision+"'\n\n"] - -fvers.write(''.join(fvers_lines)) -fvers.close() v = 0 if isrerun == 'no': cmd = 'scons -Q install --isrerun=yes' diff --git a/__init__.py b/__init__.py index 138b442..a6e2c5b 100755 --- a/__init__.py +++ b/__init__.py @@ -25,13 +25,9 @@ # Author: Giangi Sacco #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - -from __future__ import print_function - -from .version import release_version, release_svn_revision, release_date -from .version import svn_revision +from .release_history import release_version, release_svn_revision, release_date +svn_revision = release_svn_revision +version = release_history # compatibility alias __version__ = release_version diff --git a/components/isceobj/StripmapProc/runDispersive.py b/components/isceobj/StripmapProc/runDispersive.py index 305022b..724c189 100644 --- a/components/isceobj/StripmapProc/runDispersive.py +++ b/components/isceobj/StripmapProc/runDispersive.py @@ -9,7 +9,6 @@ from isceobj.Constants import SPEED_OF_LIGHT import numpy as np import gdal -from scipy import ndimage try: import cv2 except ImportError: @@ -296,6 +295,8 @@ def fill(data, invalid=None): Output: Return a filled array. """ + from scipy import ndimage + if invalid is None: invalid = np.isnan(data) ind = ndimage.distance_transform_edt(invalid, diff --git a/components/isceobj/StripmapProc/runResampleSlc.py b/components/isceobj/StripmapProc/runResampleSlc.py index c108c98..b1dfa72 100644 --- a/components/isceobj/StripmapProc/runResampleSlc.py +++ b/components/isceobj/StripmapProc/runResampleSlc.py @@ -75,6 +75,7 @@ def runResampleSlc(self, kind='coarse'): if kind in ['coarse', 'refined']: azname = os.path.join(offsetsDir, self.insar.azimuthOffsetFilename) rgname = os.path.join(offsetsDir, self.insar.rangeOffsetFilename) + flatten = True else: azname = os.path.join(offsetsDir, self.insar.azimuthRubbersheetFilename) if self.doRubbersheetingRange: diff --git a/components/isceobj/StripmapProc/runRubbersheet.py b/components/isceobj/StripmapProc/runRubbersheet.py index b16a58e..ea417bd 100644 --- a/components/isceobj/StripmapProc/runRubbersheet.py +++ b/components/isceobj/StripmapProc/runRubbersheet.py @@ -6,7 +6,6 @@ import isce import isceobj from osgeo import gdal -from scipy import ndimage import numpy as np import os @@ -24,6 +23,9 @@ def fill(data, invalid=None): Output: Return a filled array. """ + + from scipy import ndimage + if invalid is None: invalid = np.isnan(data) ind = ndimage.distance_transform_edt(invalid, @@ -35,6 +37,8 @@ def fill(data, invalid=None): def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName): #masking and Filtering + from scipy import ndimage + ##Read in the offset file ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly) Offset = ds.GetRasterBand(1).ReadAsArray() diff --git a/components/isceobj/StripmapProc/runRubbersheetAzimuth.py b/components/isceobj/StripmapProc/runRubbersheetAzimuth.py index 75583f1..43ee4a8 100755 --- a/components/isceobj/StripmapProc/runRubbersheetAzimuth.py +++ b/components/isceobj/StripmapProc/runRubbersheetAzimuth.py @@ -9,14 +9,14 @@ import isce import isceobj from osgeo import gdal -from scipy import ndimage -from astropy.convolution import convolve import numpy as np import os def mask_filterNoSNR(denseOffsetFile,filterSize,outName): # Masking the offsets with a data-based approach - + + from scipy import ndimage + # Open the offsets ds = gdal.Open(denseOffsetFile+'.vrt',gdal.GA_ReadOnly) off_az = ds.GetRasterBand(1).ReadAsArray() @@ -79,6 +79,9 @@ def mask_filterNoSNR(denseOffsetFile,filterSize,outName): def off_masking(off,filterSize,thre=2): + + from scipy import ndimage + # Define the mask to fill the offsets vram = ndimage.median_filter(off.real, filterSize) vazm = ndimage.median_filter(off.imag, filterSize) @@ -112,6 +115,8 @@ def fill(data, invalid=None): def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName): #masking and Filtering + from scipy import ndimage + ##Read in the offset file ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly) Offset = ds.GetRasterBand(band).ReadAsArray() @@ -154,7 +159,9 @@ def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outNam return None def fill_with_smoothed(off,filterSize): - + + from astropy.convolution import convolve + off_2filt=np.copy(off) kernel = np.ones((filterSize,filterSize),np.float32)/(filterSize*filterSize) loop = 0 diff --git a/components/isceobj/StripmapProc/runRubbersheetRange.py b/components/isceobj/StripmapProc/runRubbersheetRange.py index 2f1ab3f..04fc2a2 100755 --- a/components/isceobj/StripmapProc/runRubbersheetRange.py +++ b/components/isceobj/StripmapProc/runRubbersheetRange.py @@ -9,15 +9,14 @@ import isce import isceobj from osgeo import gdal -from scipy import ndimage import numpy as np import os -from astropy.convolution import convolve - def mask_filterNoSNR(denseOffsetFile,filterSize,outName): # Masking the offsets with a data-based approach - + + from scipy import ndimage + # Open the offsets ds = gdal.Open(denseOffsetFile+'.vrt',gdal.GA_ReadOnly) off_az = ds.GetRasterBand(1).ReadAsArray() @@ -78,6 +77,9 @@ def mask_filterNoSNR(denseOffsetFile,filterSize,outName): return def off_masking(off,filterSize,thre=2): + + from scipy import ndimage + vram = ndimage.median_filter(off.real, filterSize) vazm = ndimage.median_filter(off.imag, filterSize) @@ -100,6 +102,8 @@ def fill(data, invalid=None): Output: Return a filled array. """ + from scipy import ndimage + if invalid is None: invalid = np.isnan(data) ind = ndimage.distance_transform_edt(invalid, @@ -108,7 +112,9 @@ def fill(data, invalid=None): return data[tuple(ind)] def fill_with_smoothed(off,filterSize): - + + from astropy.convolution import convolve + off_2filt=np.copy(off) kernel = np.ones((filterSize,filterSize),np.float32)/(filterSize*filterSize) loop = 0 @@ -131,6 +137,8 @@ def fill_with_smoothed(off,filterSize): def mask_filter(denseOffsetFile, snrFile, band, snrThreshold, filterSize, outName): #masking and Filtering + from scipy import ndimage + ##Read in the offset file ds = gdal.Open(denseOffsetFile + '.vrt', gdal.GA_ReadOnly) Offset = ds.GetRasterBand(band).ReadAsArray() @@ -236,6 +244,8 @@ def resampleOffset(maskedFiltOffset, geometryOffset, outName): def runRubbersheetRange(self): + from scipy import ndimage + if not self.doRubbersheetingRange: print('Rubber sheeting in azimuth not requested ... skipping') return diff --git a/components/isceobj/TopsProc/runIon.py b/components/isceobj/TopsProc/runIon.py index 8407287..d0c4af6 100644 --- a/components/isceobj/TopsProc/runIon.py +++ b/components/isceobj/TopsProc/runIon.py @@ -9,9 +9,6 @@ import shutil import datetime import numpy as np import numpy.matlib -import scipy.signal as ss -from scipy import interpolate -from scipy.interpolate import interp1d import isceobj import logging @@ -638,6 +635,7 @@ def cal_coherence(inf, win=5, edge=0): 4: keep all samples ''' + import scipy.signal as ss if win % 2 != 1: raise Exception('window size must be odd!') @@ -1682,6 +1680,9 @@ def computeDopplerOffset(burst, firstline, lastline, firstcolumn, lastcolumn, nr output: first lines > 0, last lines < 0 ''' + from scipy import interpolate + from scipy.interpolate import interp1d + Vs = np.linalg.norm(burst.orbit.interpolateOrbit(burst.sensingMid, method='hermite').getVelocity()) Ks = 2 * Vs * burst.azimuthSteeringRate / burst.radarWavelength @@ -1830,6 +1831,7 @@ def adaptive_gaussian(ionos, wgt, size_max, size_min): size_max: maximum window size size_min: minimum window size ''' + import scipy.signal as ss length = (ionos.shape)[0] width = (ionos.shape)[1] @@ -1892,6 +1894,8 @@ def filt_gaussian(self, ionParam): currently not implemented. a less accurate method is to use ionsphere without any projection ''' + from scipy import interpolate + from scipy.interpolate import interp1d ################################################# #SET PARAMETERS HERE @@ -2659,5 +2663,3 @@ def runIon(self): #esd_noion(self, ionParam) return - - \ No newline at end of file diff --git a/components/isceobj/TopsProc/runOffsetFilter.py b/components/isceobj/TopsProc/runOffsetFilter.py index 51735d9..e9989d9 100644 --- a/components/isceobj/TopsProc/runOffsetFilter.py +++ b/components/isceobj/TopsProc/runOffsetFilter.py @@ -3,7 +3,6 @@ # Copyright 2016 # -from scipy.ndimage.filters import median_filter import numpy as np import isce import isceobj @@ -20,6 +19,8 @@ def runOffsetFilter(self): if not self.doDenseOffsets: return + from scipy.ndimage.filters import median_filter + offsetfile = os.path.join(self._insar.mergedDirname, self._insar.offsetfile) snrfile = os.path.join(self._insar.mergedDirname, self._insar.snrfile) print('\n======================================') diff --git a/components/isceobj/TopsProc/runPrepESD.py b/components/isceobj/TopsProc/runPrepESD.py index 5d65b78..0cf9c3c 100755 --- a/components/isceobj/TopsProc/runPrepESD.py +++ b/components/isceobj/TopsProc/runPrepESD.py @@ -8,7 +8,6 @@ import numpy as np import os import isceobj import logging -import scipy.signal as SS from isceobj.Util.ImageUtil import ImageLib as IML import datetime import pprint @@ -177,6 +176,7 @@ def createCoherence(intfile, win=5): ''' Compute coherence using scipy convolve 2D. ''' + import scipy.signal as SS corfile = os.path.splitext(intfile)[0] + '.cor' filt = np.ones((win,win))/ (1.0*win*win) diff --git a/contrib/stack/stripmapStack/Stack.py b/contrib/stack/stripmapStack/Stack.py index 8c736b8..b82b2f2 100755 --- a/contrib/stack/stripmapStack/Stack.py +++ b/contrib/stack/stripmapStack/Stack.py @@ -197,6 +197,8 @@ class config(object): self.f.write('nomcf : ' + self.noMCF + '\n') self.f.write('master : ' + self.master + '\n') self.f.write('defomax : ' + self.defoMax + '\n') + self.f.write('alks : ' + self.alks + '\n') + self.f.write('rlks : ' + self.rlks + '\n') self.f.write('method : ' + self.unwMethod + '\n') self.f.write('##########################'+'\n') diff --git a/contrib/stack/stripmapStack/unwrap.py b/contrib/stack/stripmapStack/unwrap.py index bae4893..77080ce 100755 --- a/contrib/stack/stripmapStack/unwrap.py +++ b/contrib/stack/stripmapStack/unwrap.py @@ -113,9 +113,19 @@ def extractInfoFromPickle(pckfile, inps): data['earthRadius'] = elp.local_radius_of_curvature(llh.lat, hdg) #azspacing = burst.azimuthTimeInterval * sv.getScalarVelocity() - azres = 20.0 + #azres = 20.0 + azspacing = sv.getScalarVelocity() / burst.PRF + azres = burst.platform.antennaLength / 2.0 + azfact = azres / azspacing + + burst.getInstrument() + rgBandwidth = burst.instrument.pulseLength * burst.instrument.chirpSlope + rgres = abs(SPEED_OF_LIGHT / (2.0 * rgBandwidth)) + rgspacing = burst.instrument.rangePixelSize + rgfact = rgres / rgspacing #data['corrlooks'] = inps.rglooks * inps.azlooks * azspacing / azres + data['corrlooks'] = inps.rglooks * inps.azlooks / (azfact * rgfact) data['rglooks'] = inps.rglooks data['azlooks'] = inps.azlooks @@ -149,7 +159,7 @@ def runUnwrap(infile, outfile, corfile, config, costMode = None,initMethod = Non altitude = config['altitude'] rangeLooks = config['rglooks'] azimuthLooks = config['azlooks'] - #corrLooks = config['corrlooks'] + corrLooks = config['corrlooks'] maxComponents = 20 snp = Snaphu() @@ -163,7 +173,7 @@ def runUnwrap(infile, outfile, corfile, config, costMode = None,initMethod = Non snp.setAltitude(altitude) snp.setCorrfile(corfile) snp.setInitMethod(initMethod) - # snp.setCorrLooks(corrLooks) + snp.setCorrLooks(corrLooks) snp.setMaxComponents(maxComponents) snp.setDefoMaxCycles(defomax) snp.setRangeLooks(rangeLooks) @@ -248,33 +258,34 @@ def runUnwrapIcu(infile, outfile): unwImage.finalizeImage() unwImage.renderHdr() -def runUnwrap2Stage(unwrappedIntFilename,connectedComponentsFilename,unwrapped2StageFilename, unwrapper_2stage_name=None, solver_2stage=None): +def runUnwrap2Stage(unwrappedIntFilename,connectedComponentsFilename,unwrapped2StageFilename, + unwrapper_2stage_name=None, solver_2stage=None): - if unwrapper_2stage_name is None: - unwrapper_2stage_name = 'REDARC0' - - if solver_2stage is None: - # If unwrapper_2state_name is MCF then solver is ignored - # and relaxIV MCF solver is used by default - solver_2stage = 'pulp' - - print('Unwrap 2 Stage Settings:') - print('Name: %s'%unwrapper_2stage_name) - print('Solver: %s'%solver_2stage) - - inpFile = unwrappedIntFilename - ccFile = connectedComponentsFilename - outFile = unwrapped2StageFilename - - # Hand over to 2Stage unwrap - unw = UnwrapComponents() - unw.setInpFile(inpFile) - unw.setConnCompFile(ccFile) - unw.setOutFile(outFile) - unw.setSolver(solver_2stage) - unw.setRedArcs(unwrapper_2stage_name) - unw.unwrapComponents() - return + if unwrapper_2stage_name is None: + unwrapper_2stage_name = 'REDARC0' + + if solver_2stage is None: + # If unwrapper_2state_name is MCF then solver is ignored + # and relaxIV MCF solver is used by default + solver_2stage = 'pulp' + + print('Unwrap 2 Stage Settings:') + print('Name: %s'%unwrapper_2stage_name) + print('Solver: %s'%solver_2stage) + + inpFile = unwrappedIntFilename + ccFile = connectedComponentsFilename + outFile = unwrapped2StageFilename + + # Hand over to 2Stage unwrap + unw = UnwrapComponents() + unw.setInpFile(inpFile) + unw.setConnCompFile(ccFile) + unw.setOutFile(outFile) + unw.setSolver(solver_2stage) + unw.setRedArcs(unwrapper_2stage_name) + unw.unwrapComponents() + return def main(iargs=None): @@ -293,24 +304,26 @@ def main(iargs=None): if inps.method != 'icu': - masterShelveDir = os.path.join(interferogramDir , 'masterShelve') - if not os.path.exists(masterShelveDir): - os.makedirs(masterShelveDir) + masterShelveDir = os.path.join(interferogramDir , 'masterShelve') + if not os.path.exists(masterShelveDir): + os.makedirs(masterShelveDir) + + inps.master = os.path.dirname(inps.master) + cpCmd='cp ' + os.path.join(inps.master, 'data*') +' '+masterShelveDir + os.system(cpCmd) + pckfile = os.path.join(masterShelveDir,'data') + print(pckfile) + metadata = extractInfoFromPickle(pckfile, inps) - inps.master = os.path.dirname(inps.master) - cpCmd='cp ' + os.path.join(inps.master, 'data*') +' '+masterShelveDir - os.system(cpCmd) - pckfile = os.path.join(masterShelveDir,'data') - print(pckfile) - metadata = extractInfoFromPickle(pckfile, inps) ######## print ('unwrapping method : ' , inps.method) if inps.method == 'snaphu': - if inps.nomcf: - fncall = runUnwrap - else: - fncall = runUnwrapMcf - fncall(inps.intfile, inps.unwprefix + '_snaphu.unw', inps.cohfile, metadata, defomax=inps.defomax) + if inps.nomcf: + fncall = runUnwrap + else: + fncall = runUnwrapMcf + fncall(inps.intfile, inps.unwprefix + '_snaphu.unw', inps.cohfile, metadata, defomax=inps.defomax) + elif inps.method == 'snaphu2stage': if inps.nomcf: fncall = runUnwrap @@ -319,11 +332,12 @@ def main(iargs=None): fncall(inps.intfile, inps.unwprefix + '_snaphu.unw', inps.cohfile, metadata, defomax=inps.defomax) # adding in the two-stage - runUnwrap2Stage(inps.unwprefix + '_snaphu.unw', inps.unwprefix + '_snaphu.unw.conncomp',inps.unwprefix + '_snaphu2stage.unw') - + runUnwrap2Stage(inps.unwprefix + '_snaphu.unw', + inps.unwprefix + '_snaphu.unw.conncomp', + inps.unwprefix + '_snaphu2stage.unw') elif inps.method == 'icu': - runUnwrapIcu(inps.intfile, inps.unwprefix + '_icu.unw') + runUnwrapIcu(inps.intfile, inps.unwprefix + '_icu.unw') if __name__ == '__main__': diff --git a/examples/input_files/stripmapApp.xml b/examples/input_files/stripmapApp.xml index f4eff23..87c1365 100644 --- a/examples/input_files/stripmapApp.xml +++ b/examples/input_files/stripmapApp.xml @@ -12,7 +12,8 @@ /Users/fattahi/process/test_roiApp/Alos_Maule_T116/demLat_S39_S35_Lon_W074_W071.dem.wgs84 True True