ktk.TimeSeries.add_info

ktk.TimeSeries.add_info#

TimeSeries.add_info(outer_key, inner_key, value, *, overwrite=False, in_place=False)[source]#

Add new info the to TimeSeries.

Although we can directly assign new values to the info property:

ts.info["Data"]["Forces"] = {"Unit": "N"}

the method provides an alternative

ts = ts.add_info("Forces", "Unit", "N")

with the following advantages:

Overwrite prevention: Setting the overwrite argument determines explicitly if you want existing info with the same name to be overwritten or not.

Parent creation: The function creates the required hierarchy of nested dictionaries.

Parameters:
  • outer_key (str) – The key for the first level of nested dictionaries of ts.info. This is the generally what the information refers to (e.g., “Time”, or the related data key such as “Forces”.

  • inner_key (str) – The key for the second level of nested dictionaries of ts.info. This is generally the nature of the information (e.g., “Unit”).

  • value (Any) – The information.

  • overwrite (bool) – Optional. True to overwrite if there is already an info key of this name. 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 info.

Return type:

TimeSeries

Raises:

ValueError – If an info with these keys already exists and overwrite is False.

Example

>>> ts = ktk.TimeSeries()
>>> ts = ts.add_info("Forces", "Unit", "N")
>>> ts
TimeSeries with attributes:
      time: array([], dtype=float64)
      data: {}
    events: []
      info: {'Time': {'Unit': 's'}, 'Forces': {'Unit': 'N'}}