stoner_measurement.plugins.trace.function_trace.FunctionTracePlugin

class stoner_measurement.plugins.trace.function_trace.FunctionTracePlugin(parent=None)[source]

Bases: TracePlugin

Calculate a synthetic trace by passing scan values to Python code.

Use this hardware-free trace plugin to test sequences, plotting, saving, transforms, and other application workflows with arbitrary reproducible data. The Scan page is the standard trace-plugin scan-generator page. The Function page defines calculate_data(x), where x is the one-dimensional NumPy array produced by the selected scan generator.

calculate_data must return a pandas.DataFrame with exactly one row for every value in x and at least one uniquely named column. The column name x is reserved: the plugin inserts the scan values as that column. The first returned column is the primary y channel and subsequent columns are auxiliary channels. All returned columns must contain numeric values. The execution namespace provides numpy as np and numpy, and pandas as pd and pandas; imports and helper functions may also be included in the editor.

User code is compiled at acquisition time. A missing or non-callable calculate_data function, an invalid return type, duplicate/reserved columns, non-numeric data, or a row-count mismatch raises an informative exception and puts the trace plugin into its standard error state.

Variables:
  • function_code (str) – Complete trusted Python source executed for each acquisition.

  • scan_generator (BaseScanGenerator) – Standard configurable generator that supplies x.

  • data (dict[str, TraceData]) – Latest successful trace, keyed by "Function Trace".

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

  • status (TraceStatus) – Inherited acquisition status, including data availability and errors.

Warning

The source is executed as normal Python and is not sandboxed. Only run code from trusted sequence files.

Keyword Parameters:

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

Examples

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

function_trace.function_code = (
    "def calculate_data(x):\n"
    "    return pd.DataFrame({'signal': 2 * x})\n"
)
function_trace.data
config_tabs(parent: QWidget | None = None) → list[tuple[str, QWidget]][source]

Return the standard Scan page followed by Function and About.

property name: str

Return the plugin and output trace display name.

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

Serialise the scan generator and calculation source.