id4_common.plans.peak_position#
Peak / centroid plans for 1D scans and 2D ``grid_scan``s (issue #59).
Public surface:
peak_pos()— diagnostic; returns a stats dict for any scan (1D or 2D). No motion.cen()— move to the FWHM midpoint of a previous scan.com()— move to the centroid (center-of-mass).maxi()— move to the x at peak max.mini()— move to the x at peak min.
For 2D grid_scan runs the move plans default to moving both
scan motors to the 2D feature. Pass positioner= a single motor to
project onto that axis instead, or positioner=[m1, m2] to be
explicit.
Backward-compat aliases for callers from PR #54: peak (= com),
pmax (= maxi), pmin (= mini).
Backend choice (no new pip deps):
apstools.utils.xy_statisticsfor 1Dcom/max/min/fwhm(already a dep).scipy.signalfor the FWHM-midpoint (cen) calculation in 1D.scipy.ndimageforcom/max/min/cenin 2D.
Module Contents#
- id4_common.plans.peak_position.peak_pos(scan_id=-1, x=None, y=None)#
Compute peak statistics for one or more detectors of a previous scan.
Loads the scan from the shared session catalog (
id4_common.utils.run_engine.cat), dispatches to the 1D or 2D backend based on the scan’s plan, and returns a nested dict.- Parameters:
scan_id (int, optional) – Catalog index. Default
-1(last scan); negative indices count from the end.x (str, optional) – For 1D scans: motor (x-axis) field name. If None, picks the single motor or, for multi-motor 1D scans, the motor with the largest range. Ignored for 2D scans.
y (str or list of str, optional) – Detector (y-axis) field name(s). If None, uses every entry in
start["hints"]["detectors"].
- Returns:
Always carries
"shape"and"axes"so callers can branch on dimensionality:1D:
{"shape": (N,), "axes": [motor], "com": {det: x, ...}, "max": {det: (x, h), ...}, "min": {det: (x, h), ...}, "fwhm": {det: w, ...}, "cen": {det: x, ...}}2D:
{"shape": (M, N), "axes": [m1, m2], "com": {det: (m1, m2), ...}, "max": {det: (m1, m2, h), ...}, "min": {det: (m1, m2, h), ...}, "cen": {det: (m1, m2), ...}, "fwhm": {det: (fwhm_m1, fwhm_m2), ...}}
- Return type:
- id4_common.plans.peak_position.cen(scan_id=-1, positioner=None, detector=None, confirm=True)#
Move to the FWHM-midpoint of a previous scan.
Equivalent to bluesky
PeakStats.cen. For asymmetric peaks this differs fromcom().- Parameters:
scan_id (int, optional) – Catalog index of the scan. Default
-1(last scan).positioner (ophyd object or list, optional) – Device(s) to move. None → autodetected from the scan’s motors (single for 1D scans, both motors for 2D
grid_scan).detector (str, optional) – Detector field name. None → first hint from the scan.
confirm (bool, optional) – If True (default), prompts for multi-motor 1D scans and for scans older than 5 minutes. False skips every prompt.
See also
- id4_common.plans.peak_position.com(scan_id=-1, positioner=None, detector=None, confirm=True)#
Move to the centroid (center-of-mass) of a previous scan.
See
cen()for parameter details.See also
- id4_common.plans.peak_position.maxi(scan_id=-1, positioner=None, detector=None, confirm=True)#
Move to the x-value at peak maximum of a previous scan.
See
cen()for parameter details.See also
- id4_common.plans.peak_position.mini(scan_id=-1, positioner=None, detector=None, confirm=True)#
Move to the x-value at peak minimum of a previous scan.
See
cen()for parameter details.See also
- id4_common.plans.peak_position.peak(scan_id=-1, feature='centroid', positioner=None, detector=None, confirm=True)#
Backward-compat: dispatch by
featuretocen()/com()/maxi()/mini().Accepts the PR-#54 feature names (
"centroid"/"x_at_max_y"/"x_at_min_y") and the new short names ("com"/"max"/"min"/"cen").