Script Calculation

Capturing User Input

The user input is available in the Input and Parameter objects in the script namespace.  It is acceptable to manipulate the input series; this will not change the original data in the workspace.

Processing Data

Refer to the following sections for EMGscript specific functions for manipulating data.  EMGscript is a superset of JavaScript, so any valid JavaScript syntax may be used.  Objects are automatically garbage collected.  Series objects are disk-backed and consume a fixed, small amount of memory not proportional to the number of samples they contain, so processing large data files is seamless and convenient.  All EMGscript extensions to the JavaScript syntax that return a series will clone the original series, so subsequent operations will not modify the original series.

Outputting Data

Assign processed data to the Output member of the script namespace.  Only data series may be outputted.

Run-Time Exceptions

At times, it may be impossible to complete a calculation because of the nature of the data being processed.  It is recommended, where possible, to use the Validate function to check user input.  However, if this is very computationally costly, a script can abort mid-execution by throwing an exception string.  The other data (if any) select by the user will continue to be processed, and the error string will be displayed to the user.  An example of this idiom is shown below.

if(typeof y == 'undefined')

     throw "The selected threshold level did not result in any detections";