Gaussian(3pm)

πŸ’– PDL::Fit::Gaussian β€” the perl manpage, but make it a group chat πŸ’–

okay bestie, gather round, because this is Gaussian(3pm) from the User Contributed Perl Documentation and it's about to be your new hyperfixation. we're talking gaussian fitting routines and we're talking them loudly. πŸ¦‹


✨ NAME ✨

PDL::Fit::Gaussian β€” routines for fitting gaussians πŸ’…


🌸 DESCRIPTION 🌸

so this module is a little collection of custom gaussian fitting routines. they were developed in collab with Alison Offer (yes, a real one, we stan a co-author) and like… they do a reasonably robust job and they're genuinely quite useful. no cap. πŸ”₯

gaussian fitting is something the author does a LOT of, so it was worth putting in their special code. main character energy honestly. ✨

⚠️ real talk warning: it is NOT clear that this code is fully debugged. the reason for that is that our author tried using the internal linear eqn solving C routines called elsewhere and they were giving erroneous results. so steal from this code with caution! however β€” and this is the slay part β€” it does give good fits to reasonable looking gaussians and tests show correct parameters. ✨

KGB 29/Oct/2002 πŸŽ€


⭐ SYNOPSIS ⭐

use PDL;
use PDL::Fit::Gaussian;
($cen, $pk, $fwhm, $back, $err, $fit) = fitgauss1d($x, $data);
($pk, $fwhm, $back, $err, $fit) = fitgauss1dr($r, $data);

look at that. two lines of loading, two lines of living. πŸ’œ


πŸ‘‘ FUNCTIONS πŸ‘‘

fitgauss1d 🧚

Fit 1D Gassian to data ndarray

(yes it says "Gassian". that's the spelling. we love her. we protect her. 🫢)

($cen, $pk, $fwhm, $back, $err, $fit) = fitgauss1d($x, $data);

($cen, $pk, $fwhm, $back, $err, $fit) = fitgauss1d($x, $data);

xval(n); data(n); [o]xcentre();[o]peak_ht(); [o]fwhm();
[o]background();int [o]err(); [o]datafit(n);
[t]sig(n); [t]ytmp(n); [t]yytmp(n); [t]rtmp(n);

okay so what does it actually do: it fits a 1D Gaussian robustly, and the free parameters are the centre, the peak height, and the FWHM. πŸ“

the background is NOT fit β€” because our author finds that generally unreliable β€” instead a median is determined in the 'outer' 10% of pixels (i.e. those at the start/end of the data ndarray). πŸŽ€

the initial estimate of the FWHM is the length of the ndarray/3, so it might fail if the ndarray is too long. (this is non-robust anyway, don't come for her). most data does just fine and this is a good default gaussian fitter. periodt. πŸ’…

the values of the error code $err correspond to:

  1. 0 β€” successful fit βœ…
  2. 1 β€” internal problem with memory allocation πŸ’€
  3. 2 β€” insufficient number of data points 😭
  4. 3 β€” fit did not converge πŸ™ˆ

SEE ALSO: fitgauss1dr() for fitting radial gaussians


fitgauss1dr πŸŒ€

Fit 1D Gassian to radial data ndarray

($pk, $fwhm2, $back, $err, $fit) = fitgauss1dr($r, $data);

($pk, $fwhm2, $back, $err, $fit) = fitgauss1dr($r, $data);

xval(n); data(n); [o]peak_ht(); [o]fwhm();
[o]background();int [o]err(); [o]datafit(n);
[t]sig(n); [t]ytmp(n); [t]yytmp(n); [t]rtmp(n);

this one fits a 1D radial Gaussian robustly, and the free parameters are the peak height and the FWHM. the centre is assumed to be X=0 (i.e. the start of the ndarray). no centre-finding here, she's already decided. πŸ‘‘

the background is NOT fit β€” again, generally unreliable β€” instead a median is determined in the 'outer' 10% of pixels (i.e. those at the end of the data ndarray). ✨

the initial estimate of the FWHM is the length of the ndarray/3, so it might fail if the ndarray is too long. (non-robust anyway, we've been over this). most data does just fine and this is a good default gaussian fitter. πŸ’–

the values of the error code $err correspond to:

  1. 0 β€” successful fit βœ…
  2. 1 β€” internal problem with memory allocation πŸ’€
  3. 2 β€” insufficient number of data points 😭
  4. 3 β€” fit did not converge πŸ™ˆ

SEE ALSO: fitgauss1d() to fit centre as well.


πŸ’€ BUGS πŸ’€

May not converge for weird data, still pretty good! 🌈

(that's it. that's the whole bug section. she's confident, she's honest, she's iconic.)


πŸŽ€ AUTHOR πŸŽ€

This file copyright (C) 1999, Karl Glazebrook (kgb@aaoepp.aao.gov.au), Gaussian fitting code by Alison Offer (aro@aaocbn.aao.gov.au). All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file. πŸ’œ


and that's the whole thing bestie, no notes, go fit some gaussians πŸ¦‹βœ¨

signing off β€” this was perl v5.42.3, dated 2026-08-21, Gaussian(3pm), mwah πŸ’…

πŸ“¦ where this page comes from