stoner_measurement.plugins.command.plot_trace.PlotTraceCommand¶
- class stoner_measurement.plugins.command.plot_trace.PlotTraceCommand(parent=None)[source]¶
Bases:
CommandPluginPlot a complete trace dataset in the main plot window.
Use this command when you want to send an already measured trace to the plot window in one step. This is most commonly used after a trace plugin has finished collecting a sweep, but it can also be used to plot derived or transformed traces.
Plot form defaults to XY, preserving existing saved sequences. A capable display also offers XYZ, XY intensity, and XYZ + value. These forms use separate X and measured-Z channel selectors or expressions, plus a Fixed Y expression evaluated once for each execution. Successive traces form slices of one rectilinear surface. The optional independent value controls colour without changing the meaning of geometric Z.
Surface and acquisition identities are string expressions, independent of the displayed title. The slice identity defaults to the exact fixed-Y value. Repeated cells/slices are rejected unless replace is selected. Clear the plot for a new run, or change the acquisition identity and explicitly enable reset. Slices retain the initial X grid; unacquired cells remain gaps. Additional controls specify fixed-Y metadata, uncertainties and explicit angular coordinate conventions. Existing XY transpose/axis controls apply only to XY. Available forms and axes refresh when the display changes; an unsupported saved form remains visible with its bindings preserved.
Selecting Polar (angle, radius) uses an independent Angle data array followed by a dependent Radius data array, for example motor position and resistance. Source angles default to degrees, with radians selectable. Polar controls include uncertainties, title/series-ID expressions, zero direction, clockwise orientation, wrapping and line/point styles. Samples retain acquisition order; repeat the initial sample to close a full circle. Polar settings are independent of the saved XY and surface bindings.
In the configuration panel you can use two modes:
Simple mode: select a trace from the trace catalogue. Optionally choose a specific y-column, transpose x and y, select plot axes, and set plotting style options.
Advanced mode: provide separate expressions for x data, y data, and the plot title. This is useful when you want to combine data from different traces or channels.
In surface forms, Surface X grid defaults to averaging repeated X and interpolating later rows onto the first row’s grid. First/last-sample modes select repeated samples in acquisition order; strict mode requires unique, matching X. Outside X range defaults to the nearest valid boundary value, with a leave-gaps option. These controls prepare plotting samples; the original acquired trace remains intact. Averaging combines sweep branches.
If the selected trace includes metadata for axis names, units, or error bars, this information is used automatically in simple mode. Optional axis names and trace styling let you send traces to custom axes or control how they appear in the plot.
For script-oriented use,
execute()emits either theplot_tracesignal (advanced mode) or theplot_trace_with_errorssignal (simple mode) with the resolved title string, x/y arrays, and optional error-bar arrays. Thesequence_enginesetter automatically wires these signals to the engine’splot_widgetso that the data appears in the main plot window without any manual signal management in the application code.- Variables:
plot_form (str) – xy, polar, xyz, xy_intensity or xyz_value; defaults to xy.
polar_radius_expr (polar_angle_expr,) – Runtime arrays for the independent angle and dependent radius.
polar_radius_error_expr (polar_angle_error_expr,) – Optional matching uncertainty arrays in the source units.
polar_settings (dict) – Angular units (degrees by default), origin, clockwise and wrapping. Zero defaults to the top and increasing angles run clockwise.
polar_title_expr (polar_id_expr,) – Runtime series identity and title. The default ID is unique and persistent; repeated execution replaces the same angular trace.
polar_style (dict) – Independent colour, line/point style and size overrides.
z_expr (new_x_expr,) – Separate runtime array expressions for additional forms. Catalogue selections store their expressions; auxiliary roles do not imply Z.
fixed_y_expr (str) – Runtime scalar second coordinate, broadcast to the X/Z row count.
fixed_y_unit (fixed_y_label,) – Physical label/unit for the second coordinate when not derivable.
value_expr (str) – Independent array expression used only by xyz_value.
regrid_policy (str) – Surface rows sort/merge X and interpolate onto the first row’s grid. mean (default) averages repeated X; first/last selects samples in acquisition order. strict requires unique, exactly matching X. Round-off-equivalent X values are grouped. Acquired data is unchanged.
regrid_bounds (str) – nearest (default) holds the closest valid boundary value outside the measured X range; missing leaves gaps. Internal NaN gaps remain.
acquisition_id_expr (surface_id_expr,) – Runtime string identities. New instances have a unique surface ID; an empty surface expression generates and saves a unique ID on load or execution, shared by subsequent slices from this command. Acquisition defaults to ‘default’. Titles never determine grouping.
slice_id_expr (str) – Optional runtime string identity; empty uses the exact fixed Y.
duplicate_policy (str) – reject (default) or replace complete repeated slices.
reset_on_change (bool) – Permit changed acquisition identities to reset a surface; default False.
coordinate_settings (dict) – CoordinateDescriptor fields: system, angular_unit, wrapping, angular_origin, clockwise and explicit spherical_convention.
z_error_expr (new_x_error_expr,) – Optional uncertainty-array expressions for the selected source slots.
trace_key (str) – Key in the
_tracescatalogue for simple mode. Format is"{instance_name}:{channel_name}". Defaults to"".column_key (str) – When non-empty, selects a specific DataFrame column from the named trace for plotting. When empty all
COLUMN_ROLE_Ycolumns are plotted. Defaults to"".transpose (bool) – When
True(simple mode only), swap the x and y arrays — and their respective error bars and axis labels — before emitting the plot signal. Defaults toFalse.advanced_mode (bool) – When
True,x_expr,y_exprandtitle_exprare used instead oftrace_key. Defaults toFalse.x_expr (str) – Python expression (evaluated against the engine namespace) that produces the x-axis data array in advanced mode. Defaults to
"".y_expr (str) – Python expression (evaluated against the engine namespace) that produces the y-axis data array in advanced mode. Defaults to
"".title_expr (str) – Python expression evaluated via
eval()to obtain the plot trace title in advanced mode. Defaults to"'plot'".plot_trace (pyqtSignal[str, object, object]) – Emitted by
execute()in advanced mode with(title, x_array, y_array). Automatically connected toset_trace()when the plugin is attached to an engine with a plot widget.plot_trace_with_errors (pyqtSignal[str, object, object, object, object]) – Emitted by
execute()in simple mode with(title, x_array, y_array, x_err, y_err)where x_err and y_err may beNonewhen no error columns are present. Automatically connected toset_trace_with_errors()when the plugin is attached to an engine with a plot widget.plot_axis_labels (pyqtSignal[AxisLabel, AxisLabel]) – Emitted by
execute()in simple mode with structured(x_label, y_label)quantity/unit metadata derived fromTraceDatametadata. Automatically connected toset_default_axis_labels()when the plugin is attached to an engine with a plot widget.plot_trace_axes (pyqtSignal[str, str, str]) – Emitted by
execute()with(trace_name, x_axis_name, y_axis_name)when the configured axes are available. Automatically connected toassign_trace_axes()when attached to an engine with a plot widget.colour (str) – Colour for the plotted trace, specified as any value accepted by pyqtgraph (e.g.
"red","#0000ff"). An empty string (the default) lets the plot panel choose a colour automatically.line_style (str) – Line style for the plotted trace. One of
"solid","dash","dot","dash-dot", or"none". An empty string (the default) uses the plot panel default ("solid").point_style (str) – Marker symbol for data points. One of
"none","circle","square","triangle","diamond","plus", or"cross". An empty string (the default) uses the plot panel default ("none").line_width (float) – Width of the plotted line in pixels. A value of
0.0(the default) lets the plot panel use its own default width.point_size (float) – Size of the plotted point markers in pixels. A value of
0.0(the default) lets the plot panel use its own default size.plot_trace_style (pyqtSignal[str, object]) – Emitted by
execute()with(trace_name, style_dict)after data is sent to the plot widget. Automatically connected toset_trace_style_from_dict()when the plugin is attached to an engine with a plot widget.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.
- Keyword Parameters:
parent (QObject | None) – Optional Qt parent object.
Examples
With an instance named
plot_tracein the sequence, use the QtConsole to inspect or edit it before running. Substitute your instance name if different; result data reflects completed steps:plot_trace.trace_key = "dummy:Dummy" plot_trace.transpose = False
With Polar traces selected in the View menu and
angle_tracealready available in the live namespace:plot_trace.plot_form = "polar" plot_trace.polar_angle_expr = "angle_trace.x" plot_trace.polar_radius_expr = "angle_trace.y" plot_trace.polar_settings = { "angular_unit": "degrees", "angular_origin": 90, "clockwise": True, }
For an installed display advertising surface assembly:
plot_trace.plot_form = "xyz" plot_trace.new_x_expr = "field_trace.x" plot_trace.z_expr = "field_trace.y" plot_trace.fixed_y_expr = "temperature.current_value" plot_trace.surface_id_expr = "'field-temperature'"
- config_widget(parent: QWidget | None = None) QWidget[source]¶
Return a settings widget for configuring the plot-trace command.
The widget contains:
A Trace dropdown (simple mode) — populated from the current
_tracescatalogue in the engine namespace.A Column dropdown (simple mode) — selects which data column from the trace to plot. Populated from the columns of the selected trace when available; defaults to the first
"y"-role column.An Advanced mode checkbox — toggles between simple and advanced configuration.
An X data dropdown (advanced mode) — selects the array to use as the horizontal axis; populated from
{trace_key}.xand{trace_key}.yentries for every trace in the catalogue.A Y data dropdown (advanced mode) — selects the array to use as the vertical axis.
A Title expression line edit (advanced mode) — a Python expression evaluated to produce the plot title at runtime.
The simple-mode trace and column dropdowns are disabled (greyed out) when advanced mode is active; the advanced-mode controls are disabled when advanced mode is inactive.
- Keyword Parameters:
parent (QWidget | None) – Optional Qt parent widget.
- Returns:
The settings widget for the PlotTrace configuration tab.
- Return type:
(QWidget)
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.command.plot_trace import PlotTraceCommand >>> from qtpy.QtWidgets import QWidget >>> isinstance(PlotTraceCommand().config_widget(), QWidget) True
- execute() None[source]¶
Retrieve trace data from the engine namespace and emit plot signals.
In simple mode the trace named by
trace_keyis looked up in the_tracesnamespace catalogue. Whencolumn_keyis set a single column is plotted. Whencolumn_keyis empty and the trace has multipleCOLUMN_ROLE_Ycolumns, every such column is plotted as a separate named trace (title"{trace_key}:{col_name}"). Error bars are derived positionally: the i-thCOLUMN_ROLE_Ecolumn is used as symmetric y-error bars for the i-thCOLUMN_ROLE_Ycolumn; the firstCOLUMN_ROLE_Dcolumn (if any) is used as symmetric x-error bars shared across all y-columns. Theplot_trace_with_errorssignal is emitted for each plotted column.In advanced mode
x_expr,y_expr, andtitle_exprare each evaluated against the engine namespace viaeval()and theplot_tracesignal(title, x_array, y_array)is emitted.Warnings are logged and execution is skipped if required data are missing or expressions are empty.
- Raises:
RuntimeError – If the plugin is not attached to a sequence engine.
TimeoutError – If the plot widget does not acknowledge a queued data update before the response timeout expires.
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.command.plot_trace import PlotTraceCommand >>> from stoner_measurement.core.sequence_engine import SequenceEngine >>> import numpy as np >>> engine = SequenceEngine() >>> cmd = PlotTraceCommand() >>> engine.add_plugin("plot_trace", cmd) >>> received = [] >>> cmd.plot_trace.connect(lambda t, x, y: received.append((t, x, y))) >>> engine._namespace["my_x"] = np.array([1.0, 2.0]) >>> engine._namespace["my_y"] = np.array([3.0, 4.0]) >>> cmd.advanced_mode = True >>> cmd.x_expr = "my_x" >>> cmd.y_expr = "my_y" >>> cmd.title_expr = "'My Plot'" >>> cmd.execute() >>> received[0][0] 'My Plot' >>> engine.shutdown()
- property name: str¶
Unique identifier for the plot-trace command.
- Returns:
"Plot Trace".- Return type:
(str)
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.command.plot_trace import PlotTraceCommand >>> PlotTraceCommand().name 'Plot Trace'
- plot_axis_labels¶
Signal emitted by execute() in simple mode — (x_label, y_label).
- plot_context_changed¶
Signal emitted when the owning engine/client endpoint changes.
- plot_ensure_x_axis¶
Signal emitted by execute() to ensure x-axis exists — (axis_name, axis_label).
- plot_ensure_y_axis¶
Signal emitted by execute() to ensure y-axis exists — (axis_name, axis_label).
- plot_trace¶
XY data signal; additional forms submit complete portable requests.
- plot_trace_axes¶
Signal emitted by execute() — (trace_name, x_axis_name, y_axis_name).
- plot_trace_style¶
Signal emitted by execute() to set trace style — (trace_name, style_dict).
- plot_trace_with_errors¶
Signal emitted by execute() in simple mode — (title, x_array, y_array, x_err, y_err).
- plot_update_queued¶
Signal emitted by execute() before each queued trace update.
- property sequence_engine: SequenceEngine | None¶
Active sequence engine, or
Nonewhen the plugin is detached.Overrides the class-level attribute defined in
BasePluginwith a full property so that the setter can automatically connect theplot_traceandplot_axis_labelssignals to the engine’splot_widgetwhenever the engine reference changes.- Returns:
The owning engine, or
Noneif not attached.- Return type:
(SequenceEngine | None)
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.command.plot_trace import PlotTraceCommand >>> from stoner_measurement.core.sequence_engine import SequenceEngine >>> engine = SequenceEngine() >>> cmd = PlotTraceCommand() >>> cmd.sequence_engine is None True >>> engine.add_plugin("plot_trace", cmd) >>> cmd.sequence_engine is engine True >>> engine.shutdown()
- to_json() dict[str, Any][source]¶
Serialise the plot-trace command configuration to a JSON-compatible dict.
- Returns:
Base dict from
to_json()extended with"trace_key","transpose","advanced_mode","x_expr","y_expr","title_expr", and format fields"colour","line_style","point_style","line_width", and"point_size".- Return type:
Examples
>>> from qtpy.QtWidgets import QApplication >>> _ = QApplication.instance() or QApplication([]) >>> from stoner_measurement.plugins.command.plot_trace import PlotTraceCommand >>> d = PlotTraceCommand().to_json() >>> d["type"] 'command' >>> "trace_key" in d and "advanced_mode" in d True >>> "colour" in d and "line_style" in d True