Skip to main content

Python API

opentimstdf.Reader opens a .d/ (TDF) bundle once and serves per-frame metadata, calibration, and decoded peaks. The supporting classes below are plain data carriers returned by Reader's methods; none of them are constructed directly.

import opentimstdf

reader = opentimstdf.Reader("run.d")

Reader​

MemberReturnsDescription
bundle_dirstrPath to the opened .d/ directory
compression_typeintCodec used for peak blocks (1 or 2)
metadata()MetadataInstrument, software, and schema-version metadata
calibration()Calibrationm/z and inverse-mobility calibration for the most-referenced MzCalibration row
mz_calibration_model()str"tables" or "range_fallback"
mz_calibration_fallback_reason()str | NoneWhy the calibration tables could not be used; None when they are
frame(id)FrameMetadata for a single frame by id
frames()list[Frame]Metadata for every frame in the run, in id order
decode_peaks(frame)list[Peak]Raw (uncalibrated) peaks for a frame
decode_spectrum(frame)DecodedSpectrumCalibrated peaks for a frame, as numpy arrays
dia_windows_for_frame(frame_id)DiaFrameWindows | NonediaPASEF isolation windows for an MS2 frame
pasef_msms_info_for_frame(frame_id)list[PasefMsMsInfo]PASEF precursor selections for an MS2 frame
prm_msms_info_for_frame(frame_id)list[PrmMsMsInfo]PRM target selections for an MS2 frame
prm_target(target_id)PrmTarget | NoneA single PRM target definition by id
precursor(precursor_id)Precursor | NoneA single DDA precursor by id
frame = reader.frame(1)
for peak in reader.decode_peaks(frame):
... # Peak(scan, tof, intensity), uncalibrated

spectrum = reader.decode_spectrum(frame)
spectrum.mz # numpy.ndarray, dtype=float64
spectrum.inv_mobility # numpy.ndarray, dtype=float64
spectrum.intensity # numpy.ndarray, dtype=uint32

decode_peaks and decode_spectrum both do the same lock-acquire-and-decode work; decode_spectrum additionally applies calibration in the same pass, so prefer it over pairing decode_peaks with manual Calibration calls when you need m/z and inverse mobility rather than raw scan/tof.

Supporting classes​

Peak​

Raw, uncalibrated per-ion values decoded straight from a frame's block stream.

FieldType
scanint
tofint
intensityint

Frame​

FieldTypeDescription
idintFrame id
timefloatRetention time (seconds)
num_scansintNumber of mobility scans in the frame
num_peaksintTotal peak count
tims_idintOffset of this frame's block in analysis.tdf_bin
scan_modeintAcquisition scan mode
msms_typeint0 for MS1, otherwise identifies the MS2 acquisition mode
mz_calibration_idintCalibration id used for this frame
accumulation_timefloat | NoneTIMS accumulation time (ms)
summed_intensitiesint | NoneSum of all peak intensities in the frame
max_intensityint | NoneMost intense peak in the frame (Frames.MaxIntensity)
polaritystr"positive" or "negative", read from Frames.Polarity

Metadata​

FieldType
schema_version_majorint
schema_version_minorint
instrument_namestr
acquisition_softwarestr
acquisition_software_versionstr
compression_typeint
acquisition_date_timestr | None

Calibration​

Converts between raw TOF/scan indices and calibrated m/z / inverse mobility. When the bundle uses the range fallback for m/z, the first calibration lookup on a Reader raises a RuntimeWarning with the reason.

MemberTypeDescription
mz_modelstr"tables" or "range_fallback"
mz_interceptfloat | NoneRange-fallback intercept (sqrt(mz) = mz_intercept + mz_slope * tof); None for the tables model
mz_slopefloat | NoneRange-fallback slope; None for the tables model
im_interceptfloatInverse-mobility calibration intercept
im_slopefloatInverse-mobility calibration slope
tof_to_mz(tof)floatCalibrated m/z for a raw TOF index
mz_to_tof(mz)intRaw TOF index nearest a given m/z
scan_to_inv_mobility(scan)floatCalibrated 1/K0 for a raw scan index
inv_mobility_to_scan(inv_mobility)intRaw scan index nearest a given 1/K0

DiaWindow / DiaFrameWindows​

dia_windows_for_frame returns one DiaFrameWindows (or None for non-diaPASEF frames), which fans out to the individual isolation windows in its windows list.

DiaFrameWindows

FieldType
frame_idint
window_groupint
windowslist[DiaWindow]

DiaWindow

FieldType
window_groupint
scan_num_beginint
scan_num_endint
isolation_mzfloat
isolation_widthfloat
collision_energyfloat

PasefMsMsInfo​

FieldType
frame_idint
scan_num_beginint
scan_num_endint
isolation_mzfloat
isolation_widthfloat
collision_energyfloat
precursor_idint (pass to Reader.precursor())

PrmMsMsInfo / PrmTarget​

prm_msms_info_for_frame returns PrmMsMsInfo entries; each carries a target_id to look up the full target definition via Reader.prm_target().

PrmMsMsInfo

FieldType
frame_idint
scan_num_beginint
scan_num_endint
isolation_mzfloat
isolation_widthfloat
collision_energyfloat
target_idint (pass to Reader.prm_target())

PrmTarget

FieldType
idint
external_idstr
timefloat
one_over_k0float
monoisotopic_mzfloat
chargeint
descriptionstr

Precursor​

A DDA precursor selection, looked up via Reader.precursor() using the precursor_id from a PasefMsMsInfo.

FieldType
idint
largest_peak_mzfloat
average_mzfloat
monoisotopic_mzfloat | None
chargeint | None
scan_numberfloat
intensityfloat
parent_frame_idint

DecodedSpectrum​

Returned by Reader.decode_spectrum(). All three arrays are the same length; index i describes one calibrated ion.

FieldTypeDescription
mznumpy.ndarray[float64]Calibrated m/z values (Da)
inv_mobilitynumpy.ndarray[float64]Calibrated inverse ion mobility (1/K0, V*s/cm^2)
intensitynumpy.ndarray[uint32]Raw intensity counts

len(spectrum) returns the peak count.

Next​