Skip to content

Commit

Permalink
FWHM-fwhm-generalized-lorentzian (#77)
Browse files Browse the repository at this point in the history
* fix: FWHM in generalized lorentzian

* chore: reduce the number of calculated points for test case

* chore: fix eslint
  • Loading branch information
jobo322 authored Sep 25, 2024
1 parent 18c4e52 commit 143a44b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/shapes/1d/generalizedLorentzian/GeneralizedLorentzian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const calculateGeneralizedLorentzianHeight = ({
gamma = 1,
area = 1,
}) => {
return area / fwhm / (3.14159 - 0.420894 * gamma) / 2;
return (area / fwhm / (3.14159 - 0.420894 * gamma)) * 2;
};

/**
Expand All @@ -102,15 +102,15 @@ export const getGeneralizedLorentzianArea = (
options: GetGeneralizedLorentzianAreaOptions,
) => {
const { fwhm = 500, height = 1, gamma = 1 } = options;
return 2 * height * fwhm * (3.14159 - 0.420894 * gamma);
return (height * fwhm * (3.14159 - 0.420894 * gamma)) / 2;
};

export const generalizedLorentzianFct = (
x: number,
fwhm: number,
gamma: number,
) => {
const u = (x / 2 / fwhm) ** 2;
const u = ((2 * x) / fwhm) ** 2;
return (1 - gamma) / (1 + u) + (gamma * (1 + u / 2)) / (1 + u + u ** 2);
};

Expand Down Expand Up @@ -145,7 +145,7 @@ export const getGeneralizedLorentzianData = (
let {
length,
factor = getGeneralizedLorentzianFactor(),
height = 1,
height = calculateGeneralizedLorentzianHeight({ fwhm, area: 1, gamma }),
} = options;

if (!length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { GeneralizedLorentzian } from '../GeneralizedLorentzian';

describe('lorentzian', () => {
it('default factor area', () => {
const lorentzian = new GeneralizedLorentzian({ fwhm: 1.5, gamma: -1 });
const lorentzian = new GeneralizedLorentzian({ fwhm: 3, gamma: 2 });
const data = lorentzian.getData({
length: 256,
height: lorentzian.calculateHeight(),
});

const area = data.reduce((a, b) => a + b, 0);
expect(area).toBeCloseTo(1);

const data2 = lorentzian.getData({
height: lorentzian.calculateHeight(2),
});
Expand Down

0 comments on commit 143a44b

Please sign in to comment.