5
5
6
6
import matplotlib .pyplot as plt
7
7
import numpy as np
8
- import pandas
9
- from pandas .api .types import is_numeric_dtype
8
+ import polars as pl
10
9
11
10
12
11
def parseArguments (args ):
@@ -29,10 +28,6 @@ def parseArguments(args):
29
28
return parser .parse_args (args )
30
29
31
30
32
- def lavg (l ):
33
- return math .exp (sum (map (math .log , l )) / len (l ))
34
-
35
-
36
31
# seaborn.color_palette("colorblind", 10).as_hex()
37
32
style_colours = [
38
33
"#0173b2" ,
@@ -50,148 +45,36 @@ def lavg(l):
50
45
styles = [(c , m ) for m in style_markers for c in style_colours ]
51
46
52
47
53
- def plotConv (ax , df , yname ):
54
- xmin = df ["mesh A" ].min ()
55
- xmax = df ["mesh A" ].max ()
56
- ymin = df [yname ].min ()
57
- ymax = df [yname ].max ()
58
-
59
- print (xmin , xmax )
60
- print (ymin , ymax )
61
-
62
-
63
- def plotError (df , prefix ):
64
- yname = "relative-l2"
65
- if yname not in df .columns :
66
- print (f"Skipping { yname } as not found in dataset." )
67
- return
68
- fig , ax = plt .subplots (sharex = True , sharey = True )
69
- series = df .groupby ("mapping" )
70
- for grouped , style in zip (series , styles ):
71
- name , group = grouped
72
- if group [yname ].max () == 0 :
73
- print (f"Dropping { yname } -series { name } as all 0" )
74
- continue
75
- color , marker = style
76
- group .plot (
77
- ax = ax ,
78
- logy = True ,
79
- logx = is_numeric_dtype (df ["mesh A" ]),
80
- x = "mesh A" ,
81
- y = yname ,
82
- label = name ,
83
- marker = marker ,
84
- color = color ,
85
- )
86
- ax .set_xlabel ("edge length(h) of mesh A" )
87
- ax .set_ylabel ("relative-l2 error mapping to mesh B" )
88
-
89
- plotConv (ax , df , yname )
90
-
91
- plt .gca ().invert_xaxis ()
92
- plt .grid ()
93
- plt .savefig (prefix + "-error.pdf" )
94
-
95
-
96
- def plotMemory (df , prefix ):
97
- yname = "peakMemB"
48
+ def plot (df : pl .DataFrame , yname : str , ylabel : str , filename : str ):
98
49
if yname not in df .columns :
99
50
print (f"Skipping { yname } as not found in dataset." )
100
51
return
101
- fig , ax = plt .subplots (sharex = True , sharey = True )
102
- series = df .groupby ("mapping" )
103
- for grouped , style in zip (series , styles ):
104
- name , group = grouped
105
- if group [yname ].max () == 0 :
106
- print (f"Dropping { yname } -series { name } as all 0" )
107
- continue
108
- color , marker = style
109
- group .plot (
110
- ax = ax ,
111
- logy = True ,
112
- logx = is_numeric_dtype (df ["mesh A" ]),
113
- x = "mesh A" ,
114
- y = yname ,
115
- label = name ,
116
- marker = marker ,
117
- color = color ,
118
- )
119
- ax .set_xlabel ("edge length(h) of mesh A" )
120
- ax .set_ylabel ("peak memory of participant B [Kbytes]" )
121
52
122
- # plotConv(ax, df, yname)
123
-
124
- plt .gca ().invert_xaxis ()
125
- plt .grid ()
126
- plt .savefig (prefix + "-peakMemB.pdf" )
127
-
128
-
129
- def plotComputeMappingTime (df , prefix ):
130
- yname = "computeMappingTime"
131
- if yname not in df .columns :
132
- print (f"Skipping { yname } as not found in dataset." )
133
- return
134
53
fig , ax = plt .subplots (sharex = True , sharey = True )
135
- series = df .groupby ("mapping" )
136
- for grouped , style in zip (series , styles ):
137
- name , group = grouped
138
- if group [yname ].max () == 0 :
139
- print (f"Dropping { yname } -series { name } as all 0" )
140
- continue
141
- color , marker = style
142
- group .plot (
143
- ax = ax ,
144
- logy = True ,
145
- logx = is_numeric_dtype (df ["mesh A" ]),
146
- x = "mesh A" ,
147
- y = yname ,
148
- label = name ,
149
- marker = marker ,
150
- color = color ,
151
- )
152
-
153
54
ax .set_xlabel ("edge length(h) of mesh A" )
154
- ax .set_ylabel ("time to compute mapping [us]" )
55
+ ax .set_ylabel (ylabel )
56
+ ax .set_yscale ("log" )
57
+ if df ["mesh A" ].dtype .is_numeric ():
58
+ ax .set_xscale ("log" )
155
59
156
- # plotConv(ax, df, yname)
157
-
158
- plt .gca ().invert_xaxis ()
159
- plt .grid ()
160
- plt .savefig (prefix + "-computet.pdf" )
161
-
162
-
163
- def plotMapDataTime (df , prefix ):
164
- yname = "mapDataTime"
165
- if yname not in df .columns :
166
- print (f"Skipping { yname } as not found in dataset." )
167
- return
168
- fig , ax = plt .subplots (sharex = True , sharey = True )
169
- series = df .groupby ("mapping" )
60
+ series = df .group_by ("mapping" )
170
61
for grouped , style in zip (series , styles ):
171
62
name , group = grouped
172
63
if group [yname ].max () == 0 :
173
64
print (f"Dropping { yname } -series { name } as all 0" )
174
65
continue
175
66
color , marker = style
176
- group .plot (
177
- ax = ax ,
178
- logy = True ,
179
- logx = is_numeric_dtype (df ["mesh A" ]),
180
- x = "mesh A" ,
181
- y = yname ,
67
+ ax .plot (
68
+ group ["mesh A" ],
69
+ group [yname ],
182
70
label = name ,
183
71
marker = marker ,
184
72
color = color ,
185
73
)
186
74
187
- ax .set_xlabel ("edge length(h) of mesh A" )
188
- ax .set_ylabel ("time to map Data [us]" )
189
-
190
- # plotConv(ax, df, yname)
191
-
192
75
plt .gca ().invert_xaxis ()
193
76
plt .grid ()
194
- plt .savefig (prefix + "-mapt .pdf" )
77
+ plt .savefig (filename + ".pdf" )
195
78
196
79
197
80
def main (argv ):
@@ -201,16 +84,40 @@ def main(argv):
201
84
plt .rcParams ["figure.figsize" ] = "8, 8"
202
85
plt .rcParams ["figure.autolayout" ] = "true"
203
86
204
- df = pandas .read_csv (args .file )
87
+ df = pl .read_csv (args .file ). sort ( "mesh A" )
205
88
toMeshes = df ["mesh B" ].unique ()
206
89
assert (
207
90
len (toMeshes ) == 1
208
91
), f"There are { len (toMeshes )} to-meshes but only 1 is allowed. Fix your dataset!"
209
- df .sort_values ("mesh A" , inplace = True )
210
- plotError (df , args .prefix )
211
- plotMemory (df , args .prefix )
212
- plotMapDataTime (df , args .prefix )
213
- plotComputeMappingTime (df , args .prefix )
92
+
93
+ if not df ["mesh A" ].dtype .is_numeric ():
94
+ print ("Note: 'mesh A' isn't numeric. The x-axis will not use log scaling." )
95
+
96
+ plot (
97
+ df ,
98
+ yname = "relative-l2" ,
99
+ ylabel = "relative-l2 error mapping to mesh B" ,
100
+ filename = f"{ args .prefix } -error" ,
101
+ )
102
+ plot (
103
+ df ,
104
+ yname = "peakMemB" ,
105
+ ylabel = "peak memory of participant B [Kbytes]" ,
106
+ filename = f"{ args .prefix } -peakMemB" ,
107
+ )
108
+ plot (
109
+ df ,
110
+ yname = "computeMappingTime" ,
111
+ ylabel = "time to compute mapping [us]" ,
112
+ filename = f"{ args .prefix } -computet" ,
113
+ )
114
+ plot (
115
+ df ,
116
+ yname = "mapDataTime" ,
117
+ ylabel = "time to map Data [us]" ,
118
+ filename = f"{ args .prefix } -mapt" ,
119
+ )
120
+
214
121
return 0
215
122
216
123
0 commit comments