File: script_parcel_multisubj.py

package info (click to toggle)
nipy 0.1.2%2B20100526-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,992 kB
  • ctags: 13,434
  • sloc: python: 47,720; ansic: 41,334; makefile: 197
file content (72 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download
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
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Example of script to parcellate mutli-subject data
author: Bertrand Thirion, 2005-2009
"""
import os.path as op
import cPickle
import tempfile

from nipy.neurospin.spatial_models.parcellation import Parcellation
from nipy.neurospin.spatial_models.parcel_io import *
from nipy.neurospin.spatial_models.hierarchical_parcellation import hparcel
import get_data_light

# Get the data
get_data_light.getIt()
nbsubj = 12
subj_id = range(nbsubj)
numbeta = [29]
data_dir = op.expanduser(op.join('~', '.nipy', 'tests', 'data',
                                 'group_t_images'))
mask_images = [op.join(data_dir,'mask_subj%02d.nii'%n)
               for n in range(nbsubj)]

learn_images =[[ op.join(data_dir,'spmT_%04d_subj_%02d.nii'%(nb,n))
                 for nb in numbeta]
                 for n in range(nbsubj)]
test_images=learn_images

nbeta = len(numbeta)

# parameter for the intersection of the mask
ths = nbsubj/2

# possibly, dimension reduction can performed on the input data
# (not recommended)
fdim = 3

# verbosity mode
verbose = 1

# number of parcels
nbparcel = 500

# write dir
swd = tempfile.mkdtemp()


# prepare the parcel structure
fpa,ldata,coord = parcel_input(mask_images,nbeta,learn_images,ths,fdim)
fpa.k = nbparcel

# run the algorithm
fpa = hparcel(fpa,ldata,coord)
#fpa,prfx0 = hparcel(fpa,ldata,coord,nbperm=200,niter=5,verbose)

#produce some output images
Parcellation_output(fpa,mask_images,learn_images,coord,subj_id,
                    verbose=1,swd=swd)

# do some parcellation-based analysis:
# take some test images whose parcel-based signal needs to be assessed 
test_images=learn_images

# a design matrix for possibly subject-specific effects
DMtx = None

# compute and write the parcel-based statistics
Parcellation_based_analysis(fpa,test_images,numbeta,swd,DMtx,verbose)

print "Wrote everything in %s" %swd