Skip to content
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
5 changes: 5 additions & 0 deletions libs/unity-py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.11.0] - 2025-05-19

### Added
* When creating STAC catalogs using the Collection resource, if an asset is a file local to the catalog file, then the file:size and file:checksum values will be added to the asset's STAC entry.

## [0.10.1] - 2025-03-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion libs/unity-py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "unity-sds-client"
version = "0.10.1"
version = "0.11.0"

description = "Unity-Py is a Python client to simplify interactions with NASA's Unity Platform."
authors = ["Anil Natha, Mike Gangl"]
Expand Down
36 changes: 28 additions & 8 deletions libs/unity-py/unity_sds_client/resources/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from unity_sds_client.resources.dataset import Dataset
from unity_sds_client.resources.data_file import DataFile
from pystac import Catalog, get_stac_version, ItemCollection, Item, Asset
from pystac.extensions.file import FileExtension
from pystac.errors import STACTypeError
import hashlib
import json
import os
from datetime import datetime
Expand Down Expand Up @@ -132,15 +134,33 @@ def to_stac(collection, data_dir):
if key.startswith("./"):
key = os.path.basename(key)

item.add_asset(
key = key,
asset = Asset(
href = item_location,
title = "{} file".format(df.type),
description = "",
roles = df.roles
asset = Asset(
href = item_location,
title = "{} file".format(df.type),
description = "",
roles = df.roles
)

# If the file exists locally on disk then add optional STAC
# attribuites: file:size, file:checksum
data_filename = os.path.join(data_dir, item_location)
if os.path.exists(data_filename):
# Get file size
file_stats = os.stat(data_filename)

# Compute MD5SUM
md5 = hashlib.md5()
with open(data_filename, "rb") as f:
while chunk := f.read(4096):
md5.update(chunk)

file_ext = FileExtension.ext(asset)
file_ext.apply(
size=file_stats.st_size,
checksum=md5.hexdigest()
)
)

item.add_asset(key=key, asset=asset)

from pystac.layout import TemplateLayoutStrategy
write_dir = data_dir
Expand Down
Loading