Skip to content

Commit 7504497

Browse files
committed
fix: calibrateX didn't move the x axis in the right direction
1 parent 0cc5064 commit 7504497

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/filters/x/__tests__/calibrateX.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('calibrateX', () => {
1313

1414
let shifted = calibrateX(data);
1515
expect(shifted.data.x).toMatchCloseTo(
16-
Float64Array.from([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]),
16+
Float64Array.from([-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]),
1717
);
1818
expect(shifted.data.y).toStrictEqual(data.y);
1919
});
@@ -81,8 +81,10 @@ describe('calibrateX', () => {
8181
});
8282
// because we look for the real maximum it is not exactly 2
8383
expect(shifted.data.x).toMatchCloseTo(
84-
Float64Array.from([-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
84+
Float64Array.from([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]),
85+
);
86+
expect(shifted.data.y).toStrictEqual(
87+
Float64Array.from([1, 1, 1, 1, 700, 1, 5, 1, 1, 1, 1, 1, 1]),
8588
);
86-
expect(shifted.data.y).toStrictEqual(data.y);
8789
});
8890
});

src/filters/x/calibrateX.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DataXY } from 'cheminfo-types';
22
import { gsd, GSDOptions } from 'ml-gsd';
3-
import { xFindClosestIndex, xMean, xSubtract } from 'ml-spectra-processing';
3+
import { xFindClosestIndex, xMean, xAdd } from 'ml-spectra-processing';
44

55
export interface CalibrateFilter {
66
name: 'calibrateX';
@@ -68,5 +68,5 @@ export function calibrateX(
6868
if (peaks.length === 0) return { data };
6969

7070
const middle = xMean(peaks.map((peak) => peak.x));
71-
return { data: { x: xSubtract(data.x, targetX - middle), y: data.y } };
71+
return { data: { x: xAdd(data.x, targetX - middle), y: data.y } };
7272
}

0 commit comments

Comments
 (0)