Comment on page

# Simple Temperature Forecasting for Substation Transformers

Forecasting time series data can be useful in many applications, be it simply for acquiring an overview of expected behavior or as incorporated in more complex anomaly detection systems. While machine-learning forecasting methods have been shown to produce excellent results in this regard, more traditional statistical modeling approaches are still very much competitive, providing the benefits of being simple yet effective, computationally inexpensive, and explainable [1].

In this application note, the popular Holt-Winters model has been implemented and used for decomposing and forecasting seasonal transformer temperature data. The following sections explain step-by-step how you can set this up for your own Disruptive Technologies (DT) Studio project for forecasting your own data.

Figure 1: Transformer temperature data forecasted 5 days into the future.

The implementation is built around using the developer API to interact with a single DT Studio project containing all sensors for which temperature is forecasted. If not already done, a project needs to be created and configured to enable API functionalities.

For authenticating the REST API against the DT Studio project, a Service Account key-id, secret, and email must be known, later to be used in the example code. If you're unfamiliar with the concept, read our guide on Creating a Service Account.

By default, all temperature sensors in the project will be individually treated and forecasted for. The number of sensors used does not have to be configured beforehand and is scaled automatically. The option to move a sensor between projects can be found when selecting a sensor in a DT Studio project as shown in figure 2.

Figure 2: Detailed overview of sensors in DT Studio project.

An example code is provided in this application note. It illustrates one way of building a transformer temperature forecasting system and is meant to serve as a precursor for further development and implementation. It uses the REST API to interface with the DT Studio project.

The example code source is publicly hosted on the official Disruptive Technologies GitHub repository under the MIT license. It can be found by following this link.

All code has been written in and tested for Python 3. While not required, it is recommended to use a virtual environment to avoid conflicts. Required dependencies can be installed using pip and the provided requirements text file.

pip3 install -r requirements.txt

Using the details found during the project authentication section, edit the following lines in

*sensor_stream.py*to authenticate the API with your DT Studio project.USERNAME = "SERVICE_ACCOUNT_KEY" # this is the key

PASSWORD = "SERVICE_ACCOUNT_SECRET" # this is the secret

PROJECT_ID = "PROJECT_ID" # this is the project id

If the example code is correctly authenticated to the DT Studio project as described above, simply running the script

*sensor_stream.py*will start streaming data from each sensor in the project for which a forecast is continuously calculated as new data arrive.python3 sensor_stream.py

For more advanced usage, such as visualizing the forecast, one or several flags can be provided upon execution.

usage: sensor_stream.py [-h] [--path] [--starttime] [--endtime] [--plot]

[--plot-debug]

Temperature forecast on Stream and Event History.

optional arguments:

-h, --help show this help message and exit

--path Absolute path to local .csv file.

--starttime Event history UTC starttime [YYYY-MM-DDTHH:MM:SSZ].

--endtime Event history UTC endtime [YYYY-MM-DDTHH:MM:SSZ].

--plot Plot the resulting forecast.

--plot-debug Plot algorithm operation.

By providing the

*--path*argument followed by the absolute path to a .csv file, the data contained in the said file will be loaded and forecasted upon. A data stream will not be started if used. The local .csv file must contain the columns*unix_time*and*temperature*.The arguments

*--starttime*and*--endtime*should be of the format*YYYY-MM-DD**T**hh:mm:ss***, where***Z**YYYY*is the year,*MM*the month, and*DD*the day. Likewise,*hh*,*mm*and*ss*is the hour, minutes, and seconds respectively. Notice the separator,**, and***T***which must be included. It should also be noted that the time is given in UTC. Local timezone corrections should, therefore, be made accordingly.***Z*By providing the

*--plot*argument, a visualization of the latest forecast will be generated when available. If historic data is included, an interactive plot will be produced after estimating occupancy for the historic data. By closing this plot, the stream will start and a non-interactive plot will update for each sample that arrives.Similar to

*--plot*, the*--plot-debug*argument will also generate a visualization but of the detailed algorithm output. They work best when used on historic or local data and are implemented for debugging purposes.With the aim of forecasting the temperature of a substation transformer several days into the future, the well-established Holt-Winters model has been implemented for real-time data collected with Disruptive Technologies Wireless Temperature Sensors. If configured properly, the model can forecast seasonality with an accuracy on par with more complex implementations such as SARIMA and LSTM [1].

