Battery temperature¶

Title: Battery temperature
Author: Michal Bezak, Tangent Works
Industry: Electronics, Automotive, Manufacturing ...
Area: Customer experience, Operations
Type: Forecasting

Description¶

Accelerating adaption of electric vehicles (EVs) is driving improvements of battery technologies at rocket speed. We have not seen such progress in decades. Bigger capacities, faster charging and longer lifespan of batteries are in focus. It is not only EVs that challenge batteries tech status quo. Smartphones, batteries installed at households, and other areas would benefit from progress in this field.

One of the factors that has impact on battery health (span-of-life in particular) and capacity is temperature. The amount of energy available for discharge is influenced by temperature. With rising temperature there is more of it (battery can provide the most at 45°C) and vice versa. However, the optimal temperature for maximizing battery lifespan and usable capacity is between 15 to 35°C. Temperature is important factor also during battery charging. To maximize the lifespan of Li-ion batteries they should not be charged below 0°C.

Nowadays, advanced battery systems rely on cooling/heating mechanisms that help batteries to operate (and keep them in healthy condition) even in extreme conditions. It is also possible to control current flow and thus help to balance battery temperature.

In this use case, we will demonstrate how TIM can predict temperature of battery.

TIM can be deployed on edge, and scale, we can imagine various scenarios of deployment, from device level (e.g. in EV), or in cloud to which vast battery grids could be connected.

Business parameters¶

Business objective: Improved quality of products
Business value: Greater value for customers
KPI: -
In [200]:
import logging
import pandas as pd
import plotly.graph_objects as go
import numpy as np
import json
import datetime

from sklearn.metrics import mean_squared_error, mean_absolute_error
import math

import tim_client
In [201]:
with open('credentials.json') as f:
    credentials_json = json.load(f)                     # loading the credentials from credentials.json

TIM_URL = 'https://timws.tangent.works/v4/api'          # URL to which the requests are sent

SAVE_JSON = False                                       # if True - JSON requests and responses are saved to JSON_SAVING_FOLDER
JSON_SAVING_FOLDER = 'logs/'                            # folder where the requests and responses are stored

LOGGING_LEVEL = 'INFO'
In [202]:
level = logging.getLevelName(LOGGING_LEVEL)
logging.basicConfig(level=level, format='[%(levelname)s] %(asctime)s - %(name)s:%(funcName)s:%(lineno)s - %(message)s')
logger = logging.getLogger(__name__)
In [203]:
credentials = tim_client.Credentials(credentials_json['license_key'], credentials_json['email'], credentials_json['password'], tim_url=TIM_URL)
api_client = tim_client.ApiClient(credentials)
In [5]:
results = dict()

Dataset(s)¶

Data contain measurements of multiple Li-ion batteries used in charge/discharge experiment.

Batteries were continuously operated in cycles - charging, discharging, resting cycles with various modifications. Our focus was on discharging with current charging randomly (random walk), current setpoints were selected from 4.5A, 3.75A, 3A, 2.25A, 1.5A and 0.75A.

During the experiment, each selected current setpoint was applied until either the battery voltage went down to 3.2V or 5 minutes passed, however we wanted to focus solely on natural discharge events, not timeouts, thus we selected the later part of original data where barttery aging/degradation was already visible.

Sampling and gaps¶

Values were resampled from original sampling (almost regular 1-second) to regular 5-second basis with mean aggregation.

Data may contain gaps, this is the case mainly for dataset with merged data from multiple batteries (of the same type and parameters). During the experiments, distribution of current to which batteries were exposed to was different. Merging such data means higher variance of values but at the same time makes models built more stable.

Data¶

Column name Description Type Availability
timestamp Absolute time stamp of sample Timestamp column
temperature Temperature of battery (Celsius) Predictor t+0
current Current measured in Amps Predictor t+0
voltage Voltage measured in Volts Predictor t+0
voltage_cumsum Cumulative sum of voltage within given cycle (Volts) Predictor t+0
capacity_removed Removed capacity within given cycle (current x timeframe) Predictor t+0
capacity_removed_cumulative Cumulative capacity reduced within given cycle Predictor t+0

Reg. ambient temperature, it is not provided, although it is known that for RW10 it was "room temperature", while for RW25 and RW21 it was "approximately 40°C".

The original file was obtained in Matlab format, it was transformed into CSV, enhanced with additional information derived from original data (capacity removed column and cumsum columns), and filtered to discharge cycles only.

To demonstrate results for out-of-sample interval, dataset was resampled to regular sampling so it was possible to match timestamps and calculate residuals. Technically, TIM is capable to work with any kind of sampling, spanning from milliseconds, irregularly sampled data, data with gaps etc.

Forecasting situation¶

TIM detects forecasting situation from current "shape" of data, i.e. if values for target and predictors end all at the same timestamp, this pattern of availability is assumed also for the model building and calculation of out-of-sample values.

Our forecasting situation assumes we have no forecasted values for predictors, we simply aim to forecast N steps ahead.

CSV files used in experiments can be downloaded here.

Source¶

Raw dataset was obtained at NASA Prognostics Center of Excellence website.

B. Bole, C. Kulkarni, and M. Daigle "Randomized Battery Usage Data Set", NASA Ames Prognostics Data Repository (http://ti.arc.nasa.gov/project/prognostic-data-repository), NASA Ames Research Center, Moffett Field, CA. Analysis of a similar dataset is published in: Brian Bole, Chetan Kulkarni, and Matthew Daigle, "Adaptation of an Electrochemistry-based Li-Ion Battery Model to Account for Deterioration Observed Under Randomized Use", in the proceedings of the Annual Conference of the Prognostics and Health Management Society, 2014

List of files for each experiment iteration:

In [18]:
datafiles ={
    'RW10': 'datasets/battery_discharge_r_RW10_temperature.csv',
    'RW25': 'datasets/battery_discharge_r_RW25_temperature.csv',
    'RW21': 'datasets/battery_discharge_r_RW21_temperature.csv',
    'merged': 'datasets/battery_discharge_r_merged_temperature.csv',
}
In [19]:
results = dict()
In [162]:
# NOTE: start re-run of each iteration by changing key to CSV file
FOCUS = 'RW10'  
In [163]:
data = tim_client.load_dataset_from_csv_file( datafiles.get(FOCUS), sep=',' )
In [164]:
prediction_horizon  = 12
In [165]:
data.shape
Out[165]:
(20289, 7)
In [166]:
data.tail(prediction_horizon+1)
Out[166]:
timestamp temperature voltage current capacity_removed capacity_removed_cumsum voltage_cumsum
20276 2014-06-02 06:06:30 35.846852 3.2452 3.75 3.75 41.2496 39.793
20277 2014-06-02 06:06:35 NaN NaN NaN NaN NaN NaN
20278 2014-06-02 06:06:40 NaN NaN NaN NaN NaN NaN
20279 2014-06-02 06:06:45 NaN NaN NaN NaN NaN NaN
20280 2014-06-02 06:06:50 NaN NaN NaN NaN NaN NaN
20281 2014-06-02 06:06:55 NaN NaN NaN NaN NaN NaN
20282 2014-06-02 06:07:00 NaN NaN NaN NaN NaN NaN
20283 2014-06-02 06:07:05 NaN NaN NaN NaN NaN NaN
20284 2014-06-02 06:07:10 NaN NaN NaN NaN NaN NaN
20285 2014-06-02 06:07:15 NaN NaN NaN NaN NaN NaN
20286 2014-06-02 06:07:20 NaN NaN NaN NaN NaN NaN
20287 2014-06-02 06:07:25 NaN NaN NaN NaN NaN NaN
20288 2014-06-02 06:07:30 NaN NaN NaN NaN NaN NaN
In [167]:
timestamp_column = 'timestamp'

target_column = 'temperature'

Visualization

In [168]:
def apply_regular_timeline( df, sec, timestamp_column ):
    vis_df = df.copy()

    vis_df[ timestamp_column ] = pd.to_datetime( vis_df[ timestamp_column ] )
    vis_df.set_index( timestamp_column, inplace=True )

    timestamps = [ vis_df.index.min() + i * datetime.timedelta( seconds=sec ) for i in range( int( ( vis_df.index.max() - vis_df.index.min() ).total_seconds()/sec ) + 1 ) ]

    temp_df = pd.DataFrame( { timestamp_column: timestamps } )
    temp_df.set_index( timestamp_column, inplace=True )

    vis_df = temp_df.join( vis_df )
    vis_df[ timestamp_column ] = vis_df.index

    return vis_df.reset_index( drop=True )
In [169]:
last_n = 10000

vis_df = apply_regular_timeline( data.iloc[-last_n:], 5, timestamp_column )

#vis_df = apply_regular_timeline( data.iloc[:], 5, timestamp_column )
In [170]:
fig = go.Figure()

fig.add_trace(go.Scatter( x = vis_df[ timestamp_column ], y = vis_df[ target_column ], name=target_column ) )

#fig.update_layout( height = 700, width = 1200, title='Target visualization' )

fig.update_layout( height = 700, width = 1200, title='Target visualization, last '+str(last_n)+' records' )

fig.show()