Skip to content

Commit

Permalink
refactor: rearranged create_stac.py to support TDE-1298 (#1183)
Browse files Browse the repository at this point in the history
### Motivation

Rearrange function flow in `create_stac.py` to simplify implementation
of TDE-1298.

### Modifications
Changed which function outputs would be kept in a local variable and
moved creating `stac_asset` closer to where it is used.

### Verification

`pytest`
  • Loading branch information
schmidtnz authored Nov 21, 2024
1 parent 119a2cd commit bc93aaf
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions scripts/stac/imagery/create_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ def create_item(
if not gdalinfo_result:
gdalinfo_result = gdal_info(asset_path)

geometry, bbox = get_extents(gdalinfo_result)

if derived_from is not None:
for derived in derived_from:
derived_item_content = read(derived)
Expand All @@ -130,7 +128,7 @@ def create_item(
)

item.update_datetime(start_datetime, end_datetime)
item.update_spatial(geometry, bbox)
item.update_spatial(*get_extents(gdalinfo_result))
item.add_collection(collection_id)

get_log().info("ImageryItem created", path=asset_path)
Expand All @@ -148,17 +146,8 @@ def create_base_item(asset_path: str, gdal_version: str) -> ImageryItem:
"""
id_ = get_file_name_from_path(asset_path)
file_content = fs.read(asset_path)
file_content_checksum = checksum.multihash_as_hex(file_content)
file_modified_datetime = format_rfc_3339_datetime_string(modified(asset_path))

stac_asset = STACAsset(
**{
"href": os.path.join(".", os.path.basename(asset_path)),
"file:checksum": checksum.multihash_as_hex(file_content),
"created": file_modified_datetime,
"updated": file_modified_datetime,
}
)

now_string = format_rfc_3339_datetime_string(utc_now())

if (topo_imagery_hash := os.environ.get("GIT_HASH")) is not None:
Expand All @@ -174,4 +163,13 @@ def create_base_item(asset_path: str, gdal_version: str) -> ImageryItem:
}
)

stac_asset = STACAsset(
**{
"href": os.path.join(".", os.path.basename(asset_path)),
"file:checksum": file_content_checksum,
"created": file_modified_datetime,
"updated": file_modified_datetime,
}
)

return ImageryItem(id_, now_string, stac_asset, stac_processing)

0 comments on commit bc93aaf

Please sign in to comment.