Skip to content

Instantly share code, notes, and snippets.

View larsoner's full-sized avatar

Eric Larson larsoner

View GitHub Profile
import mne
data_path = mne.datasets.sample.data_path()
sample_data_raw_file = data_path / "MEG" / "sample" / "sample_audvis_raw.fif"
subjects_dir = data_path / "subjects"
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False).crop(tmax=60)
events = mne.find_events(raw, stim_channel="STI 014")
epochs = mne.Epochs(raw, events, event_id = {"auditory/left": 1}, tmin=-0.3, tmax=0.7)[:10]
inverse_operator_file = data_path / "MEG" / "sample" / "sample_audvis-meg-oct-6-meg-inv.fif"
inv_operator = mne.minimum_norm.read_inverse_operator(inverse_operator_file)
stcs = mne.minimum_norm.apply_inverse_epochs(epochs, inv_operator, lambda2=1/3, pick_ori=None)
@larsoner
larsoner / bidsify_kit_phantom.py
Last active January 25, 2024 19:42
MNE-phantom-KIT-data BIDS-ification script
"""BIDSify and trim the KIT phantom data."""
from pathlib import Path
import numpy as np
from scipy.signal import find_peaks
import matplotlib.pyplot as plt
import mne
import mne_bids
from mne.io.constants import FIFF
"""Attempt to build a mne.viz.Brain-like GUI using magicgui."""
from magicgui import widgets, use_app
import numpy as np
import re
import mne
from matplotlib.figure import Figure
import pyvista
import pyvista.plotting
# Check 1-tailed t-test bias when selecting ROIs using different methods
import numpy as np
from scipy.stats import ttest_ind
rng = np.random.default_rng(0)
n_subjects = 20 # number of subjects to simulate
n_sensors = 100 # number of "sensors" (could be source points, etc.)
n_run = 5000 # number of times to simulate (n_subjects, n_sensors) values
prop_false = np.zeros((n_run, 3, 2)) # proportion of false alarms
@larsoner
larsoner / Figure_1.png
Last active May 25, 2022 15:55
Displacement field demo using matched points
Figure_1.png
@larsoner
larsoner / pel.py
Created March 13, 2022 19:34
Find best 20-minute segment since latest FTP test
import numpy as np
from datetime import datetime
from tqdm.auto import tqdm
from pytz import timezone
from peloton import PelotonWorkout
my_tz = timezone('US/Eastern')
print('Getting workout list...')
workouts = PelotonWorkout.list()
# Minimal script to test the iEEG GUI
import os.path as op
import numpy as np
import nibabel as nib
import mne
misc_path = mne.datasets.misc.data_path(verbose=True)
raw = mne.io.read_raw(op.join(misc_path, 'seeg', 'sample_seeg_ieeg.fif'))
subj_trans = mne.coreg.estimate_head_mri_t(
'sample_seeg', op.join(misc_path, 'seeg'))
@larsoner
larsoner / linux_gl.py
Last active February 10, 2022 18:31
Linux OpenGL test
from ctypes import CDLL, c_int, byref
import faulthandler
import vtk as _vtk
faulthandler.enable()
renderWindow = _vtk.vtkRenderWindow()
logger = _vtk.vtkLogger
logger.Init()
logger.SetStderrVerbosity(_vtk.vtkLogger.VERBOSITY_MAX)
renderWindow.DebugOn()
renderWindow.SetOffScreenRendering(True)
import numpy as np
from dipy.align import affine_registration, center_of_mass, translation, rigid
from dipy.align.imaffine import MutualInformationMetric
from dipy.align.transforms import RigidTransform3D
import nibabel as nib
moving = nib.load('sub-12_CT.nii.gz')
static = nib.load('sub-12_T1.mgz')
reg_kwargs = dict(
import pyglet
player = pyglet.media.Player()
source = pyglet.media.StreamingSource()
media = pyglet.media.load('example-video.mp4')
player.queue(media)
player.play()
window = pyglet.window.Window()
while player.source and player.source.video_format:
pyglet.clock.tick(poll=True)
window.clear()