File: bayesian_structural_analysis.py

package info (click to toggle)
nipy 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,352 kB
  • sloc: python: 39,115; ansic: 30,931; makefile: 210; sh: 93
file content (57 lines) | stat: -rwxr-xr-x 1,608 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
#!/usr/bin/env python3
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
__doc__ = """
Example of a script that uses the BSA (Bayesian Structural Analysis) i.e.
nipy.labs.spatial_models.bayesian_structural_analysis module.

Author : Bertrand Thirion, 2008-2013
"""
print(__doc__)

#autoindent
from os import getcwd, mkdir, path

# Local import
from get_data_light import DATA_DIR, get_second_level_dataset
from numpy import array
from scipy import stats

from nipy.labs.spatial_models.bsa_io import make_bsa_image

# Get the data
nbsubj = 12
nbeta = 29
data_dir = path.join(DATA_DIR, 'group_t_images')
mask_images = [path.join(data_dir, 'mask_subj%02d.nii' % n)
               for n in range(nbsubj)]

betas = [path.join(data_dir, 'spmT_%04d_subj_%02d.nii' % (nbeta, n))
         for n in range(nbsubj)]

missing_file = array([not path.exists(m) for m in mask_images + betas]).any()

if missing_file:
    get_second_level_dataset()

# set various parameters
subj_id = ['%04d' % i for i in range(12)]
threshold = float(stats.t.isf(0.01, 100))
sigma = 4.
prevalence_threshold = 2
prevalence_pval = 0.95
smin = 5
write_dir = path.join(getcwd(), 'results')
if not path.exists(write_dir):
    mkdir(write_dir)

algorithm = 'density'
print('algorithm used:', algorithm)

# call the function
landmarks, individual_rois = make_bsa_image(
    mask_images, betas, threshold, smin, sigma, prevalence_threshold,
    prevalence_pval, write_dir,  algorithm=algorithm,
    contrast_id='%04d' % nbeta)

print(f"Wrote all the results in directory {write_dir}")