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(
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",
61args = parser.parse_args()
64Extract some metadata about the positions of the various information in the csv file.
65These should always be the same but it's safer to check.
68 csvData = list(csv.reader(open(args.file_name,
"r"), delimiter=
","))
69except 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"
79timeIndex = csvData[0].index(
" t")
80vxIndex = csvData[0].index(
" data ") + args.v
81vyIndex = csvData[0].index(
" data ") + args.v + 1
82vzIndex = csvData[0].index(
" data ") + args.v + 2
83firstNumberIndex = csvData[0].index(
"number(0)")
84secondNumberIndex = csvData[0].index(
" number(1)")
86if " 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)")]
97remove first row which should only contain metadata
99csvData = csvData[1:-1]
103Filter 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
126Check how many tracers fit the filter by extracting the total numbers of number(0) and
127number(1) tuples that exist with the filter.
128The {number(0), number(1)} tuples should be unique for each tracer, therefore if there
129exists more than one value for either of these after filtering, there are multiple
130tracers that correspond to the filter.
131In the same way if there are none, none of the tracers correspond to the filter.
133checkFirstIndexLength = set([data[firstNumberIndex]
for data
in csvData])
134checksecondIndexLength = set([data[secondNumberIndex]
for data
in csvData])
136if len(checkFirstIndexLength) == 0:
138 "Specification was valid for none of the tracers, please check that a tracer exists at the specified position"
140elif 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"
147Extract 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]))
162Sort this data in the direction of increasing time
165dt, vx, vy, vz = zip(*sorted(zip(dt, vx, vy, vz)))
171fig, axs = plt.subplots(3)
176axs[0].set(xlabel=
"t", ylabel=
"vx")
182axs[1].set(xlabel=
"t", ylabel=
"vy")
189 axs[2].set(xlabel=
"t", ylabel=
"vz")
192fig.suptitle(
"velocities as a function of time", fontsize=20)