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