Skip to content

Commit 803bbaf

Browse files
bpinsardyarikoptic
authored andcommitted
add a check for hashable custom_info, link to new doc section
1 parent a37e276 commit 803bbaf

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

docs/heuristics.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ or::
119119
...
120120
return seqinfos # ordered dict containing seqinfo objects: list of DICOMs
121121

122+
---------------------------------------------------------------
123+
``custom_seqinfo(series_files, wrapper)``
124+
---------------------------------------------------------------
125+
If present this function will be called on eacg group of dicoms with
126+
a sample nibabel dicom wrapper to extract additional information
127+
to be used in ``infotodict``.
128+
129+
Importantly the return value of that function needs to be hashable.
130+
For instance the following non-hashable types can be converted to an alternative
131+
hashable type:
132+
- list > tuple
133+
- dict > frozendict
134+
- arrays > bytes (tobytes(), or pickle.dumps), str or tuple of tuples.
122135

123136
-------------------------------
124137
``POPULATE_INTENDED_FOR_OPTS``

heudiconv/dicoms.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def create_seqinfo(
9090
global total_files
9191
total_files += len(series_files)
9292

93+
custom_seqinfo_data = custom_seqinfo(wrapper=mw, series_files=series_files) \
94+
if custom_seqinfo else None
95+
try:
96+
hash(custom_seqinfo_data)
97+
except TypeError:
98+
raise RuntimeError("Data returned by the heuristics custom_seqinfo is not hashable. "
99+
"See https://heudiconv.readthedocs.io/en/latest/heuristics.html#custom_seqinfo for more "
100+
"details.")
101+
93102
return SeqInfo(
94103
total_files_till_now=total_files,
95104
example_dcm_file=op.basename(series_files[0]),
@@ -119,9 +128,7 @@ def create_seqinfo(
119128
date=dcminfo.get("AcquisitionDate"),
120129
series_uid=dcminfo.get("SeriesInstanceUID"),
121130
time=dcminfo.get("AcquisitionTime"),
122-
custom =
123-
custom_seqinfo(wrapper=mw, series_files=series_files)
124-
if custom_seqinfo else None,
131+
custom=custom_seqinfo_data,
125132
)
126133

127134

0 commit comments

Comments
 (0)