stoner_measurement.plugins.transform.extremum_locator.ExtremumLocatorPlugin

class stoner_measurement.plugins.transform.extremum_locator.ExtremumLocatorPlugin(parent=None)[source]

Bases: TraceChannelSelectionMixin, TransformPlugin

Locate the x coordinate of a broad maximum or minimum in a trace.

The selected y data are first smoothed with a Savitzky-Golay filter. The global maximum or minimum of that curve identifies the neighbourhood of interest, and a quadratic least-squares fit within that neighbourhood refines the x and y coordinates. This is more stable than selecting the largest raw sample for noisy parabolic or sinusoidal peaks and troughs.

The General tab selects whether to locate a maximum or minimum, an optional inclusive x search interval, the source trace, and the y column to inspect. It can also add a labelled data marker to the main plot at each successful result. Advanced data-source mode allows the calculation arrays to come from arbitrary x and y expressions in the sequence-engine namespace while the selected trace continues to supply the result units.

The Advanced tab controls two stages of noise rejection and refinement:

  • S-G window is the number of neighbouring y samples used for Savitzky-Golay smoothing. It is coerced to an odd value that fits the input. A wider window rejects more point-to-point noise but can flatten narrow extrema or blend nearby features.

  • S-G polynomial is the polynomial order within each smoothing window. It is limited to less than the effective window length. Order 2 is a good default for broad parabolic and sinusoidal extrema.

  • Turning-point prominence is the minimum peak or trough prominence as a fraction of the robust y span inside the selected x interval. Increase it to reject small noise features; reduce it for shallow extrema.

  • Quadratic fit window is the number of smoothed samples around the strongest candidate used for the final parabolic fit. Increase it for a broad noisy extremum and decrease it when neighbouring structure would bias the fit. It too is coerced to a valid odd window.

A successful run publishes extremum_x and extremum_y as scalar outputs in the values catalogue, using the source x and y units. The same results are available from the read-only extremum_x and extremum_y properties, or together as the read-only extremum (x, y) tuple. Before the first successful run, and after a failed run, these properties are None. Invalid, non-finite, mismatched, or shorter-than-three-point inputs are logged and produce no outputs.

Variables:
  • trace_key (str) – Catalogue key of the source trace.

  • column_key (str) – Selected y-data column in the source trace.

  • advanced_mode (bool) – When True, evaluate x_expr and y_expr instead of reading the selected trace arrays directly.

  • x_expr (str) – Runtime expression providing x data in advanced mode.

  • y_expr (str) – Runtime expression providing y data in advanced mode.

  • mode (str) – "maximum" or "minimum".

  • x_min_expr (str) – Optional inclusive lower x bound, expressed in engine-namespace units. Blank searches to the start of the trace.

  • x_max_expr (str) – Optional inclusive upper x bound. Blank searches to the end.

  • add_marker (bool) – Add the successful result to the main plot as a data marker.

  • smoothing_window (int) – Requested Savitzky-Golay smoothing-window length.

  • smoothing_polyorder (int) – Requested Savitzky-Golay local polynomial order.

  • turning_point_prominence (float) – Minimum prominence as a fraction of the robust selected y span.

  • fit_window (int) – Requested local quadratic-fit window length.

  • extremum_x (float | None) – Read-only fitted x coordinate from the latest successful run.

  • extremum_y (float | None) – Read-only fitted y coordinate from the latest successful run.

  • extremum (tuple[float, float] | None) – Read-only fitted (x, y) coordinate pair.

  • instance_name (str) – Inherited Python identifier for this instance in the Script tab and QtConsole.

  • comment (str) – Inherited optional note displayed beside this step.

  • sequence_engine (SequenceEngine | None) – Inherited owning engine and its live namespace; None while detached.

  • data (dict[str, Any]) – Inherited latest output mapping populated by run(), containing scalar and/or TraceData results.

Notes

The candidate is the highest or lowest qualifying prominent turning point in the smoothed, range-limited y data. If the local quadratic has the wrong curvature or places its vertex outside the fit neighbourhood, the plugin safely falls back to the smoothed candidate sample rather than extrapolating.

Keyword Parameters:

parent (QObject | None) – Optional Qt parent object.

Examples

With an instance named extremum_locator in the sequence, use the QtConsole to inspect or edit it before running. Substitute your instance name if different; result data reflects completed steps:

extremum_locator.mode = "minimum"
extremum_locator.add_marker = True
extremum_locator.extremum
add_plot_marker

Qt signal.

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

types is normally a sequence of individual types.  Each type is either a
type object or a string that is the name of a C++ type.  Alternatively
each type could itself be a sequence of types each describing a different
overloaded signal.
name is the optional C++ name of the signal.  If it is not specified then
the name of the class attribute that is bound to the signal is used.
revision is the optional revision of the signal that is exported to QML.
If it is not specified then 0 is used.
arguments is the optional sequence of the names of the signal's arguments.
config_tabs(parent: QWidget | None = None) → list[tuple[str, QWidget]][source]

Return configuration tabs for this transform plugin.

Produces a single Data tab that places the instance-name editor (from _general_config_widget()) at the top, followed by a horizontal separator and the data-selection widget returned by _build_data_tab(). An optional About tab is appended when _about_html() returns non-None content.

Subclasses that need additional tabs (e.g. a Fit Function or Parameters tab) should call super().config_tabs(parent) to obtain the base Data tab and then insert their extra tabs before the optional About tab.

Keyword Parameters:

parent (QWidget | None) – Optional Qt parent widget.

Returns:

List of (tab_title, widget) pairs starting with the combined Data tab.

Return type:

(list[tuple[str, QWidget]])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.transform import TransformPlugin
>>> class _T(TransformPlugin):
...     @property
...     def name(self): return "T"
...     @property
...     def required_inputs(self): return []
...     @property
...     def output_names(self): return []
...     def transform(self, data): return {}
>>> tabs = _T().config_tabs()
>>> tabs[0][0]
'Data'
>>> 'General' not in [t for t, _ in tabs]
True
declared_outputs() → PluginOutputs[source]

Declare extremum coordinates with their measured-axis units.

property extremum: tuple[float, float] | None

Read-only (x, y) coordinates from the latest successful run.

property extremum_x: float | None

Read-only x coordinate from the latest successful run.

property extremum_y: float | None

Read-only y coordinate from the latest successful run.

property name: str

Unique human-readable name for this plugin.

property required_inputs: list[str]

Names of input datasets that transform() requires.

validate_inputs() raises ValueError if any of these keys are absent from the data dict passed to transform().

Returns:

Ordered list of required input key names.

Return type:

(list[str])

property sequence_engine: SequenceEngine | None

Return the owning engine used to wire optional plot markers.

to_json() → dict[str, Any][source]

Serialise this plugin’s configuration to a JSON-compatible dict.

The returned dict contains at minimum:

  • "type" — the plugin sub-type tag (e.g. "trace", "state").

  • "class" — the fully qualified class path "module:ClassName" used by from_json() to reconstruct the exact subclass.

  • "instance_name" — the current instance_name.

Subclasses should call super().to_json() and then add their own configuration keys to the returned dict.

Returns:

A JSON-serialisable dictionary representing this plugin’s current configuration.

Return type:

(dict[str, Any])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.trace import DummyPlugin
>>> plugin = DummyPlugin()
>>> d = plugin.to_json()
>>> d["type"]
'trace'
>>> d["instance_name"]
'dummy'
>>> "class" in d
True
transform(data: dict[str, Any]) → dict[str, Any][source]

Locate and return the configured extremum.