Esempio n. 1
0
    def test_bbox_from_bad_string(self):
        with self.subTest(msg="Too few coordinates"):
            bbox_str = '46.07, 13.23, 46.24'
            with self.assertRaises(ValueError):
                bbox = BBox(bbox_str, CRS.WGS84)

        with self.subTest(msg="Invalid string"):
            bbox_str = '46N,13E,45N,12E'
            with self.assertRaises(ValueError):
                BBox(bbox_str, CRS.WGS84)
Esempio n. 2
0
 def test_bbox_from_flat_list(self):
     for bbox_lst in [[46.07, 13.23, 46.24, 13.57],
                      [46.24, 13.23, 46.07, 13.57],
                      [46.07, 13.57, 46.24, 13.23],
                      [46.24, 13.57, 46.07, 13.23]]:
         with self.subTest(msg="bbox={}".format(bbox_lst)):
             bbox = BBox(bbox_lst, CRS.WGS84)
             self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
             self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
             self.assertEqual(bbox.get_crs(), CRS.WGS84)
    def create_requests(self):
        """
        Creates basic requests:
        True color request for simpler data visualization
        Scaled all bands request for cloud detection
        All bands request for data processing
        :return: Tuple[tc_request, scaled_cloud_request, all_bands_request]
        """
        # Request true color data for visualization in same resolution as full data
        wms_true_color_request = WcsRequest(
            layer='TRUE_COLOR',
            bbox=self.bbox,
            data_folder=self.data_folder_name,
            time=self.time_range,
            resx=str(self.res_x) + "m",
            resy=str(self.res_y) + "m",
            image_format=MimeType.PNG,
            instance_id=self.instance_id,
            custom_url_params={
                CustomUrlParam.SHOWLOGO: False,
            },
        )
        # Scaled cloud detection must be run on images a bit bigger to get
        # boundary pixels with better accuracy
        # and to eliminate missing pixels on the edge
        cloud_bbox = list(self.coordinates)
        # Note: Numbers are not precise
        cloud_bbox[2] += 0.001
        cloud_bbox[3] += 0.001

        # Create cloud request
        wms_bands_request = WcsRequest(
            layer='ALL-BANDS',
            data_folder=self.data_folder_name,
            custom_url_params={CustomUrlParam.SHOWLOGO: False},
            bbox=BBox(bbox=cloud_bbox, crs=CRS.WGS84),
            time=self.time_range,
            resx=str(self.cloud_res_x) + "m",
            resy=str(self.cloud_res_y) + "m",
            image_format=MimeType.TIFF_d32f,
            instance_id=self.instance_id)

        # Download all bands
        wms_all_bands_request = WcsRequest(
            layer='ALL-BANDS',
            data_folder=self.data_folder_name,
            custom_url_params={CustomUrlParam.SHOWLOGO: False},
            bbox=BBox(bbox=self.bbox, crs=CRS.WGS84),
            time=self.time_range,
            resx=str(self.res_x) + "m",
            resy=str(self.res_y) + "m",
            image_format=MimeType.TIFF_d32f,
            instance_id=self.instance_id)

        return wms_true_color_request, wms_bands_request, wms_all_bands_request
Esempio n. 4
0
 def test_bbox_from_dict(self):
     bbox_dict = {
         'min_x': 46.07,
         'min_y': 13.23,
         'max_x': 46.24,
         'max_y': 13.57
     }
     bbox = BBox(bbox_dict, CRS.WGS84)
     self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
     self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
     self.assertEqual(bbox.get_crs(), CRS.WGS84)
Esempio n. 5
0
    def create_requests(self):

        wms_true_color_request = WcsRequest(
            layer='TRUE_COLOR',
            bbox=self.bbox,
            data_folder=self.data_folder_name,
            time=self.time_range,
            resx=str(self.res_x) + "m",
            resy=str(self.res_y) + "m",
            image_format=MimeType.PNG,
            instance_id=self.instance_id,
            maxcc=0.05,  #oblaki
            time_difference=datetime.timedelta(hours=2),
            custom_url_params={
                CustomUrlParam.SHOWLOGO: False,
                CustomUrlParam.TRANSPARENT: True,
            },
        )
        cloud_bbox = list(self.coordinates)
        # To get one more pixel when downloading clouds
        # Note: Numbers are not precise
        cloud_bbox[2] += 0.001
        cloud_bbox[3] += 0.001
        # Note: large widths are much much slower and more computationally expensive
        wms_bands_request = WcsRequest(
            layer='ALL-BANDS',
            data_folder=self.data_folder_name,
            custom_url_params={CustomUrlParam.SHOWLOGO: False},
            bbox=BBox(bbox=cloud_bbox, crs=CRS.WGS84),
            time=self.time_range,
            resx=str(self.cloud_res_x) + "m",
            resy=str(self.cloud_res_y) + "m",
            image_format=MimeType.TIFF_d32f,
            instance_id=self.instance_id)

        wms_all_bands_request = WcsRequest(
            layer='ALL-BANDS',
            data_folder=self.data_folder_name,
            custom_url_params={CustomUrlParam.SHOWLOGO: False},
            bbox=BBox(bbox=self.bbox, crs=CRS.WGS84),
            time=self.time_range,
            resx=str(self.res_x) + "m",
            resy=str(self.res_y) + "m",
            maxcc=0.05,  #oblaki
            time_difference=datetime.timedelta(hours=2),
            image_format=MimeType.TIFF_d32f,
            instance_id=self.instance_id)

        return wms_true_color_request, wms_bands_request, wms_all_bands_request
    def __init__(self,
                 coordinates,
                 start_time='2014-12-01',
                 end_time=datetime.datetime.now().strftime('%Y-%m-%d'),
                 data_folder_name="data/",
                 cloud_scale=6,
                 res=(10, 10),
                 redownload=False,
                 instance_id=INSTANCE_ID,
                 cloud_detector_config=None):

        self.coordinates = coordinates
        self.bbox = BBox(bbox=self.coordinates, crs=CRS.WGS84)

        self.data_folder_name = data_folder_name
        self.start_time = start_time
        self.end_time = end_time
        self.time_range = (start_time, end_time)
        self.redownload = redownload
        self.instance_id = instance_id
        if cloud_detector_config is None:
            self.cloud_detector_config = {
                'threshold': 0.4,
                'average_over': 4,
                'dilation_size': 2,
                'all_bands': True
            }
        else:
            self.cloud_detector_config = cloud_detector_config
        self.res_x, self.res_y = res
        self.cloud_res_x = cloud_scale * self.res_x
        self.cloud_res_y = cloud_scale * self.res_y
        self.cloud_scale = cloud_scale
        self.memo_data = None  # type: CloudSaturation.MemoData
Esempio n. 7
0
 def test_bbox_iter(self):
     bbox_lst = [46.07, 13.23, 46.24, 13.57]
     bbox = BBox(bbox_lst, CRS.WGS84)
     bbox_iter = [coord for coord in bbox]
     self.assertEqual(bbox_iter,
                      bbox_lst,
                      msg="Expected {}, got {}".format(bbox_lst, bbox_iter))
Esempio n. 8
0
    def __init__(
        self,
        coordinates,
        start_time='2016-01-01',
        #end_time=datetime.datetime.now().strftime('%Y-%m-%d'),
        end_time='2016-12-31',
        data_folder_name="data/",
        cloud_scale=6,
        res=(10, 10),
        redownload=False,
        instance_id=INSTANCE_ID,
        cloud_detector_config=dict(threshold=0.4,
                                   average_over=4,
                                   dilation_size=2,
                                   all_bands=True)):
        self.coordinates = coordinates
        self.bbox = BBox(bbox=self.coordinates, crs=CRS.WGS84)

        self.data_folder_name = data_folder_name
        self.start_time = start_time
        self.end_time = end_time
        self.time_range = (start_time, end_time)
        self.redownload = redownload
        self.instance_id = instance_id
        self.cloud_detection_config = cloud_detector_config
        self.res_x, self.res_y = res
        self.cloud_res_x = cloud_scale * self.res_x
        self.cloud_res_y = cloud_scale * self.res_y
        self.cloud_scale = cloud_scale
        self.memo_data = None  # type: CloudSaturation.MemoData
Esempio n. 9
0
    def setUpClass(cls):
        bbox = BBox(bbox=(47.94, -5.23, 48.17, -5.03), crs=CRS.WGS84)
        cls.stat_expect = {
            'min': 0.0008,
            'max': 0.6511,
            'mean': 0.2307,
            'median': 0.2397
        }
        cls.request_save = WmsRequest(data_folder=cls.OUTPUT_FOLDER,
                                      image_format=MimeType.TIFF_d32f,
                                      layer='ALL_BANDS',
                                      maxcc=1.0,
                                      width=512,
                                      bbox=bbox,
                                      time=('2017-10-01', '2017-10-02'),
                                      instance_id=cls.INSTANCE_ID)
        cls.data_save = cls.request_save.get_data(save_data=True,
                                                  redownload=True)

        cls.request_get = WmsRequest(image_format=MimeType.TIFF_d32f,
                                     layer='ALL_BANDS',
                                     maxcc=1.0,
                                     width=512,
                                     bbox=bbox,
                                     time=('2017-10-01', '2017-10-02'),
                                     instance_id=cls.INSTANCE_ID)
        cls.data_get = cls.request_get.get_data()
 def __init__(
         self,
         coordinates: Tuple[float, float, float, float],
         *,
         interpolate: bool = True,
         data_folder_name: str = "data/",
         stream_data_folder_name: str = os.path.join("stream_data"),
         start_date: str = "2017-01-01",
         end_date: str = "2017-12-31",
         res_x: int = 60,
         res_y: int = 60,
         redownload: bool = False,
         instance_id: str = INSTANCE_ID,
         cloud_detection_settings: Optional[CloudDetectionSettings] = None):
     self.interpolate = interpolate
     self.coordinates = coordinates
     self.bbox = BBox(self.coordinates, crs=CRS.WGS84)
     self.data_folder_name = data_folder_name
     self.stream_data_folder_name = stream_data_folder_name
     self.start_date = start_date
     self.end_date = end_date
     self.time_range = self.start_date, self.end_date
     self.res_x = res_x
     self.res_y = res_y
     self.redownload = redownload
     self.instance_id = instance_id
     if cloud_detection_settings is None:
         self.cloud_detection_settings = DEFAULT_CLOUD_DETECTION_SETTINGS
     else:
         self.cloud_detection_settings = cloud_detection_settings
