Continuous Stimulus Scan
neureptrace.continuous_stimulus_scan turns the long-stream event-detection idea
into a single reproducible workflow:
- train an event-locked decoder on labeled events from one raw run;
- scan a held-out raw run with the same window and preprocessing;
- export
P(class | time)as NeuRepTrace stream observations; - run
neureptrace.stimulus_detection; and - write event-level precision, recall, F1, latency, and false-alarm summaries.
Use this when the question is:
I have an event-locked decoder for a stimulus class. Does a held-out continuous recording contain intervals that look like that class?
CLI Example
python -m neureptrace.continuous_stimulus_scan \
--train-raw data/ds000117/sub-01/ses-meg/meg/sub-01_ses-meg_task-facerecognition_run-01_meg.fif \
--train-events data/ds000117/sub-01/ses-meg/meg/sub-01_ses-meg_task-facerecognition_run-01_events.tsv \
--scan-raw data/ds000117/sub-01/ses-meg/meg/sub-01_ses-meg_task-facerecognition_run-02_meg.fif \
--scan-events data/ds000117/sub-01/ses-meg/meg/sub-01_ses-meg_task-facerecognition_run-02_events.tsv \
--source-column stim_type \
--positive-pattern "Famous|Unfamiliar" \
--negative-pattern "Scrambled" \
--positive-label face \
--negative-label scrambled \
--target-class face \
--train-window 0.15 0.25 \
--picks meg \
--demean-window \
--slice-duration 6.0 \
--slice-count 10 \
--require-target-event \
--exclude-events-from-threshold-window \
--threshold-window 0.0 0.8 \
--detection-window 0.8 6.0 \
--threshold-method max_run \
--threshold-quantile 0.975 \
--min-consecutive 2 \
--min-duration 0.05 \
--merge-gap 0.05 \
--refractory 0.30 \
--match-tolerance 0.35 \
--out-dir results/ds000117_continuous_scan
The installed command neureptrace-continuous-stimulus-scan exposes the same
arguments.
Outputs
The output directory contains:
| File | Meaning |
|---|---|
stream_observations.csv |
Long-stream probability observations with prob_class_* columns. |
stimulus_annotations.csv |
Held-out event annotations converted to stream-relative times. |
stimulus_thresholds.csv |
Class-specific detector thresholds. |
stimulus_events.csv |
One row per detected event. |
stimulus_summary.csv |
Precision, recall, F1, false alarms, and latency summaries. |
heldout_event_metrics.csv |
Event-locked held-out accuracy/log-loss before continuous scanning. |
training_class_counts.csv |
Training event counts per class. |
API Reference
neureptrace.continuous_stimulus_scan
ContinuousStimulusScanResult
dataclass
Tables emitted by the continuous stimulus-scan workflow.
Source code in src/neureptrace/continuous_stimulus_scan.py
38 39 40 41 42 43 44 45 46 47 | |
ScanSegment
dataclass
One continuous interval to scan as an independent probability stream.
Source code in src/neureptrace/continuous_stimulus_scan.py
28 29 30 31 32 33 34 35 | |
build_scan_segments(*, scan_raw, scan_start, scan_stop, slice_duration=None, slice_starts=None, slice_count=None, slice_seed=13, scan_events=None, onset_column='onset', label_column='stimulus_class', target_classes=None, threshold_window=None, detection_window=None, require_target_event=False, exclude_events_from_threshold_window=False, stream_id=None)
Build full-run, explicit-slice, or random-slice scan segments.
Source code in src/neureptrace/continuous_stimulus_scan.py
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 | |
label_event_table(events, *, onset_column='onset', label_column='stimulus_class', source_column=None, positive_pattern=None, negative_pattern=None, positive_label='positive', negative_label='negative', case_sensitive=False)
Return events with numeric onsets and string class labels.
If source_column and positive_pattern are supplied, labels are built
from regex matches. Otherwise label_column is used directly.
Source code in src/neureptrace/continuous_stimulus_scan.py
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 | |
run_continuous_stimulus_scan(*, train_raw, train_events, scan_raw, scan_events=None, out_dir, onset_column='onset', label_column='stimulus_class', train_window=(0.1, 0.2), picks='data', baseline=None, decoder='logistic', emission_mode='calibrated', max_iter=1000, demean_window=False, scan_step=0.025, scan_start=None, scan_stop=None, slice_duration=None, slice_starts=None, slice_count=None, slice_seed=13, stream_id=None, subject=None, target_classes=None, threshold_window=(0.0, 0.8), threshold_quantile=0.95, threshold_method='max_run', score_mode='class_probability', detection_window=None, min_consecutive=1, min_duration=None, merge_gap=None, refractory=None, conflict_resolution='none', match_tolerance=0.1, annotation_latency=None, require_target_event=False, exclude_events_from_threshold_window=False)
Train an event-locked decoder, scan raw data, and detect stimulus events.
Source code in src/neureptrace/continuous_stimulus_scan.py
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 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |