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