File size: 2,011 Bytes
702c817 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | """Render the figures for every run in data/ into figures/<subject>/<session>/ (flat: overview.png,
data-*.png as recorded, derived-*.png computed).
python scripts/make_figures.py # only runs that have no figures yet
python scripts/make_figures.py --force # re-render everything (bloats the repo history -- rarely)
Doubles as the dataset's smoke test: it loads and plots every run, so if it finishes clean the data and
the lvl_running package agree. Exit code 1 if any run fails to load or plot.
"""
from __future__ import annotations
import argparse
import os
import sys
import traceback
from lvl_running import iter_sessions, plot_session
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE) # the dataset folder (scripts/ lives inside it)
def main(argv=None) -> int:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--data", default=os.path.join(ROOT, "data"))
ap.add_argument("--figures", default=os.path.join(ROOT, "figures"))
ap.add_argument("--force", action="store_true", help="re-render runs that already have figures")
a = ap.parse_args(argv)
done = skipped = failed = 0
for run_dir in iter_sessions(a.data):
rel = os.path.dirname(os.path.relpath(run_dir, a.data)) # S01/R01 (the level/ folder is dropped)
out = os.path.join(a.figures, rel)
if not a.force and os.path.isdir(out) and os.listdir(out):
skipped += 1
continue
try:
made = [k for k, p in plot_session(run_dir, out).items() if p]
print(f" {rel}: {', '.join(made) or 'no figures'}")
done += 1
except Exception:
print(f" FAIL {rel}\n{traceback.format_exc()}", file=sys.stderr)
failed += 1
print(f"{done} rendered, {skipped} already had figures, {failed} failed -> {a.figures}")
return 1 if failed else 0
if __name__ == "__main__":
raise SystemExit(main())
|