stoner_measurement.plugins.state.base.StatePlugin

class stoner_measurement.plugins.state.base.StatePlugin(parent: QObject | None = None)[source]

Bases: QObject, SequencePlugin

Abstract base class shared by StateScanPlugin and StateSweepPlugin.

This class owns all state, data-collection infrastructure, and abstract interface that is common to both plugin families. It should not be subclassed directly — use StateScanPlugin for discrete-step, ramp-to-target scanning, or StateSweepPlugin for generator-driven continuous-sweep loops.

Variables:
  • ix (int) – Zero-based index of the current iteration step.

  • value (float) – Current set-point value at the most recent iteration step.

  • stage (int) – Stage index within the current iteration step.

  • meas_flag (bool) – Whether the current step should be recorded as a measurement.

  • collect_data (bool) – When True, collect() is called at each iteration step. Defaults to False.

  • clear_on_start (bool) – When True, clear_data() is called before the loop begins. Defaults to True.

  • collect_filter (str) – Python expression evaluated by collect() to decide whether a data point should be stored. Defaults to "{instance_name}.meas_flag".

  • clear_filter (str) – Python expression evaluated by clear_data() to decide whether the collected data should be cleared. Defaults to "True".

  • collect_output_roles (dict[str, str]) – Per-output role choices from the configuration table. "x" promotes a measured readback to the trace x axis; "d", "y", and "e" set data-column roles; "-" leaves the role unspecified for the normal fallback heuristics.

  • collect_output_labels (dict[str, str]) – Optional dataframe headers keyed by catalogue output name. Edit these in the Data tab’s Label column; blank labels use the output name. Labels also apply to trace names, roles and units.

  • data (TraceData) – Accumulated measurement data. The controlled state is the shared x axis; iteration and stage are auxiliary columns and the remaining columns are evaluated sequence outputs.

  • instance_name_changed (pyqtSignal[str, str]) – Emitted when instance_name changes. Arguments are the old name and the new name.

  • state_changed (pyqtSignal[float]) – Emitted with the current measured value each time the hardware state is sampled during a ramp or sweep.

  • state_reached (pyqtSignal[float]) – Emitted once when the target set-point has been reached.

  • state_error (pyqtSignal[str]) – Emitted if the hardware faults, a timeout is exceeded, or a measured value falls outside limits.

Keyword Parameters:

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

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_scan import StateScanPlugin
>>> class _S(StateScanPlugin):
...     @property
...     def name(self): return "S"
...     @property
...     def state_name(self): return "X"
...     @property
...     def units(self): return "au"
...     def set_state(self, v): self._v = float(v)
...     def get_state(self): return getattr(self, "_v", 0.0)
...     def is_at_target(self): return True
>>> p = _S()
>>> isinstance(p.data, TraceData)
True
>>> p.data.df.empty
True
>>> p.limits
(-inf, inf)
clear_data() → None[source]

Clear the collected data if clear_filter evaluates to True.

Evaluates clear_filter in the sequence engine namespace. If the result is truthy, data is reset to an empty TraceData. If the plugin is not attached to an engine the data is always cleared unconditionally.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_scan import CounterPlugin
>>> import numpy as np
>>> p = CounterPlugin()
>>> p._data = TraceData.from_xy(np.array([0.0]), np.array([1.0]))
>>> p.clear_data()
>>> p.data.df.empty
True
collect(outputs: list[str] | None = None) → None[source]

Append a row of current output values to data.

Only collects when meas_flag is True and the plugin is attached to a sequence engine (i.e. sequence_engine is not None). Both conditions must be met. Evaluates collect_filter; if truthy, appends a row to data at the current state value. The row contains iteration and stage, followed by evaluated outputs from the engine’s values catalogue. If a selected output has an explicit "x" role, its evaluated readback becomes the x axis and the commanded value is retained in an auxiliary state column.

Keyword Parameters:

outputs (list[str] | None) – Optional list of output names to include. Resolution order is: explicit outputs argument first; then collect_outputs when set; otherwise all values-catalogue entries.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_scan import CounterPlugin
>>> from stoner_measurement.core.sequence_engine import SequenceEngine
>>> engine = SequenceEngine()
>>> p = CounterPlugin()
>>> engine.add_plugin("counter", p)
>>> p.collect_filter = "True"
>>> p.meas_flag = True
>>> p.ix = 0
>>> p.value = 1.5
>>> p.collect()
>>> p.data.x.tolist()
[1.5]
>>> int(p.data.df["iteration"].iloc[0])
0
>>> engine.shutdown()
property collect_data: bool

Whether this state plugin collects and publishes a trace table.

comment_changed

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.
configure() → None[source]

Configure the instrument (NOP default).

connect() → None[source]

Open instrument connections (NOP default).

property data: TraceData

Accumulated measurement data collected during the iteration loop.

The TraceData x axis is the controlled or swept physical state. The iteration and stage columns retain loop bookkeeping; subsequent columns contain evaluated outputs from the sequence engine’s values catalogue. Populated by collect() and reset by clear_data().

Returns:

The accumulated data, or an empty TraceData if no data has been collected or the data has been cleared.

Return type:

(TraceData)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_scan import CounterPlugin
>>> import numpy as np
>>> p = CounterPlugin()
>>> from stoner_measurement.core import TraceData
>>> isinstance(p.data, TraceData)
True
>>> p.data.df.empty
True
declared_outputs() → PluginOutputs[source]

Declare the state value, index and optional collected-data table.

disconnect() → None[source]

Release instrument resources (NOP default).

engine_cache_max_age_seconds: float = 5.0
property index: int

Current zero-based iteration index.

Returns:

The current iteration index.

Return type:

(int)

inferred_output_roles(outputs: list[str]) → dict[str, str][source]

Return the automatic roles used when all catalogue outputs are selected.

The commanded scan or sweep parameter supplies the implicit x axis, so catalogue values retain the existing behaviour of being primary y data.

instance_name_changed

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.
property is_loop_container: bool

Return True because scan and sweep children run in a loop.

property limits: tuple[float, float]

Allowed set-point or measured-value range (minimum, maximum).

Subclasses may override this to enforce hardware safety limits. The default is (-inf, inf) (no limits).

StateScanPlugin uses this in ramp_to() to reject out-of-range targets. StateSweepPlugin uses this in its iteration loop to stop the sweep if a sampled value goes out of range.

Returns:

(min_value, max_value) in the units of units.

Return type:

(tuple[float, float])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_scan import CounterPlugin
>>> CounterPlugin().limits
(-inf, inf)
member_plugins() → list[BasePlugin][source]

Return child BasePlugin instances from sub-steps.

Both StateScanPlugin and StateSweepPlugin are sequence containers that may own nested child plugins as sub-steps. This override exposes those child plugin instances so that sequence_plugins() can discover them recursively.

Only the direct children stored in sub_steps are returned; recursion into their own sub-steps is handled by the engine calling member_plugins() on each returned child in turn.

Returns:

Ordered list of directly owned child plugin instances. Returns an empty list when sub_steps is empty or contains only string entry-point descriptors.

Return type:

(list[BasePlugin])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_scan import CounterPlugin
>>> p = CounterPlugin()
>>> p.member_plugins()
[]
state_changed

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.
state_error

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.
abstract property state_name: str

Human-readable name of the controlled or swept physical quantity.

Returns:

E.g. "Magnetic Field", "Temperature", "Time".

Return type:

(str)

state_reached

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.
to_json() → dict[str, Any][source]

Serialise shared data-collection settings into the plugin dict.

Extends the base to_json() dict with collect_data, clear_on_start, collect_filter, and clear_filter. Subclasses call super().to_json() and add their own generator-specific keys.

Returns:

JSON-serialisable dict with the shared data-collection keys.

Return type:

(dict[str, Any])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.state_scan import CounterPlugin
>>> d = CounterPlugin().to_json()
>>> d["collect_data"]
False
>>> d["clear_on_start"]
True
abstract property units: str

Physical unit of the controlled or swept quantity.

Returns:

E.g. "T", "K", "s".

Return type:

(str)