Пример #1
0
    def test_orbital_correction_legacy_equality_orbfit_method_2(self):
        correct._copy_mlooked(self.params)
        correct._create_ifg_dict(self.params)
        remove_orbital_error(self.new_data_paths, self.params)

        onlyfiles = [f for f in os.listdir(SML_TEST_LEGACY_ORBITAL_DIR)
                     if os.path.isfile(os.path.join(SML_TEST_LEGACY_ORBITAL_DIR, f))
                     and f.endswith('.csv') and f.__contains__('_method2_')]

        count = 0
        for i, f in enumerate(onlyfiles):
            legacy_phase_data = np.genfromtxt(os.path.join(
                SML_TEST_LEGACY_ORBITAL_DIR, f), delimiter=',')
            for k, j in enumerate(self.new_data_paths):
                if os.path.basename(j).split('_unw.')[0] == os.path.basename(f).split('_method2_')[1].split('.')[0]:
                    count += 1
                    ifg = Ifg(j)
                    ifg.open()
                    # all numbers equal
                    # Note this changed as the nodata mask in the gdal_python.gdal_average changed to nan from 0
                    # np.testing.assert_array_almost_equal(legacy_phase_data, ifg.phase_data, decimal=3)
                    # number of nans must equal
                    assert np.sum(np.isnan(legacy_phase_data)) == np.sum(np.isnan(ifg.phase_data))

        # ensure that we have expected number of matches
        assert count == len(self.new_data_paths)
Пример #2
0
    def test_orbital_error_method2_dummy(self):
        """
        does not test anything except that the method is working
        """
        # change to orbital error correction method 2
        self.params[cf.ORBITAL_FIT_METHOD] = NETWORK_METHOD
        self.params[cf.ORBITAL_FIT_LOOKS_X] = 2
        self.params[cf.ORBITAL_FIT_LOOKS_Y] = 2
        correct._copy_mlooked(self.params)
        correct._create_ifg_dict(self.params)
        remove_orbital_error(self.new_data_paths, self.params)

        onlyfiles = [f for f in os.listdir(SML_TEST_LEGACY_ORBITAL_DIR)
                     if os.path.isfile(os.path.join(SML_TEST_LEGACY_ORBITAL_DIR, f))
                     and f.endswith('.csv') and f.__contains__('_method2_')]

        count = 0
        for i, f in enumerate(onlyfiles):
            legacy_phase_data = np.genfromtxt(os.path.join(SML_TEST_LEGACY_ORBITAL_DIR, f), delimiter=',')
            for k, j in enumerate(self.new_data_paths):
                if os.path.basename(j).split('_unw.')[0] == os.path.basename(f).split('_method2_')[1].split('.')[0]:
                    count += 1
                    ifg = Ifg(j)
                    ifg.open()
                    # number of nans must equal
                    assert np.sum(np.isnan(legacy_phase_data)) == np.sum(np.isnan(ifg.phase_data))

        # ensure that we have expected number of matches
        assert count == len(self.new_data_paths)
Пример #3
0
def test_vcm_legacy_vs_mpi(mpisync, tempdir, roipac_or_gamma_conf):

    params = configuration.Configuration(roipac_or_gamma_conf).__dict__
    LEGACY_VCM_DIR = os.path.join(SML_TEST_DIR, 'vcm')
    legacy_vcm = np.genfromtxt(os.path.join(LEGACY_VCM_DIR, 'vcmt.csv'),
                               delimiter=',')
    tmpdir = Path(mpiops.run_once(tempdir))
    params[C.OUT_DIR] = tmpdir.joinpath('out')
    params[C.PARALLEL] = 0
    output_conf = Path(tmpdir).joinpath('conf.cfg')
    pyrate.configuration.write_config_file(params=params,
                                           output_conf_file=output_conf)
    params = configuration.Configuration(output_conf).__dict__

    # dest_paths = [p.sampled_path for p in params[cf.INTERFEROGRAM_FILES]]
    # run conv2tif and prepifg, create the dest_paths files
    conv2tif.main(params)
    params = configuration.Configuration(output_conf).__dict__
    prepifg.main(params)
    params = configuration.Configuration(output_conf).__dict__
    params[C.ORBFIT_OFFSET] = True
    correct._copy_mlooked(params=params)
    correct._update_params_with_tiles(params)
    correct._create_ifg_dict(params=params)
    pyrate.core.refpixel.ref_pixel_calc_wrapper(params)
    pyrate.core.orbital.orb_fit_calc_wrapper(params)
    pyrate.core.ref_phs_est.ref_phase_est_wrapper(params)

    maxvar, vcmt = pyrate.core.covariance.maxvar_vcm_calc_wrapper(params)

    # phase data after ref pixel has changed due to commit bf2f7ebd
    # Legacy tests won't match anymore
    np.testing.assert_array_almost_equal(maxvar, legacy_maxvar, decimal=4)
    np.testing.assert_array_almost_equal(legacy_vcm, vcmt, decimal=3)
    mpiops.run_once(shutil.rmtree, tmpdir)
