How to use the sentinelhub.MimeType function in sentinelhub

To help you get started, we’ve selected a few sentinelhub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sentinel-hub / sentinelhub-py / tests / test_constants.py View on Github external
def test_canonical_extension(self):
        extension_pairs = (
            ('tiff', 'tiff'),
            ('tif', 'tiff'),
            ('jpg', 'jpg'),
            ('jpeg', 'jpg'),
            ('png', 'png'),
            ('jp2', 'jp2'),
            ('txt', 'txt'),
            ('h5', 'hdf'),
            ('hdf', 'hdf'),
            ('hdf5', 'hdf')
        )
        for ext, canon in extension_pairs:
            res = MimeType.canonical_extension(ext)
            self.assertEqual(canon, res, msg="Expected {}, got {}".format(canon, res))
github sentinel-hub / sentinel2-cloud-detector / tests / test_cloud_detector.py View on Github external
super().setUpClass()

        bbox1 = BBox([-90.9216499, 14.4190528, -90.8186531, 14.5520163], crs=CRS.WGS84)  # From examples
        bbox2 = BBox([46.16, -16.15, 46.51, -15.58], crs=CRS.WGS84)  # From sentinelhub-py examples
        cls.custom_url_params = {
            CustomUrlParam.SHOWLOGO: True,
            CustomUrlParam.TRANSPARENT: False,
            CustomUrlParam.EVALSCRIPT: 'return [B01]',
            CustomUrlParam.ATMFILTER: 'DOS1'
        }

        cls.wms_request = WmsRequest(layer='S2-DOS1', bbox=bbox1, time=('2017-12-01', '2017-12-31'), width=60,
                                     height=None, image_format=MimeType.TIFF, custom_url_params=cls.custom_url_params,
                                     instance_id=cls.CONFIG.instance_id)
        cls.wcs_request = WcsRequest(layer='S2-ATMCOR', bbox=bbox2, time='2016-07-18T07:14:04',
                                     resx='100m', resy='100m', image_format=MimeType.PNG, data_folder='.')

        cls.test_cases = [
            TestCaseContainer('WMS', CloudMaskRequest(cls.wms_request, threshold=0.6, average_over=2, dilation_size=5),
                              clm_min=0, clm_max=1, clm_mean=0.343827, clm_median=0, clp_min=0.00011, clp_max=0.99999,
                              clp_mean=0.23959, clp_median=0.01897, mask_shape=(7, 81, 60)),
            TestCaseContainer('WCS, partial no data', CloudMaskRequest(cls.wcs_request, all_bands=True), clm_min=0,
                              clm_max=1, clm_mean=0.04468, clm_median=0, clp_min=-50.0, clp_max=0.999635,
                              clp_mean=-7.5472468, clp_median=0.011568, mask_shape=(1, 634, 374))
        ]
github sentinel-hub / sentinelhub-py / tests / test_constants.py View on Github external
def test_is_image_format(self):
        image_format_extensions = (
            'tif', 'tiff', 'jpg', 'jpeg', 'tif', 'tiff', 'png', 'jpg'
        )
        for ext in image_format_extensions:
            mime_type = MimeType(MimeType.canonical_extension(ext))
            self.assertTrue(MimeType.is_image_format(mime_type),
                            msg="Expected MIME type {} to be an image format".format(mime_type.value))
github sentinel-hub / sentinel2-cloud-detector / tests / test_cloud_detector.py View on Github external
def setUpClass(cls):
        super().setUpClass()

        bbox1 = BBox([-90.9216499, 14.4190528, -90.8186531, 14.5520163], crs=CRS.WGS84)  # From examples
        bbox2 = BBox([46.16, -16.15, 46.51, -15.58], crs=CRS.WGS84)  # From sentinelhub-py examples
        cls.custom_url_params = {
            CustomUrlParam.SHOWLOGO: True,
            CustomUrlParam.TRANSPARENT: False,
            CustomUrlParam.EVALSCRIPT: 'return [B01]',
            CustomUrlParam.ATMFILTER: 'DOS1'
        }

        cls.wms_request = WmsRequest(layer='S2-DOS1', bbox=bbox1, time=('2017-12-01', '2017-12-31'), width=60,
                                     height=None, image_format=MimeType.TIFF, custom_url_params=cls.custom_url_params,
                                     instance_id=cls.CONFIG.instance_id)
        cls.wcs_request = WcsRequest(layer='S2-ATMCOR', bbox=bbox2, time='2016-07-18T07:14:04',
                                     resx='100m', resy='100m', image_format=MimeType.PNG, data_folder='.')

        cls.test_cases = [
            TestCaseContainer('WMS', CloudMaskRequest(cls.wms_request, threshold=0.6, average_over=2, dilation_size=5),
                              clm_min=0, clm_max=1, clm_mean=0.343827, clm_median=0, clp_min=0.00011, clp_max=0.99999,
                              clp_mean=0.23959, clp_median=0.01897, mask_shape=(7, 81, 60)),
            TestCaseContainer('WCS, partial no data', CloudMaskRequest(cls.wcs_request, all_bands=True), clm_min=0,
                              clm_max=1, clm_mean=0.04468, clm_median=0, clp_min=-50.0, clp_max=0.999635,
                              clp_mean=-7.5472468, clp_median=0.011568, mask_shape=(1, 634, 374))
        ]
