def prepare_metadata(iDict): processor = iDict['processor'] script_name = 'prep_{}.py'.format(processor) print('-'*50) print('prepare metadata files for {} products'.format(processor)) if processor in ['gamma', 'hyp3', 'roipac', 'snap']: # import prep_module if processor == 'gamma': from mintpy import prep_gamma as prep_module elif processor == 'hyp3': from mintpy import prep_hyp3 as prep_module elif processor == 'roipac': from mintpy import prep_roipac as prep_module elif processor == 'snap': from mintpy import prep_snap as prep_module # run prep_{processor} module for key in [i for i in iDict.keys() if (i.startswith('mintpy.load.') and i.endswith('File'))]: if len(glob.glob(str(iDict[key]))) > 0: # print command line script_name = '{}.py'.format(os.path.basename(prep_module.__name__).split('.')[-1]) iargs = [iDict[key]] if processor == 'gamma' and iDict['PLATFORM']: iargs += ['--sensor', iDict['PLATFORM'].lower()] print(script_name, ' '.join(iargs)) # run prep_module.main(iargs) elif processor == 'isce': from mintpy import prep_isce from mintpy.utils.isce_utils import get_processor # metadata meta_files = sorted(glob.glob(iDict['mintpy.load.metaFile'])) if len(meta_files) > 0: meta_file = meta_files[0] else: warnings.warn('No input metadata file found: {}'.format(iDict['mintpy.load.metaFile'])) meta_file = 'auto' # auxliary data baseline_dir = iDict['mintpy.load.baselineDir'] geom_dir = os.path.dirname(iDict['mintpy.load.demFile']) # observation obs_keys = ['mintpy.load.unwFile', 'mintpy.load.azOffFile'] obs_keys = [i for i in obs_keys if i in iDict.keys()] obs_paths = [iDict[key] for key in obs_keys if iDict[key].lower() != 'auto'] if len(obs_paths) > 0: processor = get_processor(meta_file) if processor == 'alosStack': obs_dir = os.path.dirname(obs_paths[0]) else: obs_dir = os.path.dirname(os.path.dirname(obs_paths[0])) obs_file = os.path.basename(obs_paths[0]) else: obs_dir = None obs_file = None # compose list of input arguments iargs = ['-m', meta_file, '-g', geom_dir] if baseline_dir: iargs += ['-b', baseline_dir] if obs_dir is not None: iargs += ['-d', obs_dir, '-f', obs_file] # run module print('prep_isce.py', ' '.join(iargs)) try: prep_isce.main(iargs) except: warnings.warn('prep_isce.py failed. Assuming its result exists and continue...') elif processor == 'aria': from mintpy import prep_aria ## compose input arguments # use the default template file if exists & input default_temp_files = [fname for fname in iDict['template_file'] if fname.endswith('smallbaselineApp.cfg')] if len(default_temp_files) > 0: temp_file = default_temp_files[0] else: temp_file = iDict['template_file'][0] iargs = ['--template', temp_file] # file name/dir/path ARG2OPT_DICT = { '--stack-dir' : 'mintpy.load.unwFile', '--unwrap-stack-name' : 'mintpy.load.unwFile', '--coherence-stack-name': 'mintpy.load.corFile', '--conn-comp-stack-name': 'mintpy.load.connCompFile', '--dem' : 'mintpy.load.demFile', '--incidence-angle' : 'mintpy.load.incAngleFile', '--azimuth-angle' : 'mintpy.load.azAngleFile', '--water-mask' : 'mintpy.load.waterMaskFile', } for arg_name, opt_name in ARG2OPT_DICT.items(): arg_value = iDict.get(opt_name, 'auto') if arg_value.lower() not in ['auto', 'no', 'none']: if arg_name.endswith('dir'): iargs += [arg_name, os.path.dirname(arg_value)] elif arg_name.endswith('name'): iargs += [arg_name, os.path.basename(arg_value)] else: iargs += [arg_name, arg_value] # configurations if iDict['compression']: iargs += ['--compression', iDict['compression']] if iDict['updateMode']: iargs += ['--update'] ## run print('prep_aria.py', ' '.join(iargs)) try: prep_aria.main(iargs) except: warnings.warn('prep_aria.py failed. Assuming its result exists and continue...') elif processor == 'gmtsar': from mintpy import prep_gmtsar # use the custom template file if exists & input custom_temp_files = [fname for fname in iDict['template_file'] if not fname.endswith('smallbaselineApp.cfg')] if len(custom_temp_files) == 0: raise FileExistsError('Custom template file NOT found and is required for GMTSAR!') # run prep_*.py iargs = [custom_temp_files[0], '--mintpy-dir', os.path.dirname(iDict['outdir'])] print('prep_gmtsar.py', ' '.join(iargs)) try: prep_gmtsar.main(iargs) except: warnings.warn('prep_gmtsar.py failed. Assuming its result exists and continue...') else: msg = 'un-recognized InSAR processor: {}'.format(processor) msg += '\nsupported processors: {}'.format(PROCESSOR_LIST) raise ValueError(msg) return
def run_load_data(self, step_name): """Load InSAR stacks into HDF5 files in ./inputs folder. It 1) copy auxiliary files into work directory (for Unvi of Miami only) 2) load all interferograms stack files into mintpy/inputs directory. 3) check loading result 4) add custom metadata (optional, for HDF-EOS5 format only) """ # 1) copy aux files (optional) self._copy_aux_file() # 2) loading data stack_processor = self.template['mintpy.load.processor'].lower() if stack_processor == 'aria': from mintpy import prep_aria iargs = ['--template', self.templateFile, '--update'] prep_aria.main(iargs) else: # compose list of input arguments # instead of using command line then split # to support path with whitespace iargs = ['--template', self.templateFile] if self.customTemplateFile: iargs += [self.customTemplateFile] if self.projectName: iargs += ['--project', self.projectName] # run command line print('load_data.py', ' '.join(iargs)) mintpy.load_data.main(iargs) # come back to working directory os.chdir(self.workDir) # 3) check loading result load_complete, stack_file, geom_file = ut.check_loaded_dataset(self.workDir, print_msg=True)[0:3] # 4) add custom metadata (optional) if self.customTemplateFile: print('updating {}, {} metadata based on custom template file: {}'.format( os.path.basename(stack_file), os.path.basename(geom_file), os.path.basename(self.customTemplateFile))) # use ut.add_attribute() instead of add_attribute.py because of # better control of special metadata, such as SUBSET_X/YMIN ut.add_attribute(stack_file, self.customTemplate) ut.add_attribute(geom_file, self.customTemplate) # 5) if not load_complete, plot and raise exception if not load_complete: # plot result if error occured self.plot_result(print_aux=False, plot=plot) # go back to original directory print('Go back to directory:', self.cwd) os.chdir(self.cwd) # raise error msg = 'step {}: NOT all required dataset found, exit.'.format(step_name) raise RuntimeError(msg) return