kwave.kgrid module#
- class kWaveGrid[source]#
Bases:
objectkWaveGrid is the grid class used across the k-Wave Toolbox. An object of the kWaveGrid class contains the grid coordinates and wavenumber matrices used within the simulation and reconstruction functions in k-Wave. The grid matrices are indexed as: (x, 1) in 1D; (x, y) in 2D; and (x, y, z) in 3D. The grid is assumed to be a regularly spaced Cartesian grid, with grid spacing given by dx, dy, dz (typically the grid spacing in each direction is constant).
- CFL_DEFAULT = 0.3#
- MACHINE_PRECISION = 2.220446049250313e-14#
- N#
grid size in each dimension [grid points]
- Nt#
number of time steps [s]
- property Nx#
grid size in x-direction [grid points]
- property Ny#
grid size in y-direction [grid points]
- property Nz#
grid size in z-direction [grid points]
- __init__(N, spacing)[source]#
- Parameters:
N – grid size in each dimension [grid points]
spacing – grid point spacing in each direction [m]
- dim#
Number of dimensions (1, 2 or 3)
- dt#
size of time step [s]
- dudn#
transformation gradients between uniform and staggered grids
- dudn_sg#
transformation gradients between uniform and staggered grids
- property dx#
grid point spacing in x-direction [m]
- property dy#
grid point spacing in y-direction [m]
- property dz#
grid point spacing in z-direction [m]
- highest_prime_factors(axisymmetric=None)[source]#
calculate the highest prime factors
- Parameters:
axisymmetric – Axisymmetric code or None
- Returns:
Vector of three elements
- Return type:
ndarray
- k#
scalar wavenumber
- k_dtt(dtt_type)[source]#
compute the individual wavenumber vectors, where dtt_type is the type of discrete trigonometric transform, which corresponds to the assumed input symmetry of the input function, where:
DCT-I WSWS
DCT-II HSHS
DCT-III WSWA
DCT-IV HSHA
DST-I WAWA
DST-II HAHA
DST-III WAWS
DST-IV HAHS
- Parameters:
dtt_type –
Returns:
- property k_max#
Maximum supported spatial frequency in the 3 directions [rad/m]
- Returns:
Vector of 3 elements each in [rad/m]. Value for higher dimensions set to NaN
- property k_max_all#
Maximum supported spatial frequency in all directions [rad/m] Originally k_max in kWave.kWaveGrid!
- Returns:
Scalar in [rad/m]
- k_vec#
Nx x 1 vector of wavenumber components in the x-direction [rad/m]
- property kx#
Nx x Ny x Nz grid containing repeated copies of the wavenumber components in the x-direction [rad/m]
- Returns:
plaid xn matrix
- kx_vec_dtt(dtt_type)[source]#
Compute the DTT wavenumber vector in the x-direction
- Parameters:
dtt_type –
Returns:
- property ky#
Nx x Ny x Nz grid containing repeated copies of the wavenumber components in the y-direction [rad/m]
- Returns:
plaid yn matrix
- ky_vec_dtt(dtt_type)[source]#
Compute the DTT wavenumber vector in the y-direction
- Parameters:
dtt_type –
Returns:
- property kz#
Nx x Ny x Nz grid containing repeated copies of the wavenumber components in the z-direction [rad/m]
- Returns:
plaid zn matrix
- kz_vec_dtt(dtt_type)[source]#
Compute the DTT wavenumber vector in the z-direction
- Parameters:
dtt_type –
Returns:
- static makeDTTDim(Nx, dx, dtt_type)[source]#
Create the DTT grid parameters for a single spatial direction
- Parameters:
Nx –
dx –
dtt_type –
Returns:
- static makeDim(num_points, spacing)[source]#
Create the grid parameters for a single spatial direction
- Parameters:
num_points –
spacing –
Returns:
- makeTime(c, cfl=0.3, t_end=None)[source]#
Compute Nt and dt based on the cfl number and grid size, where the number of time-steps is chosen based on the time it takes to travel from one corner of the grid to the geometrically opposite corner. Note, if c is given as a matrix, the calculation for dt is based on the maximum value, and the calculation for t_end based on the minimum value.
- Parameters:
c – sound speed
cfl – convergence condition by Courant–Friedrichs–Lewy
t_end – final time step
- Returns:
Nothing
- n_vec#
position vectors for the grid points in [0, 1]
- n_vec_sg#
position vectors for the staggered grid points in [0, 1]
- nonuniform#
flag that indicates grid non-uniformity
- setNUGrid(dim, n_vec, dudn, n_vec_sg, dudn_sg)[source]#
Function to set non-uniform grid parameters in specified dimension
- Parameters:
dim –
n_vec –
dudn –
n_vec_sg –
dudn_sg –
Returns:
- setTime(Nt, dt)[source]#
Set Nt and dt based on user input
- Parameters:
Nt –
dt –
- Return type:
None
Returns: None
- property size#
Size of grid in the all directions [m]
- spacing#
grid point spacing in each direction [m]
- property t_array#
time array [s]
- property total_grid_points: ndarray#
Total number of grid points (equal to Nx * Ny * Nz)
- property x#
Nx x Ny x Nz grid containing repeated copies of the grid coordinates in the x-direction [m]
- property x_size#
Size of grid in the x-direction [m]
- property x_vec#
Nx x 1 vector of the grid coordinates in the x-direction [m]
- property xn#
3D plaid non-uniform spatial grids
- Returns:
plaid xn matrix
- property y#
Nx x Ny x Nz grid containing repeated copies of the grid coordinates in the y-direction [m]
- property y_size#
Size of grid in the y-direction [m]
- property y_vec#
Ny x 1 vector of the grid coordinates in the y-direction [m]
- property yn#
3D plaid non-uniform spatial grids
- Returns:
plaid yn matrix
- property z#
Nx x Ny x Nz grid containing repeated copies of the grid coordinates in the z-direction [m]
- property z_size#
Size of grid in the z-direction [m]
- property z_vec#
Nz x 1 vector of the grid coordinates in the z-direction [m]
- property zn#
3D plaid non-uniform spatial grids :returns: plaid zn matrix