Skip to content

Commit bdc5913

Browse files
committed
misc changes
1 parent db89884 commit bdc5913

9 files changed

Lines changed: 174 additions & 134 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __pycache__
77
anaconda3/
88
build/
99
dist/
10+
hapicache/
1011
hapiplot.egg-info/
1112
*.dif.png
1213
.spyproject

CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ v0.2.2b0:
2828
v0.2.2b1:
2929
2022-11-15 3879436 Remove depreciated (and unneeded) fig.canvas.set_window_title
3030
v0.2.2:
31+
2022-12-09 cf3f6b
3132
v0.2.3b0:
3233
2023-01-20 0cce33...a750fd heatmap test improvements
33-
2023-01-24 3d0725 remove mean for intermagnet plots (temp fix)
34+
2023-01-24 8ee09a7 remove mean for intermagnet plots (temp fix)
35+
2023-12-31 fb6d0a8 legend str and single time val
36+
2023-12-31 24f83b0 means and time-dep bins
37+
2024-05-08 db89884 mean logic to apply only to GIN server

hapiplot/hapiplot.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,11 @@ def hapiplot(*args, **kwargs):
412412
bins_time_dependent = True
413413

414414
if 'bins' in meta['parameters'][i] and not bins_time_dependent:
415-
ylabel = meta["parameters"][i]['bins'][0]["name"] \
416-
+ " [" \
417-
+ meta["parameters"][i]['bins'][0]["units"] \
418-
+ "]"
415+
units = meta["parameters"][i]['bins'][0].get("units", None)
416+
if units is None:
417+
units = ""
418+
name = meta["parameters"][i]['bins'][0]["name"]
419+
ylabel = name + "[" + units + "]"
419420
else:
420421
ylabel = "bin #"
421422
if bins_time_dependent:
@@ -536,7 +537,10 @@ def hapiplot(*args, **kwargs):
536537
y = fill2nan(y, meta["parameters"][i]['fill'])
537538

538539
remove_mean = False
539-
if 'uk/GIN_' in meta['x_server'] and (ptype == 'integer' or ptype == 'double'):
540+
magdata = 'uk/GIN_' in meta['x_server']
541+
magdata = magdata or 'wdcapi' in meta['x_server']
542+
magdata = magdata or 'supermag' in meta['x_server']
543+
if magdata and (ptype == 'integer' or ptype == 'double'):
540544
remove_mean = True
541545
y_mean = np.nanmean(y, axis=0)
542546

hapiplot/plot/heatmap.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ def calcEdges(y, coord):
100100

101101
if len(y) == 1:
102102
# Put tick at center of bin; make bin have width = 1.
103-
y = np.array([y[0]-0.5,y[0]+0.5])
103+
if type(y[0]) == datetime.datetime:
104+
dt = datetime.timedelta(seconds=1.0)
105+
y = np.array([y[0]-dt,y[0]+dt])
106+
else:
107+
y = np.array([y[0]-0.5,y[0]+0.5])
104108
else:
105109
# y are bin centers
106110
dy = np.diff(y)
107111
dyu = np.unique(dy)
108112
if len(dyu) > 1:
109-
if coord == 'y':
110-
warning('Only bin centers given for y and bin separation distance is not constant. ' + \
111-
'Bin width assumed based on separation distance and data pickers will not work properly.')
112-
else:
113-
warning('Only bin centers given for x and bin separation distance is not constant. ' + \
114-
'Bin width assumed based on separation distance and data pickers will not work properly.')
113+
warning(f'Only bin centers given for {coord} and bin separation distance is not constant. ' + \
114+
'Bin width assumed based on separation distance and data pickers will not work properly.')
115115
y = np.append(y, y[-1] + dy[-1])
116116
else:
117117
y = np.append(y, y[-1] + dy[0])
@@ -217,7 +217,7 @@ def boundaryInfo(x, coord):
217217

