12 def __init__(self
, width
, height
):
17 self
.margin_bottom
=40;
31 self
.surface
= cairo
.ImageSurface (cairo
.FORMAT_ARGB32
,
32 self
.width
, self
.height
);
33 self
.ctx
= cairo
.Context (self
.surface
);
35 def set_x_range (self
, xmin
, xmax
):
37 print "Invalid x range";
40 self
.range_xmin
=float(xmin
);
41 self
.range_xmax
=float(xmax
);
43 def set_y_range (self
, ymin
, ymax
):
44 print "y range %g %g" % (ymin
, ymax
);
46 print "Invalid y range";
49 self
.range_ymin
=float(ymin
);
50 self
.range_ymax
=float(ymax
);
52 def set_x_range_data (self
, data
):
55 self
.set_x_range(xmin
,xmax
);
57 def set_y_range_data (self
, data
):
60 self
.set_y_range(ymin
,ymax
);
62 def set_sane_ticks (self
):
63 logrange
= math
.log10((self
.range_xmax
- self
.range_xmin
)/3);
64 tick
= math
.pow(10, math
.floor(logrange
));
65 self
.tick_major_x
= tick
;
67 logrange
= math
.log10((self
.range_ymax
- self
.range_ymin
)/3);
68 tick
= math
.pow(10, math
.floor(logrange
));
69 self
.tick_major_y
= tick
;
71 print "tick %g %g" % (self
.tick_major_x
, self
.tick_major_y
);
73 def draw_border (self
):
74 self
.ctx
.move_to (self
.margin_left
, self
.margin_top
);
75 self
.ctx
.line_to (self
.width
- self
.margin_right
, self
.margin_top
);
76 self
.ctx
.line_to (self
.width
- self
.margin_right
, self
.height
- self
.margin_bottom
);
77 self
.ctx
.line_to (self
.margin_left
, self
.height
- self
.margin_bottom
);
78 self
.ctx
.close_path ();
80 self
.ctx
.set_source_rgb (0, 0, 0);
83 def marker (self
, x
, y
):
84 self
.ctx
.move_to (x
, y
);
86 self
.ctx
.identity_matrix ();
87 self
.ctx
.rel_move_to (-self
.symbol_size
, 0);
88 self
.ctx
.rel_line_to (self
.symbol_size
*2, 0);
89 self
.ctx
.rel_move_to (-self
.symbol_size
, -self
.symbol_size
);
90 self
.ctx
.rel_line_to (0, self
.symbol_size
*2);
93 def draw_plot (self
, points
):
96 self
.ctx
.translate (self
.margin_left
,
97 self
.height
- self
.margin_bottom
);
98 self
.ctx
.scale ((self
.width
- self
.margin_right
- self
.margin_left
)/
99 (self
.range_xmax
- self
.range_xmin
),
100 -(self
.height
- self
.margin_top
- self
.margin_bottom
)/
101 (self
.range_ymax
- self
.range_ymin
));
102 self
.ctx
.translate (-self
.range_xmin
, -self
.range_ymin
);
104 if (self
.with_lines
):
105 self
.ctx
.move_to (points
[0][0], points
[0][1]);
106 for point
in points
[1:]:
107 self
.ctx
.line_to (point
[0], point
[1]);
110 self
.marker (point
[0], point
[1]);
116 self
.ctx
.move_to (self
.range_xmin
, y
);
118 self
.ctx
.identity_matrix ();
119 self
.ctx
.rel_move_to (0, 0);
120 self
.ctx
.rel_line_to (-self
.tick_size
, 0);
124 self
.ctx
.move_to (x
, self
.range_ymin
);
126 self
.ctx
.identity_matrix ();
127 self
.ctx
.rel_move_to (0, 0);
128 self
.ctx
.rel_line_to (0, self
.tick_size
);
131 def vlabel (self
, y
):
132 self
.ctx
.move_to (self
.range_xmin
, y
);
134 self
.ctx
.identity_matrix ();
135 self
.ctx
.rel_move_to (-self
.tick_size
* 6, 0);
136 self
.ctx
.show_text("%g" % y
);
139 def hlabel (self
, x
):
140 self
.ctx
.move_to (x
, self
.range_ymin
);
142 self
.ctx
.identity_matrix ();
143 self
.ctx
.rel_move_to (0, self
.tick_size
* 4);
144 self
.ctx
.show_text("%g" % x
);
147 def draw_ticks (self
):
149 self
.ctx
.translate (self
.margin_left
, self
.height
- self
.margin_bottom
);
150 self
.x_scale
= (self
.width
- self
.margin_right
- self
.margin_left
)/(self
.range_xmax
- self
.range_xmin
);
151 self
.y_scale
= (self
.height
- self
.margin_top
- self
.margin_bottom
)/(self
.range_ymax
- self
.range_ymin
);
152 print "scale %g %g" % (self
.x_scale
, self
.y_scale
);
153 self
.ctx
.scale (self
.x_scale
, -self
.y_scale
);
154 self
.ctx
.translate (-self
.range_xmin
, -self
.range_ymin
);
157 while (x
<= self
.range_ymax
):
159 x
+=self
.tick_major_y
;
161 while (x
<= self
.range_xmax
):
163 x
+=self
.tick_major_x
;
166 while (x
<= self
.range_ymax
):
168 x
+=self
.tick_major_y
;
170 while (x
<= self
.range_xmax
):
172 x
+=self
.tick_major_x
;
175 self
.ctx
.set_source_rgb (0, 0, 0);
178 def readdata(filename
):
179 file = open(filename
);
182 for line
in file.readlines():
183 points
.append(map(float,line
.split()));
190 plot
= Plot(800,600);
191 plot
.set_x_range_data(tpts
[0]);
192 m
= max(Numeric
.transpose(tpts
[14]));
193 #plot.set_x_range(0, m);
194 plot
.set_y_range(0, m
);
196 plot
.set_sane_ticks();
198 plot
.ctx
.set_source_rgb (1, 1, 1);
199 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
205 plot
.ctx
.set_line_width(0.5);
207 plot
.ctx
.set_source_rgb (1, 0, 0);
208 plot
.draw_plot (Numeric
.transpose(tpts
[0:15:14]));
210 plot
.ctx
.set_source_rgb (0, 1, 0);
211 plot
.draw_plot (Numeric
.transpose(tpts
[0:16:15]));
213 #plot.with_lines = 0;
214 #plot.draw_plot (Numeric.transpose(tpts[14:16:1]));
216 plot
.surface
.write_to_png('00000-mse.png');
218 def plot_buffer_level():
219 plot
= Plot(800,600);
220 plot
.set_x_range_data(tpts
[0]);
221 m
= max(Numeric
.transpose(tpts
[11]));
222 plot
.set_y_range(0, m
);
224 plot
.set_sane_ticks();
226 plot
.ctx
.set_source_rgb (1, 1, 1);
227 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
233 plot
.ctx
.set_line_width(0.5);
235 plot
.ctx
.set_source_rgb (1, 0, 0);
236 plot
.draw_plot (Numeric
.transpose(tpts
[0:12:11]));
238 plot
.surface
.write_to_png('00000-buffer-level.png');
240 def plot_bits_per_pic():
241 plot
= Plot(800,600);
242 plot
.set_x_range_data(tpts
[0]);
244 data_x
= Numeric
.transpose(tpts
[0]);
245 data_y1
= Numeric
.transpose(tpts
[8]);
246 data_y2
= Numeric
.transpose(tpts
[9]);
247 data_y
= Numeric
.transpose(tpts
[8]+tpts
[9]);
248 m
= max(Numeric
.transpose(data_y
));
249 plot
.set_y_range(0, m
);
251 plot
.set_sane_ticks();
253 plot
.ctx
.set_source_rgb (1, 1, 1);
254 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
260 plot
.ctx
.set_line_width(0.5);
262 plot
.ctx
.set_source_rgb (1, 0, 0);
264 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
266 plot
.ctx
.set_source_rgb (0, 1, 0);
268 plot
.draw_plot (Numeric
.transpose([data_x
,data_y1
]));
270 plot
.ctx
.set_source_rgb (0, 0, 1);
272 plot
.draw_plot (Numeric
.transpose([data_x
,data_y2
]));
274 plot
.ctx
.set_source_rgb (0.5, 0.5, 0.5);
276 plot
.draw_plot (Numeric
.transpose([data_x
,Numeric
.transpose(tpts
[3])]));
278 plot
.ctx
.set_source_rgb (0.5, 0.5, 0.5);
280 plot
.draw_plot (Numeric
.transpose([data_x
,Numeric
.transpose(tpts
[4])]));
282 plot
.surface
.write_to_png('00000-bits-per-pic.png');
284 def plot_badblock_ratio():
285 plot
= Plot(800,600);
286 data_x
= Numeric
.transpose(tpts
[0]);
287 data_y
= Numeric
.transpose(tpts
[17]);
290 plot
.set_x_range(0, mx
);
291 plot
.set_y_range(0, my
);
293 plot
.set_sane_ticks();
295 plot
.ctx
.set_source_rgb (1, 1, 1);
296 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
302 plot
.ctx
.set_line_width(0.5);
304 plot
.ctx
.set_source_rgb (1, 0, 0);
305 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
307 plot
.surface
.write_to_png('00000-badblock-ratio.png');
309 def plot_est_act_residual():
310 plot
= Plot(800,600);
311 mx
= max(Numeric
.transpose(tpts
[7]));
312 my
= max(Numeric
.transpose(tpts
[9]));
314 plot
.set_x_range(0, m
);
315 plot
.set_y_range(0, m
);
317 plot
.set_sane_ticks();
319 plot
.ctx
.set_source_rgb (1, 1, 1);
320 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
326 plot
.ctx
.set_line_width(0.5);
328 plot
.ctx
.set_source_rgb (0, 1, 0);
330 plot
.draw_plot ( [[0,0],[m
,m
]]);
332 plot
.ctx
.set_source_rgb (1, 0, 0);
334 plot
.draw_plot (Numeric
.transpose(tpts
[7:10:2]));
336 plot
.surface
.write_to_png('00000-est-act-residual.png');
338 def plot_alloc_est_residual():
339 plot
= Plot(800,600);
340 data_x
= Numeric
.transpose(tpts
[4]);
341 data_y
= Numeric
.transpose(tpts
[7]);
345 plot
.set_x_range(0, m
);
346 plot
.set_y_range(0, m
);
348 plot
.set_sane_ticks();
350 plot
.ctx
.set_source_rgb (1, 1, 1);
351 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
357 plot
.ctx
.set_line_width(0.5);
359 plot
.ctx
.set_source_rgb (0, 1, 0);
361 plot
.draw_plot ( [[0,0],[m
,m
]]);
363 plot
.ctx
.set_source_rgb (1, 0, 0);
365 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
367 plot
.surface
.write_to_png('00000-alloc-est-residual.png');
369 def plot_est_act_mc():
370 plot
= Plot(800,600);
371 mx
= max(Numeric
.transpose(tpts
[6]));
372 my
= max(Numeric
.transpose(tpts
[8]));
374 plot
.set_x_range(0, m
);
375 plot
.set_y_range(0, m
);
377 plot
.set_sane_ticks();
379 plot
.ctx
.set_source_rgb (1, 1, 1);
380 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
386 plot
.ctx
.set_line_width(0.5);
388 plot
.ctx
.set_source_rgb (0, 1, 0);
390 plot
.draw_plot ( [[0,0],[m
,m
]]);
392 plot
.ctx
.set_source_rgb (1, 0, 0);
394 plot
.draw_plot (Numeric
.transpose(tpts
[6:9:2]));
396 plot
.surface
.write_to_png('00000-est-act-mc.png');
398 def plot_est_mc_scs():
399 plot
= Plot(800,600);
400 data_x
= Numeric
.transpose(tpts
[6]);
401 data_y
= Numeric
.transpose(tpts
[10]);
404 plot
.set_x_range(0, mx
);
405 plot
.set_y_range(0, 0.1);
407 plot
.set_sane_ticks();
409 plot
.ctx
.set_source_rgb (1, 1, 1);
410 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
416 plot
.ctx
.set_line_width(0.5);
418 plot
.ctx
.set_source_rgb (1, 0, 0);
420 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
422 plot
.surface
.write_to_png('00000-est-mc-scs.png');
425 plot
= Plot(800,600);
426 #mx = max(Numeric.transpose(tpts[10]));
428 my
= max(Numeric
.transpose(tpts
[14]));
429 plot
.set_x_range(0, mx
);
430 plot
.set_y_range(0, my
);
432 plot
.set_sane_ticks();
434 plot
.ctx
.set_source_rgb (1, 1, 1);
435 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
441 plot
.ctx
.set_line_width(0.5);
443 plot
.ctx
.set_source_rgb (1, 0, 0);
445 plot
.draw_plot (Numeric
.transpose(tpts
[10:15:4]));
447 plot
.surface
.write_to_png('00000-scs-mse.png');
450 plot
= Plot(800,600);
451 data_x
= Numeric
.transpose(tpts
[0]);
452 data_y
= Numeric
.transpose(tpts
[14]);
455 plot
.set_x_range(0, mx
);
456 plot
.set_y_range(0, my
);
458 plot
.set_sane_ticks();
460 plot
.ctx
.set_source_rgb (1, 1, 1);
461 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
467 plot
.ctx
.set_line_width(0.5);
469 plot
.ctx
.set_source_rgb (1, 0, 0);
471 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
473 plot
.surface
.write_to_png('00000-scs.png');
475 def plot_badblock_vs_mse():
476 plot
= Plot(800,600);
477 data_x
= Numeric
.transpose(tpts
[17]);
478 data_y
= Numeric
.transpose(tpts
[14]);
481 plot
.set_x_range(0, mx
);
482 plot
.set_y_range(0, my
);
484 plot
.set_sane_ticks();
486 plot
.ctx
.set_source_rgb (1, 1, 1);
487 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
493 plot
.ctx
.set_line_width(0.5);
495 plot
.ctx
.set_source_rgb (1, 0, 0);
497 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
499 plot
.surface
.write_to_png('00000-badblock-vs-mse.png');
501 def plot_mc_error_vs_mse():
502 plot
= Plot(800,600);
503 data_x
= Numeric
.transpose(tpts
[13]);
504 data_y
= Numeric
.transpose(tpts
[14]);
505 #data_x = Numeric.transpose(tpts[0]);
506 #data_y = Numeric.transpose(tpts[13])/Numeric.transpose(tpts[14]);
509 plot
.set_x_range_data(data_x
);
510 plot
.set_y_range(0, my
);
512 plot
.set_sane_ticks();
514 plot
.ctx
.set_source_rgb (1, 1, 1);
515 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
521 plot
.ctx
.set_line_width(0.5);
523 plot
.ctx
.set_source_rgb (0, 1, 0);
525 plot
.draw_plot ( [[0,0],[mx
,mx
]]);
527 plot
.ctx
.set_source_rgb (1, 0, 0);
529 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
531 plot
.surface
.write_to_png('00000-mc-error-vs-mse.png');
533 def plot_hist_slope():
534 plot
= Plot(800,600);
535 data_x
= Numeric
.transpose(tpts
[0]);
536 data_y
= Numeric
.transpose(tpts
[18]);
537 plot
.set_x_range_data(data_x
);
538 plot
.set_y_range_data(data_y
);
540 plot
.set_sane_ticks();
542 plot
.ctx
.set_source_rgb (1, 1, 1);
543 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
549 plot
.ctx
.set_line_width(0.5);
551 plot
.ctx
.set_source_rgb (1, 0, 0);
552 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
554 plot
.surface
.write_to_png('00000-hist-slope.png');
556 def plot_hist_slope_vs_mse():
557 plot
= Plot(800,600);
558 data_x
= Numeric
.transpose(tpts
[18]);
559 data_y
= Numeric
.transpose(tpts
[14]);
560 plot
.set_x_range_data(data_x
);
561 plot
.set_y_range_data(data_y
);
563 plot
.set_sane_ticks();
565 plot
.ctx
.set_source_rgb (1, 1, 1);
566 plot
.ctx
.set_operator (cairo
.OPERATOR_SOURCE
);
572 plot
.ctx
.set_line_width(0.5);
575 plot
.ctx
.set_source_rgb (1, 0, 0);
576 plot
.draw_plot (Numeric
.transpose([data_x
,data_y
]));
578 plot
.surface
.write_to_png('00000-hist-slope-vs-mse.png');
581 pts
= readdata("schro_dump.picture");
583 tpts
= Numeric
.transpose(pts
);
587 plot_alloc_est_residual();
588 plot_est_act_residual();
594 plot_badblock_ratio();
595 plot_badblock_vs_mse();
596 plot_mc_error_vs_mse();
598 plot_hist_slope_vs_mse();