When configuring either a process parameter or a processor source, one of the options is named Secondary inputs, and allows you to either align input values (the default), or retain most recent input values. This article examines what this option does and why you would change it.
Different process inputs may have records that occur at different times to each other. This can be especially true when the inputs are parameters from different data sources. Even when inputs generally occur at the same timestamp, some inputs may occur at different intervals that other inputs, for example hourly instead of daily.
It's always the timestamps of primary input (i.e. the input first declared in the code) that determine the execution timestamps of the process. The Secondary inputs option affects how any of the other (secondary) inputs are aligned with these execution timestamps. For any secondary input data with timestamps that do not align with the current execution timestamp, a choice of Align input values means values will be interpolated at the execution timestamp, and these interpolated values will be used for whatever calculation is being performed by the process. Alternatively, a choice of Retain most recent input values means that the secondary value prior to the current execution timestamp is retained and used for the calculation being performed by the process.
Align input values | Secondary input values are interpolated to align with the current execution timestamp (which is determined by the primary input) |
Retain most recent input values | Secondary input values prior to the current execution timestamp are retained |
This is much clearer when shown by example. Consider a process with two input parameters, where the output of the process is the sum of the two inputs:
In this example, the values of the secondary input, param2
, when they do occur are at the same timestamps as the primary input, param1
. However, they do not occur at the same frequency. That means that for some values of param1
, there will be no corresponding value for param2
at exactly the same timestamp. Since param1
is the primary input, it determines the execution timestamps, i.e. the timestamps of the output values. If there is an execution timestamp where param1
has a value but param2
does not, what should the output be? Since the Align input values option is enabled by default, we should expect param2
to be interpolated:
Note the output of the process at the 02:00 timestamp. There was no value for param2
at this time, so a value was interpolated based on the values on either side. A value of 1 occurred at 01:00, and a value of 2 occurred at 03:00, so a value of 1.5 was interpolated at 02:00, resulting in a summed value of 21.5 being the process output at this time.
Why were no output values produced by the process after 03:00? Because the run mode of the process is currently set to All inputs updated, which means the process will not produce outputs until all inputs have advanced their current time beyond the current time of the process. Let's reset the example, but this time switch the run mode to Any input updated:
The process will now produce the following output:
The value of param2
at 02:00 has still been interpolated as 1.5, resulting in an output of 21.5, just like the previous example. But we now see that the process has continued producing outputs corresponding with the primary input timestamps, even beyond 03:00 which was the most recent timestamp for param2
. Note that the latest value of param2
has been used in subsequent calculations; it can't be interpolated because that would require values on either side.
Now we reset the example, setting the run mode back to All inputs updated, but this time we change the Secondary inputs option to Retain most recent input values:
The process will now produce the following output:
The only difference is the output value at 02:00, which is now 21 (instead of 21.5 in the previous example). That is because no interpolation took place. During the calculation at 02:00, there was no value for param2
at this timestamp, therefore the most recent input value prior to 02:00 was used, which was the value of 1 which occurred at 01:00.
The final combination of settings to try is keeping the Retain most recent input values option but changing the run mode to Any input updated:
The process will now produce the following output:
There is still no interpolation taking place, but now we now have outputs values occurring at every timestamp determined by the primary input.
This final combination of settings is perfect for a use case where an offset value needs to be applied, but the offset may change over time. If param2
is the offset in this example, then the offset value of 1 defined at 01:00 was applied to the current and future values of param1
, until the offset was updated at 3:00, and then the updated offset value of 2 was applied all current and future values of param1
. In fact, any new values for param1
will continue to have an offset of 2 applied to them indefinitely, until the value of param2
is changed.
In summary, choose the combination of run mode and secondary input option that make sense for your own use case, based on if you want interpolation of secondary inputs.
Comments
0 comments
Article is closed for comments.