Пример #1
0
 def __get_files_from_attr(self, attr, input_type=InputTypes.IFG):
     val = self.__getattribute__(attr)
     files = parse_namelist(val)
     return [
         MultiplePaths(p, self.__dict__, input_type=input_type)
         for p in files
     ]
Пример #2
0
    def test_get_epochs(self):
        def str2date(s):
            segs = s[:4], s[4:6], s[6:]  # year, month, day
            return date(*[int(sg) for sg in segs])

        raw_date = [
            '20060619', '20060828', '20061002', '20061106', '20061211',
            '20070115', '20070219', '20070326', '20070430', '20070604',
            '20070709', '20070813', '20070917'
        ]

        exp_dates = [str2date(d) for d in raw_date]
        exp_repeat = [1, 1, 3, 3, 4, 3, 3, 3, 3, 3, 3, 2, 2]
        exp_spans = [
            0, 0.1916, 0.2875, 0.3833, 0.4791, 0.5749, 0.6708, 0.7666, 0.8624,
            0.9582, 1.0541, 1.1499, 1.2457
        ]

        ifms = join(SML_TEST_TIF, "ifms_17")
        ifgs = [Ifg(join(SML_TEST_TIF, p)) for p in parse_namelist(ifms)]
        for i in ifgs:
            i.open()

        epochs = get_epochs(ifgs)[0]

        self.assertTrue((exp_dates == epochs.dates).all())
        self.assertTrue((exp_repeat == epochs.repeat).all())
        assert_array_almost_equal(exp_spans, epochs.spans, decimal=4)
Пример #3
0
    def test_parse_namelist():
        nl = join(SML_TEST_TIF, 'ifms_17')
        result = list(config.parse_namelist(nl))
        assert len(result) == 17
        files = [
            "geo_060619-061002_unw.tif", "geo_060828-061211_unw.tif",
            "geo_061002-070430_unw.tif", "geo_070115-070917_unw.tif",
            "geo_070219-070604_unw.tif"
        ]

        for path in files:
            assert path in result
Пример #4
0
def validate_file_list_values(file_list, no_of_epochs):
    if file_list is None:  # pragma: no cover
        raise ValueError("No value supplied for input file list: " + str(file_list))

    files = parse_namelist(file_list)

    for f in files:
        if not Path(f).exists():  # pragma: no cover
            raise ConfigException(f"{f} does not exist")
        else:
            matches = extract_epochs_from_filename(filename_with_epochs=f)
            if len(matches) < no_of_epochs:  # pragma: no cover
                raise ConfigException(f"the number of epochs in {f} names are less the required number: {no_of_epochs}")
Пример #5
0
def get_header_paths(input_file, slc_file_list):
    """
    Function that matches input GAMMA file names with GAMMA header file names

    :param str input_file: input GAMMA image file.
    :param str slc_dir: GAMMA SLC header file directory
    :return: list of matching header files
    :rtype: list
    """
    f = Path(input_file)
    epochs = extract_epochs_from_filename(f.name)
    header_names = cf.parse_namelist(slc_file_list)
    matches = [hdr for hdr in header_names if any(e in hdr for e in epochs)]
    return matches
Пример #6
0
def get_header_paths(input_file, slc_file_list, slc_dir):
    """
    Function that matches input GAMMA file names with GAMMA header file names

    :param str input_file: input GAMMA image file.
    :param str slc_dir: GAMMA SLC header file directory
    :return: list of matching header files
    :rtype: list
    """
    _, file_name = split(input_file)
    PTN = re.compile(r'\d{8}')  # match 8 digits for the dates
    epochs = PTN.findall(file_name)
    header_names = cf.parse_namelist(slc_file_list)
    matches = [hdr for hdr in header_names if any(e in hdr for e in epochs)]
    return [os.path.join(slc_dir, hdr) for hdr in matches]
