Exemplo n.º 1
0
def gamma_multiprocessing(unw_path, params):
    """
    Gamma multiprocessing wrapper for geotif conversion.

    :param unw_path: Wnwrapped interferogram path
    :param params: Parameters dictionary corresponding to config file
    
    :return xxxx
    """
    dem_hdr_path = params[cf.DEM_HEADER_FILE]
    slc_dir = params[cf.SLC_DIR]
    mkdir_p(params[cf.OUT_DIR])
    header_paths = gamma_task.get_header_paths(unw_path, slc_dir=slc_dir)
    combined_headers = gamma.manage_headers(dem_hdr_path, header_paths)

    dest = output_tiff_filename(unw_path, params[cf.OUT_DIR])
    if os.path.basename(unw_path).split('.')[1] == \
            (params[cf.APS_INCIDENCE_EXT] or params[cf.APS_ELEVATION_EXT]):
        # TODO: implement incidence class here
        combined_headers['FILE_TYPE'] = 'Incidence'

    write_geotiff(combined_headers,
                  unw_path,
                  dest,
                  nodata=params[cf.NO_DATA_VALUE])
    return dest
Exemplo n.º 2
0
 def setUp(self):
     random_text = tempfile.mktemp()
     self.confFile = os.path.join(TEMPDIR,
                                  '{}/roipac_test.cfg'.format(random_text))
     self.ifgListFile = os.path.join(
         TEMPDIR, '{}/roipac_ifg.list'.format(random_text))
     self.base_dir = os.path.dirname(self.confFile)
     shared.mkdir_p(self.base_dir)
     self.hdr = SML_TEST_DEM_HDR
Exemplo n.º 3
0
 def setUp(self):
     self.base = join(PYRATEPATH, 'tests', 'test_data', 'gamma')
     self.hdr = join(self.base, 'dem16x20raw.dem.par')
     temp_text = tempfile.mktemp()
     self.confFile = os.path.join(TEMPDIR,
                                  '{}/gamma_test.cfg'.format(temp_text))
     self.ifgListFile = os.path.join(TEMPDIR,
                                     '{}/gamma_ifg.list'.format(temp_text))
     self.base_dir = os.path.dirname(self.confFile)
     shared.mkdir_p(self.base_dir)
Exemplo n.º 4
0
def test_spatio_temporal_filter():
    import tempfile
    from pyrate import shared
    from os.path import basename, join
    from collections import OrderedDict
    from pyrate.scripts import run_prepifg
    from osgeo import gdal
    from pyrate import ifgconstants as ifc
    ifg_out = sio.loadmat(
        os.path.join(SML_TEST_DIR, 'matlab_aps',
                     'ifg_spatio_temp_out.mat'))['ifg']

    tsincr = sio.loadmat(
        os.path.join(SML_TEST_DIR, 'matlab_aps', 'tsincr_svd.mat'))['tsincr']
    params = cf.get_config_params(os.path.join(TEST_CONF_GAMMA))
    params[cf.OUT_DIR] = tempfile.mkdtemp()
    params[cf.TMPDIR] = join(params[cf.OUT_DIR], cf.TMPDIR)
    shared.mkdir_p(params[cf.TMPDIR])
    params[cf.SLPF_METHOD] = 2
    params[cf.SLPF_CUTOFF] = 0
    params[cf.SLPF_ORDER] = 1
    params[cf.SLPF_NANFILL] = 0
    params[cf.TLPF_METHOD] = 3
    params[cf.TLPF_CUTOFF] = 0.25
    params[cf.TLPF_PTHR] = 5
    ifgs = small_data_setup()
    _ = [ifgs_pk.pop(k) for k in ['gt', 'epochlist', 'md', 'wkt']]
    preread_ifgs = {
        join(params[cf.OUT_DIR], basename(k)): v
        for k, v in ifgs_pk.items()
    }
    preread_ifgs = OrderedDict(sorted(preread_ifgs.items()))

    run_prepifg.main(params)
    for k, v in preread_ifgs.items():
        v.path = join(params[cf.OUT_DIR], basename(k))
        preread_ifgs[k] = v
    ifg = ifgs[0]
    ifg.x_size = xpsize
    ifg.y_size = ypsize
    spatio_temporal_filter(tsincr, ifg, params, preread_ifgs)
    for i in ifgs:
        i.close()

    for (p, v), i in zip(preread_ifgs.items(), range(ifg_out.shape[2])):
        ds = gdal.Open(p)
        metadata = ds.GetMetadata()
        assert ifc.PYRATE_APS_ERROR in metadata
        assert metadata[ifc.PYRATE_APS_ERROR] == ifc.APS_REMOVED
        arr = ds.GetRasterBand(1).ReadAsArray()
        np.testing.assert_array_almost_equal(arr, ifg_out[:, :, i], decimal=3)
