Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit af16c3f

Browse files
author
Adam Richie-Halford
committed
Add float dtype for eddy outlier thresholding
1 parent 5117a9d commit af16c3f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

dmriprep/run.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def run_dmriprep_pe(dwi_file, dwi_file_AP, dwi_file_PA, bvec_file, bval_file,
266266
eddy.inputs.repol = True
267267
eddy.inputs.niter = 1 # TODO: make this a parameter to the function with default 5
268268

269-
def drop_outliers_fn(outlier_report, threshold):
269+
def drop_outliers_fn(outlier_report, threshold, dwi_file):
270270
"""Get list of scans that exceed threshold for number of outliers
271271
272272
Parameters
@@ -280,14 +280,19 @@ def drop_outliers_fn(outlier_report, threshold):
280280
treated the fraction of allowed outlier slices before we drop the
281281
whole volume. Float param in not yet implemented
282282
283+
dwi_file: string
284+
Path to nii dwi file to determine total number of slices
285+
283286
Returns
284287
-------
285288
drop_scans: numpy.ndarray
286289
List of scan indices to drop
287290
"""
291+
import nibabel as nib
288292
import numpy as np
289293
import os.path as op
290294
import parse
295+
291296
with open(op.abspath(outlier_report), 'r') as fp:
292297
lines = fp.readlines()
293298

@@ -303,6 +308,9 @@ def drop_outliers_fn(outlier_report, threshold):
303308
def num_outliers(scan, outliers):
304309
return len([d for d in outliers if d['scan'] == scan])
305310

311+
if 0 < threshold < 1:
312+
threshold *= threshold * nib.load(dwi_file).shape[2]
313+
306314
drop_scans = np.array([
307315
s for s in scans
308316
if num_outliers(s, outliers) > threshold
@@ -311,13 +319,14 @@ def num_outliers(scan, outliers):
311319
return drop_scans
312320

313321
drop_outliers_node = pe.Node(niu.Function(
314-
input_names=["outlier_report", "threshold"],
322+
input_names=["outlier_report", "threshold", "dwi_file"],
315323
output_names=["drop_scans"],
316324
function=drop_outliers_fn),
317325
name="drop_outliers_node"
318326
)
319327

320-
drop_outliers_node.inputs.threshold = 1
328+
drop_outliers_node.inputs.threshold = 0.02
329+
drop_outliers_node.inputs.dwi_file = dwi_file
321330
wf.connect(prep, "fsl_eddy.out_outlier_report",
322331
drop_outliers_node, "outlier_report")
323332

0 commit comments

Comments
 (0)