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

Commit 4de6634

Browse files
committed
Merge remote-tracking branch 'upstream/master' into new_fsl
2 parents c01ed20 + a4e687e commit 4de6634

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

dmriprep/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
import errno
1010
import logging
1111
import os
12+
import warnings
13+
14+
# Filter warnings that are visible whenever you import another package that
15+
# was compiled against an older numpy than is installed.
16+
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
17+
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
1218

1319
from . import data
1420
from . import io

dmriprep/data.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ def list_all_subjects(self):
251251
"""
252252
raise NotImplementedError
253253

254+
def filter_keys(self, subject):
255+
"""Study-specific S3 key filtering
256+
257+
Parameters
258+
----------
259+
subject : dmriprep.data.Subject
260+
subject instance
261+
"""
262+
raise NotImplementedError
263+
254264
def postprocess(self, subject):
255265
"""Study-specific postprocessing steps
256266
@@ -362,6 +372,34 @@ def get_subs_from_tsv_key(s3_key):
362372

363373
return all_subjects
364374

375+
def filter_keys(self, subject):
376+
"""Filter S3 keys based on HBN specific vagaries
377+
378+
HBN Site-CBIC has multiple anatomy folders due to
379+
motion correction software at the scanner level.
380+
If subject.site == "Site-CBIC" then choose only the
381+
anatomy files in the T1W_VNavNorm files
382+
383+
Parameters
384+
----------
385+
subject : dmriprep.data.Subject
386+
subject instance
387+
"""
388+
if subject.site == "Site-CBIC":
389+
t1w_keys = subject.s3_keys['t1w']
390+
freesurfer_keys = subject.s3_keys['freesurfer']
391+
correct_dir = "T1w_VNavNorm"
392+
393+
subject._s3_keys['t1w'] = list(filter(
394+
lambda x: correct_dir in x,
395+
t1w_keys
396+
))
397+
398+
subject._s3_keys['freesurfer'] = list(filter(
399+
lambda x: correct_dir in x,
400+
freesurfer_keys
401+
))
402+
365403
def postprocess(self, subject):
366404
"""Move the T1 file back into the freesurfer directory.
367405
@@ -416,6 +454,7 @@ def __init__(self, subject_id, study, site=None):
416454
self._valid = False
417455
self._organize_s3_keys()
418456
if self.valid:
457+
self.study.filter_keys(self)
419458
self._s3_keys = self._determine_directions(self._s3_keys)
420459
self._files = None
421460

dmriprep/qc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import matplotlib.pyplot as plt
1111

1212

13-
1413
def reorient_array(data, aff):
1514
# rearrange the matrix to RAS orientation
1615
orientation = nib.orientations.io_orientation(aff)

dmriprep/run.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import os.path as op
22
from shutil import copyfile
3-
import warnings
4-
5-
# Filter warnings that are visible whenever you import another package that
6-
# was compiled against an older numpy than is installed.
7-
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
8-
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
93

104

115
def run_dmriprep(dwi_file, bvec_file, bval_file,
@@ -407,7 +401,8 @@ def num_outliers(scan, outliers):
407401
return len([d for d in outliers if d['scan'] == scan])
408402

409403
if 0 < threshold < 1:
410-
threshold *= nib.load(dwi_file).shape[2]
404+
img = nib.load(dwi_file)
405+
threshold *= img.shape[img.header.get_n_slices()]
411406

412407
drop_scans = np.array([
413408
s for s in scans
@@ -488,8 +483,19 @@ def drop_outliers_fn(in_file, in_bval, in_bvec, drop_scans):
488483

489484
img = nib.load(op.abspath(in_file))
490485
img_data = img.get_fdata()
491-
img_data_thinned = np.delete(img_data, drop_scans, axis=3)
492-
img_thinned = nib.Nifti1Image(img_data_thinned.astype(np.float64), img.affine, header=img.header)
486+
img_data_thinned = np.delete(img_data,
487+
drop_scans,
488+
axis=3)
489+
if isinstance(img, nib.nifti1.Nifti1Image):
490+
img_thinned = nib.Nifti1Image(img_data_thinned.astype(np.float64),
491+
img.affine,
492+
header=img.header)
493+
elif isinstance(img, nib.nifti2.Nifti2Image):
494+
img_thinned = nib.Nifti2Image(img_data_thinned.astype(np.float64),
495+
img.affine,
496+
header=img.header)
497+
else:
498+
raise TypeError("in_file does not contain Nifti image datatype.")
493499

494500
out_file = fname_presuffix(in_file, suffix="_thinned", newpath=op.abspath('.'))
495501
nib.save(img_thinned, op.abspath(out_file))

0 commit comments

Comments
 (0)