Skip to content

Instantly share code, notes, and snippets.

View larsoner's full-sized avatar

Eric Larson larsoner

View GitHub Profile
@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')
function HomerOfflineConverter(pathname)
%This function converts recorded NIRx datasets into Homer2 format (*.nirs)
%Please provide as input the root path, within all datasets are located
%If no probeInfo file can be found, it is necessary to choose it manually
%
%Note: to account for the original inter-optode distances, a few functions
%are added to properly import the 2D coordinates and convert them to 3D
%
%By: NIRx Medical Technologies
%Contact: [email protected]
#!/usr/bin/env python3
"""
mailmanToMBox.py: Inserts line feeds to create mbox format from Mailman Gzip'd
Text archives decompressed
Usage: ./to-mbox.py dir
Where dir is a directory containing .txt files pulled from mailman Gzip'd Text and decompressed
Adapted from https://gist.github.com/corydolphin/1728592#gistcomment-2583599
"""
import sys
import os.path as op
import numpy as np
import mne
from mne.time_frequency import csd_morlet
from mne.beamformer import make_dics, apply_dics_csd
# Simulate bilateral auditory data
subject = 'sample'
data_path = mne.datasets.testing.data_path()
fname_raw = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw.fif')
import numpy as np
from scipy import stats
import mne
import matplotlib.pyplot as plt
# 1. Load data
raw = mne.io.read_raw_fif('CC_CP004_PN_L_RUN01_tsss.fif')
other = mne.io.read_raw_egi('CC_CP004_PN_L_Run01_20201016_110457.mff')
# 2. Get times for both instances that should match
t_raw = (mne.find_events(raw)[:, 0] - raw.first_samp) / raw.info['sfreq']
import os.path as op
import mne
from mne.io.constants import FIFF
subjects = ('ANTS3-0Months3T', 'ANTS6-0Months3T', 'ANTS12-0Months3T')
subjects_dir = '.'
for subject in subjects:
subject_dir = op.join(subjects_dir, subject)
assert op.isdir(subject_dir), subject_dir