Cycle Times#

The “time” a event occurs in a battery time series occurs can have many meanings. A “date time” is the moment it occured accordingly to a calendar, a “test time” is the elapsed time between, and so on. The battery data toolkit provides the TimeEnhancer to compute the many ways of describing time for a time series, and the CycleTimesSummarizer to produce summaries of times for each cycle

[1]:
%matplotlib inline
from matplotlib import pyplot as plt
from battdat.postprocess.timing import CycleTimesSummarizer, TimeEnhancer
from battdat.data import CellDataset
from datetime import datetime, timedelta
import pandas as pd

Load Example Dataset#

The “single-resistor” datasets provided with battery-data-toolkit includes only a single cycle. We’ll duplicate it to provide an example for this cycle.

[2]:
dataset = CellDataset.from_hdf('../../../tests/files/example-data/single-resistor-constant-charge_from-charged.hdf')
dataset.raw_data.tail()
[2]:
test_time current voltage cycle_number
2396 7188.0 1.0 3.096667 0
2397 7191.0 1.0 3.097500 0
2398 7194.0 1.0 3.098333 0
2399 7197.0 1.0 3.099167 0
2400 7200.0 1.0 3.100000 0

Make a copy of the cycle, increment the cycle_number and advance the test_time.

[3]:
cycle_two = dataset.raw_data.copy()
cycle_two['cycle_number'] += 1
cycle_two['test_time'] += cycle_two['test_time'].max() + cycle_two['test_time'].iloc[1]
cycle_two.head()
[3]:
test_time current voltage cycle_number
0 7203.0 -1.0 2.899167 1
1 7206.0 -1.0 2.898333 1
2 7209.0 -1.0 2.897500 1
3 7212.0 -1.0 2.896667 1
4 7215.0 -1.0 2.895833 1

As an example, we’ll replace the test time with a date time so that we can show to recove the test time using TimeEnhancer

[4]:
timeseries = pd.concat([dataset.raw_data, cycle_two], ignore_index=True)
[5]:
now = datetime.now()
timeseries['date_time'] = timeseries['test_time'].apply(lambda x: now + timedelta(seconds=x))
timeseries.drop(columns='test_time', inplace=True)
[6]:
dataset.tables['raw_data'] = timeseries
dataset.raw_data.head()
[6]:
current voltage cycle_number date_time
0 -1.0 2.899167 0 2024-11-21 17:11:03.218830
1 -1.0 2.898333 0 2024-11-21 17:11:06.218830
2 -1.0 2.897500 0 2024-11-21 17:11:09.218830
3 -1.0 2.896667 0 2024-11-21 17:11:12.218830
4 -1.0 2.895833 0 2024-11-21 17:11:15.218830

Recover the Test Time#

The TimeEnhancer class computes a test time and cycle time (time since the start of a cycle) given the date time for measurements. It produces: - test_time: Time since the beginning of the time series - cycle_time: Time since the beginning of a cycle

[7]:
computer = TimeEnhancer()
[8]:
computer.compute_features(dataset).tail()
[8]:
test_time cycle_time
4797 14391.0 7188.0
4798 14394.0 7191.0
4799 14397.0 7194.0
4800 14400.0 7197.0
4801 14403.0 7200.0

The dataset now contains these additional ways of representing time.

Compute the Cycle Time#

CycleTimesSummarizer class computes two features describing entire cycles: - cycle_start: The time elapsed between first measurement of the cycle and the first measurement for the battery - cycle_duration: The time elapsed between the start of the cycle and the beginning of the next cycle

[9]:
computer = CycleTimesSummarizer()
computer.column_names
[9]:
['cycle_start', 'cycle_duration']

Compute them by calling the compute_features function.

[10]:
computer.compute_features(dataset)
[10]:
cycle_number cycle_start cycle_duration
0 0 0.0 7203.0
1 1 7203.0 7200.0

The first cycle starts at 0 seconds and the second starts 7203 seconds later, yielding a cycle duration of 7203 seconds.

There is no third cycle in our data file, so we only report the duration of the next cycle as the time between its first and last measurement: 7200 seconds.

[ ]: