Skip to content

Instantly share code, notes, and snippets.

View larsoner's full-sized avatar

Eric Larson larsoner

View GitHub Profile
@larsoner
larsoner / mixed_norm_visual_left.py
Created April 15, 2025 15:48
mixed_norm_visual_left.py
import numpy as np
import mne
from mne.datasets import sample
from mne.inverse_sparse import make_stc_from_dipoles, mixed_norm
from mne.minimum_norm import apply_inverse, make_inverse_operator
from mne.viz import (
plot_dipole_amplitudes,
plot_dipole_locations,
plot_sparse_source_estimates,
@larsoner
larsoner / Makefile
Last active December 21, 2024 18:46
SWIG -fastdispatch changes arguments that can be used
.PHONY: all clean openmeeg_wrap.cxx _example.so test1 test2 test3 test4 test5
all : clean example_wrap.cxx _example.so test1 test2 test3 test4 test5
clean:
rm -f *.o
rm -f *.so
rm -f *wrap*.c*
rm -f *wrapper.py
rm -Rf build
rm -Rf __pycache__
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)