Created
January 28, 2018 21:08
-
-
Save agramfort/3690a41529ffa9534701e6a330460f07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
import pandas as pd | |
from mayavi import mlab | |
import mne | |
from mne.viz import plot_alignment | |
import neo | |
subjects_dir = os.path.join(os.getcwd(), 'subjects') | |
electrodes_fname = os.path.join(os.getcwd(), 'anat/implantation/elec_pos_patient.txt') | |
electrodes = pd.read_csv(electrodes_fname, sep='\t', header=None) | |
electrodes.columns = ['ch_name', 'x', 'y', 'z'] | |
electrodes = electrodes.set_index('ch_name') | |
ch_names = electrodes.index.values.tolist() | |
dig_ch_pos = dict(zip(ch_names, 1e-3 * electrodes.values)) | |
montage = mne.channels.DigMontage(dig_ch_pos=dig_ch_pos) | |
info = mne.create_info(ch_names, 1000., 'seeg', montage=montage) | |
fig = plot_alignment(info, subject='epimap', subjects_dir=subjects_dir, | |
surfaces=['pial'], meg=False) | |
mlab.view(200, 70) | |
raw_fname = os.path.join(os.getcwd(), 'seeg/SZ1.TRC') | |
reader = neo.rawio.MicromedRawIO(filename=raw_fname) | |
reader.parse_header() | |
ch_names = list(reader.header['signal_channels']['name']) | |
def match_ch_type(name): | |
out = 'seeg' | |
if 'ecg' in name: | |
out = 'ecg' | |
if name in ['fz', 'cz']: | |
out = 'eeg' | |
return out | |
dig_ch_pos = {k:v for k, v in dig_ch_pos.items() if k in ch_names} | |
montage = mne.channels.DigMontage(dig_ch_pos=dig_ch_pos) | |
ch_types = [match_ch_type(ch) for ch in ch_names] | |
data = np.array(reader.get_analogsignal_chunk()) | |
data = reader.rescale_signal_raw_to_float(data).T | |
data *= 1e-6 # putdata from microvolts to volts | |
sfreq = reader.get_signal_sampling_rate() | |
info = mne.create_info(ch_names, sfreq, ch_types=ch_types, montage=montage) | |
raw = mne.io.RawArray(data, info) | |
raw.info['bads'] = ["v'1", "f'1"] | |
raw.plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment