Ejemplo n.º 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)
Ejemplo n.º 2
0
    def test_additional_data(self):
        """ Download additional data, such as viewAzimuthMean, sunAzimuthAngles...
        """
        task = SentinelHubInputTask(bands_feature=(FeatureType.DATA, 'BANDS'),
                                    bands=['B01', 'B02', 'B05'],
                                    additional_data=[
                                        (FeatureType.MASK, 'dataMask',
                                         'IS_DATA'), (FeatureType.MASK, 'CLM'),
                                        (FeatureType.MASK, 'SCL'),
                                        (FeatureType.MASK, 'SNW'),
                                        (FeatureType.MASK, 'CLD'),
                                        (FeatureType.DATA, 'CLP'),
                                        (FeatureType.DATA, 'viewAzimuthMean',
                                         'view_azimuth_mean'),
                                        (FeatureType.DATA, 'sunAzimuthAngles'),
                                        (FeatureType.DATA, 'sunZenithAngles')
                                    ],
                                    size=self.size,
                                    maxcc=self.maxcc,
                                    time_difference=self.time_difference,
                                    data_source=DataSource.SENTINEL2_L2A,
                                    max_threads=self.max_threads)

        eopatch = task.execute(bbox=self.bbox,
                               time_interval=self.time_interval)

        bands = eopatch[(FeatureType.DATA, 'BANDS')]
        is_data = eopatch[(FeatureType.MASK, 'IS_DATA')]
        clm = eopatch[(FeatureType.MASK, 'CLM')]
        scl = eopatch[(FeatureType.MASK, 'SCL')]
        snw = eopatch[(FeatureType.MASK, 'SNW')]
        cld = eopatch[(FeatureType.MASK, 'CLD')]
        clp = eopatch[(FeatureType.DATA, 'CLP')]
        view_azimuth_mean = eopatch[(FeatureType.DATA, 'view_azimuth_mean')]
        sun_azimuth_angles = eopatch[(FeatureType.DATA, 'sunAzimuthAngles')]
        sun_zenith_angles = eopatch[(FeatureType.DATA, 'sunZenithAngles')]

        self.assertTrue(
            np.allclose(array_stats(bands), [0.027, 0.0243, 0.0162]))

        width, height = self.size
        self.assertTrue(bands.shape == (4, height, width, 3))
        self.assertTrue(is_data.shape == (4, height, width, 1))
        self.assertTrue(is_data.dtype == np.bool)
        self.assertTrue(clm.shape == (4, height, width, 1))
        self.assertTrue(clm.dtype == np.uint8)
        self.assertTrue(scl.shape == (4, height, width, 1))
        self.assertTrue(snw.shape == (4, height, width, 1))
        self.assertTrue(cld.shape == (4, height, width, 1))
        self.assertTrue(clp.shape == (4, height, width, 1))
        self.assertTrue(view_azimuth_mean.shape == (4, height, width, 1))
        self.assertTrue(sun_azimuth_angles.shape == (4, height, width, 1))
        self.assertTrue(sun_zenith_angles.shape == (4, height, width, 1))
        self.assertTrue(len(eopatch.timestamp) == 4)
    def test_additional_data(self):
        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, "BANDS"),
            bands=["B01", "B02", "B05"],
            additional_data=[
                (FeatureType.MASK, "dataMask", "IS_DATA"),
                (FeatureType.MASK, "CLM"),
                (FeatureType.MASK, "SCL"),
                (FeatureType.MASK, "SNW"),
                (FeatureType.MASK, "CLD"),
                (FeatureType.DATA, "CLP"),
                (FeatureType.DATA, "viewAzimuthMean", "view_azimuth_mean"),
                (FeatureType.DATA, "sunAzimuthAngles"),
                (FeatureType.DATA, "sunZenithAngles"),
            ],
            size=self.size,
            maxcc=self.maxcc,
            time_difference=self.time_difference,
            data_collection=DataCollection.SENTINEL2_L2A,
            max_threads=self.max_threads,
        )

        eopatch = task.execute(bbox=self.bbox,
                               time_interval=self.time_interval)

        bands = eopatch[(FeatureType.DATA, "BANDS")]
        is_data = eopatch[(FeatureType.MASK, "IS_DATA")]
        clm = eopatch[(FeatureType.MASK, "CLM")]
        scl = eopatch[(FeatureType.MASK, "SCL")]
        snw = eopatch[(FeatureType.MASK, "SNW")]
        cld = eopatch[(FeatureType.MASK, "CLD")]
        clp = eopatch[(FeatureType.DATA, "CLP")]
        view_azimuth_mean = eopatch[(FeatureType.DATA, "view_azimuth_mean")]
        sun_azimuth_angles = eopatch[(FeatureType.DATA, "sunAzimuthAngles")]
        sun_zenith_angles = eopatch[(FeatureType.DATA, "sunZenithAngles")]

        assert calculate_stats(bands) == approx([0.027, 0.0243, 0.0162])

        width, height = self.size
        assert bands.shape == (4, height, width, 3)
        assert is_data.shape == (4, height, width, 1)
        assert is_data.dtype == bool
        assert clm.shape == (4, height, width, 1)
        assert clm.dtype == np.uint8
        assert scl.shape == (4, height, width, 1)
        assert snw.shape == (4, height, width, 1)
        assert cld.shape == (4, height, width, 1)
        assert clp.shape == (4, height, width, 1)
        assert view_azimuth_mean.shape == (4, height, width, 1)
        assert sun_azimuth_angles.shape == (4, height, width, 1)
        assert sun_zenith_angles.shape == (4, height, width, 1)
        assert len(eopatch.timestamp) == 4
    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
    def test_no_data_input_task_request(self):
        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, "BANDS"),
            additional_data=[(FeatureType.MASK, "dataMask")],
            size=self.size,
            maxcc=0.0,
            data_collection=DataCollection.SENTINEL2_L1C,
        )
        eopatch = task.execute(bbox=self.bbox,
                               time_interval=("2021-01-01", "2021-01-20"))

        bands = eopatch[FeatureType.DATA, "BANDS"]
        assert bands.shape == (0, 101, 99, 13)
        masks = eopatch[FeatureType.MASK, "dataMask"]
        assert masks.shape == (0, 101, 99, 1)
