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
22 changes: 11 additions & 11 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.4",
"@vitest/coverage-v8": "^4.0.16",
"@zakodium/tsconfig": "^1.0.2",
"eslint": "^9.35.0",
"eslint-config-cheminfo-typescript": "^20.0.0",
"eslint": "^9.39.2",
"eslint-config-cheminfo-typescript": "^21.0.1",
"jest-matcher-deep-close-to": "^3.0.2",
"prettier": "^3.6.2",
"rimraf": "^6.0.1",
"typescript": "^5.9.2",
"typescript-json-schema": "^0.65.1",
"vitest": "^3.2.4"
"prettier": "^3.7.4",
"rimraf": "^6.1.2",
"typescript": "^5.9.3",
"typescript-json-schema": "^0.67.1",
"vitest": "^4.0.16"
},
"dependencies": {
"baselines": "^1.1.9",
"cheminfo-types": "^1.8.1",
"ml-gsd": "^13.0.1",
"cheminfo-types": "^1.10.0",
"ml-gsd": "^13.1.1",
"ml-savitzky-golay-generalized": "^4.2.0",
"ml-spectra-processing": "^14.17.1"
"ml-spectra-processing": "^14.19.0"
}
}
2 changes: 1 addition & 1 deletion src/__tests__/filterXY.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ test('unknown filter', () => {
y: Float64Array.from([1, 2, 3, 4, 1]),
};

expect(() => filterXY(data, filters)).toThrow('Unknown filter: abc');
expect(() => filterXY(data, filters)).toThrowError('Unknown filter: abc');
});
2 changes: 1 addition & 1 deletion src/filterMatrix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DoubleMatrix } from 'ml-spectra-processing';
import type { DoubleMatrix } from 'cheminfo-types';

import type { FilterMatrixType } from './FilterMatrixType.ts';

Expand All @@ -12,7 +12,7 @@
data: matrix,
};

const logs: any = [];

Check warning on line 15 in src/filterMatrix.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type

/**
* todo
Expand Down
9 changes: 6 additions & 3 deletions src/filterXY.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DataXY } from 'cheminfo-types';
import type { DataXY, DoubleArray } from 'cheminfo-types';
import { xEnsureFloat64, xyGrowingX } from 'ml-spectra-processing';

import type { FilterXYType } from './FilterXYType.ts';
Expand All @@ -6,11 +6,14 @@

/**
* Apply filters on {x:[], y:[]}
* @param data

Check warning on line 9 in src/filterXY.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "data" description
* @param filters

Check warning on line 10 in src/filterXY.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "filters" description
* @returns A very important number
* @returns

Check warning on line 11 in src/filterXY.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @returns description
*/
export function filterXY(data: DataXY, filters: FilterXYType[]) {
export function filterXY(
data: DataXY,
filters: FilterXYType[],
): { logs: Array<{ name: string; time: number }>; data: DataXY<DoubleArray> } {
let result = {
data: xyGrowingX({ x: xEnsureFloat64(data.x), y: xEnsureFloat64(data.y) }),
};
Expand Down
4 changes: 3 additions & 1 deletion src/filters/baseline/airPLSBaseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
name: 'airPLSBaseline';
}

/**

Check warning on line 9 in src/filters/baseline/airPLSBaseline.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @returns declaration

Check warning on line 9 in src/filters/baseline/airPLSBaseline.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc block description
* @param data

Check warning on line 10 in src/filters/baseline/airPLSBaseline.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "data" description
*/
export function airPLSBaseline(data: DataXY<Float64Array>) {
export function airPLSBaseline(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
data.y = baselineFct(data.y).correctedSpectrum;
return { data };
}
4 changes: 3 additions & 1 deletion src/filters/baseline/iterativePolynomialBaseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
name: 'iterativePolynomialBaseline';
}

/**

Check warning on line 9 in src/filters/baseline/iterativePolynomialBaseline.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @returns declaration

Check warning on line 9 in src/filters/baseline/iterativePolynomialBaseline.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc block description
* @param data

Check warning on line 10 in src/filters/baseline/iterativePolynomialBaseline.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Missing JSDoc @param "data" description
*/
export function iterativePolynomialBaseline(data: DataXY<Float64Array>) {
export function iterativePolynomialBaseline(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
data.y = baselineFct(data.y).correctedSpectrum;
return { data };
}
4 changes: 3 additions & 1 deletion src/filters/baseline/rollingAverageBaseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface RollingAverageBaselineFilter {
/**
* @param data
*/
export function rollingAverageBaseline(data: DataXY<Float64Array>) {
export function rollingAverageBaseline(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
data.y = baselineFct(data.y).correctedSpectrum;
return { data };
}
4 changes: 3 additions & 1 deletion src/filters/baseline/rollingBallBaseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface RollingBallBaselineFilter {
/**
* @param data
*/
export function rollingBallBaseline(data: DataXY<Float64Array>) {
export function rollingBallBaseline(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
data.y = baselineFct(data.y).correctedSpectrum;
return { data };
}
4 changes: 3 additions & 1 deletion src/filters/baseline/rollingMedianBaseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface RollingMedianBaselineFilter {
/**
* @param data
*/
export function rollingMedianBaseline(data: DataXY<Float64Array>) {
export function rollingMedianBaseline(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
data.y = baselineFct(data.y).correctedSpectrum;
return { data };
}
4 changes: 3 additions & 1 deletion src/filters/scaling/centerMean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface CenterMeanFilter {
* Center the mean
* @param data
*/
export function centerMean(data: DataXY<Float64Array>) {
export function centerMean(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
const { y } = data;
const mean = xMean(y);
for (let i = 0; i < y.length; i++) {
Expand Down
4 changes: 3 additions & 1 deletion src/filters/scaling/centerMedian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface CenterMedianFilter {
* Center the median
* @param data
*/
export function centerMedian(data: DataXY<Float64Array>) {
export function centerMedian(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
const { y } = data;
const median = xMedian(y);
for (let i = 0; i < y.length; i++) {
Expand Down
4 changes: 3 additions & 1 deletion src/filters/scaling/divideBySD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface DivideBySDFilter {
* Center the mean
* @param data
*/
export function divideBySD(data: DataXY<Float64Array>) {
export function divideBySD(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
const { y } = data;
const sd = xStandardDeviation(y);
for (let i = 0; i < y.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/filters/scaling/normed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type NormedOptions = Omit<
export function normed(
data: DataXY<Float64Array>,
options: NormedOptions = {},
) {
): { data: DataXY<Float64Array> } {
xNormed(data.y, { ...options, output: data.y });
return { data };
}
4 changes: 3 additions & 1 deletion src/filters/scaling/paretoNormalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface ParetoNormalizationFilter {
* Filter that allows to
* @param data
*/
export function paretoNormalization(data: DataXY<Float64Array>) {
export function paretoNormalization(data: DataXY<Float64Array>): {
data: DataXY<Float64Array>;
} {
return {
data: {
x: data.x,
Expand Down
2 changes: 1 addition & 1 deletion src/filters/scaling/rescale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type RescaleOptions = Omit<
export function rescale(
data: DataXY<Float64Array>,
options: RescaleOptions = {},
) {
): { data: DataXY<Float64Array> } {
xRescale(data.y, { ...options, output: data.y });
return { data };
}
2 changes: 1 addition & 1 deletion src/filters/sg/firstDerivative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type FirstDerivativeOptions = Omit<SGGOptions, 'derivative'>;
export function firstDerivative(
data: DataXY<Float64Array>,
options: FirstDerivativeOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { x, y } = data;
return { data: { x, y: sgg(y, x, { ...options, derivative: 1 }) } };
}
2 changes: 1 addition & 1 deletion src/filters/sg/savitzkyGolay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type SavitzkyGolayOptions = SGGOptions;
export function savitzkyGolay(
data: DataXY<Float64Array>,
options: SavitzkyGolayOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { x, y } = data;
return { data: { x, y: sgg(y, x, options) } };
}
2 changes: 1 addition & 1 deletion src/filters/sg/secondDerivative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type SecondDerivativeOptions = Omit<SGGOptions, 'derivative'>;
export function secondDerivative(
data: DataXY<Float64Array>,
options: SecondDerivativeOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { x, y } = data;
return { data: { x, y: sgg(y, x, { ...options, derivative: 2 }) } };
}
2 changes: 1 addition & 1 deletion src/filters/sg/thirdDerivative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ThirdDerivativeOptions = Omit<SGGOptions, 'derivative'>;
export function thirdDerivative(
data: DataXY<Float64Array>,
options: ThirdDerivativeOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { x, y } = data;
return { data: { x, y: sgg(y, x, { ...options, derivative: 3 }) } };
}
2 changes: 1 addition & 1 deletion src/filters/x/__tests__/calibrateX.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('calibrateX', () => {
y: Float64Array.from([1, 1, 5, 1]),
};

expect(() => calibrateX(data, { from: 1, to: 10 })).toThrow(
expect(() => calibrateX(data, { from: 1, to: 10 })).toThrowError(
'Window size is higher than the data lengt',
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/filters/x/calibrateX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface CalibrateOptions {
export function calibrateX(
data: DataXY<Float64Array>,
options: CalibrateOptions = {},
) {
): { data: DataXY<Float64Array> } {
const {
targetX = 0,
nbPeaks = 1,
Expand Down
4 changes: 3 additions & 1 deletion src/filters/x/ensureGrowing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface EnsureGrowingFilter {
* http://www-groups.mcs.st-andrews.ac.uk/~john/analysis/Lectures/L8.html
* @param data
*/
export function ensureGrowing(data: DataXY<Float64Array>) {
export function ensureGrowing(data: DataXY<Float64Array>): {
data: DataXY<Float64Array | number[]>;
} {
return { data: xyEnsureGrowingX(data) };
}
2 changes: 1 addition & 1 deletion src/filters/x/equallySpaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ export interface EquallySpacedOptions {
export function equallySpaced(
data: DataXY<Float64Array>,
options: EquallySpacedOptions = {},
) {
): { data: DataXY<number[]> } {
return { data: xyEquallySpaced(data, options) };
}
2 changes: 1 addition & 1 deletion src/filters/x/filterX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface FilterXOptions {
export function filterX(
data: DataXY<Float64Array>,
options: FilterXOptions = {},
) {
): { data: DataXY<number[]> } {
return {
data: xyFilterX(data, options),
};
Expand Down
2 changes: 1 addition & 1 deletion src/filters/x/fromTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type FromToOptions = Parameters<typeof xGetFromToIndex>[1];
export function fromTo(
data: DataXY<Float64Array>,
options: FromToOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { fromIndex, toIndex } = xGetFromToIndex(data.x, options);
return {
data: {
Expand Down
4 changes: 3 additions & 1 deletion src/filters/x/reverseIfNeeded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface ReverseIfNeededFilter {
* http://www-groups.mcs.st-andrews.ac.uk/~john/analysis/Lectures/L8.html
* @param data
*/
export function reverseIfNeeded(data: DataXY<Float64Array>) {
export function reverseIfNeeded(data: DataXY<Float64Array>): {
data: DataXY<Float64Array | number[]>;
} {
return { data: xyGrowingX(data) };
}
2 changes: 1 addition & 1 deletion src/filters/x/setMaxX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SetMaxXOptions {
export function setMaxX(
data: DataXY<Float64Array>,
options: SetMaxXOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { max = 1 } = options;
const existingMax = xMaxValue(data.x);
if (existingMax === max) {
Expand Down
2 changes: 1 addition & 1 deletion src/filters/x/setMinX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SetMinXOptions {
export function setMinX(
data: DataXY<Float64Array>,
options: SetMinXOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { min = 0 } = options;
const existingMin = xMinValue(data.x);
if (existingMin === min) {
Expand Down
2 changes: 1 addition & 1 deletion src/filters/x/xFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface XFunctionOptions {
export function xFunction(
data: DataXY<Float64Array>,
options: XFunctionOptions = {},
) {
): { data: DataXY<Float64Array> } {
return {
data: {
x: xApplyFunctionStr(data.x, {
Expand Down
2 changes: 1 addition & 1 deletion src/filters/y/setMaxY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SetMaxYOptions {
export function setMaxY(
data: DataXY<Float64Array>,
options: SetMaxYOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { max = 1 } = options;
const existingMax = xMaxValue(data.y);
if (existingMax === max) {
Expand Down
2 changes: 1 addition & 1 deletion src/filters/y/setMinY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SetMinYOptions {
export function setMinY(
data: DataXY<Float64Array>,
options: SetMinYOptions = {},
) {
): { data: DataXY<Float64Array> } {
const { min = 0 } = options;
const existingMin = xMinValue(data.y);
if (existingMin === min) {
Expand Down
2 changes: 1 addition & 1 deletion src/matrixFilters/centerZMean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DoubleMatrix } from 'ml-spectra-processing';
import type { DoubleMatrix } from 'cheminfo-types';
import { matrixCenterZMean } from 'ml-spectra-processing';

export interface MatrixCenterZMeanFilter {
Expand Down
2 changes: 1 addition & 1 deletion src/matrixFilters/pqn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DoubleMatrix } from 'ml-spectra-processing';
import type { DoubleMatrix } from 'cheminfo-types';
import { matrixPQN } from 'ml-spectra-processing';

export interface PQNFilter {
Expand Down
2 changes: 1 addition & 1 deletion src/matrixFilters/zRescale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DoubleMatrix } from 'ml-spectra-processing';
import type { DoubleMatrix } from 'cheminfo-types';
import { matrixZRescale } from 'ml-spectra-processing';

export interface MatrixZRescaleFilter {
Expand Down