forked from t-makaro/animatplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeline.py
More file actions
53 lines (43 loc) · 1.47 KB
/
timeline.py
File metadata and controls
53 lines (43 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
from animatplot.util import demeshgrid
class Timeline:
"""An object to contain and control all of the time
Parameters
----------
t : array_like
gets converted to a numpy array representing
the time at each frame of the animation
units : str, optional
the units the time is measured in.
fps : float, optional
indicates the number of frames per second to play
log : bool, optional
Displays the time scale logarithmically (base 10). Defaults to False.
"""
def __init__(self, t, units='', fps=10, log=False):
t = np.asanyarray(t)
if len(t.shape) > 1:
self.t = demeshgrid(t)
if self.t is None:
raise ValueError("Unable to interpret time values."
"Please try passing a 1D array instead.")
else:
self.t = t
self.fps = fps
self.units = units
self.log = log
if self.log:
self.t = np.log10(self.t)
self.index = 0
self._len = len(self.t)
def __getitem__(self, i):
return self.t.__getitem__(i)
def __repr__(self):
time = repr(self.t)
units = repr(self.units)
return "Timeline(t={}, units={}, fps={})".format(time, units, self.fps)
def __len__(self):
return self._len
def _update(self):
"""Increments the current time."""
self.index = (self.index + 1) % self._len