Пример #1
0
def _prepifg_multiprocessing(path, xlooks, ylooks, exts, thresh, crop, params):
    """
    Multiprocessing wrapper for prepifg
    """
    processor = params[cf.PROCESSOR]  # roipac or gamma
    if processor == GAMMA:
        header = gamma.gamma_header(path, params)
    elif processor == ROIPAC:
        header = roipac.roipac_header(path, params)
    else:
        raise PreprocessError('Processor must be ROI_PAC (0) or GAMMA (1)')
    # If we're performing coherence masking, find the coherence file for this IFG.
    # TODO: Refactor _is_interferogram to be unprotected (remove '_')
    if params[cf.COH_MASK] and shared._is_interferogram(header):
        coherence_path = cf.coherence_paths_for(path, params, tif=True)[0]
        coherence_thresh = params[cf.COH_THRESH]
    else:
        coherence_path = None
        coherence_thresh = None

    prepifg_helper.prepare_ifg(path,
                               xlooks,
                               ylooks,
                               exts,
                               thresh,
                               crop,
                               out_path=params[cf.OUT_DIR],
                               header=header,
                               coherence_path=coherence_path,
                               coherence_thresh=coherence_thresh)
Пример #2
0
def _prepifg_multiprocessing(path, xlooks, ylooks, exts, thresh, crop, params):
    """
    Multiprocessing wrapper for prepifg
    """
    processor = params[cf.PROCESSOR]  # roipac, gamma or geotif
    if (processor == GAMMA) or (processor == GEOTIF):
        header = gamma.gamma_header(path, params)
    elif processor == ROIPAC:
        log.info("Warning: ROI_PAC support will be deprecated in a future PyRate release")
        header = roipac.roipac_header(path, params)
    else:
        raise PreprocessError('Processor must be ROI_PAC (0) or GAMMA (1)')

    # If we're performing coherence masking, find the coherence file for this IFG.
    if params[cf.COH_MASK] and shared._is_interferogram(header):
        coherence_path = cf.coherence_paths_for(path, params, tif=True)
        coherence_thresh = params[cf.COH_THRESH]
    else:
        coherence_path = None
        coherence_thresh = None

    if params[cf.LARGE_TIFS]:
        op = output_tiff_filename(path, params[cf.OUT_DIR])
        looks_path = cf.mlooked_path(op, ylooks, crop)
        return path, coherence_path, looks_path
    else:
        prepifg_helper.prepare_ifg(path, xlooks, ylooks, exts, thresh, crop, out_path=params[cf.OUT_DIR],
                                   header=header, coherence_path=coherence_path, coherence_thresh=coherence_thresh)
Пример #3
0
    def test_multilooked_projection_same_as_geotiff(self):
        xlooks = ylooks = 1
        exts = get_analysis_extent(crop_opt=MAXIMUM_CROP,
                                   rasters=self.ifgs,
                                   xlooks=xlooks,
                                   ylooks=ylooks,
                                   user_exts=None)
        out_dir = tempfile.mkdtemp()
        params = common.min_params(out_dir)
        params[C.IFG_LKSX] = xlooks
        params[C.IFG_LKSY] = ylooks
        params[C.IFG_CROP_OPT] = MAXIMUM_CROP
        params[C.GEOMETRY_DIR] = Path(out_dir).joinpath(C.GEOMETRY_DIR)
        params[C.GEOMETRY_DIR].mkdir(exist_ok=True)
        params[C.INTERFEROGRAM_DIR] = Path(out_dir).joinpath(
            C.INTERFEROGRAM_DIR)
        params[C.INTERFEROGRAM_DIR].mkdir(exist_ok=True)

        mlooked_paths = [
            mlooked_path(f, params, input_type=InputTypes.IFG)
            for f in self.ifg_paths
        ]
        for i, h, m in zip(self.ifg_paths, self.headers, mlooked_paths):
            prepare_ifg(i,
                        xlooks,
                        ylooks,
                        exts,
                        thresh=0.5,
                        crop_opt=MAXIMUM_CROP,
                        header=h,
                        write_to_disk=True,
                        out_path=m)
        self.assert_projection_equal(self.ifg_paths + mlooked_paths)
Пример #4
0
def _prepifg_multiprocessing(m_path: MultiplePaths, exts: Tuple[float, float, float, float], params: dict):
    """
    Multiprocessing wrapper for prepifg
    """
    xlooks, ylooks, crop = cf.transform_params(params)
    thresh = params[cf.NO_DATA_AVERAGING_THRESHOLD]
    header = find_header(m_path, params)
    header[ifc.INPUT_TYPE] = m_path.input_type

    # If we're performing coherence masking, find the coherence file for this IFG.
    if params[cf.COH_MASK] and shared._is_interferogram(header):
        coherence_path = cf.coherence_paths_for(m_path.converted_path, params, tif=True)
        coherence_thresh = params[cf.COH_THRESH]
    else:
        coherence_path = None
        coherence_thresh = None

    if params[cf.LARGE_TIFS]:
        op = output_tiff_filename(m_path.converted_path, params[cf.OUT_DIR])
        looks_path = cf.mlooked_path(op, ylooks, crop)
        return m_path.converted_path, coherence_path, looks_path
    else:
        prepifg_helper.prepare_ifg(m_path.converted_path, xlooks, ylooks, exts, thresh, crop,
                                   out_path=params[cf.OUT_DIR], header=header, coherence_path=coherence_path,
                                   coherence_thresh=coherence_thresh)
