Skip to content
Merged
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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@
},
"homepage": "https://github.com/mljs/signal-processing#readme",
"devDependencies": {
"@vitest/coverage-v8": "^3.2.3",
"@vitest/coverage-v8": "^3.2.4",
"@zakodium/tsconfig": "^1.0.2",
"eslint": "^9.29.0",
"eslint-config-cheminfo-typescript": "^18.0.1",
"eslint": "^9.33.0",
"eslint-config-cheminfo-typescript": "^19.0.0",
"jest-matcher-deep-close-to": "^3.0.2",
"prettier": "^3.5.3",
"prettier": "^3.6.2",
"rimraf": "^6.0.1",
"typescript": "^5.8.3",
"typescript": "^5.9.2",
"typescript-json-schema": "^0.65.1",
"vitest": "^3.2.3"
"vitest": "^3.2.4"
},
"dependencies": {
"baselines": "^1.1.9",
"cheminfo-types": "^1.8.1",
"ml-gsd": "^13.0.1",
"ml-savitzky-golay-generalized": "^4.2.0",
"ml-spectra-processing": "^14.12.0"
"ml-spectra-processing": "^14.17.0"
}
}
8 changes: 4 additions & 4 deletions src/FilterXYType.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import type {
AirPLSBaselineFilter,
CalibrateFilter,
CenterMeanFilter,
CenterMedianFilter,
DivideBySDFilter,
EnsureGrowingFilter,
EquallySpacedFilter,
FilterXFilter,
FirstDerivativeFilter,
IterativePolynomialBaselineFilter,
FromToFilter,
IterativePolynomialBaselineFilter,
NormedFilter,
ParetoNormalizationFilter,
RescaleFilter,
RollingAverageBaselineFilter,
RollingBallBaselineFilter,
RollingMedianBaselineFilter,
SavitzkyGolayFilter,
SecondDerivativeFilter,
ThirdDerivativeFilter,
FilterXFilter,
XFunctionFilter,
YFunctionFilter,
CalibrateFilter,
ParetoNormalizationFilter,
} from './filters/filters.ts';
import type { ReverseIfNeededFilter } from './filters/x/reverseIfNeeded.ts';

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/filterMatrix.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import type { FilterMatrixType } from '../FilterMatrixType.ts';
import { filterMatrix } from '../index.ts';
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/filterXY.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';

