DT Developer Docs
REST APIDT StudioStatus Page
  • Getting Started
  • Overview
  • Concepts
    • Devices
    • Events
    • Topics
      • Temperature Measurement Interval
      • Motion Sensor Activity Timer
  • Data Connectors
    • Introduction to Data Connectors
    • Creating a Data Connector
    • Configuring a Data Connector
    • Receiving Events
    • Best Practices
    • Example Integrations
      • Heroku
      • Google Cloud Functions
      • AWS Lambda
      • Azure HTTP Triggers
      • IBM Cloud Actions
    • Development Guides
      • Local Development with ngrok
  • REST API
  • Introduction to REST API
  • Explore Our Endpoints
    • with cURL
    • with Python API
    • with Postman
  • Authentication
    • OAuth2
    • Basic Auth
  • Error Codes
  • Emulator API
  • Examples
    • Pagination
    • Streaming Events
    • Touch to Identify
    • Refreshing Access Token
  • Reference
  • Status Page
  • Service Accounts
    • Introduction to Service Accounts
    • Creating a Service Account
    • Managing Access Rights
    • Permissions
    • Organizational Structures
  • Other
    • Application Notes
      • Generating a Room Temperature Heatmap
      • Modeling Fridge Content Temperatures
      • Outlier Detection on Multiple Temperature Sensors
      • Simple Temperature Forecasting for Substation Transformers
      • Sensor Data Insight with Power BI and Azure
      • Third-Party Sensor Data in DT Cloud
    • Frequently Asked Question
Powered by GitBook
On this page
  • Introduction
  • DT Studio Project Configuration
  • Project Authentication
  • Adding sensors to the project
  • Example Code
  • Source Access
  • Environment Setup
  • Usage
  • Implementation
  • Holt-Winters Additive Method
  • Initialization
  • Forecast
  • Confidence Interval
  • References

Was this helpful?

  1. Other
  2. Application Notes

Simple Temperature Forecasting for Substation Transformers

Last updated 1 year ago

Was this helpful?

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

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

Source Access

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

Forecast

Confidence Interval

References

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 .

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 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 .

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 yty_tyt​ with a seasonal period mmm are given by

lt=α(yt−st−m)+(1−α)(lt−1+bt−1)l_t = \alpha(y_t-s_{t-m}) + (1-\alpha)(l_{t-1}+b_{t-1})lt​=α(yt​−st−m​)+(1−α)(lt−1​+bt−1​) bt=β(lt−lt−1)+(1−β)bt−1b_t = \beta(l_t - l_{t-1}) + (1-\beta)b_{t-1}bt​=β(lt​−lt−1​)+(1−β)bt−1​ st=γ(yt−lt−1−bt−1)+(1−γ)st−ms_t = \gamma(y_t - l_{t-1} - b_{t-1}) + (1-\gamma)s_{t-m}st​=γ(yt​−lt−1​−bt−1​)+(1−γ)st−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.

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 .

In essence, a KKK-season moving average is fit to an initial length L0>K⋅mL_0>K\cdot mL0​>K⋅m amount of temperature data, y0y_0y0​. After subtracting the moving average, the initial season s0s_0s0​ is defined as the average seasonal period in L0L_0L0​. By then expanding s0s_0s0​ over L0L_0L0​, it is subtracted from y0y_0y0​ for which linear regression is subsequently fit. The initial level l0l_0l0​ is defined as the regression intercept and initial trend b0b_0b0​ as the slope.

After initialization, an estimate of future values can be calculated using the level, trend, and season components. A hhh-sample forecast is given by

y^t+h∣t=lt+hbt+st+h−m(k+1),\hat{y}_{t+h|t} = l_t + hb_t + s_{t+h-m(k+1)},y^​t+h∣t​=lt​+hbt​+st+h−m(k+1)​,

where mmm 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.

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 yty_tyt​ 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

d^T+h∣T=cσ^=cσ^h−1m+1\hat{d}_{T+h|T}=c\hat{\sigma}=c\hat{\sigma}\sqrt{\frac{h-1}{m}+1}d^T+h∣T​=cσ^=cσ^mh−1​+1​

where σ^\hat{\sigma}σ^ is the standard deviation of previous forecast residuals and ccc a multiplier. Assuming a normal distribution, ccc can be found through a table lookup, where for instance choosing c=1.96c=1.96c=1.96 results in a 95%95\%95% confidence interval [3]. Figure 6 shows how the confidence interval expands for forecasts farther into the future.

Makridakis S, Spiliotis E, Assimakopoulos V (2018) Statistical and Machine Learning forecasting methods: Concerns and ways forward. PLoS ONE 13(3): e0194889.

Creating a Service Account
REST API
this link
here
https://doi.org/10.1371/journal.pone.0194889
https://otexts.com/fpp2/holt-winters.html
https://otexts.com/fpp2/prediction-intervals.html
https://robjhyndman.com/hyndsight/hw-initialization/
Figure 1: Transformer temperature data forecasted 5 days into the future.
Figure 2: Detailed overview of sensors in DT Studio project.
Figure 3: Algorithm flow chart from new event sample to forecast values.
Figure 4: Temperature data and its isolated level, trend, and a seasonal component.
Figure 5: Five day forecast of transformer temperature data.
Figure 6: Confidence interval of five-day forecast.