Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsvu committed Jan 30, 2023
1 parent 8c51374 commit 6ad9ede
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Visualization/Python/PlotPowerMonitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ def plot_power_monitors(volfiles: Union[spectre_h5.H5Vol,
ax_colspan.set_xlabel("Mode number")


def parse_step(ctx, param, value):
if value is None:
return None
if value.lower() == "last":
return -1
return int(value)


@click.command()
@click.argument("h5_files",
nargs=-1,
Expand All @@ -144,9 +152,9 @@ def plot_power_monitors(volfiles: Union[spectre_h5.H5Vol,
"-d",
help=("Name of volume data subfile within the h5 files."))
@click.option("--step",
type=int,
help=("Observation step number. "
"Specify '-1' for the last step in the file. "
callback=parse_step,
help=("Observation step number. Specify '-1' or 'last' "
"for the last step in the file (default). "
"Mutually exclusive with '--time'."))
@click.option("--time",
type=float,
Expand All @@ -161,7 +169,8 @@ def plot_power_monitors(volfiles: Union[spectre_h5.H5Vol,
"-b",
"block_or_group_names",
multiple=True,
help=("Names of blocks or block groups to analyze."))
help=("Names of blocks or block groups to analyze. "
"Can be specified multiple times."))
@click.option("--list-vars",
"-l",
is_flag=True,
Expand Down Expand Up @@ -213,7 +222,9 @@ def plot_power_monitors_command(h5_files, subfile_name, step, time,
dim = volfiles[0].get_dimension()

# Select observation
if (step is None) == (time is None):
if step is None and time is None:
step = -1
elif step is not None and time is not None:
raise click.UsageError(
f"Specify either '--step' (in [0, {len(obs_ids) - 1}], or -1) or "
f"'--time' (in [{obs_values[0]:g}, {obs_values[-1]:g}]).")
Expand Down

0 comments on commit 6ad9ede

Please sign in to comment.