med64 0.0.2

Headless MED64 electrophysiology toolkit: .modat I/O, spike/burst analysis, assays, spike-rate maps, and CSV/HTML/SVG/HDF5 export
Documentation
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
//! Propagation delay maps and conduction velocity (PDM).

use serde::{Deserialize, Serialize};

use crate::analysis::{run_analysis, AnalysisOptions, SpikeTrain};
use crate::error::{Med64Error, Result};
use crate::layout::WellPlate;
use crate::toolkit::propagation_oversample::{
    upsample_delay_grid, OversampleGrid, OversampleMode, ShihyouBins,
};
use std::path::{Path, PathBuf};

#[derive(Debug, Clone)]
pub struct PropagationOptions {
    pub analysis: AnalysisOptions,
    pub electrode_pitch_um: f64,
    pub grid_cols: usize,
    pub grid_rows: usize,
    /// Reference channel for delay=0; None = earliest first-spike channel.
    pub reference_channel: Option<usize>,
    /// Average-bin layout after first-spike map (`AverageBin` 16/32/PRESTO).
    pub average_bin: AverageBinKind,
    /// PRESTO well plate when `average_bin == Presto` (`AverageBinPresto.wellsuu`).
    pub well_plate: WellPlate,
    /// Number of time bins for conduction series (0 / 1 = single map).
    pub conduction_bins: usize,
    /// Wire `combooversample` spatial upsample of the delay field.
    pub oversample: OversampleMode,
    /// Wire `comboshihyou` color quantization (5/10/20).
    pub shihyou: ShihyouBins,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AverageBinKind {
    #[default]
    None,
    Bin16,
    Bin32,
    Presto,
}

impl AverageBinKind {
    pub fn parse(s: &str) -> Option<Self> {
        match s.trim().to_ascii_lowercase().as_str() {
            "none" | "off" => Some(Self::None),
            "16" | "bin16" => Some(Self::Bin16),
            "32" | "bin32" => Some(Self::Bin32),
            "presto" | "24" => Some(Self::Presto),
            _ => None,
        }
    }
}

impl Default for PropagationOptions {
    fn default() -> Self {
        Self {
            analysis: AnalysisOptions { max_blocks: Some(10), ..AnalysisOptions::default() },
            electrode_pitch_um: 150.0,
            grid_cols: 8,
            grid_rows: 8,
            reference_channel: None,
            average_bin: AverageBinKind::None,
            well_plate: WellPlate::Wells24,
            conduction_bins: 1,
            oversample: OversampleMode::None,
            shihyou: ShihyouBins::Off,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropagationCell {
    pub channel: usize,
    pub row: usize,
    pub col: usize,
    pub first_spike_ms: Option<f64>,
    pub delay_ms: Option<f64>,
    pub velocity_mm_per_s: Option<f64>,
    /// Palette index from `kurai*` (0 = unset).
    pub color_index: u16,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropagationReport {
    pub path: std::path::PathBuf,
    pub reference_channel: usize,
    pub reference_time_ms: f64,
    pub cells: Vec<PropagationCell>,
    /// Optional dense oversampled delay field.
    pub oversample: Option<OversampleGrid>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConductionFrame {
    pub bin_index: usize,
    pub start_ms: f64,
    pub end_ms: f64,
    pub report: PropagationReport,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConductionSeries {
    pub path: PathBuf,
    pub frames: Vec<ConductionFrame>,
}

/// First-spike latency map relative to a reference electrode.
pub fn propagation_delay_map(
    path: impl AsRef<Path>,
    options: &PropagationOptions,
) -> Result<PropagationReport> {
    let path = path.as_ref();
    let report = run_analysis(path, &options.analysis)?;
    Ok(propagation_from_spikes(path, &report.spikes, options))
}

pub fn propagation_from_spikes(
    path: impl AsRef<Path>,
    train: &SpikeTrain,
    options: &PropagationOptions,
) -> PropagationReport {
    let mut first: std::collections::BTreeMap<usize, f64> = std::collections::BTreeMap::new();
    for spike in &train.spikes {
        first
            .entry(spike.channel)
            .and_modify(|t| *t = t.min(spike.within_trace_time_ms))
            .or_insert(spike.within_trace_time_ms);
    }
    let (ref_ch, ref_t) = if let Some(ch) = options.reference_channel {
        (ch, first.get(&ch).copied().unwrap_or(0.0))
    } else {
        first
            .iter()
            .min_by(|a, b| a.1.partial_cmp(b.1).unwrap())
            .map(|(&c, &t)| (c, t))
            .unwrap_or((0, 0.0))
    };
    let (ref_r, ref_c) = grid_pos(ref_ch, options.grid_rows, options.grid_cols);
    let mut cells = Vec::new();
    let n = options.grid_rows * options.grid_cols;
    for ch in 0..n {
        let (row, col) = grid_pos(ch, options.grid_rows, options.grid_cols);
        let first_spike = first.get(&ch).copied();
        let delay = first_spike.map(|t| t - ref_t);
        let velocity = delay.map(|d| {
            if d.abs() < 1e-6 {
                return 0.0;
            }
            let dist_um = (((row as f64 - ref_r as f64).powi(2)
                + (col as f64 - ref_c as f64).powi(2))
            .sqrt())
                * options.electrode_pitch_um;
            (dist_um / 1000.0) / (d / 1000.0) // mm / s
        });
        cells.push(PropagationCell {
            channel: ch,
            row,
            col,
            first_spike_ms: first_spike,
            delay_ms: delay,
            velocity_mm_per_s: velocity,
            color_index: 0,
        });
    }
    let mut report = PropagationReport {
        path: path.as_ref().to_path_buf(),
        reference_channel: ref_ch,
        reference_time_ms: ref_t,
        cells,
        oversample: None,
    };
    report.cells = apply_average_bins(&report.cells, options.average_bin, options);
    apply_color_and_oversample(&mut report, options);
    report
}

fn apply_color_and_oversample(report: &mut PropagationReport, options: &PropagationOptions) {
    let maxamp = report.cells.iter().filter_map(|c| c.delay_ms).fold(0.0_f64, f64::max);
    for c in &mut report.cells {
        if let Some(d) = c.delay_ms {
            c.color_index =
                crate::toolkit::propagation_oversample::color_bin(d, maxamp, options.shihyou);
        }
    }
    if matches!(options.oversample, OversampleMode::None) {
        return;
    }
    let rows = report.cells.iter().map(|c| c.row).max().unwrap_or(0) + 1;
    let cols = report.cells.iter().map(|c| c.col).max().unwrap_or(0) + 1;
    let mut grid = vec![f64::NAN; rows * cols];
    for c in &report.cells {
        if let Some(d) = c.delay_ms {
            if c.row < rows && c.col < cols {
                grid[c.row * cols + c.col] = d;
            }
        }
    }
    report.oversample =
        Some(upsample_delay_grid(&grid, rows, cols, options.oversample, options.shihyou));
}

/// Split spikes into `N` time bins and compute one delay map per bin.
pub fn conduction_series_from_spikes(
    path: impl AsRef<Path>,
    train: &SpikeTrain,
    options: &PropagationOptions,
) -> ConductionSeries {
    let path = path.as_ref();
    let n_bins = options.conduction_bins.max(1);
    if n_bins <= 1 || train.spikes.is_empty() {
        let report = propagation_from_spikes(path, train, options);
        return ConductionSeries {
            path: path.to_path_buf(),
            frames: vec![ConductionFrame {
                bin_index: 0,
                start_ms: 0.0,
                end_ms: train.spikes.iter().map(|s| s.within_trace_time_ms).fold(0.0, f64::max),
                report,
            }],
        };
    }
    let t_min = train.spikes.iter().map(|s| s.within_trace_time_ms).fold(f64::INFINITY, f64::min);
    let t_max =
        train.spikes.iter().map(|s| s.within_trace_time_ms).fold(f64::NEG_INFINITY, f64::max);
    let span = (t_max - t_min).max(1e-9);
    let mut frames = Vec::with_capacity(n_bins);
    for b in 0..n_bins {
        let start = t_min + span * b as f64 / n_bins as f64;
        let end = t_min + span * (b + 1) as f64 / n_bins as f64;
        let mut subset = SpikeTrain::default();
        for spike in &train.spikes {
            let t = spike.within_trace_time_ms;
            if t >= start && (t < end || (b + 1 == n_bins && t <= end)) {
                subset.spikes.push(spike.clone());
            }
        }
        let report = propagation_from_spikes(path, &subset, options);
        frames.push(ConductionFrame { bin_index: b, start_ms: start, end_ms: end, report });
    }
    ConductionSeries { path: path.to_path_buf(), frames }
}

pub fn conduction_series(
    path: impl AsRef<Path>,
    options: &PropagationOptions,
) -> Result<ConductionSeries> {
    let path = path.as_ref();
    let report = run_analysis(path, &options.analysis)?;
    Ok(conduction_series_from_spikes(path, &report.spikes, options))
}

/// Stage 1: spike detection only (PDM Detector).
pub fn pdm_detect(path: impl AsRef<Path>, analysis: &AnalysisOptions) -> Result<SpikeTrain> {
    Ok(run_analysis(path, analysis)?.spikes)
}

pub fn write_propagation_csv(report: &PropagationReport, path: impl AsRef<Path>) -> Result<()> {
    let path = path.as_ref();
    let mut w =
        String::from("channel,row,col,first_spike_ms,delay_ms,velocity_mm_per_s,color_index\n");
    for c in &report.cells {
        w.push_str(&format!(
            "{},{},{},{},{},{},{}\n",
            c.channel + 1,
            c.row,
            c.col,
            opt_f64(c.first_spike_ms),
            opt_f64(c.delay_ms),
            opt_f64(c.velocity_mm_per_s),
            c.color_index
        ));
    }
    std::fs::write(path, w)
        .map_err(|source| Med64Error::WriteIo { path: path.to_path_buf(), source })?;
    if let Some(grid) = &report.oversample {
        let op = path.with_file_name(
            path.file_stem()
                .and_then(|s| s.to_str())
                .map(|s| format!("{s}_oversample.csv"))
                .unwrap_or_else(|| "propagation_oversample.csv".into()),
        );
        write_oversample_csv(grid, &op)?;
    }
    Ok(())
}

pub fn write_oversample_csv(grid: &OversampleGrid, path: impl AsRef<Path>) -> Result<()> {
    let path = path.as_ref();
    let mut w = String::from("row,col,delay_ms,color_index\n");
    for r in 0..grid.rows {
        for c in 0..grid.cols {
            let i = r * grid.cols + c;
            let d = grid.delays_ms[i];
            w.push_str(&format!(
                "{},{},{},{}\n",
                r,
                c,
                if d.is_finite() { format!("{d:.6}") } else { String::new() },
                grid.color_index[i]
            ));
        }
    }
    std::fs::write(path, w)
        .map_err(|source| Med64Error::WriteIo { path: path.to_path_buf(), source })
}

/// Delay heatmap + reference info + mean velocity.
pub fn write_propagation_html(report: &PropagationReport, path: impl AsRef<Path>) -> Result<()> {
    let path = path.as_ref();
    let cols = report.cells.iter().map(|c| c.col).max().map(|c| c + 1).unwrap_or(8);
    let max_d = report.cells.iter().filter_map(|c| c.delay_ms).fold(1e-6_f64, f64::max);
    let mean_vel = {
        let vs: Vec<f64> = report
            .cells
            .iter()
            .filter_map(|c| c.velocity_mm_per_s)
            .filter(|v| v.is_finite())
            .collect();
        if vs.is_empty() {
            0.0
        } else {
            vs.iter().sum::<f64>() / vs.len() as f64
        }
    };
    let cells_json = serde_json::to_string(
        &report
            .cells
            .iter()
            .map(|c| {
                serde_json::json!({
                    "ch": c.channel + 1,
                    "row": c.row,
                    "col": c.col,
                    "delay": c.delay_ms,
                    "vel": c.velocity_mm_per_s,
                    "t": c.delay_ms.map(|d| (d / max_d).clamp(0.0, 1.0)).unwrap_or(0.0),
                })
            })
            .collect::<Vec<_>>(),
    )
    .unwrap_or_else(|_| "[]".into());
    let html = format!(
        r#"<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>Propagation delay</title>
<style>
body{{font-family:system-ui;margin:1.25rem;background:#fafafa}}
.grid{{display:grid;gap:3px;max-width:480px}}
.cell{{aspect-ratio:1;border-radius:3px;cursor:pointer}}
#detail{{margin-top:1rem;padding:.75rem;background:#fff;border:1px solid #ddd;border-radius:6px}}
</style></head><body>
<h1>Propagation delay map</h1>
<p>{src} · ref ch{ref_ch} @ {ref_t:.3} ms · mean velocity {vel:.2} mm/s</p>
<div class="grid" id="g" style="grid-template-columns:repeat({cols},1fr)"></div>
<div id="detail">Click a cell for details</div>
<script>
const cells = {cells};
const g = document.getElementById('g');
const detail = document.getElementById('detail');
cells.forEach(c => {{
  const d = document.createElement('div');
  d.className = 'cell';
  const t = c.t;
  d.style.background = `rgb(${{Math.round(255*t)}},80,${{Math.round(255*(1-t))}})`;
  d.title = 'Ch' + c.ch;
  d.onclick = () => {{
    detail.textContent = `Ch ${{c.ch}} · delay ${{c.delay != null ? c.delay.toFixed(3)+' ms' : 'n/a'}} · velocity ${{c.vel != null ? c.vel.toFixed(2)+' mm/s' : 'n/a'}}`;
  }};
  g.appendChild(d);
}});
</script></body></html>"#,
        src = report.path.display(),
        ref_ch = report.reference_channel + 1,
        ref_t = report.reference_time_ms,
        vel = mean_vel,
        cols = cols,
        cells = cells_json
    );
    std::fs::write(path, html)
        .map_err(|source| Med64Error::WriteIo { path: path.to_path_buf(), source })
}

/// Playable conduction frames (JS slider).
pub fn write_conduction_html(series: &ConductionSeries, path: impl AsRef<Path>) -> Result<()> {
    let path = path.as_ref();
    let frames_json = serde_json::to_string(
        &series
            .frames
            .iter()
            .map(|f| {
                let max_d =
                    f.report.cells.iter().filter_map(|c| c.delay_ms).fold(1e-6_f64, f64::max);
                serde_json::json!({
                    "bin": f.bin_index,
                    "start": f.start_ms,
                    "end": f.end_ms,
                    "ref_ch": f.report.reference_channel + 1,
                    "ref_t": f.report.reference_time_ms,
                    "cells": f.report.cells.iter().map(|c| serde_json::json!({
                        "ch": c.channel + 1,
                        "row": c.row,
                        "col": c.col,
                        "delay": c.delay_ms,
                        "t": c.delay_ms.map(|d| (d / max_d).clamp(0.0, 1.0)).unwrap_or(0.0),
                    })).collect::<Vec<_>>(),
                })
            })
            .collect::<Vec<_>>(),
    )
    .unwrap_or_else(|_| "[]".into());
    let cols = series
        .frames
        .first()
        .and_then(|f| f.report.cells.iter().map(|c| c.col).max())
        .map(|c| c + 1)
        .unwrap_or(8);
    let html = format!(
        r#"<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>Conduction series</title>
<style>
body{{font-family:system-ui;margin:1.25rem}}
.grid{{display:grid;gap:3px;max-width:480px}}
.cell{{aspect-ratio:1;border-radius:3px}}
input[type=range]{{width:min(480px,100%)}}
</style></head><body>
<h1>Conduction series</h1>
<p>{src} · {n} frames</p>
<label>Frame <span id="lab">0</span></label><br>
<input type="range" id="slider" min="0" max="{max}" value="0">
<p id="meta"></p>
<div class="grid" id="g" style="grid-template-columns:repeat({cols},1fr)"></div>
<script>
const frames = {frames};
const g = document.getElementById('g');
const slider = document.getElementById('slider');
const lab = document.getElementById('lab');
const meta = document.getElementById('meta');
function render(i) {{
  const f = frames[i];
  lab.textContent = i;
  meta.textContent = `bin ${{f.bin}} · ${{f.start.toFixed(1)}}–${{f.end.toFixed(1)}} ms · ref ch${{f.ref_ch}} @ ${{f.ref_t.toFixed(3)}} ms`;
  g.innerHTML = '';
  f.cells.forEach(c => {{
    const d = document.createElement('div');
    d.className = 'cell';
    d.style.background = `rgb(${{Math.round(255*c.t)}},80,${{Math.round(255*(1-c.t))}})`;
    d.title = 'Ch' + c.ch + (c.delay != null ? (' ' + c.delay.toFixed(2) + ' ms') : '');
    g.appendChild(d);
  }});
}}
slider.oninput = () => render(+slider.value);
render(0);
</script></body></html>"#,
        src = series.path.display(),
        n = series.frames.len(),
        max = series.frames.len().saturating_sub(1),
        cols = cols,
        frames = frames_json
    );
    std::fs::write(path, html)
        .map_err(|source| Med64Error::WriteIo { path: path.to_path_buf(), source })
}

fn apply_average_bins(
    cells: &[PropagationCell],
    kind: AverageBinKind,
    options: &PropagationOptions,
) -> Vec<PropagationCell> {
    match kind {
        AverageBinKind::None => cells.to_vec(),
        AverageBinKind::Bin16 => average_fixed_groups(cells, 4, options),
        AverageBinKind::Bin32 => average_fixed_groups(cells, 2, options),
        AverageBinKind::Presto => average_presto_wells(cells, options),
    }
}

fn mean_opt(vals: &[f64]) -> Option<f64> {
    if vals.is_empty() {
        None
    } else {
        Some(vals.iter().sum::<f64>() / vals.len() as f64)
    }
}

fn velocity_from_delay(options: &PropagationOptions, delay: Option<f64>) -> Option<f64> {
    delay.map(|d| {
        if d.abs() < 1e-6 {
            0.0
        } else {
            (options.electrode_pitch_um / 1000.0) / (d / 1000.0)
        }
    })
}

fn average_fixed_groups(
    cells: &[PropagationCell],
    group: usize,
    options: &PropagationOptions,
) -> Vec<PropagationCell> {
    let mut out = Vec::new();
    let n = options.grid_rows * options.grid_cols;
    let bins = n.div_ceil(group);
    for b in 0..bins {
        let slice = &cells[(b * group).min(cells.len())..((b + 1) * group).min(cells.len())];
        let delays: Vec<f64> = slice.iter().filter_map(|c| c.delay_ms).collect();
        let firsts: Vec<f64> = slice.iter().filter_map(|c| c.first_spike_ms).collect();
        let delay = mean_opt(&delays);
        out.push(PropagationCell {
            channel: b,
            row: b / options.grid_cols.max(1),
            col: b % options.grid_cols.max(1),
            first_spike_ms: mean_opt(&firsts),
            delay_ms: delay,
            velocity_mm_per_s: velocity_from_delay(options, delay),
            color_index: 0,
        });
    }
    out
}

/// `AverageBinPresto`: mean first-spike delay per well (`wellsuu` electrodes/well).
fn average_presto_wells(
    cells: &[PropagationCell],
    options: &PropagationOptions,
) -> Vec<PropagationCell> {
    let plate = options.well_plate;
    let n_wells = plate.well_count();
    let cols = plate.plate_cols().max(1);
    let mut buckets: Vec<(Vec<f64>, Vec<f64>)> =
        (0..n_wells).map(|_| (Vec::new(), Vec::new())).collect();
    for c in cells {
        let w = plate.well_of_channel(c.channel).min(n_wells.saturating_sub(1));
        if let Some(d) = c.delay_ms {
            buckets[w].0.push(d);
        }
        if let Some(t) = c.first_spike_ms {
            buckets[w].1.push(t);
        }
    }
    buckets
        .into_iter()
        .enumerate()
        .map(|(w, (delays, firsts))| {
            let delay = mean_opt(&delays);
            PropagationCell {
                channel: w,
                row: w / cols,
                col: w % cols,
                first_spike_ms: mean_opt(&firsts),
                delay_ms: delay,
                velocity_mm_per_s: velocity_from_delay(options, delay),
                color_index: 0,
            }
        })
        .collect()
}

fn grid_pos(channel: usize, rows: usize, cols: usize) -> (usize, usize) {
    let idx = channel % (rows * cols);
    (idx / cols, idx % cols)
}

fn opt_f64(v: Option<f64>) -> String {
    v.map(|x| format!("{x:.6}")).unwrap_or_default()
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::analysis::spike::{Spike, SpikeTrain};

    #[test]
    fn delay_increases_with_time() {
        let mut train = SpikeTrain::default();
        train.push(Spike { channel: 0, within_trace_time_ms: 10.0, ..Default::default() });
        train.push(Spike { channel: 1, within_trace_time_ms: 20.0, ..Default::default() });
        let report = propagation_from_spikes(
            "mem.modat",
            &train,
            &PropagationOptions { reference_channel: Some(0), ..Default::default() },
        );
        let c1 = report.cells.iter().find(|c| c.channel == 1).unwrap();
        assert!((c1.delay_ms.unwrap() - 10.0).abs() < 1e-9);
    }

    #[test]
    fn conduction_bins_split() {
        let mut train = SpikeTrain::default();
        for (ch, t) in [(0, 10.0), (1, 20.0), (0, 100.0), (1, 110.0)] {
            train.push(Spike { channel: ch, within_trace_time_ms: t, ..Default::default() });
        }
        let series = conduction_series_from_spikes(
            "mem.modat",
            &train,
            &PropagationOptions {
                reference_channel: Some(0),
                conduction_bins: 2,
                ..Default::default()
            },
        );
        assert_eq!(series.frames.len(), 2);
    }
}