7
7
from nipype .interfaces .base import File , isdefined
8
8
from nipype .interfaces .mixins import reporting
9
9
10
+ from ..viz .utils import plot_registration , coolwarm_transparent
11
+
10
12
11
13
class FieldmapReportletInputSpec (reporting .ReportCapableInputSpec ):
12
14
reference = File (exists = True , mandatory = True , desc = 'input reference' )
@@ -33,7 +35,6 @@ def _run_interface(self, runtime):
33
35
34
36
def _generate_report (self ):
35
37
"""Generate a reportlet."""
36
- import numpy as np
37
38
NIWORKFLOWS_LOG .info ('Generating visual report' )
38
39
39
40
refnii = load_img (self .inputs .reference )
@@ -43,7 +44,6 @@ def _generate_report(self):
43
44
cuts = cuts_from_bbox (contour_nii or mask_nii , cuts = self ._n_cuts )
44
45
fmapdata = fmapnii .get_fdata ()
45
46
vmax = max (fmapdata .max (), abs (fmapdata .min ()))
46
- thres = np .percentile (fmapdata [fmapdata > 0 ], 5 )
47
47
48
48
# Call composer
49
49
compose_view (
@@ -59,67 +59,8 @@ def _generate_report(self):
59
59
label = 'fieldmap (Hz)' ,
60
60
contour = contour_nii ,
61
61
compress = False ,
62
- plot_params = {'cmap' : 'coolwarm' ,
63
- 'vmax' : vmax ,
62
+ plot_params = {'cmap' : coolwarm_transparent (),
63
+ 'vmax' : vmax ,
64
64
'vmin' : - vmax }),
65
65
out_file = self ._out_report
66
66
)
67
-
68
- def plot_registration (anat_nii , div_id , plot_params = None ,
69
- order = ('z' , 'x' , 'y' ), cuts = None ,
70
- estimate_brightness = False , label = None , contour = None ,
71
- compress = 'auto' ):
72
- """
73
- Plots the foreground and background views
74
- Default order is: axial, coronal, sagittal
75
- """
76
- from uuid import uuid4
77
-
78
- from lxml import etree
79
- from nilearn .plotting import plot_anat
80
- from svgutils .transform import SVGFigure
81
- from niworkflows .viz .utils import robust_set_limits , extract_svg , SVGNS
82
-
83
- plot_params = plot_params or {}
84
-
85
- # Use default MNI cuts if none defined
86
- if cuts is None :
87
- raise NotImplementedError # TODO
88
-
89
- out_files = []
90
- if estimate_brightness :
91
- plot_params = robust_set_limits (anat_nii .get_data ().reshape (- 1 ),
92
- plot_params )
93
-
94
- # Plot each cut axis
95
- for i , mode in enumerate (list (order )):
96
- plot_params ['display_mode' ] = mode
97
- plot_params ['cut_coords' ] = cuts [mode ]
98
- if i == 0 :
99
- plot_params ['title' ] = label
100
- else :
101
- plot_params ['title' ] = None
102
-
103
- # Generate nilearn figure
104
- display = plot_anat (anat_nii , ** plot_params )
105
- if contour is not None :
106
- display .add_contours (contour , colors = 'g' , levels = [0.5 ],
107
- linewidths = 0.5 )
108
-
109
- svg = extract_svg (display , compress = compress )
110
- display .close ()
111
-
112
- # Find and replace the figure_1 id.
113
- try :
114
- xml_data = etree .fromstring (svg )
115
- except etree .XMLSyntaxError as e :
116
- NIWORKFLOWS_LOG .info (e )
117
- return
118
- find_text = etree .ETXPath ("//{%s}g[@id='figure_1']" % SVGNS )
119
- find_text (xml_data )[0 ].set ('id' , '%s-%s-%s' % (div_id , mode , uuid4 ()))
120
-
121
- svg_fig = SVGFigure ()
122
- svg_fig .root = xml_data
123
- out_files .append (svg_fig )
124
-
125
- return out_files
0 commit comments