[2]:
import timeatlas as ta import pandas as pd
A time series is a series of data points indexed (or listed or graphed) in time order. Most commonly, a time series is a sequence taken at successive equally spaced points in time. - Wikipedia
In TimeAtlas, a time series is based on a Pandas DataFrame with a DatetimeIndex. There are multiple ways to create a TimeSeries directly in a notebook. For instance, directly with the objects :
Create an DatetimeIndex
Create the DataFrame
Build the TimeSeries
[3]:
index = pd.DatetimeIndex(['2019-01-01', '2019-01-02', '2019-01-03', '2019-01-04']) my_series = pd.DataFrame([0.4, 1.0, 0.7, 0.6], index=index) ts = ta.TimeSeries(my_series) ts
values 2019-01-01 0.4 2019-01-02 1.0 2019-01-03 0.7 2019-01-04 0.6
With TimeSeries.create() :
TimeSeries.create()
Create the empty TimeSeries, by specifying start, end and the frequency
Add values
Warning
A TimeSeries in TimeAtlas is immutable.
[4]:
ts = ta.TimeSeries.create('2019-01-01', '2019-01-04', freq='1D') ts = ts.fill([0.4, 1.0, 0.7, 0.6]) ts
Usually there are some important data that we would like to keep close the TimeSeries but are not directly part of the values of the TimeSeries.
TimeAtlas has an object Metadata, where we can store these additional data. You can whatever data you feel is important to you by providing a dictionary.
[5]:
items = {'Name': "Test", "Year": 2019, "Nested": {1: "test", 2: "test", 3: "test",}} metadata = ta.Metadata(items=items) metadata
{'Name': 'Test', 'Year': 2019, 'Nested': {1: 'test', 2: 'test', 3: 'test'}}
There are also some predefined information that might come in handy:
Unit : unit of the data in the TimeSeries
Unit
Sensor : Name of the sensor recording the data
Sensor
Coords : coordinates/location, where the data is recorded
Coords
[6]:
from timeatlas.types import Unit, Sensor, Coords unit = Unit(name="Volt", symbol="V", data_type="float") sensor = Sensor(id=1337, name="Temperatur Sensor A1") location = Coords(long=7.1591, lat=46.7933)
[7]:
unit
<timeatlas.types.unit.Unit at 0x7fbac1adb310>
[8]:
sensor
Sensor ID: 1337; Name: Temperatur Sensor A1
[9]:
location
46.7933°N, 7.1591°E
Adding data to an existing MeteData-object.
[10]:
metadata.add(items=unit) metadata.add(items=sensor) metadata.add(items=location)
{'Name': 'Test', 'Year': 2019, 'Nested': {1: 'test', 2: 'test', 3: 'test'}, 'unit': <timeatlas.types.unit.Unit at 0x7fbac1adb310>, 'sensor': Sensor ID: 1337; Name: Temperatur Sensor A1, 'coords': 46.7933°N, 7.1591°E}
[11]:
metadata
[12]:
[a for a in dir(unit) if not a.startswith('__')]
['_abc_impl', 'data_type', 'items', 'name', 'symbol']
In TimeAtlas, a TimeSeriesDataset is a collection TimeSeries. The behaviour in most cases is similar to a classical list, with some additional functionalities.
To create a TimeSeriesDataset we first need a some TimeSeries. The TimeSeriesDataset will be represented by a small overview of statistic on each TimeSeries in it.
[13]:
ts = ta.TimeSeries.create('2019-01-01', '2019-01-04', freq='1D') ts = ts.fill([i for i in range(len(ts))]) ts2 = ta.TimeSeries.create('2019-01-01', '2019-01-04', freq='H') ts2 = ts2.fill([i for i in range(len(ts2))]) ts3 = ta.TimeSeries.create('2019-01-01', '2019-01-10', freq='1D') ts3 = ts3.fill([i for i in range(len(ts3))]) tsd = ta.TimeSeriesDataset([ts, ts2, ts3]) tsd
minimum maximum mean median kurtosis skewness 0 0 3 1.5 1.5 -1.2 0.0 1 0 72 36.0 36.0 -1.2 0.0 2 0 9 4.5 4.5 -1.2 0.0
Like in TimeSeries we can also use TimeSeriesDataset.create(). This will create the specified numbers of TimeSeries all with the same start, end and frequency.
TimeSeriesDataset.create()
[14]:
tsd = ta.TimeSeriesDataset.create(length=3, start='2019-01-01', end='2019-01-04', freq="1D") print(f"TimeSeriesDataset.create() made a TimeSeriesDataset of length: {len(tsd)}")
TimeSeriesDataset.create() made a TimeSeriesDataset of length: 3
[ ]: