Skip to content

Commit 9a69d46

Browse files
committed
test: Added tests
1 parent 9e0d525 commit 9a69d46

File tree

4 files changed

+477
-14
lines changed

4 files changed

+477
-14
lines changed

pystac/extensions/processing.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,24 @@ def expression(self) -> dict[str, str | Any] | None:
223223

224224
@expression.setter
225225
def expression(self, v: str | Any | None) -> None:
226-
if isinstance(v, str):
227-
exp_format = "string"
228-
elif isinstance(v, object):
229-
exp_format = "object"
226+
if v is None:
227+
self._set_property(EXPRESSION_PROP, v)
230228
else:
231-
raise ValueError(
232-
"The provided expression is not a valid type (string or object)"
233-
)
234-
235-
expression = {
236-
"format": exp_format,
237-
"expression": v,
238-
}
239-
240-
self._set_property(EXPRESSION_PROP, expression)
229+
if isinstance(v, str):
230+
exp_format = "string"
231+
elif isinstance(v, object):
232+
exp_format = "object"
233+
else:
234+
raise ValueError(
235+
"The provided expression is not a valid type (string or object)"
236+
)
237+
238+
expression = {
239+
"format": exp_format,
240+
"expression": v,
241+
}
242+
243+
self._set_property(EXPRESSION_PROP, expression)
241244

242245
@property
243246
def lineage(self) -> str | None:
@@ -302,12 +305,40 @@ def get_schema_uri(cls) -> str:
302305

303306
@classmethod
304307
def ext(cls, obj: T, add_if_missing: bool = False) -> ProcessingExtension[T]:
308+
import pystac.errors
309+
305310
if isinstance(obj, pystac.Item):
311+
if not add_if_missing and cls.get_schema_uri() not in obj.stac_extensions:
312+
raise pystac.errors.ExtensionNotImplemented(
313+
f"{cls.__name__} not implemented for Item id={getattr(obj, 'id', None)}"
314+
)
306315
cls.ensure_has_extension(obj, add_if_missing)
307316
return cast(ProcessingExtension[pystac.Item], ItemProcessingExtension(obj))
317+
elif isinstance(obj, pystac.Asset):
318+
owner = obj.owner if hasattr(obj, "owner") else None
319+
if owner and isinstance(owner, pystac.Item):
320+
if (
321+
not add_if_missing
322+
and cls.get_schema_uri() not in owner.stac_extensions
323+
):
324+
raise pystac.errors.ExtensionNotImplemented(
325+
f"{cls.__name__} not implemented for Asset href={getattr(obj, 'href', None)} (owner Item id={getattr(owner, 'id', None)})"
326+
)
327+
cls.ensure_has_extension(owner, add_if_missing) if owner else None
328+
return cast(
329+
ProcessingExtension[pystac.Asset], AssetProcessingExtension(obj)
330+
)
308331
else:
309332
raise pystac.ExtensionTypeError(cls._ext_error_message(obj))
310333

334+
@classmethod
335+
def summaries(
336+
cls, obj: pystac.Collection, add_if_missing: bool = False
337+
) -> SummariesProcessingExtension:
338+
"""Returns the extended summaries object for the given collection."""
339+
cls.ensure_has_extension(obj, add_if_missing)
340+
return SummariesProcessingExtension(obj)
341+
311342

