Skip to content

Commit

Permalink
fix: location should be geographic_description
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet committed Jan 14, 2024
1 parent 06b5cfb commit 0d4f91d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 43 deletions.
10 changes: 1 addition & 9 deletions scripts/collection_from_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ def main() -> None:
parser.add_argument(
"--location", dest="location", help="Optional Location of dataset, e.g. Hutt City", type=str, required=False
)
parser.add_argument(
"--geographic-description",
dest="geographic_description",
help="Optional Location Name, e.g. South Island",
type=str,
required=False,
)
parser.add_argument(
"--start-date",
dest="start_date",
Expand Down Expand Up @@ -110,10 +103,9 @@ def main() -> None:
"start_datetime": arguments.start_date,
"end_datetime": arguments.end_date,
"lifecycle": arguments.lifecycle,
"location": arguments.location,
"geographic_description": arguments.location,
"event_name": arguments.event,
"historic_survey_number": arguments.historic_survey_number,
"geographic_description": arguments.geographic_description,
}

collection = ImageryCollection(
Expand Down
34 changes: 21 additions & 13 deletions scripts/stac/imagery/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,20 @@ def write_to(self, destination: str) -> None:
def _title(self) -> str:
"""Generates the title for imagery and elevation datasets.
Satellite Imagery / Urban Aerial Photos / Rural Aerial Photos:
[Location / Region if no Location specified] [GSD] [?Event Name] [Data Sub-Type] ([Year(s)]) [?- Preview]
[geographic_description / Region if no geographic_description specified] [GSD] [?Event Name] [Data Sub-Type]
([Year(s)]) [?- Preview]
DEM / DSM:
[Location / Region if no Location specified] [?- Event Name] LiDAR [GSD] [Data Sub-Type] ([Year(s)]) [?- Preview]
[geographic_description / Region if no geographic_description specified] [?- Event Name] LiDAR [GSD]
[Data Sub-Type] ([Year(s)]) [?- Preview]
If Historic Survey Number:
[Location / Region if no Location specified] [GSD] [Survey Number] ([Year(s)]) [?- Preview]
[geographic_description / Region if no geographic_description specified] [GSD] [Survey Number] ([Year(s)])
[?- Preview]
Returns:
Dataset Title
"""
# format optional metadata
location = self.metadata.get("location")
geographic_description = self.metadata.get("geographic_description")
historic_survey_number = self.metadata.get("historic_survey_number")
event = self.metadata.get("event_name")

Expand All @@ -230,8 +233,8 @@ def _title(self) -> str:
date = f"{self.metadata['start_datetime'].year}-{self.metadata['end_datetime'].year}"

# determine dataset name
if location:
name = location
if geographic_description:
name = geographic_description
else:
name = HUMAN_READABLE_REGIONS[self.metadata["region"]]

Expand Down Expand Up @@ -268,7 +271,8 @@ def _description(self) -> str:
Urban Aerial Photos / Rural Aerial Photos:
Orthophotography within the [Region] region captured in the [Year(s)] flying season.
DEM / DSM:
[Digital Surface Model / Digital Elevation Model] within the [region] [?- location] region in [year(s)].
[Digital Surface Model / Digital Elevation Model] within the [region]
[?- geographic_description] region in [year(s)].
Satellite Imagery:
Satellite imagery within the [Region] region captured in [Year(s)].
Historical Imagery:
Expand All @@ -278,7 +282,7 @@ def _description(self) -> str:
Dataset Description
"""
# format optional metadata
location = self.metadata.get("location")
geographic_description = self.metadata.get("geographic_description")
historic_survey_number = self.metadata.get("historic_survey_number")
event = self.metadata.get("event_name")

Expand All @@ -288,9 +292,9 @@ def _description(self) -> str:
else:
date = f"{self.metadata['start_datetime'].year}-{self.metadata['end_datetime'].year}"

# format location for metadata description
if location:
location = f"- {location}"
# format geographic_description for metadata description
if geographic_description:
geographic_description = f"- {geographic_description}"

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

Expand All @@ -301,9 +305,13 @@ def _description(self) -> str:
elif self.metadata["category"] in [URBAN_AERIAL_PHOTOS, RURAL_AERIAL_PHOTOS]:
desc = f"Orthophotography within the {region} region captured in the {date} flying season"
elif self.metadata["category"] == DEM:
desc = " ".join(f"Digital Elevation Model within the {region} {location or ''} region in {date}".split())
desc = " ".join(
f"Digital Elevation Model within the {region} {geographic_description or ''} region in {date}".split()
)
elif self.metadata["category"] == DSM:
desc = " ".join(f"Digital Surface Model within the {region} {location or ''} region in {date}".split())
desc = " ".join(
f"Digital Surface Model within the {region} {geographic_description or ''} region in {date}".split()
)
else:
raise SubtypeParameterError(self.metadata["category"])

Expand Down
6 changes: 2 additions & 4 deletions scripts/stac/imagery/metadata_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ class CollectionMetadata(TypedDict):
end_date: Dataset capture end date
lifecycle: Dataset status
Optional:
location: Optional location of dataset, e.g. Hutt City
geographic_description: Optional geographic_description of dataset, e.g. Hutt City
event: Optional details of capture event, e.g. Cyclone Gabrielle
historic_survey_number: Optional historic imagery survey number, e.g. SNC88445
geographic_description: Optional location name, e.g. South Island
"""

category: str
Expand All @@ -22,10 +21,9 @@ class CollectionMetadata(TypedDict):
start_datetime: datetime
end_datetime: datetime
lifecycle: str
location: Optional[str]
geographic_description: Optional[str]
event_name: Optional[str]
historic_survey_number: Optional[str]
geographic_description: Optional[str]


class SubtypeParameterError(Exception):
Expand Down
9 changes: 4 additions & 5 deletions scripts/stac/tests/collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ def setup() -> Generator[CollectionMetadata, None, None]:
"start_datetime": datetime(2022, 2, 2),
"end_datetime": datetime(2022, 2, 2),
"lifecycle": "completed",
"location": None,
"event_name": "Forest assessment",
"historic_survey_number": None,
"geographic_description": "North Island",
"geographic_description": "Auckland North",
}
yield metadata


