Manipulate a time series
The objective here is to create and manipulate a time series.
A time series is a particular field where the mesh 1-d and regular, eg a time grid .
It is possible to draw a time series, using interpolation between the values: see the use case on the Field.
A time series can be obtained as a realization of a multivariate stochastic process
of dimension where
is discretized according to the regular grid .
The values of the time series are defined by:
A time series is stored in the TimeSeries object that stores the regular time grid and the associated values.
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
ot.Log.Show(ot.Log.NONE)
Create the RegularGrid
tMin = 0.0
timeStep = 0.1
N = 100
myTimeGrid = ot.RegularGrid(tMin, timeStep, N)
Case 1: Create a time series from a time grid and values
Care! The number of steps of the time grid must correspond to the size of the values
myValues = ot.Normal(3).getSample(myTimeGrid.getVertices().getSize())
myTimeSeries = ot.TimeSeries(myTimeGrid, myValues)
myTimeSeries
class=TimeSeries name=Unnamed derived from=class=FieldImplementation name=Unnamed mesh=class=Mesh name=Unnamed dimension=1 vertices=class=Sample name=Unnamed implementation=class=SampleImplementation name=Unnamed size=100 dimension=1 description=[t] data=[[0],[0.1],[0.2],[0.3],[0.4],[0.5],[0.6],[0.7],[0.8],[0.9],[1],[1.1],[1.2],[1.3],[1.4],[1.5],[1.6],[1.7],[1.8],[1.9],[2],[2.1],[2.2],[2.3],[2.4],[2.5],[2.6],[2.7],[2.8],[2.9],[3],[3.1],[3.2],[3.3],[3.4],[3.5],[3.6],[3.7],[3.8],[3.9],[4],[4.1],[4.2],[4.3],[4.4],[4.5],[4.6],[4.7],[4.8],[4.9],[5],[5.1],[5.2],[5.3],[5.4],[5.5],[5.6],[5.7],[5.8],[5.9],[6],[6.1],[6.2],[6.3],[6.4],[6.5],[6.6],[6.7],[6.8],[6.9],[7],[7.1],[7.2],[7.3],[7.4],[7.5],[7.6],[7.7],[7.8],[7.9],[8],[8.1],[8.2],[8.3],[8.4],[8.5],[8.6],[8.7],[8.8],[8.9],[9],[9.1],[9.2],[9.3],[9.4],[9.5],[9.6],[9.7],[9.8],[9.9]] simplices=[[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[10,11],[11,12],[12,13],[13,14],[14,15],[15,16],[16,17],[17,18],[18,19],[19,20],[20,21],[21,22],[22,23],[23,24],[24,25],[25,26],[26,27],[27,28],[28,29],[29,30],[30,31],[31,32],[32,33],[33,34],[34,35],[35,36],[36,37],[37,38],[38,39],[39,40],[40,41],[41,42],[42,43],[43,44],[44,45],[45,46],[46,47],[47,48],[48,49],[49,50],[50,51],[51,52],[52,53],[53,54],[54,55],[55,56],[56,57],[57,58],[58,59],[59,60],[60,61],[61,62],[62,63],[63,64],[64,65],[65,66],[66,67],[67,68],[68,69],[69,70],[70,71],[71,72],[72,73],[73,74],[74,75],[75,76],[76,77],[77,78],[78,79],[79,80],[80,81],[81,82],[82,83],[83,84],[84,85],[85,86],[86,87],[87,88],[88,89],[89,90],[90,91],[91,92],[92,93],[93,94],[94,95],[95,96],[96,97],[97,98],[98,99]] values=class=Sample name=Normal implementation=class=SampleImplementation name=Normal size=100 dimension=3 description=[X0,X1,X2] data=[[1.01189,-0.608942,0.259667],[0.324782,0.541045,0.124925],[0.63389,0.71797,0.204209],[-0.230565,-0.441029,0.218173],[0.358047,0.389048,0.0223299],[1.65473,0.718066,1.20039],[-0.0428541,0.299168,-1.95814],[0.342204,-0.822006,0.414328],[-0.336382,1.84368,-0.637582],[0.411799,-0.176888,-1.10384],[-0.414421,0.266101,-0.340295],[0.716981,-0.624488,1.48763],[-0.235484,0.22803,-0.8464],[-0.0506129,0.963482,-0.266606],[0.718303,-1.35427,-0.399967],[0.827442,-1.60123,-0.789026],[-0.470555,-1.17375,-1.17225],[1.44633,-0.0109896,-0.392194],[0.423681,-0.215168,-1.36186],[0.653895,1.87561,-0.402469],[0.623307,-0.207295,1.17231],[0.2915,-2.07544,-0.229841],[0.93204,-2.89787,-0.485802],[-0.315465,0.563317,-1.54763],[1.74913,-0.711751,0.120468],[0.85627,0.591214,-1.07519],[-0.751024,-0.550295,-1.29029],[0.776951,0.556825,-0.989392],[2.2382,-0.015504,0.87992],[1.10091,-1.08794,1.28143],[0.770213,-1.11943,0.361488],[-1.43777,0.192138,-1.69362],[1.48814,-0.979175,-1.66438],[2.75891,-0.0568873,-0.517364],[0.0644103,-0.497525,-1.67019],[-0.527852,1.15265,0.156536],[-0.790078,0.119299,-1.69795],[-0.4429,-0.541246,-1.35629],[-0.549982,-1.22042,-0.177045],[1.70917,-0.636661,0.218454],[0.448041,1.22407,-0.239304],[-0.437019,-0.533459,0.430689],[-0.549999,-0.920782,-2.35124],[-0.956058,0.943051,0.725423],[0.103282,0.516111,2.00502],[1.63507,-1.43977,0.529791],[1.03687,-0.444105,-0.753347],[0.100154,-0.550234,1.41372],[0.464214,0.447407,-1.05761],[1.35995,-0.710775,-0.164241],[-1.28354,0.556653,0.548566],[1.68737,0.79344,-0.540027],[-0.848387,-0.103264,0.958601],[-1.02522,-0.354939,-0.869302],[0.266897,0.296524,-2.24114],[-1.5607,-2.272,0.722451],[-2.16128,-0.32861,1.06975],[-1.77994,-0.832708,-0.245372],[-0.0205006,-0.170101,0.529296],[-0.725104,-1.16247,0.199523],[0.727148,-0.260688,-0.136772],[0.52023,-0.659133,-0.180673],[-1.04885,0.512371,0.20648],[-0.960832,0.414682,-1.22871],[2.57497,-0.00804901,-1.8859],[0.830757,-0.378346,0.479046],[1.60938,-0.570841,0.269096],[0.803503,0.583218,0.449756],[-0.693556,1.89666,0.0270818],[-0.258272,-0.37012,0.0456596],[-0.343048,-0.392484,-2.41093],[1.93921,-0.590044,0.22705],[-0.141765,0.855507,0.286761],[0.564812,-0.509701,1.40334],[-1.37852,0.434035,0.0342518],[0.896116,-0.870577,1.36995],[0.272597,0.579223,-1.5321],[0.957065,0.427663,-0.36668],[0.648699,-0.00464944,0.171548],[-0.0795761,0.455389,-2.14009],[0.933245,0.818686,-1.54826],[0.370246,-0.773089,-0.0129833],[0.187309,-2.13145,-1.19768],[-0.00500185,-0.125673,-1.89201],[3.40565,-0.103576,0.415448],[0.727255,0.978855,1.15808],[0.295275,0.283934,1.29426],[0.200773,0.342265,0.164085],[-0.608383,0.144346,0.537733],[0.696557,1.18791,2.18097],[-0.194809,0.628316,0.230866],[-0.648071,-0.0280203,0.871005],[1.24473,-0.106358,-0.234489],[-2.0102,0.121701,-1.33163],[-0.825457,-1.21658,-1.02579],[-1.22486,-0.735057,0.267431],[-0.313967,0.328403,-1.18542],[0.272577,-0.537997,-0.154628],[0.0348939,0.357208,0.87381],[-1.4897,-1.60323,0.276884]] start=0 timeStep=0.1 n=100
Case 2: Get a time series from a Process
myProcess = ot.WhiteNoise(ot.Normal(3), myTimeGrid)
myTimeSeries2 = myProcess.getRealization()
myTimeSeries2
| t | X0 | X1 | X2 |
0 | 0 | -0.2052791 | 0.3135911 | 1.520626 |
1 | 0.1 | 2.127892 | 0.1574096 | 0.05643199 |
2 | 0.2 | 1.05201 | -1.069286 | 0.03896958 |
3 | 0.3 | 0.1088619 | 1.560223 | 0.8978581 |
4 | 0.4 | 0.07131786 | 0.3290581 | 0.7683447 |
5 | 0.5 | -0.2017215 | 0.1483074 | 0.4988259 |
6 | 0.6 | -0.5406089 | 0.202215 | 1.52964 |
7 | 0.7 | -1.192179 | 0.5249542 | -0.1271758 |
8 | 0.8 | 1.001217 | 0.2995675 | -0.07324792 |
9 | 0.9 | -0.5928008 | 0.509773 | 1.568079 |
10 | 1 | 0.3693428 | 0.6873462 | 0.2602205 |
11 | 1.1 | 1.560101 | 0.6838802 | -0.2604079 |
12 | 1.2 | 0.1696515 | -1.016573 | 0.8102853 |
13 | 1.3 | -0.9345477 | 0.4402335 | 0.1026545 |
14 | 1.4 | 0.1625502 | 0.9776058 | -0.6851276 |
15 | 1.5 | -0.04119683 | -0.1615313 | 0.009488993 |
16 | 1.6 | -0.6992373 | 0.8356431 | 0.9612086 |
17 | 1.7 | -0.3953424 | 0.2505092 | -1.712787 |
18 | 1.8 | -0.3033722 | 1.713433 | 0.2879968 |
19 | 1.9 | -0.3462038 | -1.243077 | -0.6619336 |
20 | 2 | -0.5396257 | 0.7891796 | 0.525199 |
21 | 2.1 | 0.2655049 | -0.6153533 | 0.6677281 |
22 | 2.2 | -0.3206562 | -0.00603524 | -1.440427 |
23 | 2.3 | 0.07065125 | 0.4005165 | -0.5370034 |
24 | 2.4 | -2.130432 | 0.1862285 | -1.326288 |
25 | 2.5 | 0.2426011 | -0.8973327 | -0.9573643 |
26 | 2.6 | 1.588237 | -0.2380769 | -0.6543979 |
27 | 2.7 | 1.498919 | -0.7131357 | -1.335157 |
28 | 2.8 | 0.5676285 | 0.640198 | -0.259729 |
29 | 2.9 | 0.1922855 | -1.402221 | 0.5600177 |
30 | 3 | -1.356244 | 1.034522 | -0.3787931 |
31 | 3.1 | -0.1257271 | -0.5878356 | 1.078941 |
32 | 3.2 | -1.669386 | 1.708344 | -0.8459409 |
33 | 3.3 | -0.1786205 | -0.1958844 | 1.811325 |
34 | 3.4 | 0.4000363 | 1.108118 | -0.4552358 |
35 | 3.5 | -0.7934174 | 2.283829 | 0.351885 |
36 | 3.6 | -0.06082214 | 1.182574 | 2.057236 |
37 | 3.7 | 2.083603 | -1.109457 | 0.6461174 |
38 | 3.8 | 0.3140881 | -1.259195 | 2.51347 |
39 | 3.9 | 1.106768 | -1.237082 | -0.4050629 |
40 | 4 | 1.244775 | 0.2588656 | -0.1137998 |
41 | 4.1 | 0.3814998 | 0.1557911 | 0.4024124 |
42 | 4.2 | 1.332716 | -0.8056192 | 0.3854209 |
43 | 4.3 | -1.61086 | -0.6874292 | -0.02107395 |
44 | 4.4 | -1.405266 | -0.6029087 | -0.07453712 |
45 | 4.5 | -0.287633 | -0.4026233 | -0.4894317 |
46 | 4.6 | -0.5803388 | 1.196489 | 1.004556 |
47 | 4.7 | 0.5372572 | -0.08770909 | 1.423935 |
48 | 4.8 | 0.6820146 | 2.884055 | 0.2796988 |
49 | 4.9 | -1.178997 | -0.143892 | 0.6813079 |
50 | 5 | 0.01437919 | 0.5099701 | -1.060234 |
51 | 5.1 | 0.04483657 | 0.2499197 | 1.24773 |
52 | 5.2 | -0.3856004 | -0.2880728 | -0.5890517 |
53 | 5.3 | 0.4995753 | 1.132313 | -0.8437811 |
54 | 5.4 | 1.43619 | -0.1876503 | 0.940522 |
55 | 5.5 | 0.7151117 | -1.439318 | -0.1429401 |
56 | 5.6 | -0.1765888 | 0.9054335 | 0.6688361 |
57 | 5.7 | -0.1848348 | -0.2056171 | 0.8539061 |
58 | 5.8 | 1.082717 | 0.7860448 | -1.839514 |
59 | 5.9 | -0.4807376 | -0.7431111 | 0.2583894 |
60 | 6 | 0.06498678 | 0.8220976 | -0.2202976 |
61 | 6.1 | -1.267407 | 0.06548754 | -2.506485 |
62 | 6.2 | 0.2182682 | -0.3734256 | -0.3483342 |
63 | 6.3 | -1.020392 | -0.9373684 | 0.793814 |
64 | 6.4 | -0.983334 | -0.4151898 | 0.1049272 |
65 | 6.5 | -0.4991656 | 0.3643877 | -0.1627931 |
66 | 6.6 | 0.4925782 | 0.3548167 | -0.8811936 |
67 | 6.7 | -0.819895 | -2.106536 | 0.1773956 |
68 | 6.8 | -0.04881701 | -0.9867962 | -0.8862132 |
69 | 6.9 | 1.219161 | 0.266691 | 0.188304 |
70 | 7 | 0.8090514 | 1.619885 | -0.5646788 |
71 | 7.1 | -0.9921044 | 0.7245245 | 0.3057475 |
72 | 7.2 | -0.4119946 | 2.759856 | 0.4088039 |
73 | 7.3 | 1.121707 | -0.6501654 | -1.034288 |
74 | 7.4 | 1.150379 | 0.5587453 | 1.332409 |
75 | 7.5 | -0.3225148 | 0.4750779 | -0.1536095 |
76 | 7.6 | 1.035535 | 1.381175 | 1.225896 |
77 | 7.7 | -0.1056646 | 0.3069166 | 0.4924758 |
78 | 7.8 | 0.4262604 | -0.5698308 | -0.4156163 |
79 | 7.9 | -2.609303 | -2.173168 | -1.324497 |
80 | 8 | -1.45585 | 0.1801837 | 1.421198 |
81 | 8.1 | 1.866039 | -0.1742316 | -1.55547 |
82 | 8.2 | 1.4884 | 1.303924 | -1.061323 |
83 | 8.3 | -1.305955 | -1.629615 | -0.2962869 |
84 | 8.4 | 0.8739792 | 0.1051378 | -0.02998592 |
85 | 8.5 | -1.516032 | 1.474471 | -1.03669 |
86 | 8.6 | -1.534651 | 0.8259901 | 0.457382 |
87 | 8.7 | -0.3865615 | 1.28411 | -0.3259461 |
88 | 8.8 | 1.637177 | -0.8420178 | -0.2924097 |
89 | 8.9 | 0.3615991 | 0.4570965 | 0.237978 |
90 | 9 | 1.020826 | 1.699262 | -0.5438809 |
91 | 9.1 | 0.4973056 | -1.469904 | -2.294773 |
92 | 9.2 | -0.2623551 | -1.554523 | -2.82731 |
93 | 9.3 | 0.5825531 | 0.4139608 | -0.9302437 |
94 | 9.4 | 0.549059 | -0.69065 | -0.6021352 |
95 | 9.5 | -0.7677184 | 1.285077 | -0.22259 |
96 | 9.6 | 1.221741 | 0.4439343 | -0.7078664 |
97 | 9.7 | -1.056912 | 0.5648551 | 0.2980986 |
98 | 9.8 | 1.342418 | 1.085837 | 0.8239627 |
99 | 9.9 | -0.6283856 | -0.8834576 | 0.8607533 |
Get the number of values of the time series
Get the dimension of the values observed at each time
myTimeSeries.getMesh().getDimension()
Get the value Xi at index i
i = 37
print("Xi = ", myTimeSeries.getValueAtIndex(i))
Xi = [-0.4429,-0.541246,-1.35629]
Get the time series at index i : Xi
i = 37
print("Xi = ", myTimeSeries[i])
Xi = [-0.4429,-0.541246,-1.35629]
Get a the marginal value at index i of the time series
i = 37
# get the time stamp:
print("ti = ", myTimeSeries.getTimeGrid().getValue(i))
# get the first component of the corresponding value :
print("Xi1 = ", myTimeSeries[i, 0])
ti = 3.7
Xi1 = -0.44290028916853585
Get all the values (X1, .., Xn) of the time series
| X0 | X1 | X2 |
0 | 1.011887 | -0.6089418 | 0.259667 |
1 | 0.3247816 | 0.5410446 | 0.124925 |
2 | 0.6338902 | 0.7179695 | 0.2042093 |
3 | -0.2305653 | -0.4410291 | 0.2181727 |
4 | 0.3580472 | 0.3890482 | 0.02232993 |
5 | 1.654732 | 0.7180658 | 1.200392 |
6 | -0.04285412 | 0.2991685 | -1.958143 |
7 | 0.3422039 | -0.8220064 | 0.4143278 |
8 | -0.3363815 | 1.84368 | -0.637582 |
9 | 0.4117993 | -0.1768882 | -1.10384 |
10 | -0.4144207 | 0.2661011 | -0.3402945 |
11 | 0.7169809 | -0.6244882 | 1.487634 |
12 | -0.2354843 | 0.2280304 | -0.8464 |
13 | -0.05061286 | 0.9634821 | -0.2666059 |
14 | 0.7183027 | -1.35427 | -0.3999666 |
15 | 0.8274424 | -1.601233 | -0.7890261 |
16 | -0.470555 | -1.173748 | -1.172249 |
17 | 1.446331 | -0.01098964 | -0.3921936 |
18 | 0.4236814 | -0.2151677 | -1.361857 |
19 | 0.6538955 | 1.875609 | -0.4024692 |
20 | 0.6233072 | -0.2072951 | 1.17231 |
21 | 0.2915004 | -2.075439 | -0.2298406 |
22 | 0.9320396 | -2.897866 | -0.485802 |
23 | -0.3154649 | 0.5633166 | -1.547632 |
24 | 1.749131 | -0.7117512 | 0.1204685 |
25 | 0.8562701 | 0.5912137 | -1.075188 |
26 | -0.751024 | -0.5502947 | -1.290288 |
27 | 0.7769506 | 0.5568254 | -0.9893918 |
28 | 2.238198 | -0.01550398 | 0.87992 |
29 | 1.100906 | -1.087936 | 1.281433 |
30 | 0.7702127 | -1.119431 | 0.3614885 |
31 | -1.437774 | 0.1921378 | -1.693616 |
32 | 1.488139 | -0.9791753 | -1.664384 |
33 | 2.758905 | -0.05688733 | -0.5173643 |
34 | 0.06441027 | -0.4975254 | -1.670192 |
35 | -0.5278518 | 1.152648 | 0.1565362 |
36 | -0.790078 | 0.1192994 | -1.69795 |
37 | -0.4429003 | -0.5412464 | -1.356292 |
38 | -0.5499819 | -1.220419 | -0.1770449 |
39 | 1.709167 | -0.6366608 | 0.2184536 |
40 | 0.4480405 | 1.224067 | -0.2393039 |
41 | -0.4370185 | -0.5334587 | 0.4306893 |
42 | -0.5499989 | -0.9207816 | -2.351244 |
43 | -0.9560584 | 0.943051 | 0.7254229 |
44 | 0.1032824 | 0.5161109 | 2.005021 |
45 | 1.635069 | -1.439767 | 0.5297914 |
46 | 1.036868 | -0.4441049 | -0.7533471 |
47 | 0.1001542 | -0.5502341 | 1.41372 |
48 | 0.464214 | 0.4474071 | -1.057613 |
49 | 1.359945 | -0.710775 | -0.1642414 |
50 | -1.283544 | 0.5566532 | 0.5485656 |
51 | 1.687374 | 0.7934399 | -0.5400267 |
52 | -0.848387 | -0.1032642 | 0.9586013 |
53 | -1.025222 | -0.3549386 | -0.8693017 |
54 | 0.266897 | 0.296524 | -2.241144 |
55 | -1.560704 | -2.271998 | 0.7224505 |
56 | -2.161275 | -0.3286104 | 1.069747 |
57 | -1.779941 | -0.8327076 | -0.2453716 |
58 | -0.0205006 | -0.1701006 | 0.5292955 |
59 | -0.7251038 | -1.162473 | 0.1995235 |
60 | 0.7271477 | -0.2606875 | -0.1367718 |
61 | 0.5202298 | -0.6591333 | -0.1806734 |
62 | -1.048847 | 0.5123711 | 0.2064803 |
63 | -0.960832 | 0.4146824 | -1.228714 |
64 | 2.57497 | -0.008049008 | -1.885899 |
65 | 0.830757 | -0.3783459 | 0.4790463 |
66 | 1.609382 | -0.5708413 | 0.2690964 |
67 | 0.8035033 | 0.5832181 | 0.4497564 |
68 | -0.6935559 | 1.896662 | 0.02708176 |
69 | -0.258272 | -0.37012 | 0.04565963 |
70 | -0.3430478 | -0.3924844 | -2.410929 |
71 | 1.939206 | -0.5900438 | 0.2270499 |
72 | -0.1417654 | 0.8555065 | 0.286761 |
73 | 0.5648119 | -0.5097008 | 1.403344 |
74 | -1.378522 | 0.4340351 | 0.03425181 |
75 | 0.8961165 | -0.8705775 | 1.369953 |
76 | 0.2725969 | 0.5792226 | -1.532103 |
77 | 0.957065 | 0.4276634 | -0.3666802 |
78 | 0.6486989 | -0.004649441 | 0.1715484 |
79 | -0.07957611 | 0.4553892 | -2.140093 |
80 | 0.9332446 | 0.8186856 | -1.548256 |
81 | 0.370246 | -0.773089 | -0.01298333 |
82 | 0.1873089 | -2.131449 | -1.197682 |
83 | -0.005001849 | -0.1256726 | -1.892007 |
84 | 3.40565 | -0.1035762 | 0.4154477 |
85 | 0.7272545 | 0.9788553 | 1.158081 |
86 | 0.2952752 | 0.2839339 | 1.294258 |
87 | 0.2007735 | 0.342265 | 0.1640854 |
88 | -0.6083832 | 0.1443463 | 0.5377329 |
89 | 0.6965567 | 1.187906 | 2.180975 |
90 | -0.1948093 | 0.6283156 | 0.2308662 |
91 | -0.6480712 | -0.02802031 | 0.8710046 |
92 | 1.244731 | -0.1063582 | -0.2344887 |
93 | -2.010204 | 0.1217012 | -1.331632 |
94 | -0.8254575 | -1.216578 | -1.025789 |
95 | -1.224865 | -0.7350567 | 0.2674311 |
96 | -0.3139666 | 0.3284034 | -1.185418 |
97 | 0.2725766 | -0.5379969 | -0.1546276 |
98 | 0.03489387 | 0.3572081 | 0.8738098 |
99 | -1.489697 | -1.603233 | 0.2768838 |
Compute the temporal Mean
It corresponds to the mean of the values of the time series
myTimeSeries.getInputMean()
class=Point name=Unnamed dimension=3 values=[0.153322,-0.0887119,-0.139828]
Draw the marginal i of the time series using linear interpolation
graph = myTimeSeries.drawMarginal(0)
view = viewer.View(graph)
with no interpolation
graph = myTimeSeries.drawMarginal(0, False)
view = viewer.View(graph)
plt.show()