Skip to content

Access scientific extension on item using .ext #1496

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

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading