Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed notebooks/gridweights.nii.gz
Binary file not shown.
18 changes: 3 additions & 15 deletions notebooks/test_first.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"source": [
"import sys\n",
"import logging\n",
"USE_GRIDWEIGHTS = False\n",
"root = logging.getLogger()\n",
"loglevel = logging.DEBUG\n",
"root.setLevel(loglevel)\n",
Expand All @@ -39,16 +38,6 @@
"We'll start by generating a transducer and drawing it using some vtk-based methods"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import kwave\n",
"kwave.url_dict"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -116,7 +105,7 @@
"metadata": {},
"outputs": [],
"source": [
"ds = openlifu.sim.run_simulation(arr=arr, \n",
"(ds, output) = openlifu.sim.run_simulation(arr=arr, \n",
" params=params, \n",
" delays=delays,\n",
" apod= apod,\n",
Expand All @@ -125,8 +114,7 @@
" dt=protocol.sim_setup.dt,\n",
" t_end=protocol.sim_setup.t_end,\n",
" amplitude = 1,\n",
" load_gridweights=USE_GRIDWEIGHTS,\n",
" save_gridweights=USE_GRIDWEIGHTS)"
" gpu = False)"
]
},
{
Expand Down Expand Up @@ -228,7 +216,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
484 changes: 0 additions & 484 deletions notebooks/test_gridweights.ipynb

This file was deleted.

3 changes: 1 addition & 2 deletions notebooks/test_nifti.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@
" cycles = np.max([np.round(pulse.duration * pulse.frequency), 20]),\n",
" dt=protocol.sim_setup.dt,\n",
" t_end=protocol.sim_setup.t_end,\n",
" amplitude = 1,\n",
" save_gridweights=False)"
" amplitude = 1)"
]
},
{
Expand Down
36 changes: 5 additions & 31 deletions src/openlifu/sim/kwave_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,14 @@ def get_sensor(kgrid, record=['p_max','p_min']):
sensor = kSensor(sensor_mask, record=record)
return sensor

def get_source(kgrid, karray, source_sig, grid_weights=None):
def get_source(kgrid, karray, source_sig):
source = kSource()
logging.info("Getting binary mask")
source.p_mask = karray.get_array_binary_mask(kgrid)
logging.info("Getting distributed source signal")
source.p = karray.get_distributed_source_signal(kgrid, source_sig, grid_weights=grid_weights)
source.p = karray.get_distributed_source_signal(kgrid, source_sig)
return source

def hash_array_kgrid(kgrid, karray):
c = Calculator(Crc32.CRC32)
d = {'x':kgrid.x_vec.tolist(),
'y':kgrid.y_vec.tolist(),
'z':kgrid.z_vec.tolist(),
'transform': karray.array_transformation.tolist(),
'BLI_tolerance': karray.bli_tolerance,
'upsampling_rate': karray.upsampling_rate}
check = c.checksum(bytes(json.dumps(d), 'utf-8'))
return f'{check:x}'

def run_simulation(arr: xdc.Transducer,
params: xa.Dataset,
delays: Optional[np.ndarray] = None,
Expand All @@ -84,12 +73,9 @@ def run_simulation(arr: xdc.Transducer,
amplitude: float = 1,
dt: float = 0,
t_end: float = 0,
grid_weights: Optional[np.ndarray] = None,
load_gridweights: bool = True,
save_gridweights: bool = True,
db = None,
bli_tolerance: float = 0.05,
upsampling_rate: int = 5,
gpu: bool = True
):
delays = delays if delays is not None else np.zeros(arr.numelements())
apod = apod if apod is not None else np.ones(arr.numelements())
Expand All @@ -106,27 +92,15 @@ def run_simulation(arr: xdc.Transducer,
upsampling_rate=upsampling_rate)
medium = get_medium(params)
sensor = get_sensor(kgrid, record=['p_max', 'p_min'])
if grid_weights is None and load_gridweights and db is not None:
h = hash_array_kgrid(kgrid, karray)
available_hashes = db.get_gridweight_hashes(arr.id)
if h in available_hashes:
logging.info("Loading grid weights")
grid_weights = db.load_gridweights(arr.id, h)
if grid_weights is None:
logging.info("Calculating grid weights")
grid_weights = np.array([karray.get_element_grid_weights(kgrid, i) for i in range(karray.number_elements)])
if save_gridweights and db is not None:
logging.info("Saving grid weights")
db.add_gridweights(arr.id, h, grid_weights, on_conflict='overwrite')
source = get_source(kgrid, karray, source_mat, grid_weights=grid_weights)
source = get_source(kgrid, karray, source_mat)
logging.info("Running simulation")
simulation_options = SimulationOptions(
pml_auto=True,
pml_inside=False,
save_to_disk=True,
data_cast='single'
)
execution_options = SimulationExecutionOptions(is_gpu_simulation=True)
execution_options = SimulationExecutionOptions(is_gpu_simulation=gpu)
output = kspaceFirstOrder3D(kgrid=kgrid,
source=source,
sensor=sensor,
Expand Down