/usr/share/pyshared/nipy/interfaces/spm.py is in python-nipy 0.3.0-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
''' Interfaces to SPM '''
from __future__ import with_statement
import os
import numpy as np
from scipy.io import savemat
from nibabel import load
from nibabel.onetime import setattr_on_read
from nibabel.tmpdirs import InTemporaryDirectory
from .matlab import run_matlab_script
class SpmInfo(object):
@setattr_on_read
def spm_path(self):
with InTemporaryDirectory() as tmpdir:
run_matlab_script("""
spm_path = spm('dir');
fid = fopen('spm_path.txt', 'wt');
fprintf(fid, '%s', spm_path);
fclose(fid);
""")
spm_path = open('spm_path.txt', 'rt').read()
return spm_path
spm_info = SpmInfo()
def make_job(jobtype, jobname, contents):
return {'jobs':[{jobtype:[{jobname:contents}]}]}
# XXX this should be moved into a matdict class or something
def fltcols(vals):
''' Trivial little function to make 1xN float vector '''
return np.atleast_2d(np.array(vals, dtype=float))
def run_jobdef(jobdef):
with InTemporaryDirectory():
savemat('pyjobs.mat', jobdef)
run_matlab_script("""
load pyjobs;
spm_jobman('run', jobs);
""")
def scans_for_fname(fname):
img = load(fname)
n_scans = img.shape[3]
scans = np.zeros((n_scans, 1), dtype=object)
for sno in range(n_scans):
scans[sno] = '%s,%d' % (fname, sno+1)
return scans
def scans_for_fnames(fnames):
n_sess = len(fnames)
sess_scans = np.zeros((1,n_sess), dtype=object)
for sess in range(n_sess):
sess_scans[0,sess] = scans_for_fname(fnames[sess])
return sess_scans
def fname_presuffix(fname, prefix='', suffix='', use_ext=True):
pth, fname = os.path.split(fname)
fname, ext = os.path.splitext(fname)
if not use_ext:
ext = ''
return os.path.join(pth, prefix+fname+suffix+ext)
def fnames_presuffix(fnames, prefix='', suffix=''):
f2 = []
for fname in fnames:
f2.append(fname_presuffix(fname, prefix, suffix))
return f2
|