TemporalData

class TemporalData(temporal_data, variables, times, true_times)[source]

Class representing any sort of temporal data for a specified list of variables

Since teneto’s TemporalNetwork class requires all times to start at zero, we again have the concept of ‘true’ times as well as times offset to start at zero.

Parameters
  • temporal_data (ndarray) – 2D array whose columns are the variables we’re interested in and whose rows are the temporal data for these variables

  • variables (list of str) – List (not a numpy array) of variable names

  • times (ndarray) – 1D array based on true_times but with values shifted to start at zero

  • true_times ndarray – 1D array of time points

downsample(skip)[source]

Return a downsampled copy of the TemporalData object, by skipping ever ‘skip’ elements

Parameters

skip (int, optional) – How many times to skip: 1 out of skip is kept.

Return type

TemporalData

classmethod from_df(df, times, true_times, i_tend=None)[source]

Create a TemporalData from a DataFrame with variables as columns and timepoints as rows

Parameters
  • df (pandas DataFrame) – DataFrame containing the temporal data. Indices correspond to time points and columns to variables.

  • times (ndarray) – 1D array based on true_times but with values shifted to start at zero

  • true_times ndarray – 1D array of time points

  • i_tend (int, optional) – Index after which to cut the time series. Default: None (not cut).

Return type

TemporalData

classmethod from_dict(dict_, times, true_times, i_tend=None)[source]

Create a TemporalData from a dict with variables as keys and time series as values

Parameters
  • dict_ (dict) – Dictionary containing the temporal data. Keys are variables names and values are the associated time series.

  • times (ndarray) – 1D array based on true_times but with values shifted to start at zero

  • true_times ndarray – 1D array of time points

  • i_tend (int, optional) – Index after which to cut the time series. Default: None (not cut).

Return type

TemporalData

normalise()[source]

Return new TemporalData where each time series is normalised by its maximum

plot_relative_optima(variable, optima_type, ax=None, use_true_times=True, plot_var=True)[source]

Plot relative optima for a prticular variable

Parameters
  • variable (str) – The name of the variable whose optima we want to plot

  • optima_type ({‘minima’, ‘maxima’}) – Wether to look for minima or maxima

  • ax (matplotlib.Axes, optional) – Axes on which to plot

  • use_true_times (bool, optional) – Whether to use the ‘actual’ times or offset the times so that they start at zero

  • plot_var (bool, optional) – Wether to plot the times series associated to the variable.

Return type

None

plot_series(variables=None, ax=None, norm=False, add_labels=True, labels_xvals=None, use_true_times=True)[source]

Plot particular variables’ values over time

Parameters
  • variables (list of str) – Names of the variable whose values we want to plot

  • ax (matplotlib.Axes, optional) – Axes on which to plot

  • norm (bool, optional) – Whether or not to normalise the time series by dividing through by the max (default False)

  • add_labels (bool, optional) – Whether to label the variables when plotting (default True)

  • labels_xvals (list of float, optional) – The positions along the x-axis at which to place the variables’ labels (if using). If set to None (default), labels will be placed at regular intervals along x-axis.

  • use_true_times (bool, optional) – Whether to use the ‘actual’ times or offset the times so that they start at zero (default True)

Return type

None

relative_optima(variable, optima_type)[source]

Get relative optima for a particular variable

Parameters
  • variable (str) – Name of the variable whose optima we want

  • optima_type ({‘minima’, ‘maxima’}) – Type of optima to look for

Returns

  • optima (list_like) – Value of the variable at its optima

  • optima_times (list_like) – Times at which these optima occur

save_to_csv(filepath, index=False)[source]

Save temporal data to .csv file, with variables as rows and time points as columns.

Parameters
  • filepath (str) – Path at which to save the file.

  • index (bool, optional) – Whether to save the index. Default: False.

Return type

None

series(variable)[source]

Get temporal data for a particular variable

Parameters

variable (str) – The name of a variable for which there is temporal data.

Returns

Time series

Return type

np.ndarray

to_df()[source]

Convert temporal data to pandas.DataFrame format, with variables as rows and time points as columns

to_dict()[source]

Convert temporal data to dict format, with variables as keys and time series as values