MenuMENU

EasyCalibrate Pro

Wavelength calibration of spectrometers using second-order polynomials

In the EasyCalibrate script, we showed how to perform wavelength calibration (i. e., the assignment of pixels ➙ wavelength (nm) for our DIY spectrometers) with just a few lines of Python script. For this purpose, linear regression was used, which is perfectly adequate for simple applications with low calibration requirements.

However, if you want to perform more sophisticated experiments, you will quickly find that linear calibration is not sufficient for this purpose. The use of second-degree polynomials provides a remedy here.

On this page, we present a corresponding improved Python script. With this script, our DIY spectrometers can be calibrated so that, for example, the positions of the emission peaks across the entire sensor area can be determined in the experiment with an accuracy of a few tenths of a nanometer.

Wavelength calibration with red CCFL (cold cathode fluorescent lamp) as reference source

For the demonstration of the script, a red cold cathode lamp (CCFL) is used here as an example reference source, since these light sources are relatively easy and inexpensive to obtain (we are also happy to help here).

They are used, for example, in the effect lighting of gaming PCs or as LCD backlights.

But in general, CCFLs offer a number of additional advantages:

  • they can be operated with the aid of a battery-powered inverter;
  • In the start-up phase, CCFLs show several narrow emission lines between 435 nm and 810 nm, which are distributed relatively evenly across the sensitivity range of our DIY spectrometer; this is very practical for reliable and robust polynomial calibration using quadratic fit;
  • the position of the emission lines is very temperature-stable.

However, other light sources (such as LEDs or laser diodes) with known emission maxima can also be used for calibration. Bandpass or edge filters are also suitable. Some of these options are already prepared (but commented out) in the example script. These can be reactivated at any time if required and modified with the wavelengths and designations specifically used by the user.

Short and compact: What EasyCalibratePro can do

The software provides a live display of the line-scan camera data (counts versus pixel, and after calibration also with a wavelength scale) and allows you to set the integration time as well as start and stop the camera.

Reference peaks can be marked interactively, either via right-click or by pressing the spacebar.

Calibration is performed using a fit depending on the number of reference points: with two reference points a linear fit is used, and with three or more reference points a quadratic fit (2nd order) is applied. The calibration can be saved and reloaded; for compatibility with other scripts, both a CSV file and a TXT file are generated. In addition, the current spectrum can be exported as a CSV file (pixel, counts, and optionally wavelength).

The workflow explained quickly

  1. Start script
    python EasyCalibratePro.py
  2. Switch on CCFL and measure immediately
    The argon lines are still present in the first ~20 s.
  3. Stop live readout (Start/Stop)
    Live readout is stopped for reproducible peak setting.
  4. Prepare calibration dialog
    Open »Start Calibration,« reference buttons are visible.
  5. Select reference ➙ Set peak
    Set by right-clicking or pressing the space bar (both are bound).
  6. Calculate fit (Calibrate)
    • 2 points: linear
    • ≥3 points: quadratic (2nd order)
  7. Save calibration (Save)
    A CSV file (a,b,c) and, optionally, a TXT file for older tools are created.

The complete Python script is available for download here. Only the most important passages are discussed in detail below.


Screen video: »Calibration with red CCFL (during the start phase)«

This video shows the workflow when using the script. First, after switching on the lamp, an integration time is selected at which the reference peaks are clearly visible. After stopping the camera, the lines can then be identified and marked at leisure.

Special feature of CCFL calibration: Measurement window approx. 20 seconds.

In the red CCFL, in addition to the Hg lines, Argon lines are also clearly visible at the beginning. These Argon lines are particularly valuable for calibration because they provide additional reference points in the red/NIR range. However, they disappear within about 20 seconds once the lamp reaches operating temperature.

Why? During warm-up, the mercury vapor pressure/concentration in the tube rises; the spectrum becomes increasingly dominated by Hg processes, and Argon emissions fade into the background (depending on the lamp type, this happens faster or slower).

After warm-up, the spectrum is stable, but less attractive for a "multi-point" calibration: The red color now mainly comes from a phosphor that has strong emission around approx. 615 nm and weaker components between approx. 575–625 nm; the additional Argon lines are no longer available.

For calibration, the reference lines should therefore be made visible within the first ~20 seconds after switching on by choosing an appropriate integration time, and then the camera should be stopped. In practice, this also means that the calibration script should already be running before the CCFL is turned on.

 

Calibration quality: Best practices

The quality of a calibration depends primarily on the selected reference peaks and the integration time used!

Be aware of the time window:
The references should be quick and easy to find. Here, for example, set them within the first ~20 s before the argon lines disappear. Use prepared »fingerprints« (see below) of the required signals!
Distribute reference points cleverly:
Do not just calibrate »in the middle«; deliberately include lines at the ends of the measuring range (here, for example: Ar 696/763/810).
Avoid saturation:
Peaks must not be »cut off« at the top because the sensor may be overdriven/saturated; otherwise, the maximum will shift.
Mark peak maximum::
For emission lines, always select the maximum, not an edge. Edges are more suitable when using edge filters.

»Spectral fingerprint«: The positions of the emission lines used in the script are marked in this spectrum. Simply click and print: This should make it easy to identify the corresponding lines during calibration.


Reference lines in the script: CCFL (Hg/Ar) as an example configuration

At the beginning of the script, the reference source is selected via a commented-out block. Five reference points are prepared for the red CCFL (Hg/Ar):

# calibration data for five emission lines (Hg/Ar) of a red CCFL (Cold Cathode Fluorescent Lamp)

# number of calibration points (min. 2, max. 5)
N_REF_POINTS = 5  

# wavelengths of the calibartion lines/points
ref_values_nm = [435.83, 546.07, 696.54, 763.51, 810.37][:N_REF_POINTS]

# label of buttons
ref_labels = ["Peak for \"Hg 435\"", "Peak for \"Hg 546\"", "Peak for \"Ar 696\"", "Peak for \"Ar 763\"", "Peak for \"Ar 810\""][:N_REF_POINTS]


The script also already contains (commented-out) sections for the use of other reference sources, including for bandpass filters or inexpensive laser diode modules.


Second-order polynomial regression in spectrometer calibration

Why is »linear« often not enough?

Over larger spectral ranges, the »pixel ➙ wavelength« mapping in real setups is often slightly nonlinear (optical geometry, imaging errors, dispersion effects). A quadratic approach is an established, stable compromise here: significantly more accurate than linear, but much more robust than higher polynomials.

Model and fit in the script

A quadratic model is used for three or more reference points:

λ(px)=apx2+bpx+c
 

In the code (key lines):

               a, b, c = np.polyfit(pixels, waves, 2)
               polyfit = np.poly1d([a, b, c])
 

With exactly two points, a linear fit is automatically applied.

 

Here you can easily ask a question or inquiry about our products:

Product inquiry

Request for:


Last update: 2026-22-01