forked from nicofarr/dynamicnetworks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
signal_extract.py
63 lines (49 loc) · 2.35 KB
/
signal_extract.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 4 19:12:13 2018
@author: majd
"""
import nilearn.datasets as dataset
from nilearn.input_data import NiftiLabelsMasker , NiftiMapsMasker , NiftiSpheresMasker
from nilearn.datasets import load_mni152_template,load_mni152_brain_mask
brainmask = load_mni152_brain_mask()
mem = Memory('nilearn_cache')
def signal_extract(data,atlas,t_r=2.2,masker_type='Spheres',saveas='file'):
"""
Extracts BOLD time-series from regions of interest
Parameters
----------
data: Filenames of subjects.
atlas: regions or coordinates to extract signals from.
masker_type : Type of masker used to extract BOLD signals . types are : 'Spheres','Maps','Labels'
saveas : Destination to save and load output (.npz)
Returns
---------
subject_ts : array-like , 2-D (n_subjects,n_regions)
Array of BOLD time-series
"""
subjects_ts=[]
if os.path.exists(saveas):
subjects_ts=np.load(saveas)['arr_0']
else:
if masker_type== 'Spheres':
masker = NiftiSpheresMasker(
seeds=atlas, smoothing_fwhm=6, radius=4 ,mask_img=brainmask,
detrend=False, standardize=True, low_pass=0.1, high_pass=0.01, t_r=t_r)
elif masker_type == 'Maps':
masker = NiftiMapsMasker(maps_img=atlas,mask_img=brainmask,standardize=True,
high_pass=0.01,low_pass=0.1,detrend=False,t_r=t_r,
memory_level=2,smoothing_fwhm=5,resampling_target='data',
memory=mem,verbose=5)
elif masker_type == 'Labels':
masker = NiftiLabelsMasker(labels_img=atlas,mask_img=brainmask,standardize=True,
high_pass=0.01,low_pass=0.1,detrend=False,t_r=t_r,
memory_level=2,smoothing_fwhm=5,resampling_target='data',
memory=mem,verbose=5)
else:
raise ValueError("Please provide masker type")
for func_file in data:
time_series = masker.fit_transform(func_file)
subjects_ts.append(time_series)
np.savez(saveas,subjects_ts)
return subjects_ts