1 import matplotlib.pyplot
as plt
5 "Written by Marc Marot-Lassauzaie, I use this file to convert data from the .csv files generated by the parsers to somewhat legible plots"
9 parse arguments to get details about which data should be extracted
12 parser = argparse.ArgumentParser(description=
'Script to convert CSV generated by ExaHyPE2 executions into plots')
13 parser.add_argument(
"--f", dest=
"file_name", type=str, required=
True, help=
"Name of the file to be checked, does not need to contain '.csv'" )
14 parser.add_argument(
"--v", dest=
"v", type=int, required=
True, help=
"Index of the variable to be plotted" )
15 parser.add_argument(
"--name", dest=
"variable_name", type=str, default=
None, help=
"Name of the variable to be plotted" )
16 parser.add_argument(
"--tmax", dest=
"t_max", type=float, default=
None, help=
"Minimal time for which data should be plotted" )
17 parser.add_argument(
"--tmin", dest=
"t_min", type=float, default=
None, help=
"Maximal time for which data should be plotted" )
18 parser.add_argument(
"--x", dest=
"x", type=float, default=
None, help=
"x position of tracer which should be considered" )
19 parser.add_argument(
"--y", dest=
"y", type=float, default=
None, help=
"y position of tracer which should be considered" )
20 parser.add_argument(
"--z", dest=
"z", type=float, default=
None, help=
"z position of tracer which should be considered" )
21 args = parser.parse_args()
23 var_name =
"Value" if args.variable_name==
None else args.variable_name
27 Extract some metadata about the positions of the various information in the csv file.
28 These should always be the same but it's safer to check.
31 csvData = list(csv.reader(open(args.file_name,
'r'), delimiter=
','))
32 except FileNotFoundError:
34 csvData = list(csv.reader(open(args.file_name +
'.csv',
'r'), delimiter=
','))
36 print(
"the file you have specified does not exist, please make sure that it does in the specified location")
40 timeIndex = csvData[0].index(
' t')
41 dataIndex = csvData[0].index(
" data ") + args.v
42 firstNumberIndex = csvData[0].index(
'number(0)')
43 secondNumberIndex = csvData[0].index(
' number(1)')
44 if ' x(2)' in csvData[0]:
45 positionIndexes = [csvData[0].index(
' x(0)'), csvData[0].index(
' x(1)'), csvData[0].index(
' x(2)')]
47 positionIndexes = [csvData[0].index(
' x(0)'), csvData[0].index(
' x(1)')]
50 remove first row which should only contain metadata
52 csvData = csvData[1:-1]
56 Filter out only the data from tracers at the specified positions
62 value = value
and float(a[timeIndex])>=args.t_min
64 value = value
and float(a[timeIndex])<=args.t_max
66 value = value
and float(a[positionIndexes[0]])==args.x
68 value = value
and float(a[positionIndexes[1]])==args.y
70 value = value
and float(a[positionIndexes[2]])==args.z
77 Check how many tracers fit the filter by extracting the total numbers of number(0) and
78 number(1) tuples that exist with the filter.
79 The {number(0), number(1)} tuples should be unique for each tracer, therefore if there
80 exists more than one value for either of these after filtering, there are multiple
81 tracers that correspond to the filter.
82 In the same way if there are none, none of the tracers correspond to the filter.
84 checkFirstIndexLength = set([data[firstNumberIndex]
for data
in csvData])
85 checksecondIndexLength = set([data[secondNumberIndex]
for data
in csvData])
87 if len(checkFirstIndexLength)==0:
88 raise Exception(
"Specification was valid for none of the tracers, please check that a tracer exists at the specified position")
89 elif len(checkFirstIndexLength)>1
or len(checksecondIndexLength) >1:
90 raise Exception(
"Specification was valid for more than one tracer, please clarify which you want through use of positions x, y and z")
94 Extract only the data from time and from the required value
101 dt.append(
float(row[timeIndex]))
102 y.append(
float(row[dataIndex]))
105 Sort this data in the direction of increasing time
108 dt, y = zip(*sorted(zip(dt,y)))
115 plt.plot(dt, y, color =
'b', linestyle =
'dashed',
116 marker =
'o',label = var_name +
" as a function of time")
118 plt.xticks(rotation = 25)
121 plt.title(var_name +
' as a function of time', fontsize = 20)