m3resp.link_breaths_by_time#
- m3resp.link_breaths_by_time(breaths_by_modality=None, *, time_tolerance=0.5)[source]#
Group breaths across modalities by their timing in seconds.
Each breath is used once. Its representative time is
extremum_timewhen available, otherwise the midpoint of start/end. Modalities are visited in mapping order, with each modality’s breaths sorted by this time. For each unassigned breath, the closest unused breath from each other modality is added if it falls within time_tolerance of that breath. For equal distances, the first match in sorted order is used.- Parameters:
breaths_by_modality (Mapping[str, Sequence[BreathEvent] | None] | None) – Modality names mapped to breath sequences or None. Breath times must share a time axis. None gives an empty result.
time_tolerance (float) – Maximum time difference in seconds from the breath that starts a group; must be at least zero.
- Returns:
- Groups ordered by the representative time of their
first breath, containing the original breath objects. Unmatched breaths form single-modality groups with confidence=None. Matched groups have confidence
1 - largest_time_difference/tolerance; exact matches with zero tolerance have confidence=1.
- Return type:
- Raises:
ValueError – If time_tolerance is negative.