def test_title_description_id_created_on_init(metadata: CollectionMetadata) -> None:
collection = ImageryCollection(metadata)
assert collection.stac["title"] == "Auckland 0.3m Forest assessment Urban Aerial Photos (2022)"
assert collection.stac["title"] == "Auckland North 0.3m Forest assessment Urban Aerial Photos (2022)"
assert (
collection.stac["description"]
== "Orthophotography within the Auckland region captured in the 2022 flying season, published as a record of the Forest assessment event." # pylint: disable=line-too-long
)
assert collection.stac["id"]
assert collection.stac["linz:region"] == "auckland"
assert collection.stac["linz:geographic_description"] == "North Island"
assert collection.stac["linz:geographic_description"] == "Auckland North"
assert collection.stac["linz:event_name"] == "Forest assessment"
assert collection.stac["linz:lifecycle"] == "completed"
assert collection.stac["linz:geospatial_category"] == "urban-aerial-photos"
Expand Down Expand Up @@ -184,4 +183,4 @@ def test_event_name_is_present(metadata: CollectionMetadata) -> None:

def test_geographic_description_is_present(metadata: CollectionMetadata) -> None:
collection = ImageryCollection(metadata)
assert "North Island" == collection.stac["linz:geographic_description"]
assert "Auckland North" == collection.stac["linz:geographic_description"]
12 changes: 6 additions & 6 deletions scripts/stac/tests/generate_description_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ def setup() -> Generator[Tuple[CollectionMetadata, CollectionMetadata], None, No
"start_datetime": datetime(2023, 1, 1),
"end_datetime": datetime(2023, 2, 2),
"lifecycle": "completed",
"location": None,
"geographic_description": None,
"event_name": None,
"historic_survey_number": None,
"geographic_description": None,
}
metadata_hb: CollectionMetadata = {
"category": "rural-aerial-photos",
Expand All @@ -28,10 +27,9 @@ def setup() -> Generator[Tuple[CollectionMetadata, CollectionMetadata], None, No
"start_datetime": datetime(2023, 1, 1),
"end_datetime": datetime(2023, 2, 2),
"lifecycle": "completed",
"location": None,
"geographic_description": None,
"event_name": None,
"historic_survey_number": None,
"geographic_description": None,
}
yield (metadata_auck, metadata_hb)

Expand All @@ -51,10 +49,12 @@ def test_generate_description_elevation(metadata: Tuple[CollectionMetadata, Coll
assert collection.stac["description"] == description


def test_generate_description_elevation_location_input(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
def test_generate_description_elevation_geographic_description_input(
metadata: Tuple[CollectionMetadata, CollectionMetadata]
) -> None:
metadata_auck, _ = metadata
metadata_auck["category"] = "dem"
metadata_auck["location"] = "Central"
metadata_auck["geographic_description"] = "Central"
collection = ImageryCollection(metadata_auck)
description = "Digital Elevation Model within the Auckland - Central region in 2023."
assert collection.stac["description"] == description
Expand Down
8 changes: 3 additions & 5 deletions scripts/stac/tests/generate_title_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def setup() -> Generator[Tuple[CollectionMetadata, CollectionMetadata], None, No
"start_datetime": datetime(2023, 1, 1),
"end_datetime": datetime(2023, 2, 2),
"lifecycle": "completed",
"location": None,
"event_name": None,
"historic_survey_number": None,
"geographic_description": None,
Expand All @@ -28,7 +27,6 @@ def setup() -> Generator[Tuple[CollectionMetadata, CollectionMetadata], None, No
"start_datetime": datetime(2023, 1, 1),
"end_datetime": datetime(2023, 2, 2),
"lifecycle": "completed",
"location": None,
"event_name": None,
"historic_survey_number": None,
"geographic_description": None,
Expand Down Expand Up @@ -84,9 +82,9 @@ def test_generate_title_long_date(metadata: Tuple[CollectionMetadata, Collection
assert collection.stac["title"] == title


def test_generate_title_location(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
def test_generate_title_geographic_description(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
metadata_auck, _ = metadata
metadata_auck["location"] = "Ponsonby"
metadata_auck["geographic_description"] = "Ponsonby"
collection = ImageryCollection(metadata_auck)
title = "Ponsonby 0.3m Rural Aerial Photos (2023)"
assert collection.stac["title"] == title
Expand Down Expand Up @@ -129,7 +127,7 @@ def test_generate_dsm_title_preview(metadata: Tuple[CollectionMetadata, Collecti

def test_generate_imagery_title_empty_optional_str(metadata: Tuple[CollectionMetadata, CollectionMetadata]) -> None:
metadata_auck, _ = metadata
metadata_auck["location"] = ""
metadata_auck["geographic_description"] = ""
metadata_auck["event_name"] = ""
collection = ImageryCollection(metadata_auck)
title = "Auckland 0.3m Rural Aerial Photos (2023)"
Expand Down
1 change: 0 additions & 1 deletion scripts/stac/tests/item_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def test_imagery_add_collection(mocker) -> None: # type: ignore
"start_datetime": datetime(2022, 2, 2),
"end_datetime": datetime(2022, 2, 2),
"lifecycle": "completed",
"location": None,
"event_name": None,
"historic_survey_number": None,
"geographic_description": None,
Expand Down

0 comments on commit 0d4f91d

Please sign in to comment.