spectrum-generator
Advanced tools
Comparing version 7.0.1 to 8.0.0
@@ -6,3 +6,3 @@ import { getShape1D } from 'ml-peak-shape-generator'; | ||
constructor(options = {}) { | ||
const { from = 0, to = 1000, nbPoints = 10001, peakWidthFct = () => 5, shape = { kind: 'gaussian' }, } = options; | ||
const { from = 0, to = 1000, nbPoints = 10001, peakWidthFct, shape = { kind: 'gaussian', fwhm: 5 }, } = options; | ||
this.from = from; | ||
@@ -26,3 +26,3 @@ this.to = to; | ||
} | ||
if (typeof this.peakWidthFct !== 'function') { | ||
if (this.peakWidthFct && typeof this.peakWidthFct !== 'function') { | ||
throw new TypeError('peakWidthFct option must be a function'); | ||
@@ -59,2 +59,3 @@ } | ||
* Add a single peak to the spectrum. | ||
* A peak may be either defined as [x,y,fwhm,...] or as {x, y, shape} | ||
* @param peak | ||
@@ -82,3 +83,2 @@ * @param options | ||
intensity = peak.y; | ||
peakFWHM = peak.fwhm; | ||
peakWidth = peak.width; | ||
@@ -98,7 +98,19 @@ peakShapeOptions = peak.shape; | ||
} | ||
let { fwhm = peakFWHM !== undefined | ||
let { widthLeft, widthRight } = options; | ||
/* | ||
if we don't force the fwhm we just take the one from the shape | ||
however we have many way to force it: | ||
- use [x,y,fwhm] | ||
- define `width` that will be converted to fwhm | ||
- define `widthLeft` and `widthRight` to define asymmetric peaks | ||
- have a callback `peakWidthFct` | ||
This should evolve in the future because we will not always have `fwhm` | ||
*/ | ||
const fwhm = peakFWHM !== undefined | ||
? peakFWHM | ||
: peakWidth | ||
? this.shape.widthToFWHM(peakWidth) | ||
: this.peakWidthFct(xPosition), widthLeft, widthRight, } = options; | ||
: this.peakWidthFct | ||
? this.peakWidthFct(xPosition) | ||
: this.shape.fwhm; | ||
if (!widthLeft) | ||
@@ -105,0 +117,0 @@ widthLeft = fwhm; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -38,3 +38,2 @@ import type { DataXY } from 'cheminfo-types'; | ||
*/ | ||
fwhm?: number; | ||
width?: number; | ||
@@ -113,2 +112,3 @@ /** | ||
* Add a single peak to the spectrum. | ||
* A peak may be either defined as [x,y,fwhm,...] or as {x, y, shape} | ||
* @param peak | ||
@@ -115,0 +115,0 @@ * @param options |
@@ -12,3 +12,3 @@ "use strict"; | ||
constructor(options = {}) { | ||
const { from = 0, to = 1000, nbPoints = 10001, peakWidthFct = () => 5, shape = { kind: 'gaussian' }, } = options; | ||
const { from = 0, to = 1000, nbPoints = 10001, peakWidthFct, shape = { kind: 'gaussian', fwhm: 5 }, } = options; | ||
this.from = from; | ||
@@ -32,3 +32,3 @@ this.to = to; | ||
} | ||
if (typeof this.peakWidthFct !== 'function') { | ||
if (this.peakWidthFct && typeof this.peakWidthFct !== 'function') { | ||
throw new TypeError('peakWidthFct option must be a function'); | ||
@@ -65,2 +65,3 @@ } | ||
* Add a single peak to the spectrum. | ||
* A peak may be either defined as [x,y,fwhm,...] or as {x, y, shape} | ||
* @param peak | ||
@@ -88,3 +89,2 @@ * @param options | ||
intensity = peak.y; | ||
peakFWHM = peak.fwhm; | ||
peakWidth = peak.width; | ||
@@ -104,7 +104,19 @@ peakShapeOptions = peak.shape; | ||
} | ||
let { fwhm = peakFWHM !== undefined | ||
let { widthLeft, widthRight } = options; | ||
/* | ||
if we don't force the fwhm we just take the one from the shape | ||
however we have many way to force it: | ||
- use [x,y,fwhm] | ||
- define `width` that will be converted to fwhm | ||
- define `widthLeft` and `widthRight` to define asymmetric peaks | ||
- have a callback `peakWidthFct` | ||
This should evolve in the future because we will not always have `fwhm` | ||
*/ | ||
const fwhm = peakFWHM !== undefined | ||
? peakFWHM | ||
: peakWidth | ||
? this.shape.widthToFWHM(peakWidth) | ||
: this.peakWidthFct(xPosition), widthLeft, widthRight, } = options; | ||
: this.peakWidthFct | ||
? this.peakWidthFct(xPosition) | ||
: this.shape.fwhm; | ||
if (!widthLeft) | ||
@@ -111,0 +123,0 @@ widthLeft = fwhm; |
@@ -7,3 +7,2 @@ import type { DoubleArray } from 'cheminfo-types'; | ||
width?: number; | ||
fwhm?: number; | ||
shape?: Shape1D; | ||
@@ -10,0 +9,0 @@ } |
{ | ||
"name": "spectrum-generator", | ||
"version": "7.0.1", | ||
"version": "8.0.0", | ||
"description": "generate a spectrum from discrete peaks", | ||
@@ -53,12 +53,12 @@ "main": "./lib/index.js", | ||
"cheminfo-build": "^1.1.11", | ||
"cheminfo-types": "^1.0.0", | ||
"eslint": "^8.9.0", | ||
"cheminfo-types": "^1.1.0", | ||
"eslint": "^8.10.0", | ||
"eslint-config-cheminfo-typescript": "^10.3.0", | ||
"jest": "^27.5.1", | ||
"jest-matcher-deep-close-to": "^3.0.2", | ||
"ml-savitzky-golay-generalized": "^4.0.0", | ||
"ml-savitzky-golay-generalized": "^4.0.1", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.5.5" | ||
"typescript": "^4.6.2" | ||
}, | ||
@@ -65,0 +65,0 @@ "dependencies": { |
@@ -45,3 +45,2 @@ import type { DataXY } from 'cheminfo-types'; | ||
*/ | ||
fwhm?: number; | ||
width?: number; | ||
@@ -111,3 +110,3 @@ /** | ||
public interval: number; | ||
private peakWidthFct: NumToNumFn; | ||
private peakWidthFct: NumToNumFn | undefined; | ||
private maxPeakHeight: number; | ||
@@ -121,4 +120,4 @@ private shape: Shape1DInstance; | ||
nbPoints = 10001, | ||
peakWidthFct = () => 5, | ||
shape = { kind: 'gaussian' }, | ||
peakWidthFct, | ||
shape = { kind: 'gaussian', fwhm: 5 }, | ||
} = options; | ||
@@ -149,3 +148,3 @@ | ||
if (typeof this.peakWidthFct !== 'function') { | ||
if (this.peakWidthFct && typeof this.peakWidthFct !== 'function') { | ||
throw new TypeError('peakWidthFct option must be a function'); | ||
@@ -187,2 +186,3 @@ } | ||
* Add a single peak to the spectrum. | ||
* A peak may be either defined as [x,y,fwhm,...] or as {x, y, shape} | ||
* @param peak | ||
@@ -218,3 +218,2 @@ * @param options | ||
intensity = peak.y; | ||
peakFWHM = peak.fwhm; | ||
peakWidth = peak.width; | ||
@@ -237,11 +236,20 @@ peakShapeOptions = peak.shape; | ||
let { | ||
fwhm = peakFWHM !== undefined | ||
let { widthLeft, widthRight } = options; | ||
/* | ||
if we don't force the fwhm we just take the one from the shape | ||
however we have many way to force it: | ||
- use [x,y,fwhm] | ||
- define `width` that will be converted to fwhm | ||
- define `widthLeft` and `widthRight` to define asymmetric peaks | ||
- have a callback `peakWidthFct` | ||
This should evolve in the future because we will not always have `fwhm` | ||
*/ | ||
const fwhm = | ||
peakFWHM !== undefined | ||
? peakFWHM | ||
: peakWidth | ||
? this.shape.widthToFWHM(peakWidth) | ||
: this.peakWidthFct(xPosition), | ||
widthLeft, | ||
widthRight, | ||
} = options; | ||
: this.peakWidthFct | ||
? this.peakWidthFct(xPosition) | ||
: this.shape.fwhm; | ||
@@ -248,0 +256,0 @@ if (!widthLeft) widthLeft = fwhm; |
@@ -8,3 +8,2 @@ import type { DoubleArray } from 'cheminfo-types'; | ||
width?: number; | ||
fwhm?: number; | ||
shape?: Shape1D; | ||
@@ -11,0 +10,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
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
108270
2034