c4dynamics.states.state.state.data#
- state.data(var=None, scale=1.0)[source]#
Returns arrays of stored time and data.
data()
returns a tuple containing two numpy arrays: the first consists of timestamps, and the second contains the values of a var corresponding to those timestamps.var may be each one of the state variables or the parameters.
If var is not introduced,
data()
returns a single array of the entire state histories.If data were not stored,
data()
returns an empty array.- Parameters:
var (str) – The name of the variable or parameter of the required histories.
scale (float or int, optional) – A scaling factor to apply to the variable values, by default 1.
- Returns:
out (array or tuple of numpy arrays) – if var is introduced, out is a tuple of a timestamps array and an array of var values corresponding to those timestamps. If var is not introduced, then \(n \times m+1\) numpy array is returned, where n is the number of stored samples, and m+1 is the number of state variables and times.
Examples
Get all stored data:
>>> np.random.seed(100) # to reproduce results >>> s = c4d.state(x = 1, y = 0, z = 0) >>> for t in np.linspace(0, 1, 3): ... s.X = np.random.rand(3) ... s.store(t) >>> s.data() [[0. 0.543 0.278 0.424] [0.5 0.845 0.005 0.121] [1. 0.671 0.826 0.137]]
Data of a variable:
>>> time, x_data = s.data('x') >>> time [0. 0.5 1.] >>> x_data [0.543 0.845 0.671] >>> s.data('y')[1] [0.278 0.005 0.826]
Get data with scaling:
>>> s = c4d.state(phi = 0) >>> for p in np.linspace(0, c4d.pi): ... s.phi = p ... s.store() >>> s.data('phi', c4d.r2d)[1] [0 3.7 7.3 ... 176.3 180]
Data of a parameter
>>> s = c4d.state(x = 100, vx = 10) >>> s.mass = 25 >>> s.storeparams('mass', t = 0.1) >>> s.data('mass') (array([0.1]), array([25.]))