def testConvertSCHdot(self): elp = Planet("Earth").get_elp() elp.setSCH(66.0, -105.0, 36.0) #From for_ellipsoid_test.F #convert_schdot_to_xyzdot, sch_to_xyz r_sch = [1468.0, -234.0, 7000.0] r_schdot = [800.0, -400.0, 100.0] r_xyz = [-672788.46258740244, -2514950.4839521507, 5810769.7976823179] r_xyzdot = [853.73728655948685, 118.98447071885982, 258.79594191185748] posXYZ, velXYZ = elp.schdot_to_xyzdot(r_sch, r_schdot) for (a, b) in zip(r_xyz, posXYZ): self.assertAlmostEqual(a, b, places=3) for (a, b) in zip(r_xyzdot, velXYZ): self.assertAlmostEqual(a, b, places=3) #convert_schdot_to_xyzdot, xyz_to_sch r_xyz = [-672100.0, -2514000.0, 5811000.0] r_xyzdot = [800.0, -400.0, 100.0] r_sch = [2599.1237664792707, 70.396218844576666, 6764.7576835183427] r_schdot = [ 415.39842327248573, -781.28909619852459, 164.41258499283407 ] posSCH, velSCH = elp.xyzdot_to_schdot(r_xyz, r_xyzdot) for (a, b) in zip(r_sch, posSCH): self.assertAlmostEqual(a, b, places=3) for (a, b) in zip(r_schdot, velSCH): self.assertAlmostEqual(a, b, delta=0.1)
def testSCH2(self): elp = Planet("Earth").get_elp() #Peg at North Pole, S path on prime meridian heading North to South elp.setSCH(90., 0., -90.) #SCH = [0.,0.,0.] => XYZ = [elp.b, 0., 0.] sch = [0., 0., 0.] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], 0., places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], elp.b, places=3) sch1 = elp.xyz_to_sch(xyz) for (s, s1) in zip(sch, sch1): self.assertAlmostEqual(s, s1, places=3) #SCH = [pi*elp.pegRadCur, 0, elp.b+(elp.pegOV[2]-elp.pegRadCur)] => #XYZ=[0., 0., -elp.b] sch = [ numpy.pi * elp.pegRadCur, 0., elp.b + elp.pegOV[2] - elp.pegRadCur ] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], 0., places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], -elp.b, places=3) sch1 = elp.xyz_to_sch(xyz) for (s, s1) in zip(sch, sch1): self.assertAlmostEqual(s, s1, places=3)
def testXYZSCH(self): elp = Planet("Earth").get_elp() elp.setSCH(30., 60., 45.) sch = [-50000., 200000., 1000.] xyz = elp.sch_to_xyz(sch) sch1 = elp.xyz_to_sch(xyz) for (s, s1) in zip(sch, sch1): self.assertAlmostEqual(s, s1, places=3) xyz = [-4.e6, 10.e6, 1.e6] sch = elp.xyz_to_sch(xyz) xyz1 = elp.sch_to_xyz(sch) for (x, x1) in zip(xyz, xyz1): self.assertAlmostEqual(x, x1, places=3) elp.setSCH(65., -22., -30.) sch = [100000., -100000., 100000.] xyz = elp.sch_to_xyz(sch) sch1 = elp.xyz_to_sch(xyz) for (s, s1) in zip(sch, sch1): self.assertAlmostEqual(s, s1, places=3) xyz = [-1.e6, -2.e6, 100.e6] sch = elp.xyz_to_sch(xyz) xyz1 = elp.sch_to_xyz(sch) for (x, x1) in zip(xyz, xyz1): self.assertAlmostEqual(x, x1, places=3)
def extract_stripmap_metadata(meta_file): """Read metadata from shelve file for StripMap stack from ISCE Parameters: meta_file : str, path of the shelve file, i.e. masterShelve/data.dat Returns: meta : dict, metadata """ import isce import isceobj from isceobj.Planet.Planet import Planet if os.path.basename( meta_file) == "data.dat": #shelve file from stripmapStack fbase = os.path.splitext(meta_file)[0] with shelve.open(fbase, flag='r') as mdb: frame = mdb['frame'] elif meta_file.endswith(".xml"): #XML file from stripmapApp frame = load_product(meta_file) else: raise ValueError( 'un-recognized isce/stripmap metadata file: {}'.format(meta_file)) metadata = {} metadata['prf'] = frame.PRF metadata['startUTC'] = frame.sensingStart metadata['stopUTC'] = frame.sensingStop metadata['radarWavelength'] = frame.radarWavelegth metadata['startingRange'] = frame.startingRange metadata['polarization'] = str(frame.polarization).replace('/', '') if metadata['polarization'].startswith("b'"): metadata['polarization'] = metadata['polarization'][2:4] metadata['trackNumber'] = frame.trackNumber metadata['orbitNumber'] = frame.orbitNumber time_seconds = (frame.sensingStart.hour * 3600.0 + frame.sensingStart.minute * 60.0 + frame.sensingStart.second) metadata['CENTER_LINE_UTC'] = time_seconds orbit = frame.orbit peg = orbit.interpolateOrbit(frame.sensingMid, method='hermite') Vs = np.linalg.norm(peg.getVelocity()) #satellite speed metadata['azimuthResolution'] = frame.platform.antennaLength / 2.0 metadata['azimuthPixelSize'] = Vs / frame.PRF frame.getInstrument() rgBandwidth = frame.instrument.pulseLength * frame.instrument.chirpSlope metadata['rangeResolution'] = abs(SPEED_OF_LIGHT / (2.0 * rgBandwidth)) metadata['rangePixelSize'] = frame.instrument.rangePixelSize refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(frame.sensingMid)) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] # for StripMap metadata['beam_mode'] = 'SM' return metadata, frame
def testSCHDOT(self): elp = Planet("Earth").get_elp() elp.setSCH(0., 0., 90.) sch = [0., 0., 0.] schdot = [0., 0., 10.] xyz, xyzdot = elp.schdot_to_xyzdot(sch, schdot) ans = [10.0, 0.0, 0.0] for (x, x1) in zip(xyzdot, ans): self.assertAlmostEqual(x, x1, places=3) xyz = [elp.a, 0., 0.] sch1, schdot1 = elp.xyzdot_to_schdot(xyz, xyzdot) for (s, s1) in zip(schdot, schdot1): self.assertAlmostEqual(s, s1, places=3) elp.setSCH(30., 60., 30.) sch = [0., 0., 0.] schdot = [10., 0., 0.] xyz, xyzdot = elp.schdot_to_xyzdot(sch, schdot) ans = [-6.495190528383289, -1.2499999999999996, 7.500000000000001] for (x, x1) in zip(xyzdot, ans): self.assertAlmostEqual(x, x1, places=3) xyz = elp.sch_to_xyz(sch) sch1, schdot1 = elp.xyzdot_to_schdot(xyz, xyzdot) for (s, s1) in zip(schdot, schdot1): self.assertAlmostEqual(s, s1, places=3)
def testSETSCH(self): elp = Planet("Earth").get_elp() elp.setSCH(66.0, -105.0, 36.0) #From for_ellipsoid_test.F r_radcur = 6391364.9560780991 r_ov = [-490.98983883031178, -1832.3990245149471, -34854.866159332916] r_mat = [ [-0.10527118956908345, 0.75904333077238850, -0.64247272211096140], [-0.39287742804503412, 0.56176045358432036, 0.72806079369889010], [0.91354545764260087, 0.32905685648333960, 0.23907380036690279] ] r_matinv = [ [-0.10527118956908345, -0.39287742804503412, 0.91354545764260087], [0.75904333077238850, 0.56176045358432036, 0.32905685648333960], [-0.64247272211096140, 0.72806079369889010, 0.23907380036690279] ] self.assertAlmostEqual(r_radcur, elp.pegRadCur, places=3) for (a, b) in zip(r_ov, elp.pegOV): self.assertAlmostEqual(a, b, places=3) for i in range(3): for (a, b) in zip(r_mat[i], elp.pegRotMat[i]): self.assertAlmostEqual(a, b, places=3) for i in range(3): for (a, b) in zip(r_matinv[i], elp.pegRotMatInv[i]): self.assertAlmostEqual(a, b, places=3)
def extractInfo(xmlName, inps): ''' Extract required information from pickle file. ''' from isceobj.Planet.Planet import Planet from isceobj.Util.geo.ellipsoid import Ellipsoid frame = ut.loadProduct(xmlName) burst = frame.bursts[0] planet = Planet(pname='Earth') elp = Ellipsoid(planet.ellipsoid.a, planet.ellipsoid.e2, 'WGS84') data = {} data['wavelength'] = burst.radarWavelength tstart = frame.bursts[0].sensingStart tend = frame.bursts[-1].sensingStop #tmid = tstart + 0.5*(tend - tstart) tmid = tstart orbit = burst.orbit peg = orbit.interpolateOrbit(tmid, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getENUHeading(tmid) refElp.setSCH(llh[0], llh[1], hdg) earthRadius = refElp.pegRadCur altitude = llh[2] #sv = burst.orbit.interpolateOrbit(tmid, method='hermite') #pos = sv.getPosition() #llh = elp.ECEF(pos[0], pos[1], pos[2]).llh() data['altitude'] = altitude #llh.hgt #hdg = burst.orbit.getHeading() data['earthRadius'] = earthRadius #elp.local_radius_of_curvature(llh.lat, hdg) #azspacing = burst.azimuthTimeInterval * sv.getScalarVelocity() #azres = 20.0 #corrfile = os.path.join(self._insar.mergedDirname, self._insar.coherenceFilename) rangeLooks = inps.rglooks azimuthLooks = inps.azlooks azfact = 0.8 rngfact = 0.8 corrLooks = rangeLooks * azimuthLooks/(azfact*rngfact) data['corrlooks'] = corrLooks #inps.rglooks * inps.azlooks * azspacing / azres data['rglooks'] = inps.rglooks data['azlooks'] = inps.azlooks return data
def extract_tops_metadata(xml_file): """Read metadata from xml file for Sentinel-1/TOPS Parameters: xml_file : str, path of the .xml file, i.e. master/IW1.xml Returns: meta : dict, metadata """ import isce from isceobj.Planet.Planet import Planet obj = load_product(xml_file) burst = obj.bursts[0] burstEnd = obj.bursts[-1] metadata = {} metadata['prf'] = burst.prf metadata['startUTC'] = burst.burstStartUTC metadata['stopUTC'] = burstEnd.burstStopUTC metadata['radarWavelength'] = burst.radarWavelength metadata['rangePixelSize'] = burst.rangePixelSize metadata['startingRange'] = burst.startingRange metadata['passDirection'] = burst.passDirection metadata['polarization'] = burst.polarization metadata['trackNumber'] = burst.trackNumber metadata['orbitNumber'] = burst.orbitNumber time_seconds = (burst.burstStartUTC.hour * 3600.0 + burst.burstStartUTC.minute * 60.0 + burst.burstStartUTC.second) metadata['CENTER_LINE_UTC'] = time_seconds orbit = burst.orbit peg = orbit.interpolateOrbit(burst.sensingMid, method='hermite') Vs = np.linalg.norm(peg.getVelocity()) metadata['satelliteSpeed'] = Vs metadata['azimuthPixelSize'] = Vs * burst.azimuthTimeInterval refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(burst.sensingMid)) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] # for Sentinel-1 metadata['beam_mode'] = 'IW' metadata['swathNumber'] = burst.swathNumber # 1. multipel subswaths xml_files = glob.glob(os.path.join(os.path.dirname(xml_file), 'IW*.xml')) if len(xml_files) > 1: swath_num = [ load_product(fname).bursts[0].swathNumber for fname in xml_files ] metadata['swathNumber'] = ''.join(str(i) for i in sorted(swath_num)) # 2. calculate ASF frame number for Sentinel-1 metadata['firstFrameNumber'] = int( 0.2 * (burst.burstStartUTC - obj.ascendingNodeTime).total_seconds()) metadata['lastFrameNumber'] = int( 0.2 * (burstEnd.burstStopUTC - obj.ascendingNodeTime).total_seconds()) return metadata, burst
def extract_tops_metadata(xml_file): """Read metadata from xml file for Sentinel-1/TOPS Parameters: xml_file : str, path of the .xml file, i.e. master/IW1.xml Returns: meta : dict, metadata """ import isce from isceobj.Planet.Planet import Planet obj = load_product(xml_file) burst = obj.bursts[0] burstEnd = obj.bursts[-1] metadata = {} metadata['prf'] = burst.prf metadata['startUTC'] = burst.burstStartUTC metadata['stopUTC'] = burstEnd.burstStopUTC metadata['radarWavelength'] = burst.radarWavelength metadata['rangePixelSize'] = burst.rangePixelSize metadata['startingRange'] = burst.startingRange metadata['passDirection'] = burst.passDirection metadata['polarization'] = burst.polarization metadata['trackNumber'] = burst.trackNumber metadata['orbitNumber'] = burst.orbitNumber time_seconds = (burst.burstStartUTC.hour * 3600.0 + burst.burstStartUTC.minute * 60.0 + burst.burstStartUTC.second) metadata['CENTER_LINE_UTC'] = time_seconds orbit = burst.orbit peg = orbit.interpolateOrbit(burst.sensingMid, method='hermite') Vs = np.linalg.norm(peg.getVelocity()) metadata['satelliteSpeed'] = Vs metadata['azimuthPixelSize'] = Vs*burst.azimuthTimeInterval refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(burst.sensingMid)) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] # for Sentinel-1 metadata['beam_mode'] = 'IW' metadata['swathNumber'] = burst.swathNumber # 1. multipel subswaths xml_files = glob.glob(os.path.join(os.path.dirname(xml_file), 'IW*.xml')) if len(xml_files) > 1: swath_num = [load_product(fname).bursts[0].swathNumber for fname in xml_files] metadata['swathNumber'] = ''.join(str(i) for i in sorted(swath_num)) # 2. calculate ASF frame number for Sentinel-1 metadata['firstFrameNumber'] = int(0.2 * (burst.burstStartUTC - obj.ascendingNodeTime).total_seconds()) metadata['lastFrameNumber'] = int(0.2 * (burstEnd.burstStopUTC - obj.ascendingNodeTime).total_seconds()) return metadata
def extract_stripmap_metadata(meta_file): """Read metadata from shelve file for StripMap stack from ISCE Parameters: meta_file : str, path of the shelve file, i.e. masterShelve/data.dat Returns: meta : dict, metadata """ import isce import isceobj import isceobj.StripmapProc.StripmapProc as St from isceobj.Planet.Planet import Planet if os.path.basename( meta_file) == "data.dat": #shelve file from stripmapStack fbase = os.path.splitext(meta_file)[0] with shelve.open(fbase, flag='r') as mdb: frame = mdb['frame'] elif meta_file.endswith(".xml"): #XML file from stripmapApp frame = load_product(meta_file) metadata = {} metadata['prf'] = frame.PRF metadata['startUTC'] = frame.sensingStart metadata['stopUTC'] = frame.sensingStop metadata['radarWavelength'] = frame.radarWavelegth metadata['rangePixelSize'] = frame.instrument.rangePixelSize metadata['startingRange'] = frame.startingRange metadata['polarization'] = frame.polarization.replace('/', '') if metadata['polarization'].startswith("b'"): metadata['polarization'] = metadata['polarization'][2:4] metadata['trackNumber'] = frame.trackNumber metadata['orbitNumber'] = frame.orbitNumber time_seconds = (frame.sensingStart.hour * 3600.0 + frame.sensingStart.minute * 60.0 + frame.sensingStart.second) metadata['CENTER_LINE_UTC'] = time_seconds orbit = frame.orbit peg = orbit.interpolateOrbit(frame.sensingMid, method='hermite') Vs = np.linalg.norm(peg.getVelocity()) metadata['satelliteSpeed'] = Vs metadata['azimuthPixelSize'] = Vs / frame.PRF refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(frame.sensingMid)) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] # for StripMap metadata['beam_mode'] = 'SM' return metadata
def extract_stripmap_metadata(meta_file): """Read metadata from shelve file for StripMap stack from ISCE Parameters: meta_file : str, path of the shelve file, i.e. masterShelve/data.dat Returns: meta : dict, metadata """ import isce import isceobj import isceobj.StripmapProc.StripmapProc as St from isceobj.Planet.Planet import Planet if os.path.basename(meta_file) == "data.dat": #shelve file from stripmapStack fbase = os.path.splitext(meta_file)[0] with shelve.open(fbase, flag='r') as mdb: frame = mdb['frame'] elif meta_file.endswith(".xml"): #XML file from stripmapApp frame = load_product(meta_file) metadata = {} metadata['prf'] = frame.PRF metadata['startUTC'] = frame.sensingStart metadata['stopUTC'] = frame.sensingStop metadata['radarWavelength'] = frame.radarWavelegth metadata['rangePixelSize'] = frame.instrument.rangePixelSize metadata['startingRange'] = frame.startingRange metadata['polarization'] = frame.polarization.replace('/', '') if metadata['polarization'].startswith("b'"): metadata['polarization'] = metadata['polarization'][2:4] metadata['trackNumber'] = frame.trackNumber metadata['orbitNumber'] = frame.orbitNumber time_seconds = (frame.sensingStart.hour*3600.0 + frame.sensingStart.minute*60.0 + frame.sensingStart.second) metadata['CENTER_LINE_UTC'] = time_seconds orbit = frame.orbit peg = orbit.interpolateOrbit(frame.sensingMid, method='hermite') Vs = np.linalg.norm(peg.getVelocity()) metadata['satelliteSpeed'] = Vs metadata['azimuthPixelSize'] = Vs/frame.PRF refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(frame.sensingMid)) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] # for StripMap metadata['beam_mode'] = 'SM' return metadata
def testDEBUG(self): elp = Planet("Earth").get_elp() elp.setSCH(19.2796271, -155.282224, 58.9432911) posSCH = [-58033.8, 0.0, 12494.4008] velSCH = [234.84106135055595, 0.0, 12494.4008] posXYZ = [-5511147.555045444, -2482080.457636343, 2068314.4442497757] velXYZ = [-10652.45905403, -5017.70635173, 4184.84656172] p, v = elp.schdot_to_xyzdot(posSCH, velSCH) for (a, b) in zip(p, posXYZ): self.assertAlmostEqual(a, b, places=3) for (a, b) in zip(v, velXYZ): self.assertAlmostEqual(a, b, places=3)
def extractInfo(inps): ''' Extract required information from pickle file. ''' from isceobj.Planet.Planet import Planet from isceobj.Util.geo.ellipsoid import Ellipsoid from iscesys.Component.ProductManager import ProductManager as PM pm = PM() #pm.configure frame = pm.loadProduct(inps.xmlFile) burst = frame.bursts[0] planet = Planet(pname='Earth') elp = Ellipsoid(planet.ellipsoid.a, planet.ellipsoid.e2, 'WGS84') data = {} data['wavelength'] = burst.radarWavelength tstart = frame.bursts[0].sensingStart #tend = frame.bursts[-1].sensingStop #tmid = tstart + 0.5*(tend - tstart) tmid = tstart orbit = burst.orbit peg = orbit.interpolateOrbit(tmid, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getENUHeading(tmid) refElp.setSCH(llh[0], llh[1], hdg) earthRadius = refElp.pegRadCur altitude = llh[2] #sv = burst.orbit.interpolateOrbit(tmid, method='hermite') #pos = sv.getPosition() #llh = elp.ECEF(pos[0], pos[1], pos[2]).llh() data['altitude'] = altitude #llh.hgt #hdg = burst.orbit.getHeading() data[ 'earthRadius'] = earthRadius #elp.local_radius_of_curvature(llh.lat, hdg) return data
def extractIsceMetadata(shelveFile): with shelve.open(shelveFile, flag='r') as mdb: burst = mdb['frame'] #reference = ut.loadProduct(shelveFile) #burst = reference.bursts[0] #burstEnd = reference.bursts[-1] metadata = {} metadata['radarWavelength'] = burst.radarWavelegth metadata['rangePixelSize'] = burst.instrument.rangePixelSize metadata['prf'] = burst.PRF metadata['startUTC'] = burst.sensingStart metadata['stopUTC'] = burst.sensingStop metadata['startingRange'] = burst.startingRange time_seconds = burst.sensingStart.hour * 3600.0 + burst.sensingStart.minute * 60.0 + burst.sensingStart.second metadata['CENTER_LINE_UTC'] = time_seconds Vs = np.linalg.norm( burst.orbit.interpolateOrbit(burst.sensingMid, method='hermite').getVelocity()) metadata['satelliteSpeed'] = Vs metadata['azimuthTimeInterval'] = 1. / burst.PRF #azimuthTimeInterval metadata['azimuthPixelSize'] = Vs * metadata[ 'azimuthTimeInterval'] #burst.azimuthTimeInterval #metadata['azimuthPixelSize'] = burst.instrument.azimuthPixelSize tstart = burst.sensingStart tend = burst.sensingStop tmid = tstart + 0.5 * (tend - tstart) orbit = burst.orbit peg = orbit.interpolateOrbit(tmid, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getENUHeading(tmid) refElp.setSCH(llh[0], llh[1], hdg) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] return metadata
def testConvertSCH(self): elp = Planet("Earth").get_elp() elp.setSCH(66.0, -105.0, 36.0) #From for_ellipsoid_test.F #convert_sch_to_xyz, sch_to_xyz r_sch = [1468.0, -234.0, 7000.0] r_xyz = [-672788.46258740244, -2514950.4839521507, 5810769.7976823179] r_llh = [66.009415512068244, -104.97681810507400, 6999.9999703792855] posXYZ = elp.sch_to_xyz(r_sch) for (a, b) in zip(r_xyz, posXYZ): self.assertAlmostEqual(a, b, places=3) #convert_sch_to_xyz, xyz_to_sch r_xyz = [-672100.0, -2514000.0, 5811000.0] r_sch = [2599.1237664792707, 70.396218844576666, 6764.7576835183427] r_llh = [66.019224990424505, -104.96758302093188, 6764.7576984856278] posXYZ = elp.sch_to_xyz(r_sch) for (a, b) in zip(r_xyz, posXYZ): self.assertAlmostEqual(a, b, places=3)
def extractIsceMetadata(xmlFile): master = ut.loadProduct(xmlFile) burst = master.bursts[0] burstEnd = master.bursts[-1] metadata = {} metadata['radarWavelength'] = burst.radarWavelength metadata['rangePixelSize'] = burst.rangePixelSize metadata['prf'] = burst.prf metadata['startUTC'] = burst.burstStartUTC metadata['stopUTC'] = burstEnd.burstStopUTC metadata['startingRange'] = burst.startingRange time_seconds = burst.burstStartUTC.hour * 3600.0 + burst.burstStartUTC.minute * 60.0 + burst.burstStartUTC.second metadata['CENTER_LINE_UTC'] = time_seconds Vs = np.linalg.norm( burst.orbit.interpolateOrbit(burst.sensingMid, method='hermite').getVelocity()) metadata['satelliteSpeed'] = Vs metadata['azimuthTimeInterval'] = burst.azimuthTimeInterval metadata['azimuthPixelSize'] = Vs * burst.azimuthTimeInterval tstart = burst.sensingStart tend = burstEnd.sensingStop tmid = tstart + 0.5 * (tend - tstart) orbit = burst.orbit peg = orbit.interpolateOrbit(tmid, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getENUHeading(tmid) refElp.setSCH(llh[0], llh[1], hdg) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] return metadata
def extract_alosStack_metadata(meta_file, geom_dir): import isce import isceobj from isceobj.Planet.Planet import Planet track = load_track(os.path.dirname(meta_file), os.path.basename(meta_file).strip('.track.xml')) rlooks, alooks, width, length = extract_image_size_alosStack(geom_dir) spotlightModes, stripmapModes, scansarNominalModes, scansarWideModes, scansarModes = alos2_acquisition_modes( ) meta = {} meta['prf'] = track.prf meta['startUTC'] = track.sensingStart + datetime.timedelta( seconds=(alooks - 1.0) / 2.0 * track.azimuthLineInterval) meta['stopUTC'] = meta['startUTC'] + datetime.timedelta( seconds=(length - 1) * alooks * track.azimuthLineInterval) meta['radarWavelength'] = track.radarWavelength meta['startingRange'] = track.startingRange + ( rlooks - 1.0) / 2.0 * track.rangePixelSize meta['passDirection'] = track.passDirection.upper() meta['polarization'] = track.frames[0].swaths[0].polarization #meta['trackNumber'] = track.trackNumber #meta['orbitNumber'] = track.orbitNumber meta['PLATFORM'] = sensor.standardize_sensor_name('alos2') sensingMid = meta['startUTC'] + datetime.timedelta( seconds=(meta['stopUTC'] - meta['startUTC']).total_seconds() / 2.0) time_seconds = (sensingMid.hour * 3600.0 + sensingMid.minute * 60.0 + sensingMid.second) meta['CENTER_LINE_UTC'] = time_seconds peg = track.orbit.interpolateOrbit(sensingMid, method='hermite') Vs = np.linalg.norm(peg.getVelocity()) meta['azimuthPixelSize'] = Vs * track.azimuthLineInterval meta['rangePixelSize'] = track.rangePixelSize azBandwidth = track.prf * 0.8 if track.operationMode in scansarNominalModes: azBandwidth /= 5.0 if track.operationMode in scansarWideModes: azBandwidth /= 7.0 #use a mean burst synchronizatino here if track.operationMode in scansarModes: azBandwidth *= 0.85 meta['azimuthResolution'] = Vs * (1.0 / azBandwidth) meta['rangeResolution'] = 0.5 * SPEED_OF_LIGHT * ( 1.0 / track.frames[0].swaths[0].rangeBandwidth) elp = Planet(pname='Earth').ellipsoid llh = elp.xyz_to_llh(peg.getPosition()) elp.setSCH(llh[0], llh[1], track.orbit.getENUHeading(sensingMid)) meta['HEADING'] = track.orbit.getENUHeading(sensingMid) meta['earthRadius'] = elp.pegRadCur meta['altitude'] = llh[2] meta['beam_mode'] = track.operationMode meta['swathNumber'] = ''.join( str(swath.swathNumber) for swath in track.frames[0].swaths) meta['firstFrameNumber'] = track.frames[0].frameNumber meta['lastFrameNumber'] = track.frames[-1].frameNumber meta['ALOOKS'] = alooks meta['RLOOKS'] = rlooks # NCORRLOOKS for coherence calibration rgfact = float(meta['rangeResolution']) / float(meta['rangePixelSize']) azfact = float(meta['azimuthResolution']) / float(meta['azimuthPixelSize']) meta['NCORRLOOKS'] = meta['RLOOKS'] * meta['ALOOKS'] / (rgfact * azfact) # update pixel_size for multilooked data meta['rangePixelSize'] *= meta['RLOOKS'] meta['azimuthPixelSize'] *= meta['ALOOKS'] edge = 3 lat_file = glob.glob( os.path.join(geom_dir, '*_{}rlks_{}alks.lat'.format(rlooks, alooks)))[0] img = isceobj.createImage() img.load(lat_file + '.xml') width = img.width length = img.length data = np.memmap(lat_file, dtype='float64', mode='r', shape=(length, width)) meta['LAT_REF1'] = str(data[0 + edge, 0 + edge]) meta['LAT_REF2'] = str(data[0 + edge, -1 - edge]) meta['LAT_REF3'] = str(data[-1 - edge, 0 + edge]) meta['LAT_REF4'] = str(data[-1 - edge, -1 - edge]) lon_file = glob.glob( os.path.join(geom_dir, '*_{}rlks_{}alks.lon'.format(rlooks, alooks)))[0] data = np.memmap(lon_file, dtype='float64', mode='r', shape=(length, width)) meta['LON_REF1'] = str(data[0 + edge, 0 + edge]) meta['LON_REF2'] = str(data[0 + edge, -1 - edge]) meta['LON_REF3'] = str(data[-1 - edge, 0 + edge]) meta['LON_REF4'] = str(data[-1 - edge, -1 - edge]) los_file = glob.glob( os.path.join(geom_dir, '*_{}rlks_{}alks.los'.format(rlooks, alooks)))[0] data = np.memmap(los_file, dtype='float32', mode='r', shape=(length * 2, width))[0:length * 2:2, :] inc_angle = data[int(length / 2), int(width / 2)] meta['CENTER_INCIDENCE_ANGLE'] = str(inc_angle) pointingDirection = {'right': -1, 'left': 1} meta['ANTENNA_SIDE'] = str(pointingDirection[track.pointingDirection]) return meta, track
def runUnwrap(self,costMode = None,initMethod = None, defomax = None, initOnly = None): if costMode is None: costMode = 'DEFO' if initMethod is None: initMethod = 'MST' if defomax is None: defomax = 4.0 if initOnly is None: initOnly = False wrapName = os.path.join( self._insar.mergedDirname, self._insar.filtFilename) unwrapName = os.path.join( self._insar.mergedDirname, self._insar.unwrappedIntFilename) img = isceobj.createImage() img.load(wrapName + '.xml') swathList = self._insar.getValidSwathList(self.swaths) for swath in swathList[0:1]: ifg = self._insar.loadProduct( os.path.join(self._insar.fineIfgDirname, 'IW{0}.xml'.format(swath))) wavelength = ifg.bursts[0].radarWavelength width = img.getWidth() ####tmid tstart = ifg.bursts[0].sensingStart tend = ifg.bursts[-1].sensingStop tmid = tstart + 0.5*(tend - tstart) orbit = ifg.bursts[0].orbit peg = orbit.interpolateOrbit(tmid, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getENUHeading(tmid) refElp.setSCH(llh[0], llh[1], hdg) earthRadius = refElp.pegRadCur altitude = llh[2] corrfile = os.path.join(self._insar.mergedDirname, self._insar.coherenceFilename) rangeLooks = self.numberRangeLooks azimuthLooks = self.numberAzimuthLooks azfact = 0.8 rngfact = 0.8 corrLooks = rangeLooks * azimuthLooks/(azfact*rngfact) maxComponents = 20 snp = Snaphu() snp.setInitOnly(initOnly) snp.setInput(wrapName) snp.setOutput(unwrapName) snp.setWidth(width) snp.setCostMode(costMode) snp.setEarthRadius(earthRadius) snp.setWavelength(wavelength) snp.setAltitude(altitude) snp.setCorrfile(corrfile) snp.setInitMethod(initMethod) snp.setCorrLooks(corrLooks) snp.setMaxComponents(maxComponents) snp.setDefoMaxCycles(defomax) snp.setRangeLooks(rangeLooks) snp.setAzimuthLooks(azimuthLooks) snp.setCorFileFormat('FLOAT_DATA') snp.prepare() snp.unwrap() ######Render XML outImage = isceobj.Image.createUnwImage() outImage.setFilename(unwrapName) outImage.setWidth(width) outImage.setAccessMode('read') outImage.renderVRT() outImage.createImage() outImage.finalizeImage() outImage.renderHdr() #####Check if connected components was created if snp.dumpConnectedComponents: connImage = isceobj.Image.createImage() connImage.setFilename(unwrapName+'.conncomp') #At least one can query for the name used self._insar.connectedComponentsFilename = unwrapName+'.conncomp' connImage.setWidth(width) connImage.setAccessMode('read') connImage.setDataType('BYTE') connImage.renderVRT() connImage.createImage() connImage.finalizeImage() connImage.renderHdr() return
def numberOfLooks(self, frame, posting, azlooks, rglooks): ''' Compute relevant number of looks. ''' from isceobj.Planet.Planet import Planet from isceobj.Constants import SPEED_OF_LIGHT import numpy as np azFinal = None rgFinal = None if azlooks is not None: azFinal = azlooks if rglooks is not None: rgFinal = rglooks if (azFinal is not None) and (rgFinal is not None): return (azFinal, rgFinal) if posting is None: raise Exception('Input posting is none. Either specify (azlooks, rglooks) or posting in input file') elp = Planet(pname='Earth').ellipsoid ####First determine azimuth looks tmid = frame.sensingMid sv = frame.orbit.interpolateOrbit( tmid, method='hermite') #.getPosition() llh = elp.xyz_to_llh(sv.getPosition()) if azFinal is None: hdg = frame.orbit.getENUHeading(tmid) elp.setSCH(llh[0], llh[1], hdg) sch, vsch = elp.xyzdot_to_schdot(sv.getPosition(), sv.getVelocity()) azFinal = max(int(np.round(posting * frame.PRF / vsch[0])), 1) if rgFinal is None: pulseLength = frame.instrument.pulseLength chirpSlope = frame.instrument.chirpSlope #Range Bandwidth rBW = np.abs(chirpSlope)*pulseLength # Slant Range resolution rgres = abs(SPEED_OF_LIGHT / (2.0 * rBW)) r0 = frame.startingRange rmax = frame.getFarRange() rng =(r0+rmax)/2 Re = elp.pegRadCur H = sch[2] cos_beta_e = (Re**2 + (Re + H)**2 -rng**2)/(2*Re*(Re+H)) sin_bet_e = np.sqrt(1 - cos_beta_e**2) sin_theta_i = sin_bet_e*(Re + H)/rng print("incidence angle at the middle of the swath: ", np.arcsin(sin_theta_i)*180.0/np.pi) groundRangeRes = rgres/sin_theta_i print("Ground range resolution at the middle of the swath: ", groundRangeRes) rgFinal = max(int(np.round(posting/groundRangeRes)),1) return azFinal, rgFinal
def extract_tops_metadata(xml_file): """Read metadata from xml file for Sentinel-1/TOPS Parameters: xml_file : str, path of the .xml file, i.e. reference/IW1.xml Returns: meta : dict, metadata burst : isceobj.Sensor.TOPS.BurstSLC.BurstSLC object """ import isce import isceobj from isceobj.Planet.Planet import Planet obj = load_product(xml_file) burst = obj.bursts[0] burstEnd = obj.bursts[-1] meta = {} meta['prf'] = burst.prf meta['startUTC'] = burst.burstStartUTC meta['stopUTC'] = burstEnd.burstStopUTC meta['radarWavelength'] = burst.radarWavelength meta['startingRange'] = burst.startingRange meta['passDirection'] = burst.passDirection meta['polarization'] = burst.polarization meta['trackNumber'] = burst.trackNumber meta['orbitNumber'] = burst.orbitNumber try: meta['PLATFORM'] = sensor.standardize_sensor_name(obj.spacecraftName) except: if os.path.basename(xml_file).startswith('IW'): meta['PLATFORM'] = 'sen' time_seconds = (burst.sensingMid.hour * 3600.0 + burst.sensingMid.minute * 60.0 + burst.sensingMid.second) meta['CENTER_LINE_UTC'] = time_seconds orbit = burst.orbit peg = orbit.interpolateOrbit(burst.sensingMid, method='hermite') # Sentinel-1 TOPS pixel spacing Vs = np.linalg.norm(peg.getVelocity()) #satellite speed meta['azimuthPixelSize'] = Vs * burst.azimuthTimeInterval meta['rangePixelSize'] = burst.rangePixelSize # Sentinel-1 TOPS spatial resolution iw_str = 'IW2' if os.path.basename(xml_file).startswith('IW'): iw_str = os.path.splitext(os.path.basename(xml_file))[0] meta['azimuthResolution'] = sensor.SENSOR_DICT['sen'][iw_str][ 'azimuth_resolution'] meta['rangeResolution'] = sensor.SENSOR_DICT['sen'][iw_str][ 'range_resolution'] elp = Planet(pname='Earth').ellipsoid llh = elp.xyz_to_llh(peg.getPosition()) elp.setSCH(llh[0], llh[1], orbit.getENUHeading(burst.sensingMid)) meta['HEADING'] = orbit.getENUHeading(burst.sensingMid) meta['earthRadius'] = elp.pegRadCur meta['altitude'] = llh[2] # for Sentinel-1 meta['beam_mode'] = 'IW' meta['swathNumber'] = burst.swathNumber # 1. multipel subswaths xml_files = glob.glob(os.path.join(os.path.dirname(xml_file), 'IW*.xml')) if len(xml_files) > 1: swath_num = [ load_product(fname).bursts[0].swathNumber for fname in xml_files ] meta['swathNumber'] = ''.join(str(i) for i in sorted(swath_num)) # 2. calculate ASF frame number for Sentinel-1 meta['firstFrameNumber'] = int( 0.2 * (burst.burstStartUTC - obj.ascendingNodeTime).total_seconds()) meta['lastFrameNumber'] = int( 0.2 * (burstEnd.burstStopUTC - obj.ascendingNodeTime).total_seconds()) return meta, burst
def snaphuUnwrap(track, t, wrapName, corName, unwrapName, nrlks, nalks, costMode='DEFO', initMethod='MST', defomax=4.0, initOnly=False): #runUnwrap(self, costMode = 'SMOOTH',initMethod = 'MCF', defomax = 2, initOnly = True) ''' track: track object t: time for computing earth radius and altitude, normally mid azimuth time wrapName: input interferogram corName: input coherence file unwrapName: output unwrapped interferogram nrlks: number of range looks of the interferogram nalks: number of azimuth looks of the interferogram ''' import datetime import numpy as np import isceobj from contrib.Snaphu.Snaphu import Snaphu from isceobj.Planet.Planet import Planet corImg = isceobj.createImage() corImg.load(corName + '.xml') width = corImg.width length = corImg.length #get altitude orbit = track.orbit peg = orbit.interpolateOrbit(t, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getENUHeading(t) refElp.setSCH(llh[0], llh[1], hdg) earthRadius = refElp.pegRadCur altitude = llh[2] rangeLooks = nrlks azimuthLooks = nalks azfact = 0.8 rngfact = 0.8 corrLooks = rangeLooks * azimuthLooks / (azfact * rngfact) maxComponents = 20 snp = Snaphu() snp.setInitOnly(initOnly) snp.setInput(wrapName) snp.setOutput(unwrapName) snp.setWidth(width) snp.setCostMode(costMode) snp.setEarthRadius(earthRadius) snp.setWavelength(track.radarWavelength) snp.setAltitude(altitude) snp.setCorrfile(corName) snp.setInitMethod(initMethod) snp.setCorrLooks(corrLooks) snp.setMaxComponents(maxComponents) snp.setDefoMaxCycles(defomax) snp.setRangeLooks(rangeLooks) snp.setAzimuthLooks(azimuthLooks) if corImg.bands == 1: snp.setCorFileFormat('FLOAT_DATA') snp.prepare() snp.unwrap() ######Render XML outImage = isceobj.Image.createUnwImage() outImage.setFilename(unwrapName) outImage.setWidth(width) outImage.setAccessMode('read') outImage.renderVRT() outImage.createImage() outImage.finalizeImage() outImage.renderHdr() #####Check if connected components was created if snp.dumpConnectedComponents: connImage = isceobj.Image.createImage() connImage.setFilename(unwrapName + '.conncomp') connImage.setWidth(width) connImage.setAccessMode('read') connImage.setDataType('BYTE') connImage.renderVRT() connImage.createImage() connImage.finalizeImage() connImage.renderHdr() del connImage del corImg del snp del outImage #remove wired things in no-data area amp = np.memmap(unwrapName, dtype='float32', mode='r+', shape=(length * 2, width)) wrap = np.fromfile(wrapName, dtype=np.complex64).reshape(length, width) (amp[0:length * 2:2, :])[np.nonzero(wrap == 0)] = 0 (amp[1:length * 2:2, :])[np.nonzero(wrap == 0)] = 0 del amp del wrap return
def extract_isce_metadata(xmlFile, rscFile=None): import isce from isceobj.Planet.Planet import Planet print('extract metadata from xml file:', xmlFile) metadata = {} master = load_product(xmlFile) metadata['spacecraftName'] = master.spacecraftName burst = master.bursts[0] burstEnd = master.bursts[-1] metadata['radarWavelength'] = burst.radarWavelength metadata['rangePixelSize'] = burst.rangePixelSize metadata['prf'] = burst.prf metadata['startUTC'] = burst.burstStartUTC metadata['stopUTC'] = burstEnd.burstStopUTC metadata['startingRange'] = burst.startingRange metadata['passDirection'] = burst.passDirection metadata['polarization'] = burst.polarization metadata['trackNumber'] = burst.trackNumber metadata['orbitNumber'] = burst.orbitNumber metadata['swathNumber'] = burst.swathNumber # swathNumber for multipel subswaths xml_files = glob.glob(os.path.join(os.path.dirname(xmlFile), 'IW*.xml')) if len(xml_files) > 1: swath_num = [] for xml_file in xml_files: swath_num.append(load_product(xml_file).bursts[0].swathNumber) metadata['swathNumber'] = ''.join(str(i) for i in sorted(swath_num)) # calculate ASF frame number for Sentinel-1 metadata['firstFrameNumber'] = int( np.floor( 0.2 * (burst.burstStartUTC - master.ascendingNodeTime).total_seconds())) metadata['lastFrameNumber'] = int( np.floor(0.2 * (burstEnd.burstStopUTC - master.ascendingNodeTime).total_seconds())) time_seconds = (burst.burstStartUTC.hour * 3600.0 + burst.burstStartUTC.minute * 60.0 + burst.burstStartUTC.second) metadata['CENTER_LINE_UTC'] = time_seconds Vs = np.linalg.norm( burst.orbit.interpolateOrbit(burst.sensingMid, method='hermite').getVelocity()) metadata['satelliteSpeed'] = Vs metadata['azimuthTimeInterval'] = burst.azimuthTimeInterval metadata['azimuthPixelSize'] = Vs * burst.azimuthTimeInterval tstart = burst.sensingStart tend = burstEnd.sensingStop tmid = tstart + 0.5 * (tend - tstart) orbit = burst.orbit peg = orbit.interpolateOrbit(tmid, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getENUHeading(tmid) refElp.setSCH(llh[0], llh[1], hdg) metadata['earthRadius'] = refElp.pegRadCur metadata['altitude'] = llh[2] # make all value in string format for key, value in metadata.items(): metadata[key] = str(value) metadata = readfile.standardize_metadata_isce(metadata) if rscFile: print('writing ', rscFile) writefile.write_roipac_rsc(metadata, rscFile) return metadata
def testSCH1(self): elp = Planet("Earth").get_elp() #S path on Earth equator West to East, origin at y=z=0 elp.setSCH(0., 0., 90.) #SCH = [0.,0.,0.] => XYZ = [elp.a, 0., 0.] sch = [0., 0., 0.] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], elp.a, places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], 0., places=3) sch1 = elp.xyz_to_sch(xyz) for (s, s1) in zip(sch, sch1): self.assertAlmostEqual(s, s1, places=3) #SCH = [(pi/2)*elp.a, 0, 0] => XYZ=[0., elp.a, 0.] sch = [numpy.pi * elp.a / 2., 0., 0.] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], 0., places=3) self.assertAlmostEqual(xyz[1], elp.a, places=3) self.assertAlmostEqual(xyz[2], 0., places=3) sch1 = elp.xyz_to_sch(xyz) for (s, s1) in zip(sch, sch1): self.assertAlmostEqual(s, s1, places=3) #SCH = [pi*elp.a, 0, 0] => XYZ=[-elp.a, 0., 0.] sch = [numpy.pi * elp.a, 0., 0.] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], -elp.a, places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], 0., places=3) # Round off causes degenerate case where lon = -180 and lon=180 are the same # point and xyz(-sch) = xyz(+sch), but -sch != sch # # sch1 = elp.xyz_to_sch(xyz) # print(sch1) # for (s,s1) in zip(sch, sch1): # self.assertAlmostEqual(s, s1, places=3) #SCH = [(3pi/2)*elp.a, 0, 0] => XYZ=[0., -elp.a, 0.] sch = [3 * numpy.pi * elp.a / 2., 0., 0.] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], 0., places=3) self.assertAlmostEqual(xyz[1], -elp.a, places=3) self.assertAlmostEqual(xyz[2], 0., places=3) # sch1 = elp.xyz_to_sch(xyz) # for (s,s1) in zip(sch, sch1): # self.assertAlmostEqual(s, s1, places=3) #SCH = [2pi*elp.a, 0, 0] => XYZ=[elp.a, 0., 0.] sch = [2. * numpy.pi * elp.a, 0., 0.] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], elp.a, places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], 0., places=3) #Another sch degeneracy due to angle branch cut # sch1 = elp.xyz_to_sch(xyz) # for (s,s1) in zip(sch, sch1): # self.assertAlmostEqual(s, s1, places=3) #SCH = [0., (pi/2)*elp.a, elp.b-elp.a] => XYZ = [0., 0., elp.b] sch = [0., numpy.pi * elp.a / 2., elp.b - elp.a] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], 0., places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], elp.b, places=3) # sch1 = elp.xyz_to_sch(xyz) # for (s,s1) in zip(sch, sch1): # self.assertAlmostEqual(s, s1, places=3) #SCH = [0., pi*elp.a, 0.] => XYZ = [-elp.a, 0., 0.] sch = [0., numpy.pi * elp.a, 0.] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], -elp.a, places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], 0., places=3) #SCH = [0., (3pi/2)*elp.a, elp.b-elp.a] => XYZ = [0., 0., -elp.b] sch = [0., 3. * numpy.pi * elp.a / 2., elp.b - elp.a] xyz = elp.sch_to_xyz(sch) self.assertAlmostEqual(xyz[0], 0., places=3) self.assertAlmostEqual(xyz[1], 0., places=3) self.assertAlmostEqual(xyz[2], -elp.b, places=3)
def rdr2geo(self, aztime, rng, height=0., doppler = None, wvl = None, planet=None, side=-1): ''' Returns point on ground at given height and doppler frequency. Never to be used for heavy duty computing. ''' from isceobj.Planet.Planet import Planet ####Setup doppler for the equations dopfact = 0.0 hdg = self.getENUHeading(time=aztime) sv = self.interpolateOrbit(aztime, method='hermite') pos = sv.getPosition() vel = sv.getVelocity() vmag = np.linalg.norm(vel) if doppler is not None: dopfact = doppler(DTU.seconds_since_midnight(aztime), rng) * 0.5 * wvl * rng/vmag if planet is None: refElp = Planet(pname='Earth').ellipsoid else: refElp = planet.ellipsoid ###Convert position and velocity to local tangent plane satLLH = refElp.xyz_to_llh(pos) refElp.setSCH(satLLH[0], satLLH[1], hdg) radius = refElp.pegRadCur #####Setup ortho normal system right below satellite satVec = np.array(pos) velVec = np.array(vel) ###Setup TCN basis clat = np.cos(np.radians(satLLH[0])) slat = np.sin(np.radians(satLLH[0])) clon = np.cos(np.radians(satLLH[1])) slon = np.sin(np.radians(satLLH[1])) nhat = np.array([-clat*clon, -clat*slon, -slat]) temp = np.cross(nhat, velVec) chat = temp / np.linalg.norm(temp) temp = np.cross(chat, nhat) that = temp / np.linalg.norm(temp) vhat = velVec / np.linalg.norm(velVec) ####Solve the range doppler eqns iteratively ####Initial guess zsch = height for ii in range(10): ###Near nadir tests if (satLLH[2]-zsch) >= rng: return None a = (satLLH[2] + radius) b = (radius + zsch) costheta = 0.5*(a/rng + rng/a - (b/a)*(b/rng)) sintheta = np.sqrt(1-costheta*costheta) gamma = rng*costheta alpha = dopfact - gamma*np.dot(nhat,vhat)/np.dot(vhat,that) beta = -side*np.sqrt(rng*rng*sintheta*sintheta - alpha*alpha) delta = alpha * that + beta * chat + gamma * nhat targVec = satVec + delta targLLH = refElp.xyz_to_llh(list(targVec)) targXYZ = refElp.llh_to_xyz([targLLH[0], targLLH[1], height]) targSCH = refElp.xyz_to_sch(targXYZ) zsch = targSCH[2] rdiff = rng - np.linalg.norm(np.array(satVec) - np.array(targXYZ)) return targLLH
def runUnwrap(inps, costMode=None, initMethod=None, defomax=None, initOnly=None): if costMode is None: costMode = 'DEFO' if initMethod is None: initMethod = 'MST' if defomax is None: defomax = 4.0 if initOnly is None: initOnly = False #get earth radius and altitude using master's orbit with open(inps.mframe, 'rb') as f: mframe = pickle.load(f) azti = 1.0 / mframe.PRF tmid = mframe.getSensingStart() + datetime.timedelta( seconds=azti * (mframe.getNumberOfLines() / 2.0)) orbit = mframe.getOrbit() peg = orbit.interpolateOrbit(tmid, method='hermite') refElp = Planet(pname='Earth').ellipsoid llh = refElp.xyz_to_llh(peg.getPosition()) hdg = orbit.getHeading(tmid) #change to the following after updated to the newest version of isce #hdg = orbit.getENUHeading(tmid) refElp.setSCH(llh[0], llh[1], hdg) earthRadius = refElp.pegRadCur altitude = llh[2] wrapName = inps.inf unwrapName = inps.unw corrfile = inps.cor width = getWidth(wrapName + '.xml') wavelength = mframe.getInstrument().getRadarWavelength() rangeLooks = inps.rlks azimuthLooks = inps.alks #calculate azimuth resolution and pixel size azres = mframe.platform.antennaLength / 2.0 vel = np.sqrt(peg.velocity[0] * peg.velocity[0] + peg.velocity[1] * peg.velocity[1] + peg.velocity[2] * peg.velocity[2]) hgt = np.sqrt(peg.position[0] * peg.position[0] + peg.position[1] * peg.position[1] + peg.position[2] * peg.position[2]) azimuthPixelSpacing = earthRadius / hgt * vel * azti azfact = azres / azimuthPixelSpacing #calculate range resolution and pixel size rBW = mframe.instrument.pulseLength * mframe.instrument.chirpSlope rgres = abs(SPEED_OF_LIGHT / (2.0 * rBW)) slantRangePixelSpacing = 0.5 * SPEED_OF_LIGHT / mframe.rangeSamplingRate rngfact = rgres / slantRangePixelSpacing print('azfact: {}, rngfact: {}'.format(azfact, rngfact)) corrLooks = azimuthLooks * rangeLooks / (azfact * rngfact) maxComponents = 20 snp = Snaphu() snp.setInitOnly(initOnly) # follow snp.setInput(wrapName) snp.setOutput(unwrapName) snp.setWidth(width) snp.setCostMode(costMode) # follow snp.setEarthRadius(earthRadius) snp.setWavelength(wavelength) snp.setAltitude(altitude) snp.setCorrfile(corrfile) snp.setInitMethod(initMethod) # follow snp.setCorrLooks(corrLooks) snp.setMaxComponents(maxComponents) snp.setDefoMaxCycles(defomax) # follow snp.setRangeLooks(rangeLooks) snp.setAzimuthLooks(azimuthLooks) #snp.setCorFileFormat('FLOAT_DATA') snp.prepare() snp.unwrap() ######Render XML outImage = isceobj.Image.createUnwImage() outImage.setFilename(unwrapName) outImage.setWidth(width) outImage.setAccessMode('read') outImage.renderVRT() outImage.createImage() outImage.finalizeImage() outImage.renderHdr() #####Check if connected components was created if snp.dumpConnectedComponents: connImage = isceobj.Image.createImage() connImage.setFilename(unwrapName + '.conncomp') #At least one can query for the name used #self._insar.connectedComponentsFilename = unwrapName+'.conncomp' connImage.setWidth(width) connImage.setAccessMode('read') connImage.setDataType('BYTE') connImage.renderVRT() connImage.createImage() connImage.finalizeImage() connImage.renderHdr() return