def generate_temporal_coherence_mask(self): """Generate reliable pixel mask from temporal coherence""" geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] tcoh_file = 'temporalCoherence.h5' mask_file = 'maskTempCoh.h5' tcoh_min = self.template['mintpy.networkInversion.minTempCoh'] scp_args = '{} -m {} -o {} --shadow {}'.format(tcoh_file, tcoh_min, mask_file, geom_file) print('generate_mask.py', scp_args) # update mode: run only if: # 1) output file exists and newer than input file, AND # 2) all config keys are the same config_keys = ['mintpy.networkInversion.minTempCoh'] print('update mode: ON') flag = 'skip' if ut.run_or_skip(out_file=mask_file, in_file=tcoh_file, print_msg=False) == 'run': flag = 'run' else: print( '1) output file: {} already exists and newer than input file: {}' .format(mask_file, tcoh_file)) atr = readfile.read_attribute(mask_file) if any( str(self.template[i]) != atr.get(i, 'False') for i in config_keys): flag = 'run' print( '2) NOT all key configration parameters are the same: {}'. format(config_keys)) else: print('2) all key configuration parameters are the same: {}'. format(config_keys)) print('run or skip: {}'.format(flag)) if flag == 'run': mintpy.generate_mask.main(scp_args.split()) # update configKeys atr = {} for key in config_keys: atr[key] = self.template[key] ut.add_attribute(mask_file, atr) # check number of pixels selected in mask file for following analysis num_pixel = np.sum(readfile.read(mask_file)[0] != 0.) print('number of reliable pixels: {}'.format(num_pixel)) min_num_pixel = float( self.template['mintpy.networkInversion.minNumPixel']) if num_pixel < min_num_pixel: msg = "Not enough reliable pixels (minimum of {}). ".format( int(min_num_pixel)) msg += "Try the following:\n" msg += "1) Check the reference pixel and make sure it's not in areas with unwrapping errors\n" msg += "2) Check the network and make sure it's fully connected without subsets" raise RuntimeError(msg) return
def run_unwrap_error_correction(self, step_name): """Correct phase-unwrapping errors""" method = self.template['mintpy.unwrapError.method'] if not method: print('phase-unwrapping error correction is OFF.') return # check required input files stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] mask_file = 'maskConnComp.h5' scp_args_bridge = '{} -t {} --update'.format(stack_file, self.templateFile) scp_args_closure = '{} {} -t {} --update'.format(stack_file, mask_file, self.templateFile) from mintpy import unwrap_error_bridging, unwrap_error_phase_closure if method == 'bridging': unwrap_error_bridging.main(scp_args_bridge.split()) elif method == 'phase_closure': unwrap_error_phase_closure.main(scp_args_closure.split()) elif method == 'bridging+phase_closure': scp_args_bridge += ' -i unwrapPhase -o unwrapPhase_bridging' unwrap_error_bridging.main(scp_args_bridge.split()) scp_args_closure += ' -i unwrapPhase_bridging -o unwrapPhase_bridging_phaseClosure' unwrap_error_phase_closure.main(scp_args_closure.split()) else: raise ValueError('un-recognized method: {}'.format(method)) return
def run_network_modification(self, step_name): """Modify network of interferograms before the network inversion.""" # check the existence of ifgramStack.h5 stack_file, geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1:3] coh_txt = '{}_coherence_spatialAvg.txt'.format(os.path.splitext(os.path.basename(stack_file))[0]) try: net_fig = [i for i in ['Network.pdf', 'pic/Network.pdf'] if os.path.isfile(i)][0] except: net_fig = None # 1) output waterMask.h5 to simplify the detection/use of waterMask water_mask_file = 'waterMask.h5' if 'waterMask' in readfile.get_dataset_list(geom_file): print('generate {} from {} for conveniency'.format(water_mask_file, geom_file)) if ut.run_or_skip(out_file=water_mask_file, in_file=geom_file) == 'run': water_mask, atr = readfile.read(geom_file, datasetName='waterMask') atr['FILE_TYPE'] = 'waterMask' writefile.write(water_mask, out_file=water_mask_file, metadata=atr) # 2) modify network scp_args = '{} -t {}'.format(stack_file, self.templateFile) print('modify_network.py', scp_args) mintpy.modify_network.main(scp_args.split()) # 3) plot network scp_args = '{} -t {} --nodisplay'.format(stack_file, self.templateFile) print('\nplot_network.py', scp_args) if ut.run_or_skip(out_file=net_fig, in_file=[stack_file, coh_txt, self.templateFile], check_readable=False) == 'run': mintpy.plot_network.main(scp_args.split()) # 4) aux files: maskConnComp and avgSpatialCoh self.generate_ifgram_aux_file() return
def run_geocode(self, step_name): """geocode data files in radar coordinates into ./geo folder.""" if self.template['mintpy.geocode']: ts_file = self.get_timeseries_filename(self.template)[step_name]['input'] atr = readfile.read_attribute(ts_file) if 'Y_FIRST' not in atr.keys(): # 1. geocode out_dir = os.path.join(self.workDir, 'geo') if not os.path.isdir(out_dir): os.makedirs(out_dir) print('create directory:', out_dir) geom_file, lookup_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2:4] in_files = [geom_file, 'temporalCoherence.h5', ts_file, 'velocity.h5'] scp_args = '-l {l} -t {t} --outdir {o} --update '.format(l=lookup_file, t=self.templateFile, o=out_dir) for in_file in in_files: scp_args += ' {}'.format(in_file) print('geocode.py', scp_args) mintpy.geocode.main(scp_args.split()) # 2. generate reliable pixel mask in geo coordinate geom_file = os.path.join(out_dir, 'geo_{}'.format(os.path.basename(geom_file))) tcoh_file = os.path.join(out_dir, 'geo_temporalCoherence.h5') mask_file = os.path.join(out_dir, 'geo_maskTempCoh.h5') tcoh_min = self.template['mintpy.networkInversion.minTempCoh'] scp_args = '{} -m {} -o {} --shadow {}'.format(tcoh_file, tcoh_min, mask_file, geom_file) print('generate_mask.py', scp_args) if ut.run_or_skip(out_file=mask_file, in_file=tcoh_file) == 'run': mintpy.generate_mask.main(scp_args.split()) else: print('geocoding is OFF') return
def run_unwrap_error_correction(self, step_name): """Correct phase-unwrapping errors""" method = self.template['mintpy.unwrapError.method'] if not method: print('phase-unwrapping error correction is OFF.') return # check required input files stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] mask_file = 'maskConnComp.h5' scp_args_bridge = '{} -t {} --update'.format(stack_file, self.templateFile) scp_args_closure = '{} {} -t {} --update'.format( stack_file, mask_file, self.templateFile) from mintpy import unwrap_error_bridging, unwrap_error_phase_closure if method == 'bridging': unwrap_error_bridging.main(scp_args_bridge.split()) elif method == 'phase_closure': unwrap_error_phase_closure.main(scp_args_closure.split()) elif method == 'bridging+phase_closure': scp_args_bridge += ' -i unwrapPhase -o unwrapPhase_bridging' unwrap_error_bridging.main(scp_args_bridge.split()) scp_args_closure += ' -i unwrapPhase_bridging -o unwrapPhase_bridging_phaseClosure' unwrap_error_phase_closure.main(scp_args_closure.split()) else: raise ValueError('un-recognized method: {}'.format(method)) return
def run_network_modification(self, step_name): """Modify network of interferograms before the network inversion.""" # check the existence of ifgramStack.h5 stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] coh_txt = '{}_coherence_spatialAvg.txt'.format( os.path.splitext(os.path.basename(stack_file))[0]) try: net_fig = [ i for i in ['Network.pdf', 'pic/Network.pdf'] if os.path.isfile(i) ][0] except: net_fig = None # 1) modify network scp_args = '{} -t {}'.format(stack_file, self.templateFile) print('modify_network.py', scp_args) mintpy.modify_network.main(scp_args.split()) # 2) plot network scp_args = '{} -t {} --nodisplay'.format(stack_file, self.templateFile) print('\nplot_network.py', scp_args) if ut.run_or_skip(out_file=net_fig, in_file=[stack_file, coh_txt, self.templateFile], check_readable=False) == 'run': mintpy.plot_network.main(scp_args.split()) # 3) aux files: maskConnComp and avgSpatialCoh self.generate_ifgram_aux_file() return
def run_network_modification(self, step_name): """Modify network of interferograms before the network inversion.""" # check the existence of ifgramStack.h5 stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] coh_txt = '{}_coherence_spatialAvg.txt'.format(os.path.splitext(os.path.basename(stack_file))[0]) try: net_fig = [i for i in ['Network.pdf', 'pic/Network.pdf'] if os.path.isfile(i)][0] except: net_fig = None # 1) modify network scp_args = '{} -t {}'.format(stack_file, self.templateFile) print('modify_network.py', scp_args) mintpy.modify_network.main(scp_args.split()) # 2) plot network scp_args = '{} -t {} --nodisplay'.format(stack_file, self.templateFile) print('\nplot_network.py', scp_args) if ut.run_or_skip(out_file=net_fig, in_file=[stack_file, coh_txt, self.templateFile], check_readable=False) == 'run': mintpy.plot_network.main(scp_args.split()) # 3) aux files: maskConnComp and avgSpatialCoh self.generate_ifgram_aux_file() return
def run_ifgram_stacking(self, step_name): """Traditional interferograms stacking.""" # check the existence of ifgramStack.h5 stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] pha_vel_file = 'avgPhaseVelocity.h5' scp_args = '{} --dataset unwrapPhase -o {} --update'.format(stack_file, pha_vel_file) print('temporal_average.py', scp_args) mintpy.temporal_average.main(scp_args.split()) 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 scp_args = '--template {}'.format(self.templateFile) if self.customTemplateFile: scp_args += ' {}'.format(self.customTemplateFile) if self.projectName: scp_args += ' --project {}'.format(self.projectName) # run print("load_data.py", scp_args) mintpy.load_data.main(scp_args.split()) 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] # 3.1) output waterMask.h5 water_mask_file = 'waterMask.h5' if 'waterMask' in readfile.get_dataset_list(geom_file): print('generate {} from {} for conveniency'.format(water_mask_file, geom_file)) if ut.run_or_skip(out_file=water_mask_file, in_file=geom_file) == 'run': water_mask, atr = readfile.read(geom_file, datasetName='waterMask') atr['FILE_TYPE'] = 'waterMask' writefile.write(water_mask, out_file=water_mask_file, metadata=atr) # 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
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 # 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('\nload_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
def run_reference_point(self, step_name): """Select reference point. It 1) generate mask file from common conn comp 2) generate average spatial coherence and its mask 3) add REF_X/Y and/or REF_LAT/LON attribute to stack file """ stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] coh_file = 'avgSpatialCoh.h5' scp_args = '{} -t {} -c {}'.format(stack_file, self.templateFile, coh_file) print('reference_point.py', scp_args) mintpy.reference_point.main(scp_args.split()) return
def run_network_modification(self, step_name, plot=True): """Modify network of interferograms before the network inversion.""" # check the existence of ifgramStack.h5 stack_file, geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1:3] coh_txt = 'coherenceSpatialAvg.txt' try: net_fig = [i for i in ['network.pdf', 'pic/network.pdf'] if os.path.isfile(i)][0] except: net_fig = None # 1) output waterMask.h5 to simplify the detection/use of waterMask water_mask_file = 'waterMask.h5' if 'waterMask' in readfile.get_dataset_list(geom_file): print('generate {} from {} for conveniency'.format(water_mask_file, geom_file)) if ut.run_or_skip(out_file=water_mask_file, in_file=geom_file) == 'run': water_mask, atr = readfile.read(geom_file, datasetName='waterMask') # ignore no-data pixels in geometry files ds_name_list = readfile.get_dataset_list(geom_file) for ds_name in ['latitude','longitude']: if ds_name in ds_name_list: print('set pixels with 0 in {} to 0 in waterMask'.format(ds_name)) ds = readfile.read(geom_file, datasetName=ds_name)[0] water_mask[ds == 0] = 0 atr['FILE_TYPE'] = 'waterMask' writefile.write(water_mask, out_file=water_mask_file, metadata=atr) # 2) modify network iargs = [stack_file, '-t', self.templateFile] print('\nmodify_network.py', ' '.join(iargs)) mintpy.modify_network.main(iargs) # 3) plot network iargs = [stack_file, '-t', self.templateFile, '--nodisplay'] dsNames = readfile.get_dataset_list(stack_file) if any('phase' in i.lower() for i in dsNames): iargs += ['-d', 'coherence', '-v', '0.2', '1.0'] elif any('offset' in i.lower() for i in dsNames): iargs += ['-d', 'offsetSNR', '-v', '0', '20'] print('\nplot_network.py', ' '.join(iargs)) # run if self.template['mintpy.plot'] and plot: if ut.run_or_skip(out_file=net_fig, in_file=[stack_file, coh_txt, self.templateFile], check_readable=False) == 'run': mintpy.plot_network.main(iargs) else: print('mintpy.plot is turned OFF, skip plotting network.') return
def run_network_modification(self, step_name, plot=True): """Modify network of interferograms before the network inversion.""" # check the existence of ifgramStack.h5 stack_file, geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1:3] coh_txt = '{}_coherence_spatialAvg.txt'.format(os.path.splitext(os.path.basename(stack_file))[0]) try: net_fig = [i for i in ['Network.pdf', 'pic/Network.pdf'] if os.path.isfile(i)][0] except: net_fig = None # 1) output waterMask.h5 to simplify the detection/use of waterMask water_mask_file = 'waterMask.h5' if 'waterMask' in readfile.get_dataset_list(geom_file): print('generate {} from {} for conveniency'.format(water_mask_file, geom_file)) if ut.run_or_skip(out_file=water_mask_file, in_file=geom_file) == 'run': water_mask, atr = readfile.read(geom_file, datasetName='waterMask') # ignore no-data pixels in geometry files ds_name_list = readfile.get_dataset_list(geom_file) for ds_name in ['latitude','longitude']: if ds_name in ds_name_list: print('set pixels with 0 in {} to 0 in waterMask'.format(ds_name)) ds = readfile.read(geom_file, datasetName=ds_name)[0] water_mask[ds == 0] = 0 atr['FILE_TYPE'] = 'waterMask' writefile.write(water_mask, out_file=water_mask_file, metadata=atr) # 2) modify network scp_args = '{} -t {}'.format(stack_file, self.templateFile) print('modify_network.py', scp_args) mintpy.modify_network.main(scp_args.split()) # 3) plot network if self.template['mintpy.plot'] and plot: scp_args = '{} -t {} --nodisplay'.format(stack_file, self.templateFile) dsNames = readfile.get_dataset_list(stack_file) if any('phase' in i.lower() for i in dsNames): scp_args += ' -d coherence -v 0.2 1.0 ' elif any('offset' in i.lower() for i in dsNames): scp_args += ' -d offsetSNR -v 0 20 ' print('\nplot_network.py', scp_args) if ut.run_or_skip(out_file=net_fig, in_file=[stack_file, coh_txt, self.templateFile], check_readable=False) == 'run': mintpy.plot_network.main(scp_args.split()) # 4) aux files: maskConnComp and avgSpatialCoh self.generate_ifgram_aux_file() return
def generate_temporal_coherence_mask(self): """Generate reliable pixel mask from temporal coherence""" geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] tcoh_file = 'temporalCoherence.h5' mask_file = 'maskTempCoh.h5' tcoh_min = self.template['mintpy.networkInversion.minTempCoh'] scp_args = '{} -m {} -o {} --shadow {}'.format(tcoh_file, tcoh_min, mask_file, geom_file) print('generate_mask.py', scp_args) # update mode: run only if: # 1) output file exists and newer than input file, AND # 2) all config keys are the same config_keys = ['mintpy.networkInversion.minTempCoh'] print('update mode: ON') flag = 'skip' if ut.run_or_skip(out_file=mask_file, in_file=tcoh_file, print_msg=False) == 'run': flag = 'run' else: print('1) output file: {} already exists and newer than input file: {}'.format(mask_file, tcoh_file)) atr = readfile.read_attribute(mask_file) if any(str(self.template[i]) != atr.get(i, 'False') for i in config_keys): flag = 'run' print('2) NOT all key configration parameters are the same: {}'.format(config_keys)) else: print('2) all key configuration parameters are the same: {}'.format(config_keys)) print('run or skip: {}'.format(flag)) if flag == 'run': mintpy.generate_mask.main(scp_args.split()) # update configKeys atr = {} for key in config_keys: atr[key] = self.template[key] ut.add_attribute(mask_file, atr) # check number of pixels selected in mask file for following analysis num_pixel = np.sum(readfile.read(mask_file)[0] != 0.) print('number of reliable pixels: {}'.format(num_pixel)) min_num_pixel = float(self.template['mintpy.networkInversion.minNumPixel']) if num_pixel < min_num_pixel: msg = "Not enough reliable pixels (minimum of {}). ".format(int(min_num_pixel)) msg += "Try the following:\n" msg += "1) Check the reference pixel and make sure it's not in areas with unwrapping errors\n" msg += "2) Check the network and make sure it's fully connected without subsets" raise RuntimeError(msg) return
def generate_ifgram_aux_file(self): """Generate auxiliary files from ifgramStack file""" stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] mask_file = 'maskConnComp.h5' coh_file = 'avgSpatialCoh.h5' # 1) generate mask file from the common connected components scp_args = '{} --nonzero -o {} --update'.format(stack_file, mask_file) print('\ngenerate_mask.py', scp_args) mintpy.generate_mask.main(scp_args.split()) # 2) generate average spatial coherence scp_args = '{} --dataset coherence -o {} --update'.format(stack_file, coh_file) print('\ntemporal_average.py', scp_args) mintpy.temporal_average.main(scp_args.split()) return
def run_network_inversion(self, step_name): """Invert network of interferograms for raw phase time-series. 1) network inversion --> timeseries.h5, temporalCoherence.h5, numInvIfgram.h5 2) temporalCoherence.h5 --> maskTempCoh.h5 """ # check the existence of ifgramStack.h5 stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] # 1) invert ifgramStack for time-series scp_args = '{} -t {} --update '.format(stack_file, self.templateFile) print('ifgram_inversion.py', scp_args) mintpy.ifgram_inversion.main(scp_args.split()) # 2) get reliable pixel mask: maskTempCoh.h5 self.generate_temporal_coherence_mask() return
def run_topographic_residual_correction(self, step_name): """step - correct_topography Topographic residual (DEM error) correction (optional). """ geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] fnames = self.get_timeseries_filename(self.template)[step_name] in_file = fnames['input'] out_file = fnames['output'] if in_file != out_file: scp_args = '{f} -g {g} -t {t} -o {o} --update '.format( f=in_file, g=geom_file, t=self.templateFile, o=out_file) print('dem_error.py', scp_args) mintpy.dem_error.main(scp_args.split()) else: print('No topographic residual correction.') return
def run_reference_point(self, step_name): """Select reference point. It 1) generate mask file from common conn comp 2) generate average spatial coherence and its mask 3) add REF_X/Y and/or REF_LAT/LON attribute to stack file """ # 1-2) aux files: maskConnComp and avgSpatialCoh self.generate_ifgram_aux_file() # 3) add REF_X/Y(/LAT/LON) of the reference point stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] coh_file = 'avgSpatialCoh.h5' iargs = [stack_file, '-t', self.templateFile, '-c', coh_file] print('reference_point.py', ' '.join(iargs)) mintpy.reference_point.main(iargs) return
def generate_ifgram_aux_file(self): """Generate auxiliary files from ifgramStack file, including: """ stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] cc_mask_file = 'maskConnComp.h5' coh_file = 'avgSpatialCoh.h5' # 1) generate mask file from the common connected components scp_args = '{} --nonzero -o {} --update'.format(stack_file, cc_mask_file) print('\ngenerate_mask.py', scp_args) mintpy.generate_mask.main(scp_args.split()) # 2) generate average spatial coherence scp_args = '{} --dataset coherence -o {} --update'.format(stack_file, coh_file) print('\ntemporal_average.py', scp_args) mintpy.temporal_average.main(scp_args.split()) return
def run_topographic_residual_correction(self, step_name): """step - correct_topography Topographic residual (DEM error) correction (optional). """ geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] fnames = self.get_timeseries_filename(self.template)[step_name] in_file = fnames['input'] out_file = fnames['output'] if in_file != out_file: scp_args = '{f} -g {g} -t {t} -o {o} --update '.format(f=in_file, g=geom_file, t=self.templateFile, o=out_file) print('dem_error.py', scp_args) mintpy.dem_error.main(scp_args.split()) else: print('No topographic residual correction.') return
def run_save2hdfeos5(self, step_name): """Save displacement time-series and its aux data in geo coordinate into HDF-EOS5 format""" if self.template['mintpy.save.hdfEos5'] is True: # input ts_file = self.get_timeseries_filename( self.template)[step_name]['input'] # Add attributes from custom template to timeseries file if self.customTemplate is not None: ut.add_attribute(ts_file, self.customTemplate) tcoh_file = 'temporalCoherence.h5' mask_file = 'geo_maskTempCoh.h5' geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] if 'geo' in ts_file: tcoh_file = './geo/geo_temporalCoherence.h5' mask_file = './geo/geo_maskTempCoh.h5' geom_file = './geo/geo_{}'.format(os.path.basename(geom_file)) # cmd print('--------------------------------------------') scp_args = '{f} -c {c} -m {m} -g {g} -t {t}'.format( f=ts_file, c=tcoh_file, m=mask_file, g=geom_file, t=self.templateFile) print('save_hdfeos5.py', scp_args) # output (check existing file) atr = readfile.read_attribute(ts_file) SAT = sensor.get_unavco_mission_name(atr) try: hdfeos5_file = get_file_list('{}_*.he5'.format(SAT))[0] except: hdfeos5_file = None if ut.run_or_skip( out_file=hdfeos5_file, in_file=[ts_file, tcoh_file, mask_file, geom_file]) == 'run': mintpy.save_hdfeos5.main(scp_args.split()) else: print('save time-series to HDF-EOS5 format is OFF.') return
def run_local_oscillator_drift_correction(self, step_name): """Correct local oscillator drift (LOD). Automatically applied for Envisat data. Automatically skipped for all the other data. """ geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] fnames = self.get_timeseries_filename(self.template)[step_name] in_file = fnames['input'] out_file = fnames['output'] if in_file != out_file: scp_args = '{} {} -o {}'.format(in_file, geom_file, out_file) print('local_oscilator_drift.py', scp_args) if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run': mintpy.local_oscilator_drift.main(scp_args.split()) else: atr = readfile.read_attribute(in_file) sat = atr.get('PLATFORM', None) print('No local oscillator drift correction is needed for {}.'.format(sat)) return
def run_topographic_residual_correction(self, step_name): """step - correct_topography Topographic residual (DEM error) correction (optional). """ geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] fnames = self.get_timeseries_filename(self.template)[step_name] in_file = fnames['input'] out_file = fnames['output'] if in_file != out_file: iargs = [in_file, '-t', self.templateFile, '-o', out_file, '--update'] if self.template['mintpy.topographicResidual.pixelwiseGeometry']: iargs += ['-g', geom_file] print('dem_error.py', ' '.join(iargs)) mintpy.dem_error.main(iargs) else: print('No topographic residual correction.') return
def run_quick_overview(self, step_name): """A quick overview on the interferogram stack for: 1) avgPhaseVelocity.h5: possible ground deformation through interferogram stacking 2) numNonzeroIntClosure.h5: phase unwrapping errors through the integer ambiguity of phase closure """ # check the existence of ifgramStack.h5 stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] # 1) stack interferograms pha_vel_file = 'avgPhaseVelocity.h5' scp_args = '{} --dataset unwrapPhase -o {} --update'.format(stack_file, pha_vel_file) print('temporal_average.py', scp_args) mintpy.temporal_average.main(scp_args.split()) # 2) calculate the integer ambiguity of closure phase water_mask_file = 'waterMask.h5' scp_args = '{} --water-mask {} --action calculate --update'.format(stack_file, water_mask_file) print('unwrap_error_phase_closure.py', scp_args) mintpy.unwrap_error_phase_closure.main(scp_args.split()) return
def run_quick_overview(self, step_name): """A quick overview on the interferogram stack for: 1) avgPhaseVelocity.h5: possible ground deformation through interferogram stacking 2) numTriNonzeroIntAmbiguity.h5: phase unwrapping errors through the integer ambiguity of phase closure """ # check the existence of ifgramStack.h5 stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] # 1) stack interferograms pha_vel_file = 'avgPhaseVelocity.h5' iargs = [stack_file, '--dataset', 'unwrapPhase', '-o', pha_vel_file, '--update'] print('temporal_average.py', ' '.join(iargs)) mintpy.temporal_average.main(iargs) # 2) calculate the number of interferogram triplets with non-zero integer ambiguity water_mask_file = 'waterMask.h5' iargs = [stack_file, '--water-mask', water_mask_file, '--action', 'calculate', '--update'] print('unwrap_error_phase_closure.py', ' '.join(iargs)) mintpy.unwrap_error_phase_closure.main(iargs) return
def generate_ifgram_aux_file(self): """Generate auxiliary files from ifgramStack file""" stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] dsNames = readfile.get_dataset_list(stack_file) mask_file = 'maskConnComp.h5' coh_file = 'avgSpatialCoh.h5' snr_file = 'avgSpatialSnr.h5' # 1) generate mask file from the common connected components if any('phase' in i.lower() for i in dsNames): scp_args = '{} --nonzero -o {} --update'.format(stack_file, mask_file) print('\ngenerate_mask.py', scp_args) mintpy.generate_mask.main(scp_args.split()) # 2) generate average spatial coherence if any('phase' in i.lower() for i in dsNames): scp_args = '{} --dataset coherence -o {} --update'.format(stack_file, coh_file) elif any('offset' in i.lower() for i in dsNames): scp_args = '{} --dataset offsetSNR -o {} --update'.format(stack_file, snr_file) print('\ntemporal_average.py', scp_args) mintpy.temporal_average.main(scp_args.split()) return
def run_geocode(self, step_name): """geocode data files in radar coordinates into ./geo folder.""" if self.template['mintpy.geocode']: ts_file = self.get_timeseries_filename(self.template)[step_name]['input'] atr = readfile.read_attribute(ts_file) if 'Y_FIRST' not in atr.keys(): # 1. geocode out_dir = os.path.join(self.workDir, 'geo') os.makedirs(out_dir, exist_ok=True) geom_file, lookup_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2:4] in_files = [geom_file, 'temporalCoherence.h5', 'avgSpatialCoh.h5', ts_file, 'velocity.h5'] iargs = ['-l', lookup_file, '-t', self.templateFile, '--outdir', out_dir, '--update'] for in_file in in_files: iargs += [in_file] print('geocode.py', ' '.join(iargs)) mintpy.geocode.main(iargs) # 2. generate reliable pixel mask in geo coordinate geom_file = os.path.join(out_dir, 'geo_{}'.format(os.path.basename(geom_file))) tcoh_file = os.path.join(out_dir, 'geo_temporalCoherence.h5') mask_file = os.path.join(out_dir, 'geo_maskTempCoh.h5') tcoh_min = self.template['mintpy.networkInversion.minTempCoh'] iargs = [tcoh_file, '-m', tcoh_min, '-o', mask_file] # exclude pixels in shadow if shadowMask dataset is available if (self.template['mintpy.networkInversion.shadowMask'] is True and 'shadowMask' in readfile.get_dataset_list(geom_file)): iargs += ['--base', geom_file, '--base-dataset', 'shadowMask', '--base-value', '1'] print('generate_mask.py', ' '.join(iargs)) if ut.run_or_skip(out_file=mask_file, in_file=tcoh_file) == 'run': mintpy.generate_mask.main(iargs) else: print('dataset is geocoded, skip geocoding and continue.') else: print('geocoding is OFF') return
def run_save2hdfeos5(self, step_name): """Save displacement time-series and its aux data in geo coordinate into HDF-EOS5 format""" if self.template['mintpy.save.hdfEos5'] is True: # input ts_file = self.get_timeseries_filename(self.template)[step_name]['input'] # Add attributes from custom template to timeseries file if self.customTemplate is not None: ut.add_attribute(ts_file, self.customTemplate) tcoh_file = 'temporalCoherence.h5' mask_file = 'geo_maskTempCoh.h5' geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] if 'geo' in ts_file: tcoh_file = './geo/geo_temporalCoherence.h5' mask_file = './geo/geo_maskTempCoh.h5' geom_file = './geo/geo_{}'.format(os.path.basename(geom_file)) # cmd print('--------------------------------------------') scp_args = '{f} -c {c} -m {m} -g {g} -t {t}'.format(f=ts_file, c=tcoh_file, m=mask_file, g=geom_file, t=self.templateFile) print('save_hdfeos5.py', scp_args) # output (check existing file) atr = readfile.read_attribute(ts_file) SAT = sensor.get_unavco_mission_name(atr) try: hdfeos5_file = get_file_list('{}_*.he5'.format(SAT))[0] except: hdfeos5_file = None if ut.run_or_skip(out_file=hdfeos5_file, in_file=[ts_file, tcoh_file, mask_file, geom_file]) == 'run': mintpy.save_hdfeos5.main(scp_args.split()) else: print('save time-series to HDF-EOS5 format is OFF.') return
def run_unwrap_error_correction(self, step_name): """Correct phase-unwrapping errors""" method = self.template['mintpy.unwrapError.method'] if not method: print('phase-unwrapping error correction is OFF.') return # check required input files stack_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1] mask_file = 'maskConnComp.h5' iargs_bridge = [stack_file, '--template', self.templateFile, '--update'] iargs_closure = iargs_bridge + ['--cc-mask', mask_file] if method == 'bridging': print('unwrap_error_bridging.py', ' '.join(iargs_bridge)) mintpy.unwrap_error_bridging.main(iargs_bridge) elif method == 'phase_closure': print('unwrap_error_phase_closure.py', ' '.join(iargs_closure)) mintpy.unwrap_error_phase_closure.main(iargs_closure) elif method == 'bridging+phase_closure': iargs_bridge += ['-i', 'unwrapPhase', '-o', 'unwrapPhase_bridging'] print('unwrap_error_bridging.py', ' '.join(iargs_bridge)) mintpy.unwrap_error_bridging.main(iargs_bridge) iargs_closure += ['-i', 'unwrapPhase_bridging', '-o', 'unwrapPhase_bridging_phaseClosure'] print('unwrap_error_phase_closure.py', ' '.join(iargs_closure)) mintpy.unwrap_error_phase_closure.main(iargs_closure) else: raise ValueError('un-recognized method: {}'.format(method)) return
def run_tropospheric_delay_correction(self, step_name): """Correct tropospheric delays.""" geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] mask_file = 'maskTempCoh.h5' fnames = self.get_timeseries_filename(self.template)[step_name] in_file = fnames['input'] out_file = fnames['output'] if in_file != out_file: poly_order = self.template['mintpy.troposphericDelay.polyOrder'] tropo_model = self.template[ 'mintpy.troposphericDelay.weatherModel'] weather_dir = self.template['mintpy.troposphericDelay.weatherDir'] method = self.template['mintpy.troposphericDelay.method'] def get_dataset_size(fname): atr = readfile.read_attribute(fname) return (atr['LENGTH'], atr['WIDTH']) # Phase/Elevation Ratio (Doin et al., 2009) if method == 'height_correlation': tropo_look = self.template['mintpy.troposphericDelay.looks'] tropo_min_cor = self.template[ 'mintpy.troposphericDelay.minCorrelation'] scp_args = '{f} -g {g} -p {p} -m {m} -o {o} -l {l} -t {t}'.format( f=in_file, g=geom_file, p=poly_order, m=mask_file, o=out_file, l=tropo_look, t=tropo_min_cor) print( 'tropospheric delay correction with height-correlation approach' ) print('tropo_phase_elevation.py', scp_args) if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run': mintpy.tropo_phase_elevation.main(scp_args.split()) # Weather Re-analysis Data (Jolivet et al., 2011;2014) elif method == 'pyaps': scp_args = '-f {f} --model {m} -g {g} -w {w}'.format( f=in_file, m=tropo_model, g=geom_file, w=weather_dir) print( 'Atmospheric correction using Weather Re-analysis dataset (PyAPS, Jolivet et al., 2011)' ) print('Weather Re-analysis dataset:', tropo_model) tropo_file = './inputs/{}.h5'.format(tropo_model) if ut.run_or_skip(out_file=out_file, in_file=[in_file, tropo_file]) == 'run': if os.path.isfile(tropo_file) and get_dataset_size( tropo_file) == get_dataset_size(in_file): scp_args = '{f} {t} -o {o} --force'.format( f=in_file, t=tropo_file, o=out_file) print('--------------------------------------------') print('Use existed tropospheric delay file: {}'.format( tropo_file)) print('diff.py', scp_args) mintpy.diff.main(scp_args.split()) else: if tropo_model in ['ERA5']: cmd = 'tropo_pyaps3.py' + ' ' + scp_args print(cmd) status = subprocess.Popen(cmd, shell=True).wait() # from mintpy import tropo_pyaps3#tropo_pyaps3 # print('tropo_pyaps3.py', scp_args) #print('tropo_pyaps3.py', scp_args) # tropo_pyaps3.main(scp_args.split()) #tropo_pyaps3.main(scp_args.split()) else: # opt 1 - using tropo_pyaps as python module and call its main function # prefered, disabled for now to make it compatible with python2-pyaps #print('tropo_pyaps.py', scp_args) #from mintpy import tropo_pyaps #tropo_pyaps.main(scp_args.split()) # opt 2 - using tropo_pyaps as executable script # will be deprecated after python3-pyaps is fully funcational cmd = 'tropo_pyaps.py ' + scp_args print(cmd) status = subprocess.Popen(cmd, shell=True).wait() else: print('No tropospheric delay correction.') return
def run_tropospheric_delay_correction(self, step_name): """Correct tropospheric delays.""" geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] mask_file = 'maskTempCoh.h5' fnames = self.get_timeseries_filename(self.template)[step_name] in_file = fnames['input'] out_file = fnames['output'] if in_file != out_file: poly_order = self.template['mintpy.troposphericDelay.polyOrder'] tropo_model = self.template['mintpy.troposphericDelay.weatherModel'] weather_dir = self.template['mintpy.troposphericDelay.weatherDir'] method = self.template['mintpy.troposphericDelay.method'] def get_dataset_size(fname): atr = readfile.read_attribute(fname) return (atr['LENGTH'], atr['WIDTH']) # Phase/Elevation Ratio (Doin et al., 2009) if method == 'height_correlation': tropo_look = self.template['mintpy.troposphericDelay.looks'] tropo_min_cor = self.template['mintpy.troposphericDelay.minCorrelation'] iargs = [in_file, '-g', geom_file, '-p', poly_order, '-m', mask_file, '-o', out_file, '-l', tropo_look, '-t', tropo_min_cor] print('tropospheric delay correction with height-correlation approach') print('\ntropo_phase_elevation.py', ' '.join(iargs)) if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run': mintpy.tropo_phase_elevation.main(iargs) # Weather re-analysis data with iterative tropospheric decomposition (GACOS) # Yu et al., 2017; 2018a; 2018b elif method == 'gacos': GACOS_dir = self.template['mintpy.troposphericDelay.gacosDir'] iargs = ['-f', in_file, '-g', geom_file, '-o', out_file, '--dir', GACOS_dir] print('tropospheric delay correction with gacos approach') print('\ntropo_gacos.py', ' '.join(iargs)) if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run': mintpy.tropo_gacos.main(iargs) # Weather Re-analysis Data (Jolivet et al., 2011;2014) elif method == 'pyaps': iargs = ['-f', in_file, '--model', tropo_model, '-g', geom_file, '-w', weather_dir] print('Atmospheric correction using Weather Re-analysis dataset (PyAPS, Jolivet et al., 2011)') print('Weather Re-analysis dataset:', tropo_model) tropo_file = './inputs/{}.h5'.format(tropo_model) if ut.run_or_skip(out_file=out_file, in_file=[in_file, tropo_file]) == 'run': if os.path.isfile(tropo_file) and get_dataset_size(tropo_file) == get_dataset_size(in_file): iargs = [in_file, tropo_file, '-o', out_file, '--force'] print('--------------------------------------------') print('Use existed tropospheric delay file: {}'.format(tropo_file)) print('\ndiff.py', ' '.join(iargs)) mintpy.diff.main(iargs) else: if tropo_model in ['ERA5']: from mintpy import tropo_pyaps3 print('\ntropo_pyaps3.py', ' '.join(iargs)) tropo_pyaps3.main(iargs) else: # opt 1 - using tropo_pyaps as python module and call its main function # prefered, disabled for now to make it compatible with python2-pyaps #print('tropo_pyaps.py', ' '.join(iargs)) #from mintpy import tropo_pyaps #tropo_pyaps.main(iargs) # opt 2 - using tropo_pyaps as executable script # will be deprecated after python3-pyaps is fully funcational cmd = 'tropo_pyaps.py '+' '.join(iargs) print(cmd) status = subprocess.Popen(cmd, shell=True).wait() else: print('No tropospheric delay correction.') return
def main(iargs=None): inps = cmd_line_parse(iargs) dateStr = datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d:%H%M%S') if not iargs is None: msg = os.path.basename(__file__) + ' ' + ' '.join(iargs[:]) string = dateStr + " * " + msg print(string) else: msg = os.path.basename(__file__) + ' ' + ' '.join(sys.argv[1::]) string = dateStr + " * " + msg print(string) work_dir = os.path.dirname(inps.outdir) #os.chdir(work_dir) # read input options inpsDict = read_inps2dict(inps) prepare_metadata(inpsDict) inpsDict = read_subset_box(inpsDict) extraDict = get_extra_metadata(inpsDict) if not 'PLATFORM' in extraDict: slcStack = os.path.join(os.path.dirname(work_dir), 'inputs/slcStack.h5') atr = readfile.read_attribute(slcStack) if 'PLATFORM' in atr: extraDict['PLATFORM'] = atr['PLATFORM'] # initiate objects inpsDict['ds_name2key'] = datasetName2templateKey stackObj = mld.read_inps_dict2ifgram_stack_dict_object(inpsDict) # prepare wirte updateMode, comp, box, boxGeo = print_write_setting(inpsDict) box = None boxGeo = None if stackObj and not os.path.isdir(inps.outdir): os.makedirs(inps.outdir) print('create directory: {}'.format(inps.outdir)) # write if stackObj and mld.update_object(inps.outfile[0], stackObj, box, updateMode=updateMode, xstep=inpsDict['xstep'], ystep=inpsDict['ystep']): print('-' * 50) stackObj.write2hdf5(outputFile=inps.outfile[0], access_mode='w', box=box, compression=comp, extra_metadata=extraDict) geo_files = ['geometryRadar.h5', 'geometryGeo.h5'] copy_file = False for geometry_file_2 in geo_files: geometry_file = os.path.join(os.path.dirname(work_dir), 'inputs', geometry_file_2) if os.path.exists(geometry_file): copy_file = True break if copy_file: if not os.path.exists( os.path.join(work_dir, 'inputs/{}'.format(geometry_file_2))): shutil.copyfile( geometry_file, os.path.join(work_dir, 'inputs/{}'.format(geometry_file_2))) else: geomRadarObj, geomGeoObj = mld.read_inps_dict2geometry_dict_object( inpsDict) if geomRadarObj and mld.update_object(inps.outfile[1], geomRadarObj, box, updateMode=updateMode, xstep=inpsDict['xstep'], ystep=inpsDict['ystep']): print('-' * 50) geomRadarObj.write2hdf5(outputFile=inps.outfile[1], access_mode='w', box=box, xstep=inpsDict['xstep'], ystep=inpsDict['ystep'], compression='lzf', extra_metadata=extraDict) if geomGeoObj and mld.update_object(inps.outfile[2], geomGeoObj, boxGeo, updateMode=updateMode, xstep=inpsDict['xstep'], ystep=inpsDict['ystep']): print('-' * 50) geomGeoObj.write2hdf5(outputFile=inps.outfile[2], access_mode='w', box=boxGeo, xstep=inpsDict['xstep'], ystep=inpsDict['ystep'], compression='lzf') # check loading result load_complete, stack_file, geom_file = ut.check_loaded_dataset( work_dir=work_dir, print_msg=True)[0:3] # add custom metadata (optional) customTemplate = inps.template_file[0] if customTemplate: print('updating {}, {} metadata based on custom template file: {}'. format(os.path.basename(stack_file), os.path.basename(geom_file), os.path.basename(customTemplate))) # 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, inpsDict) ut.add_attribute(geom_file, inpsDict) ut.add_attribute(stack_file, extraDict) # if not load_complete, plot and raise exception if not load_complete: # go back to original directory print('Go back to directory:', work_dir) os.chdir(work_dir) # raise error msg = 'step load_ifgram: NOT all required dataset found, exit.' raise SystemExit(msg) return inps.outfile
def main(iargs=None): """ Overwrite filtered SLC images in Isce merged/SLC directory. """ Parser = MinoPyParser(iargs, script='invert_network') inps = Parser.parse() dateStr = datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d:%H%M%S') if not iargs is None: msg = os.path.basename(__file__) + ' ' + ' '.join(iargs[:]) string = dateStr + " * " + msg print(string) else: msg = os.path.basename(__file__) + ' ' + ' '.join(sys.argv[1::]) string = dateStr + " * " + msg print(string) start_time = time.time() os.chdir(inps.work_dir) minopy_dir = os.path.dirname(inps.work_dir) if inps.template_file is None: inps.template_file = os.path.join(minopy_dir, 'smallbaselineApp.cfg') minopy_template_file = os.path.join(minopy_dir, 'minopyApp.cfg') inps.ifgramStackFile = os.path.join(inps.work_dir, 'inputs/ifgramStack.h5') template = readfile.read_template(minopy_template_file) if template['minopy.timeseries.tempCohType'] == 'auto': template['minopy.timeseries.tempCohType'] = 'full' atr = {} atr['minopy.timeseries.tempCohType'] = template[ 'minopy.timeseries.tempCohType'] ut.add_attribute(inps.ifgramStackFile, atr) # 1) invert ifgramStack for time-series stack_file = ut.check_loaded_dataset(inps.work_dir, print_msg=False)[1] #wrapped_phase_series = os.path.join(minopy_dir, 'inverted/phase_series.h5') iargs = [ stack_file, '-t', inps.template_file, '--update', '--norm', inps.residualNorm, '--tcoh', inps.temp_coh, '--mask-threshold', str(inps.maskThreshold), '--smooth_factor', inps.L1_alpha ] #, '--calc-cov'] if not inps.minNormVelocity: iargs += ['--min-norm-phase'] print('\nifgram_inversion_L1L2.py', ' '.join(iargs)) ifgram_inversion_L1L2.main(iargs) # 1) Replace temporal coherence with the one obtained from full stack inversion iargs = ['-d', inps.work_dir] if inps.shadow_mask: iargs = ['-d', inps.work_dir, '--shadow_mask'] print('\ngenerate_temporal_coherence.py', ' '.join(iargs)) generate_temporal_coherence.main(iargs) #m, s = divmod(time.time() - start_time, 60) #print('time used: {:02.0f} mins {:02.1f} secs.\n'.format(m, s)) 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': # use subprocess instead of main() here to avoid import gdal3 # which is required in prep_aria.py cmd = 'prep_aria.py --template {} --update '.format(self.templateFile) print(cmd) subprocess.Popen(cmd, shell=True).wait() else: # compose command line scp_args = '--template {}'.format(self.templateFile) if self.customTemplateFile: scp_args += ' {}'.format(self.customTemplateFile) if self.projectName: scp_args += ' --project {}'.format(self.projectName) # run command line print("load_data.py", scp_args) mintpy.load_data.main(scp_args.split()) # 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
def run_tropospheric_delay_correction(self, step_name): """Correct tropospheric delays.""" geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[2] mask_file = 'maskTempCoh.h5' fnames = self.get_timeseries_filename(self.template)[step_name] in_file = fnames['input'] out_file = fnames['output'] if in_file != out_file: poly_order = self.template['mintpy.troposphericDelay.polyOrder'] tropo_model = self.template['mintpy.troposphericDelay.weatherModel'] weather_dir = self.template['mintpy.troposphericDelay.weatherDir'] method = self.template['mintpy.troposphericDelay.method'] def get_dataset_size(fname): atr = readfile.read_attribute(fname) return (atr['LENGTH'], atr['WIDTH']) # Phase/Elevation Ratio (Doin et al., 2009) if method == 'height_correlation': tropo_look = self.template['mintpy.troposphericDelay.looks'] tropo_min_cor = self.template['mintpy.troposphericDelay.minCorrelation'] scp_args = '{f} -g {g} -p {p} -m {m} -o {o} -l {l} -t {t}'.format(f=in_file, g=geom_file, p=poly_order, m=mask_file, o=out_file, l=tropo_look, t=tropo_min_cor) print('tropospheric delay correction with height-correlation approach') print('tropo_phase_elevation.py', scp_args) if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run': mintpy.tropo_phase_elevation.main(scp_args.split()) # Weather Re-analysis Data (Jolivet et al., 2011;2014) elif method == 'pyaps': scp_args = '-f {f} --model {m} -g {g} -w {w}'.format(f=in_file, m=tropo_model, g=geom_file, w=weather_dir) print('Atmospheric correction using Weather Re-analysis dataset (PyAPS, Jolivet et al., 2011)') print('Weather Re-analysis dataset:', tropo_model) tropo_file = './inputs/{}.h5'.format(tropo_model) if ut.run_or_skip(out_file=out_file, in_file=[in_file, tropo_file]) == 'run': if os.path.isfile(tropo_file) and get_dataset_size(tropo_file) == get_dataset_size(in_file): scp_args = '{f} {t} -o {o} --force'.format(f=in_file, t=tropo_file, o=out_file) print('--------------------------------------------') print('Use existed tropospheric delay file: {}'.format(tropo_file)) print('diff.py', scp_args) mintpy.diff.main(scp_args.split()) else: if tropo_model in ['ERA5']: from mintpy import tropo_pyaps3 print('tropo_pyaps3.py', scp_args) tropo_pyaps3.main(scp_args.split()) else: # opt 1 - using tropo_pyaps as python module and call its main function # prefered, disabled for now to make it compatible with python2-pyaps #print('tropo_pyaps.py', scp_args) #from mintpy import tropo_pyaps #tropo_pyaps.main(scp_args.split()) # opt 2 - using tropo_pyaps as executable script # will be deprecated after python3-pyaps is fully funcational cmd = 'tropo_pyaps.py '+scp_args print(cmd) status = subprocess.Popen(cmd, shell=True).wait() else: print('No tropospheric delay correction.') return