33import logging
44from typing import List
55
6- import kwave
7- import kwave .data
86import numpy as np
97import xarray as xa
10- from kwave .kgrid import kWaveGrid
11- from kwave .kmedium import kWaveMedium
12- from kwave .ksensor import kSensor
13- from kwave .ksource import kSource
14- from kwave .kspaceFirstOrder3D import kspaceFirstOrder3D
15- from kwave .options .simulation_execution_options import SimulationExecutionOptions
16- from kwave .options .simulation_options import SimulationOptions
17- from kwave .utils .kwave_array import kWaveArray
188
199from openlifu import xdc
2010from openlifu .util .units import getunitconversion
2111
2212
2313def get_kgrid (coords : xa .Coordinates , t_end = 0 , dt = 0 , sound_speed_ref = 1500 , cfl = 0.5 ):
14+ from kwave .kgrid import kWaveGrid
2415 units = [coords [dim ].attrs ['units' ] for dim in coords .dims ]
2516 if not all (unit == units [0 ] for unit in units ):
2617 raise ValueError ("All coordinates must have the same units" )
@@ -40,6 +31,9 @@ def get_karray(arr: xdc.Transducer,
4031 upsampling_rate : int = 5 ,
4132 translation : List [float ] = [0. ,0. ,0. ],
4233 rotation : List [float ] = [0. ,0. ,0. ]):
34+ import kwave
35+ import kwave .data
36+ from kwave .utils .kwave_array import kWaveArray
4337 karray = kWaveArray (bli_tolerance = bli_tolerance , upsampling_rate = upsampling_rate ,
4438 single_precision = True )
4539 for el in arr .elements :
@@ -53,6 +47,7 @@ def get_karray(arr: xdc.Transducer,
5347 return karray
5448
5549def get_medium (params : xa .Dataset , ref_values_only : bool = False ):
50+ from kwave .kmedium import kWaveMedium
5651 if ref_values_only :
5752 medium = kWaveMedium (sound_speed = params ['sound_speed' ].attrs ['ref_value' ],
5853 density = params ['density' ].attrs ['ref_value' ],
@@ -68,11 +63,13 @@ def get_medium(params: xa.Dataset, ref_values_only: bool = False):
6863 return medium
6964
7065def get_sensor (kgrid , record = ['p_max' ,'p_min' ]):
66+ from kwave .ksensor import kSensor
7167 sensor_mask = np .ones ([kgrid .Nx , kgrid .Ny , kgrid .Nz ])
7268 sensor = kSensor (sensor_mask , record = record )
7369 return sensor
7470
7571def get_source (kgrid , karray , source_sig ):
72+ from kwave .ksource import kSource
7673 source = kSource ()
7774 logging .info ("Getting binary mask" )
7875 source .p_mask = karray .get_array_binary_mask (kgrid )
@@ -95,6 +92,9 @@ def run_simulation(arr: xdc.Transducer,
9592 gpu : bool = True ,
9693 ref_values_only : bool = False
9794):
95+ from kwave .kspaceFirstOrder3D import kspaceFirstOrder3D
96+ from kwave .options .simulation_execution_options import SimulationExecutionOptions
97+ from kwave .options .simulation_options import SimulationOptions
9898 delays = delays if delays is not None else np .zeros (arr .numelements ())
9999 apod = apod if apod is not None else np .ones (arr .numelements ())
100100 kgrid = get_kgrid (params .coords , dt = dt , t_end = t_end , cfl = cfl )
0 commit comments