Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental dashboard to monitor simulations #6137

Merged
merged 8 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ preview = true
profile = "black"
line_length = 80
skip_gitignore = true
known_first_party = ["spectre"]
8 changes: 5 additions & 3 deletions src/Visualization/Python/Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

logger = logging.getLogger(__name__)

DEFAULT_MPL_STYLESHEET = os.path.join(
os.path.dirname(__file__), "plots.mplstyle"
)


def apply_stylesheet_command():
"""Add a CLI option to apply a stylesheet for plotting"""
Expand All @@ -35,9 +39,7 @@ def decorator(f):
@functools.wraps(f)
def command(stylesheet, **kwargs):
# Apply the default stylesheet and the user-provided one
stylesheets = [
os.path.join(os.path.dirname(__file__), "plots.mplstyle")
]
stylesheets = [DEFAULT_MPL_STYLESHEET]
if stylesheet is not None:
stylesheets.append(stylesheet)
plt.style.use(stylesheets)
Expand Down
191 changes: 99 additions & 92 deletions src/Visualization/Python/PlotCce.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,97 +34,18 @@ def _parse_modes(ctx, param, all_modes):
return result


@click.command(name="cce")
@click.argument(
"h5_filename",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
nargs=1,
)
@click.option(
"--modes",
"-m",
multiple=True,
callback=_parse_modes,
required=True,
help=(
"Which mode to plot. Specified as 'l,m' (e.g. '--modes 2,2'). Will plot"
" both real and imaginary components unless '--real' or '--imag' are"
" specified. Can be specified multiple times."
),
)
@click.option(
"--real",
is_flag=True,
default=False,
help="Plot only real modes. Mutually exclusive with '--imag'.",
)
@click.option(
"--imag",
is_flag=True,
default=False,
help="Plot only imaginary modes. Mutually exclusive with '--real'.",
)
@click.option(
"--extraction-radius",
"-r",
type=int,
help=(
"Extraction radius of data to plot as an int. If there is only one Cce"
" subfile, that one will be used and this option does not need to be"
" specified. The expected form of the Cce subfile is 'SpectreRXXXX.cce'"
" where XXXX is the zero-padded integer extraction radius. This option"
" is ignored if the backwards compatibility option '--cce-group'/'-d'"
" is specified."
),
)
@click.option(
"--list-extraction-radii",
"-l",
is_flag=True,
default=False,
help="List Cce subfiles in the 'h5_filename' and exit.",
)
@click.option(
"--cce-group",
"-d",
"backward_cce_group",
help=(
"Option for backwards compatibility with an old version of CCE data."
" This is the group name of the CCE data in the 'h5_filename'"
" (typically Cce). This option should only be used if your CCE data was"
" produced with a version of SpECTRE prior to this Pull Request:"
" https://github.com/sxs-collaboration/spectre/pull/5985."
),
)
# Plotting options
@click.option(
"--x-bounds",
type=float,
nargs=2,
help="The lower and upper bounds of the x-axis.",
)
@click.option(
"--x-label",
help="The label on the x-axis.",
)
@click.option(
"--title",
"-t",
help="Title of the graph.",
)
@apply_stylesheet_command()
@show_or_save_plot_command()
def plot_cce_command(
def plot_cce(
h5_filename: str,
modes: Sequence[str],
real: bool,
imag: bool,
extraction_radius: Optional[int],
list_extraction_radii: bool,
backward_cce_group: Optional[str],
x_bounds: Optional[Sequence[float]],
x_label: Optional[str],
title: Optional[str],
real: bool = False,
imag: bool = False,
extraction_radius: Optional[int] = None,
list_extraction_radii: bool = False,
backward_cce_group: Optional[str] = None,
x_bounds: Optional[Sequence[float]] = None,
x_label: Optional[str] = None,
title: Optional[str] = None,
fig: Optional[plt.Figure] = None,
):
"""
Plot the Strain, News, and Psi0-Psi4 from the output of a SpECTRE CCE run.
Expand Down Expand Up @@ -233,8 +154,9 @@ def plot_cce_command(
data = data[(data.index >= x_bounds[0]) & (data.index <= x_bounds[1])]

# Set up the plots
fig, axes = plt.subplots(len(plot_quantities), 1, sharex=True)
axes = list(axes)
if fig is None:
fig = plt.figure(figsize=(8, 2 * len(plot_quantities)))
axes = list(fig.subplots(len(plot_quantities), 1, sharex=True))
# Make the legend look a bit nicer
divisor = 1 if (real or imag) else 2
num_col = min(4, len(modes) / divisor)
Expand Down Expand Up @@ -276,9 +198,94 @@ def plot_cce_command(
axes[-1].set_xlabel(x_label)

# Plot needs to be fairly big
fig.set_size_inches(8, 2 * len(plot_quantities))
if title:
plt.suptitle(title)
return fig


@click.command(name="cce", help=plot_cce.__doc__)
@click.argument(
"h5_filename",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
nargs=1,
)
@click.option(
"--modes",
"-m",
multiple=True,
callback=_parse_modes,
required=True,
help=(
"Which mode to plot. Specified as 'l,m' (e.g. '--modes 2,2'). Will plot"
" both real and imaginary components unless '--real' or '--imag' are"
" specified. Can be specified multiple times."
),
)
@click.option(
"--real",
is_flag=True,
default=False,
help="Plot only real modes. Mutually exclusive with '--imag'.",
)
@click.option(
"--imag",
is_flag=True,
default=False,
help="Plot only imaginary modes. Mutually exclusive with '--real'.",
)
@click.option(
"--extraction-radius",
"-r",
type=int,
help=(
"Extraction radius of data to plot as an int. If there is only one Cce"
" subfile, that one will be used and this option does not need to be"
" specified. The expected form of the Cce subfile is 'SpectreRXXXX.cce'"
" where XXXX is the zero-padded integer extraction radius. This option"
" is ignored if the backwards compatibility option '--cce-group'/'-d'"
" is specified."
),
)
@click.option(
"--list-extraction-radii",
"-l",
is_flag=True,
default=False,
help="List Cce subfiles in the 'h5_filename' and exit.",
)
@click.option(
"--cce-group",
"-d",
"backward_cce_group",
help=(
"Option for backwards compatibility with an old version of CCE data."
" This is the group name of the CCE data in the 'h5_filename'"
" (typically Cce). This option should only be used if your CCE data was"
" produced with a version of SpECTRE prior to this Pull Request:"
" https://github.com/sxs-collaboration/spectre/pull/5985."
),
)
# Plotting options
@click.option(
"--x-bounds",
type=float,
nargs=2,
help="The lower and upper bounds of the x-axis.",
)
@click.option(
"--x-label",
help="The label on the x-axis.",
)
@click.option(
"--title",
"-t",
help="Title of the graph.",
)
@apply_stylesheet_command()
@show_or_save_plot_command()
def plot_cce_command(**kwargs):
_rich_traceback_guard = True # Hide traceback until here
plot_cce(**kwargs)


if __name__ == "__main__":
Expand Down
130 changes: 68 additions & 62 deletions src/Visualization/Python/PlotControlSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,14 @@
logger = logging.getLogger(__name__)


@click.command(name="control-system")
@click.argument(
"reduction_files",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
nargs=-1,
required=True,
)
@click.option(
"--with-shape/--without-shape",
default=True,
show_default=True,
help="Wether or not to plot shape control.",
)
@click.option(
"--shape-l_max",
"-l",
type=int,
default=2,
show_default=True,
help=(
"The max number of spherical harmonics to show on the plot. Since"
" higher ell can have a lot of components, it may be desirable to show"
" fewer components. Never plots l=0,1 since we don't control these"
" components. Only used if '--with-shape'."
),
)
@click.option(
"--show-all-m",
is_flag=True,
default=False,
show_default=True,
help=(
"When plotting shape control, for a given ell, plot all m components."
" Default is, for a given ell, to plot the L2 norm over all the m"
" components. Only used if '--with-shape'."
),
)
# Plotting options
@click.option(
"--x-bounds",
type=float,
nargs=2,
help="The lower and upper bounds of the x-axis.",
)
@click.option(
"--x-label",
help="The label on the x-axis.",
)
@click.option(
"--title",
"-t",
help="Title of the graph.",
)
@apply_stylesheet_command()
@show_or_save_plot_command()
def plot_control_system_command(
def plot_control_system(
reduction_files: Sequence[str],
with_shape: str,
show_all_m: bool,
shape_l_max: int,
x_bounds: Optional[Sequence[float]],
x_label: Optional[str],
title: Optional[str],
with_shape: bool = True,
show_all_m: bool = False,
shape_l_max: int = 2,
x_bounds: Optional[Sequence[float]] = None,
x_label: Optional[str] = None,
title: Optional[str] = None,
):
"""
Plot diagnostic information regarding all control systems except size
Expand Down Expand Up @@ -278,6 +223,67 @@ def extract_relevant_columns(
if title:
fig.suptitle(title)
axes[1].legend(loc="center left", bbox_to_anchor=(1.01, 1.1))
return fig


@click.command(name="control-system", help=plot_control_system.__doc__)
@click.argument(
"reduction_files",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True),
nargs=-1,
required=True,
)
@click.option(
"--with-shape/--without-shape",
default=True,
show_default=True,
help="Wether or not to plot shape control.",
)
@click.option(
"--shape-l_max",
"-l",
type=int,
default=2,
show_default=True,
help=(
"The max number of spherical harmonics to show on the plot. Since"
" higher ell can have a lot of components, it may be desirable to show"
" fewer components. Never plots l=0,1 since we don't control these"
" components. Only used if '--with-shape'."
),
)
@click.option(
"--show-all-m",
is_flag=True,
default=False,
show_default=True,
help=(
"When plotting shape control, for a given ell, plot all m components."
" Default is, for a given ell, to plot the L2 norm over all the m"
" components. Only used if '--with-shape'."
),
)
# Plotting options
@click.option(
"--x-bounds",
type=float,
nargs=2,
help="The lower and upper bounds of the x-axis.",
)
@click.option(
"--x-label",
help="The label on the x-axis.",
)
@click.option(
"--title",
"-t",
help="Title of the graph.",
)
@apply_stylesheet_command()
@show_or_save_plot_command()
def plot_control_system_command(**kwargs):
_rich_traceback_guard = True # Hide traceback until here
return plot_control_system(**kwargs)


if __name__ == "__main__":
Expand Down
Loading
Loading