Skip to content

Commit fd1b079

Browse files
committed
Add tests for Item Assets extension
1 parent 7e535c6 commit fd1b079

File tree

2 files changed

+396
-0
lines changed

2 files changed

+396
-0
lines changed
Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
5+
"eo"
6+
],
7+
"type": "Collection",
8+
"id": "landsat-8-l1",
9+
"title": "Landsat 8 L1",
10+
"description": "Landsat 8 imagery radiometrically calibrated and orthorectified using ground points and Digital Elevation Model (DEM) data to correct relief displacement.",
11+
"keywords": [
12+
"landsat",
13+
"earth observation",
14+
"usgs"
15+
],
16+
"extent": {
17+
"spatial": {
18+
"bbox": [
19+
[
20+
-180,
21+
-90,
22+
180,
23+
90
24+
]
25+
]
26+
},
27+
"temporal": {
28+
"interval": [
29+
[
30+
"2013-06-01T00:00:00Z",
31+
null
32+
]
33+
]
34+
}
35+
},
36+
"providers": [
37+
{
38+
"name": "USGS",
39+
"roles": [
40+
"producer"
41+
],
42+
"url": "https://landsat.usgs.gov/"
43+
},
44+
{
45+
"name": "Planet Labs",
46+
"roles": [
47+
"processor"
48+
],
49+
"url": "https://github.com/landsat-pds/landsat_ingestor"
50+
},
51+
{
52+
"name": "AWS",
53+
"roles": [
54+
"host"
55+
],
56+
"url": "https://landsatonaws.com/"
57+
},
58+
{
59+
"name": "Development Seed",
60+
"roles": [
61+
"processor"
62+
],
63+
"url": "https://github.com/sat-utils/sat-api"
64+
}
65+
],
66+
"license": "PDDL-1.0",
67+
"summaries": {
68+
"gsd": [
69+
15
70+
],
71+
"platform": [
72+
"landsat-8"
73+
],
74+
"instruments": [
75+
"oli",
76+
"tirs"
77+
],
78+
"view:off_nadir": [
79+
0
80+
],
81+
"eo:bands": [
82+
{
83+
"name": "B1",
84+
"common_name": "coastal",
85+
"center_wavelength": 0.44,
86+
"full_width_half_max": 0.02
87+
},
88+
{
89+
"name": "B2",
90+
"common_name": "blue",
91+
"center_wavelength": 0.48,
92+
"full_width_half_max": 0.06
93+
},
94+
{
95+
"name": "B3",
96+
"common_name": "green",
97+
"center_wavelength": 0.56,
98+
"full_width_half_max": 0.06
99+
},
100+
{
101+
"name": "B4",
102+
"common_name": "red",
103+
"center_wavelength": 0.65,
104+
"full_width_half_max": 0.04
105+
},
106+
{
107+
"name": "B5",
108+
"common_name": "nir",
109+
"center_wavelength": 0.86,
110+
"full_width_half_max": 0.03
111+
},
112+
{
113+
"name": "B6",
114+
"common_name": "swir16",
115+
"center_wavelength": 1.6,
116+
"full_width_half_max": 0.08
117+
},
118+
{
119+
"name": "B7",
120+
"common_name": "swir22",
121+
"center_wavelength": 2.2,
122+
"full_width_half_max": 0.2
123+
},
124+
{
125+
"name": "B8",
126+
"common_name": "pan",
127+
"center_wavelength": 0.59,
128+
"full_width_half_max": 0.18
129+
},
130+
{
131+
"name": "B9",
132+
"common_name": "cirrus",
133+
"center_wavelength": 1.37,
134+
"full_width_half_max": 0.02
135+
},
136+
{
137+
"name": "B10",
138+
"common_name": "lwir11",
139+
"center_wavelength": 10.9,
140+
"full_width_half_max": 0.8
141+
},
142+
{
143+
"name": "B11",
144+
"common_name": "lwir12",
145+
"center_wavelength": 12,
146+
"full_width_half_max": 1
147+
}
148+
]
149+
},
150+
"item_assets": {
151+
"thumbnail": {
152+
"type": "image/jpeg",
153+
"title": "Thumbnail",
154+
"description": "A medium sized thumbnail",
155+
"roles": [
156+
"thumbnail"
157+
]
158+
},
159+
"metadata": {
160+
"type": "mtl",
161+
"roles": [
162+
"metadata"
163+
],
164+
"title": "Original Metadata",
165+
"description": "The original MTL metadata file provided for each Landsat scene"
166+
},
167+
"B1": {
168+
"type": "image/tiff; application=geotiff",
169+
"eo:bands": [
170+
{
171+
"name": "B1",
172+
"common_name": "coastal",
173+
"center_wavelength": 0.44,
174+
"full_width_half_max": 0.02
175+
}
176+
],
177+
"title": "Coastal Band (B1)",
178+
"description": "Coastal Band Top Of the Atmosphere"
179+
},
180+
"B2": {
181+
"type": "image/tiff; application=geotiff",
182+
"eo:bands": [
183+
{
184+
"name": "B2",
185+
"common_name": "blue",
186+
"center_wavelength": 0.48,
187+
"full_width_half_max": 0.06
188+
}
189+
],
190+
"title": "Blue Band (B2)",
191+
"description": "Blue Band Top Of the Atmosphere"
192+
},
193+
"B3": {
194+
"type": "image/tiff; application=geotiff",
195+
"eo:bands": [
196+
{
197+
"name": "B3",
198+
"common_name": "green",
199+
"center_wavelength": 0.56,
200+
"full_width_half_max": 0.06
201+
}
202+
],
203+
"title": "Green Band (B3)",
204+
"description": "Green Band (B3) Top Of the Atmosphere"
205+
},
206+
"B4": {
207+
"type": "image/tiff; application=geotiff",
208+
"eo:bands": [
209+
{
210+
"name": "B4",
211+
"common_name": "red",
212+
"center_wavelength": 0.65,
213+
"full_width_half_max": 0.04
214+
}
215+
],
216+
"title": "Red Band (B4)",
217+
"description": "Red Band (B4) Top Of the Atmosphere"
218+
},
219+
"B5": {
220+
"type": "image/tiff; application=geotiff",
221+
"eo:bands": [
222+
{
223+
"name": "B5",
224+
"common_name": "nir",
225+
"center_wavelength": 0.86,
226+
"full_width_half_max": 0.03
227+
}
228+
],
229+
"title": "NIR Band (B5)",
230+
"description": "NIR Band (B5) Top Of the Atmosphere"
231+
},
232+
"B6": {
233+
"type": "image/tiff; application=geotiff",
234+
"eo:bands": [
235+
{
236+
"name": "B6",
237+
"common_name": "swir16",
238+
"center_wavelength": 1.6,
239+
"full_width_half_max": 0.08
240+
}
241+
],
242+
"title": "SWIR Band (B6)",
243+
"description": "SWIR Band at 1.6um (B6) Top Of the Atmosphere"
244+
},
245+
"B7": {
246+
"type": "image/tiff; application=geotiff",
247+
"eo:bands": [
248+
{
249+
"name": "B7",
250+
"common_name": "swir22",
251+
"center_wavelength": 2.2,
252+
"full_width_half_max": 0.2
253+
}
254+
],
255+
"title": "SWIR Band (B7)",
256+
"description": "SWIR Band at 2.2um (B7) Top Of the Atmosphere"
257+
},
258+
"B8": {
259+
"type": "image/tiff; application=geotiff",
260+
"eo:bands": [
261+
{
262+
"name": "B8",
263+
"common_name": "pan",
264+
"center_wavelength": 0.59,
265+
"full_width_half_max": 0.18
266+
}
267+
],
268+
"title": "Panchromatic Band (B8)",
269+
"description": "Panchromatic Band (B8) Top Of the Atmosphere"
270+
},
271+
"B9": {
272+
"type": "image/tiff; application=geotiff",
273+
"eo:bands": [
274+
{
275+
"name": "B9",
276+
"common_name": "cirrus",
277+
"center_wavelength": 1.37,
278+
"full_width_half_max": 0.02
279+
}
280+
],
281+
"title": "Cirrus Band (B9)",
282+
"description": "Cirrus Band (B9) Top Of the Atmosphere - for cirrus cloud detection"
283+
},
284+
"B10": {
285+
"type": "image/tiff; application=geotiff",
286+
"eo:bands": [
287+
{
288+
"name": "B10",
289+
"common_name": "lwir11",
290+
"center_wavelength": 10.9,
291+
"full_width_half_max": 0.8
292+
}
293+
],
294+
"title": "LWIR Band (B10)",
295+
"description": "Long-wave IR Band at 11um (B10) Top Of the Atmosphere"
296+
},
297+
"B11": {
298+
"type": "image/tiff; application=geotiff",
299+
"eo:bands": [
300+
{
301+
"name": "B11",
302+
"common_name": "lwir12",
303+
"center_wavelength": 12,
304+
"full_width_half_max": 1
305+
}
306+
],
307+
"title": "LWIR Band (B11)",
308+
"description": "Long-wave IR Band at 12um (B11) Top Of the Atmosphere"
309+
}
310+
},
311+
"links": []
312+
}

