emgbenchanon commited on
Commit
fa287f8
·
verified ·
1 Parent(s): af6481d

Add README.md

Browse files
Files changed (1) hide show
  1. README.md +255 -0
README.md ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gpl-3.0
3
+ task_categories:
4
+ - other
5
+ language:
6
+ - en
7
+ tags:
8
+ - electromyography
9
+ - emg
10
+ - motor-unit-decomposition
11
+ - blind-source-separation
12
+ - dynamic-contraction
13
+ - synthetic
14
+ - neuromuscular
15
+ size_categories:
16
+ - n<1K
17
+ pretty_name: MUniverse Dynamic EMG Benchmark v2
18
+ ---
19
+
20
+ # MUniverse Dynamic EMG Benchmark v2
21
+
22
+ **336 synthetic non-stationary surface EMG recordings** for benchmarking motor-unit decomposition algorithms under dynamic joint motion. 21 motor-unit pool combinations (26–113 MUs) × 5 simulated subjects × 7 forearm muscles × 8 conditions (sinusoidal/triangular wrist Flexion–Extension at two amplitudes × two SNR levels), at 70-ch and 320-ch electrode configurations.
23
+
24
+ ## Files
25
+
26
+ | File | Size | Purpose |
27
+ |---|---|---|
28
+ | `recordings.tar.gz` | 4.7 GB | The 336 `.npz` recordings (`benchmark_v2/{ch070,ch320}/`) |
29
+ | `reproducibility_bundle.zip` | 36 KB | Scripts, manifests, NeuroMotion patch, PBS templates |
30
+ | `benchmark_spec.json` | 7 KB | Declarative spec: subjects, muscles, conditions, combos |
31
+ | `README.md` | 8 KB | This page (also inside the bundle, as the canonical reproduction guide) |
32
+
33
+ SHA256:
34
+ - `recordings.tar.gz`: `715458efd70ca8932e1e45a642698fa11a4446e0352dbe1840e0a7e251544f56`
35
+ - `reproducibility_bundle.zip`: `f4e034726a5c2afd60f408d3e32d63be074a586235316c38926feafd3d3e0988`
36
+
37
+ ## Quick load
38
+
39
+ ```python
40
+ import numpy as np
41
+ d = np.load("benchmark_v2/ch320/SA10-hi_ECU_sub03_N055.npz", allow_pickle=True)
42
+ emg = d["emg"] # (T, 320) float32
43
+ spike_mu_0 = d["spike_mu_0"] # (n_spikes,) int64 — ground-truth indices
44
+ angle_profile = d["angle_profile"] # (T,) joint angle in degrees
45
+ effort_profile = d["effort_profile"] # (T,) effort, fraction MVC
46
+ fs = int(d["fs"]) # 2048
47
+ ```
48
+
49
+ See `benchmark_spec.json` for the full parameter grid (8 conditions × 21 combos × 2 channel configs = 336).
50
+
51
+ ## Reproduction
52
+
53
+ The dataset is fully reproducible from open code: NeuroMotion + BioMime → MUAP libraries → crosstalk filtering → NeuroMotion synthesis. Stage-by-stage scripts and PBS templates are inside `reproducibility_bundle.zip`. The original README (which lives at `experiments/v2/README.md` inside the bundle) walks through all five stages.
54
+
55
+
56
+ ---
57
+
58
+ ## Original reproducibility README
59
+
60
+ _Below is the canonical reproduction guide as it appears inside `reproducibility_bundle.zip`._
61
+
62
+
63
+ Complete configuration, scripts, and metadata to regenerate the **v2 benchmark**: 336 non-stationary EMG recordings across 21 motor-unit pool combinations (26–113 MUs), 5 subjects, 7 muscle types, and 8 conditions (sinusoid/triangular angle × 2 difficulties × 2 SNR).
64
+
65
+ The benchmark was generated using **MUniverse as-is** — no modifications to the core package except a single small patch to NeuroMotion's Triangular angle-profile generator (included in `scripts/patches/`). The story of this bundle is:
66
+
67
+ 1. Generate 40 MUAP libraries using NeuroMotion+BioMime (5 subjects × 8 muscles at Flex-Ext DOF).
68
+ 2. Analyze pairwise MUAP similarity, filter each library to a "crosstalk-clean" subset.
69
+ 3. Use NeuroMotion to synthesize 336 EMG recordings from those clean subsets, each exposed to different rotation profiles and noise levels.
70
+
71
+ ## Contents
72
+
73
+ ```
74
+ experiments/v2/
75
+ ├── README.md # This file
76
+ ├── benchmark_spec.json # Declarative specification (reviewer-readable)
77
+ ├── combos.json # The 21 subject-muscle-threshold combos used
78
+ ├── scripts/ # Scripts used, in execution order
79
+ │ ├── 01_generate_muap_caches.py # Stage 1: Run BioMime to make 40 caches (GPU)
80
+ │ ├── 02_analyze_crosstalk.py # Stage 2: Pairwise similarity analysis
81
+ │ ├── 03_create_clean_caches.py # Stage 3: Filter each cache to a clean subset
82
+ │ ├── 04_generate_recordings.py # Stage 4: Run NeuroMotion on clean caches
83
+ │ ├── 05_fix_triangular.py # Stage 5: Bug fix, regenerate triangular only
84
+ │ ├── build_metadata.py # (meta) Generates the manifest CSVs below
85
+ │ └── patches/
86
+ │ └── neuromotion_triangular_symmetric.patch # NeuroMotion fix
87
+ └── metadata/
88
+ ├── muap_caches_manifest.csv # 40 caches with shapes, fiber density, sha256
89
+ ├── combos_manifest.csv # 21 clean combo pools
90
+ ├── conditions_manifest.csv # 8 condition definitions
91
+ └── recordings_manifest.csv # 336 recordings with full parameters
92
+ ```
93
+
94
+ ## Prerequisites
95
+
96
+ 1. **MUniverse** — tested against `dynamic_zi_resampling` branch (see `git log`). Clone the repo and install:
97
+ ```bash
98
+ git clone https://github.com/dfarinagroup/muniverse muniverse-live
99
+ cd muniverse-live
100
+ git checkout dynamic_zi_resampling
101
+ pip install -e .
102
+ ```
103
+
104
+ 2. **NeuroMotion Singularity/Docker image** — `pranavm19/muniverse-test:neuromotion`:
105
+ ```bash
106
+ cd src/environment
107
+ singularity pull muniverse-test_neuromotion.sif docker://pranavm19/muniverse-test:neuromotion
108
+ ```
109
+
110
+ 3. **NeuroMotion triangular patch** — apply to `src/muniverse/data_generation/_run_neuromotion.py`:
111
+ ```bash
112
+ cd muniverse-live
113
+ git apply experiments/v2/scripts/patches/neuromotion_triangular_symmetric.patch
114
+ ```
115
+ (Or just copy the `Triangular` branch from that file into your `_run_neuromotion.py` line ~434.)
116
+
117
+ 4. **Hardware**:
118
+ - Stage 1 (MUAP generation): **GPU** — each of 40 caches takes ~2-3 min on A40 / RTX6000.
119
+ - Stages 2–5: CPU only.
120
+
121
+ 5. **Disk**:
122
+ - MUAP caches: ~95 GB permanent
123
+ - Clean caches: ~8 GB
124
+ - Recordings: ~5 GB
125
+ - Raw outputs + configs: ~10 GB ephemeral (safe to delete after gen)
126
+
127
+ ## Reproduction Steps
128
+
129
+ ### Stage 1: Generate 40 MUAP caches (GPU, ~1.5 hours)
130
+
131
+ Each cache is a `(num_mus, 130, 10, 32, 96)` numpy array — MUAPs over 130 angle steps for each MU on a 10×32 electrode grid.
132
+
133
+ ```bash
134
+ # Generate all 40 (5 subjects × 8 muscles at Flex-Ext DOF)
135
+ python experiments/v2/scripts/01_generate_muap_caches.py
136
+ ```
137
+
138
+ The script edits these hardcoded paths — adjust before running:
139
+ - `CACHE_ROOT`: where to write the caches
140
+ - `RAW_ROOT`: scratch dir for container outputs (ephemeral is fine)
141
+ - `SIF_PATH`: path to the NeuroMotion Singularity image
142
+
143
+ Output: `<CACHE_ROOT>/cache_sub-simXX/subject_X_{MUSCLE}_Flexion-Extension_muaps.npy` + `_metadata.json` + `_mn_properties.csv`.
144
+
145
+ ### Stage 2: Crosstalk analysis (CPU, ~5 min)
146
+
147
+ ```bash
148
+ python experiments/v2/scripts/02_analyze_crosstalk.py
149
+ ```
150
+
151
+ Discovers all Flex-Ext caches, computes pairwise cosine similarity at mid-pose, and writes clean-subset selections at thresholds 0.75 / 0.80 / 0.85 / 0.90 to:
152
+ `experiments/results/crosstalk_v3/exp_crosstalk_clean_subsets.json`
153
+
154
+ ### Stage 3: Create 21 clean caches (CPU, ~1 min)
155
+
156
+ ```bash
157
+ python experiments/v2/scripts/03_create_clean_caches.py
158
+ ```
159
+
160
+ Reads the crosstalk JSON and writes 21 filtered caches to `experiments/clean_caches_v2/` (organized as `{tier}/sub{N}_{muscle}_thr{XX}/...`). Also writes `combos.json` — the master list consumed by Stage 4.
161
+
162
+ ### Stage 4: Generate 336 recordings (CPU, ~55 min)
163
+
164
+ ```bash
165
+ python experiments/v2/scripts/04_generate_recordings.py \
166
+ --config experiments/clean_caches_v2/combos.json
167
+ ```
168
+
169
+ For each combo, runs the container 8 times (one per condition), post-processes into 2 channel configs (ch070 + ch320), and writes:
170
+ `<BENCHMARK_ROOT>/ch{070,320}/{cond}_{muscle}_sub{N}_N{K}.npz`
171
+
172
+ ### Stage 5 (only if you hit the bug): Fix triangular recordings
173
+
174
+ If you run Stage 4 **without** the NeuroMotion patch applied, the 168 triangular recordings will have flat 0° angle profiles. To detect: check any `TA*.npz` file — `angle_profile` should oscillate ±sin_amplitude.
175
+
176
+ If buggy, patch NeuroMotion and regenerate just the triangular recordings:
177
+
178
+ ```bash
179
+ # Submit as array job (21 combos × ~3 min each)
180
+ qsub experiments/v2/run_regenerate_triangular.pbs
181
+
182
+ # Or run interactively, one combo at a time
183
+ for i in {0..20}; do
184
+ python experiments/v2/scripts/05_fix_triangular.py --combo-idx $i
185
+ done
186
+ ```
187
+
188
+ ### Rebuild metadata CSVs
189
+
190
+ ```bash
191
+ python experiments/v2/scripts/build_metadata.py
192
+ ```
193
+
194
+ Regenerates `metadata/*.csv` from the actual files on disk (useful for validation).
195
+
196
+ ## Data Format
197
+
198
+ Each recording is a `.npz` file following `/BENCHMARK_DATA_FORMAT.md` with:
199
+
200
+ | Key | Shape | Description |
201
+ |-----|-------|-------------|
202
+ | `emg` | `(T, M)` float32 | EMG samples-first |
203
+ | `spike_mu_{i}` | `(n_spikes,)` int64 | GT spike sample indices per MU (empty for inactive) |
204
+ | `angle_profile` | `(T,)` | Joint angle over time (deg) |
205
+ | `effort_profile` | `(T,)` | Effort over time (fraction MVC) |
206
+ | `fs`, `n_channels`, `n_samples`, `muscle`, `subject_seed`, `af`, ... | scalars | Full parameters |
207
+
208
+ ## Conditions Summary
209
+
210
+ All 8 conditions use **constant effort at 50% MVC** with **0.3 Hz** sinusoid/triangle. Duration 10s, fs=2048.
211
+
212
+ | ID | Angle Profile | af (fraction of ±65°) | ±deg | SNR (dB) |
213
+ |----|---------------|----------------------|------|----------|
214
+ | SA05-hi | Sinusoid | 0.5 | ±32.5 | 25 |
215
+ | SA05-lo | Sinusoid | 0.5 | ±32.5 | 20 |
216
+ | SA10-hi | Sinusoid | 1.0 | ±65.0 | 25 |
217
+ | SA10-lo | Sinusoid | 1.0 | ±65.0 | 20 |
218
+ | TA05-hi | Triangular | 0.5 | ±32.5 | 25 |
219
+ | TA05-lo | Triangular | 0.5 | ±32.5 | 20 |
220
+ | TA10-hi | Triangular | 1.0 | ±65.0 | 25 |
221
+ | TA10-lo | Triangular | 1.0 | ±65.0 | 20 |
222
+
223
+ ## Combo Summary
224
+
225
+ 21 combos grouped into 3 pool-size tiers:
226
+
227
+ | Tier | # Combos | Pool range | Typical recording |
228
+ |------|:-:|:-:|---|
229
+ | **Small** | 6 | 26–45 MUs | PL × 3 subjects + FCU_h + ECRL + FDSI |
230
+ | **Medium** | 8 | 47–74 MUs | ECU, FDSI, EDI, ECRB, FCU_u |
231
+ | **Large** | 7 | 77–113 MUs | EDI, ECU, ECRB, FCU_u at threshold 0.90 |
232
+
233
+ See `combos.json` / `metadata/combos_manifest.csv` for the exact list.
234
+
235
+ ## Verification
236
+
237
+ After reproduction, verify the dataset is correct:
238
+
239
+ ```bash
240
+ # Compare against recordings_manifest.csv (336 rows)
241
+ python experiments/v2/scripts/build_metadata.py
242
+ diff <(sort experiments/v2/metadata/recordings_manifest.csv) <(sort <your-regenerated>/recordings_manifest.csv)
243
+ ```
244
+
245
+ MUAP cache SHA256 hashes (first 16 hex chars) are in `metadata/muap_caches_manifest.csv` for integrity checking of the Stage 1 outputs.
246
+
247
+ ## Citation
248
+
249
+ ```
250
+ <pending — paper in prep>
251
+ ```
252
+
253
+ ## License
254
+
255
+ Same as MUniverse core (GPL-3.0).