-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateFigures.py
More file actions
293 lines (252 loc) · 13.4 KB
/
createFigures.py
File metadata and controls
293 lines (252 loc) · 13.4 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env python3
# example usage:
# python3 createFigures.py -i outputDataCollection -o figures
import matplotlib.pyplot as plt
import matplotlib.patches as mplpatches
import numpy as np
import argparse
import random
import math
import pandas
import datetime
import time
def createFigure(inputFile, outputDirectory):
# parse data
data = {}
df = pandas.read_csv(inputFile, sep='\t', names=("file name", "test type", "graph type", "real", "usr", "sys", "max memory", "nodes/edges/paths", "nodes/edges/paths time", "blank"))
df = df.drop("blank", axis=1)
# print(df)
convertData = []
deserializeData = []
for testType in df["test type"].unique():
if testType == 0:
convertData = df.loc[df['test type'] == testType]
if testType == 2:
deserializeData = df.loc[df['test type'] == testType]
elif testType > 2:
data[testType] = df.loc[df['test type'] == testType]
for fileName in convertData["file name"].unique():
if fileName == "all.vg" or fileName == "created" or fileName == ".DS_Store":
pass
else:
# make the figure
figure_width = 6.5
figure_height = 6.5
plt.figure(figsize=(figure_width, figure_height))
panel_width = 1 / figure_width # gives fraction so that we get 1 inch
panel_height = 1 / figure_height
panel1 = plt.axes([.1, .525, panel_width * 2, panel_height * 2])
panel2 = plt.axes([.6, .525, panel_width * 2, panel_height * 2])
panel3 = plt.axes([.1, .1, panel_width * 2, panel_height * 2])
panel4 = plt.axes([.6, .1, panel_width * 2, panel_height * 2])
panel5 = plt.axes([.1, .925, panel_width * 5.25, panel_height / 4], frameon=False)
# remove tick marks/labeling from legend
panel5.tick_params(axis="both", which="both",
bottom=False, labelbottom=False,
left=False, labelleft=False,
right=False, labelright=False,
top=False, labeltop=False
)
convertFileData = convertData.loc[df["file name"] == fileName]
memory = {}
speed = {}
utilize = {}
nodes = {}
edges = {}
paths = {}
print(fileName)
for graphType in convertFileData["graph type"].unique():
graphName = None
if graphType == 1:
graphName = ".vg"
elif graphType == 2:
graphName = ".pg"
elif graphType == 3:
graphName = ".hg"
elif graphType == 4:
graphName = ".og"
deserializeFileGraphData = deserializeData.loc[df["file name"] == fileName[:-3]+graphName].loc[df["graph type"] == graphType]
utilize[graphType] = np.mean(deserializeFileGraphData["max memory"])
convertFileGraphData = convertFileData.loc[df["graph type"] == graphType]
memory[graphType] = np.mean(convertFileGraphData["max memory"])
# speed[graphType] = np.mean(convertFileGraphData["sys"] + convertFileGraphData["usr"])
speed[graphType] = [convertFileGraphData["sys"] + convertFileGraphData["usr"]]
for testType in [3,4,5]:
dataFileGraphData = data[testType].loc[df["file name"] == fileName[:-3] + graphName].loc[df["graph type"] == graphType]
if testType == 3:
x = time.strptime(dataFileGraphData["nodes/edges/paths time"].split(',')[0],'%H:%M:%S')
nodes[graphType] = [datetime.timedelta(hours=x.tm_hour, minutes=x.tm_min, seconds=x.tm_sec).total_seconds()] /np.mean(dataFileGraphData["nodes/edges/paths"].astype(np.float))
print(nodes[graphType])
elif testType ==4:
edges[graphType] = [dataFileGraphData["nodes/edges/paths time"].astype(np.float)] /np.mean(dataFileGraphData["nodes/edges/paths"].astype(np.float))
elif testType == 5:
paths[graphType] = [dataFileGraphData["nodes/edges/paths time"].astype(np.float)] /np.mean(dataFileGraphData["nodes/edges/paths"].astype(np.float))
# colors of vg, pg, hg, and og
R = [128/255,168/255,67/255,7/255]
G = [171/255,221/255,162/255,104/255]
B = [134/255,181/255,202/255,172/255]
# graphNumbers = {1:"vg", 2:"pg", 3:"hg", 4:"og"}
graphNumbers = {1: "vg", 2: "pg", 3: "hg"}
# legend
bins = np.arange(0, len(graphNumbers) + 1, 1)
for index in range(0, len(graphNumbers)):
bottom = 0
left = bins[index]
width = bins[index + 1] - left -.8
height = 1
rectangle1 = mplpatches.Rectangle([left, bottom], width, height,
edgecolor="black",
facecolor=(R[index], G[index], B[index]),
linewidth=.1)
panel5.add_patch(rectangle1)
panel5.text(left+ width + .15, bottom+(height/2), graphNumbers[index+1], va="center", ha="center")
panel5.set_ylim(0, 1)
panel5.set_xlim(0, 4)
# panel 1, 2, 3
bins = np.arange(0, len(memory)+1, 1)
errorBarWidth = .015
errorBins = [ b+.5 - errorBarWidth/2 for b in bins]
errorBars = []
for index in range(0, len(memory)):
bottom = 0
left = bins[index] + .1
width = bins[index + 1] - left - .1
errorBarLeft = errorBins[index]
height = memory[index+1]
rectangle1 = mplpatches.Rectangle([left, bottom], width, height,
edgecolor="black",
facecolor=(R[index], G[index], B[index]),
linewidth=.1)
panel1.add_patch(rectangle1)
speedHeight = np.mean(speed[index+1])
rectangle2 = mplpatches.Rectangle([left, bottom], width, speedHeight,
edgecolor="black",
facecolor=(R[index], G[index], B[index]),
linewidth=.1)
panel2.add_patch(rectangle2)
speedStd = np.std(speed[index + 1])
errorBar = mplpatches.Rectangle([errorBarLeft, speedHeight-speedStd], errorBarWidth, speedStd*2,
edgecolor="black",
facecolor="black",
linewidth=.1)
errorBars.append(speedHeight+speedStd)
panel2.add_patch(errorBar)
utilizeHeight = utilize[index + 1]
rectangle3 = mplpatches.Rectangle([left, bottom], width,
utilizeHeight,
edgecolor="black",
facecolor=(R[index], G[index], B[index]),
linewidth=.1)
panel3.add_patch(rectangle3)
scientific = np.format_float_scientific(max(memory.values())*1.1)
power = int(scientific.split("e+")[-1])
panel1.set_ylim(0, max(memory.values()) * 1.1)
panel1.set_xlim(0, max(bins))
roundedNumber = special_round(max(memory.values()) * 1.1, 10**power)
panel1.set_yticks([a for a in np.linspace(0, roundedNumber, 5)])
panel1.set_yticklabels([a for a in np.linspace(0, roundedNumber/10**power, 5)])
panel1.set_ylabel("Maximum Memory ($10^{" + str(power) + "}$ bytes)", )
panel1.set_title("Construction Memory Usage")
# offset = panel1.get_yaxis().get_offset_text()
# print(offset, offset.get_text())
# panel1.set_ylabel('{0} {1}'.format(panel1.get_ylabel(), offset))
# offset.set_visible(False)
# modify tick marks/labeling
panel1.tick_params(axis="both", which="both",
bottom=False, labelbottom=False,
left=True, labelleft=True,
right=False, labelright=False,
top=False, labeltop=False
)
panel2.set_ylim(0, max(errorBars) * 1.05)
panel2.set_xlim(0, max(bins))
panel2.set_ylabel("Time (CPU cycles)")
# modify tick marks/labeling
panel2.tick_params(axis="both", which="both",
bottom=False, labelbottom=False,
left=True, labelleft=True,
right=False, labelright=False,
top=False, labeltop=False
)
scientific = np.format_float_scientific(max(utilize.values()) * 1.1)
power = int(scientific.split("e+")[-1])
panel3.set_ylim(0, max(utilize.values()) * 1.1)
panel3.set_xlim(0, max(bins))
roundedNumber = special_round(max(utilize.values()) * 1.1, 10 ** power)
panel3.set_yticks([a for a in np.linspace(0, roundedNumber, 5)])
panel3.set_yticklabels([a for a in np.linspace(0, roundedNumber / 10 ** power, 5)])
panel3.set_ylabel("Maximum Memory ($10^{" + str(power) + "}$ bytes)", )
panel2.set_title("Construction Speed Usage")
panel3.set_title("Utilization Memory Usage")
# modify tick marks/labeling
panel3.tick_params(axis="both", which="both",
bottom=False, labelbottom=False,
left=True, labelleft=True,
right=False, labelright=False,
top=False, labeltop=False
)
# panel 4
bins = np.arange(0, len(nodes) *3 + 1, 1)
errorBarWidth = .04
errorBins = [b + .5 - errorBarWidth / 2 for b in bins]
errorBars = []
counter = 0
for nep in [nodes, edges, paths]:
nepIndexing = 0
for index in range(len(nodes) *(counter), len(nodes) * (counter+1)):
bottom = 0
left = bins[index]
width = bins[index + 1] - left
height = np.mean(nep[nepIndexing +1])
errorBarLeft = errorBins[index]
rectangle1 = mplpatches.Rectangle([left, bottom], width,
height,
edgecolor="black",
facecolor=(R[nepIndexing], G[nepIndexing], B[nepIndexing]),
linewidth=.1)
panel4.add_patch(rectangle1)
speedStd = np.std(nep[nepIndexing +1])
errorBar = mplpatches.Rectangle([errorBarLeft, height - speedStd], errorBarWidth,
speedStd * 2,
edgecolor="black",
facecolor="black",
linewidth=.1)
errorBars.append(height + speedStd)
panel4.add_patch(errorBar)
nepIndexing += 1
counter += 1
panel4.set_ylim(0, max(errorBars) * 1.1)
panel4.set_xlim(0, max(bins))
panel4.set_ylabel("Time per Access (seconds)")
panel4.set_title("Access Time")
# modify tick marks/labeling
panel4.tick_params(axis="both", which="both",
bottom=False, labelbottom=True,
left=True, labelleft=True,
right=False, labelright=False,
top=False, labeltop=False
)
panel4.set_xticks([ i + len(nodes)/2 for i in np.arange(0, len(nodes)* (counter), 3)])
panel4.set_xticklabels(["nodes", "edges", "paths"])
# save plot to output file
plt.savefig(outputDirectory+"/"+fileName[:-3]+".png", dpi=600)
def argParser():
parser = argparse.ArgumentParser(add_help=True)
parser.add_argument("--outputDirectory", "-o",
type=str,
help="specify the file name of the output file")
parser.add_argument("--inputFile", "-i",
type=str,
help="specify the file name of the input file")
return vars(parser.parse_args())
def special_round(number,base):
"""
Round numbers to a specific base.
"""
floored = math.ceil(number/base) * base
return floored
def main():
args = argParser()
createFigure(args["inputFile"], args["outputDirectory"])
if __name__ == "__main__":
main()