SABER
saber_plot.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 import argparse
4 import os
5 import sys
6 
7 # Parser
8 parser = argparse.ArgumentParser()
9 parser.add_argument("bindir", help="Binary directory")
10 parser.add_argument("testdata", help="Test data directory")
11 parser.add_argument("test", help="Test name")
12 parser.add_argument("mpi", help="Number of MPI tasks")
13 parser.add_argument("omp", help="Number of OpenMP threads")
14 args = parser.parse_args()
15 
16 # Insert path
17 sys.path.insert(1, os.path.join(args.bindir, "saber_plot"))
18 
19 # Available plots list
20 plot_list=["avg","diag","dirac","lct","lct_cor","local_diag_cor","local_diag_loc","normality","randomization","sampling_grids","umf","var"]
21 done_list=["normality","sampling_grids","lct","lct_cor"]
22 done = {}
23 alias_list = {
24  "avg": "avg",
25  "diag": "diag",
26  "dirac": "contour_centered",
27  "lct": "contour_positive",
28  "lct_cor": "lct_cor",
29  "local_diag_cor": "contour_positive",
30  "local_diag_loc": "contour_positive",
31  "normality": "normality",
32  "randomization": "randomization",
33  "sampling_grids": "sampling_grids",
34  "umf": "umf",
35  "var": "contour_positive"
36 }
37 for plot in plot_list:
38  done[plot] = False
39 
40 # BUMP tests
41 if args.test.find("bump_")==0:
42  # Make output directory
43  testfig = args.testdata + "/" + args.test + "/fig"
44  if not os.path.exists(testfig):
45  os.mkdir(testfig)
46 
47  # Create jpg figures
48  for f in sorted(os.listdir(os.path.join(args.testdata, args.test))):
49  if os.path.isfile(os.path.join(args.testdata, args.test, f)) and f.find("test_" + args.mpi + "-" + args.omp)==0:
50  suffix = f.split("test_" + args.mpi + "-" + args.omp + "_")[1][:-(len(f.rsplit(".")[-1])+1)]
51  for plot in plot_list:
52  if suffix.find(plot)==0 and not done[plot]:
53  print("Calling " + plot + " in " + args.test + " (" + args.mpi + "-" + args.omp + ")")
54  plot_alias = alias_list[plot]
55  module = __import__(plot_alias)
56  func = getattr(module, plot_alias)
57  if plot in done_list:
58  func(args.testdata, args.test, args.mpi, args.omp, plot, testfig)
59  done[plot] = True
60  else:
61  func(args.testdata, args.test, args.mpi, args.omp, suffix, testfig)
62 
63  if (os.path.isdir(os.path.join(args.testdata, args.test, "fig"))):
64  # Create HTML page
65  message = "<html><head></head><body><h1>" + args.test + "</h1><ul>"
66  for f in sorted(os.listdir(os.path.join(args.testdata, args.test, "fig"))):
67  if f.find("test_" + args.mpi + "-" + args.omp)==0:
68  short_name = f.replace("test_" + args.mpi + "-" + args.omp + "_", "").replace(".jpg", "")
69  message = message + "<li><a href=\"#" + short_name + "\">" + short_name + "</a></li>"
70  message = message + "</ul>"
71  for f in sorted(os.listdir(os.path.join(args.testdata, args.test, "fig"))):
72  if f.find("test_" + args.mpi + "-" + args.omp)==0:
73  short_name = f.replace("test_" + args.mpi + "-" + args.omp + "_", "").replace(".jpg", "")
74  cmd = "mogrify -trim " + os.path.join(args.testdata, args.test, "fig", f)
75  os.system(cmd)
76  message = message + "<h2 id=\"" + short_name + "\">" + short_name + "</h2><img src=\"" + f + "\" width=800px><br><a href=\"#top\">Back to top</a>"
77 
78  message = message + "</body></html>"
79  f = open(os.path.join(args.testdata, args.test, "fig", "index_" + args.mpi + "-" + args.omp + ".html"), "w")
80  f.write(message)
81  f.close()
saber_plot.func
func
Definition: saber_plot.py:56