Skip to content

DIA Windows

tdfpy.DiaWindow dataclass

DiaWindow(
    _timsdata: TimsData,
    window_index: int,
    window_group: int,
    scan_num_begin: int,
    scan_num_end: int,
    isolation_mz: float,
    isolation_width: float,
    collision_energy: float,
    frame_id: int,
    rt: float,
    polarity: Polarity,
)

Bases: DiaWindowGroup, _TdfData

A DIA isolation window bound to a specific frame.

Extends DiaWindowGroup with per-frame context (frame_id, rt, polarity). Provides raw and centroided spectrum access and ion mobility conversion properties.

frame_id instance-attribute

frame_id: int

Frame ID this window belongs to.

rt instance-attribute

rt: float

Retention time of the parent frame in seconds.

polarity instance-attribute

polarity: Polarity

Ion polarity.

peaks property

peaks: list[npt.NDArray[np.float64]]

Read raw peaks for this DIA window and return as list of (mz, intensity) arrays.

centroid

centroid(
    mz_tolerance: float = 8,
    mz_tolerance_type: Literal["ppm", "da"] = "ppm",
    im_tolerance: float = 0.05,
    im_tolerance_type: Literal[
        "relative", "absolute"
    ] = "relative",
    min_peaks: int = 3,
    max_peaks: int | None = None,
    noise_filter=None,
    ion_mobility_type: Literal[
        "ccs", "ook0", "voltage"
    ] = "ook0",
) -> np.ndarray

Centroid the spectrum for this DIA window using the specified parameters.

Source code in src/tdfpy/elems.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
def centroid(
    self,
    mz_tolerance: float = 8,
    mz_tolerance_type: Literal["ppm", "da"] = "ppm",
    im_tolerance: float = 0.05,
    im_tolerance_type: Literal["relative", "absolute"] = "relative",
    min_peaks: int = 3,
    max_peaks: int | None = None,
    noise_filter=None,
    ion_mobility_type: Literal["ccs", "ook0", "voltage"] = "ook0",
) -> np.ndarray:
    """Centroid the spectrum for this DIA window using the specified parameters."""
    get_spectrum = partial(
        get_centroided_spectrum,
        self.timsdata,
        frame_id=self.frame_id,
        spectrum_index=None,
        ion_mobility_type=ion_mobility_type,
        mz_tolerance=mz_tolerance,
        mz_tolerance_type=mz_tolerance_type,
        im_tolerance=im_tolerance,
        im_tolerance_type=im_tolerance_type,
        min_peaks=min_peaks,
        max_peaks=max_peaks,
        noise_filter=noise_filter,
    )

    try:
        return get_spectrum(use_numba=True)
    except Exception:
        warnings.warn(
            f"Numba centroiding failed for frame {self.frame_id}. Falling back to Python implementation.",
            UserWarning,
            stacklevel=2,
        )
        return get_spectrum(use_numba=False)

tdfpy.DiaWindowGroup dataclass

DiaWindowGroup(
    window_index: int,
    window_group: int,
    scan_num_begin: int,
    scan_num_end: int,
    isolation_mz: float,
    isolation_width: float,
    collision_energy: float,
)

A DIA isolation window definition (shared across frames in the same group).

Defines the m/z isolation range, mobility scan range, and collision energy for one window within a DIA window group. DiaWindow extends this with per-frame fields (frame_id, rt, polarity).

Field Type Description
window_index int Index of this window within its group
window_group int Window group ID
scan_num_begin int First mobility scan (inclusive)
scan_num_end int Last mobility scan (inclusive)
isolation_mz float Isolation window center m/z
isolation_width float Isolation window width in Th
collision_energy float Collision energy in eV