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.2.0 to 4.3.0

12

CHANGELOG.md
# Changelog
## [4.3.0](https://www.github.com/cheminfo/spectrum-generator/compare/v4.2.0...v4.3.0) (2020-10-29)
### Features
* allow x,y,width objects to addPeak ([d3da510](https://www.github.com/cheminfo/spectrum-generator/commit/d3da5107fce78867e7ff59e9f6c611d49d69fd3a))
### Bug Fixes
* correct examples for typescript ([fa44388](https://www.github.com/cheminfo/spectrum-generator/commit/fa443880c0ff3f437c0c5228d127f652bf813a86))
## [4.2.0](https://www.github.com/cheminfo/spectrum-generator/compare/v4.1.2...v4.2.0) (2020-10-15)

@@ -4,0 +16,0 @@

14

lib/index.js

@@ -137,6 +137,8 @@ 'use strict';

typeof peak !== 'object' ||
(peak.length !== 2 && (peak.x === undefined || peak.y === undefined))
(peak.length !== 2 &&
peak.length !== 3 &&
(peak.x === undefined || peak.y === undefined))
) {
throw new Error(
'peak must be an array with two values or an object with {x,y}',
'peak must be an array with two (or three) values or an object with {x,y,width?}',
);

@@ -146,7 +148,9 @@ }

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

@@ -157,3 +161,5 @@

let {
width = this.peakWidthFct(xPosition),
width = peakWidth === undefined
? this.peakWidthFct(xPosition)
: peakWidth,
widthLeft,

@@ -160,0 +166,0 @@ widthRight,

{
"name": "spectrum-generator",
"version": "4.2.0",
"version": "4.3.0",
"description": "generate a spectrum from discrete peaks",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -95,2 +95,3 @@ export interface SpectrumGeneratorOptions {

y: number;
width?: number;
}

@@ -102,2 +103,3 @@

* @example
* ```js
* import SG from 'spectrum-generator';

@@ -113,5 +115,7 @@ * const sg = new SG({from: 0, to: 100, nbPoints: 1001, peakWidthFct: (x) => 1 + 3 * x / 1000 });

* sg.addBaseline( (x) => x * x / 100 );
* var spectrum = sg.getSpectrum();
*
* const spectrum = sg.getSpectrum();
* ```
*
* @example
* ```js
* import SG from 'spectrum-generator';

@@ -130,2 +134,3 @@ * const spectrum=SG.generateSpectrum([ [20,3], [30,2], [40,2] ], {

* })
* ```
*/

@@ -132,0 +137,0 @@ constructor(options?: SpectrumGeneratorOptions);

@@ -8,3 +8,4 @@ import { SpectrumGenerator } from '..';

const addPeaksReg = /^peaks must be an array/;
const addPeakReg = /^peak must be an array with two values or an object with {x,y}$/;
const addPeakError =
'peak must be an array with two (or three) values or an object with {x,y,width?}';

@@ -44,9 +45,9 @@ describe('errors', () => {

const generator = new SpectrumGenerator();
expect(() => generator.addPeak()).toThrow(addPeakReg);
expect(() => generator.addPeak({})).toThrow(addPeakReg);
expect(() => generator.addPeak({})).toThrow(addPeakReg);
expect(() => generator.addPeak([])).toThrow(addPeakReg);
expect(() => generator.addPeak([1])).toThrow(addPeakReg);
expect(() => generator.addPeak([1, 2, 3])).toThrow(addPeakReg);
expect(() => generator.addPeak()).toThrow(addPeakError);
expect(() => generator.addPeak({})).toThrow(addPeakError);
expect(() => generator.addPeak({})).toThrow(addPeakError);
expect(() => generator.addPeak([])).toThrow(addPeakError);
expect(() => generator.addPeak([1])).toThrow(addPeakError);
expect(() => generator.addPeak([1, 2, 3, 4])).toThrow(addPeakError);
});
});

@@ -90,2 +90,75 @@ import { xyMaxYPoint } from 'ml-spectra-processing';

});
it('generation with [{x,y,width}]', () => {
const generator = new SpectrumGenerator({
from: 0,
to: 10,
nbPoints: 101,
peakWidthFct: () => 5,
});
generator.addPeak({ x: 3, y: 10, width: 1 });
generator.addPeak([7, 10, 1]);
const spectrum = generator.getSpectrum();
const ys = spectrum.y;
expect(ys[25]).toBe(5);
expect(ys[30]).toBe(10);
expect(ys[35]).toBe(5);
expect(ys[65]).toBe(5);
expect(ys[70]).toBe(10);
expect(ys[75]).toBe(5);
expect(ys[31] === ys[71]).toBe(true);
});
it('test various width', () => {
let spectrumGenerator = new SpectrumGenerator({
from: 0,
to: 10,
nbPoints: 101,
peakWidthFct: () => 0.1,
shape: {
kind: 'lorentzian',
options: {
length: 13,
fwhm: 4,
},
},
});
spectrumGenerator.addPeak(
{ x: 2.5, y: 2 },
{
width: 0.1,
shape: {
kind: 'lorentzian',
options: {
length: 13,
fwhm: 4,
},
},
},
);
spectrumGenerator.addPeak(
{ x: 5, y: 1 },
{
width: 0.2,
shape: {
kind: 'gaussian',
options: {
length: 13,
fwhm: 4,
},
},
},
);
const spectrum = spectrumGenerator.getSpectrum();
let max = xyMaxYPoint(spectrum);
expect(spectrum.y[49]).toBe(0.5);
expect(max.x).toBe(2.5);
expect(max.y).toBe(2);
});
});

@@ -79,6 +79,8 @@ import normed from 'ml-array-normed';

typeof peak !== 'object' ||
(peak.length !== 2 && (peak.x === undefined || peak.y === undefined))
(peak.length !== 2 &&
peak.length !== 3 &&
(peak.x === undefined || peak.y === undefined))
) {
throw new Error(
'peak must be an array with two values or an object with {x,y}',
'peak must be an array with two (or three) values or an object with {x,y,width?}',
);

@@ -88,7 +90,9 @@ }

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

@@ -99,3 +103,5 @@

let {
width = this.peakWidthFct(xPosition),
width = peakWidth === undefined
? this.peakWidthFct(xPosition)
: peakWidth,
widthLeft,

@@ -102,0 +108,0 @@ widthRight,

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