nzhagen / jcamp

A set of Python utilities for reading JCAMP-DX files.
MIT License
54 stars 31 forks source link

`JCAMP_calc_xsec`: tolerate arbitrary values for YUNITS? #29

Open sumpfralle opened 1 year ago

sumpfralle commented 1 year ago

The latest specification describes the YUNITS field as follows:

can be ARBITRARY UNITS, STRING

The following example values are mentioned in the specification:

But in JCAMP_calc_xsec the current implementation of jcamp seems to insist on specific values:

Personally I am surprised, that a function named JCAMP_calc_xsec interferes with y values at all.

Maybe this adjustment of y_values could be optional? Or it could tolerate unknown values in order to skip the adjustment of y values?

My current workaround is to set yunits to absorbance (which seems to skip this processing step).

I am willing to prepare a proposal, if you can hint me at your preferred solution.

nzhagen commented 1 year ago

Actually, I wrote "jcamp_calc_xsec" as a convenient way to convert the units of the input spectrum into absorption cross-section. If the input spectrum supplies arbitrary units, then there will be no easy way to know how to convert this to absorption cross-section. The three examples shown here of y-units are taken from the various JCAMP files that I've used in the past as part of the NIST infrared spectral database.

When you mention about the adjustment of the y values, do you mean that running "jcamp_calc_xsec()" will change the y values of the original input? It certainly wasn't meant to do that, so if it does then that behavior should be considered a bug. (A bug which I didn't encounter because I'm always converting my spectra to xsec.)

nzhagen commented 1 year ago

I saw where in the code that this function can change the y-values. I made a slight modification to make sure that the input will not get changed.

As for the "power" or "intensity" values -- I can't see any way to convert these to cross-section values without knowing the representation of these in their basic units.

Is there something different that would work better for you?