Skip to content

Instantly share code, notes, and snippets.

View larsoner's full-sized avatar

Eric Larson larsoner

View GitHub Profile
@larsoner
larsoner / magic.ipynb
Last active February 11, 2026 17:01
MagicGUI
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""Visual stimulus design.
Tools for drawing shapes and text on the screen.
"""
# Authors: Dan McCloy <drmccloy@uw.edu>
# Eric Larson <larsoner@uw.edu>
# Ross Maddox <rkmaddox@uw.edu>
#
# License: BSD (3-clause)
@larsoner
larsoner / fwd_opt.py
Last active August 22, 2025 20:12
See how we can speed up dipole fitting
import numpy as np
import mne
import time
data_path = mne.datasets.sample.data_path()
subjects_dir = data_path / 'subjects'
n_dips = 10
radius = 0.05
rr = np.random.default_rng(0).normal(size=(n_dips, 3))
rr /= np.linalg.norm(rr, axis=1)[:, np.newaxis] / radius * 0.9
@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