astrophotography/pipeline/unzip.py
laurence c6299f41ab Move the processing code under pipeline/
Preparing to merge this repository into a combined astrophotography
repo. session-scripts/ becomes pipeline/ because the scripts import
layout.py from their own directory and must stay together, and because
'pipeline' says what it is rather than how it came about. observing/
stays at the top level: observing plans are not processing code.
2026-07-21 17:13:54 +01:00

33 lines
1.1 KiB
Python

"""Uncompress every calibrated-*.zip in the session folder, in place.
iTelescope ships each calibrated frame as a one-entry zip (.fit.zip and
.tif.zip). Extraction is skipped when the target already exists and is
non-empty, so this is safe to re-run.
"""
import glob
import os
import zipfile
import layout
SRC = layout.SESSION
zips = sorted(glob.glob(layout.path("calibrated-*.zip")))
print(f"{len(zips)} calibrated archives")
done = skipped = 0
for z in zips:
with zipfile.ZipFile(z) as zf:
for info in zf.infolist():
target = layout.path(os.path.basename(info.filename))
if os.path.exists(target) and os.path.getsize(target) == info.file_size:
skipped += 1
continue
with zf.open(info) as fsrc, open(target, "wb") as fdst:
while chunk := fsrc.read(1 << 20):
fdst.write(chunk)
done += 1
print(f"extracted {done}, already present {skipped}")
for ext in (".fit", ".tif"):
n = len(glob.glob(layout.path(f"calibrated-*{ext}")))
print(f"{ext}: {n} files")