Skip to content

Instantly share code, notes, and snippets.

View dengemann's full-sized avatar

Denis A. Engemann dengemann

View GitHub Profile
@dengemann
dengemann / corrupt_fiff.py
Created November 29, 2012 21:15
corrupt_fiff.py
"""
======================================================
Corrupt fiff file by saving it using an identitcal fid
======================================================
This script shows how to corrupt a fiff file.
"""
# License: BSD (3-clause)
events = mne.find_events(raw)
ica_epochs = mne.Epochs(ica_raw, events, 1, -.2, .5, picks=np.arange(ica.n_components), baseline=None)
ica_epochs.average(False).plot()
mne.viz.plot_topo_image_epochs(ica_epochs, ica_lout, 0.5)
@dengemann
dengemann / evaluate_manual_responses.py
Created December 5, 2012 14:07
Measure reaction times and classify responses from Epochs and reject based upon the result.
def _check_resp(stim, resp, l_cor, r_cor):
""" Helper function for evaluating responses
Parameters
"""
ret = 0
if resp == 8 and stim in l_cor:
ret = 1
elif resp == 64 and stim in r_cor:
ret = 1
return ret
@dengemann
dengemann / mne_ica.sel
Last active December 10, 2015 07:28
A selection file for mne_browse_raw for convenient display of ICA sources and auxiliary channels.
%
% This standard selection file is for the ICA sources from mne-python (ica.sources_as_raw)
%
% $Header$
% $Log$
% Revision 0.0 2012/12/28 08:33:18 de
%
%
%
%
# Author: Denis A. Engemann <d.engemann@fz-juelich.de>
""" Export Magnes3600WH weight tables for your study
If you want to include reference channels (might be a good idea),
currently, the way to go is to use the following mne command
to create the compensation data:
$ mne_create_comp_data
usage: mne_create_comp_data [options]
""" How to add measurment info to bti files.
Warning, this is example code. Trivially, you need to change paths but also
this code assumes you already exported the weights to .txt files and your
path is organized like this:
subjects_dir/subject{here are the weights}/kind{main, resting state, rempty room}/run/files{raw.fif}
"""
import os
import os.path as op
@dengemann
dengemann / ranova.py
Last active December 16, 2015 11:28
repeated measures ANOVA
# Author: d.engemann@fz-juelich.de
#
# License: BSD (3-clause)
# XXX clafify licensing
import numpy as np
from collections import namedtuple
from scipy.signal import detrend
from scipy import stats
import numpy as np
import pandas as pd
from rpy2 import robjects as rob
# test data as found in MNE-Python
data = np.random.RandomState(42).randn(20, 8)
# prepare categorial factors for R long table format
var = data.flatten()
aa = ['a1', 'a1', 'a1', 'a1', 'a2', 'a2', 'a2', 'a2'] * 20
% This standard selection file is for the Magnes WH3600 systems
%
% put this file in ~./mne/ when using Juelich MAGNES data
% in case the selction is not immediately loaded when opening a raw fif file
% go to 'File'->'Load channel selections ...' where all user defined channel selections
% residing in ~/.mne will be displayed.
%
% Sequential selections (this assumes that the trigger channel has been renamed to STI 014)
%
MEG4D 1:MEG 001|MEG 002|MEG 003|MEG 004|MEG 005|MEG 006|MEG 007|MEG 008|MEG 009|MEG 010|MEG 011|MEG 012|MEG 013|MEG 014|MEG 015|MEG 016|MEG 017|MEG 018|MEG 019|MEG 020|MEG 021|MEG 022|MEG 023|MEG 024|MEG 025|MEG 026|MEG 027|MEG 028|MEG 029|MEG 030|MEG 031|ECG 001|EOG 001|EOG 002|STI 013|STI 014
#!/bin/csh
source /localdata/scripts/set_sub.sh
mne_do_forward_solution --spacing oct-6 --mindist 5 --overwrite \
--meas $SUBJECTS_DIR/$SUBJECT/main_raw.fif \
--fwd $SUBJECTS_DIR/$SUBJECT/main-fwd.fif --megonly