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
1 change: 0 additions & 1 deletion .eslintrc.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/npm-prerelease.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/npm-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
uses: zakodium/workflows/.github/workflows/npm-prerelease.yml@npm-prerelease-v1
secrets:
github-token: ${{ secrets.BOT_TOKEN }}
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
32 changes: 16 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Release
on:
push:
branches:
- main
jobs:
release:
# Documentation: https://github.com/zakodium/workflows#release
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
with:
npm: true
secrets:
github-token: ${{ secrets.BOT_TOKEN }}
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
name: Release

on:
push:
branches:
- main

jobs:
release:
# Documentation: https://github.com/zakodium/workflows#release
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
with:
npm: true
secrets:
github-token: ${{ secrets.BOT_TOKEN }}
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
CHANGELOG.md
4 changes: 0 additions & 4 deletions babel.config.js

This file was deleted.

9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig, globalIgnores } from 'eslint/config';
import ts from 'eslint-config-cheminfo-typescript/base';

export default defineConfig(globalIgnores(['coverage', 'lib']), ts, {
files: ['script/**'],
rules: {
'no-console': 'off',
},
});
47 changes: 22 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
"name": "ml-spectra-fitting",
"version": "4.2.4",
"description": "Fit spectra using gaussian or lorentzian",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
"types": "./lib/index.d.ts",
"type": "module",
"exports": "./lib/index.js",
"files": [
"lib",
"src",
"lib-esm"
"src"
],
"scripts": {
"build": "npm run tsc && cheminfo-build --entry lib-esm/index.js --root SpectraFitting",
Comment thread
tpoisseau marked this conversation as resolved.
"build": "npm run tsc && cheminfo-build --entry lib/index.js --root SpectraFitting",
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"eslint": "eslint src",
"eslint-fix": "npm run eslint -- --fix",
"clean": "rimraf lib",
"eslint": "eslint .",
"eslint-fix": "eslint . --fix",
"prepack": "npm run tsc",
"test": "npm run test-only && npm run eslint && npm run check-types && npm run prettier",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test-only": "jest --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json",
"debug": "npm run prepublishOnly && node src/debug.js"
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"prettier": "prettier --check .",
"prettier-write": "prettier --write .",
"test-only": "vitest --run --coverage",
"tsc": "npm run clean && npm run tsc-build",
"tsc-build": "tsc --project tsconfig.build.json"
},
"repository": {
"type": "git",
Expand All @@ -46,23 +42,24 @@
},
"homepage": "https://github.com/mljs/spectra-fitting",
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@types/jest": "^29.5.12",
"@types/node": "^24.0.1",
"@vitest/coverage-v8": "^3.2.3",
"@zakodium/tsconfig": "^1.0.1",
"cheminfo-build": "^1.2.0",
"eslint": "^8.57.0",
"eslint-config-cheminfo-typescript": "^12.2.0",
"jest": "^29.7.0",
"eslint": "^9.28.0",
"eslint-config-cheminfo-typescript": "^18.0.1",
"jest-matcher-deep-close-to": "^3.0.2",
"prettier": "^3.2.5",
"rimraf": "^6.0.1",
"spectrum-generator": "^8.0.11",
"typescript": "^5.4.2"
"typescript": "^5.8.3",
"vitest": "^3.2.3"
},
"dependencies": {
"cheminfo-types": "^1.7.2",
"ml-array-max": "^1.2.4",
"ml-direct": "^1.0.0",
"ml-levenberg-marquardt": "^4.1.3",
"ml-levenberg-marquardt": "^5.0.0",
"ml-peak-shape-generator": "^4.1.4",
"ml-spectra-processing": "^14.2.0"
}
Expand Down
8 changes: 3 additions & 5 deletions src/__tests__/globalOptimization.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

import { optimize } from '../index';

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
import { optimize } from '../index.ts';

