Mass Spectrometry
Mass spectrometry is commonly used in catalysis and electrocatalysis for two different types of data - spectra, where intensity is taken while scanning over m/z, and multiple ion detection (MID) where the intensity of a small set of m/z values are tracked in time.
The main TechniqueMeasurement class for MID data is the MSMeasurement
.
The position of spectra in ixdat is not completely set yet. Currently, they exist as Spectrum
base
class alongside Measurement
. For more details see Spectrum
The ms
module
Module for representation and analysis of MS measurements
- class ixdat.techniques.ms.MSCalResult(name=None, mol=None, mass=None, cal_type=None, F=None)[source]
A class for a mass spec ms_calibration result.
- FIXME: I think that something inheriting directly from Saveable does not belong in
a technique module.
- class ixdat.techniques.ms.MSCalibration(name=None, date=None, tstamp=None, setup=None, ms_cal_results=None, signal_bgs=None, technique='MS', measurement=None)[source]
Class for mass spec calibrations. TODO: replace with powerful external package
- calibrate_series(key, measurement=None)[source]
Return a calibrated series for key if possible.
If key starts with “n_”, it is interpreted as a molecule flux. This method then searches the calibration for a sensitivity factor for that molecule uses it to divide the relevant mass signal from the measurement. Example acceptable keys: “n_H2”, “n_dot_H2”. If the key does not start with “n_”, or the calibration can’t find a relevant sensitivity factor and mass signal, this method returns None.
- class ixdat.techniques.ms.MSInlet(*, l_cap=0.001, w_cap=6e-06, h_cap=6e-06, gas='He', T=298.15, p=100000.0, verbose=True)[source]
A class for describing the inlet to the mass spec
Every MSInlet describes the rate and composition of the gas entering a mass spectrometer. The default is a Spectro Inlets EC-MS chip.
- calc_l_cap_eff(n_dot_measured, gas=None, w_cap=None, h_cap=None, T=None, p=None)[source]
Calculate gas specific effective length of the capillary in [m] and add {gas:value} to l_cap_eff (dict)
- Parameters
w_cap (float) – Capillary width [m], defaults to self.w_cap
h_cap (float) – Capillary height [m], defaults to self.h_cap
n_dot_measured (float) – Measured flux of gas [mol/s]
gas (dict or str) – The gas in the chip, defaults to self.gas
T (float) – Temperature [K], if to be updated
p (float) – Pressure [Pa], if to be updated
- Returns
Gas specific effective length in [m]
- Return type
float
- calc_n_dot_0(gas=None, w_cap=None, h_cap=None, l_cap=None, T=None, p=None)[source]
Calculate the total molecular flux through the capillary in [s^-1]
Uses Equation 4.10 of Trimarco, 2017. “Real-time detection of sub-monolayer desorption phenomena during electrochemical reactions: Instrument development and applications.” PhD Thesis, Technical University of Denmark.
- Parameters
w_cap (float) – Capillary width [m], defaults to self.w_cap
h_cap (float) – Capillary height [m], defaults to self.h_cap
l_cap (float) – Capillary length [m], defaults to self.l_cap
gas (dict or str) – The gas in the chip, defaults to self.gas
T (float) – Temperature [K], if to be updated
p (float) – Pressure [Pa], if to be updated
- Returns
The total molecular flux in [s^-1] through the capillary
- Return type
float
- class ixdat.techniques.ms.MSMeasurement(name, **kwargs)[source]
Class implementing raw MS functionality
- cut(**kwargs)
Return a new measurement with the data in the given time interval
- Parameters
tspan (iter of float) – The time interval to use, relative to self.tstamp tspan[0] is the start time of the interval, and tspan[-1] is the end time of the interval. Using tspan[-1] means you can directly use a long time vector that you have at hand to describe the time interval you’re looking for.
t_zero (float or str) – The time in the measurement to set to t=0. If a float, it is interpreted as wrt the original tstamp. String options include “start”, which puts t=0 at the start of the cut interval.
- default_exporter
alias of
MSExporter
- gas_flux_calibration(mol, mass, inlet=None, chip=None, tspan=None, tspan_bg=None, ax=None, carrier_mol=None, mol_conc_ppm=None)[source]
Fit mol’s sensitivity at mass based on one period with steady gas composition.
- Parameters
mol (str) – The name of the molecule to calibrate
mass (str) – The mass to calibrate at
inlet (MSInlet) – An object with a calc_n_dot_0 method for total flux to the vacuum chamber containing the mass spectrometer.
chip (MSInlet) – DEPRECATED. Old name for inlet.
tspan (iter) – The timespan to average the signal over. Defaults to all
tspan_bg (iter) – Optional timespan at which the signal is at its background.
ax (matplotlib axis) – The axis on which to indicate what signal is used with a thicker line. Defaults to none
carrier_mol (str) – The name of the molecule of the carrier gas if a dilute analyte is used. Calibration assumes total flux of the capillary is the same as the flux of pure carrier gas. Defaults to None.
mol_conc_ppm (float) – Concentration of the dilute analyte in the carrier gas in ppm. Defaults to None.
- Returns MSCalResult: a MS calibration result containing the sensitivity factor
for mol at mass
- gas_flux_calibration_curve(mol, mass, inlet=None, chip=None, tspan_list=None, carrier_mol=None, mol_conc_ppm=None, p_inlet=None, tspan_bg=None, ax='new', axis_measurement=None, remove_bg_on_axis_measurement=True, return_ax=False)[source]
Fit mol’s sensitivity at mass from 2+ periods of steady gas composition.
- Parameters
inlet (MSInlet) – An object with a calc_n_dot_0 method for total flux to the vacuum chamber containing the mass spectrometer.
mol (str) – Name of the molecule to calibrate
mass (str) – Name of the mass at which to calibrate
inlet – An object with a calc_n_dot_0 method for total flux to the vacuum chamber containing the mass spectrometer.
chip (MSInlet) – DEPRECATED. Old name for inlet.
tspan_list (list of tspan) – The timespans of steady concentration or pressure
carrier_mol (str) – The name of the molecule of the carrier gas if a dilute analyte is used. Calibration assumes total flux of the capillary is the same as the flux of pure carrier gas. Defaults to None.
mol_conc_ppm (float or list) – Concentration of the dilute analyte in the carrier gas in ppm. Defaults to None. Accepts float (for pressure calibration) or list for concentration calibration. If list needs to be same length as tspan_list or selector_list.
p_inlet (float, list) – Pressure at the inlet (Pa). Overwrites the pressure inherent to self (i.e. the MSInlet object). Accepts float (for conc. calibration) or list for pressure calibration. If list, then needs to be same length as tspan_list or selector_list.
tspan_bg (tspan) – The time to use as a background
ax (Axis) – The axis on which to plot the ms_calibration curve result. Defaults to a new axis.
axis_measurement (Axis) – The MS plot axes to highlight the ms_calibration on. Defaults to None.
remove_bg_on_axis_measurement (bool) – Whether the plot on axis_measurement is showing raw data or bg subtracted data. Defaults to True, i.e. plotting data with the same bg subtraction as used for the calibration.
return_ax (bool) – Whether to return the axis on which the calibration curve is plotted together with the MSCalResult. Defaults to False.
- Return MSCalResult(, Axis): The result of the MS calibration (and calibration
curve axis if requested) based on flux calculation during selected time periods.
TODO: automatically recognize the pressure from measurement (if available)
- grab(item, tspan=None, tspan_bg=None, include_endpoints=False, remove_background=False)[source]
Returns t, S where S is raw signal in [A] for a given signal name (ie mass)
- Parameters
item (str) – Name of the signal. If item has the form f”n_dot_{mol}”, then grab_flux(mol) is returned.
tspan (list) – Timespan for which the signal is returned.
tspan_bg (list) – Timespan that corresponds to the background signal. If not given, no background is subtracted.
remove_background (bool) – Whether to remove a pre-set background if available. This is special to MSMeasurement. Defaults to False, but in grab_flux it defaults to True.
include_endpoints (bool) – Whether to ensure tspan[0] and tspan[-1] are in t
- grab_flux(mol, tspan=None, tspan_bg=None, remove_background=True, removebackground=None, include_endpoints=False)[source]
Return the flux of mol (calibrated signal) in [mol/s]
Note: - With native ixdat quantification (use_siq=False),
grab_flux(mol, …) is identical to grab(f”n_dot_{mol}”, …) with remove_background=True by default. An MSCalibration does the maths.
With an external quantification package (use_siq=True), the maths are done here with the help of self.quantifier
- Parameters
mol (str or MSCalResult) – Name of the molecule or a ms_calibration thereof
tspan (list) – Timespan for which the signal is returned.
tspan_bg (list) – Timespan that corresponds to the background signal. If not given, no background is subtracted.
remove_background (bool) – Whether to remove a pre-set background if available Defaults to True.
removebackground (bool) – DEPRECATED. Use remove_background.
include_endpoints (bool) – Whether to interpolate for tspan[0] and tspan[-1]
- grab_flux_for_t(mol, t, tspan_bg=None, remove_background=False, removebackground=None)[source]
Return the flux of mol (calibrated signal) in [mol/s] for a given time vec
- Parameters
mol (str) – Name of the molecule.
t (np.array) – The time vector along which to give the flux
tspan_bg (tspan) – Timespan that corresponds to the background signal. If not given, no background is subtracted.
remove_background (bool) – Whether to remove a pre-set background if available
removebackground (bool) – DEPRECATED. Use remove_background.
- grab_for_t(item, t, tspan_bg=None, remove_background=False)[source]
Return a numpy array with the value of item interpolated to time t
- Parameters
item (str) – The name of the value to grab
t (np array) – The time vector to grab the value for
tspan_bg (iterable) – Optional. A timespan defining when item is at its baseline level. The average value of item in this interval will be subtracted from what is returned.
remove_background (bool) – Whether to remove a pre-set background if available. This is special to MSMeasurement. Defaults to False, but in grab_flux it defaults to True.
- grab_siq_fluxes(tspan=None, tspan_bg=None, remove_background=False, include_endpoints=False)[source]
Return a time vector and a dictionary with all the quantified fluxes
- Parameters
tspan (list) – Timespan for which the signal is returned.
tspan_bg (list) – Timespan that corresponds to the background signal. If not given, no background is subtracted.
remove_background (bool) – Whether to remove a pre-set background if available Defaults to True..
include_endpoints (bool) – Whether to interpolate for tspan[0] and tspan[-1]
- integrate_signal(mass, tspan, tspan_bg, ax=None)[source]
Integrate a ms signal with background subtraction and evt. plotting
- TODO: Should this, like grab_signal does now, have the option of using a
background saved in the object rather than calculating a new one?
- Parameters
mass (str) – The mass for which to integrate the signal
tspan (tspan) – The timespan over which to integrate
tspan_bg (tspan) – Timespan at which the signal is at its background value
ax (Axis) – axis to plot on. Defaults to None
- property mass_list
List of the masses for which ValueSeries are contained in the measurement
- multicut(**kwargs)
Return a selection of the measurement including each of the given tspans
- set_bg(tspan_bg=None, mass_list=None)[source]
Set background values for mass_list to the average signal during tspan_bg.
- set_siq_quantifier(quantifier=None, calibration=None, mol_list=None, mass_list=None, carrier='He')[source]
Set the spectro_inlets_quantification quantifier.
The Quantifier is an object with the method calc_n_dot, which takes a dictionary of signals or signal vectors in [A] and return a dictionary of molecular fluxes in [mol/s]. The quantifier typically does this by solving the linear equations of S_M = sum_i ( F_M^i * n_dot^i ) Where n_dot^i is the flux to the vacuum chamber of molecule i in [mol/s], S_M is the signal at mass M in [A], and F_M^i is the sensitivity factor of molecule i at mass M. The quantifier thus needs access to a set of sensitivity factors.
The quantifier can be built in this method (avoiding explicit import of the spectro_inlets_quantification package) by providing the sensitivity factors in the form of a Calibration (which can be obtained from e.g. MSMeasurement.multicomp_gas_flux_cal) and the specification of which ones to use by mol_list and mass_list. The quantifier will always use all the masses in mass_list to solve for the flux of all the mols in mol_list.
The argument carrier is required by some quantifiers but only used if partial pressures before the MS inlet are required (quantifier.calc_pp)
Quantification is only as accurate as your sensitivity factors!
- Parameters
quantifier (Quantifier) – The quantifier, if prepared before method call. No additional arguments needed. Otherwise, the following three are needed:
calibration (Calibration) – The calibration to build the quantifier with
mol_list (list of str) – The list of molecules to use in flux calculations. These should all be represented in the Calibration. If not provided, we’ll use all the mols in the Calibration.
mass_list (list of str) – The list of masses to use in flux calculations. These should all be represented in the Calibration. If not provided, we’ll use all the masses in the Calibration.
carrier (optional, str) – The carrier gas in the experiment. Defaults to “He”.
- siq_gas_flux_calibration(mol, mass, tspan, chip=None)[source]
Simple pure-gas flux calibration, using spectro_inlets_quantification
- Parameters
mol (str) – Name of molecule to be calibrated (e.g. “He”)
mass (str) – Mass at which to calibrate it (e.g. “M4”)
tspan (timespan) – A timespan during which the pure gas is in the chip
chip (Chip, optional) – An object defining the capillary inlet, if different than the standard chip assumed by the external package.
- Returns CalPoint: An object from spectro_inlets_quantification,
representing the calibration result
- siq_gas_flux_calibration_curve(mol, mass, chip=None, tspan_list=None, carrier_mol=None, mol_conc_ppm=None, p_inlet=None, tspan_bg=None, ax='new', axis_measurement=None, remove_bg_on_axis_measurement=True, return_ax=False)[source]
Fit mol’s sensitivity at mass from 2+ periods of steady gas composition.
- Parameters
mol (str) – Name of the molecule to calibrate
mass (str) – Name of the mass at which to calibrate
tspan_list (list of tspan) – The timespans of steady concentration or pressure
carrier_mol (str) – The name of the molecule of the carrier gas if a dilute analyte is used. Calibration assumes total flux of the capillary is the same as the flux of pure carrier gas. Defaults to None.
mol_conc_ppm (float, list) – Concentration of the dilute analyte in the carrier gas in ppm. Defaults to None. Accepts float (for pressure calibration) or list for concentration calibration. If list needs to be same length as tspan_list or selector_list.
p_inlet (float, list) – Pressure at the inlet (Pa). Overwrites the pressure inherent to self (i.e. the MSInlet object). Accepts float (for conc. calibration) or list for pressure calibration. If list, then needs to be same length as tspan_list or selector_list.
tspan_bg (tspan) – The time to use as a background
ax (Axis) – The axis on which to plot the ms_calibration curve result. Defaults to a new axis.
axis_measurement (Axes) – The MS plot axes to highlight the ms_calibration on. Defaults to None. These axes are not returned.
remove_bg_on_axis_measurement (bool) – Whether the plot on axis_measurement is showing raw data or bg subtracted data. Defaults to True, i.e. plotting data with the same bg subtraction as used for the calibration.
return_ax (bool) – Whether to return the axis on which the calibration curve is plotted together with the MSCalResult. Defaults to False.
- Returns CalPoint: An object from spectro_inlets_quantification,
representing the calibration result
TODO: automatically recognize the pressure from measurement (if available)
- siq_multicomp_gas_flux_calibration(mol_list, mass_list, gas, tspan, gas_bg=None, tspan_bg=None, chip=None)[source]
Calibration of multiple components of a calibration gas simultaneously
Uses a matrix equation and the reference spectra in the molecule data files.
The results are only as accurate as the reference spectrum used. For this reason, this method is a last resort and it is recommended not to use a multicomponent calibration gas. Instead, get a separate calibration gas for each molecule to be calibrated.
Here is an explanation of the math used in this method:
- The fundamental matrix equation is:
S_vec = F_mat @ n_dot_vec
- Elementwise, this is:
S_M = sum_i ( F^i_M * n_dot^i )
- Rewrite to show that sensitivity factors follow each molecule’s spectrum:
S_M = sum_i (F_weight_i * spectrum^i_M * n_dot^i)
- And regroup the parts that only depend on the molecule (^i):
S_M = sum_i (spectrum^i_M * (F_weight^i * n_dot^i)) S_M = sum_i (spectrum^i_M * sensitivity_flux^i)
- Change back into a matrix equation, and solve it:
S_vec = spectrum_mat @ sensitivity_flux_vec sensitivity_flux_vec = spectrum_mat^-1 @ S_vec # eq. 1
- Ungroup the part we grouped before (the “sensitivity_flux”):
F_weight^i = sensitivity_flux^i / n_dot^i # eq. 2
- And, in the end, each sensitivity factor is:
F_M^i = F_weight^i * spectrum^i_M # eq. 3
Equations 1, 2, and 3 are implemented in the code of this method.
- Parameters
mol_list (list of str) – List of the names of the molecules to calibrate
mass_list (list of str) – List of the masses to calibrate
gas (Gas, dict, or str) – Composition of the calibration gas, e.g. {“Ar”: 0.95, “H2”: 0.05} for 5% H2 in Ar
tspan (Timespan) – Timespan during which the calibration gas is in the chip
gas_bg (Gas, dict, or str) – Composition of the background gas
tspan_bg (Timespan) – Timespan during which the background gas is in the chip
chip (Chip, optional) – object describing the MS capillary, if different than the standard chip in the MS quantification package
- Returns Calibration: An object from spectro_inlets_quantification,
representing all the calibration results from the calibration.
- class ixdat.techniques.ms.MSSpectroMeasurement(name, **kwargs)[source]
- cut(**kwargs)
Select the portion of the data in a given tspan.
See
cut()
- default_exporter
alias of
MSSpectroExporter
- default_plotter
alias of
MSSpectroPlotter
- multicut(**kwargs)
Return a selection of the measurement including each of the given tspans