Exemple #1
0
def _timeseries_calc(ifg_paths, params, vcmt, tiles, preread_ifgs):
    """
    MPI wrapper for time series calculation.
    """
    if params[cf.TIME_SERIES_CAL] == 0:
        log.info('Time Series Calculation not required')
        return

    if params[cf.TIME_SERIES_METHOD] == 1:
        log.info('Calculating time series using Laplacian Smoothing method')
    elif params[cf.TIME_SERIES_METHOD] == 2:
        log.info('Calculating time series using SVD method')

    output_dir = params[cf.TMPDIR]
    process_tiles = mpiops.array_split(tiles)
    for t in process_tiles:
        log.debug('Calculating time series for tile {}'.format(t.index))
        ifg_parts = [shared.IfgPart(p, t, preread_ifgs) for p in ifg_paths]
        mst_tile = np.load(
            os.path.join(output_dir, 'mst_mat_{}.npy'.format(t.index)))
        res = timeseries.time_series(ifg_parts, params, vcmt, mst_tile)
        tsincr, tscum, _ = res
        np.save(file=os.path.join(output_dir, 'tsincr_{}.npy'.format(t.index)),
                arr=tsincr)
        np.save(file=os.path.join(output_dir, 'tscuml_{}.npy'.format(t.index)),
                arr=tscum)
    mpiops.comm.barrier()
Exemple #2
0
def _linrate_calc(ifg_paths, params, vcmt, tiles, preread_ifgs):
    """
    MPI wrapper for linrate calculation
    """
    process_tiles = mpiops.array_split(tiles)
    log.info('Calculating rate map from stacking')
    output_dir = params[cf.TMPDIR]
    for t in process_tiles:
        log.debug('Stacking of tile {}'.format(t.index))
        ifg_parts = [shared.IfgPart(p, t, preread_ifgs) for p in ifg_paths]
        mst_grid_n = np.load(
            os.path.join(output_dir, 'mst_mat_{}.npy'.format(t.index)))
        rate, error, samples = linrate.linear_rate(ifg_parts, params, vcmt,
                                                   mst_grid_n)
        # declare file names
        np.save(file=os.path.join(output_dir,
                                  'linrate_{}.npy'.format(t.index)),
                arr=rate)
        np.save(file=os.path.join(output_dir,
                                  'linerror_{}.npy'.format(t.index)),
                arr=error)
        np.save(file=os.path.join(output_dir,
                                  'linsamples_{}.npy'.format(t.index)),
                arr=samples)
    mpiops.comm.barrier()
Exemple #3
0
def _calc_svd_time_series(ifg_paths, params, preread_ifgs, tiles):
    """
    Helper function to obtain time series for spatio-temporal filter
    using SVD method
    """
    # Is there other existing functions that can perform this same job?
    log.info('Calculating time series via SVD method for ' 'APS correction')
    # copy params temporarily
    new_params = deepcopy(params)
    new_params[cf.TIME_SERIES_METHOD] = 2  # use SVD method

    process_tiles = mpiops.array_split(tiles)

    nvels = None
    for t in process_tiles:
        log.debug('Calculating time series for tile {} during APS '
                  'correction'.format(t.index))
        ifg_parts = [
            shared.IfgPart(p, t, preread_ifgs, params) for p in ifg_paths
        ]
        mst_tile = np.load(
            os.path.join(params[cf.TMPDIR], 'mst_mat_{}.npy'.format(t.index)))
        tsincr = time_series(ifg_parts, new_params, vcmt=None, mst=mst_tile)[0]
        np.save(file=os.path.join(params[cf.TMPDIR],
                                  'tsincr_aps_{}.npy'.format(t.index)),
                arr=tsincr)
        nvels = tsincr.shape[2]

    nvels = mpiops.comm.bcast(nvels, root=0)
    mpiops.comm.barrier()
    # need to assemble tsincr from all processes
    tsincr_g = mpiops.run_once(_assemble_tsincr, ifg_paths, params,
                               preread_ifgs, tiles, nvels)
    log.debug('Finished calculating time series for spatio-temporal filter')
    return tsincr_g
