Getting Started

k-Wave-gen offers basic interoperability between C++/CUDA solvers offered in k-Wave toolkit and Python. While k-Wave primarily focuses on MATLAB as working environment, this code shows how Python can be used as an alternative.

The code represents minimal implementation to allow interfacing k-Wave solvers with Python and DOES NOT aim to implement all features of k-Wave MATLAB toolbox.

The code allows to:

Basic Usage

The basic idea behind input/output files is to provide “file-like” interface, which user provides solely with data required to perform the simulation. The implementation then takes care of checking validity of provided data (eg. “is provided array of right shape?”) and generates flags and other derived data required by the solver. For example:

with KWaveInputFile(...) as file:
    # The data can now be written directly to the file using calls
    # such as "file.write_*".
    # NOTE: The data are written DIRECTLY and therefore should
    # be written only ONCE!

# HERE: The file is finalized and closed as it leaves the scope.

The output files are handled similarly.

Slightly different approach is necessary, when k-Wave Binary Driver is used. In this case the input file has to stay in the scope even after it is closed so it can be used with the driver.

input_file  = KWaveInputFile(...)
output_file = KWaveOutputFile(...)

with input_file as file:
    # Setup input file as usual...

driver = KWaveBinaryDriver(...)
# Setup the driver...
driver.run(input_file, output_file) # Run the simulation

with output_file as file:
    # Here outputs of the simulation can be analyzed

Examples

Few examples which show basic usage of the code and compare it to the MATLAB.

  • Example 1: Simple homogeneous linear problem with initial pressure.

  • Example 2: Simple homogeneous linear problem with single pressure source.

  • Example 3: Simple homogeneous linear problem with multiple pressure sources.

  • Example 4: Simple homogeneous linear problem with initial pressure which shows how to use binary driver to run and analyze results of the simulation.