github sentinel-hub / sentinelhub-py / tests / test_constants.py View on Github external
def test_get_string(self):
        type_string_pairs = (
            (MimeType.PNG, 'image/png'),
            (MimeType.JPG, 'image/jpeg'),
            (MimeType.TIFF, 'image/tiff'),
            (MimeType.TIFF_d32f, 'image/tiff;depth=32f'),
            (MimeType.JSON, 'application/json'),
            (MimeType.CSV, 'text/csv'),
            (MimeType.ZIP, 'application/zip'),
            (MimeType.HDF, 'application/x-hdf'),
            (MimeType.XML, 'application/xml'),
            (MimeType.TXT, 'text/plain')
        )
        for img_type, img_str in type_string_pairs:
            res = MimeType.get_string(img_type)
            self.assertEqual(img_str, res, msg="Expected {}, got {}".format(img_str, res))
github sentinel-hub / eo-learn / io / eolearn / io / sh_add.py View on Github external
def __init__(self, feature_type, layer, feature_name=None, data_source=None,
                 image_format=MimeType.TIFF_d32f, instance_id=None, custom_url_params=None):

        self.feature_type = feature_type
        self.layer = layer
        self.feature_name = layer if feature_name is None else feature_name
        self.data_source = data_source
        self.image_format = image_format
        self.instance_id = instance_id

        custom_params = {CustomUrlParam.SHOWLOGO: False,
                         CustomUrlParam.TRANSPARENT: False}
        if custom_url_params is None:
            self.custom_url_params = custom_params
        else:
            self.custom_url_params = {**custom_params, **custom_url_params}
github sentinel-hub / eo-learn / io / eolearn / io / sh_input.py View on Github external
def __init__(self, layer, feature_name=None, valid_data_mask_name='IS_DATA',
                 service_type=None, data_source=None,
                 size_x=None, size_y=None, maxcc=1.0, image_format=MimeType.TIFF_d32f,
                 instance_id=None, custom_url_params=None, time_difference=datetime.timedelta(seconds=-1)):
        # pylint: disable=too-many-arguments
        self.layer = layer
        self.feature_name = layer if feature_name is None else feature_name
        self.valid_data_mask_name = valid_data_mask_name
        self.service_type = service_type
        self.data_source = data_source
        self.size_x = size_x
        self.size_y = size_y
        self.maxcc = maxcc
        self.image_format = image_format
        self.instance_id = instance_id

        custom_params = {CustomUrlParam.SHOWLOGO: False,
                         CustomUrlParam.TRANSPARENT: True}
        if custom_url_params is None:
github sentinel-hub / eo-learn / io / eolearn / io / processing_api.py View on Github external
def _request_payload(self, date, bbox, size_x, size_y):
        """ Build the payload dictionary for the request
        """
        date_from, date_to = date - self.time_difference, date + self.time_difference
        time_from, time_to = date_from.isoformat() + 'Z', date_to.isoformat() + 'Z'

        responses = [shr.response('default', MimeType.TIFF.get_string()), shr.response('userdata', 'application/json')]

        data = shr.data(time_from=time_from, time_to=time_to, data_type=self.data_source.api_identifier())
        data['dataFilter']['maxCloudCoverage'] = int(self.maxcc * 100)

        return shr.body(
            request_bounds=shr.bounds(crs=bbox.crs.opengis_string, bbox=list(bbox)),
            request_data=[data],
            request_output=shr.output(size_x=size_x, size_y=size_y, responses=responses),
            evalscript=self.generate_evalscript()
        )
github sentinel-hub / sentinel2-cloud-detector / s2cloudless / S2PixelCloudDetector.py View on Github external
def _prepare_ogc_request_params(self):
        """ Method makes sure that correct parameters will be used for download of S-2 bands.
        """
        self.ogc_request.image_format = MimeType.TIFF_d32f
        if self.ogc_request.custom_url_params is None:
            self.ogc_request.custom_url_params = {}
        self.ogc_request.custom_url_params.update({
            CustomUrlParam.SHOWLOGO: False,
            CustomUrlParam.TRANSPARENT: True,
            CustomUrlParam.EVALSCRIPT: S2_BANDS_EVALSCRIPT if self.all_bands else MODEL_EVALSCRIPT,
            CustomUrlParam.ATMFILTER: 'NONE'
        })
        self.ogc_request.create_request(reset_wfs_iterator=False)