Detalhes do pacote

spectrum-generator

cheminfo3.9kMIT8.1.0

generate a spectrum from discrete peaks

readme (leia-me)

spectrum-generator

NPM version build status npm download DOI

Generates a spectrum from discrete peaks. The shape of the peaks can be customized.

The shape is generated using ml-peak-shape-generator and you may use all the corresponding options of getShape.

Installation

$ npm i spectrum-generator

Usage

generateSpectrum

import { generateSpectrum } from 'spectrum-generator';

const peaks = [
  [4, 10],
  [20, 30],
  [236, 1],
  [569, 76],
];
const spectrum = generateSpectrum(peaks, {
  generator: {
    from: 0,
    to: 1000,
    nbPoints: 10001,
  },
  shape: {
    kind: 'gaussian', // default value is gaussian
  },
});

Example to generate a high resolution spectrum using lorentzian peaks shape

import { generateSpectrum } from 'spectrum-generator';

const peaks = [
  [1, 10],
  [2, 30],
  [3, 1],
  [4, 76],
];

/*
Peaks can also be introduced as:
- const peaks = [{x:1,y:10},{x:2,y:30},{x:3,y:1},{x:4,y:76}]
- const peaks = {x:[1,2,3,4], y:[10,30,1,76]}
- const peaks = [ [1,10,5], [2,30,10] ] // third argument is the peak fwhm
*/

const spectrum = generateSpectrum(peaks, {
  generator: {
    from: 0,
    to: 10,
    nbPoints: 1001,
  },
  shape: {
    kind: 'lorentzian',
  },
});

genrateSpectrum with baseline

const spectrum = generateSpectrum([{ x: 5, y: 100 }], {
  generator: {
    from: 0,
    to: 10,
    nbPoints: 51,
    peakWidthFct: () => 2,
  },
  baseline: (x) => x / 10,
});

genereateSpectrum with noise

Generate with some noise

const spectrum = generateSpectrum([{ x: 5, y: 100 }], {
  generator: {
    from: 0,
    to: 10,
    nbPoints: 51,
    peakWidthFct: () => 2,
  },
  noise: {
    percent: 10,
    distribution: 'uniform',
  },
});

class SpectrumGenerator

import { SpectrumGenerator } from 'spectrum-generator';

const generator = new SpectrumGenerator();
generator.addPeak([5, 20]);
generator.addPeak({ x: 5, y: 20 }); // we may either add an array of 2 elements or an object with x,y values
generator.addPeak([30, 56]);
generator.addPeaks([
  {x: 40, y: 12}, // it can also be an array of 2 elements
  {x: 10, y:1},
]);
const spectrum = generator.getSpectrum();

generator.reset();

generator.addPeak({x: 10, y: 50}], { // customize peaks shape
  width: 0.1, // width of peak is FWHM
  factor: 10, // 10 times fwhm. Lorentzian are rather flat
  shape: {
    kind: 'lorentzian',
  }
});

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,
  shape: {
    kind: 'gaussian',
  }
});
const otherSpectrum = generator.getSpectrum();

API Documentation

License

MIT


changelog (log de mudanças)

Changelog

8.1.0 (2025-03-28)