Пример #7
0
    def setUpClass(cls):
        cls.tif_dir = tempfile.mkdtemp()
        cls.test_conf = common.TEST_CONF_GAMMA

        # change the required params
        cls.params = Configuration(cls.test_conf).__dict__
        cls.params[cf.OBS_DIR] = common.SML_TEST_GAMMA
        cls.params[cf.PROCESSOR] = 1  # gamma
        file_list = list(
            cf.parse_namelist(os.path.join(common.SML_TEST_GAMMA, 'ifms_17')))
        fd, cls.params[cf.IFG_FILE_LIST] = tempfile.mkstemp(suffix='.conf',
                                                            dir=cls.tif_dir)
        os.close(fd)
        # write a short filelist with only 3 gamma unws
        with open(cls.params[cf.IFG_FILE_LIST], 'w') as fp:
            for f in file_list[:3]:
                fp.write(os.path.join(common.SML_TEST_GAMMA, f) + '\n')
        cls.params[cf.OUT_DIR] = cls.tif_dir
        cls.params[cf.PARALLEL] = 0
        cls.params[cf.REF_EST_METHOD] = 1
        cls.params[cf.DEM_FILE] = common.SML_TEST_DEM_GAMMA
        # base_unw_paths need to be geotiffed and multilooked by run_prepifg
        cls.base_unw_paths = cf.original_ifg_paths(
            cls.params[cf.IFG_FILE_LIST], cls.params[cf.OBS_DIR])
        cls.base_unw_paths.append(common.SML_TEST_DEM_GAMMA)

        # dest_paths are tifs that have been geotif converted and multilooked
        conv2tif.main(cls.params)
        prepifg.main(cls.params)

        cls.dest_paths = [
            Path(cls.tif_dir).joinpath(Path(c.sampled_path).name).as_posix()
            for c in cls.params[cf.INTERFEROGRAM_FILES][:-2]
        ]

        cls.ifgs = common.small_data_setup(datafiles=cls.dest_paths)
Пример #8
0
    def setUpClass(cls):
        cls.tif_dir = tempfile.mkdtemp()
        cls.test_conf = common.TEST_CONF_GAMMA

        # change the required params
        cls.params = Configuration(cls.test_conf).__dict__
        cls.params[cf.OBS_DIR] = common.SML_TEST_GAMMA
        cls.params[cf.PROCESSOR] = 1  # gamma
        file_list = list(
            cf.parse_namelist(os.path.join(common.SML_TEST_GAMMA, 'ifms_17')))
        fd, cls.params[cf.IFG_FILE_LIST] = tempfile.mkstemp(suffix='.conf',
                                                            dir=cls.tif_dir)
        os.close(fd)
        # write a short filelist with only 3 gamma unws
        with open(cls.params[cf.IFG_FILE_LIST], 'w') as fp:
            for f in file_list[:3]:
                fp.write(os.path.join(common.SML_TEST_GAMMA, f) + '\n')
        cls.params[cf.OUT_DIR] = cls.tif_dir
        cls.params[cf.PARALLEL] = 0
        cls.params[cf.REF_EST_METHOD] = 1
        cls.params[cf.DEM_FILE] = common.SML_TEST_DEM_GAMMA
        # base_unw_paths need to be geotiffed and multilooked by run_prepifg
        cls.base_unw_paths = cf.original_ifg_paths(
            cls.params[cf.IFG_FILE_LIST], cls.params[cf.OBS_DIR])
        cls.base_unw_paths.append(common.SML_TEST_DEM_GAMMA)

        xlks, ylks, crop = cf.transform_params(cls.params)
        # dest_paths are tifs that have been geotif converted and multilooked
        conv2tif.main(cls.params)
        prepifg.main(cls.params)
        # run_prepifg.gamma_prepifg(cls.base_unw_paths, cls.params)
        cls.base_unw_paths.pop()  # removed dem as we don't want it in ifgs

        cls.dest_paths = cf.get_dest_paths(cls.base_unw_paths, crop,
                                           cls.params, xlks)
        cls.ifgs = common.small_data_setup(datafiles=cls.dest_paths)
