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

ml-gsd

Package Overview
Dependencies
Maintainers
10
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-gsd - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

67

lib/index.js

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

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var SG = _interopDefault(require('ml-savitzky-golay-generalized'));
var SG = require('ml-savitzky-golay-generalized');
var mlOptimizeLorentzian = require('ml-optimize-lorentzian');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var SG__default = /*#__PURE__*/_interopDefaultLegacy(SG);
/**

@@ -28,3 +30,2 @@ * Global spectra deconvolution

* @param {number} [options.heightFactor = 0] - Factor to multiply the calculated height (usually 2)
* @param {boolean} [options.boundaries = false] - Return also the inflection points of the peaks
* @param {number} [options.derivativeThreshold = -1] - Filters based on the amplitude of the first derivative

@@ -74,3 +75,3 @@ * @return {Array<object>}

// we can assume it to be equally spaced variable
let Y = y;
let yData = y;
let dY, ddY;

@@ -81,3 +82,3 @@ const { windowSize, polynomial } = sgOptions;

if (smoothY) {
Y = SG(y, x[1] - x[0], {
yData = SG__default['default'](y, x[1] - x[0], {
windowSize,

@@ -88,3 +89,3 @@ polynomial,

}
dY = SG(y, x[1] - x[0], {
dY = SG__default['default'](y, x[1] - x[0], {
windowSize,

@@ -94,3 +95,3 @@ polynomial,

});
ddY = SG(y, x[1] - x[0], {
ddY = SG__default['default'](y, x[1] - x[0], {
windowSize,

@@ -102,3 +103,3 @@ polynomial,

if (smoothY) {
Y = SG(y, x, {
yData = SG__default['default'](y, x, {
windowSize,

@@ -109,3 +110,3 @@ polynomial,

}
dY = SG(y, x, {
dY = SG__default['default'](y, x, {
windowSize,

@@ -115,3 +116,3 @@ polynomial,

});
ddY = SG(y, x, {
ddY = SG__default['default'](y, x, {
windowSize,

@@ -122,13 +123,13 @@ polynomial,

}
// console.log('this is 2', y)
const X = x;
const dx = x[1] - x[0];
const xData = x;
const dX = x[1] - x[0];
let maxDdy = 0;
let maxY = 0;
for (let i = 0; i < Y.length; i++) {
for (let i = 0; i < yData.length; i++) {
if (Math.abs(ddY[i]) > maxDdy) {
maxDdy = Math.abs(ddY[i]);
}
if (Math.abs(Y[i]) > maxY) {
maxY = Math.abs(Y[i]);
if (Math.abs(yData[i]) > maxY) {
maxY = Math.abs(yData[i]);
}

@@ -139,6 +140,6 @@ }

let lastMin = null;
let minddY = new Array(Y.length - 2);
let intervalL = new Array(Y.length);
let intervalR = new Array(Y.length);
let broadMask = new Array(Y.length - 2);
let minddY = new Array(yData.length - 2);
let intervalL = new Array(yData.length);
let intervalR = new Array(yData.length);
let broadMask = new Array(yData.length - 2);
let minddYLen = 0;

@@ -149,3 +150,3 @@ let intervalLLen = 0;

// By the intermediate value theorem We cannot find 2 consecutive maximum or minimum
for (let i = 1; i < Y.length - 1; ++i) {
for (let i = 1; i < yData.length - 1; ++i) {
// filter based on derivativeThreshold

@@ -160,6 +161,6 @@ // console.log('pasa', y[i], dY[i], ddY[i]);

lastMin = {
x: X[i],
x: xData[i],
index: i,
};
if (dx > 0 && lastMax !== null) {
if (dX > 0 && lastMax !== null) {
intervalL[intervalLLen++] = lastMax;

@@ -176,6 +177,6 @@ intervalR[intervalRLen++] = lastMin;

lastMax = {
x: X[i],
x: xData[i],
index: i,
};
if (dx < 0 && lastMin !== null) {
if (dX < 0 && lastMin !== null) {
intervalL[intervalLLen++] = lastMax;

@@ -190,3 +191,3 @@ intervalR[intervalRLen++] = lastMin;

// TODO should we change this to have 3 arrays ? Huge overhead creating arrays
minddY[minddYLen++] = i; // ( [X[i], Y[i], i] );
minddY[minddYLen++] = i; // ( [xData[i], yData[i], i] );
broadMask[broadMaskLen++] = Math.abs(ddY[i]) <= broadRatio * maxDdy;

@@ -205,3 +206,3 @@ }

for (let j = 0; j < minddY.length; ++j) {
frequency = X[minddY[j]];
frequency = xData[minddY[j]];
possible = -1;

@@ -229,7 +230,7 @@ let k = lastK + 1;

if (possible !== -1) {
if (Math.abs(Y[minddY[j]]) > minMaxRatio * maxY) {
if (Math.abs(yData[minddY[j]]) > minMaxRatio * maxY) {
signals[signalsLen++] = {
index: minddY[j],
x: frequency,
y: (Y[minddY[j]] + yCorrection.b) / yCorrection.m,
y: (yData[minddY[j]] + yCorrection.b) / yCorrection.m,
width: Math.abs(intervalR[possible].x - intervalL[possible].x), // widthCorrection

@@ -243,4 +244,4 @@ soft: broadMask[j],

if (heightFactor) {
let yLeft = Y[intervalL[possible].index];
let yRight = Y[intervalR[possible].index];
let yLeft = yData[intervalL[possible].index];
let yRight = yData[intervalR[possible].index];
signals[signalsLen - 1].height =

@@ -255,3 +256,3 @@ heightFactor * (signals[signalsLen - 1].y - (yLeft + yRight) / 2);

if (realTopDetection) {
determineRealTop(signals, X, Y);
determineRealTop(signals, xData, yData);
}

@@ -258,0 +259,0 @@

{
"name": "ml-gsd",
"version": "5.0.1",
"version": "5.0.2",
"description": "Global Spectra Deconvolution",

@@ -44,14 +44,14 @@ "main": "lib/index.js",

"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.9.6",
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
"chemcalc": "^3.4.1",
"cheminfo-tools": "^1.23.3",
"eslint": "^7.0.0",
"eslint": "^7.9.0",
"eslint-config-cheminfo": "^3.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.13.1",
"eslint-plugin-prettier": "^3.1.3",
"jest": "^26.0.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.20.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.4.2",
"ml-stat": "^1.3.3",
"prettier": "^2.0.5",
"rollup": "^2.10.4",
"prettier": "^2.1.2",
"rollup": "^2.28.2",
"spectrum-generator": "^4.0.2",

@@ -58,0 +58,0 @@ "xy-parser": "^3.0.0"

@@ -46,6 +46,2 @@ # global-spectral-deconvolution

#### boundaries=false
Return also the inflection points of the peaks
#### derivativeThreshold=0

@@ -52,0 +48,0 @@

@@ -20,3 +20,2 @@ import SG from 'ml-savitzky-golay-generalized';

* @param {number} [options.heightFactor = 0] - Factor to multiply the calculated height (usually 2)
* @param {boolean} [options.boundaries = false] - Return also the inflection points of the peaks
* @param {number} [options.derivativeThreshold = -1] - Filters based on the amplitude of the first derivative

@@ -66,3 +65,3 @@ * @return {Array<object>}

// we can assume it to be equally spaced variable
let Y = y;
let yData = y;
let dY, ddY;

@@ -73,3 +72,3 @@ const { windowSize, polynomial } = sgOptions;

if (smoothY) {
Y = SG(y, x[1] - x[0], {
yData = SG(y, x[1] - x[0], {
windowSize,

@@ -92,3 +91,3 @@ polynomial,

if (smoothY) {
Y = SG(y, x, {
yData = SG(y, x, {
windowSize,

@@ -110,13 +109,13 @@ polynomial,

}
// console.log('this is 2', y)
const X = x;
const dx = x[1] - x[0];
const xData = x;
const dX = x[1] - x[0];
let maxDdy = 0;
let maxY = 0;
for (let i = 0; i < Y.length; i++) {
for (let i = 0; i < yData.length; i++) {
if (Math.abs(ddY[i]) > maxDdy) {
maxDdy = Math.abs(ddY[i]);
}
if (Math.abs(Y[i]) > maxY) {
maxY = Math.abs(Y[i]);
if (Math.abs(yData[i]) > maxY) {
maxY = Math.abs(yData[i]);
}

@@ -127,6 +126,6 @@ }

let lastMin = null;
let minddY = new Array(Y.length - 2);
let intervalL = new Array(Y.length);
let intervalR = new Array(Y.length);
let broadMask = new Array(Y.length - 2);
let minddY = new Array(yData.length - 2);
let intervalL = new Array(yData.length);
let intervalR = new Array(yData.length);
let broadMask = new Array(yData.length - 2);
let minddYLen = 0;

@@ -137,3 +136,3 @@ let intervalLLen = 0;

// By the intermediate value theorem We cannot find 2 consecutive maximum or minimum
for (let i = 1; i < Y.length - 1; ++i) {
for (let i = 1; i < yData.length - 1; ++i) {
// filter based on derivativeThreshold

@@ -148,6 +147,6 @@ // console.log('pasa', y[i], dY[i], ddY[i]);

lastMin = {
x: X[i],
x: xData[i],
index: i,
};
if (dx > 0 && lastMax !== null) {
if (dX > 0 && lastMax !== null) {
intervalL[intervalLLen++] = lastMax;

@@ -164,6 +163,6 @@ intervalR[intervalRLen++] = lastMin;

lastMax = {
x: X[i],
x: xData[i],
index: i,
};
if (dx < 0 && lastMin !== null) {
if (dX < 0 && lastMin !== null) {
intervalL[intervalLLen++] = lastMax;

@@ -178,3 +177,3 @@ intervalR[intervalRLen++] = lastMin;

// TODO should we change this to have 3 arrays ? Huge overhead creating arrays
minddY[minddYLen++] = i; // ( [X[i], Y[i], i] );
minddY[minddYLen++] = i; // ( [xData[i], yData[i], i] );
broadMask[broadMaskLen++] = Math.abs(ddY[i]) <= broadRatio * maxDdy;

@@ -193,3 +192,3 @@ }

for (let j = 0; j < minddY.length; ++j) {
frequency = X[minddY[j]];
frequency = xData[minddY[j]];
possible = -1;

@@ -217,7 +216,7 @@ let k = lastK + 1;

if (possible !== -1) {
if (Math.abs(Y[minddY[j]]) > minMaxRatio * maxY) {
if (Math.abs(yData[minddY[j]]) > minMaxRatio * maxY) {
signals[signalsLen++] = {
index: minddY[j],
x: frequency,
y: (Y[minddY[j]] + yCorrection.b) / yCorrection.m,
y: (yData[minddY[j]] + yCorrection.b) / yCorrection.m,
width: Math.abs(intervalR[possible].x - intervalL[possible].x), // widthCorrection

@@ -231,4 +230,4 @@ soft: broadMask[j],

if (heightFactor) {
let yLeft = Y[intervalL[possible].index];
let yRight = Y[intervalR[possible].index];
let yLeft = yData[intervalL[possible].index];
let yRight = yData[intervalR[possible].index];
signals[signalsLen - 1].height =

@@ -243,3 +242,3 @@ heightFactor * (signals[signalsLen - 1].y - (yLeft + yRight) / 2);

if (realTopDetection) {
determineRealTop(signals, X, Y);
determineRealTop(signals, xData, yData);
}

@@ -246,0 +245,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