def setup_class(cls): cls.params = Configuration(common.MEXICO_CROPA_CONF).__dict__ # run prepifg prepifg.main(cls.params) # copy IFGs to temp folder correct._copy_mlooked(cls.params) # read radar azimuth, range and dem tif files geom_files = Configuration.geometry_files(cls.params) rdc_az_file = geom_files['rdc_azimuth'] geom_az = Geometry(rdc_az_file) cls.az = geom_az.data rdc_rg_file = geom_files['rdc_range'] geom_rg = Geometry(rdc_rg_file) cls.rg = geom_rg.data dem_file = join(cls.params[C.GEOMETRY_DIR], 'dem.tif') dem_data = DEM(dem_file) cls.dem = dem_data.data # calc bperp using pyrate funcs cls.pbperp = cls.pyrate_bperp()
def _process_dem_error_per_tile(tile: Tile, params: dict) -> None: """ Convenience function for processing DEM error in tiles :param tile: pyrate.core.shared.Tile Class object. :param params: Dictionary of PyRate configuration parameters. """ ifg_paths = [ ifg_path.tmp_sampled_path for ifg_path in params[C.INTERFEROGRAM_FILES] ] ifg0_path = ifg_paths[0] ifg0 = Ifg(ifg0_path) ifg0.open(readonly=True) # read lon and lat values of multi-looked ifg (first ifg only) lon, lat = geometry.get_lonlat_coords(ifg0) # read azimuth and range coords and DEM from tif files generated in prepifg geom_files = Configuration.geometry_files(params) rdc_az_file = geom_files['rdc_azimuth'] geom_az = Geometry(rdc_az_file) rdc_rg_file = geom_files['rdc_range'] geom_rg = Geometry(rdc_rg_file) dem_file = params[C.DEM_FILE_PATH].sampled_path dem = DEM(dem_file) preread_ifgs = params[C.PREREAD_IFGS] threshold = params[C.DE_PTHR] ifg_parts = [ shared.IfgPart(p, tile, preread_ifgs, params) for p in ifg_paths ] lon_parts = lon(tile) lat_parts = lat(tile) az_parts = geom_az(tile) rg_parts = geom_rg(tile) dem_parts = dem(tile) log.debug( f"Calculating per-pixel baseline for tile {tile.index} during DEM error correction" ) bperp, look_angle, range_dist = _calculate_bperp_wrapper( ifg_paths, az_parts, rg_parts, lat_parts, lon_parts, dem_parts) log.debug( f"Calculating DEM error for tile {tile.index} during DEM error correction" ) # mst_tile = np.load(Configuration.mst_path(params, tile.index)) # calculate the DEM error estimate and the correction values for each IFG # current implementation uses the look angle and range distance matrix of the primary SLC in the last IFG # todo: check the impact of using the same information from another SLC dem_error, dem_error_correction, _ = calc_dem_errors( ifg_parts, bperp, look_angle, range_dist, threshold) # dem_error contains the estimated DEM error for each pixel (i.e. the topographic change relative to the DEM) # size [row, col] # dem_error_correction contains the correction value for each interferogram # size [num_ifg, row, col] # save tiled data in tmpdir np.save(file=os.path.join(params[C.TMPDIR], 'dem_error_{}.npy'.format(tile.index)), arr=dem_error) # swap the axes of 3D array to fit the style used in function assemble_tiles tmp_array = np.moveaxis(dem_error_correction, 0, -1) # new dimension is [row, col, num_ifg] # save tiled data into tmpdir np.save(file=os.path.join( params[C.TMPDIR], 'dem_error_correction_{}.npy'.format(tile.index)), arr=tmp_array) # Calculate and save the average perpendicular baseline for the tile bperp_avg = np.nanmean(bperp, axis=(1, 2), dtype=np.float64) np.save(file=os.path.join(params[C.TMPDIR], 'bperp_avg_{}.npy'.format(tile.index)), arr=bperp_avg)
def __save_merged_files(ifgs_dict, params, array, out_type, index=None, savenpy=None): """ Convenience function to save PyRate geotiff and numpy array files """ outdir = params[C.OUT_DIR] ts_dir = params[C.TIMESERIES_DIR] vel_dir = params[C.VELOCITY_DIR] log.debug('Saving PyRate outputs {}'.format(out_type)) gt, md, wkt = ifgs_dict['gt'], ifgs_dict['md'], ifgs_dict['wkt'] epochlist = ifgs_dict['epochlist'] if out_type in ('tsincr', 'tscuml'): epoch = epochlist.dates[index + 1] dest = join(ts_dir, out_type + "_" + str(epoch) + ".tif") npy_file = join(ts_dir, out_type + "_" + str(epoch) + ".npy") # sequence position; first time slice is #0 md['SEQUENCE_POSITION'] = index + 1 md[ifc.EPOCH_DATE] = epoch else: dest = join(vel_dir, out_type + ".tif") npy_file = join(vel_dir, out_type + '.npy') md[ifc.EPOCH_DATE] = [d.strftime('%Y-%m-%d') for d in epochlist.dates] md[ifc.DATA_TYPE] = out_type_md_dict[out_type] if out_type in los_projection_out_types: # apply LOS projection and sign conversion for these outputs incidence_path = Path( Configuration.geometry_files(params)['incidence_angle']) if incidence_path.exists(): # We can do LOS projection if params[C.LOS_PROJECTION] == ifc.LINE_OF_SIGHT: log.info( f"Retaining Line-of-sight signal projection for file {dest}" ) elif params[C.LOS_PROJECTION] != ifc.LINE_OF_SIGHT: log.info( f"Projecting Line-of-sight signal into " f"{ifc.LOS_PROJECTION_OPTION[params[C.LOS_PROJECTION]]} for file {dest}" ) incidence = shared.Geometry(incidence_path) incidence.open() array /= los_projection_divisors[params[C.LOS_PROJECTION]]( incidence.data) * params[C.SIGNAL_POLARITY] md[C.LOS_PROJECTION.upper()] = ifc.LOS_PROJECTION_OPTION[params[ C.LOS_PROJECTION]] md[C.SIGNAL_POLARITY.upper()] = params[C.SIGNAL_POLARITY] if out_type in error_out_types: # add n-sigma value to error file metadata # TODO: move the multiplication of nsigma and error data here? md[C.VELERROR_NSIG.upper()] = params[C.VELERROR_NSIG] log.info( f"Saving file {dest} with {params[C.VELERROR_NSIG]}-sigma uncertainties" ) shared.write_output_geotiff(md, gt, wkt, array, dest, np.nan) # clear the extra metadata so it does not mess up other images if C.LOS_PROJECTION.upper() in md: md.pop(C.LOS_PROJECTION.upper()) if C.SIGNAL_POLARITY.upper() in md: md.pop(C.SIGNAL_POLARITY.upper()) if C.VELERROR_NSIG.upper() in md: md.pop(C.VELERROR_NSIG.upper()) if savenpy: np.save(file=npy_file, arr=array) log.debug('Finished saving {}'.format(out_type))
def __parallelly_write(tup, params, ifg_path): array, output_type = tup dest = Configuration.geometry_files(params)[output_type] if mpiops.size > 0: log.debug(f"Writing {dest} using process {mpiops.rank}") __save_geom_files(ifg_path, dest, array, output_type)