Skip to content

Instantly share code, notes, and snippets.

@WillForan
Created June 2, 2020 02:27
Show Gist options
  • Save WillForan/d7dbcf83011d83b531ecb3f4519ab828 to your computer and use it in GitHub Desktop.
Save WillForan/d7dbcf83011d83b531ecb3f4519ab828 to your computer and use it in GitHub Desktop.
[heudiconv] MIA: bvec+bval
import os
def create_key(template, outtype=('nii.gz',), annotation_classes=None):
if template is None or not template:
raise ValueError('Template must be a valid format string')
return template, outtype, annotation_classes
def infotodict(seqinfo):
t1w = create_key('sub-{subject}/anat/sub-{subject}_T1w')
dwi = create_key('sub-{subject}/dwi/sub-{subject}_run-{item:01d}_dwi')
mag = create_key('sub-{subject}/fmap/sub-{subject}_run-{item:01d}_magnitude')
phase = create_key('sub-{subject}/fmap/sub-{subject}_run-{item:01d}_phase1')
info = {t1w: [], dwi: [], mag: [], phase: []}
for s in seqinfo:
if('tfl-multiecho' in s.protocol_name) and\
(s.dim3 == 176) and (s.dim4 == 1):
# assume last one is always the best
info[t1w] = [s.series_id]
elif ('diff113' in s.protocol_name) and\
(s.dim3 == 66) and (s.dim4 == 113):
info[dwi].append(s.series_id)
elif ('gre_field_mapping' in s.protocol_name) and (s.dim3 == 120):
info[mag].append(s.series_id)
elif ('gre_field_mapping' in s.protocol_name) and (s.dim3 == 60):
info[phase].append(s.series_id)
else:
print(f"no match for {s.protocol_name} {s.series_id} {s.dim3} {s.dim4}")
return info
d2n
d2n/sub-11354_run-1_dwi.bval
d2n/sub-11354_run-1_dwi.bvec
d2n/sub-11354_run-1_dwi.json
d2n/sub-11354_run-1_dwi.nii.gz
bids_out_local
bids_out_local/.heudiconv
bids_out_local/.heudiconv/11354
bids_out_local/.heudiconv/11354/info
bids_out_local/.heudiconv/11354/info/11354.auto.txt
bids_out_local/.heudiconv/11354/info/11354.edit.txt
bids_out_local/.heudiconv/11354/info/dicominfo.tsv
bids_out_local/.heudiconv/11354/info/filegroup.json
bids_out_local/.heudiconv/11354/info/heuristic.py
bids_out_local/CHANGES
bids_out_local/dataset_description.json
bids_out_local/participants.json
bids_out_local/participants.tsv
bids_out_local/README
bids_out_local/sub-11354
bids_out_local/sub-11354/dwi
bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi.json
bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi.nii.gz
bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi_prov.ttl
bids_out_local/sub-11354/sub-11354_scans.json
bids_out_local/sub-11354/sub-11354_scans.tsv
ho "# Filelist"
find d2n bids_out* | tee files.ls
#22:25:34 rhea:/Volumes/Phillips/P5/scripts/bids_test
./testme.bash |tee stdout.log
# DOCKER
INFO: Running heudiconv version 0.8.0 latest 0.8.0
INFO: Need to process 1 study sessions
INFO: PROCESSING STARTS: {'subject': '11354', 'outdir': '/out/', 'session': None}
INFO: Processing 113 dicoms
INFO: Reloading existing filegroup.json because /out/.heudiconv/11354/info/11354.edit.txt exists
INFO: Doing conversion using dcm2niix
INFO: Converting /out/sub-11354/dwi/sub-11354_run-1_dwi (113 DICOMs) -> /out/sub-11354/dwi . Converter: dcm2niix . Output types: ('nii.gz',)
Traceback (most recent call last):
File "/opt/miniconda-latest/bin/heudiconv", line 11, in <module>
load_entry_point('heudiconv', 'console_scripts', 'heudiconv')()
File "/src/heudiconv/heudiconv/cli/run.py", line 134, in main
process_args(args)
File "/src/heudiconv/heudiconv/cli/run.py", line 352, in process_args
grouping=args.grouping,)
File "/src/heudiconv/heudiconv/convert.py", line 211, in prep_conversion
dcmconfig=dcmconfig,)
File "/src/heudiconv/heudiconv/convert.py", line 324, in convert
% (outname)
RuntimeError: was asked to convert into /out/sub-11354/dwi/sub-11354_run-1_dwi.nii.gz but destination already exists
# Local
INFO: Running heudiconv version 0.8.0 latest 0.8.0
INFO: Need to process 1 study sessions
INFO: PROCESSING STARTS: {'subject': '11354', 'outdir': '/Volumes/Phillips/P5/scripts/bids_test/bids_out_local/', 'session': None}
INFO: Processing 113 dicoms
INFO: Analyzing 113 dicoms
INFO: Generated sequence info for 1 studies with 113 entries total
INFO: Doing conversion using dcm2niix
INFO: Converting /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi (113 DICOMs) -> /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi . Converter: dcm2niix . Output types: ('nii.gz',)
200601-22:25:59,933 nipype.workflow INFO:
[Node] Setting-up "convert" in "/tmp/dcm2niixm0swv4jf/convert".
INFO: [Node] Setting-up "convert" in "/tmp/dcm2niixm0swv4jf/convert".
200601-22:26:01,264 nipype.workflow INFO:
[Node] Running "convert" ("nipype.interfaces.dcm2nii.Dcm2niix"), a CommandLine Interface with command:
dcm2niix -b y -z y -x n -t n -m n -f /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi -o . -s n -v n /tmp/dcm2niixm0swv4jf/convert
INFO: [Node] Running "convert" ("nipype.interfaces.dcm2nii.Dcm2niix"), a CommandLine Interface with command:
dcm2niix -b y -z y -x n -t n -m n -f /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi -o . -s n -v n /tmp/dcm2niixm0swv4jf/convert
200601-22:26:02,179 nipype.interface INFO:
stdout 2020-06-01T22:26:02.179697:Chris Rorden's dcm2niiX version v1.0.20190902 (JP2:OpenJPEG) GCC8.3.0 (64-bit Linux)
INFO: stdout 2020-06-01T22:26:02.179697:Chris Rorden's dcm2niiX version v1.0.20190902 (JP2:OpenJPEG) GCC8.3.0 (64-bit Linux)
200601-22:26:02,180 nipype.interface INFO:
stdout 2020-06-01T22:26:02.179697:Found 113 DICOM file(s)
INFO: stdout 2020-06-01T22:26:02.179697:Found 113 DICOM file(s)
200601-22:26:02,180 nipype.interface INFO:
stdout 2020-06-01T22:26:02.179697:CSA slice timing based on 2nd volume, 1st volume corrupted (CMRR bug, range 0..20697.5, TR=4161 ms)
INFO: stdout 2020-06-01T22:26:02.179697:CSA slice timing based on 2nd volume, 1st volume corrupted (CMRR bug, range 0..20697.5, TR=4161 ms)
200601-22:26:02,180 nipype.interface INFO:
stdout 2020-06-01T22:26:02.179697:Convert 113 DICOM as ./Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi (128x128x66x113)
INFO: stdout 2020-06-01T22:26:02.179697:Convert 113 DICOM as ./Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi (128x128x66x113)
INFO: stdout 2020-06-01T22:26:03.160032:Compress: "/usr/bin/pigz" -b 960 -n -f -6 "./Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi.nii"
200601-22:26:03,160 nipype.interface INFO:
stdout 2020-06-01T22:26:03.160032:Compress: "/usr/bin/pigz" -b 960 -n -f -6 "./Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi.nii"
200601-22:26:03,160 nipype.interface INFO:
stdout 2020-06-01T22:26:03.160032:Conversion required 1.571929 seconds (0.603903 for core code).
INFO: stdout 2020-06-01T22:26:03.160032:Conversion required 1.571929 seconds (0.603903 for core code).
INFO: [Node] Finished "convert".
200601-22:26:03,450 nipype.workflow INFO:
[Node] Finished "convert".
WARNING: Failed to find task field in /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi.json.
INFO: [Node] Setting-up "embedder" in "/tmp/embedmetaoo63kdpp/embedder".
200601-22:26:04,452 nipype.workflow INFO:
[Node] Setting-up "embedder" in "/tmp/embedmetaoo63kdpp/embedder".
INFO: [Node] Running "embedder" ("nipype.interfaces.utility.wrappers.Function")
200601-22:26:06,64 nipype.workflow INFO:
[Node] Running "embedder" ("nipype.interfaces.utility.wrappers.Function")
WARNING: [Node] Error on "embedder" (/tmp/embedmetaoo63kdpp/embedder)
200601-22:26:14,856 nipype.workflow WARNING:
[Node] Error on "embedder" (/tmp/embedmetaoo63kdpp/embedder)
ERROR: Embedding failed: 'NoneType' object is not subscriptable
INFO: Post-treating /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/sub-11354/dwi/sub-11354_run-1_dwi.json file
INFO: Lock 140105832424952 acquired on /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/heudiconv.lock
INFO: Populating template files under /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/
INFO: Lock 140105832424952 released on /Volumes/Phillips/P5/scripts/bids_test/bids_out_local/heudiconv.lock
INFO: PROCESSING DONE: {'subject': '11354', 'outdir': '/Volumes/Phillips/P5/scripts/bids_test/bids_out_local/', 'session': None}
# DCM2NII
#!/usr/bin/env bash
echo "# DOCKER"
docker run --rm -it -v $(pwd):/in -v bids_out:/out nipy/heudiconv:latest \
-b -o out \
-c dcm2niix \
-d '/in/{subject}*/*/*' \
-f '/in/bids_heuristic.py' \
-p $@\
-s 11354
echo "# Local"
heudiconv \
-b -o bids_out_local \
-c dcm2niix \
-d '{subject}*/*/*' \
-f 'bids_heuristic.py' \
-p $@ \
-s 11354
echo "# DCM2NII"
test ! -d d2n && mkdir $_
[ ! -r d2n/sub-11354_run-1_dwi.nii.gz ] &&
dcm2niix -b y -z y -x n -t n -m n -f sub-11354_run-1_dwi -o d2n -s n -v n 11354/diff113_current_PA_1152x1152.16/
echo "# Filelist"
find d2n bids_out* | tee files.ls
@jrad1
Copy link

jrad1 commented Oct 15, 2020

Dear WillForan,

When I execute docker run nipy/heudiconv:latest -c dcm2niix ..., I have the same warnings and errors as you, from "WARNING: Failed to find task field" to "ERROR: Embedding failed: 'NoneType'". Do you know how to overcome them?

With best wishes,

J

@WillForan
Copy link
Author

this gist was attached to the issue on nipy/heudiconv#38

I think I gave up and ran dcm2niix manually for the dwi sequences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment