def extract_attribute_interferogram(fname): '''Read/extract attributes for PySAR from Gamma .unw, .cor and .int file Inputs: fname : str, Gamma interferogram filename or path, i.e. /PopoSLT143TsxD/diff_filt_HDR_130118-130129_4rlks.unw Output: atr : dict, Attributes dictionary ''' file_dir = os.path.dirname(fname) file_basename = os.path.basename(fname) atr_file = fname + '.rsc' #if os.path.isfile(atr_file): # return atr_file atr = {} atr['PROCESSOR'] = 'gamma' atr['INSAR_PROCESSOR'] = 'gamma' atr['FILE_TYPE'] = os.path.splitext(fname)[1] ## Get info: date12, num of loooks date12 = str(re.findall('\d{6}[-_]\d{6}', file_basename)[0]).replace('_', '-') atr['DATE12'] = date12 m_date, s_date = date12.split('-') lks = os.path.splitext(file_basename.split(date12)[1])[0] ## Read .off and .par file off_file = file_dir + '/' + date12 + lks + '.off' m_par_file = file_dir + '/' + m_date + lks + '.amp.par' s_par_file = file_dir + '/' + s_date + lks + '.amp.par' #print 'read '+m_par_file #print 'read '+off_file par_dict = readfile.read_gamma_par(m_par_file) off_dict = readfile.read_gamma_par(off_file) #print 'convert Gamma attribute to ROI_PAC style' atr.update(par_dict) atr.update(off_dict) atr = readfile.attribute_gamma2roipac(atr) ## Perp Baseline Info #print 'extract baseline info from %s, %s and %s file' % (m_par_file, s_par_file, off_file) atr = get_perp_baseline(m_par_file, s_par_file, off_file, atr) ## LAT/LON_REF1/2/3/4 #print 'extract LAT/LON_REF1/2/3/4 from '+m_par_file atr = get_lalo_ref(m_par_file, atr) ## Write to .rsc file #print 'writing >>> '+atr_file print 'merge %s, %s and %s into %s' % (os.path.basename(m_par_file), os.path.basename(s_par_file),\ os.path.basename(off_file), os.path.basename(atr_file)) writefile.write_roipac_rsc(atr, atr_file) return atr_file
def extract_attribute_dem_geo(fname): '''Read/extract attribute for .dem file from Gamma to ROI_PAC For example, it read input file, sim_150911-150922.utm.dem, find its associated par file, sim_150911-150922.utm.dem.par, read it, and convert to ROI_PAC style and write it to an rsc file, sim_150911-150922.utm.dem.rsc ''' atr = {} atr['PROCESSOR'] = 'gamma' atr['INSAR_PROCESSOR'] = 'gamma' atr['FILE_TYPE'] = os.path.splitext(fname)[1] atr['Y_UNIT'] = 'degrees' atr['X_UNIT'] = 'degrees' par_file = fname + '.par' print 'read ' + os.path.basename(par_file) print 'convert Gamma attribute to ROI_PAC style' par_dict = readfile.read_gamma_par(par_file) par_dict = readfile.attribute_gamma2roipac(par_dict) atr.update(par_dict) ## Write to .rsc file rsc_file = fname + '.rsc' try: atr_orig = readfile.read_roipac_rsc(rsc_file) except: atr_orig = None if atr_orig != atr: print 'writing >>> ' + os.path.basename(rsc_file) writefile.write_roipac_rsc(atr, rsc_file) return rsc_file
def extract_attribute_lookup_table(fname): '''Read/extract attribute for .UTM_TO_RDC file from Gamma to ROI_PAC For example, it read input file, sim_150911-150922.UTM_TO_RDC, find its associated par file, sim_150911-150922.utm.dem.par, read it, and convert to ROI_PAC style and write it to an rsc file, sim_150911-150922.UTM_TO_RDC.rsc''' ## Check existed .rsc file rsc_file_list = ut.get_file_list(fname + '.rsc') if rsc_file_list: rsc_file = rsc_file_list[0] print rsc_file + ' is existed, no need to re-extract.' return rsc_file atr = {} atr['PROCESSOR'] = 'gamma' atr['INSAR_PROCESSOR'] = 'gamma' atr['FILE_TYPE'] = os.path.splitext(fname)[1] atr['Y_UNIT'] = 'degrees' atr['X_UNIT'] = 'degrees' par_file = os.path.splitext(fname)[0] + '.utm.dem.par' print 'read ' + os.path.basename(par_file) par_dict = readfile.read_gamma_par(par_file) print 'convert Gamma attribute to ROI_PAC style' par_dict = readfile.attribute_gamma2roipac(par_dict) atr.update(par_dict) ## Write to .rsc file rsc_file = fname + '.rsc' try: atr_orig = readfile.read_roipac_rsc(rsc_file) except: atr_orig = None if atr_orig != atr: print 'writing >>> ' + os.path.basename(rsc_file) writefile.write_roipac_rsc(atr, rsc_file) return rsc_file
def extract_attribute_dem_radar(fname): '''Read/extract attribute for .hgt_sim file from Gamma to ROI_PAC Input: sim_150911-150922.hgt_sim sim_150911-150922.rdc.dem Search for: sim_150911-150922.diff_par Output: sim_150911-150922.hgt_sim.rsc sim_150911-150922.rdc.dem.rsc ''' atr = {} atr['PROCESSOR'] = 'gamma' atr['INSAR_PROCESSOR'] = 'gamma' atr['FILE_TYPE'] = os.path.splitext(fname)[1] # Get basename of file fname_base = os.path.splitext(fname)[0] for i in range(5): fname_base = os.path.splitext(fname_base)[0] par_file = fname_base + '.diff_par' print 'read ' + os.path.basename(par_file) print 'convert Gamma attribute to ROI_PAC style' par_dict = readfile.read_gamma_par(par_file) par_dict = readfile.attribute_gamma2roipac(par_dict) atr.update(par_dict) ## Write to .rsc file rsc_file = fname + '.rsc' try: atr_orig = readfile.read_roipac_rsc(rsc_file) except: atr_orig = None if atr_orig != atr: print 'writing >>> ' + os.path.basename(rsc_file) writefile.write_roipac_rsc(atr, rsc_file) return rsc_file
def extract_attribute_dem_radar(fname): '''Read/extract attribute for .hgt_sim file from Gamma to ROI_PAC For example, it read input file, sim_150911-150922.hgt_sim, find its associated par file, sim_150911-150922.diff_par, read it, and convert to ROI_PAC style and write it to an rsc file, sim_150911-150922.hgt_sim.rsc ''' atr = {} atr['PROCESSOR'] = 'gamma' atr['INSAR_PROCESSOR'] = 'gamma' atr['FILE_TYPE'] = os.path.splitext(fname)[1] par_file = os.path.splitext(fname)[0] + '.diff_par' print 'read ' + os.path.basename(par_file) print 'convert Gamma attribute to ROI_PAC style' par_dict = readfile.read_gamma_par(par_file) par_dict = readfile.attribute_gamma2roipac(par_dict) atr.update(par_dict) ## Write to .rsc file rsc_file = fname + '.rsc' print 'writing >>> ' + os.path.basename(rsc_file) writefile.write_roipac_rsc(atr, rsc_file) return rsc_file
def extract_attribute_interferogram(fname): '''Read/extract attributes for PySAR from Gamma .unw, .cor and .int file Inputs: fname : str, Gamma interferogram filename or path, i.e. /PopoSLT143TsxD/diff_filt_HDR_130118-130129_4rlks.unw Output: atr : dict, Attributes dictionary ''' file_dir = os.path.dirname(fname) file_basename = os.path.basename(fname) rsc_file = fname + '.rsc' #if os.path.isfile(rsc_file): # return rsc_file atr = {} atr['PROCESSOR'] = 'gamma' atr['INSAR_PROCESSOR'] = 'gamma' atr['FILE_TYPE'] = os.path.splitext(fname)[1] ## Get info: date12, num of loooks try: date12 = str(re.findall('\d{8}[-_]\d{8}', file_basename)[0]) except: date12 = str(re.findall('\d{6}[-_]\d{6}', file_basename)[0]) m_date, s_date = date12.replace('_', '-').split('-') atr['DATE12'] = ptime.yymmdd(m_date) + '-' + ptime.yymmdd(s_date) lks = os.path.splitext(file_basename.split(date12)[1])[0] ## Read .off and .par file off_file = file_dir + '/*' + date12 + lks + '.off' m_par_file = [ file_dir + '/*' + m_date + lks + i for i in ['.amp.par', '.ramp.par'] ] s_par_file = [ file_dir + '/*' + s_date + lks + i for i in ['.amp.par', '.ramp.par'] ] try: off_file = ut.get_file_list(off_file)[0] except: print '\nERROR: Can not find .off file, it supposed to be like: ' + off_file try: m_par_file = ut.get_file_list(m_par_file)[0] except: print '\nERROR: Can not find master date .par file, it supposed to be like: ' + m_par_file try: s_par_file = ut.get_file_list(s_par_file)[0] except: print '\nERROR: Can not find slave date .par file, it supposed to be like: ' + s_par_file #print 'read '+m_par_file #print 'read '+off_file par_dict = readfile.read_gamma_par(m_par_file) off_dict = readfile.read_gamma_par(off_file) #print 'convert Gamma attribute to ROI_PAC style' atr.update(par_dict) atr.update(off_dict) atr = readfile.attribute_gamma2roipac(atr) ## Perp Baseline Info #print 'extract baseline info from %s, %s and %s file' % (m_par_file, s_par_file, off_file) atr = get_perp_baseline(m_par_file, s_par_file, off_file, atr) ## LAT/LON_REF1/2/3/4 #print 'extract LAT/LON_REF1/2/3/4 from '+m_par_file atr = get_lalo_ref(m_par_file, atr) ## Write to .rsc file #print 'writing >>> '+rsc_file try: atr_orig = readfile.read_roipac_rsc(rsc_file) except: atr_orig = None if atr_orig != atr: print 'merge %s, %s and %s into %s' % (os.path.basename(m_par_file), os.path.basename(s_par_file),\ os.path.basename(off_file), os.path.basename(rsc_file)) writefile.write_roipac_rsc(atr, rsc_file) return rsc_file