Skip to content

Commit 8dc2859

Browse files
Clean up k-wave files
Closes #435
1 parent 8327bed commit 8dc2859

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/openlifu/sim/kwave_if.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
from copy import deepcopy
5+
from pathlib import Path
56
from typing import List
67

78
import numpy as np
@@ -222,6 +223,13 @@ def run_simulation(arr: xdc.Transducer,
222223
coords=[pcoords[dim] for dim in ['t','x','y','z']],
223224
attrs={'units':'Pa', 'long_name':'Pressure'})
224225

226+
# clean up temporary files created by k-wave
227+
for filename in [simulation_options.input_filename, simulation_options.output_filename]:
228+
try:
229+
Path(filename).unlink(missing_ok=True)
230+
except Exception as e:
231+
logging.warning(f"Could not remove temporary file {filename}: {e}")
232+
225233
ds = xa.Dataset(ds_dict)
226234
if return_kwave_outputs and return_kwave_inputs:
227235
return ds, output, inputs

0 commit comments

Comments
 (0)