Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"homepage": "https://github.com/cheminfo/spectra-processor#readme",
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
"@types/chroma-js": "^3.1.2",
"@types/node": "^24.10.2",
"@types/object-hash": "^3.0.6",
"@vitest/coverage-v8": "^4.0.15",
"@zakodium/tsconfig": "^1.0.2",
"cheminfo-build": "^1.3.1",
Expand Down
84 changes: 84 additions & 0 deletions src/Kinds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import type { Entry } from 'jcampconverter';

/**
* Display options for spectroscopy data
*/
export interface DisplayOptions {
xLabel: string;
xInverted: boolean;
yLabel: string;
}

/**
* Kind object defining how to handle a spectrum
*/
export interface Kind {
normalization?: Record<string, any>;
importation?: {
converter: (value: number) => number;
};
kind?: string;
display: DisplayOptions;
}

/**
* Determines the appropriate Kind based on JCAMP data
* @param data - JCAMP entry data
* @returns The appropriate Kind or undefined
*/
export function getJcampKind(data: Entry): Kind | undefined {
if (!data.dataType || !data.spectra?.[0]?.yUnits) {
return undefined;
}

const dataType = data.dataType.toLowerCase();
const yUnits = data.spectra[0].yUnits.toLowerCase();

if (dataType.match(/infrared/)) {
if (yUnits.match(/absorbance/)) {
return IR_ABSORBANCE;
} else {
return IR_TRANSMITTANCE;
}
}
return undefined;
}

export const IR_TRANSMITTANCE: Kind = {
normalization: {},
importation: {
converter: (transmittance: number) => -Math.log10(transmittance),
},
kind: 'Infrared',
display: {
xLabel: 'wavelength [cm-1]',
xInverted: true,
yLabel: 'Absorbance',
},
};

export const IR_ABSORBANCE: Kind = {
normalization: {},
kind: 'Infrared',
display: {
xLabel: 'wavelength [cm-1]',
xInverted: true,
yLabel: 'Absorbance',
},
};

export const nmr1H: Kind = {
display: {
xLabel: 'δ [ppm]',
xInverted: true,
yLabel: 'Intensity',
},
};

export const nmr13C: Kind = {
display: {
xLabel: 'δ [ppm]',
xInverted: true,
yLabel: 'Intensity',
},
};
Loading