stoner_measurement.plugins.trace.function_trace.FunctionTracePlugin¶
- class stoner_measurement.plugins.trace.function_trace.FunctionTracePlugin(parent=None)[source]¶
Bases:
TracePluginCalculate 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), wherexis the one-dimensional NumPy array produced by the selected scan generator.calculate_datamust return apandas.DataFramewith exactly one row for every value inxand at least one uniquely named column. The column namexis 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 providesnumpyasnpandnumpy, andpandasaspdandpandas; imports and helper functions may also be included in the editor.User code is compiled at acquisition time. A missing or non-callable
calculate_datafunction, 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_tracein 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