Skip to content

Commit

Permalink
feat!: improve appendCalibration and rename after / before
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Apr 24, 2024
1 parent 0f634a9 commit 17ce030
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/parser/casa/__tests__/appendCalibration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ Calib M = 1.1 A = 5.1 ADD`;
expect(calibrations).toHaveLength(3);
expect(calibrations).toStrictEqual([
{
after: 20.1,
before: 10.1,
referenced: 20.1,
measured: 10.1,
bindingEnergyShift: 10.000000000000002,
kind: 'bindingEnergy',
kineticEnergyShift: -10.000000000000002,
},
{
after: 40.2,
before: 20.2,
referenced: 40.2,
measured: 20.2,
bindingEnergyShift: 20.000000000000004,
kind: 'bindingEnergy',
kineticEnergyShift: -20.000000000000004,
},
{
after: 5.1,
before: 1.1,
referenced: 5.1,
measured: 1.1,
bindingEnergyShift: -3.9999999999999996,
kind: 'kineticEnergy',
kineticEnergyShift: 3.9999999999999996,
Expand Down
21 changes: 16 additions & 5 deletions src/parser/casa/appendCalibration.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
/**
* Referencing: (energy calibration, typically performed on the binding energy scale)
" Calib M = 0 A = 3.111 ADD"
* means that the block should be shifted in binding energy by adding the difference A - M = 3.111 eV. M is not necessarily 0.
* If the line contains BE, it means that the operation should be done on the BE scale,
* alternatively, simply change the sign of the difference, here it would be -3,111, to be added to the data in the binding energy scale.
* @param {object} calibrations
* @param {string} line
*/


export function appendCalibration(calibrations, line) {
let calibration = {};
// Calib M = 281.1700 A = 284.8 BE ADD
// calibration may be present on many lines

let fields = line.match(
/Calib M = (?<before>.*) A = (?<after>[^ ]*) (?<rest>.*)/,
/Calib M = (?<measured>.*) A = (?<referenced>[^ ]*) (?<rest>.*)/,
);
if (!fields) {
throw new Error(`appendCalibration fails on: ${line}`);
Expand All @@ -14,13 +25,13 @@ export function appendCalibration(calibrations, line) {
`appendCalibration fails because line does not contain ADD: ${line}`,
);
}
calibration.before = Number(fields.groups.before);
calibration.after = Number(fields.groups.after);
calibration.measured = Number(fields.groups.measured);
calibration.referenced = Number(fields.groups.referenced);
if (fields.groups.rest.includes('BE')) {
calibration.bindingEnergyShift = calibration.after - calibration.before;
calibration.bindingEnergyShift = calibration.referenced - calibration.measured;
calibration.kind = 'bindingEnergy';
} else {
calibration.bindingEnergyShift = calibration.before - calibration.after;
calibration.bindingEnergyShift = calibration.measured - calibration.referenced;
calibration.kind = 'kineticEnergy';
}
calibration.kineticEnergyShift = -calibration.bindingEnergyShift;
Expand Down

0 comments on commit 17ce030

Please sign in to comment.