Dynamics

ExogenousDynamicVariable

class qsdsan.utils.ExogenousDynamicVariable(ID, t=None, y=None, function=None, interpolator=None, derivative_approximator=None, intpl_kwargs={})

Creates an exogenously dynamic variable by interpolating time-series data or providing a function of time.

Note

Extrapolation is allowed, assuming the time-series data are periodic and continuous at both bounds.

Parameters:
  • ID (str) – Unique identifier of the variable.

  • t (array_like) – A 1-D array of time data, must be sorted.

  • y (array_like) – A 1-D array of the variable values at corresponding time points, length must match the t array.

  • function (callable, optional) – A function that returns the variable value at a given time. Ignored if t and y are provided.

  • interpolator (str or int or callable, optional) – Interpolation method to use. It can be a string (e.g., ‘slinear’, ‘quadratic’, ‘cubic’) or an integer within [1,5] to specify the order of a spline interpolation. Other strings will be passed on to scipy.interpolate.interp1d as the ‘kind’ argument. It can also be a class in scipy.interpolate that takes time-series data as input upon initiation. Interpolant that is not at least first-order differentiable is not recommended (e.g., linear interpolation). The default is scipy.interpolate.CubicSpline.

  • derivative_approximator (callable, optional) – A function that returns derivative of the variable at given time. If none specified, will use the derivative() method (if available) of the interpolant.

  • intpl_kwargs (dict, optional) – Keyword arguments for initiating the interpolant.

classmethod batch_init(data, interpolator=None, derivative_approximator=None, intpl_kwargs={}, **load_data_kwargs)

Creates a list of ExogenousDynamicVariable objects from time-series data.

Parameters:
  • data (str or pandas.DataFrame) – Time series data of multiple variables. If provided as a file, file extension should be one of (“.cvs”, “.xls”, “xlsx”).

  • load_data_kwargs (optional) – Additional keyword arguments passed to qsdsan.utils.load_data().

derivative(t)

Returns the derivative of the variable at time t