Low-level access¶
Direct access to the two files inside a .d folder: PandasTdf reads the analysis.tdf
SQLite metadata into pandas DataFrames, and TimsData decodes frames from
analysis.tdf_bin in pure Python (no Bruker native library). Prefer the high-level
DDA/DIA/PRM readers unless you need raw frame or scan data.
tdfpy.PandasTdf
dataclass
¶
A class for working with TDF (Bruker Data File) using pandas DataFrames.
calibration_info
property
¶
The 'CalibrationInfo' table as a pandas DataFrame. :return: table as a pandas DataFrame
dia_frame_msms_info
property
¶
The 'DiaFrameMsMsInfo' table as a pandas DataFrame. :return: table as a pandas DataFrame
dia_frame_msms_window_groups
property
¶
The 'DiaFrameMsMsWindowGroups' table as a pandas DataFrame. :return: table as a pandas DataFrame
dia_frame_msms_windows
property
¶
The 'DiaFrameMsMsWindows' table as a pandas DataFrame. :return: table as a pandas DataFrame
error_log
property
¶
The 'ErrorLog' table as a pandas DataFrame. :return: table as a pandas DataFrame
frame_msms_info
property
¶
The 'FrameMsMsInfo' table as a pandas DataFrame. :return: table as a pandas DataFrame
frame_properties
property
¶
The 'FrameProperties' table as a pandas DataFrame. :return: table as a pandas DataFrame
frames
property
¶
The 'Frames' table as a pandas DataFrame. :return: table as a pandas DataFrame
global_metadata
property
¶
The 'GlobalMetadata' table as a pandas DataFrame. :return: table as a pandas DataFrame
group_properties
property
¶
The 'GroupProperties' table as a pandas DataFrame. :return: table as a pandas DataFrame
mz_calibration
property
¶
The 'MzCalibration' table as a pandas DataFrame. :return: table as a pandas DataFrame
pasef_frame_msms_info
property
¶
The 'PasefFrameMsMsInfo' table as a pandas DataFrame. :return: table as a pandas DataFrame
precursors
property
¶
The 'Precursors' table as a pandas DataFrame. :return: table as a pandas DataFrame
properties
property
¶
The 'Properties' table as a pandas DataFrame. :return: table as a pandas DataFrame
property_definitions
property
¶
The 'PropertyDefinitions' table as a pandas DataFrame. :return: table as a pandas DataFrame
property_groups
property
¶
The 'PropertyGroups' table as a pandas DataFrame. :return: table as a pandas DataFrame
segments
property
¶
The 'Segments' table as a pandas DataFrame. :return: table as a pandas DataFrame
tims_calibration
property
¶
The 'TimsCalibration' table as a pandas DataFrame. :return: table as a pandas DataFrame
prm_frame_measurement_mode
property
¶
The 'PrmFrameMeasurementMode' table as a pandas DataFrame. :return: table as a pandas DataFrame
prm_frame_msms_info
property
¶
The 'PrmFrameMsMsInfo' table as a pandas DataFrame. :return: table as a pandas DataFrame
prm_targets
property
¶
The 'PrmTargets' table as a pandas DataFrame. :return: table as a pandas DataFrame
is_dda
property
¶
Checks if the database contains DDA (Data-Dependent Acquisition) data.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if DDA data is present, False otherwise. |
is_prm
property
¶
Checks if the database contains PRM (Parallel Reaction Monitoring) data.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if PRM data is present, False otherwise. |
is_dia
property
¶
Checks if the database contains DIA (Data-Independent Acquisition) data.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if DIA data is present, False otherwise. |
is_maldi
property
¶
Checks if the database contains MALDI (Matrix-Assisted Laser Desorption/Ionization) data. Not supported in tdfpy, but this method can be used to check for MALDI data if it is added in the future.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if MALDI data is present, False otherwise. |
get_table_names
¶
Retrieves the names of all tables in the SQLite database.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of table names in the database. |
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If SQLite cannot read the database. |
Source code in src/tdfpy/tdf.py
tdfpy.TimsData
¶
TimsData(
analysis_directory: str | os.PathLike[str],
*,
use_recalibrated_state: bool = False,
pressure_compensation_strategy: PressureCompensationStrategy = PressureCompensationStrategy.NoPressureCompensation
)
Random-access reader for a Bruker .d folder.
Metadata is loaded eagerly on open; spectral data is read from
analysis.tdf_bin on demand.
Reading frames from several threads through one open reader is safe: frame
bytes are fetched with :func:os.pread, which takes its offset as an
argument and so shares no file position between threads, and decompression
goes through stateless one-shot entry points. Where os.pread is
unavailable (Windows) the seek + read pair is serialised by a lock instead.
close() is not safe to race against an in-flight read, and the
sqlite3 connection on :attr:conn keeps sqlite3's own thread rules.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
UnsupportedTdfError
|
For unsupported options, compression types or a folder whose metadata is incomplete. |
TdfpyError
|
If SQLite cannot read |
TdfpyKeyError
|
From per-frame methods, for a frame ID not in the file. |
ReaderClosedError
|
From spectral reads after :meth: |
Source code in src/tdfpy/timsdata.py
frame_ids
property
¶
Frame IDs in acquisition ID order. Requires an open reader.
frame_metadata
¶
frame_metadata(frame_id: int) -> FrameMetadata
Read eagerly loaded metadata without accessing SQLite.
metadata_table
¶
Read an immutable snapshot of a gate metadata table.
Supported names are PropertyDefinitions, GroupProperties, and DiaFrameMsMsWindows. An absent table produces an empty tuple.
Raises:
| Type | Description |
|---|---|
TdfpyKeyError
|
If |
Source code in src/tdfpy/timsdata.py
mz_calibration_key
¶
Identify the effective m/z conversion, including temperature drift.
Source code in src/tdfpy/timsdata.py
calibration_key
¶
Identify the effective m/z and mobility conversions for caching.
close
¶
Close analysis.tdf_bin and the SQLite connection. Safe to call twice.
Source code in src/tdfpy/timsdata.py
index_to_mz
¶
Convert TOF sample indices to m/z for frame_id.
mz_to_index
¶
Convert m/z to (fractional) TOF sample indices for frame_id.
scan_num_to_ook0
¶
Convert scan numbers to inverse reduced mobility 1/K0 (V·s/cm²).
ook0_to_scan_num
¶
Convert 1/K0 (V·s/cm²) to (fractional) scan numbers.
scan_num_to_voltage
¶
voltage_to_scan_num
¶
Convert TIMS ramp voltage to (fractional) scan numbers.
read_frame_arrays
¶
read_frame_arrays(
frame_id: int,
scan_begin: int = 0,
scan_end: int | None = None,
) -> tuple[
npt.NDArray[np.int64],
npt.NDArray[np.uint32],
npt.NDArray[np.uint32],
]
Read scans [scan_begin, scan_end) as three flat, parallel arrays.
Returns (scan_indices, tof_indices, intensities), one entry per peak.
This is the cheap path: peaks for a contiguous scan range are already
contiguous in the decoded frame, so it slices rather than splitting the
frame into per-scan arrays the way :meth:read_scans must.
Prefer this whenever you were going to concatenate read_scans output
back together.
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If a bound is not an integer, or the range is outside
|
TdfpyKeyError
|
If |
Source code in src/tdfpy/timsdata.py
read_scans
¶
read_scans(
frame_id: int, scan_begin: int, scan_end: int
) -> list[
tuple[npt.NDArray[np.uint32], npt.NDArray[np.uint32]]
]
Read scans [scan_begin, scan_end) of a frame.
Returns one (tof_indices, intensities) pair per scan. Intensities are
normalised to a 100 ms accumulation window, matching Bruker.
See :meth:read_frame_arrays for a flat-array alternative that avoids
materialising one array pair per scan.
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If a bound is not an integer, or the range is outside
|
TdfpyKeyError
|
If |
Source code in src/tdfpy/timsdata.py
tdfpy.timsdata_connect
¶
timsdata_connect(
analysis_dir: str | os.PathLike[str],
) -> Generator[TimsData, None, None]
Open a :class:TimsData and close it on exit.
Source code in src/tdfpy/timsdata.py
tdfpy.FrameMetadata
dataclass
¶
FrameMetadata(
frame_id: int,
rt: float,
msms_type: int,
polarity: str,
num_scans: int,
num_peaks: int,
property_group_id: int | None,
mz_calibration_id: int,
tims_calibration_id: int,
t1: float,
t2: float,
)
Immutable per-frame metadata, loaded from the Frames table when the reader opens.
Returned by :meth:TimsData.frame_metadata. Reading it needs no SQLite access.
msms_type
instance-attribute
¶
Frames.MsMsType: 0 MS1, 8 DDA MS2, 9 DIA MS2, 10 PRM MS2 (see :class:~tdfpy.MsMsType).
property_group_id
instance-attribute
¶
Frames.PropertyGroup, or None when NULL.
mz_calibration_id
instance-attribute
¶
Frames.MzCalibration: row ID in the MzCalibration table.
tims_calibration_id
instance-attribute
¶
Frames.TimsCalibration: row ID in the TimsCalibration table.
Errors¶
Every tdfpy error subclasses TdfpyError (a ValueError). Unsupported or unvalidated
formats raise instead of returning approximate values.
tdfpy.TdfpyError
¶
Bases: ValueError
Base class of every tdfpy error.
Raised directly for invalid arguments (a negative tolerance, an unknown
option name) and for SQLite errors while reading analysis.tdf.
tdfpy.TdfpyKeyError
¶
Bases: TdfpyError, KeyError
An ID or key that is not in the acquisition.
Raised by lookup indexing (dda.precursors[99999]), by the MetaData
and Calibration key accessors, and by :class:~tdfpy.TimsData for an
unknown frame ID.
tdfpy.ReaderClosedError
¶
Bases: TdfpyError, RuntimeError
Spectral data was requested after the reader was closed.
Frame elements keep a reference to the reader's :class:~tdfpy.TimsData;
once the with block exits, their spectral accessors raise this instead of
returning stale data.
tdfpy.AcquisitionTypeError
¶
Bases: TdfpyError
A reader was opened on a .d folder of another acquisition type.
For example DDA("run.d") on a diaPASEF run. Check the type first with
:func:~tdfpy.get_acquisition_type.
tdfpy.UnsupportedTdfError
¶
Bases: TdfpyError, NotImplementedError
A .d folder this reader has not been validated against, or a corrupt one.
Raised for legacy compression types, unsupported reader options and any
analysis.tdf_bin whose layout checks fail.
tdfpy.UnsupportedCalibrationError
¶
Bases: TdfpyError, NotImplementedError
A calibration model type that has not been validated.
Bruker ships several model types; only those seen on real data are implemented. An unknown model raises rather than returning plausible but wrong numbers.