Ejemplo n.º 6
0
    def test_aux_request_args(self):
        """ Download low resolution data with `PREVIEW` mode
        """
        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, 'BANDS'),
            resolution=260,
            maxcc=self.maxcc,
            time_difference=self.time_difference,
            data_collection=DataCollection.SENTINEL2_L1C,
            max_threads=self.max_threads,
            aux_request_args={'dataFilter': {'previewMode': 'PREVIEW'}}
        )

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

        self.assertTrue(bands.shape == (4, 4, 4, 13))
        self.assertTrue(np.allclose(array_stats(bands), [0.0, 0.0493, 0.0277]))
Ejemplo n.º 7
0
    def test_scl_only(self):
        """ Download just SCL, without any other bands
        """
        task = SentinelHubInputTask(
            bands_feature=None,
            additional_data=[(FeatureType.DATA, 'SCL')],
            size=self.size,
            maxcc=self.maxcc,
            time_difference=self.time_difference,
            data_collection=DataCollection.SENTINEL2_L2A,
            max_threads=self.max_threads
        )

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

        width, height = self.size
        self.assertTrue(scl.shape == (4, height, width, 1))
    def test_aux_request_args(self):
        """Download low resolution data with `PREVIEW` mode"""
        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, "BANDS"),
            resolution=260,
            maxcc=self.maxcc,
            time_difference=self.time_difference,
            data_collection=DataCollection.SENTINEL2_L1C,
            max_threads=self.max_threads,
            aux_request_args={"dataFilter": {
                "previewMode": "PREVIEW"
            }},
        )

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

        assert bands.shape == (4, 4, 4, 13)
        assert calculate_stats(bands) == approx([0.0, 0.0493, 0.0277])
    def test_specific_bands(self):
        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, "BANDS"),
            bands=["B01", "B02", "B03"],
            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,
        )

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

        assert calculate_stats(bands) == approx([0.0648, 0.1193, 0.063])

        width, height = self.size
        assert bands.shape == (4, height, width, 3)
Ejemplo n.º 10
0
    def test_specific_bands(self):
        """ Download S2L1C bands and dataMask
        """
        task = SentinelHubInputTask(
            bands_feature=(FeatureType.DATA, 'BANDS'),
            bands=["B01", "B02", "B03"],
            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
        )

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

        self.assertTrue(np.allclose(array_stats(bands), [0.0648, 0.1193, 0.063]))

        width, height = self.size
        self.assertTrue(bands.shape == (4, height, width, 3))
Ejemplo n.º 11
0
    def test_single_scene(self):
        """ Download S2L1C bands and dataMask
        """
        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,
            single_scene=True,
            mosaicking_order="leastCC"
        )

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

        width, height = self.size
        self.assertTrue(bands.shape == (1, height, width, 13))
        self.assertTrue(is_data.shape == (1, height, width, 1))
        self.assertTrue(len(eopatch.timestamp) == 1)
Ejemplo n.º 12
0
    def test_S2L2A(self):
        """ Download just SCL, without other bands
        """
        task = SentinelHubInputTask(bands_feature=(FeatureType.DATA, 'BANDS'),
                                    additional_data=[(FeatureType.MASK,
                                                      'dataMask')],
                                    size=self.size,
                                    maxcc=self.maxcc,
                                    time_difference=self.time_difference,
                                    data_source=DataSource.SENTINEL2_L2A,
                                    max_threads=self.max_threads)

        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.0107, 0.0123, 0.0087]))

        width, height = self.size
        self.assertTrue(bands.shape == (4, height, width, 12))
        self.assertTrue(is_data.shape == (4, height, width, 1))
        self.assertTrue(len(eopatch.timestamp) == 4)