Minimum-Norm Estimates

Initialize NeuroAnalyzer
using NeuroAnalyzer
using CairoMakie
CairoMakie.activate!(type = "png")
# Quarto sets a default figure size (672 × 480 px), which overrides the sizes of
# NeuroAnalyzer figures: remove it
delete!(CairoMakie.Makie.CURRENT_DEFAULT_THEME, :resolution)
NeuroAnalyzer.progress_bar = false

# Makie figure and axis settings matching NeuroAnalyzer plots
fig_size = (900, 450)
ax_style = (titlesize = 18,
            xlabelsize = 18,
            ylabelsize = 18,
            xticklabelsize = 12,
            yticklabelsize = 12,
            xticks = LinearTicks(10),
            xminorticksvisible = true,
            xminorticks = IntervalsBetween(10),
            xautolimitmargin = (0, 0),
            yautolimitmargin = (0.1, 0.1))

Minimum-norm estimates model the activity as many dipoles on the cortex (the source space) and choose, among all source distributions that explain the data, the one with the smallest overall strength (see the Introduction to Source Imaging). NeuroAnalyzer computes them as MNE-Python does, and gives the same estimates:

  1. inverse_operator(): the parts that do not depend on the data, computed once from the forward solution and the noise covariance: the whitener, the source covariance (depth weighting and orientation prior) and the singular value decomposition of the whitened and weighted lead field (an INVERSE object)
  2. apply_inverse(): the source estimate of the data (a SOURCEESTIMATE object) with one of three methods: the minimum-norm estimate (MNE, current in A·m), dSPM and sLORETA (noise-normalized, unitless)

Data and forward model

The example is the auditory evoked response of the sample recording of MNE-Python (left-ear tones, MEG and EEG), as in the Introduction to Source Imaging: the forward solution of a coarse BEM model (320 triangles per surface) and a cortical source space of the FreeSurfer surfaces of the subject (source_space(): oct5, about 1000 sources per hemisphere; the folder of the subject contains surf/?h.white and surf/?h.sphere), and the averaged response with the noise covariance of the baseline:

bem_dir = "files/bem/sample"
raw_file = "files/meg/sample_audvis_raw.fif"
bem_file = joinpath(bem_dir, "sample-320-320-320-bem-sol.fif")
bem_sol = import_bem(bem_file)
src = source_space(bem_dir; spacing = "oct5")
trans_file = joinpath(bem_dir, "sample_audvis_raw-trans.fif")
head_mri = import_trans(trans_file; from = :head, to = :tkr)
fwd = forward(raw_file, src, bem_sol, head_mri; exclude_bads = true)

obj = import_fiff(raw_file)
ch = fwd.labels
obj = NeuroAnalyzer.filter(obj;
                           ch = ch,
                           fprototype = :butterworth,
                           ftype = :lp,
                           cutoff = 40,
                           order = 4,
                           report = false)
apply_ssp_projectors!(obj)
ep = epoch(obj; marker_value = "1", offset = 0.2, ep_len = 0.7)
nc = noise_cov(ep; ch = ch, seg = (-0.2, 0.0))
erp = average_epochs(ep; bl = (-0.2, 0.0))

Whitening

Magnetometers (fT), gradiometers (fT/cm) and EEG channels (μV) are combined by whitening with the noise covariance (whitener()): the data and the lead field are converted to units of the noise standard deviation. MEG and EEG are whitened separately, and the directions removed by the projectors carry no noise and are dropped: the rank of the whitened data is the number of channels minus the 3 SSP projectors of the MEG channels and minus 1 for the average reference of the EEG channels:

wt = whitener(nc; avg_ref = true)
println("channels: ", length(wt.labels))
println("rank: ", wt.rank)
channels: 364
rank: Dict("meg" => 302, "eeg" => 58)

Inverse operator

inverse_operator() uses the defaults of MNE-Python:

  • loose orientation (loose = 0.2): three dipoles per source, along the normal of the cortex and two tangential directions; the tangential components are weighted by 0.2 (the currents of the cortex flow mainly along the normal); fixed = true: one dipole per source, along the normal; loose = 1: free orientation
  • depth weighting (depth = 0.8): the minimum-norm estimate favours superficial sources, which explain the data with smaller currents; the sources are weighted by the inverse of the strength of their lead fields (raised to the power 0.8)
  • EEG average reference: the EEG channels are always average-referenced (in the whitener)
iop = inverse_operator(fwd, nc)
NeuroAnalyzer INVERSE
  channels: 364 (grad 203, mag 102, eeg 59)
  sources: 2018 (lh, rh), loose (0.2) orientation
  depth weighting: 0.8
  rank: 360
  frame: head

Source estimate

apply_inverse() applies the inverse operator to the averaged response. The regularization λ is 1 / SNR² for the expected signal-to-noise ratio of the data: 1/9 (SNR = 3) for averaged responses. The noise of an average of nave epochs is the noise of single epochs divided by nave: for averaged data (average_epochs()), nave is the number of averaged epochs (here 75), and the dSPM values increase with its square root:

stc = apply_inverse(iop, erp; method = :dspm, λ = 1 / 9)
NeuroAnalyzer SOURCEESTIMATE
  sources: 2018 (lh, rh), scalar
  time points: 421 (-0.2–0.499 s)
  measure: dspm
  frame: head

The source estimate has one value per source and time point. The largest dSPM value of each hemisphere between 80 and 120 ms (the N100 of the auditory response) is in the auditory cortex of both hemispheres:

tw = findall(t -> 0.08 <= t <= 0.12, stc.time)
peaks = Int64[]
for (h, hemi) in enumerate(stc.src.spaces)
    s = findall(==(h), stc.src.space)
    m = vec(maximum(stc.data[s, 1, tw]; dims = 2))
    k = s[argmax(m)]
    push!(peaks, k)
    t_peak = stc.time[tw[argmax(stc.data[k, 1, tw])]]
    println(hemi, ": source ", k,
            ", dSPM ", round(maximum(m); digits = 1),
            " at ", round(Int, 1000 * t_peak), " ms")
end
lh: source 450, dSPM 28.4 at 100 ms
rh: source 1595, dSPM 25.4 at 88 ms

The time courses of the two sources:

fig = Figure(size = fig_size)
ax = Axis(fig[1, 1];
          ax_style...,
          xlabel = "Time [s]",
          ylabel = "dSPM",
          title = "Auditory cortex")
for (k, hemi) in zip(peaks, ("left", "right"))
    lines!(ax, stc.time, stc.data[k, 1, :]; label = hemi)
end
axislegend(ax)
fig

Source estimate on the cortex

The sources are vertices of the white matter surface of the subject (stc.src.vertices: vertex numbers of ?h.white): each vertex of the surface (about 155000 per hemisphere) gets the value of its nearest source (MNE-Python smooths the values over the surface instead). The dSPM values at the peak of the left hemisphere (seen from the left):

t_peak = tw[argmax(stc.data[peaks[1], 1, tw])]
surf_dir = joinpath(bem_dir, "surf")
white = NeuroAnalyzer.SURFACE[]
inflated = NeuroAnalyzer.SURFACE[]
for (h, hemi) in enumerate(("lh", "rh"))
    w = import_surf(joinpath(surf_dir, "$hemi.white"); tkr = true)
    # sources of the hemisphere and their positions on the surface
    s = findall(==(h), stc.src.space)
    p = w.vertices[stc.src.vertices[s], :]
    # nearest source of each vertex
    near = [argmin(vec(sum(abs2, p .- v'; dims = 2)))
            for v in eachrow(w.vertices)]
    w.values[:dspm] = reshape(stc.data[s[near], 1, t_peak], :, 1)
    push!(white, w)
    # inflated surface: the same vertices
    f = import_inflated(joinpath(surf_dir, "$hemi.inflated"))
    f.values[:dspm] = w.values[:dspm]
    push!(inflated, f)
end
title = "dSPM at $(round(Int, 1000 * stc.time[t_peak])) ms"
plot_surface(white[1];
             values = :dspm,
             cmap = :hot,
             cb_title = "dSPM",
             cam = (0, 180),
             title = title,
             gui = false)

On the inflated surface (import_inflated()), the activity in the sulci is visible: the auditory cortex is in the Sylvian fissure, on the upper surface of the temporal lobe:

plot_surface(inflated[1];
             values = :dspm,
             cmap = :hot,
             cb_title = "dSPM",
             cam = (0, 180),
             title = title,
             gui = false)

Methods

The three methods differ in the normalization of the estimate:

Method method Values Localization
MNE :mne current (A·m) blurred, biased towards superficial sources
dSPM :dspm MNE divided by its noise standard deviation at each source statistical map (noise z-score), less depth bias
sLORETA :sloreta MNE divided by the square root of its resolution at each source no localization error for single sources without noise
for m in (:mne, :dspm, :sloreta)
    s = apply_inverse(iop, erp; method = m)
    v, i = findmax(s.data[:, 1, tw])
    println(rpad(m, 8), "peak: source ", i[1],
            " (", s.src.spaces[s.src.space[i[1]]], "), ",
            round(Int, 1000 * s.time[tw[i[2]]]), " ms, ",
            round(v; sigdigits = 3), " ", s.units)
end
mne     peak: source 365 (lh), 104 ms, 2.36e-9 A·m
dspm    peak: source 450 (lh), 100 ms, 28.4 
sloreta peak: source 365 (lh), 104 ms, 9.18 

Orientations

For a loose or free inverse operator, the three components of each source are combined (pick_ori):

  • nothing (default): the amplitude of the three components (unsigned)
  • :normal: the component along the normal of the cortex (signed: positive values are currents flowing out of the cortex, negative values into it)
  • :vector: the three components (x, y, z of the head frame; vector source estimate, sources × 3 × time points)
stc_n = apply_inverse(iop, erp; method = :dspm, pick_ori = :normal)
stc_v = apply_inverse(iop, erp; method = :dspm, pick_ori = :vector)
k = peaks[1]
println("amplitude: ", round(stc.data[k, 1, t_peak]; digits = 1))
println("normal:    ", round(stc_n.data[k, 1, t_peak]; digits = 1))
println("vector:    ", round.(stc_v.data[k, :, t_peak]; digits = 1))
amplitude: 28.4
normal:    -28.3
vector:    [-0.5, -25.4, -12.8]

Files of MNE-Python

Inverse operators (-inv.fif, make_inverse_operator()) and source estimates (.stc, .w) of MNE-Python are loaded with import_inv() and import_stc(); the source estimates of apply_inverse() are the same as those of MNE-Python (the inverse operators of MNE-Python with a diagonal noise covariance excepted, see import_inv()):

iop = import_inv("sample_audvis-meg-oct-6-meg-inv.fif")
stc = apply_inverse(iop, erp; method = :dspm)
# a source estimate of MNE-Python, with its source space
stc = import_stc("sample_audvis-meg-lh.stc", iop.src)

Source spaces of MNE-Python with patch information (import_src(): header[:patch_normals]) use the mean normals of the cortical patches of the sources (use_cps of MNE-Python) for the orientations; the source space of this tutorial (source_space()) has no patch information: the normals of the white matter surface at the sources are used.