Пример #5
0
def _prepifg_multiprocessing(m_path: MultiplePaths, exts: Tuple[float, float,
                                                                float, float],
                             params: dict):
    """
    Multiprocessing wrapper for prepifg
    """
    thresh = params[cf.NO_DATA_AVERAGING_THRESHOLD]
    hdr = find_header(m_path, params)
    hdr[ifc.INPUT_TYPE] = m_path.input_type
    xlooks, ylooks, crop = cf.transform_params(params)
    hdr[ifc.IFG_LKSX] = xlooks
    hdr[ifc.IFG_LKSY] = ylooks
    hdr[ifc.IFG_CROP] = crop

    # If we're performing coherence masking, find the coherence file for this IFG.
    if params[cf.COH_MASK] and shared._is_interferogram(hdr):
        coherence_path = cf.coherence_paths_for(m_path.converted_path,
                                                params,
                                                tif=True)
        coherence_thresh = params[cf.COH_THRESH]
    else:
        coherence_path = None
        coherence_thresh = None

    if params[cf.LARGE_TIFS]:
        return m_path.converted_path, coherence_path, m_path.sampled_path
    else:
        prepifg_helper.prepare_ifg(m_path.converted_path,
                                   xlooks,
                                   ylooks,
                                   exts,
                                   thresh,
                                   crop,
                                   out_path=m_path.sampled_path,
                                   header=hdr,
                                   coherence_path=coherence_path,
                                   coherence_thresh=coherence_thresh)
        Path(m_path.sampled_path).chmod(0o444)  # readonly output
Пример #6
0
def prepare_ifgs(raster_data_paths,
                 crop_opt,
                 xlooks,
                 ylooks,
                 headers,
                 params,
                 thresh=0.5,
                 user_exts=None,
                 write_to_disc=True):
    """
    Wrapper function to prepare a sequence of interferogram files for
    PyRate analysis. See prepifg.prepare_ifg() for full description of
    inputs and returns.

    Note: function need refining for crop options

    :param list raster_data_paths: List of interferogram file paths
    :param int crop_opt: Crop option
    :param int xlooks: Number of multi-looks in x; 5 is 5 times smaller, 1 is no change
    :param int ylooks: Number of multi-looks in y
    :param float thresh: see thresh in prepare_ifgs()
    :param tuple user_exts: Tuple of user defined georeferenced extents for
        new file: (xfirst, yfirst, xlast, ylast)cropping coordinates
    :param bool write_to_disc: Write new data to disk

    :return: resampled_data: output cropped and resampled image
    :rtype: ndarray
    :return: out_ds: destination gdal dataset object
    :rtype: List[gdal.Dataset]
    """
    if xlooks != ylooks:
        log.warning('X and Y multi-look factors are not equal')

    # use metadata check to check whether it's a dem or ifg
    rasters = [dem_or_ifg(r) for r in raster_data_paths]
    exts = get_analysis_extent(crop_opt, rasters, xlooks, ylooks, user_exts)
    out_paths = []
    for r, t in zip(raster_data_paths, rasters):
        if isinstance(t, DEM):
            input_type = InputTypes.DEM
        else:
            input_type = InputTypes.IFG
        out_path = MultiplePaths(r, params, input_type).sampled_path
        out_paths.append(out_path)
    return [
        prepare_ifg(d, xlooks, ylooks, exts, thresh, crop_opt, h,
                    write_to_disc, p)
        for d, h, p in zip(raster_data_paths, headers, out_paths)
    ]
Пример #7
0
def _create_mlooked_dataset(multi_path, ifg_path, exts, params):
    '''
    Wrapper to generate a multi-looked dataset for a single ifg
    '''
    header = find_header(multi_path, params)
    thresh = params[C.NO_DATA_AVERAGING_THRESHOLD]
    crop_opt = prepifg_helper.ALREADY_SAME_SIZE
    xlooks = params[C.ORBITAL_FIT_LOOKS_X]
    ylooks = params[C.ORBITAL_FIT_LOOKS_Y]
    out_path = tempfile.mktemp()
    log.debug(
        f'Multi-looking {ifg_path} with factors X = {xlooks} and Y = {ylooks} for orbital correction'
    )
    resampled_data, out_ds = prepifg_helper.prepare_ifg(
        ifg_path, xlooks, ylooks, exts, thresh, crop_opt, header, False,
        out_path)
    return out_ds
Пример #8
0
def __create_multilooked_dataset_for_network_correction(params):
    multi_paths = params[cf.INTERFEROGRAM_FILES]
    ifg_paths = [p.tmp_sampled_path for p in multi_paths]
    headers = [find_header(p, params) for p in multi_paths]
    crop_opt = prepifg_helper.ALREADY_SAME_SIZE
    xlooks = params[cf.ORBITAL_FIT_LOOKS_X]
    ylooks = params[cf.ORBITAL_FIT_LOOKS_Y]
    thresh = params[cf.NO_DATA_AVERAGING_THRESHOLD]
    rasters = [shared.dem_or_ifg(r) for r in ifg_paths]
    exts = prepifg_helper.get_analysis_extent(crop_opt, rasters, xlooks,
                                              ylooks, None)

    out_paths = [tempfile.mktemp() for _ in ifg_paths]
    mlooked_dataset = [
        prepifg_helper.prepare_ifg(d, xlooks, ylooks, exts, thresh, crop_opt,
                                   h, False, p)
        for d, h, p in zip(ifg_paths, headers, out_paths)
    ]
    mlooked = [Ifg(m[1]) for m in mlooked_dataset]
    for m in mlooked:
        m.initialize()
        shared.nan_and_mm_convert(m, params)
    return mlooked