Skip to content

Commit f1d2a08

Browse files
committed
ENH: custom_seqinfo - provide a way for heuristics to extract/add arbitrary value
Just a draft implementation
1 parent 8a96064 commit f1d2a08

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

heudiconv/convert.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
175175
file_filter=getattr(heuristic, 'filter_files', None),
176176
dcmfilter=getattr(heuristic, 'filter_dicom', None),
177177
flatten=True,
178-
custom_grouping=getattr(heuristic, 'grouping', None))
178+
custom_grouping=getattr(heuristic, 'grouping', None),
179+
# callable which will be provided dcminfo and returned
180+
# structure extend seqinfo
181+
custom_seqinfo=getattr(heuristic, 'custom_seqinfo', None),
182+
)
179183

180184
seqinfo_list = list(seqinfo.keys())
181185
filegroup = {si.series_id: x for si, x in seqinfo.items()}

heudiconv/dicoms.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
total_files = 0
2525

2626

27-
def create_seqinfo(mw, series_files, series_id):
27+
def create_seqinfo(mw, series_files, series_id, custom_seqinfo=None):
2828
"""Generate sequence info
2929
3030
Parameters
@@ -91,6 +91,9 @@ def create_seqinfo(mw, series_files, series_id):
9191
date=dcminfo.get('AcquisitionDate'),
9292
series_uid=dcminfo.get('SeriesInstanceUID'),
9393
time=dcminfo.get('AcquisitionTime'),
94+
custom=
95+
custom_seqinfo(wrapper=mw, series_files=series_files)
96+
if custom_seqinfo else None,
9497
)
9598
return seqinfo
9699

@@ -138,7 +141,9 @@ def validate_dicom(fl, dcmfilter):
138141

139142
def group_dicoms_into_seqinfos(files, grouping, file_filter=None,
140143
dcmfilter=None, flatten=False,
141-
custom_grouping=None):
144+
custom_grouping=None,
145+
custom_seqinfo=None,
146+
):
142147
"""Process list of dicoms and return seqinfo and file group
143148
`seqinfo` contains per-sequence extract of fields from DICOMs which
144149
will be later provided into heuristics to decide on filenames
@@ -159,9 +164,11 @@ def group_dicoms_into_seqinfos(files, grouping, file_filter=None,
159164
Creates a flattened `seqinfo` with corresponding DICOM files. True when
160165
invoked with `dicom_dir_template`.
161166
custom_grouping: str or callable, optional
162-
grouping key defined within heuristic. Can be a string of a
163-
DICOM attribute, or a method that handles more complex groupings.
164-
167+
grouping key defined within heuristic. Can be a string of a
168+
DICOM attribute, or a method that handles more complex groupings.
169+
custom_seqinfo: callable, optional
170+
A callable which will be provided MosaicWrapper giving possibility to
171+
extract any custom DICOM metadata of interest.
165172
166173
Returns
167174
-------
@@ -273,7 +280,8 @@ def group_dicoms_into_seqinfos(files, grouping, file_filter=None,
273280
else:
274281
# nothing to see here, just move on
275282
continue
276-
seqinfo = create_seqinfo(mw, series_files, series_id)
283+
284+
seqinfo = create_seqinfo(mw, series_files, series_id, custom_seqinfo)
277285

278286
if per_studyUID:
279287
key = studyUID

heudiconv/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'date', # 24
4949
'series_uid', # 25
5050
'time', # 26
51+
'custom', # 27
5152
]
5253

5354
SeqInfo = namedtuple('SeqInfo', seqinfo_fields)

0 commit comments

Comments
 (0)