-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvbm_entities_layer.py
More file actions
81 lines (67 loc) · 3.13 KB
/
Copy pathvbm_entities_layer.py
File metadata and controls
81 lines (67 loc) · 3.13 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This layer defines the nodes of pre-processing pipeline and correlation computation function
"""
import nipype.pipeline.engine as pe
import nipype.interfaces.spm as spm
spm.terminal_output = 'file'
from nipype.interfaces.io import DataSink
from nipype.interfaces.utility import Function
#Stop printing nipype.workflow info to stdout
from nipype import logging
logging.getLogger('nipype.workflow').setLevel('CRITICAL')
## Reorientation node & settings ##
class Reorient:
def __init__(self, **template_dict):
self.node = pe.Node(interface=spm.ApplyTransform(), name='reorient')
self.node.inputs.mat = template_dict['transf_mat_path']
self.node.inputs.paths = template_dict['spm_path']
## Segementation Node and settings ##
class Segment:
def __init__(self, **template_dict):
"""
segment.node.inputs.channel_info: (a tuple of the form: (a float, a float, a tuple of the
form: (a boolean, a boolean)))
A tuple with the following fields:
- bias regularisation (0-10)
- FWHM of Gaussian smoothness of bias
- which maps to save (Corrected, Field) - a tuple of two boolean
values
"""
self.node = pe.Node(interface=spm.NewSegment(), name='segmentation')
self.node.inputs.paths = template_dict['spm_path']
self.node.inputs.channel_info = (
template_dict['BIAS_REGULARISATION'],
template_dict['FWHM_GAUSSIAN_SMOOTH_BIAS'], (False, False))
self.node.inputs.affine_regularization=template_dict['affine_regularization']
self.node.inputs.warping_regularization=template_dict['warping_regularization']
self.node.inputs.sampling_distance=template_dict['sampling_distance']
self.node.inputs.mrf_weighting=template_dict['mrf_weighting']
self.node.inputs.cleanup_partitions=template_dict['cleanup']
def transform_list(normalized_class_images):
return [each[0] for each in normalized_class_images]
class List_Normalized_Images:
def __init__(self):
self.node = pe.Node(
interface=Function(
input_names='normalized_class_images',
output_names='list_norm_images',
function=transform_list),
name='List_normalized_images')
## Smoothing Node & Settings ##
class Smooth:
def __init__(self, **template_dict):
"""
smooth.node.inputs.fwhm: (a list of from 3 to 3 items which are a float or a float)
3-list of fwhm for each dimension
This is the size of the Gaussian (in mm) for smoothing the preprocessed data by. This is typically between about 4mm and 12mm.
"""
self.node = pe.Node(interface=spm.Smooth(), name='smoothing')
self.node.inputs.paths = template_dict['spm_path']
self.node.inputs.fwhm = template_dict['FWHM_SMOOTH']
self.node.inputs.implicit_masking=template_dict['implicit_masking']
## Datsink Node that collects segmented, smoothed files and writes to temp_write_dir ##
class Datasink:
def __init__(self):
self.node = pe.Node(interface=DataSink(), name='sinker')