Import/Export of JCAMP-DX files

JCAMP-DX is an open format initially developed for IR data and extended to other spectroscopies. At present, the JCAMP-DX reader implemented in SpectroChemPy is limited to IR data and AFFN encoding (see [McDonald and Paul A. Wilks, 1988].

The JCAMP-DX reader of SpectroChemPy has been essentially written to read JCAMP-DX files exported by the SpectroChemPy write_jdx() writer.

[1]:
import spectrochempy as scp

X = scp.read_omnic("irdata//CO@Mo_Al2O3.SPG")
S0 = X[0]
S0
  SpectroChemPy's API - v.0.8.2.dev7
©Copyright 2014-2025 - A.Travert & C.Fernandez @ LCS
Running on GitHub Actions
MPL Configuration directory: /home/runner/.config/matplotlib
Stylelib directory: /home/runner/.config/matplotlib/stylelib
[1]:
NDDataset: [float64] a.u. (shape: (y:1, x:3112))[CO@Mo_Al2O3]
Summary
name
:
CO@Mo_Al2O3
author
:
runner@fv-az2211-104
created
:
2025-04-27 01:45:39+00:00
description
:
Omnic title: Group sust Mo_Al2O3_base line.SPG
Omnic filename: /home/runner/.spectrochempy/testdata/irdata/CO@Mo_Al2O3.SPG
history
:
2025-04-27 01:45:39+00:00> Imported from spg file /home/runner/.spectrochempy/testdata/irdata/CO@Mo_Al2O3.SPG.
2025-04-27 01:45:39+00:00> Sorted by date
2025-04-27 01:45:39+00:00> Slice extracted: (0)
Data
title
:
absorbance
values
:
...
[[0.0008032 3.788e-05 ... 0.0003027 0.0003745]] a.u.
shape
:
(y:1, x:3112)
Dimension `x`
size
:
3112
title
:
wavenumbers
coordinates
:
[ 4000 3999 ... 1001 999.9] cm⁻¹
Dimension `y`
size
:
1
title
:
acquisition timestamp (GMT)
coordinates
:
[1.477e+09] s
labels
:
...
[[ 2016-10-18 13:49:35+00:00]
[ *Résultat de Soustraction:04_Mo_Al2O3_calc_0.003torr_LT_after sulf_Oct 18 15:46:42 2016 (GMT+02:00)]]
[2]:
S0.write_jcamp("CO@Mo_Al2O3_0.jdx", confirm=False)
[2]:
PosixPath('/home/runner/work/spectrochempy/spectrochempy/docs/sources/userguide/importexport/CO@Mo_Al2O3_0.jdx')

Then used (and maybe changed) by a 3rd party software, and re-imported in spectrochempy:

[3]:
newS0 = scp.read_jcamp("CO@Mo_Al2O3_0.jdx")
newS0
[3]:
NDDataset: [float64] a.u. (shape: (y:1, x:3112))[CO@Mo_Al2O3]
Summary
name
:
CO@Mo_Al2O3
author
:
runner@fv-az2211-104
created
:
2025-04-27 01:45:39+00:00
description
:
Dataset from jdx file: 'CO@Mo_Al2O3'
history
:
2025-04-27 01:45:39+00:00> Imported from jdx file
Data
title
:
absorbance
values
:
...
[[0.0008032 3.787e-05 ... 0.0003027 0.0003745]] a.u.
shape
:
(y:1, x:3112)
Dimension `x`
size
:
3112
title
:
wavenumbers
coordinates
:
[ 4000 3999 ... 1001 999.9] cm⁻¹

It is important to note here that the conversion to JCAMP-DX changes the last digits of absorbance and wavenumbers:

[4]:
from spectrochempy.utils.compare import difference
[5]:
max_error, max_rel_error = difference(S0, newS0)
print(f"Max absolute difference in absorbance: {max_error:.3g}")
print(f"Max relative difference in absorbance: {max_rel_error:.3g}")
Max absolute difference in absorbance: 1.12e-08
Max relative difference in absorbance: 0.863
[6]:
max_error, max_rel_error = difference(S0.x, newS0.x)
print(f"Max absolute difference in wavenumber: {max_error:.3g}")
print(f"Max relative difference in wavenumber: {max_rel_error:.3g}")
Max absolute difference in wavenumber: 0
Max relative difference in wavenumber: 0

But this is much beyond the experimental accuracy of the data.