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(
13 description=
"Script to convert CSV generated by ExaHyPE2 executions into plots"
20 help=
"Name of the file to be checked, does not need to contain '.csv'",
23 "--v", dest=
"v", type=int, default=0, help=
"Index of the variable to be plotted"
30 help=
"Minimal time for which data should be plotted",
37 help=
"Maximal time for which data should be plotted",
44 help=
"x position of tracer which should be considered",
51 help=
"y position of tracer which should be considered",
58 help=
"z position of tracer which should be considered",
61 args = parser.parse_args()
64 Extract some metadata about the positions of the various information in the csv file.
65 These should always be the same but it's safer to check.
68 csvData = list(csv.reader(open(args.file_name,
"r"), delimiter=
","))
69 except FileNotFoundError:
71 csvData = list(csv.reader(open(args.file_name +
".csv",
"r"), delimiter=
","))
74 "the file you have specified does not exist, please make sure that it does in the specified location"
79 timeIndex = csvData[0].index(
" t")
80 vxIndex = csvData[0].index(
" data ") + args.v
81 vyIndex = csvData[0].index(
" data ") + args.v + 1
82 vzIndex = csvData[0].index(
" data ") + args.v + 2
83 firstNumberIndex = csvData[0].index(
"number(0)")
84 secondNumberIndex = csvData[0].index(
" number(1)")
86 if " x(2)" in csvData[0]:
89 csvData[0].index(
" x(0)"),
90 csvData[0].index(
" x(1)"),
91 csvData[0].index(
" x(2)"),
94 positionIndexes = [csvData[0].index(
" x(0)"), csvData[0].index(
" x(1)")]
97 remove first row which should only contain metadata
99 csvData = csvData[1:-1]
103 Filter out only the data from tracers at the specified positions
109 if args.t_min !=
None:
110 value = value
and float(a[timeIndex]) >= args.t_min
111 if args.t_max !=
None:
112 value = value
and float(a[timeIndex]) <= args.t_max
114 value = value
and float(a[positionIndexes[0]]) == args.x
116 value = value
and float(a[positionIndexes[1]]) == args.y
117 if dim==3
and args.z !=
None:
118 value = value
and float(a[positionIndexes[2]]) == args.z
126 Check how many tracers fit the filter by extracting the total numbers of number(0) and
127 number(1) tuples that exist with the filter.
128 The {number(0), number(1)} tuples should be unique for each tracer, therefore if there
129 exists more than one value for either of these after filtering, there are multiple
130 tracers that correspond to the filter.
131 In the same way if there are none, none of the tracers correspond to the filter.
133 checkFirstIndexLength = set([data[firstNumberIndex]
for data
in csvData])
134 checksecondIndexLength = set([data[secondNumberIndex]
for data
in csvData])
136 if len(checkFirstIndexLength) == 0:
138 "Specification was valid for none of the tracers, please check that a tracer exists at the specified position"
140 elif len(checkFirstIndexLength) > 1
or len(checksecondIndexLength) > 1:
142 "Specification was valid for more than one tracer, please clarify which you want through use of positions x, y and z"
147 Extract only the data from time and from the required value
156 dt.append(
float(row[timeIndex]))
157 vx.append(
float(row[vxIndex]))
158 vy.append(
float(row[vyIndex]))
159 vz.append(
float(row[vzIndex]))
162 Sort this data in the direction of increasing time
165 dt, vx, vy, vz = zip(*sorted(zip(dt, vx, vy, vz)))
171 fig, axs = plt.subplots(3)
176 axs[0].set(xlabel=
"t", ylabel=
"vx")
182 axs[1].set(xlabel=
"t", ylabel=
"vy")
189 axs[2].set(xlabel=
"t", ylabel=
"vz")
192 fig.suptitle(
"velocities as a function of time", fontsize=20)