# Accessing Variables in Python User-Operator Scripts

## Input Variables

When Infiniium starts a user-operator script, the following variables are passed to the script as key:value pairs in a dictionary. Any variables that you defined with the <Variable> XML element are also passed to the script as well as any user-defined control variables that you defined with the <Integer>, <Double>, <Enumeration>, <String>, or <File> XML elements. For example, your script will start with the function definition shown below. The input variables are passes in the variables dictionary. In the second line, the function uses the SrcData dictionary key to assign the value which is the input waveform to the SrcData variable.

    def algorithm(variables):
        SrcData = variables['SrcData']
        …
        …

In your script, you can print the output variables to the Show Output window as demonstrated in Lesson 2 and explained in Troubleshooting Python scripts.

Each input variable, except for SoftwareVersion, listed in the following table has four forms. The one listed is for a single input waveform or the first waveform in a multiple-input waveform function. If second, third, or fourth input waveforms exist, their variables have "2", "3", or "4" appended. For example, the SrcData2 variable is used for the second waveform, the SrcData3 variable for the third waveform, and the SrcData4 variable is used for the fourth waveform.

Input Variables
Dictionary keys | Type | Description
--- | --- | ---
SrcData | numpy.ndarray | The input waveform. Values are in volts for electrical signals and Watts for optical signals. Example key: value pair:
    'SrcData': array([-2.24755, -0.246670, -0.251945, …, 0.24080, 0.24792, 0.2524])
SrcDataFile | string | When file-base I/O is used (see File-Based I/O in Python), this variable is used instead of the SrcData variable.
Source | string | The source of the input waveform. Example key: value pair: 'Source': 'Channel 2'
XOrg | float | The time of the first x-axis value of the input waveform value of SrcData. Example key: value pair: 'XOrg': 8.785e-11
XInc | float | The spacing of the x-axis input waveform values of SrcData. Example key: value pair: 'XInc': 2.232e-13
XUnits | string | The X units associated with the input waveform. Refer to Valid Measurement Units. Example key: value pair: 'XUnits': 'Second'
YUnits | string | The Y units associated with the input waveform. Refer to Valid Measurement Units. Example key: value pair: 'YUnits': 'Volt'
SymbolRate | float | The current value of the 'SymbolRate' control. Example key: value pair: 'SymbolRate': 9953280000.0
SrcClipped | boolean | Set to True if the source data was clipped high or low; otherwise set to False. Example key: value pair: 'SrcClipped': True
ClipHigh | float | The maximum value that could be present in the source waveform. If SrcClipped is True, check to see which elements of SrcData are equal to ClipHigh to determine which elements were clipped. Example key: value pair: 'ClipHigh': 0.51057
ClipLow | float | The minimum value that could be present in the source waveform. If SrcClipped is True, check to see which elements of SrcData are equal to ClipLow to determine which elements were clipped. Example key: value pair: 'ClipLow': -0.510869
IsAvgComplete | boolean | Flag tells if waveform averaging is complete. Set to True if complete, otherwise False if not complete. Example key: value pair: 'IsAvgComplete': True
AvgAcqCount | long | The current value of the 'Number of Averages' control in the Averaging tab of the Acquisition dialog if averaging is enabled, otherwise its value is 1. The value is an unsigned long integer in Python. Example key: value pair: 'AvgAcqCount': 1L
SourceBw | float | The bandwidth of the input source. Example key: value pair: 'SourceBw': 150000000000.0
SignalType | string | The signal type of the input source (for example, Unspecified, NRZ, PAM4, etc.). Example key: value pair: 'SignalType': 'NRZ'
YMiddle | float | The Y middle of the display of the input source.
YDispRange | float | The Y range of the display of the input source.
SoftwareVersion | string | The Infiniium software version that is being run.
Markers | list of dictionaries | Marker information if markers are on source waveform. If a marker is not on, it is not included in the list. Example key: value pair:
    'Markers': [
    {'Status': 'Correct','Source': 'Channel 2','Name': 'X1,'Position': 1.01033e-10},
    {'Status': 'Correct','Source': 'Channel 2','Name': 'X2,'Position': 1.28445e-10},
    {'Status': 'Correct','Source': 'Channel 2','Name': 'X3,'Position': 1.50625e-10},
    {'Status': 'Correct','Source': 'Channel 2','Name': 'X4,'Position': 1.78664e-10}]

## Output Variables

This topic lists the variables whose values are returned to Infiniium when your script completes. The top three variables listed in the table must be set in your script. The remaining variables may be used, if needed.

Variables Output From Script
Variable | Type | Description
--- | --- | ---
Variables that must be returned by your script
FiltData | list | Output waveform.
FiltDataFile |  | When file-base I/O is used (see File-Based I/O in Python), this variable is used instead of the FiltData variable.
XOrg | float | The time of the first x-axis value of FiltData.
XInc | float | The spacing of the x-axis values of FiltData.
Optional variables that can be returned by your script
Gain | float | Signal gain of operators that have one input.
FilterWidth | float | Filter width.
FilterDelay | float | Filter delay.
XUnits | string | The X units associated with the output waveform's x-axis. Refer to Valid Measurement Units.
YUnits | string | The Y units associated with the output waveform's y-axis. Refer to Valid Measurement Units.
ErrorMsg | string | Any generated Infiniium error message.