コード例 #1
0
    def test_S2L1C_float32_uint16(self):
        """ Download S2L1C bands and dataMask
        """
        test_dir = os.path.dirname(os.path.realpath(__file__))
        cache_folder = os.path.join(test_dir, 'cache_test')

        if os.path.exists(cache_folder):
            shutil.rmtree(cache_folder)

        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, 'BANDS'),
            additional_data=[(FeatureType.MASK, 'dataMask')],
            size=self.size,
            maxcc=self.maxcc,
            time_difference=self.time_difference,
            data_collection=DataCollection.SENTINEL2_L1C,
            max_threads=self.max_threads,
            cache_folder=cache_folder)

        eopatch = task.execute(bbox=self.bbox,
                               time_interval=self.time_interval)
        bands = eopatch[(FeatureType.DATA, 'BANDS')]
        is_data = eopatch[(FeatureType.MASK, 'dataMask')]

        self.assertTrue(
            np.allclose(array_stats(bands), [0.0233, 0.0468, 0.0252]))

        width, height = self.size
        self.assertTrue(bands.shape == (4, height, width, 13))
        self.assertTrue(is_data.shape == (4, height, width, 1))
        self.assertTrue(len(eopatch.timestamp) == 4)
        self.assertTrue(bands.dtype == np.float32)

        self.assertTrue(os.path.exists(cache_folder))

        # change task's bans_dtype and run it again
        task.bands_dtype = np.uint16

        eopatch = task.execute(bbox=self.bbox,
                               time_interval=self.time_interval)
        bands = eopatch[(FeatureType.DATA, 'BANDS')]

        self.assertTrue(
            np.allclose(array_stats(bands), [232.5769, 467.5385, 251.8654]))

        self.assertTrue(bands.dtype == np.uint16)

        shutil.rmtree(cache_folder)
コード例 #2
0
    def test_s2l1c_float32_uint16(self, cache_folder):
        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, "BANDS"),
            additional_data=[(FeatureType.MASK, "dataMask")],
            size=self.size,
            maxcc=self.maxcc,
            time_difference=self.time_difference,
            data_collection=DataCollection.SENTINEL2_L1C,
            max_threads=self.max_threads,
            cache_folder=cache_folder,
        )

        eopatch = task.execute(bbox=self.bbox,
                               time_interval=self.time_interval)
        bands = eopatch[(FeatureType.DATA, "BANDS")]
        is_data = eopatch[(FeatureType.MASK, "dataMask")]

        assert calculate_stats(bands) == approx([0.0233, 0.0468, 0.0252])

        width, height = self.size
        assert bands.shape == (4, height, width, 13)
        assert is_data.shape == (4, height, width, 1)
        assert len(eopatch.timestamp) == 4
        assert bands.dtype == np.float32

        assert os.path.exists(cache_folder)

        # change task's bans_dtype and run it again
        task.bands_dtype = np.uint16

        eopatch = task.execute(bbox=self.bbox,
                               time_interval=self.time_interval)
        bands = eopatch[(FeatureType.DATA, "BANDS")]

        assert calculate_stats(bands) == approx([232.5769, 467.5385, 251.8654])

        assert bands.dtype == np.uint16