@@ -151,8 +151,8 @@ def group_dicoms_into_seqinfos(files, grouping, file_filter=None,
151
151
flatten : bool, optional
152
152
Creates a flattened `seqinfo` with corresponding DICOM files. True when
153
153
invoked with `dicom_dir_template`.
154
- custom_grouping: variable or method , optional
155
- ` grouping` variable defined within heuristic. Can be a string of a
154
+ custom_grouping: str or callable , optional
155
+ grouping key defined within heuristic. Can be a string of a
156
156
DICOM attribute, or a method that handles more complex groupings.
157
157
158
158
@@ -183,6 +183,8 @@ def group_dicoms_into_seqinfos(files, grouping, file_filter=None,
183
183
nfl_before - nfl_after ))
184
184
185
185
if grouping == 'custom' :
186
+ if custom_grouping is None :
187
+ raise RuntimeError ("Custom grouping is not defined in heuristic" )
186
188
if callable (custom_grouping ):
187
189
return custom_grouping (files , dcmfilter , SeqInfo )
188
190
grouping = custom_grouping
@@ -255,13 +257,13 @@ def group_dicoms_into_seqinfos(files, grouping, file_filter=None,
255
257
seqinfo = create_seqinfo (mw , series_files , series_id )
256
258
257
259
if per_studyUID :
258
- key = studyUID . split ( '.' )[ - 1 ]
260
+ key = studyUID
259
261
elif grouping == 'accession_number' :
260
- key = accession_number = mw .dcm_data .get ("AccessionNumber" )
262
+ key = mw .dcm_data .get ("AccessionNumber" )
261
263
elif grouping == 'all' :
262
264
key = 'all'
263
265
elif custom_grouping :
264
- key = custom = mw .dcm_data .get (custom_grouping )
266
+ key = mw .dcm_data .get (custom_grouping )
265
267
else :
266
268
key = ''
267
269
lgr .debug ("%30s %30s %27s %27s %5s nref=%-2d nsrc=%-2d %s" % (
@@ -276,22 +278,9 @@ def group_dicoms_into_seqinfos(files, grouping, file_filter=None,
276
278
))
277
279
278
280
if not flatten :
279
- if per_studyUID :
280
- if studyUID not in seqinfos :
281
- seqinfos [studyUID ] = OrderedDict ()
282
- seqinfos [studyUID ][seqinfo ] = series_files
283
- elif grouping == 'accession_number' :
284
- if accession_number not in seqinfos :
285
- seqinfos [accession_number ] = OrderedDict ()
286
- seqinfos [accession_number ][seqinfo ] = series_files
287
- elif grouping == 'all' :
288
- if 'all' not in seqinfos :
289
- seqinfos ['all' ] = OrderedDict ()
290
- seqinfos ['all' ][seqinfo ] = series_files
291
- elif custom_grouping :
292
- if custom not in seqinfos :
293
- seqinfos [custom ] = OrderedDict ()
294
- seqinfos [custom ][seqinfo ] = series_files
281
+ if key not in seqinfos :
282
+ seqinfos [key ] = OrderedDict ()
283
+ seqinfos [key ][seqinfo ] = series_files
295
284
else :
296
285
seqinfos [seqinfo ] = series_files
297
286
0 commit comments