Peano
Loading...
Searching...
No Matches
render.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import os
4import argparse
5
8
9if __name__ == "__main__":
10 parser = argparse.ArgumentParser(description="Peano 4 - Render Script")
11 parser.add_argument(
12 "--filter-fine-grid",
13 action="store_true",
14 default=False,
15 help="Display only fine grid",
16 )
17 parser.add_argument(
18 "--filter-average",
19 action="store_true",
20 default=False,
21 help="Average over cell data (reduces resolution/memory)",
22 )
23 parser.add_argument(
24 "--norm-calculator",
25 action="store_true",
26 default=False,
27 help="Compute norm over each point",
28 )
29 parser.add_argument(
30 "--shrink-cells",
31 type=float,
32 default=1.0,
33 help="Shrink or expand patches/cells. Off by default, i.e. set to 1.0",
34 )
35 parser.add_argument(
36 "--eliminate-relative-paths",
37 action="store_true",
38 default=False,
39 help="If you invoke the script on a different directory than your current working directory, ensure that all meta files written do not hold relative paths",
40 )
41 parser.add_argument(
42 "--split-unknowns",
43 action="store_true",
44 default=False,
45 help="If the patch file names its unknowns, write one additional array per variable (scalar or vector), so filters can address it by name",
46 )
47 parser.add_argument("--dir", default=".", help="Output directory")
48 parser.add_argument(
49 "-v",
50 "--verbose",
51 action="store_true",
52 default=False,
53 help="Run in a chatty mode",
54 )
55 parser.add_argument(
56 "-s",
57 "--single-file",
58 action="store_true",
59 default=False,
60 help="Input file is single snapshot (and not meta file)",
61 )
62 parser.add_argument(
63 "-j",
64 "--max-workers",
65 type=int,
66 nargs="?",
67 const=None,
68 default=1,
69 help="Number of workers processing the snapshots in parallel",
70 )
71 parser.add_argument(
72 "--type",
73 choices=["vtu-unstructured"],
74 default="vtu-unstructured",
75 help="Output format",
76 )
77 parser.add_argument(
78 "-start",
79 "--start-snapshot-index",
80 dest="start",
81 type=int,
82 help="Set the snapshot number where the merge starts (all snapshots before will be ignored), default is 0 (starts from beginning)",
83 default=0,
84 )
85 parser.add_argument(
86 "-end",
87 "--end-snapshot-index",
88 dest="end",
89 type=int,
90 help="Set the snapshot number where the merge ends (all snapshots after will be ignored), default is -1 (ends at the last)",
91 default=-1,
92 )
93 parser.add_argument(dest="filename", help="Input file name")
94 args = parser.parse_args()
95
96 # Start with some sanity checks
97 if not os.path.exists(args.filename):
98 raise Exception(
99 "Specified input file '{}' does not exist, exiting...".format(args.filename)
100 )
101
102 total_snapshot_number = 0
103 with open(args.filename, "r") as metafile:
104 for line in metafile.readlines():
105 if "timestamp" in line:
106 total_snapshot_number += 1
107
108 if (args.start > args.end and args.end != -1) or args.start < 0 or args.end < -1:
109 raise Exception("Specified snapshot index is wrong, please check.")
110 elif args.end == -1:
111 start_snapshot = args.start
112 end_snapshot = (
113 total_snapshot_number - 1
114 ) # Processing all snapshots if no end snapshot is specified.
115 elif args.end > (total_snapshot_number - 1):
116 start_snapshot = args.start
117 end_snapshot = total_snapshot_number - 1
118 print(
119 "Warning: specified end snapshot index exceeds the total number, reset to the last snapshot."
120 )
121 else:
122 start_snapshot = args.start
123 end_snapshot = args.end
124
125 print(
126 "The meta file includes",
127 total_snapshot_number,
128 "snapshots, processing snapshot",
129 start_snapshot,
130 "to",
131 end_snapshot,
132 )
133
134 visualiser = None
135 if args.type == "vtu-unstructured":
137 file_name=args.filename,
138 output_directory=args.dir,
139 verbose=args.verbose,
140 start=start_snapshot,
141 end=end_snapshot,
142 split_unknowns=args.split_unknowns,
143 )
144
145 #
146 # Ensure the filter order is cheap-to-expensive
147 #
148 if args.filter_average:
149 visualiser.append_filter(
151 )
152 if args.filter_fine_grid:
153 visualiser.append_filter(
155 )
156 if args.norm_calculator:
157 visualiser.append_filter(
158 tarch.plotter.api.filters.Calculator(verbose=args.verbose)
159 )
160 if args.shrink_cells != 1.0:
161 visualiser.append_filter(
163 args.shrink_cells, verbose=args.verbose
164 )
165 )
166
167 if args.single_file:
168 visualiser.display_single_file()
169 else:
170 visualiser.display(args.max_workers)
Calculate some value per voxel/sample point.
Definition Calculator.py:12
The visualiser is first and foremost a persistency layer around datasets.