Skip to content

Instantly share code, notes, and snippets.

View satra's full-sized avatar

Satrajit Ghosh satra

View GitHub Profile
import os
import numpy as np
from nipype.interfaces.spm import *
import nipype.interfaces.matlab as mlab # how to run matlab
mlab.MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")
mlab.MatlabCommand.set_default_paths('/software/spm8')
@satra
satra / display_crash.py
Created February 14, 2011 22:36
Displays nipype crash files with formatted information
#! /usr/bin/env python
import argparse
from nipype.utils.filemanip import loadcrash
def display_crash_files(crashfile, rerun):
"display crash file content and rerun if required"
crash_data = loadcrash(crashfile)
node = crash_data['node']
@satra
satra / itkNaryMaximumImageFilter.py
Created February 14, 2011 23:03
itkNaryMaximumImageFilter definition
import os
from nipype.interfaces.base import (CommandLine, CommandLineInputSpec,
TraitedSpec, File,
InputMultiPath, traits)
from nipype.utils.misc import isdefined
from nipype.utils.filemanip import fname_presuffix
class ITKNaryMaximumImageFilterInputSpec(CommandLineInputSpec):
tcl_script = File(exists=True, argstr = '-b %s', position = 1,
@satra
satra / twosamplettest.py
Created February 17, 2011 02:13
Nipype: SPM two sample t-test workflow
l2BGflow = pe.Workflow(name='l2BGflow')
# setup a between group 2-sample t-test node
twosamplettestdes = pe.Node(interface=spm.TwoSampleTTestDesign(), name="twosampttestdes")
twosamplettestdes.inputs.explicit_mask_file = os.path.abspath('/software/spm8/apriori/brainmask.nii')
l2BGestimate = pe.Node(interface=spm.EstimateModel(), name="twosampleestimate")
l2BGestimate.inputs.estimation_method = {'Classical' : 1}
l2BGconestimate = pe.Node(interface = spm.EstimateContrast(), name="twosampleconestimate")
con_1 = ('Controls','T', ['Group_{1}'],[1])
con_2 = ('Patients','T', ['Group_{2}'],[1])
con_3 = ('Controls>Patients','T',['Group_{1}','Group_{2}'],[1,-1])
@satra
satra / preprocess_haxby1.py
Created February 22, 2011 03:14
nipype interface use to preprocess the haxby dataset
"""
Preprocess the Haxby data with SPM+FSL: normalize to MNI
"""
import os
import urllib
import tarfile
import gzip
import glob
import shutil
@satra
satra / EPD_virtualenv_ubuntu.rst
Created February 23, 2011 15:00
EPD for NiPyPE

from EPD install:

As the last step, you should edit your .bashrc or prepend
the EPD install path:

    /software/python/EPD/7.0/bin

Thank you for installing EPD!

$ export PATH=/software/python/EPD/7.0/bin:$PATH

@satra
satra / 00README
Created February 26, 2011 19:40
Installing EPD 7.0 + ETS on OSX x64 + virtualenv
Please note that this gist applies to EPD version 7.0 and 7.1. EPD 7.1 includes ETS
but not completely on OSX x64. Furthermore a patch has been submitted for inclusion
in virtualenv that should resolve the virtualenv issue.
The notes below were compiled for 7.0 and will need to be replaced with corresponding
7.1 paths.
https://github.com/satra/virtualenv/tree/fix/EPDpatch
@satra
satra / sge_example.py
Created March 15, 2011 01:23
runs a simple spm job on the sge cluster
"""Example script that executes via SGE qsub
"""
import nipype.pipeline.engine as pe
import nipype.interfaces.matlab as mlab
import nipype.interfaces.spm as spm
import os
mlab.MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")
mlab.MatlabCommand.set_default_paths('/software/spm8')
In [19]: class A(HasTraits):
foo = Int
def __init__(self, **kwargs):
super(A, self).__init__(**kwargs)
self.on_trait_change(self.raiseerror, 'foo')
def raiseerror(self, obj, name, old, new):
raise Exception('testing exception')
....:
....:
class Stream(object):
"""Function to capture stdout and stderr streams with timestamps
http://stackoverflow.com/questions/4984549/merge-and-sync-stdout-and-stderr/5188359#5188359
"""
def __init__(self, name, impl):
self._name = name
self._impl = impl
self._buf = ''