Ejemplo n.º 1
0
    def test_get_data_multi_binary(self):
        with open(REQUEST_MULTI_JSON, 'r') as fp:
            request = json.load(fp)

        sentinel_hub = SentinelHub()

        # TODO (forman): discuss with Primoz how to effectively do multi-bands request
        t1 = time.perf_counter()
        response = sentinel_hub.get_data(request,
                                         mime_type='application/octet-stream')
        t2 = time.perf_counter()
        print(f"test_get_data_multi_binary: took {t2 - t1} secs")

        _write_zarr_array(self.RESPONSE_MULTI_ZARR, response.content, 0,
                          (512, 512, 4), '<f4')

        sentinel_hub.close()

        zarr_array = zarr.open_array(self.RESPONSE_MULTI_ZARR)
        self.assertEqual((1, 512, 512, 4), zarr_array.shape)
        self.assertEqual((1, 512, 512, 4), zarr_array.chunks)
        np_array = np.array(zarr_array).astype(np.float32)
        self.assertEqual(np.float32, np_array.dtype)
        np.testing.assert_almost_equal(
            np.array([
                0.6425, 0.6676, 0.5922, 0.5822, 0.5735, 0.4921, 0.5902, 0.6518,
                0.5825, 0.5321
            ],
                     dtype=np.float32), np_array[0, 0, 0:10, 0])
        np.testing.assert_almost_equal(
            np.array([
                0.8605, 0.8528, 0.8495, 0.8378, 0.8143, 0.7959, 0.7816, 0.7407,
                0.7182, 0.7326
            ],
                     dtype=np.float32), np_array[0, 511, -10:, 0])
Ejemplo n.º 2
0
 def test_it(self):
     sentinel_hub = SentinelHub(api_url='https://creodias.sentinel-hub.com')
     # sentinel_hub = SentinelHub(api_url='https://services-uswest2.sentinel-hub.com')
     # sentinel_hub = SentinelHub()
     collections = sentinel_hub.collections()
     self.assertIsInstance(collections, list)
     self.assertTrue(len(collections) >= 1)
     sentinel_hub.close()
Ejemplo n.º 3
0
    def test_get_data_multi(self):
        with open(REQUEST_MULTI_JSON, 'r') as fp:
            request = json.load(fp)

        sentinel_hub = SentinelHub()

        t1 = time.perf_counter()
        response = sentinel_hub.get_data(request)
        t2 = time.perf_counter()
        print(f"test_get_data_multi: took {t2 - t1} secs")

        with open(self.RESPONSE_MULTI_TAR, 'wb') as fp:
            fp.write(response.content)

        sentinel_hub.close()
Ejemplo n.º 4
0
 def test_variable_names(self):
     expected_band_names = [
         'B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A',
         'B09', 'B10', 'B11', 'B12', 'viewZenithMean', 'viewAzimuthMean',
         'sunZenithAngles', 'sunAzimuthAngles'
     ]
     sentinel_hub = SentinelHub(session=SessionMock({
         'get': {
             'https://services.sentinel-hub.com/api/v1/process/dataset/S2L2A/bands':
             {
                 'data': expected_band_names
             }
         }
     }))
     self.assertEqual(expected_band_names, sentinel_hub.band_names('S2L2A'))
     sentinel_hub.close()
Ejemplo n.º 5
0
 def test_token_info(self):
     expected_token_info = {
         'name': 'Norman Fomferra',
         'email': '*****@*****.**',
         'active': True
     }
     sentinel_hub = SentinelHub(session=SessionMock({
         'get': {
             'https://services.sentinel-hub.com/oauth/tokeninfo':
             expected_token_info
         }
     }))
     self.assertEqual(
         expected_token_info, {
             k: v
             for k, v in sentinel_hub.token_info.items()
             if k in ['name', 'email', 'active']
         })
     sentinel_hub.close()
Ejemplo n.º 6
0
 def test_get_features(self):
     properties = [{
         'datetime': '2019-10-02T10:35:47Z'
     }, {
         'datetime': '2019-10-04T10:25:47Z'
     }, {
         'datetime': '2019-10-05T10:45:36Z'
     }, {
         'datetime': '2019-10-05T10:45:44Z'
     }]
     expected_features = [dict(properties=p) for p in properties]
     sentinel_hub = SentinelHub(session=SessionMock({
         'post': {
             'https://services.sentinel-hub.com/api/v1/catalog/search':
             dict(type='FeatureCollection', features=expected_features)
         }
     }))
     self.assertEqual(
         expected_features,
         sentinel_hub.get_features(collection_name='sentinel-2-l2a',
                                   bbox=(12, 53, 13, 54),
                                   time_range=('2019-10-02', '2019-10-05')))
     sentinel_hub.close()