Exemple #4
0
def _stacking_for_tile(tile, params):
    """
    Wrapper for stacking calculation on a single tile
    """
    preread_ifgs = params[C.PREREAD_IFGS]
    vcmt = params[C.VCMT]
    ifg_paths = [
        ifg_path.tmp_sampled_path for ifg_path in params[C.INTERFEROGRAM_FILES]
    ]
    output_dir = params[C.TMPDIR]
    log.debug(f"Stacking of tile {tile.index}")
    ifg_parts = [
        shared.IfgPart(p, tile, preread_ifgs, params) for p in ifg_paths
    ]
    mst_tile = np.load(Configuration.mst_path(params, tile.index))
    rate, error, samples = stack_rate_array(ifg_parts, params, vcmt, mst_tile)
    np.save(file=os.path.join(output_dir,
                              'stack_rate_{}.npy'.format(tile.index)),
            arr=rate)
    np.save(file=os.path.join(output_dir,
                              'stack_error_{}.npy'.format(tile.index)),
            arr=error)
    np.save(file=os.path.join(output_dir,
                              'stack_samples_{}.npy'.format(tile.index)),
            arr=samples)
Exemple #5
0
def _calc_svd_time_series(ifg_paths: List[str], params: dict,
                          preread_ifgs: dict, tiles: List[Tile]) -> np.ndarray:
    """
    Helper function to obtain time series for spatio-temporal filter
    using SVD method
    """
    # Is there other existing functions that can perform this same job?
    log.info('Calculating incremental time series via SVD method for APS '
             'correction')
    # copy params temporarily
    new_params = deepcopy(params)
    new_params[C.TIME_SERIES_METHOD] = 2  # use SVD method

    process_tiles = mpiops.array_split(tiles)

    nvels = None
    for t in process_tiles:
        log.debug(f'Calculating time series for tile {t.index} during APS '
                  f'correction')
        ifgp = [shared.IfgPart(p, t, preread_ifgs, params) for p in ifg_paths]
        mst_tile = np.load(Configuration.mst_path(params, t.index))
        tsincr = time_series(ifgp, new_params, vcmt=None, mst=mst_tile)[0]
        np.save(file=os.path.join(params[C.TMPDIR],
                                  f'tsincr_aps_{t.index}.npy'),
                arr=tsincr)
        nvels = tsincr.shape[2]

    nvels = mpiops.comm.bcast(nvels, root=0)
    mpiops.comm.barrier()
    # need to assemble tsincr from all processes
    tsincr_g = _assemble_tsincr(ifg_paths, params, preread_ifgs, tiles, nvels)
    log.debug('Finished calculating time series for spatio-temporal filter')
    return tsincr_g
Exemple #6
0
def __calc_time_series_for_tile(tile, params):
    """
    Wrapper for time series calculation on a single tile
    """
    preread_ifgs = params[cf.PREREAD_IFGS]
    vcmt = params[cf.VCMT]
    ifg_paths = [
        ifg_path.tmp_sampled_path
        for ifg_path in params[cf.INTERFEROGRAM_FILES]
    ]
    output_dir = params[cf.TMPDIR]
    log.debug(f"Calculating time series for tile {tile.index}")
    ifg_parts = [
        shared.IfgPart(p, tile, preread_ifgs, params) for p in ifg_paths
    ]
    mst_tile = np.load(Configuration.mst_path(params, tile.index))
    tsincr, tscuml, _ = time_series(ifg_parts, params, vcmt, mst_tile)
    np.save(file=os.path.join(output_dir, 'tscuml_{}.npy'.format(tile.index)),
            arr=tscuml)
    # optional save of tsincr npy tiles
    if params["savetsincr"] == 1:
        np.save(file=os.path.join(output_dir,
                                  'tsincr_{}.npy'.format(tile.index)),
                arr=tsincr)
    tscuml = np.insert(tscuml, 0, 0,
                       axis=2)  # add zero epoch to tscuml 3D array
    log.info('Calculating linear regression of cumulative time series')
    linrate, intercept, r_squared, std_err, samples = linear_rate_array(
        tscuml, ifg_parts, params)
    np.save(file=os.path.join(output_dir,
                              'linear_rate_{}.npy'.format(tile.index)),
            arr=linrate)
    np.save(file=os.path.join(output_dir,
                              'linear_intercept_{}.npy'.format(tile.index)),
            arr=intercept)
    np.save(file=os.path.join(output_dir,
                              'linear_rsquared_{}.npy'.format(tile.index)),
            arr=r_squared)
    np.save(file=os.path.join(output_dir,
                              'linear_error_{}.npy'.format(tile.index)),
            arr=std_err)
    np.save(file=os.path.join(output_dir,
                              'linear_samples_{}.npy'.format(tile.index)),
            arr=samples)
Exemple #7
0
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)