218218
def iscategorical(x):
219219
return isinstance(x[0], np.character)
220-
220+
221221
def categoryinfo(x):
222222
if len(x.shape) > 1:
223223
raise ValueError('If x contains characters, it must have one column or one row.')
@@ -359,6 +359,16 @@ def allint(x):
359359
if np.all(np.isnan(z)):
360360
allnan = True
361361

362+
if len(x) == 1 and type(x[0]) == datetime.datetime:
363+
# If single time value, we only want a tick value at that time.
364+
stv = x[0].isoformat().replace("+00:00","Z")
365+
x = np.array([stv])
366+
367+
if len(y) == 1 and type(y[0]) == datetime.datetime:
368+
# If single time value, we only want a tick value at that time.
369+
stv = y[0].isoformat().replace("+00:00","Z")
370+
y = np.array([stv])
371+
362372
categoricalx = iscategorical(x)
363373
x, xc, xedges, xcl, xlabels = boundaryInfo(x,'x')
364374

@@ -420,18 +430,19 @@ def allint(x):
420430
hatch=opts['nan.hatch']+opts['nan.hatch'],
421431
edgecolor=edgecolor, label='NaN'))
422432

433+
#for spine in ax.spines.values(): spine.set_edgecolor(None)
434+
423435
# TODO: Handle case where > 10.
424436
# Label every Nth, etc. as needed
425437
if xedges and x.size <= 10:
426438
ax.set_xticks(x)
427439
if xc.size > 0 and xc.size <= 10:
428440
ax.set_xticks(xc)
429-
if len(xcl) > 0:
441+
if len(xcl) > 0 and len(xlabels) > 0:
430442
# Relabel x-ticks b/c nonuniform center spacing.
431443
ax.set_xticklabels(xcl[0:-1])
432444

433-
#for spine in ax.spines.values(): spine.set_edgecolor(None)
434-
445+
# TODO: Duplicate code
435446
if yedges and y.size <= 10:
436447
ax.set_yticks(y)
437448
if yc.size > 0 and yc.size <= 10:
@@ -511,7 +522,7 @@ def setTicks(labels, coord):
511522
if len(zc) == 1:
512523
nc = len(zc)
513524
else:
514-
nc = np.int(zc[-1]-zc[0] + 1)
525+
nc = int(zc[-1]-zc[0] + 1)
515526
nc = np.min([1024, nc])
516527
if 'cmap.numcolors' in kwargs:
517528
if opts['cmap.numcolors'] != nc:

hapiplot/plot/heatmap_test.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
from datetime import datetime, timedelta
88
import numpy as np
99

10-
#tests = range(0,31)
11-
#tests = range(27,29)
12-
#tests = range(23,24)
13-
tests = range(0,3)
14-
#tests = [25]
15-
tests = [4]
10+
tests = range(0,5)
11+
tests = [0]
1612

1713
import matplotlib as plt
1814
plt.rcParams.update({'figure.max_open_warning': 0})
@@ -33,7 +29,7 @@ def testimg(fig, tn, tl):
3329

3430
for tn in tests:
3531

36-
# 1x1 ints
32+
# 1x1 ints and datetimes
3733
if tn == 0:
3834
x = np.array([1]) # Columns
3935
y = np.array([1]) # Rows
@@ -56,61 +52,68 @@ def testimg(fig, tn, tl):
5652
fig, _ = heatmap(x, y, z, title=title)
5753
testimg(fig,tn,'c')
5854

55+
x = [datetime(1970, 1, 1)]
56+
y = [1]
57+
z = [[1]]
58+
title = 'test #' + str(tn) + 'd z=1x1 dtime; col center and row center'
59+
fig, _ = heatmap(x, y, z, title=title)
60+
testimg(fig,tn,'d')
61+
5962
# 1x2 and 2x1 ints
6063
if tn == 1:
6164
x = np.array([1]) # Columns
6265
y = np.array([1,2]) # Rows
6366
z = np.array([[1],[2]])
64-
title = 'test #' + str(tn) + 'd z=2x1 ints; col center and row centers'
67+
title = 'test #' + str(tn) + 'a z=2x1 ints; col center and row centers'
6568
fig, _ = heatmap(x, y, z, title=title)
6669
testimg(fig,tn,'a')
6770

