kwave.utils.conversion module¶
- cart2grid(kgrid, cart_data, axisymmetric=False)[source]¶
Interpolates the set of Cartesian points defined by cart_data onto a binary matrix defined by the kWaveGrid object kgrid using nearest neighbour interpolation. An error is returned if the Cartesian points are outside the computational domain defined by kgrid.
- Parameters:
kgrid (kWaveGrid) – simulation grid
cart_data (Float[ndarray, '1 NumPoints'] | Float[ndarray, '2 NumPoints'] | Float[ndarray, '3 NumPoints']) – Cartesian sensor points
axisymmetric (bool) – set to True to use axisymmetric interpolation
- Returns:
A binary grid
- Return type:
tuple
- cart2pol(x, y)[source]¶
Convert from cartesian to polar coordinates.
- Parameters:
x (Real[ndarray, '...'] | number | int | float) – The x-coordinate of the point.
y (Real[ndarray, '...'] | number | int | float) – The y-coordinate of the point.
- Returns:
A tuple containing the polar coordinates of the point.
- Return type:
tuple[Real[ndarray, ‘…’] | number | int | float, Real[ndarray, ‘…’] | number | int | float]
- cast_to_type(data, matlab_type)[source]¶
- Parameters:
data (Real[ndarray, '...'] | number | int | float) – The data to cast.
matlab_type (str) – The type to cast to.
- Returns:
The cast data.
- Return type:
Any
- db2neper(alpha, y=1)[source]¶
Convert decibels to nepers.
- Parameters:
alpha (Real[ndarray, '...'] | number | int | float) – Attenuation in dB / (MHz ^ y cm).
y (Real[ndarray, ' '] | number | int | float) – Power law exponent (default=1).
- Returns:
Attenuation in Nepers / ((rad / s) ^ y m).
- Return type:
Real[ndarray, ‘…’] | number | int | float
- find_closest(array, value)[source]¶
- Parameters:
array (ndarray)
value (Num[ndarray, ' '] | number | int | float | complex)
- freq2wavenumber(n, k_max, filter_cutoff, c, k_dim)[source]¶
Convert the given frequency and maximum wavenumber to a wavenumber cutoff and filter size.
- Parameters:
n (int) – The size of the grid.
k_max (float) – The maximum wavenumber.
filter_cutoff (float) – The frequency to convert to a wavenumber cutoff.
c (float) – The speed of sound.
k_dim (int | tuple[int]) – The dimensions of the wavenumber grid.
- Returns:
A tuple containing the calculated filter size and wavenumber cutoff.
- Return type:
tuple[int, float]
- grid2cart(input_kgrid, grid_selection)[source]¶
Returns the Cartesian coordinates of the non-zero points of a binary grid.
- Parameters:
input_kgrid (kWaveGrid) – k-Wave grid object returned by kWaveGrid
grid_selection (ndarray) – binary grid with the same dimensions as the k-Wave grid kgrid
- Returns:
1 x N, 2 x N, or 3 x N (for 1, 2, and 3 dimensions) array of Cartesian sensor points order_index: returns a list of indices of the returned cart_data coordinates.
- Return type:
cart_data
- Raises:
ValueError – when input_kgrid.dim is not in [1, 2, 3]
- hounsfield2density(ct_data, plot_fitting=False)[source]¶
Convert Hounsfield units in CT data to density values [kg / m ^ 3] based on experimental data.
- Parameters:
ct_data (Float[ndarray, 'Dim1 Dim2'] | Float[ndarray, 'Dim1 Dim2 Dim3']) – The CT data in Hounsfield units.
plot_fitting (bool, optional) – Whether to plot the fitting curve (default: False).
- Returns:
The density values in [kg / m ^ 3].
- Return type:
Float[ndarray, ‘Dim1 Dim2’] | Float[ndarray, ‘Dim1 Dim2 Dim3’]
- hounsfield2soundspeed(ct_data)[source]¶
Calculates the sound speed of a medium given a CT (computed tomography) of the medium. For soft tissue, the approximate sound speed can also be returned using the empirical relationship given by Mast [1].
- Parameters:
ct_data (Float[ndarray, 'Dim1 Dim2'] | Float[ndarray, 'Dim1 Dim2 Dim3']) – matrix of Hounsfield values.
- Returns:
A matrix of sound speed values of size of ct_data.
- Return type:
Float[ndarray, ‘Dim1 Dim2’] | Float[ndarray, ‘Dim1 Dim2 Dim3’]
References
[1] Mast, T. D., “Empirical relationships between acoustic parameters in human soft tissues,” Acoust. Res. Lett. Online, 1(2), pp. 37-42 (2000).
- neper2db(alpha, y=1)[source]¶
Converts an attenuation coefficient in units of Nepers / ((rad / s) ^ y m) to units of dB / (MHz ^ y cm).
- Parameters:
alpha (Real[ndarray, '...'] | number | int | float) – Attenuation in Nepers / ((rad / s) ^ y m)
y (Real[ndarray, ' '] | number | int | float) – Power law exponent (default=1)
- Returns:
Attenuation in dB / (MHz ^ y cm)
- Return type:
Real[ndarray, ‘…’] | number | int | float