kwave.utils.interp module

get_bli(func, dx=1, up_sampling_factor=20, plot=False)[source]

Calculates the band-limited interpolant of a 1D input function.

Parameters:
  • func (ndarray) – The 1D input function.

  • dx (float | None) – Spatial sampling in meters. Defaults to 1.

  • up_sampling_factor (int | None) – Up-sampling factor used to sample the underlying BLI. Defaults to 20.

  • plot (bool | None) – Whether to plot the BLI. Defaults to False.

Returns:

A tuple containing the BLI and the x-grid for the BLI.

Return type:

tuple[ndarray, ndarray]

get_delta_bli(Nx, dx, x, x0, include_imag=False)[source]

Exact BLI of an arbitrarily positioned delta function.

Calculates the exact Band-Limited Interpolation (BLI) of an arbitrarily positioned delta function. For grid dimensions with an evenly-sampled periodicity, a small Nyquist frequency sinusoid is added. This sinusoid is invisible on grid samples and has zero amplitude when the delta function lies on a grid node. It is important when the evaluation points aren’t grid nodes, and when the delta function is off-grid. It serves to ensure conjugate symmetry in the BLI’s Fourier transform.

Parameters:
  • Nx (int) – Number of grid points in the relevant Cartesian direction.

  • dx (float) – Grid point spacing [m].

  • x (ndarray) – Coordinates at which the BLI is evaluated [m].

  • x0 (int | float) – Coordinate at which the BLI is centered [m].

  • include_imag (bool) – Whether to include the imaginary component of the off-grid delta function. Defaults to False.

Returns:

Value of the BLI at the specified coordinates.

Return type:

f

interp_cart_data(kgrid, cart_sensor_data, cart_sensor_mask, binary_sensor_mask, interp='nearest')[source]

Takes a matrix of time-series data recorded over a set of Cartesian sensor points given by cart_sensor_mask and computes the equivalent time-series at each sensor position on the binary sensor mask binary_sensor_mask using interpolation. The properties of binary_sensor_mask are defined by the k-Wave grid object kgrid. Two and three-dimensional data are supported.

Usage:

binary_sensor_data = interp_cart_data(kgrid, cart_sensor_data, cart_sensor_mask, binary_sensor_mask) binary_sensor_data = interp_cart_data(kgrid, cart_sensor_data, cart_sensor_mask, binary_sensor_mask, interp)

Parameters:
  • kgrid – k-Wave grid object returned by kWaveGrid

  • cart_sensor_data – original sensor data measured over cart_sensor_mask indexed as cart_sensor_data(sensor position, time)

  • cart_sensor_mask – Cartesian sensor mask over which cart_sensor_data is measured

  • binary_sensor_mask – binary sensor mask at which equivalent time-series are computed via interpolation

  • interp – (optional) interpolation mode used to compute the time-series, both ‘nearest’ and ‘linear’ (two-point) modes are supported (default = ‘nearest’)

Returns:

array of time-series corresponding to the sensor positions given by binary_sensor_mask

interpftn(x, sz, win=None)[source]

Resamples an N-D matrix to the size given in sz using Fourier interpolation.

Parameters:
  • x – matrix to interpolate

  • sz (tuple) – list or tupple of new size

  • win – (optional) name of windowing function to use

Returns:

Resampled matrix

Examples

>>> y = interpftn(x, sz)
>>> y = interpftn(x, sz, win)
interpolate2d(grid_points, grid_values, interp_locs, method='linear', copy_nans=True)[source]

Interpolates input grid values at the given locations Added by Farid

Matlab version of this function assumes unstructured grid. Interpolating such grid in Python using SciPy is very expensive. Thankfully, working with structured grid is fine for our purposes. We still support 3D arguments for backward compatibility even though they are mapped to 1D grid. While mapping we assume that only one axis per 3D grid changes throughout the grid.

Parameters:
  • copy_nans

  • grid_points (list[ndarray]) – List of 1D or 3D Numpy arrays

  • grid_values (ndarray) – A 3D Numpy array which holds values at grid_points

  • interp_locs (list[ndarray]) – List of 1D or 3D Numpy arrays

Return type:

ndarray

interpolate2d_with_queries(grid_points, grid_values, queries, method='linear', copy_nans=True)[source]

Interpolates input grid values at the given locations Added by Farid

Simplified version of interpolate2D_coords. Expects interp_locs to be [N, 2] coordinates of the interpolation locations. Does not create meshgrid on the interp_locs as interpolate2D_coords! WARNING: supposed to support only 2D interpolation!

Parameters:
  • copy_nans

  • grid_points (list[ndarray]) – List of 1D or 3D Numpy arrays

  • grid_values (ndarray) – A 3D Numpy array which holds values at grid_points

  • queries (ndarray) – Numpy array with shape [N, 2]

Return type:

ndarray

interpolate3d(grid_points, grid_values, interp_locs)[source]

Interpolates input grid values at the given locations Added by Farid

Matlab version of this function assumes unstructured grid. Interpolating such grid in Python using SciPy is very expensive. Thankfully, working with structured grid is fine for our purposes. We still support 3D arguments for backward compatibility even though they are mapped to 1D grid. While mapping we assume that only one axis per 3D grid changes throughout the grid.

Parameters:
  • grid_points (list[ndarray]) – List of 1D or 3D Numpy arrays

  • grid_values (ndarray) – A 3D Numpy array which holds values at grid_points

  • interp_locs (list[ndarray]) – List of 1D or 3D Numpy arrays

Return type:

ndarray