Пример #4
0
 def test_dem_error_used_from_disc_on_rerun(self):
     correct._copy_mlooked(self.params)
     correct._update_params_with_tiles(self.params)
     times_written = self.__run_once()
     assert len(times_written) == len(self.ifg_paths)
     times_written_1 = self.__run_once()
     np.testing.assert_array_equal(times_written_1, times_written)
Пример #5
0
def test_plot_closure(mexico_cropa_params):
    config = Configuration(MEXICO_CROPA_CONF)
    params = config.__dict__
    check_call(f"mpirun -n 3 pyrate prepifg -f {MEXICO_CROPA_CONF}",
               shell=True)

    correct._copy_mlooked(params)
    correct.__validate_correct_steps(params)
    # house keeping
    correct._update_params_with_tiles(params)
    correct._create_ifg_dict(params)
    params[C.REFX_FOUND], params[
        C.REFY_FOUND] = correct.ref_pixel_calc_wrapper(params)

    # run through the correct steps in user specified sequence
    for step in steps:
        if step == 'phase_closure':
            correct.correct_steps[step](params, config)
        else:
            correct.correct_steps[step](params)

    closure_plot_file = Path(config.phase_closure_dir).joinpath(
        f'closure_loops_iteration_1_fig_0.png')
    assert closure_plot_file.exists()
    shutil.rmtree(params[C.OUT_DIR], ignore_errors=True)
Пример #6
0
    def setup_class(cls):
        params = Configuration(common.TEST_CONF_ROIPAC).__dict__
        params[cf.TEMP_MLOOKED_DIR] = os.path.join(params[cf.OUT_DIR], cf.TEMP_MLOOKED_DIR)
        conv2tif.main(params)
        prepifg.main(params)

        params[cf.REF_EST_METHOD] = 2

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

        dest_paths, headers = common.repair_params_for_correct_tests(params[cf.OUT_DIR], params)
        correct._copy_mlooked(params)
        copied_dest_paths = [os.path.join(params[cf.TEMP_MLOOKED_DIR], os.path.basename(d)) for d in dest_paths]
        del dest_paths
        # start run_pyrate copy
        ifgs = pre_prepare_ifgs(copied_dest_paths, params)
        mst_grid = tests.common.mst_calculation(copied_dest_paths, params)

        refx, refy = pyrate.core.refpixel.ref_pixel_calc_wrapper(params)

        params[cf.REFX] = refx
        params[cf.REFY] = refy
        params[cf.ORBFIT_OFFSET] = True

        # Estimate and remove orbit errors
        pyrate.core.orbital.remove_orbital_error(ifgs, params)
        ifgs = prepare_ifgs_without_phase(copied_dest_paths, params)
        for ifg in ifgs:
            ifg.close()
        correct._update_params_with_tiles(params)
        _, ifgs = pyrate.core.ref_phs_est.ref_phase_est_wrapper(params)
        ifgs[0].open()
        r_dist = vcm_module.RDist(ifgs[0])()
        ifgs[0].close()
        maxvar = [vcm_module.cvd(i, params, r_dist)[0] for i in copied_dest_paths]
        for ifg in ifgs:
            ifg.open()
        vcmt = vcm_module.get_vcmt(ifgs, maxvar)    
        for ifg in ifgs:
            ifg.close()     
            ifg.open()
        
        # Calculate stacked rate map
        params[cf.PARALLEL] = 1
        cls.rate, cls.error, cls.samples = tests.common.calculate_stack_rate(ifgs, params, vcmt, mst_mat=mst_grid)

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

        stackrate_dir = os.path.join(SML_TEST_DIR, 'stackrate')

        cls.rate_container = np.genfromtxt(os.path.join(stackrate_dir, 'stackmap.csv'), delimiter=',')
        cls.error_container = np.genfromtxt(os.path.join(stackrate_dir, 'errormap.csv'), delimiter=',')
        cls.samples_container = np.genfromtxt(os.path.join(stackrate_dir, 'coh_sta.csv'), delimiter=',')
    
        for ifg in ifgs:
            ifg.close()

        cls.params = params