Esempio n. 11
0
 def setUpClass(cls):
     bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
     cls.stat_expect = {'min': 0.1443, 'max': 0.4915, 'mean': 0.3565, 'median': 0.4033}
     cls.request = WcsRequest(data_folder='TestOutputs', bbox=bbox, layer='ALL_BANDS', resx='10m', resy='20m',
                              time=('2017-01-01', '2017-02-01'), maxcc=1.0, image_format=MimeType.TIFF_d32f,
                              instance_id=INSTANCE_ID)
     cls.data = cls.request.get_data(save_data=True, redownload=True)
     cls.dates = cls.request.get_dates()
Esempio n. 12
0
 def test_bbox_to_str(self):
     x1, y1, x2, y2 = 45, 12, 47, 14
     crs = CRS.WGS84
     expect_str = "{},{},{},{}".format(x1, y1, x2, y2)
     bbox = BBox(((x1, y1), (x2, y2)), crs)
     self.assertEqual(
         str(bbox),
         expect_str,
         msg="String representations not matching: expected {}, got {}".
         format(expect_str, str(bbox)))
Esempio n. 13
0
    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', instance_id=self.INSTANCE_ID)

        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")
Esempio n. 14
0
 def setUpClass(cls):
     bbox = BBox(bbox=(47.94, -5.23, 48.17, -5.03), crs=CRS.WGS84)
     cls.request = OgcRequest(image_format=MimeType.TIFF_d32f,
                              layer='ALL_BANDS',
                              maxcc=1.0,
                              data_folder='TestOutputs',
                              bbox=bbox,
                              time=('2017-10-01', '2017-10-31'),
                              time_difference=datetime.timedelta(days=10),
                              source=DataSource.WMS,
                              instance_id=INSTANCE_ID)
Esempio n. 15
0
 def test_get_area_dates(self):
     bbox = BBox([
         1059111.463919402, 4732980.791418114, 1061557.4488245277,
         4735426.776323237
     ],
                 crs=CRS.POP_WEB)
     dates = get_area_dates(bbox, ('2016-01-23', '2016-11-24'), maxcc=0.7)
     self.assertTrue(isinstance(dates, list),
                     msg="Expected a list, got {}".format(type(dates)))
     self.assertEqual(
         len(dates), 22,
         "Expected a list of length 22, got length {}".format(len(dates)))
Esempio n. 16
0
 def setUpClass(cls):
     bbox = BBox(bbox=(47.94, -5.23, 48.17, -5.03), crs=CRS.WGS84)
     cls.request = WmsRequest(data_folder=cls.FALSE_FOLDER,
                              image_format=MimeType.PNG,
                              layer='TRUE_COLOR',
                              maxcc=1.0,
                              width=512,
                              height=512,
                              time='latest',
                              bbox=bbox,
                              instance_id=cls.INSTANCE_ID)
     cls.data = cls.request.get_data(save_data=False, redownload=True)
Esempio n. 17
0
    def setUpClass(cls):
        bbox = BBox(bbox=[(524358.0140363087, 6964349.630376049),
                          (534141.9536568124, 6974133.5699965535)],
                    crs=CRS.POP_WEB)

        gpd_request = GeopediaWmsRequest(layer='ttl1917',
                                         theme='ml_aws',
                                         bbox=bbox,
                                         width=50,
                                         height=50,
                                         image_format=MimeType.PNG)

        cls.data = gpd_request.get_data()
Esempio n. 18
0
 def test_get_image_dimensions(self):
     bbox = BBox(((111.644, 8.655), (111.7, 8.688)), CRS.WGS84)
     width = geo_utils.get_image_dimension(bbox, height=715)
     height = geo_utils.get_image_dimension(bbox, width=1202)
     expected_width = 1203
     expected_height = 715
     self.assertEqual(width,
                      expected_width,
                      msg="Expected width {}, got {}".format(
                          expected_width, width))
     self.assertEqual(height,
                      expected_height,
                      msg="Expected height {}, got {}".format(
                          expected_height, height))
    def create_requests(self):
        # Get all bands
        all_bands_request = WcsRequest(
            layer="ALL-BANDS",
            data_folder=self.settings.data_folder_name,
            custom_url_params={CustomUrlParam.SHOWLOGO: False},
            bbox=BBox(bbox=self.settings.bbox, crs=CRS.WGS84),
            time=self.settings.time_range,
            resx=str(self.settings.res_x) + "m",
            resy=str(self.settings.res_y) + "m",
            image_format=MimeType.TIFF_d32f,
            instance_id=self.settings.instance_id)

        if (self.settings.cloud_detection_settings.x_scale == 1
                and self.settings.cloud_detection_settings.y_scale == 1):
            cloud_bands_request = all_bands_request
        else:
            cloud_bbox = list(self.settings.coordinates)
            # To get one more pixel when downloading clouds
            # Note: Numbers are not precise
            cloud_bbox[2] += 0.001
            cloud_bbox[3] += 0.001
            cloud_bbox = tuple(cloud_bbox)

            cloud_bands_request = WcsRequest(
                layer='ALL-BANDS',
                data_folder=self.settings.data_folder_name,
                custom_url_params={CustomUrlParam.SHOWLOGO: False},
                bbox=BBox(bbox=cloud_bbox, crs=CRS.WGS84),
                time=self.settings.time_range,
                resx=str(self.settings.cloud_detection_settings.x_scale) + "m",
                resy=str(self.settings.cloud_detection_settings.y_scale) + "m",
                image_format=MimeType.TIFF_d32f,
                instance_id=self.settings.instance_id)

        return all_bands_request, cloud_bands_request
