File size: 10,425 Bytes
fa287f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
---
license: gpl-3.0
task_categories:
  - other
language:
  - en
tags:
  - electromyography
  - emg
  - motor-unit-decomposition
  - blind-source-separation
  - dynamic-contraction
  - synthetic
  - neuromuscular
size_categories:
  - n<1K
pretty_name: MUniverse Dynamic EMG Benchmark v2
---

# MUniverse Dynamic EMG Benchmark v2

**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.

## Files

| File | Size | Purpose |
|---|---|---|
| `recordings.tar.gz` | 4.7 GB | The 336 `.npz` recordings (`benchmark_v2/{ch070,ch320}/`) |
| `reproducibility_bundle.zip` | 36 KB | Scripts, manifests, NeuroMotion patch, PBS templates |
| `benchmark_spec.json` | 7 KB | Declarative spec: subjects, muscles, conditions, combos |
| `README.md` | 8 KB | This page (also inside the bundle, as the canonical reproduction guide) |

SHA256:
- `recordings.tar.gz`: `715458efd70ca8932e1e45a642698fa11a4446e0352dbe1840e0a7e251544f56`
- `reproducibility_bundle.zip`: `f4e034726a5c2afd60f408d3e32d63be074a586235316c38926feafd3d3e0988`

## Quick load

```python
import numpy as np
d = np.load("benchmark_v2/ch320/SA10-hi_ECU_sub03_N055.npz", allow_pickle=True)
emg            = d["emg"]              # (T, 320) float32
spike_mu_0     = d["spike_mu_0"]       # (n_spikes,) int64 — ground-truth indices
angle_profile  = d["angle_profile"]    # (T,) joint angle in degrees
effort_profile = d["effort_profile"]   # (T,) effort, fraction MVC
fs             = int(d["fs"])          # 2048
```

See `benchmark_spec.json` for the full parameter grid (8 conditions × 21 combos × 2 channel configs = 336).

## Reproduction

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.


---

## Original reproducibility README

_Below is the canonical reproduction guide as it appears inside `reproducibility_bundle.zip`._


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

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:

1. Generate 40 MUAP libraries using NeuroMotion+BioMime (5 subjects × 8 muscles at Flex-Ext DOF).
2. Analyze pairwise MUAP similarity, filter each library to a "crosstalk-clean" subset.
3. Use NeuroMotion to synthesize 336 EMG recordings from those clean subsets, each exposed to different rotation profiles and noise levels.

## Contents

```
experiments/v2/
├── README.md                              # This file
├── benchmark_spec.json                    # Declarative specification (reviewer-readable)
├── combos.json                            # The 21 subject-muscle-threshold combos used
├── scripts/                               # Scripts used, in execution order
│   ├── 01_generate_muap_caches.py         # Stage 1: Run BioMime to make 40 caches (GPU)
│   ├── 02_analyze_crosstalk.py            # Stage 2: Pairwise similarity analysis
│   ├── 03_create_clean_caches.py          # Stage 3: Filter each cache to a clean subset
│   ├── 04_generate_recordings.py          # Stage 4: Run NeuroMotion on clean caches
│   ├── 05_fix_triangular.py               # Stage 5: Bug fix, regenerate triangular only
│   ├── build_metadata.py                  # (meta) Generates the manifest CSVs below
│   └── patches/
│       └── neuromotion_triangular_symmetric.patch    # NeuroMotion fix
└── metadata/
    ├── muap_caches_manifest.csv           # 40 caches with shapes, fiber density, sha256
    ├── combos_manifest.csv                # 21 clean combo pools
    ├── conditions_manifest.csv            # 8 condition definitions
    └── recordings_manifest.csv            # 336 recordings with full parameters
```

## Prerequisites

1. **MUniverse** — tested against `dynamic_zi_resampling` branch (see `git log`). Clone the repo and install:
   ```bash
   git clone https://github.com/dfarinagroup/muniverse muniverse-live
   cd muniverse-live
   git checkout dynamic_zi_resampling
   pip install -e .
   ```

2. **NeuroMotion Singularity/Docker image**`pranavm19/muniverse-test:neuromotion`:
   ```bash
   cd src/environment
   singularity pull muniverse-test_neuromotion.sif docker://pranavm19/muniverse-test:neuromotion
   ```

3. **NeuroMotion triangular patch** — apply to `src/muniverse/data_generation/_run_neuromotion.py`:
   ```bash
   cd muniverse-live
   git apply experiments/v2/scripts/patches/neuromotion_triangular_symmetric.patch
   ```
   (Or just copy the `Triangular` branch from that file into your `_run_neuromotion.py` line ~434.)

4. **Hardware**:
   - Stage 1 (MUAP generation): **GPU** — each of 40 caches takes ~2-3 min on A40 / RTX6000.
   - Stages 2–5: CPU only.

5. **Disk**:
   - MUAP caches: ~95 GB permanent
   - Clean caches: ~8 GB
   - Recordings: ~5 GB
   - Raw outputs + configs: ~10 GB ephemeral (safe to delete after gen)

