Skip to content

Incorrect sorting of acquisitions due to lexicographical comparison of AcquisitionTime #358

@msohlin

Description

@msohlin

I have identified a sorting issue in dcm2bids that affects run ordering when multiple dynamic acquisitions are present (e.g. DCE series).

The problem appears to originate in sidecar.py, specifically in the Sidecar.lt() method, where sidecars are compared using:

self.compKeys = ["AcquisitionTime", "SeriesNumber", "SidecarFilename"]

The comparison of AcquisitionTime is currently performed as a string comparison

self.data.get(key) < other.data.get(key)

This leads to incorrect ordering when seconds are not zero-padded in the JSON.

Example:

Two sidecars:

AcquisitionTime: "08:39:12.180000" AcquisitionTime: "08:39:6.332500"

Lexicographical comparison gives:

"08:39:12.180000" < "08:39:6.332500" → True

This is incorrect chronologically, because 6 seconds occurs before 12 seconds.

As a result, dynamic runs are misordered during sidecar.build_acquisitions, which then affects run numbering.

Environment

  • dcm2bids version: 3.2.0
  • dcm2niix version: v1.0.20250505
  • Python: 3.9.21
  • OS: Ubuntu 22.04 (VirtualBox)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions