Example #1
0
    def test_get_available_collections(self):
        collections = DataCollection.get_available_collections()
        self._check_collection_list(collections)

        config = SHConfig()
        config.sh_base_url = ServiceUrl.EOCLOUD
        eocloud_collections = DataCollection.get_available_collections(
            config=config)
        self._check_collection_list(eocloud_collections)
        self.assertNotEqual(eocloud_collections, collections)
Example #2
0
    def test_define_byoc_and_batch(self):
        byoc_id = '0000d273-7e89-4f00-971e-9024f89a0000'
        byoc = DataCollection.define_byoc(byoc_id, name=f'MY_BYOC')
        batch = DataCollection.define_batch(byoc_id, name='MY_BATCH')

        self.assertEqual(byoc, DataCollection.MY_BYOC)
        self.assertEqual(batch, DataCollection.MY_BATCH)

        for ds in [byoc, batch]:
            self.assertTrue(ds.api_id.endswith(byoc_id))
            self.assertEqual(ds.collection_id, byoc_id)

        with self.assertWarns(SHDeprecationWarning):
            byoc2 = DataCollection(byoc_id.replace('0', '1'))

        self.assertTrue(byoc, byoc2)
    def __init__(self,
                 data_collection,
                 size=None,
                 resolution=None,
                 cache_folder=None,
                 config=None,
                 max_threads=None):
        """
        :param data_collection: A collection of requested satellite data.
        :type data_collection: DataCollection
        :param size: Number of pixels in x and y dimension.
        :type size: tuple(int, int)
        :param resolution: Resolution in meters, passed as a single number or a tuple of two numbers -
            resolution in horizontal and resolution in vertical direction.
        :type resolution: float or (float, float)
        :param cache_folder: Path to cache_folder. If set to None (default) requests will not be cached.
        :type cache_folder: str
        :param config: An instance of SHConfig defining the service
        :type config: SHConfig or None
        :param max_threads: Maximum threads to be used when downloading data.
        :type max_threads: int
        """
        if (size is None) == (resolution is None):
            raise ValueError(
                "Exactly one of the parameters 'size' and 'resolution' should be given."
            )

        self.size = size
        self.resolution = resolution
        self.config = config or SHConfig()
        self.max_threads = max_threads
        self.data_collection = DataCollection(data_collection)
        self.cache_folder = cache_folder
Example #4
0
    def __init__(self,
                 classifier,
                 data_feature,
                 cm_size_x=None,
                 cm_size_y=None,
                 cmask_feature='CLM',
                 cprobs_feature=None,
                 instance_id=None,
                 data_collection=None,
                 image_format=MimeType.TIFF_d32f,
                 model_evalscript=MODEL_EVALSCRIPT,
                 data_source=None):
        """ Constructor

        If both `cm_size_x` and `cm_size_y` are `None` and `data_feature` exists, cloud detection is computed at same
        resolution of `data_feature`.

        :param classifier: Cloud detector classifier. This object implements a `get_cloud_probability_map` and
            `get_cloud_masks` functions to generate probability maps and binary masks
        :param data_feature: Name of key in eopatch.data dictionary to be used as input to the classifier. If the
            `data_feature` does not exist, a new OGC request at the given cloud mask resolution is made
            with layer name set to `data_feature` parameter.
        :param cm_size_x: Resolution to be used for computation of cloud mask. Allowed values are number of column
            pixels (WMS-request) or spatial resolution (WCS-request, e.g. '10m'). Default is `None`
        :param cm_size_y: Resolution to be used for computation of cloud mask. Allowed values are number of row
            pixels (WMS-request) or spatial resolution (WCS-request, e.g. '10m'). Default is `None`
        :param cmask_feature: Name of key to be used for the cloud mask to add. The cloud binary mask is added to the
            `eopatch.mask` attribute dictionary. Default is `'clm'`.
        :param cprobs_feature: Name of key to be used for the cloud probability map to add. The cloud probability map is
            added to the `eopatch.data` attribute dictionary. Default is `None`, so no cloud probability map will
            be computed.
        :param instance_id: Instance ID to be used for OGC request. Default is `None`
        :param data_collection: Data collection to be requested by OGC service request.
        :param image_format: Image format to be requested by OGC service request. Default is `MimeType.TIFF_d32f`
        :param model_evalscript: CustomUrlParam defining the EVALSCRIPT to be used by OGC request. Should reflect the
            request necessary for the correct functioning of the classifier. For instance, for the
            `S2PixelCloudDetector` classifier, `MODEL_EVALSCRIPT` is used as it requests the required 10
            bands. Default is `MODEL_EVALSCRIPT`
        :param data_source: A deprecated alternative to data_collection
        :type data_source: DataCollection
        """
        warnings.warn(
            "AddCloudMaskTask is being deprecated. Please use AddMultiCloudMaskTask instead. "
            "See showcase at examples/mask/CloudMaskTask.ipynb",
            SHDeprecationWarning)

        data_collection = DataCollection(
            handle_deprecated_data_source(data_collection, data_source)
            or DataCollection.SENTINEL2_L1C)

        self.classifier = classifier
        self.data_feature = data_feature
        self.cm_feature = cmask_feature
        self.cm_size_x = cm_size_x
        self.cm_size_y = cm_size_y
        self.cprobs_feature = cprobs_feature
        self.instance_id = instance_id
        self.data_collection = data_collection
        self.image_format = image_format
        self.model_evalscript = model_evalscript
