def compute_tar_digest(path):
hash_fn = hashlib.sha256()
with open(path, "rb") as f:
while chunk := f.read(8192):
hash_fn.update(chunk)
return f"sha256:{hash_fn.hexdigest()}"
tar_dir = Path("../data/pastis")
layers = []
for tile_name in sorted(tile_metadata.keys()):
tar_path = tar_dir / f"{tile_name}.tar"
if not tar_path.exists():
print(f"⚠️ Skipping {tile_name}: tar file not found at {tar_path}")
continue
print(f"\nProcessing {tar_path.name}...")
digest = compute_tar_digest(tar_path)
meta = tile_metadata[tile_name]
layer = {
"tile": tile_name,
"bounding_box": meta.get("bounding_box"),
"temporal_coverage": meta.get("dates"),
"layer_digest": digest,
"layer_mediaType": "application/vnd.oci.image.layer.v1.tar"
}
layers.append(layer)
config = {
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.config.v1+json",
"artifactType": "application/vnd.whatever.v1+tar",
"dataset": "PASTIS-HD",
"created_by": "IGN",
"license": "etalab-2.0",
"tiles": layers
}
out_path = tar_dir / "config-2433.json"
with open(out_path, "w") as f:
json.dump(config, f, indent=2)
Config written at /home/stefan/papers/oci-eo-data-packages/data/sample/config-2433.json)