-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
80 lines (72 loc) · 2.23 KB
/
plotter.py
File metadata and controls
80 lines (72 loc) · 2.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
'''
A simple utility that plots level vs. time for the standard h5 (or csv)
level sensor output files.
'''
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('infile', help='The .h5 or .csv input file to plot')
parser.add_argument('-i', '--interactive', action='store_true',
help='interactive plotting')
parser.add_argument('-o', '--output', default=None, help='output file')
args = parser.parse_args()
import h5py
import csv
import numpy as np
import matplotlib
if args.interactive:
pass
else:
matplotlib.use('agg')
import matplotlib.pyplot as plt
import matplotlib.dates as mpldates
import matplotlib.ticker as mplticker
import os
import datetime
from autodateminorlocator import AutoDateMinorLocator
infilename = args.infile
basename, extension = os.path.splitext(infilename)
if args.output:
outfilename = args.output
else:
outfilename = basename + '.pdf'
if extension == '.h5':
with h5py.File(infilename, 'r') as infile:
data = infile['measurements'][:]
elif extension == '.csv':
with open(infilename, 'r') as infile:
reader = csv.reader(infile)
firstrow = next(reader)
data = []
for row in reader:
data.append(list(map(float,row)))
data = np.array(data, dtype=float)
print(data.shape)
else:
raise ValueError("Invalid file extension. Must be .h5 or .csv")
timestamps = data[:,0]
risetimes = data[:,1]
risetimes_err = data[:,2]
positions = data[:,3]
positions_err = data[:,4]
fig, ax1 = plt.subplots()
locator = mpldates.AutoDateLocator();
formatter = mpldates.AutoDateFormatter(locator)
formatter.scaled[1/(24*60.)] = '%H:%M'
ax1.xaxis.set_major_formatter(formatter)
ax1.xaxis.set_major_locator(locator)
ax1.xaxis.set_minor_locator(AutoDateMinorLocator())
ax1.yaxis.set_minor_locator(mplticker.AutoMinorLocator())
ax2 = ax1.twinx()
xvalues = list(map(datetime.datetime.fromtimestamp, timestamps))
ax2.plot(xvalues, risetimes)
ax1.plot(xvalues, positions, alpha=0)
ax1.grid(b=True, which='major', alpha=0.75)
ax1.grid(b=True, which='minor', alpha=0.25)
ax1.set_ylabel(r'Liquid level [cm]')
ax2.set_ylabel(r'$RC$ Rise Time [$\mu$s]')
ax1.set_xlabel('Clock time')
#fig.tight_layout()
if args.interactive:
plt.show()
else:
plt.savefig(outfilename)