@@ -79,7 +79,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):
79
79
80
80
81
81
def prep_conversion (sid , dicoms , outdir , heuristic , converter , anon_sid ,
82
- anon_outdir , with_prov , ses , bids , seqinfo , min_meta ,
82
+ anon_outdir , with_prov , ses , bids_options , seqinfo , min_meta ,
83
83
overwrite , dcmconfig ):
84
84
if dicoms :
85
85
lgr .info ("Processing %d dicoms" , len (dicoms ))
@@ -88,7 +88,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
88
88
else :
89
89
raise ValueError ("neither dicoms nor seqinfo dict was provided" )
90
90
91
- if bids :
91
+ if bids_options is not None :
92
92
if not sid :
93
93
raise ValueError (
94
94
"BIDS requires alphanumeric subject ID. Got an empty value" )
@@ -102,7 +102,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
102
102
103
103
# Generate heudiconv info folder
104
104
idir = op .join (outdir , '.heudiconv' , anon_sid )
105
- if bids and ses :
105
+ if bids_options is not None and ses :
106
106
idir = op .join (idir , 'ses-%s' % str (ses ))
107
107
if anon_outdir == outdir :
108
108
idir = op .join (idir , 'info' )
@@ -177,7 +177,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
177
177
write_config (edit_file , info )
178
178
save_json (filegroup_file , filegroup )
179
179
180
- if bids :
180
+ if bids_options is not None :
181
181
# the other portion of the path would mimic BIDS layout
182
182
# so we don't need to worry here about sub, ses at all
183
183
tdir = anon_outdir
@@ -192,7 +192,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
192
192
scaninfo_suffix = getattr (heuristic , 'scaninfo_suffix' , '.json' ),
193
193
custom_callable = getattr (heuristic , 'custom_callable' , None ),
194
194
with_prov = with_prov ,
195
- bids = bids ,
195
+ bids_options = bids_options ,
196
196
outdir = tdir ,
197
197
min_meta = min_meta ,
198
198
overwrite = overwrite ,
@@ -201,7 +201,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
201
201
for item_dicoms in filegroup .values ():
202
202
clear_temp_dicoms (item_dicoms )
203
203
204
- if bids :
204
+ if bids_options is not None and 'notop' not in bids_options :
205
205
if seqinfo :
206
206
keys = list (seqinfo )
207
207
add_participant_record (anon_outdir ,
@@ -213,7 +213,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
213
213
214
214
215
215
def convert (items , converter , scaninfo_suffix , custom_callable , with_prov ,
216
- bids , outdir , min_meta , overwrite , symlink = True , prov_file = None ,
216
+ bids_options , outdir , min_meta , overwrite , symlink = True , prov_file = None ,
217
217
dcmconfig = None ):
218
218
"""Perform actual conversion (calls to converter etc) given info from
219
219
heuristic's `infotodict`
@@ -256,7 +256,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
256
256
# We want to create this dir only if we are converting it to nifti,
257
257
# or if we're using BIDS
258
258
dicom_only = outtypes == ('dicom' ,)
259
- if not (dicom_only and bids ) and not op .exists (prefix_dirname ):
259
+ if not (dicom_only and ( bids_options is not None ) ) and not op .exists (prefix_dirname ):
260
260
os .makedirs (prefix_dirname )
261
261
262
262
for outtype in outtypes :
@@ -265,7 +265,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
265
265
lgr .debug ("Includes the following dicoms: %s" , item_dicoms )
266
266
267
267
if outtype == 'dicom' :
268
- convert_dicom (item_dicoms , bids , prefix ,
268
+ convert_dicom (item_dicoms , bids_options , prefix ,
269
269
outdir , tempdirs , symlink , overwrite )
270
270
elif outtype in ['nii' , 'nii.gz' ]:
271
271
assert converter == 'dcm2niix' , ('Invalid converter '
@@ -279,16 +279,16 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
279
279
280
280
# run conversion through nipype
281
281
res , prov_file = nipype_convert (item_dicoms , prefix , with_prov ,
282
- bids , tmpdir , dcmconfig )
282
+ bids_options , tmpdir , dcmconfig )
283
283
284
- bids_outfiles = save_converted_files (res , item_dicoms , bids ,
284
+ bids_outfiles = save_converted_files (res , item_dicoms , bids_options ,
285
285
outtype , prefix ,
286
286
outname_bids ,
287
287
overwrite = overwrite )
288
288
289
289
# save acquisition time information if it's BIDS
290
290
# at this point we still have acquisition date
291
- if bids :
291
+ if bids_options is not None :
292
292
save_scans_key (item , bids_outfiles )
293
293
# Fix up and unify BIDS files
294
294
tuneup_bids_json_files (bids_outfiles )
@@ -310,7 +310,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
310
310
elif not bids_outfiles :
311
311
lgr .debug ("No BIDS files were produced, nothing to embed to then" )
312
312
elif outname :
313
- embed_metadata_from_dicoms (bids , item_dicoms , outname , outname_bids ,
313
+ embed_metadata_from_dicoms (bids_options , item_dicoms , outname , outname_bids ,
314
314
prov_file , scaninfo , tempdirs , with_prov ,
315
315
min_meta )
316
316
if scaninfo and op .exists (scaninfo ):
@@ -326,16 +326,17 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
326
326
custom_callable (* item )
327
327
328
328
329
- def convert_dicom (item_dicoms , bids , prefix ,
329
+ def convert_dicom (item_dicoms , bids_options , prefix ,
330
330
outdir , tempdirs , symlink , overwrite ):
331
331
"""Save DICOMs as output (default is by symbolic link)
332
332
333
333
Parameters
334
334
----------
335
335
item_dicoms : list of filenames
336
336
DICOMs to save
337
- bids : bool
338
- Save to BIDS format
337
+ bids_options : list or None
338
+ If not None then save to BIDS format. List may be empty
339
+ or contain bids specific options
339
340
prefix : string
340
341
Conversion outname
341
342
outdir : string
@@ -352,7 +353,7 @@ def convert_dicom(item_dicoms, bids, prefix,
352
353
-------
353
354
None
354
355
"""
355
- if bids :
356
+ if bids_options is not None :
356
357
# mimic the same hierarchy location as the prefix
357
358
# although it could all have been done probably
358
359
# within heuristic really
@@ -383,7 +384,7 @@ def convert_dicom(item_dicoms, bids, prefix,
383
384
shutil .copyfile (filename , outfile )
384
385
385
386
386
- def nipype_convert (item_dicoms , prefix , with_prov , bids , tmpdir , dcmconfig = None ):
387
+ def nipype_convert (item_dicoms , prefix , with_prov , bids_options , tmpdir , dcmconfig = None ):
387
388
"""
388
389
Converts DICOMs grouped from heuristic using Nipype's Dcm2niix interface.
389
390
@@ -395,8 +396,9 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir, dcmconfig=None)
395
396
Heuristic output path
396
397
with_prov : Bool
397
398
Store provenance information
398
- bids : Bool
399
- Output BIDS sidecar JSONs
399
+ bids_options : List or None
400
+ If not None then output BIDS sidecar JSONs
401
+ List may contain bids specific options
400
402
tmpdir : Directory
401
403
Conversion working directory
402
404
dcmconfig : File (optional)
@@ -425,7 +427,7 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir, dcmconfig=None)
425
427
convertnode .inputs .terminal_output = 'allatonce'
426
428
else :
427
429
convertnode .terminal_output = 'allatonce'
428
- convertnode .inputs .bids_format = bids
430
+ convertnode .inputs .bids_format = bids_options is not None
429
431
eg = convertnode .run ()
430
432
431
433
# prov information
@@ -439,7 +441,7 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir, dcmconfig=None)
439
441
return eg , prov_file
440
442
441
443
442
- def save_converted_files (res , item_dicoms , bids , outtype , prefix , outname_bids , overwrite ):
444
+ def save_converted_files (res , item_dicoms , bids_options , outtype , prefix , outname_bids , overwrite ):
443
445
"""Copy converted files from tempdir to output directory.
444
446
Will rename files if necessary.
445
447
@@ -449,8 +451,9 @@ def save_converted_files(res, item_dicoms, bids, outtype, prefix, outname_bids,
449
451
Nipype conversion Node with results
450
452
item_dicoms: list of filenames
451
453
DICOMs converted
452
- bids : bool
453
- Option to save to BIDS
454
+ bids : list or None
455
+ If not list save to BIDS
456
+ List may contain bids specific options
454
457
prefix : string
455
458
456
459
Returns
@@ -481,7 +484,7 @@ def save_converted_files(res, item_dicoms, bids, outtype, prefix, outname_bids,
481
484
# dwi etc which might spit out multiple files
482
485
483
486
suffixes = ([str (i + 1 ) for i in range (len (res_files ))]
484
- if bids else None )
487
+ if ( bids_options is not None ) else None )
485
488
486
489
if not suffixes :
487
490
lgr .warning ("Following series files likely have "
0 commit comments