Skip to content

Commit

Permalink
Merge pull request #49 from crim-ca/item_validation
Browse files Browse the repository at this point in the history
validate the resulting STAC item
  • Loading branch information
dchandan authored Feb 22, 2024
2 parents 8d59988 + 5647a64 commit 28c5465
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased](https://github.com/crim-ca/stac-populator) (latest)

* Add validation to the stac items in CMIP6_UofT implementation
* Replace CMIP6 JSON-schema URL to
`"https://raw.githubusercontent.com/dchandan/stac-extension-cmip6/main/json-schema/schema.json"`
for a more up-to-date validation of available STAC CMIP6 properties.
Expand Down
6 changes: 6 additions & 0 deletions STACpopulator/implementations/CMIP6_UofT/add_CMIP6.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from typing import Any, MutableMapping, NoReturn, Optional, Union

from pystac import STACValidationError
from pystac.extensions.datacube import DatacubeExtension
from requests.sessions import Session

Expand Down Expand Up @@ -75,6 +76,11 @@ def create_stac_item(
except Exception as e:
raise Exception("Failed to add THREDDS extension") from e

try:
item.validate()
except STACValidationError:
raise Exception("Failed to validate STAC item") from e

# print(json.dumps(item.to_dict()))
return json.loads(json.dumps(item.to_dict()))

Expand Down

0 comments on commit 28c5465

Please sign in to comment.