Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow linting of Item collections #95

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Options:
-m, --max-depth INTEGER Maximum depth to traverse when recursing. Omit this
argument to get full recursion. Ignored if
`recursive == False`.
-i, --item_collection Lint and validate a stac api item collection
response.
-r, --recursive Recursively validate all related stac objects.
--help Show this message and exit. Show this message and exit.
```
Expand All @@ -38,6 +40,12 @@ $ make build
$ make shell
```
---
### Item Collection Example

```
$ stac-check https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item_collection
```
---
### Lint JSON

```
Expand All @@ -49,9 +57,26 @@ for k, v in linter.create_best_practices_dict().items():
print(k, ":", v)
```
---
### CLI Examples
### Lint in-memory dictionary

```
from stac_check.lint import Linter

stac_item = {
"stac_version": "1.0.0",
"stac_extensions": [],
"type": "Feature",
}

linter = Linter(stac_item, assets=True)

for k, v in linter.create_best_practices_dict().items():
print(k, ":", v)
```
---
### CLI Example Output

``` stac-check https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json --recursive ```
``` $ stac-check https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json --recursive ```
```
____ ____ __ ___ ___ _ _ ____ ___ __ _
/ ___)(_ _)/ _\ / __)___ / __)/ )( \( __)/ __)( / )
Expand Down Expand Up @@ -96,7 +121,7 @@ Error Message: Expecting value: line 1 column 1 (char 0)
-------------------------
```

``` stac-check sample_files/0.9.0/landsat8-sample.json```
``` $ stac-check sample_files/0.9.0/landsat8-sample.json```

<pre><b>stac-check: STAC spec validaton and linting tool</b>

Expand Down Expand Up @@ -159,7 +184,7 @@ This object has 4 links



``` stac-check sample_files/1.0.0/core-item-bad-links.json --links --assets```
``` $ stac-check sample_files/1.0.0/core-item-bad-links.json --links --assets```
<pre>
<b>stac-check: STAC spec validaton and linting tool</b>

Expand Down Expand Up @@ -201,7 +226,7 @@ LINK request errors:
This object has 4 links
</pre>

``` stac-check sample_files/0.9.0/bad-item.json```
``` $ stac-check sample_files/0.9.0/bad-item.json```
<pre>
<b>stac-check: STAC spec validaton and linting tool</b>

Expand Down
137 changes: 137 additions & 0 deletions examples/lint_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from stac_check.lint import Linter

file = {
"stac_version": "1.0.0",
"stac_extensions": [],
"type": "Feature",
"id": "20201211_223832_CS2",
"bbox": [
172.91173669923782,
1.3438851951615003,
172.95469614953714,
1.3690476620161975
],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
172.91173669923782,
1.3438851951615003
],
[
172.95469614953714,
1.3438851951615003
],
[
172.95469614953714,
1.3690476620161975
],
[
172.91173669923782,
1.3690476620161975
],
[
172.91173669923782,
1.3438851951615003
]
]
]
},
"properties": {
"title": "Core Item",
"description": "A sample STAC Item that includes examples of all common metadata",
"datetime": None,
"start_datetime": "2020-12-11T22:38:32.125Z",
"end_datetime": "2020-12-11T22:38:32.327Z",
"created": "2020-12-12T01:48:13.725Z",
"updated": "2020-12-12T01:48:13.725Z",
"platform": "cool_sat1",
"instruments": [
"cool_sensor_v1"
],
"constellation": "ion",
"mission": "collection 5624",
"gsd": 0.512
},
"collection": "simple-collection",
"links": [
{
"rel": "collection",
"href": "./collection.json",
"type": "application/json",
"title": "Simple Example Collection"
},
{
"rel": "root",
"href": "./collection.json",
"type": "application/json",
"title": "Simple Example Collection"
},
{
"rel": "parent",
"href": "./collection.json",
"type": "application/json",
"title": "Simple Example Collection"
},
{
"rel": "alternate",
"type": "text/html",
"href": "http://remotedata.io/catalog/20201211_223832_CS2/index.html",
"title": "HTML version of this STAC Item"
}
],
"assets": {
"analytic": {
"href": "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"title": "4-Band Analytic",
"roles": [
"data"
]
},
"thumbnail": {
"href": "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.jpg",
"title": "Thumbnail",
"type": "image/png",
"roles": [
"thumbnail"
]
},
"visual": {
"href": "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"title": "3-Band Visual",
"roles": [
"visual"
]
},
"udm": {
"href": "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic_udm.tif",
"title": "Unusable Data Mask",
"type": "image/tiff; application=geotiff;"
},
"json-metadata": {
"href": "http://remotedata.io/catalog/20201211_223832_CS2/extended-metadata.json",
"title": "Extended Metadata",
"type": "application/json",
"roles": [
"metadata"
]
},
"ephemeris": {
"href": "http://cool-sat.com/catalog/20201211_223832_CS2/20201211_223832_CS2.EPH",
"title": "Satellite Ephemeris Metadata"
}
}
}
linter = Linter(file, assets=True)

print(f"valid: {linter.valid_stac}")
print(f"error_type: {linter.error_type}")
print(f"error_msg: {linter.error_msg}")
print(f"schema: {linter.schema}")
print(f"file_name: {linter.file_name}")
print("------")
for k,v in linter.create_best_practices_dict().items():
print(k,":",v)
Loading