Пример #7
0
 def setup_class(cls):
     cls.conf = TEST_CONF_GAMMA
     params = Configuration(cls.conf).__dict__
     conv2tif.main(params)
     params = Configuration(cls.conf).__dict__
     prepifg.main(params)
     cls.params = Configuration(cls.conf).__dict__
     correct._copy_mlooked(cls.params)
     correct._create_ifg_dict(cls.params)
Пример #8
0
 def __run_once(self):
     tiles = self.params[cf.TILES]
     mst_files = [Configuration.mst_path(self.params, t.index) for t in tiles]
     correct._copy_mlooked(self.params)
     correct._create_ifg_dict(self.params)
     save_numpy_phase(self.ifg_paths, self.params)
     mst.mst_calc_wrapper(self.params)
     assert all(m.exists() for m in mst_files)
     return [os.stat(o).st_mtime for o in mst_files]
Пример #9
0
 def setup_method(cls):
     cls.conf = TEST_CONF_GAMMA
     params = Configuration(cls.conf).__dict__
     conv2tif.main(params)
     params = Configuration(cls.conf).__dict__
     prepifg.main(params)
     params = Configuration(cls.conf).__dict__
     correct._copy_mlooked(params)
     cls.params = params
Пример #10
0
    def setup_class(cls):
        roipac_params = Configuration(TEST_CONF_ROIPAC).__dict__
        from copy import deepcopy
        params = deepcopy(roipac_params)
        shared.mkdir_p(params[C.TMPDIR])
        params[C.REF_EST_METHOD] = 2
        conv2tif.main(params)
        params = deepcopy(roipac_params)
        prepifg.main(params)
        params = deepcopy(roipac_params)
        base_ifg_paths = [
            c.unwrapped_path for c in params[C.INTERFEROGRAM_FILES]
        ]
        dest_paths = [c.converted_path for c in params[C.INTERFEROGRAM_FILES]]
        params[C.INTERFEROGRAM_FILES] = [
            MultiplePaths(d, params) for d in dest_paths
        ]
        for p in params[C.INTERFEROGRAM_FILES]:  # hack
            p.sampled_path = p.converted_path

        for i in dest_paths:
            Path(i).chmod(
                0o664
            )  # assign write permission as conv2tif output is readonly
        ifgs = common.pre_prepare_ifgs(dest_paths, params)
        correct._copy_mlooked(params)
        correct._update_params_with_tiles(params)
        correct._create_ifg_dict(params)
        pyrate.core.refpixel.ref_pixel_calc_wrapper(params)
        params[C.ORBFIT_OFFSET] = True
        pyrate.core.orbital.remove_orbital_error(ifgs, params)
        ifgs = prepare_ifgs_without_phase(dest_paths, params)
        for ifg in ifgs:
            ifg.close()

        for p in params[C.INTERFEROGRAM_FILES]:  # hack
            p.tmp_sampled_path = p.sampled_path
        _, cls.ifgs = pyrate.core.ref_phs_est.ref_phase_est_wrapper(params)
        ifgs[0].open()
        r_dist = RDist(ifgs[0])()
        ifgs[0].close()
        # Calculate interferogram noise
        cls.maxvar = [
            cvd(i,
                params,
                r_dist,
                calc_alpha=True,
                save_acg=True,
                write_vals=True)[0] for i in dest_paths
        ]
        cls.vcmt = get_vcmt(ifgs, cls.maxvar)
        for ifg in ifgs:
            ifg.close()
        cls.params = params