describe('Optimize sum of Gaussians', () => {
const peaks = [
Expand Down Expand Up @@ -59,7 +57,7 @@ describe('Optimize sum of Gaussians', () => {
for (const key in peak) {
//@ts-expect-error to be improved
const value = peak[key];
// eslint-disable-next-line @typescript-eslint/no-loop-func

it(`peak at ${peak.x} key: ${key}`, () => {
//@ts-expect-error to be improved
expect(result.peaks[i][key]).toMatchCloseTo(value, 2);
Expand Down
11 changes: 5 additions & 6 deletions src/__tests__/mixShapes.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

import { optimize } from '../index';

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
import { optimize } from '../index.ts';

describe('Sum of a mix of distributions', () => {
it('2 peaks', () => {
Expand Down Expand Up @@ -94,7 +92,8 @@ describe('Sum of a mix of distributions', () => {
expect(result.peaks[i]).toMatchCloseTo(peaks[i], 3);
}
});
it('20 peaks with overlap', () => {
// it seems CI needs extra time for this test
it('20 peaks with overlap', { timeout: 10000 }, () => {
const nbPeaks = 5;
const peaks = [];
for (let i = 0; i < nbPeaks; i++) {
Expand All @@ -119,7 +118,7 @@ describe('Sum of a mix of distributions', () => {
optimization: { options: { maxIterations: 10 } },
});
// we have a little bit more error on mu
//@ts-expect-error we ignoere this ts error
//@ts-expect-error we ignore this ts error
peaks.forEach((peak) => peak.shape.mu && delete peak.shape.mu);
for (let i = 0; i < result.peaks.length; i++) {
expect(result.peaks[i]).toMatchCloseTo(peaks[i], 3);
Expand Down
6 changes: 2 additions & 4 deletions src/__tests__/oneShape.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

import { optimize } from '../index';

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
import { optimize } from '../index.ts';

const nbPoints = 31;
const xFactor = 0.1;
Expand Down
6 changes: 2 additions & 4 deletions src/__tests__/specifyShapeInOptimize.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

import { optimize } from '../index';

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
import { optimize } from '../index.ts';

describe('Optimize sum of Gaussians', () => {
it('positive maxima peaks, default value', () => {
Expand Down
7 changes: 3 additions & 4 deletions src/__tests__/specifyShapeInPeaks.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { DataXY } from 'cheminfo-types';
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { generateSpectrum } from 'spectrum-generator';
import { describe, expect, it } from 'vitest';

import { optimize, Peak } from '../index';

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
import { optimize } from '../index.ts';
import type { Peak } from '../index.ts';

const nbPoints = 31;
const xFactor = 0.1;
Expand Down
20 changes: 9 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { DataXY } from 'cheminfo-types';
import { Shape1D } from 'ml-peak-shape-generator';
import type { DataXY } from 'cheminfo-types';
import type { Shape1D } from 'ml-peak-shape-generator';
import { xMinMaxValues } from 'ml-spectra-processing';

import { getSumOfShapes } from './shapes/getSumOfShapes';
import { getInternalPeaks } from './util/internalPeaks/getInternalPeaks';
import { selectMethod } from './util/selectMethod';
import { getSumOfShapes } from './shapes/getSumOfShapes.ts';
import { getInternalPeaks } from './util/internalPeaks/getInternalPeaks.ts';
import { selectMethod } from './util/selectMethod.ts';
import type { InternalDirectOptimizationOptions } from './util/wrappers/directOptimization.js';

export interface InitialParameter {
init?: OptimizationParameter;
Expand Down Expand Up @@ -61,12 +62,9 @@ export interface LMOptimizationOptions extends GeneralAlgorithmOptions {
errorTolerance?: number;
}

export interface DirectOptimizationOptions extends GeneralAlgorithmOptions {
epsilon?: number;
tolerance?: number;
tolerance2?: number;
initialState?: any;
}
export interface DirectOptimizationOptions
extends GeneralAlgorithmOptions,
InternalDirectOptimizationOptions {}

export interface OptimizationOptions {
/**
Expand Down
12 changes: 8 additions & 4 deletions src/shapes/getSumOfShapes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { InternalPeak } from '../util/internalPeaks/getInternalPeaks';
import type { InternalPeak } from '../util/internalPeaks/getInternalPeaks.ts';

/**
* This function returns the sumOfShapes function
* This function gives sumOfShapes access to the peak list and the associated data
* @param parameters - parameters
* @param internalPeaks
*/

export function getSumOfShapes(internalPeaks: InternalPeak[]) {
Expand All @@ -14,8 +14,12 @@ export function getSumOfShapes(internalPeaks: InternalPeak[]) {
const peakX = parameters[peak.fromIndex];
const y = parameters[peak.fromIndex + 1];
for (let i = 2; i < parameters.length; i++) {
//@ts-expect-error Not simply to solve the issue
peak.shapeFct[peak.parameters[i]] = parameters[peak.fromIndex + i];
type Parameter = (typeof peak.parameters)[number];
const shapeFctKey = peak.parameters[i] as Extract<
Parameter,
keyof typeof peak.shapeFct
>;
peak.shapeFct[shapeFctKey] = parameters[peak.fromIndex + i];
}
totalY += y * peak.shapeFct.fct(x - peakX);
}
Expand Down
7 changes: 4 additions & 3 deletions src/util/__tests__/selectMethod.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { selectMethod } from '../selectMethod';
import { describe, expect, it } from 'vitest';

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

describe('selectMethod', () => {
it('throw errors', () => {
expect(() => {
//@ts-expect-error expected to fail
selectMethod({ kind: 'fail' });
selectMethod({ kind: 'fail' as never });
}).toThrow('Unknown fitting algorithm');
});
});
4 changes: 2 additions & 2 deletions src/util/internalPeaks/DefaultParameters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
import type {
Shape1DInstance,
PseudoVoigt,
GeneralizedLorentzian,
} from 'ml-peak-shape-generator';

import { Peak } from '../../index';
import type { Peak } from '../../index.ts';

export const DefaultParameters = {
x: {
Expand Down
8 changes: 3 additions & 5 deletions src/util/internalPeaks/__tests__/getInternalPeaks.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
import { describe, expect, it } from 'vitest';

import { Peak } from '../../..';
import { getInternalPeaks } from '../getInternalPeaks';

expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
import type { Peak } from '../../../index.ts';
import { getInternalPeaks } from '../getInternalPeaks.js';

describe('getInternalPeaks', () => {
it('default values', () => {
Expand Down
10 changes: 6 additions & 4 deletions src/util/internalPeaks/getInternalPeaks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getShape1D, Shape1D, Shape1DInstance } from 'ml-peak-shape-generator';
import type { Shape1D, Shape1DInstance } from 'ml-peak-shape-generator';
import { getShape1D } from 'ml-peak-shape-generator';

import { Peak, OptimizeOptions } from '../../index';
import { assert } from '../assert';
import type { Peak, OptimizeOptions } from '../../index.ts';
import { assert } from '../assert.ts';

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

type Parameter = 'x' | 'y' | 'fwhm' | 'mu' | 'gamma';

Expand All @@ -22,6 +23,7 @@ export interface InternalPeak {
/**
* Return an array of internalPeaks that contains the exact init, min, max values based on the options
* @param peaks
* @param minMaxY
* @param options
* @returns
*/
Expand Down
4 changes: 2 additions & 2 deletions src/util/selectMethod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { levenbergMarquardt } from 'ml-levenberg-marquardt';

import { OptimizationOptions } from '../index';
import type { OptimizationOptions } from '../index.ts';

import { directOptimization } from './wrappers/directOptimization';
import { directOptimization } from './wrappers/directOptimization.ts';

/** Algorithm to select the method.
* @param optimizationOptions - Optimization options
Expand Down
Loading