epdfsuite.recalibration

Functions

recalibrate_from_isocurve(image[, n_levels, ...])

Find the beam centre from iso-intensity contours of an amorphous halo.

epdfsuite.recalibration.recalibrate_from_isocurve(image, n_levels=7, level_range=(0.15, 0.75), min_points=40, fit_circle=True, rms_rel_max=0.15, min_arc_deg=60.0, cluster_window=15.0, initial_center=None, max_center_offset=None, mask=None, plot=False)[source]

Find the beam centre from iso-intensity contours of an amorphous halo.

For amorphous specimens the scattered intensity decreases monotonically from the direct beam, so iso-intensity lines are approximately circular arcs centred on the beam. This method:

  1. Computes intensity percentiles on valid (unmasked) pixels only, then sets masked pixels to 0 so they do not generate contours.

  2. Samples n_levels intensity levels across level_range.

  3. Extracts iso-intensity contours with skimage.measure.find_contours.

  4. Discards contour points that fall inside the masked region.

  5. Fits a circle (Kasa algebraic method) to each surviving contour.

  6. Filters by circularity: keeps only fits where rms / R < rms_rel_max (rejects non-circular contours such as mask edges or noise).

  7. Filters by arc span: keeps only fits whose angular coverage around the fitted centre exceeds min_arc_deg (rejects very short arcs that produce biased Kasa estimates).

  8. If initial_center is provided, additionally discards fits whose centre is farther than max_center_offset pixels from that estimate.

  9. Clusters the surviving centre estimates: computes a robust median, then discards outliers whose centre deviates from it by more than cluster_window pixels.

  10. Returns the median of the final cluster.

Parameters:
  • image (ndarray) – 2-D image as a numpy array.

  • n_levels (int, optional) – Number of iso-intensity levels to sample. Default is 7.

  • level_range (tuple of float, optional) – (low, high) as fractions of the visible (unmasked) intensity range after hot-pixel clipping. Default is (0.15, 0.75).

  • min_points (int, optional) – Minimum number of unmasked contour points required to attempt a fit. Default is 40.

  • fit_circle (bool, optional) – If True (default), fit a circle (3 parameters, more stable on partial arcs). If False, fit a general ellipse.

  • rms_rel_max (float, optional) – Maximum allowed normalised RMS residual rms / R to accept a contour as circular. Default is 0.15 (15 % of radius). Increase if the halo is slightly elliptical; decrease to be stricter.

  • min_arc_deg (float, optional) – Minimum angular span (degrees) of the arc around the fitted centre required to accept the contour. Default is 60.0. Short arcs (beamstop edge, noise patch) are rejected.

  • initial_center (tuple of float or None, optional) – Rough centre (x, y) in pixels used to filter out geometrically implausible circle fits. When None no distance filtering is applied.

  • cluster_window (float, optional) – Radius (pixels) of the final clustering window. After all per-contour fits have passed the circularity and arc-span filters, a robust median is computed and any estimate farther than cluster_window pixels from it is discarded as an outlier before computing the final centre. Default is 15.0.

  • max_center_offset (float or None, optional) – Maximum allowed distance (pixels) between a per-contour fitted centre and initial_center. Defaults to 25 % of the smallest image dimension when initial_center is provided.

  • mask (ndarray of bool or None, optional) – Boolean mask where True marks invalid pixels (beamstop, detector edge, etc.).

  • plot (bool, optional) – Show a diagnostic figure. Default is False.

Returns:

  • x_c (float) – X coordinate of the beam centre (pixels).

  • y_c (float) – Y coordinate of the beam centre (pixels).