def read_template_file2inps(template_file, inps=None): """Read seed/reference info from template file and update input namespace""" if not inps: inps = cmd_line_parse(['']) inps_dict = vars(inps) template = readfile.read_template(template_file) template = ut.check_template_auto_value(template) prefix = 'pysar.reference.' key_list = [i for i in list(inps_dict) if prefix + i in template.keys()] for key in key_list: value = template[prefix + key] if value: if key in ['coherenceFile', 'maskFile']: inps_dict[key] = value elif key == 'minCoherence': inps_dict[key] = float(value) key = prefix + 'yx' if key in template.keys(): value = template[key] if value: inps.ref_y, inps.ref_x = [int(i) for i in value.split(',')] key = prefix + 'lalo' if key in template.keys(): value = template[key] if value: inps.ref_lat, inps.ref_lon = [float(i) for i in value.split(',')] return inps
def read_template2inps(template_file, inps): """Read input template options into Namespace inps""" print('read input option from template file: ' + template_file) if not inps: inps = cmd_line_parse() inps_dict = vars(inps) template = readfile.read_template(template_file) template = ut.check_template_auto_value(template) prefix = 'pysar.geocode.' key_list = [i for i in list(inps_dict.keys()) if prefix + i in template.keys()] for key in key_list: value = template[prefix + key] if value: if key == 'SNWE': inps_dict[key] = tuple([float(i) for i in value.split(',')]) elif key in ['latStep', 'lonStep']: inps_dict[key] = float(value) elif key in ['interpMethod']: inps_dict[key] = value elif key == 'fillValue': if 'nan' in value.lower(): inps_dict[key] = np.nan else: inps_dict[key] = float(value) inps.laloStep = [inps.latStep, inps.lonStep] if None in inps.laloStep: inps.laloStep = None return inps
def read_inps2dict(inps): print('read options from template file: '+os.path.basename(inps.templateFile)) template = readfile.read_template(inps.templateFile) template = ut.check_template_auto_value(template) iDict = vars(inps) key_prefix = 'isce.' key_list = [i.split(key_prefix)[1] for i in template.keys() if i.startswith(key_prefix)] for key in key_list: iDict[key] = template[key_prefix+key] return iDict
def read_template2inps(templateFile, inps=None): """Update inps with options from templateFile""" if not inps: inps = cmd_line_parse() template = readfile.read_template(templateFile) template = ut.check_template_auto_value(template) key = 'pysar.reference.date' if key in template.keys() and template[key]: inps.refDate = template[key] return inps
def read_template2inps(template_file, inps=None): """Read input template options into Namespace inps""" if not inps: inps = cmd_line_parse() inpsDict = vars(inps) print('read options from template file: '+os.path.basename(template_file)) template = readfile.read_template(inps.template_file) template = ut.check_template_auto_value(template) # Update inps if key existed in template file prefix = 'pysar.network.' keyList = [i for i in list(inpsDict.keys()) if prefix+i in template.keys()] for key in keyList: value = template[prefix+key] if key in ['coherenceBased', 'keepMinSpanTree']: inpsDict[key] = value elif value: if key in ['minCoherence', 'tempBaseMax', 'perpBaseMax']: inpsDict[key] = float(value) elif key in ['connNumMax']: inpsDict[key] = int(value) elif key in ['maskFile', 'referenceFile']: inpsDict[key] = value elif key == 'aoiYX': tmp = [i.strip() for i in value.split(',')] sub_y = sorted([int(i.strip()) for i in tmp[0].split(':')]) sub_x = sorted([int(i.strip()) for i in tmp[1].split(':')]) inps.aoi_pix_box = (sub_x[0], sub_y[0], sub_x[1], sub_y[1]) elif key == 'aoiLALO': tmp = [i.strip() for i in value.split(',')] sub_lat = sorted([float(i.strip()) for i in tmp[0].split(':')]) sub_lon = sorted([float(i.strip()) for i in tmp[1].split(':')]) inps.aoi_geo_box = (sub_lon[0], sub_lat[1], sub_lon[1], sub_lat[0]) # Check lookup file if not inps.lookupFile: print('Warning: no lookup table file found! Can not use '+key+' option without it.') print('skip this option.') inps.aoi_pix_box = None elif key in ['startDate', 'endDate']: inpsDict[key] = ptime.yyyymmdd(value) elif key == 'excludeDate': inpsDict[key] = ptime.yyyymmdd(value.replace(',', ' ').split()) elif key == 'excludeIfgIndex': inpsDict[key] += value.replace(',', ' ').split() inps.excludeIfgIndex = read_input_index_list(inps.excludeIfgIndex, stackFile=inps.file) # Turn reset on if 1) no input options found to drop ifgram AND 2) there is template input if all(not i for i in [inps.referenceFile, inps.tempBaseMax, inps.perpBaseMax, inps.connNumMax, inps.excludeIfgIndex, inps.excludeDate, inps.coherenceBased, inps.startDate, inps.endDate, inps.reset, inps.manual]): print('No input option found to remove interferogram') print('Keep all interferograms by enable --reset option') inps.reset = True return inps
def read_inps2dict(inps): """Read input Namespace object info into inpsDict""" # Read input info into inpsDict inpsDict = vars(inps) inpsDict['PLATFORM'] = None # Read template file template = {} for fname in inps.template_file: temp = readfile.read_template(fname) temp = ut.check_template_auto_value(temp) template.update(temp) for key, value in template.items(): inpsDict[key] = value if 'processor' in template.keys(): template['pysar.load.processor'] = template['processor'] prefix = 'pysar.load.' key_list = [ i.split(prefix)[1] for i in template.keys() if i.startswith(prefix) ] for key in key_list: value = template[prefix + key] if key in ['processor', 'updateMode', 'compression']: inpsDict[key] = template[prefix + key] elif value: inpsDict[prefix + key] = template[prefix + key] if inpsDict['compression'] == False: inpsDict['compression'] = None # PROJECT_NAME --> PLATFORM if not inpsDict['PROJECT_NAME']: inpsDict['PROJECT_NAME'] = sensor.project_name2sensor_name( inps.template_file)[1] inpsDict['PLATFORM'] = sensor.project_name2sensor_name( inpsDict['PROJECT_NAME'])[0] if inpsDict['PLATFORM']: print('platform : {}'.format(inpsDict['PLATFORM'])) print('processor: {}'.format(inpsDict['processor'])) # Here to insert code to check default file path for miami user if (auto_path.autoPath and 'SCRATCHDIR' in os.environ and inpsDict['PROJECT_NAME'] is not None): print(('check auto path setting for Univ of Miami users' ' for processor: {}'.format(inpsDict['processor']))) inpsDict = auto_path.get_auto_path( processor=inpsDict['processor'], project_name=inpsDict['PROJECT_NAME'], template=inpsDict) return inpsDict
def read_template2inps(template_file, inps=None): """Read input template options into Namespace inps""" if not inps: inps = cmd_line_parse() inpsDict = vars(inps) print('read options from tempalte file: '+os.path.basename(inps.template_file)) template = readfile.read_template(template_file) template = ut.check_template_auto_value(template) key_list = [i for i in list(inpsDict.keys()) if key_prefix+i in template.keys()] for key in key_list: value = template[key_prefix+key] if value: if key in ['waterMaskFile']: inpsDict[key] = value return inps
def read_template2inps(templateFile, inps): """Update inps with pysar.residualRms.* option from templateFile""" if not inps: inps = cmd_line_parse() inpsDict = vars(inps) print('read options from template file: '+os.path.basename(templateFile)) template = readfile.read_template(templateFile) template = ut.check_template_auto_value(template) prefix = 'pysar.residualRms.' keyList = [i for i in list(inpsDict.keys()) if prefix+i in template.keys()] for key in keyList: value = template[prefix+key] if value: if key in ['maskFile', 'ramp']: inpsDict[key] = value elif key in ['cutoff']: inpsDict[key] = float(value) return inps
def read_template2inps(template_file, inps=None): """Read input template file into inps.excludeDate""" if not inps: inps = cmd_line_parse() inpsDict = vars(inps) print('read options from template file: '+os.path.basename(template_file)) template = readfile.read_template(inps.template_file) template = ut.check_template_auto_value(template) # Read template option keyList = [i for i in list(inpsDict.keys()) if key_prefix+i in template.keys()] for key in keyList: value = template[key_prefix+key] if key in ['phaseVelocity']: inpsDict[key] = value elif value: if key in ['polyOrder']: inpsDict[key] = int(value) elif key in ['excludeDate','stepFuncDate']: inpsDict[key] = ptime.yyyymmdd(value.replace(',', ' ').split()) return inps
def read_template2inps(template_file, inps): """Read input template options into Namespace inps""" if not inps: inps = cmd_line_parse() inpsDict = vars(inps) template = readfile.read_template(template_file) template = ut.check_template_auto_value(template) keyList = [ i for i in list(inpsDict.keys()) if key_prefix + i in template.keys() ] for key in keyList: value = template[key_prefix + key] if key in ['maskDataset']: inpsDict[key] = value elif value: if key in ['maskThreshold']: inpsDict[key] = float(value) elif key in ['weightFunc', 'residualNorm', 'waterMaskFile']: inpsDict[key] = value return inps
def read_template2inps(template_file, inps=None): """Read input template options into Namespace inps""" if not inps: inps = cmd_line_parse() inpsDict = vars(inps) print('read options from template file: ' + os.path.basename(template_file)) template = readfile.read_template(inps.template_file) template = ut.check_template_auto_value(template) # Coherence-based network modification prefix = 'pysar.network.' key = prefix + 'maskFile' if key in template.keys(): if template[key]: inps.maskFile = template[key] key = prefix + 'minCoherence' if key in template.keys(): if template[key]: inps.coh_thres = float(template[key]) return inps
def read_template2inps(templateFile, inps=None): """Read network options from template file into Namespace variable inps""" if not inps: inps = cmd_line_parse() inpsDict = vars(inps) # Read template file template = readfile.read_template(templateFile) template = ut.check_template_auto_value( template, auto_file='../defaults/selectNetwork.cfg') if not template: log('Empty template: ' + templateFile) return None prefix = 'selectNetwork.' # Check obsolete option prefix for i in ['selectPairs.', 'select.network.']: if any(i in key for key in template.keys()): msg = 'obsolete option prefix detected: {}\n'.format(i) msg += 'Use {} instead'.format(prefix) raise Exception(msg) if all(prefix not in key for key in template.keys()): msg = 'no valid input option deteced in template file!\n' msg += 'Check the template below for supported options:\n' msg += TEMPLATE raise Exception(msg) # convert template into inpsDict keyList = [ i for i in list(inpsDict.keys()) if prefix + i in template.keys() ] for key in keyList: value = template[prefix + key] # bool if key in ['keepSeasonal']: inpsDict[key] = value elif value: # str if key in ['method', 'referenceFile', 'tempPerpList']: inpsDict[key] = value # date in YYYYMMDD elif key in ['masterDate', 'startDate', 'endDate']: inpsDict[key] = ptime.yyyymmdd(value) # list of dates in YYYYMMDD elif key in ['excludeDate']: inps.excludeDate = ptime.yyyymmdd( [i.strip() for i in value.split(',')]) # float elif key in [ 'perpBaseMax', 'tempBaseMax', 'tempBaseMin', 'dopOverlapMin' ]: inpsDict[key] = float(value) # int elif key in ['connNum']: inpsDict[key] = int(value) # read tempPerpList from str if isinstance(inps.tempPerpList, str): inps.tempPerpList = [[float(j) for j in i.split(',')] for i in inps.tempPerpList.split(';')] # Initial network using input methods inps.method = inps.method.lower().replace('-', '_') if inps.method in ['star', 'ps']: inps.method = 'star' elif inps.method.startswith('seq'): inps.method = 'sequential' elif inps.method.startswith('hierar'): inps.method = 'hierarchical' elif inps.method in ['mst', 'min_spanning_tree', 'minimum_spanning_tree']: inps.method = 'mst' # for coherence prediction key = 'PLATFORM' if key in template.keys() and not inps.sensor: inps.sensor = template[key] key = 'COH_COLOR_JUMP' if key in template.keys(): inps.coh_thres = float(template[key]) # project name and sensor project_name = os.path.splitext(os.path.basename(inps.template_file))[0] log('project name: ' + project_name) if not inps.sensor: inps.sensor = sensor.project_name2sensor(project_name)[0] # Output directory/filename if not inps.outfile: if autoPath and 'SCRATCHDIR' in os.environ: inps.out_dir = os.getenv( 'SCRATCHDIR') + '/' + project_name + '/PROCESS' else: try: inps.out_dir = os.path.dirname( os.path.abspath(inps.referenceFile)) except: inps.out_dir = os.path.dirname( os.path.abspath(inps.baseline_file)) inps.outfile = inps.out_dir + '/ifgram_list.txt' # Auto path of bl_list.txt file (for Miami user) if not inps.baseline_file and autoPath and 'SCRATCHDIR' in os.environ: bl_file = os.path.join(os.getenv('SCRATCHDIR'), '{}/SLC/bl_list.txt'.format(project_name)) if os.path.isfile(bl_file): inps.baseline_file = bl_file if not inps.referenceFile and not inps.baseline_file: raise Exception( 'No baseline file or reference file found! At least one is required.' ) return inps
def read_template(inps): print('\n********** Read Template File **********') # default template inps.templateFile = os.path.join(inps.workDir, 'pysarApp_template.txt') if not os.path.isfile(inps.templateFile): print('generate default template file:', inps.templateFile) shutil.copy2(inps.autoTemplateFile, inps.workDir) else: check_obsolete_default_template(inps) # custom template customTemplate = None if inps.customTemplateFile: # Copy custom template file to work directory inputs_dir = os.path.join(inps.workDir, 'INPUTS') if ut.run_or_skip(out_file=os.path.join(inputs_dir, os.path.basename(inps.customTemplateFile)), in_file=inps.customTemplateFile, check_readable=False) == 'run': if not os.path.isdir(inputs_dir): os.makedirs(inputs_dir) print('create directory:', inputs_dir) shutil.copy2(inps.customTemplateFile, inputs_dir) print('copy {} to INPUTS directory'.format(os.path.basename(inps.customTemplateFile))) # Read custom template print('read custom template file:', inps.customTemplateFile) customTemplate = readfile.read_template(inps.customTemplateFile) # correct some loose type errors standardValues = {'def':'auto', 'default':'auto', 'y':'yes', 'on':'yes', 'true':'yes', 'n':'no', 'off':'no', 'false':'no' } for key, value in customTemplate.items(): if value in standardValues.keys(): customTemplate[key] = standardValues[value] for key in ['pysar.deramp', 'pysar.troposphericDelay.method']: if key in customTemplate.keys(): customTemplate[key] = customTemplate[key].lower().replace('-', '_') if 'processor' in customTemplate.keys(): customTemplate['pysar.load.processor'] = customTemplate['processor'] for key in ['SUBSET_XMIN', 'SUBSET_YMIN']: if key in customTemplate.keys(): customTemplate.pop(key) # Update default template with custom input template print('update default template based on input custom template') inps.templateFile = ut.update_template_file(inps.templateFile, customTemplate) if inps.generate_template: raise SystemExit('Exit as planned after template file generation.') print('read default template file:', inps.templateFile) template = readfile.read_template(inps.templateFile) template = ut.check_template_auto_value(template) # Get existing files name: unavco_attributes.txt try: inps.unavcoMetadataFile = ut.get_file_list('unavco_attribute*txt', abspath=True)[0] except: inps.unavcoMetadataFile = None print('No UNAVCO attributes file found.') return inps, template, customTemplate
def _read_template(self): # read custom template, to: # 1) update default template # 2) add metadata to ifgramStack file and HDF-EOS5 file self.customTemplate = None if self.customTemplateFile: cfile = self.customTemplateFile # Copy custom template file to INPUTS directory for backup inputs_dir = os.path.join(self.workDir, 'INPUTS') if not os.path.isdir(inputs_dir): os.makedirs(inputs_dir) print('create directory:', inputs_dir) if ut.run_or_skip(out_file=os.path.join(inputs_dir, os.path.basename(cfile)), in_file=cfile, check_readable=False) == 'run': shutil.copy2(cfile, inputs_dir) print('copy {} to INPUTS directory for backup.'.format( os.path.basename(cfile))) # Read custom template print('read custom template file:', cfile) cdict = readfile.read_template(cfile) # correct some loose type errors standardValues = { 'def': 'auto', 'default': 'auto', 'y': 'yes', 'on': 'yes', 'true': 'yes', 'n': 'no', 'off': 'no', 'false': 'no' } for key, value in cdict.items(): if value in standardValues.keys(): cdict[key] = standardValues[value] for key in ['pysar.deramp', 'pysar.troposphericDelay.method']: if key in cdict.keys(): cdict[key] = cdict[key].lower().replace('-', '_') if 'processor' in cdict.keys(): cdict['pysar.load.processor'] = cdict['processor'] # these metadata are used in load_data.py only, not needed afterwards # (in order to manually add extra offset when the lookup table is shifted) # (seen in ROI_PAC product sometimes) for key in ['SUBSET_XMIN', 'SUBSET_YMIN']: if key in cdict.keys(): cdict.pop(key) self.customTemplate = dict(cdict) # Update default template file based on custom template print('update default template based on input custom template') self.templateFile = ut.update_template_file( self.templateFile, self.customTemplate) print('read default template file:', self.templateFile) self.template = readfile.read_template(self.templateFile) self.template = ut.check_template_auto_value(self.template) # correct some loose setup conflicts if self.template['pysar.geocode'] is False: for key in ['pysar.save.hdfEos5', 'pysar.save.kmz']: if self.template[key] is True: self.template['pysar.geocode'] = True print('Turn ON pysar.geocode in order to run {}.'.format( key)) break return
def read_template(inps): print('\n********** Read Template File **********') # default template inps.templateFile = os.path.join(inps.workDir, 'pysarApp_template.txt') if not os.path.isfile(inps.templateFile): print('generate default template file: ' + inps.templateFile) with open(inps.templateFile, 'w') as f: f.write(TEMPLATE) else: inps.templateFile = check_obsolete_default_template(inps.templateFile) # custom template templateCustom = None if inps.templateFileCustom: # Copy custom template file to work directory if ut.update_file(os.path.basename(inps.templateFileCustom), inps.templateFileCustom, check_readable=False): shutil.copy2(inps.templateFileCustom, inps.workDir) print('copy {} to work directory'.format( os.path.basename(inps.templateFileCustom))) # Read custom template print('read custom template file: ' + inps.templateFileCustom) templateCustom = readfile.read_template(inps.templateFileCustom) # correct some loose type errors for key in templateCustom.keys(): if templateCustom[key].lower() in ['default']: templateCustom[key] = 'auto' elif templateCustom[key].lower() in ['n', 'off', 'false']: templateCustom[key] = 'no' elif templateCustom[key].lower() in ['y', 'on', 'true']: templateCustom[key] = 'yes' for key in ['pysar.deramp', 'pysar.troposphericDelay.method']: if key in templateCustom.keys(): templateCustom[key] = templateCustom[key].lower().replace( '-', '_') if 'processor' in templateCustom.keys(): templateCustom['pysar.load.processor'] = templateCustom[ 'processor'] # Update default template with custom input template print('update default template based on input custom template') inps.templateFile = ut.update_template_file(inps.templateFile, templateCustom) if inps.generate_template: raise SystemExit('Exit as planned after template file generation.') print('read default template file: ' + inps.templateFile) template = readfile.read_template(inps.templateFile) template = ut.check_template_auto_value(template) # Get existing files name: unavco_attributes.txt try: inps.unavcoMetadataFile = ut.get_file_list('unavco_attribute*txt', abspath=True)[0] except: inps.unavcoMetadataFile = None print('No UNAVCO attributes file found.') return inps, template, templateCustom