spectrum-generator
Advanced tools
Comparing version 8.0.11 to 8.0.12
@@ -67,6 +67,6 @@ import { getShape2D } from 'ml-peak-shape-generator'; | ||
for (const c of peakCoordinates) { | ||
if (peaks[c] && Array.isArray(peaks[c])) { | ||
if (nbPeaks !== peaks[c].length) { | ||
throw new Error('x, y, z should have the same length'); | ||
} | ||
if (peaks[c] && | ||
Array.isArray(peaks[c]) && | ||
nbPeaks !== peaks[c].length) { | ||
throw new Error('x, y, z should have the same length'); | ||
} | ||
@@ -117,3 +117,3 @@ } | ||
? getShape2D(shapeOptions) | ||
: Object.assign(Object.create(Object.getPrototypeOf(this.shape)), JSON.parse(JSON.stringify(this.shape))); | ||
: Object.assign(Object.create(Object.getPrototypeOf(this.shape)), structuredClone(this.shape)); | ||
let { fwhm = peakFWHM !== undefined | ||
@@ -120,0 +120,0 @@ ? peakFWHM |
@@ -33,2 +33,3 @@ import { getShape1D } from 'ml-peak-shape-generator'; | ||
* @param peaks - Peaks to add. | ||
* @param options | ||
*/ | ||
@@ -152,4 +153,4 @@ addPeaks(peaks, options) { | ||
* Add noise to the spectrum. | ||
* | ||
* @param percent - Noise's amplitude in percents of the spectrum max value. Default: 1. | ||
* @param options | ||
*/ | ||
@@ -162,2 +163,3 @@ addNoise(options) { | ||
* Get the generated spectrum. | ||
* @param options | ||
*/ | ||
@@ -195,6 +197,10 @@ getSpectrum(options = {}) { | ||
reset() { | ||
const spectrum = this.data; | ||
for (let i = 0; i < this.nbPoints; i++) { | ||
spectrum.x[i] = this.from + i * this.interval; | ||
if (this.nbPoints === 1) { | ||
this.data.x[0] = (this.from + this.to) / 2; | ||
} | ||
else { | ||
for (let i = 0; i < this.nbPoints; i++) { | ||
this.data.x[i] = this.from + i * this.interval; | ||
} | ||
} | ||
return this; | ||
@@ -201,0 +207,0 @@ } |
@@ -28,4 +28,4 @@ import type { Shape2D, XYNumber } from 'ml-peak-shape-generator'; | ||
* @default `shape: { | ||
kind: 'gaussian', | ||
},` | ||
* kind: 'gaussian', | ||
* },` | ||
*/ | ||
@@ -96,3 +96,3 @@ shape?: Shape2D; | ||
maxZ: number; | ||
z: number[][] | Float64Array[]; | ||
z: Float64Array<ArrayBufferLike>[] | number[][]; | ||
}; | ||
@@ -99,0 +99,0 @@ reset(): this; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateSpectrum2D = exports.Spectrum2DGenerator = void 0; | ||
exports.Spectrum2DGenerator = void 0; | ||
exports.generateSpectrum2D = generateSpectrum2D; | ||
const ml_peak_shape_generator_1 = require("ml-peak-shape-generator"); | ||
@@ -70,6 +71,6 @@ const ml_spectra_processing_1 = require("ml-spectra-processing"); | ||
for (const c of peakCoordinates) { | ||
if (peaks[c] && Array.isArray(peaks[c])) { | ||
if (nbPeaks !== peaks[c].length) { | ||
throw new Error('x, y, z should have the same length'); | ||
} | ||
if (peaks[c] && | ||
Array.isArray(peaks[c]) && | ||
nbPeaks !== peaks[c].length) { | ||
throw new Error('x, y, z should have the same length'); | ||
} | ||
@@ -120,3 +121,3 @@ } | ||
? (0, ml_peak_shape_generator_1.getShape2D)(shapeOptions) | ||
: Object.assign(Object.create(Object.getPrototypeOf(this.shape)), JSON.parse(JSON.stringify(this.shape))); | ||
: Object.assign(Object.create(Object.getPrototypeOf(this.shape)), structuredClone(this.shape)); | ||
let { fwhm = peakFWHM !== undefined | ||
@@ -190,3 +191,2 @@ ? peakFWHM | ||
} | ||
exports.generateSpectrum2D = generateSpectrum2D; | ||
function ensureXYNumber(input) { | ||
@@ -193,0 +193,0 @@ return typeof input !== 'object' ? { x: input, y: input } : { ...input }; |
@@ -107,2 +107,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
* @param peaks - Peaks to add. | ||
* @param options | ||
*/ | ||
@@ -124,4 +125,4 @@ addPeaks(peaks: Peak1D[] | PeakSeries, options?: PeakOptions): void; | ||
* Add noise to the spectrum. | ||
* | ||
* @param percent - Noise's amplitude in percents of the spectrum max value. Default: 1. | ||
* @param options | ||
*/ | ||
@@ -131,4 +132,5 @@ addNoise(options?: NoiseOptions): this; | ||
* Get the generated spectrum. | ||
* @param options | ||
*/ | ||
getSpectrum(options?: GetSpectrumOptions | boolean): DataXY<Float64Array>; | ||
getSpectrum(options?: GetSpectrumOptions | boolean): DataXY<Float64Array<ArrayBufferLike>>; | ||
/** | ||
@@ -135,0 +137,0 @@ * Resets the generator with an empty spectrum. |
@@ -6,3 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateSpectrum = exports.SpectrumGenerator = void 0; | ||
exports.SpectrumGenerator = void 0; | ||
exports.generateSpectrum = generateSpectrum; | ||
const ml_peak_shape_generator_1 = require("ml-peak-shape-generator"); | ||
@@ -40,2 +41,3 @@ const addBaseline_1 = __importDefault(require("./util/addBaseline")); | ||
* @param peaks - Peaks to add. | ||
* @param options | ||
*/ | ||
@@ -159,4 +161,4 @@ addPeaks(peaks, options) { | ||
* Add noise to the spectrum. | ||
* | ||
* @param percent - Noise's amplitude in percents of the spectrum max value. Default: 1. | ||
* @param options | ||
*/ | ||
@@ -169,2 +171,3 @@ addNoise(options) { | ||
* Get the generated spectrum. | ||
* @param options | ||
*/ | ||
@@ -202,6 +205,10 @@ getSpectrum(options = {}) { | ||
reset() { | ||
const spectrum = this.data; | ||
for (let i = 0; i < this.nbPoints; i++) { | ||
spectrum.x[i] = this.from + i * this.interval; | ||
if (this.nbPoints === 1) { | ||
this.data.x[0] = (this.from + this.to) / 2; | ||
} | ||
else { | ||
for (let i = 0; i < this.nbPoints; i++) { | ||
this.data.x[i] = this.from + i * this.interval; | ||
} | ||
} | ||
return this; | ||
@@ -239,3 +246,2 @@ } | ||
} | ||
exports.generateSpectrum = generateSpectrum; | ||
//# sourceMappingURL=SpectrumGenerator.js.map |
import type { DataXY } from 'cheminfo-types'; | ||
type BaseLineFn = (x: number) => number; | ||
export default function addBaseline(data: DataXY, baselineFct: BaseLineFn): DataXY<import("cheminfo-types").DoubleArray>; | ||
export default function addBaseline(data: DataXY, baselineFct: BaseLineFn): DataXY<import("cheminfo-types").NumberArray>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = addBaseline; | ||
function addBaseline(data, baselineFct) { | ||
@@ -13,3 +14,2 @@ if (!baselineFct) | ||
} | ||
exports.default = addBaseline; | ||
//# sourceMappingURL=addBaseline.js.map |
@@ -22,2 +22,2 @@ import type { DataXY } from 'cheminfo-types'; | ||
} | ||
export default function addNoise(data: DataXY, options?: NoiseOptions): DataXY<import("cheminfo-types").DoubleArray>; | ||
export default function addNoise(data: DataXY, options?: NoiseOptions): DataXY<import("cheminfo-types").NumberArray>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = addNoise; | ||
const ml_spectra_processing_1 = require("ml-spectra-processing"); | ||
@@ -18,3 +19,2 @@ function addNoise(data, options = {}) { | ||
} | ||
exports.default = addNoise; | ||
//# sourceMappingURL=addNoise.js.map |
{ | ||
"name": "spectrum-generator", | ||
"version": "8.0.11", | ||
"version": "8.0.12", | ||
"description": "generate a spectrum from discrete peaks", | ||
@@ -31,3 +31,3 @@ "main": "./lib/index.js", | ||
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types", | ||
"test-only": "jest --coverage", | ||
"test-only": "vitest run --coverage", | ||
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm", | ||
@@ -51,19 +51,21 @@ "tsc-cjs": "tsc --project tsconfig.cjs.json", | ||
"@types/d3-random": "^3.0.3", | ||
"@types/jest": "^29.5.12", | ||
"@types/jest": "^29.5.14", | ||
"@vitest/coverage-v8": "2.1.8", | ||
"cheminfo-build": "^1.2.0", | ||
"cheminfo-types": "^1.7.2", | ||
"eslint": "^8.57.0", | ||
"eslint-config-cheminfo-typescript": "^12.2.0", | ||
"cheminfo-types": "^1.8.1", | ||
"eslint": "^9.16.0", | ||
"eslint-config-cheminfo-typescript": "^17.0.0", | ||
"jest": "^29.7.0", | ||
"jest-matcher-deep-close-to": "^3.0.2", | ||
"ml-savitzky-golay-generalized": "^4.0.1", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^5.4.2" | ||
"ml-savitzky-golay-generalized": "^4.2.0", | ||
"prettier": "^3.4.2", | ||
"rimraf": "^6.0.1", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.7.2", | ||
"vitest": "^2.1.8" | ||
}, | ||
"dependencies": { | ||
"ml-peak-shape-generator": "^4.1.2", | ||
"ml-spectra-processing": "^14.2.0" | ||
"ml-peak-shape-generator": "^4.1.4", | ||
"ml-spectra-processing": "^14.8.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { getShape2D, Shape2DClass } from 'ml-peak-shape-generator'; | ||
import { getShape2D } from 'ml-peak-shape-generator'; | ||
import type { | ||
@@ -6,2 +6,3 @@ Shape2D, | ||
XYNumber, | ||
Shape2DClass, | ||
} from 'ml-peak-shape-generator'; | ||
@@ -53,4 +54,4 @@ import { matrixMinMaxZ } from 'ml-spectra-processing'; | ||
* @default `shape: { | ||
kind: 'gaussian', | ||
},` | ||
* kind: 'gaussian', | ||
* },` | ||
*/ | ||
@@ -187,6 +188,8 @@ shape?: Shape2D; | ||
for (const c of peakCoordinates) { | ||
if (peaks[c] && Array.isArray(peaks[c])) { | ||
if (nbPeaks !== peaks[c].length) { | ||
throw new Error('x, y, z should have the same length'); | ||
} | ||
if ( | ||
peaks[c] && | ||
Array.isArray(peaks[c]) && | ||
nbPeaks !== peaks[c].length | ||
) { | ||
throw new Error('x, y, z should have the same length'); | ||
} | ||
@@ -251,3 +254,3 @@ } | ||
Object.create(Object.getPrototypeOf(this.shape)), | ||
JSON.parse(JSON.stringify(this.shape)), | ||
structuredClone(this.shape), | ||
) as Shape2DInstance); | ||
@@ -254,0 +257,0 @@ |
@@ -155,2 +155,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
* @param peaks - Peaks to add. | ||
* @param options | ||
*/ | ||
@@ -279,2 +280,3 @@ public addPeaks(peaks: Peak1D[] | PeakSeries, options?: PeakOptions) { | ||
const middlePoint = Math.round((xPosition - this.from) / this.interval); | ||
// PEAK SHAPE MAY BE ASYMMETRC (widthLeft and widthRight) ! | ||
@@ -312,4 +314,4 @@ // we calculate the left part of the shape | ||
* Add noise to the spectrum. | ||
* | ||
* @param percent - Noise's amplitude in percents of the spectrum max value. Default: 1. | ||
* @param options | ||
*/ | ||
@@ -323,2 +325,3 @@ public addNoise(options?: NoiseOptions) { | ||
* Get the generated spectrum. | ||
* @param options | ||
*/ | ||
@@ -356,8 +359,9 @@ public getSpectrum(options: GetSpectrumOptions | boolean = {}) { | ||
public reset() { | ||
const spectrum = this.data; | ||
for (let i = 0; i < this.nbPoints; i++) { | ||
spectrum.x[i] = this.from + i * this.interval; | ||
if (this.nbPoints === 1) { | ||
this.data.x[0] = (this.from + this.to) / 2; | ||
} else { | ||
for (let i = 0; i < this.nbPoints; i++) { | ||
this.data.x[i] = this.from + i * this.interval; | ||
} | ||
} | ||
return this; | ||
@@ -364,0 +368,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111837
2071
15