Extract every n-th element from an array.
arr
Array<number> Input array.size
number Step size. (optional, default 1
)idx
number Starting point. (optional, default 0
)ArrayNth( [ 1, 2, 3, 4, 5, 6], 2, 2 );
// returns [3, 5]
Returns **(Array<number> | void)** Every n-th element. |
This is a flexible function to generate an array of arithmetic progressions. All arguments must be integers.
start
number Start value. (optional, default 0
)stop
number Stop value.step
number Step size. (optional, default 1
)transform **("none" |
"log" |
"ln" |
"x2" )** Generate a progression and transform numbers. (optional, default "none" ) |
ArrayRange(10);
// returns [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
ArrayRange(1,11);
// returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ArrayRange(0, 30, 5);
// returns [0, 5, 10, 15, 20, 25]
ArrayRange(0, 10, 3);
// returns [0, 3, 6, 9]
ArrayRange(0, 10, 3, "x2");
// returns [0, 9, 36, 81]
ArrayRange(0, -10, -1);
// returns [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
ArrayRange(0);
// returns []
ArrayRange(1,0);
// returns []
Returns **(Array<number> | void)** |
This function transforms an array of [x, y] pairs into an object with an array of x and an array of y values
ArrayUnZip( [ [1, 4], [2, 5], [3, 6] ] );
//returns {x: [1, 2, 3], y: [4, 5, 6]}
Returns **(object | void)** { x: [x1, x2, …, xn], y: [y1, y2, …, yn] } |
This function transforms two arrays into one array of x,y pairs Both arrays supplied need to have the same size.
var x = [1, 2, 3];
var y = [4, 5, 6];
ArrayZip(x,y)
//returns [ [1, 4], [2, 5], [3, 6] ]
Returns **(Array<number> | void)** [ [x1,y1], [x2,y2], …, [xn,yn] ]. |
Add a Danger Message for the User. These messages will be shown in the data viewer as well. Use these messages to indicate a problematic issue that will most likely result in an invalid measurement.
danger('Your Danger Message', output);
// output['messages']['info']['Your Danger Message']
Returns object pushes the message into the output object.
Find the positions for protocols within a protocol set matching the provided label. If only one label exists within a set, a number is returned. When multiple protocols in the set have the same label an array with all indexes of matching labels is returned.
label
string Label from the protocol setjson
Object Required! The protocol contentarray
boolean Always return an array (optional, default false
)GetIndexByLabel( "PAM", json );
// returns e.g. 1 or [1,2]
GetIndexByLabel( "PAM", json, true );
// returns e.g. [1] or [1,2]
Returns **(number | Array<number>)** Single index or an array of indexes |
Generate a protocol lookup table for a protocol set.
json
objectGetLabelLookup(json);
// returns e.g. { "PAM": [0,2], "ECS": [1]}
Returns object Lookup table
Returns the protocol from within the protocol set matching the provided label. If only one label exists, one protocol object is returned. When multiple protocols in the set have the same label an array with all protcol objects of matching labels is returned.
label
string The label from the protocol setjson
Object Required! The protocol contentarray
boolean Always return an array (optional, default false
)GetIndexByLabel( "PAM", json );
// returns e.g. { "label": "PAM", ...} or [{ "label": "PAM", ...}, { "label": "PAM", ...}]
GetIndexByLabel( "PAM", json, true );
// returns e.g. [{ "label": "PAM", ...}] or [{ "label": "PAM", ...}, { "label": "PAM", ...}]
Returns **(Object | Array<Object>)** Single protocol or an array of protocols |
Add an Info Message for the User. Use these messages to give additional information (if necessary).
info('Your Info Message', output);
// output['messages']['info']['Your Info Message']
Returns object pushes the message into the output object.
Math.abs(x) returns the absolute value of x.
x
numberMath.abs(4.7);
// returns 5
Math.abs(4.4);
// returns 4;
Returns number
Math.acos(x) returns the arccosine of x, in radians.
x
numberMath.acos(0.5);
// returns 1.0471975511965979
Returns number
Math.asin(x) returns the arcsine of x, in radians.
x
numberMath.asin(0.5);
// returns 0.5235987755982989
Returns number
Math.atan(x) returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians.
x
numberMath.atan(0.5);
// returns 0.4636476090008061
Returns number
Math.atan2(y, x) returns the arctangent of the quotient of its arguments.
Math.atan2(0.5,2);
// returns 0.24497866312686414
Returns number
Math.ceil(x) returns the value of x rounded up to its nearest integer.
x
numberMath.ceil(4.7);
// returns 5
Returns number
Math.cos(x) returns the cosine of x (x is in radians).
x
numberMath.cos(1);
// returns 0.5403023058681398
Returns number
Euler’s number (approx. 2.718).
Math.E;
// returns 2.718281828459045
Returns number 2.718281828459045
Math.exp(x) returns the value of Ex.
x
numberMath.exp(3);
// returns 20.085536923187668
Returns number
Math.floor(x) returns the value of x rounded down to its nearest integer.
x
numberMath.floor(4.7);
// returns 4
Returns number
Natural logarithm of 10 (approx. 2.302).
Math.LN10;
// returns 2.302585092994046
Returns number 2.302585092994046
Natural logarithm of 2 (approx. 0.693).
Math.LN2;
// returns 0.6931471805599453
Returns number 0.6931471805599453
Math.log(x) returns the natural logarithm (base E) of x.
x
numberMath.log(4.7);
// returns 1.547562508716013
Returns number
Base-10 logarithm of E (approx. 0.434).
Math.LOG10E;
// returns 0.4342944819032518
Returns number 0.4342944819032518
Base-2 logarithm of E (approx. 1.442).
Math.LOG2E;
// returns 1.4426950408889634
Returns number 1.4426950408889634
Math.max(x, y, z, …, n) returns the number with the highest value.
x
numberMath.max(0, 150, 30, 20, -8, -200);
// returns 150
Returns number
Math.min(x, y, z, …, n) returns the number with the lowest value.
x
numberMath.min(0, 150, 30, 20, -8, -200);
// returns -200
Returns number
PI (approx. 3.14)
Math.PI;
// returns 3.141592653589793
Returns number 3.141592653589793
Math.pow(x, y) returns the value of x to the power of y.
Math.pow(3,2);
// returns 9
Returns number
Random number
Math.random();
// returns a random number
Returns number between 0 and 1
Math.round(x) returns the value of x rounded to its nearest integer.
x
numberMath.round(4.7);
// returns 5
// Math.round(4.4);
// returns 4
Returns number
Math.sin(x) returns the sine of x (x is in radians).
x
numberMath.sin(1);
// returns 0.8414709848078965
Returns number
Math.sqrt(x) returns the square root of x.
x
numberMath.sqrt(2);
// returns 1.4142135623730951
Returns number
Square root of 1/2 (approx. 0.707).
Math.SQRT1_2;
// returns 0.7071067811865476
Returns number 0.7071067811865476
Square root of 2 (approx. 1.414).
Math.SQRT2;
// returns 1.4142135623730951
Returns number 1.4142135623730951
Math.tan(x) returns the tangent of an angle.
x
numberMath.tan(1);
// returns 1.5574077246549023
Returns number
Fit exponential decay to Y = Y0 + Ae^(-x/t) A and t are the fitted variables, the provided input array needs to be an array of x,y pairs.
MathEXPINVREG( [ [x1,y1], [x2,y2], ..., [xn,yn] ] );
// returns
{
"points": [ [x1,y1], [x2,y2], ..., [xn,yn] ],
"results": [A, t],
"error": yError,
"asymptote": asymptote,
"rsquared": linReg.rsquared,
"lifetime": lifetime,
"slope": slope
}
Returns object Results from fit including points, values for A and t, error, asymptote, rsquared, lifetime, slope.
Function to perform a simple linear regression (y = mx +b), returning slope, y-intercent, correlation coefficient (R) and coefficient of determination (R²).
MathLINREG([60,61,62,63,65], [3.1,3.6,3.8,4,4.1]);
// returns {
// "m": 0.188, // slope
// "b": -7.964, // y intercept
// "r": 0.912, // correlation coefficient
// "r2": 0.832 // coefficient of determination
}
Returns object Linear regression results
Returns the natural logarithm (base E) of a number.
value
numberMathLN(10);
// returns 2.302585092994046
Returns number
Returns the logarithm (base 10) of a number.
value
numberMathLOG(10);
// returns 1
Returns number
Get the maximum value from an array of numbers. The function fails if the array is empty or has invalid values.
MathMAX([1,2,3,4.5]);
// returns 4.5
Returns number
Calculate the mean from an array of numbers. The function fails if the array is empty or has invalid values.
MathMEAN([1,2,3,4.5]);
// returns 2.625
Returns number
Calculate the median from an array of numbers. The function fails if the array is empty or has invalid values.
MathMEDIAN([1,2,3,4.5]);
// returns 2.5
Returns number
Get the minimum value from an array of numbers. The function fails if the array is empty or has invalid values.
MathMIN([1,2,3,4.5]);
// returns 1
Returns number
Multiple Linear Regression
input_raw
Array<array> Array of x,y value pairs arrays [ [ [x1,y1], [x2,y2], …, [xn,yn] ], [ [x1,y1], [x2,y2], …, [xn,yn] ] ]MathEXPINVREG( [ [ [x1,y1], [x2,y2], ..., [xn,yn] ], [ [x1,y1], [x2,y2], ..., [xn,yn] ] ] );
// returns
{
"rsquared": rSq,
"slopes": [slope1, ...],
"points": [ [x1, x2, ..., xn], [y1, y2, ..., yn] ]
}
Returns object Returns rsquared, slopes and points.
Polynomial fit to y = a0 + a1x + a2x^2 + a3x^3….
input_raw
Array<array> Array of x,y value pairs arrays [ [ [x1,y1], [x2,y2], …, [xn,yn] ], [ [x1,y1], [x2,y2], …, [xn,yn] ] ]degree
size
degree degree.MathPOLYREG( [ [ [x1,y1], [x2,y2], ..., [xn,yn] ], [ [x1,y1], [x2,y2], ..., [xn,yn] ] ], degree );
// returns
{
"points": points,
"slopes": slopes,
"error": yError
}
Returns object Returns points, slopes and error
Calculate the variance from an array of numbers. The function fails if the array is empty or has invalid values.
MathROUND(1.23456789, 5);
// returns 1.2346
Returns number
Calculate the standard error from an array of numbers. The function fails if the array is empty or has invalid values.
MathSTDERR([1,2,3,4.5]);
// returns 0.6465050270492876
Returns number
Calculate the variance from an array of numbers. The function fails if the array is empty or has invalid values.
MathSTDEV([1,2,3,4.5]);
// returns 1.2930100540985752
Returns number
Calculate the variance from an array of numbers. The function fails if the array is empty or has invalid values.
MathSTDEVS([1,2,3,4.5]);
// returns 1.4930394055974097
Returns number
Calculate the sum from an array of numbers. The function fails if the array is empty or has invalid values.
MathSum([1,2,3,4.5]);
// returns 10.5
Returns number
Calculate the variance from an array of numbers. The function fails if the array is empty or has invalid values.
MathVARIANCE([1,2,3,4.5]);
// returns 2.2292
Returns number
Function to perform a non-linear regression.
data
object Data for the non-linear regression needs to be provided as an array of x,y pairs. [[x1,y1], [x2,y2], ..., [xn,yn]]
options
object
options.equation **(string |
function)** Select preset equation (string) or supply function |
options.initial
Array<number> Array with the initial guesses for parameters in equation [a, b, …, h]options.iterations
number Number of iterations (maximum 2000) (optional, default 200
)options.cPts
number? Number of datapointsoptions.cVar
number Number of independant variablesoptions.cPar
number Number of parametersoptions.RelaxF
number Fractional adjustment factor (Values smaller than 1 will make the covergence slower but more stable) (optional, default 1.0
)options.SEy **(1 |
"Y" |
"Sqrt(Y)" |
"w" |
"Rep" )** Standard Error associated with the Y variable (Equal 1 , Relative Y , Counts Sqrt(Y) , Data w , Replicates Rep (optional, default 1 ) |
options.yTrans **("Y" |
"LN(Y)" |
"SQRT(Y)" |
"1/Y" )** Transformation (optional, default "Y" ) |
options.x1Trans **("X1" |
"LN(X1)" |
"SQRT(X1)" |
"1/X1" )** Transformation (optional, default "X1" ) |
options.x2Trans **("X2" |
"LN(X2)" |
"SQRT(X2)" |
"1/X2" )** Transformation (optional, default "X2" ) |
options.x3Trans **("X3" |
"LN(X3)" |
"SQRT(X3)" |
"1/X3" )** Transformation (optional, default "X3" ) |
options.x4Trans **("X4" |
"LN(X4)" |
"SQRT(X4)" |
"1/X4" )** Transformation (optional, default "X4" ) |
options.x5Trans **("X5" |
"LN(X5)" |
"SQRT(X5)" |
"1/X5" )** Transformation (optional, default "X5" ) |
options.x6Trans **("X6" |
"LN(X6)" |
"SQRT(X6)" |
"1/X6" )** Transformation (optional, default "X6" ) |
options.x7Trans **("X7" |
"LN(X7)" |
"SQRT(X7)" |
"1/X7" )** Transformation (optional, default "X7" ) |
options.x8Trans **("X8" |
"LN(X8)" |
"SQRT(X8)" |
"1/X8" )** Transformation (optional, default "X8" ) |
options.Centered
boolean Centered Approximation to Partial Derivatives (optional, default false
)options.LeastAbs
boolean Least-Absolute -Value curve fitting (optional, default false
)options.cPctile
number Percentile (optional, default 50
)NonLinearRegression(
[
[x1, y1],
[x2, y2],
...,
[xn, yn]
],
{
equation: "b + a * e(- x / c)",
initial: [a, b, c]
}
)
// Available equations
// "b + a * e(- x / c)"
// "( a - c ) * e( - b * t ) + c"
// "( c + a / ( 1 + b / x ) )"
// "( c + a * a / ( 1 + b / x ) )"
// returns
// {
// text: <string>,
// ParameterEstimates: <string>,
// CovarianceMatrix: <string>,
// r2: <number>
// parameters: {
// name: <string>,
// value: <number>,
// sd_error: <number>,
// p: <number>
// },
// RMS_error: <number>,
// presets: <object>,
// iterations: <number>,
// RMS_errors: <array>
// }
// Use a custom fitting function
// The function can contain the following parameters:
// x, t, a, b, c, .. h
// Not all parameters have to be defined and they can
// be in a random order. Use parameter names in alphabetical
// order (e.g. a and b, a and c without b will not work)
var decay = function(x,a,b,c){
return b + a * Math.exp( -x / c );
};
NonLinearRegression(
[
[x1, y1],
[x2, y2],
...,
[xn, yn]
],
{
equation: decay,
initial: [a, b, c]
}
)
// The returned object has the same structure as object in
// in the previous example.
Returns object
The function transforms a given array by providing a second same length array, or a single number.
fn **("add" |
"subtract" |
"multiply" |
"divide" |
"+" |
"-" |
"*" |
"/" |
"normToMin" |
"normToMax" |
"normToRange" |
"normToIdx" |
"normToVal" |
"ma" |
"sgf" |
"abs" |
"absorbance" |
"absolute" )** Available functions to transform the input array. |
a1
Array<number> Input array.a2 **(number |
Array<number>)?** Second array or single number |
TransformTrace('subtract', [1, 2, 3, 4], [0, 1, 2, 1]);
// returns [1, 1, 1, 3]
TransformTrace('add', [1, 2, 3, 4], [0, 1, 2, 1]);
// returns [1, 3, 5, 5]
TransformTrace('add', [1, 2, 3, 4], 5);
// returns [6, 7, 8, 9]
TransformTrace('normToMin', [1.5, 2, 3, 4]);
// returns [1, 1.3333, 2, 2.6665]
TransformTrace('normToMax', [1.5, 2, 3, 4]);
// returns [0.375, 0.5, 0.75, 1]
TransformTrace('normToRange', [1.5, 2, 3, 4]);
// returns [0, 0.2, 0.6, 1]
TransformTrace('normToIdx', [1.5, 2, 3, 4], 1);
// returns [0.75, 1, 1.5, 2]
TransformTrace('normToVal', [1, 2, 3, 4], 2);
// returns [0.75, 1, 1.5, 2]
// Smoothing (ma= Moving average, sgf= Savitzky-Golay filter)
TransformTrace('ma', [1.5, 2, 3, 4]);
// returns [1.6667, 2.1665, 3, 3.6665]
TransformTrace('sgf', [1,2,3,4,3,2,1,1]);
// returns [1.3333333333333333,1.9523809523809523]
// Absorbance (abs) -log(I/I0)
// In case no value is provided, I0 is the fist value from the array
TransformTrace('abs', [1.5, 2, 3, 4]);
// returns [-0, -0.12494, -0.30103, -0.42597]
TransformTrace('absorbance', [1.5, 2, 3, 4]);
// returns [-0, -0.12494, -0.30103, -0.42597]
// The provided value is I0
TransformTrace('abs', [1.5, 2, 3, 4], 1);
// returns [-0.1761, -0.3010, -0.4771, -0.6021]
// Absolute numbers
TransformTrace('absolute', [1, -2, 3, -4]);
// returns [1, 2, 3, 4]
Returns **(Array<number> | string | void)** Transformed array, a string with an error message or null |
Add an Warning Message for the User. Use these messages to indicate a potential issue and direct the user to check the measurement again.
warning('Your Warning Message', output);
// output['messages']['warning']['Your Warning Message']
Returns object pushes the message into the output object.