Skip to content

Commit

Permalink
feat: add scientific extension
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed May 10, 2022
1 parent 74a80c0 commit 542d5fc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
- Dataset homepage: https://www.usgs.gov/core-science-systems/ngp/3dep
- STAC extensions used:
- [proj](https://github.com/stac-extensions/projection/)
- Extra fields:
- None
- [raster](https://github.com/stac-extensions/raster/)
- [scientific](https://github.com/stac-extensions/scientific/)

This package creates STAC items for USGS 3DEP (formerly NED) elevation data.

Expand Down
2 changes: 2 additions & 0 deletions examples/usgs-3dep-1/n41w106-1/n41w106-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"start_datetime": "2020-10-03T00:00:00Z",
"end_datetime": "2020-10-10T00:00:00Z",
"sci:citation": "U.S. Geological Survey, 2022, USGS 1 Arc Second n41w106 20220331, accessed 2022-05-09",
"datetime": "2020-10-10T00:00:00Z"
},
"geometry": {
Expand Down Expand Up @@ -119,6 +120,7 @@
],
"stac_extensions": [
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/raster/v1.0.0/schema.json"
],
"collection": "usgs-3dep-1"
Expand Down
2 changes: 2 additions & 0 deletions examples/usgs-3dep-13/n41w106-13/n41w106-13.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"start_datetime": "2020-10-03T00:00:00Z",
"end_datetime": "2020-10-10T00:00:00Z",
"sci:citation": "U.S. Geological Survey, 2022, USGS 1/3 Arc Second n41w106 20220331, accessed 2022-05-09",
"datetime": "2020-10-10T00:00:00Z"
},
"geometry": {
Expand Down Expand Up @@ -119,6 +120,7 @@
],
"stac_extensions": [
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/raster/v1.0.0/schema.json"
],
"collection": "usgs-3dep-13"
Expand Down
10 changes: 10 additions & 0 deletions src/stactools/threedep/stac.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import datetime
from typing import Optional

from pystac import Item
from pystac.extensions.raster import DataType, RasterBand, RasterExtension, Sampling
from pystac.extensions.scientific import ScientificExtension
from stactools.core import create
from stactools.core.io import ReadHrefModifier

Expand Down Expand Up @@ -43,6 +45,14 @@ def create_item_from_metadata(
item.common_metadata.start_datetime = metadata.start_datetime
item.common_metadata.end_datetime = metadata.end_datetime
item.links.append(metadata.via_link(base))

scientific = ScientificExtension.ext(item, add_if_missing=True)
assert metadata.publication_datetime
scientific.citation = (
f"U.S. Geological Survey, {metadata.publication_datetime.year}, {metadata.title}, "
f"accessed {datetime.date.today().isoformat()}"
)

data = metadata.data_asset(base)
item.add_asset("data", data)
raster = RasterExtension.ext(data, add_if_missing=True)
Expand Down
8 changes: 0 additions & 8 deletions tests/test_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,3 @@ def modify_href(href: str) -> str:
)
_ = stac.create_item(path, modify_href)
self.assertTrue(did_it)

def test_explicit_none_goes_to_aws(self) -> None:
path = test_data.get_path(
"data-files/base/1/TIFF/current/n41w106/USGS_1_n41w106.xml"
)
item0 = stac.create_item(path)
item1 = stac.create_item(path, base=None)
self.assertEqual(item0.to_dict(), item1.to_dict())

0 comments on commit 542d5fc

Please sign in to comment.