Before you begin
- You are familiar with how Sift organizes data into Assets, Channels, and Runs.
- If not, see Understand Assets, Channels, and Runs.
- You know the CEL expression logic you want to reuse. If you need help writing expressions, see Expression syntax.
How reusable expression logic works
A User-Defined Function is a reusable CEL expression that can be called by name inside the expressions of Calculated Channels, Rules, and other User-Defined Functions. It does not produce a signal on its own. It acts as a building block that encapsulates a piece of logic, such as a threshold calculation or a normalization formula, that you want to apply consistently across multiple places in your workspace. Each input in a User-Defined Function is assigned a shorthand variable ($1, $2, and so on) based on the order you define them. You use these variables to write the expression, just as you would in a Calculated Channel.
Example
For example, say you want to convert temperature readings from Celsius to Fahrenheit across multiple assets. Instead of writing($1 * 9/5) + 32 in every Calculated Channel and Rule separately, you define it once as a User-Defined Function called celsius_to_fahrenheit with the expression ($1 * 9/5) + 32.
You can then reference it in Calculated Channels, Rules, and other User-Defined Functions:
- In a Calculated Channel:
celsius_to_fahrenheit($1) - In a Rule:
celsius_to_fahrenheit($1) > 200
Create a User-Defined Function
- In Sift’s homepage, click the User-Defined Functions tab.
- Click New Function.
- In the User-defined function name box, enter a name for the function. For naming requirements, see User-Defined Functions settings.
- Optional: In the Description box, enter a description of what the function does.
- In the Input Channels box, select a data type for the first input (
$1).- To add more inputs, click Add input Channel and select a data type for each additional input.
- In the Expression box, write the CEL expression using the defined input variables. For supported syntax, see Expression syntax.
- Optional: In the Preview section, click Select Run to select a Run, then review the plot to confirm the function produces the expected values against the input Channels.
- Click Save.
Verify the function
You can confirm the User-Defined Function is working correctly in two ways:- During creation: In the Preview section, select a Run, and review the output to confirm the expression produces the expected values before saving.
- After saving: The function appears in the User-Defined Functions section of the Expression Syntax panel. Call it in a Rule, Calculated Channel, or other User-Defined Function to confirm it behaves as expected.