Skip to content

Commit b99fbd3

Browse files
committed
categorical fixes
1 parent 8e73841 commit b99fbd3

3 files changed

Lines changed: 98 additions & 94 deletions

File tree

hapiplot/hapiplot.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,6 @@ def hapiplot(*args, **kwargs):
682682
if nodata == True:
683683
tsopts['nodata'] = True
684684

685-
if remove_mean:
686-
with rc_context(rc=opts['rcParams']):
687-
fig = timeseries(Time, y-y_mean, **tsopts)
688-
else:
689-
with rc_context(rc=opts['rcParams']):
690-
fig = timeseries(Time, y, **tsopts)
691685
if remove_mean:
692686
with rc_context(rc=opts['rcParams']):
693687
fig = timeseries(Time, y-y_mean, **tsopts)

hapiplot/plot/timeseries.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,19 @@ def timeseries(t, y, **kwargs):
8888
props = {}
8989

9090
ylabels = []
91+
categorical = False
9192
width, height = matplotlib.rcParams.get('figure.figsize', (7, 3))
9293

9394
if issubclass(y.dtype.type, np.flexible):
95+
categorical = True
9496
# See https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.scalars.html
9597
# for diagram of subclasses.
9698
# Find unique strings and give each an integer value.
9799
# Modify tick labels to correspond to unique strings
98100
yu = np.unique(y)
99-
print(len(yu))
100101
if len(yu) > 20:
101-
print(height)
102102
height = height * (len(yu)/5)
103+
#height = min(height * (len(yu) / 20.0), 12)
103104
yi = np.zeros((y.shape))
104105
for i in range(0, len(yu)):
105106
yi[y == yu[i]] = i
@@ -113,12 +114,12 @@ def timeseries(t, y, **kwargs):
113114
if opts['returnimage']:
114115
# See note above about OO API for explanation for why this is
115116
# done differently if returnimage=True
116-
fig = Figure(figsize=(width, height))
117+
fig = Figure(figsize=(width, height), constrained_layout=categorical)
117118
# Attach canvas to fig, which is needed by datetick and hapiplot.
118119
FigureCanvas(fig)
119120
ax = fig.add_subplot(111)
120121
else:
121-
fig, ax = plt.subplots(figsize=(width, height))
122+
fig, ax = plt.subplots(figsize=(width, height), constrained_layout=categorical)
122123

123124
if len(y.shape) > 1:
124125
all_nan = np.full((y.shape[1]), False)
@@ -199,8 +200,6 @@ def timeseries(t, y, **kwargs):
199200
for i in range(0, len(all_nan)):
200201
leg.get_lines()[i].set_alpha(1)
201202

202-
ax.set_position([0.12,0.125,0.850,0.75])
203-
204203
if np.all(all_nan):
205204
ax.grid(which='major', axis='x')
206205
else:

test/bugs.py

Lines changed: 93 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,99 @@
11
from hapiclient import hapi
22
from hapiplot import hapiplot
33

4-
# http://localhost:8999/#server=DAS+2&dataset=Cassini/MAG/Magnitude&parameters=B_mag&start=2016-12-11T13:00:00&stop=2016-12-11T23:00&return=image&format=svg
5-
# http://hapi-server.org/servers-dev/#server=FadenTemp&dataset=Iowa+City+Conditions&parameters=Temperature&start=2022-02-11T00:00:00.000Z&stop=2022-02-12T00:00:00.000Z&return=image&format=svg
64