## Reproduction Steps

### Stage 1: Generate 40 MUAP caches (GPU, ~1.5 hours)

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.

```bash
# Generate all 40 (5 subjects × 8 muscles at Flex-Ext DOF)
python experiments/v2/scripts/01_generate_muap_caches.py
```

The script edits these hardcoded paths — adjust before running:
- `CACHE_ROOT`: where to write the caches
- `RAW_ROOT`: scratch dir for container outputs (ephemeral is fine)
- `SIF_PATH`: path to the NeuroMotion Singularity image

Output: `<CACHE_ROOT>/cache_sub-simXX/subject_X_{MUSCLE}_Flexion-Extension_muaps.npy` + `_metadata.json` + `_mn_properties.csv`.

### Stage 2: Crosstalk analysis (CPU, ~5 min)

```bash
python experiments/v2/scripts/02_analyze_crosstalk.py
```

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:
`experiments/results/crosstalk_v3/exp_crosstalk_clean_subsets.json`

### Stage 3: Create 21 clean caches (CPU, ~1 min)

```bash
python experiments/v2/scripts/03_create_clean_caches.py
```

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.

### Stage 4: Generate 336 recordings (CPU, ~55 min)

```bash
python experiments/v2/scripts/04_generate_recordings.py \
    --config experiments/clean_caches_v2/combos.json
```

For each combo, runs the container 8 times (one per condition), post-processes into 2 channel configs (ch070 + ch320), and writes:
`<BENCHMARK_ROOT>/ch{070,320}/{cond}_{muscle}_sub{N}_N{K}.npz`

### Stage 5 (only if you hit the bug): Fix triangular recordings

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.

If buggy, patch NeuroMotion and regenerate just the triangular recordings:

```bash
# Submit as array job (21 combos × ~3 min each)
qsub experiments/v2/run_regenerate_triangular.pbs

# Or run interactively, one combo at a time
for i in {0..20}; do
    python experiments/v2/scripts/05_fix_triangular.py --combo-idx $i
done
```

### Rebuild metadata CSVs

```bash
python experiments/v2/scripts/build_metadata.py
```

Regenerates `metadata/*.csv` from the actual files on disk (useful for validation).

## Data Format

Each recording is a `.npz` file following `/BENCHMARK_DATA_FORMAT.md` with:

| Key | Shape | Description |
|-----|-------|-------------|
| `emg` | `(T, M)` float32 | EMG samples-first |
| `spike_mu_{i}` | `(n_spikes,)` int64 | GT spike sample indices per MU (empty for inactive) |
| `angle_profile` | `(T,)` | Joint angle over time (deg) |
| `effort_profile` | `(T,)` | Effort over time (fraction MVC) |
| `fs`, `n_channels`, `n_samples`, `muscle`, `subject_seed`, `af`, ... | scalars | Full parameters |

## Conditions Summary

All 8 conditions use **constant effort at 50% MVC** with **0.3 Hz** sinusoid/triangle. Duration 10s, fs=2048.

| ID | Angle Profile | af (fraction of ±65°) | ±deg | SNR (dB) |
|----|---------------|----------------------|------|----------|
| SA05-hi | Sinusoid   | 0.5 | ±32.5 | 25 |
| SA05-lo | Sinusoid   | 0.5 | ±32.5 | 20 |
| SA10-hi | Sinusoid   | 1.0 | ±65.0 | 25 |
| SA10-lo | Sinusoid   | 1.0 | ±65.0 | 20 |
| TA05-hi | Triangular | 0.5 | ±32.5 | 25 |
| TA05-lo | Triangular | 0.5 | ±32.5 | 20 |
| TA10-hi | Triangular | 1.0 | ±65.0 | 25 |
| TA10-lo | Triangular | 1.0 | ±65.0 | 20 |

## Combo Summary

21 combos grouped into 3 pool-size tiers:

| Tier | # Combos | Pool range | Typical recording |
|------|:-:|:-:|---|
| **Small**  | 6 | 26–45 MUs | PL × 3 subjects + FCU_h + ECRL + FDSI |
| **Medium** | 8 | 47–74 MUs | ECU, FDSI, EDI, ECRB, FCU_u |
| **Large**  | 7 | 77–113 MUs | EDI, ECU, ECRB, FCU_u at threshold 0.90 |

See `combos.json` / `metadata/combos_manifest.csv` for the exact list.

## Verification

After reproduction, verify the dataset is correct:

```bash
# Compare against recordings_manifest.csv (336 rows)
python experiments/v2/scripts/build_metadata.py
diff <(sort experiments/v2/metadata/recordings_manifest.csv) <(sort <your-regenerated>/recordings_manifest.csv)
```

MUAP cache SHA256 hashes (first 16 hex chars) are in `metadata/muap_caches_manifest.csv` for integrity checking of the Stage 1 outputs.

## Citation

```
<pendingpaper in prep>
```

## License

Same as MUniverse core (GPL-3.0).