Skip to content

Commit 87a74ae

Browse files
sbryngelsonclaude
andcommitted
Reuse first-step read and add diagnostic warnings for missing timestep dirs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 29f20a9 commit 87a74ae

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

toolchain/mfc/viz/reader.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ def discover_timesteps(case_dir: str, fmt: str) -> List[int]:
241241
pass
242242
return sorted(steps)
243243

244+
import warnings # pylint: disable=import-outside-toplevel
245+
warnings.warn(
246+
f"No timestep directories found: checked '{root_dir}' and '{p0_dir}'",
247+
stacklevel=2,
248+
)
249+
244250
elif fmt == 'silo':
245251
p0_dir = os.path.join(case_dir, 'silo_hdf5', 'p0')
246252
if os.path.isdir(p0_dir):
@@ -253,7 +259,13 @@ def discover_timesteps(case_dir: str, fmt: str) -> List[int]:
253259
pass
254260
return sorted(steps)
255261

256-
return [] # no timestep files found in expected directories
262+
import warnings # pylint: disable=import-outside-toplevel
263+
warnings.warn(
264+
f"No timestep directory found: checked '{p0_dir}'",
265+
stacklevel=2,
266+
)
267+
268+
return []
257269

258270

259271
def _discover_processors(case_dir: str, fmt: str) -> List[int]:

toolchain/mfc/viz/viz.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,17 @@ def read_step(step):
186186
return assemble_silo(case_dir, step, var=varname)
187187
return assemble(case_dir, step, fmt, var=varname)
188188

189-
# Validate variable name by reading the first timestep (without var filter)
190-
def read_step_all_vars(step):
189+
# Validate variable name by reading the first timestep (without var filter),
190+
# then reuse it for the first rendered frame to avoid double I/O.
191+
first_assembled = read_step(requested_steps[0])
192+
if varname not in first_assembled.variables:
193+
# Re-read without filter to show all available variable names
191194
if fmt == 'silo':
192195
from .silo_reader import assemble_silo # pylint: disable=import-outside-toplevel
193-
return assemble_silo(case_dir, step)
194-
return assemble(case_dir, step, fmt)
195-
196-
test_assembled = read_step_all_vars(requested_steps[0])
197-
if varname not in test_assembled.variables:
198-
avail = sorted(test_assembled.variables.keys())
196+
all_vars_assembled = assemble_silo(case_dir, requested_steps[0])
197+
else:
198+
all_vars_assembled = assemble(case_dir, requested_steps[0], fmt)
199+
avail = sorted(all_vars_assembled.variables.keys())
199200
cons.print(f"[bold red]Error:[/bold red] Variable '{varname}' not found.")
200201
cons.print(f"[bold]Available variables:[/bold] {', '.join(avail)}")
201202
sys.exit(1)
@@ -231,7 +232,7 @@ def read_step_all_vars(step):
231232
failures = []
232233
for step in step_iter:
233234
try:
234-
assembled = read_step(step)
235+
assembled = first_assembled if step == requested_steps[0] else read_step(step)
235236
except (FileNotFoundError, EOFError, ValueError) as exc:
236237
cons.print(f"[yellow]Warning:[/yellow] Skipping step {step}: {exc}")
237238
failures.append(step)

0 commit comments

Comments
 (0)