def addSlc(self): from isceobj.Util import Poly2D from isceobj.Constants import SPEED_OF_LIGHT formslc = self._inputPorts['slc'] if (formslc): ####Set up azimuth carrier information coeffs = [] coeffs.append([ 2 * np.pi * val for val in formslc.dopplerCentroidCoefficients ]) self.dopplerPoly = Poly2D.Poly2D() self.dopplerPoly.initPoly( rangeOrder=len(formslc.dopplerCentroidCoefficients) - 1, azimuthOrder=0, coeffs=coeffs) ######Setup range carrier information delr = 0.5 * SPEED_OF_LIGHT / formslc.rangeSamplingRate self.slantRangePixelSpacing = delr self.radarWavelength = formslc.radarWavelength # coeffs = [[0.0, -4 * np.pi * delr/self.radarWavelength]] # self.rangeCarrierPoly = Poly2D.Poly2D() # self.rangeCarrierPoly.initPoly(rangeOrder=1, azimuthOrder=0, coeffs=coeffs) img = isceobj.createImage() IU.copyAttributes(formslc.slcImage, img) img.setAccessMode('read') self.imageIn = img
def parseParFile(self): '''Parse the par file if any is available.''' if self._parFile not in (None, ''): par = ParFile(self._parFile) ####Update orbit svs = par['prep_block']['sensor']['ephemeris']['sv_block'][ 'state_vector'] datefmt = '%Y%m%d%H%M%S%f' for entry in svs: sv = StateVector() sv.setPosition( [float(entry['x']), float(entry['y']), float(entry['z'])]) sv.setVelocity([ float(entry['xv']), float(entry['yv']), float(entry['zv']) ]) sv.setTime(datetime.datetime.strptime(entry['Date'], datefmt)) self.frame.orbit.addStateVector(sv) self.frame.orbit._stateVectors = sorted( self.frame.orbit._stateVectors, key=lambda x: x.getTime()) doppinfo = par['prep_block']['sensor']['beam'][ 'DopplerCentroidParameters'] #######Selectively update some values. #######Currently used only for doppler centroids. self.doppler_ref_range = float(doppinfo['reference_range']) self.doppler_ref_azi = datetime.datetime.strptime( doppinfo['reference_date'], '%Y%m%d%H%M%S%f') self.doppler_predict = float(doppinfo['Predict_doppler']) self.doppler_DAR = float(doppinfo['DAR_doppler']) coeff = doppinfo['doppler_centroid_coefficients'] rngOrder = int(coeff['number_of_coefficients_first_dimension']) - 1 azOrder = int(coeff['number_of_coefficients_second_dimension']) - 1 self.doppler_coeff = Poly2D.Poly2D() self.doppler_coeff.initPoly(rangeOrder=rngOrder, azimuthOrder=azOrder) self.doppler_coeff.setMeanRange(self.doppler_ref_range) self.doppler_coeff.setMeanAzimuth( secondsSinceMidnight(self.doppler_ref_azi)) parms = [] for ii in range(azOrder + 1): row = [] for jj in range(rngOrder + 1): key = 'a%d%d' % (ii, jj) val = float(coeff[key]) row.append(val) parms.append(row) self.doppler_coeff.setCoeffs(parms)
def createImages(self): #assume that even if an image is passed, the createImage and finalizeImage are called here if self.demImage is None and not self.demFilename == '': self.demImage = IF.createDemImage() demAccessMode = 'read' demWidth = self.demWidth self.demImage.initImage(self.demFilename,demAccessMode,demWidth) elif self.demImage is None:#this should never happen, atleast when using the correct method. same for other images self.logger.error('Must either pass the demImage in the call or set self.demFilename.') raise Exception if(self.latImage == None and not self.latFilename == ''): self.latImage = IF.createImage() accessMode = 'write' dataType = 'DOUBLE' width = self.width self.latImage.initImage(self.latFilename,accessMode,width,dataType) elif(self.latImage == None): self.logger.error('Must either pass the latImage in the call or set self.latFilename.') raise Exception if(self.lonImage == None and not self.lonFilename == ''): self.lonImage = IF.createImage() accessMode = 'write' dataType = 'DOUBLE' width = self.width self.lonImage.initImage(self.lonFilename,accessMode,width,dataType) elif(self.lonImage == None): self.logger.error('Must either pass the lonImage in the call or set self.lonFilename.') raise Exception if(self.heightImage == None and not self.heightFilename == ''): self.heightImage = IF.createImage() accessMode = 'write' dataType = 'DOUBLE' width = self.width self.heightImage.initImage(self.heightFilename,accessMode,width,dataType) elif(self.heightImage == None): self.logger.error('Must either pass the heightImage in the call or set self.heightFilename.') raise Exception ####User provided an input file name for slant range to work with if(self.slantRangeImage == None and not self.slantRangeFilename == ''): if self.rangeFirstSample: raise Exception('Cannot provide both slant range image and range first sample as input') if self.slantRangePixelSpacing: raise Exception('Cannot provide both slant range image and slant range pixel spacing as input') self.slantRangeImage = IF.createImage() self.slantRangeImage.load(self.slantRangeFilename + '.xml') self.slantRangeImage.setAccessMode = 'READ' if self.slantRangeImage.width != self.width: raise Exception('Slant Range Image width {0} does not match input width {1}'.format(self.slantRangeImage.width, self.width)) if self.slantRangeImage.length != self.length: raise Exception('Slant Range Image length {0} does not match input length {1}'.format(self.slantRangeImage.length, self.length)) self.slantRangeImage.createImage() ###Set these to zero since not used but bindings need it - PSA self.rangeFirstSample = 0.0 self.slantRangePixelSpacing = 0.0 ####User provided an image like object (maybe polynomial) elif self.slantRangeImage is not None: if self.slantRangeImage.width != self.width: raise Exception('Slant Range Image width {0} does not match input width {1}'.format(self.slantRangeImage.width, self.width)) if self.slantRangeImage.length != self.length: raise Exception('Slant Range Image length {0} does not match input length {1}'.format(self.slantRangeImage.length, self.length)) #####Standard operation else: r0 = self.rangeFirstSample dr = self.slantRangePixelSpacing*self.numberRangeLooks self.slantRangeImage = Poly2D.Poly2D() self.slantRangeImage.setWidth(self.width) self.slantRangeImage.setLength(self.length) self.slantRangeImage.setNormRange(1.0) self.slantRangeImage.setNormAzimuth(1.0) self.slantRangeImage.setMeanRange(0.0) self.slantRangeImage.setMeanAzimuth(0.0) self.slantRangeImage.initPoly(rangeOrder=1, azimuthOrder=0, coeffs=[[r0,dr]]) if(self.losImage == None and not self.losFilename == ''): self.losImage = IF.createImage() accessMode = 'write' dataType ='FLOAT' bands = 2 scheme = 'BIL' width = self.width self.losImage.initImage(self.losFilename,accessMode,width,dataType,bands=bands,scheme=scheme) if (self.incImage == None and not self.incFilename == ''): self.incImage = IF.createImage() accessMode = 'write' dataType = 'FLOAT' bands = 2 scheme = 'BIL' width = self.width self.incImage.initImage(self.incFilename, accessMode, width, dataType, bands=bands, scheme=scheme) if (self.maskImage == None and not self.maskFilename == ''): self.maskImage = IF.createImage() accessMode = 'write' dataType = 'BYTE' bands = 1 scheme = 'BIL' width = self.width self.maskImage.initImage(self.maskFilename, accessMode, width, dataType, bands=bands, scheme=scheme) #the dem image could have different datatype so create a caster here #the short is the data type used in the fortran. self.demImage.setCaster('read','FLOAT') self.demImage.createImage() self.latImage.createImage() self.lonImage.createImage() self.heightImage.createImage() self.losImage.createImage() if self.incImage: self.incImage.createImage() if self.maskImage: self.maskImage.createImage() return
def setDefaults(self): if self.ellipsoidMajorSemiAxis is None: self.ellipsoidMajorSemiAxis = CN.EarthMajorSemiAxis if self.ellipsoidEccentricitySquared is None: self.ellipsoidEccentricitySquared = CN.EarthEccentricitySquared if self.numberIterations is None: self.numberIterations = 25 if self.secondaryIterations is None: self.secondaryIterations = 10 if self.threshold is None: self.threshold = 0.05 if self.heightFilename == '': self.heightFilename = 'z.rdr' self.logger.warning('The real height file has been given the default name %s' % (self.heightFilename)) if self.latFilename == '': self.latFilename = 'lat.rdr' self.logger.warning('The latitude file has been given the default name %s' % (self.latFilename)) if self.lonFilename == '': self.lonFilename = 'lon.rdr' self.logger.warning('The longitude file has been given the default name %s' % (self.lonFilename)) if self.losFilename == '': self.losFilename = 'los.rdr' self.logger.warning('The los file has been given the default name %s' % (self.losFilename)) if self.pegHeading is None: ###Compute the peg value here and set it tbef = self.sensingStart + datetime.timedelta(seconds=(0.5*self.length / self.prf)) self.pegHeading = np.radians(self.orbit.getENUHeading(tbef)) self.logger.warning('Default Peg heading set to: ' + str(self.pegHeading)) if self.polyDoppler is None: self.polyDoppler = Poly2D.Poly2D(name=self.name+'_dopplerPoly') self.polyDoppler.setWidth(self.width) self.polyDoppler.setLength(self.length) self.polyDoppler.setNormRange(1.0) self.polyDoppler.setNormAzimuth(1.0) self.polyDoppler.setMeanRange(0.0) self.polyDoppler.setMeanAzimuth(0.0) self.polyDoppler.initPoly(rangeOrder=0, azimuthOrder=0, coeffs=[[0.0]]) else: if self.polyDoppler.getWidth() != self.width: raise Exception('Doppler Centroid object does not have the same width as input image') if self.polyDoppler.getLength() != self.length: raise Exception('Doppler Centroid object does not have the same length as input image') if self.demInterpolationMethod is None: self.demInterpolationMethod = 'BILINEAR' else: if self.demInterpolationMethod.upper() not in list(self.interpolationMethods.keys()): raise Exception ('Interpolation method must be one of ' + str(list(self.interpolationMethods.keys()))) if self.orbitInterpolationMethod is None: self.orbitInterpolationMethod = 'HERMITE' else: if self.orbitInterpolationMethod.upper() not in list(self.orbitInterpolationMethods.keys()): raise Exception('Orbit interpolation method must be one of ' + str(list(self.demInterpolationMethods.keys()))) ###Slant range settings if self.slantRangeFilename in ['',None]: if self.slantRangePixelSpacing is None: raise Exception('No slant range file provided. slantRangePixelSpacing cannot be None') if self.rangeFirstSample is None: raise Exception('No slant range file provided. rangeFirstSample cannot be None')
def createImages(self): if self.imageIn._accessor is None: self.imageIn.createImage() self.imageInAccessor = self.imageIn.getImagePointer() if self.imageOut._accessor is None: self.imageOut.createImage() self.imageOutAccessor = self.imageOut.getImagePointer() if self.rangeCarrierPoly is not None: self.rangeCarrierAccessor = self.rangeCarrierPoly.exportToC() else: print('No Range Carrier provided.') print('Assuming zero range carrier.') poly = Poly2D.Poly2D() poly.initPoly(rangeOrder=0, azimuthOrder=0, coeffs=[[0.]]) self.rangeCarrierAccessor = poly.exportToC() if self.azimuthCarrierPoly is not None: self.azimuthCarrierAccessor = self.azimuthCarrierPoly.exportToC() else: poly = Poly2D.Poly2D() poly.initPoly(rangeOrder=0, azimuthOrder=0, coeffs=[[0.]]) self.azimuthCarrierAccessor = poly.exportToC() print('No Azimuth Carrier provided.') print('Assuming zero azimuth carrier.') if self.rangeOffsetsPoly is not None: self.rangeOffsetsAccessor = self.rangeOffsetsPoly.exportToC() else: print('No range offset polynomial provided') poly = Poly2D.Poly2D() poly.initPoly(rangeOrder=0, azimuthOrder=0, coeffs=[[0.]]) self.rangeOffsetsAccessor = poly.exportToC() if self.azimuthOffsetsPoly is not None: self.azimuthOffsetsAccessor = self.azimuthOffsetsPoly.exportToC() else: print('No azimuth offset polynomial provided') poly = Poly2D.Poly2D() poly.initPoly(rangeOrder=0, azimuthOrder=0, coeffs=[[0.]]) self.azimuthOffsetsAccessor = poly.exportToC() if self.residualRangeImage is not None: if self.residualRangeImage._accessor is None: self.residualRangeImage.setCaster('read', 'DOUBLE') self.residualRangeImage.createImage() self.residualRangeAccessor = self.residualRangeImage.getImagePointer( ) else: self.residualRangeAccessor = 0 if self.residualAzimuthImage is not None: if self.residualAzimuthImage._accessor is None: self.residualAzimuthImage.setCaster('read', 'DOUBLE') self.residualAzimuthImage.createImage() self.residualAzimuthAccessor = self.residualAzimuthImage.getImagePointer( ) else: self.residualAzimuthAccessor = 0 if self.dopplerPoly is not None: self.dopplerAccessor = self.dopplerPoly.exportToC() else: print('No doppler polynomial provided') print('Assuming zero doppler centroid') poly = Poly2D.Poly2D() poly.initPoly(rangeOrder=0, azimuthOrder=0, coeffs=[[0.]]) self.dopplerAccessor = poly.exportToC()
def setDefaults(self): if self.ellipsoidMajorSemiAxis is None: self.ellipsoidMajorSemiAxis = CN.EarthMajorSemiAxis if self.ellipsoidEccentricitySquared is None: self.ellipsoidEccentricitySquared = CN.EarthEccentricitySquared if self.isMocomp is None: self.isMocomp = (8192 - 2048) / 2 if self.numberIterations is None: self.numberIterations = 25 if self.heightRFilename == '': self.heightRFilename = 'z.rdr' self.logger.warning( 'The real height file has been given the default name %s' % (self.heightRFilename)) if self.heightSchFilename == '': self.heightSchFilename = 'zsch.rdr' self.logger.warning( 'The sch height file has been given the default name %s' % (self.heightSchFilename)) if self.latFilename == '': self.latFilename = 'lat.rdr' self.logger.warning( 'The latitude file has been given the default name %s' % (self.latFilename)) if self.lonFilename == '': self.lonFilename = 'lon.rdr' self.logger.warning( 'The longitude file has been given the default name %s' % (self.lonFilename)) if self.losFilename == '': self.losFilename = 'los.rdr' self.logger.warning( 'The los file has been given the default name %s' % (self.losFilename)) if self.polyDoppler is None: self.polyDoppler = Poly2D.Poly2D(name=self.name + '_topoPoly') self.polyDoppler.setWidth(self.width) self.polyDoppler.setLength(self.length) self.polyDoppler.setNormRange(1.0 / (1.0 * self.numberRangeLooks)) self.polyDoppler.setNormAzimuth(1.0 / (1.0 * self.numberAzimuthLooks)) self.polyDoppler.setMeanRange(0.) self.polyDoppler.setMeanAzimuth(0.) self.polyDoppler.initPoly( rangeOrder=len(self.dopplerCentroidCoeffs) - 1, azimuthOrder=0, coeffs=[self.dopplerCentroidCoeffs]) if self.demInterpolationMethod is None: self.demInterpolationMethod = 'BILINEAR' else: if self.demInterpolationMethod.upper() not in list( self.interpolationMethods.keys()): raise Exception('Interpolation method must be one of ' + str(list(self.interpolationMethods.keys())))
def getFitPolynomials(self,rangeOrder=2,azimuthOrder=2,maxOrder=True, usenumpy=False): from stdproc.stdproc.offsetpoly.Offsetpoly import Offsetpoly from isceobj.Util import Poly2D numCoeff = 0 ####Try and use Howard's polynomial fit code whenever possible if (rangeOrder == azimuthOrder) and (rangeOrder <= 3): if (rangeOrder == 1): if maxOrder: numCoeff = 3 else: numCoeff = 4 elif (rangeOrder == 2): if maxOrder: numCoeff = 6 elif (rangeOrder == 3): if maxOrder: numCoeff = 10 inArr = np.array(self.unpackOffsets()) azmin = np.min(inArr[:,2]) inArr[:,2] -= azmin ####Use Howard's code if (numCoeff != 0) and not usenumpy: x = list(inArr[:,0]) y = list(inArr[:,2]) dx = list(inArr[:,1]) dy = list(inArr[:,3]) sig = list(inArr[:,4]) ####Range Offsets obj = Offsetpoly() obj.setLocationAcross(x) obj.setLocationDown(y) obj.setSNR(sig) obj.setOffset(dx) obj.numberFitCoefficients = numCoeff obj.offsetpoly() val = obj.offsetPoly #####Unpack into 2D array if numCoeff == 3: coeffs = [[val[0], val[1]], [val[2], 0.0]] elif numCoeff == 4: coeffs = [[val[0], val[1]], [val[2], val[3]]] elif numCoeff == 6: coeffs = [[val[0], val[1], val[4]], [val[2], val[3], 0.0], [val[5], 0.0, 0.0]] elif numCoeff == 10: ####Unpacking needs to be checked. coeffs = [[val[0], val[1], val[4], val[8]], [val[2], val[3], val[6], 0.0], [val[5], val[7],0.0, 0.0], [val[9], 0.0, 0.0, 0.0]] rangePoly = Poly2D.Poly2D() rangePoly.setMeanAzimuth(azmin) rangePoly.initPoly(rangeOrder=rangeOrder, azimuthOrder=azimuthOrder, coeffs=coeffs) ####Azimuth Offsets obj.setOffset(dy) obj.offsetpoly() val = obj.offsetPoly #####Unpack into 2D array if numCoeff == 3: coeffs = [[val[0], val[1]], [val[2], 0.0]] elif numCoeff == 4: coeffs = [[val[0], val[1]], [val[2], val[3]]] elif numCoeff == 6: coeffs = [[val[0], val[1], val[4]], [val[2], val[3], 0.0], [val[5], 0.0, 0.0]] elif numCoeff == 10: ####Unpacking needs to be checked. coeffs = [[val[0], val[1], val[4], val[8]], [val[2], val[3], val[6], 0.0], [val[5], val[7],0.0, 0.0], [val[9], 0.0, 0.0, 0.0]] azimuthPoly = Poly2D.Poly2D() azimuthPoly.setMeanAzimuth(azmin) azimuthPoly.initPoly(rangeOrder=rangeOrder, azimuthOrder=azimuthOrder, coeffs=coeffs) ####Fallback to numpy based polynomial fitting else: x = inArr[:,0] y = inArr[:,2] dx = inArr[:,1] dy = inArr[:,3] sig = inArr[:,4] azimuthPoly = Poly2D.Poly2D() azimuthPoly.initPoly(rangeOrder=rangeOrder, azimuthOrder=azimuthOrder) azimuthPoly.polyfit(x,y,dy, sig=sig) azimuthPoly._meanAzimuth += azmin rangePoly = Poly2D.Poly2D() rangePoly.initPoly(rangeOrder=rangeOrder, azimuthOrder=azimuthOrder) rangePoly.polyfit(x,y,dx,sig=sig) rangePoly._meanAzimuth += azmin return (azimuthPoly, rangePoly)