stoner_measurement.plugins.monitor.magnet_controller.MagneticFieldMonitorPlugin

class stoner_measurement.plugins.monitor.magnet_controller.MagneticFieldMonitorPlugin(parent=None)[source]

Bases: MonitorPlugin

Publish live magnet-controller readings into the sequence value catalogue.

Use this monitor when you want the sequence to have access to live magnet information such as field, current, voltage, ramp rate, heater state, and stability. The selected quantities appear in the sequence value catalogue and can then be displayed, logged, plotted, saved, or used by other plugins.

In the configuration panel, choose which quantities should be reported.

The General tab sets the instance name and comment. Measurement selection and polling options are on Settings.

You can enable any combination of:

  • Field

  • Target field

  • Current

  • Voltage

  • Field rate

  • Target field rate

  • Heater

  • At target

  • Stable

The configuration tab presents these quantities as independent check boxes, allowing you to publish only the values needed by the rest of the sequence. The same tab also includes a force fresh poll option for cases where each read should actively request an updated hardware state from the controller engine instead of relying on cached values.

For more technical use, the selected parameters are exposed both via read() / last_reading and as typed accessor methods on the instance itself (field(), target_field(), current(), voltage(), field_rate(), heater(), at_target(), stable()) so that they can be referenced directly in sequence scripts.

Variables:
  • report_field (bool) – When True, the measured field is included in every reading.

  • report_target_field (bool) – When True, the target field is included in every reading.

  • report_current (bool) – When True, the magnet current is included in every reading.

  • report_voltage (bool) – When True, the magnet voltage is included in every reading.

  • report_field_rate (bool) – When True, the field rate of change is included in every reading.

  • report_target_field_rate (bool) – When True, the controller’s target field ramp rate is included in every reading.

  • report_heater (bool) – When True, the heater state is included in every reading.

  • report_at_target (bool) – When True, the at-target flag is included in every reading.

  • report_stability (bool) – When True, the stability flag is included in every reading.

  • force_fresh_poll (bool) – When True, every call to read() requests an immediate hardware poll from the engine rather than relying solely on the cached engine state.

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

  • last_reading (dict[str, float]) – Inherited read-only access to the latest cached readings.

  • monitor_interval (int) – Inherited timer polling interval in milliseconds; initially 1000.

Keyword Parameters:

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

Examples

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

magnetic_field_monitor.force_fresh_poll = False
magnetic_field_monitor.last_reading
at_target() → float[source]

Return whether the magnet is at its target field.

Returns:

1.0 when at target or 0.0 otherwise.

Return type:

(float)

config_widget(parent: QWidget | None = None) → QWidget[source]

Return the configuration widget for this plugin.

Keyword Parameters:

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

Returns:

Configuration widget with all plugin settings.

Return type:

(QWidget)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor.magnet_controller import MagneticFieldMonitorPlugin
>>> m = MagneticFieldMonitorPlugin()
>>> w = m.config_widget()
>>> w is not None
True
configure() → None[source]

No-op — the engine is configured by dedicated state-control plugins.

connect() → None[source]

Ensure the engine is connected and start the polling timer.

Raises:

RuntimeError – If no magnet controller is connected.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor.magnet_controller import MagneticFieldMonitorPlugin
>>> m = MagneticFieldMonitorPlugin()
>>> try:
...     m.connect()
... except RuntimeError:
...     pass
property controller_features: frozenset[str]

Return controller feature flags required by this plugin.

current() → float[source]

Return the current magnet current in amps.

Returns:

Magnet current in amps, or math.nan when unavailable.

Return type:

(float)

declared_outputs() → PluginOutputs[source]

Declare configured outputs and their physical units together.

disconnect() → None[source]

Stop the polling timer; the shared engine is left running.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor.magnet_controller import MagneticFieldMonitorPlugin
>>> m = MagneticFieldMonitorPlugin()
>>> m.stop_monitoring()
>>> m.disconnect()
field() → float[source]

Return the current magnetic field in tesla.

Returns:

Magnetic field in tesla, or math.nan when unavailable.

Return type:

(float)

field_rate() → float[source]

Return the field ramp rate in tesla per minute.

Returns:

Field ramp rate in T/min, or math.nan when unavailable.

Return type:

(float)

heater() → float[source]

Return the persistent-switch heater state.

Returns:

1.0 when the heater is on, 0.0 when it is off, or math.nan when unavailable.

Return type:

(float)

property name: str

Unique human-readable name for this plugin.

property quantity_names: list[str]

Ordered list of parameter keys returned by read().

Returns:

Parameter identifiers for all currently enabled outputs.

Return type:

(list[str])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor.magnet_controller import MagneticFieldMonitorPlugin
>>> m = MagneticFieldMonitorPlugin()
>>> "field" in m.quantity_names
True
read(*, force_poll: bool = False) → dict[str, float][source]

Read the latest parameter snapshot from the engine.

By default retrieves the engine’s cached state without issuing additional hardware queries. When force_poll is True the engine performs an immediate hardware poll and the freshly read state is used, making the call synchronous with the hardware.

Keyword Parameters:

force_poll (bool) – When True, requests an immediate hardware poll from the engine before returning values. Defaults to False.

Returns:

Mapping of parameter name to current value. Returns math.nan for any parameter that cannot be obtained from the engine state.

Return type:

(dict[str, float])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor.magnet_controller import MagneticFieldMonitorPlugin
>>> m = MagneticFieldMonitorPlugin()
>>> reading = m.read()
>>> "field" in reading
True
>>> reading_forced = m.read(force_poll=True)
>>> "field" in reading_forced
True
stable() → float[source]

Return whether the magnetic field is stable.

Returns:

1.0 when stable or 0.0 otherwise.

Return type:

(float)

target_field() → float[source]

Return the current target magnetic field in tesla.

Returns:

Target magnetic field in tesla, or math.nan when unavailable.

Return type:

(float)

target_field_rate() → float[source]

Return the programmed field ramp rate in tesla per minute.

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

Serialise plugin configuration to a JSON-compatible dict.

Returns:

Serialised configuration.

Return type:

(dict[str, object])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor.magnet_controller import MagneticFieldMonitorPlugin
>>> m = MagneticFieldMonitorPlugin()
>>> d = m.to_json()
>>> d["report_field"]
True
property units: dict[str, str]

Mapping of parameter name to physical unit string.

Returns:

Unit strings for each enabled parameter.

Return type:

(dict[str, str])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor.magnet_controller import MagneticFieldMonitorPlugin
>>> m = MagneticFieldMonitorPlugin()
>>> m.units["field"]
'T'
>>> m.units["current"]
'A'
voltage() → float[source]

Return the current magnet voltage in volts.

Returns:

Magnet voltage in volts, or math.nan when unavailable.

Return type:

(float)