tests/extensions/test_item_assets.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import json
2+
import unittest
3+
4+
from pystac import Collection, collection
5+
from pystac.extensions.item_assets import AssetDefinition, ItemAssetsExtension
6+
7+
from tests.utils import TestCases, assert_to_from_dict
8+
9+
10+
class TestItemAssetsExtension(unittest.TestCase):
11+
def setUp(self) -> None:
12+
self.maxDiff = None
13+
self.collection = Collection.from_file(
14+
TestCases.get_path("data-files/item-assets/example-landsat8.json")
15+
)
16+
17+
def test_example(self) -> None:
18+
collection = self.collection.clone()
19+
item_ext = ItemAssetsExtension.ext(collection)
20+
21+
self.assertEqual(len(item_ext.item_assets), 13)
22+
23+
self.assertEqual(
24+
item_ext.item_assets["B1"],
25+
AssetDefinition(
26+
{
27+
"type": "image/tiff; application=geotiff",
28+
"eo:bands": [
29+
{
30+
"name": "B1",
31+
"common_name": "coastal",
32+
"center_wavelength": 0.44,
33+
"full_width_half_max": 0.02,
34+
}
35+
],
36+
"title": "Coastal Band (B1)",
37+
"description": "Coastal Band Top Of the Atmosphere",
38+
}
39+
),
40+
)
41+
42+
class TestAssetDefinition(unittest.TestCase):
43+
def setUp(self) -> None:
44+
self.maxDiff = None
45+
self.collection = Collection.from_file(
46+
TestCases.get_path("data-files/item-assets/example-landsat8.json")
47+
)
48+
49+
def test_title(self) -> None:
50+
asset_defn = AssetDefinition({})
51+
title = "Very Important Asset"
52+
53+
asset_defn.title = title
54+
55+
self.assertEqual(asset_defn.title, title)
56+
self.assertEqual(asset_defn.to_dict()["title"], title)
57+
58+
def test_description(self) -> None:
59+
asset_defn = AssetDefinition({})
60+
description = "What an incredibly important asset this is!"
61+
62+
asset_defn.description = description
63+
64+
self.assertEqual(asset_defn.description, description)
65+
self.assertEqual(asset_defn.to_dict()["description"], description)
66+
67+
def test_media_type(self) -> None:
68+
asset_defn = AssetDefinition({})
69+
media_type = "application/json"
70+
71+
asset_defn.media_type = media_type
72+
73+
self.assertEqual(asset_defn.media_type, media_type)
74+
self.assertEqual(asset_defn.to_dict()["type"], media_type)
75+
76+
def test_roles(self) -> None:
77+
asset_defn = AssetDefinition({})
78+
roles = ["thumbnail"]
79+
80+
asset_defn.roles = roles
81+
82+
self.assertEqual(asset_defn.roles, roles)
83+
self.assertEqual(asset_defn.to_dict()["roles"], roles)
84+

0 commit comments

Comments
 (0)