Skip to content

Commit 9c2ad6d

Browse files
committed
Update file ext tests, only extend Assets
1 parent b405ba2 commit 9c2ad6d

File tree

4 files changed

+230
-59
lines changed

4 files changed

+230
-59
lines changed

pystac/extensions/file.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from pystac.utils import get_required
1818

19-
T = TypeVar("T", pystac.Item, pystac.Asset)
19+
T = TypeVar("T", bound=pystac.Asset)
2020

2121
SCHEMA_URI = "https://stac-extensions.github.io/file/v2.0.0/schema.json"
2222

@@ -60,7 +60,7 @@ def apply(self, values: List[Any], summary: str) -> None:
6060

6161
@classmethod
6262
def create(cls, values: List[Any], summary: str) -> "MappingObject":
63-
"""Creates a new :class:`~MapptingObject` instance.
63+
"""Creates a new :class:`~MappingObject` instance.
6464
6565
Args:
6666
values : The value(s) in the file. At least one array element is required.
@@ -96,16 +96,15 @@ class FileExtension(
9696
"""An abstract class that can be used to extend the properties of an
9797
:class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
9898
:stac-ext:`File Info Extension <file>`. This class is generic over the type of
99-
STAC Object to be extended (e.g. :class:`~pystac.Item`,
100-
:class:`~pystac.Asset`).
99+
STAC Object to be extended (e.g. :class:`~pystac.Asset`).
101100
102101
To create a concrete instance of :class:`FileExtension`, use the
103102
:meth:`FileExtension.ext` method. For example:
104103
105104
.. code-block:: python
106105
107-
>>> item: pystac.Item = ...
108-
>>> file_ext = FileExtension.ext(item)
106+
>>> asset: pystac.Asset = ...
107+
>>> file_ext = FileExtension.ext(asset)
109108
"""
110109

111110
def apply(
@@ -195,40 +194,20 @@ def ext(obj: T) -> "FileExtension[T]":
195194
"""Extends the given STAC Object with properties from the :stac-ext:`File Info
196195
Extension <file>`.
197196
198-
This extension can be applied to instances of :class:`~pystac.Item` or
199-
:class:`~pystac.Asset`.
197+
This extension can be applied to instances of :class:`~pystac.Asset`.
200198
201199
Raises:
202200
203201
pystac.ExtensionTypeError : If an invalid object type is passed.
204202
"""
205-
if isinstance(obj, pystac.Item):
206-
return cast(FileExtension[T], ItemFileExtension(obj))
207-
elif isinstance(obj, pystac.Asset):
203+
if isinstance(obj, pystac.Asset):
208204
return cast(FileExtension[T], AssetFileExtension(obj))
209205
else:
210206
raise pystac.ExtensionTypeError(
211207
f"File extension does not apply to type {type(obj)}"
212208
)
213209

214210

215-
class ItemFileExtension(FileExtension[pystac.Item]):
216-
"""A concrete implementation of :class:`FileExtension` on an :class:`~pystac.Item`
217-
that extends the properties of the Item to include properties defined in the
218-
:stac-ext:`File Info Extension <file>`.
219-
220-
This class should generally not be instantiated directly. Instead, call
221-
:meth:`FileExtension.ext` on an :class:`~pystac.Item` to extend it.
222-
"""
223-
224-
def __init__(self, item: pystac.Item):
225-
self.item = item
226-
self.properties = item.properties
227-
228-
def __repr__(self) -> str:
229-
return "<ItemFileExtension Item id={}>".format(self.item.id)
230-
231-
232211
class AssetFileExtension(FileExtension[pystac.Asset]):
233212
"""A concrete implementation of :class:`FileExtension` on an :class:`~pystac.Asset`
234213
that extends the Asset fields to include properties defined in the

tests/data-files/file/collection.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"stac_version": "1.0.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/file/v2.0.0/schema.json"
5+
],
6+
"id": "example",
7+
"type": "Collection",
8+
"title": "File Example",
9+
"description": "This examples shows how to use the file extension for collection assets.",
10+
"extent": {
11+
"spatial": {
12+
"bbox": [
13+
[
14+
-180,
15+
-90,
16+
180,
17+
90
18+
]
19+
]
20+
},
21+
"temporal": {
22+
"interval": [
23+
[
24+
"2012-01-15T12:00:00Z",
25+
"2014-12-15T12:00:00Z"
26+
]
27+
]
28+
}
29+
},
30+
"license": "Apache-2.0",
31+
"links": [
32+
{
33+
"href": "https://example.com",
34+
"type": "text/html",
35+
"rel": "about"
36+
}
37+
],
38+
"assets": {
39+
"thumbnail": {
40+
"href": "logo.png",
41+
"title": "A preview image for visualization.",
42+
"type": "image/png",
43+
"roles": [
44+
"thumbnail"
45+
],
46+
"file:checksum": "90e4021044a8995dd50b6657a037a7839304535b",
47+
"file:size": 153600
48+
}
49+
}
50+
}
Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{
2+
"id": "S1A_EW_GRDM_1SSH_20181103T235855_20181103T235955_024430_02AD5D_5616",
23
"type": "Feature",
34
"stac_version": "1.0.0",
4-
"id": "S1A_EW_GRDM_1SSH_20181103T235855_20181103T235955_024430_02AD5D_5616",
5-
"properties": {
6-
"datetime": "2018-11-03T23:58:55Z"
7-
},
5+
"stac_extensions": [
6+
"https://stac-extensions.github.io/file/v2.0.0/schema.json"
7+
],
8+
"bbox": [
9+
-70.275032,
10+
-64.72924,
11+
-65.087479,
12+
-51.105831
13+
],
814
"geometry": {
915
"type": "Polygon",
1016
"coordinates": [
@@ -32,54 +38,58 @@
3238
]
3339
]
3440
},
35-
"links": [],
41+
"properties": {
42+
"datetime": "2018-11-03T23:58:55Z"
43+
},
3644
"assets": {
3745
"noises": {
3846
"href": "./annotation/calibration/noise-s1a-ew-grd-hh-20181103t235855-20181103t235955-024430-02ad5d-001.xml",
39-
"type": "text/xml",
4047
"title": "Calibration Schema",
48+
"type": "text/xml",
4149
"file:checksum": "90e40210a30d1711e81a4b11ef67b28744321659"
4250
},
4351
"calibrations": {
4452
"href": "./annotation/calibration/calibration-s1a-ew-grd-hh-20181103t235855-20181103t235955-024430-02ad5d-001.xml",
45-
"type": "text/xml",
4653
"title": "Noise Schema",
54+
"type": "text/xml",
4755
"file:checksum": "90e402104fc5351af67db0b8f1746efe421a05e4"
4856
},
4957
"products": {
5058
"href": "./annotation/s1a-ew-grd-hh-20181103t235855-20181103t235955-024430-02ad5d-001.xml",
51-
"type": "text/xml",
5259
"title": "Product Schema",
60+
"type": "text/xml",
5361
"file:checksum": "90e402107a7f2588a85362b9beea2a12d4514d45"
5462
},
5563
"measurement": {
5664
"href": "./measurement/s1a-ew-grd-hh-20181103t235855-20181103t235955-024430-02ad5d-001.tiff",
57-
"type": "image/tiff",
5865
"title": "Measurements",
66+
"type": "image/tiff",
67+
"sar:polarizations": [
68+
"HH"
69+
],
5970
"file:byte_order": "little-endian",
60-
"file:data_type": "uint16",
6171
"file:size": 209715200,
6272
"file:header_size": 4096,
6373
"file:checksum": "90e40210163700a8a6501eccd00b6d3b44ddaed0"
6474
},
6575
"thumbnail": {
6676
"href": "./preview/quick-look.png",
67-
"type": "image/png",
6877
"title": "Thumbnail",
78+
"type": "image/png",
6979
"file:byte_order": "big-endian",
70-
"file:data_type": "uint8",
7180
"file:size": 146484,
72-
"file:checksum": "90e40210f52acd32b09769d3b1871b420789456c",
73-
"file:nodata": []
81+
"file:checksum": "90e40210f52acd32b09769d3b1871b420789456c"
7482
}
7583
},
76-
"bbox": [
77-
-70.275032,
78-
-64.72924,
79-
-65.087479,
80-
-51.105831
81-
],
82-
"stac_extensions": [
83-
"https://stac-extensions.github.io/file/v1.0.0/schema.json"
84+
"links": [
85+
{
86+
"rel": "self",
87+
"href": "./item.json"
88+
},
89+
{
90+
"rel": "parent",
91+
"href": "./collection.json",
92+
"file:checksum": "11146d97123fd2c02dec9a1b6d3b13136dbe600cf966"
93+
}
8494
]
8595
}

0 commit comments

Comments
 (0)