示例#1
0
def __check_and_apply_demerrors_found_on_disc(ifg_paths: list,
                                              params: dict) -> bool:
    """
    Convenience function to check if DEM error correction files have already been produced in a previous run
    :param ifg_paths: List of interferogram class objects.
    :param params: Dictionary of PyRate configuration parameters.
    :return: bool value: True if dem error files found on disc, otherwise False.
    """
    saved_dem_err_paths = [
        MultiplePaths.dem_error_path(ifg_path, params)
        for ifg_path in ifg_paths
    ]
    for d, i in zip(saved_dem_err_paths, ifg_paths):
        if d.exists():
            dem_corr = np.load(d)
            if isinstance(i, str):
                # are paths
                ifg = Ifg(i)
                ifg.open()
            else:
                ifg = i
            ifg.phase_data -= dem_corr
            # set geotiff meta tag and save phase to file
            # TODO: calculate avg bperp and add to metadata even for reused DEM error correction
            _save_dem_error_corrected_phase(ifg)

    return all(d.exists() for d in saved_dem_err_paths)
示例#2
0
def _write_dem_errors(ifg_paths: list, params: dict,
                      preread_ifgs: dict) -> None:
    """
    Convenience function for writing DEM error (one file) and DEM error correction for each IFG to disc
    :param ifg_paths: List of interferogram class objects.
    :param params: Dictionary of PyRate configuration parameters.
    :param preread_ifgs: Dictionary of interferogram metadata.
    """
    tiles = params[C.TILES]

    # re-assemble tiles and save into dem_error dir
    shape = preread_ifgs[ifg_paths[0]].shape

    # save dem error as geotiff file in out directory
    gt, md, wkt = shared.get_geotiff_header_info(ifg_paths[0])
    md[ifc.DATA_TYPE] = ifc.DEM_ERROR
    dem_error = assemble_tiles(shape,
                               params[C.TMPDIR],
                               tiles,
                               out_type='dem_error')
    dem_error_file = os.path.join(params[C.DEM_ERROR_DIR], 'dem_error.tif')
    shared.remove_file_if_exists(dem_error_file)
    shared.write_output_geotiff(md, gt, wkt, dem_error, dem_error_file, np.nan)

    # read the average bperp vals for each ifg and each tile
    bperp = np.empty(shape=(len(tiles), len(ifg_paths)), dtype=np.float64)
    for t in tiles:
        bperp_file = Path(
            join(params[C.TMPDIR], 'bperp_avg_' + str(t.index) + '.npy'))
        arr = np.load(file=bperp_file)
        bperp[t.index, :] = arr

    # loop over all ifgs
    idx = 0
    for ifg_path in ifg_paths:
        ifg = Ifg(ifg_path)
        ifg.open()
        shared.nan_and_mm_convert(ifg,
                                  params)  # ensure we have phase data in mm
        # read dem error correction file from tmpdir
        dem_error_correction_ifg = assemble_tiles(
            shape,
            params[C.TMPDIR],
            tiles,
            out_type='dem_error_correction',
            index=idx)
        # calculate average bperp value across all tiles for the ifg
        bperp_val = np.nanmean(bperp[:, idx])
        dem_error_correction_on_disc = MultiplePaths.dem_error_path(
            ifg.data_path, params)
        np.save(file=dem_error_correction_on_disc,
                arr=dem_error_correction_ifg)
        idx += 1

        # subtract DEM error from the ifg
        ifg.phase_data -= dem_error_correction_ifg
        _save_dem_error_corrected_phase(ifg, bperp_val)
示例#3
0
 def __run_once(self):
     dem_files = [
         MultiplePaths.dem_error_path(i, self.params)
         for i in self.ifg_paths
     ]
     correct._copy_mlooked(self.params)
     correct._update_params_with_tiles(self.params)
     correct._create_ifg_dict(self.params)
     save_numpy_phase(self.ifg_paths, self.params)
     dem_error_calc_wrapper(self.params)
     assert all(m.exists() for m in dem_files)
     return [os.stat(o).st_mtime for o in dem_files]