diff --git a/scripts/stac/imagery/collection.py b/scripts/stac/imagery/collection.py index 444a6d2a6..486ae19b2 100644 --- a/scripts/stac/imagery/collection.py +++ b/scripts/stac/imagery/collection.py @@ -1,6 +1,5 @@ import os from collections.abc import Callable -from dataclasses import asdict from datetime import datetime from typing import Any @@ -12,7 +11,7 @@ from scripts.files.fs import write from scripts.json_codec import dict_to_json_bytes from scripts.stac.imagery.capture_area import generate_capture_area, gsd_to_float -from scripts.stac.imagery.item import BoundingBox, ImageryItem +from scripts.stac.imagery.item import BoundingBox from scripts.stac.imagery.metadata_constants import ( DATA_CATEGORIES, DEM, @@ -130,18 +129,18 @@ def add_capture_area(self, polygons: list[BaseGeometry], target: str, artifact_t if StacExtensions.file.value not in self.stac["stac_extensions"]: self.stac["stac_extensions"].append(StacExtensions.file.value) - def add_item(self, item: ImageryItem) -> None: + def add_item(self, item: dict[Any, Any]) -> None: """Add an `Item` to the `links` of the `Collection`. Args: item: STAC Item to add """ - item_self_link = next((feat for feat in item.links if feat["rel"] == "self"), None) - file_checksum = checksum.multihash_as_hex(dict_to_json_bytes(asdict(item))) + item_self_link = next((feat for feat in item["links"] if feat["rel"] == "self"), None) + file_checksum = checksum.multihash_as_hex(dict_to_json_bytes(item)) if item_self_link: self.add_link(href=item_self_link["href"], file_checksum=file_checksum) - self.update_temporal_extent(item.properties.start_datetime, item.properties.end_datetime) - self.update_spatial_extent(item.bbox) + self.update_temporal_extent(item["properties"]["start_datetime"], item["properties"]["end_datetime"]) + self.update_spatial_extent(item["bbox"]) def add_link(self, href: str, file_checksum: str) -> None: """Add a `link` to the existing `links` list of the Collection. diff --git a/scripts/stac/imagery/tests/collection_test.py b/scripts/stac/imagery/tests/collection_test.py index a8b23fe0d..16270a646 100644 --- a/scripts/stac/imagery/tests/collection_test.py +++ b/scripts/stac/imagery/tests/collection_test.py @@ -1,5 +1,6 @@ import json import os +from dataclasses import asdict from datetime import datetime, timezone from shutil import rmtree from tempfile import TemporaryDirectory, mkdtemp @@ -138,7 +139,7 @@ def test_add_item(metadata: CollectionMetadata, subtests: SubTests) -> None: "BR34_5000_0304", item_file_path, now_function, start_datetime, end_datetime, geometry, bbox, collection.stac["id"] ) - collection.add_item(item) + collection.add_item(asdict(item)) links = collection.stac["links"].copy()