-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hapiplot_visual.py
More file actions
229 lines (185 loc) · 8.23 KB
/
test_hapiplot_visual.py
File metadata and controls
229 lines (185 loc) · 8.23 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import numpy as np
tests = range(0,7)
#tests = [1]
from hapiclient import hapi
from hapiplot import hapiplot
for tn in tests:
if tn == 1 or tn == 2:
# Compare png with GUI plot
import io
from PIL import Image
title = 'GUI and PNG should match visually'
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
dataset = 'dataset1'
start = '1970-01-01Z'
stop = '1970-01-01T00:00:11Z'
parameters = 'scalar'
opts = {'logging': False, 'usecache': False}
popts = {'useimagecache': False,
'logging': True,
'title': title,
'returnimage': True}
if tn == 1:
# returnimage=True for scalar parameter - compare with GUI plot
parameters = 'scalar'
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
meta = hapiplot(data, meta, **popts)
img = meta['parameters'][1]['hapiplot']['image']
Image.open(io.BytesIO(img)).show()
if tn == 2:
# returnimage=True for heatmap parameter - compare with GUI plot
parameters = 'spectra'
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
meta = hapiplot(data, meta, **popts)
img = meta['parameters'][1]['hapiplot']['image']
Image.open(io.BytesIO(img)).show()
popts['title'] = title
popts['returnimage'] = False
hapiplot(data, meta, **popts)
if tn == 3:
# Transparency
import io
from PIL import Image
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
dataset = 'dataset1'
start = '1970-01-01Z'
stop = '1970-01-01T00:00:11Z'
parameters = 'scalar'
opts = {'logging': False, 'usecache': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
popts = {
'usecache': True,
'useimagecache': False,
'logging': True,
'saveimage': True,
'returnimage': True,
'title': 'Second image should have transparent background'
}
meta = hapiplot(data, meta, **popts)
img1 = meta['parameters'][1]['hapiplot']['image']
Image.open(io.BytesIO(img1)).show()
popts['rcParams'] = {'savefig.transparent': True}
meta = hapiplot(data, meta, **popts)
img2 = meta['parameters'][1]['hapiplot']['image']
Image.open(io.BytesIO(img2)).show()
if tn == 4:
# Rc params
import io
from PIL import Image
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
dataset = 'dataset1'
start = '1970-01-01Z'
stop = '1970-01-01T00:00:11Z'
parameters = 'scalar'
opts = {'logging': False, 'usecache': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
popts = {
'usecache': True,
'useimagecache': False,
'logging': True,
'saveimage': True,
'returnimage': True,
'title': 'Both plots should have black bg and yellow text',
'rcParams': {
'savefig.transparent': False,
'figure.facecolor': 'black',
'savefig.facecolor': 'black',
'text.color': 'yellow',
'xtick.color': 'yellow',
'ytick.color': 'yellow',
'axes.labelcolor': 'yellow'
}
}
meta = hapiplot(data, meta, **popts)
img = meta['parameters'][1]['hapiplot']['image']
Image.open(io.BytesIO(img)).show()
popts['returnimage'] = False
hapiplot(data, meta, **popts)
if tn == 5:
# Style and rc parameters before and after + tight layout
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
dataset = 'dataset1'
parameters = 'vector'
start = '1970-01-01Z'
stop = '1970-01-01T00:00:11Z'
opts = {'logging': True, 'usecache': False}
#https://matplotlib.org/gallery/style_sheets/style_sheets_reference.html
#https://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html
import matplotlib
rclib = matplotlib.style.library
print('Style options available:')
for key in rclib:
print(key)
popts = {
'logging': True,
'saveimage': False,
'style': 'classic',
'title': 'Tight layout test. Figures should match.'
}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
# Set labels and make tight layout after call to hapiplot
meta = hapiplot(data, meta, **popts)
fig = meta['parameters'][1]['hapiplot']['figure']
fig.axes[0].set_ylabel('y label\nsub y label\nsub sub ylabel 2')
fig.tight_layout()
#fig.show()
# Two calls to fig.tight_layout() may be needed b/c of bug in PyQt:
# https://github.com/matplotlib/matplotlib/issues/10361
# Set labels and make tight in call to hapiplot
popts['_rcParams'] = {'figure.bbox': 'tight'}
popts['ylabel'] = 'y label\nsub y label\nsub sub ylabel 2'
meta = hapiplot(data, meta, **popts)
if tn == 6:
# Spectra w/ only bin centers and different timeStampLocations
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
dataset = 'dataset1'
start = '1970-01-01Z'
stop = '1970-01-01T00:00:11Z'
parameters = 'spectra'
opts = {'logging': True, 'usecache': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
popts = {'logging': True}
data['spectra'][3,3] = -1e31 # Add a fill value
# Default
popts['title'] = 'Default'
hapiplot(data, meta, **popts)
# Should be same as previous plot
popts['title'] = 'Should be same as default plot.'
meta['timeStampLocation'] = 'center'
hapiplot(data, meta, **popts)
popts['title'] = 'NaN patch should be between 00:03 and 00:04'
meta['timeStampLocation'] = 'begin'
hapiplot(data, meta, **popts)
popts['title'] = 'NaN patch should be between 00:02 and 00:03'
meta['timeStampLocation'] = 'end'
hapiplot(data, meta, **popts)
if tn == 7:
# Spectra w/ only bin centers and different timeStampLocations
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
dataset = 'dataset1'
start = '1970-01-01Z'
stop = '1970-01-01T00:00:11Z'
parameters = 'spectra'
opts = {'logging': True, 'usecache': True}
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
popts = {'logging': True}
# Remove 6th time value so cadence is not uniform
# Missing time value is at 00:00:06. Note that data at this time
# takes on the value of data at 00:00:05. If we knew the bin,
# width was uniform, values at 00:00:06 could be set as NaN.
# heatmap does not assume the bin width is uniform. Some software
# will assume bin width is uniform and equal to the difference
# between timestamps.
data = np.delete(data, 6, 0)
for i in range(9):
data['spectra'][i,i] = -1e31 # Add a fill value
popts['title'] = 'Bins centered on timestamp; NaNs on diagonal; no value at 00:06'
meta['timeStampLocation'] = 'center'
hapiplot(data, meta, **popts)
popts['title'] = 'Bins start on timestamp; NaNs on diagonal; no value at 00:06'
meta['timeStampLocation'] = 'begin'
hapiplot(data, meta, **popts)
popts['title'] = 'Bins end on timestamp; NaNs on diagonal; no value at 00:06'
popts['title'] = 'Should match previous'
meta['timeStampLocation'] = 'end'
hapiplot(data, meta, **popts)