Skip to content

Commit

Permalink
DAS-2146: First stab at pulling correct asset from Item
Browse files Browse the repository at this point in the history
This probably works, but it is a first try.
  • Loading branch information
flamingbear committed May 22, 2024
1 parent 8cbc1a2 commit 55574f7
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions harmony_browse_image_generator/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,34 @@ def validate_message(self):
'Harmony ScaleExtents must be in order [xmin,ymin,xmax,ymax].'
)

def asset_from_item(self, item: Item) -> Asset:
"""Returns the correct asset from a stac Item.
Find an asset with 'visual' in any of the item's values' roles.
If not found return the asset that has 'data' in its item's values' roles.
"""
try:
return next(
item_asset
for item_asset in item.assets.values()
if 'visual' in (item_asset.roles or [])
)
except StopIteration:
return next(
item_asset
for item_asset in item.assets.values()
if 'data' in (item_asset.roles or [])
)

def process_item(self, item: Item, source: HarmonySource) -> Item:
"""Processes a single input STAC item."""

try:
working_directory = mkdtemp()
results = item.clone()
results.assets = {}

asset = next(
item_asset
for item_asset in item.assets.values()
if 'data' in (item_asset.roles or [])
)
asset = self.asset_from_item(item)

color_palette = get_color_palette_from_item(item)

Expand Down

0 comments on commit 55574f7

Please sign in to comment.