Essential Functions

[ ]:
import timeatlas as ta
import numpy as np

In this guide, we present you some examples where TimeAtlas can be used.

Creating TimeSeries

[4]:
values = np.random.randn(100)
values.ravel()[np.random.choice(values.size, 10, replace=False)] = np.nan

ts1 = ta.TimeSeries.create('2019-03-01', '2019-06-08', freq='1D')
ts1 = ts1.fill(values)

values = np.random.randn(60)
values.ravel()[np.random.choice(values.size, 10, replace=False)] = np.nan

ts2 = ta.TimeSeries.create('2020-03-01', '2020-04-29', freq='1D')
ts2 = ts2.fill(values)

Dealing with different length of TimeSeries

There the possibility of padding the TimeSeries. It will pad it with np.nan until the given timestamp

[33]:
ts2_padded = ts2.pad(limit='2019-06-08')
ts2_padded
[33]:
              values
2019-06-08       NaN
2019-06-09       NaN
2019-06-10       NaN
2019-06-11       NaN
2019-06-12       NaN
...              ...
2020-04-25  0.596698
2020-04-26 -0.549478
2020-04-27 -0.062611
2020-04-28  0.979095
2020-04-29 -1.150297

[327 rows x 1 columns]

It might also be adventitious to remove the np.nan from the left, right or both sides of the TimeSeries.

[34]:
ts_trimmed = ts2_padded.trim(side='both')
ts_trimmed
[34]:
              values
2020-03-01  1.297396
2020-03-02 -0.026979
2020-03-03  2.525833
2020-03-04 -0.907044
2020-03-05  2.251274
2020-03-06  0.773656
2020-03-07       NaN
2020-03-08  0.127736
2020-03-09  0.210494
2020-03-10  0.394397
2020-03-11       NaN
2020-03-12 -0.837164
2020-03-13  1.359918
2020-03-14  0.606832
2020-03-15  0.129245
2020-03-16 -0.796973
2020-03-17       NaN
2020-03-18  0.103552
2020-03-19 -0.047688
2020-03-20 -0.932393
2020-03-21 -0.540284
2020-03-22 -0.468820
2020-03-23       NaN
2020-03-24  0.584597
2020-03-25  0.825047
2020-03-26  0.669108
2020-03-27       NaN
2020-03-28  0.811758
2020-03-29 -0.971524
2020-03-30 -1.625764
2020-03-31  0.478373
2020-04-01  0.266248
2020-04-02 -0.120767
2020-04-03 -1.209642
2020-04-04 -0.564476
2020-04-05  0.231693
2020-04-06  0.316299
2020-04-07       NaN
2020-04-08 -0.783829
2020-04-09 -0.571719
2020-04-10 -0.102494
2020-04-11  0.492242
2020-04-12       NaN
2020-04-13       NaN
2020-04-14 -0.175210
2020-04-15       NaN
2020-04-16 -0.239909
2020-04-17 -1.302179
2020-04-18 -2.026889
2020-04-19 -0.359681
2020-04-20  0.959360
2020-04-21  0.210031
2020-04-22 -0.536432
2020-04-23  0.030768
2020-04-24       NaN
2020-04-25  0.596698
2020-04-26 -0.549478
2020-04-27 -0.062611
2020-04-28  0.979095
2020-04-29 -1.150297

Merging TimeSeries

Merge two TimeSeries is as easy as baking carrot cake.

[35]:
ts_merged = ts_trimmed.merge(ts1)

TimeAtlas (v0.1.1) is not yet taking care of the duplicate indices. This feature might follow in later versions.

[36]:
ts_merged
[36]:
              values
2019-03-01  1.496622
2019-03-02 -1.143969
2019-03-03       NaN
2019-03-04       NaN
2019-03-05 -0.196187
...              ...
2020-04-25  0.596698
2020-04-26 -0.549478
2020-04-27 -0.062611
2020-04-28  0.979095
2020-04-29 -1.150297

[160 rows x 1 columns]

Resampling a TimeSeries

[65]:
values = np.random.randn(366 * 24)
values.ravel()[np.random.choice(values.size, 70, replace=False)] = np.nan
ts3 = ta.TimeSeries.create("2020-01-01", "2020-12-31 23:00:00", freq="H")
ts3 = ts3.fill(values)
[66]:
ts3
[66]:
                       values
2020-01-01 00:00:00 -0.874376
2020-01-01 01:00:00 -0.537712
2020-01-01 02:00:00 -1.487388
2020-01-01 03:00:00 -0.689474
2020-01-01 04:00:00  0.148005
...                       ...
2020-12-31 19:00:00 -0.071308
2020-12-31 20:00:00  0.280191
2020-12-31 21:00:00 -0.378189
2020-12-31 22:00:00 -1.072594
2020-12-31 23:00:00 -0.275559

[8784 rows x 1 columns]
[67]:
ts3_resample = ts3.resample(freq="1D")
[68]:
ts3_resample

[68]:
              values
2020-01-01 -0.874376
2020-01-02 -0.418154
2020-01-03 -1.213908
2020-01-04 -0.555403
2020-01-05 -0.630505
...              ...
2020-12-27  1.149431
2020-12-28  1.452904
2020-12-29  0.439203
2020-12-30  0.126455
2020-12-31  1.178389

[366 rows x 1 columns]

Simple statists are included.

[70]:
ts3_resample.describe()
[70]:
count    363.000000
mean      -0.019161
std        0.995951
min       -2.777850
25%       -0.738260
50%       -0.038589
75%        0.751444
max        2.111992
Name: values, dtype: float64