Skip to content
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

fix: Treat item as dict TDE-1209 #993

Merged
merged 1 commit into from
Jul 1, 2024
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
13 changes: 6 additions & 7 deletions scripts/stac/imagery/collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from collections.abc import Callable
from dataclasses import asdict
from datetime import datetime
from typing import Any

Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion scripts/stac/imagery/tests/collection_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

Expand Down
Loading