Exemplo n.º 1
0
    def test_covariance_17ifgs(self):
        # From Matlab Pirate after raw data import
        # (no reference pixel correction and units in radians)
        exp_maxvar = [
            5.6149, 8.7710, 2.9373, 0.3114, 12.9931, 2.0459, 0.4236, 2.1243,
            0.4745, 0.6725, 0.8333, 3.8232, 3.3052, 2.4925, 16.0159, 2.8025,
            1.4345
        ]

        exp_alpha = [
            0.0356, 0.1601, 0.5128, 0.5736, 0.0691, 0.1337, 0.2333, 0.3202,
            1.2338, 0.4273, 0.9024, 0.1280, 0.3585, 0.1599, 0.0110, 0.1287,
            0.0676
        ]

        act_maxvar = []
        act_alpha = []
        for i in self.ifgs:

            if bool((i.phase_data == 0).all()) is True:
                raise Exception("All zero")

            maxvar, alpha = cvd(i, self.params, calc_alpha=True)
            self.assertTrue(maxvar is not None)
            self.assertTrue(alpha is not None)

            act_maxvar.append(maxvar)
            act_alpha.append(alpha)

        assert_array_almost_equal(act_maxvar, exp_maxvar, decimal=3)

        # This test fails for greater than 1 decimal place.
        # Discrepancies observed in distance calculations.
        assert_array_almost_equal(act_alpha, exp_alpha, decimal=1)
Exemplo n.º 2
0
    def setUpClass(cls):
        params = cf.get_config_params(common.TEST_CONF_ROIPAC)
        cls.temp_out_dir = tempfile.mkdtemp()
        sys.argv = ['run_prepifg.py', common.TEST_CONF_ROIPAC]
        params[cf.OUT_DIR] = cls.temp_out_dir
        run_prepifg.main(params)

        params[cf.REF_EST_METHOD] = 2

        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)
        # start run_pyrate copy
        ifgs = shared.pre_prepare_ifgs(dest_paths, params)
        mst_grid = 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 = common.prepare_ifgs_without_phase(dest_paths, params)
        _, ifgs = rpe.estimate_ref_phase(ifgs, params, refx, refy)

        maxvar = [vcm.cvd(i, params)[0] for i in ifgs]
        vcmt = vcm.get_vcmt(ifgs, maxvar)

        params[cf.TIME_SERIES_METHOD] = 1
        params[cf.PARALLEL] = 0
        # Calculate time series
        cls.tsincr_0, cls.tscum_0, _ = common.calculate_time_series(
            ifgs, params, vcmt, mst=mst_grid)

        params[cf.PARALLEL] = 1
        cls.tsincr_1, cls.tscum_1, cls.tsvel_1 = \
            common.calculate_time_series(ifgs, params, vcmt, mst=mst_grid)

        params[cf.PARALLEL] = 2
        cls.tsincr_2, cls.tscum_2, cls.tsvel_2 = \
            common.calculate_time_series(ifgs, params, vcmt, mst=mst_grid)

        # load the matlab data
        ts_dir = os.path.join(common.SML_TEST_DIR, 'matlab_time_series')
        tsincr_path = os.path.join(ts_dir, 'ts_incr_interp0_method1.csv')
        ts_incr = np.genfromtxt(tsincr_path)

        # the matlab tsvel return is a bit pointless and not tested here
        # tserror is not returned
        # tserr_path = os.path.join(SML_TIME_SERIES_DIR,
        # 'ts_error_interp0_method1.csv')
        # ts_err = np.genfromtxt(tserr_path, delimiter=',')
        tscum_path = os.path.join(ts_dir, 'ts_cum_interp0_method1.csv')
        ts_cum = np.genfromtxt(tscum_path)
        cls.ts_incr = np.reshape(ts_incr,
                                 newshape=cls.tsincr_0.shape,
                                 order='F')
        cls.ts_cum = np.reshape(ts_cum, newshape=cls.tscum_0.shape, order='F')
Exemplo n.º 3
0
    def test_covariance_basic(self):
        ifgs = small5_ifgs()

        for i in ifgs:
            i.open()

            if bool((i.phase_data == 0).all()) is True:
                raise Exception("All zero")

            maxvar, alpha = cvd(i, self.params, calc_alpha=True)
            self.assertTrue(maxvar is not None)
            self.assertTrue(alpha is not None)
            print("maxvar: %s, alpha: %s" % (maxvar, alpha))
Exemplo n.º 4
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.REF_EST_METHOD] = 2
        run_prepifg.main(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 = shared.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)
        _, ifgs = rpe.estimate_ref_phase(ifgs, params, refx, refy)

        # Calculate interferogram noise
        cls.maxvar = [cvd(i, params)[0] for i in ifgs]
        cls.vcmt = get_vcmt(ifgs, cls.maxvar)
