@@ -79,7 +79,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):
79
79
80
80
def prep_conversion (sid , dicoms , outdir , heuristic , converter , anon_sid ,
81
81
anon_outdir , with_prov , ses , bids , seqinfo , min_meta ,
82
- overwrite ):
82
+ overwrite , dcmconfig ):
83
83
if dicoms :
84
84
lgr .info ("Processing %d dicoms" , len (dicoms ))
85
85
elif seqinfo :
@@ -195,7 +195,8 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
195
195
bids = bids ,
196
196
outdir = tdir ,
197
197
min_meta = min_meta ,
198
- overwrite = overwrite ,)
198
+ overwrite = overwrite ,
199
+ dcmconfig = dcmconfig ,)
199
200
200
201
for item_dicoms in filegroup .values ():
201
202
clear_temp_dicoms (item_dicoms )
@@ -212,7 +213,8 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
212
213
213
214
214
215
def convert (items , converter , scaninfo_suffix , custom_callable , with_prov ,
215
- bids , outdir , min_meta , overwrite , symlink = True , prov_file = None ):
216
+ bids , outdir , min_meta , overwrite , symlink = True , prov_file = None ,
217
+ dcmconfig = None ):
216
218
"""Perform actual conversion (calls to converter etc) given info from
217
219
heuristic's `infotodict`
218
220
@@ -279,7 +281,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
279
281
280
282
# run conversion through nipype
281
283
res , prov_file = nipype_convert (item_dicoms , prefix , with_prov ,
282
- bids , tmpdir )
284
+ bids , tmpdir , dcmconfig )
283
285
284
286
bids_outfiles = save_converted_files (res , item_dicoms , bids ,
285
287
outtype , prefix ,
@@ -383,8 +385,25 @@ def convert_dicom(item_dicoms, bids, prefix,
383
385
shutil .copyfile (filename , outfile )
384
386
385
387
386
- def nipype_convert (item_dicoms , prefix , with_prov , bids , tmpdir ):
387
- """ """
388
+ def nipype_convert (item_dicoms , prefix , with_prov , bids , tmpdir , dcmconfig = None ):
389
+ """
390
+ Converts DICOMs grouped from heuristic using Nipype's Dcm2niix interface.
391
+
392
+ Parameters
393
+ ----------
394
+ item_dicoms : List
395
+ DICOM files to convert
396
+ prefix : String
397
+ Heuristic output path
398
+ with_prov : Bool
399
+ Store provenance information
400
+ bids : Bool
401
+ Output BIDS sidecar JSONs
402
+ tmpdir : Directory
403
+ Conversion working directory
404
+ dcmconfig : File (optional)
405
+ JSON file used for additional Dcm2niix configuration
406
+ """
388
407
import nipype
389
408
if with_prov :
390
409
from nipype import config
@@ -394,9 +413,11 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
394
413
395
414
item_dicoms = list (map (op .abspath , item_dicoms )) # absolute paths
396
415
397
- dicom_dir = op .dirname (item_dicoms [0 ]) if item_dicoms else None
416
+ fromfile = dcmconfig if dcmconfig else None
417
+ if fromfile :
418
+ lgr .info ("Using custom config file %s" , fromfile )
398
419
399
- convertnode = Node (Dcm2niix (), name = 'convert' )
420
+ convertnode = Node (Dcm2niix (from_file = fromfile ), name = 'convert' )
400
421
convertnode .base_dir = tmpdir
401
422
convertnode .inputs .source_names = item_dicoms
402
423
convertnode .inputs .out_filename = op .basename (op .dirname (prefix ))
0 commit comments