Пример #9
0
    def setUpClass(cls):
        rate_types = ['stack_rate', 'stack_error', 'stack_samples']
        cls.tif_dir = tempfile.mkdtemp()
        cls.test_conf = common.TEST_CONF_GAMMA

        from pyrate.configuration import Configuration
        # change the required params
        params = Configuration(cls.test_conf).__dict__
        params[cf.OBS_DIR] = common.SML_TEST_GAMMA
        params[cf.PROCESSES] = 4
        params[cf.PROCESSOR] = 1  # gamma
        params[cf.IFG_FILE_LIST] = os.path.join(common.SML_TEST_GAMMA,
                                                'ifms_17')
        params[cf.OUT_DIR] = cls.tif_dir
        params[cf.PARALLEL] = 1
        params[cf.APS_CORRECTION] = False
        params[cf.TMPDIR] = os.path.join(params[cf.OUT_DIR], cf.TMPDIR)
        rows, cols = params["rows"], params["cols"]

        # xlks, ylks, crop = cf.transform_params(params)

        # base_unw_paths need to be geotiffed by converttogeotif
        #  and multilooked by run_prepifg
        base_unw_paths = list(cf.parse_namelist(params[cf.IFG_FILE_LIST]))

        multi_paths = [
            MultiplePaths(params[cf.OUT_DIR],
                          b,
                          ifglksx=params[cf.IFG_LKSX],
                          ifgcropopt=params[cf.IFG_CROP_OPT])
            for b in base_unw_paths
        ]

        # dest_paths are tifs that have been geotif converted and multilooked
        cls.converted_paths = [b.converted_path for b in multi_paths]
        cls.sampled_paths = [b.sampled_path for b in multi_paths]
        from copy import copy
        orig_params = copy(params)
        conv2tif.main(params)
        prepifg.main(orig_params)
        tiles = pyrate.core.shared.get_tiles(cls.sampled_paths[0], rows, cols)
        ifgs = common.small_data_setup()
        params[cf.INTERFEROGRAM_FILES] = multi_paths

        cls.refpixel_p, cls.maxvar_p, cls.vcmt_p = process.process_ifgs(
            cls.sampled_paths, params, rows, cols)
        cls.mst_p = common.reconstruct_mst(ifgs[0].shape, tiles,
                                           params[cf.TMPDIR])
        cls.rate_p, cls.error_p, cls.samples_p = \
            [common.reconstruct_stack_rate(ifgs[0].shape, tiles, params[cf.TMPDIR], t) for t in rate_types]

        common.remove_tifs(params[cf.OBS_DIR])

        # now create the non parallel version
        cls.tif_dir_s = tempfile.mkdtemp()
        params[cf.PARALLEL] = 0
        params[cf.PROCESSES] = 1
        params[cf.OUT_DIR] = cls.tif_dir_s
        params[cf.TMPDIR] = os.path.join(params[cf.OUT_DIR], cf.TMPDIR)
        multi_paths = [
            MultiplePaths(params[cf.OUT_DIR],
                          b,
                          ifglksx=params[cf.IFG_LKSX],
                          ifgcropopt=params[cf.IFG_CROP_OPT])
            for b in base_unw_paths
        ]

        cls.converted_paths_s = [b.converted_path for b in multi_paths]
        cls.sampled_paths_s = [b.sampled_path for b in multi_paths]
        orig_params = copy(params)
        conv2tif.main(params)
        prepifg.main(orig_params)
        params[cf.INTERFEROGRAM_FILES] = multi_paths
        cls.refpixel, cls.maxvar, cls.vcmt = process.process_ifgs(
            cls.sampled_paths_s, params, rows, cols)
        cls.mst = common.reconstruct_mst(ifgs[0].shape, tiles,
                                         params[cf.TMPDIR])
        cls.rate, cls.error, cls.samples = \
            [common.reconstruct_stack_rate(ifgs[0].shape, tiles, params[cf.TMPDIR], t) for t in rate_types]
Пример #10
0
 def __get_files_from_attr(self, attr, input_type=InputTypes.IFG):
     val = self.__getattribute__(attr)
     files = parse_namelist(val)
     return [MultiplePaths(self.outdir, p, self.ifglksx, self.ifgcropopt, input_type=input_type) for p in files]
Пример #11
0
 def __get_files_from_attr(self, attr):
     val = self.__getattribute__(attr)
     files = parse_namelist(val)
     return [MultiplePaths(self.outdir, p, self.ifglksx, self.ifgcropopt) for p in files]