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.3.0 to 4.4.0

12

CHANGELOG.md
# Changelog
## [4.4.0](https://www.github.com/cheminfo/spectrum-generator/compare/v4.3.0...v4.4.0) (2020-10-31)
### Features
* add cache for shape generation ([468e162](https://www.github.com/cheminfo/spectrum-generator/commit/468e16204f7befd5c7bef063d13d5d7761d63852))
### Bug Fixes
* bug with add peak and custom shapes ([6d712be](https://www.github.com/cheminfo/spectrum-generator/commit/6d712beca2f9985d3d60f62679fc6ee1d908bfc6))
## [4.3.0](https://www.github.com/cheminfo/spectrum-generator/compare/v4.2.0...v4.3.0) (2020-10-29)

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

23

lib/index.js

@@ -9,2 +9,3 @@ 'use strict';

var XSAdd = require('ml-xsadd');
var objectHash = require('object-hash');

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

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

@@ -67,2 +69,5 @@ function addBaseline(data, baselineFct) {

let shapesCache = {};
const MAX_CACHE_LENGTH = 20;
class SpectrumGenerator {

@@ -177,4 +182,4 @@ constructor(options = {}) {

const firstValue = xPosition - (widthLeft / 2) * this.shape.factor;
const lastValue = xPosition + (widthRight / 2) * this.shape.factor;
const firstValue = xPosition - (widthLeft / 2) * shape.factor;
const lastValue = xPosition + (widthRight / 2) * shape.factor;

@@ -286,4 +291,11 @@ const firstPoint = Math.max(

function createShape(kind, options) {
const hash = objectHash__default['default']({ kind, options });
if (shapesCache[hash]) {
return shapesCache[hash];
}
let shape = {};
let newShape = mlPeakShapeGenerator.getShape(kind, options);
shape.data = normed__default['default'](newShape.data, {

@@ -296,2 +308,9 @@ algorithm: 'max',

shape.halfLength = Math.floor(newShape.data.length / 2);
if (Object.keys(shapesCache > MAX_CACHE_LENGTH)) {
shapesCache = {};
}
shapesCache[hash] = shape;
return shape;

@@ -298,0 +317,0 @@ }

5

package.json
{
"name": "spectrum-generator",
"version": "4.3.0",
"version": "4.4.0",
"description": "generate a spectrum from discrete peaks",

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

"ml-peak-shape-generator": "^0.4.0",
"ml-xsadd": "2.0.0"
"ml-xsadd": "2.0.0",
"object-hash": "^2.0.3"
}
}

@@ -82,4 +82,4 @@ # spectrum-generator

generator.addPeaks([
[40, 12], // it can also be an array of objects with x,y properties
[10, 1],
{x: 40, y: 12}, // it can also be an array of 2 elements
{x: 10, y:1},
]);

@@ -90,4 +90,4 @@ const spectrum = generator.getSpectrum();

generator.addPeak([10, 50], { // customize peaks shape
width: 0.1,
generator.addPeak({x: 10, y: 50}], { // customize peaks shape
width: 0.1, // width of peak is FWHM
shape: {

@@ -102,3 +102,5 @@ kind: 'lorentzian',

generator.addPeak([10, 50], { // customize peaks shape
generator.addPeak({x: 10, y: 50, width: 2}) // specifiy the peak width. This is the peak width half height (FWHM)
generator.addPeak({x: 10, y: 50}], { // customize peaks shape
width: 0.1,

@@ -105,0 +107,0 @@ shape: {

@@ -6,3 +6,7 @@ import normed from 'ml-array-normed';

import addNoise from './util/addNoise.js';
import objectHash from 'object-hash';
let shapesCache = {};
const MAX_CACHE_LENGTH = 20;
export class SpectrumGenerator {

@@ -117,4 +121,4 @@ constructor(options = {}) {

const firstValue = xPosition - (widthLeft / 2) * this.shape.factor;
const lastValue = xPosition + (widthRight / 2) * this.shape.factor;
const firstValue = xPosition - (widthLeft / 2) * shape.factor;
const lastValue = xPosition + (widthRight / 2) * shape.factor;

@@ -226,4 +230,11 @@ const firstPoint = Math.max(

function createShape(kind, options) {
const hash = objectHash({ kind, options });
if (shapesCache[hash]) {
return shapesCache[hash];
}
let shape = {};
let newShape = getShape(kind, options);
shape.data = normed(newShape.data, {

@@ -236,3 +247,10 @@ algorithm: 'max',

shape.halfLength = Math.floor(newShape.data.length / 2);
if (Object.keys(shapesCache > MAX_CACHE_LENGTH)) {
shapesCache = {};
}
shapesCache[hash] = shape;
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