neurotools.spatial.points module

Collected functions from 2018–2023 concerning analyses of 2D data.

Most of these routines work on 2D (x,y) points encoded as complex z=x+iy numbers.

neurotools.spatial.points.p2c(p)[source]

Convert a point in terms of a length-2 iterable into a complex number

neurotools.spatial.points.c2p(z)[source]

Convert complex-valued np.array with (shape) into a 2×(shape) np.float32 array.

Parameters:

z (np.complex64 or np.complex128)

neurotools.spatial.points.to_xypoint(z)[source]

Convert possible complex (x,y) point intoformation into float32 (x,y) points.

Parameters:

z (np.complex64) – Array of (x,y) points encoded as x+iy complex64

Returns:

(x,y) poiny array with shape 2 × z.shape

Return type:

np.float32

neurotools.spatial.points.closest(point, otherpoints, radius=inf)[source]

Find nearest (x,y) point witin a collection of other points, with maximum distance radius

Parameters:
  • point (np.float32 with shape 2) – (x,y) point to match

  • otherpoints (np.float32 with shape 2×NPOINTS) – List of (x,y) points to compare

  • radius (float) – Maximum allowed distance

Returns:

  • imatch (int) – index into otherpoints of the match, or None if there is no match within radius

  • xymatch (np.float32 with shape 2) – (x,y) coordinates of closestmatch

  • distance (float) – distance to match, or NaN if no match

neurotools.spatial.points.pair_neighbors(z1, z2, radius=inf)[source]
Parameters:
  • z1 (1D np.complex64) – List of x+iy points

  • z2 (1D np.complex64) – List of x+iy points

  • radius (float, default inf) – Maximum connection distance

Returns:

  • edges (NPOINTS × 2 np.int32) – Indecies (i,j) into point lists (z1,z2) of pairs

  • points (NPOINTS × 2 np.complex64) – x+iy points from (z1,x2) pairs

  • delta (NPOINTS np.float32:) – List of distances for each pair

neurotools.spatial.points.paired_distances(z1, z2)[source]

Calculate pairwise distances between two sets of (x,y) points encoded as x+iy complex numbers

Parameters:
  • z1 (1D np.complex64) – List of x+iy points

  • z2 (1D np.complex64)

Returns:

distance – Array of paired distances

Return type:

np.float32 with shape z1.shape+z2.shape

neurotools.spatial.points.assign_to_regions(regions, points)[source]

Assign 2D points to Voronoi regions, returning the indecies into regions for each point in points

Parameters:
  • regions (2 × NREGIONS np.float32) – (x,y) coordinates of Vornoi region centers

  • points (2 × NPOINTS np.float32) – (x,y) points to assign to regions

Returns:

indecies – Index into regions for each point

Return type:

NPOINTS np.int32

neurotools.spatial.points.collect_in_regions(regions, points, return_indecies=False)[source]

Bin points to Voronoi regions, returning a list of (x,y) points in each region.

Parameters:
  • regions (2×NREGIONS np.float32) – (x,y) coordinates of Vornoi region centers

  • points (2×NPOINTS np.float32) – (x,y) points to assign to regions

  • return_indecies (boolean; default False) – Whether to additionally return the index into the NPOINTS assigned to each region

Returns:

  • allocated (list) – Length NREGIONS list of 2 × NPOINTSINREGION np.float32 arrays

  • indecies (list) – Returned only if `return_indecies=True`; Length NREGIONS list of NPOINTSINREGION np.int32 arrays, each containing the indecies into the length-NPOINTS array assigned to each region in `regions.

neurotools.spatial.points.gaussian_from_points(points)[source]

Get the mean and (sample) covariance of a point cloud.

Note: we suppress warnings here because returning NaNs for an empty point set is entirely reasonable, and simplifies code elsewhere.

Parameters:

points (NDIM × NPOINTS np.float32) – Point data.

Returns:

  • μ (NDIM np.float32) – Mean

  • Σ (NDIM × NDIM np.float32) – Sample covariance

neurotools.spatial.points.collect_gaussians(regions, s)[source]

Return the mean and covariance of points within each Voronoi region.

Returns:

  • means (np.float32)

  • sigmas (np.float32)