Exemple #1
0
def run(da, di, mf):
    print(('Processing : %4d nAm (dip %d) : SSS=%s' % (da, di, mf)).ljust(42),
          end='')
    epochs, evoked, cov, sphere = get_data(base_path, di, da, mf, bads=bads)
    # Hack to only use gradiometers
    epochs.pick_types(meg='grad')
    evoked.pick_types(meg='grad')
    # Do LCMV
    data_cov = mne.compute_covariance(epochs, tmin=0.)
    stc = mne.beamformer.lcmv(evoked,
                              fwd,
                              cov,
                              data_cov,
                              reg=0.01,
                              pick_ori='max-power',
                              reduce_rank=True,
                              max_ori_out='signed')
    stc = abs(stc)
    idx_max = np.argmax(np.mean(stc.data, axis=1))
    vertno_max = stc.vertices[idx_max]
    pos = src[0]['rr'][vertno_max]
    ori = None
    amp = None
    gof = None

    actual_params = dict(actual_pos=actual_pos[di - 1],
                         actual_ori=actual_ori[di - 1],
                         actual_amp=da / 2.)
    error = compute_error(di, pos, ori, amp, **actual_params)
    error['gof'] = gof
    error['maxfilter'] = mf
    return pd.DataFrame(error, index=[0])
def run(da, di, mf):
    print(('Processing : %4d nAm (dip %d) : SSS=%s' % (da, di, mf)).ljust(43),
          end='')
    epochs, evoked, cov, sphere = get_data(base_path, di, da, mf, bads=bads)

    # # Hack to only use gradiometers
    # epochs.pick_types(meg='grad')
    # evoked.pick_types(meg='grad')

    dip = mne.beamformer.rap_music(evoked,
                                   fwd,
                                   cov,
                                   n_dipoles=1,
                                   return_residual=False)[0]
    t_idx = np.argmax(dip.gof)
    pos = dip.pos[t_idx]
    ori = dip.ori[t_idx]
    gof = dip.gof[t_idx]
    amp = dip.amplitude[t_idx]
    actual_params = dict(actual_pos=actual_pos[di - 1],
                         actual_ori=actual_ori[di - 1],
                         actual_amp=da / 2.)
    error = compute_error(di, pos, ori, 1e9 * amp, **actual_params)
    error['gof'] = gof
    error['maxfilter'] = mf
    return pd.DataFrame(error, index=[0])
def run(da, di, mf):
    print(('Processing : %4d nAm (dip %d) : SSS=%s' % (da, di, mf)).ljust(43),
          end='')
    epochs, evoked, cov, sphere = get_data(base_path, di, da, mf, bads=bads)

    # Do LCMV
    reduce_rank = True  # as we use a sphere model
    pick_ori = 'max-power'
    rank = None

    # # Expose MNE bug...
    # reduce_rank = False
    # pick_ori = None
    # rank = None

    data_cov = mne.compute_covariance(epochs, tmin=0.05)
    filters = mne.beamformer.make_lcmv(epochs.info,
                                       fwd,
                                       data_cov,
                                       reg=0.05,
                                       noise_cov=cov,
                                       pick_ori=pick_ori,
                                       rank=rank,
                                       weight_norm='nai',
                                       reduce_rank=reduce_rank)

    stc = mne.beamformer.apply_lcmv(evoked, filters, max_ori_out='signed')
    stc = abs(stc)
    idx_max = np.argmax(np.mean(stc.data, axis=1))
    vertno_max = stc.vertices[idx_max]
    pos = src[0]['rr'][vertno_max]
    ori = None
    amp = None
    gof = None

    actual_params = dict(actual_pos=actual_pos[di - 1],
                         actual_ori=actual_ori[di - 1],
                         actual_amp=da / 2.)
    error = compute_error(di, pos, ori, amp, **actual_params)
    error['gof'] = gof
    error['maxfilter'] = mf
    return pd.DataFrame(error, index=[0])
