When defining functions for virtual channels, you must follow these specific Python syntax rules:
- Default Numeric Values: All function arguments must have default numeric values.
- Incorrect:
def Function1(a, b, t=0) - Correct:
def Function1(a=1.5, b=0, t=0)
- Reserved Time Argument: The last argument must be
t=0. This argument is reserved for the time stamp and cannot be used for other purposes. - Return Numeric Values: Every possible code branch must explicitly return a numeric value. Returning
None or strings will cause errors. - Available Modules: The following modules are pre-imported and available within your function:
math as mathpandas as pdnumpy as np
- Cross-referencing: One user-defined function can call another user-defined function.
def Function1(a=0, t=0):
if a > 5:
return 1
else:
return 0
# Function2 can call Function1
def Function2(b=1, c=7, t=0):
if b != 0:
return Function1(c)
else:
return c / 2