Esempio n. 20
0
 def test_bbox_to_resolution(self):
     bbox = BBox(((111.644, 8.655), (111.7, 8.688)), CRS.WGS84)
     resx, resy = geo_utils.bbox_to_resolution(bbox, 512, 512)
     expected_resx = 12.02
     expected_resy = 7.15
     self.assertAlmostEqual(resx,
                            expected_resx,
                            delta=1E-2,
                            msg="Expected resx {}, got {}".format(
                                str(expected_resx), str(resx)))
     self.assertAlmostEqual(resy,
                            expected_resy,
                            delta=1E-2,
                            msg="Expected resy {}, got {}".format(
                                str(expected_resy), str(resy)))
Esempio n. 21
0
    def test_init(self):

        valid_dir_name = 'test_dir'
        try:
            os.makedirs(os.path.abspath(valid_dir_name))
        except OSError as exception:
            if exception.errno != errno.EEXIST:
                self.fail('Failed to create test directory at {}'.format(os.path.abspath(valid_dir_name)))

        bbox = BBox((8.655, 111.7, 8.688, 111.6), crs=CRS.WGS84)
        data_request = WcsRequest(data_folder=valid_dir_name, bbox=bbox,
                                  layer='ALL_BANDS', instance_id=INSTANCE_ID)

        self.assertEqual(valid_dir_name, data_request.data_folder,
                         msg="Expected {}, got {}".format(valid_dir_name, data_request.data_folder))

        os.rmdir(os.path.abspath(valid_dir_name))

        data_request = WcsRequest(data_folder=valid_dir_name, bbox=bbox,
                                  layer='ALL_BANDS', instance_id=INSTANCE_ID)

        self.assertEqual(True, os.path.exists(os.path.abspath(data_request.data_folder)),
                         msg="Expected output dir {} to exist.".format(data_request.data_folder))

        os.rmdir(os.path.abspath(valid_dir_name))

        invalid_dir_name = '/test_dir'
        try:
            os.makedirs(os.path.abspath(invalid_dir_name))
        except OSError:
            try:
                WcsRequest(data_folder=invalid_dir_name,
                                           bbox=bbox,
                                           layer='ALL_BANDS')
            except ValueError as err:
                LOGGER.error(err)
Esempio n. 22
0
    def setUpClass(cls):
        bbox = BBox(bbox=(47.94, -5.23, 48.17, -5.03), crs=CRS.WGS84)

        cls.stat_expect_atmfilter = {'min': 12, 'max': 255, 'mean': 190.0, 'median': 199.0}
        cls.stat_expect_preview = {'min': 28, 'max': 253, 'mean': 171.8, 'median': 171.0}
        cls.stat_expect_evalscript_url = {'min': 17, 'max': 255, 'mean': 162.4, 'median': 159.0}
        cls.stat_expect_evalscript = {'min': 0, 'max': 235, 'mean': 46.22, 'median': 54.0}

        cls.request_atmfilter = WmsRequest(data_folder='TestOutputs', image_format=MimeType.PNG, layer='TRUE_COLOR',
                                           maxcc=1.0, width=512, height=512, bbox=bbox, instance_id=INSTANCE_ID,
                                           time=('2017-10-01', '2017-10-02'),
                                           custom_url_params={CustomUrlParam.ATMFILTER: 'ATMCOR',
                                                              CustomUrlParam.QUALITY: 100,
                                                              CustomUrlParam.DOWNSAMPLING: 'BICUBIC',
                                                              CustomUrlParam.UPSAMPLING: 'BICUBIC'})

        cls.request_preview = WmsRequest(data_folder='TestOutputs', image_format=MimeType.PNG, layer='TRUE_COLOR',
                                         maxcc=1.0, width=512, height=512, bbox=bbox, time=('2017-10-01', '2017-10-02'),
                                         instance_id=INSTANCE_ID, custom_url_params={CustomUrlParam.PREVIEW: 2})

        cls.request_evalscript_url = WmsRequest(data_folder='TestOutputs', image_format=MimeType.PNG,
                                                layer='TRUE_COLOR', maxcc=1.0, width=512, height=512, bbox=bbox,
                                                time=('2017-10-01', '2017-10-02'), instance_id=INSTANCE_ID,
                                                custom_url_params={CustomUrlParam.EVALSCRIPTURL:
                                                                   'https://raw.githubusercontent.com/sentinel-hub/'
                                                                   'customScripts/master/sentinel-2/false_color_'
                                                                   'infrared/script.js'})
        cls.request_evalscript = WmsRequest(data_folder='TestOutputs', image_format=MimeType.PNG, layer='TRUE_COLOR',
                                            maxcc=1.0, height=512, bbox=bbox,
                                            time=('2017-10-01', '2017-10-02'), instance_id=INSTANCE_ID,
                                            custom_url_params={CustomUrlParam.EVALSCRIPT: 'return [B10,B8A,B03]'})

        cls.data_atmfilter = cls.request_atmfilter.get_data(redownload=True)
        cls.data_preview = cls.request_preview.get_data(redownload=True)
        cls.data_evalscript_url = cls.request_evalscript_url.get_data(redownload=True)
        cls.data_evalscript = cls.request_evalscript.get_data(redownload=True)
