def mst_calc_wrapper(params): """ MPI wrapper function for MST calculation """ log.info('Calculating minimum spanning tree matrix') def _save_mst_tile(tile: Tile, params: dict) -> None: """ Convenient inner loop for mst tile saving """ preread_ifgs = params[C.PREREAD_IFGS] dest_tifs = [ ifg_path.tmp_sampled_path for ifg_path in params[C.INTERFEROGRAM_FILES] ] mst_file_process_n = Configuration.mst_path(params, index=tile.index) if mst_file_process_n.exists(): return mst_tile = mst_multiprocessing(tile, dest_tifs, preread_ifgs, params) # locally save the mst_mat np.save(file=mst_file_process_n, arr=mst_tile) tiles_split(_save_mst_tile, params) log.debug('Finished minimum spanning tree calculation')
def dem_error_calc_wrapper(params: dict) -> None: """ MPI wrapper for DEM error correction :param params: Dictionary of PyRate configuration parameters. """ if not params[C.DEMERROR]: log.info("DEM error correction not required") return # geometry information needed to calculate Bperp for each pixel using first IFG in list ifg_paths = [ ifg_path.tmp_sampled_path for ifg_path in params[C.INTERFEROGRAM_FILES] ] # check if DEM error correction is already available if mpiops.run_once(__check_and_apply_demerrors_found_on_disc, ifg_paths, params): log.warning("Reusing DEM error correction from previous run!!!") else: log.info("Calculating DEM error correction") # read and open the first IFG in list ifg0_path = ifg_paths[0] ifg0 = Ifg(ifg0_path) ifg0.open(readonly=True) # not currently implemented for ROIPAC data which breaks some tests # if statement can be deleted once ROIPAC is deprecated from PyRate if ifg0.meta_data[ifc.PYRATE_INSAR_PROCESSOR] == 'ROIPAC': log.warning( "Geometry calculations are not implemented for ROI_PAC") return if params[C.BASE_FILE_LIST] is None: log.warning( "No baseline files supplied: DEM error has not been computed") return # todo: subtract other corrections (e.g. orbital) from displacement phase before estimating the DEM error # the following code is a quick way to do the bperp calculation, but is not identical to the GAMMA output # where the near range of the first SLC is used for each pair. # calculate look angle for interferograms (using the Near Range of the first SLC) # look_angle = geometry.calc_local_geometry(ifg0, None, rg, lon, lat, params) # bperp = geometry.calc_local_baseline(ifg0, az, look_angle) # split full arrays in to tiles for parallel processing tiles_split(_process_dem_error_per_tile, params) preread_ifgs = params[C.PREREAD_IFGS] # write dem error and correction values to file mpiops.run_once(_write_dem_errors, ifg_paths, params, preread_ifgs) shared.save_numpy_phase(ifg_paths, params) log.debug('Finished DEM error correction step')
def stack_calc_wrapper(params): """ Wrapper for stacking on a set of tiles. """ log.info('Calculating rate map via stacking') if not Configuration.vcmt_path(params).exists(): raise FileNotFoundError( "VCMT is not found on disc. Have you run the 'correct' step?") params[C.PREREAD_IFGS] = cp.load( open(Configuration.preread_ifgs(params), 'rb')) params[C.VCMT] = np.load(Configuration.vcmt_path(params)) params[C.TILES] = Configuration.get_tiles(params) tiles_split(_stacking_for_tile, params) log.debug("Finished stacking calc!")
def timeseries_calc_wrapper(params): """ Wrapper for time series calculation on a set of tiles. """ if params[C.TIME_SERIES_METHOD] == 1: log.info('Calculating time series using Laplacian Smoothing method') elif params[C.TIME_SERIES_METHOD] == 2: log.info('Calculating time series using SVD method') if not Configuration.vcmt_path(params).exists(): raise FileNotFoundError("VCMT is not found on disc. Have you run the 'correct' step?") params[C.PREREAD_IFGS] = cp.load(open(Configuration.preread_ifgs(params), 'rb')) params[C.VCMT] = np.load(Configuration.vcmt_path(params)) params[C.TILES] = Configuration.get_tiles(params) tiles_split(__calc_time_series_for_tile, params) log.debug("Finished timeseries calc!")
def test_tiles_split(parallel, data_type): params = { C.TILES: data_types[data_type], C.PARALLEL: parallel, C.LOG_LEVEL: 'INFO', 'multiplier': 2, C.PROCESSES: 4 } def func(tile, params): return tile * params['multiplier'] ret = tiles_split(func, params) expected_ret = np.array( [item * params['multiplier'] for item in data_types[data_type]], dtype=object) np.testing.assert_array_equal(ret, expected_ret)