312343
class ItemProcessingExtension(ProcessingExtension[pystac.Item]):
313344
item: pystac.Item
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/processing/v1.2.0/schema.json"
5+
],
6+
"type": "Collection",
7+
"id": "Sentinel2-L2A",
8+
"title": "Sentinel-2 MSI: MultiSpectral Instrument, Level-2A",
9+
"description": "Sentinel-2 is a wide-swath, high-resolution, multi-spectral imaging mission.",
10+
"license": "proprietary",
11+
"providers": [
12+
{
13+
"name": "European Union/ESA/Copernicus",
14+
"roles": [
15+
"producer",
16+
"licensor"
17+
],
18+
"url": "https://sentinel.esa.int/web/sentinel/user-guides/sentinel-2-msi",
19+
"processing:lineage": "Generation of Level-1C User Product",
20+
"processing:level": "L1",
21+
"processing:facility": "Copernicus S2 Processing and Archiving Facility",
22+
"processing:version": "02.06"
23+
},
24+
{
25+
"name": "Processing Corp.",
26+
"roles": [
27+
"processor"
28+
],
29+
"processing:lineage": "Generation of Level-2A User Product",
30+
"processing:level": "L2A",
31+
"processing:software": {
32+
"Sentinel-2 Toolbox": "8.0.0"
33+
}
34+
},
35+
{
36+
"name": "Storage Provider, Inc.",
37+
"roles": [
38+
"host"
39+
]
40+
}
41+
],
42+
"extent": {
43+
"spatial": {
44+
"bbox": [
45+
[
46+
-180,
47+
-56,
48+
180,
49+
83
50+
]
51+
]
52+
},
53+
"temporal": {
54+
"interval": [
55+
[
56+
"2015-06-23T00:00:00Z",
57+
null
58+
]
59+
]
60+
}
61+
},
62+
"summaries": {
63+
"datetime": {
64+
"minimum": "2015-06-23T00:00:00Z",
65+
"maximum": "2019-07-10T13:44:56Z"
66+
},
67+
"platform": [
68+
"sentinel-2a",
69+
"sentinel-2b"
70+
],
71+
"constellation": [
72+
"sentinel-2"
73+
],
74+
"instruments": [
75+
"msi"
76+
],
77+
"gsd": [
78+
10,
79+
30,
80+
60
81+
],
82+
"processing:level": [
83+
"L1",
84+
"L2"
85+
]
86+
},
87+
"links": [
88+
{
89+
"rel": "items",
90+
"type": "application/geo+json",
91+
"href": "https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-grd/items"
92+
},
93+
{
94+
"rel": "parent",
95+
"type": "application/json",
96+
"href": "https://planetarycomputer.microsoft.com/api/stac/v1/"
97+
},
98+
{
99+
"rel": "root",
100+
"type": "application/json",
101+
"href": "https://planetarycomputer.microsoft.com/api/stac/v1/"
102+
},
103+
{
104+
"rel": "self",
105+
"type": "application/json",
106+
"href": "https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-grd"
107+
},
108+
{
109+
"rel": "license",
110+
"href": "https://sentinel.esa.int/documents/247904/690755/Sentinel_Data_Legal_Notice",
111+
"title": "Copernicus Sentinel data terms"
112+
},
113+
{
114+
"rel": "describedby",
115+
"href": "https://planetarycomputer.microsoft.com/dataset/sentinel-1-grd",
116+
"title": "Human readable dataset overview and reference",
117+
"type": "text/html"
118+
}
119+
]
120+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
5+
"https://stac-extensions.github.io/sar/v1.0.0/schema.json",
6+
"https://stac-extensions.github.io/processing/v1.2.0/schema.json"
7+
],
8+
"id": "S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF",
9+
"properties": {
10+
"datetime": "2016-08-22T18:28:23.368922Z",
11+
"start_datetime": "2016-08-22T18:28:23.368922Z",
12+
"end_datetime": "2016-08-22T18:28:48.368201Z",
13+
"created": "2016-08-23T00:38:22Z",
14+
"platform": "sentinel-1a",
15+
"constellation": "sentinel-1",
16+
"mission": "sentinel-1",
17+
"instruments": [
18+
"c-sar"
19+
],
20+
"sat:absolute_orbit": 12717,
21+
"sat:orbit_state": "ascending",
22+
"sat:relative_orbit": 45,
23+
"sat:anx_datetime": "2016-08-22T18:24:52.513706Z",
24+
"sar:instrument_mode": "IW",
25+
"sar:frequency_band": "C",
26+
"sar:polarizations": [
27+
"VV",
28+
"VH"
29+
],
30+
"sar:product_type": "GRD",
31+
"processing:lineage": "GRD Post Processing",
32+
"processing:level": "L1",
33+
"processing:facility": "Copernicus S1 Core Ground Segment - DPA",
34+
"processing:software": {
35+
"Sentinel-1 IPF": "002.71"
36+
},
37+
"processing:datetime": "2016-08-23T00:30:33Z"
38+
},
39+
"links": [
40+
{
41+
"title": "GRD Post Processing (90AF)",
42+
"rel": "processing-execution",
43+
"href": "https://api.example.com/processing/s1-grd-l1c/jobs/90AF",
44+
"type": "application/json"
45+
}
46+
],
47+
"assets": {
48+
"manifest": {
49+
"type": "text/xml",
50+
"roles": [
51+
"metadata"
52+
],
53+
"title": "SAFE Manifest",
54+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/manifest.safe",
55+
"created": "2016-08-23T00:30:33Z"
56+
},
57+
"quick-look": {
58+
"type": "image/png",
59+
"roles": [
60+
"overview"
61+
],
62+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/preview/quick-look.png"
63+
},
64+
"annotation-vv-iw": {
65+
"type": "text/xml",
66+
"roles": [
67+
"metadata"
68+
],
69+
"title": "Annotation VV IW",
70+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/annotation/s1a-iw-grd-vv-20160822t182823-20160822t182848-012717-013ffe-001.xml",
71+
"sar:polarizations": [
72+
"VV"
73+
]
74+
},
75+
"amplitude-vv-iw": {
76+
"type": "image/tiff; application=geotiff",
77+
"roles": [
78+
"data"
79+
],
80+
"title": "IW VV Amplitude pixel values",
81+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/annotation/s1a-iw-grd-vv-20160822t182823-20160822t182848-012717-013ffe-001.tiff",
82+
"sar:polarizations": [
83+
"VV"
84+
]
85+
},
86+
"annotation-vh-iw": {
87+
"type": "text/xml",
88+
"roles": [
89+
"metadata"
90+
],
91+
"title": "Annotation VH IW",
92+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/annotation/s1a-iw-grd-vh-20160822t182823-20160822t182848-012717-013ffe-002.xml",
93+
"sar:polarizations": [
94+
"VH"
95+
]
96+
},
97+
"amplitude-vh-iw": {
98+
"type": "image/tiff; application=geotiff",
99+
"roles": [
100+
"data"
101+
],
102+
"title": "IW VH Amplitude pixel values",
103+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/annotation/s1a-iw-grd-vh-20160822t182823-20160822t182848-012717-013ffe-002.tiff",
104+
"sar:polarizations": [
105+
"VH"
106+
]
107+
},
108+
"calibration-vv-iw": {
109+
"type": "text/xml",
110+
"roles": [
111+
"data"
112+
],
113+
"title": "Calibration VV IW",
114+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/annotation/calibration/calibration-s1a-iw-grd-vv-20160822t182823-20160822t182848-012717-013ffe-001.xml",
115+
"sar:polarizations": [
116+
"VV"
117+
]
118+
},
119+
"calibration-vh-iw": {
120+
"type": "text/xml",
121+
"roles": [
122+
"data"
123+
],
124+
"title": "Calibration VH IW",
125+
"href": "data/S1A_IW_GRDH_1SDV_20160822T182823_20160822T182848_012717_013FFE_90AF.SAFE/annotation/calibration/calibration-s1a-iw-grd-vh-20160822t182823-20160822t182848-012717-013ffe-002.xml",
126+
"sar:polarizations": [
127+
"VH"
128+
]
129+
}
130+
},
131+
"type": "Feature",
132+
"geometry": {
133+
"type": "Polygon",
134+
"coordinates": [
135+
[
136+
[
137+
-5.730959,
138+
14.953436
139+
],
140+
[
141+
-3.431006,
142+
15.388663
143+
],
144+
[
145+
-3.136116,
146+
13.880572
147+
],
148+
[
149+
-5.419919,
150+
13.441674
151+
],
152+
[
153+
-5.730959,
154+
14.953436
155+
]
156+
]
157+
]
158+
},
159+
"bbox": [
160+
-5.730959,
161+
13.441674,
162+
-3.136116,
163+
15.388663
164+
]
165+
}

0 commit comments

Comments
 (0)