Skip to content

Instantly share code, notes, and snippets.

View larsoner's full-sized avatar

Eric Larson larsoner

View GitHub Profile
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: support@nirx.net
#!/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
import numpy as np
import mne
raws = list()
# kiloword
epo = mne.read_epochs(
mne.datasets.kiloword.data_path() + '/kword_metadata-epo.fif')
epo.pick_types(meg=False, eeg=True)
# XXX this / 1000. is a bug with kiloword, should be in meters!
@larsoner
larsoner / lens.py
Created May 18, 2020 17:57
Testing length calculations for upfirdn
import numpy as np
def output_lens(len_h, in_len, up, down):
in_len_copy = in_len + (len_h + (-len_h % up)) // up - 1
nt = in_len_copy * up
need = nt // down
if nt % down > 0:
need += 1
# need2 = int(np.ceil((in_len * up + len_h - 1) / down))
# In fsaverage/mri ran:
#
# $ mri_aparc2aseg --s fsaverage --volmask --annot HCPMMP1
# $ mri_aparc2aseg --s fsaverage --volmask --annot HCPMMP1_combined
#
# Then this script can be used to create the lookup table for atlas_ids.
import os.path as op
import numpy as np
import mne
import os
import time
from datetime import datetime, timezone, timedelta
import mne
import numpy as np
import h5py
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import os.path as op
import mne
from mne import compute_rank
from mne.beamformer import make_lcmv
data_path = mne.datasets.testing.data_path()
fname_raw = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw.fif')
fname_fwd = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc-meg-eeg-oct-4-fwd.fif')
raw = mne.io.read_raw_fif(fname_raw).fix_mag_coil_types()