Though simple, the implementation does require some prior knowledge about the data on which it is applied. The expected seasonal sample period, i.e. hourly, daily, weekly, must be provided. If unknown, it is recommended that the model is changed for double exponential smoothing which does not require this information. Additionally, a configurable number of seasons is required to initialize the model components. This is done to avoid initial erratic behavior.

The implementation has been structured such that typical tuning parameters for the algorithm are located in the file

*./config/parameters.py.*As no single configuration can work for all data, users are encouraged to experiment with different combinations better suited for their own data.Figure 3: Algorithm flow chart from new event sample to forecast values.

Also known as Triple Exponential Smoothing, the Holt-Winters Method is an extension of the earlier Holt's Linear Trend Model [2]. Through the addition of seasonality to the initial level- and trend components, the model has been a popular choice for forecasting and decomposition of time series. Though several variants of the model exist, such as the multiplicative method, the additive method represents data as a sum of three smoothing equations. With one equation per component, the isolated trend, level, and season of a signal

$y_t$

with a seasonal period $m$

are given by

$l_t = \alpha(y_t-s_{t-m}) + (1-\alpha)(l_{t-1}+b_{t-1})$

$b_t = \beta(l_t - l_{t-1}) + (1-\beta)b_{t-1}$

$s_t = \gamma(y_t - l_{t-1} - b_{t-1}) + (1-\gamma)s_{t-m}$

respectively, where

$α$

, $β$

, and $γ$

are smoothing parameters tuned for individual datasets. Though usually found empirically through trial and error, one can apply optimization techniques such as steepest descent to find the optimum smoothing parameters. However, this has the potential of fitting a local minimum and does therefore still require some kind of manual intervention. Figure 4 shows a temperature time-series decomposed by the additive method.Figure 4: Temperature data and its isolated level, trend, and a seasonal component.

Due to the recursive nature of exponential smoothing, the level, trend, and seasonal components must be initialized with some values. While many approaches have been proposed, here we implemented one proposed by Rob Hyndman [4]. A more detailed explanation can be found here.

In essence, a

$K$

-season moving average is fit to an initial length $L_0>K\cdot m$

amount of temperature data, $y_0$

. After subtracting the moving average, the initial season $s_0$

is defined as the average seasonal period in $L_0$

. By then expanding $s_0$

over $L_0$

, it is subtracted from $y_0$

for which linear regression is subsequently fit. The initial level $l_0$

is defined as the regression intercept and initial trend $b_0$

as the slope.After initialization, an estimate of future values can be calculated using the level, trend, and season components. A

$h$

-sample forecast is given by$\hat{y}_{t+h|t} = l_t + hb_t + s_{t+h-m(k+1)},$

where

$m$

is the season length as previously mentioned. Essentially, this extends the exponentially weighted slope into the future from the given level, adding the seasonal component on top of it. Depending on the chosen smoothing parameters, the forecast may or may not capture small changes in the signal.Figure 5: Five day forecast of transformer temperature data.

Forecast values should be interpreted as an indicator of how the signal might behave in the future based on previous behavior, not as a guaranteed truth. This becomes more evident if a confidence interval is included, a range for which we expect

$y_t$

to land with a given percentage of certainty. The width is dependent on the accuracy of earlier forecasts, while also becoming wider the longer into the future we forecast. Therefore, for a hh-step forecast of our seasonal data, the confidence interval is given by$\hat{d}_{T+h|T}=c\hat{\sigma}=c\hat{\sigma}\sqrt{\frac{h-1}{m}+1}$

where

$\hat{\sigma}$

is the standard deviation of previous forecast residuals and $c$

a multiplier. Assuming a normal distribution, $c$

can be found through a table lookup, where for instance choosing $c=1.96$

results in a $95\%$

confidence interval [3]. Figure 6 shows how the confidence interval expands for forecasts farther into the future.Figure 6: Confidence interval of five-day forecast.

- 1.Makridakis S, Spiliotis E, Assimakopoulos V (2018) Statistical and Machine Learning forecasting methods: Concerns and ways forward. PLoS ONE 13(3): e0194889. https://doi.org/10.1371/journal.pone.0194889

Last modified 27d ago