Пример #11
0
 def setup_method(cls):
     cls.conf = TEST_CONF_GAMMA
     params = Configuration(cls.conf).__dict__
     conv2tif.main(params)
     params = Configuration(cls.conf).__dict__
     prepifg.main(params)
     cls.params = Configuration(cls.conf).__dict__
     correct._copy_mlooked(cls.params)
     correct._create_ifg_dict(cls.params)
     multi_paths = cls.params[cf.INTERFEROGRAM_FILES]
     cls.ifg_paths = [p.tmp_sampled_path for p in multi_paths]
Пример #12
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]
Пример #13
0
    def test_calc_dem_errors(self):
        # validate output of current version of the code with saved files from an independent test run
        # only the reference phase and dem_error are used in this test

        # saved dem_error.tif (expected)
        dem_error_tif_exp = join(dem_error_path, 'dem_error.tif')
        dem = DEM(dem_error_tif_exp)
        dem_error_exp = dem.data
        # run relevant parts of the 'correct' step
        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)
        # subtract the reference phase to enable comparison with a 'normal' pyrate run
        ref_phase_est_wrapper(self.params)
        dem_error_calc_wrapper(self.params)
        # dem_error.tif from this run (result)
        dem_error_tif_res = join(self.params[C.DEM_ERROR_DIR], 'dem_error.tif')
        dem = DEM(dem_error_tif_res)
        dem_error_res = dem.data
        # check equality
        np.testing.assert_allclose(dem_error_exp, dem_error_res)

        # ifg correction files in subdirectory out/dem_error/
        # three different ifgs:
        # ifg1 -> short_baseline_ifg: 20180106-20180319 (ca. 3 m)
        # ifg2 -> long_baseline_ifg: 20180130-20180412(ca. 108 m)
        # ifg3 -> medium_baseline_ifg: 20180412-20180518 (ca. 48 m)
        # load saved files
        dem_error_ifg1_path = join(dem_error_path,
                                   '20180106-20180319_ifg_20_dem_error.npy')
        dem_error_ifg1_exp = np.load(dem_error_ifg1_path)
        dem_error_ifg2_path = join(dem_error_path,
                                   '20180130-20180412_ifg_20_dem_error.npy')
        dem_error_ifg2_exp = np.load(dem_error_ifg2_path)
        dem_error_ifg3_path = join(dem_error_path,
                                   '20180412-20180518_ifg_20_dem_error.npy')
        dem_error_ifg3_exp = np.load(dem_error_ifg3_path)
        # load correction values saved from this run (result)
        dem_error_ifg1_path = Path(self.params[C.DEM_ERROR_DIR]).joinpath(
            '20180106-20180319_ifg_20_dem_error.npy')
        dem_error_ifg1_res = np.load(dem_error_ifg1_path)
        dem_error_ifg2_path = Path(self.params[C.DEM_ERROR_DIR]).joinpath(
            '20180130-20180412_ifg_20_dem_error.npy')
        dem_error_ifg2_res = np.load(dem_error_ifg2_path)
        dem_error_ifg3_path = Path(self.params[C.DEM_ERROR_DIR]).joinpath(
            '20180412-20180518_ifg_20_dem_error.npy')
        dem_error_ifg3_res = np.load(dem_error_ifg3_path)
        # check equality
        np.testing.assert_allclose(dem_error_ifg1_exp, dem_error_ifg1_res)
        np.testing.assert_allclose(dem_error_ifg2_exp, dem_error_ifg2_res)
        np.testing.assert_allclose(dem_error_ifg3_exp, dem_error_ifg3_res)
Пример #14
0
 def setup_method(cls):
     cls.conf = common.TEST_CONF_GAMMA
     params = Configuration(cls.conf).__dict__
     conv2tif.main(params)
     params = Configuration(cls.conf).__dict__
     prepifg.main(params)
     cls.params = Configuration(cls.conf).__dict__
     correct._copy_mlooked(cls.params)
     correct._update_params_with_tiles(cls.params)
     correct._create_ifg_dict(cls.params)
     multi_paths = cls.params[cf.INTERFEROGRAM_FILES]
     cls.ifg_paths = [p.tmp_sampled_path for p in multi_paths]
     cls.ifgs = [shared.Ifg(i) for i in cls.ifg_paths]
     for i in cls.ifgs:
         i.open()
     shared.save_numpy_phase(cls.ifg_paths, cls.params)
     correct.mst_calc_wrapper(cls.params)