Esempio n. 23
0
    def setUpClass(cls):
        wgs84_bbox = BBox(bbox=(-5.23, 48.0, -5.03, 48.17), crs=CRS.WGS84)
        wgs84_bbox_2 = BBox(bbox=(21.3, 64.0, 22.0, 64.5), crs=CRS.WGS84)
        wgs84_bbox_3 = BBox(bbox=(-72.0, -70.4, -71.8, -70.2), crs=CRS.WGS84)
        pop_web_bbox = BBox(bbox=(1292344.0, 5195920.0, 1310615.0, 5214191.0),
                            crs=CRS.POP_WEB)
        geometry_wkt = 'POLYGON((1292344.0 5205055.5, 1301479.5 5195920.0, 1310615.0 5205055.5, ' \
                       '1301479.5 5214191.0, 1292344.0 5205055.5))'
        img_width = 100
        img_height = 100
        resx = '53m'
        resy = '78m'
        expected_date = datetime.datetime.strptime('2017-10-07T11:20:58',
                                                   '%Y-%m-%dT%H:%M:%S')

        cls.test_cases = [
            cls.OgcTestCase('generalWmsTest',
                            OgcRequest(
                                data_folder=cls.OUTPUT_FOLDER,
                                image_format=MimeType.TIFF_d32f,
                                bbox=wgs84_bbox,
                                layer='BANDS-S2-L1C',
                                maxcc=0.5,
                                size_x=img_width,
                                size_y=img_height,
                                time=('2017-01-01', '2018-01-01'),
                                instance_id=cls.INSTANCE_ID,
                                service_type=ServiceType.WMS,
                                time_difference=datetime.timedelta(days=10)),
                            result_len=14,
                            img_min=0.0,
                            img_max=1.5964,
                            img_mean=0.1810,
                            img_median=0.1140,
                            tile_num=29,
                            save_data=True,
                            data_filter=[0, -2, 0]),
            cls.OgcTestCase('generalWcsTest',
                            OgcRequest(
                                data_folder=cls.OUTPUT_FOLDER,
                                image_format=MimeType.TIFF_d32f,
                                bbox=wgs84_bbox,
                                layer='BANDS-S2-L1C',
                                maxcc=0.6,
                                size_x=resx,
                                size_y=resy,
                                time=('2017-10-01', '2018-01-01'),
                                instance_id=cls.INSTANCE_ID,
                                service_type=ServiceType.WCS,
                                time_difference=datetime.timedelta(days=5)),
                            result_len=5,
                            img_min=0.0002,
                            img_max=0.5266,
                            img_mean=0.1038,
                            img_median=0.0948,
                            tile_num=9,
                            date_check=expected_date,
                            save_data=True,
                            data_filter=[0, -1]),
            # CustomUrlParam tests:
            cls.OgcTestCase('customUrlAtmcorQualitySampling',
                            WmsRequest(data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.PNG,
                                       layer='TRUE-COLOR-S2-L1C',
                                       width=img_width,
                                       bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={
                                           CustomUrlParam.SHOWLOGO: True,
                                           CustomUrlParam.ATMFILTER: 'ATMCOR',
                                           CustomUrlParam.QUALITY: 100,
                                           CustomUrlParam.DOWNSAMPLING:
                                           'BICUBIC',
                                           CustomUrlParam.UPSAMPLING: 'BICUBIC'
                                       }),
                            result_len=1,
                            img_min=11,
                            img_max=255,
                            img_mean=193.796,
                            img_median=206,
                            tile_num=2,
                            data_filter=[0, -1]),
            cls.OgcTestCase('customUrlPreview',
                            WmsRequest(data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.PNG,
                                       layer='TRUE-COLOR-S2-L1C',
                                       height=img_height,
                                       bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={
                                           CustomUrlParam.SHOWLOGO: True,
                                           CustomUrlParam.PREVIEW: 2
                                       }),
                            result_len=1,
                            img_min=27,
                            img_max=253,
                            img_mean=176.732,
                            img_median=177,
                            tile_num=2),
            cls.OgcTestCase(
                'customUrlEvalscripturl',
                WcsRequest(
                    data_folder=cls.OUTPUT_FOLDER,
                    image_format=MimeType.PNG,
                    layer='TRUE-COLOR-S2-L1C',
                    resx=resx,
                    resy=resy,
                    bbox=pop_web_bbox,
                    instance_id=cls.INSTANCE_ID,
                    time=('2017-10-01', '2017-10-02'),
                    custom_url_params={
                        CustomUrlParam.SHOWLOGO:
                        True,
                        CustomUrlParam.EVALSCRIPTURL:
                        'https://raw.githubusercontent.com/sentinel-hub/'
                        'customScripts/master/sentinel-2/false_color_infrared/'
                        'script.js'
                    }),
                result_len=1,
                img_min=41,
                img_max=255,
                img_mean=230.568,
                img_median=255,
                tile_num=3),
            cls.OgcTestCase('customUrlEvalscript,Transparent',
                            WcsRequest(data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.PNG,
                                       layer='TRUE-COLOR-S2-L1C',
                                       resx=resx,
                                       resy=resy,
                                       bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={
                                           CustomUrlParam.SHOWLOGO:
                                           True,
                                           CustomUrlParam.TRANSPARENT:
                                           True,
                                           CustomUrlParam.EVALSCRIPT:
                                           'return [B10,B8A, B03 ]'
                                       }),
                            result_len=1,
                            img_min=0,
                            img_max=255,
                            img_mean=100.1543,
                            img_median=68.0,
                            tile_num=2),
            cls.OgcTestCase('FalseLogo,BgColor,Geometry',
                            WmsRequest(data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.PNG,
                                       layer='TRUE-COLOR-S2-L1C',
                                       width=img_width,
                                       height=img_height,
                                       bbox=pop_web_bbox,
                                       instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={
                                           CustomUrlParam.SHOWLOGO: False,
                                           CustomUrlParam.BGCOLOR: "F4F86A",
                                           CustomUrlParam.GEOMETRY:
                                           geometry_wkt
                                       }),
                            result_len=1,
                            img_min=63,
                            img_max=255,
                            img_mean=213.3590,
                            img_median=242.0,
                            tile_num=3),

            # DataSource tests:
            cls.OgcTestCase('S2 L1C Test',
                            WmsRequest(data_source=DataSource.SENTINEL2_L1C,
                                       data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d8,
                                       layer='BANDS-S2-L1C',
                                       width=img_width,
                                       height=img_height,
                                       bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02')),
                            result_len=1,
                            img_min=38,
                            img_max=152,
                            img_mean=84.6465,
                            img_median=84.0,
                            tile_num=2),
            cls.OgcTestCase('S2 L2A Test',
                            WmsRequest(data_source=DataSource.SENTINEL2_L2A,
                                       data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF,
                                       layer='BANDS-S2-L2A',
                                       width=img_width,
                                       height=img_height,
                                       bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02')),
                            result_len=1,
                            img_min=0.0,
                            img_max=65535,
                            img_mean=22743.5164,
                            img_median=21390.0,
                            tile_num=2),
            cls.OgcTestCase('L8 Test',
                            WmsRequest(
                                data_source=DataSource.LANDSAT8,
                                data_folder=cls.OUTPUT_FOLDER,
                                image_format=MimeType.TIFF_d32f,
                                layer='BANDS-L8',
                                width=img_width,
                                height=img_height,
                                bbox=wgs84_bbox,
                                instance_id=cls.INSTANCE_ID,
                                time=('2017-10-05', '2017-10-10'),
                                time_difference=datetime.timedelta(hours=1)),
                            result_len=1,
                            img_min=0.0011,
                            img_max=285.72415,
                            img_mean=52.06075,
                            img_median=0.5192,
                            tile_num=2),
            cls.OgcTestCase('DEM Test',
                            WmsRequest(data_source=DataSource.DEM,
                                       data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f,
                                       layer='DEM',
                                       width=img_width,
                                       height=img_height,
                                       bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID),
                            result_len=1,
                            img_min=-108.0,
                            img_max=-18.0,
                            img_mean=-72.1819,
                            img_median=-72.0),
            cls.OgcTestCase('MODIS Test',
                            WmsRequest(data_source=DataSource.MODIS,
                                       data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f,
                                       layer='BANDS-MODIS',
                                       width=img_width,
                                       height=img_height,
                                       bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID,
                                       time='2017-10-01'),
                            result_len=1,
                            img_min=0.0,
                            img_max=3.2767,
                            img_mean=0.136408,
                            img_median=0.00240,
                            tile_num=1),
            cls.OgcTestCase('S1 IW Test',
                            WmsRequest(
                                data_source=DataSource.SENTINEL1_IW,
                                data_folder=cls.OUTPUT_FOLDER,
                                image_format=MimeType.TIFF_d32f,
                                layer='BANDS-S1-IW',
                                width=img_width,
                                height=img_height,
                                bbox=wgs84_bbox,
                                instance_id=cls.INSTANCE_ID,
                                time=('2017-10-01', '2017-10-02'),
                                time_difference=datetime.timedelta(hours=1)),
                            result_len=1,
                            img_min=0.0,
                            img_max=1.0,
                            img_mean=0.104584,
                            img_median=0.06160,
                            tile_num=2),
            cls.OgcTestCase('S1 EW Test',
                            WmsRequest(
                                data_source=DataSource.SENTINEL1_EW,
                                data_folder=cls.OUTPUT_FOLDER,
                                image_format=MimeType.TIFF_d32f,
                                layer='BANDS-S1-EW',
                                width=img_width,
                                height=img_height,
                                bbox=wgs84_bbox_2,
                                instance_id=cls.INSTANCE_ID,
                                time=('2018-2-7', '2018-2-8'),
                                time_difference=datetime.timedelta(hours=1)),
                            result_len=2,
                            img_min=0.0003,
                            img_max=1.0,
                            img_mean=0.53118,
                            img_median=1.0,
                            tile_num=3),
            cls.OgcTestCase(
                'S1 EW SH Test',
                WmsRequest(data_source=DataSource.SENTINEL1_EW_SH,
                           data_folder=cls.OUTPUT_FOLDER,
                           image_format=MimeType.TIFF_d16,
                           layer='BANDS-S1-EW-SH',
                           width=img_width,
                           height=img_height,
                           bbox=wgs84_bbox_3,
                           custom_url_params={CustomUrlParam.SHOWLOGO: True},
                           instance_id=cls.INSTANCE_ID,
                           time=('2018-2-6', '2018-2-8'),
                           time_difference=datetime.timedelta(hours=1)),
                result_len=1,
                img_min=465,
                img_max=59287,
                img_mean=5323.0523,
                img_median=943.0,
                tile_num=1)
        ]
        """
        cls.test_cases.extend([
            cls.OgcTestCase('EOCloud S1 IW Test',
                            WmsRequest(data_source=DataSource.SENTINEL1_IW, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS_S1_IW',
                                       width=img_width, height=img_height, bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID, time=('2017-10-01', '2017-10-02'),
                                       time_difference=datetime.timedelta(hours=1)),
                            result_len=1, img_min=0.0, img_max=0.49706, img_mean=0.04082, img_median=0.00607,
                            tile_num=2),
        ])
        """

        for test_case in cls.test_cases:
            test_case.collect_data()
Esempio n. 24
0
 def test_bbox_from_bad_dict(self):
     bbox_dict = {'x1': 46.07, 'y1': 13.23, 'x2': 46.24, 'y2': 13.57}
     with self.assertRaises(KeyError):
         bbox = BBox(bbox_dict, CRS.WGS84)
Esempio n. 25
0
 def test_bbox_no_crs(self):
     with self.assertRaises(TypeError):
         bbox = BBox('46,13,47,20')
Esempio n. 26
0
    def setUpClass(cls):
        wgs84_bbox = BBox(bbox=(48.0, -5.23, 48.17, -5.03), crs=CRS.WGS84)
        wgs84_bbox_2 = BBox(bbox=(64.0, 21.3, 64.5, 22.0), crs=CRS.WGS84)
        wgs84_bbox_3 = BBox(bbox=(-70.4, -72.0, -70.2, -71.8), crs=CRS.WGS84)
        pop_web_bbox = BBox(bbox=(1292344.0, 5195920.0, 1310615.0, 5214191.0), crs=CRS.POP_WEB)
        img_width = 100
        img_height = 100
        resx='53m'
        resy='78m'
        expected_date = datetime.datetime.strptime('2017-10-07T11:20:58', '%Y-%m-%dT%H:%M:%S')

        cls.test_cases = [
            cls.OgcTestCase('generalWmsTest',
                            OgcRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.TIFF_d32f, bbox=wgs84_bbox,
                                       layer='ALL_BANDS', maxcc=0.5, size_x=img_width, size_y=img_height,
                                       time=('2017-10-01', '2018-01-01'), instance_id=cls.INSTANCE_ID,
                                       service_type=ServiceType.WMS, time_difference=datetime.timedelta(days=10)),
                            result_len=3, img_min=0.0, img_max=0.4544, img_mean=0.1038, img_median=0.0945,
                            date_check=expected_date, save_data=True),
            cls.OgcTestCase('generalWcsTest',
                            OgcRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.TIFF_d32f, bbox=wgs84_bbox,
                                       layer='ALL_BANDS', maxcc=0.6, size_x=resx, size_y=resy,
                                       time=('2017-10-01', '2018-01-01'), instance_id=cls.INSTANCE_ID,
                                       service_type=ServiceType.WCS, time_difference=datetime.timedelta(days=5)),
                            result_len=5, img_min=0.0002, img_max=0.5266, img_mean=0.1038, img_median=0.0948,
                            date_check=expected_date, save_data=True),

            # CustomUrlParam tests:
            cls.OgcTestCase('customUrlAtmcorQualitySampling',
                            WmsRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.PNG, layer='TRUE_COLOR',
                                       width=img_width, bbox=wgs84_bbox, instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={CustomUrlParam.ATMFILTER: 'ATMCOR',
                                                          CustomUrlParam.QUALITY: 100,
                                                          CustomUrlParam.DOWNSAMPLING: 'BICUBIC',
                                                          CustomUrlParam.UPSAMPLING: 'BICUBIC'}),
                            result_len=1, img_min=11, img_max=255, img_mean=193.796, img_median=206),
            cls.OgcTestCase('customUrlPreview',
                            WmsRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.PNG, layer='TRUE_COLOR',
                                       height=img_height, bbox=wgs84_bbox, instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={CustomUrlParam.PREVIEW: 2}),
                            result_len=1, img_min=27, img_max=253, img_mean=176.732, img_median=177),
            cls.OgcTestCase('customUrlEvalscripturl',
                            WcsRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.PNG, layer='TRUE_COLOR',
                                       resx=resx, resy=resy, bbox=pop_web_bbox, instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={CustomUrlParam.EVALSCRIPTURL:
                                                          'https://raw.githubusercontent.com/sentinel-hub/'
                                                          'customScripts/master/sentinel-2/false_color_infrared/'
                                                          'script.js'}),
                            result_len=1, img_min=41, img_max=255, img_mean=230.568, img_median=255),
            cls.OgcTestCase('customUrlEvalscript',
                            WcsRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.PNG, layer='TRUE_COLOR',
                                       resx=resx, resy=resy, bbox=wgs84_bbox, instance_id=cls.INSTANCE_ID,
                                       time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={CustomUrlParam.EVALSCRIPT: 'return [B10,B8A, B03 ]'}),
                            result_len=1, img_min=0, img_max=235, img_mean=48.539, img_median=55),
            cls.OgcTestCase('customUrlLogoTransparent',
                            WmsRequest(data_folder=cls.OUTPUT_FOLDER, image_format=MimeType.PNG, layer='TRUE_COLOR',
                                       width=img_width, height=img_height, bbox=pop_web_bbox,
                                       instance_id=cls.INSTANCE_ID, time=('2017-10-01', '2017-10-02'),
                                       custom_url_params={CustomUrlParam.SHOWLOGO: True,
                                                          CustomUrlParam.TRANSPARENT: True}),
                            result_len=1, img_min=47, img_max=255, img_mean=229.3749, img_median=242.0),

            # DataSource tests:
            cls.OgcTestCase('S2 L1C Test',
                            WmsRequest(data_source=DataSource.SENTINEL2_L1C, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS-S2-L1C',
                                       width=img_width, height=img_height, bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID, time=('2017-10-01', '2017-10-02')),
                            result_len=1, img_min=0.00089, img_max=0.6284, img_mean=0.2373, img_median=0.2477),
            cls.OgcTestCase('S2 L2A Test',
                            WmsRequest(data_source=DataSource.SENTINEL2_L2A, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS-S2-L2A',
                                       width=img_width, height=img_height, bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID, time=('2017-10-01', '2017-10-02')),
                            result_len=1, img_min=0.0, img_max=1.6720, img_mean=0.34747, img_median=0.32640),
            cls.OgcTestCase('L8 Test',
                            WmsRequest(data_source=DataSource.LANDSAT8, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS-L8',
                                       width=img_width, height=img_height, bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID, time=('2017-10-05', '2017-10-10'),
                                       time_difference=datetime.timedelta(hours=1)),
                            result_len=1, img_min=0.0011, img_max=285.72415, img_mean=52.06075, img_median=0.5192),
            cls.OgcTestCase('DEM Test',
                            WmsRequest(data_source=DataSource.DEM, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='DEM',
                                       width=img_width, height=img_height, bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID),
                            result_len=1, img_min=-108.0, img_max=-18.0, img_mean=-72.1819, img_median=-72.0),
            cls.OgcTestCase('MODIS Test',
                            WmsRequest(data_source=DataSource.MODIS, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS-MODIS',
                                       width=img_width, height=img_height, bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID, time='2017-10-01'),
                            result_len=1, img_min=0.0, img_max=3.2767, img_mean=0.136408, img_median=0.00240),
            cls.OgcTestCase('S1 IW Test',
                            WmsRequest(data_source=DataSource.SENTINEL1_IW, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS-S1-IW',
                                       width=img_width, height=img_height, bbox=wgs84_bbox,
                                       instance_id=cls.INSTANCE_ID, time=('2017-10-01', '2017-10-02'),
                                       time_difference=datetime.timedelta(hours=1)),
                            result_len=1, img_min=0.0, img_max=1.0, img_mean=0.104584, img_median=0.06160),
            cls.OgcTestCase('S1 EW Test',
                            WmsRequest(data_source=DataSource.SENTINEL1_EW, data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS-S1-EW',
                                       width=img_width, height=img_height, bbox=wgs84_bbox_2,
                                       instance_id=cls.INSTANCE_ID, time=('2018-2-7', '2018-2-8'),
                                       time_difference=datetime.timedelta(hours=1)),
                            result_len=2, img_min=0.0003, img_max=1.0, img_mean=0.53118, img_median=1.0),
            cls.OgcTestCase('S1 EW SH Test',
                            WmsRequest(data_source=DataSource.SENTINEL1_EW_SH,
                                       data_folder=cls.OUTPUT_FOLDER,
                                       image_format=MimeType.TIFF_d32f, layer='BANDS-S1-EW-SH',
                                       width=img_width, height=img_height, bbox=wgs84_bbox_3,
                                       instance_id=cls.INSTANCE_ID, time=('2018-2-6', '2018-2-8'),
                                       time_difference=datetime.timedelta(hours=1)),
                            result_len=1, img_min=0.006987, img_max=0.83078, img_mean=0.06599, img_median=0.0140)
        ]

        for test_case in cls.test_cases:
            test_case.collect_data()
