These operations stay available. Asset-centric identifiers on these operations are deprecated. Identify the resource with an instance ID (
space and externalId) instead.See Deprecated and retired features for dates, and Data modeling status for CDF projects for how DATA_MODELING_ONLY and HYBRID projects behave while you upgrade.space and externalId of its CogniteTimeSeries instance, and surround the values with single or double quotes. For example, to calculate the pressure drop across a filter from its inlet and outlet pressure sensors, use the expression TS{space='my_space', externalId='PT-2101'} - TS{space='my_space', externalId='PT-2102'}.
You can also apply functions, for example abs(TS{space='my_space', externalId='FIC-3001.SP'} - TS{space='my_space', externalId='FIC-3001.PV'}) for the deviation from a setpoint, and use aggregates as inputs, for example TS{space='my_space', externalId='PT-2101', aggregate='average', granularity='1h'} - TS{space='my_space', externalId='PT-2102', aggregate='average', granularity='1h'} for the hourly average pressure drop.
Functions
Synthetic time series support these functions:- Time series inputs.
- Mathematical operators +,-,*,/.
- Grouping with brackets ().
- Trigonometrics. sin(x), cos(x) and pi().
- ln(x), pow(base, exponent), sqrt(x), exp(x), abs(x).
- Variable length functions. max(x1, x2, …), min(…), avg(…).
- round(x, decimals) (
-10<decimals<10). on_error(expression, default), for handling errors like overflow or division by zero.map(expression, [list of strings to map from], [list of values to map to], default).
Functions like
avg(x1, x2, ...), min(...), and max(...) compute values across multiple inputs at each point in time. They don’t aggregate a single time series across a time range. To aggregate over time, use the aggregate parameter instead, for example, ts{space='my_space', externalId='TT-1001', aggregate='average', granularity='1h'}.Convert string and state time series to doubles
Synthetic expressions operate on numbers. To use a string or state time series as an input, wrap it in themap() function, which converts its values to doubles. The last argument is the fallback value for values that aren’t in the list.
For a string time series, map the text values. If, for example, a time series records diagnostic messages from a pump controller, you can convert the messages to a severity score with:
"Nominal operation" is mapped to 0, "Vibration warning" to 1, and any other message to 2.
For a state time series, map the state labels. For example, to plot a valve position as 0 and 1:
map(). If a data point holds a state that isn’t in the time series’ current state set, for example after the state set was changed, the expression returns an error even though map() has a fallback value. To return a value instead, wrap the expression in on_error():
Error handling: on_error()
There are three possible errors:- TYPE_ERROR: You’re using an invalid type as input. For example, a string time series with the division operator.
- BAD_DOMAIN: You’re using invalid input ranges. For example, division by zero, or sqrt of a negative number.
- OVERFLOW: The result is more than 10^100 in absolute value.
on_error() function, for example on_error(1/TS{space='my_space', externalId='FT-1001'}, 0). This can happen because of interpolation, even if none of the raw data points are zero.
How expressions are evaluated
Output timestamps
CDF returns a data point at every timestamp where:- Any input time series has a data point.
- All input time series are defined, that is, between their first and last data point, inclusive.
A + B has data points at 30, 40, 45, and 50.
Interpolation between data points
When an input time series has no data point at an output timestamp, CDF interpolates its value: linearly for continuous time series, and by carrying the previous value forward for stepwise time series. See Stepwise vs continuous. Unlike regular aggregates, synthetic time series interpolate across gaps of any length. If a time series has data points in 1971 and 2050, CDF defines it for every timestamp between them.Aggregation
To use an aggregate as an input, add theaggregate and granularity parameters to the time series reference, and optionally alignment. The aggregate must be interpolation, stepinterpolation, or average. Enclose the aggregate and granularity values in quotes.
interpolation on continuous time series, which changes within the interval. For how CDF calculates each aggregate, and why to prefer interpolation over stepinterpolation, see Common aggregates.
Granularity
Granularity uses the same format as regular aggregates, for example120s, 15m, 48h, or 365d. See Granularity. Intervals are half-open: they include the start time and exclude the end time.
Synthetic time series limit the granularity size to 120 seconds, 120 minutes, 100,000 hours, or 100,000 days.
Alignment
Thealignment parameter sets where the aggregate intervals start. It’s a timestamp in milliseconds, and every interval boundary is a whole number of granularities away from it: intervals are on the form [N*granularity + alignment, (N+1)*granularity + alignment), where N is an integer. By default, alignment=0, so intervals are aligned to Thursday 00:00:00 UTC, 1 January 1970.
Use alignment when your intervals don’t start at midnight or on a Thursday. For example, a plant that runs three 8-hour shifts starting at 06:00 UTC can calculate the average flow per shift with an 8-hour granularity aligned to 06:00:
granularity='7d' with alignment=345600000 (Monday, 5 January 1970) returns weekly aggregates that start on Mondays instead of Thursdays.
To align day or month aggregates to local midnight in a time zone, use the timeZone parameter instead of alignment.
Alignment differences from regular aggregates
Synthetic time series and regular data point retrieval align aggregate intervals differently:Time zone
ThetimeZone parameter controls how calendar-based granularities (day, month) are interpreted. Specify it at the query level (not per-expression) using any IANA time zone identifier, such as Europe/Oslo or America/New_York.
UTC. For daylight saving time handling and worked examples, see Calendar and time zone.
Unit conversion
If a time series has aunit, you can convert its values to a different unit within the same quantity.
targetUnit or targetUnitSystem, but not both. The chosen target unit must be compatible with the original unit. When querying data points using synthetic time series, the values will no longer retain their unit information.
For instance, despite it not being physically accurate, it is possible to add values from a temperature time series to those from a distance time series.
Limits
In a single request, you can ask for:- 10 expressions (10 synthetic time series).
- 10,000 data points, summed over all expressions.
- 100 input time series referrals, summed over all expressions.
- 2000 tokens in each expression. Similar to 2000 characters, except that words and numbers are counted as a single character.