Features

  • support to negative peaks in 2D spectra generation(#85) (70f81b0)

8.0.12 (2024-12-05)

Bug Fixes

  • generalizedLorentzian shape supported (#86) (a2f4dc8)
  • result was wrong if only 1 point (e12dacd)

8.0.11 (2024-03-07)

Bug Fixes

8.0.10 (2024-03-06)

Bug Fixes

8.0.9 (2024-01-31)

Documentation

8.0.8 (2023-07-18)

Bug Fixes

8.0.7 (2023-03-24)

Bug Fixes

8.0.6 (2022-11-13)

Documentation

  • fix the abstract of CITATION.cff (4f2d133)

8.0.5 (2022-11-13)

Documentation

8.0.4 (2022-08-09)

Bug Fixes

8.0.3 (2022-08-06)

Bug Fixes

8.0.2 (2022-05-12)

Bug Fixes

8.0.1 (2022-03-25)

Bug Fixes

  • spectrum2DGenerator: avoid reference (a32dbcd)

8.0.0 (2022-03-02)

⚠ BREAKING CHANGES

  • fwhm is a property of the shape

Features

  • fwhm is a property of the shape (3596ae4)

7.0.1 (2022-02-25)

Bug Fixes

7.0.0 (2022-02-15)

⚠ BREAKING CHANGES

  • refactor addNoise to use createRandomArray

Miscellaneous Chores

  • refactor addNoise to use createRandomArray (9abe344)

6.0.4 (2022-02-09)

Bug Fixes

  • convert width to fwhm in spectrum2D (#57) (80a2586)

6.0.3 (2022-02-03)

Bug Fixes

  • spectrum2DGenerator: use the width option in addPeak (#55) (e7ccbda)

6.0.2 (2021-11-29)

Bug Fixes

  • update ml-peak-shape-generator to 4.0.1 (#53) (e574fd1)

6.0.1 (2021-11-23)

Bug Fixes

6.0.0 (2021-11-18)

⚠ BREAKING CHANGES

  • change input structure of shape parameter (#49)

Features

  • change input structure of shape parameter (#49) (77e6a19)

5.4.1 (2021-10-20)

Bug Fixes

  • check if width is defined and != zero (060ecf3)
  • move types folder to src (8895dfb)
  • update eslint and cheminfo-config (a9c7787)

5.4.0 (2021-09-25)

Features

5.3.0 (2021-09-24)

Features

5.2.0 (2021-09-24)

Features

  • remove extra types folder n export types (#40) (b85b220)

5.1.0 (2021-08-30)

Features

  • export XYNumber type from peak-shape-generator (4b13588)
  • update @types/jest (37b23a4)

5.0.2 (2021-08-13)

Bug Fixes

  • rows in the first index (48cd472)

5.0.1 (2021-08-10)

Bug Fixes

5.0.0 (2021-08-10)

⚠ BREAKING CHANGES

  • major version with typescript migration

Features

  • major version with typescript migration (38581da)

4.8.1 (2021-08-10)

Bug Fixes

  • reverse a breaking change (41293c7)

4.8.0 (2021-08-09)

Features

  • fixing usage of peak options close #31 (#32) (98bd1da)
  • typescript migration, add Spectrum2DGenerator (#34) (72907f8)

4.7.1 (2021-03-24)

Bug Fixes

4.7.0 (2021-01-06)

Features

  • Use gaussian ration directly from peaks (#28) (36e1051)

4.6.0 (2020-12-11)

Features

4.5.0 (2020-12-10)

Features

  • Improve speed by calculating point to point the peak shape. (#24) (b987289)

4.4.2 (2020-12-04)

Bug Fixes

4.4.1 (2020-11-18)

Bug Fixes

  • peak shape and package updates (65dd5e7)

4.4.0 (2020-10-31)

Features

  • add cache for shape generation (468e162)

Bug Fixes

  • bug with add peak and custom shapes (6d712be)

4.3.0 (2020-10-29)

Features

  • allow x,y,width objects to addPeak (d3da510)

Bug Fixes

  • correct examples for typescript (fa44388)

4.2.0 (2020-10-15)

Features

  • addPeaks accepts options (e0d3bec)

4.1.2 (2020-10-12)

Bug Fixes

4.1.1 (2020-10-12)

Bug Fixes

  • remove docs to force rebuild with github actions (9e2c964)

4.1.0 (2020-10-12)

Features

4.0.2 (2020-04-18)

Bug Fixes

  • one more edge bug that leads to y=0 (8bbca0f)

4.0.1 (2020-04-18)

Bug Fixes

  • example SpectrumGenerator (cf49ce1)
  • examples (4a8289b)
  • rouding problem in spectrum generation yield to zero values (fcb1521)

4.0.0 (2020-03-18)

3.2.2 (2020-03-13)

Bug Fixes

  • remove cheminfo-tools from dependencies (5c17e1c)

3.2.1 (2020-03-07)

Bug Fixes

3.2.0 (2020-03-02)

Features

  • allow to specify the shape (abb6a7d)

3.1.0 (2019-01-10)

3.0.1 (2018-10-23)

Bug Fixes

  • addPeak: fix peak generation with non-integer middlepoint index (#3) (baf1a6e)

3.0.0 (2018-10-23)

2.0.1 (2018-08-03)

2.0.0 (2018-07-28)

1.1.0 (2018-03-12)

1.0.1 (2018-03-09)

Bug Fixes

  • fix bug when start not 0 and pointsPerUnit not 1 (a41d3db)

1.0.0 (2017-11-09)

Features

  • implement spectrum generator (6199252)