mutable struct NEURO
header::NeuroAnalyzer.HEADER
history::Vector{String}
markers::DataFrame
epochs::DataFrame
locs::DataFrame
time_pts::Vector{Float64}
epoch_time::Vector{Float64}
data::Array{Float64, 3}
endNeuroAnalyzer.NEURO
NeuroAnalyzer functions operate on NeuroAnalyzer objects. The main object is NeuroAnalyzer.NEURO, which holds a single recording of any type (e.g. EEG, MEG or NIRS) together with its metadata.
| Field | Contents |
|---|---|
header |
metadata: subject, recording and notes (see Header) |
history |
list of the processing steps applied to the object, with their parameters |
markers |
event markers (see Event markers) |
epochs |
epoch metadata, one row per epoch (see Epoch metadata) |
locs |
channel (electrode, magnetometer, gradiometer or optode) locations |
time_pts |
time of each sample (in seconds) from the start of the recording |
epoch_time |
time of each sample (in seconds) within an epoch; negative before the event onset |
data |
the signal: channels × samples × epochs |
A NEURO object is created by importing a recording (e.g. import_edf(), import_fiff(), import_snirf()), by loading a saved object (load_neuro()) or by creating an empty object (create_object()). Objects are saved with save_neuro().
using NeuroAnalyzer
eeg = import_edf("files/eeg/eeg-test-edf.edf")println("data type: ", datatype(eeg))
println("channels: ", nchannels(eeg))
println("epochs: ", nepochs(eeg))
println("sampling rate: ", sr(eeg), " Hz")
println("duration: ", signal_duration(eeg), " s")data type: eeg
channels: 24
epochs: 1
sampling rate: 256 Hz
duration: 1205.0 s
info() prints a summary of the object:
info(eeg) Data type: EEG
File format: EDF
Source file: files/eeg/eeg-test-edf.edf
File size [MB]: 14.13
Memory size [MB]: 61.2
Subject: 528004 SIT 52, 20220831-122227-{d589f756-53fc-4f1b-915d-6e3b8c1560ad}
Recording: EEGDigiTrack EEG-1042 (42-channel EEG Amplifier) V0.5 Rev. 41
Recording date: 31.08.22
Recording time: 12:32:53
Sampling rate (Hz): 256
Signal length [samples]: 308480
Signal length [seconds]: 1205.0
Number of channels: 24
Epoch conditions: none
Number of epochs: 1
Epoch length [samples]: 308480
Epoch length [seconds]: 1205.0
Reference type: physical
Line frequency: 50 Hz
Markers: no
Channel locations: yes (unit unknown)
Number of EEG channels: 19
Channels:
ch label type unit bad
------ --------------- ----------- ------- -------
1 Fp1 EEG μV false
2 Fp2 EEG μV false
3 F3 EEG μV false
4 F4 EEG μV false
5 C3 EEG μV false
6 C4 EEG μV false
7 P3 EEG μV false
8 P4 EEG μV false
9 O1 EEG μV false
10 O2 EEG μV false
11 F7 EEG μV false
12 F8 EEG μV false
13 T3 EEG μV false
14 T4 EEG μV false
15 T5 EEG μV false
16 T6 EEG μV false
17 A1 REF μV false
18 A2 REF μV false
19 Fz EEG μV false
20 Cz EEG μV false
21 Pz EEG μV false
22 EOG1 EOG μV false
23 EOG2 EOG μV false
24 ECG ECG μV false
Functions operating on NEURO objects take the object(s) as positional arguments and all other arguments as keyword arguments, e.g. delete_epoch!(eeg; ep = 12). Multiple dispatch is used wherever possible.
Most edit and process functions have a mutator variant (e.g. delete_epoch() and delete_epoch!()). Mutators modify the input object in place: delete_channel!(eeg; ch = "Fp1") instead of eeg = delete_channel(eeg; ch = "Fp1"). Functions without ! return a new object and leave the input unchanged.
Channels are selected with the ch keyword, by label (ch = "C4"), by several labels (ch = ["Fp1", "Fp2"]), by type (ch = "eeg", ch = ["eeg", "eog"]), with a regular expression (ch = r"^F"), or as ch = "all" or ch = "bad". See the Glossary.
Functions whose names start with _ (e.g. NeuroAnalyzer._band_power()) are private: they work on plain vectors and arrays, are used internally by the public functions, and may change without notice.
Header
The header holds the metadata in two dictionaries and free-text notes:
mutable struct HEADER
subject::Dict
recording::Dict
notes::String
endThey are accessed as e.g. eeg.header.recording[:sampling_rate]; for the most common fields there are accessor functions (sr(), labels(), chtypes(), datatype(), channel_order()). header() prints the header.
Subject
| Key | Type | Contents |
|---|---|---|
:id |
String |
subject identifier |
:first_name |
String |
|
:middle_name |
String |
|
:last_name |
String |
|
:handedness |
String |
|
:head_circumference |
Real |
-1 if unknown |
:weight |
Real |
-1 if unknown |
:height |
Real |
-1 if unknown |
Personal data are removed with anonymize().
Recording
Keys common to all data types:
| Key | Type | Contents |
|---|---|---|
:data_type |
String |
e.g. "eeg", "meg", "nirs" (see NeuroAnalyzer.data_types) |
:file_name |
String |
source file |
:file_size_mb |
Real |
source file size in MB |
:file_type |
String |
e.g. "EDF", "BDF", "BrainVision", "FIFF", "SNIRF" |
:recording |
String |
equipment description |
:recording_date |
String |
|
:recording_time |
String |
|
:label |
Vector{String} |
channel labels, e.g. ["Fp1", "Fp2"] |
:channel_type |
Vector{String} |
channel types, e.g. ["eeg", "eog"] (see NeuroAnalyzer.channel_types) |
:unit |
Vector{String} |
channel units, e.g. ["μV"] (see NeuroAnalyzer.channel_units) |
:channel_order |
Vector{Int64} |
logical order of channels (sorted by type), see Data |
:sampling_rate |
Int64 |
in Hz |
:bad_channel |
Vector{Bool} |
true for channels marked as bad |
:lowpass |
Vector{Float64} |
low-pass frequency of each channel in Hz (no filter: the Nyquist frequency) |
:highpass |
Vector{Float64} |
high-pass frequency of each channel in Hz (no filter: 0) |
:notch |
Vector{Vector{Float64}} |
notch filter frequencies of each channel in Hz (none: empty vector), e.g. [50.0, 100.0] |
The low-pass, high-pass and notch frequencies are read from the file (e.g. the prefiltering field of EDF, BDF and GDF files such as HP:0.1Hz LP:70Hz N:50Hz, FIFF lowpass/highpass) and updated by filter() (low-pass: the lower of the current value and the cut-off; high-pass: the higher; band-pass: both; notch filters (fprototype = :iirnotch) add their frequency to :notch; band-stop filters do not change them), remove_powerline() (adds the removed frequencies to :notch) and resample() (the low-pass frequency is at most the new Nyquist frequency; notches above it are removed).
Additional keys for EEG, sEEG, ECoG and iEEG:
| Key | Type | Contents |
|---|---|---|
:reference |
String |
e.g. "physical", "AVG" |
:transducers |
Vector{String} |
electrode type per channel |
:gain |
Vector{Float64} |
gain per channel |
:line_frequency |
Real |
power line frequency in Hz (default 50) |
Additional keys for MEG:
| Key | Type | Contents |
|---|---|---|
:reference |
String |
for EEG channels, e.g. "physical", "AVG" |
:line_frequency |
Real |
power line frequency in Hz, read from the file (0 if not stored) |
:magnetometers |
Vector{Int64} |
magnetometer channel numbers |
:gradiometers |
Vector{Int64} |
gradiometer channel numbers |
:coil_type |
Vector{String} |
sensor type per channel |
:coil_id |
Vector{Int64} |
FIFF coil type code per channel |
:coil_loc |
Matrix{Float64} |
sensor geometry, channels × 12: position (m) and orientation (FIFF/MNE loc convention) |
:dev_head_t |
Matrix{Float64} |
4 × 4 device → head transform |
:head_origin |
Vector{Float64} |
origin of the head sphere fitted to the digitization points (m) |
:hpi |
Dict{Symbol, Any} |
head position indicator (cHPI) coils: frequencies, positions, coil numbers |
:first_time |
Float64 |
time (s) of the first sample from the start of the acquisition |
:ssp_labels |
Vector{String} |
names of the SSP projectors |
:ssp_channels |
Vector{Bool} |
channels the SSP projectors apply to |
:ssp_data |
Matrix{Float64} |
SSP projection vectors |
:maxshield |
Bool |
true for data recorded with internal active shielding |
:sss, :tsss |
Bool |
true after Maxwell filtering (SSS / tSSS) |
:sss_info |
Dict{Symbol, Any} |
Maxwell filtering parameters (added by maxwell_filter()), including the data rank |
Additional keys for NIRS:
| Key | Type | Contents |
|---|---|---|
:wavelengths |
Vector{Float64} |
wavelengths in nm |
:wavelength_index |
Vector{Int64} |
wavelength (index into :wavelengths) of each nirs_int / nirs_od channel |
:optode_pairs |
Matrix{Int64} |
source and detector number of each channel |
:src_labels |
Vector{String} |
source labels, e.g. ["S1", "S2"] |
:det_labels |
Vector{String} |
detector labels, e.g. ["D1", "D2"] |
:optode_labels |
Vector{String} |
all optode labels (sources and detectors) |
Keys of all data types with channel locations (EEG, sEEG, ECoG, iEEG, MEG and NIRS), see Channel locations:
| Key | Type | Contents |
|---|---|---|
:coord_system |
String |
coordinate system of the locations (BIDS names, e.g. "CapTrak", "EEGLAB"); empty if unknown |
:length_unit |
String |
unit of the locations: "m", "cm" or "mm"; empty if unknown |
:coord_ref |
Dict{String, NTuple{3, Float64}} |
the locations (x, y, z per channel) the system and unit were stored for |
These keys are read with locs_coord(), which checks that they still apply to the current locations.
NIRS channel labels combine the source, the detector and the wavelength or signal type, e.g. "S1_D1 760" (intensity), "S1_D1 760 OD" (optical density) or "S1_D1 HbO" (concentration).
Additional keys for MEP:
| Key | Type | Contents |
|---|---|---|
:stimulation_intensity |
Vector{Int64} |
stimulation intensity per channel |
:coil_type |
Vector{String} |
stimulation coil |
:stimulation_sample |
Vector{Int64} |
sample of the stimulus |
:markers_pos |
Vector{Int64} |
sample of the positive MEP peak |
:markers_neg |
Vector{Int64} |
sample of the negative MEP peak |
Sensors, EDA and TPT objects have only the common keys.
Example (EEG):
rec = eeg.header.recording
for k in [:file_type, :recording, :reference, :line_frequency]
println(rpad(string(k), 16), rec[k])
endfile_type EDF
recording EEGDigiTrack EEG-1042 (42-channel EEG Amplifier) V0.5 Rev. 41
reference physical
line_frequency 50
Notes
notes is free text, e.g. the task, the instructions or anything else about the recording (one item per line). Importers store there the task and similar metadata of the file (e.g. Task: FaceRecognition from a BIDS sidecar, the comments of an EEGLAB dataset, the project name of a FIFF file). info() prints the notes; they can be edited directly or with add_note!(), view_note() and delete_note!():
eeg.header.notes = "Task: eyes closed resting state\nSubject drowsy after 10 min"
println(eeg.header.notes)Task: eyes closed resting state
Subject drowsy after 10 min
Files saved by earlier versions (with an experiment dictionary of name, notes and design, and recording notes in header.recording[:recording_notes]) are converted when loaded: the non-empty fields become lines of the notes (Experiment: ..., the notes, Design: ..., the recording notes).
Event markers
markers is a DataFrame with one row per event:
| Column | Type | Contents |
|---|---|---|
:type |
String |
marker type (stim, response, annotation, BAD, boundary, epoch, other) |
:start |
Float64 |
event start in seconds |
:length |
Float64 |
event duration in seconds |
:value |
String |
event value or description |
:channel |
Vector{String} |
labels of the channels the event refers to; empty = all channels |
The fixed columns may be followed by extra columns (e.g. trial_type, response_time from BIDS events.tsv), kept by all marker functions.
Markers are added, edited and deleted with add_marker!(), edit_marker!() and delete_marker!(), and exported with export_markers().
Epoch metadata
epochs is a DataFrame with one row per epoch:
| Column | Type | Contents |
|---|---|---|
:condition |
String |
condition label of the epoch (e.g. the marker value of marker-based epochs); empty if none |
:source |
String |
source recording or session (the name of the imported file) |
:reject |
Bool |
true for epochs marked as rejected (epoch_reject!(), also epochs with bad segments); excluded by average_epochs() and get_epochs() unless rejected = true |
:onset |
Float64 |
onset of the epoch in the original recording in seconds (NaN for the average of an ERP) |
epoch() creates the table: marker-based epochs get a condition label (the marker value, another marker column or labels given by a dictionary), fixed-length epochs have no condition. The table follows the epochs when they are deleted, reordered or extracted. get_epochs() returns the numbers of the epochs of a condition, epoch_conditions() the condition labels. Objects saved by NeuroAnalyzer before v0.26.12 get the table when loaded.
Fixed-length epochs (no conditions):
first(epoch(eeg; ep_len = 10).epochs, 3)| Row | condition | source | reject | onset |
|---|---|---|---|---|
| String | String | Bool | Float64 | |
| 1 | eeg-test-edf.edf | false | 0.0 | |
| 2 | eeg-test-edf.edf | false | 10.0 | |
| 3 | eeg-test-edf.edf | false | 20.0 |
Channel locations
locs is a DataFrame with one row per channel:
| Column | Contents |
|---|---|
:label |
channel label |
:loc_radius |
planar radius |
:loc_theta |
planar angle (degrees) |
:loc_x, :loc_y, :loc_z |
Cartesian coordinates (RAS) |
:loc_radius_sph |
spherical radius |
:loc_theta_sph |
spherical azimuth (degrees) |
:loc_phi_sph |
spherical elevation (degrees) |
The coordinates are kept in the units of their source (e.g. meters for FIFF); functions that need a unit sphere (topographic plots, interpolation, spherical splines) normalize them. The axes are always in the NeuroAnalyzer orientation (x: right, y: nose, z: up); importers rotate coordinates of other orientations (e.g. EEGLAB, CTF: x towards the nose). Locations are loaded with load_locs!() and exported with export_locs(); see Channel locations.
Coordinate system and unit
The coordinate system (e.g. "CapTrak", "EEGLAB", "MNI305"; BIDS names) and the unit of the locations ("m", "cm", "mm") are stored in the header (:coord_system, :length_unit) when they are known:
| Source | Coordinate system | Unit |
|---|---|---|
import_bids() |
coordsystem.json |
coordsystem.json |
import_fiff() |
— | m |
import_ft() |
coordsys of elec, grad, opto |
unit of elec, grad, opto |
import_set() |
EEGLAB | — |
import_bv() ([Coordinates]) |
— | — (unit sphere) |
import_snirf(), import_nirx(), import_nirs() |
— | length unit of the file |
load_locs!() (ELC files) |
— | UnitPosition |
set_locs_coord!() |
given | given |
They are read with locs_coord(), which returns the system, the unit and whether the unit was guessed. A unit that is not known is guessed from the size of the head: the median distance of the channels from the origin is about 0.08–0.1 for meters, 8–10 for centimeters and 80–100 for millimeters (other values, e.g. 1 for locations on a unit sphere: unknown). The positions in the ELC file are in mm:
eeg_l = load_locs(eeg; file_name = "files/locs/standard_1020.elc")
locs_coord(eeg_l)(system = "", unit = "mm", guessed = false)
The stored values apply to the locations they were stored for: when the locations are rescaled (e.g. locs_scale!(), locs_normalize!()), the unit no longer applies and is guessed; when most channels are moved (e.g. locs_rotz!(), load_locs!()), the coordinate system is unknown. Editing a few positions, deleting or renaming channels keeps them:
locs_scale!(eeg_l.locs; r = 0.001)
locs_coord(eeg_l)(system = "", unit = "m", guessed = true)
set_locs_coord!() sets them, e.g. after converting the locations:
set_locs_coord!(eeg_l; system = "Other", unit = "m")
locs_coord(eeg_l)(system = "Other", unit = "m", guessed = false)
Calculations of physical distances (e.g. NIRS source-detector distances in od2conc() and nirs_quality()) use only a stored unit; if it is not known, millimeters are assumed (with a warning).
Data
All computations are performed in double precision (64-bit floating point). The signal is stored in data as Array{Float64, 3}: channels × samples × epochs. If epochs are not defined, the whole signal is a single epoch, i.e. there is always at least one epoch:
println("continuous: ", size(eeg.data))
ep = epoch(eeg; ep_len = 2)
println("epoched: ", size(ep.data))continuous: (24, 308480, 1)
epoched: (24, 512, 602)
Because the data are a standard Julia array, they can be processed with any Julia package. to_df() converts an object into a DataFrame (one column per channel, plus time), and export_csv() saves it as CSV.
Channels are stored in the original sequence (physical order). For plotting, channels are grouped by type (logical order: e.g. MEG, EEG, reference, EOG, ECG, EMG, other); the logical order is stored in :channel_order and returned by channel_order().
NeuroAnalyzer.STUDY
NeuroAnalyzer.STUDY describes a group of recordings for group-level analysis (see Group-Level Analysis):
mutable struct STUDY
name::String
notes::String
root::String
design::DataFrame
measures::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
name |
study name |
notes |
free-text notes (e.g. the aim of the study, inclusion criteria); study_create(...; notes = "...") or study.notes = "..." |
root |
base folder; relative file names are relative to it |
design |
design table: one row per recording (subject, session, group, file, include, covariates) |
measures |
cached measures (:erp, :psd, :tf) of all recordings and conditions, see study_measure!() |
history |
processing history |
The study holds the file names, not the signals: recordings are loaded one at a time. It is created with study_create() or from a BIDS dataset with study_bids(), and saved with save_study().
NeuroAnalyzer.DIPOLE
NeuroAnalyzer.DIPOLE holds an equivalent current dipole fitted with dipole_fit():
mutable struct DIPOLE
pos::Matrix{Float64}
q::Matrix{Float64}
gof::Vector{Float64}
sphere_center::Vector{Float64}
sphere_radius::Float64
frame::Symbol
header::Dict{Symbol, Any}
end| Field | Contents |
|---|---|
pos |
dipole position(s): 1 × 3 (fixed dipole) or time points × 3 (moving dipole) |
q |
dipole moments: 3 × time points |
gof |
goodness of fit (0–1), one value per fit |
sphere_center |
center of the fitted head sphere |
sphere_radius |
radius of the fitted head sphere |
frame |
coordinate frame of pos and q: :head (BEM model: head frame of the recording, mm, nAm) or :unknown (spherical model: units of the channel locations) |
header |
head model, channels, units, time points |
DIPOLE(pos, q) creates a single dipole in a unit sphere (without a fit, frame = :unknown), e.g. for simulations. Dipoles are plotted with plot_dipole() (ICBM152 template head) and with plot_slices(mri; dipole = d) and plot_surface(srf; dipole = d) (MRI and surfaces of the subject; a dipole in the head frame is moved to the MRI by the coregistration transform, trans, or the anatomical landmarks, landmarks), see Dipole Fitting.
NeuroAnalyzer.MRI
NeuroAnalyzer.MRI holds an MRI volume (or a series of volumes, e.g. fMRI or diffusion-weighted images):
mutable struct MRI
data::Array{Float32, 4}
affine::Matrix{Float64}
frame::Symbol
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
data |
voxel values: x × y × z × volumes (1 volume for anatomical images, e.g. T1) |
affine |
4 × 4 transformation from voxel indices to coordinates in mm in frame |
frame |
coordinate frame: :ras (scanner RAS), :tkr (FreeSurfer surface RAS), :mni (MNI space), :head (EEG/MEG head frame) or :unknown |
header |
file name, modality and the original header fields |
history |
processing history |
The voxels are stored in the orientation of the file (they are not resampled); the orientation, voxel size and position of the volume in space are given by the affine. As in NIfTI and MGH files, the affine uses 0-based voxel indices \((i, j, k)\):
\[ \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = A \begin{bmatrix} i \\ j \\ k \\ 1 \end{bmatrix} \]
and voxel \((i, j, k)\) of volume \(v\) is data[i + 1, j + 1, k + 1, v]. The values are stored as Float32 (half the memory of Float64; label volumes, e.g. FreeSurfer aseg, are stored exactly). voxel_size() returns the size of the voxels in mm.
An MRI object is created from an array (3D data are one volume; default affine: 1 mm voxels, origin at the first voxel):
mri = NeuroAnalyzer.MRI(data;
affine = A,
frame = :ras)
voxel_size(mri)NeuroAnalyzer.SURFACE
NeuroAnalyzer.SURFACE holds a triangulated surface (mesh), e.g. the scalp, skull or cortex:
mutable struct SURFACE
vertices::Matrix{Float64}
faces::Matrix{Int64}
values::Dict{Symbol, Matrix{Float64}}
frame::Symbol
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
vertices |
vertex coordinates in mm: vertices × 3 (x, y, z) |
faces |
triangles: triangles × 3 (vertex numbers, counter-clockwise seen from outside, i.e. the normals point outwards) |
values |
data defined at the vertices, by name: vertices × components (e.g. :thickness: n × 1, :E: n × 3 for the electric field vector) |
frame |
coordinate frame (as for MRI) |
header |
file name, surface type (e.g. pial, white, scalp) and the original header fields |
history |
processing history |
srf = NeuroAnalyzer.SURFACE(vertices, faces; frame = :tkr)Values defined at the vertices (e.g. curvature or cortical thickness, source estimates, the electric field of a brain stimulation simulation) are stored in values; a vector is one component:
srf = NeuroAnalyzer.SURFACE(vertices, faces;
values = Dict(:magnE => magn_e,
:E => e_xyz),
frame = :tkr)
srf.values[:magnE]MRI volumes and surfaces are separate objects, not parts of the NEURO object: one MRI can be used with several recordings of the same subject. Their coordinates are related to the channel locations of a recording by the coordinate frame and a coregistration transformation (head frame ↔︎ MRI).
NeuroAnalyzer.BEM
NeuroAnalyzer.BEM holds a boundary element model of the head (see Head Models): nested closed surfaces separating compartments of constant conductivity, optionally with the BEM solution:
mutable struct BEM
surfaces::Vector{SURFACE}
conductivity::Vector{Float64}
solution::Matrix{Float64}
method::Symbol
frame::Symbol
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
surfaces |
closed surfaces, innermost first (1 layer: inner skull; 3 layers: inner skull, outer skull, scalp), in the same frame |
conductivity |
conductivity (S/m) of the compartment inside each surface; outside the outermost surface is air |
solution |
BEM solution matrix (potentials at the collocation points of all surfaces); 0 × 0 if the model is not solved |
method |
collocation: :linear (at the vertices) or :constant (at the triangles) |
frame |
coordinate frame of the surfaces (as for MRI) |
header |
file name, solver and the original fields |
history |
processing history |
The surfaces must be closed, with the normals pointing outwards, and nested. A model is created from surfaces and conductivities (the frame is taken from the surfaces), or loaded with import_bem():
bem = NeuroAnalyzer.BEM([inner_skull, outer_skull, scalp], [0.3, 0.006, 0.3])NeuroAnalyzer.SOURCESPACE
NeuroAnalyzer.SOURCESPACE holds the candidate source (dipole) locations of one or more spaces, e.g. the two cortical surfaces, a volume grid inside the inner skull or discrete points (see Head Models):
mutable struct SOURCESPACE
pos::Matrix{Float64}
normals::Matrix{Float64}
space::Vector{Int64}
vertices::Vector{Int64}
spaces::Vector{Symbol}
kind::Vector{Symbol}
triangles::Vector{Matrix{Int64}}
frame::Symbol
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
pos |
source positions in mm: sources × 3 (x, y, z), ordered by space |
normals |
unit vectors: sources × 3 (cortical surfaces: normal to the cortex) |
space |
space of each source (index into spaces) |
vertices |
index of each source in the full surface or grid of its space |
spaces |
name of each space, e.g. :lh, :rh, :volume |
kind |
kind of each space: :surface, :volume or :discrete |
triangles |
per space: triangles between its sources (indices into the sources of that space); 0 × 3 if none |
frame |
coordinate frame (as for MRI) |
header |
file name and per-space information (e.g. the volume grid) |
history |
processing history |
Source spaces are loaded with import_src() or created with source_space_volume(); the columns of a forward solution follow the order of the sources.
NeuroAnalyzer.FORWARD
NeuroAnalyzer.FORWARD holds a forward solution (lead field): the signal at each channel produced by a dipole of unit moment (1 A·m) at each source (see Forward Solutions):
mutable struct FORWARD
gain::Matrix{Float64}
labels::Vector{String}
channel_type::Vector{String}
src::SOURCESPACE
orientation::Symbol
frame::Symbol
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
gain |
gain matrix: channels × (3 × sources) (free orientation: dipoles along x, y, z of frame) or channels × sources (fixed orientation: dipoles along the normals) |
labels |
channel labels (rows of gain) |
channel_type |
channel types: "eeg", "mag", "grad" |
src |
sources (columns of gain), in frame |
orientation |
:free or :fixed |
frame |
coordinate frame of the sources and dipole orientations (as for MRI) |
header |
file name, units (SI per A·m: V for EEG, T for magnetometers, T/m for gradiometers), transforms (mm), bad channels |
history |
processing history |
Forward solutions are loaded with import_fwd() or computed with forward() and forward_eeg().
NeuroAnalyzer.NOISECOV
NeuroAnalyzer.NOISECOV holds a noise covariance for source localization (see Noise Covariance):
mutable struct NOISECOV
cov::Matrix{Float64}
labels::Vector{String}
channel_type::Vector{String}
units::Vector{String}
nfree::Int64
method::Symbol
shrinkage::Float64
reg::Float64
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
cov |
covariance: channels × channels, symmetric, in the units of the channels (μV², fT², (fT/cm)²) |
labels |
channel labels |
channel_type |
channel types |
units |
units of the channels |
nfree |
degrees of freedom (number of samples - 1) |
method |
:empirical, :ledoit_wolf, :imported or :unknown |
shrinkage |
Ledoit-Wolf shrinkage (0: none) |
reg |
regularization: fraction of the mean variance of each channel type added to the diagonal |
header |
file name and the original fields |
history |
processing history |
The noise covariance is estimated with noise_cov(), loaded with import_cov(), or created from a matrix and the channels (e.g. a diagonal model of the sensor noise):
nc = NeuroAnalyzer.NOISECOV(cov, labels, channel_type)NeuroAnalyzer.SOURCEESTIMATE
NeuroAnalyzer.SOURCEESTIMATE holds a source estimate: the activity of each source of a source space over time, the output of the inverse methods (as SourceEstimate and VectorSourceEstimate of MNE-Python):
mutable struct SOURCEESTIMATE
data::Array{Float64, 3}
src::SOURCESPACE
time::Vector{Float64}
measure::Symbol
units::String
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
data |
sources × components × time points: 1 component (scalar: e.g. current along the normal, amplitude, dSPM, power) or 3 components (vector: along x, y, z of the frame of src) |
src |
sources (rows of data), in their frame |
time |
time points (s), e.g. the epoch time (0: stimulus) |
measure |
what the values are: :current, :amplitude, :dspm, :sloreta, :eloreta, :power or :unknown |
units |
units of the values, e.g. "nAm"; "" for unitless measures (dSPM, sLORETA) |
header |
inverse method, regularization, channels, file name, subject |
history |
processing history |
A source estimate is created from a matrix (sources × time points: scalar) or an array (sources × 3 × time points: vector) and the source space:
stc = NeuroAnalyzer.SOURCEESTIMATE(data,
src,
time;
measure = :current,
units = "nAm")Source estimates of MNE-Python (.stc, .w) are loaded with import_stc(), with their source space (the files contain the vertex numbers of the sources, not their positions):
src = import_src("sample-oct-6-src.fif")
stc = import_stc("sample_audvis-meg-lh.stc", src)Scalar source estimates are saved as files of MNE-Python with export_stc() (cortical source spaces: <name>-lh.stc and <name>-rh.stc; volume: <name>-vl.stc). The sources of a cortical source space are vertices of the surfaces of the subject: stc_surface() returns the full surface of a hemisphere (?h.white, ?h.pial, ?h.inflated) with the values of a time point spread to all its vertices (values[:stc]; smoothing over the surface as MNE-Python, or nearest source), and plot_stc() plots them over time (time slider, time course of the peak source, animations; see Minimum-norm estimates):
export_stc("auditory.stc", stc)
lh = stc_surface(stc, import_surf("lh.white"; tkr = true); t = 10, smooth = 10)
plot_stc(stc, [import_inflated("lh.inflated"), import_inflated("rh.inflated")]; t = 10)
plot_stc(stc, import_inflated("lh.inflated"); t = 1:20, file_name = "auditory.mp4")NeuroAnalyzer.INVERSE
NeuroAnalyzer.INVERSE holds an inverse operator of the minimum-norm methods (MNE, dSPM, sLORETA, eLORETA): the parts of the source estimate that do not depend on the data, computed once and applied to any data, method and regularization (as InverseOperator of MNE-Python):
mutable struct INVERSE
labels::Vector{String}
channel_type::Vector{String}
src::SOURCESPACE
orientation::Symbol
loose::Float64
depth::Float64
source_nn::Matrix{Float64}
source_cov::Vector{Float64}
whitener::Matrix{Float64}
eigen_fields::Matrix{Float64}
sing::Vector{Float64}
eigen_leads::Matrix{Float64}
noise_cov::NOISECOV
frame::Symbol
header::Dict{Symbol, Any}
history::Vector{String}
end| Field | Contents |
|---|---|
labels |
channels (columns of whitener) |
channel_type |
channel types: "eeg", "mag", "grad" |
src |
sources, in frame |
orientation |
:fixed (one column per source, along the normal) or :free (three columns per source) |
loose |
weight of the tangential components: 0 (fixed), 0–1 (loose), 1 (free) |
depth |
exponent of the depth weighting (0: none; NaN: unknown, imported operators) |
source_nn |
orientation of each column (columns × 3): normals, local surface frames (loose) or x, y, z (free) |
source_cov |
source covariance R of each column: depth weighting × orientation prior, scaled |
whitener |
whitener W (components × channels, units of NeuroAnalyzer signals; projectors included) |
eigen_fields |
Uᵀ of the SVD of the whitened and weighted lead field W G R^(1/2) = U diag(s) Vᵀ |
sing |
singular values s |
eigen_leads |
V (columns × components) |
noise_cov |
noise covariance of the channels |
frame |
coordinate frame of the sources and orientations |
header |
file name, depth and orientation priors, projectors, rank, transforms |
history |
processing history |
The minimum-norm estimate is K * data, with the kernel K = R^(1/2) V diag(s / (s² + λ)) Uᵀ W (A·m); dSPM and sLORETA divide it by its noise; eLORETA replaces R by source weights fitted iteratively (stored in header[:eloreta]). The inverse operator is computed from a forward solution and a noise covariance with inverse_operator(), or loaded with import_inv() (saved for MNE-Python with export_inv()); the source estimate (SOURCEESTIMATE) is computed with apply_inverse():
inv = inverse_operator(fwd, nc; loose = 0.2, depth = 0.8)
stc = apply_inverse(inv, erp; method = :dspm, λ = 1 / 9)