ktk.TimeSeries.add_data

ktk.TimeSeries.add_data#

TimeSeries.add_data(data_key, data_value, *, overwrite=False, in_place=False)[source]#

Add new data to the TimeSeries.

Conceptually, these two lines are equivalent:

timeseries.data["name"] = value
timeseries = timeseries.add_data(name, value)

However, using add_data performs additional checks to ensure that no existing data is overwritten, and that time is matching for all data. See Raises section for more information on these checks.

Parameters:
  • data_key (str) – Name of the data key.

  • data_value (ArrayLike) – Any data that can be converted to a NumPy array

  • overwrite (bool) – Optional. True to overwrite if there is already a data key of this name in the TimeSeries. Default is False.

  • in_place (bool) – Optional. True to modify and return the original TimeSeries. False to return a modified copy of the TimeSeries while leaving the original TimeSeries intact. Default is False.

Returns:

The TimeSeries with the added data.

Return type:

TimeSeries

Raises:

ValueError – In any of these conditions: 1. If data with this key already exists and overwrite is False. 2. If the size of the data (first dimension) does not match the size of existing data or the existing time. 3. If data is a pandas DataFrame and its index does not match the existing time.

Example

>>> ts = ktk.TimeSeries()
>>> ts = ts.add_data("data1", [1.0, 2.0, 3.0])
>>> ts = ts.add_data("data2", [4.0, 5.0, 6.0])
>>> ts
TimeSeries with attributes:
         time: array([], dtype=float64)
         data: {'data1': array([1., 2., 3.]), 'data2': array([4., 5., 6.])}
    time_info: {'Unit': 's'}
    data_info: {}
       events: []