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.4.1 to 4.4.2

src/__tests__/generateSpectrum.shape.test.js

8

CHANGELOG.md
# Changelog
### [4.4.2](https://www.github.com/cheminfo/spectrum-generator/compare/v4.4.1...v4.4.2) (2020-12-04)
### Bug Fixes
* correct some shapes imperfections ([eacf462](https://www.github.com/cheminfo/spectrum-generator/commit/eacf4628077939f7fec6894eb5e8966443feb76f))
* NaN bug ([17a5fc9](https://www.github.com/cheminfo/spectrum-generator/commit/17a5fc936be41339048898f6d13c2ef4c487f92b))
### [4.4.1](https://www.github.com/cheminfo/spectrum-generator/compare/v4.4.0...v4.4.1) (2020-11-18)

@@ -4,0 +12,0 @@

42

lib/index.js

@@ -7,5 +7,5 @@ 'use strict';

var mlPeakShapeGenerator = require('ml-peak-shape-generator');
var objectHash = require('object-hash');
var d3Random = require('d3-random');
var XSAdd = require('ml-xsadd');
var objectHash = require('object-hash');

@@ -15,4 +15,4 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var normed__default = /*#__PURE__*/_interopDefaultLegacy(normed);
var objectHash__default = /*#__PURE__*/_interopDefaultLegacy(objectHash);
var XSAdd__default = /*#__PURE__*/_interopDefaultLegacy(XSAdd);
var objectHash__default = /*#__PURE__*/_interopDefaultLegacy(objectHash);

@@ -195,16 +195,38 @@ function addBaseline(data, baselineFct) {

// we calculate the left part of the shape
for (let index = firstPoint; index < middlePoint; index++) {
for (let index = firstPoint; index < Math.max(middlePoint, 0); index++) {
let ratio = ((xPosition - this.data.x[index]) / widthLeft) * 2;
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;
let shapeIndex = shape.halfLength - (ratio * shape.fwhm) / 2;
let floorIndex = Math.floor(shapeIndex);
let ceilIndex = Math.ceil(shapeIndex);
let value =
floorIndex === shapeIndex
? shape.data[shapeIndex]
: shape.data[floorIndex] * (ceilIndex - shapeIndex) +
shape.data[ceilIndex] * (shapeIndex - floorIndex);
shapeIndex = Math.round(shapeIndex);
if (floorIndex >= 0 && ceilIndex < shape.data.length) {
this.data.y[index] += value * intensity;
}
}
// we calculate the right part of the gaussian
for (let index = middlePoint; index <= lastPoint; index++) {
for (
let index = Math.min(middlePoint, lastPoint);
index <= lastPoint;
index++
) {
let ratio = ((this.data.x[index] - xPosition) / widthRight) * 2;
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;
let shapeIndex = shape.halfLength - (ratio * shape.fwhm) / 2;
let floorIndex = Math.floor(shapeIndex);
let ceilIndex = Math.ceil(shapeIndex);
let value =
floorIndex === shapeIndex
? shape.data[shapeIndex]
: shape.data[floorIndex] * (ceilIndex - shapeIndex) +
shape.data[ceilIndex] * (shapeIndex - floorIndex);
shapeIndex = Math.round(shapeIndex);
if (floorIndex >= 0 && ceilIndex <= shape.data.length) {
this.data.y[index] += value * intensity;
}

@@ -211,0 +233,0 @@ }

{
"name": "spectrum-generator",
"version": "4.4.1",
"version": "4.4.2",
"description": "generate a spectrum from discrete peaks",

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

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

});
expect(spectrum.y[8]).toBe(0.5);
expect(spectrum.y[8]).toBeCloseTo(0.5, 10);

@@ -113,3 +113,3 @@ checkSymmetry(spectrum);

let max = xyMaxYPoint(spectrum);
expect(spectrum.y[49]).toBe(0.5);
expect(spectrum.y[49]).toBeCloseTo(0.5, 10);
expect(max.x).toBe(5);

@@ -195,4 +195,6 @@ expect(max.y).toBe(1);

for (let i = 0; i <= Math.floor(spectrum.y.length / 2); i++) {
expect(spectrum.y[i]).toStrictEqual(spectrum.y[spectrum.y.length - i - 1]);
expect(spectrum.y[i] - spectrum.y[spectrum.y.length - i - 1]).toBeCloseTo(
0,
);
}
}
import { xyMaxYPoint } from 'ml-spectra-processing';
import { SpectrumGenerator } from '..';

@@ -86,3 +87,3 @@

let max = xyMaxYPoint(spectrum);
expect(spectrum.y[49]).toBe(0.5);
expect(spectrum.y[49]).toBeCloseTo(0.5, 10);
expect(max.x).toBe(2.5);

@@ -115,3 +116,3 @@ expect(max.y).toBe(2);

expect(ys[31] === ys[71]).toBe(true);
expect(ys[31] - ys[71]).toBeCloseTo(0, 10);
});

@@ -161,3 +162,3 @@

let max = xyMaxYPoint(spectrum);
expect(spectrum.y[49]).toBe(0.5);
expect(spectrum.y[49]).toBeCloseTo(0.5, 10);
expect(max.x).toBe(2.5);

@@ -164,0 +165,0 @@ expect(max.y).toBe(2);

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

expect(sumX).toBe(10050);
expect(sumY).toBeCloseTo(4257.612704089137, 4);
expect(sumY).toBeCloseTo(4257.612789255516, 4);
});

@@ -58,0 +58,0 @@

import normed from 'ml-array-normed';
import { getShape } from 'ml-peak-shape-generator';
import objectHash from 'object-hash';
import addBaseline from './util/addBaseline.js';
import addNoise from './util/addNoise.js';
import objectHash from 'object-hash';

@@ -134,16 +134,38 @@ let shapesCache = {};

// we calculate the left part of the shape
for (let index = firstPoint; index < middlePoint; index++) {
for (let index = firstPoint; index < Math.max(middlePoint, 0); index++) {
let ratio = ((xPosition - this.data.x[index]) / widthLeft) * 2;
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;
let shapeIndex = shape.halfLength - (ratio * shape.fwhm) / 2;
let floorIndex = Math.floor(shapeIndex);
let ceilIndex = Math.ceil(shapeIndex);
let value =
floorIndex === shapeIndex
? shape.data[shapeIndex]
: shape.data[floorIndex] * (ceilIndex - shapeIndex) +
shape.data[ceilIndex] * (shapeIndex - floorIndex);
shapeIndex = Math.round(shapeIndex);
if (floorIndex >= 0 && ceilIndex < shape.data.length) {
this.data.y[index] += value * intensity;
}
}
// we calculate the right part of the gaussian
for (let index = middlePoint; index <= lastPoint; index++) {
for (
let index = Math.min(middlePoint, lastPoint);
index <= lastPoint;
index++
) {
let ratio = ((this.data.x[index] - xPosition) / widthRight) * 2;
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;
let shapeIndex = shape.halfLength - (ratio * shape.fwhm) / 2;
let floorIndex = Math.floor(shapeIndex);
let ceilIndex = Math.ceil(shapeIndex);
let value =
floorIndex === shapeIndex
? shape.data[shapeIndex]
: shape.data[floorIndex] * (ceilIndex - shapeIndex) +
shape.data[ceilIndex] * (shapeIndex - floorIndex);
shapeIndex = Math.round(shapeIndex);
if (floorIndex >= 0 && ceilIndex <= shape.data.length) {
this.data.y[index] += value * intensity;
}

@@ -150,0 +172,0 @@ }

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