3 A simple Python script to postprocess, inspect and convert the csv
4 files dumped by the particle database.
13import matplotlib.pyplot
as plt
16parser = argparse.ArgumentParser(
17 description=
"ExaHyPE 2 - Particle toolbox postprocessing"
23 help=
"Input files. If the filename does not contain the postfix .csv, the script will load all files fitting filename*.csv.",
31 help=
"Dimensions of underlying simulation, i.e. 2 or 3",
37 help=
"Output name. An appropritae filename extension is added automatically depending on the output format",
43 choices=[
"seismogram",
"initial-tracer-location"],
44 help=
"Pick output type",
51 help=
"Pick value to go with target (quantity of interest of Q data projected onto tracer)",
58 help=
"Pick particles. Empty means all particles, otherwise you specify the particles through '(1,4)(7,8)'",
61 "-l",
"--legend", dest=
"legend", default=
None, help=
"Legend (comma-separated)"
63args = parser.parse_args()
69ExaHyPE 2 - Particle toolbox postprocessing
70===========================================
71(C) Mladen Ivkovic, Tobias Weinzierl, Han Zhang
73Type in --help to find out about the arguments.
79for file
in args.files:
80 if not ".csv" in file:
82 "filename " + file +
" is not complete. Search for files " + file +
"*.csv"
84 new_dataset = peano4.api.toolbox.particles.postprocessing.load_file_sequence(
89 new_dataset.parse(file, args.dimensions)
91 datasets.append(new_dataset)
96 +
" was not a valid Peano 4 particle database file"
99print(
"merge {} datasets".format(len(datasets)))
100flattened_dataset = datasets[0]
101for i
in datasets[1:-1]:
102 flattened_dataset.append(i)
106 for pick
in args.pick.split(
"(")[1:]:
107 filter = (int(pick.split(
",")[0]), int(pick.split(
",")[1].split(
")")[0]))
108 flattened_dataset.add_filter(filter)
111if args.target ==
"seismogram":
112 column = int(args.value)
115 if args.legend !=
None:
116 labels = args.legend.split(
",")
117 peano4.api.toolbox.particles.postprocessing.seismogram(
118 flattened_dataset, column, labels
123 output = args.files[0]
125 plt.xlabel(
"Simulation time $t$")
126 plt.ylabel(
"$Q_{" + str(column) +
"}(t)$")
127 plt.savefig(output +
".pdf")
128 plt.savefig(output +
".png")
129elif args.target ==
"initial-tracer-location" and args.dimensions == 2:
130 keys = flattened_dataset.extract_particle_keys()
131 for particle
in keys:
132 time, pos_x, pos_y = flattened_dataset.get_position(particle)
134 "Particle {},{}: {}, {}".format(
135 particle[0], particle[1], pos_x[0], pos_y[0]
138elif args.target ==
"initial-tracer-location" and args.dimensions == 3:
139 keys = flattened_dataset.extract_particle_keys()
140 for particle
in keys:
141 time, pos_x, pos_y, pos_z = flattened_dataset.get_position(particle)
143 "Particle {},{}: {}, {}, {}".format(
144 particle[0], particle[1], pos_x[0], pos_y[0], pos_z[0]
148 print(
"Unknown target")
Dataset object corresponding to one VTU snapshot.