@@ -56,17 +56,17 @@ class _BSplineApproxInputSpec(BaseInterfaceInputSpec):
56
56
in_data = File (exists = True , mandatory = True , desc = "path to a fieldmap" )
57
57
in_mask = File (exists = True , desc = "path to a brain mask" )
58
58
bs_spacing = InputMultiObject (
59
- [DEFAULT_ZOOMS_MM ],
59
+ [DEFAULT_HF_ZOOMS_MM ],
60
60
traits .Tuple (traits .Float , traits .Float , traits .Float ),
61
61
usedefault = True ,
62
62
desc = "spacing between B-Spline control points" ,
63
63
)
64
64
ridge_alpha = traits .Float (
65
- 0.01 , usedefault = True , desc = "controls the regularization"
65
+ 1e-4 , usedefault = True , desc = "controls the regularization"
66
66
)
67
67
recenter = traits .Enum (
68
- "mode" ,
69
68
"median" ,
69
+ "mode" ,
70
70
"mean" ,
71
71
False ,
72
72
usedefault = True ,
@@ -80,7 +80,7 @@ class _BSplineApproxInputSpec(BaseInterfaceInputSpec):
80
80
zooms_min = traits .Union (
81
81
traits .Float ,
82
82
traits .Tuple (traits .Float , traits .Float , traits .Float ),
83
- default_value = 4 .0 ,
83
+ default_value = 1 .0 ,
84
84
usedefault = True ,
85
85
desc = "limit minimum image zooms, set 0.0 to use the original image" ,
86
86
)
@@ -90,6 +90,7 @@ class _BSplineApproxInputSpec(BaseInterfaceInputSpec):
90
90
91
91
92
92
class _BSplineApproxOutputSpec (TraitedSpec ):
93
+ out_intercept = traits .Float
93
94
out_field = File (exists = True )
94
95
out_coeff = OutputMultiObject (File (exists = True ))
95
96
out_error = File (exists = True )
@@ -139,15 +140,15 @@ def _run_interface(self, runtime):
139
140
140
141
# Load in the fieldmap
141
142
fmapnii = nb .load (self .inputs .in_data )
142
- fmapnii = nb .as_closest_canonical (fmapnii )
143
+ # fmapnii = nb.as_closest_canonical(fmapnii)
143
144
zooms = fmapnii .header .get_zooms ()
144
145
145
146
# Get a mask (or define on the spot to cover the full extent)
146
147
masknii = (
147
148
nb .load (self .inputs .in_mask ) if isdefined (self .inputs .in_mask ) else None
148
149
)
149
- if masknii is not None :
150
- masknii = nb .as_closest_canonical (masknii )
150
+ # if masknii is not None:
151
+ # masknii = nb.as_closest_canonical(masknii)
151
152
152
153
# Determine the shape of bspline coefficients
153
154
# This should not change with resizing, so do it first
@@ -211,9 +212,7 @@ def _run_interface(self, runtime):
211
212
)
212
213
213
214
# Fit the model
214
- model = lm .Ridge (
215
- alpha = self .inputs .ridge_alpha , fit_intercept = False , solver = "lsqr"
216
- )
215
+ model = lm .Ridge (alpha = self .inputs .ridge_alpha , fit_intercept = False )
217
216
for attempt in range (3 ):
218
217
model .fit (colmat , data .reshape (- 1 ))
219
218
extreme = np .abs (model .coef_ ).max ()
@@ -228,6 +227,8 @@ def _run_interface(self, runtime):
228
227
f"Extreme value { extreme :.2e} detected in spline coefficients."
229
228
)
230
229
230
+ self ._results ["out_intercept" ] = model .intercept_
231
+
231
232
# Store coefficients
232
233
index = 0
233
234
self ._results ["out_coeff" ] = []
@@ -247,11 +248,11 @@ def _run_interface(self, runtime):
247
248
# Interpolating in the original grid will require a new collocation matrix
248
249
if need_resize :
249
250
fmapnii = nb .load (self .inputs .in_data )
250
- fmapnii = nb .as_closest_canonical (fmapnii )
251
+ # fmapnii = nb.as_closest_canonical(fmapnii)
251
252
data = fmapnii .get_fdata (dtype = "float32" ) - center
252
253
if masknii is not None :
253
254
masknii = nb .load (self .inputs .in_mask )
254
- masknii = nb .as_closest_canonical (masknii )
255
+ # masknii = nb.as_closest_canonical(masknii)
255
256
mask = np .asanyarray (masknii .dataobj ) > 1e-4
256
257
else :
257
258
mask = np .ones_like (fmapnii .dataobj , dtype = bool )
@@ -267,14 +268,20 @@ def _run_interface(self, runtime):
267
268
# Store interpolated field
268
269
hdr = fmapnii .header .copy ()
269
270
hdr .set_data_dtype ("float32" )
270
- fmapnii .__class__ (interp_data , fmapnii .affine , hdr ).to_filename (out_name )
271
+ outnii = fmapnii .__class__ (interp_data , fmapnii .affine , hdr )
272
+ outnii .header ["cal_max" ] = np .abs (outnii .dataobj ).max ()
273
+ outnii .header ["cal_min" ] = - outnii .header ["cal_max" ]
274
+ outnii .to_filename (out_name )
271
275
self ._results ["out_field" ] = out_name
272
276
273
277
# Write out fitting-error map
274
278
self ._results ["out_error" ] = out_name .replace ("_field." , "_error." )
275
- fmapnii .__class__ (
276
- data * mask - interp_data , fmapnii .affine , fmapnii .header
277
- ).to_filename (self ._results ["out_error" ])
279
+ errornii = fmapnii .__class__ (
280
+ (data - interp_data ) * mask , fmapnii .affine , fmapnii .header
281
+ )
282
+ errornii .header ["cal_min" ] = 0
283
+ errornii .header ["cal_max" ] = np .max (errornii .dataobj )
284
+ errornii .to_filename (self ._results ["out_error" ])
278
285
279
286
if not self .inputs .extrapolate :
280
287
return runtime
0 commit comments