neurotools.spatial.peaks module

neurotools.spatial.peaks.blurkernel(L, σ, normalize=False)[source]

1D Gaussian blur convolution kernel

Parameters:
  • L (int) – Size of L×L spatial domain

  • σ (positive float) – kernel radius exp(-x²/σ) (standard deviation in x and y ×⎷2)

  • normalize (boolean) – Whether to make kernel sum to 1

neurotools.spatial.peaks.blurkernel2D(L, σ, normalize=False)[source]

2D Gaussian blur convolution kernel

Parameters:
  • L (int) – Size of L×L spatial domain

  • σ (positive number) – kernel radius exp(-x²/σ) (standard deviation in x and y ×⎷2)

  • normalize (boolean; default False) – whether to make kernel sum to 1

neurotools.spatial.peaks.conv(x, K)[source]

Compute circular 2D convolution using FFT Kernel K should already be fourier-transformed

Parameters:
  • x (2D array)

  • K (Fourier-transformed convolution kernel)

neurotools.spatial.peaks.blur(x, σ, **kwargs)[source]

2D Gaussian blur via fft

Parameters:
  • x (2D np.array)

  • σ (float) – kernel radius exp(-x²/σ) (standard deviation in x and y ×⎷2)

neurotools.spatial.peaks.findpeaks(q, height_threshold=-inf, r=1)[source]

Find points higher than height_threshold, that are also higher than all other points in a radius r circular neighborhood.

Parameters:
  • q (np.float32) – 2D array of potential values

  • height_threshold (float) – Peaks must be higher than this to cound.

  • r (int) – Peaks must be larger than all other pixels in radius r to count.

Returns:

2D boolean array of the same sape as q, indicating which pixels are local maxima within radius r.

Return type:

np.bool

neurotools.spatial.peaks.dx_op(L)[source]
Parameters:

L (int) – Size of L×L spatial grid

neurotools.spatial.peaks.hessian_2D(q)[source]

Get Hessian of discrete 2D function at all points

Parameters:

q (np.complex64) – List of peak locations encoded as x+iy complex

neurotools.spatial.peaks.circle_mask(nr, nc)[source]

Zeros out corner frequencies

Parameters:
  • nr (int) – number of rows in mask

  • nc (int) – number of columns in mask

neurotools.spatial.peaks.fft_upsample_2D(x, factor=4)[source]

Upsample 2D array using the FFT

Parameters:

x (2D np.float32)

neurotools.spatial.peaks.interpolate_peaks(z, r=1, return_coordinates='index', height_threshold=None)[source]

Obtain peak locations by quadratic interpolation.

Presently, this function expects a square array.

Parameters:
  • z (ndarray, L×L×NSAMPLES) – A 3D array of sampled 2D grid-fields, where the LAST axis is the sample numer.

  • r (positive int; default 1) – Radius over which point must be local maximum to include. Defaults to 1 (nearest neighbors)

  • return_coordinates (str; deftault 'index') – Can be ‘index’ or ‘normalized’. If ‘index’, points will be returns in units of array index. If ‘normalized’, points will be returned in units [0,1]².

  • height_threshold (float) – Threshold (in height) for peak inclusion. Defaults to the 25th percentil of z

Returns:

  • ix (interpolated x location of peaks)

  • iy (interpolated y location of peaks)

  • rz (indecies of which sample each peak comes from)

neurotools.spatial.peaks.bin_spikes(px, py, s, L, w=None)[source]

Bin spikes, using linear interpolation to distribute point mass to four nearest pixels, weighted by distance.

Parameters:
  • px (np.flaot32) – x location of points

  • py (np.float32) – y location of points

  • s (np.array) – spike count at each point

  • L (int) – number of spatial bins for the LxL grid

  • w (np.float32) – weights to apply to each point (default is None for no weigting)

neurotools.spatial.peaks.get_peak_density(z, resolution, r=1, height_threshold=None)[source]

Obtain peaks by quadratic interpolation, then bin the results to a spatial grid with linear interpolation.

Parameters:
  • z (ndarray, L×L×NSAMPLES) – A 3D array of 2D grid field samples, where the LAST axis is the sample numer.

  • resolution (int>1) – Upsampling factor for binned peal locations

  • r (integer) – Radius over which point must be local maximum to include. Defaults to 1.

  • height_threshold (float) – Threshold (in height) for peak inclusion. Defaults to the 25th percentil of z

neurotools.spatial.peaks.brute_force_local_2d_maxima(x, R=5)[source]

Find points higher than all neighbors within radius r in a 2D array.

Parameters:
  • x (2D np.array;)

  • maxima. (Signal in which to locate local)

  • R (int;) – RxR region in which a peak must be a local maxima to be included.

Returns:

(x,y)

Return type:

tuple of np.int32 arrays with peak coordinates.