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_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 main(argv): ##### Check Inputs if not argv or argv[0] in ['-h', '--help']: usage() sys.exit(1) if len(argv) < 2 or not argv[1]: raise Exception('\nAt lease 2 inputs are needed.\n') ##### Read Original Attributes #print '************ Add / Update HDF5 File Attributes *************' File = argv[0] atr = readfile.read_attribute(File) print 'Input file is ' + atr['PROCESSOR'] + ' ' + atr[ 'FILE_TYPE'] + ': ' + File ##### Read New Attributes atr_new = dict() for i in range(1, len(argv)): if os.path.isfile(argv[i]): atr_tmp = readfile.read_template(argv[i]) atr_new.update(atr_tmp) else: atr_tmp = argv[i].split('=') atr_new[atr_tmp[0].strip()] = atr_tmp[1].strip() print "The following attributes will be added/updated, or removed if new value is 'None':" info.print_attributes(atr_new) ext = os.path.splitext(File)[1] ##### Update h5 File if ext in ['.h5', '.he5']: File = ut.add_attribute(File, atr_new) else: if not ut.update_attribute_or_not(atr_new, atr): print 'All updated (removed) attributes already exists (do not exists) and have the same value, skip update.' else: for key, value in atr_new.iteritems(): # delete the item is new value is None if value == 'None': try: atr.pop(key) except: pass else: atr[key] = value if atr['PROCESSOR'] == 'roipac': print 'writing >>> ' + File + '.rsc' writefile.write_roipac_rsc(atr, File + '.rsc') return File
def extract_attribute(fname): '''Read/extract attributes for PySAR from ROI_PAC .unw, .int, .cor file. For each unwrapped interferogram or spatial coherence file, there are 2 .rsc files: basic metadata file and baseline parameter file. e.g. filt_100901-110117-sim_HDR_4rlks_c10.unw filt_100901-110117-sim_HDR_4rlks_c10.unw.rsc 100901-110117_baseline.rsc Inputs: fname : string, ROI_PAC interferogram filename or path, i.e. /KujuT422F650AlosA/filt_100901-110117-sim_HDR_4rlks_c10.unw Outputs: atr : dict, Attributes dictionary ''' ## 1. Read basic metadata file basic_rsc_file = fname + '.rsc' basic_dict = readfile.read_roipac_rsc(basic_rsc_file) # return if baseline attributes are already there. if 'P_BASELINE_TOP_HDR' in basic_dict.keys(): return basic_rsc_file atr = {} atr['PROCESSOR'] = 'roipac' atr['INSAR_PROCESSOR'] = 'roipac' atr['FILE_TYPE'] = os.path.splitext(fname)[1] ## 2. Read baseline metadata file date1, date2 = basic_dict['DATE12'].split('-') baseline_rsc_file = os.path.dirname( fname) + '/' + date1 + '_' + date2 + '_baseline.rsc' baseline_dict = readfile.read_roipac_rsc(baseline_rsc_file) print 'read ' + os.path.basename( basic_rsc_file) + ' and ' + os.path.basename(baseline_rsc_file) ## 3. Merge atr.update(basic_dict) atr.update(baseline_dict) ## Write to rsc file atr_file = fname + '.rsc' #print 'writing >>> '+os.path.basename(atr_file) writefile.write_roipac_rsc(atr, atr_file) return atr_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