Пример #15
0
    def test_orbital_correction_legacy_equality(self):
        from pyrate import correct
        from pyrate.configuration import MultiplePaths

        multi_paths = [MultiplePaths(p, params=self.params) for p in self.ifg_paths]
        for m in multi_paths:  # cheat
            m.sampled_path = m.converted_path

        self.params[cf.INTERFEROGRAM_FILES] = multi_paths
        self.params['rows'], self.params['cols'] = 2, 3
        Path(self.BASE_DIR).joinpath('tmpdir').mkdir(exist_ok=True, parents=True)
        correct._copy_mlooked(self.params)
        correct._update_params_with_tiles(self.params)
        correct._create_ifg_dict(self.params)
        correct._copy_mlooked(self.params)
        pyrate.core.orbital.orb_fit_calc_wrapper(self.params)

        onlyfiles = [f for f in os.listdir(SML_TEST_LEGACY_ORBITAL_DIR)
            if os.path.isfile(os.path.join(SML_TEST_LEGACY_ORBITAL_DIR, f))
            and f.endswith('.csv') and f.__contains__('_method1_')]

        count = 0
        for i, f in enumerate(onlyfiles):
            ifg_data = np.genfromtxt(os.path.join(SML_TEST_LEGACY_ORBITAL_DIR, f), delimiter=',')
            for k, j in enumerate([m.tmp_sampled_path for m in multi_paths]):
                ifg = Ifg(j)
                ifg.open()
                print(f)
                print(j)
                if os.path.basename(j).split('_ifg.')[0] == os.path.basename(f).split(
                        '_orb_planar_1lks_method1_geo_')[1].split('.')[0]:
                    count += 1
                    # all numbers equal
                    np.testing.assert_array_almost_equal(ifg_data, ifg.phase_data, decimal=2)

                    # means must also be equal
                    assert np.nanmean(ifg_data) == pytest.approx(np.nanmean(ifg.phase_data), abs=1e-2)

                    # number of nans must equal
                    assert np.sum(np.isnan(ifg_data)) == np.sum(np.isnan(ifg.phase_data))
                ifg.close()

        # ensure that we have expected number of matches
        assert count == len(self.ifg_paths)
Пример #16
0
 def __run_once(self):
     ref_phs_file = Configuration.ref_phs_file(self.params)
     correct._copy_mlooked(self.params)
     multi_paths = self.params[cf.INTERFEROGRAM_FILES]
     ifg_paths = [p.tmp_sampled_path for p in multi_paths]
     ifgs = [Ifg(i) for i in ifg_paths]
     self.params[cf.REFX_FOUND], self.params[
         cf.REFY_FOUND] = ref_pixel_calc_wrapper(self.params)
     correct._create_ifg_dict(self.params)
     ref_phase_est_wrapper(self.params)
     for i in ifgs:
         i.open()
     phase_prev = [i.phase_data for i in ifgs]
     # assert ref_ph_file present
     assert ref_phs_file.exists()
     time_written = os.stat(ref_phs_file).st_mtime
     for i in ifgs:
         i.close()
     return phase_prev, time_written
Пример #17
0
 def setup_class(cls):
     cls.params = Configuration(common.MEXICO_CROPA_CONF).__dict__
     # run prepifg
     prepifg.main(cls.params)
     # copy IFGs to temp folder
     correct._copy_mlooked(cls.params)
     # read radar azimuth, range and dem tif files
     geom_files = Configuration.geometry_files(cls.params)
     rdc_az_file = geom_files['rdc_azimuth']
     geom_az = Geometry(rdc_az_file)
     cls.az = geom_az.data
     rdc_rg_file = geom_files['rdc_range']
     geom_rg = Geometry(rdc_rg_file)
     cls.rg = geom_rg.data
     dem_file = join(cls.params[C.GEOMETRY_DIR], 'dem.tif')
     dem_data = DEM(dem_file)
     cls.dem = dem_data.data
     # calc bperp using pyrate funcs
     cls.pbperp = cls.pyrate_bperp()
