Spectrometer & Pulse Shaper Wavelength Calibration#
Wavelength and wavenumber axis calibration maps detector pixel indices
\(p \in \{1, \dots, N_{\text{pix}}\}\) to physical spectral values (wavelength \(\lambda\)
in nm or wavenumber \(\tilde{\nu}\) in \(\text{cm}^{-1}\)). PyMORGAN provides a dedicated
calibration engine in pymorgan.cal, supporting both spectrometer calibration (for
probe beam spectrographs) and pulse shaper calibration (for optical pulse shaper pump beam
masks).
Pipeline Overview#
The calibration workflow matches an experimentally measured absorption spectrum \(I_{\text{meas}}(p)\) against a high-resolution reference FTIR spectrum \(A_{\text{ref}}(\lambda)\) (such as liquid 1,4-dioxane, liquid polystyrene, or atmospheric water vapour). Non-linear least-squares (NLS) optimisation fits optical dispersion parameters so that the synthetic spectrum evaluated through the dispersion function reproduces the reference absorption features.
The workflow proceeds in six stages:
Load Reference Spectrum: Load \(A_{\text{ref}}(\lambda)\) or \(A_{\text{ref}}(\tilde{\nu})\) with automatic delimiter and unit detection (
load_reference_spectrum()).Load Experimental Data: Parse raw detector intensity or absorbance arrays for one of twelve hardware setups (
load_experimental_spectrum()).Pre-Alignment (Template Scanning): Perform 1D cross-correlation scanning to estimate the initial wavelength shift \(\lambda_1\) at pixel 1.
NLS Parameter Fitting: Optimise dispersion coefficients and additive polynomial baseline using
scipy.optimize.least_squareswith 1st or 2nd Savitzky–Golay derivative filtering.Axis Inversion: Invert pixel-to-wavelength mapping \(p(\lambda) \to \lambda(p)\) analytically or numerically.
Export & Integration: Save calibrated axis arrays (
CalibratedProbe.csv,CalibratedPump.csv,SingleMask.txt,MultipleMask.txt).
Data Model & Data Structures#
The pymorgan.cal package defines five immutable data structures:
ReferenceSpectrum: Container for reference spectra library items:class ReferenceSpectrum(NamedTuple): name: str # Spectrum name (e.g. 'FTIR-Dioxane') spectral_axis: ndarray # Spectral grid (nm or cm-1) absorbance: ndarray # Absorbance array A(x) axis_unit: str # Unit hint ('nm' or 'cm-1')
ExperimentalData: Container for loaded experimental spectrograph measurements:class ExperimentalData(NamedTuple): detector_data: list[ndarray] # Raw detector intensity/absorbance arrays gratings: list[float] # Grating groove density (grooves/mm) cwl: list[float] # Central wavelength setting (nm or cm-1) file_path: Path # File path on disk min_wl: float | None = None # Lower spectral bound from metadata max_wl: float | None = None # Upper spectral bound from metadata spectral_range: str | None = None # Detected regime ('Mid-IR', 'UV/Vis', 'NIR')
CalibrationResult: Output container returned byfit_wavelength_axis():class CalibrationResult(NamedTuple): wavelength_nm: ndarray # Calibrated wavelength axis (nm) wavenumber_cm1: ndarray # Calibrated wavenumber axis (cm-1) fit_params: ndarray # Optimised dispersion parameters vector p residuals: ndarray # Fit residual array ref_x_cut: ndarray # Reference spectral axis in active cut region ref_y_cut: ndarray # Reference absorbance in active cut region model_y_fit: ndarray # Modelled experimental absorbance fit baseline_fit: ndarray # Additive polynomial baseline curve exp_corr_y_fit: ndarray # Baseline-corrected experimental absorbance ref_y_corr: ndarray # Baseline-corrected reference spectrum
SpectrumFitResult: Container for 1D Gaussian pump/probe beam profile diagnostics:class SpectrumFitResult(NamedTuple): amplitude: float # Peak amplitude (Counts) w0: float # Central frequency w0 (cm-1 or nm) fwhm: float # Full-Width at Half-Maximum (FWHM) fit_curve: ndarray # High-density fitted Gaussian profile axis_fit: ndarray # High-density evaluation axis
ProbeFitResult: Container returned byfit_probe_spectrum(), wrapping multi-detector Gaussian diagnostics:class ProbeFitResult(NamedTuple): fits: list[SpectrumFitResult] # Per-detector Gaussian fit results detector_data: list[ndarray] # Raw detector arrays that were fitted
Mathematical Optical Dispersion Models#
PyMORGAN supports three physical models for mapping reference wavelength \(\lambda\) (in nm) to detector pixel index \(p(\lambda) \in [1, N_{\text{pix}}]\):
1. Linear Grating Dispersion Model#
For diffraction grating spectrographs in first-order paraxial approximation, the pixel position \(p(\lambda)\) varies linearly with wavelength around the central wavelength \(\lambda_0\):
where \(d\) is the linear dispersion in pixels/nm.
2. Polynomial Grating Dispersion Model#
For wide-bandwidth spectrographs or non-paraxial grating setups (such as UniGE TRUVIS-II), higher-order geometric distortion is modelled via a 2nd- or 3rd-order polynomial expansion around central wavelength \(\lambda_0\):
where \(c_2\) and \(c_3\) are quadratic and cubic dispersion curvature coefficients.
3. Prism Dispersion Model (SF10 Glass)#
For prism-based spectrographs (e.g. UniGE NIR-TA using an SF10 Flint glass equilateral prism), dispersion is governed by Snell’s law and the Sellmeier equation:
with Sellmeier coefficients (\(\lambda_{\mu\text{m}} = \lambda / 1000\)):
The deflection output angle \(\theta_{\text{out}}(\lambda)\) from a prism with apex angle \(\alpha = 60.84^\circ\) at incidence angle \(\theta_{\text{in}}\) and resulting pixel index \(p(\lambda)\) are:
Forward Model, Baseline Correction & Derivative Cost Function#
Given measured experimental spectrum array \(I_{\text{meas}}(p)\), the model synthesises an experimental absorbance curve \(y_{\text{model}}(\lambda)\) matched to reference grid points \(\lambda\):
where \(s\) is a global scaling factor and \((b_0, b_1, b_2)\) parameterise a smooth background baseline polynomial. To eliminate broad solvent/background baseline drift during fitting, optimisation is performed in derivative space using Savitzky–Golay numerical filters (window size \(W\), polynomial order 2):
Axis Inversion & Gaussian Pump Diagnostics#
Once optimal parameters \(\mathbf{p}^*\) are found, the calibrated wavelength axis \(\lambda(p)\) for pixel indices \(p \in \{1, \dots, N_{\text{pix}}\}\) is computed:
Linear Grating: \(\lambda(p) = \frac{p - 1}{d} + \lambda_1\).
Polynomial Grating: Inverted via dense 1D grid interpolation over \(\lambda \in [250, 1000]\text{ nm}\).
Prism Model: Inverted via KDTree spatial nearest-neighbour search against dense evaluation grid \(p(\lambda)\).
Wavenumbers: \(\tilde{\nu}(p) = 10^7 / \lambda(p)\).
Pump beam profiles in optical pulse shaper calibration are fitted with a 3-parameter Gaussian distribution:
Supported Hardware Setup Configurations#
The calibration engine pre-configures twelve spectrograph hardware setups:
Code |
Setup Name |
Default \(\lambda_0\) |
Dispersion Guess |
Degree |
Default Bounds (\(\Delta\lambda_{\text{rel}}\)) |
|---|---|---|---|---|---|
|
UoS TRIR |
\(2000\text{ cm}^{-1}\) |
\(0.30\text{ px/cm}^{-1}\) |
2 |
|
|
UniGE TA |
|
|
2 |
|
|
UniGE nsTA |
|
|
2 |
|
|
UZH Lab 2 |
\(2000\text{ cm}^{-1}\) |
\(0.30\text{ px/cm}^{-1}\) |
2 |
|
|
UniGE NIR-TA |
|
|
Prism |
|
|
RAL Absorbance |
\(2000\text{ cm}^{-1}\) |
\(0.30\text{ px/cm}^{-1}\) |
2 |
|
|
RAL Intensity |
\(2000\text{ cm}^{-1}\) |
\(0.30\text{ px/cm}^{-1}\) |
2 |
|
|
UniGE TRIR (Int.) |
\(2000\text{ cm}^{-1}\) |
\(0.30\text{ px/cm}^{-1}\) |
2 |
|
|
UniGE TRIR (Abs.) |
\(2000\text{ cm}^{-1}\) |
\(0.30\text{ px/cm}^{-1}\) |
2 |
|
|
UniGE TRUVIS-II |
|
|
3 |
|
|
Light Conversion HARPIA-TA (Int.) |
|
|
2 |
|
|
PyMESS ( |
Auto-routed |
Auto-routed |
Auto |
Routed by spectral range |
HARPIA Range Presets (Setup 11)#
Setup 11 (Light Conversion HARPIA-TA (Int.)) supports two optical presets via
harpia_preset:
Vis Range (
"Vis"): \(\lambda_0 = 515\text{ nm}\), dispersion guess \(d_0 = 1.0\text{ px/nm}\), relative fit bounds \([-165, +235]\text{ nm}\) (spanning \(350\text{–}750\text{ nm}\)).UV Range (
"UV"): \(\lambda_0 = 440\text{ nm}\), dispersion guess \(d_0 = 1.15\text{ px/nm}\), relative fit bounds \([-120, +160]\text{ nm}\) (spanning \(320\text{–}600\text{ nm}\)).
PyMESS HDF5 Automatic Pathway Routing (Setup 12)#
Setup 12 (PyMESS) reads .h5 calibration datasets produced by PyMESS (both
spectrometer probe_* and pulse-shaper pump_* files). PyMORGAN inspects the HDF5 metadata
(/meta/spectrometer/range, type, cwl, and grating) to detect the spectral regime
and routes the dispersion pathway via resolve_effective_cal_type():
Mid-IR (\(\lambda_0 \ge 2500\text{ nm}\) or \(1000 < \lambda_0 < 2500\text{ nm}\) with grating \(< 200\text{ l/mm}\)): Routes to UniGE TRIR (Setup
8).UV/Vis (\(\lambda_0 < 850\text{ nm}\)): Routes to UniGE TRUVIS-II (Setup
10).NIR (\(850 \le \lambda_0 < 2500\text{ nm}\)): Routes to UniGE NIR-TA (Setup
5).
Graphical User Interface (3-Column Inspector Layout)#
The Calibration Tab combines 4 synchronised diagnostic subplots (Raw Measurements, Calculated Absorbance & Physical Baseline, Reference Overlay, and Calibration Fit) above a 3-Column Inspector Panel where file selection, dispersion parameters, and fit controls remain simultaneously visible without tab switching:
Column 1 — Calibration Files & Type: Hardware setup selector, contextual
HARPIA RangeorPyMESS Regimesub-selector, Reference FTIR dropdown, and file browsers for Pump (Air), Pump (Solvent), Single Mask, and Multiple Mask.Column 2 — Calibration Parameters: Side-by-side cards for Spectrometer Setup & Bounds (Detector array, Grating, CWL, Fit Axis Unit, Relative Cut Range) and Dispersion Model & Fit Options (Dispersion model radio buttons, Derivative mode, Baseline correction checkbox, Smoothing window, and Initial/Fitted Dispersion).
Column 3 — Fit Control: One-click ↻ Fit Spec. and ↻ Fit Shaper action buttons, live status banner, and export actions (Save Spec. Cal., Save Shaper Cal., Pump Fit).
Programmatic Usage Example#
import pymorgan.cal as cal
# 1. Load reference FTIR spectrum
ref = cal.load_reference_spectrum("FTIR-Dioxane.csv")
# 2. Load experimental probe spectrum (e.g. PyMESS .h5 setup 12)
exp = cal.load_experimental_spectrum("probe_polystyrene.h5", cal_type_code=12)
# 3. Perform wavelength calibration fit
res = cal.fit_wavelength_axis(
meas_y=exp.detector_data[0],
ref_x=ref.spectral_axis,
ref_y=ref.absorbance,
cal_type_code=12,
cwl=exp.cwl[0],
use_derivative="1st",
spectral_range=exp.spectral_range,
)
print(f"Calibrated span: {res.wavelength_nm[0]:.2f} nm to {res.wavelength_nm[-1]:.2f} nm")
cal.save_calibration_file(res.wavenumber_cm1, "output_dir", filename="CalibratedProbe.csv")
# 4. Fit probe beam Gaussian profiles (multi-detector)
probe_fit = cal.fit_probe_spectrum(exp.detector_data, exp.cwl)
for det_idx, fit in enumerate(probe_fit.fits):
print(f"Detector {det_idx}: w0={fit.w0:.1f} cm-1, FWHM={fit.fwhm:.1f} cm-1")
# 5. Query default parameters for a given setup
params = cal.get_default_calibration_params(cal_type_code=11, harpia_preset="UV")
print(params["degree"], params["cwl_guess"])