How to use the sentinelhub.TestSentinelHub 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_data_request.py View on Github external
class TestDataRequest(TestSentinelHub):
    def test_init(self):

        bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
        data_request = WcsRequest(data_folder=self.OUTPUT_FOLDER, bbox=bbox, layer='BANDS-S2-L1C')
        data_request.create_request(reset_wfs_iterator=True)  # This method is used by s2cloudless, don't rename it

        self.assertEqual(self.OUTPUT_FOLDER, data_request.data_folder,
                         msg="Expected {}, got {}".format(self.OUTPUT_FOLDER, data_request.data_folder))
        self.assertTrue(isinstance(data_request.get_filename_list(), list), "Expected a list")
        self.assertTrue(isinstance(data_request.get_url_list(), list), "Expected a list")
        self.assertTrue(data_request.is_valid_request(), "Request should be valid")


class TestDataRequestSaving(TestSentinelHub):

    @classmethod
    def setUpClass(cls):
        super().setUpClass()

        cls.product_id = 'S2A_MSIL1C_20180113T001101_N0206_R073_T55KGP_20180113T013328.SAFE'
        metafiles = 'inspire '
        cls.request_without_folder = AwsProductRequest(bands='', metafiles=metafiles, safe_format=True,
                                                       product_id=cls.product_id)
        cls.request_with_folder = AwsProductRequest(data_folder=cls.OUTPUT_FOLDER, bands='', metafiles=metafiles,
                                                    safe_format=True, product_id=cls.product_id)

    def test_saving_responses(self):
        try:
            data = self.request_without_folder.get_data()
            self.assertTrue(isinstance(data, list), "Expected a list")
github sentinel-hub / sentinelhub-py / tests / test_data_request.py View on Github external
import unittest
import os

from sentinelhub import WcsRequest, AwsProductRequest, BBox, CRS, get_file_list, get_folder_list, TestSentinelHub


class TestDataRequest(TestSentinelHub):
    def test_init(self):

        bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
        data_request = WcsRequest(data_folder=self.OUTPUT_FOLDER, bbox=bbox, layer='BANDS-S2-L1C')
        data_request.create_request(reset_wfs_iterator=True)  # This method is used by s2cloudless, don't rename it

        self.assertEqual(self.OUTPUT_FOLDER, data_request.data_folder,
                         msg="Expected {}, got {}".format(self.OUTPUT_FOLDER, data_request.data_folder))
        self.assertTrue(isinstance(data_request.get_filename_list(), list), "Expected a list")
        self.assertTrue(isinstance(data_request.get_url_list(), list), "Expected a list")
        self.assertTrue(data_request.is_valid_request(), "Request should be valid")


class TestDataRequestSaving(TestSentinelHub):

    @classmethod
github sentinel-hub / sentinelhub-py / tests / test_areas.py View on Github external
import unittest
import os
import itertools

import shapely.geometry

from sentinelhub import BBoxSplitter, OsmSplitter, TileSplitter, CustomGridSplitter, BBox, read_data, CRS, \
    DataSource, TestSentinelHub


class TestOgc(TestSentinelHub):

    class SplitterTestCase:

        def __init__(self, name, splitter, bbox_len):
            self.name = name
            self.splitter = splitter
            self.bbox_len = bbox_len

    @classmethod
    def setUpClass(cls):
        super().setUpClass()

        geojson = read_data(os.path.join(cls.INPUT_FOLDER, 'cies_islands.json'))
        cls.area = shapely.geometry.shape(geojson)

        bbox_grid = [BBox((x / 10, y / 100, (x + 1) / 10, (y + 1) / 100), CRS.WGS84)
github sentinel-hub / sentinelhub-py / tests / test_ogc.py View on Github external
import unittest
import datetime
import numpy as np

from sentinelhub import WmsRequest, WcsRequest, CRS, MimeType, CustomUrlParam, ServiceType, DataSource, BBox,\
    TestSentinelHub, TestCaseContainer
from sentinelhub.data_request import OgcRequest
from sentinelhub.ogc import OgcImageService


class TestOgc(TestSentinelHub):

    class OgcTestCase(TestCaseContainer):
        """
        Container for each test case of sentinelhub OGC functionalities
        """
        def __init__(self, name, request, result_len, save_data=False, **kwargs):
            super().__init__(name, request, **kwargs)

            self.result_len = result_len
            self.save_data = save_data

            self.data = None

        def collect_data(self):
            if self.save_data:
                self.request.save_data(redownload=True, data_filter=self.data_filter)
github sentinel-hub / sentinelhub-py / tests / test_geopedia.py View on Github external
gpd_request = GeopediaWmsRequest(layer=1917, theme='ml_aws', bbox=bbox, width=50, height=50,
                                         image_format=MimeType.PNG)

        cls.data = gpd_request.get_data()

    def test_return_type(self):
        data_len = 1
        self.assertTrue(isinstance(self.data, list), "Expected a list")
        self.assertEqual(len(self.data), data_len,
                         "Expected a list of length {}, got length {}".format(data_len, len(self.data)))

    def test_stats(self):
        self.test_numpy_data(np.array(self.data), exp_min=0, exp_max=255, exp_mean=150.9248, exp_median=255)


class TestGeopediaImageService(TestSentinelHub):

    @classmethod
    def setUpClass(cls):
        super().setUpClass()

        bbox = BBox(bbox=[(13520759, 437326), (13522689, 438602)], crs=CRS.POP_WEB)
        cls.image_field_name = 'Masks'

        cls.gpd_request = GeopediaImageRequest(layer=1749, bbox=bbox, image_field_name=cls.image_field_name,
                                               image_format=MimeType.PNG, data_folder=cls.OUTPUT_FOLDER)
        cls.image_list = cls.gpd_request.get_data(save_data=True)

    def test_return_type(self):
        self.assertTrue(isinstance(self.image_list, list), 'Expected a list, got {}'.format(type(self.image_list)))

        expected_len = 5
github sentinel-hub / sentinel2-cloud-detector / tests / test_all.py View on Github external
import unittest
import os

from sentinelhub import TestSentinelHub


class TestS2Cloudless(TestSentinelHub):

    INPUT_DATA_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'TestInputs', 'input_arrays.npz')


