Skip to content

Commit 42d0923

Browse files
sbryngelsonclaude
andcommitted
Add sensible defaults to ./mfc.sh viz flags
- --step defaults to 'last' (most recent timestep); interactive/TUI still override to 'all' internally - --var auto-selects first available variable for 2D/3D static rendering instead of erroring; prints which variable was chosen - --cmap defaults to 'viridis', --dpi to 150, --fps to 10, --slice-axis to 'z' (moving implicit renderer defaults into the CLI so they appear in --help) - Remove no-action quick-start guide (defaults now do something useful) - Remove berlin/managua/vanimo from --cmap completion list - Clean up or-fallbacks and guard conditions made redundant by defaults Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2498a0f commit 42d0923

2 files changed

Lines changed: 32 additions & 63 deletions

File tree

toolchain/mfc/cli/commands.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,9 @@
882882
),
883883
Argument(
884884
name="step",
885-
help="Timestep(s): single int, start:end:stride, or 'all'.",
885+
help="Timestep(s): single int, start:end:stride, 'last', or 'all' (default: last).",
886886
type=str,
887-
default=None,
887+
default='last',
888888
metavar="STEP",
889889
),
890890
Argument(
@@ -909,7 +909,7 @@
909909
name="cmap",
910910
help="Matplotlib colormap name (default: viridis).",
911911
type=str,
912-
default=None,
912+
default='viridis',
913913
metavar="CMAP",
914914
completion=Completion(type=CompletionType.CHOICES, choices=[
915915
# Perceptually uniform sequential
@@ -934,7 +934,7 @@
934934
"turbo", "jet", "rainbow", "nipy_spectral", "gist_ncar",
935935
"gist_rainbow", "gist_stern", "gist_earth", "ocean", "terrain",
936936
"gnuplot", "gnuplot2", "CMRmap", "cubehelix", "brg", "flag", "prism",
937-
"berlin", "managua", "vanimo", "Wistia",
937+
"Wistia",
938938
]),
939939
),
940940
Argument(
@@ -955,14 +955,14 @@
955955
name="dpi",
956956
help="Image resolution in DPI (default: 150).",
957957
type=int,
958-
default=None,
958+
default=150,
959959
metavar="DPI",
960960
),
961961
Argument(
962962
name="slice-axis",
963963
help="Axis for 3D slice: x, y, or z (default: z).",
964964
type=str,
965-
default=None,
965+
default='z',
966966
choices=["x", "y", "z"],
967967
dest="slice_axis",
968968
completion=Completion(type=CompletionType.CHOICES, choices=["x", "y", "z"]),
@@ -993,7 +993,7 @@
993993
name="fps",
994994
help="Frames per second for MP4 output (default: 10).",
995995
type=int,
996-
default=None,
996+
default=10,
997997
metavar="FPS",
998998
),
999999
Argument(

toolchain/mfc/viz/viz.py

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,6 @@ def viz(): # pylint: disable=too-many-locals,too-many-statements,too-many-branc
7373

7474
cons.print(f"[bold]Format:[/bold] {fmt}")
7575

76-
# Quick guide when no action is specified
77-
no_action = (not ARG('list_steps') and not ARG('list_vars')
78-
and ARG('var') is None and ARG('step') is None
79-
and not ARG('interactive') and not ARG('tui'))
80-
if no_action:
81-
cons.print()
82-
d = case_dir
83-
cons.print("[bold]Quick start:[/bold]")
84-
cons.print(f" [green]./mfc.sh viz {d} --list-steps[/green]"
85-
" [dim]see available timesteps[/dim]")
86-
cons.print(f" [green]./mfc.sh viz {d} --list-vars --step 0[/green]"
87-
" [dim]see available variables[/dim]")
88-
cons.print(f" [green]./mfc.sh viz {d} --var pres --step last[/green]"
89-
" [dim]render a PNG[/dim]")
90-
cons.print(f" [green]./mfc.sh viz {d} --var pres --step all --mp4[/green]"
91-
" [dim]render an MP4[/dim]")
92-
cons.print(f" [green]./mfc.sh viz {d} --var pres --step 0 --slice-axis z[/green]"
93-
" [dim]3D midplane slice[/dim]")
94-
cons.print()
95-
cons.print("[dim]Run [bold]./mfc.sh viz --help[/bold] for all options.[/dim]")
96-
return
97-
9876
# Handle --list-steps
9977
if ARG('list_steps'):
10078
steps = discover_timesteps(case_dir, fmt)
@@ -155,12 +133,8 @@ def viz(): # pylint: disable=too-many-locals,too-many-statements,too-many-branc
155133
step_arg = ARG('step')
156134
tiled = varname is None or varname == 'all'
157135

158-
if step_arg is None:
159-
if ARG('interactive') or ARG('tui'):
160-
step_arg = 'all' # default to all steps in interactive/TUI mode
161-
else:
162-
raise MFCException("--step is required for rendering. "
163-
"Use --list-steps to see available timesteps, or pass --step all.")
136+
if ARG('interactive') or ARG('tui'):
137+
step_arg = 'all' # always load all steps in interactive/TUI mode
164138

165139
steps = discover_timesteps(case_dir, fmt)
166140
if not steps:
@@ -174,31 +148,21 @@ def viz(): # pylint: disable=too-many-locals,too-many-statements,too-many-branc
174148
raise MFCException(msg)
175149

176150
# Collect rendering options
177-
render_opts = {}
178-
cmap = ARG('cmap')
179-
if cmap:
180-
render_opts['cmap'] = cmap
181-
vmin = ARG('vmin')
182-
if vmin is not None:
183-
render_opts['vmin'] = float(vmin)
184-
vmax = ARG('vmax')
185-
if vmax is not None:
186-
render_opts['vmax'] = float(vmax)
187-
dpi = ARG('dpi')
188-
if dpi is not None:
189-
render_opts['dpi'] = int(dpi)
151+
render_opts = {
152+
'cmap': ARG('cmap'),
153+
'dpi': ARG('dpi'),
154+
'slice_axis': ARG('slice_axis'),
155+
}
156+
if ARG('vmin') is not None:
157+
render_opts['vmin'] = float(ARG('vmin'))
158+
if ARG('vmax') is not None:
159+
render_opts['vmax'] = float(ARG('vmax'))
190160
if ARG('log_scale'):
191161
render_opts['log_scale'] = True
192-
193-
slice_axis = ARG('slice_axis')
194-
slice_index = ARG('slice_index')
195-
slice_value = ARG('slice_value')
196-
if slice_axis:
197-
render_opts['slice_axis'] = slice_axis
198-
if slice_index is not None:
199-
render_opts['slice_index'] = int(slice_index)
200-
if slice_value is not None:
201-
render_opts['slice_value'] = float(slice_value)
162+
if ARG('slice_index') is not None:
163+
render_opts['slice_index'] = int(ARG('slice_index'))
164+
if ARG('slice_value') is not None:
165+
render_opts['slice_value'] = float(ARG('slice_value'))
202166

203167
interactive = ARG('interactive')
204168

@@ -222,11 +186,16 @@ def read_step(step):
222186
f"Refusing to load {len(requested_steps)} timesteps for 3D data "
223187
"(limit is 500). Use --step with a range or stride to reduce.")
224188

