def load_data_from_template(inps): '''Load dataset for PySAR time series using input template''' ##------------------------------------ Read Input Path -------------------------------------## # Initial value inps.unw = None inps.cor = None #inps.int = None inps.lut = None inps.dem_radar = None inps.dem_geo = None # 1.1 Read template contents (support multiple template files input) inps.template_file = [os.path.abspath(i) for i in inps.template_file] # Move default template file pysarApp_template.txt to the end of list, so that it has highest priority default_template_file = [i for i in inps.template_file if 'pysarApp' in i] if default_template_file: inps.template_file.remove(default_template_file[0]) inps.template_file.append(default_template_file[0]) template = dict() # Read file by file for File in inps.template_file: temp_dict = readfile.read_template(File) for key, value in temp_dict.iteritems(): temp_dict[key] = ut.check_variable_name(value) template.update(temp_dict) keyList = template.keys() # Project Name if not inps.project_name: inps.template_filename = [ os.path.basename(i) for i in inps.template_file ] try: inps.template_filename.remove('pysarApp_template.txt') except: pass if inps.template_filename: inps.project_name = os.path.splitext(inps.template_filename[0])[0] for key in [ 'processor', 'processing_software', 'unavco.processing_software', 'pysar.insarProcessor' ]: if key in keyList: value = template[key] if value == 'auto': inps.insarProcessor = 'roipac' else: inps.insarProcessor = value print '--------------------------------------------' print 'InSAR processing software: ' + inps.insarProcessor if 'pysar.unwrapFiles' in keyList: inps.unw = template['pysar.unwrapFiles'] if 'pysar.corFiles' in keyList: inps.cor = template['pysar.corFiles'] if 'pysar.lookupFile' in keyList: inps.lut = template['pysar.lookupFile'] if 'pysar.demFile.radarCoord' in keyList: inps.dem_radar = template['pysar.demFile.radarCoord'] if 'pysar.demFile.geoCoord' in keyList: inps.dem_geo = template['pysar.demFile.geoCoord'] # Check existed single dataset files inps_tmp = argparse.Namespace() inps_tmp = ut.check_loaded_dataset(inps.timeseries_dir, inps_tmp, print_msg=False) if (not inps.lut or inps.lut == 'auto') and inps_tmp.lookup_file: inps.lut = inps_tmp.lookup_file if (not inps.dem_radar or inps.dem_radar == 'auto') and inps_tmp.dem_radar_file: inps.dem_radar = inps_tmp.dem_radar_file if (not inps.dem_geo or inps.dem_geo == 'auto') and inps_tmp.dem_geo_file: inps.dem_geo = inps_tmp.dem_geo_file # 1.2 Auto Setting for Geodesy Lab - University of Miami if pysar.miami_path and 'SCRATCHDIR' in os.environ and inps.project_name: inps = auto_path_miami(inps, template) # 1.3 get snap_connect.byt path if .unw is input if inps.unw: inps.snap_connect = inps.unw.split('.unw')[0] + '_snap_connect.byt' else: inps.snap_connect = None # PYSAR directory if not inps.timeseries_dir: inps.timeseries_dir = os.getcwd() if not os.path.isdir(inps.timeseries_dir): os.makedirs(inps.timeseries_dir) #print "PySAR working directory: "+inps.timeseries_dir # TEMPLATE file directory (to support relative path input) inps.template_dir = os.path.dirname(inps.template_file[-1]) os.chdir(inps.template_dir) print 'Go to TEMPLATE directory: ' + inps.template_dir print 'unwrapped interferograms to load: ' + str(inps.unw) #print 'wrapped interferograms to load: '+str(inps.int) print 'spatial coherence files to load: ' + str(inps.cor) print 'lookup table file to load: ' + str(inps.lut) print 'DEM file in radar coord to load: ' + str(inps.dem_radar) print 'DEM file in geo coord to load: ' + str(inps.dem_geo) ##------------------------------------ Loading into HDF5 ---------------------------------------## # required - unwrapped interferograms inps.ifgram_file = load_file(inps.unw, vars(inps), file_type='interferograms') inps.coherence_file = load_file(inps.cor, vars(inps), file_type='coherence') #inps.wrap_ifgram_file = load_file(inps.int, vars(inps), file_type='wrapped') if inps.snap_connect: inps.snap_connect_file = load_file(inps.snap_connect, vars(inps)) # optional but recommend files - single_dataset file inps.lookup_file = load_file(inps.lut, vars(inps), file_type='geometry') inps.dem_radar_file = load_file(inps.dem_radar, vars(inps), file_type='dem') inps.dem_geo_file = load_file(inps.dem_geo, vars(inps), file_type='dem') os.chdir(inps.timeseries_dir) print 'Go back to PYSAR directory: ' + inps.timeseries_dir return inps
def main(argv): try: templateFile = argv[1] except: print ''' ******************************************* loading the processed data for PySAR: interferograms (unwrapped and wrapped) coherence files (generate Mask at the same time) Usage: load_data.py TEMPLATEFILE ******************************************* ''' sys.exit(1) templateContents = readfile.read_template(templateFile) projectName = os.path.basename(templateFile.partition('.')[0]) ############# Assign workubf directory ############################## try: tssarProjectDir = os.getenv('TSSARDIR') +'/'+projectName # use TSSARDIR if environment variable exist except: tssarProjectDir = os.getenv('SCRATCHDIR') + '/' + projectName + "/TSSAR" # FA 7/2015: adopted for new directory structure print "QQ " + tssarProjectDir if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir) ########### Use defaults if paths not given in template file ######### try: igramPath=templateContents['pysar.inputdata'] igramPath=check_variable_name(igramPath) except: igramPath = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*c10.unw' try: corPath=templateContents['pysar.CorFiles'] corPath=check_variable_name(corPath) except: corPath = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*.cor' try: wrapPath=templateContents['pysar.wrapped'] wrapPath=check_variable_name(wrapPath) except: wrapPath = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS/DONE/I*/filt_*0*sim_HDR_*rlks.int' ######################### Unwrapped Interferograms ######################## try: if os.path.isfile(tssarProjectDir+'/LoadedData.h5'): print '\nLoadedData.h5'+ ' already exists.\n' sys.exit(1) print 'loading interferograms ...' igramList = glob.glob(igramPath) k = 'interferograms' check_number(k,igramList) # number check igramList,mode_width,mode_length = check_size(k,igramList) # size check h5file = tssarProjectDir+'/LoadedData.h5' f = h5py.File(h5file) gg = f.create_group('interferograms') MaskZero=np.ones([int(mode_length),int(mode_width)]) for igram in igramList: if not os.path.basename(igram) in f: print 'Adding ' + igram group = gg.create_group(os.path.basename(igram)) amp,unw,unwrsc = readfile.read_float32(igram) MaskZero=amp*MaskZero dset = group.create_dataset(os.path.basename(igram), data=unw, compression='gzip') for key,value in unwrsc.iteritems(): group.attrs[key] = value d1,d2=unwrsc['DATE12'].split('-') baseline_file=os.path.dirname(igram)+'/'+d1+'_'+d2+'_baseline.rsc' baseline=readfile.read_rsc_file(baseline_file) for key,value in baseline.iteritems(): group.attrs[key] = value else: print os.path.basename(h5file) + " already contains " + os.path.basename(igram) Mask=np.ones([int(mode_length),int(mode_width)]) Mask[MaskZero==0]=0 gm = f.create_group('mask') dset = gm.create_dataset('mask', data=Mask, compression='gzip') f.close() ######################################################################## print 'writing to Mask.h5' h5file = 'Mask.h5' h5mask = h5py.File(h5file,'w') group=h5mask.create_group('mask') dset = group.create_dataset(os.path.basename('mask'), data=Mask, compression='gzip') h5mask.close() except: print 'No unwrapped interferogram is loaded.\n' ############################# Coherence ################################ try: if os.path.isfile(tssarProjectDir+'/Coherence.h5'): print '\nCoherence.h5'+ ' already exists.\n' sys.exit(1) print 'loading corelation files ...' corList = glob.glob(corPath) k = 'coherence' check_number(k,corList) # number check corList,mode_width,mode_length = check_size(k,corList) # size check h5file = tssarProjectDir+'/Coherence.h5' fcor = h5py.File(h5file) gg = fcor.create_group('coherence') meanCoherence=np.zeros([int(mode_length),int(mode_width)]) for cor in corList: if not os.path.basename(cor) in fcor: print 'Adding ' + cor group = gg.create_group(os.path.basename(cor)) amp,unw,unwrsc = readfile.read_float32(cor) meanCoherence=meanCoherence+unw dset = group.create_dataset(os.path.basename(cor), data=unw, compression='gzip') for key,value in unwrsc.iteritems(): group.attrs[key] = value d1,d2=unwrsc['DATE12'].split('-') baseline_file=os.path.dirname(cor)+'/'+d1+'_'+d2+'_baseline.rsc' baseline=readfile.read_rsc_file(baseline_file) for key,value in baseline.iteritems(): group.attrs[key] = value else: print os.path.basename(h5file) + " already contains " + os.path.basename(cor) meanCoherence=meanCoherence/(len(corList)) print '********************************' print 'writing average_spatial_coherence.h5' h5file_CorMean = tssarProjectDir+'/average_spatial_coherence.h5' fcor_mean = h5py.File(h5file_CorMean,'w') group=fcor_mean.create_group('mask') dset = group.create_dataset(os.path.basename('mask'), data=meanCoherence, compression='gzip') fcor_mean.close() print '********************************' print 'writing meanCoherence group to the interferogram file' gc = fcor.create_group('meanCoherence') dset = gc.create_dataset('meanCoherence', data=meanCoherence, compression='gzip') print '********************************' fcor.close() except: print 'No correlation file is loaded.\n' ########################## Wrapped Interferograms ############################ try: if os.path.isfile(tssarProjectDir+'/Wrapped.h5'): print '\nWrapped.h5'+ ' already exists.\n' sys.exit(1) print 'loading wrapped phase ...' wrapList = glob.glob(wrapPath) k = 'wrapped' check_number(k,wrapList) # number check wrapList,mode_width,mode_length = check_size(k,wrapList) # size check h5file = tssarProjectDir+'/Wrapped.h5' fw = h5py.File(h5file) gg = fw.create_group('wrapped') for wrap in wrapList: if not os.path.basename(wrap) in fw: print 'Adding ' + wrap group = gg.create_group(os.path.basename(wrap)) amp,unw,unwrsc = readfile.read_complex64(wrap) dset = group.create_dataset(os.path.basename(wrap), data=unw, compression='gzip') for key,value in unwrsc.iteritems(): group.attrs[key] = value d1,d2=unwrsc['DATE12'].split('-') baseline_file=os.path.dirname(wrap)+'/'+d1+'_'+d2+'_baseline.rsc' baseline=readfile.read_rsc_file(baseline_file) for key,value in baseline.iteritems(): group.attrs[key] = value else: print os.path.basename(h5file) + " already contains " + os.path.basename(wrap) fw.close() print 'Writed '+str(len(wrapList))+' wrapped interferograms to '+h5file except: print 'No wrapped interferogram is loaded.\n' try: geomapFile=templateContents['pysar.geomap'] geomapFile=check_variable_name(geomapFile) cpCmd="cp " + geomapFile + " " + tssarProjectDir print cpCmd os.system(cpCmd) cpCmd="cp " + geomapFile + ".rsc " + tssarProjectDir print cpCmd os.system(cpCmd) except: print "*********************************" print "Warning: no geomap file given" print "*********************************"
def main(argv): try: templateFile = argv[1] except: print ''' ******************************************* loading the processed data for PySAR: interferograms (unwrapped and wrapped) coherence files (generate Mask at the same time) Usage: load_data.py TEMPLATEFILE ******************************************* ''' sys.exit(1) templateContents = readfile.read_template(templateFile) projectName = os.path.basename(templateFile.partition('.')[0]) ############# Assign workubf directory ############################## try: tssarProjectDir = os.getenv( 'TSSARDIR' ) + '/' + projectName # use TSSARDIR if environment variable exist except: tssarProjectDir = os.getenv( 'SCRATCHDIR' ) + '/' + projectName + "/TSSAR" # FA 7/2015: adopted for new directory structure print "QQ " + tssarProjectDir if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir) ########### Use defaults if paths not given in template file ######### try: igramPath = templateContents['pysar.inputdata'] igramPath = check_variable_name(igramPath) except: igramPath = os.getenv( 'SCRATCHDIR' ) + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*c10.unw' try: corPath = templateContents['pysar.CorFiles'] corPath = check_variable_name(corPath) except: corPath = os.getenv( 'SCRATCHDIR' ) + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*.cor' try: wrapPath = templateContents['pysar.wrapped'] wrapPath = check_variable_name(wrapPath) except: wrapPath = os.getenv( 'SCRATCHDIR' ) + '/' + projectName + '/PROCESS/DONE/I*/filt_*0*sim_HDR_*rlks.int' ######################### Unwrapped Interferograms ######################## try: if os.path.isfile(tssarProjectDir + '/LoadedData.h5'): print '\nLoadedData.h5' + ' already exists.\n' sys.exit(1) print 'loading interferograms ...' igramList = glob.glob(igramPath) k = 'interferograms' check_number(k, igramList) # number check igramList, mode_width, mode_length = check_size( k, igramList) # size check h5file = tssarProjectDir + '/LoadedData.h5' f = h5py.File(h5file) gg = f.create_group('interferograms') MaskZero = np.ones([int(mode_length), int(mode_width)]) for igram in igramList: if not os.path.basename(igram) in f: print 'Adding ' + igram group = gg.create_group(os.path.basename(igram)) amp, unw, unwrsc = readfile.read_float32(igram) MaskZero = amp * MaskZero dset = group.create_dataset(os.path.basename(igram), data=unw, compression='gzip') for key, value in unwrsc.iteritems(): group.attrs[key] = value d1, d2 = unwrsc['DATE12'].split('-') baseline_file = os.path.dirname( igram) + '/' + d1 + '_' + d2 + '_baseline.rsc' baseline = readfile.read_rsc_file(baseline_file) for key, value in baseline.iteritems(): group.attrs[key] = value else: print os.path.basename( h5file) + " already contains " + os.path.basename(igram) Mask = np.ones([int(mode_length), int(mode_width)]) Mask[MaskZero == 0] = 0 gm = f.create_group('mask') dset = gm.create_dataset('mask', data=Mask, compression='gzip') f.close() ######################################################################## print 'writing to Mask.h5' h5file = 'Mask.h5' h5mask = h5py.File(h5file, 'w') group = h5mask.create_group('mask') dset = group.create_dataset(os.path.basename('mask'), data=Mask, compression='gzip') h5mask.close() except: print 'No unwrapped interferogram is loaded.\n' ############################# Coherence ################################ try: if os.path.isfile(tssarProjectDir + '/Coherence.h5'): print '\nCoherence.h5' + ' already exists.\n' sys.exit(1) print 'loading corelation files ...' corList = glob.glob(corPath) k = 'coherence' check_number(k, corList) # number check corList, mode_width, mode_length = check_size(k, corList) # size check h5file = tssarProjectDir + '/Coherence.h5' fcor = h5py.File(h5file) gg = fcor.create_group('coherence') meanCoherence = np.zeros([int(mode_length), int(mode_width)]) for cor in corList: if not os.path.basename(cor) in fcor: print 'Adding ' + cor group = gg.create_group(os.path.basename(cor)) amp, unw, unwrsc = readfile.read_float32(cor) meanCoherence = meanCoherence + unw dset = group.create_dataset(os.path.basename(cor), data=unw, compression='gzip') for key, value in unwrsc.iteritems(): group.attrs[key] = value d1, d2 = unwrsc['DATE12'].split('-') baseline_file = os.path.dirname( cor) + '/' + d1 + '_' + d2 + '_baseline.rsc' baseline = readfile.read_rsc_file(baseline_file) for key, value in baseline.iteritems(): group.attrs[key] = value else: print os.path.basename( h5file) + " already contains " + os.path.basename(cor) meanCoherence = meanCoherence / (len(corList)) print '********************************' print 'writing average_spatial_coherence.h5' h5file_CorMean = tssarProjectDir + '/average_spatial_coherence.h5' fcor_mean = h5py.File(h5file_CorMean, 'w') group = fcor_mean.create_group('mask') dset = group.create_dataset(os.path.basename('mask'), data=meanCoherence, compression='gzip') fcor_mean.close() print '********************************' print 'writing meanCoherence group to the interferogram file' gc = fcor.create_group('meanCoherence') dset = gc.create_dataset('meanCoherence', data=meanCoherence, compression='gzip') print '********************************' fcor.close() except: print 'No correlation file is loaded.\n' ########################## Wrapped Interferograms ############################ try: if os.path.isfile(tssarProjectDir + '/Wrapped.h5'): print '\nWrapped.h5' + ' already exists.\n' sys.exit(1) print 'loading wrapped phase ...' wrapList = glob.glob(wrapPath) k = 'wrapped' check_number(k, wrapList) # number check wrapList, mode_width, mode_length = check_size(k, wrapList) # size check h5file = tssarProjectDir + '/Wrapped.h5' fw = h5py.File(h5file) gg = fw.create_group('wrapped') for wrap in wrapList: if not os.path.basename(wrap) in fw: print 'Adding ' + wrap group = gg.create_group(os.path.basename(wrap)) amp, unw, unwrsc = readfile.read_complex64(wrap) dset = group.create_dataset(os.path.basename(wrap), data=unw, compression='gzip') for key, value in unwrsc.iteritems(): group.attrs[key] = value d1, d2 = unwrsc['DATE12'].split('-') baseline_file = os.path.dirname( wrap) + '/' + d1 + '_' + d2 + '_baseline.rsc' baseline = readfile.read_rsc_file(baseline_file) for key, value in baseline.iteritems(): group.attrs[key] = value else: print os.path.basename( h5file) + " already contains " + os.path.basename(wrap) fw.close() print 'Writed ' + str( len(wrapList)) + ' wrapped interferograms to ' + h5file except: print 'No wrapped interferogram is loaded.\n' try: geomapFile = templateContents['pysar.geomap'] geomapFile = check_variable_name(geomapFile) cpCmd = "cp " + geomapFile + " " + tssarProjectDir print cpCmd os.system(cpCmd) cpCmd = "cp " + geomapFile + ".rsc " + tssarProjectDir print cpCmd os.system(cpCmd) except: print "*********************************" print "Warning: no geomap file given" print "*********************************"
def main(argv): DelayType = 'comb' try: opts, args = getopt.getopt(argv, "f:d:s:h:D:i:") except getopt.GetoptError: Usage() sys.exit(1) for opt, arg in opts: if opt == '-f': timeSeriesFile = arg elif opt == '-d': demFile = arg elif opt == '-s': atmSource = arg elif opt == '-h': hr = arg elif opt == '-D': DelayType = arg elif opt == '-i': inc_angle = arg try: timeSeriesFile demFile except: Usage() sys.exit(1) demFile = ut.check_variable_name(demFile) demCoord = ut.radar_or_geo(demFile) h5timeseries = h5py.File(timeSeriesFile) yref = h5timeseries['timeseries'].attrs['ref_y'] xref = h5timeseries['timeseries'].attrs['ref_x'] ############################################################### #incidence angle to map the zenith delay to the slant delay try: inc_angle except: print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' print 'WARNING:' print 'incedence angle is not specified >>>> Average look angle is used ... ' print 'For more precise results use input option -i to introduce the incidence angle file or average incodence angle' print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' input_inc_angle = 'None' wavelength = float(h5timeseries['timeseries'].attrs['WAVELENGTH']) inc_angle1 = float(h5timeseries['timeseries'].attrs['LOOK_REF1']) inc_angle2 = float(h5timeseries['timeseries'].attrs['LOOK_REF2']) inc_angle = (inc_angle1 + inc_angle2) / 2.0 print '*******************************************************************************' print 'Near Look Angle: ' + str(inc_angle1) print 'Far Look Angle:' + str(inc_angle2) print 'Average Look Angle (used in pyaps to calculate delay): ' + str( inc_angle) print 'Acquisition time is : ' + hr print '*******************************************************************************' inc_angle = str(inc_angle) if os.path.isfile(inc_angle): incidenceFile = inc_angle h5incidence = h5py.File(incidenceFile, 'r') iset = h5incidence['mask'].get('mask') inc_angle = iset[0:iset.shape[0], 0:iset.shape[1]] h5incidence.close() else: inc_angle = float(inc_angle) print 'incidence angle = ' + str(inc_angle) inc_angle = inc_angle * pi / 180.0 ################################################################ dateList = h5timeseries['timeseries'].keys() if atmSource in ['ecmwf', 'ECMWF']: gribSource = 'ECMWF' if not os.path.isdir('ECMWF'): print 'making directory: ECMWF' os.mkdir('ECMWF') ecmwf_file = [] for d in dateList: ecm = './ECMWF/ERA-Int_' + d + '_' + hr + '.grb' ecmwf_file.append(ecm) print[d] if not os.path.isfile(ecm): pa.ECMWFdload([d], hr, './ECMWF/') else: print ecm + ' already exists.' elif atmSource in ['narr', 'NARR']: gribSource = 'NARR' if not os.path.isdir('NARR'): print 'making directory: NARR' os.mkdir('NARR') ecmwf_file = [] for d in dateList: ecm = './NARR/narr-a_221_' + d + '_' + hr + '00_000.grb' ecmwf_file.append(ecm) print[d] if not os.path.isfile(ecm): pa.NARRdload([d], hr, './NARR/') else: print ecm + ' already exists.' elif atmSource in ['era', 'ERA']: gribSource = 'ERA' if not os.path.isdir('ERA'): print 'making directory: ERA' os.mkdir('ERA') ecmwf_file = [] for d in dateList: ecm = './ERA/ERA_' + d + '_' + hr + '.grb' ecmwf_file.append(ecm) print[d] if not os.path.isfile(ecm): pa.ERAdload([d], hr, './ERA/') else: print ecm + ' already exists.' elif atmSource in ['merra', 'MERRA']: gribSource = 'MERRA' if not os.path.isdir('MERRA'): print 'making directory: MERRA' os.mkdir('MERRA') ecmwf_file = [] for d in dateList: ecm = './MERRA/merra-' + d + '-' + hr + '.hdf' ecmwf_file.append(ecm) print[d] if not os.path.isfile(ecm): pa.MERRAdload([d], hr, './MERRA/') else: print ecm + ' already exists.' else: Usage() sys.exit(1) print '*******************************************************************************' print 'Calcualting delay for each epoch.' h5phsName = atmSource + '.h5' h5phs = h5py.File(h5phsName, 'w') outName = timeSeriesFile.replace( '.h5', '_') + atmSource + '.h5' #Yunjun, Feb 15, 2015 #outName=timeSeriesFile.replace('.h5','')+'_tropCorPyAPS.h5' h5apsCor = h5py.File(outName, 'w') group = h5apsCor.create_group('timeseries') group_phs = h5phs.create_group('timeseries') #if 'X_FIRST' in h5timeseries['timeseries'].attrs.keys(): # demCoord='geo' # print 'The coordinate system is : Geo' #else: # demCoord='radar' # print 'The coordinate system is : radar' print ecmwf_file[0] if demCoord == 'radar': aps1 = pa.PyAPS_rdr(str(ecmwf_file[0]), demFile, grib=gribSource, verb=True, Del=DelayType) else: aps1 = pa.PyAPS_geo(str(ecmwf_file[0]), demFile, grib=gribSource, verb=True, Del=DelayType) phs1 = zeros((aps1.ny, aps1.nx)) aps1.getdelay(phs1) phs1 = (phs1 - phs1[yref, xref]) / cos(inc_angle) dset = group.create_dataset(dateList[0], data=phs1 - phs1, compression='gzip') for i in range(1, len(ecmwf_file)): ecm = ecmwf_file[i] print ecm if demCoord == 'radar': aps = pa.PyAPS_rdr(str(ecm), demFile, grib=gribSource, verb=True, Del=DelayType) else: aps = pa.PyAPS_geo(str(ecm), demFile, grib=gribSource, verb=True, Del=DelayType) phs = zeros((aps.ny, aps.nx)) aps.getdelay(phs) phs = (phs - phs[yref, xref]) / cos(inc_angle) phs = phs - phs1 dset = group_phs.create_dataset(dateList[i], data=phs, compression='gzip') dset1 = h5timeseries['timeseries'].get(dateList[i]) data1 = dset1[0:dset1.shape[0], 0:dset1.shape[1]] dset = group.create_dataset(dateList[i], data=data1 + phs, compression='gzip') for key, value in h5timeseries['timeseries'].attrs.iteritems(): group.attrs[key] = value group_phs.attrs[key] = value dset1 = h5timeseries['mask'].get('mask') Mask = dset1[0:dset1.shape[0], 0:dset1.shape[1]] group = h5apsCor.create_group('mask') dset = group.create_dataset('mask', data=Mask, compression='gzip')
def main(argv): DelayType='comb' try: opts, args = getopt.getopt(argv,"f:d:s:h:D:i:") except getopt.GetoptError: Usage() ; sys.exit(1) for opt,arg in opts: if opt == '-f': timeSeriesFile = arg elif opt == '-d': demFile = arg elif opt == '-s': atmSource=arg elif opt == '-h': hr=arg elif opt == '-D': DelayType=arg elif opt == '-i': inc_angle=arg try: timeSeriesFile demFile except: Usage() ; sys.exit(1) demFile=check_variable_name(demFile) h5timeseries = h5py.File(timeSeriesFile) yref=h5timeseries['timeseries'].attrs['ref_y'] xref=h5timeseries['timeseries'].attrs['ref_x'] ############################################################### #incidence angle to map the zenith delay to the slant delay try: inc_angle except: print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' print 'WARNING:' print 'incedence angle is not specified >>>> Average look angle is used ... ' print 'For more precise results use input option -i to introduce the incidence angle file or average incodence angle' print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' input_inc_angle='None' wavelength=float(h5timeseries['timeseries'].attrs['WAVELENGTH']) inc_angle1=float(h5timeseries['timeseries'].attrs['LOOK_REF1']) inc_angle2=float(h5timeseries['timeseries'].attrs['LOOK_REF2']) inc_angle=(inc_angle1+inc_angle2)/2.0 print '*******************************************************************************' print 'Near Look Angle: ' + str(inc_angle1) print 'Far Look Angle:' + str(inc_angle2) print 'Average Look Angle (used in pyaps to calculate delay): ' + str(inc_angle) print 'Acquisition time is : '+ hr print '*******************************************************************************' inc_angle=str(inc_angle) if os.path.isfile(inc_angle): incidenceFile=inc_angle h5incidence=h5py.File(incidenceFile,'r') iset=h5incidence['mask'].get('mask') inc_angle=iset[0:iset.shape[0],0:iset.shape[1]] h5incidence.close() else: inc_angle=float(inc_angle) print 'incidence angle = '+ str(inc_angle) inc_angle=inc_angle*pi/180.0 ################################################################ dateList = h5timeseries['timeseries'].keys() if atmSource in ['ecmwf','ECMWF']: gribSource='ECMWF' if not os.path.isdir('ECMWF'): print 'making directory: ECMWF' os.mkdir('ECMWF') ecmwf_file=[] for d in dateList: ecm='./ECMWF/ERA-Int_'+d+'_'+hr+'.grb' ecmwf_file.append(ecm) print [d] if not os.path.isfile(ecm): pa.ECMWFdload([d],hr,'./ECMWF/') else: print ecm + ' already exists.' elif atmSource in ['narr','NARR']: gribSource='NARR' if not os.path.isdir('NARR'): print 'making directory: NARR' os.mkdir('NARR') ecmwf_file=[] for d in dateList: ecm='./NARR/narr-a_221_'+d+'_'+hr+'00_000.grb' ecmwf_file.append(ecm) print [d] if not os.path.isfile(ecm): pa.NARRdload([d],hr,'./NARR/') else: print ecm + ' already exists.' elif atmSource in ['era','ERA']: gribSource='ERA' if not os.path.isdir('ERA'): print 'making directory: ERA' os.mkdir('ERA') ecmwf_file=[] for d in dateList: ecm='./ERA/ERA_'+d+'_'+hr+'.grb' ecmwf_file.append(ecm) print [d] if not os.path.isfile(ecm): pa.ERAdload([d],hr,'./ERA/') else: print ecm + ' already exists.' elif atmSource in ['merra','MERRA']: gribSource='MERRA' if not os.path.isdir('MERRA'): print 'making directory: MERRA' os.mkdir('MERRA') ecmwf_file=[] for d in dateList: ecm='./MERRA/merra-'+d+'-'+hr+'.hdf' ecmwf_file.append(ecm) print [d] if not os.path.isfile(ecm): pa.MERRAdload([d],hr,'./MERRA/') else: print ecm + ' already exists.' else: Usage();sys.exit(1) print '*******************************************************************************' print 'Calcualting delay for each epoch.' h5phsName=atmSource + '.h5' h5phs=h5py.File(h5phsName,'w') outName=timeSeriesFile.replace('.h5','_') + atmSource + '.h5' #Yunjun, Feb 15, 2015 # outName=timeSeriesFile.replace('.h5','')+'_tropCorPyAPS.h5' h5apsCor=h5py.File(outName,'w') group=h5apsCor.create_group('timeseries') group_phs=h5phs.create_group('timeseries') if 'X_FIRST' in h5timeseries['timeseries'].attrs.keys(): demCoord='geo' print 'The coordinate system is : Geo' else: demCoord='radar' print 'The coordinate system is : radar' print ecmwf_file[0] if demCoord=='radar': aps1 = pa.PyAPS_rdr(str(ecmwf_file[0]),demFile,grib=gribSource,verb=True,Del=DelayType) else: aps1 = pa.PyAPS_geo(ecmwf_file[0],demFile,grib=gribSource,verb=True,Del=DelayType) phs1 = zeros((aps1.ny,aps1.nx)) aps1.getdelay(phs1) phs1=(phs1 - phs1[yref,xref])/cos(inc_angle) dset = group.create_dataset(dateList[0], data= phs1- phs1, compression='gzip') for i in range(1,len(ecmwf_file)): ecm=ecmwf_file[i] print ecm if demCoord=='radar': aps = pa.PyAPS_rdr(str(ecm),demFile,grib=gribSource,verb=True,Del=DelayType) else: aps = pa.PyAPS_geo(str(ecm),demFile,grib=gribSource,verb=True,Del=DelayType) phs = zeros((aps.ny,aps.nx)) aps.getdelay(phs) phs=(phs - phs[yref,xref])/cos(inc_angle) phs=phs-phs1 dset = group_phs.create_dataset(dateList[i], data= phs, compression='gzip') dset1 = h5timeseries['timeseries'].get(dateList[i]) data1 = dset1[0:dset1.shape[0],0:dset1.shape[1]] dset = group.create_dataset(dateList[i], data= data1+phs, compression='gzip') for key,value in h5timeseries['timeseries'].attrs.iteritems(): group.attrs[key] = value group_phs.attrs[key] = value dset1 = h5timeseries['mask'].get('mask') Mask = dset1[0:dset1.shape[0],0:dset1.shape[1]] group = h5apsCor.create_group('mask') dset = group.create_dataset('mask', data=Mask, compression='gzip')
def main(argv): inps = cmdLineParse() #print '\n*************** Loading ROI_PAC Data into PySAR ****************' inps.project_name = os.path.splitext(os.path.basename(inps.template_file))[0] print 'project: '+inps.project_name ##### 1. Read file path # Priority: command line input > template > auto setting # Read template contents into inps Namespace inps.template_file = os.path.abspath(inps.template_file) template_dict = readfile.read_template(inps.template_file) for key, value in template_dict.iteritems(): template_dict[key] = ut.check_variable_name(value) keyList = template_dict.keys() if not inps.unw and 'pysar.unwrapFiles' in keyList: inps.unw = template_dict['pysar.unwrapFiles'] if not inps.cor and 'pysar.corFiles' in keyList: inps.cor = template_dict['pysar.corFiles'] if not inps.int and 'pysar.wrapFiles' in keyList: inps.int = template_dict['pysar.wrapFiles'] if not inps.geomap and 'pysar.geomap' in keyList: inps.geomap = template_dict['pysar.geomap'] if not inps.dem_radar and 'pysar.dem.radarCoord' in keyList: inps.dem_radar = template_dict['pysar.dem.radarCoord'] if not inps.dem_geo and 'pysar.dem.geoCoord' in keyList: inps.dem_geo = template_dict['pysar.dem.geoCoord'] # Auto Setting for Geodesy Lab - University of Miami if pysar.miami_path and 'SCRATCHDIR' in os.environ: inps = auto_path_miami(inps, template_dict) # TIMESERIES directory for PySAR if not inps.timeseries_dir: inps.timeseries_dir = os.getcwd() if not os.path.isdir(inps.timeseries_dir): os.mkdir(inps.timeseries_dir) print "PySAR working directory: "+inps.timeseries_dir # TEMPLATE file directory (to support relative path input) inps.template_dir = os.path.dirname(inps.template_file) os.chdir(inps.template_dir) print 'Go to TEMPLATE directory: '+inps.template_dir # Get all file list inps.snap_connect = [] if inps.unw: print 'unwrapped interferograms: '+str(inps.unw) inps.snap_connect = inps.unw.split('.unw')[0]+'_snap_connect.byt' inps.snap_connect = sorted(glob.glob(inps.snap_connect)) inps.unw = sorted(glob.glob(inps.unw)) if inps.int: print 'wrapped interferograms: '+str(inps.int) inps.int = sorted(glob.glob(inps.int)) if inps.cor: print 'coherence files: '+str(inps.cor) inps.cor = sorted(glob.glob(inps.cor)) try: inps.geomap = glob.glob(inps.geomap)[0] except: inps.geomap = None try: inps.dem_radar = glob.glob(inps.dem_radar)[-1] except: inps.dem_radar = None try: inps.dem_geo = glob.glob(inps.dem_geo)[0] except: inps.dem_geo = None print 'geomap file: '+str(inps.geomap) print 'DEM file in radar coord: '+str(inps.dem_radar) print 'DEM file in geo coord: '+str(inps.dem_geo) ##### 2. Load data into hdf5 file inps.ifgram_file = inps.timeseries_dir+'/unwrapIfgram.h5' inps.coherence_file = inps.timeseries_dir+'/coherence.h5' inps.wrapIfgram_file = inps.timeseries_dir+'/wrapIfgram.h5' inps.snap_connect_file = inps.timeseries_dir+'/snaphuConnectComponent.h5' inps.mask_file = inps.timeseries_dir+'/Mask.h5' inps.spatial_coherence_file = inps.timeseries_dir+'/average_spatial_coherence.h5' # 2.1 multi_group_hdf5_file # Unwrapped Interferograms if inps.unw: unwList = load_roipac2multi_group_h5('interferograms', inps.unw, inps.ifgram_file, vars(inps))[1] # Update mask only when update unwrapIfgram.h5 if unwList: print 'Generate mask from amplitude of interferograms' roipac_nonzero_mask(inps.unw, inps.mask_file) elif os.path.isfile(inps.ifgram_file): print os.path.basename(inps.ifgram_file)+' already exists, no need to re-load.' else: sys.exit('ERROR: Cannot load/find unwrapped interferograms!') # Optional if inps.snap_connect: load_roipac2multi_group_h5('snaphu_connect_component', inps.snap_connect, inps.snap_connect_file, vars(inps)) # Coherence if inps.cor: cohFile,corList = load_roipac2multi_group_h5('coherence', inps.cor, inps.coherence_file, vars(inps)) if corList: meanCohCmd = 'temporal_average.py '+cohFile+' '+inps.spatial_coherence_file print meanCohCmd os.system(meanCohCmd) elif os.path.isfile(inps.coherence_file): print os.path.basename(inps.coherence_file)+' already exists, no need to re-load.' else: print 'WARNING: Cannot load/find coherence.' # Wrapped Interferograms if inps.int: load_roipac2multi_group_h5('wrapped', inps.int, inps.wrapIfgram_file, vars(inps)) elif os.path.isfile(inps.wrapIfgram_file): print os.path.basename(inps.wrapIfgram_file)+' already exists, no need to re-load.' else: print "WARNING: Cannot load/find wrapped interferograms. It's okay, continue without it ..." # 2.2 single dataset file if inps.geomap: copy_roipac_file(inps.geomap, inps.timeseries_dir) if inps.dem_radar: copy_roipac_file(inps.dem_radar, inps.timeseries_dir) if inps.dem_geo: copy_roipac_file(inps.dem_geo, inps.timeseries_dir)
def main(argv): try: templateFile = argv[1] except: Usage() sys.exit(1) projectName = os.path.basename(templateFile.partition('.')[0]) try: tssarProjectDir = os.getenv('TSSARDIR') + '/' + projectName except: tssarProjectDir = os.getenv( 'SCRATCHDIR' ) + '/' + projectName + "/TSSAR" # FA 7/2015: adopted for new directory structure print "QQ " + tssarProjectDir if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir) os.chdir(tssarProjectDir) igramFile = 'LoadedData.h5' Modified_igramFile = 'Modified_LoadedData.h5' if os.path.isfile(Modified_igramFile): print Modified_igramFile + ' already exists.' igramFile = Modified_igramFile template = readfile.read_template(templateFile) Rlooks = template['Rlooks_unw'] ######################################### # Loading interferograms ######################################### print '******************************************' print '' if os.path.isfile(igramFile): print igramFile + ' already exists.' else: loadCmd = 'load_data.py ' + templateFile print loadCmd os.system(loadCmd) # copyDemCmd='copy_dem_trans.py ' + templateFile # print copyDemCmd # os.system(copyDemCmd) print '' print '******************************************' ######################################### # Check the subset ######################################### try: subset = template['pysar.subset.yx'].split(',') print subset print subset[0] subsetOutName = 'subset_' + igramFile subsetCmd = 'subset.py -f ' + igramFile + ' -y ' + subset[ 0] + ' -x ' + subset[1] + ' -o ' + subsetOutName print '*****************************************' print 'Subset the area ...' print subsetCmd os.system(subsetCmd) igramFile = subsetOutName print '*****************************************' except: print '*****************************************' print 'No Subset selected. Processing the whole area' print '*****************************************' ######################################### #Referencing all interferograms to the same pixel ######################################### rdr_or_geo = radar_Or_geo(igramFile) print '******************************************' print '' if os.path.isfile('Seeded_' + igramFile): igramFile = 'Seeded_' + igramFile print igramFile + ' already exists.' else: print 'referncing all interferograms to the same pixel.' if 'pysar.seed.ll' in template.keys(): 'Checking the lat/lon refernce point' lat = template['pysar.seed.ll'].split(',')[0] lon = template['pysar.seed.ll'].split(',')[1] seedCmd = 'SeedData.py -f ' + igramFile + ' -l ' + lat + ' -L ' + lon elif 'pysar.seed.yx' in template.keys(): 'Checking y/x reference point' y = template['pysar.seed.yx'].split(',')[0] x = template['pysar.seed.yx'].split(',')[1] seedCmd = 'seed_data.py -f ' + igramFile + ' -y ' + y + ' -x ' + x else: seedCmd = 'seed_data.py -f ' + igramFile igramFile = 'Seeded_' + igramFile print seedCmd os.system(seedCmd) print '' print '******************************************' ############################################ #unwrapping error correction based on the # consistency of triplets of interferograms ############################################ print '******************************************' print '' try: template['pysar.unwrap_error'] if template['pysar.unwrap_error'] in ('y', 'yes', 'Yes', 'YES'): print 'unwrapping error correction might take a while depending on the size of your data set! ' unwCmd = 'unwrap_error.py ' + igramFile os.system(unwCmd) igramFile = igramFile.split('.')[0] + '_unwCor.h5' else: print 'No unwrapping error correction.' except: print 'No unwrapping error correction.' print '' print '******************************************' ######################################### # inversion of interferograms ######################################## print '******************************************' print '' if os.path.isfile(igramFile.split('.')[0] + '_unwCor.h5'): igramFile = igramFile.split('.')[0] + '_unwCor.h5' print igramFile + ' exists.' if os.path.isfile('timeseries.h5'): print 'timeseries.h5 already exists, inversion is not needed.' else: invertCmd = 'igram_inversion.py ' + igramFile print invertCmd os.system(invertCmd) timeseriesFile = 'timeseries.h5' print '' print '******************************************' ############################################## #temporal coherence: #A parameter to evaluate the consistency of # timeseries with the interferograms ############################################## print '******************************************' print '' # if os.path.isfile('temporal_coherence.h5'): # print 'temporal_coherence.h5 already exists.' # else: # tempcohCmd='temporal_coherence.py '+igramFile+' '+timeseriesFile # print tempcohCmd # os.system(tempcohCmd) tempcohCmd = 'temporal_coherence.py ' + igramFile + ' ' + timeseriesFile print tempcohCmd os.system(tempcohCmd) print '' print '******************************************' ############################################## #update Mask based on temporal coherence # add by Yunjun Feb 15, 2015 ############################################## print '******************************************' print '' try: template['pysar.mask'] if template['pysar.mask'] in ('yes', 'Yes', 'YES', 'y'): print 'Updating mask according to temporal coherence' cohT = template['pysar.mask.threshold'] maskCmd = 'generate_mask.py -f temporal_coherence.h5 -m ' + cohT + ' -M 1.0 -o Mask.h5' print maskCmd os.system(maskCmd) else: print 'No update for mask.' except: print 'No update for mask.' print '' print '******************************************' ############################################## # Generate incident angle # add by Yunjun Feb 15, 2015 ############################################## print '******************************************' print '' inciCmd = 'incidence_angle.py -f timeseries.h5' print inciCmd os.system(inciCmd) print '' print '******************************************' ############################################## #If Satellite is Envisat and if Coordinate #system is radar then LOD correction ############################################## print '******************************************' print '' h5file = h5py.File(timeseriesFile, 'r') if rdr_or_geo == 'radar': if h5file['timeseries'].attrs['PLATFORM'] == 'ENVISAT': LODcmd = 'lod.py ' + timeseriesFile print LODcmd os.system(LODcmd) timeseriesFile = timeseriesFile.split('.')[0] + '_LODcor.h5' print '' print '******************************************' ############################################## # Tropospheric Correction ############################################## print '******************************************' print '' try: if (template['pysar.tropospheric_delay'] in ('y', 'yes', 'Yes', 'YES') ) and template['pysar.orbit_error.method'] == 'BaseTropCor': print ''' +++++++++++++++++++++++++++++++++++++++++++++++++++ WARNING: Orbital error correction was BaseTropCor. Tropospheric correction was already applied simultaneous with baseline error correction. Tropospheric correction can not be applied again. To apply the tropospheric correction separate from baseline error correction, chhose other existing options for orbital error correction. +++++++++++++++++++++++++++++++++++++++++++++++++++ ''' template['pysar.tropospheric_delay'] = 'no' except: print 'Checking the tropospheric delay correction ...' if template['pysar.tropospheric_delay'] in ('y', 'yes', 'Yes', 'YES'): # demFile='radar_'+Rlooks+'rlks.hgt' demFile = template['pysar.dem'] demFile = check_variable_name(demFile) # print 'DEM file: '+demFile if not os.path.isfile(demFile): print '++++++++++++++++++++++++++++++++++++++++++++++' print 'Error:' print 'DEM (radar_*rlks.hgt file) was not found!' print 'Continue without tropospheric correction ...' print '++++++++++++++++++++++++++++++++++++++++++++++' else: if template['pysar.tropospheric_delay.method'] in [ 'height-correlation', 'height_correlation', 'Height-Correlation', 'Height_Correlation' ]: print 'tropospheric delay correction with height-correlation approach' try: polyOrder = template['pysar.trop.polyOrder'] except: print 'Deafult polynomial order for troposphreic correction = 1' polyOrder = '1' cmdTrop = 'tropospheric_correction.py' + ' -f ' + timeseriesFile + ' -d ' + demfile + ' -p ' + polyOrder os.system(cmdTrop) timeseriesFile = timeseriesFile.split('.')[0] + '_tropCor.h5' elif template['pysar.tropospheric_delay.method'] == 'pyaps': print 'Atmospheric correction using Numerical Weather Models (using PyAPS software)' print 'reading DEM, source of NWM and acquisition time from template file' source_of_NWM = template['pysar.Numerical_Weather_Model'] print 'Numerical Weather Model: ' + source_of_NWM acquisition_time = template['pysar.acquisition_time'] print 'acquisition time: ' + acquisition_time # cmdTrop = ["tropcor_pyaps.py -f ",timeseriesFile," -d ",demFile," -s ",source_of_NWM," -h ",acquisition_time," -i incidence_angle.h5"] cmdTrop = 'tropcor_pyaps.py -f ' + timeseriesFile + ' -d ' + demFile + ' -s ' + source_of_NWM + ' -h ' + acquisition_time + ' -i incidence_angle.h5' print cmdTrop os.system(cmdTrop) # subprocess.Popen(cmdTrop).wait() timeseriesFile = timeseriesFile.split( '.')[0] + '_' + source_of_NWM + '.h5' else: print 'Atmospheric correction method not recognized.' else: print 'No atmospheric delay correction.' print '' print '******************************************' ############################################## #topographic residuals ############################################## print '******************************************' print '' try: template['pysar.topo_error'] if template['pysar.topo_error'] in ('yes', 'Yes', 'YES', 'y'): print 'Correcting topographic residuals' topoCmd = 'dem_error.py ' + timeseriesFile + ' ' + igramFile print topoCmd os.system(topoCmd) timeseriesFile = timeseriesFile.split('.')[0] + '_demCor.h5' else: print 'No correction for topographic residuals.' except: print 'No correction for topographic residuals.' print '' print '******************************************' ############################################## #Orbit correction ############################################## print '******************************************' print '' try: template['pysar.orbit_error'] if template['pysar.orbit_error'] in ('yes', 'Yes', 'YES', 'y'): try: orbit_error_method = template['pysar.orbit_error.method'] print 'orbit error correction method : ' + orbit_error_method if orbit_error_method in [ 'quadratic', 'plane', 'quardatic_range', 'quadratic_azimiuth', 'plane_range', 'plane_azimuth' ]: orbitCmd = 'remove_plane.py ' + timeseriesFile + ' ' + template[ 'pysar.orbit_error.method'] #+ ' Mask.h5' timeseriesFile = timeseriesFile.split('.')[ 0] + '_' + template['pysar.orbit_error.method'] + '.h5' print orbitCmd os.system(orbitCmd) elif orbit_error_method == 'baselineCor': orbitCmd = 'baseline_error.py ' + timeseriesFile #+ ' Mask.h5' print orbitCmd try: h5file = h5py.File(timeseriesFile, 'r') daz = float( h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE']) os.system(orbitCmd) timeseriesFile = timeseriesFile.split( '.')[0] + '_' + template[ 'pysar.orbit_error.method'] + '.h5' except: print 'WARNING!' print 'Skipping orbital error correction.' print 'baselineCor method can only be applied in radar coordinate' elif orbit_error_method == 'BaseTropCor': demfile = template['pysar.dem'] demfile = check_variable_name(demfile) try: polyOrder = template['pysar.trop.polyOrder'] except: print 'Deafult polynomial order for troposphreic correction = 1' polyOrder = 1 try: h5file = h5py.File(timeseriesFile, 'r') daz = float( h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE']) orbitCmd = 'baseline_trop.py ' + timeseriesFile + ' ' + demfile + ' ' + polyOrder + 'range_and_azimuth' print 'Joint estimation of Baseline error and tropospheric delay [height-correlation approach]' print orbitCmd os.system(orbitCmd) timeseriesFile = timeseriesFile.split( '.')[0] + '_' + template[ 'pysar.orbit_error.method'] + '.h5' except: print 'WARNING!' print 'Skipping orbital error correction.' print 'baselineCor method can only be applied in radar coordinate' else: print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++' print 'WARNING!' print 'Orbital error correction method was not recognized!' print 'Possible options are:' print 'quadratic, plane, quardatic_range, quadratic_azimiuth, plane_range, plane_azimuth,baselineCor,BaseTropCor' print 'Continue without orbital errors correction...' print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++' except: print 'No orbital errors correction.' else: print 'No orbital errors correction.' except: print 'No orbital errors correction.' print '' print '******************************************' ############################################# #Velocity and rmse maps ############################################# print '******************************************' print '' velCmd = 'timeseries2velocity.py ' + timeseriesFile print velCmd os.system(velCmd) print '' print '******************************************' ############################################# #Masking the velocity based on the temporal #coherence or rmse if it's specified ############################################# print '******************************************' print '' try: template['pysar.mask'] if template['pysar.mask'] in ('yes', 'Yes', 'YES', 'y'): try: template['pysar.mask.threshold'] maskCmd = 'masking.py -f velocity.h5 -m temporal_coherence.h5 -t ' + template[ 'pysar.mask.threshold'] print 'Masking the velocity file using the temporal coherence with the threshold of ' + template[ 'pysar.mask.threshold'] except: maskCmd = 'Masking.py -f velocity.h5 -m temporal_coherence.h5 -t 0.7' print 'Masking the velocity file using the temporal coherence with the threshold of 0.7' os.system(maskCmd) # rmCmd='rm velocity.h5' # os.system(rmCmd) # mvCmd='mv velocity_masked.h5 velocity.h5' # os.system(mvCmd) else: print 'No masking applied' except: print 'No masking applied' print '' print '******************************************' ############################################ #Geocoding ############################################ print '******************************************' print '' try: template['pysar.geocode'] if template['pysar.geocode'] in ('y', 'yes', 'Yes', 'YES'): geomapFile = 'geomap_' + Rlooks + 'rlks.trans' # geoCmd = 'geocode.py '+timeseriesFile+' '+geomapFile # print geoCmd # os.system(geoCmd) geoCmd = 'geocode.py velocity.h5 ' + geomapFile print geoCmd os.system(geoCmd) geoCmd = 'geocode.py Mask.h5 ' + geomapFile print geoCmd os.system(geoCmd) # maskCmd = 'Masking.py -f geo_'+timeseriesFile+' -m geo_Mask.h5' # print maskCmd # os.system(maskCmd) maskCmd = 'masking.py -f geo_velocity.h5 -m geo_Mask.h5' print maskCmd os.system(maskCmd) else: print 'No geocoding applied' except: print 'No geocoding applied' print '' print '******************************************' ############################################# # PySAR v1.0 # ############################################# print '' print '###############################################' print '' print 'End of PySAR processing.' print '' print '################################################'
def main(argv): try: templateFile = argv[1] except: Usage();sys.exit(1) projectName = os.path.basename(templateFile.partition('.')[0]) try: tssarProjectDir = os.getenv('TSSARDIR') +'/'+projectName except: tssarProjectDir = os.getenv('SCRATCHDIR') + '/' + projectName + "/TSSAR" # FA 7/2015: adopted for new directory structure print "QQ " + tssarProjectDir if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir) os.chdir(tssarProjectDir) igramFile = 'LoadedData.h5' Modified_igramFile = 'Modified_LoadedData.h5' if os.path.isfile(Modified_igramFile): print Modified_igramFile + ' already exists.' igramFile=Modified_igramFile template = readfile.read_template(templateFile) Rlooks = template['Rlooks_unw'] ######################################### # Loading interferograms ######################################### print '******************************************' print'' if os.path.isfile(igramFile): print igramFile + ' already exists.' else: loadCmd='load_data.py ' + templateFile print loadCmd os.system(loadCmd) # copyDemCmd='copy_dem_trans.py ' + templateFile # print copyDemCmd # os.system(copyDemCmd) print'' print '******************************************' ######################################### # Check the subset ######################################### try: subset= template['pysar.subset.yx'].split(',') print subset print subset[0] subsetOutName='subset_'+igramFile subsetCmd='subset.py -f '+ igramFile + ' -y '+subset[0]+' -x '+subset[1] + ' -o ' + subsetOutName print '*****************************************' print 'Subset the area ...' print subsetCmd os.system(subsetCmd) igramFile=subsetOutName print '*****************************************' except: print '*****************************************' print 'No Subset selected. Processing the whole area' print '*****************************************' ######################################### #Referencing all interferograms to the same pixel ######################################### rdr_or_geo=radar_Or_geo(igramFile) print '******************************************' print'' if os.path.isfile('Seeded_'+igramFile): igramFile = 'Seeded_'+igramFile print igramFile + ' already exists.' else: print 'referncing all interferograms to the same pixel.' if 'pysar.seed.ll' in template.keys(): 'Checking the lat/lon refernce point' lat= template['pysar.seed.ll'].split(',')[0] lon= template['pysar.seed.ll'].split(',')[1] seedCmd= 'SeedData.py -f ' + igramFile + ' -l ' +lat+ ' -L '+lon elif 'pysar.seed.yx' in template.keys(): 'Checking y/x reference point' y= template['pysar.seed.yx'].split(',')[0] x= template['pysar.seed.yx'].split(',')[1] seedCmd= 'seed_data.py -f ' + igramFile + ' -y ' +y+ ' -x '+x else: seedCmd= 'seed_data.py -f ' + igramFile igramFile = 'Seeded_'+igramFile print seedCmd os.system(seedCmd) print'' print '******************************************' ############################################ #unwrapping error correction based on the # consistency of triplets of interferograms ############################################ print '******************************************' print'' try: template['pysar.unwrap_error'] if template['pysar.unwrap_error'] in ('y','yes','Yes','YES'): print 'unwrapping error correction might take a while depending on the size of your data set! ' unwCmd='unwrap_error.py '+igramFile os.system(unwCmd) igramFile=igramFile.split('.')[0]+'_unwCor.h5' else: print 'No unwrapping error correction.' except: print 'No unwrapping error correction.' print'' print '******************************************' ######################################### # inversion of interferograms ######################################## print '******************************************' print'' if os.path.isfile(igramFile.split('.')[0]+'_unwCor.h5'): igramFile = igramFile.split('.')[0]+'_unwCor.h5' print igramFile + ' exists.' if os.path.isfile('timeseries.h5'): print 'timeseries.h5 already exists, inversion is not needed.' else: invertCmd = 'igram_inversion.py '+ igramFile print invertCmd os.system(invertCmd) timeseriesFile='timeseries.h5' print'' print '******************************************' ############################################## #temporal coherence: #A parameter to evaluate the consistency of # timeseries with the interferograms ############################################## print '******************************************' print'' # if os.path.isfile('temporal_coherence.h5'): # print 'temporal_coherence.h5 already exists.' # else: # tempcohCmd='temporal_coherence.py '+igramFile+' '+timeseriesFile # print tempcohCmd # os.system(tempcohCmd) tempcohCmd='temporal_coherence.py '+igramFile+' '+timeseriesFile print tempcohCmd os.system(tempcohCmd) print'' print '******************************************' ############################################## #update Mask based on temporal coherence # add by Yunjun Feb 15, 2015 ############################################## print '******************************************' print'' try: template['pysar.mask'] if template['pysar.mask'] in ('yes','Yes','YES','y'): print 'Updating mask according to temporal coherence' cohT=template['pysar.mask.threshold'] maskCmd='generate_mask.py -f temporal_coherence.h5 -m '+ cohT +' -M 1.0 -o Mask.h5' print maskCmd os.system(maskCmd) else: print 'No update for mask.' except: print 'No update for mask.' print'' print '******************************************' ############################################## # Generate incident angle # add by Yunjun Feb 15, 2015 ############################################## print '******************************************' print'' inciCmd='incidence_angle.py -f timeseries.h5' print inciCmd os.system(inciCmd) print'' print '******************************************' ############################################## #If Satellite is Envisat and if Coordinate #system is radar then LOD correction ############################################## print '******************************************' print'' h5file=h5py.File(timeseriesFile,'r') if rdr_or_geo =='radar': if h5file['timeseries'].attrs['PLATFORM']=='ENVISAT': LODcmd='lod.py '+timeseriesFile print LODcmd os.system(LODcmd) timeseriesFile=timeseriesFile.split('.')[0]+'_LODcor.h5' print'' print '******************************************' ############################################## # Tropospheric Correction ############################################## print '******************************************' print'' try: if (template['pysar.tropospheric_delay'] in ('y','yes','Yes','YES')) and template['pysar.orbit_error.method']=='BaseTropCor': print ''' +++++++++++++++++++++++++++++++++++++++++++++++++++ WARNING: Orbital error correction was BaseTropCor. Tropospheric correction was already applied simultaneous with baseline error correction. Tropospheric correction can not be applied again. To apply the tropospheric correction separate from baseline error correction, chhose other existing options for orbital error correction. +++++++++++++++++++++++++++++++++++++++++++++++++++ ''' template['pysar.tropospheric_delay']='no' except: print 'Checking the tropospheric delay correction ...' if template['pysar.tropospheric_delay'] in ('y','yes','Yes','YES'): # demFile='radar_'+Rlooks+'rlks.hgt' demFile=template['pysar.dem'] demFile=check_variable_name(demFile) # print 'DEM file: '+demFile if not os.path.isfile(demFile): print '++++++++++++++++++++++++++++++++++++++++++++++' print 'Error:' print 'DEM (radar_*rlks.hgt file) was not found!' print 'Continue without tropospheric correction ...' print '++++++++++++++++++++++++++++++++++++++++++++++' else: if template['pysar.tropospheric_delay.method'] in ['height-correlation','height_correlation','Height-Correlation','Height_Correlation']: print 'tropospheric delay correction with height-correlation approach' try: polyOrder=template['pysar.trop.polyOrder'] except: print 'Deafult polynomial order for troposphreic correction = 1' polyOrder='1' cmdTrop='tropospheric_correction.py'+ ' -f '+ timeseriesFile + ' -d '+ demfile + ' -p '+ polyOrder os.system(cmdTrop) timeseriesFile=timeseriesFile.split('.')[0]+'_tropCor.h5' elif template['pysar.tropospheric_delay.method']=='pyaps': print 'Atmospheric correction using Numerical Weather Models (using PyAPS software)' print 'reading DEM, source of NWM and acquisition time from template file' source_of_NWM=template['pysar.Numerical_Weather_Model'] print 'Numerical Weather Model: '+source_of_NWM acquisition_time=template['pysar.acquisition_time'] print 'acquisition time: '+acquisition_time # cmdTrop = ["tropcor_pyaps.py -f ",timeseriesFile," -d ",demFile," -s ",source_of_NWM," -h ",acquisition_time," -i incidence_angle.h5"] cmdTrop = 'tropcor_pyaps.py -f '+timeseriesFile+ ' -d '+ demFile +' -s ' + source_of_NWM + ' -h '+ acquisition_time + ' -i incidence_angle.h5' print cmdTrop os.system(cmdTrop) # subprocess.Popen(cmdTrop).wait() timeseriesFile=timeseriesFile.split('.')[0]+'_'+source_of_NWM+'.h5' else: print 'Atmospheric correction method not recognized.' else: print 'No atmospheric delay correction.' print'' print '******************************************' ############################################## #topographic residuals ############################################## print '******************************************' print'' try: template['pysar.topo_error'] if template['pysar.topo_error'] in ('yes','Yes','YES','y'): print 'Correcting topographic residuals' topoCmd='dem_error.py '+ timeseriesFile +' '+ igramFile print topoCmd os.system(topoCmd) timeseriesFile=timeseriesFile.split('.')[0]+'_demCor.h5' else: print 'No correction for topographic residuals.' except: print 'No correction for topographic residuals.' print'' print '******************************************' ############################################## #Orbit correction ############################################## print '******************************************' print'' try: template['pysar.orbit_error'] if template['pysar.orbit_error'] in ('yes','Yes','YES','y'): try: orbit_error_method=template['pysar.orbit_error.method'] print 'orbit error correction method : '+orbit_error_method if orbit_error_method in ['quadratic', 'plane', 'quardatic_range', 'quadratic_azimiuth', 'plane_range', 'plane_azimuth']: orbitCmd='remove_plane.py '+timeseriesFile+' '+template['pysar.orbit_error.method'] #+ ' Mask.h5' timeseriesFile=timeseriesFile.split('.')[0]+'_'+template['pysar.orbit_error.method']+'.h5' print orbitCmd os.system(orbitCmd) elif orbit_error_method == 'baselineCor': orbitCmd='baseline_error.py ' +timeseriesFile #+ ' Mask.h5' print orbitCmd try: h5file=h5py.File(timeseriesFile,'r') daz=float(h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE']) os.system(orbitCmd) timeseriesFile=timeseriesFile.split('.')[0]+'_'+template['pysar.orbit_error.method']+'.h5' except: print 'WARNING!' print 'Skipping orbital error correction.' print 'baselineCor method can only be applied in radar coordinate' elif orbit_error_method =='BaseTropCor': demfile=template['pysar.dem'] demfile=check_variable_name(demfile) try: polyOrder=template['pysar.trop.polyOrder'] except: print 'Deafult polynomial order for troposphreic correction = 1' polyOrder=1 try: h5file=h5py.File(timeseriesFile,'r') daz=float(h5file['timeseries'].attrs['AZIMUTH_PIXEL_SIZE']) orbitCmd='baseline_trop.py '+timeseriesFile+' '+ demfile +' '+ polyOrder +'range_and_azimuth' print 'Joint estimation of Baseline error and tropospheric delay [height-correlation approach]' print orbitCmd os.system(orbitCmd) timeseriesFile=timeseriesFile.split('.')[0]+'_'+template['pysar.orbit_error.method']+'.h5' except: print 'WARNING!' print 'Skipping orbital error correction.' print 'baselineCor method can only be applied in radar coordinate' else: print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++' print 'WARNING!' print 'Orbital error correction method was not recognized!' print 'Possible options are:' print 'quadratic, plane, quardatic_range, quadratic_azimiuth, plane_range, plane_azimuth,baselineCor,BaseTropCor' print 'Continue without orbital errors correction...' print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++' except: print 'No orbital errors correction.' else: print 'No orbital errors correction.' except: print 'No orbital errors correction.' print'' print '******************************************' ############################################# #Velocity and rmse maps ############################################# print '******************************************' print'' velCmd='timeseries2velocity.py '+timeseriesFile print velCmd os.system(velCmd) print'' print '******************************************' ############################################# #Masking the velocity based on the temporal #coherence or rmse if it's specified ############################################# print '******************************************' print'' try: template['pysar.mask'] if template['pysar.mask'] in ('yes','Yes','YES','y'): try: template['pysar.mask.threshold'] maskCmd='masking.py -f velocity.h5 -m temporal_coherence.h5 -t '+template['pysar.mask.threshold'] print 'Masking the velocity file using the temporal coherence with the threshold of '+template['pysar.mask.threshold'] except: maskCmd='Masking.py -f velocity.h5 -m temporal_coherence.h5 -t 0.7' print 'Masking the velocity file using the temporal coherence with the threshold of 0.7' os.system(maskCmd) # rmCmd='rm velocity.h5' # os.system(rmCmd) # mvCmd='mv velocity_masked.h5 velocity.h5' # os.system(mvCmd) else: print 'No masking applied' except: print 'No masking applied' print'' print '******************************************' ############################################ #Geocoding ############################################ print '******************************************' print'' try: template['pysar.geocode'] if template['pysar.geocode'] in ('y','yes','Yes','YES'): geomapFile='geomap_'+Rlooks+'rlks.trans' # geoCmd = 'geocode.py '+timeseriesFile+' '+geomapFile # print geoCmd # os.system(geoCmd) geoCmd = 'geocode.py velocity.h5 '+geomapFile print geoCmd os.system(geoCmd) geoCmd = 'geocode.py Mask.h5 '+geomapFile print geoCmd os.system(geoCmd) # maskCmd = 'Masking.py -f geo_'+timeseriesFile+' -m geo_Mask.h5' # print maskCmd # os.system(maskCmd) maskCmd = 'masking.py -f geo_velocity.h5 -m geo_Mask.h5' print maskCmd os.system(maskCmd) else: print 'No geocoding applied' except: print 'No geocoding applied' print'' print '******************************************' ############################################# # PySAR v1.0 # ############################################# print'' print '###############################################' print '' print 'End of PySAR processing.' print '' print '################################################'
def main(argv): try: templateFile = argv[1] except: Usage() sys.exit(1) from pysar._pysar_utilities import check_variable_name templateContents = readfile.read_template(templateFile) projectName = os.path.basename(templateFile).partition(".")[0] try: processProjectDir = argv[2] tssarProjectDir = argv[3] except: if os.getenv("PARENTDIR"): processProjectDir = os.getenv("SCRATCHDIR") + "/" + projectName + "/PROCESS" tssarProjectDir = os.getenv("SCRATCHDIR") + "/" + projectName + "/TSSAR" else: processProjectDir = os.getenv("PROCESSDIR") + "/" + projectName tssarProjectDir = os.getenv("TSSARDIR") + "/" + projectName print "\n*************** Loading Data into PySAR ****************" print "PROCESS directory: " + processProjectDir print "TSSAR directory: " + tssarProjectDir if not os.path.isdir(tssarProjectDir): os.mkdir(tssarProjectDir) ########### Use defaults if paths not given in template file ######### import h5py import numpy as np optionName = {} optionName["interferograms"] = "pysar.inputFiles" optionName["coherence"] = "pysar.corFiles" optionName["wrapped"] = "pysar.wrappedFiles" optionName["geomap"] = "pysar.geomap" optionName["demGeo"] = "pysar.dem.geoCoord" optionName["demRdr"] = "pysar.dem.radarCoord" try: igramPath = templateContents["pysar.inputFiles"] igramPath = check_variable_name(igramPath) except: igramPath = processProjectDir + "/DONE/IFGRAM*/filt_*.unw" print "Path pattern for unwrapped interferogram: " + igramPath # except: igramPath = os.getenv('SCRATCHDIR') + '/' + projectName + '/PROCESS/DONE/IFGRAM*/filt_*.unw' try: corPath = templateContents["pysar.corFiles"] corPath = check_variable_name(corPath) except: corPath = processProjectDir + "/DONE/IFGRAM*/filt_*rlks.cor" print "Path pattern for coherence: " + corPath try: wrapPath = templateContents["pysar.wrappedFiles"] wrapPath = check_variable_name(wrapPath) except: wrapPath = processProjectDir + "/DONE/IFGRAM*/filt_*rlks.int" print "Path pattern for wrapped interferogram: " + wrapPath # try: demRdrPath = templateContents['pysar.dem.radarCoord']; demRdrPath = check_variable_name(demRdrPath) # except: # demRdrList=glob.glob(demRdrPath) ########################################################################### ######################### Unwrapped Interferograms ######################## try: if os.path.isfile(tssarProjectDir + "/LoadedData.h5"): print "\nLoadedData.h5" + " already exists." sys.exit(1) igramList = glob.glob(igramPath) igramList = sorted(igramList) k = "interferograms" check_number(k, optionName[k], igramList) # number check print "loading interferograms ..." igramList, mode_width, mode_length = check_size(k, igramList) # size check igramList = sorted(igramList) h5file = tssarProjectDir + "/LoadedData.h5" f = h5py.File(h5file, "w") gg = f.create_group("interferograms") MaskZero = np.ones([int(mode_length), int(mode_width)]) for igram in igramList: if not os.path.basename(igram) in f: print "Adding " + igram group = gg.create_group(os.path.basename(igram)) amp, unw, unwrsc = readfile.read_float32(igram) MaskZero *= amp dset = group.create_dataset(os.path.basename(igram), data=unw, compression="gzip") for key, value in unwrsc.iteritems(): group.attrs[key] = value d1, d2 = unwrsc["DATE12"].split("-") baseline_file = os.path.dirname(igram) + "/" + d1 + "_" + d2 + "_baseline.rsc" baseline = readfile.read_roipac_rsc(baseline_file) for key, value in baseline.iteritems(): group.attrs[key] = value group.attrs["PROJECT_NAME"] = projectName group.attrs["UNIT"] = "radian" else: print os.path.basename(h5file) + " already contains " + os.path.basename(igram) Mask = np.ones([int(mode_length), int(mode_width)]) Mask[MaskZero == 0] = 0 # gm = f.create_group('mask') # dset = gm.create_dataset('mask', data=Mask, compression='gzip') f.close() ############## Mask file ############### print "writing to Mask.h5\n" # Mask=np.ones([int(mode_length),int(mode_width)]) # Mask[MaskZero==0]=0 h5file = tssarProjectDir + "/Mask.h5" h5mask = h5py.File(h5file, "w") group = h5mask.create_group("mask") dset = group.create_dataset(os.path.basename("mask"), data=Mask, compression="gzip") for key, value in unwrsc.iteritems(): group.attrs[key] = value h5mask.close() except: print "No unwrapped interferogram is loaded.\n" ######################################################################## ############################# Coherence ################################ try: if os.path.isfile(tssarProjectDir + "/Coherence.h5"): print "\nCoherence.h5" + " already exists." sys.exit(1) corList = glob.glob(corPath) corList = sorted(corList) k = "coherence" check_number(k, optionName[k], corList) # number check print "loading coherence files ..." corList, mode_width, mode_length = check_size(k, corList) # size check corList = sorted(corList) h5file = tssarProjectDir + "/Coherence.h5" fcor = h5py.File(h5file, "w") gg = fcor.create_group("coherence") meanCoherence = np.zeros([int(mode_length), int(mode_width)]) for cor in corList: if not os.path.basename(cor) in fcor: print "Adding " + cor group = gg.create_group(os.path.basename(cor)) amp, unw, unwrsc = readfile.read_float32(cor) meanCoherence += unw dset = group.create_dataset(os.path.basename(cor), data=unw, compression="gzip") for key, value in unwrsc.iteritems(): group.attrs[key] = value d1, d2 = unwrsc["DATE12"].split("-") baseline_file = os.path.dirname(cor) + "/" + d1 + "_" + d2 + "_baseline.rsc" baseline = readfile.read_roipac_rsc(baseline_file) for key, value in baseline.iteritems(): group.attrs[key] = value group.attrs["PROJECT_NAME"] = projectName group.attrs["UNIT"] = "1" else: print os.path.basename(h5file) + " already contains " + os.path.basename(cor) # fcor.close() ########### mean coherence file ############### meanCoherence = meanCoherence / (len(corList)) print "writing meanCoherence group to the coherence h5 file" gc = fcor.create_group("meanCoherence") dset = gc.create_dataset("meanCoherence", data=meanCoherence, compression="gzip") print "writing average_spatial_coherence.h5\n" h5file_CorMean = tssarProjectDir + "/average_spatial_coherence.h5" fcor_mean = h5py.File(h5file_CorMean, "w") group = fcor_mean.create_group("mask") dset = group.create_dataset(os.path.basename("mask"), data=meanCoherence, compression="gzip") for key, value in unwrsc.iteritems(): group.attrs[key] = value fcor_mean.close() fcor.close() except: print "No correlation file is loaded.\n" ############################################################################## ########################## Wrapped Interferograms ############################ try: if os.path.isfile(tssarProjectDir + "/Wrapped.h5"): print "\nWrapped.h5" + " already exists." sys.exit(1) wrapList = glob.glob(wrapPath) wrapList = sorted(wrapList) k = "wrapped" check_number(k, optionName[k], wrapList) # number check print "loading wrapped phase ..." wrapList, mode_width, mode_length = check_size(k, wrapList) # size check wrapList = sorted(wrapList) h5file = tssarProjectDir + "/Wrapped.h5" fw = h5py.File(h5file, "w") gg = fw.create_group("wrapped") for wrap in wrapList: if not os.path.basename(wrap) in fw: print "Adding " + wrap group = gg.create_group(os.path.basename(wrap)) amp, unw, unwrsc = readfile.read_complex_float32(wrap) dset = group.create_dataset(os.path.basename(wrap), data=unw, compression="gzip") for key, value in unwrsc.iteritems(): group.attrs[key] = value d1, d2 = unwrsc["DATE12"].split("-") baseline_file = os.path.dirname(wrap) + "/" + d1 + "_" + d2 + "_baseline.rsc" baseline = readfile.read_roipac_rsc(baseline_file) for key, value in baseline.iteritems(): group.attrs[key] = value group.attrs["PROJECT_NAME"] = projectName group.attrs["UNIT"] = "radian" else: print os.path.basename(h5file) + " already contains " + os.path.basename(wrap) fw.close() print "Writed " + str(len(wrapList)) + " wrapped interferograms to " + h5file + "\n" except: print "No wrapped interferogram is loaded.\n" ############################################################################## ################################# geomap.trans ############################### try: geomapPath = tssarProjectDir + "/geomap*.trans" geomapList = glob.glob(geomapPath) if len(geomapList) > 0: print "\ngeomap*.trans" + " already exists." sys.exit(1) geomapPath = templateContents["pysar.geomap"] geomapPath = check_variable_name(geomapPath) geomapList = glob.glob(geomapPath) cpCmd = "cp " + geomapList[0] + " " + tssarProjectDir print cpCmd os.system(cpCmd) cpCmd = "cp " + geomapList[0] + ".rsc " + tssarProjectDir print cpCmd + "\n" os.system(cpCmd) except: # print "*********************************" print "no geomap file is loaded.\n" # print "*********************************\n" ############################################################################## ################################## DEM ##################################### try: demRdrPath = tssarProjectDir + "/radar*.hgt" demRdrList = glob.glob(demRdrPath) if len(demRdrList) > 0: print "\nradar*.hgt" + " already exists." sys.exit(1) demRdrPath = templateContents["pysar.dem.radarCoord"] demRdrPath = check_variable_name(demRdrPath) demRdrList = glob.glob(demRdrPath) cpCmd = "cp " + demRdrList[0] + " " + tssarProjectDir print cpCmd os.system(cpCmd) cpCmd = "cp " + demRdrList[0] + ".rsc " + tssarProjectDir print cpCmd + "\n" os.system(cpCmd) except: # print "*********************************" print "no DEM (radar coordinate) file is loaded.\n" # print "*********************************" try: demGeoPath = tssarProjectDir + "/*.dem" demGeoList = glob.glob(demGeoPath) if len(demGeoList) > 0: print "\n*.dem" + " already exists." sys.exit(1) demGeoPath = templateContents["pysar.dem.geoCoord"] demGeoPath = check_variable_name(demGeoPath) demGeoList = glob.glob(demGeoPath) cpCmd = "cp " + demGeoList[0] + " " + tssarProjectDir print cpCmd os.system(cpCmd) cpCmd = "cp " + demGeoList[0] + ".rsc " + tssarProjectDir print cpCmd + "\n" os.system(cpCmd) except: # print "*********************************" print "no DEM (geo coordinate) file is loaded.\n"