Simple Temperature Forecasting for Substation Transformers

Introduction

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.

DT Studio Project Configuration

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.

Project Authentication

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.

Adding sensors to the project

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.

Example Code

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.

Source Access

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.

Environment Setup

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

Usage

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-DDThh:mm:ssZ, where 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, T, and Z which must be included. It should also be noted that the time is given in UTC. Local timezone corrections should, therefore, be made accordingly.

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.

Implementation

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.

Holt-Winters Additive Method

Initialization

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.

Forecast

Confidence Interval

References

  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 updated