Esempio n. 27
0
 def test_bbox_from_nested_tuple(self):
     bbox_tup = (46.07, 13.23), (46.24, 13.57)
     bbox = BBox(bbox_tup, CRS.WGS84)
     self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
     self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
     self.assertEqual(bbox.get_crs(), CRS.WGS84)
Esempio n. 28
0
 def test_bbox_from_nested_list(self):
     bbox_lst = [[-46.07, -13.23], [46.24, 13.57]]
     bbox = BBox(bbox_lst, CRS.WGS84)
     self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
     self.assertEqual(bbox.get_lower_left(), (-46.07, -13.23))
     self.assertEqual(bbox.get_crs(), CRS.WGS84)
Esempio n. 29
0
 def test_bbox_from_string(self):
     bbox_str = '46.07, 13.23, 46.24, 13.57'
     bbox = BBox(bbox_str, CRS.WGS84)
     self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
     self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
     self.assertEqual(bbox.get_crs(), CRS.WGS84)
Esempio n. 30
0
 def test_bbox_from_list_tuple_combo(self):
     bbox_list = [(46.07, 13.23), (46.24, 13.57)]
     bbox = BBox(bbox_list, CRS.WGS84)
     self.assertEqual(bbox.get_upper_right(), (46.24, 13.57))
     self.assertEqual(bbox.get_lower_left(), (46.07, 13.23))
     self.assertEqual(bbox.get_crs(), CRS.WGS84)