Exemplo n.º 5
0
def maxvar_vcm_calc(ifg_paths, params, preread_ifgs):
    """
    MPI capable maxvar and vcmt computation.

    :param ifg_paths: List of interferogram paths
    :param params: Parameters dictionary corresponding to config file
    :param preread_ifgs: Dictionary containing interferogram characteristics for efficient computing

    :return maxvar: Array of shape (nifgs, 1)
    :return vcmt: Array of shape (nifgs, nifgs)
    """
    log.info('Calculating maxvar and vcm')
    process_indices = mpiops.array_split(range(len(ifg_paths)))
    prcs_ifgs = mpiops.array_split(ifg_paths)
    process_maxvar = []
    for n, i in enumerate(prcs_ifgs):
        log.info('Calculating maxvar for {} of process ifgs {} of '
                 'total {}'.format(n + 1, len(prcs_ifgs), len(ifg_paths)))
        # TODO: cvd calculation is still pretty slow - revisit
        process_maxvar.append(vcm_module.cvd(i, params)[0])
    if mpiops.rank == MASTER_PROCESS:
        maxvar = np.empty(len(ifg_paths), dtype=np.float64)
        maxvar[process_indices] = process_maxvar
        for i in range(1, mpiops.size):  # pragma: no cover
            rank_indices = mpiops.array_split(range(len(ifg_paths)), i)
            this_process_ref_phs = np.empty(len(rank_indices),
                                            dtype=np.float64)
            mpiops.comm.Recv(this_process_ref_phs, source=i, tag=i)
            maxvar[rank_indices] = this_process_ref_phs
    else:  # pragma: no cover
        maxvar = np.empty(len(ifg_paths), dtype=np.float64)
        mpiops.comm.Send(np.array(process_maxvar, dtype=np.float64),
                         dest=MASTER_PROCESS,
                         tag=mpiops.rank)

    maxvar = mpiops.comm.bcast(maxvar, root=0)
    vcmt = mpiops.run_once(vcm_module.get_vcmt, preread_ifgs, maxvar)
    return maxvar, vcmt
