def setup_class(cls, gamma_params): # change the required params shutil.rmtree(gamma_params[cf.OUT_DIR]) # start with a clean directory shared.mkdir_p(gamma_params[cf.OUT_DIR]) cls.params = gamma_params cls.params[cf.OBS_DIR] = common.SML_TEST_GAMMA cls.params[cf.PROCESSOR] = 1 # gamma cls.params[cf.PARALLEL] = 0 cls.params[cf.REF_EST_METHOD] = 1 cls.params[cf.DEM_FILE] = common.SML_TEST_DEM_GAMMA # base_unw_paths need to be geotiffed and multilooked by run_prepifg cls.base_unw_paths = cf.original_ifg_paths( cls.params[cf.IFG_FILE_LIST], cls.params[cf.OBS_DIR]) cls.base_unw_paths.append(common.SML_TEST_DEM_GAMMA) # dest_paths are tifs that have been geotif converted and multilooked conv2tif.main(cls.params) prepifg.main(cls.params) cls.dest_paths = [ Path(cls.params[cf.OUT_DIR]).joinpath(Path( c.sampled_path).name).as_posix() for c in cls.params[cf.INTERFEROGRAM_FILES][:-2] ] cls.ifgs = [dem_or_ifg(i) for i in cls.dest_paths] for i in cls.ifgs: i.open() i.nodata_value = 0
def setup_class(cls, gamma_params): # change the required params shared.mkdir_p(gamma_params[C.OUT_DIR]) from copy import deepcopy cls.params = deepcopy(gamma_params) cls.params[WORKING_DIR] = common.GAMMA_SML_TEST_DIR cls.params[C.PROCESSOR] = 1 # gamma cls.params[C.PARALLEL] = 0 cls.params[C.REF_EST_METHOD] = 1 cls.params[C.DEM_FILE] = common.SML_TEST_DEM_GAMMA cls.params[C.BASE_FILE_LIST] = common.GAMMA_SML_TEST_DIR # base_unw_paths need to be geotiffed and multilooked by run_prepifg cls.base_unw_paths = tests.common.original_ifg_paths( cls.params[C.IFG_FILE_LIST], cls.params[WORKING_DIR]) cls.base_unw_paths.append(common.SML_TEST_DEM_GAMMA) # dest_paths are tifs that have been geotif converted and multilooked conv2tif.main(cls.params) prepifg.main(cls.params) cls.dest_paths = [ Path(cls.params[C.INTERFEROGRAM_DIR]).joinpath( Path(c.sampled_path).name).as_posix() for c in gamma_params[C.INTERFEROGRAM_FILES] ] cls.dest_paths += [ Path(cls.params[C.COHERENCE_DIR]).joinpath( Path(c.sampled_path).name).as_posix() for c in gamma_params[C.COHERENCE_FILE_PATHS] ] cls.ifgs = [dem_or_ifg(i) for i in cls.dest_paths] for i in cls.ifgs: i.open() i.nodata_value = 0
def setUpClass(cls): # read in the params _, _, params = cf.get_ifg_paths(TEST_CONF_GAMMA) glob_prefix = "*utm_unw_1rlks_1cr.tif" # SERIAL cls.serial_dir = tempfile.mkdtemp() params[cf.OUT_DIR] = cls.serial_dir params[cf.PARALLEL] = False shared.mkdir_p(cls.serial_dir) gtif_paths = conv2tif.main(params) prepifg.main(params) serial_df = glob.glob(os.path.join(cls.serial_dir, glob_prefix)) cls.serial_ifgs = small_data_setup(datafiles=serial_df) # Clean up serial converted tifs so we can test parallel conversion common.remove_tifs(SML_TEST_GAMMA) # PARALLEL cls.parallel_dir = tempfile.mkdtemp() params[cf.OUT_DIR] = cls.parallel_dir params[cf.PARALLEL] = True shared.mkdir_p(cls.parallel_dir) gtif_paths = conv2tif.main(params) prepifg.main(params) para_df = glob.glob(os.path.join(cls.parallel_dir, glob_prefix)) cls.para_ifgs = small_data_setup(datafiles=para_df)
def main(params): """ Main workflow function for preparing interferograms for PyRate. :param dict params: Parameters dictionary read in from the config file """ # TODO: looks like ifg_paths are ordered according to ifg list # This probably won't be a problem because input list won't be reordered # and the original gamma generated list is ordered) this may not affect # the important pyrate stuff anyway, but might affect gen_thumbs.py. # Going to assume ifg_paths is ordered correcly # pylint: disable=too-many-branches shared.mpi_vs_multiprocess_logging("prepifg", params) ifg_paths = params[cf.INTERFEROGRAM_FILES] if params[cf.DEM_FILE] is not None: # optional DEM conversion ifg_paths.append(params[cf.DEM_FILE_PATH]) if params[cf.COH_MASK]: ifg_paths.extend(params[cf.COHERENCE_FILE_PATHS]) shared.mkdir_p(params[cf.OUT_DIR]) # create output dir user_exts = (params[cf.IFG_XFIRST], params[cf.IFG_YFIRST], params[cf.IFG_XLAST], params[cf.IFG_YLAST]) xlooks, ylooks, crop = cf.transform_params(params) ifgs = [prepifg_helper.dem_or_ifg(p.converted_path) for p in ifg_paths] exts = prepifg_helper.get_analysis_extent(crop, ifgs, xlooks, ylooks, user_exts=user_exts) process_ifgs_paths = np.array_split(ifg_paths, mpiops.size)[mpiops.rank] do_prepifg(process_ifgs_paths, exts, params) mpiops.comm.barrier() log.info("Finished prepifg")
def __save_ifgs_dict_with_headers_and_epochs(dest_tifs, ifgs_dict, params, process_tifs): tmpdir = params[cf.TMPDIR] if not os.path.exists(tmpdir): shared.mkdir_p(tmpdir) preread_ifgs_file = Configuration.preread_ifgs(params) nifgs = len(dest_tifs) # add some extra information that's also useful later gt, md, wkt = shared.get_geotiff_header_info( process_tifs[0].tmp_sampled_path) epochlist = algorithm.get_epochs(ifgs_dict)[0] log.info('Found {} unique epochs in the {} interferogram network'.format( len(epochlist.dates), nifgs)) ifgs_dict['epochlist'] = epochlist ifgs_dict['gt'] = gt ifgs_dict['md'] = md ifgs_dict['wkt'] = wkt # dump ifgs_dict file for later use cp.dump(ifgs_dict, open(preread_ifgs_file, 'wb')) for k in ['gt', 'epochlist', 'md', 'wkt']: ifgs_dict.pop(k) return ifgs_dict
def main(params): """ Main workflow function for preparing interferograms for PyRate. :param dict params: Parameters dictionary read in from the config file """ # TODO: looks like ifg_paths are ordered according to ifg list # This probably won't be a problem because input list won't be reordered # and the original gamma generated list is ordered) this may not affect # the important pyrate stuff anyway, but might affect gen_thumbs.py. # Going to assume ifg_paths is ordered correcly # pylint: disable=too-many-branches shared.mpi_vs_multiprocess_logging("prepifg", params) ifg_paths = params[cf.INTERFEROGRAM_FILES] if params[cf.DEM_FILE] is not None: # optional DEM conversion ifg_paths.append(params[cf.DEM_FILE_PATH]) shared.mkdir_p(params[cf.OUT_DIR]) # create output dir process_ifgs_paths = np.array_split(ifg_paths, mpiops.size)[mpiops.rank] gtiff_paths = [p.converted_path for p in process_ifgs_paths] do_prepifg(gtiff_paths, params) mpiops.comm.barrier() log.info("Finished prepifg")
def setUpClass(cls): params = Configuration(TEST_CONF_ROIPAC).__dict__ cls.temp_out_dir = tempfile.mkdtemp() sys.argv = ['prepifg.py', TEST_CONF_ROIPAC] params[cf.OUT_DIR] = cls.temp_out_dir params[cf.TMPDIR] = os.path.join(cls.temp_out_dir, cf.TMPDIR) shared.mkdir_p(params[cf.TMPDIR]) params[cf.REF_EST_METHOD] = 2 conv2tif.main(params) prepifg.main(params) cls.params = params xlks, ylks, crop = cf.transform_params(params) base_ifg_paths = cf.original_ifg_paths(params[cf.IFG_FILE_LIST], params[cf.OBS_DIR]) dest_paths = cf.get_dest_paths(base_ifg_paths, crop, params, xlks) ifgs = common.pre_prepare_ifgs(dest_paths, params) refx, refy = process._ref_pixel_calc(dest_paths, params) pyrate.core.orbital.remove_orbital_error(ifgs, params) ifgs = prepare_ifgs_without_phase(dest_paths, params) for ifg in ifgs: ifg.close() _, cls.ifgs = process._ref_phase_estimation(dest_paths, params, refx, refy) ifgs[0].open() r_dist = RDist(ifgs[0])() ifgs[0].close() # Calculate interferogram noise cls.maxvar = [cvd(i, params, r_dist, calc_alpha=True, save_acg=True, write_vals=True)[0] for i in dest_paths] cls.vcmt = get_vcmt(ifgs, cls.maxvar) for ifg in ifgs: ifg.close()
def setUp(self): random_text = tempfile.mktemp() self.confFile = os.path.join(TEMPDIR, '{}/roipac_test.cfg'.format(random_text)) self.ifgListFile = os.path.join( TEMPDIR, '{}/roipac_ifg.list'.format(random_text)) self.base_dir = os.path.dirname(self.confFile) shared.mkdir_p(self.base_dir) self.hdr = SML_TEST_DEM_HDR
def process_ifgs(ifg_paths, params, rows, cols): """ Top level function to perform PyRate workflow on given interferograms :param list ifg_paths: List of interferogram paths :param dict params: Dictionary of configuration parameters :param int rows: Number of sub-tiles in y direction :param int cols: Number of sub-tiles in x direction :return: refpt: tuple of reference pixel x and y position :rtype: tuple :return: maxvar: array of maximum variance values of interferograms :rtype: ndarray :return: vcmt: Variance-covariance matrix array :rtype: ndarray """ if mpiops.size > 1: # turn of multiprocessing during mpi jobs params[cf.PARALLEL] = False outdir = params[cf.TMPDIR] if not os.path.exists(outdir): shared.mkdir_p(outdir) tiles = mpiops.run_once(get_tiles, ifg_paths[0], rows, cols) preread_ifgs = _create_ifg_dict(ifg_paths, params=params) # validate user supplied ref pixel refpixel.validate_supplied_lat_lon(params) refpx, refpy = _ref_pixel_calc(ifg_paths, params) # remove non ifg keys _ = [preread_ifgs.pop(k) for k in ['gt', 'epochlist', 'md', 'wkt']] multi_paths = params[cf.INTERFEROGRAM_FILES] _orb_fit_calc(multi_paths, params, preread_ifgs) _ref_phase_estimation(ifg_paths, params, refpx, refpy) shared.save_numpy_phase(ifg_paths, tiles, params) _mst_calc(ifg_paths, params, tiles, preread_ifgs) # spatio-temporal aps filter wrap_spatio_temporal_filter(ifg_paths, params, tiles, preread_ifgs) maxvar, vcmt = _maxvar_vcm_calc(ifg_paths, params, preread_ifgs) # save phase data tiles as numpy array for timeseries and stackrate calc shared.save_numpy_phase(ifg_paths, tiles, params) _timeseries_calc(ifg_paths, params, vcmt, tiles, preread_ifgs) _stack_calc(ifg_paths, params, vcmt, tiles, preread_ifgs) log.info('PyRate workflow completed') return (refpx, refpy), maxvar, vcmt
def independent_orbital_correction(ifg, params): """ Calculates and removes an orbital error surface from a single independent interferogram. Warning: This will write orbital error corrected phase_data to the ifg. :param Ifg class instance ifg: the interferogram to be corrected :param str degree: model to fit (PLANAR / QUADRATIC / PART_CUBIC) :param bool offset: True to calculate the model using an offset :param dict params: dictionary of configuration parameters :return: None - interferogram phase data is updated and saved to disk """ degree = params[cf.ORBITAL_FIT_DEGREE] offset = params[cf.ORBFIT_OFFSET] orbfit_correction_on_disc = MultiplePaths.orb_error_path( ifg.data_path, params) if not ifg.is_open: ifg.open() shared.nan_and_mm_convert(ifg, params) if orbfit_correction_on_disc.exists(): log.info( f'Reusing already computed orbital fit correction for {ifg.data_path}' ) orbital_correction = np.load(file=orbfit_correction_on_disc) else: # vectorise, keeping NODATA vphase = reshape(ifg.phase_data, ifg.num_cells) dm = get_design_matrix(ifg, degree, offset) # filter NaNs out before getting model clean_dm = dm[~isnan(vphase)] data = vphase[~isnan(vphase)] model = lstsq(clean_dm, data)[0] # first arg is the model params # calculate forward model & morph back to 2D if offset: fullorb = np.reshape(np.dot(dm[:, :-1], model[:-1]), ifg.phase_data.shape) else: fullorb = np.reshape(np.dot(dm, model), ifg.phase_data.shape) if not orbfit_correction_on_disc.parent.exists(): shared.mkdir_p(orbfit_correction_on_disc.parent) offset_removal = nanmedian(np.ravel(ifg.phase_data - fullorb)) orbital_correction = fullorb - offset_removal # dump to disc np.save(file=orbfit_correction_on_disc, arr=orbital_correction) # subtract orbital error from the ifg ifg.phase_data -= orbital_correction # set orbfit meta tag and save phase to file _save_orbital_error_corrected_phase(ifg) ifg.close()
def setup_method(self): self.base = join(PYRATEPATH, 'tests', 'test_data', 'gamma') self.hdr = join(self.base, 'dem16x20raw.dem.par') temp_text = tempfile.mktemp() self.confFile = os.path.join(TEMPDIR, '{}/gamma_test.cfg'.format(temp_text)) self.ifgListFile = os.path.join(TEMPDIR, '{}/gamma_ifg.list'.format(temp_text)) self.base_dir = os.path.dirname(self.confFile) shared.mkdir_p(self.base_dir)
def setup_class(cls): roipac_params = Configuration(TEST_CONF_ROIPAC).__dict__ from copy import deepcopy params = deepcopy(roipac_params) shared.mkdir_p(params[C.TMPDIR]) params[C.REF_EST_METHOD] = 2 conv2tif.main(params) params = deepcopy(roipac_params) prepifg.main(params) params = deepcopy(roipac_params) base_ifg_paths = [ c.unwrapped_path for c in params[C.INTERFEROGRAM_FILES] ] dest_paths = [c.converted_path for c in params[C.INTERFEROGRAM_FILES]] params[C.INTERFEROGRAM_FILES] = [ MultiplePaths(d, params) for d in dest_paths ] for p in params[C.INTERFEROGRAM_FILES]: # hack p.sampled_path = p.converted_path for i in dest_paths: Path(i).chmod( 0o664 ) # assign write permission as conv2tif output is readonly ifgs = common.pre_prepare_ifgs(dest_paths, params) correct._copy_mlooked(params) correct._update_params_with_tiles(params) correct._create_ifg_dict(params) pyrate.core.refpixel.ref_pixel_calc_wrapper(params) params[C.ORBFIT_OFFSET] = True pyrate.core.orbital.remove_orbital_error(ifgs, params) ifgs = prepare_ifgs_without_phase(dest_paths, params) for ifg in ifgs: ifg.close() for p in params[C.INTERFEROGRAM_FILES]: # hack p.tmp_sampled_path = p.sampled_path _, cls.ifgs = pyrate.core.ref_phs_est.ref_phase_est_wrapper(params) ifgs[0].open() r_dist = RDist(ifgs[0])() ifgs[0].close() # Calculate interferogram noise cls.maxvar = [ cvd(i, params, r_dist, calc_alpha=True, save_acg=True, write_vals=True)[0] for i in dest_paths ] cls.vcmt = get_vcmt(ifgs, cls.maxvar) for ifg in ifgs: ifg.close() cls.params = params
def verify_corrections(self, ifgs, exp, deg, offset): # checks orbital correction against unit test version params = dict() params[cf.ORBITAL_FIT_METHOD] = NETWORK_METHOD params[cf.ORBITAL_FIT_DEGREE] = deg params[cf.ORBITAL_FIT_LOOKS_X] = 1 params[cf.ORBITAL_FIT_LOOKS_Y] = 1 params[cf.PARALLEL] = False params[cf.ORBFIT_OFFSET] = offset params[cf.PREREAD_IFGS] = None params[cf.OUT_DIR] = tempfile.mkdtemp() mkdir_p(Path(params[cf.OUT_DIR]).joinpath(cf.ORB_ERROR_DIR)) network_orbital_correction(ifgs, params, self.ml_ifgs) act = [i.phase_data for i in ifgs] assert_array_almost_equal(act, exp, decimal=4)
def main(params=None): """ Main workflow function for preparing interferograms for PyRate. :param dict params: Parameters dictionary read in from the config file """ # TODO: looks like base_ifg_paths are ordered according to ifg list # This probably won't be a problem because input list won't be reordered # and the original gamma generated list is ordered) this may not affect # the important pyrate stuff anyway, but might affect gen_thumbs.py. # Going to assume base_ifg_paths is ordered correcly # pylint: disable=too-many-branches usage = 'Usage: pyrate prepifg <config_file>' if mpiops.size > 1: # Over-ride input options if this is an MPI job params[cf.PARALLEL] = False if params: base_ifg_paths = cf.original_ifg_paths(params[cf.IFG_FILE_LIST], params[cf.OBS_DIR]) else: # if params not provided read from config file if (not params) and (len(sys.argv) < 3): print(usage) return base_ifg_paths, _, params = cf.get_ifg_paths(sys.argv[2]) if params[cf.DEM_FILE] is not None: # optional DEM conversion base_ifg_paths.append(params[cf.DEM_FILE]) processor = params[cf.PROCESSOR] # roipac or gamma if processor == GAMMA: # Incidence/elevation only supported for GAMMA if params[cf.APS_INCIDENCE_MAP]: base_ifg_paths.append(params[cf.APS_INCIDENCE_MAP]) if params[cf.APS_ELEVATION_MAP]: base_ifg_paths.append(params[cf.APS_ELEVATION_MAP]) shared.mkdir_p(params[cf.OUT_DIR]) # create output dir process_base_ifgs_paths = np.array_split(base_ifg_paths, mpiops.size)[mpiops.rank] gtiff_paths = [ shared.output_tiff_filename(f, params[cf.OBS_DIR]) for f in process_base_ifgs_paths ] do_prepifg(gtiff_paths, params) log.info("Finished prepifg")
def setUpClass(cls): params = Configuration(TEST_CONF_ROIPAC).__dict__ cls.temp_out_dir = tempfile.mkdtemp() sys.argv = ['prepifg.py', TEST_CONF_ROIPAC] params[cf.OUT_DIR] = cls.temp_out_dir params[cf.TMPDIR] = os.path.join(cls.temp_out_dir, cf.TMPDIR) shared.mkdir_p(params[cf.TMPDIR]) params[cf.REF_EST_METHOD] = 2 conv2tif.main(params) prepifg.main(params) cls.params = params base_ifg_paths = [ c.unwrapped_path for c in params[cf.INTERFEROGRAM_FILES] ] dest_paths = [c.converted_path for c in params[cf.INTERFEROGRAM_FILES]] dest_paths = dest_paths[:-2] for i in dest_paths: Path(i).chmod( 0o664 ) # assign write permission as conv2tif output is readonly ifgs = common.pre_prepare_ifgs(dest_paths, params) refx, refy = process._ref_pixel_calc(dest_paths, params) headers = [roipac.roipac_header(i, cls.params) for i in base_ifg_paths] pyrate.core.orbital.remove_orbital_error(ifgs, params, headers) ifgs = prepare_ifgs_without_phase(dest_paths, params) for ifg in ifgs: ifg.close() _, cls.ifgs = process._ref_phase_estimation(dest_paths, params, refx, refy) ifgs[0].open() r_dist = RDist(ifgs[0])() ifgs[0].close() # Calculate interferogram noise cls.maxvar = [ cvd(i, params, r_dist, calc_alpha=True, save_acg=True, write_vals=True)[0] for i in dest_paths ] cls.vcmt = get_vcmt(ifgs, cls.maxvar) for ifg in ifgs: ifg.close()
def setUpClass(cls): params = Configuration(TEST_CONF_ROIPAC).__dict__ cls.temp_out_dir = tempfile.mkdtemp() params[cf.OUT_DIR] = cls.temp_out_dir params[cf.TMPDIR] = os.path.join(params[cf.OUT_DIR], cf.TMPDIR) shared.mkdir_p(params[cf.TMPDIR]) conv2tif.main(params) prepifg.main(params) params[cf.REF_EST_METHOD] = 2 xlks, _, crop = cf.transform_params(params) base_ifg_paths = [ c.unwrapped_path for c in params[cf.INTERFEROGRAM_FILES] ] headers = [roipac.roipac_header(i, params) for i in base_ifg_paths] dest_paths = [ Path(cls.temp_out_dir).joinpath(Path( c.sampled_path).name).as_posix() for c in params[cf.INTERFEROGRAM_FILES][:-2] ] # start run_pyrate copy ifgs = pre_prepare_ifgs(dest_paths, params) mst_grid = tests.common.mst_calculation(dest_paths, params) refx, refy = process._ref_pixel_calc(dest_paths, params) # Estimate and remove orbit errors pyrate.core.orbital.remove_orbital_error(ifgs, params, headers) ifgs = prepare_ifgs_without_phase(dest_paths, params) for ifg in ifgs: ifg.close() _, ifgs = process._ref_phase_estimation(dest_paths, params, refx, refy) ifgs[0].open() r_dist = vcm_module.RDist(ifgs[0])() ifgs[0].close() maxvar = [vcm_module.cvd(i, params, r_dist)[0] for i in dest_paths] for ifg in ifgs: ifg.open() vcmt = vcm_module.get_vcmt(ifgs, maxvar) for ifg in ifgs: ifg.close() ifg.open() # Calculate stacked rate map params[cf.PARALLEL] = 1 cls.rate, cls.error, cls.samples = tests.common.calculate_stack_rate( ifgs, params, vcmt, mst_mat=mst_grid) # Calculate stacked rate map params[cf.PARALLEL] = 0 cls.rate_s, cls.error_s, cls.samples_s = tests.common.calculate_stack_rate( ifgs, params, vcmt, mst_mat=mst_grid) stackrate_dir = os.path.join(SML_TEST_DIR, 'stackrate') cls.rate_container = np.genfromtxt(os.path.join( stackrate_dir, 'stackmap.csv'), delimiter=',') cls.error_container = np.genfromtxt(os.path.join( stackrate_dir, 'errormap.csv'), delimiter=',') cls.samples_container = np.genfromtxt(os.path.join( stackrate_dir, 'coh_sta.csv'), delimiter=',') for ifg in ifgs: ifg.close()
def gamma_params(): params = Configuration(TEST_CONF_GAMMA).__dict__ shared.mkdir_p(params[C.OUT_DIR]) yield params shutil.rmtree(params[C.OUT_DIR], ignore_errors=True)
def main(params): """ Main workflow function for preparing interferograms for PyRate. :param dict params: Parameters dictionary read in from the config file """ # TODO: looks like ifg_paths are ordered according to ifg list # This probably won't be a problem because input list won't be reordered # and the original gamma generated list is ordered) this may not affect # the important pyrate stuff anyway, but might affect gen_thumbs.py. # Going to assume ifg_paths is ordered correcly # pylint: disable=too-many-branches shared.mpi_vs_multiprocess_logging("prepifg", params) ifg_paths = params[C.INTERFEROGRAM_FILES] if params[C.DEM_FILE] is not None: # optional DEM conversion ifg_paths.append(params[C.DEM_FILE_PATH]) if params[C.COH_FILE_LIST] is not None: ifg_paths.extend(params[C.COHERENCE_FILE_PATHS]) if params[C.COH_FILE_LIST] is None and params[C.COH_MASK]: raise FileNotFoundError( "Cannot apply coherence masking: no coherence file list " "supplied (parameter 'cohfilelist')") shared.mkdir_p(params[C.OUT_DIR]) # create output dir user_exts = (params[C.IFG_XFIRST], params[C.IFG_YFIRST], params[C.IFG_XLAST], params[C.IFG_YLAST]) xlooks, ylooks, crop = transform_params(params) ifgs = [prepifg_helper.dem_or_ifg(p.converted_path) for p in ifg_paths] exts = prepifg_helper.get_analysis_extent(crop, ifgs, xlooks, ylooks, user_exts=user_exts) ifg0 = ifgs[0] ifg0.open() transform = ifg0.dataset.GetGeoTransform() process_ifgs_paths = np.array_split(ifg_paths, mpiops.size)[mpiops.rank] do_prepifg(process_ifgs_paths, exts, params) if params[C.LT_FILE] is not None: log.info("Calculating and writing geometry files") __write_geometry_files(params, exts, transform, ifg_paths[0].sampled_path) else: log.info("Skipping geometry calculations: Lookup table not provided") if params[C.COH_FILE_LIST] is not None: log.info("Calculating and writing coherence statistics") mpiops.run_once(__calc_coherence_stats, params, ifg_paths[0].sampled_path) else: log.info("Skipping coherence file statistics computation.") log.info("Finished 'prepifg' step") ifg0.close()
def setUpClass(cls): params = cf.get_config_params(TEST_CONF_ROIPAC) cls.temp_out_dir = tempfile.mkdtemp() params[cf.OUT_DIR] = cls.temp_out_dir params[cf.TMPDIR] = os.path.join(params[cf.OUT_DIR], cf.TMPDIR) shared.mkdir_p(params[cf.TMPDIR]) conv2tif.main(params) prepifg.main(params) params[cf.REF_EST_METHOD] = 2 xlks, _, crop = cf.transform_params(params) base_ifg_paths = cf.original_ifg_paths(params[cf.IFG_FILE_LIST], params[cf.OBS_DIR]) dest_paths = cf.get_dest_paths(base_ifg_paths, crop, params, xlks) print(f"base_ifg_paths={base_ifg_paths}") print(f"dest_paths={dest_paths}") # start run_pyrate copy ifgs = pre_prepare_ifgs(dest_paths, params) mst_grid = tests.common.mst_calculation(dest_paths, params) refx, refy = process._ref_pixel_calc(dest_paths, params) # Estimate and remove orbit errors pyrate.core.orbital.remove_orbital_error(ifgs, params) ifgs = prepare_ifgs_without_phase(dest_paths, params) for ifg in ifgs: ifg.close() _, ifgs = process._ref_phase_estimation(dest_paths, params, refx, refy) ifgs[0].open() r_dist = vcm_module.RDist(ifgs[0])() ifgs[0].close() maxvar = [vcm_module.cvd(i, params, r_dist)[0] for i in dest_paths] for ifg in ifgs: ifg.open() vcmt = vcm_module.get_vcmt(ifgs, maxvar) for ifg in ifgs: ifg.close() ifg.open() # Calculate linear rate map params[cf.PARALLEL] = 1 cls.rate, cls.error, cls.samples = tests.common.calculate_linear_rate( ifgs, params, vcmt, mst_mat=mst_grid) params[cf.PARALLEL] = 2 cls.rate_2, cls.error_2, cls.samples_2 = \ tests.common.calculate_linear_rate(ifgs, params, vcmt, mst_mat=mst_grid) params[cf.PARALLEL] = 0 # Calculate linear rate map cls.rate_s, cls.error_s, cls.samples_s = \ tests.common.calculate_linear_rate(ifgs, params, vcmt, mst_mat=mst_grid) linrate_dir = os.path.join(SML_TEST_DIR, 'linrate') cls.rate_container = np.genfromtxt(os.path.join( linrate_dir, 'stackmap.csv'), delimiter=',') cls.error_container = np.genfromtxt(os.path.join( linrate_dir, 'errormap.csv'), delimiter=',') cls.samples_container = np.genfromtxt(os.path.join( linrate_dir, 'coh_sta.csv'), delimiter=',') for ifg in ifgs: ifg.close()
def independent_orbital_correction(ifg_path, params): """ Calculates and removes an orbital error surface from a single independent interferogram. Warning: This will write orbital error corrected phase_data to the ifg. :param Ifg class instance ifg: the interferogram to be corrected :param dict params: dictionary of configuration parameters :return: None - interferogram phase data is updated and saved to disk """ log.debug(f"Orbital correction of {ifg_path}") degree = params[C.ORBITAL_FIT_DEGREE] offset = params[C.ORBFIT_OFFSET] intercept = params[C.ORBFIT_INTERCEPT] xlooks = params[C.ORBITAL_FIT_LOOKS_X] ylooks = params[C.ORBITAL_FIT_LOOKS_Y] ifg0 = shared.Ifg(ifg_path) if isinstance(ifg_path, str) else ifg_path # get full-resolution design matrix fullres_dm = get_design_matrix(ifg0, degree, intercept=intercept) ifg = shared.dem_or_ifg(ifg_path) if isinstance(ifg_path, str) else ifg_path multi_path = MultiplePaths(ifg.data_path, params) orb_on_disc = MultiplePaths.orb_error_path(ifg.data_path, params) if not ifg.is_open: ifg.open() shared.nan_and_mm_convert(ifg, params) fullres_ifg = ifg # keep a backup fullres_phase = fullres_ifg.phase_data if orb_on_disc.exists(): log.info( f'Reusing already computed orbital fit correction: {orb_on_disc}') orbital_correction = np.load(file=orb_on_disc) else: # Multi-look the ifg data if either X or Y is greater than 1 if (xlooks > 1) or (ylooks > 1): exts, _, _ = __extents_from_params(params) mlooked = _create_mlooked_dataset(multi_path, ifg.data_path, exts, params) ifg = Ifg(mlooked) # multi-looked Ifg object ifg.initialize() shared.nan_and_mm_convert(ifg, params) # vectorise phase data, keeping NODATA vphase = reshape(ifg.phase_data, ifg.num_cells) # compute design matrix for multi-looked data mlooked_dm = get_design_matrix(ifg, degree, intercept=intercept) # invert to obtain the correction image (forward model) at full-res orbital_correction = __orb_correction(fullres_dm, mlooked_dm, fullres_phase, vphase, offset=offset) # save correction to disc if not orb_on_disc.parent.exists(): shared.mkdir_p(orb_on_disc.parent) np.save(file=orb_on_disc, arr=orbital_correction) # subtract orbital correction from the full-res ifg fullres_ifg.phase_data -= orbital_correction # set orbfit meta tag and save phase to file _save_orbital_error_corrected_phase(fullres_ifg, params)
def gamma_params(): params = Configuration(TEST_CONF_GAMMA).__dict__ shutil.rmtree(params[cf.OUT_DIR]) shared.mkdir_p(params[cf.OUT_DIR]) yield params shutil.rmtree(params[cf.OUT_DIR])