0
# Data Input/Output
1
2
Complete support for neuroimaging file formats with unified interfaces for reading, writing, and converting between formats. MNE-Python supports over 20 different file formats commonly used in MEG, EEG, and neuroimaging research.
3
4
## Capabilities
5
6
### Raw Data Reading
7
8
Read continuous neuroimaging data from various file formats with consistent interfaces and automatic format detection.
9
10
```python { .api }
11
def read_raw(fname: str, preload: bool = False, verbose: Optional[Union[bool, str, int]] = None, **kwargs) -> Raw:
12
"""
13
Read raw data from file, auto-detecting the format.
14
15
Parameters:
16
- fname: Path to the raw data file
17
- preload: Load data into memory immediately
18
- verbose: Verbosity level
19
- **kwargs: Additional format-specific parameters
20
21
Returns:
22
Raw object containing continuous data
23
"""
24
25
def read_raw_fif(fname: str, allow_maxshield: bool = False, preload: bool = False,
26
on_split_missing: str = 'raise', verbose: Optional[Union[bool, str, int]] = None) -> Raw:
27
"""
28
Read FIF format raw data.
29
30
Parameters:
31
- fname: Path to the .fif file
32
- allow_maxshield: Allow reading MaxShield processed data
33
- preload: Load data into memory immediately
34
- on_split_missing: How to handle missing split files
35
- verbose: Verbosity level
36
37
Returns:
38
Raw object containing continuous data
39
"""
40
41
def read_raw_edf(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
42
stim_channel: str = 'auto', exclude: List[str] = (), preload: bool = False) -> Raw:
43
"""
44
Read European Data Format (EDF/EDF+) files.
45
46
Parameters:
47
- fname: Path to the .edf file
48
- eog: Names of EOG channels
49
- misc: Names of miscellaneous channels
50
- stim_channel: Name of stimulus channel
51
- exclude: List of channels to exclude
52
- preload: Load data into memory immediately
53
54
Returns:
55
Raw object containing continuous data
56
"""
57
58
def read_raw_brainvision(vhdr_fname: str, eog: Union[List[str], str] = None,
59
misc: Union[List[str], str] = None, scale: float = 1.0,
60
preload: bool = False) -> Raw:
61
"""
62
Read BrainVision format files (.vhdr, .vmrk, .eeg).
63
64
Parameters:
65
- vhdr_fname: Path to the .vhdr file
66
- eog: Names of EOG channels
67
- misc: Names of miscellaneous channels
68
- scale: Scaling factor for data
69
- preload: Load data into memory immediately
70
71
Returns:
72
Raw object containing continuous data
73
"""
74
75
def read_raw_eeglab(input_fname: str, eog: Union[List[str], str] = None,
76
preload: bool = False, uint16_codec: Optional[str] = None) -> Raw:
77
"""
78
Read EEGLAB .set files.
79
80
Parameters:
81
- input_fname: Path to the .set file
82
- eog: Names of EOG channels
83
- preload: Load data into memory immediately
84
- uint16_codec: Codec for uint16 data
85
86
Returns:
87
Raw object containing continuous data
88
"""
89
90
def read_raw_ctf(directory: str, system_clock: str = 'truncate', preload: bool = False,
91
clean_names: bool = False) -> Raw:
92
"""
93
Read CTF MEG data from directory containing .ds dataset.
94
95
Parameters:
96
- directory: Path to .ds directory
97
- system_clock: How to handle system clock issues
98
- preload: Load data into memory immediately
99
- clean_names: Clean channel names
100
101
Returns:
102
Raw object containing continuous data
103
"""
104
105
def read_raw_kit(sqd_fname: str, mrk: Optional[str] = None, elp: Optional[str] = None,
106
hsp: Optional[str] = None, stim: Union[List[int], int] = None,
107
slope: str = '-', stimthresh: float = 1.0, preload: bool = False) -> Raw:
108
"""
109
Read KIT/Yokogawa MEG data.
110
111
Parameters:
112
- sqd_fname: Path to SQD file
113
- mrk: Marker file path
114
- elp: Electrode position file path
115
- hsp: Head shape file path
116
- stim: Stimulus channels
117
- slope: Direction of trigger slope
118
- stimthresh: Threshold for stimulus detection
119
- preload: Load data into memory immediately
120
121
Returns:
122
Raw object containing continuous data
123
"""
124
125
def read_raw_ant(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
126
preload: bool = False) -> Raw:
127
"""
128
Read ANT Neuro format (.cnt) files.
129
130
Parameters:
131
- fname: Path to the .cnt file
132
- eog: Names of EOG channels
133
- misc: Names of miscellaneous channels
134
- preload: Load data into memory immediately
135
136
Returns:
137
Raw object containing continuous data
138
"""
139
140
def read_raw_artemis123(fname: str, preload: bool = False) -> Raw:
141
"""
142
Read ARTEMIS123 format (.bin) files.
143
144
Parameters:
145
- fname: Path to the .bin file
146
- preload: Load data into memory immediately
147
148
Returns:
149
Raw object containing continuous data
150
"""
151
152
def read_raw_bdf(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
153
stim_channel: str = 'auto', exclude: List[str] = (), preload: bool = False) -> Raw:
154
"""
155
Read BDF format (Biosemi variant of EDF) files.
156
157
Parameters:
158
- fname: Path to the .bdf file
159
- eog: Names of EOG channels
160
- misc: Names of miscellaneous channels
161
- stim_channel: Name of stimulus channel
162
- exclude: List of channels to exclude
163
- preload: Load data into memory immediately
164
165
Returns:
166
Raw object containing continuous data
167
"""
168
169
def read_raw_boxy(fname: str, preload: bool = False) -> Raw:
170
"""
171
Read BOXY format (.txt) files.
172
173
Parameters:
174
- fname: Path to the .txt file
175
- preload: Load data into memory immediately
176
177
Returns:
178
Raw object containing continuous data
179
"""
180
181
def read_raw_bti(pdf_fname: str, config_fname: str, head_shape_fname: Optional[str] = None,
182
rotation_x: float = 0.0, translation: Tuple[float, float, float] = (0.0, 0.02, 0.11),
183
convert: bool = True, rename_channels: bool = True, sort_by_ch_name: bool = True,
184
preload: bool = False) -> Raw:
185
"""
186
Read BTI/4D Neuroimaging MEG data.
187
188
Parameters:
189
- pdf_fname: Path to PDF file
190
- config_fname: Path to config file
191
- head_shape_fname: Path to head shape file
192
- rotation_x: Rotation around x-axis
193
- translation: Translation vector
194
- convert: Convert to MNE coordinate system
195
- rename_channels: Rename channels to MNE convention
196
- sort_by_ch_name: Sort channels by name
197
- preload: Load data into memory immediately
198
199
Returns:
200
Raw object containing continuous data
201
"""
202
203
def read_raw_cnt(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
204
ecg: Union[List[str], str] = None, emg: Union[List[str], str] = None,
205
data_format: str = 'auto', date_format: str = 'mm/dd/yy', preload: bool = False) -> Raw:
206
"""
207
Read Neuroscan CNT format files.
208
209
Parameters:
210
- fname: Path to the .cnt file
211
- eog: Names of EOG channels
212
- misc: Names of miscellaneous channels
213
- ecg: Names of ECG channels
214
- emg: Names of EMG channels
215
- data_format: Data format ('auto', 'int16', 'int32')
216
- date_format: Date format in header
217
- preload: Load data into memory immediately
218
219
Returns:
220
Raw object containing continuous data
221
"""
222
223
def read_raw_curry(fname: str, preload: bool = False) -> Raw:
224
"""
225
Read Curry format (.dat/.dap/.rs3/.cdt/.cef) files.
226
227
Parameters:
228
- fname: Path to the Curry file
229
- preload: Load data into memory immediately
230
231
Returns:
232
Raw object containing continuous data
233
"""
234
235
def read_raw_egi(fname: str, events_as_annotations: bool = True, event_id: Optional[Dict] = None,
236
include: Optional[List[str]] = None, exclude: Optional[List[str]] = None,
237
preload: bool = False) -> Raw:
238
"""
239
Read EGI format (.mff) files.
240
241
Parameters:
242
- fname: Path to the .mff directory
243
- events_as_annotations: Store events as annotations
244
- event_id: Event ID mapping
245
- include: Channels to include
246
- exclude: Channels to exclude
247
- preload: Load data into memory immediately
248
249
Returns:
250
Raw object containing continuous data
251
"""
252
253
def read_raw_eximia(fname: str, preload: bool = False) -> Raw:
254
"""
255
Read Eximia format (.nxe) files.
256
257
Parameters:
258
- fname: Path to the .nxe file
259
- preload: Load data into memory immediately
260
261
Returns:
262
Raw object containing continuous data
263
"""
264
265
def read_raw_eyelink(fname: str, create_annotations: List[str] = None, apply_offsets: bool = False,
266
find_overlaps: bool = False, overlap_threshold: float = 0.05,
267
preload: bool = False) -> Raw:
268
"""
269
Read EyeLink format (.asc) files.
270
271
Parameters:
272
- fname: Path to the .asc file
273
- create_annotations: Events to create annotations from
274
- apply_offsets: Apply time offsets
275
- find_overlaps: Find overlapping fixations and saccades
276
- overlap_threshold: Overlap threshold in seconds
277
- preload: Load data into memory immediately
278
279
Returns:
280
Raw object containing continuous data
281
"""
282
283
def read_raw_fieldtrip(fname: str, info: Optional[Info] = None, data_name: str = 'data',
284
preload: bool = False) -> Raw:
285
"""
286
Read FieldTrip format (.mat) files.
287
288
Parameters:
289
- fname: Path to the .mat file
290
- info: Measurement info object
291
- data_name: Name of data field in .mat file
292
- preload: Load data into memory immediately
293
294
Returns:
295
Raw object containing continuous data
296
"""
297
298
def read_raw_fil(fname: str, preload: bool = False) -> Raw:
299
"""
300
Read UCL FIL OPM format (.bin) files.
301
302
Parameters:
303
- fname: Path to the .bin file
304
- preload: Load data into memory immediately
305
306
Returns:
307
Raw object containing continuous data
308
"""
309
310
def read_raw_gdf(fname: str, eog: Union[List[str], str] = None, misc: Union[List[str], str] = None,
311
stim_channel: str = 'auto', exclude: List[str] = (), preload: bool = False) -> Raw:
312
"""
313
Read GDF (General Data Format) files.
314
315
Parameters:
316
- fname: Path to the .gdf file
317
- eog: Names of EOG channels
318
- misc: Names of miscellaneous channels
319
- stim_channel: Name of stimulus channel
320
- exclude: List of channels to exclude
321
- preload: Load data into memory immediately
322
323
Returns:
324
Raw object containing continuous data
325
"""
326
327
def read_raw_hitachi(fname: str, subject_info: Optional[Dict] = None, preload: bool = False) -> Raw:
328
"""
329
Read Hitachi NIRS format files.
330
331
Parameters:
332
- fname: Path to the Hitachi file
333
- subject_info: Subject information dictionary
334
- preload: Load data into memory immediately
335
336
Returns:
337
Raw object containing continuous data
338
"""
339
340
def read_raw_nedf(fname: str, preload: bool = False) -> Raw:
341
"""
342
Read NEDF format (.nedf) files.
343
344
Parameters:
345
- fname: Path to the .nedf file
346
- preload: Load data into memory immediately
347
348
Returns:
349
Raw object containing continuous data
350
"""
351
352
def read_raw_neuralynx(fname: str, preload: bool = False) -> Raw:
353
"""
354
Read Neuralynx format files.
355
356
Parameters:
357
- fname: Path to the Neuralynx file
358
- preload: Load data into memory immediately
359
360
Returns:
361
Raw object containing continuous data
362
"""
363
364
def read_raw_nicolet(fname: str, ch_type: str = 'eeg', eog: Union[List[str], str] = None,
365
misc: Union[List[str], str] = None, preload: bool = False) -> Raw:
366
"""
367
Read Nicolet format (.data) files.
368
369
Parameters:
370
- fname: Path to the .data file
371
- ch_type: Default channel type
372
- eog: Names of EOG channels
373
- misc: Names of miscellaneous channels
374
- preload: Load data into memory immediately
375
376
Returns:
377
Raw object containing continuous data
378
"""
379
380
def read_raw_nihon(fname: str, preload: bool = False) -> Raw:
381
"""
382
Read Nihon Kohden format (.eeg) files.
383
384
Parameters:
385
- fname: Path to the .eeg file
386
- preload: Load data into memory immediately
387
388
Returns:
389
Raw object containing continuous data
390
"""
391
392
def read_raw_nirx(fname: str, saturated: str = 'annotate', preload: bool = False) -> Raw:
393
"""
394
Read NIRx NIRS format (.hdr) files.
395
396
Parameters:
397
- fname: Path to the .hdr file
398
- saturated: How to handle saturated channels ('annotate', 'ignore')
399
- preload: Load data into memory immediately
400
401
Returns:
402
Raw object containing continuous data
403
"""
404
405
def read_raw_nsx(fname: str, preload: bool = False) -> Raw:
406
"""
407
Read Blackrock NSx format (.ns3) files.
408
409
Parameters:
410
- fname: Path to the .ns3 file
411
- preload: Load data into memory immediately
412
413
Returns:
414
Raw object containing continuous data
415
"""
416
417
def read_raw_persyst(fname: str, preload: bool = False) -> Raw:
418
"""
419
Read Persyst format (.lay) files.
420
421
Parameters:
422
- fname: Path to the .lay file
423
- preload: Load data into memory immediately
424
425
Returns:
426
Raw object containing continuous data
427
"""
428
429
def read_raw_snirf(fname: str, optode_frame: str = 'head', preload: bool = False) -> Raw:
430
"""
431
Read SNIRF NIRS format (.snirf) files.
432
433
Parameters:
434
- fname: Path to the .snirf file
435
- optode_frame: Coordinate frame for optodes
436
- preload: Load data into memory immediately
437
438
Returns:
439
Raw object containing continuous data
440
"""
441
```
442
443
### Epochs and Evoked Data Reading
444
445
Read preprocessed epoched data and averaged evoked responses from various formats.
446
447
```python { .api }
448
def read_epochs(fname: str, proj: bool = True, preload: bool = True,
449
verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
450
"""
451
Read epochs from FIF file.
452
453
Parameters:
454
- fname: Path to epochs file
455
- proj: Apply SSP projections
456
- preload: Load data into memory
457
- verbose: Verbosity level
458
459
Returns:
460
Epochs object
461
"""
462
463
def read_evokeds(fname: str, condition: Union[int, str, List] = None,
464
baseline: Optional[Tuple[float, float]] = None,
465
proj: bool = True, verbose: Optional[Union[bool, str, int]] = None) -> Union[Evoked, List[Evoked]]:
466
"""
467
Read evoked response(s) from FIF file.
468
469
Parameters:
470
- fname: Path to evoked file
471
- condition: Which condition(s) to read
472
- baseline: Baseline correction period
473
- proj: Apply SSP projections
474
- verbose: Verbosity level
475
476
Returns:
477
Evoked object or list of Evoked objects
478
"""
479
480
def read_epochs_eeglab(input_fname: str, events: Optional[ArrayLike] = None,
481
event_id: Optional[Dict] = None, eog: Union[str, List[str]] = (),
482
verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
483
"""
484
Read EEGLAB epochs from .set file.
485
486
Parameters:
487
- input_fname: Path to .set file
488
- events: Event array
489
- event_id: Event ID mapping
490
- eog: EOG channel names
491
- verbose: Verbosity level
492
493
Returns:
494
Epochs object
495
"""
496
```
497
498
### Array-Based Data Creation
499
500
Create MNE data objects directly from numpy arrays when importing from other analysis environments.
501
502
```python { .api }
503
def RawArray(data: ArrayLike, info: Info, first_samp: int = 0,
504
copy: str = 'auto', verbose: Optional[Union[bool, str, int]] = None) -> Raw:
505
"""
506
Create Raw object from numpy array.
507
508
Parameters:
509
- data: Data array (n_channels, n_times)
510
- info: Measurement info
511
- first_samp: First sample index
512
- copy: Whether to copy data
513
- verbose: Verbosity level
514
515
Returns:
516
Raw object
517
"""
518
519
def EpochsArray(data: ArrayLike, info: Info, events: Optional[ArrayLike] = None,
520
tmin: float = 0.0, event_id: Optional[Dict] = None,
521
selection: Optional[ArrayLike] = None, drop_log: Optional[List] = None,
522
verbose: Optional[Union[bool, str, int]] = None) -> Epochs:
523
"""
524
Create Epochs object from numpy array.
525
526
Parameters:
527
- data: Data array (n_epochs, n_channels, n_times)
528
- info: Measurement info
529
- events: Event array
530
- tmin: Start time of epochs
531
- event_id: Event ID mapping
532
- selection: Subset of original event indices
533
- drop_log: Drop log from original epochs
534
- verbose: Verbosity level
535
536
Returns:
537
Epochs object
538
"""
539
540
def EvokedArray(data: ArrayLike, info: Info, tmin: float = 0.0,
541
comment: str = '', nave: int = 1, kind: str = 'average',
542
verbose: Optional[Union[bool, str, int]] = None) -> Evoked:
543
"""
544
Create Evoked object from numpy array.
545
546
Parameters:
547
- data: Data array (n_channels, n_times)
548
- info: Measurement info
549
- tmin: Start time
550
- comment: Comment for evoked response
551
- nave: Number of averaged epochs
552
- kind: Type of data ('average' or 'standard_error')
553
- verbose: Verbosity level
554
555
Returns:
556
Evoked object
557
"""
558
```
559
560
### Measurement Info Creation and Manipulation
561
562
Create and modify measurement information containers that store channel details and acquisition parameters.
563
564
```python { .api }
565
def create_info(ch_names: List[str], sfreq: float, ch_types: Union[str, List[str]] = 'eeg',
566
verbose: Optional[Union[bool, str, int]] = None) -> Info:
567
"""
568
Create measurement info structure.
569
570
Parameters:
571
- ch_names: Channel names
572
- sfreq: Sampling frequency in Hz
573
- ch_types: Channel types ('eeg', 'meg', 'stim', etc.)
574
- verbose: Verbosity level
575
576
Returns:
577
Info object with measurement information
578
"""
579
580
def read_info(fname: str, verbose: Optional[Union[bool, str, int]] = None) -> Info:
581
"""
582
Read measurement info from file.
583
584
Parameters:
585
- fname: Path to file containing info
586
- verbose: Verbosity level
587
588
Returns:
589
Info object
590
"""
591
592
def anonymize_info(info: Info, daysback: int = None, keep_his: bool = False,
593
verbose: Optional[Union[bool, str, int]] = None) -> Info:
594
"""
595
Remove subject information from Info object.
596
597
Parameters:
598
- info: Info object to anonymize
599
- daysback: Days to subtract from measurement date
600
- keep_his: Keep head isotrak digitization
601
- verbose: Verbosity level
602
603
Returns:
604
Anonymized Info object
605
"""
606
```
607
608
### Event Detection and Handling
609
610
Find and manipulate events in continuous data for epoch creation.
611
612
```python { .api }
613
def find_events(raw: Raw, stim_channel: Optional[str] = None, output: str = 'onset',
614
consecutive: Union[bool, str] = True, min_duration: float = 0,
615
shortest_event: int = 2, mask: Optional[int] = None,
616
uint_cast: bool = False, mask_type: str = 'and',
617
initial_event: bool = False, verbose: Optional[Union[bool, str, int]] = None) -> ArrayLike:
618
"""
619
Find events in raw data.
620
621
Parameters:
622
- raw: Raw data instance
623
- stim_channel: Name of stimulus channel
624
- output: Output format ('onset', 'offset', 'step')
625
- consecutive: How to handle consecutive events
626
- min_duration: Minimum event duration
627
- shortest_event: Minimum number of samples
628
- mask: Mask for event values
629
- uint_cast: Cast to unsigned integer
630
- mask_type: Mask operation type
631
- initial_event: Include initial event
632
- verbose: Verbosity level
633
634
Returns:
635
Events array (n_events, 3) with [sample, prev_id, id]
636
"""
637
638
def make_fixed_length_events(raw: Raw, id: int = 1, start: float = 0, stop: Optional[float] = None,
639
duration: float = 1.0, first_samp: bool = True,
640
overlap: float = 0.0) -> ArrayLike:
641
"""
642
Make fixed length events for epoching.
643
644
Parameters:
645
- raw: Raw data instance
646
- id: Event ID to use
647
- start: Start time
648
- stop: Stop time
649
- duration: Event duration
650
- first_samp: Include first sample
651
- overlap: Overlap between events
652
653
Returns:
654
Events array
655
"""
656
```
657
658
### Covariance Estimation
659
660
Compute noise covariance matrices for inverse modeling and source analysis.
661
662
```python { .api }
663
def compute_covariance(epochs: Epochs, tmin: Optional[float] = None, tmax: Optional[float] = None,
664
method: Union[str, List[str]] = 'empirical', method_params: Optional[Dict] = None,
665
cv: int = 3, scalings: Optional[Dict] = None, n_jobs: int = 1,
666
return_estimators: bool = False, on_mismatch: str = 'raise',
667
rank: Optional[Union[str, int, Dict]] = None,
668
verbose: Optional[Union[bool, str, int]] = None) -> Covariance:
669
"""
670
Compute covariance matrix from epochs.
671
672
Parameters:
673
- epochs: Epochs data
674
- tmin: Start time for covariance estimation
675
- tmax: End time for covariance estimation
676
- method: Covariance estimation method
677
- method_params: Method-specific parameters
678
- cv: Cross-validation folds
679
- scalings: Channel scaling factors
680
- n_jobs: Number of parallel jobs
681
- return_estimators: Return all estimators
682
- on_mismatch: How to handle channel mismatches
683
- rank: Data rank specification
684
- verbose: Verbosity level
685
686
Returns:
687
Covariance object
688
"""
689
690
def read_cov(fname: str, verbose: Optional[Union[bool, str, int]] = None) -> Covariance:
691
"""
692
Read covariance matrix from file.
693
694
Parameters:
695
- fname: Path to covariance file
696
- verbose: Verbosity level
697
698
Returns:
699
Covariance object
700
"""
701
702
def write_cov(fname: str, cov: Covariance, overwrite: bool = False,
703
verbose: Optional[Union[bool, str, int]] = None) -> None:
704
"""
705
Write covariance matrix to file.
706
707
Parameters:
708
- fname: Output filename
709
- cov: Covariance object to write
710
- overwrite: Overwrite existing file
711
- verbose: Verbosity level
712
"""
713
```
714
715
### Data Concatenation and Combination
716
717
Combine multiple data objects into single containers for analysis across sessions or conditions.
718
719
```python { .api }
720
def concatenate_raws(raws: List[Raw], preload: Optional[bool] = None,
721
events_list: Optional[List[ArrayLike]] = None) -> Raw:
722
"""
723
Concatenate raw data objects.
724
725
Parameters:
726
- raws: List of Raw objects to concatenate
727
- preload: Load data into memory
728
- events_list: List of events for each raw object
729
730
Returns:
731
Concatenated Raw object
732
"""
733
734
def concatenate_epochs(epochs_list: List[Epochs], add_offset: bool = True) -> Epochs:
735
"""
736
Concatenate epochs objects.
737
738
Parameters:
739
- epochs_list: List of Epochs objects
740
- add_offset: Add offset to event IDs to avoid conflicts
741
742
Returns:
743
Concatenated Epochs object
744
"""
745
746
def grand_average(all_inst: List[Union[Evoked, AverageTFR]], interpolate_bads: bool = True,
747
drop_bads: bool = True) -> Union[Evoked, AverageTFR]:
748
"""
749
Compute grand average across subjects/sessions.
750
751
Parameters:
752
- all_inst: List of evoked responses or TFR objects
753
- interpolate_bads: Interpolate bad channels
754
- drop_bads: Drop bad channels
755
756
Returns:
757
Grand averaged object
758
"""
759
```
760
761
### File Format Conversion and Export
762
763
Export MNE data objects to other analysis software formats and convert between different neuroimaging file formats.
764
765
```python { .api }
766
def what(fname: str) -> str:
767
"""
768
Determine file type from filename or header.
769
770
Parameters:
771
- fname: Path to file
772
773
Returns:
774
String describing file type
775
"""
776
777
def match_channel_orders(instances: List[Union[Raw, Epochs, Evoked]], copy: bool = True) -> List:
778
"""
779
Match channel orders across multiple instances.
780
781
Parameters:
782
- instances: List of MNE objects
783
- copy: Make copies of instances
784
785
Returns:
786
List of instances with matched channel orders
787
"""
788
789
def show_fiff(fname: str, tag: Optional[int] = None, indent: str = '\t',
790
read_limit: Optional[int] = None, max_str: int = 30) -> None:
791
"""
792
Show contents of FIF file.
793
794
Parameters:
795
- fname: Path to FIF file
796
- tag: Tag to show (show all if None)
797
- indent: String to use for indentation
798
- read_limit: Maximum number of tags to read
799
- max_str: Maximum string length to show
800
"""
801
802
def read_fiducials(fname: str) -> List[Dict]:
803
"""
804
Read fiducial points from file.
805
806
Parameters:
807
- fname: Path to fiducials file
808
809
Returns:
810
List of fiducial point dictionaries
811
"""
812
813
def write_fiducials(fname: str, pts: List[Dict], coord_frame: int, overwrite: bool = False) -> None:
814
"""
815
Write fiducial points to file.
816
817
Parameters:
818
- fname: Output filename
819
- pts: List of fiducial points
820
- coord_frame: Coordinate frame constant
821
- overwrite: Overwrite existing file
822
"""
823
```
824
825
## Usage Examples
826
827
### Reading Different File Formats
828
829
```python
830
import mne
831
832
# Read FIF format (native MNE format)
833
raw_fif = mne.io.read_raw_fif('sample_audvis_raw.fif', preload=True)
834
835
# Read EDF format
836
raw_edf = mne.io.read_raw_edf('sleep_recording.edf', preload=True)
837
838
# Read BrainVision format
839
raw_bv = mne.io.read_raw_brainvision('experiment.vhdr', preload=True)
840
841
# Read EEGLAB format
842
raw_eeglab = mne.io.read_raw_eeglab('experiment.set', preload=True)
843
```
844
845
### Creating Data from Arrays
846
847
```python
848
import mne
849
import numpy as np
850
851
# Create synthetic data
852
sfreq = 1000 # Hz
853
times = np.arange(0, 10, 1/sfreq)
854
data = np.random.randn(64, len(times))
855
856
# Create channel names and info
857
ch_names = [f'EEG{i:03d}' for i in range(64)]
858
ch_types = ['eeg'] * 64
859
info = mne.create_info(ch_names, sfreq, ch_types)
860
861
# Create Raw object
862
raw = mne.io.RawArray(data, info)
863
864
# Create epochs data
865
n_epochs = 100
866
epochs_data = np.random.randn(n_epochs, 64, 1000)
867
events = np.column_stack([np.arange(n_epochs) * 1000,
868
np.zeros(n_epochs, dtype=int),
869
np.ones(n_epochs, dtype=int)])
870
871
epochs = mne.EpochsArray(epochs_data, info, events, tmin=-0.5)
872
```
873
874
### Concatenating Multiple Files
875
876
```python
877
import mne
878
879
# Load multiple raw files
880
raw1 = mne.io.read_raw_fif('session1.fif', preload=True)
881
raw2 = mne.io.read_raw_fif('session2.fif', preload=True)
882
raw3 = mne.io.read_raw_fif('session3.fif', preload=True)
883
884
# Concatenate into single object
885
raw = mne.concatenate_raws([raw1, raw2, raw3])
886
887
# Load multiple epochs files
888
epochs1 = mne.read_epochs('condition1-epo.fif')
889
epochs2 = mne.read_epochs('condition2-epo.fif')
890
891
# Concatenate epochs
892
all_epochs = mne.concatenate_epochs([epochs1, epochs2])
893
```
894
895
### Event Detection and Covariance Estimation
896
897
```python
898
import mne
899
900
# Load raw data
901
raw = mne.io.read_raw_fif('sample_audvis_raw.fif', preload=True)
902
903
# Find events in stimulus channel
904
events = mne.find_events(raw, stim_channel='STI 014')
905
print(f"Found {len(events)} events")
906
907
# Create epochs around events
908
epochs = mne.Epochs(raw, events, event_id={'auditory': 1, 'visual': 3},
909
tmin=-0.2, tmax=0.5, preload=True)
910
911
# Compute noise covariance from baseline period
912
noise_cov = mne.compute_covariance(epochs, tmin=-0.2, tmax=0.0, method='empirical')
913
914
# Save covariance for later use
915
mne.write_cov('sample-cov.fif', noise_cov)
916
917
# Load covariance from file
918
loaded_cov = mne.read_cov('sample-cov.fif')
919
920
# Create fixed-length events for resting state analysis
921
rest_events = mne.make_fixed_length_events(raw, duration=2.0, overlap=0.5)
922
rest_epochs = mne.Epochs(raw, rest_events, tmin=0, tmax=2.0, preload=True)
923
```
924
925
## Types
926
927
```python { .api }
928
class Info:
929
"""
930
Measurement information container.
931
932
Behaves like a dictionary containing all metadata for a recording,
933
with keys restricted to FIF format specification.
934
"""
935
ch_names: List[str] # Channel names
936
sfreq: float # Sampling frequency in Hz
937
bads: List[str] # Bad channel names
938
nchan: int # Number of channels
939
highpass: Optional[float] # Highpass filter frequency
940
lowpass: Optional[float] # Lowpass filter frequency
941
942
def copy(self) -> 'Info': ...
943
def normalize_proj(self) -> 'Info': ...
944
945
class Covariance:
946
"""
947
Data covariance matrix container.
948
949
Stores covariance matrix with metadata for noise modeling and inverse solutions.
950
"""
951
data: ArrayLike # Covariance matrix (n_channels, n_channels)
952
ch_names: List[str] # Channel names
953
nfree: int # Degrees of freedom
954
method: str # Estimation method used
955
956
def plot(self, info: Info, **kwargs) -> Figure: ...
957
def save(self, fname: str) -> None: ...
958
959
ArrayLike = Union[np.ndarray, List, Tuple]
960
```