Example #5
0
    def test_define(self):
        for _ in range(3):
            data_collection = DataCollection.define('NEW',
                                                    api_id='X',
                                                    sensor_type='Sensor',
                                                    bands=('B01', ),
                                                    is_timeless=True)

        self.assertEqual(data_collection, DataCollection.NEW)

        with self.assertRaises(ValueError):
            DataCollection.define('NEW_NEW',
                                  api_id='X',
                                  sensor_type='Sensor',
                                  bands=('B01', ),
                                  is_timeless=True)

        with self.assertRaises(ValueError):
            DataCollection.define('NEW', api_id='Y')
Example #6
0
    def test_define_from(self):
        bands = ['B01', 'XYZ']
        for _ in range(3):
            data_collection = DataCollection.define_from(
                DataCollection.SENTINEL5P, 'NEW_5P', api_id='X', bands=bands)

        self.assertEqual(data_collection, DataCollection.NEW_5P)
        self.assertEqual(data_collection.api_id, 'X')
        self.assertEqual(data_collection.wfs_id,
                         DataCollection.SENTINEL5P.wfs_id)
        self.assertEqual(data_collection.bands, tuple(bands))
Example #7
0
    def __init__(self,
                 layer,
                 feature=None,
                 valid_data_mask_feature='IS_DATA',
                 service_type=None,
                 data_collection=None,
                 size_x=None,
                 size_y=None,
                 maxcc=None,
                 image_format=MimeType.TIFF_d32f,
                 instance_id=None,
                 custom_url_params=None,
                 time_difference=None,
                 raise_download_errors=True,
                 data_source=None):
        # pylint: disable=too-many-arguments

        warnings.warn(
            "eo-learn is deprecating OGC services for the Processing API. "
            "Please use SentinelHubInputTask instead. See examples/io/ProcessingIO.ipynb for examples.",
            SHDeprecationWarning)

        data_collection = DataCollection(
            handle_deprecated_data_source(data_collection, data_source))

        self.layer = layer
        self.feature_type, self.feature_name = next(
            self._parse_features(layer if feature is None else feature,
                                 default_feature_type=FeatureType.DATA)())
        self.valid_data_mask_feature = self._parse_features(
            valid_data_mask_feature, default_feature_type=FeatureType.MASK)
        self.service_type = service_type
        self.data_collection = data_collection
        self.size_x = size_x
        self.size_y = size_y
        self.maxcc = maxcc
        self.image_format = image_format
        self.instance_id = instance_id

        if custom_url_params is None:
            custom_url_params = {}
        self.custom_url_params = {
            **{
                CustomUrlParam.SHOWLOGO: False,
                CustomUrlParam.TRANSPARENT: True
            },
            **custom_url_params
        }

        self.time_difference = time_difference
        self.raise_download_errors = raise_download_errors
Example #8
0
    def test_attributes(self):
        ds = DataCollection.SENTINEL3_OLCI

        for attr_name in [
                'api_id', 'wfs_id', 'service_url', 'bands', 'sensor_type'
        ]:
            value = getattr(ds, attr_name)
            self.assertNotEqual(value, None)
            self.assertEqual(value, getattr(ds.value, attr_name))

        ds = DataCollection.define('EMPTY')

        for attr_name in ['api_id', 'wfs_id', 'bands']:
            with self.assertRaises(ValueError):
                getattr(ds, attr_name)

        self.assertEqual(ds.service_url, None)
request_all_bands.save_data()

print(f'The output directory has been created and a tiff file with all 13 bands was saved into ' \
      'the following structure:\n')
for folder, _, filenames in os.walk(request_all_bands.data_folder):
    for filename in filenames:
        print(os.path.join(folder, filename))


# Example 5: Other Data Collections
"""
The sentinelhub package supports various data collections. The previous examples
have used 'DataCollection.SENTINEL2_L1C'.
"""
print('Supported DataCollections:\n')
for collection in DataCollection.get_available_collections():
    print(collection)

# try Digital Elevation Model (DEM) type:
# use FLOAT32 since the values can be negative (below sea level)
evalscript_dem = '''
//VERSION=3
function setup() {
  return {
    input: ["DEM"],
    output: {
      id: "default",
      bands: 1,
      sampleType: SampleType.FLOAT32
    }
  }
"""
Tutorial to show how to obtain data from a desired data collection using sentinelhub.
"""

import cv2
import numpy as np
import matplotlib.pyplot as plt
from sentinelhub import DataCollection
from sentinelhub import SHConfig, BBox, CRS, SentinelHubRequest, MimeType, bbox_to_dimensions


def change_brightness(img, alpha=1.0, beta=0.0):
    return cv2.addWeighted(img, alpha, np.zeros(img.shape, img.dtype), 0, beta)


for collection in DataCollection.get_available_collections():
    print(collection)

CLIENT_ID = '9d542985-ed95-4357-b740-37596b1d5f70'
CLIENT_SECRET = ')(/q5|#Q[[C:Oy3Is46,kpQYR28ovX9y2@,6UP@D'
config = SHConfig()
if CLIENT_ID and CLIENT_SECRET:
    config.sh_client_id = CLIENT_ID
    config.sh_client_secret = CLIENT_SECRET

# Columbia Glacier, Alaska
glacier_bbox = BBox([-147.8, 60.96, -146.5, 61.38], crs=CRS.WGS84)
glacier_size = (700, 466)
time_interval = '2020-07-15', '2020-07-16'

evalscript_true_color = """