Skip to content

Commit

Permalink
Access scientific extension on item using .ext (#1496)
Browse files Browse the repository at this point in the history
* Access scientific extension on item using .ext

* Update changelog - delinquent
  • Loading branch information
jsignell authored Jan 17, 2025
1 parent 1cf7f3f commit e90b945
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
- Use [uv](https://github.com/astral-sh/uv) for development dependencies and docs ([#1439](https://github.com/stac-utils/pystac/pull/1439))
- Correctly detect absolute file path ref on windows, reflecting change in python 3.13 ([#1475](https://github.com/stac-utils/pystac/pull/14750)) (only effects python 3.13)
- Deprecated `ItemAssetExtension` ([#1476](https://github.com/stac-utils/pystac/pull/1476))
- Update Projection Extension to version 2 - proj:epsg -> proj:code ([#1287](https://github.com/stac-utils/pystac/pull/1287))
- Update migrate code to handle license changes in STAC spec 1.1.0 ([#1491](https://github.com/stac-utils/pystac/pull/1491))
- Allow links to have `file://` prefix - but don't write them that way by default ([#1489](https://github.com/stac-utils/pystac/pull/1489))

### Fixed

- Use `application/geo+json` for `item` links ([#1495](https://github.com/stac-utils/pystac/pull/1495))
- Includes the scientific extension in Item's ext interface ([#1496](https://github.com/stac-utils/pystac/pull/1496))

## [v1.11.0] - 2024-09-26

Expand Down
4 changes: 4 additions & 0 deletions pystac/extensions/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ def sar(self) -> SarExtension[Item]:
def sat(self) -> SatExtension[Item]:
return SatExtension.ext(self.stac_object)

@property
def sci(self) -> ScientificExtension[Item]:
return ScientificExtension.ext(self.stac_object)

@property
def storage(self) -> StorageExtension[Item]:
return StorageExtension.ext(self.stac_object)
Expand Down
24 changes: 24 additions & 0 deletions tests/extensions/test_scientific.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pystac
from pystac import ExtensionTypeError
from pystac.errors import ExtensionNotImplemented
from pystac.extensions import scientific
from pystac.extensions.scientific import (
Publication,
Expand Down Expand Up @@ -494,3 +495,26 @@ def test_summaries_adds_uri(self) -> None:
self.assertNotIn(
ScientificExtension.get_schema_uri(), collection.stac_extensions
)


@pytest.fixture
def ext_item() -> pystac.Item:
path = TestCases.get_path("data-files/scientific/item.json")
return pystac.Item.from_file(path)


def test_ext_syntax(ext_item: pystac.Item) -> None:
assert ext_item.ext.sci.doi == "10.5061/dryad.s2v81.2/27.2"


def test_ext_syntax_remove(ext_item: pystac.Item) -> None:
ext_item.ext.remove("sci")
assert ext_item.ext.has("sci") is False
with pytest.raises(ExtensionNotImplemented):
ext_item.ext.sci


def test_ext_syntax_add(item: pystac.Item) -> None:
item.ext.add("sci")
assert item.ext.has("sci") is True
assert isinstance(item.ext.sci, ScientificExtension)

0 comments on commit e90b945

Please sign in to comment.