Spectrum
mzmlpy.spectra.Spectrum
dataclass
Spectrum(element: ElementTree.Element)
Bases: _ParamGroup, _BinaryDataArrayMixin, _ScanListMixin, _PrecursorListMixin, _ProductListMixin
An mzML spectrum element.
Exposes binary data arrays (mz, intensity, charge, ion mobility via has_im/im_types),
scan metadata (scan_start_time, ion_injection_time, lower_mz, upper_mz, spectrum_type,
polarity, ms_level, TIC), and structured precursor/product lists.
id
property
id: str
Get spectrum id.
id_dict
property
id_dict: dict[str, int | str]
Parse the native id into its key=value components (e.g. {"scan": 19}).
Vendor native ids are space-separated key=value tokens, e.g. Thermo
"controllerType=0 controllerNumber=1 scan=19" or Bruker "frame=1016 scan=1".
Integer components are returned as ints, so spectrum.id_dict["scan"] gives the scan
number without manual parsing.
spot_id
property
spot_id: str | None
Get spectrum spot id, or None if not present.
index
property
index: int | None
Get spectrum index, or None if not present.
default_array_length
property
default_array_length: int | None
Get spectrum default array length, or None if not present.
data_processing_ref
property
data_processing_ref: str | None
Get spectrum data processing reference, or None if not present.
source_file_ref
property
source_file_ref: str | None
Get spectrum source file reference, or None if not present.
mz
property
mz: np.ndarray | None
Get m/z array as a numpy array, or None if not present.
intensity
property
intensity: np.ndarray | None
Get intensity array as a numpy array, or None if not present.
charge
property
charge: np.ndarray | None
Return the per-point charge array, or None if no charge binary array is present.
has_im
property
has_im: bool
Return True if this spectrum carries ion mobility data — either as a binary array (e.g. combined-IM frames) or as a scan-level cvParam (e.g. Bruker timsTOF PASEF MS2).
im_types
property
im_types: set[BinaryDataArrayAccession]
Return the set of ion mobility array accessions present in this spectrum; empty set if none.
spectrum_type
cached
property
spectrum_type: Literal['centroid', 'profile'] | None
Get spectrum type (centroid / profile / unknown).
polarity
cached
property
polarity: Literal['positive', 'negative'] | None
Get polarity (positive / negative / or unknown scan).
TIC
cached
property
TIC: float | None
Get total ion current (TIC) for this spectrum.
ms_level
cached
property
ms_level: int | None
Get MS level for this spectrum.
base_peak_mz
property
base_peak_mz: float | None
Base peak m/z for this spectrum (MS:1000504).
base_peak_intensity
property
base_peak_intensity: float | None
Base peak intensity for this spectrum (MS:1000505).
lowest_observed_mz
property
lowest_observed_mz: float | None
Lowest observed m/z for this spectrum (MS:1000528).
highest_observed_mz
property
highest_observed_mz: float | None
Highest observed m/z for this spectrum (MS:1000527).
ns
cached
property
ns: str
Get XML namespace from the element tag.
accessions
cached
property
accessions: set[str]
Get a set of all accession numbers from the cvParams.
names
cached
property
names: set[str]
Get a set of all names from the cvParams.
ref_params
property
ref_params: list[ReferenceableParamGroupRef]
Get a list of all referenceable parameters from the XML element.
has_products
property
has_products: bool
Check if this spectrum has a product list.
products
property
products: list[Product]
Get a list of Product objects for the product list of this spectrum, or None
has_precursors
property
has_precursors: bool
Check if this spectrum has a precursor list.
precursors
property
precursors: list[Precursor]
Get a list of Precursor objects for the precursor list of this spectrum, or None .
spectra_combination
property
spectra_combination: (
Literal["no_combination", "median", "sum", "mean"]
| None
)
Get spectrum combination type (if any) for this spectrum.
scans
property
scans: list[Scan]
Get a list of Scan objects for the scan list of this spectrum, or None if no scan list is present.
is_single_scan
property
is_single_scan: bool
Check if this spectrum has a single scan.
lower_mz
property
lower_mz: float | None
Get scan window lower limit for this spectrum, if it has a single scan with a single scan window.
upper_mz
property
upper_mz: float | None
Get scan window upper limit for this spectrum, if it has a single scan with a single scan window.
scan_start_time
property
scan_start_time: timedelta | None
Get scan start time for this spectrum, if it has a single scan.
ion_injection_time
property
ion_injection_time: timedelta | None
Get ion injection time for this spectrum, if it has a single scan.
ion_mobility
property
ion_mobility: float | None
Scan-level ion mobility for this spectrum: inverse reduced ion mobility (preferred) or drift time. Common for Bruker timsTOF PASEF MS2, where mobility is a scan cvParam rather than a binary array. Returns None if the spectrum has no single scan or no mobility term.
filter_string
property
filter_string: str | None
Scan filter string for this spectrum (from its single scan), if present.
binary_arrays
property
binary_arrays: list[BinaryDataArray]
Get a list of BinaryDataConverter objects for each binary data array.
get_cvparm
get_cvparm(id: str) -> CvParam | None
Get a cvParam by accession or name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
100 101 102 103 104 105 | |
cv_float
cv_float(id: str) -> float | None
Return a cvParam's value as a float, or None if the term is absent or has no value.
Raises ValueError naming the term and its bad value if the value is present but not numeric — more actionable than a bare "could not convert string to float".
Source code in src/mzmlpy/elems/dtree_wrapper.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
cv_int
cv_int(id: str) -> int | None
Return a cvParam's value as an int, or None if absent or valueless (see :meth:cv_float).
Source code in src/mzmlpy/elems/dtree_wrapper.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_binary_array
get_binary_array(id: str) -> BinaryDataArray | None
Get a BinaryDataConverter object for the binary data array with the specified id.
Source code in src/mzmlpy/spectra.py
272 273 274 275 276 | |
has_binary_array
has_binary_array(id: str) -> bool
Check if a binary data array with the specified id exists.
Source code in src/mzmlpy/spectra.py
278 279 280 281 282 | |
serialize
serialize() -> dict
return the full element content
Source code in src/mzmlpy/elems/dtree_wrapper.py
63 64 65 66 67 68 69 70 | |
get_attribute
get_attribute(attr_name: str) -> str | None
Get an attribute value from the element.
Source code in src/mzmlpy/elems/dtree_wrapper.py
72 73 74 | |
has_cvparm
has_cvparm(id: str) -> bool
Check if a cvParam with the given accession or name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
107 108 109 | |
get_user_param
get_user_param(name: str) -> UserParam | None
Get a userParam by name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
167 168 169 170 171 172 | |
has_user_param
has_user_param(name: str) -> bool
Check if a userParam with the given name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
174 175 176 | |
get_ref_param
get_ref_param(
ref: str,
) -> ReferenceableParamGroupRef | None
Get a referenceable parameter by ref.
Source code in src/mzmlpy/elems/dtree_wrapper.py
187 188 189 190 191 192 | |
has_ref_param
has_ref_param(ref: str) -> bool
Check if a referenceable parameter with the given ref exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
194 195 196 | |
Scan
mzmlpy.spectra.Scan
dataclass
Scan(element: ElementTree.Element)
Bases: _ParamGroup
A single scan event with timing, window, and CV parameter metadata.
scan_windows
property
scan_windows: list[ScanWindow]
Get a list of ScanWindow objects for the scan window list of this scan.
is_single_windowed_scan
property
is_single_windowed_scan: bool
Check if this scan has a single scan window.
lower_mz
property
lower_mz: float | None
Get scan window lower limit for this scan, if it has a single scan window.
upper_mz
property
upper_mz: float | None
Get scan window upper limit for this scan, if it has a single scan window.
scan_start_time
property
scan_start_time: timedelta | None
Get scan start time for this scan.
ion_injection_time
property
ion_injection_time: timedelta | None
Get ion injection time for this scan.
inverse_reduced_ion_mobility
property
inverse_reduced_ion_mobility: float | None
Inverse reduced ion mobility (1/K0) for this scan (MS:1002815), e.g. Bruker timsTOF.
ion_mobility_drift_time
property
ion_mobility_drift_time: float | None
Ion mobility drift time for this scan (MS:1002476).
filter_string
property
filter_string: str | None
Instrument filter string for this scan (MS:1000512), e.g. a Thermo scan filter.
faims_compensation_voltage
property
faims_compensation_voltage: float | None
FAIMS compensation voltage for this scan (MS:1001581).
Front-end high-field asymmetric waveform ion mobility (FAIMS) filtering: each scan may carry a single compensation voltage. See the PSI IM-MS/DIA recommendation v1.0, §3.6.
selexion_separation_voltage
property
selexion_separation_voltage: float | None
SCIEX SelexION differential-mobility separation voltage for this scan (MS:1003394).
selexion_compensation_voltage
property
selexion_compensation_voltage: float | None
SCIEX SelexION differential-mobility compensation voltage for this scan (MS:1003371).
ns
cached
property
ns: str
Get XML namespace from the element tag.
accessions
cached
property
accessions: set[str]
Get a set of all accession numbers from the cvParams.
names
cached
property
names: set[str]
Get a set of all names from the cvParams.
ref_params
property
ref_params: list[ReferenceableParamGroupRef]
Get a list of all referenceable parameters from the XML element.
serialize
serialize() -> dict
return the full element content
Source code in src/mzmlpy/elems/dtree_wrapper.py
63 64 65 66 67 68 69 70 | |
get_attribute
get_attribute(attr_name: str) -> str | None
Get an attribute value from the element.
Source code in src/mzmlpy/elems/dtree_wrapper.py
72 73 74 | |
get_cvparm
get_cvparm(id: str) -> CvParam | None
Get a cvParam by accession or name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
100 101 102 103 104 105 | |
has_cvparm
has_cvparm(id: str) -> bool
Check if a cvParam with the given accession or name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
107 108 109 | |
cv_float
cv_float(id: str) -> float | None
Return a cvParam's value as a float, or None if the term is absent or has no value.
Raises ValueError naming the term and its bad value if the value is present but not numeric — more actionable than a bare "could not convert string to float".
Source code in src/mzmlpy/elems/dtree_wrapper.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
cv_int
cv_int(id: str) -> int | None
Return a cvParam's value as an int, or None if absent or valueless (see :meth:cv_float).
Source code in src/mzmlpy/elems/dtree_wrapper.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_user_param
get_user_param(name: str) -> UserParam | None
Get a userParam by name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
167 168 169 170 171 172 | |
has_user_param
has_user_param(name: str) -> bool
Check if a userParam with the given name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
174 175 176 | |
get_ref_param
get_ref_param(
ref: str,
) -> ReferenceableParamGroupRef | None
Get a referenceable parameter by ref.
Source code in src/mzmlpy/elems/dtree_wrapper.py
187 188 189 190 191 192 | |
has_ref_param
has_ref_param(ref: str) -> bool
Check if a referenceable parameter with the given ref exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
194 195 196 | |
ScanWindow
mzmlpy.spectra.ScanWindow
dataclass
ScanWindow(element: ElementTree.Element)
Bases: _ParamGroup
A scan window defining the m/z range acquired in a single scan.
lower_mz
property
lower_mz: float | None
Get scan window lower limit for this spectrum.
upper_mz
property
upper_mz: float | None
Get scan window upper limit for this spectrum.
ns
cached
property
ns: str
Get XML namespace from the element tag.
accessions
cached
property
accessions: set[str]
Get a set of all accession numbers from the cvParams.
names
cached
property
names: set[str]
Get a set of all names from the cvParams.
ref_params
property
ref_params: list[ReferenceableParamGroupRef]
Get a list of all referenceable parameters from the XML element.
serialize
serialize() -> dict
return the full element content
Source code in src/mzmlpy/elems/dtree_wrapper.py
63 64 65 66 67 68 69 70 | |
get_attribute
get_attribute(attr_name: str) -> str | None
Get an attribute value from the element.
Source code in src/mzmlpy/elems/dtree_wrapper.py
72 73 74 | |
get_cvparm
get_cvparm(id: str) -> CvParam | None
Get a cvParam by accession or name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
100 101 102 103 104 105 | |
has_cvparm
has_cvparm(id: str) -> bool
Check if a cvParam with the given accession or name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
107 108 109 | |
cv_float
cv_float(id: str) -> float | None
Return a cvParam's value as a float, or None if the term is absent or has no value.
Raises ValueError naming the term and its bad value if the value is present but not numeric — more actionable than a bare "could not convert string to float".
Source code in src/mzmlpy/elems/dtree_wrapper.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
cv_int
cv_int(id: str) -> int | None
Return a cvParam's value as an int, or None if absent or valueless (see :meth:cv_float).
Source code in src/mzmlpy/elems/dtree_wrapper.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_user_param
get_user_param(name: str) -> UserParam | None
Get a userParam by name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
167 168 169 170 171 172 | |
has_user_param
has_user_param(name: str) -> bool
Check if a userParam with the given name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
174 175 176 | |
get_ref_param
get_ref_param(
ref: str,
) -> ReferenceableParamGroupRef | None
Get a referenceable parameter by ref.
Source code in src/mzmlpy/elems/dtree_wrapper.py
187 188 189 190 191 192 | |
has_ref_param
has_ref_param(ref: str) -> bool
Check if a referenceable parameter with the given ref exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
194 195 196 | |
BinaryDataArray
mzmlpy.spectra.BinaryDataArray
dataclass
BinaryDataArray(element: ElementTree.Element)
Bases: _ParamGroup
Wraps a single binaryDataArray XML element, handling base64 decoding and decompression.
Exposes compression type, numeric encoding, semantic array type, and a data property
that decodes the raw bytes into a NumPy array on each access.
compression
cached
property
compression: CompressionTypeAccessions | None
Return the compression accession for this array, or None if no compression CV term is present.
encoding
cached
property
encoding: BinaryDataTypeAccession | None
Return the binary data type accession (e.g. 32-bit or 64-bit float/int), or None if absent.
binary_array_type
cached
property
binary_array_type: BinaryDataArrayAccession | None
Return the semantic array type accession (e.g. m/z, intensity, ion mobility), or None if absent.
data
property
data: np.ndarray
Decode and return the binary data as a NumPy array.
Raw numeric encodings retain their declared dtype, including empty arrays. Numpress returns reconstructed float64 values. Arrays are writable. Decoding runs on every access. Store the result locally when using it repeatedly.
ns
cached
property
ns: str
Get XML namespace from the element tag.
accessions
cached
property
accessions: set[str]
Get a set of all accession numbers from the cvParams.
names
cached
property
names: set[str]
Get a set of all names from the cvParams.
ref_params
property
ref_params: list[ReferenceableParamGroupRef]
Get a list of all referenceable parameters from the XML element.
serialize
serialize() -> dict
return the full element content
Source code in src/mzmlpy/elems/dtree_wrapper.py
63 64 65 66 67 68 69 70 | |
get_attribute
get_attribute(attr_name: str) -> str | None
Get an attribute value from the element.
Source code in src/mzmlpy/elems/dtree_wrapper.py
72 73 74 | |
get_cvparm
get_cvparm(id: str) -> CvParam | None
Get a cvParam by accession or name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
100 101 102 103 104 105 | |
has_cvparm
has_cvparm(id: str) -> bool
Check if a cvParam with the given accession or name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
107 108 109 | |
cv_float
cv_float(id: str) -> float | None
Return a cvParam's value as a float, or None if the term is absent or has no value.
Raises ValueError naming the term and its bad value if the value is present but not numeric — more actionable than a bare "could not convert string to float".
Source code in src/mzmlpy/elems/dtree_wrapper.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
cv_int
cv_int(id: str) -> int | None
Return a cvParam's value as an int, or None if absent or valueless (see :meth:cv_float).
Source code in src/mzmlpy/elems/dtree_wrapper.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_user_param
get_user_param(name: str) -> UserParam | None
Get a userParam by name.
Source code in src/mzmlpy/elems/dtree_wrapper.py
167 168 169 170 171 172 | |
has_user_param
has_user_param(name: str) -> bool
Check if a userParam with the given name exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
174 175 176 | |
get_ref_param
get_ref_param(
ref: str,
) -> ReferenceableParamGroupRef | None
Get a referenceable parameter by ref.
Source code in src/mzmlpy/elems/dtree_wrapper.py
187 188 189 190 191 192 | |
has_ref_param
has_ref_param(ref: str) -> bool
Check if a referenceable parameter with the given ref exists.
Source code in src/mzmlpy/elems/dtree_wrapper.py
194 195 196 | |