ml-peak-shape-generator
Advanced tools
Comparing version 3.0.3 to 4.0.0
# Changelog | ||
## [4.0.0](https://www.github.com/mljs/peak-shape-generator/compare/v3.0.3...v4.0.0) (2021-11-26) | ||
### ⚠ BREAKING CHANGES | ||
* simplify exposed methods and interface | ||
### Features | ||
* simplify exposed methods and interface ([eabd472](https://www.github.com/mljs/peak-shape-generator/commit/eabd47296336b088a014276f956ed902e8620c13)) | ||
### Bug Fixes | ||
* avoid duplication of interfaces ([#58](https://www.github.com/mljs/peak-shape-generator/issues/58)) ([6b68b58](https://www.github.com/mljs/peak-shape-generator/commit/6b68b5892b88ae6ec7921cee819cecb6b17dfe1d)) | ||
### [3.0.3](https://www.github.com/mljs/peak-shape-generator/compare/v3.0.2...v3.0.3) (2021-11-23) | ||
@@ -4,0 +20,0 @@ |
@@ -1,9 +0,7 @@ | ||
export { Gaussian } from './shapes/1d/gaussian/Gaussian'; | ||
export { Lorentzian } from './shapes/1d/lorentzian/Lorentzian'; | ||
export { PseudoVoigt } from './shapes/1d/pseudoVoigt/PseudoVoigt'; | ||
export * from './shapes/1d/gaussian/Gaussian'; | ||
export * from './shapes/1d/lorentzian/Lorentzian'; | ||
export * from './shapes/1d/pseudoVoigt/PseudoVoigt'; | ||
export { Gaussian2D } from './shapes/2d/gaussian2D/Gaussian2D'; | ||
export * from './util/getShape1D'; | ||
export * from './util/getShape2D'; | ||
export * from './util/getShapeData1D'; | ||
export * from './util/getShapeData2D'; | ||
export * from './shapes/1d/getShape1D'; | ||
export * from './shapes/2d/getShape2D'; | ||
//# sourceMappingURL=index.js.map |
@@ -31,3 +31,3 @@ import { ROOT_2LN2, GAUSSIAN_EXP_FACTOR, ROOT_PI_OVER_LN2, } from '../../../util/constants'; | ||
export function calculateGaussianHeight(options) { | ||
let { fwhm = 1, area = 1, sd } = options; | ||
let { fwhm = 500, area = 1, sd } = options; | ||
if (sd) | ||
@@ -47,8 +47,5 @@ fwhm = gaussianWidthToFWHM(2 * sd); | ||
export function getGaussianArea(options) { | ||
let { fwhm, sd, height = 1 } = options; | ||
let { fwhm = 500, sd, height = 1 } = options; | ||
if (sd) | ||
fwhm = gaussianWidthToFWHM(2 * sd); | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
return (height * ROOT_PI_OVER_LN2 * fwhm) / 2; | ||
@@ -55,0 +52,0 @@ } |
@@ -42,6 +42,3 @@ import { ROOT_THREE } from '../../../util/constants'; | ||
export const getLorentzianArea = (options) => { | ||
const { fwhm, height = 1 } = options; | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
const { fwhm = 500, height = 1 } = options; | ||
return (height * Math.PI * fwhm) / 2; | ||
@@ -48,0 +45,0 @@ }; |
@@ -37,3 +37,3 @@ import { GAUSSIAN_EXP_FACTOR, ROOT_2LN2_MINUS_ONE, ROOT_PI_OVER_LN2, } from '../../../util/constants'; | ||
} | ||
export const calculatePseudoVoigtHeight = (options) => { | ||
export const calculatePseudoVoigtHeight = (options = {}) => { | ||
let { fwhm = 1, mu = 0.5, area = 1 } = options; | ||
@@ -52,6 +52,3 @@ return (2 * area) / (fwhm * (mu * ROOT_PI_OVER_LN2 + (1 - mu) * Math.PI)); | ||
export const getPseudoVoigtArea = (options) => { | ||
const { fwhm, height = 1, mu = 0.5 } = options; | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
const { fwhm = 500, height = 1, mu = 0.5 } = options; | ||
return (fwhm * height * (mu * ROOT_PI_OVER_LN2 + (1 - mu) * Math.PI)) / 2; | ||
@@ -58,0 +55,0 @@ }; |
import { GAUSSIAN_EXP_FACTOR } from '../../../util/constants'; | ||
import { getGaussianFactor, gaussianFwhmToWidth, gaussianWidthToFWHM, } from '../../1d/gaussian/Gaussian'; | ||
export class Gaussian2D { | ||
// /** | ||
// * The maximum z value of the shape, default keep surface equal 1. | ||
// */ | ||
// public height: number; | ||
constructor(options = {}) { | ||
@@ -83,3 +79,3 @@ let { fwhm = 50, sd } = options; | ||
export const calculateGaussian2DHeight = (options = {}) => { | ||
let { volume = 1, fwhm = 1, sd } = options; | ||
let { volume = 1, fwhm = 50, sd } = options; | ||
fwhm = ensureFWHM2D(fwhm, sd); | ||
@@ -86,0 +82,0 @@ return (volume * Math.LN2 * 4) / (Math.PI * fwhm.y * fwhm.x); |
@@ -1,12 +0,10 @@ | ||
export { Gaussian } from './shapes/1d/gaussian/Gaussian'; | ||
export { Lorentzian } from './shapes/1d/lorentzian/Lorentzian'; | ||
export { PseudoVoigt } from './shapes/1d/pseudoVoigt/PseudoVoigt'; | ||
export { Gaussian2D, XYNumber } from './shapes/2d/gaussian2D/Gaussian2D'; | ||
export * from './util/getShape1D'; | ||
export * from './util/getShape2D'; | ||
export * from './util/getShapeData1D'; | ||
export * from './util/getShapeData2D'; | ||
export * from './shapes/1d/gaussian/Gaussian'; | ||
export * from './shapes/1d/lorentzian/Lorentzian'; | ||
export * from './shapes/1d/pseudoVoigt/PseudoVoigt'; | ||
export { Gaussian2D } from './shapes/2d/gaussian2D/Gaussian2D'; | ||
export * from './shapes/1d/getShape1D'; | ||
export * from './shapes/2d/getShape2D'; | ||
export type { Shape1D } from './shapes/1d/Shape1D'; | ||
export type { Shape2D } from './shapes/2d/Shape2D'; | ||
export type { Shape1DClass } from './shapes/1d/Shape1DClass'; | ||
export type { Shape2DClass } from './shapes/2d/Shape2DClass'; | ||
export type { Shape1DInstance } from './shapes/1d/Shape1DInstance'; | ||
export type { Shape2DInstance } from './shapes/2d/Shape2DInstance'; |
@@ -13,15 +13,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Gaussian2D = exports.PseudoVoigt = exports.Lorentzian = exports.Gaussian = void 0; | ||
var Gaussian_1 = require("./shapes/1d/gaussian/Gaussian"); | ||
Object.defineProperty(exports, "Gaussian", { enumerable: true, get: function () { return Gaussian_1.Gaussian; } }); | ||
var Lorentzian_1 = require("./shapes/1d/lorentzian/Lorentzian"); | ||
Object.defineProperty(exports, "Lorentzian", { enumerable: true, get: function () { return Lorentzian_1.Lorentzian; } }); | ||
var PseudoVoigt_1 = require("./shapes/1d/pseudoVoigt/PseudoVoigt"); | ||
Object.defineProperty(exports, "PseudoVoigt", { enumerable: true, get: function () { return PseudoVoigt_1.PseudoVoigt; } }); | ||
exports.Gaussian2D = void 0; | ||
__exportStar(require("./shapes/1d/gaussian/Gaussian"), exports); | ||
__exportStar(require("./shapes/1d/lorentzian/Lorentzian"), exports); | ||
__exportStar(require("./shapes/1d/pseudoVoigt/PseudoVoigt"), exports); | ||
var Gaussian2D_1 = require("./shapes/2d/gaussian2D/Gaussian2D"); | ||
Object.defineProperty(exports, "Gaussian2D", { enumerable: true, get: function () { return Gaussian2D_1.Gaussian2D; } }); | ||
__exportStar(require("./util/getShape1D"), exports); | ||
__exportStar(require("./util/getShape2D"), exports); | ||
__exportStar(require("./util/getShapeData1D"), exports); | ||
__exportStar(require("./util/getShapeData2D"), exports); | ||
__exportStar(require("./shapes/1d/getShape1D"), exports); | ||
__exportStar(require("./shapes/2d/getShape2D"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,15 @@ | ||
import type { DoubleArray } from 'cheminfo-types'; | ||
import type { GetData1DOptions } from '../GetData1DOptions'; | ||
interface ICalculateHeight { | ||
import type { Shape1DClass } from '../Shape1DClass'; | ||
interface CalculateGaussianHeightOptions { | ||
/** | ||
* @default 500 | ||
*/ | ||
fwhm?: number; | ||
/** | ||
* @default 1 | ||
*/ | ||
area?: number; | ||
sd?: number; | ||
} | ||
export interface IGaussianClassOptions { | ||
export interface GaussianClassOptions { | ||
/** | ||
@@ -20,3 +26,3 @@ * Full width at half maximum. | ||
} | ||
export interface IGetAreaGaussianOptions { | ||
interface GetGaussianAreaOptions { | ||
/** | ||
@@ -38,43 +44,4 @@ * The maximum intensity value of the shape. | ||
} | ||
export interface IGaussianClass { | ||
export declare class Gaussian implements Shape1DClass { | ||
/** | ||
* Calculate the height depending of fwhm and area. | ||
*/ | ||
calculateHeight(area?: number): number; | ||
/** | ||
* Return a parameterized function of a gaussian shape (see README for equation). | ||
* @returns - the y value of gaussian with the current parameters. | ||
*/ | ||
fct(x: number): number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @returns fwhm | ||
*/ | ||
widthToFWHM(width: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a gaussian shape. | ||
* @returns Intensity values. | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
} | ||
export declare class Gaussian implements IGaussianClass { | ||
/** | ||
* Full width at half maximum. | ||
@@ -84,3 +51,3 @@ * @default 500 | ||
fwhm: number; | ||
constructor(options?: IGaussianClassOptions); | ||
constructor(options?: GaussianClassOptions); | ||
fwhmToWidth(fwhm?: number): number; | ||
@@ -94,9 +61,9 @@ widthToFWHM(width: number): number; | ||
} | ||
export declare function calculateGaussianHeight(options: ICalculateHeight): number; | ||
export declare function calculateGaussianHeight(options: CalculateGaussianHeightOptions): number; | ||
export declare function gaussianFct(x: number, fwhm: number): number; | ||
export declare function gaussianWidthToFWHM(width: number): number; | ||
export declare function gaussianFwhmToWidth(fwhm: number): number; | ||
export declare function getGaussianArea(options: IGetAreaGaussianOptions): number; | ||
export declare function getGaussianArea(options: GetGaussianAreaOptions): number; | ||
export declare function getGaussianFactor(area?: number): number; | ||
export declare function getGaussianData(shape?: IGaussianClassOptions, options?: GetData1DOptions): Float64Array; | ||
export declare function getGaussianData(shape?: GaussianClassOptions, options?: GetData1DOptions): Float64Array; | ||
export {}; |
@@ -38,3 +38,3 @@ "use strict"; | ||
function calculateGaussianHeight(options) { | ||
let { fwhm = 1, area = 1, sd } = options; | ||
let { fwhm = 500, area = 1, sd } = options; | ||
if (sd) | ||
@@ -58,8 +58,5 @@ fwhm = gaussianWidthToFWHM(2 * sd); | ||
function getGaussianArea(options) { | ||
let { fwhm, sd, height = 1 } = options; | ||
let { fwhm = 500, sd, height = 1 } = options; | ||
if (sd) | ||
fwhm = gaussianWidthToFWHM(2 * sd); | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
return (height * constants_1.ROOT_PI_OVER_LN2 * fwhm) / 2; | ||
@@ -66,0 +63,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { GetData1DOptions } from '../GetData1DOptions'; | ||
export interface ILorentzianClassOptions { | ||
import type { GetData1DOptions } from '../GetData1DOptions'; | ||
import type { Shape1DClass } from '../Shape1DClass'; | ||
export interface LorentzianClassOptions { | ||
/** | ||
@@ -10,3 +10,3 @@ * Full width at half maximum. | ||
} | ||
export interface IGetAreaLorentzianOptions { | ||
interface GetLorentzianAreaOptions { | ||
/** | ||
@@ -23,47 +23,4 @@ * The maximum intensity value of the shape | ||
} | ||
export interface ILorentzianClass { | ||
export declare class Lorentzian implements Shape1DClass { | ||
/** | ||
* Calculate the height depending of fwhm and area. | ||
*/ | ||
calculateHeight(area?: number): number; | ||
/** | ||
* Return a parameterized function of a lorentzian shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param fwhm - full width half maximum | ||
* @returns - the y value of lorentzian with the current parameters. | ||
*/ | ||
fct(x: number): number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/LorentzianFunction.html) | ||
* @param width - Width between the inflection points | ||
* @returns fwhm | ||
*/ | ||
widthToFWHM(width: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/LorentzianFunction.html) | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
* @returns | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a lorentzian shape. | ||
* @returns y values | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
} | ||
export declare class Lorentzian implements ILorentzianClass { | ||
/** | ||
* Full width at half maximum. | ||
@@ -73,3 +30,3 @@ * @default 500 | ||
fwhm: number; | ||
constructor(options?: ILorentzianClassOptions); | ||
constructor(options?: LorentzianClassOptions); | ||
fwhmToWidth(fwhm?: number): number; | ||
@@ -90,4 +47,5 @@ widthToFWHM(width: number): number; | ||
export declare const lorentzianFwhmToWidth: (fwhm: number) => number; | ||
export declare const getLorentzianArea: (options: IGetAreaLorentzianOptions) => number; | ||
export declare const getLorentzianArea: (options: GetLorentzianAreaOptions) => number; | ||
export declare const getLorentzianFactor: (area?: number) => number; | ||
export declare const getLorentzianData: (shape?: ILorentzianClassOptions, options?: GetData1DOptions) => Float64Array; | ||
export declare const getLorentzianData: (shape?: LorentzianClassOptions, options?: GetData1DOptions) => Float64Array; | ||
export {}; |
@@ -50,6 +50,3 @@ "use strict"; | ||
const getLorentzianArea = (options) => { | ||
const { fwhm, height = 1 } = options; | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
const { fwhm = 500, height = 1 } = options; | ||
return (height * Math.PI * fwhm) / 2; | ||
@@ -56,0 +53,0 @@ }; |
@@ -1,4 +0,4 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { GetData1DOptions } from '../GetData1DOptions'; | ||
export interface IPseudoVoigtClassOptions { | ||
import { Shape1DClass } from '../Shape1DClass'; | ||
export interface PseudoVoigtClassOptions { | ||
/** | ||
@@ -15,3 +15,3 @@ * Full width at half maximum. | ||
} | ||
export interface IGetAreaPseudoVoigtOptions { | ||
interface GetPseudoVoigtAreaOptions { | ||
/** | ||
@@ -33,55 +33,17 @@ * The maximum intensity value of the shape | ||
} | ||
interface ICalculateHeightOptions { | ||
fwhm: number; | ||
mu: number; | ||
area: number; | ||
} | ||
export interface IPseudoVoigtClass { | ||
interface CalculatePseudoVoightHeightOptions { | ||
/** | ||
* Calculate the height depending of fwhm, mu and area. | ||
* @default 1 | ||
*/ | ||
calculateHeight(area?: number): number; | ||
fwhm?: number; | ||
/** | ||
* Return a parameterized function of a pseudo voigt shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param fwhm - full width half maximum | ||
* @returns - the y value of pseudo voigt with the current parameters. | ||
* @default 0.5 | ||
*/ | ||
fct(x: number): number; | ||
mu?: number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* @param width - Width between the inflection points | ||
* @param [mu=0.5] Ratio of gaussian contribution in the shape | ||
* @returns fwhm | ||
* @default 1 | ||
*/ | ||
widthToFWHM(width: number, mu?: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @param [mu=0.5] Ratio of gaussian contribution in the shape | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number, mu?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
* @returns | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a pseudo voigt shape. | ||
* @returns y values | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
area?: number; | ||
} | ||
export declare class PseudoVoigt implements IPseudoVoigtClass { | ||
/** | ||
* Full width at half maximum. | ||
* @default 500 | ||
*/ | ||
export declare class PseudoVoigt implements Shape1DClass { | ||
fwhm: number; | ||
@@ -93,3 +55,3 @@ /** | ||
mu: number; | ||
constructor(options?: IPseudoVoigtClassOptions); | ||
constructor(options?: PseudoVoigtClassOptions); | ||
fwhmToWidth(fwhm?: number, mu?: number): number; | ||
@@ -103,9 +65,9 @@ widthToFWHM(width: number, mu?: number): number; | ||
} | ||
export declare const calculatePseudoVoigtHeight: (options: ICalculateHeightOptions) => number; | ||
export declare const calculatePseudoVoigtHeight: (options?: CalculatePseudoVoightHeightOptions) => number; | ||
export declare const pseudoVoigtFct: (x: number, fwhm: number, mu: number) => number; | ||
export declare const pseudoVoigtWidthToFWHM: (width: number, mu?: number) => number; | ||
export declare const pseudoVoigtFwhmToWidth: (fwhm: number, mu?: number) => number; | ||
export declare const getPseudoVoigtArea: (options: IGetAreaPseudoVoigtOptions) => number; | ||
export declare const getPseudoVoigtArea: (options: GetPseudoVoigtAreaOptions) => number; | ||
export declare const getPseudoVoigtFactor: (area?: number, mu?: number) => number; | ||
export declare const getPseudoVoigtData: (shape?: IPseudoVoigtClassOptions, options?: GetData1DOptions) => Float64Array; | ||
export declare const getPseudoVoigtData: (shape?: PseudoVoigtClassOptions, options?: GetData1DOptions) => Float64Array; | ||
export {}; |
@@ -41,3 +41,3 @@ "use strict"; | ||
exports.PseudoVoigt = PseudoVoigt; | ||
const calculatePseudoVoigtHeight = (options) => { | ||
const calculatePseudoVoigtHeight = (options = {}) => { | ||
let { fwhm = 1, mu = 0.5, area = 1 } = options; | ||
@@ -60,6 +60,3 @@ return (2 * area) / (fwhm * (mu * constants_1.ROOT_PI_OVER_LN2 + (1 - mu) * Math.PI)); | ||
const getPseudoVoigtArea = (options) => { | ||
const { fwhm, height = 1, mu = 0.5 } = options; | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
const { fwhm = 500, height = 1, mu = 0.5 } = options; | ||
return (fwhm * height * (mu * constants_1.ROOT_PI_OVER_LN2 + (1 - mu) * Math.PI)) / 2; | ||
@@ -66,0 +63,0 @@ }; |
@@ -1,17 +0,17 @@ | ||
import type { IGaussianClassOptions } from './gaussian/Gaussian'; | ||
import type { ILorentzianClassOptions } from './lorentzian/Lorentzian'; | ||
import type { IPseudoVoigtClassOptions } from './pseudoVoigt/PseudoVoigt'; | ||
import type { GaussianClassOptions } from './gaussian/Gaussian'; | ||
import type { LorentzianClassOptions } from './lorentzian/Lorentzian'; | ||
import type { PseudoVoigtClassOptions } from './pseudoVoigt/PseudoVoigt'; | ||
/** | ||
* kind of shape | ||
*/ | ||
interface IGaussianShape1D extends IGaussianClassOptions { | ||
interface GaussianShape1D extends GaussianClassOptions { | ||
kind: 'gaussian'; | ||
} | ||
interface ILorentzianShape1D extends ILorentzianClassOptions { | ||
interface LorentzianShape1D extends LorentzianClassOptions { | ||
kind: 'lorentzian'; | ||
} | ||
interface IPseudoVoigtShape1D extends IPseudoVoigtClassOptions { | ||
interface PseudoVoigtShape1D extends PseudoVoigtClassOptions { | ||
kind: 'pseudoVoigt'; | ||
} | ||
export declare type Shape1D = IGaussianShape1D | ILorentzianShape1D | IPseudoVoigtShape1D; | ||
export declare type Shape1D = GaussianShape1D | LorentzianShape1D | PseudoVoigtShape1D; | ||
export {}; |
@@ -1,4 +0,42 @@ | ||
import type { Gaussian } from './gaussian/Gaussian'; | ||
import type { Lorentzian } from './lorentzian/Lorentzian'; | ||
import type { PseudoVoigt } from './pseudoVoigt/PseudoVoigt'; | ||
export declare type Shape1DClass = Gaussian | PseudoVoigt | Lorentzian; | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { GetData1DOptions } from './GetData1DOptions'; | ||
export interface Shape1DClass { | ||
fwhm: number; | ||
/** | ||
* Calculate the height depending of fwhm and area. | ||
*/ | ||
calculateHeight(area?: number): number; | ||
/** | ||
* Return a parameterized function of a gaussian shape (see README for equation). | ||
* @returns - the y value of gaussian with the current parameters. | ||
*/ | ||
fct(x: number): number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @returns fwhm | ||
*/ | ||
widthToFWHM(width: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a gaussian shape. | ||
* @returns Intensity values. | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
} |
@@ -1,3 +0,3 @@ | ||
import type { DoubleArray } from 'cheminfo-types'; | ||
import type { GetData2DOptions } from '../GetData2DOptions'; | ||
import { Shape2DClass } from '../Shape2DClass'; | ||
export interface XYNumber { | ||
@@ -7,8 +7,14 @@ x: number; | ||
} | ||
interface ICalculateHeightGaussian2D { | ||
interface CalculateGaussian2DHeightOptions { | ||
sd?: number | XYNumber; | ||
/** | ||
* @default 50 | ||
*/ | ||
fwhm?: number | XYNumber; | ||
/** | ||
* @default 1 | ||
*/ | ||
volume?: number; | ||
} | ||
export interface IGaussian2DClassOptions { | ||
export interface Gaussian2DClassOptions { | ||
/** | ||
@@ -30,3 +36,3 @@ * Full width at half maximum. | ||
*/ | ||
export interface IGetVolumeGaussian2DOptions { | ||
export interface GetGaussian2DVolumeOptions { | ||
/** | ||
@@ -40,2 +46,3 @@ * The maximum intensity value of the shape | ||
* Could specify the value for each axis by a xy object or both by a number. | ||
* @default 50 | ||
*/ | ||
@@ -49,32 +56,6 @@ fwhm?: number | XYNumber; | ||
} | ||
export interface IGaussian2DClass { | ||
calculateHeight(volume?: number): number; | ||
/** | ||
* Return a parameterized function of a Gaussian2D shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param y - y value to calculate. | ||
* @param fwhmX - full width half maximum in the x axis. | ||
* @param fwhmY - full width half maximum in the y axis. | ||
* @returns - the z value of bi-dimensional gaussian with the current parameters. | ||
*/ | ||
fct(x: number, y: number): number; | ||
widthToFWHM(width: number): number; | ||
fwhmToWidth(fwhm?: number): number; | ||
getVolume(height?: number): number; | ||
getFactor(volume?: number): number; | ||
/** | ||
* Calculate the intensity matrix of a gaussian shape. | ||
* @returns z values. | ||
*/ | ||
getData(options?: GetData2DOptions): DoubleArray[]; | ||
} | ||
export declare class Gaussian2D implements IGaussian2DClass { | ||
/** | ||
* Full width at half maximum. | ||
* Could specify the value for each axis by a xy object or both by a number. | ||
* @default 50 | ||
*/ | ||
export declare class Gaussian2D implements Shape2DClass { | ||
fwhmX: number; | ||
fwhmY: number; | ||
constructor(options?: IGaussian2DClassOptions); | ||
constructor(options?: Gaussian2DClassOptions); | ||
fct(x: number, y: number): number; | ||
@@ -90,5 +71,5 @@ getData(options?: GetData2DOptions): any[]; | ||
export declare const gaussian2DFct: (x: number, y: number, xFWHM: number, yFWHM: number) => number; | ||
export declare const getGaussian2DData: (shape: IGaussian2DClassOptions, options?: GetData2DOptions) => any[]; | ||
export declare const calculateGaussian2DHeight: (options?: ICalculateHeightGaussian2D) => number; | ||
export declare const getGaussian2DVolume: (options?: IGetVolumeGaussian2DOptions) => number; | ||
export declare const getGaussian2DData: (shape: Gaussian2DClassOptions, options?: GetData2DOptions) => any[]; | ||
export declare const calculateGaussian2DHeight: (options?: CalculateGaussian2DHeightOptions) => number; | ||
export declare const getGaussian2DVolume: (options?: GetGaussian2DVolumeOptions) => number; | ||
export {}; |
@@ -7,6 +7,2 @@ "use strict"; | ||
class Gaussian2D { | ||
// /** | ||
// * The maximum z value of the shape, default keep surface equal 1. | ||
// */ | ||
// public height: number; | ||
constructor(options = {}) { | ||
@@ -90,3 +86,3 @@ let { fwhm = 50, sd } = options; | ||
const calculateGaussian2DHeight = (options = {}) => { | ||
let { volume = 1, fwhm = 1, sd } = options; | ||
let { volume = 1, fwhm = 50, sd } = options; | ||
fwhm = ensureFWHM2D(fwhm, sd); | ||
@@ -93,0 +89,0 @@ return (volume * Math.LN2 * 4) / (Math.PI * fwhm.y * fwhm.x); |
@@ -1,6 +0,6 @@ | ||
import type { IGaussian2DClassOptions } from './gaussian2D/Gaussian2D'; | ||
import type { Gaussian2DClassOptions } from './gaussian2D/Gaussian2D'; | ||
/** | ||
* kind of shape | ||
*/ | ||
interface IGaussianShape2D extends IGaussian2DClassOptions { | ||
interface IGaussianShape2D extends Gaussian2DClassOptions { | ||
kind: 'gaussian'; | ||
@@ -7,0 +7,0 @@ } |
@@ -1,2 +0,38 @@ | ||
import type { Gaussian2D } from './gaussian2D/Gaussian2D'; | ||
export declare type Shape2DClass = Gaussian2D; | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { GetData2DOptions } from './GetData2DOptions'; | ||
import { XYNumber } from './XYNumber'; | ||
export interface Shape2DClass { | ||
/** | ||
* Full width at half maximum. | ||
* Could specify the value for each axis by a xy object or both by a number. | ||
* @default 50 | ||
*/ | ||
fwhmX: number; | ||
fwhmY: number; | ||
/** | ||
* setter to parameters fwhmX and fwhmY | ||
*/ | ||
fwhm: number | XYNumber; | ||
/** | ||
* Calculate the height depending of fwhm and volumen. | ||
*/ | ||
calculateHeight(volume?: number): number; | ||
/** | ||
* Return a parameterized function of a Gaussian2D shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param y - y value to calculate. | ||
* @param fwhmX - full width half maximum in the x axis. | ||
* @param fwhmY - full width half maximum in the y axis. | ||
* @returns - the z value of bi-dimensional gaussian with the current parameters. | ||
*/ | ||
fct(x: number, y: number): number; | ||
widthToFWHM(width: number): number; | ||
fwhmToWidth(fwhm?: number): number; | ||
getVolume(height?: number): number; | ||
getFactor(volume?: number): number; | ||
/** | ||
* Calculate the intensity matrix of a gaussian shape. | ||
* @returns z values. | ||
*/ | ||
getData(options?: GetData2DOptions): DoubleArray[]; | ||
} |
{ | ||
"name": "ml-peak-shape-generator", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"description": "Generate various peak shapes", | ||
@@ -26,3 +26,2 @@ "main": "./lib/index.js", | ||
"scripts": { | ||
"build": "npm run tsc && cheminfo-build", | ||
"check-types": "tsc --noEmit", | ||
@@ -62,11 +61,11 @@ "clean": "rimraf lib lib-esm", | ||
"devDependencies": { | ||
"@types/jest": "^27.0.2", | ||
"@types/jest": "^27.0.3", | ||
"compute-erfinv": "^3.0.1", | ||
"eslint": "^8.2.0", | ||
"eslint-config-cheminfo-typescript": "^10.2.2", | ||
"jest": "^27.0.6", | ||
"prettier": "^2.3.2", | ||
"eslint": "^8.3.0", | ||
"eslint-config-cheminfo-typescript": "^10.2.4", | ||
"jest": "^27.3.1", | ||
"prettier": "^2.5.0", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.0.4", | ||
"typescript": "^4.4.4" | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.5.2" | ||
}, | ||
@@ -73,0 +72,0 @@ "dependencies": { |
@@ -1,14 +0,12 @@ | ||
export { Gaussian } from './shapes/1d/gaussian/Gaussian'; | ||
export { Lorentzian } from './shapes/1d/lorentzian/Lorentzian'; | ||
export { PseudoVoigt } from './shapes/1d/pseudoVoigt/PseudoVoigt'; | ||
export { Gaussian2D, XYNumber } from './shapes/2d/gaussian2D/Gaussian2D'; | ||
export * from './shapes/1d/gaussian/Gaussian'; | ||
export * from './shapes/1d/lorentzian/Lorentzian'; | ||
export * from './shapes/1d/pseudoVoigt/PseudoVoigt'; | ||
export { Gaussian2D } from './shapes/2d/gaussian2D/Gaussian2D'; | ||
export * from './util/getShape1D'; | ||
export * from './util/getShape2D'; | ||
export * from './util/getShapeData1D'; | ||
export * from './util/getShapeData2D'; | ||
export * from './shapes/1d/getShape1D'; | ||
export * from './shapes/2d/getShape2D'; | ||
export type { Shape1D } from './shapes/1d/Shape1D'; | ||
export type { Shape2D } from './shapes/2d/Shape2D'; | ||
export type { Shape1DClass } from './shapes/1d/Shape1DClass'; | ||
export type { Shape2DClass } from './shapes/2d/Shape2DClass'; | ||
export type { Shape1DInstance } from './shapes/1d/Shape1DInstance'; | ||
export type { Shape2DInstance } from './shapes/2d/Shape2DInstance'; |
@@ -1,3 +0,1 @@ | ||
import type { DoubleArray } from 'cheminfo-types'; | ||
import { | ||
@@ -10,5 +8,12 @@ ROOT_2LN2, | ||
import type { GetData1DOptions } from '../GetData1DOptions'; | ||
import type { Shape1DClass } from '../Shape1DClass'; | ||
interface ICalculateHeight { | ||
interface CalculateGaussianHeightOptions { | ||
/** | ||
* @default 500 | ||
*/ | ||
fwhm?: number; | ||
/** | ||
* @default 1 | ||
*/ | ||
area?: number; | ||
@@ -18,3 +23,3 @@ sd?: number; | ||
export interface IGaussianClassOptions { | ||
export interface GaussianClassOptions { | ||
/** | ||
@@ -32,3 +37,3 @@ * Full width at half maximum. | ||
export interface IGetAreaGaussianOptions { | ||
interface GetGaussianAreaOptions { | ||
/** | ||
@@ -51,44 +56,4 @@ * The maximum intensity value of the shape. | ||
export interface IGaussianClass { | ||
export class Gaussian implements Shape1DClass { | ||
/** | ||
* Calculate the height depending of fwhm and area. | ||
*/ | ||
calculateHeight(area?: number): number; | ||
/** | ||
* Return a parameterized function of a gaussian shape (see README for equation). | ||
* @returns - the y value of gaussian with the current parameters. | ||
*/ | ||
fct(x: number): number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @returns fwhm | ||
*/ | ||
widthToFWHM(width: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a gaussian shape. | ||
* @returns Intensity values. | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
} | ||
export class Gaussian implements IGaussianClass { | ||
/** | ||
* Full width at half maximum. | ||
@@ -99,3 +64,3 @@ * @default 500 | ||
public constructor(options: IGaussianClassOptions = {}) { | ||
public constructor(options: GaussianClassOptions = {}) { | ||
const { fwhm = 500, sd } = options; | ||
@@ -135,4 +100,6 @@ | ||
export function calculateGaussianHeight(options: ICalculateHeight) { | ||
let { fwhm = 1, area = 1, sd } = options; | ||
export function calculateGaussianHeight( | ||
options: CalculateGaussianHeightOptions, | ||
) { | ||
let { fwhm = 500, area = 1, sd } = options; | ||
@@ -156,11 +123,7 @@ if (sd) fwhm = gaussianWidthToFWHM(2 * sd); | ||
export function getGaussianArea(options: IGetAreaGaussianOptions) { | ||
let { fwhm, sd, height = 1 } = options; | ||
export function getGaussianArea(options: GetGaussianAreaOptions) { | ||
let { fwhm = 500, sd, height = 1 } = options; | ||
if (sd) fwhm = gaussianWidthToFWHM(2 * sd); | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
return (height * ROOT_PI_OVER_LN2 * fwhm) / 2; | ||
@@ -174,3 +137,3 @@ } | ||
export function getGaussianData( | ||
shape: IGaussianClassOptions = {}, | ||
shape: GaussianClassOptions = {}, | ||
options: GetData1DOptions = {}, | ||
@@ -177,0 +140,0 @@ ) { |
@@ -1,7 +0,6 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { ROOT_THREE } from '../../../util/constants'; | ||
import { GetData1DOptions } from '../GetData1DOptions'; | ||
import type { GetData1DOptions } from '../GetData1DOptions'; | ||
import type { Shape1DClass } from '../Shape1DClass'; | ||
export interface ILorentzianClassOptions { | ||
export interface LorentzianClassOptions { | ||
/** | ||
@@ -14,3 +13,3 @@ * Full width at half maximum. | ||
export interface IGetAreaLorentzianOptions { | ||
interface GetLorentzianAreaOptions { | ||
/** | ||
@@ -28,48 +27,4 @@ * The maximum intensity value of the shape | ||
export interface ILorentzianClass { | ||
export class Lorentzian implements Shape1DClass { | ||
/** | ||
* Calculate the height depending of fwhm and area. | ||
*/ | ||
calculateHeight(area?: number): number; | ||
/** | ||
* Return a parameterized function of a lorentzian shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param fwhm - full width half maximum | ||
* @returns - the y value of lorentzian with the current parameters. | ||
*/ | ||
fct(x: number): number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/LorentzianFunction.html) | ||
* @param width - Width between the inflection points | ||
* @returns fwhm | ||
*/ | ||
widthToFWHM(width: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/LorentzianFunction.html) | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
* @returns | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a lorentzian shape. | ||
* @returns y values | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
} | ||
export class Lorentzian implements ILorentzianClass { | ||
/** | ||
* Full width at half maximum. | ||
@@ -80,3 +35,3 @@ * @default 500 | ||
public constructor(options: ILorentzianClassOptions = {}) { | ||
public constructor(options: LorentzianClassOptions = {}) { | ||
const { fwhm = 500 } = options; | ||
@@ -132,9 +87,4 @@ | ||
export const getLorentzianArea = (options: IGetAreaLorentzianOptions) => { | ||
const { fwhm, height = 1 } = options; | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
export const getLorentzianArea = (options: GetLorentzianAreaOptions) => { | ||
const { fwhm = 500, height = 1 } = options; | ||
return (height * Math.PI * fwhm) / 2; | ||
@@ -148,3 +98,3 @@ }; | ||
export const getLorentzianData = ( | ||
shape: ILorentzianClassOptions = {}, | ||
shape: LorentzianClassOptions = {}, | ||
options: GetData1DOptions = {}, | ||
@@ -151,0 +101,0 @@ ) => { |
@@ -1,3 +0,1 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { | ||
@@ -9,6 +7,7 @@ GAUSSIAN_EXP_FACTOR, | ||
import { GetData1DOptions } from '../GetData1DOptions'; | ||
import { Shape1DClass } from '../Shape1DClass'; | ||
import { gaussianFct, getGaussianFactor } from '../gaussian/Gaussian'; | ||
import { lorentzianFct, getLorentzianFactor } from '../lorentzian/Lorentzian'; | ||
export interface IPseudoVoigtClassOptions { | ||
export interface PseudoVoigtClassOptions { | ||
/** | ||
@@ -26,3 +25,3 @@ * Full width at half maximum. | ||
export interface IGetAreaPseudoVoigtOptions { | ||
interface GetPseudoVoigtAreaOptions { | ||
/** | ||
@@ -45,57 +44,18 @@ * The maximum intensity value of the shape | ||
interface ICalculateHeightOptions { | ||
fwhm: number; | ||
mu: number; | ||
area: number; | ||
} | ||
export interface IPseudoVoigtClass { | ||
interface CalculatePseudoVoightHeightOptions { | ||
/** | ||
* Calculate the height depending of fwhm, mu and area. | ||
* @default 1 | ||
*/ | ||
calculateHeight(area?: number): number; | ||
fwhm?: number; | ||
/** | ||
* Return a parameterized function of a pseudo voigt shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param fwhm - full width half maximum | ||
* @returns - the y value of pseudo voigt with the current parameters. | ||
* @default 0.5 | ||
*/ | ||
fct(x: number): number; | ||
mu?: number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* @param width - Width between the inflection points | ||
* @param [mu=0.5] Ratio of gaussian contribution in the shape | ||
* @returns fwhm | ||
* @default 1 | ||
*/ | ||
widthToFWHM(width: number, mu?: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @param [mu=0.5] Ratio of gaussian contribution in the shape | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number, mu?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
* @returns | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a pseudo voigt shape. | ||
* @returns y values | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
area?: number; | ||
} | ||
export class PseudoVoigt implements IPseudoVoigtClass { | ||
/** | ||
* Full width at half maximum. | ||
* @default 500 | ||
*/ | ||
export class PseudoVoigt implements Shape1DClass { | ||
public fwhm: number; | ||
@@ -108,3 +68,3 @@ /** | ||
public constructor(options: IPseudoVoigtClassOptions = {}) { | ||
public constructor(options: PseudoVoigtClassOptions = {}) { | ||
const { fwhm = 500, mu = 0.5 } = options; | ||
@@ -155,3 +115,3 @@ | ||
export const calculatePseudoVoigtHeight = ( | ||
options: ICalculateHeightOptions, | ||
options: CalculatePseudoVoightHeightOptions = {}, | ||
) => { | ||
@@ -174,8 +134,4 @@ let { fwhm = 1, mu = 0.5, area = 1 } = options; | ||
export const getPseudoVoigtArea = (options: IGetAreaPseudoVoigtOptions) => { | ||
const { fwhm, height = 1, mu = 0.5 } = options; | ||
if (fwhm === undefined) { | ||
throw new Error('should pass fwhm or sd parameters'); | ||
} | ||
export const getPseudoVoigtArea = (options: GetPseudoVoigtAreaOptions) => { | ||
const { fwhm = 500, height = 1, mu = 0.5 } = options; | ||
return (fwhm * height * (mu * ROOT_PI_OVER_LN2 + (1 - mu) * Math.PI)) / 2; | ||
@@ -189,3 +145,3 @@ }; | ||
export const getPseudoVoigtData = ( | ||
shape: IPseudoVoigtClassOptions = {}, | ||
shape: PseudoVoigtClassOptions = {}, | ||
options: GetData1DOptions = {}, | ||
@@ -192,0 +148,0 @@ ) => { |
@@ -1,4 +0,4 @@ | ||
import type { IGaussianClassOptions } from './gaussian/Gaussian'; | ||
import type { ILorentzianClassOptions } from './lorentzian/Lorentzian'; | ||
import type { IPseudoVoigtClassOptions } from './pseudoVoigt/PseudoVoigt'; | ||
import type { GaussianClassOptions } from './gaussian/Gaussian'; | ||
import type { LorentzianClassOptions } from './lorentzian/Lorentzian'; | ||
import type { PseudoVoigtClassOptions } from './pseudoVoigt/PseudoVoigt'; | ||
@@ -8,16 +8,14 @@ /** | ||
*/ | ||
interface IGaussianShape1D extends IGaussianClassOptions { | ||
interface GaussianShape1D extends GaussianClassOptions { | ||
kind: 'gaussian'; | ||
} | ||
interface ILorentzianShape1D extends ILorentzianClassOptions { | ||
interface LorentzianShape1D extends LorentzianClassOptions { | ||
kind: 'lorentzian'; | ||
} | ||
interface IPseudoVoigtShape1D extends IPseudoVoigtClassOptions { | ||
interface PseudoVoigtShape1D extends PseudoVoigtClassOptions { | ||
kind: 'pseudoVoigt'; | ||
} | ||
export type Shape1D = | ||
| IGaussianShape1D | ||
| ILorentzianShape1D | ||
| IPseudoVoigtShape1D; | ||
export type Shape1D = GaussianShape1D | LorentzianShape1D | PseudoVoigtShape1D; |
@@ -1,5 +0,44 @@ | ||
import type { Gaussian } from './gaussian/Gaussian'; | ||
import type { Lorentzian } from './lorentzian/Lorentzian'; | ||
import type { PseudoVoigt } from './pseudoVoigt/PseudoVoigt'; | ||
import { DoubleArray } from 'cheminfo-types'; | ||
export type Shape1DClass = Gaussian | PseudoVoigt | Lorentzian; | ||
import { GetData1DOptions } from './GetData1DOptions'; | ||
export interface Shape1DClass { | ||
fwhm: number; | ||
/** | ||
* Calculate the height depending of fwhm and area. | ||
*/ | ||
calculateHeight(area?: number): number; | ||
/** | ||
* Return a parameterized function of a gaussian shape (see README for equation). | ||
* @returns - the y value of gaussian with the current parameters. | ||
*/ | ||
fct(x: number): number; | ||
/** | ||
* Compute the value of Full Width at Half Maximum (FWHM) from the width between the inflection points. | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @returns fwhm | ||
*/ | ||
widthToFWHM(width: number): number; | ||
/** | ||
* Compute the value of width between the inflection points from Full Width at Half Maximum (FWHM). | ||
* for more information check the [mathworld page](https://mathworld.wolfram.com/GaussianFunction.html) | ||
* @param fwhm - Full Width at Half Maximum. | ||
* @returns width | ||
*/ | ||
fwhmToWidth(fwhm?: number): number; | ||
/** | ||
* Calculate the area of a specific shape. | ||
* @returns returns the area of the specific shape and parameters. | ||
*/ | ||
getArea(height?: number): number; | ||
/** | ||
* Calculate the number of times FWHM allows to reach a specific area coverage. | ||
* @param [area=0.9999] Expected area to be covered. | ||
*/ | ||
getFactor(area?: number): number; | ||
/** | ||
* Calculate intensity array of a gaussian shape. | ||
* @returns Intensity values. | ||
*/ | ||
getData(options?: GetData1DOptions): DoubleArray; | ||
} |
@@ -1,3 +0,1 @@ | ||
import type { DoubleArray } from 'cheminfo-types'; | ||
import { GAUSSIAN_EXP_FACTOR } from '../../../util/constants'; | ||
@@ -10,2 +8,3 @@ import { | ||
import type { GetData2DOptions } from '../GetData2DOptions'; | ||
import { Shape2DClass } from '../Shape2DClass'; | ||
@@ -17,9 +16,15 @@ export interface XYNumber { | ||
interface ICalculateHeightGaussian2D { | ||
interface CalculateGaussian2DHeightOptions { | ||
sd?: number | XYNumber; | ||
/** | ||
* @default 50 | ||
*/ | ||
fwhm?: number | XYNumber; | ||
/** | ||
* @default 1 | ||
*/ | ||
volume?: number; | ||
} | ||
export interface IGaussian2DClassOptions { | ||
export interface Gaussian2DClassOptions { | ||
/** | ||
@@ -42,3 +47,3 @@ * Full width at half maximum. | ||
*/ | ||
export interface IGetVolumeGaussian2DOptions { | ||
export interface GetGaussian2DVolumeOptions { | ||
/** | ||
@@ -52,2 +57,3 @@ * The maximum intensity value of the shape | ||
* Could specify the value for each axis by a xy object or both by a number. | ||
* @default 50 | ||
*/ | ||
@@ -62,38 +68,7 @@ fwhm?: number | XYNumber; | ||
export interface IGaussian2DClass { | ||
calculateHeight(volume?: number): number; | ||
/** | ||
* Return a parameterized function of a Gaussian2D shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param y - y value to calculate. | ||
* @param fwhmX - full width half maximum in the x axis. | ||
* @param fwhmY - full width half maximum in the y axis. | ||
* @returns - the z value of bi-dimensional gaussian with the current parameters. | ||
*/ | ||
fct(x: number, y: number): number; | ||
widthToFWHM(width: number): number; | ||
fwhmToWidth(fwhm?: number): number; | ||
getVolume(height?: number): number; | ||
getFactor(volume?: number): number; | ||
/** | ||
* Calculate the intensity matrix of a gaussian shape. | ||
* @returns z values. | ||
*/ | ||
getData(options?: GetData2DOptions): DoubleArray[]; | ||
} | ||
export class Gaussian2D implements IGaussian2DClass { | ||
/** | ||
* Full width at half maximum. | ||
* Could specify the value for each axis by a xy object or both by a number. | ||
* @default 50 | ||
*/ | ||
export class Gaussian2D implements Shape2DClass { | ||
public fwhmX: number; | ||
public fwhmY: number; | ||
// /** | ||
// * The maximum z value of the shape, default keep surface equal 1. | ||
// */ | ||
// public height: number; | ||
public constructor(options: IGaussian2DClassOptions = {}) { | ||
public constructor(options: Gaussian2DClassOptions = {}) { | ||
let { fwhm = 50, sd } = options; | ||
@@ -170,3 +145,3 @@ | ||
export const getGaussian2DData = ( | ||
shape: IGaussian2DClassOptions, | ||
shape: Gaussian2DClassOptions, | ||
options: GetData2DOptions = {}, | ||
@@ -214,5 +189,5 @@ ) => { | ||
export const calculateGaussian2DHeight = ( | ||
options: ICalculateHeightGaussian2D = {}, | ||
options: CalculateGaussian2DHeightOptions = {}, | ||
) => { | ||
let { volume = 1, fwhm = 1, sd } = options; | ||
let { volume = 1, fwhm = 50, sd } = options; | ||
fwhm = ensureFWHM2D(fwhm, sd); | ||
@@ -223,3 +198,3 @@ return (volume * Math.LN2 * 4) / (Math.PI * fwhm.y * fwhm.x); | ||
export const getGaussian2DVolume = ( | ||
options: IGetVolumeGaussian2DOptions = {}, | ||
options: GetGaussian2DVolumeOptions = {}, | ||
) => { | ||
@@ -226,0 +201,0 @@ let { fwhm = 50, height = 1, sd } = options; |
@@ -1,2 +0,2 @@ | ||
import type { IGaussian2DClassOptions } from './gaussian2D/Gaussian2D'; | ||
import type { Gaussian2DClassOptions } from './gaussian2D/Gaussian2D'; | ||
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
interface IGaussianShape2D extends IGaussian2DClassOptions { | ||
interface IGaussianShape2D extends Gaussian2DClassOptions { | ||
kind: 'gaussian'; | ||
@@ -9,0 +9,0 @@ } |
@@ -1,3 +0,40 @@ | ||
import type { Gaussian2D } from './gaussian2D/Gaussian2D'; | ||
import { DoubleArray } from 'cheminfo-types'; | ||
export type Shape2DClass = Gaussian2D; | ||
import { GetData2DOptions } from './GetData2DOptions'; | ||
import { XYNumber } from './XYNumber'; | ||
export interface Shape2DClass { | ||
/** | ||
* Full width at half maximum. | ||
* Could specify the value for each axis by a xy object or both by a number. | ||
* @default 50 | ||
*/ | ||
fwhmX: number; | ||
fwhmY: number; | ||
/** | ||
* setter to parameters fwhmX and fwhmY | ||
*/ | ||
fwhm: number | XYNumber; | ||
/** | ||
* Calculate the height depending of fwhm and volumen. | ||
*/ | ||
calculateHeight(volume?: number): number; | ||
/** | ||
* Return a parameterized function of a Gaussian2D shape (see README for equation). | ||
* @param x - x value to calculate. | ||
* @param y - y value to calculate. | ||
* @param fwhmX - full width half maximum in the x axis. | ||
* @param fwhmY - full width half maximum in the y axis. | ||
* @returns - the z value of bi-dimensional gaussian with the current parameters. | ||
*/ | ||
fct(x: number, y: number): number; | ||
widthToFWHM(width: number): number; | ||
fwhmToWidth(fwhm?: number): number; | ||
getVolume(height?: number): number; | ||
getFactor(volume?: number): number; | ||
/** | ||
* Calculate the intensity matrix of a gaussian shape. | ||
* @returns z values. | ||
*/ | ||
getData(options?: GetData2DOptions): DoubleArray[]; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127588
119
2071