Skip to content

Instantly share code, notes, and snippets.

View wmvanvliet's full-sized avatar

Marijn van Vliet wmvanvliet

View GitHub Profile
@wmvanvliet
wmvanvliet / faster.py
Last active January 22, 2022 10:32
First, second and third steps of the FASTER algorithm
import numpy as np
import scipy.signal
import mne
from scipy.stats import kurtosis
from mne.preprocessing import find_outliers
from mne.fixes import nanmean
from mne.utils import logger
#from mne.preprocessing.eog import _get_eog_channel_index
@wmvanvliet
wmvanvliet / bubble.py
Created March 5, 2015 11:13
Centered bubble chart
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import numpy as np
plt.figure()
s = [ 50000.,10478.2, 4733.4,3185.3,2484.7,2310.9]
for s_ in s:
radius = np.sqrt(s_)/np.pi
plt.gca().add_patch(Circle((1, radius), radius))
plt.ylim(0, 150)
@wmvanvliet
wmvanvliet / gist:2bcd03751c28b77a0306
Created April 3, 2015 08:43
Test moving between references
import numpy as np
from numpy.testing import assert_allclose
nchannels, nsamples = 10, 100
data = np.random.rand(nchannels, nsamples)
# Average reference
data_avg = data - np.mean(data, axis=0)
# Referenced to channel 0
@wmvanvliet
wmvanvliet / topomap_skirt_demo.py
Created August 12, 2015 15:41
Demonstration of the new outline='skirt' functionality
# Python
import mne
import numpy as np
from matplotlib import pyplot as plt
# Channel positions
ch_names = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10', 'A11', 'A12', 'A13', 'A14', 'A15', 'A16', 'A17', 'A18', 'A19', 'A20', 'A21', 'A22', 'A23', 'A24', 'A25', 'A26', 'A27', 'A28', 'A29', 'A30', 'A31', 'A32', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'B11', 'B12', 'B13', 'B14', 'B15', 'B16', 'B17', 'B18', 'B19', 'B20', 'B21', 'B22', 'B23', 'B24', 'B25', 'B26', 'B27', 'B28', 'B29', 'B30', 'B31', 'B32', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16', 'C17', 'C18', 'C19', 'C20', 'C21', 'C22', 'C23', 'C24', 'C25', 'C26', 'C27', 'C28', 'C29', 'C30', 'C31', 'C32', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'D11', 'D12', 'D13', 'D14', 'D15', 'D16', 'D17', 'D18', 'D19', 'D20', 'D21', 'D22', 'D23', 'D24', 'D25', 'D26', 'D27', 'D28', 'D29', 'D30', 'D31', 'D32']
montage = mne.channels.read_montage('biosemi128')
info
@wmvanvliet
wmvanvliet / signal_quality.py
Created March 9, 2016 14:21
Evaluation of bad channel detection method
import mne
import numpy as np
from scipy.stats import norm
from matplotlib import pyplot as plt
# Load required sample data
data_path = mne.datasets.sample.data_path()
subjects_dir = data_path + '/subjects'
evoked = mne.read_evokeds(data_path + '/MEG/sample/sample_audvis-ave.fif')[0]
fwd = mne.read_forward_solution(data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif', surf_ori=False, force_fixed=True)
@wmvanvliet
wmvanvliet / checker.py
Last active August 6, 2016 17:45
Script that extracts all docstrings from a Python module, saves them to a file, and proceeds to compile a list of possible duplicates based on levenshtein distance.
from __future__ import print_function
import os.path as op
import inspect
import distance
import numpy as np
from scipy.misc import comb
import progressbar as pb
import progressbar.widgets as pw
@wmvanvliet
wmvanvliet / label_size.py
Created August 30, 2016 06:30
Example on how to compute the size of a label on the cortex with MNE
from __future__ import print_function
import mne
data_path = mne.datasets.sample.data_path()
subjects_dir = data_path + '/subjects'
subject = 'sample'
fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
# Read the source space. Normally, you would use mne.read_source_spaces for
# this, but the sample data does not include a '-src.fif' file. Therefore, in
@wmvanvliet
wmvanvliet / haufe.ipynb
Last active July 14, 2017 09:25
Testing the Haufe trick
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wmvanvliet
wmvanvliet / plot_vector_mne_solution.py
Created July 23, 2017 17:58
Testing PySurfer vector data
"""
==============================
Plotting the full MNE solution
==============================
The source space that is used for the inverse computation defines a set of
dipoles, distributed across the cortex. When visualizing a source estimate, it
is sometimes useful to show the dipole directions, as well as their estimated
magnitude.
"""
@wmvanvliet
wmvanvliet / _3d.old.py
Created July 25, 2017 13:22
One function to rule them all..
def plot_source_estimates(stc, subject=None, surface=None, hemi='lh',
colormap='auto', time_label='auto',
smoothing_steps=10, transparent=None,
brain_alpha=None, alpha=None, vector_alpha=1.,
scale_factor=None, time_viewer=False,
subjects_dir=None, figure=None, views='lat',
colorbar=True, clim='auto', cortex="classic",
size=800, background="black", foreground="white",
initial_time=None, time_unit='s', backend='auto',
spacing='oct6'):