Exemplo n.º 5
0
    def setUpClass(cls):

        luigi_dir = tempfile.mktemp()
        non_luigi_dir = tempfile.mkdtemp()
        cls.luigi_confFile = os.path.join(
            TEMPDIR, '{}/gamma_test.conf'.format(luigi_dir))
        cls.luigi_ifgListFile = os.path.join(
            TEMPDIR, '{}/gamma_ifg.list'.format(luigi_dir))
        cls.non_luigi_confFile = os.path.join(
            TEMPDIR, '{}/gamma_test.conf'.format(non_luigi_dir))
        cls.non_luigi_ifgListFile = os.path.join(
            TEMPDIR, '{}/gamma_ifg.list'.format(non_luigi_dir))

        cls.luigi_base_dir = os.path.dirname(cls.luigi_confFile)
        cls.non_luigi_base_dir = os.path.dirname(cls.non_luigi_confFile)
        shared.mkdir_p(cls.luigi_base_dir)
        shared.mkdir_p(cls.non_luigi_base_dir)
Exemplo n.º 6
0
def main(params=None):
    """
    Main workflow function for preparing interferograms for PyRate.

    :param dict params: Parameters dictionary read in from the config file
    """
    # TODO: looks like base_ifg_paths are ordered according to ifg list
    # This probably won't be a problem because input list won't be reordered
    # and the original gamma generated list is ordered) this may not affect
    # the important pyrate stuff anyway, but might affect gen_thumbs.py.
    # Going to assume base_ifg_paths is ordered correcly
    # pylint: disable=too-many-branches

    usage = 'Usage: pyrate prepifg <config_file>'
    if mpiops.size > 1:  # Over-ride input options if this is an MPI job
        params[cf.PARALLEL] = False

    if params:
        base_ifg_paths = cf.original_ifg_paths(params[cf.IFG_FILE_LIST])
    else:
        # if params not provided read from config file
        if (not params) and (len(sys.argv) < 3):
            print(usage)
            return
        base_ifg_paths, _, params = cf.get_ifg_paths(sys.argv[2])

    base_ifg_paths.append(params[cf.DEM_FILE])
    processor = params[cf.PROCESSOR]  # roipac or gamma
    if processor == GAMMA:  # Incidence/elevation only supported for GAMMA
        if params[cf.APS_INCIDENCE_MAP]:
            base_ifg_paths.append(params[cf.APS_INCIDENCE_MAP])
        if params[cf.APS_ELEVATION_MAP]:
            base_ifg_paths.append(params[cf.APS_ELEVATION_MAP])

    mkdir_p(params[cf.OUT_DIR])  # create output dir

    process_base_ifgs_paths = np.array_split(base_ifg_paths,
                                             mpiops.size)[mpiops.rank]
    if processor == ROIPAC:
        roipac_prepifg(process_base_ifgs_paths, params)
    elif processor == GAMMA:
        gamma_prepifg(process_base_ifgs_paths, params)
    else:
        raise prepifg.PreprocessError(
            'Processor must be ROI_PAC (0) or GAMMA (1)')
    log.info("Finished prepifg")
Exemplo n.º 7
0
    def setUpClass(cls):

        cls.serial_dir = tempfile.mkdtemp()
        cls.parallel_dir = tempfile.mkdtemp()
        unw_paths = glob.glob(os.path.join(SML_TEST_GAMMA, "*_utm.unw"))

        # read in the params
        _, _, params = cf.get_ifg_paths(TEST_CONF_GAMMA)
        params[cf.OUT_DIR] = cls.serial_dir
        params[cf.PARALLEL] = False

        shared.mkdir_p(cls.serial_dir)
        run_prepifg.gamma_prepifg(unw_paths, params)

        params[cf.OUT_DIR] = cls.parallel_dir
        params[cf.PARALLEL] = True
        shared.mkdir_p(cls.parallel_dir)
        run_prepifg.gamma_prepifg(unw_paths, params)
