-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
245 lines (182 loc) · 8.6 KB
/
Copy pathplot.py
File metadata and controls
245 lines (182 loc) · 8.6 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import matplotlib.pyplot as plt
import numpy as np
import itertools
from glob import glob
import progressbar
AVG_DIR = 'smallavg/'
def function_table():
# function numbers
# AND 00 01 10 11 -> 0001 = 1
AND = 1
# OR 00 01 10 11 -> 0111 = 7
OR = 1 + 2 + 4
# NAND 00 01 10 11 -> 1110 = 14
NAND = 8 + 4 + 2
# NOR 00 01 10 11 -> 1001 = 9
NOR = 8 + 1
# XOR 00 01 10 11 -> 0110 = 6
XOR = 4 + 2
# compile function table
# for each Ci
# make a binary output string 'XXXX'
# corresponding to inputs 00 01 10 11
# if the integer version of that binary number is a func,
# add it to the function dict
Ci_possibilities = ["".join(seq)
for seq in itertools.product("01", repeat=4)]
function_table = {}
for ci in Ci_possibilities:
outstring = ''
for inpair in ['00', '01', '10', '11']:
outputs_for_input = list(map(float, [fname[-5:-4]
for fname in glob('smalldata/' + ci + '_' + inpair + '*')]))
avg_output_for_input = int(round(sum(outputs_for_input)/len(outputs_for_input)))
outstring += str(avg_output_for_input)
#print("output string for {0}: {1}".format(ci, outstring))
outval = int(outstring, 2)
#print("output string int: {0}".format(outval))
if outval == AND:
function_table[ci] = 'AND'
elif outval == OR:
function_table[ci] = 'OR'
elif outval == NAND:
function_table[ci] = 'NAND'
elif outval == NOR:
function_table[ci] = 'NOR'
elif outval == XOR:
function_table[ci] = 'XOR'
else:
function_table[ci] = 'none'
return function_table
def generate_average_signals():
Ci_possibilities = ["".join(seq)
for seq in itertools.product("01", repeat=4)]
for ci in Ci_possibilities:
for inpair in ['00', '01', '10', '11']:
signals = glob('smalldata/' + ci + '_' + inpair + '*')
reduced_signals = signals
for signal in signals:
siggy = np.loadtxt(signal)
if len(siggy) < 96:
reduced_signals.remove(siggy)
if len(siggy) > 100:
print("removing overlong signal: {0}".format(len(siggy)))
reduced_signals.remove(siggy)
signals = reduced_signals
# begin np array of signals (assume len 98)
avg_signal = np.empty((96, len(signals)))
# construct np array of ci,inp files (one ts per column)
bar = progressbar.ProgressBar(max_value=len(signals))
for index, signal in enumerate(signals):
siggy = np.loadtxt(signal)
if len(siggy) > 96:
print("signal too long: length {0}".format(len(siggy)))
while len(siggy) > 96:
siggy = siggy[:-1]
# remove last entry
# add signal to array
avg_signal[:,index] = siggy.T
bar.update(index)
avg_signal = avg_signal.mean(axis=1)
fpath = 'smallavg/' + ci + '_' + inpair + '.txt'
np.savetxt(fpath, avg_signal)
print("finished generating avg signals")
def plot_all():
for ci in ["".join(seq)
for seq in itertools.product("01", repeat=4)]:
for inpair in ['00', '01', '10', '11']:
x = np.linspace(0, 96*3.3, 97*3.3)
plt.gcf().subplots_adjust(left=0.2)#, right=0.73)
#plt.gcf().subplots_adjust(bottom=0.3)
plt.ylabel('Current (A)')
plt.xlabel('\nTime (320 us)')
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off') # labels along the bottom edge are off
for avg_signal in glob('smalldata/' + ci + '_' + inpair + '*'):
ts = np.loadtxt(avg_signal)
plt.plot(ts, label = avg_signal[:-4].strip('smalldata/'))
# Place a legend to the right of this smaller subplot.
#plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., ncol=2)
plt.title("Power Signature of {0}({1})".format(ci, inpair))
plt.savefig('smallimg/' + ci + '_' + inpair + '.png')
plt.clf()
#plt.show()
def plot_averages():
for ci in ["".join(seq)
for seq in itertools.product("01", repeat=4)]:
for inpair in ['00', '01', '10', '11']:
x = np.linspace(0, 96, 97)
#plt.gcf().subplots_adjust(left=0.2)#, right=0.73)
#plt.gcf().subplots_adjust(bottom=0.2)
plt.ylabel('Current (A)')
plt.xlabel('\nTime (320 us)')
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off') # labels along the bottom edge are off
fname = 'smallavg/' + ci + '_' + inpair + '.txt'
ts = np.loadtxt(fname)
plt.plot(ts, label = fname[:-4].strip('smallavg/'))
# Place a legend to the right of this smaller subplot.
#plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., ncol=2)
#plt.title("Average Power Signature of {0}({1})".format(ci, inpair))
plt.axis('off')
plt.savefig('smallimgavg/noplots/' + ci + '_' + inpair + '.png')
plt.clf()
#plt.show()
def plot_all_by_input():
for inpair in ['00', '01', '10', '11']:
for ci in ["".join(seq)
for seq in itertools.product("01", repeat=4)]:
x = np.linspace(0, 96, 97)
plt.gcf().subplots_adjust(left=0.2)#, right=0.73)
plt.gcf().subplots_adjust(bottom=0.2)
plt.ylabel('Current (A)')
plt.xlabel('\nTime (320 us)')
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off') # labels along the bottom edge are off
for fname in glob('smalldata/' + ci + '_' + inpair + '*'):
ts = np.loadtxt(fname)
plt.plot(ts, label = fname[:-4].strip('smallavg/')[:-3])
# Place a legend to the right of this smaller subplot.
#plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)#, ncol=2)
plt.title("Average Power Signature of {0}".format(inpair))
plt.savefig('smallimg/input/' + inpair + '.png')
plt.clf()
def plot_all_averages_by_input():
for inpair in ['00', '01', '10', '11']:
for ci in ["".join(seq)
for seq in itertools.product("01", repeat=4)]:
x = np.linspace(0, 96, 97)
plt.gcf().subplots_adjust(left=0.2, right=0.73)
plt.gcf().subplots_adjust(bottom=0.2)
plt.ylabel('Current (A)')
plt.xlabel('\nTime (320 us)')
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off') # labels along the bottom edge are off
fname = 'smallavg/' + ci + '_' + inpair + '.txt'
ts = np.loadtxt(fname)
plt.plot(ts, label = fname[:-4].strip('smallavg/')[:-3])
# Place a legend to the right of this smaller subplot.
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)#, ncol=2)
#plt.title("Average Power Signature of {0}".format(inpair))
plt.savefig('smallimgavg/input/' + inpair + '.png')
plt.clf()
#plot_all()
#plot_averages()
#plot_all_by_input()
#plot_all_averages_by_input()