if __name__ == '__main__':
    loader = unittest.TestLoader()
    suite = loader.discover(os.path.dirname(os.path.realpath(__file__)))
    runner = unittest.TextTestRunner()
    runner.run(suite)
github sentinel-hub / sentinelhub-py / tests / test_geometry.py View on Github external
bbox = BBox([46.07, 13.23, 46.24, 13.57], CRS.WGS84)

        self.assertTrue(isinstance(bbox.get_geojson(), dict),
                        "Expected dictionary, got type {}".format(type(bbox.geometry)))
        self.assertTrue(isinstance(bbox.get_geometry(), shapely.geometry.Polygon),
                        "Expected type {}, got type {}".format(shapely.geometry.Polygon,
                                                               type(bbox.get_geometry())))

    def test_buffer(self):
        bbox = BBox([46.07, 13.23, 46.24, 13.57], CRS.WGS84)

        self.assertEqual(bbox, bbox.buffer(0), "Buffer 1 should not change bounding box")
        self.assertEqual(bbox, bbox.buffer(1).buffer(-0.5), "Twice buffered bounding box should return to original")


class TestGeometry(TestSentinelHub):

    @classmethod
    def setUpClass(cls):
        super().setUpClass()

        polygon = shapely.geometry.Polygon([(465888.8773268595, 5079639.43613863),
                                            (465885.3413983975, 5079641.52461826),
                                            (465882.9542217017, 5079647.16604353),
                                            (465888.8780175466, 5079668.70367663),
                                            (465888.877326859, 5079639.436138632)])
        cls.wkt_string = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), ' \
                         '(30 20, 20 15, 20 25, 30 20)))'
        cls.geometry1 = Geometry(polygon, CRS(32633))
        cls.geometry2 = Geometry(cls.wkt_string, CRS.WGS84)
        cls.bbox = BBox(bbox=[14.00, 45.00, 14.03, 45.03], crs=CRS.WGS84)
        cls.bbox_collection = BBoxCollection([cls.bbox, BBox('46,13,47,20', CRS.WGS84)])
github sentinel-hub / sentinelhub-py / tests / test_constants.py View on Github external
(CRS.POP_WEB, 'EPSG:3857'),
            (CRS.WGS84, 'EPSG:4326'),
            (CRS.UTM_33N, 'EPSG:32633'),
            (CRS.UTM_33S, 'EPSG:32733')
        )
        for crs, epsg in crs_values:
            with self.subTest(msg=epsg):
                ogc_str = CRS.ogc_string(crs)
                self.assertEqual(epsg, ogc_str, msg="Expected {}, got {}".format(epsg, ogc_str))

    def test_has_value(self):
        for crs in CRS:
            self.assertTrue(CRS.has_value(crs.value), msg="Expected support for CRS {}".format(crs.value))


class TestMimeType(TestSentinelHub):
    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 / sentinelhub-py / tests / test_constants.py View on Github external
class TestRequestType(TestSentinelHub):
    def test_request_type(self):
        with self.assertRaises(ValueError):
            RequestType('post')

        with self.assertRaises(ValueError):
            RequestType('get')

        try:
            RequestType('POST')
            RequestType('GET')
        except BaseException:
            self.fail("Couldn't instantiate enum")


class TestDataSource(TestSentinelHub):
    def test_adding_custom_datasource(self):
        collectionid_datasourcename_wfsid = (
            ('0000d273-7e89-4f00-971e-9025f89a0000', 'BYOC_0000d273-7e89-4f00-971e-9025f89a0000',
             'DSS10-0000d273-7e89-4f00-971e-9025f89a0000'),
        )
        for collection_id, data_source_name, wfs_id in collectionid_datasourcename_wfsid:
            datasource = DataSource(collection_id)

            wfsid_tested = DataSource.get_wfs_typename(datasource)
            self.assertEqual(data_source_name, datasource.name, msg="Expected {}, got {}".
                             format(data_source_name, datasource.name))
            self.assertEqual(wfs_id, wfsid_tested, msg="Expected {}, got {}".format(wfs_id, wfsid_tested))

            self.assertTrue(datasource in DataSource.get_available_sources(), msg='Datasource should be in the list'
                                                                                   'of all datasources')
            self.assertTrue(datasource in DataSource.get_custom_sources(), msg='Datasource should be in the list'
github sentinel-hub / sentinelhub-py / tests / test_io_utils.py View on Github external
import unittest
import os
import numpy as np

from platform import python_implementation

from sentinelhub import read_data, write_data, TestSentinelHub


class TestIO(TestSentinelHub):

    class IOTestCase:

        def __init__(self, filename, mean, shape=(2048, 2048, 3)):
            self.filename = filename
            self.mean = mean
            self.shape = shape

    @classmethod
    def setUpClass(cls):
        super().setUpClass()

        cls.test_cases = [
            cls.IOTestCase('img.tif', 13577.494856),
            cls.IOTestCase('img.jpg', 52.41194),
            cls.IOTestCase('img.png', 52.33736),