9
9
from pathlib import Path
10
10
import sys
11
11
import tarfile
12
- from typing import TYPE_CHECKING , Any , Dict , List , NamedTuple , Optional , Union , overload
12
+ from typing import TYPE_CHECKING , Any , Dict , Hashable , List , NamedTuple , Optional , Union , overload
13
+ from typing_extensions import Protocol
13
14
from unittest .mock import patch
14
15
import warnings
15
16
42
43
compresslevel = 9
43
44
44
45
45
- def create_seqinfo (mw : dw .Wrapper , series_files : list [str ], series_id : str ) -> SeqInfo :
46
+ class CustomSeqinfoT (Protocol ):
47
+ def __call__ (self , wrapper : dw .Wrapper , series_files : list [str ]) -> Hashable : ...
48
+
49
+
50
+ def create_seqinfo (
51
+ mw : dw .Wrapper ,
52
+ series_files : list [str ],
53
+ series_id : str ,
54
+ custom_seqinfo : CustomSeqinfoT | None = None ,
55
+ ) -> SeqInfo :
46
56
"""Generate sequence info
47
57
48
58
Parameters
@@ -109,6 +119,9 @@ def create_seqinfo(mw: dw.Wrapper, series_files: list[str], series_id: str) -> S
109
119
date = dcminfo .get ("AcquisitionDate" ),
110
120
series_uid = dcminfo .get ("SeriesInstanceUID" ),
111
121
time = dcminfo .get ("AcquisitionTime" ),
122
+ custom =
123
+ custom_seqinfo (wrapper = mw , series_files = series_files )
124
+ if custom_seqinfo else None ,
112
125
)
113
126
114
127
@@ -199,6 +212,7 @@ def group_dicoms_into_seqinfos(
199
212
dict [SeqInfo , list [str ]],
200
213
]
201
214
| None = None ,
215
+ custom_seqinfo : CustomSeqinfoT | None = None ,
202
216
) -> dict [SeqInfo , list [str ]]:
203
217
...
204
218
@@ -215,6 +229,7 @@ def group_dicoms_into_seqinfos(
215
229
dict [SeqInfo , list [str ]],
216
230
]
217
231
| None = None ,
232
+ custom_seqinfo : CustomSeqinfoT | None = None ,
218
233
) -> dict [Optional [str ], dict [SeqInfo , list [str ]]] | dict [SeqInfo , list [str ]]:
219
234
"""Process list of dicoms and return seqinfo and file group
220
235
`seqinfo` contains per-sequence extract of fields from DICOMs which
@@ -236,9 +251,11 @@ def group_dicoms_into_seqinfos(
236
251
Creates a flattened `seqinfo` with corresponding DICOM files. True when
237
252
invoked with `dicom_dir_template`.
238
253
custom_grouping: str or callable, optional
239
- grouping key defined within heuristic. Can be a string of a
240
- DICOM attribute, or a method that handles more complex groupings.
241
-
254
+ grouping key defined within heuristic. Can be a string of a
255
+ DICOM attribute, or a method that handles more complex groupings.
256
+ custom_seqinfo: callable, optional
257
+ A callable which will be provided MosaicWrapper giving possibility to
258
+ extract any custom DICOM metadata of interest.
242
259
243
260
Returns
244
261
-------
@@ -358,7 +375,7 @@ def group_dicoms_into_seqinfos(
358
375
else :
359
376
# nothing to see here, just move on
360
377
continue
361
- seqinfo = create_seqinfo (mw , series_files , series_id_str )
378
+ seqinfo = create_seqinfo (mw , series_files , series_id_str , custom_seqinfo )
362
379
363
380
key : Optional [str ]
364
381
if per_studyUID :
0 commit comments