New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ml-rolling-ball-baseline

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-rolling-ball-baseline - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

lib-esm/index.d.ts

87

lib/index.js

@@ -1,81 +0,6 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isAnyArray = require('is-any-array');
var mlSpectraProcessing = require('ml-spectra-processing');
/**
* Rolling ball baseline correction algorithm.
* From the abstract of (1):
* "This algorithm behaves equivalently to traditional polynomial backgrounds in simple spectra,
* [...] and is considerably more robust for multiple overlapping peaks, rapidly varying background [...]
*
* The baseline is the trace one gets by rolling a ball below a spectrum. Algorithm has three steps:
* Finding the minima in each window, find maxima among minima and then smooth over them by averaging.
*
* Reference:
* (1) Kneen, M. A.; Annegarn, H. J.
* Algorithm for Fitting XRF, SEM and PIXE X-Ray Spectra Backgrounds.
* Nuclear Instruments and Methods in Physics Research Section B: Beam Interactions with Materials and Atoms 1996, 109–110, 209–213.
* https://doi.org/10.1016/0168-583X(95)00908-6.
* (2) Kristian Hovde Liland, Bjørn-Helge Mevik, Roberto Canteri: baseline.
* https://cran.r-project.org/web/packages/baseline/index.html
* @export
* @param {Array} spectrum
* @param {Object} [options={}]
* @param {Number} [options.windowM] - width of local window for minimization/maximization, defaults to 4% of the spectrum length
* @param {Number} [options.windowS] - width of local window for smoothing, defaults to 8% of the spectrum length
*/
function rollingBall(spectrum, options = {}) {
if (!isAnyArray.isAnyArray(spectrum)) {
throw new Error('Spectrum must be an array');
}
if (spectrum.length === 0) {
throw new TypeError('Spectrum must not be empty');
}
const numberPoints = spectrum.length;
const maxima = new Float64Array(numberPoints);
const minima = new Float64Array(numberPoints);
const baseline = new Float64Array(numberPoints);
// windowM 4 percent of spectrum length
// windowS 8 percent of spectrum length
const {
windowM = Math.round(numberPoints * 0.04),
windowS = Math.round(numberPoints * 0.08),
} = options;
// fi(1) in original paper
for (let i = 0; i < spectrum.length; i++) {
let windowLeft = Math.max(0, i - windowM);
let windowRight = Math.min(i + windowM + 1, spectrum.length);
minima[i] = mlSpectraProcessing.xMinValue(spectrum, {
fromIndex: windowLeft,
toIndex: windowRight,
});
}
// fi in original paper
for (let i = 0; i < minima.length; i++) {
let windowLeft = Math.max(0, i - windowM);
let windowRight = Math.min(i + windowM + 1, minima.length);
maxima[i] = mlSpectraProcessing.xMaxValue(minima, {
fromIndex: windowLeft,
toIndex: windowRight,
});
}
for (let i = 0; i < minima.length; i++) {
let windowLeft = Math.max(0, i - windowS);
let windowRight = Math.min(i + windowS + 1, maxima.length);
baseline[i] = mlSpectraProcessing.xMean(maxima.subarray(windowLeft, windowRight));
}
return baseline;
}
exports.rollingBall = rollingBall;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rollingBall = void 0;
const rollingBall_1 = require("./rollingBall");
Object.defineProperty(exports, "rollingBall", { enumerable: true, get: function () { return rollingBall_1.rollingBall; } });
//# sourceMappingURL=index.js.map
{
"name": "ml-rolling-ball-baseline",
"version": "1.1.0",
"version": "2.0.0",
"description": "Rolling ball baseline correction",
"main": "lib/index.js",
"module": "src/index.js",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib",
"src"
"src",
"lib-esm"
],
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"eslint": "eslint src",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "rollup -c",
"prepack": "npm run tsc",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-only && npm run eslint && npm run prettier",
"test-only": "jest --coverage"
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"test-only": "jest --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json"
},

@@ -32,9 +39,11 @@ "repository": {

"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.17.7",
"@types/jest": "^27.4.1",
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^27.5.2",
"cheminfo-types": "^1.4.0",
"eslint": "^8.12.0",
"eslint-config-cheminfo": "^7.3.0",
"eslint-config-cheminfo-typescript": "^11.2.2",
"jest": "^27.5.1",
"prettier": "^2.6.1",
"rollup": "^2.70.1"
"rimraf": "^3.0.2"
},

@@ -41,0 +50,0 @@ "dependencies": {

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