Download pulse/data/recordings.py from velvet-pine-22/PULSE-code: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/velvet-pine-22/PULSE-code/resolve/main/pulse/data/recordings.py
- Command line
-
hf download hf://velvet-pine-22/PULSE-code/pulse/data/recordings.py
-
curl -L -o recordings.py https://huggingface.co/velvet-pine-22/PULSE-code/resolve/main/pulse/data/recordings.py
2.58 kB
| """Recording index from ``metadata/recordings.csv``. | |
| The ``split`` column of that file is the legacy fixed 31/5 hold-out and is not | |
| used by any camera-ready experiment (it is exposed as ``legacy_holdout``). | |
| """ | |
| from __future__ import annotations | |
| import csv | |
| from dataclasses import dataclass | |
| from typing import Dict, FrozenSet, List | |
| from ..errors import DataRootError | |
| from ..paths import DataRoot, make_rid, vol_number | |
| SCENARIOS_TASK = tuple(f"s{i}" for i in range(1, 9)) # S1-S8: scripted daily tasks | |
| SCENARIO_S9 = "s9" # S9: motion primitives | |
| class Recording: | |
| rid: str | |
| volunteer: str | |
| scenario: str | |
| duration_sec: float | |
| n_samples_100hz: int | |
| aligned_modalities: FrozenSet[str] | |
| missing_modalities: FrozenSet[str] | |
| has_dense_annotations: bool | |
| legacy_holdout: str | |
| def lists(self, metadata_name: str) -> bool: | |
| return metadata_name in self.aligned_modalities | |
| def _split_set(s: str) -> FrozenSet[str]: | |
| return frozenset(x for x in (s or "").split("|") if x) | |
| def load_recordings(dr: DataRoot) -> Dict[str, Recording]: | |
| path = dr.recordings_csv | |
| if not path.is_file(): | |
| raise DataRootError(f"missing {path}") | |
| out: Dict[str, Recording] = {} | |
| with open(path, encoding="utf-8", newline="") as f: | |
| for row in csv.DictReader(f): | |
| rid = row["recording_id"].strip() | |
| vol, scen = row["volunteer_id"].strip(), row["scenario_id"].strip() | |
| if make_rid(vol, scen) != rid: | |
| raise DataRootError(f"recordings.csv: id {rid} != {vol}{scen}") | |
| if rid in out: | |
| raise DataRootError(f"recordings.csv: duplicate {rid}") | |
| out[rid] = Recording( | |
| rid=rid, volunteer=vol, scenario=scen, | |
| duration_sec=float(row["duration_sec"] or "nan"), | |
| n_samples_100hz=int(float(row["n_samples_100hz"] or 0)), | |
| aligned_modalities=_split_set(row.get("aligned_modalities", "")), | |
| missing_modalities=_split_set(row.get("missing_modalities", "")), | |
| has_dense_annotations=str(row.get("has_dense_annotations", "0")).strip() == "1", | |
| legacy_holdout=row.get("split", ""), | |
| ) | |
| return out | |
| def sort_rids(rids) -> List[str]: | |
| def key(r: str): | |
| v, s = r.split("s", 1) | |
| return (vol_number(v), int(s)) | |
| return sorted(rids, key=key) | |
| def volunteers(recs: Dict[str, Recording]) -> List[str]: | |
| return sorted({r.volunteer for r in recs.values()}, key=vol_number) | |