Skip to content

Instantly share code, notes, and snippets.

View larsoner's full-sized avatar

Eric Larson larsoner

View GitHub Profile
"""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
import mne
import numpy as np
import vtk
from vtk.util import numpy_support
import pyvistaqt
raw = mne.io.read_raw_fif(
mne.datasets.sample.data_path() + '/MEG/sample/sample_audvis_raw.fif')
data, times = raw[:, :]
n_points = 1000
import sys
import mne
import numpy as np
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from qwt import QwtPlot, QwtLegend, QwtPlotCurve, QwtAbstractScaleDraw
raw = mne.io.read_raw_fif(
mne.datasets.sample.data_path() + '/MEG/sample/sample_audvis_raw.fif')
data, times = raw[:, :] # preload
@larsoner
larsoner / gist:4c964e21045fc499cb5e380dc79137c0
Created February 3, 2021 20:19
bems_brainsuite_fsl.py
# convert MGZ->NII
#
# $ bet T1.nii stripped.nii.gz -n -A -v -e
#
import numpy as np
import nibabel as nib
import pyvista as pv
import mne
img = nib.load('T1.mgz')