Exemplo n.º 6
0
def test_timeseries_linrate_mpi(mpisync, tempdir, modify_config,
                                ref_est_method, row_splits, col_splits,
                                get_crop, orbfit_lks, orbfit_method,
                                orbfit_degrees):
    params = modify_config
    outdir = mpiops.run_once(tempdir)
    params[cf.OUT_DIR] = outdir
    params[cf.TMPDIR] = os.path.join(params[cf.OUT_DIR], cf.TMPDIR)
    params[cf.DEM_HEADER_FILE] = SML_TEST_DEM_HDR_GAMMA
    params[cf.REF_EST_METHOD] = ref_est_method
    params[cf.IFG_CROP_OPT] = get_crop
    params[cf.ORBITAL_FIT_LOOKS_Y] = orbfit_lks
    params[cf.ORBITAL_FIT_LOOKS_X] = orbfit_lks
    params[cf.ORBITAL_FIT_METHOD] = orbfit_method
    params[cf.ORBITAL_FIT_DEGREE] = orbfit_degrees
    xlks, ylks, crop = cf.transform_params(params)
    if xlks * col_splits > 45 or ylks * row_splits > 70:
        print('skipping test because lks and col_splits are not compatible')
        return

    # skip some tests in travis to run CI faster
    if TRAVIS and (xlks % 2 or row_splits % 2 or col_splits % 2
                   or orbfit_lks % 2):
        print('Skipping in travis env for faster CI run')
        return
    print("xlks={}, ref_est_method={}, row_splits={}, col_splits={}, "
          "get_crop={}, orbfit_lks={}, orbfit_method={}, "
          "rank={}".format(xlks, ref_est_method, row_splits, col_splits,
                           get_crop, orbfit_lks, orbfit_method, orbfit_degrees,
                           mpiops.rank))

    base_unw_paths = cf.original_ifg_paths(params[cf.IFG_FILE_LIST])
    # dest_paths are tifs that have been geotif converted and multilooked
    dest_paths = cf.get_dest_paths(base_unw_paths, crop, params, xlks)

    # run prepifg, create the dest_paths files
    if mpiops.rank == 0:
        run_prepifg.gamma_prepifg(base_unw_paths, params)

    mpiops.comm.barrier()

    (refpx,
     refpy), maxvar, vcmt = run_pyrate.process_ifgs(ifg_paths=dest_paths,
                                                    params=params,
                                                    rows=row_splits,
                                                    cols=col_splits)

    tiles = mpiops.run_once(run_pyrate.get_tiles,
                            dest_paths[0],
                            rows=row_splits,
                            cols=col_splits)
    postprocessing.postprocess_linrate(row_splits, col_splits, params)
    postprocessing.postprocess_timeseries(row_splits, col_splits, params)
    ifgs_mpi_out_dir = params[cf.OUT_DIR]
    ifgs_mpi = small_data_setup(datafiles=dest_paths)

    # single process timeseries/linrate calculation
    if mpiops.rank == 0:
        params_old = modify_config
        params_old[cf.OUT_DIR] = tempdir()
        params_old[cf.REF_EST_METHOD] = ref_est_method
        params_old[cf.IFG_CROP_OPT] = get_crop
        params_old[cf.ORBITAL_FIT_LOOKS_Y] = orbfit_lks
        params_old[cf.ORBITAL_FIT_LOOKS_X] = orbfit_lks
        params_old[cf.ORBITAL_FIT_METHOD] = orbfit_method
        params_old[cf.ORBITAL_FIT_DEGREE] = orbfit_degrees
        xlks, ylks, crop = cf.transform_params(params_old)
        base_unw_paths = cf.original_ifg_paths(params_old[cf.IFG_FILE_LIST])
        dest_paths = cf.get_dest_paths(base_unw_paths, crop, params_old, xlks)
        run_prepifg.gamma_prepifg(base_unw_paths, params_old)

        ifgs = shared.pre_prepare_ifgs(dest_paths, params_old)
        mst_grid = tests.common.mst_calculation(dest_paths, params_old)
        refy, refx = refpixel.ref_pixel(ifgs, params_old)
        assert (refx == refpx) and (refy == refpy)  # both must match
        pyrate.orbital.remove_orbital_error(ifgs, params_old)
        ifgs = common.prepare_ifgs_without_phase(dest_paths, params_old)
        rpe.estimate_ref_phase(ifgs, params_old, refx, refy)
        ifgs = shared.pre_prepare_ifgs(dest_paths, params_old)
        maxvar_s = [vcm.cvd(i, params_old)[0] for i in ifgs]
        vcmt_s = vcm.get_vcmt(ifgs, maxvar)
        tsincr, tscum, _ = tests.common.compute_time_series(
            ifgs, mst_grid, params, vcmt)
        rate, error, samples = tests.common.calculate_linear_rate(
            ifgs, params_old, vcmt, mst_grid)
        mst_mpi = reconstruct_mst(ifgs[0].shape, tiles, params[cf.TMPDIR])
        np.testing.assert_array_almost_equal(mst_grid, mst_mpi)
        tsincr_mpi, tscum_mpi = reconstruct_times_series(
            ifgs[0].shape, tiles, params[cf.TMPDIR])

        rate_mpi, error_mpi, samples_mpi = \
            [reconstruct_linrate(ifgs[0].shape, tiles, params[cf.TMPDIR], t)
             for t in ['linrate', 'linerror', 'linsamples']]
        np.testing.assert_array_almost_equal(maxvar, maxvar_s)
        np.testing.assert_array_almost_equal(vcmt, vcmt_s)
        for i, j in zip(ifgs, ifgs_mpi):
            np.testing.assert_array_almost_equal(i.phase_data, j.phase_data)
        np.testing.assert_array_almost_equal(tsincr, tsincr_mpi, decimal=4)
        np.testing.assert_array_almost_equal(tscum, tscum_mpi, decimal=4)
        np.testing.assert_array_almost_equal(rate, rate_mpi, decimal=4)
        np.testing.assert_array_almost_equal(error, error_mpi, decimal=4)
        np.testing.assert_array_almost_equal(samples, samples_mpi, decimal=4)

        # assert linear rate output tifs are same
        _tifs_same(ifgs_mpi_out_dir, params_old[cf.OUT_DIR], 'linrate.tif')
        _tifs_same(ifgs_mpi_out_dir, params_old[cf.OUT_DIR], 'linerror.tif')
        _tifs_same(ifgs_mpi_out_dir, params_old[cf.OUT_DIR], 'linsamples.tif')

        # assert time series output tifs are same
        epochlist = algorithm.get_epochs(ifgs)[0]

        for i in range(tsincr.shape[2]):
            _tifs_same(ifgs_mpi_out_dir, params_old[cf.OUT_DIR],
                       'tsincr' + '_' + str(epochlist.dates[i + 1]) + ".tif")

        # 12 timeseries outputs
        assert i + 1 == tsincr.shape[2]
        shutil.rmtree(ifgs_mpi_out_dir)  # remove mpi out dir
        shutil.rmtree(params_old[cf.OUT_DIR])  # remove serial out dir
Exemplo n.º 7
0
 def setUpClass(cls):
     cls.ifgs = common.small_data_setup()
     cls.params = default_params()
     cls.mstmat = mst.mst_boolean_array(cls.ifgs)
     cls.maxvar = [vcm.cvd(i, cls.params)[0] for i in cls.ifgs]
     cls.vcmt = vcm.get_vcmt(cls.ifgs, cls.maxvar)
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(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 = shared.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)

        maxvar = [vcm_module.cvd(i, params)[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=',')