Download scripts/make_figures.py from lvlmotion/running: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/datasets/lvlmotion/running/resolve/main/scripts/make_figures.py
- Command line
-
hf download hf://datasets/lvlmotion/running/scripts/make_figures.py
-
curl -L -o make_figures.py https://huggingface.co/datasets/lvlmotion/running/resolve/main/scripts/make_figures.py
2.01 kB
| """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()) | |