Пример #18
0
    def test_ref_phase_used_from_disc_on_rerun(self, ref_est_method):
        self.params = Configuration(self.conf).__dict__
        self.params[C.REF_EST_METHOD] = ref_est_method
        correct._copy_mlooked(self.params)
        correct._update_params_with_tiles(self.params)

        phase_prev, time_written = self.__run_once()

        # run again
        phase_now, time_written_1 = self.__run_once()

        # and once more
        phase_again, time_written_2 = self.__run_once()

        # assert no new file was written
        assert time_written_1 == time_written
        assert time_written_2 == time_written

        # assert phase data is unchanged after applying ref_ph correction from disc
        np.testing.assert_array_equal(phase_now, phase_prev)
        np.testing.assert_array_equal(phase_now, phase_again)
Пример #19
0
    def test_orb_error_multiple_run_does_not_change_phase_data(self, orbfit_method, orbfit_degrees):
        self.params[cf.ORBITAL_FIT_METHOD] = orbfit_method
        self.params[cf.ORBITAL_FIT_DEGREE] = orbfit_degrees
        remove_orbital_error(self.ifg_paths, self.params)
        ifgs = [Ifg(i) for i in self.ifg_paths]
        for i in ifgs:
            i.open()

        phase_prev = [i.phase_data for i in ifgs]

        # orb correct once more
        correct._copy_mlooked(self.params)
        remove_orbital_error(self.ifg_paths, self.params)

        # and again
        correct._copy_mlooked(self.params)
        remove_orbital_error(self.ifg_paths, self.params)
        ifgs = [Ifg(i) for i in self.ifg_paths]
        for i in ifgs:
            i.open()
        phase_now = [i.phase_data for i in ifgs]
        np.testing.assert_array_equal(phase_now, phase_prev)
Пример #20
0
    def setup_class(cls):
        params = Configuration(common.TEST_CONF_ROIPAC).__dict__
        params[cf.TEMP_MLOOKED_DIR] = os.path.join(params[cf.OUT_DIR],
                                                   cf.TEMP_MLOOKED_DIR)
        conv2tif.main(params)
        prepifg.main(params)

        params[cf.REF_EST_METHOD] = 2

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

        dest_paths, headers = common.repair_params_for_correct_tests(
            params[cf.OUT_DIR], params)
        correct._copy_mlooked(params)
        copied_dest_paths = [
            os.path.join(params[cf.TEMP_MLOOKED_DIR], os.path.basename(d))
            for d in dest_paths
        ]
        del dest_paths
        # start run_pyrate copy
        ifgs = common.pre_prepare_ifgs(copied_dest_paths, params)
        mst_grid = common.mst_calculation(copied_dest_paths, params)
        refx, refy = pyrate.core.refpixel.ref_pixel_calc_wrapper(params)

        params[cf.REFX] = refx
        params[cf.REFY] = refy
        params[cf.ORBFIT_OFFSET] = True

        # Estimate and remove orbit errors
        pyrate.core.orbital.remove_orbital_error(ifgs, params)
        ifgs = common.prepare_ifgs_without_phase(copied_dest_paths, params)
        for ifg in ifgs:
            ifg.close()

        correct._update_params_with_tiles(params)
        _, ifgs = pyrate.core.ref_phs_est.ref_phase_est_wrapper(params)
        ifgs[0].open()
        r_dist = covariance.RDist(ifgs[0])()
        ifgs[0].close()
        # Calculate interferogram noise
        maxvar = [
            covariance.cvd(i, params, r_dist)[0] for i in copied_dest_paths
        ]
        for ifg in ifgs:
            ifg.open()
        vcmt = covariance.get_vcmt(ifgs, maxvar)
        for ifg in ifgs:
            ifg.close()
            ifg.open()
            ifg.nodata_value = 0.0

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

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

        # copy legacy data
        SML_TIME_SERIES_DIR = os.path.join(common.SML_TEST_DIR, 'time_series')
        tsincr_path = os.path.join(SML_TIME_SERIES_DIR,
                                   'ts_incr_interp0_method2.csv')
        ts_incr = np.genfromtxt(tsincr_path)

        tscum_path = os.path.join(SML_TIME_SERIES_DIR,
                                  'ts_cum_interp0_method2.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')
        cls.params = params
