pytweezer.analysis.gaussian_fit module

Fit a 1-D Gaussian to an incoming data trace and publish the parameters.

Input:

One data stream carrying either a 1-D array (y only, x is the index) or a 2xN [x, y] array – e.g. a profile from projections.py.

Output:

A data message (no array) whose header carries the fit parameters: amplitude, center, sigma, fwhm, offset, plus method and success. Published on <name> (the process’s own stream).

Properties:
  • datastreams: ([str]) input data streams.

  • method: (str) 'lsq' (default, accurate least-squares fit) or 'moments' (a faster closed-form estimate – centre is reliable but the width is biased high by baseline noise in the tails; use only when raw speed matters more than an accurate sigma).

The 'lsq' path seeds scipy.optimize.curve_fit() with the gaussian_moments() estimate so it converges in a few iterations, and caps maxfev so a pathological trace cannot stall the analysis loop.

class pytweezer.analysis.gaussian_fit.GaussianFit(name)[source]

Bases: DataAnalysis

process(head, data)[source]

Transform one received message.

Parameters:
  • head – the message header dict.

  • data – the payload (numpy array for images/data).

Returns:

(head, data) to republish, or None to drop the message. The default is a pass-through.

pytweezer.analysis.gaussian_fit.gaussian(x, amplitude, center, sigma, offset)[source]

Gaussian model: offset + amplitude * exp(-0.5*((x-center)/sigma)**2).

pytweezer.analysis.gaussian_fit.gaussian_moments(x, y)[source]

Closed-form Gaussian estimate from the data’s moments (fast, no fit).

Returns a params dict; success is False when the trace carries no positive signal above baseline (a flat or empty profile).