Exemplo n.º 8
0
    def setUpClass(cls):

        params = cf.get_config_params(TEST_CONF_ROIPAC)
        cls.temp_out_dir = tempfile.mkdtemp()
        sys.argv = ['run_prepifg.py', TEST_CONF_ROIPAC]
        params[cf.OUT_DIR] = cls.temp_out_dir
        params[cf.TMPDIR] = os.path.join(cls.temp_out_dir, cf.TMPDIR)
        shared.mkdir_p(params[cf.TMPDIR])
        params[cf.REF_EST_METHOD] = 2
        run_prepifg.main(params)
        cls.params = params
        xlks, ylks, crop = cf.transform_params(params)
        base_ifg_paths = cf.original_ifg_paths(params[cf.IFG_FILE_LIST])
        dest_paths = cf.get_dest_paths(base_ifg_paths, crop, params, xlks)
        ifgs = common.pre_prepare_ifgs(dest_paths, params)
        refx, refy = run_pyrate._ref_pixel_calc(dest_paths, params)
        pyrate.orbital.remove_orbital_error(ifgs, params)
        ifgs = prepare_ifgs_without_phase(dest_paths, params)
        _, cls.ifgs = rpe.estimate_ref_phase(ifgs, params, refx, refy)
        r_dist = RDist(ifgs[0])()
        # Calculate interferogram noise
        cls.maxvar = [cvd(i, params, r_dist, calc_alpha=True,
                          save_acg=True, write_vals=True)[0] for i in ifgs]
        cls.vcmt = get_vcmt(ifgs, cls.maxvar)
Exemplo n.º 9
0
    def setUpClass(cls):
        params = cf.get_config_params(TEST_CONF_ROIPAC)
        cls.temp_out_dir = tempfile.mkdtemp()

        sys.argv = ['run_prepifg.py', TEST_CONF_ROIPAC]
        params[cf.OUT_DIR] = cls.temp_out_dir
        params[cf.TMPDIR] = os.path.join(params[cf.OUT_DIR], cf.TMPDIR)
        shared.mkdir_p(params[cf.TMPDIR])
        run_prepifg.main(params)

        params[cf.REF_EST_METHOD] = 2

        xlks, _, crop = cf.transform_params(params)

        base_ifg_paths = cf.original_ifg_paths(params[cf.IFG_FILE_LIST])

        dest_paths = cf.get_dest_paths(base_ifg_paths, crop, params, xlks)

        # start run_pyrate copy
        ifgs = pre_prepare_ifgs(dest_paths, params)
        mst_grid = tests.common.mst_calculation(dest_paths, params)

        refx, refy = run_pyrate._ref_pixel_calc(dest_paths, params)

        # Estimate and remove orbit errors
        pyrate.orbital.remove_orbital_error(ifgs, params)
        ifgs = prepare_ifgs_without_phase(dest_paths, params)

        _, ifgs = rpe.estimate_ref_phase(ifgs, params, refx, refy)
        r_dist = vcm_module.RDist(ifgs[0])()
        maxvar = [vcm_module.cvd(i, params, r_dist)[0] for i in ifgs]
        vcmt = vcm_module.get_vcmt(ifgs, maxvar)

        # Calculate linear rate map
        params[cf.PARALLEL] = 1
        cls.rate, cls.error, cls.samples = tests.common.calculate_linear_rate(
            ifgs, params, vcmt, mst_mat=mst_grid)

        params[cf.PARALLEL] = 2
        cls.rate_2, cls.error_2, cls.samples_2 = \
            tests.common.calculate_linear_rate(ifgs, params, vcmt,
                                               mst_mat=mst_grid)

        params[cf.PARALLEL] = 0
        # Calculate linear rate map
        cls.rate_s, cls.error_s, cls.samples_s = \
            tests.common.calculate_linear_rate(ifgs, params, vcmt,
                                               mst_mat=mst_grid)

        matlab_linrate_dir = os.path.join(SML_TEST_DIR, 'matlab_linrate')

        cls.rate_matlab = np.genfromtxt(os.path.join(matlab_linrate_dir,
                                                     'stackmap.csv'),
                                        delimiter=',')
        cls.error_matlab = np.genfromtxt(os.path.join(matlab_linrate_dir,
                                                      'errormap.csv'),
                                         delimiter=',')

        cls.samples_matlab = np.genfromtxt(os.path.join(
            matlab_linrate_dir, 'coh_sta.csv'),
                                           delimiter=',')