Skip to content

Commit b87d82c

Browse files
sbryngelsonclaude
andcommitted
Add h5py/imageio deps, cmap completion, quick-start guide, simplify imports
- Add h5py, imageio, imageio-ffmpeg to required deps in pyproject.toml - Remove optional h5py guard in silo_reader.py (now always installed) - Import imageio.v2 at module level in renderer.py (hard dep, no fallback) - Add --cmap tab completion with 17 colormaps to commands.py - Add quick-start guide in viz.py when no action flags are specified Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e3b6817 commit b87d82c

5 files changed

Lines changed: 34 additions & 26 deletions

File tree

toolchain/mfc/cli/commands.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,12 @@
911911
type=str,
912912
default=None,
913913
metavar="CMAP",
914+
completion=Completion(type=CompletionType.CHOICES, choices=[
915+
"viridis", "plasma", "magma", "inferno", "cividis",
916+
"hot", "cool", "jet", "rainbow", "turbo",
917+
"RdBu", "seismic", "bwr", "coolwarm",
918+
"gray", "bone", "pink",
919+
]),
914920
),
915921
Argument(
916922
name="vmin",

toolchain/mfc/viz/renderer.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import tempfile
1111

1212
import numpy as np
13+
14+
import imageio.v2 as imageio
15+
1316
import matplotlib
1417
matplotlib.use('Agg')
1518
import matplotlib.pyplot as plt # pylint: disable=wrong-import-position
@@ -234,12 +237,6 @@ def render_mp4(varname, steps, output, fps=10, # pylint: disable=too-many-argum
234237
frame_files = sorted(f for f in os.listdir(viz_dir) if f.endswith('.png'))
235238

236239
success = False
237-
try:
238-
import imageio # pylint: disable=import-outside-toplevel
239-
except ImportError:
240-
print("imageio is not installed. Install it with: pip install imageio imageio-ffmpeg")
241-
return False
242-
243240
try:
244241
imageio.mimwrite(
245242
output,

toolchain/mfc/viz/silo_reader.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,22 @@
77
Actual data lives in numbered datasets under the ``.silo/`` group.
88
99
This reader uses h5py to navigate that structure.
10-
11-
Requires: h5py (optional dependency).
1210
"""
1311

1412
import os
1513
import warnings
1614
from typing import Dict, List, Optional, Tuple
1715

16+
import h5py
1817
import numpy as np
1918

2019
from .reader import AssembledData, ProcessorData, assemble_from_proc_data
2120

22-
try:
23-
import h5py
24-
25-
HAS_H5PY = True
26-
except ImportError:
27-
HAS_H5PY = False
28-
2921
# Silo type constants (from silo.h)
3022
_DB_QUADMESH = 130
3123
_DB_QUADVAR = 501
3224

3325

34-
def _check_h5py():
35-
if not HAS_H5PY:
36-
raise ImportError(
37-
"h5py is required to read Silo-HDF5 files.\n"
38-
"Install it with: pip install h5py\n"
39-
"Or re-run post_process with format=2 to produce binary output."
40-
)
41-
42-
4326

4427
def _resolve_path(h5file, path_bytes):
4528
"""Resolve a silo internal path (e.g. b'/.silo/#000003') and return its data as a numpy array."""
@@ -60,7 +43,6 @@ def read_silo_file( # pylint: disable=too-many-locals
6043
Returns:
6144
ProcessorData with grid coordinates and variable arrays.
6245
"""
63-
_check_h5py()
6446

6547
with h5py.File(path, "r") as f:
6648
# --- locate the mesh ------------------------------------------------
@@ -146,7 +128,6 @@ def assemble_silo(
146128
"""
147129
Read and assemble multi-processor Silo-HDF5 data for a given timestep.
148130
"""
149-
_check_h5py()
150131

151132
base = os.path.join(case_dir, "silo_hdf5")
152133
if not os.path.isdir(base):

toolchain/mfc/viz/viz.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ def viz(): # pylint: disable=too-many-locals,too-many-statements,too-many-branc
7070

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

73+
# Quick guide when no action is specified
74+
if not ARG('list_steps') and not ARG('list_vars') and ARG('var') is None:
75+
cons.print()
76+
d = case_dir
77+
cons.print("[bold]Quick start:[/bold]")
78+
cons.print(f" [green]./mfc.sh viz {d} --list-steps[/green]"
79+
" [dim]see available timesteps[/dim]")
80+
cons.print(f" [green]./mfc.sh viz {d} --list-vars --step 0[/green]"
81+
" [dim]see available variables[/dim]")
82+
cons.print(f" [green]./mfc.sh viz {d} --var pres --step 0[/green]"
83+
" [dim]render a PNG[/dim]")
84+
cons.print(f" [green]./mfc.sh viz {d} --var pres --step all --mp4[/green]"
85+
" [dim]render an MP4[/dim]")
86+
cons.print(f" [green]./mfc.sh viz {d} --var pres --step 0 --slice-axis z[/green]"
87+
" [dim]3D midplane slice[/dim]")
88+
cons.print()
89+
cons.print("[dim]Run [bold]./mfc.sh viz --help[/bold] for all options.[/dim]")
90+
return
91+
7392
# Handle --list-steps
7493
if ARG('list_steps'):
7594
steps = discover_timesteps(case_dir, fmt)

toolchain/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ dependencies = [
3737
"seaborn",
3838
"matplotlib",
3939

40+
# Visualization
41+
"h5py",
42+
"imageio>=2.33",
43+
"imageio-ffmpeg>=0.5.0",
44+
4045
# Chemistry
4146
"cantera>=3.1.0",
4247
#"pyrometheus == 1.0.5",

0 commit comments

Comments
 (0)