7-
all = False
8-
bn = 3
9-
10-
if bn == 0 or all == True:
11-
server = 'http://hapi-server.org/servers-dev/TestData3.1/hapi'
12-
dataset = 'dataset1'
13-
parameter = ''
14-
start = '1970-01-01T00:00:00Z'
15-
stop = '1970-01-01T00:00:10Z'
16-
17-
opts = {'logging': True, 'usecache': False}
18-
19-
meta = hapi(server, dataset, **opts)
20-
21-
for i in range(0,len(meta['parameters'])):
22-
parameter = meta['parameters'][i]['name']
23-
print("test_hapiplot(): Plotting " + parameter)
24-
data, metax = hapi(server, dataset, parameter, start, stop, **opts)
25-
26-
popts = {'useimagecache': False, 'logging': True}
27-
28-
metap = hapiplot(data, metax, **popts)
29-
30-
if bn == 1 or all == True:
31-
# No data from 10-20 but still colored
32-
server = 'http://hapi-server.org/servers-dev/TestData2.0/hapi'
33-
dataset = 'dataset1'
34-
parameter = 'spectra'
35-
start = '1970-01-01T00:00:01Z'
36-
stop = '1970-01-01T00:00:30Z'
37-
opts = {'logging': True, 'usecache': True}
38-
39-
data, meta = hapi(server, dataset, parameter, start, stop, **opts)
40-
41-
popts = {'logging': True, 'returnimage': False, 'usecache': False}
42-
hapiplot(data, meta, **popts)
43-
44-
if bn == 2 or all == True:
45-
# Should be "no data"
46-
server = 'http://hapi-server.org/servers-dev/TestData2.0/hapi'
47-
dataset = 'dataset1'
48-
parameter = 'spectra'
49-
start = '1970-01-01T00:00:11Z'
50-
stop = '1970-01-01T00:00:12Z'
51-
opts = {'logging': True, 'usecache': False}
52-
53-
data, meta = hapi(server, dataset, parameter, start, stop, **opts)
54-
55-
popts = {'logging': True, 'returnimage': False, 'usecache': False}
5+
logging = True
6+
7+
bn = 7 # None => run all tests
8+
9+
opts = {'logging': logging, 'usecache': False}
10+
popts = {'useimagecache': False, 'logging': logging}
11+
12+
tests = {
13+
0: {
14+
"comment": "",
15+
"server": 'http://hapi-server.org/servers-dev/TestData3.1/hapi',
16+
"dataset": 'dataset1',
17+
"parameters": '',
18+
"start": '1970-01-01T00:00:00Z',
19+
"stop": '1970-01-01T00:00:10Z'
20+
},
21+
1: {
22+
"comment": "No data from 10-20s but still colored",
23+
"server": 'http://hapi-server.org/servers-dev/TestData2.0/hapi',
24+
"dataset": 'dataset1',
25+
"parameters": 'spectra',
26+
"start": '1970-01-01T00:00:01Z',
27+
"stop": '1970-01-01T00:00:30Z'
28+
},
29+
2: {
30+
"comment": "No data but still colored",
31+
"server": 'http://hapi-server.org/servers-dev/TestData2.0/hapi',
32+
"dataset": 'dataset1',
33+
"parameters": 'spectra',
34+
"start": '1970-01-01T00:00:11Z',
35+
"stop": '1970-01-01T00:00:12Z'
36+
},
37+
3: {
38+
"server": 'http://hapi-server.org/servers-dev/TestData3.0/hapi',
39+
"dataset": 'dataset1',
40+
"parameters": '',
41+
"start": '1970-01-01T00:00:00Z',
42+
"stop": '1970-01-01T00:02:00Z'
43+
},
44+
4: {
45+
"server": 'http://hapi-server.org/servers-dev/TestData3.0/hapi',
46+
"dataset": 'dataset1',
47+
"parameters": 'vector',
48+
"start": '1970-01-01T00:00:00Z',
49+
"stop": '1970-01-01T00:00:11Z'
50+
},
51+
5: {
52+
"server": 'https://cdaweb.gsfc.nasa.gov/hapi',
53+
"dataset": 'THE_L2_FGM@0',
54+
"parameters": 'the_fgs_gsm',
55+
"start": '2024-08-11T00:00:00Z',
56+
"stop": '2024-08-12T00:00:00.000Z'
57+
},
58+
6: {
59+
"server": 'https://supermag.jhuapl.edu/hapi',
60+
"dataset": 'indices_all',
61+
"parameters": 'SMUdstid',
62+
"start": '2018-01-18T00:00Z',
63+
"stop": '2018-01-19T01:00Z'
64+
},
65+
7: {
66+
"server": 'https://jfaden.net/HapiServerDemo/hapi',
67+
"dataset": 'Iowa City Conditions',
68+
"parameters": 'Temperature',
69+
"start": '2022-02-11T00:00:00.000Z',
70+
"stop": '2022-02-12T00:00:00.000Z'
71+
},
72+
8: {
73+
'server': 'https://planet.physics.uiowa.edu/das/das2Server/hapi',
74+
'dataset': 'Cassini/MAG/Magnitude',
75+
'parameters': '',
76+
'start': '2016-12-11T13:00:00',
77+
'stop': '2016-12-11T23:00'
78+
}
79+
}
80+
81+
for tn in tests.keys():
82+
if bn is not None and tn != bn:
83+
continue
84+
85+
test = tests[tn]
86+
if 'comment' in test:
87+
print(f"Running test {tn} - {test['comment']}")
88+
else:
89+
print(f"Running test {tn}")
90+
91+
server = test['server']
92+
dataset = test['dataset']
93+
parameters = test['parameters']
94+
start = test['start']
95+
stop = test['stop']
96+
97+
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
5698
hapiplot(data, meta, **popts)
5799

58-
if bn == 3 or all == True:
59-
60-
logging = True
61-
server = 'http://hapi-server.org/servers/TestData3.0/hapi'
62-
dataset = 'dataset1'
63-
parameters = ''
64-
start = '1970-01-01Z'
65-
stop = '1970-01-01T00:02:00Z'
66-
opts = {'logging': logging, 'usecache': False}
67-
68-
data, metax = hapi(server, dataset, parameters, start, stop, **opts)
69-
70-
popts = {'useimagecache': False, 'logging': logging}
71-
72-
hapiplot(data, metax, **popts)
73-
74-
if bn == 4 or all == True:
75-
76-
logging = True
77-
server = 'http://hapi-server.org/servers/TestData2.0/hapi'
78-
dataset = 'dataset1'
79-
parameters = 'vector'
80-
start = '1970-01-01Z'
81-
stop = '1970-01-01T00:00:11Z'
82-
opts = {'logging': logging, 'usecache': False}
83-
84-
data, metax = hapi(server, dataset, parameters, start, stop, **opts)
85-
86-
popts = {'useimagecache': False, 'logging': logging}
87-
88-
hapiplot(data, metax, **popts)

0 commit comments

Comments
 (0)