Skip to content
38 changes: 36 additions & 2 deletions examples/LinearMHD/itpa_tae_benchmark/pproc_TAE_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
10% fails with an ``AssertionError`` after the figures are saved (not with
``--test-run``). Figures are written into ``<path_out>/results``. The energy and harmonics plots use plasma-plots
(``pip install "struphy[pproc]"``).

Unless ``--no-frames``, the frames of three videos of the radial velocity u_r over the run (at most ``--max-frames``
saved time steps) are written into ``<path_out>/results/frames/``: ``u_r_rz`` (the poloidal plane), ``u_r_3d_cut``
(3D, the camera on the poloidal cross-section of the cutaway) and ``u_r_3d`` (3D, the whole torus with the
cutaway), see ``struphy.post_processing.frames``. Make a video e.g. with
``ffmpeg -framerate 25 -i frame_%04d.png -pix_fmt yuv420p u_r_rz.mp4`` in a frames folder.
"""

import argparse
Expand All @@ -21,6 +27,7 @@
from matplotlib import pyplot as plt

from struphy import Output
from struphy.post_processing.frames import write_videos
from struphy.post_processing.plot_3d import plot_field_3d
from struphy.post_processing.slices import plot_physical_slices

Expand Down Expand Up @@ -109,7 +116,7 @@ def finish(figs, results_dir, save_figs):
plt.close(fig)


def main(path_out=DEFAULT_OUTPUT, save_figs=True):
def main(path_out=DEFAULT_OUTPUT, save_figs=True, frames=True, max_frames=500):
run = Output(path_out)
snapshots = run.standard_snapshots()
# VTK files (for the 3D views) of the standard snapshots only
Expand Down Expand Up @@ -179,6 +186,24 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
else:
print(f"No 3D view of {species}/{variable}: its basis {basis!r} is not in the VTK files.")

if frames:
# frames of videos of the radial velocity u_r (the first component in the normalized basis, radial for the
# circular flux surfaces of the HollowTorus): the poloidal plane and two 3D views, at most max_frames saved
# time steps, in <path_out>/results/frames/u_r_rz, u_r_3d_cut and u_r_3d (frame_*.png)
videos = write_videos(
run,
"mhd/velocity",
os.path.join(results_dir, "frames"),
component=0,
basis="norm",
prefix="u_r",
label="radial velocity u_r",
max_frames=max_frames,
)
for video, files in videos.items():
if files: # (empty on the ranks other than 0)
print(f"{len(files)} frames of {video} in {os.path.join(results_dir, 'frames', video)}")

if not save_figs:
plt.show()

Expand All @@ -204,5 +229,14 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
help="Simulation output folder (default: the output folder of the run flags, sim_data beside this script)",
)
pproc_parser.add_argument("--show", action="store_true", help="Show the figures instead of saving them.")
pproc_parser.add_argument("--no-frames", action="store_true", help="Do not write the frames of the videos.")
pproc_parser.add_argument(
"--max-frames", type=int, default=500, help="Largest number of frames per video (default: 500)."
)
pproc_args = pproc_parser.parse_args(other_flags)
main(pproc_args.path_out, save_figs=not pproc_args.show)
main(
pproc_args.path_out,
save_figs=not pproc_args.show,
frames=not pproc_args.no_frames,
max_frames=pproc_args.max_frames,
)
38 changes: 36 additions & 2 deletions examples/LinearMHD/lowmode_tae/pproc_lowmode_tae.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
and saved; a deviation of more than 10% fails with an ``AssertionError`` after the figures are saved (not with
``--test-run``). Figures are written into ``<path_out>/results``. The energy and harmonics plots use plasma-plots
(``pip install "struphy[pproc]"``).

Unless ``--no-frames``, the frames of three videos of the radial velocity u_r over the run (at most ``--max-frames``
saved time steps) are written into ``<path_out>/results/frames/``: ``u_r_rz`` (the poloidal plane), ``u_r_3d_cut``
(3D, the camera on the poloidal cross-section of the cutaway) and ``u_r_3d`` (3D, the whole torus with the
cutaway), see ``struphy.post_processing.frames``. Make a video e.g. with
``ffmpeg -framerate 25 -i frame_%04d.png -pix_fmt yuv420p u_r_rz.mp4`` in a frames folder.
"""

import argparse
Expand All @@ -20,6 +26,7 @@
from matplotlib import pyplot as plt

from struphy import Output
from struphy.post_processing.frames import write_videos
from struphy.post_processing.plot_3d import plot_field_3d
from struphy.post_processing.slices import plot_physical_slices

Expand Down Expand Up @@ -105,7 +112,7 @@ def finish(figs, results_dir, save_figs):
plt.close(fig)


def main(path_out=DEFAULT_OUTPUT, save_figs=True):
def main(path_out=DEFAULT_OUTPUT, save_figs=True, frames=True, max_frames=500):
run = Output(path_out)
snapshots = run.standard_snapshots()
# VTK files (for the 3D views) of the standard snapshots only
Expand Down Expand Up @@ -171,6 +178,24 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
else:
print(f"No 3D view of {species}/{variable}: its basis {basis!r} is not in the VTK files.")

if frames:
# frames of videos of the radial velocity u_r (the first component in the normalized basis, radial for the
# circular flux surfaces of the HollowTorus): the poloidal plane and two 3D views, at most max_frames saved
# time steps, in <path_out>/results/frames/u_r_rz, u_r_3d_cut and u_r_3d (frame_*.png)
videos = write_videos(
run,
"mhd/velocity",
os.path.join(results_dir, "frames"),
component=0,
basis="norm",
prefix="u_r",
label="radial velocity u_r",
max_frames=max_frames,
)
for video, files in videos.items():
if files: # (empty on the ranks other than 0)
print(f"{len(files)} frames of {video} in {os.path.join(results_dir, 'frames', video)}")

if not save_figs:
plt.show()

Expand All @@ -192,5 +217,14 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
help="Simulation output folder (default: the output folder of the run flags, sim_data beside this script)",
)
pproc_parser.add_argument("--show", action="store_true", help="Show the figures instead of saving them.")
pproc_parser.add_argument("--no-frames", action="store_true", help="Do not write the frames of the videos.")
pproc_parser.add_argument(
"--max-frames", type=int, default=500, help="Largest number of frames per video (default: 500)."
)
pproc_args = pproc_parser.parse_args(other_flags)
main(pproc_args.path_out, save_figs=not pproc_args.show)
main(
pproc_args.path_out,
save_figs=not pproc_args.show,
frames=not pproc_args.no_frames,
max_frames=pproc_args.max_frames,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
folder of the run with ``--filter none``), the MHD kinetic energy and its part outside the toroidal harmonic n = 6 of
both runs are overlaid in ``filter_comparison.png``. Figures are written into ``<path_out>/results``. The energy and
harmonics plots use plasma-plots (``pip install "struphy[pproc]"``).

Unless ``--no-frames``, the frames of three videos of the radial velocity u_r over the run (at most ``--max-frames``
saved time steps) are written into ``<path_out>/results/frames/``: ``u_r_rz`` (the poloidal plane), ``u_r_3d_cut``
(3D, the camera on the poloidal cross-section of the cutaway) and ``u_r_3d`` (3D, the whole torus with the
cutaway), see ``struphy.post_processing.frames``. Make a video e.g. with
``ffmpeg -framerate 25 -i frame_%04d.png -pix_fmt yuv420p u_r_rz.mp4`` in a frames folder.
"""

import argparse
Expand All @@ -22,6 +28,7 @@
from matplotlib import pyplot as plt

from struphy import Output
from struphy.post_processing.frames import write_videos
from struphy.post_processing.plot_3d import plot_field_3d
from struphy.post_processing.slices import plot_physical_slices

Expand Down Expand Up @@ -270,7 +277,7 @@ def finish(figs, results_dir, save_figs):
plt.close(fig)


def main(path_out=None, save_figs=True, compare=None, fit_window=FIT_WINDOW):
def main(path_out=None, save_figs=True, compare=None, fit_window=FIT_WINDOW, frames=True, max_frames=500):
path_out = DEFAULT_OUTPUT if path_out is None else path_out
run = Output(path_out)
snapshots = run.standard_snapshots()
Expand Down Expand Up @@ -361,6 +368,24 @@ def main(path_out=None, save_figs=True, compare=None, fit_window=FIT_WINDOW):
else:
print(f"No 3D view of {species}/{variable}: its basis {basis!r} is not in the VTK files.")

if frames:
# frames of videos of the radial velocity u_r (the first component in the normalized basis, radial for the
# circular flux surfaces of the HollowTorus): the poloidal plane and two 3D views, at most max_frames saved
# time steps, in <path_out>/results/frames/u_r_rz, u_r_3d_cut and u_r_3d (frame_*.png)
videos = write_videos(
run,
"mhd/velocity",
os.path.join(results_dir, "frames"),
component=0,
basis="norm",
prefix="u_r",
label="radial velocity u_r",
max_frames=max_frames,
)
for video, files in videos.items():
if files: # (empty on the ranks other than 0)
print(f"{len(files)} frames of {video} in {os.path.join(results_dir, 'frames', video)}")

if not save_figs:
plt.show()

Expand Down Expand Up @@ -403,10 +428,16 @@ def cli():
help="Time window of the frequency and growth rate fits (default: %(default)s).",
)
pproc_parser.add_argument("--show", action="store_true", help="Show the figures instead of saving them.")
pproc_parser.add_argument("--no-frames", action="store_true", help="Do not write the frames of the videos.")
pproc_parser.add_argument(
"--max-frames", type=int, default=500, help="Largest number of frames per video (default: 500)."
)
pproc_args = pproc_parser.parse_args(other_flags)
main(
pproc_args.path_out,
save_figs=not pproc_args.show,
compare=pproc_args.compare,
fit_window=tuple(pproc_args.fit_window),
frames=not pproc_args.no_frames,
max_frames=pproc_args.max_frames,
)
38 changes: 36 additions & 2 deletions examples/LinearMHDDriftkineticCC/lowmode_tae/pproc_lowmode_tae.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
With ``--save-results`` (passed by ``submit_lowmode_tae_cpu_vs_gpu.py`` after each profiling run, ``--setup profiling``)
the scope-profiler HTML report and a summary of the cost per step are written into ``<path_out>/results`` instead; the
profiling packaging uploads them with the run.

Unless ``--no-frames``, the frames of three videos of the radial velocity u_r over the run (at most ``--max-frames``
saved time steps) are written into ``<path_out>/results/frames/``: ``u_r_rz`` (the poloidal plane), ``u_r_3d_cut``
(3D, the camera on the poloidal cross-section of the cutaway) and ``u_r_3d`` (3D, the whole torus with the
cutaway), see ``struphy.post_processing.frames``. Make a video e.g. with
``ffmpeg -framerate 25 -i frame_%04d.png -pix_fmt yuv420p u_r_rz.mp4`` in a frames folder.
"""

import argparse
Expand All @@ -23,6 +29,7 @@
from matplotlib import pyplot as plt

from struphy import Output
from struphy.post_processing.frames import write_videos
from struphy.post_processing.plot_3d import plot_field_3d
from struphy.post_processing.slices import plot_physical_slices

Expand Down Expand Up @@ -192,7 +199,7 @@ def save_profiling_results(path_out):
results.print_summary(include=["^prop: ", "^kernel: "], sort="total", title="propagators and kernels")


def main(path_out=DEFAULT_OUTPUT, save_figs=True):
def main(path_out=DEFAULT_OUTPUT, save_figs=True, frames=True, max_frames=500):
run = Output(path_out)
snapshots = run.standard_snapshots()
# VTK files (for the 3D views) of the standard snapshots only
Expand Down Expand Up @@ -266,6 +273,24 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
else:
print(f"No 3D view of {species}/{variable}: its basis {basis!r} is not in the VTK files.")

if frames:
# frames of videos of the radial velocity u_r (the first component in the normalized basis, radial for the
# circular flux surfaces of the HollowTorus): the poloidal plane and two 3D views, at most max_frames saved
# time steps, in <path_out>/results/frames/u_r_rz, u_r_3d_cut and u_r_3d (frame_*.png)
videos = write_videos(
run,
"mhd/velocity",
os.path.join(results_dir, "frames"),
component=0,
basis="norm",
prefix="u_r",
label="radial velocity u_r",
max_frames=max_frames,
)
for video, files in videos.items():
if files: # (empty on the ranks other than 0)
print(f"{len(files)} frames of {video} in {os.path.join(results_dir, 'frames', video)}")

if not save_figs:
plt.show()

