-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_traces.py
81 lines (74 loc) · 2.25 KB
/
plot_traces.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
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
import os.path
import sys
import json
import glob
import numpy as np
import matplotlib.pyplot as plt
def getMeta(npy_filename):
json_filename=os.path.splitext(npy_filename)[0]+".json"
with open(json_filename, "r", encoding='latin1') as f:
meta=json.load(f)
return meta
def createX(meta):
x0=meta['x_0']
deltax=meta['delta_x']
numpnts=meta['numpnts']
lastx=x0+deltax*numpnts
x=np.linspace(x0,lastx,numpnts)
return x
def getNpyBasename(npy_filename):
return os.path.basename(os.path.splitext(npy_filename)[0])
class TraceKey:
"""Key useable for sorting tracenames."""
def __init__(self,npy_filename):
c=getNpyBasename(npy_filename).split('_')
self.prefix=c[0]
self.group=int(c[1])
self.series=int(c[2])
self.sweep=int(c[3])
self.trace=c[4]
def __lt__(self, other):
if(self.prefix<other.prefix):
return True
if(self.prefix>other.prefix):
return False
if(self.group<other.group):
return True
if(self.group>other.group):
return False
if(self.series<other.series):
return True
if(self.series>other.series):
return False
if(self.sweep<other.sweep):
return True
if(self.sweep>other.sweep):
return False
if(self.trace<other.trace):
return True
return False
if __name__ == '__main__':
if(len(sys.argv)<2):
print("""
usage: plot_traces <pattern1>.npy [<pattern2>.npy ...]
example: plot_traces "PM_1_*V*.npy" "PM_2_*Vm.npy"
""",file=sys.stderr)
sys.exit(-1)
fig, ax = plt.subplots()
filelist=[]
for index in range(1,len(sys.argv)):
filelist+=glob.glob(sys.argv[index])
if(len(filelist)==0):
print("no matching files found",file=sys.stderr)
sys.exit(-1)
filelist.sort(key=TraceKey)
for npy_filename in filelist:
basename=os.path.basename(os.path.splitext(npy_filename)[0])
meta=getMeta(npy_filename)
x_w=createX(meta)
y_w=np.load(npy_filename)
ax.plot(x_w,y_w,label=basename)
ax.legend()
ax.set_xlabel('['+meta['unit_x']+']')
ax.set_ylabel('['+meta['unit_y']+']')
plt.show()