slitflow.loc.fit module

class Gauss2D(info_path=None)[source]

Bases: Table

Fit spot localizations with 2D Gaussian distribution.

Caution

The input image should be split into a single frame image. In other words, the shape of reqs[0] in process() should be (1, height, width).

Parameters:
  • reqs[0] (Image) – Image to fit. Required params; pitch, length_unit.

  • reqs[1] (Table) – Roughly predicted X,Y-coordinate.

  • param["half_width"] (int) – Half width of the clipping rectangle in pixel to fit the spot image. The shape of clipped image is (2 * half_width + 1, 2 * half_width + 1).

  • param["split_depth"] (int) – File split depth number.

Returns:

Refined X,Y-coordinate

Return type:

Table

set_info(param={})[source]

Copy params from reqs[0] and columns from reqs[1].

static process(reqs, param)[source]

Fit spot localizations with 2D Gaussian distribution.

Parameters:
  • reqs[0] (numpy.ndarray) – Numpy 3D array with the shape of (1, height, width).

  • reqs[1] (pandas.DataFrame) – Roughly predicted X,Y-coordinate.

  • param["calc_cols"] (list of str) – X,Y-coordinate column names.

  • param["use_cols"] (list of str) – Column names to use. Index column names + calc_cols.

  • param["half_width"] (int) – Half width of the clipping rectangle in pixel to fit the spot image. The shape of clipped image is (2 * half_width + 1, 2 * half_width + 1).

  • param["split_depth"] (int) – File split depth number.

Returns:

Refined X,Y-coordinate

Return type:

Table

fit_gauss_2d(clip, half_width)[source]

Fit clip image with 2D Gaussian.

Parameters:
  • clip (numpy.ndarray) – Two-dimensional array for fitting.

  • half_width (int) – Half width of the clipping rectangle. clip.shape = (2 * half_width + 1, 2 * half_width + 1).

Returns:

tuples containing

  • amplitude (float): Amplitude of 2D Gaussian

  • y_center (float): Y-coordinate of 2D Gaussian center

  • x_center (float): X-coordinate of 2D Gaussian center

  • sigma (float): Standard deviation of 2D Gaussian

  • back (float): Background offset of 2D Gaussian

  • se_amplitude (float): Standard deviation error of amplitude

  • se_y_center (float): Standard deviation error of Y-coordinate

  • se_x_center (float): Standard deviation error of X-coordinate

  • se_sigma (float): Standard deviation error of sigma

  • se_back (float): Standard deviation error of background

  • rmsr (float): Root mean square of residual (Background)

  • rsqr (float): R-squared

If fitting is failed, this function returns (amp_ini, half_width, half_width, half_width / 3, back_ini, 100, 100, 100, 100, 100, 1, 1)

gauss2d(xy, amp, xc, yc, sigma, back)[source]

Returns the 2D Gaussian value of the X,Y-coordinate.

Parameters:
  • xy (tuple of float) – (x,y) coordinates to calculate the value.

  • amp (float) – Amplitude.

  • xc (float) – X-coordinate of 2D Gaussian center.

  • yc (float) – Y-coordinate of 2D Gaussian center.

  • sigma (float) – Standard deviation of 2D Gaussian.

  • back (float) – Background offset of 2D Gaussian.

Returns:

2D Gaussian value of the X,Y-coordinate

Return type:

float