Exemple #4
0
def run(da, di, mf):
    print(('Processing : %4d nAm (dip %d) : SSS=%s' % (da, di, mf)).ljust(43),
          end='')
    epochs, evoked, cov, sphere = get_data(base_path, di, da, mf, bads=bads)

    evoked_pst = evoked.copy().crop(0.05, None)
    inverse_operator = mne.minimum_norm.make_inverse_operator(epochs.info,
                                                              fwd,
                                                              cov,
                                                              loose=1,
                                                              depth=0.199)
    snr, snr_est = mne.minimum_norm.estimate_snr(evoked_pst, inverse_operator)
    peak_ch, peak_time = evoked_pst.get_peak(ch_type='mag')
    tp = int((peak_time - evoked_pst.times[0]) * evoked_pst.info['sfreq'])
    snr_peak = snr[tp]

    print(" SNR: %2.3f" % snr_peak)
    snrs = dict(actual_dipole_amplitude=da, dipole_index=di)
    snrs['snr'] = snr_peak
    snrs['maxfilter'] = mf
    return pd.DataFrame(snrs, index=[0])
def run(da, di, mf):
    print(('Processing : %4d nAm (dip %d) : SSS=%s' % (da, di, mf)).ljust(42),
          end="")
    epochs, evoked, cov, sphere = get_data(base_path, di, da, mf, bads=bads)
    # Hack to only use gradiometers
    epochs.pick_types(meg='grad')
    evoked.pick_types(meg='grad')
    # Do the dipole fit
    t_peak = 66e-3  # only fit the largest peak
    evoked.crop(t_peak, t_peak)
    dip = mne.fit_dipole(evoked, cov, sphere)[0]
    pos = dip.pos[0]
    ori = dip.ori[0]
    gof = dip.gof[0]
    actual_params = dict(actual_pos=actual_pos[di - 1],
                         actual_ori=actual_ori[di - 1],
                         actual_amp=da / 2.)
    error = compute_error(di, pos, ori, 1e9 * dip.amplitude, **actual_params)
    error['gof'] = gof
    error['maxfilter'] = mf
    return pd.DataFrame(error)
Exemple #6
0
import mne

from phantom_helpers import (get_data, get_fwd, actual_pos, maxfilter_options,
                             dipole_amplitudes, dipole_indices, plot_errors)


errors = np.empty(
    (len(maxfilter_options), len(dipole_amplitudes), len(dipole_indices)))
src, fwd = get_fwd()

for ui, mf in enumerate(maxfilter_options):
    for ai, dipole_amplitude in enumerate(dipole_amplitudes):
        print(('Processing : %4d nAm : SSS=%s'
               % (dipole_amplitude, mf)).ljust(40), end='')
        for di, dipole_idx in enumerate(dipole_indices):
            epochs, evoked, cov, sphere = get_data(
                dipole_idx, dipole_amplitude, mf)
            # Do LCMV
            data_cov = mne.compute_covariance(epochs, tmin=0.)
            stc = mne.beamformer.lcmv(
                evoked, fwd, cov, data_cov, reg=0.01, pick_ori='max-power')
            idx_max = np.argmax(np.mean(stc.data, axis=1))
            vertno_max = stc.vertices[idx_max]
            pos = src[0]['rr'][vertno_max]
            errors[ui, ai, di] = 1e3 * np.linalg.norm(
                pos - actual_pos[dipole_idx - 1])
            if dipole_amplitude < 1000 and errors[ui, ai, di] > 20:
                raise RuntimeError
        print(np.round(errors[ui, ai], 1))

plot_errors(errors, 'lcmv')
import numpy as np
import mne

from phantom_helpers import (get_data, get_fwd, plot_errors, actual_pos,
                             maxfilter_options, dipole_indices,
                             dipole_amplitudes)

errors = np.empty(
    (len(maxfilter_options), len(dipole_amplitudes), len(dipole_indices)))

src, fwd = get_fwd()
for ui, use_maxwell_filter in enumerate(maxfilter_options):
    for ai, dipole_amplitude in enumerate(dipole_amplitudes):
        print(('Processing : %4d nAm : SSS=%s' %
               (dipole_amplitude, use_maxwell_filter)).ljust(40),
              end='')
        for di, dipole_idx in enumerate(dipole_indices):
            epochs, evoked, cov, sphere = \
                get_data(dipole_idx, dipole_amplitude, use_maxwell_filter)
            pos = mne.beamformer.rap_music(evoked,
                                           fwd,
                                           cov,
                                           n_dipoles=1,
                                           return_residual=False)[0].pos[0]
            errors[ui, ai,
                   di] = 1e3 * np.linalg.norm(pos - actual_pos[dipole_idx - 1])
        print(np.round(errors[ui, ai], 1))

plot_errors(errors, 'music')