-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtimeseries_to_gaf.py
49 lines (43 loc) · 1.37 KB
/
timeseries_to_gaf.py
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
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
from pyts.image import GramianAngularField
import pandas as pd
import os
from typing import *
matplotlib.use('Agg')
# Pass times-eries and create a Gramian Angular Field image
# Grab times-eries and draw the charts
def create_gaf(ts) -> Dict[str, Any]:
"""
:param ts:
:return:
"""
data = dict()
gadf = GramianAngularField(method='difference', image_size=ts.shape[0])
data['gadf'] = gadf.fit_transform(pd.DataFrame(ts).T)[0]
return data
# Create images of the bundle that we pass
def create_images(X_plots: Any, image_name: str, destination: str, image_matrix: tuple =(2, 2)) -> None:
"""
:param X_plots:
:param image_name:
:param destination:
:param image_matrix:
:return:
"""
fig = plt.figure(figsize=[img * 4 for img in image_matrix])
grid = ImageGrid(fig,
111,
axes_pad=0,
nrows_ncols=image_matrix,
share_all=True,
)
images = X_plots
for image, ax in zip(images, grid):
ax.set_xticks([])
ax.set_yticks([])
ax.imshow(image, cmap='rainbow', origin='lower')
repo = os.path.join('GramianAngularFields/TRAIN', destination)
fig.savefig(os.path.join(repo, image_name))
plt.close(fig)