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.1.2 to 4.2.0

src/__tests__/SpectrumGenerator.shapes.test.js

7

CHANGELOG.md
# Changelog
## [4.2.0](https://www.github.com/cheminfo/spectrum-generator/compare/v4.1.2...v4.2.0) (2020-10-15)
### Features
* addPeaks accepts options ([e0d3bec](https://www.github.com/cheminfo/spectrum-generator/commit/e0d3bec4c9347b959471ba2cd2917b3251149afe))
### [4.1.2](https://www.github.com/cheminfo/spectrum-generator/compare/v4.1.1...v4.1.2) (2020-10-12)

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

53

lib/index.js

@@ -90,9 +90,4 @@ 'use strict';

this.maxPeakHeight = Number.MIN_SAFE_INTEGER;
this.shape = mlPeakShapeGenerator.getShape(options.shape.kind, options.shape.options);
this.shape.data = normed__default['default'](this.shape.data, {
algorithm: 'max',
});
this.shapeFactor = (this.shape.data.length - 1) / this.shape.fwhm;
this.shapeLength = this.shape.data.length;
this.shapeHalfLength = Math.floor(this.shape.data.length / 2);
this.shape = createShape(options.shape.kind, options.shape.options);
assertNumber(this.from, 'from');

@@ -113,3 +108,3 @@ assertNumber(this.to, 'to');

addPeaks(peaks) {
addPeaks(peaks, options) {
if (

@@ -130,7 +125,7 @@ !Array.isArray(peaks) &&

for (const peak of peaks) {
this.addPeak(peak);
this.addPeak(peak, options);
}
} else {
for (let i = 0; i < peaks.x.length; i++) {
this.addPeak([peaks.x[i], peaks.y[i]]);
this.addPeak([peaks.x[i], peaks.y[i]], options);
}

@@ -166,9 +161,14 @@ }

widthRight,
shape: shapeOptions,
} = options;
const shape = shapeOptions
? createShape(shapeOptions.kind, shapeOptions.options)
: this.shape;
if (!widthLeft) widthLeft = width;
if (!widthRight) widthRight = width;
const firstValue = xPosition - (widthLeft / 2) * this.shapeFactor;
const lastValue = xPosition + (widthRight / 2) * this.shapeFactor;
const firstValue = xPosition - (widthLeft / 2) * this.shape.factor;
const lastValue = xPosition + (widthRight / 2) * this.shape.factor;

@@ -188,7 +188,5 @@ const firstPoint = Math.max(

let ratio = ((xPosition - this.data.x[index]) / widthLeft) * 2;
let shapeIndex = Math.round(
this.shapeHalfLength - (ratio * this.shape.fwhm) / 2,
);
if (shapeIndex >= 0 && shapeIndex < this.shape.data.length) {
this.data.y[index] += this.shape.data[shapeIndex] * intensity;
let shapeIndex = Math.round(shape.halfLength - (ratio * shape.fwhm) / 2);
if (shapeIndex >= 0 && shapeIndex < shape.data.length) {
this.data.y[index] += shape.data[shapeIndex] * intensity;
}

@@ -200,7 +198,5 @@ }

let shapeIndex = Math.round(
this.shapeHalfLength - (ratio * this.shape.fwhm) / 2,
);
if (shapeIndex >= 0 && shapeIndex <= this.shape.data.length) {
this.data.y[index] += this.shape.data[shapeIndex] * intensity;
let shapeIndex = Math.round(shape.halfLength - (ratio * shape.fwhm) / 2);
if (shapeIndex >= 0 && shapeIndex <= shape.data.length) {
this.data.y[index] += shape.data[shapeIndex] * intensity;
}

@@ -285,3 +281,16 @@ }

function createShape(kind, options) {
let shape = {};
let newShape = mlPeakShapeGenerator.getShape(kind, options);
shape.data = normed__default['default'](newShape.data, {
algorithm: 'max',
});
shape.fwhm = newShape.fwhm;
shape.factor = (newShape.data.length - 1) / newShape.fwhm;
shape.length = newShape.data.length;
shape.halfLength = Math.floor(newShape.data.length / 2);
return shape;
}
exports.SpectrumGenerator = SpectrumGenerator;
exports.generateSpectrum = generateSpectrum;
{
"name": "spectrum-generator",
"version": "4.1.2",
"version": "4.2.0",
"description": "generate a spectrum from discrete peaks",

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

@@ -88,3 +88,24 @@ # spectrum-generator

generator.reset();
generator.addPeak([10, 50]);
generator.addPeak([10, 50], { // customize peaks shape
width: 0.1,
shape: {
kind: 'lorentzian',
options: {
fwhm: 1000,
length: 10001,
},
}
});
generator.addPeak([10, 50], { // customize peaks shape
width: 0.1,
shape: {
kind: 'gaussian',
options: {
fwhm: 1000,
length: 10001,
},
}
});
const otherSpectrum = generator.getSpectrum();

@@ -91,0 +112,0 @@ ```

@@ -136,3 +136,3 @@ export interface SpectrumGeneratorOptions {

*/
addPeaks(peaks: number[][] | XYObject[] | Spectrum): this;
addPeaks(peaks: number[][] | XYObject[] | Spectrum, options?: PeakOptions): this;

@@ -139,0 +139,0 @@ /**

@@ -32,9 +32,4 @@ import normed from 'ml-array-normed';

this.maxPeakHeight = Number.MIN_SAFE_INTEGER;
this.shape = getShape(options.shape.kind, options.shape.options);
this.shape.data = normed(this.shape.data, {
algorithm: 'max',
});
this.shapeFactor = (this.shape.data.length - 1) / this.shape.fwhm;
this.shapeLength = this.shape.data.length;
this.shapeHalfLength = Math.floor(this.shape.data.length / 2);
this.shape = createShape(options.shape.kind, options.shape.options);
assertNumber(this.from, 'from');

@@ -55,3 +50,3 @@ assertNumber(this.to, 'to');

addPeaks(peaks) {
addPeaks(peaks, options) {
if (

@@ -72,7 +67,7 @@ !Array.isArray(peaks) &&

for (const peak of peaks) {
this.addPeak(peak);
this.addPeak(peak, options);
}
} else {
for (let i = 0; i < peaks.x.length; i++) {
this.addPeak([peaks.x[i], peaks.y[i]]);
this.addPeak([peaks.x[i], peaks.y[i]], options);
}

@@ -108,9 +103,14 @@ }

widthRight,
shape: shapeOptions,
} = options;
const shape = shapeOptions
? createShape(shapeOptions.kind, shapeOptions.options)
: this.shape;
if (!widthLeft) widthLeft = width;
if (!widthRight) widthRight = width;
const firstValue = xPosition - (widthLeft / 2) * this.shapeFactor;
const lastValue = xPosition + (widthRight / 2) * this.shapeFactor;
const firstValue = xPosition - (widthLeft / 2) * this.shape.factor;
const lastValue = xPosition + (widthRight / 2) * this.shape.factor;

@@ -130,7 +130,5 @@ const firstPoint = Math.max(

let ratio = ((xPosition - this.data.x[index]) / widthLeft) * 2;
let shapeIndex = Math.round(
this.shapeHalfLength - (ratio * this.shape.fwhm) / 2,
);
if (shapeIndex >= 0 && shapeIndex < this.shape.data.length) {
this.data.y[index] += this.shape.data[shapeIndex] * intensity;
let shapeIndex = Math.round(shape.halfLength - (ratio * shape.fwhm) / 2);
if (shapeIndex >= 0 && shapeIndex < shape.data.length) {
this.data.y[index] += shape.data[shapeIndex] * intensity;
}

@@ -142,7 +140,5 @@ }

let shapeIndex = Math.round(
this.shapeHalfLength - (ratio * this.shape.fwhm) / 2,
);
if (shapeIndex >= 0 && shapeIndex <= this.shape.data.length) {
this.data.y[index] += this.shape.data[shapeIndex] * intensity;
let shapeIndex = Math.round(shape.halfLength - (ratio * shape.fwhm) / 2);
if (shapeIndex >= 0 && shapeIndex <= shape.data.length) {
this.data.y[index] += shape.data[shapeIndex] * intensity;
}

@@ -226,1 +222,14 @@ }

}
function createShape(kind, options) {
let shape = {};
let newShape = getShape(kind, options);
shape.data = normed(newShape.data, {
algorithm: 'max',
});
shape.fwhm = newShape.fwhm;
shape.factor = (newShape.data.length - 1) / newShape.fwhm;
shape.length = newShape.data.length;
shape.halfLength = Math.floor(newShape.data.length / 2);
return shape;
}
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