DOSMA
DOSMA copied to clipboard
Allow `group_by` and `sort_by` to take a list of tags
For some DICOM datasets I would like to order the slices based on multiple tags. For example, in a dataset with a TemporalPositionIdentifier
present, I would like to sort by ImagePositionPatient
first, and then using the position identifier. The same applies to group_by too.
Preferably, it would be nice to add support for ascending/descending sorts for each tag too:
# single tag
dm.read(path, sort_by="InstanceNumber")
# multiple tags
dm.read(path, sort_by=["ImagePositionPatient", "TemporalPositionIdentifier"])
# multiple tags + order
dm.read(path, sort_by=[{ "tag": "ImagePositionPatient", "asc": True }, { "tag": "TemporalPositionIdentifier", "asc": False }])
NB: maybe we should consider to set the default sort_by
to ImagePositionPatient
.
DOSMA supports multi-tag sorting/group_by - https://github.com/ad12/DOSMA/blob/bd5efecbb944263c9a5d7853f154d9071c72ba62/dosma/core/io/dicom_io.py#L83-L84
For arguments to sort_by
, it may be easier to specify a sort_key
argument that allows the user to customize their sorting algorithm
Default for sort_by
is InstanceNumber
because 1) it is the default value to sort by when writing dicoms and 2) it is scalar value that is easier to sort by. It is unclear what sorting by position would mean in cases where all coordinates in the position are changing (e.g. oblique scans)
DOSMA supports multi-tag sorting/group_by -
Ha. Maybe an option for a callback would be nice for users to define their own sorting algo. Is that what you meant with sort_key
?
Default for
sort_by
isInstanceNumber
because 1) it is the default value to sort by when writing dicoms and 2) it is scalar value that is easier to sort by. It is unclear what sorting by position would mean in cases where all coordinates in the position are changing (e.g. oblique scans)
The problem with InstanceNumber
is, that doesn't have to correlate with slice position at all. DICOM does not enforce that in the standard IIRC. I'll look into other implementations, but I'm pretty sure most of them use ImagePositionPatient
+ ImageOrientationPatient
.