Skip to content

Commit

Permalink
refactor: check historical imagery based on its category rather than …
Browse files Browse the repository at this point in the history
…survey number
  • Loading branch information
paulfouquet committed Jan 23, 2024
1 parent 8f10bf0 commit 795f004
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
9 changes: 6 additions & 3 deletions scripts/stac/imagery/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
HUMAN_READABLE_REGIONS,
RURAL_AERIAL_PHOTOS,
SATELLITE_IMAGERY,
SCANNED_AERIAL_PHOTOS,
URBAN_AERIAL_PHOTOS,
CollectionMetadata,
MissingMetadataError,
SubtypeParameterError,
)
from scripts.stac.imagery.provider import Provider, ProviderRole
Expand Down Expand Up @@ -244,7 +246,9 @@ def _title(self) -> str:
else:
preview = None

if historic_survey_number:
if self.metadata["category"] == SCANNED_AERIAL_PHOTOS:
if not historic_survey_number:
raise MissingMetadataError("historic_survey_number")
return " ".join(f"{name} {self.metadata['gsd']} {historic_survey_number} ({date}) {preview or ''}".split())

if self.metadata["category"] in [
Expand Down Expand Up @@ -283,7 +287,6 @@ def _description(self) -> str:
"""
# format optional metadata
geographic_description = self.metadata.get("geographic_description")
historic_survey_number = self.metadata.get("historic_survey_number")
event = self.metadata.get("event_name")

# format date for metadata
Expand All @@ -298,7 +301,7 @@ def _description(self) -> str:

region = HUMAN_READABLE_REGIONS[self.metadata["region"]]

if historic_survey_number:
if self.metadata["category"] == SCANNED_AERIAL_PHOTOS:
desc = f"Scanned aerial imagery within the {region} region captured in {date}"
elif self.metadata["category"] == SATELLITE_IMAGERY:
desc = f"Satellite imagery within the {region} region captured in {date}"
Expand Down
5 changes: 5 additions & 0 deletions scripts/stac/imagery/metadata_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def __init__(self, category: str) -> None:
self.message = f"Unrecognised/Unimplemented Subtype Parameter: {category}"


class MissingMetadataError(Exception):
def __init__(self, metadata: str) -> None:
self.message = f"Missing metadata: {metadata}"


AERIAL_PHOTOS = "aerial-photos"
SCANNED_AERIAL_PHOTOS = "scanned-aerial-photos"
RURAL_AERIAL_PHOTOS = "rural-aerial-photos"
Expand Down
2 changes: 1 addition & 1 deletion scripts/stac/tests/generate_description_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_generate_description_satellite_imagery(metadata: Tuple[CollectionMetada

def test_generate_description_historic_imagery(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
metadata_auck, _ = metadata
metadata_auck["category"] = "aerial-photos"
metadata_auck["category"] = "scanned-aerial-photos"
metadata_auck["historic_survey_number"] = "SNC8844"
collection = ImageryCollection(metadata_auck)
description = "Scanned aerial imagery within the Auckland region captured in 2023."
Expand Down
14 changes: 12 additions & 2 deletions scripts/stac/tests/generate_title_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from scripts.stac.imagery.collection import ImageryCollection
from scripts.stac.imagery.metadata_constants import CollectionMetadata
from scripts.stac.imagery.metadata_constants import CollectionMetadata, MissingMetadataError


@pytest.fixture(name="metadata", autouse=True)
Expand Down Expand Up @@ -68,12 +68,22 @@ def test_generate_satellite_imagery_title(metadata: Tuple[CollectionMetadata, Co
def test_generate_historic_imagery_title(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
title = "Auckland 0.3m SNC8844 (2023)"
metadata_auck, _ = metadata
metadata_auck["category"] = "aerial-photos"
metadata_auck["category"] = "scanned-aerial-photos"
metadata_auck["historic_survey_number"] = "SNC8844"
collection = ImageryCollection(metadata_auck)
assert collection.stac["title"] == title


def test_generate_historic_imagery_title_missing_number(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
metadata_auck, _ = metadata
metadata_auck["category"] = "scanned-aerial-photos"
metadata_auck["historic_survey_number"] = None
with pytest.raises(MissingMetadataError) as excinfo:
ImageryCollection(metadata_auck)

assert "historic_survey_number" in str(excinfo.value)


def test_generate_title_long_date(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
metadata_auck, _ = metadata
metadata_auck["end_datetime"] = datetime(2024, 1, 1)
Expand Down

0 comments on commit 795f004

Please sign in to comment.