tokio.timeseries module¶
TimeSeries class to simplify updating and manipulating the in-memory representation of time series data.
-
class
tokio.timeseries.
TimeSeries
(dataset_name=None, start=None, end=None, timestep=None, num_columns=None, column_names=None, timestamp_key=None, sort_hex=False)[source]¶ Bases:
object
In-memory representation of an HDF5 group in a TokioFile. Can either initialize with no datasets, or initialize against an existing HDF5 group.
-
convert_to_deltas
()[source]¶ Convert a matrix of monotonically increasing rows into deltas. Replaces self.dataset with a matrix with the same number of columns but one fewer row (taken off the bottom of the matrix). Also adjusts the timestamps dataset.
-
get_insert_pos
(timestamp, column_name, create_col=False)[source]¶ Determine col and row indices corresponding to timestamp and col name
Parameters: Returns: (t_index, c_index) (long or None)
-
init
(start, end, timestep, num_columns, dataset_name, column_names=None, timestamp_key=None)[source]¶ Create a new TimeSeries dataset object
Responsible for setting self.timestep, self.timestamp_key, and self.timestamps
Parameters: - start (datetime) – timestamp to correspond with the 0th index
- end (datetime) – timestamp at which timeseries will end (exclusive)
- timestep (int) – seconds between consecutive timestamp indices
- num_columns (int) – number of columns to initialize in the numpy.ndarray
- dataset_name (str) – an HDF5-compatible name for this timeseries
- column_names (list of str, optional) – strings by which each column should be indexed. Must be less than or equal to num_columns in length; difference remains uninitialized
- timestamp_key (str, optional) – an HDF5-compatible name for this timeseries’ timestamp vector. Default is /groupname/timestamps
-
insert_element
(timestamp, column_name, value, reducer=None)[source]¶ Given a timestamp (datetime.datetime object) and a column name (string), update an element of the dataset. If a reducer function is provided, use that function to reconcile any existing values in the element to be updated.
-
rearrange_columns
(new_order)[source]¶ Rearrange the dataset’s columnar data by an arbitrary column order given as an enumerable list
-
-
tokio.timeseries.
sorted_nodenames
(nodenames, sort_hex=False)[source]¶ Gnarly routine to sort nodenames naturally. Required for nodes named things like ‘bb23’ and ‘bb231’.
-
tokio.timeseries.
timeseries_deltas
(dataset)[source]¶ Convert monotonically increasing values into deltas
Subtract every row of the dataset from the row that precedes it to convert a matrix of monotonically increasing rows into deltas. This is a lossy process because the deltas for the final measurement of the time series cannot be calculated.
Parameters: dataset (numpy.ndarray) – The dataset to convert from absolute values into deltas. rows should correspond to time, and columns to individual components Returns: - The deltas between each row in the given input dataset.
- Will have the same number of columns as the input dataset and one fewer rows.
Return type: numpy.ndarray