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

HARMONY-1922: Add geometry to STAC item when bbox is defined, but geometry is not #49

Merged
merged 2 commits into from
Oct 17, 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
10 changes: 7 additions & 3 deletions harmony_service_lib/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,13 @@ def _process_catalog_recursive(self, catalog):
result.clear_items()
source = None
for item in items:
cloned_item = item.clone()
# if there is a bbox, but no geometry, create a geometry from the bbox
if cloned_item.bbox and not cloned_item.geometry:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know why an item could have bbox, but no geometry?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Harmony is creating them that way. Up until recently this didn't matter, but pystac started enforcing the spec, so we decided to add the geometry by duplicating the bbox as a polygon.

cloned_item.geometry = util.bbox_to_geometry(cloned_item.bbox)
item_count = item_count + 1
source = source or self._get_item_source(item)
output_item = self.process_item(item.clone(), source)
source = source or self._get_item_source(cloned_item)
output_item = self.process_item(cloned_item, source)
if output_item:
# Ensure the item gets a new ID
if output_item.id == item.id:
Expand All @@ -209,7 +213,7 @@ def _process_with_callbacks(self):
completed = 0
for source in self.message.sources:
for granule in source.granules:
item = Item(granule.id, None, granule.bbox, None, {
item = Item(granule.id, util.bbox_to_geometry(granule.bbox), granule.bbox, None, {
'start_datetime': granule.temporal.start,
'end_datetime': granule.temporal.end
})
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
boto3 ~= 1.14
deprecation ~= 2.1.0
pynacl ~= 1.4
pystac>=1.0.0,<1.11.0 # Locked due to HARMONY-1922
pystac >= 1.0.0
python-json-logger ~= 2.0.1
requests ~= 2.24
urllib3 ~= 1.26.9
11 changes: 8 additions & 3 deletions tests/test_adapter_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def test_get_all_items_handles_children(self, test_patch):
adapter = AdapterTester(message, catalog, config=self.config)
all_items = list(adapter.get_all_catalog_items(catalog, True))
self.assertEqual(all_items, [ *items_a, *items_b ])


def test_unaltered_ids_are_assigned_new_uuids(self):
catalog = Catalog('0', 'Catalog 0')
Expand Down Expand Up @@ -218,7 +217,10 @@ def test_legacy_invocations_create_stac_catalogs(self):
'end_datetime': '2002-02-02T02:02:02Z',
'datetime': None
},
'geometry': None,
'geometry': {
'coordinates': [[[-1, -2], [-1, 4], [3, 4], [3, -2], [-1, -2]]],
'type': 'Polygon'
},
'links': [],
'assets': {
'data': {
Expand All @@ -239,7 +241,10 @@ def test_legacy_invocations_create_stac_catalogs(self):
'end_datetime': '2004-04-04T04:04:04Z',
'datetime': None
},
'geometry': None,
'geometry': {
'coordinates': [[[-5, -6], [-5, 8], [7, 8], [7, -6], [-5, -6]]],
'type': 'Polygon'
},
'links': [],
'assets': {
'data': {
Expand Down
Loading