@@ -386,7 +386,7 @@ def _assign_dicom_time(ti):
386
386
return outtar
387
387
388
388
389
- def embed_nifti (dcmfiles , niftifile , infofile , bids_info , min_meta ):
389
+ def embed_nifti (dcmfiles , niftifile , infofile , bids_info ):
390
390
"""
391
391
392
392
If `niftifile` doesn't exist, it gets created out of the `dcmfiles` stack,
@@ -403,7 +403,6 @@ def embed_nifti(dcmfiles, niftifile, infofile, bids_info, min_meta):
403
403
niftifile
404
404
infofile
405
405
bids_info
406
- min_meta
407
406
408
407
Returns
409
408
-------
@@ -416,44 +415,31 @@ def embed_nifti(dcmfiles, niftifile, infofile, bids_info, min_meta):
416
415
import json
417
416
import re
418
417
419
- if not min_meta :
420
- from heudiconv .external .dcmstack import ds
421
- stack = ds .parse_and_stack (dcmfiles , force = True ).values ()
422
- if len (stack ) > 1 :
423
- raise ValueError ('Found multiple series' )
424
- # may be odict now - iter to be safe
425
- stack = next (iter (stack ))
426
-
427
- # Create the nifti image using the data array
428
- if not op .exists (niftifile ):
429
- nifti_image = stack .to_nifti (embed_meta = True )
430
- nifti_image .to_filename (niftifile )
431
- return ds .NiftiWrapper (nifti_image ).meta_ext .to_json ()
432
-
433
- orig_nii = nb .load (niftifile )
434
- aff = orig_nii .affine
435
- ornt = nb .orientations .io_orientation (aff )
436
- axcodes = nb .orientations .ornt2axcodes (ornt )
437
- new_nii = stack .to_nifti (voxel_order = '' .join (axcodes ), embed_meta = True )
438
- meta = ds .NiftiWrapper (new_nii ).meta_ext .to_json ()
439
-
440
- meta_info = None if min_meta else json .loads (meta )
418
+ from heudiconv .external .dcmstack import ds
419
+ stack = ds .parse_and_stack (dcmfiles , force = True ).values ()
420
+ if len (stack ) > 1 :
421
+ raise ValueError ('Found multiple series' )
422
+ # may be odict now - iter to be safe
423
+ stack = next (iter (stack ))
424
+
425
+ # Create the nifti image using the data array
426
+ if not op .exists (niftifile ):
427
+ nifti_image = stack .to_nifti (embed_meta = True )
428
+ nifti_image .to_filename (niftifile )
429
+ return ds .NiftiWrapper (nifti_image ).meta_ext .to_json ()
430
+
431
+ orig_nii = nb .load (niftifile )
432
+ aff = orig_nii .affine
433
+ ornt = nb .orientations .io_orientation (aff )
434
+ axcodes = nb .orientations .ornt2axcodes (ornt )
435
+ new_nii = stack .to_nifti (voxel_order = '' .join (axcodes ), embed_meta = True )
436
+ meta_info = ds .NiftiWrapper (new_nii ).meta_ext .to_json ()
441
437
442
438
if bids_info :
439
+ # make nice with python 3 - same behavior?
440
+ meta_info = meta_info .copy ()
441
+ meta_info .update (bids_info )
443
442
444
- if min_meta :
445
- meta_info = bids_info
446
- else :
447
- # make nice with python 3 - same behavior?
448
- meta_info = meta_info .copy ()
449
- meta_info .update (bids_info )
450
- # meta_info = dict(meta_info.items() + bids_info.items())
451
- try :
452
- meta_info ['TaskName' ] = re .search (
453
- r'(?<=_task-)\w+' , op .basename (infofile )
454
- ).group (0 ).split ('_' )[0 ]
455
- except AttributeError :
456
- pass
457
443
# write to outfile
458
444
with open (infofile , 'wt' ) as fp :
459
445
json .dump (meta_info , fp , indent = 3 , sort_keys = True )
@@ -462,8 +448,7 @@ def embed_nifti(dcmfiles, niftifile, infofile, bids_info, min_meta):
462
448
463
449
464
450
def embed_metadata_from_dicoms (bids_options , item_dicoms , outname , outname_bids ,
465
- prov_file , scaninfo , tempdirs , with_prov ,
466
- min_meta ):
451
+ prov_file , scaninfo , tempdirs , with_prov ):
467
452
"""
468
453
Enhance sidecar information file with more information from DICOMs
469
454
@@ -477,7 +462,6 @@ def embed_metadata_from_dicoms(bids_options, item_dicoms, outname, outname_bids,
477
462
scaninfo
478
463
tempdirs
479
464
with_prov
480
- min_meta
481
465
482
466
Returns
483
467
-------
@@ -490,14 +474,13 @@ def embed_metadata_from_dicoms(bids_options, item_dicoms, outname, outname_bids,
490
474
item_dicoms = list (map (op .abspath , item_dicoms ))
491
475
492
476
embedfunc = Node (Function (input_names = ['dcmfiles' , 'niftifile' , 'infofile' ,
493
- 'bids_info' , 'min_meta' ],
477
+ 'bids_info' ,],
494
478
output_names = ['outfile' , 'meta' ],
495
479
function = embed_nifti ),
496
480
name = 'embedder' )
497
481
embedfunc .inputs .dcmfiles = item_dicoms
498
482
embedfunc .inputs .niftifile = op .abspath (outname )
499
483
embedfunc .inputs .infofile = op .abspath (scaninfo )
500
- embedfunc .inputs .min_meta = min_meta
501
484
embedfunc .inputs .bids_info = load_json (op .abspath (outname_bids )) if (bids_options is not None ) else None
502
485
embedfunc .base_dir = tmpdir
503
486
cwd = os .getcwd ()
0 commit comments