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

ml-peak-shape-generator

Package Overview
Dependencies
Maintainers
6
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-peak-shape-generator - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

9

History.md

@@ -0,1 +1,10 @@

# [0.3.0](https://github.com/cheminfo/ml-peak-shape-generator/compare/v0.2.0...v0.3.0) (2020-03-02)
### Features
* allow to specify final length of array ([e83ab31](https://github.com/cheminfo/ml-peak-shape-generator/commit/e83ab31f59c141b95a9f76d6cee782cd6b70b9a8))
# [0.2.0](https://github.com/cheminfo/ml-peak-shape-generator/compare/v0.1.0...v0.2.0) (2020-03-02)

@@ -2,0 +11,0 @@

69

lib/index.js

@@ -10,3 +10,4 @@ 'use strict';

* @param {number} [options.sd] - Standard deviation, if it's defined fwhm parameter will be ignored.
* @param {number} [options.factor = 3] - factor to increase window size: nbPoints = fwhm * factor
* @param {number} [options.factor = 3] - Number of time to take fwhm to calculate length
* @param {number} [options.length = fwhm * factor] - total number of points to calculate
* @return {Float64Array} - array of Y points

@@ -16,3 +17,3 @@ */

function gaussian(options = {}) {
let { factor = 3, fwhm = 500, sd } = options;
let { length, factor = 3, fwhm = 500, sd } = options;

@@ -25,7 +26,7 @@ if (sd) {

const halfWidth = fwhm / 2;
const lenGaussian = 2 * parseInt(halfWidth, 10) * factor + (fwhm % 2);
const center = (lenGaussian - 1) / 2;
if (!length) length = fwhm * factor;
const vector = new Float64Array(lenGaussian);
const center = (length - 1) / 2;
const vector = new Float64Array(length);
const normalConstant = 1 / Math.sqrt(2 * Math.PI) / sd;

@@ -35,8 +36,4 @@ for (let i = 0; i <= center; i++) {

normalConstant * Math.exp(-(1 / 2) * Math.pow((i - center) / sd, 2));
vector[length - 1 - i] = vector[i];
}
let limit = fwhm % 2 ? center : center + 1;
vector.set(
vector.slice(0, parseInt(limit, 10)).reverse(),
parseInt(center + 1, 10),
);
return vector;

@@ -49,3 +46,4 @@ }

* @param {number} [options.fwhm = 500] - number of points in Full Width at Half Maximum.
* @param {number} [options.factor = 3] - factor to increase window size: nbPoints = fwhm * factor
* @param {number} [options.factor = 3] - Number of time to take fwhm to calculate length
* @param {number} [options.length = fwhm * factor] - total number of points to calculate
* @return {Float64Array} - array of Y points.

@@ -55,8 +53,9 @@ */

function lorentzian(options = {}) {
const { factor = 8, fwhm = 1000 } = options;
let { length, factor = 3, fwhm = 1000 } = options;
if (length === undefined) length = fwhm * factor;
const halfWidth = fwhm / 2;
const lenLorentzian = 2 * parseInt(halfWidth, 10) * factor + (fwhm % 2);
const center = (lenLorentzian - 1) / 2;
const center = (length - 1) / 2;
const normalConstant = 1 / Math.PI;
const vector = new Float64Array(lenLorentzian);
const vector = new Float64Array(length);
for (let i = 0; i <= center; i++) {

@@ -66,8 +65,4 @@ vector[i] =

(Math.pow(i - center, 2) + Math.pow(halfWidth, 2));
vector[length - 1 - i] = vector[i];
}
let limit = fwhm % 2 ? center : center + 1;
vector.set(
vector.slice(0, parseInt(limit, 10)).reverse(),
parseInt(center + 1, 10),
);
return vector;

@@ -81,3 +76,4 @@ }

* @param {number} [options.mu = 0.5] - fraction of lorentzian contribution.
* @param {number} [options.factor] - factor to increase window size: nbPoints = fwhm * factor
* @param {number} [options.factor = 3] - Number of time to take fwhm to calculate length
* @param {number} [options.length = fwhm * 3] - total number of points to calculate
* @return {number}

@@ -87,7 +83,6 @@ */

function pseudoVoigt(options = {}) {
const { factor = 2, fwhm = 500, mu = 0.5 } = options;
let { length, factor = 3, fwhm = 1000, mu = 0.5 } = options;
if (length === undefined) length = fwhm * factor;
const halfWidth = fwhm / 2;
const lenPVoigt = 2 * parseInt(halfWidth, 10) * factor + (fwhm % 2);
const center = (lenPVoigt - 1) / 2;
const center = (length - 1) / 2;
const sigma = fwhm / 2 / Math.sqrt(2 * Math.log(2));

@@ -98,3 +93,3 @@

const gFactor = (1 - mu) * (1 / Math.sqrt(Math.PI) / sigma);
const vector = new Float64Array(lenPVoigt);
const vector = new Float64Array(length);
for (let i = 0; i <= center; i++) {

@@ -104,8 +99,4 @@ vector[i] =

gFactor * Math.exp(-1 * Math.pow((i - center) / sigma, 2));
vector[length - 1 - i] = vector[i];
}
let limit = fwhm % 2 ? center : center + 1;
vector.set(
vector.slice(0, parseInt(limit, 10)).reverse(),
parseInt(center + 1, 10),
);
return vector;

@@ -128,2 +119,3 @@ }

function getShape(kind = 1, options = {}) {
if (typeof kind === 'string') kind = getKind(kind);
switch (kind) {

@@ -141,2 +133,15 @@ case 1:

function getKind(kind) {
switch (kind.toLowerCase().replace(/[^a-z]/g, '')) {
case 'gaussian':
return GAUSSIAN;
case 'lorentzian':
return LORENTZIAN;
case 'pseudovoigt':
return PSEUDO_VOIGT;
default:
throw new Error(`Unknown kind: ${kind}`);
}
}
exports.GAUSSIAN = GAUSSIAN;

@@ -143,0 +148,0 @@ exports.LORENTZIAN = LORENTZIAN;

{
"name": "ml-peak-shape-generator",
"version": "0.2.0",
"version": "0.3.0",
"description": "",

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

@@ -6,3 +6,4 @@ /**

* @param {number} [options.sd] - Standard deviation, if it's defined fwhm parameter will be ignored.
* @param {number} [options.factor = 3] - factor to increase window size: nbPoints = fwhm * factor
* @param {number} [options.factor = 3] - Number of time to take fwhm to calculate length
* @param {number} [options.length = fwhm * factor] - total number of points to calculate
* @return {Float64Array} - array of Y points

@@ -12,3 +13,3 @@ */

export function gaussian(options = {}) {
let { factor = 3, fwhm = 500, sd } = options;
let { length, factor = 3, fwhm = 500, sd } = options;

@@ -21,7 +22,7 @@ if (sd) {

const halfWidth = fwhm / 2;
const lenGaussian = 2 * parseInt(halfWidth, 10) * factor + (fwhm % 2);
const center = (lenGaussian - 1) / 2;
if (!length) length = fwhm * factor;
const vector = new Float64Array(lenGaussian);
const center = (length - 1) / 2;
const vector = new Float64Array(length);
const normalConstant = 1 / Math.sqrt(2 * Math.PI) / sd;

@@ -31,9 +32,5 @@ for (let i = 0; i <= center; i++) {

normalConstant * Math.exp(-(1 / 2) * Math.pow((i - center) / sd, 2));
vector[length - 1 - i] = vector[i];
}
let limit = fwhm % 2 ? center : center + 1;
vector.set(
vector.slice(0, parseInt(limit, 10)).reverse(),
parseInt(center + 1, 10),
);
return vector;
}

@@ -19,2 +19,3 @@ /**

export function getShape(kind = 1, options = {}) {
if (typeof kind === 'string') kind = getKind(kind);
switch (kind) {

@@ -31,1 +32,14 @@ case 1:

}
function getKind(kind) {
switch (kind.toLowerCase().replace(/[^a-z]/g, '')) {
case 'gaussian':
return GAUSSIAN;
case 'lorentzian':
return LORENTZIAN;
case 'pseudovoigt':
return PSEUDO_VOIGT;
default:
throw new Error(`Unknown kind: ${kind}`);
}
}

@@ -5,3 +5,4 @@ /**

* @param {number} [options.fwhm = 500] - number of points in Full Width at Half Maximum.
* @param {number} [options.factor = 3] - factor to increase window size: nbPoints = fwhm * factor
* @param {number} [options.factor = 3] - Number of time to take fwhm to calculate length
* @param {number} [options.length = fwhm * factor] - total number of points to calculate
* @return {Float64Array} - array of Y points.

@@ -11,8 +12,9 @@ */

export function lorentzian(options = {}) {
const { factor = 8, fwhm = 1000 } = options;
let { length, factor = 3, fwhm = 1000 } = options;
if (length === undefined) length = fwhm * factor;
const halfWidth = fwhm / 2;
const lenLorentzian = 2 * parseInt(halfWidth, 10) * factor + (fwhm % 2);
const center = (lenLorentzian - 1) / 2;
const center = (length - 1) / 2;
const normalConstant = 1 / Math.PI;
const vector = new Float64Array(lenLorentzian);
const vector = new Float64Array(length);
for (let i = 0; i <= center; i++) {

@@ -22,9 +24,5 @@ vector[i] =

(Math.pow(i - center, 2) + Math.pow(halfWidth, 2));
vector[length - 1 - i] = vector[i];
}
let limit = fwhm % 2 ? center : center + 1;
vector.set(
vector.slice(0, parseInt(limit, 10)).reverse(),
parseInt(center + 1, 10),
);
return vector;
}

@@ -6,3 +6,4 @@ /**

* @param {number} [options.mu = 0.5] - fraction of lorentzian contribution.
* @param {number} [options.factor] - factor to increase window size: nbPoints = fwhm * factor
* @param {number} [options.factor = 3] - Number of time to take fwhm to calculate length
* @param {number} [options.length = fwhm * 3] - total number of points to calculate
* @return {number}

@@ -12,7 +13,6 @@ */

export function pseudoVoigt(options = {}) {
const { factor = 2, fwhm = 500, mu = 0.5 } = options;
let { length, factor = 3, fwhm = 1000, mu = 0.5 } = options;
if (length === undefined) length = fwhm * factor;
const halfWidth = fwhm / 2;
const lenPVoigt = 2 * parseInt(halfWidth, 10) * factor + (fwhm % 2);
const center = (lenPVoigt - 1) / 2;
const center = (length - 1) / 2;
const sigma = fwhm / 2 / Math.sqrt(2 * Math.log(2));

@@ -23,3 +23,3 @@

const gFactor = (1 - mu) * (1 / Math.sqrt(Math.PI) / sigma);
const vector = new Float64Array(lenPVoigt);
const vector = new Float64Array(length);
for (let i = 0; i <= center; i++) {

@@ -29,9 +29,5 @@ vector[i] =

gFactor * Math.exp(-1 * Math.pow((i - center) / sigma, 2));
vector[length - 1 - i] = vector[i];
}
let limit = fwhm % 2 ? center : center + 1;
vector.set(
vector.slice(0, parseInt(limit, 10)).reverse(),
parseInt(center + 1, 10),
);
return vector;
}
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