6871
x = np.array([1,2]) # Columns
6972
y = np.array([1,2]) # Rows
7073
z = np.array([[1],[2]])
71-
title = 'test #' + str(tn) + 'd z=2x1 ints; col edges and row centers'
74+
title = 'test #' + str(tn) + 'b z=2x1 ints; col edges and row centers'
7275
fig, _ = heatmap(x, y, z, title=title)
7376
testimg(fig,tn,'b')
7477

7578
x = np.array([1]) # Columns
7679
y = np.array([1,2,3]) # Rows
7780
z = np.array([[1],[2]])
78-
title = 'test #' + str(tn) + 'f z=2x1 ints; col center and row edges'
81+
title = 'test #' + str(tn) + 'c z=2x1 ints; col center and row edges'
7982
fig, _ = heatmap(x, y, z, title=title)
8083
testimg(fig,tn,'c')
8184

8285
x = np.array([1,4]) # Columns
8386
y = np.array([1,2,3]) # Rows
8487
z = np.array([[1],[2]])
85-
title = 'test #' + str(tn) + 'g z=2x1 ints; col edges and row edges'
88+
title = 'test #' + str(tn) + 'd z=2x1 ints; col edges and row edges'
8689
fig, _ = heatmap(x, y, z, title=title)
8790
testimg(fig,tn,'d')
8891

8992
x = np.array([1,2]) # Columns
9093
y = np.array([1]) # Rows
9194
z = np.array([[1,2]])
92-
title = 'test #' + str(tn) + 'h z=1x2 ints; col centers and row center'
95+
title = 'test #' + str(tn) + 'e z=1x2 ints; col centers and row center'
9396
fig, _ = heatmap(x, y, z, title=title)
9497
testimg(fig,tn,'e')
9598

9699
x = np.array([1,2]) # Columns
97100
y = np.array([1,2]) # Rows
98101
z = np.array([[1,2]])
99-
title = 'test #' + str(tn) + 'i z=1x2 ints; col centers and row edges'
102+
title = 'test #' + str(tn) + 'f z=1x2 ints; col centers and row edges'
100103
fig, _ = heatmap(x, y, z, title=title)
101104
testimg(fig,tn,'f')
102105

103106
x = np.array([1,2,3]) # Columns
104107
y = np.array([1]) # Rows
105108
z = np.array([[1,2]])
106-
title = 'test #' + str(tn) + 'j z=1x2 ints; col edges and row center'
109+
title = 'test #' + str(tn) + 'g z=1x2 ints; col edges and row center'
107110
fig, _ = heatmap(x, y, z, title=title)
108111
testimg(fig,tn,'g')
109112

110113
x = np.array([1,3,4]) # Columns
111114
y = np.array([1,2.5]) # Rows
112115
z = np.array([[1,2]])
113-
title = 'test #' + str(tn) + 'k z=1x2 ints; col edges and row edges'
116+
title = 'test #' + str(tn) + 'h z=1x2 ints; col edges and row edges'
114117
fig, _ = heatmap(x, y, z, title=title)
115118
testimg(fig,tn,'h')
116119

test/bugs.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
all = False
88
bn = 3
99

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+
1030
if bn == 1 or all == True:
1131
# No data from 10-20 but still colored
1232
server = 'http://hapi-server.org/servers-dev/TestData2.0/hapi'
@@ -34,3 +54,35 @@
3454

3555
popts = {'logging': True, 'returnimage': False, 'usecache': False}
3656
hapiplot(data, meta, **popts)
57+
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)