Skip to content

Repository files navigation

spc-parser

Parser for .spc spectroscopy files: Thermo Galactic GRAMS SPC and Shimadzu UVProbe (OLE2 and flat). The format is auto-detected.

Zakodium logo

Maintained by Zakodium

NPM version build status Test coverage npm download DOI

Installation

$ npm i spc-parser

This package is ESM-only. It requires Node.js ≥ 20.19, ≥ 22.12, or any 24.x or later, or a bundler. CommonJS consumers must import it (no require).

Usage

import { readFileSync } from 'node:fs';
import { join } from 'node:path';

import { parse } from 'spc-parser';

const arrayBuffer = readFileSync(join(import.meta.dirname, 'spectrum.spc'));

const result = parse(arrayBuffer);
// result is a JSON object containing everything that was parsed

Exports

Export Description
parse(buffer) Parses an .spc file, auto-detecting the format. Accepts an ArrayBuffer, a typed array / DataView, a Node.js Buffer, or an IOBuffer. Returns a ParseResult.
guessSpectraType(meta) Classifies a parsed Galactic Header as 'ir' | 'uv' | 'raman' | 'mass' | 'other'.

ParseResult has three properties: meta (the Galactic Header or the Shimadzu UvProbeMeta), spectra (an array of MeasurementXY from cheminfo-types) and logs (the Galactic log block, null or absent when the file has none).

parse throws when the buffer is neither an OLE2 compound document, a Thermo Galactic SPC, nor a Shimadzu UVProbe flat file.

Credits and useful information

SPC file format

SPC is a file format used in the GRAMS Software Suite for storing all kinds of spectroscopic data, including infrared spectra, Raman spectra and UV/VIS spectra. The data is stored in binary with some parts encoded in ASCII. As such, the file must be viewed in either a hex editor or any compatible spectroscopy software.

An SPC file is organized in three blocks:

  1. File-Header block
  2. Data block
  3. Log block

The File Header contains information about the whole file, such as how values are read, the type of format (Old, New LSB, New MSB), the structure of the data block (XY, XYY or XYXY) and the number of spectra.

The Data block contains the spectrum data and is composed of a subheader for each spectrum, the X values before the subheader if XY or XYY, else after each subheader if XYXY. After the subheader and X values come the Y values, which are read according to the method determined in the Main Header.

The Log block contains miscellaneous information that varies for each file, with a part written in ASCII and another one in binary.

Useful files for the specification for the spc-format can be found at the docs folder in the Github repo

License

MIT

About

Parse SPC files in javascript

Resources

Stars

4 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages