Skip to content

Commit fe17687

Browse files
sbryngelsonclaude
andcommitted
Fix MP4 opts mutation, frame cleanup safety, silo skip warning
- Copy opts dict in render_mp4 to avoid mutating caller's dict - Only delete generated frame files during cleanup, not all files - Add missing-file warning in silo reader (consistent with binary reader) - Fix render_mp4 comment and _resolve_path docstring accuracy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 306016c commit fe17687

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

toolchain/mfc/viz/renderer.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ def render_mp4(varname, steps, output, fps=10, # pylint: disable=too-many-argum
156156
if not steps:
157157
raise ValueError("No timesteps provided for MP4 generation")
158158

159-
# Pre-compute vmin/vmax from first and last frames if not provided
159+
opts = dict(opts) # avoid mutating the caller's dict
160+
161+
# Pre-compute vmin/vmax from first, middle, and last frames if not provided
160162
auto_vmin = opts.get('vmin')
161163
auto_vmax = opts.get('vmax')
162164

@@ -229,9 +231,14 @@ def render_mp4(varname, steps, output, fps=10, # pylint: disable=too-many-argum
229231
if writer is not None:
230232
writer.close()
231233

232-
# Clean up frames
234+
# Clean up only the frames we created
233235
if success:
234-
for fname in os.listdir(viz_dir):
235-
os.remove(os.path.join(viz_dir, fname))
236-
os.rmdir(viz_dir)
236+
for fname in frame_files:
237+
fpath = os.path.join(viz_dir, fname)
238+
if os.path.isfile(fpath):
239+
os.remove(fpath)
240+
try:
241+
os.rmdir(viz_dir)
242+
except OSError:
243+
pass # directory not empty (pre-existing files)
237244
return success

toolchain/mfc/viz/silo_reader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _check_h5py():
4141

4242

4343
def _resolve_path(h5file, path_bytes):
44-
"""Resolve a silo internal path (e.g. b'/.silo/#000003') to a dataset."""
44+
"""Resolve a silo internal path (e.g. b'/.silo/#000003') and return its data as a numpy array."""
4545
path = path_bytes.decode() if isinstance(path_bytes, bytes) else str(path_bytes)
4646
return np.array(h5file[path])
4747

@@ -160,6 +160,8 @@ def assemble_silo(
160160
for rank in ranks:
161161
silo_file = os.path.join(base, f"p{rank}", f"{step}.silo")
162162
if not os.path.isfile(silo_file):
163+
import warnings # pylint: disable=import-outside-toplevel
164+
warnings.warn(f"Processor file not found, skipping: {silo_file}", stacklevel=2)
163165
continue
164166
pdata = read_silo_file(silo_file, var_filter=var)
165167
proc_data.append((rank, pdata))

0 commit comments

Comments
 (0)