This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
/
test_worldview.py
107 lines (90 loc) · 4.22 KB
/
test_worldview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'''
Authors: Donnie Marino, Kostas Stamatiou
Contact: dmarino@digitalglobe.com
Unit tests for the gbdxtools.Idaho class
'''
from gbdxtools import Interface
from gbdxtools import CatalogImage, WV02, WV03_VNIR, WV03_SWIR
from auth_mock import get_mock_gbdx_session
import vcr
from os.path import join, isfile, dirname, realpath
import tempfile
import unittest
try:
from urlparse import urlparse
except:
from urllib.parse import urlparse
# How to use the mock_gbdx_session and vcr to create unit tests:
# 1. Add a new test that is dependent upon actually hitting GBDX APIs.
# 2. Decorate the test with @vcr appropriately
# 3. Replace "dummytoken" with a real gbdx token
# 4. Run the tests (existing test shouldn't be affected by use of a real token). This will record a "cassette".
# 5. Replace the real gbdx token with "dummytoken" again
# 6. Edit the cassette to remove any possibly sensitive information (s3 creds for example)
def force(r1, r2):
return True
my_vcr = vcr.VCR()
my_vcr.register_matcher('force', force)
my_vcr.match_on = ['force']
class CatalogImageTest(unittest.TestCase):
_temp_path = None
@classmethod
def setUpClass(cls):
mock_gbdx_session = get_mock_gbdx_session(token='dymmytoken')
cls.gbdx = Interface(gbdx_connection=mock_gbdx_session)
#cls.gbdx = Interface()
cls._temp_path = tempfile.mkdtemp()
print("Created: {}".format(cls._temp_path))
@my_vcr.use_cassette('tests/unit/cassettes/test_wv_image_default.yaml', filter_headers=['authorization'])
def test_basic_catalog_image(self):
_id = '104001002838EC00'
img = self.gbdx.catalog_image(_id)
self.assertTrue(isinstance(img, WV03_VNIR))
assert img.cat_id == _id
assert img.shape == (8, 79386, 10889)
assert img.proj == 'EPSG:4326'
@my_vcr.use_cassette('tests/unit/cassettes/test_wv_image_default_aoi.yaml', filter_headers=['authorization'])
def test_cat_image_with_aoi(self):
_id = '104001002838EC00'
img = self.gbdx.catalog_image(_id, bbox=[-85.81455230712892,10.416235163695223,-85.77163696289064,10.457089934231618])
assert img.cat_id == _id
assert img.shape == (8, 3036, 3189)
assert img.proj == 'EPSG:4326'
@my_vcr.use_cassette('tests/unit/cassettes/test_wv_image_proj.yaml', filter_headers=['authorization'])
def test_cat_image_with_proj(self):
_id = '104001002838EC00'
img = CatalogImage(_id, bbox=[-85.81455230712892,10.416235163695223,-85.77163696289064,10.457089934231618], proj='EPSG:3857')
assert img.cat_id == _id
assert img.shape == (8, 3059, 3160)
assert img.proj == 'EPSG:3857'
@my_vcr.use_cassette('tests/unit/cassettes/test_wv_image_aoi.yaml', filter_headers=['authorization'])
def test_cat_image_aoi(self):
_id = '104001002838EC00'
img = CatalogImage(_id)
assert img.cat_id == _id
aoi = img.aoi(bbox=[-85.81455230712892,10.416235163695223,-85.77163696289064,10.457089934231618])
assert aoi.shape == (8, 3036, 3189)
@my_vcr.use_cassette('tests/unit/cassettes/test_wv_image_pan_band.yaml', filter_headers=['authorization'])
def test_catalog_image_panchromatic(self):
_id = '104001002838EC00'
img = self.gbdx.catalog_image(_id, band_type='Pan')
self.assertTrue(isinstance(img, WV03_VNIR))
assert img.cat_id == _id
assert img.shape == (1, 317959, 43511)
assert img.proj == 'EPSG:4326'
@my_vcr.use_cassette('tests/unit/cassettes/test_wv_image_pansharpen.yaml', filter_headers=['authorization'])
def test_catalog_image_pansharpen(self):
_id = '104001002838EC00'
img = self.gbdx.catalog_image(_id, pansharpen=True)
self.assertTrue(isinstance(img, WV03_VNIR))
assert img.cat_id == _id
assert img.shape == (8, 317959, 43511)
assert img.proj == 'EPSG:4326'
@my_vcr.use_cassette('tests/unit/cassettes/test_wv3_swir.yaml', filter_headers=['authorization'])
def test_catalog_image_pansharpen(self):
_id = '104A010010C29F00'
img = self.gbdx.catalog_image(_id)
self.assertTrue(isinstance(img, WV03_SWIR))
assert img.cat_id == _id
assert img.shape == (8, 1950, 1446)
assert img.proj == 'EPSG:4326'