Пример #21
0
 def setup_class(cls):
     cls.params = Configuration(common.MEXICO_CROPA_CONF).__dict__
     # run prepifg
     prepifg.main(cls.params)
     # copy IFGs to temp folder
     correct._copy_mlooked(cls.params)
Пример #22
0
    def setup_class(cls):
        gamma_conf = common.TEST_CONF_GAMMA
        from tests.common import manipulate_test_conf
        rate_types = ['stack_rate', 'stack_error', 'stack_samples']
        cls.tif_dir = Path(tempfile.mkdtemp())
        params = manipulate_test_conf(gamma_conf, cls.tif_dir)

        from pyrate.configuration import Configuration
        # change the required params
        params[C.PROCESSES] = 4
        params[C.PROCESSOR] = 1  # gamma
        params[C.IFG_FILE_LIST] = os.path.join(common.GAMMA_SML_TEST_DIR,
                                               'ifms_17')
        params[C.PARALLEL] = 1
        params[C.APS_CORRECTION] = 0
        params[C.REFX], params[C.REFY] = -1, -1
        rows, cols = params["rows"], params["cols"]

        output_conf_file = 'gamma.conf'
        output_conf = cls.tif_dir.joinpath(output_conf_file).as_posix()
        pyrate.configuration.write_config_file(params=params,
                                               output_conf_file=output_conf)

        config = Configuration(output_conf)
        params = config.__dict__

        common.sub_process_run(f"pyrate conv2tif -f {output_conf}")
        common.sub_process_run(f"pyrate prepifg -f {output_conf}")

        cls.sampled_paths = [
            p.tmp_sampled_path for p in params[C.INTERFEROGRAM_FILES]
        ]

        ifgs = common.small_data_setup()
        correct._copy_mlooked(params)
        tiles = pyrate.core.shared.get_tiles(cls.sampled_paths[0], rows, cols)
        correct.correct_ifgs(config)
        pyrate.main.timeseries(config)
        pyrate.main.stack(config)
        cls.refpixel_p, cls.maxvar_p, cls.vcmt_p = \
            (params[C.REFX], params[C.REFY]), params[C.MAXVAR], params[
                C.VCMT]
        cls.mst_p = common.reconstruct_mst(ifgs[0].shape, tiles,
                                           params[C.OUT_DIR])
        cls.rate_p, cls.error_p, cls.samples_p = \
            [common.reconstruct_stack_rate(ifgs[0].shape, tiles, params[C.TMPDIR], t) for t in rate_types]

        common.remove_tifs(params[C.OUT_DIR])

        # now create the non parallel version
        cls.tif_dir_s = Path(tempfile.mkdtemp())
        params = manipulate_test_conf(gamma_conf, cls.tif_dir_s)
        params[C.PROCESSES] = 4
        params[C.PROCESSOR] = 1  # gamma
        params[C.IFG_FILE_LIST] = os.path.join(common.GAMMA_SML_TEST_DIR,
                                               'ifms_17')
        params[C.PARALLEL] = 0
        params[C.APS_CORRECTION] = 0
        params[C.REFX], params[C.REFY] = -1, -1
        output_conf_file = 'gamma.conf'
        output_conf = cls.tif_dir_s.joinpath(output_conf_file).as_posix()
        pyrate.configuration.write_config_file(params=params,
                                               output_conf_file=output_conf)
        config = Configuration(output_conf)
        params = config.__dict__

        common.sub_process_run(f"pyrate conv2tif -f {output_conf}")
        common.sub_process_run(f"pyrate prepifg -f {output_conf}")

        correct._copy_mlooked(params)
        correct.correct_ifgs(config)
        pyrate.main.timeseries(config)
        pyrate.main.stack(config)
        cls.refpixel, cls.maxvar, cls.vcmt = \
            (params[C.REFX], params[C.REFY]), params[C.MAXVAR], params[
                C.VCMT]
        cls.mst = common.reconstruct_mst(ifgs[0].shape, tiles,
                                         params[C.OUT_DIR])
        cls.rate, cls.error, cls.samples = \
            [common.reconstruct_stack_rate(ifgs[0].shape, tiles, params[C.TMPDIR], t) for t in rate_types]
        cls.params = params