225-
# Tiled mode for non-TUI, non-interactive rendering only works for 1D
189+
# Tiled mode for non-TUI, non-interactive rendering only works for 1D.
190+
# For 2D/3D, auto-select the first available variable.
226191
if tiled and not interactive and not ARG('tui'):
227192
if test_assembled.ndim != 1:
228-
raise MFCException("--var is required for 2D/3D rendering. "
229-
"Use --list-vars to see available variables.")
193+
varname = avail[0] if avail else None
194+
if varname is None:
195+
raise MFCException("No variables found in output.")
196+
tiled = False
197+
cons.print(f"[dim]Auto-selected variable: [bold]{varname}[/bold]"
198+
" (use --var to specify)[/dim]")
230199

231200
if not tiled and not interactive and not ARG('tui') and varname not in test_assembled.variables:
232201
raise MFCException(f"Variable '{varname}' not found. "
@@ -247,7 +216,7 @@ def read_step(step):
247216
# Interactive mode — launch Dash web server
248217
if interactive:
249218
from .interactive import run_interactive # pylint: disable=import-outside-toplevel
250-
port = ARG('port') or 8050
219+
port = ARG('port')
251220
# Default to first available variable if --var was not specified
252221
init_var = varname if varname in avail else (avail[0] if avail else None)
253222
run_interactive(init_var, requested_steps, read_step, port=int(port))
@@ -261,7 +230,7 @@ def read_step(step):
261230

262231
# MP4 mode
263232
if ARG('mp4'):
264-
fps = ARG('fps') or 10
233+
fps = ARG('fps')
265234
label = 'all' if tiled else varname
266235
mp4_path = os.path.join(output_base, f'{label}.mp4')
267236
cons.print(f"[bold]Generating MP4:[/bold] {mp4_path} ({len(requested_steps)} frames)")

0 commit comments

Comments
 (0)