"""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")