pystac-ext-grid 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+ *.pyc
2
+ *.egg-info
3
+ *.eggs
4
+ .DS_Store
5
+ data
6
+ config.json
7
+ stdout*
8
+ /integration*
9
+ .idea
10
+ .vscode
11
+ .actrc
12
+
13
+
14
+ # Sphinx documentation
15
+ .ipynb_checkpoints/
16
+
17
+ docs/tutorials/pystac-example*
18
+ docs/tutorials/spacenet-stac/
19
+ docs/tutorials/spacenet-cog-stac/
20
+ docs/tutorials/data/
21
+ docs/quickstart_stac/
22
+
23
+ # Byte-compiled / optimized / DLL files
24
+ __pycache__/
25
+ *.py[cod]
26
+ *$py.class
27
+
28
+ # C extensions
29
+ *.so
30
+
31
+ # Distribution / packaging
32
+ .Python
33
+ build/
34
+ develop-eggs/
35
+ dist/
36
+ downloads/
37
+ eggs/
38
+ .eggs/
39
+ lib/
40
+ lib64/
41
+ parts/
42
+ sdist/
43
+ var/
44
+ wheels/
45
+ share/python-wheels/
46
+ *.egg-info/
47
+ .installed.cfg
48
+ *.egg
49
+ MANIFEST
50
+
51
+ # PyInstaller
52
+ # Usually these files are written by a python script from a template
53
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
54
+ *.manifest
55
+ *.spec
56
+
57
+ # Installer logs
58
+ pip-log.txt
59
+ pip-delete-this-directory.txt
60
+
61
+ # Unit test / coverage reports
62
+ htmlcov/
63
+ .tox/
64
+ .nox/
65
+ .coverage
66
+ .coverage.*
67
+ .cache
68
+ nosetests.xml
69
+ coverage.xml
70
+ *.cover
71
+ *.py,cover
72
+ .hypothesis/
73
+ .pytest_cache/
74
+ cover/
75
+
76
+ # Translations
77
+ *.mo
78
+ *.pot
79
+
80
+ # Django stuff:
81
+ *.log
82
+ local_settings.py
83
+ db.sqlite3
84
+ db.sqlite3-journal
85
+
86
+ # Flask stuff:
87
+ instance/
88
+ .webassets-cache
89
+
90
+ # Scrapy stuff:
91
+ .scrapy
92
+
93
+ # Sphinx documentation
94
+ docs/_build/
95
+
96
+ # PyBuilder
97
+ .pybuilder/
98
+ target/
99
+
100
+ # Jupyter Notebook
101
+ .ipynb_checkpoints
102
+
103
+ # IPython
104
+ profile_default/
105
+ ipython_config.py
106
+
107
+ # pyenv
108
+ # For a library or package, you might want to ignore these files since the code is
109
+ # intended to run in multiple environments; otherwise, check them in:
110
+ # .python-version
111
+
112
+ # pipenv
113
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
114
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
115
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
116
+ # install all needed dependencies.
117
+ # Pipfile.lock
118
+
119
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
120
+ __pypackages__/
121
+
122
+ # Celery stuff
123
+ celerybeat-schedule
124
+ celerybeat.pid
125
+
126
+ # SageMath parsed files
127
+ *.sage.py
128
+
129
+ # Environments
130
+ .env
131
+ .venv
132
+ env/
133
+ venv/
134
+ ENV/
135
+ env.bak/
136
+ venv.bak/
137
+
138
+ # Spyder project settings
139
+ .spyderproject
140
+ .spyproject
141
+
142
+ # Rope project settings
143
+ .ropeproject
144
+
145
+ # mkdocs documentation
146
+ /site
147
+
148
+ # mypy
149
+ .mypy_cache/
150
+ .dmypy.json
151
+ dmypy.json
152
+
153
+ # Pyre type checker
154
+ .pyre/
155
+
156
+ # pytype static type analyzer
157
+ .pytype/
158
+
159
+ # Cython debug symbols
160
+ cython_debug/
161
+
162
+ # asv environments
163
+ .asv
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: pystac-ext-grid
3
+ Version: 1.1.0
4
+ Summary: Grid extension for PySTAC
5
+ Project-URL: Documentation, https://pystac.readthedocs.io
6
+ Project-URL: Repository, https://github.com/stac-utils/pystac
7
+ Project-URL: Issues, https://github.com/stac-utils/pystac/issues
8
+ Project-URL: Changelog, https://github.com/stac-utils/pystac/blob/main/CHANGELOG.md
9
+ Project-URL: Discussions, https://github.com/radiantearth/stac-spec/discussions/categories/stac-software
10
+ License: Apache-2.0
11
+ Keywords: STAC,catalog,grid,imagery,pystac,raster
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Natural Language :: English
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: pystac-core
23
+ Description-Content-Type: text/markdown
24
+
25
+ # pystac-ext-grid
26
+
27
+ [PySTAC](https://pypi.org/project/pystac/) extension package for the [Grid Extension](https://github.com/stac-extensions/grid).
28
+ This extension describes gridded data products by specifying the grid code (e.g. MGRS, MODIS, or other tiling schemes) that the data corresponds to.
29
+
30
+ ## Supported versions
31
+
32
+ - [v1.1.0](https://stac-extensions.github.io/grid/v1.1.0/schema.json)
33
+ - [v1.0.0](https://stac-extensions.github.io/grid/v1.0.0/schema.json)
34
+
35
+ ## Versioning
36
+
37
+ This package's version corresponds to the version of the extension specification it targets.
38
+ When we release updates to the package code without changing the target extension version, we use [post releases](https://packaging.python.org/en/latest/discussions/versioning/#post-releases), e.g. `1.1.0.post1`.
@@ -0,0 +1,14 @@
1
+ # pystac-ext-grid
2
+
3
+ [PySTAC](https://pypi.org/project/pystac/) extension package for the [Grid Extension](https://github.com/stac-extensions/grid).
4
+ This extension describes gridded data products by specifying the grid code (e.g. MGRS, MODIS, or other tiling schemes) that the data corresponds to.
5
+
6
+ ## Supported versions
7
+
8
+ - [v1.1.0](https://stac-extensions.github.io/grid/v1.1.0/schema.json)
9
+ - [v1.0.0](https://stac-extensions.github.io/grid/v1.0.0/schema.json)
10
+
11
+ ## Versioning
12
+
13
+ This package's version corresponds to the version of the extension specification it targets.
14
+ When we release updates to the package code without changing the target extension version, we use [post releases](https://packaging.python.org/en/latest/discussions/versioning/#post-releases), e.g. `1.1.0.post1`.
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "pystac-ext-grid"
3
+ description = "Grid extension for PySTAC"
4
+ readme = "README.md"
5
+ version = "1.1.0"
6
+ authors = []
7
+ maintainers = []
8
+ keywords = ["pystac", "imagery", "raster", "catalog", "STAC", "grid"]
9
+ license = { text = "Apache-2.0" }
10
+ classifiers = [
11
+ "Development Status :: 5 - Production/Stable",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: Apache Software License",
14
+ "Natural Language :: English",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ ]
21
+ requires-python = ">=3.10"
22
+ dependencies = ["pystac-core"]
23
+
24
+ [project.urls]
25
+ Documentation = "https://pystac.readthedocs.io"
26
+ Repository = "https://github.com/stac-utils/pystac"
27
+ Issues = "https://github.com/stac-utils/pystac/issues"
28
+ Changelog = "https://github.com/stac-utils/pystac/blob/main/CHANGELOG.md"
29
+ Discussions = "https://github.com/radiantearth/stac-spec/discussions/categories/stac-software"
30
+
31
+ [build-system]
32
+ requires = ["hatchling"]
33
+ build-backend = "hatchling.build"
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["pystac"]
@@ -0,0 +1,126 @@
1
+ """Implements the :stac-ext:`Grid Extension <grid>`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from re import Pattern
7
+ from typing import Any, Literal
8
+
9
+ import pystac
10
+ from pystac.extensions.base import ExtensionManagementMixin, PropertiesExtension
11
+ from pystac.extensions.hooks import ExtensionHooks
12
+
13
+ SCHEMA_URI: str = "https://stac-extensions.github.io/grid/v1.1.0/schema.json"
14
+ SCHEMA_URIS: list[str] = [
15
+ "https://stac-extensions.github.io/grid/v1.0.0/schema.json",
16
+ SCHEMA_URI,
17
+ ]
18
+ PREFIX: str = "grid:"
19
+
20
+ # Field names
21
+ CODE_PROP: str = PREFIX + "code" # required
22
+
23
+ CODE_REGEX: str = r"[A-Z0-9]+-[-_.A-Za-z0-9]+"
24
+ CODE_PATTERN: Pattern[str] = re.compile(CODE_REGEX)
25
+
26
+
27
+ def validated_code(v: str) -> str:
28
+ if not isinstance(v, str):
29
+ raise ValueError("Invalid Grid code: must be str")
30
+ if not CODE_PATTERN.fullmatch(v):
31
+ raise ValueError(
32
+ f"Invalid Grid code: {v} does not match the regex {CODE_REGEX}"
33
+ )
34
+ return v
35
+
36
+
37
+ class GridExtension(
38
+ PropertiesExtension,
39
+ ExtensionManagementMixin[pystac.Item | pystac.Collection],
40
+ ):
41
+ """A concrete implementation of :class:`~pystac.extensions.grid.GridExtension`
42
+ on an :class:`~pystac.Item`
43
+ that extends the properties of the Item to include properties defined in the
44
+ :stac-ext:`Grid Extension <grid>`.
45
+
46
+ This class should generally not be instantiated directly. Instead, call
47
+ :meth:`~pystac.extensions.grid.GridExtension.ext` on an :class:`~pystac.Item`
48
+ to extend it.
49
+
50
+ .. code-block:: python
51
+
52
+ >>> item: pystac.Item = ...
53
+ >>> proj_ext = GridExtension.ext(item)
54
+ """
55
+
56
+ name: Literal["grid"] = "grid"
57
+
58
+ item: pystac.Item
59
+ """The :class:`~pystac.Item` being extended."""
60
+
61
+ properties: dict[str, Any]
62
+ """The :class:`~pystac.Item` properties, including extension properties."""
63
+
64
+ def __init__(self, item: pystac.Item):
65
+ self.item = item
66
+ self.properties = item.properties
67
+
68
+ def __repr__(self) -> str:
69
+ return f"<ItemGridExtension Item id={self.item.id}>"
70
+
71
+ def apply(self, code: str) -> None:
72
+ """Applies Grid extension properties to the extended Item.
73
+
74
+ Args:
75
+ code : REQUIRED. The code of the Item's grid location.
76
+ """
77
+ self.code = validated_code(code)
78
+
79
+ @property
80
+ def code(self) -> str | None:
81
+ """Get or sets the grid code of the datasource."""
82
+ return self._get_property(CODE_PROP, str)
83
+
84
+ @code.setter
85
+ def code(self, v: str) -> None:
86
+ self._set_property(CODE_PROP, validated_code(v), pop_if_none=False)
87
+
88
+ @classmethod
89
+ def get_schema_uri(cls) -> str:
90
+ return SCHEMA_URI
91
+
92
+ @classmethod
93
+ def get_schema_uris(cls) -> list[str]:
94
+ import warnings
95
+
96
+ warnings.warn(
97
+ "get_schema_uris is deprecated and will be removed in v2",
98
+ DeprecationWarning,
99
+ )
100
+ return SCHEMA_URIS
101
+
102
+ @classmethod
103
+ def ext(cls, obj: pystac.Item, add_if_missing: bool = False) -> GridExtension:
104
+ """Extends the given STAC Object with properties from the :stac-ext:`Grid
105
+ Extension <grid>`.
106
+
107
+ This extension can be applied to instances of :class:`~pystac.Item`.
108
+
109
+ Raises:
110
+
111
+ pystac.ExtensionTypeError : If an invalid object type is passed.
112
+ """
113
+ if isinstance(obj, pystac.Item):
114
+ cls.ensure_has_extension(obj, add_if_missing)
115
+ return GridExtension(obj)
116
+ else:
117
+ raise pystac.ExtensionTypeError(cls._ext_error_message(obj))
118
+
119
+
120
+ class GridExtensionHooks(ExtensionHooks):
121
+ schema_uri: str = SCHEMA_URI
122
+ prev_extension_ids: set[str] = {*[uri for uri in SCHEMA_URIS if uri != SCHEMA_URI]}
123
+ stac_object_types = {pystac.STACObjectType.ITEM}
124
+
125
+
126
+ GRID_EXTENSION_HOOKS: ExtensionHooks = GridExtensionHooks()
File without changes
@@ -0,0 +1,36 @@
1
+ interactions:
2
+ - request:
3
+ body: null
4
+ headers: {}
5
+ method: GET
6
+ uri: https://stac-extensions.github.io/grid/v1.1.0/schema.json
7
+ response:
8
+ body:
9
+ string: "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"$id\":
10
+ \"https://stac-extensions.github.io/grid/v1.1.0/schema.json#\",\n \"title\":
11
+ \"Grid Extension\",\n \"description\": \"STAC Grid Extension for STAC Items.\",\n
12
+ \ \"oneOf\": [\n {\n \"$comment\": \"This is the schema for STAC Items\",\n
13
+ \ \"allOf\": [\n {\n \"$ref\": \"#/definitions/stac_extensions\"\n
14
+ \ },\n {\n \"type\": \"object\",\n \"required\":
15
+ [\n \"type\",\n \"properties\",\n \"assets\"\n
16
+ \ ],\n \"properties\": {\n \"type\": {\n \"const\":
17
+ \"Feature\"\n },\n \"properties\": {\n \"allOf\":
18
+ [\n {\n \"required\": [\n \"grid:code\"\n
19
+ \ ]\n },\n {\n \"$ref\":
20
+ \"#/definitions/fields\"\n }\n ]\n }\n
21
+ \ }\n }\n ]\n }\n ],\n \"definitions\": {\n \"stac_extensions\":
22
+ {\n \"type\": \"object\",\n \"required\": [\n \"stac_extensions\"\n
23
+ \ ],\n \"properties\": {\n \"stac_extensions\": {\n \"type\":
24
+ \"array\",\n \"contains\": {\n \"const\": \"https://stac-extensions.github.io/grid/v1.1.0/schema.json\"\n
25
+ \ }\n }\n }\n },\n \"require_any_field\": {\n \"anyOf\":
26
+ [\n {\"required\": [\"grid:code\"]}\n ]\n },\n \"fields\":
27
+ {\n \"type\": \"object\",\n \"properties\": {\n \"grid:code\":
28
+ {\n \"type\": \"string\",\n \"pattern\": \"^[A-Z0-9]+-[-_.A-Za-z0-9]+$\"\n
29
+ \ }\n },\n \"patternProperties\": {\n \"^(?!grid:)\":
30
+ {\n \"$comment\": \"Do not allow other fields with this prefix\"\n
31
+ \ }\n },\n \"additionalProperties\": false\n }\n }\n}\n"
32
+ headers: {}
33
+ status:
34
+ code: 200
35
+ message: OK
36
+ version: 1
@@ -0,0 +1,36 @@
1
+ interactions:
2
+ - request:
3
+ body: null
4
+ headers: {}
5
+ method: GET
6
+ uri: https://stac-extensions.github.io/grid/v1.1.0/schema.json
7
+ response:
8
+ body:
9
+ string: "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"$id\":
10
+ \"https://stac-extensions.github.io/grid/v1.1.0/schema.json#\",\n \"title\":
11
+ \"Grid Extension\",\n \"description\": \"STAC Grid Extension for STAC Items.\",\n
12
+ \ \"oneOf\": [\n {\n \"$comment\": \"This is the schema for STAC Items\",\n
13
+ \ \"allOf\": [\n {\n \"$ref\": \"#/definitions/stac_extensions\"\n
14
+ \ },\n {\n \"type\": \"object\",\n \"required\":
15
+ [\n \"type\",\n \"properties\",\n \"assets\"\n
16
+ \ ],\n \"properties\": {\n \"type\": {\n \"const\":
17
+ \"Feature\"\n },\n \"properties\": {\n \"allOf\":
18
+ [\n {\n \"required\": [\n \"grid:code\"\n
19
+ \ ]\n },\n {\n \"$ref\":
20
+ \"#/definitions/fields\"\n }\n ]\n }\n
21
+ \ }\n }\n ]\n }\n ],\n \"definitions\": {\n \"stac_extensions\":
22
+ {\n \"type\": \"object\",\n \"required\": [\n \"stac_extensions\"\n
23
+ \ ],\n \"properties\": {\n \"stac_extensions\": {\n \"type\":
24
+ \"array\",\n \"contains\": {\n \"const\": \"https://stac-extensions.github.io/grid/v1.1.0/schema.json\"\n
25
+ \ }\n }\n }\n },\n \"require_any_field\": {\n \"anyOf\":
26
+ [\n {\"required\": [\"grid:code\"]}\n ]\n },\n \"fields\":
27
+ {\n \"type\": \"object\",\n \"properties\": {\n \"grid:code\":
28
+ {\n \"type\": \"string\",\n \"pattern\": \"^[A-Z0-9]+-[-_.A-Za-z0-9]+$\"\n
29
+ \ }\n },\n \"patternProperties\": {\n \"^(?!grid:)\":
30
+ {\n \"$comment\": \"Do not allow other fields with this prefix\"\n
31
+ \ }\n },\n \"additionalProperties\": false\n }\n }\n}\n"
32
+ headers: {}
33
+ status:
34
+ code: 200
35
+ message: OK
36
+ version: 1
@@ -0,0 +1,129 @@
1
+ {
2
+ "type": "Feature",
3
+ "stac_version": "1.1.0",
4
+ "id": "LC09_L2SR_081122_20221130_02_T2",
5
+ "properties": {
6
+ "platform": "landsat-9",
7
+ "instruments": [
8
+ "oli",
9
+ "tirs"
10
+ ],
11
+ "created": "2022-12-02T07:31:27.565Z",
12
+ "gsd": 30,
13
+ "description": "Landsat Collection 2 Level-2",
14
+ "eo:cloud_cover": 100,
15
+ "view:off_nadir": 0,
16
+ "view:sun_elevation": 18.24930158,
17
+ "view:sun_azimuth": 116.70818279,
18
+ "proj:epsg": 3031,
19
+ "proj:shape": [
20
+ 7731,
21
+ 7821
22
+ ],
23
+ "proj:transform": [
24
+ 30,
25
+ 0,
26
+ 743385,
27
+ 0,
28
+ -30,
29
+ 337215
30
+ ],
31
+ "grid:code": "WGS2-081122",
32
+ "landsat:cloud_cover_land": 100,
33
+ "landsat:wrs_type": "2",
34
+ "landsat:wrs_path": "081",
35
+ "landsat:wrs_row": "122",
36
+ "landsat:collection_category": "T2",
37
+ "landsat:collection_number": "02",
38
+ "landsat:correction": "L2SR",
39
+ "landsat:scene_id": "LC90811222022334LGN00",
40
+ "sci:doi": "10.5066/P9OGBGM6",
41
+ "datetime": "2022-11-30T23:10:16.172033Z",
42
+ "earthsearch:payload_id": "usgs-landsat-c2l2/workflow-landsat-to-stac/LC09_L2SR_081122_20221130_20221202_02_T2_SR",
43
+ "processing:software": {
44
+ "landsat-to-stac": "0.1.0"
45
+ },
46
+ "updated": "2022-12-02T07:31:27.565Z"
47
+ },
48
+ "geometry": {
49
+ "type": "Polygon",
50
+ "coordinates": [
51
+ [
52
+ [
53
+ 70.06845303665641,
54
+ -80.93500601550424
55
+ ],
56
+ [
57
+ 68.81052300366429,
58
+ -82.64772956732001
59
+ ],
60
+ [
61
+ 82.3854019772448,
62
+ -82.64899815759557
63
+ ],
64
+ [
65
+ 81.11511917154068,
66
+ -80.93577539197138
67
+ ],
68
+ [
69
+ 70.06845303665641,
70
+ -80.93500601550424
71
+ ]
72
+ ]
73
+ ]
74
+ },
75
+ "links": [
76
+ {
77
+ "rel": "self",
78
+ "href": "https://earth-search.aws.element84.com/v1/collections/landsat-c2-l2/items/LC09_L2SR_081122_20221130_02_T2"
79
+ },
80
+ {
81
+ "rel": "canonical",
82
+ "href": "s3://earthsearch-data/landsat-c2-l2/081/122/2022/11/LC09_L2SR_081122_20221130_02_T2/LC09_L2SR_081122_20221130_02_T2.json",
83
+ "type": "application/json"
84
+ },
85
+ {
86
+ "rel": "cite-as",
87
+ "href": "https://doi.org/10.5066/P9OGBGM6",
88
+ "title": "Landsat 8-9 OLI/TIRS Collection 2 Level-2"
89
+ },
90
+ {
91
+ "rel": "via",
92
+ "href": "https://landsatlook.usgs.gov/stac-server/collections/landsat-c2l2-sr/items/LC09_L2SR_081122_20221130_20221202_02_T2_SR",
93
+ "type": "application/json",
94
+ "title": "USGS STAC Item"
95
+ },
96
+ {
97
+ "rel": "parent",
98
+ "href": "https://earth-search.aws.element84.com/v1/collections/landsat-c2-l2"
99
+ },
100
+ {
101
+ "rel": "collection",
102
+ "href": "https://earth-search.aws.element84.com/v1/collections/landsat-c2-l2"
103
+ },
104
+ {
105
+ "rel": "root",
106
+ "href": "https://earth-search.aws.element84.com/v1/"
107
+ }
108
+ ],
109
+ "assets": {},
110
+ "bbox": [
111
+ 65.60123,
112
+ -83.097758,
113
+ 83.855046,
114
+ -80.499732
115
+ ],
116
+ "stac_extensions": [
117
+ "https://stac-extensions.github.io/processing/v1.1.0/schema.json",
118
+ "https://stac-extensions.github.io/storage/v1.0.0/schema.json",
119
+ "https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
120
+ "https://stac-extensions.github.io/raster/v1.1.0/schema.json",
121
+ "https://stac-extensions.github.io/classification/v1.0.0/schema.json",
122
+ "https://stac-extensions.github.io/eo/v1.1.0/schema.json",
123
+ "https://stac-extensions.github.io/projection/v1.0.0/schema.json",
124
+ "https://stac-extensions.github.io/view/v1.0.0/schema.json",
125
+ "https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
126
+ "https://stac-extensions.github.io/grid/v1.1.0/schema.json"
127
+ ],
128
+ "collection": "landsat-c2-l2"
129
+ }