Expand All @@ -288,6 +313,10 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
help="Simulation output folder (default: the output folder of the run flags, sim_data beside this script)",
)
pproc_parser.add_argument("--show", action="store_true", help="Show the figures instead of saving them.")
pproc_parser.add_argument("--no-frames", action="store_true", help="Do not write the frames of the videos.")
pproc_parser.add_argument(
"--max-frames", type=int, default=500, help="Largest number of frames per video (default: 500)."
)
pproc_parser.add_argument(
"--save-results",
action="store_true",
Expand All @@ -299,4 +328,9 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
if pproc_args.save_results:
save_profiling_results(pproc_args.path_out)
else:
main(pproc_args.path_out, save_figs=not pproc_args.show)
main(
pproc_args.path_out,
save_figs=not pproc_args.show,
frames=not pproc_args.no_frames,
max_frames=pproc_args.max_frames,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
With ``--save-results`` (after a profiling run, ``--setup profiling``, as in the example of LinearMHDDriftkineticCC)
the scope-profiler HTML report and a summary of the cost per step are written into ``<path_out>/results`` instead; the
profiling packaging uploads them with the run.

Unless ``--no-frames``, the frames of three videos of the radial velocity u_r over the run (at most ``--max-frames``
saved time steps) are written into ``<path_out>/results/frames/``: ``u_r_rz`` (the poloidal plane), ``u_r_3d_cut``
(3D, the camera on the poloidal cross-section of the cutaway) and ``u_r_3d`` (3D, the whole torus with the
cutaway), see ``struphy.post_processing.frames``. Make a video e.g. with
``ffmpeg -framerate 25 -i frame_%04d.png -pix_fmt yuv420p u_r_rz.mp4`` in a frames folder.
"""

import argparse
Expand All @@ -23,6 +29,7 @@
from matplotlib import pyplot as plt

from struphy import Output
from struphy.post_processing.frames import write_videos
from struphy.post_processing.plot_3d import plot_field_3d
from struphy.post_processing.slices import plot_physical_slices

Expand Down Expand Up @@ -190,7 +197,7 @@ def save_profiling_results(path_out):
results.print_summary(include=["^prop: ", "^kernel: "], sort="total", title="propagators and kernels")


def main(path_out=DEFAULT_OUTPUT, save_figs=True):
def main(path_out=DEFAULT_OUTPUT, save_figs=True, frames=True, max_frames=500):
run = Output(path_out)
snapshots = run.standard_snapshots()
# VTK files (for the 3D views) of the standard snapshots only
Expand Down Expand Up @@ -264,6 +271,24 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
else:
print(f"No 3D view of {species}/{variable}: its basis {basis!r} is not in the VTK files.")

if frames:
# frames of videos of the radial velocity u_r (the first component in the normalized basis, radial for the
# circular flux surfaces of the HollowTorus): the poloidal plane and two 3D views, at most max_frames saved
# time steps, in <path_out>/results/frames/u_r_rz, u_r_3d_cut and u_r_3d (frame_*.png)
videos = write_videos(
run,
"mhd/velocity",
os.path.join(results_dir, "frames"),
component=0,
basis="norm",
prefix="u_r",
label="radial velocity u_r",
max_frames=max_frames,
)
for video, files in videos.items():
if files: # (empty on the ranks other than 0)
print(f"{len(files)} frames of {video} in {os.path.join(results_dir, 'frames', video)}")

if not save_figs:
plt.show()

Expand All @@ -286,6 +311,10 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
help="Simulation output folder (default: the output folder of the run flags, sim_data beside this script)",
)
pproc_parser.add_argument("--show", action="store_true", help="Show the figures instead of saving them.")
pproc_parser.add_argument("--no-frames", action="store_true", help="Do not write the frames of the videos.")
pproc_parser.add_argument(
"--max-frames", type=int, default=500, help="Largest number of frames per video (default: 500)."
)
pproc_parser.add_argument(
"--save-results",
action="store_true",
Expand All @@ -297,4 +326,9 @@ def main(path_out=DEFAULT_OUTPUT, save_figs=True):
if pproc_args.save_results:
save_profiling_results(pproc_args.path_out)
else:
main(pproc_args.path_out, save_figs=not pproc_args.show)
main(
pproc_args.path_out,
save_figs=not pproc_args.show,
frames=not pproc_args.no_frames,
max_frames=pproc_args.max_frames,
)
Loading
Loading