Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spectrum-generator

Package Overview
Dependencies
Maintainers
4
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spectrum-generator - npm Package Compare versions

Comparing version 4.6.0 to 4.7.0

7

CHANGELOG.md
# Changelog
## [4.7.0](https://www.github.com/cheminfo/spectrum-generator/compare/v4.6.0...v4.7.0) (2021-01-06)
### Features
* Use gaussian ration directly from peaks ([#28](https://www.github.com/cheminfo/spectrum-generator/issues/28)) ([36e1051](https://www.github.com/cheminfo/spectrum-generator/commit/36e1051171aa1bd59821f8d116dec81137231fc4))
## [4.6.0](https://www.github.com/cheminfo/spectrum-generator/compare/v4.5.0...v4.6.0) (2020-12-11)

@@ -4,0 +11,0 @@

24

lib/index.js

@@ -64,2 +64,13 @@ 'use strict';

class SpectrumGenerator {
/**
*
* @param {object} [options={}]
* @param {number} [options.from=0]
* @param {number} [options.to=0]
* @param {function} [options.nbPoints=10001]
* @param {number} [options.factor] default value depends of the shape in order to cover 99.99% of the surface
* @param {object} [options.shape={kind:'gaussian'}]
* @param {string} [options.shape.kind] kind of shape, gaussian, lorentzian or pseudovoigt
* @param {object} [options.shape.options] options for the shape (like `mu` for pseudovoigt)
*/
constructor(options = {}) {

@@ -132,2 +143,7 @@ options = Object.assign(

/**
*
* @param {[x,y]|[x,y,w]|{x,y,width}} [peak]
* @param {*} options
*/
addPeak(peak, options = {}) {

@@ -148,4 +164,5 @@ if (

let peakWidth;
let peakOptions;
if (Array.isArray(peak)) {
[xPosition, intensity, peakWidth] = peak;
[xPosition, intensity, peakWidth, peakOptions] = peak;
} else {

@@ -155,2 +172,3 @@ xPosition = peak.x;

peakWidth = peak.width;
peakOptions = peak.options;
}

@@ -169,2 +187,6 @@

if (peakOptions) {
Object.assign(shapeOptions || {}, peakOptions || {});
}
let shapeGenerator = shapeOptions

@@ -171,0 +193,0 @@ ? mlPeakShapeGenerator.getShapeGenerator(shapeOptions)

3

package.json
{
"name": "spectrum-generator",
"version": "4.6.0",
"version": "4.7.0",
"description": "generate a spectrum from discrete peaks",

@@ -53,2 +53,3 @@ "main": "lib/index.js",

"jest": "^26.6.3",
"ml-savitzky-golay-generalized": "^2.0.3",
"ml-spectra-processing": "^4.10.0",

@@ -55,0 +56,0 @@ "pnpm": "^5.13.5",

@@ -7,8 +7,4 @@ # spectrum-generator

Generates a spectrum from discrete peaks. The shape of the peaks can be customised.
Generates a spectrum from discrete peaks. The shape of the peaks can be customized.
In order to increase the speed a `shape` is first generated and then the peaks in the final
spectrum are resulting from sampling the `shape`. A `shape` will therefore be generated with
much more points (typically fwhm:1000).
The shape is generated using [ml-peak-shape-generator](https://github.com/mljs/peak-shape-generator) and you may use all the corresponding [options](https://mljs.github.io/peak-shape-generator/#getshape) of getShape.

@@ -22,5 +18,2 @@

The spectrum generator takes an array of discrete peaks (value and intensity)
and generates peaks with a gaussian distribution (by default).
### generateSpectrum

@@ -41,2 +34,6 @@

nbPoints: 10001, // default value: 10001
factor: 3, // default value would covers 99.99% of the surface and depends on the shape
shape: {
kind: 'gaussian', // default value is gaussian
},
});

@@ -61,2 +58,3 @@ ```

- const peaks = {x:[1,2,3,4], y:[10,30,1,76]}
- const peaks = [ [1,10,5], [2,30,10] ] // third argument is the peak width
*/

@@ -70,6 +68,2 @@

kind: 'lorentzian',
options: {
fwhm: 1000,
length: 10001,
},
},

@@ -98,7 +92,5 @@ });

width: 0.1, // width of peak is FWHM
factor: 10, // 10 times fwhm. Lorentzian are rather flat
shape: {
kind: 'lorentzian',
options: {
factor: 10, // 10 times fwhm. Lorentzian are rather flat
},
}

@@ -113,6 +105,2 @@ });

kind: 'gaussian',
options: {
fwhm: 1000,
length: 10001,
},
}

@@ -119,0 +107,0 @@ });

@@ -64,3 +64,2 @@ import { xyMaxYPoint } from 'ml-spectra-processing';

options: {
length: 17,
fwhm: 4,

@@ -87,3 +86,2 @@ },

options: {
length: 10,
fwhm: 3,

@@ -107,6 +105,2 @@ },

kind: 'gaussian',
options: {
fwhm: 4,
length: 13,
},
},

@@ -128,6 +122,2 @@ });

kind: 'gaussian',
options: {
fwhm: 500,
length: 1501,
},
},

@@ -134,0 +124,0 @@ });

@@ -15,6 +15,2 @@ import { Lorentzian } from 'ml-peak-shape-generator';

kind: 'gaussian',
options: {
fwhm: 1000,
length: 5001,
},
},

@@ -30,6 +26,2 @@ });

kind: 'lorentzian',
options: {
fwhm: 1000,
length: 5001,
},
},

@@ -48,2 +40,46 @@ },

it('full generation with {x,y}', () => {
const generator = new SpectrumGenerator({
from: 0,
to: 10,
nbPoints: 101,
peakWidthFct: () => 1,
shape: {
kind: 'gaussian',
},
});
generator.addPeak({
x: 3,
y: 10,
options: { kind: 'pseudovoigt', options: { mu: 1 } },
});
generator.addPeak(
{ x: 7, y: 5 },
{
shape: {
kind: 'lorentzian',
},
},
);
generator.addPeak(
{ x: 7, y: 5, options: { options: { mu: 0 } } },
{
shape: {
kind: 'pseudovoigt',
},
},
);
const spectrum = generator.getSpectrum();
const ys = spectrum.y;
expect(ys[30]).toBeCloseTo(10 + 10 * Lorentzian.fct(3 - 7, 1), 7);
expect(ys[70]).toBeCloseTo(10, 7);
expect(ys[31] !== ys[71]).toBe(true);
});
it('second test', () => {

@@ -57,6 +93,2 @@ let spectrumGenerator = new SpectrumGenerator({

kind: 'lorentzian',
options: {
length: 13,
fwhm: 4,
},
},

@@ -83,6 +115,2 @@ });

kind: 'gaussian',
options: {
length: 13,
fwhm: 4,
},
},

@@ -132,6 +160,2 @@ },

kind: 'lorentzian',
options: {
length: 13,
fwhm: 4,
},
},

@@ -138,0 +162,0 @@ });

@@ -7,2 +7,13 @@ import { getShapeGenerator } from 'ml-peak-shape-generator';

export class SpectrumGenerator {
/**
*
* @param {object} [options={}]
* @param {number} [options.from=0]
* @param {number} [options.to=0]
* @param {function} [options.nbPoints=10001]
* @param {number} [options.factor] default value depends of the shape in order to cover 99.99% of the surface
* @param {object} [options.shape={kind:'gaussian'}]
* @param {string} [options.shape.kind] kind of shape, gaussian, lorentzian or pseudovoigt
* @param {object} [options.shape.options] options for the shape (like `mu` for pseudovoigt)
*/
constructor(options = {}) {

@@ -75,2 +86,7 @@ options = Object.assign(

/**
*
* @param {[x,y]|[x,y,w]|{x,y,width}} [peak]
* @param {*} options
*/
addPeak(peak, options = {}) {

@@ -91,4 +107,5 @@ if (

let peakWidth;
let peakOptions;
if (Array.isArray(peak)) {
[xPosition, intensity, peakWidth] = peak;
[xPosition, intensity, peakWidth, peakOptions] = peak;
} else {

@@ -98,2 +115,3 @@ xPosition = peak.x;

peakWidth = peak.width;
peakOptions = peak.options;
}

@@ -112,2 +130,6 @@

if (peakOptions) {
Object.assign(shapeOptions || {}, peakOptions || {});
}
let shapeGenerator = shapeOptions

@@ -114,0 +136,0 @@ ? getShapeGenerator(shapeOptions)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc