stoner_measurement.plugins.state.base.StatePlugin¶
- class stoner_measurement.plugins.state.base.StatePlugin(parent: QObject | None = None)[source]¶
Bases:
QObject,SequencePluginAbstract base class shared by
StateScanPluginandStateSweepPlugin.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
StateScanPluginfor discrete-step, ramp-to-target scanning, orStateSweepPluginfor 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 toFalse.clear_on_start (bool) – When
True,clear_data()is called before the loop begins. Defaults toTrue.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;
iterationandstageare auxiliary columns and the remaining columns are evaluated sequence outputs.instance_name_changed (pyqtSignal[str, str]) – Emitted when
instance_namechanges. 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_filterevaluates toTrue.Evaluates
clear_filterin the sequence engine namespace. If the result is truthy,datais reset to an emptyTraceData. 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_flagisTrueand the plugin is attached to a sequence engine (i.e.sequence_engineis notNone). Both conditions must be met. Evaluatescollect_filter; if truthy, appends a row todataat the current state value. The row containsiterationandstage, 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 auxiliarystatecolumn.- Keyword Parameters:
outputs (list[str] | None) – Optional list of output names to include. Resolution order is: explicit
outputsargument first; thencollect_outputswhen 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()
- 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.
- property data: TraceData¶
Accumulated measurement data collected during the iteration loop.
The
TraceDatax axis is the controlled or swept physical state. Theiterationandstagecolumns retain loop bookkeeping; subsequent columns contain evaluated outputs from the sequence engine’s values catalogue. Populated bycollect()and reset byclear_data().- Returns:
The accumulated data, or an empty TraceData if no data has been collected or the data has been cleared.
- Return type:
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.
- 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 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).StateScanPluginuses this inramp_to()to reject out-of-range targets.StateSweepPluginuses this in its iteration loop to stop the sweep if a sampled value goes out of range.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
BasePlugininstances from sub-steps.Both
StateScanPluginandStateSweepPluginare sequence containers that may own nested child plugins as sub-steps. This override exposes those child plugin instances so thatsequence_plugins()can discover them recursively.Only the direct children stored in
sub_stepsare returned; recursion into their own sub-steps is handled by the engine callingmember_plugins()on each returned child in turn.- Returns:
Ordered list of directly owned child plugin instances. Returns an empty list when
sub_stepsis 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 withcollect_data,clear_on_start,collect_filter, andclear_filter. Subclasses callsuper().to_json()and add their own generator-specific keys.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