import type { FilterXYType } from '../FilterXYType.ts';
import linear from '../filters/__tests__/data/linear.ts';
Expand All @@ -12,6 +12,7 @@ describe('filterXY', () => {
];

const result = filterXY(linear, filters);

expect(result.data).toStrictEqual({
x: Float64Array.from([2, 3, 4, 5, 6, 7, 8]),
y: Float64Array.from([-1, 0, 1, 2, 1, 0, -1]),
Expand All @@ -25,6 +26,7 @@ describe('filterXY', () => {
y: Float64Array.from([1, 2, 3, 4, 1]),
};
const result = filterXY(data, filters);

expect(result.data).toStrictEqual({
x: Float64Array.from([1, 2, 3, 4, 5]),
y: Float64Array.from([1, 2, 3, 4, 1]),
Expand All @@ -38,6 +40,7 @@ describe('filterXY', () => {
y: Float64Array.from([1, 2, 3, 4, 1]),
};
const result = filterXY(data, filters);

expect(result.data).toStrictEqual({
x: Float64Array.from([1, 2, 3, 4, 5]),
y: Float64Array.from([1, 4, 3, 2, 1]),
Expand Down
3 changes: 2 additions & 1 deletion src/filters/baseline/__tests__/airPLSBaseline.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import baseline from '../../__tests__/data/baseline.ts';
import { airPLSBaseline } from '../airPLSBaseline.ts';

test('airPLSBaseline', () => {
const result = airPLSBaseline(baseline);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([0, 0, 0, 0, 4, 0, 0, 0, 0]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import baseline from '../../__tests__/data/baseline.ts';
import { iterativePolynomialBaseline } from '../iterativePolynomialBaseline.ts';

test('iterativePolynomialBaseline', () => {
const result = iterativePolynomialBaseline(baseline);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import baseline from '../../__tests__/data/baseline.ts';
import { rollingAverageBaseline } from '../rollingAverageBaseline.ts';

test('rollingAverageBaseline', () => {
const result = rollingAverageBaseline(baseline);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([0, 0, 0, 0, 2, -2, 0, 0, 0]),
Expand Down
3 changes: 2 additions & 1 deletion src/filters/baseline/__tests__/rollingBallBaseline.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import baseline from '../../__tests__/data/baseline.ts';
import { rollingBallBaseline } from '../rollingBallBaseline.ts';

test('rollingBallBaseline', () => {
const result = rollingBallBaseline(baseline);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([0, 0, 0, 0, 4, 0, 0, 0, 0]),
Expand Down
3 changes: 2 additions & 1 deletion src/filters/baseline/__tests__/rollingMedianBaseline.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import baseline from '../../__tests__/data/baseline.ts';
import { rollingMedianBaseline } from '../rollingMedianBaseline.ts';

test('rollingMedianBaseline', () => {
const result = rollingMedianBaseline(baseline);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([0, 0, 0, 0, 4, 0, 0, 0, 0]),
Expand Down
3 changes: 2 additions & 1 deletion src/filters/scaling/__tests__/centerMean.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { centerMean } from '../centerMean.ts';

test('centerMean', () => {
const result = centerMean(linear);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([
Expand Down
3 changes: 2 additions & 1 deletion src/filters/scaling/__tests__/centerMedian.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { centerMedian } from '../centerMedian.ts';

test('centerMedian', () => {
const result = centerMedian(linear);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([-2, -1, 0, 1, 2, 1, 0, -1, -2]),
Expand Down
3 changes: 2 additions & 1 deletion src/filters/scaling/__tests__/divideBySD.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { divideBySD } from '../divideBySD.ts';

test('divideBySD', () => {
const result = divideBySD(linear);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([
Expand Down
3 changes: 2 additions & 1 deletion src/filters/scaling/__tests__/normed.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { normed } from '../normed.ts';

test('normed', () => {
const result = normed(linear, { algorithm: 'max', value: 10 });

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([2, 4, 6, 8, 10, 8, 6, 4, 2]),
Expand Down
3 changes: 2 additions & 1 deletion src/filters/scaling/__tests__/paretoNormalization.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import { paretoNormalization } from '../paretoNormalization.ts';

Expand All @@ -9,6 +9,7 @@ test('paretoNormalization', () => {
};

const result = paretoNormalization(data);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([2, 3, 4]),
y: Float64Array.from([
Expand Down
3 changes: 2 additions & 1 deletion src/filters/scaling/__tests__/rescale.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { rescale } from '../rescale.ts';

test('rescale', () => {
const result = rescale(linear, { min: 1, max: 2 });

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([1, 1.25, 1.5, 1.75, 2, 1.75, 1.5, 1.25, 1]),
Expand Down
7 changes: 6 additions & 1 deletion src/filters/scaling/__tests__/yFunction.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { yFunction } from '../yFunction.ts';

describe('yFunction', () => {
it('nothing to do', () => {
const result = yFunction(linear, {});

expect(result.data).toMatchCloseTo({
y: [1, 2, 3, 4, 5, 4, 3, 2, 1],
});
});

it('y+2', () => {
const result = yFunction(linear, {
function: 'y+2',
});

expect(result.data).toMatchCloseTo({
x: [1, 2, 3, 4, 5, 6, 7, 8, 9],
y: [3, 4, 5, 6, 7, 6, 5, 4, 3],
});
});

it('pow(y,2)', () => {
const result = yFunction(linear, {
function: 'pow(y,2)',
});

expect(result.data).toMatchCloseTo({
x: [1, 2, 3, 4, 5, 6, 7, 8, 9],
y: [1, 4, 9, 16, 25, 16, 9, 4, 1],
Expand Down
3 changes: 2 additions & 1 deletion src/filters/sg/__tests__/firstDerivative.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { firstDerivative } from '../firstDerivative.ts';

test('firstDerivative', () => {
const result = firstDerivative(linear);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([
Expand Down
3 changes: 2 additions & 1 deletion src/filters/sg/__tests__/savitzkyGolay.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { savitzkyGolay } from '../savitzkyGolay.ts';
Expand All @@ -7,6 +7,7 @@ test('savitzkyGolay', () => {
const result = savitzkyGolay(linear, {
derivative: 1,
});

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([
Expand Down
3 changes: 2 additions & 1 deletion src/filters/sg/__tests__/secondDerivative.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { secondDerivative } from '../secondDerivative.ts';

test('secondDerivative', () => {
const result = secondDerivative(linear);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([
Expand Down
3 changes: 2 additions & 1 deletion src/filters/sg/__tests__/thirdDerivate.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from 'vitest';
import { expect, test } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { thirdDerivative } from '../thirdDerivative.ts';

test('thirdDerivative', () => {
const result = thirdDerivative(linear);

expect(result.data).toMatchCloseTo({
x: Float64Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
y: Float64Array.from([0, 0, 0, 0, 0, 0, 0, 0, 0]),
Expand Down
6 changes: 5 additions & 1 deletion src/filters/x/__tests__/calibrateX.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';

import { calibrateX } from '../calibrateX.ts';

Expand All @@ -10,6 +10,7 @@ describe('calibrateX', () => {
};

const shifted = calibrateX(data);

expect(shifted.data.x).toMatchCloseTo(
Float64Array.from([-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]),
);
Expand All @@ -21,6 +22,7 @@ describe('calibrateX', () => {
x: Float64Array.from([0, 1, 2, 3]),
y: Float64Array.from([1, 1, 5, 1]),
};

expect(() => calibrateX(data, { from: 1, to: 10 })).toThrow(
'Window size is higher than the data lengt',
);
Expand Down Expand Up @@ -77,6 +79,7 @@ describe('calibrateX', () => {
from: 1,
to: 10,
});

// because we look for the real maximum it is not exactly 2
expect(shifted.data.x).toMatchCloseTo(
Float64Array.from([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]),
Expand Down Expand Up @@ -112,6 +115,7 @@ describe('calibrateX', () => {
gsd: gsdOptions,
nbPeaks: 2,
});

// because we look for the real maximum it is not exactly 2
expect(shifted.data.x).toMatchCloseTo(
Float64Array.from([
Expand Down
3 changes: 2 additions & 1 deletion src/filters/x/__tests__/ensureGrowing.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';

import { ensureGrowing } from '../ensureGrowing.ts';

Expand All @@ -7,6 +7,7 @@ import linear from './data/nonGrowing.ts';
describe('ensureGrowing', () => {
it('nothing to do', () => {
const result = ensureGrowing(linear);

expect(result.data).toMatchCloseTo({
x: [1, 3, 5, 6, 7, 8, 9],
y: [1, 3, 5, 4, 3, 2, 1],
Expand Down
3 changes: 2 additions & 1 deletion src/filters/x/__tests__/equallySpaced.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';

import linear from '../../__tests__/data/linear.ts';
import { equallySpaced } from '../equallySpaced.ts';
Expand All @@ -9,6 +9,7 @@ describe('equallySpaced', () => {
exclusions: [{ from: 2, to: 7 }],
numberOfPoints: 5,
});

expect(result.data).toMatchCloseTo({
x: [1, 2, 7, 8, 9],
y: [1, 2, 3, 2, 1],
Expand Down
Loading
Loading