stoner_measurement.plugins.trace.base.TracePlugin¶
- class stoner_measurement.plugins.trace.base.TracePlugin(parent: QObject | None = None)[source]¶
Bases:
QObject,BasePluginAbstract base class for plugins that collect (x, y) data traces.
A
TracePluginacquires one or more complete shared-x datasets from instruments. Subclasses must implementname(inherited fromBasePlugin) and_measure().The class provides:
Lifecycle API —
connect(),configure(),measure(), anddisconnect()form the standard sequence-engine interface.measure()owns acquisition status, result storage, and statistics; subclasses only implement the protected_measure()hook.Status reporting —
status(aTraceStatusvalue) andstatus_changedsignal communicate the current lifecycle phase.Complete-trace acquisition —
measure()returns a mapping of trace names to completeTraceDatatables.Scan generator —
scan_generatorholds the activeBaseScanGeneratorinstance. The default class used is given by_scan_generator_classand can be changed at runtime viaset_scan_generator_class().Trace details —
trace_names,x_label,y_label,x_units, andy_unitsdescribe the datasets available before acquisition.
- Variables:
_scan_generator_class (type[BaseScanGenerator]) – Default scan generator class instantiated in
__init__(). Override at class level in a subclass to change the default for that plugin type._scan_generator_classes (list[type[BaseScanGenerator]]) – Ordered list of scan generator classes offered to the user in the Scan Type configuration tab. The tab is only shown when this list contains more than one entry. Override at class level to restrict or extend the available choices.
scan_generator (BaseScanGenerator) – Active scan generator instance. Replaced (and
scan_generator_changedemitted) whenset_scan_generator_class()is called.data (dict[str, TraceData]) – Most recently acquired trace data, populated by
measure(). Maps each trace name to one completeTraceDatatable. Empty until the first successful call tomeasure().status_changed (pyqtSignal[object]) – Emitted with the new
TraceStatusvalue wheneverstatuschanges.scan_generator_changed (pyqtSignal) – Emitted after
scan_generatoris replaced with a new instance. The first configuration tab and the Scan Type selector both connect to this signal to update their content.
- Keyword Parameters:
parent (QObject | None) – Optional Qt parent object.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> plugin.plugin_type 'trace' >>> plugin.x_label 'x' >>> plugin.y_label 'y' >>> plugin.trace_names == [plugin.name] True >>> plugin.status is TraceStatus.IDLE True
- 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.
- config_tabs(parent: QWidget | None = None) list[tuple[str, QWidget]][source]¶
Return a fixed set of configuration tabs for this plugin.
Returns a Scan tab (instance name, comment, optional generator selector, and the generator’s own config widget), a Settings tab populated by
_plugin_config_tabs(), and an optional About tab whose HTML content is provided by_about_html().Tab widgets are created once and cached on the plugin instance so that user-edited state is preserved when tabs are hidden and re-shown (e.g. when the user selects a different sequence step and then re-selects this one).
- Keyword Parameters:
parent (QWidget | None) – Ignored after the first call; widgets are cached without a parent and are re-parented automatically by
QTabWidgetwhen added.- Returns:
List of
(tab_title, widget)pairs; the Scan tab is always first.- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> tabs = plugin.config_tabs() >>> tabs[0][0] 'Scan' >>> tabs[1][0] 'Settings'
- configure() None[source]¶
Apply plugin settings to the instrument.
Called after
connect()and beforemeasure()to push configuration (range, integration time, averaging, etc.) to the hardware. May also be called mid-sequence to reconfigure without reconnecting.The default implementation is a no-op. Override to send the appropriate commands to the instrument.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> plugin.configure() # reads widget values for the dummy plugin
- connect() None[source]¶
Open instrument connections and verify the instrument identity.
Called once at the start of a measurement sequence to reserve hardware resources. Subclasses should override this method to open serial, USB, GPIB, or Ethernet connections and to confirm that the connected instrument is the expected type.
The default implementation is a no-op and leaves the status unchanged (
IDLE). Override and callself._set_status(TraceStatus.IDLE)after a successful connection to signal readiness.- Raises:
RuntimeError – If the instrument cannot be reached or is not the expected type. Subclasses should raise (or emit
status_changedwithTraceStatus.ERROR) on failure.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> plugin.connect() # no-op for the dummy plugin >>> plugin.status is TraceStatus.IDLE True
- declared_outputs() PluginOutputs[source]¶
Declare trace results and optional statistics from one definition.
- disconnect() None[source]¶
Release all reserved instrument resources.
Called at the end of a measurement sequence (or after an error) to cleanly close connections and free hardware resources. The default implementation is a no-op and resets
statustoTraceStatus.IDLE. Override to close serial/USB/GPIB/Ethernet connections.Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> plugin.disconnect() >>> plugin.status is TraceStatus.IDLE True
- generate_action_code(indent: int, sub_steps: list, render_sub_step: Any) list[str][source]¶
Return action code lines that acquire a trace via
measure().- Parameters:
indent (int) – Number of four-space indentation levels for the emitted lines.
sub_steps (list) – Ignored for
TracePlugin(leaf node in the sequence tree).render_sub_step (Any) – Ignored for
TracePlugin.
- Returns:
A single line that calls
measure({})and assigns the result to the plugin’sdataattribute.- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> lines = plugin.generate_action_code(1, [], lambda s, i: []) >>> " dummy.data = dummy.measure({})" in lines True >>> any("for" in line for line in lines) False
- get_channel_statistic(channel: str, statistic: str) float[source]¶
Return a cached per-channel statistic, defaulting to
nan.
- 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.
- measure(parameters: dict[str, Any]) dict[str, TraceData][source]¶
Acquire and return all trace datasets.
This is the sole public acquisition entry point. It owns status transitions, stores the result in
data, and updates optional statistics. Subclasses implement_measure()to perform the instrument-specific acquisition.The result is also stored as
dataso that downstream code can access it without holding on to the return value.- Parameters:
parameters (dict[str, Any]) – Step-specific configuration forwarded to
_measure().- Returns:
Mapping of trace name to a complete
TraceDatadataset. The same dict is stored asdata.- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> from stoner_measurement.scan import SteppedScanGenerator >>> plugin = DummyPlugin() >>> plugin.scan_generator = SteppedScanGenerator( ... start=0.0, stages=[(0.4, 0.1, True)], parent=plugin ... ) >>> result = plugin.measure({}) >>> list(result.keys()) ['Dummy'] >>> import numpy as np >>> isinstance(result['Dummy'].x, np.ndarray) True >>> len(result['Dummy'].x) 5 >>> result['Dummy'].names['x'] 'I' >>> result['Dummy'].units['y'] 'V' >>> plugin.status is TraceStatus.DATA_AVAILABLE True >>> plugin.data is result True
- property plugin_type: str¶
Short tag identifying this plugin as a trace collector.
- Returns:
Always
"trace".- Return type:
(str)
- scan_generator_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.
- set_scan_generator_class(cls: type[BaseScanGenerator]) None[source]¶
Replace the active scan generator with a new instance of cls.
If the current generator is already an instance of cls this method does nothing. Otherwise a new instance is created (with this plugin as Qt parent), assigned to
scan_generator, andscan_generator_changedis emitted so that connected widgets can refresh their content.- Parameters:
cls (type[BaseScanGenerator]) – The scan generator class to instantiate.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> from stoner_measurement.scan import FunctionScanGenerator >>> plugin = DummyPlugin() >>> plugin.set_scan_generator_class(FunctionScanGenerator) >>> isinstance(plugin.scan_generator, FunctionScanGenerator) True
- property status: TraceStatus¶
Current operational status of this plugin.
- Returns:
The current
TraceStatusvalue.- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> plugin = DummyPlugin() >>> plugin.status is TraceStatus.IDLE True
- status_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.
- to_json() dict[source]¶
Serialise this plugin’s configuration, including the scan generator.
Extends the base
to_json()dict with a"scan_generator"key containing the serialisedscan_generatorstate.- Returns:
A JSON-serialisable dictionary with at least the keys produced by
to_json()plus"scan_generator".- Return type:
(dict)
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' >>> "scan_generator" in d True >>> d["scan_generator"]["type"] 'SteppedScanGenerator'
- property x_label: str¶
Axis label for the independent variable.
- Returns:
Human-readable label string; default
"x".- Return type:
(str)
- property x_units: str¶
Physical units for the x (independent) axis.
The default implementation returns an empty string (dimensionless). Override to specify units such as
"V","Hz", or"s".- Returns:
Unit string; empty string if dimensionless.
- Return type:
(str)
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> DummyPlugin().x_units ''
- property y_label: str¶
Axis label for the dependent variable.
- Returns:
Human-readable label string; default
"y".- Return type:
(str)
- property y_units: str¶
Physical units for the y (dependent) axis.
The default implementation returns an empty string (dimensionless). Override to specify units such as
"A","Ω", or"dB".- Returns:
Unit string; empty string if dimensionless.
- Return type:
(str)
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.trace import DummyPlugin >>> DummyPlugin().y_units ''