Skip to content

Instantly share code, notes, and snippets.

View larsoner's full-sized avatar

Eric Larson larsoner

View GitHub Profile
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()
import os.path as op
import mne
from mne import setup_volume_source_space
# preamble
data_path = mne.datasets.sample.data_path()
info = mne.io.read_info(data_path + '/MEG/sample/sample_audvis_raw.fif')
subjects_dir = data_path + '/subjects'
# copy-pasted code snippets
subject = 'fsaverage'
volume_label = [ 'Brain-Stem','ctx-lh-superiortemporal','ctx-rh-superiortemporal' ]
"""Hotelling T2 example.
Following the notation in
https://en.wikipedia.org/wiki/Hotelling%27s_T-squared_distribution#Two-sample_statistic
"""
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
rng = np.random.RandomState(0)
M, n_sensors = 100, 1000
# Make "Fourier coefficients" here
data = rng.randn(M, n_sensors) + rng.randn(M, n_sensors) * 1j
data += 0. # can be non-zero to test that it actually works for some signal
mean = np.mean(data, axis=0)
# -*- coding: utf-8 -*-
import faulthandler
import os.path as op
import numpy as np
from scipy.signal import welch, coherence, unit_impulse
from matplotlib import pyplot as plt
import mne
from mne.simulation import simulate_raw, add_noise
from mne.datasets import sample
@larsoner
larsoner / lcmv_maxpower.py
Created March 31, 2021 20:43
lcmv_maxpower.py
# 1. Replicate test
# 2. Expand to left and right hemi
# 3. Switch to oct-6
import os.path as op
import numpy as np
from numpy.testing import assert_allclose, assert_array_less
import mne
from mne.beamformer import make_lcmv, apply_lcmv
from mne.io.constants import FIFF
#!/bin/csh -ef
# Do recon-all and get flash5 and flash30 files to nii/*.nii:
# mcverter --format nifti -ndo . ${THIS_DIR}/DICOM/
# INRAGE=`find . -name "*MEMPRAGE*.nii"`
# IN5=`find . -name "*FLASH5*.nii"`
# IN30=`find . -name "*FLASH30*.nii"`
# OUTNAME="${PWD##*/}"
# SUBJ_DIR="$SUBJECTS_DIR/$OUTNAME"
# mkdir -p $SUBJ_DIR
@larsoner
larsoner / mplline.py
Created February 25, 2021 14:01
Try to get speedups with mpl by using blitting, linecollection, single line, etc.
import time
import mne
import numpy as np
import matplotlib.pyplot as plt
raw = mne.io.read_raw_fif(
mne.datasets.sample.data_path() + '/MEG/sample/sample_audvis_raw.fif')
data, times = raw[:, :]
n_points = 1000
norms = np.std(data, axis=-1, keepdims=True)
# Following https://m-clark.github.io/docs/mixedModels/anovamixed.html
import numpy as np
from scipy import stats
from pandas import DataFrame
import statsmodels.api as sm
from statsmodels.stats import anova
import statsmodels.formula.api as smf
import pingouin