phasorpy.cursor#

Select regions of interest (cursors) from phasor coordinates.

The phasorpy.cursor module provides functions to:

phasorpy.cursor.mask_from_circular_cursor(real, imag, center_real, center_imag, /, *, radius=0.05)[source]#

Return masks for circular cursors of phasor coordinates.

Parameters:
  • real (array_like) – Real component of phasor coordinates.

  • imag (array_like) – Imaginary component of phasor coordinates.

  • center_real (array_like, shape (n,)) – Real coordinates of circle centers.

  • center_imag (array_like, shape (n,)) – Imaginary coordinates of circle centers.

  • radius (array_like, optional, shape (n,)) – Radii of circles.

Returns:

masks – Boolean array of shape (n, *real.shape). The first dimension is omitted if center_* and radius are scalars. Values are True if phasor coordinates are inside circular cursor, else False.

Return type:

ndarray

Raises:

ValueError – The array shapes of real and imag do not match. The array shapes of center_real, center_imag, or radius have more than one dimension.

See also

Cursors

Examples

Create mask for a single circular cursor:

>>> mask_from_circular_cursor([0.2, 0.5], [0.4, 0.5], 0.2, 0.4, radius=0.1)
array([ True, False])

Create masks for two circular cursors with different radius:

>>> mask_from_circular_cursor(
...     [0.2, 0.5], [0.4, 0.5], [0.2, 0.5], [0.4, 0.5], radius=[0.1, 0.05]
... )
array([[ True, False],
       [False,  True]])
phasorpy.cursor.mask_from_elliptic_cursor(real, imag, center_real, center_imag, /, *, radius=0.05, radius_minor=None, angle=None)[source]#

Return masks for elliptic cursors of phasor coordinates.

Parameters:
  • real (array_like) – Real component of phasor coordinates.

  • imag (array_like) – Imaginary component of phasor coordinates.

  • center_real (array_like, shape (n,)) – Real coordinates of ellipses centers.

  • center_imag (array_like, shape (n,)) – Imaginary coordinates of ellipses centers.

  • radius (array_like, optional, shape (n,)) – Radii of ellipses along semi-major axis.

  • radius_minor (array_like, optional, shape (n,)) – Radii of ellipses along semi-minor axis. By default, the ellipses are circular.

  • angle (array_like or {'phase', 'semicircle'}, optional) – Rotation angle of semi-major axis of elliptic cursors in radians. If None or ‘phase’, align the minor axes of the ellipses with the closest tangent on the unit circle. If ‘semicircle’, align the ellipses with the universal semicircle.

Returns:

masks – Boolean array of shape (n, *real.shape). The first dimension is omitted if center_real, center_imag, radius, radius_minor, and angle are scalars. Values are True if phasor coordinates are inside elliptic cursor, else False.

Return type:

ndarray

Raises:

ValueError – The array shapes of real and imag do not match. The array shapes of center_real, center_imag, radius, radius_minor, or angle have more than one dimension.

See also

Cursors

Examples

Create mask for a single elliptic cursor:

>>> mask_from_elliptic_cursor([0.2, 0.5], [0.4, 0.5], 0.2, 0.4, radius=0.1)
array([ True, False])

Create masks for two elliptic cursors with different radii:

>>> mask_from_elliptic_cursor(
...     [0.2, 0.5],
...     [0.4, 0.5],
...     [0.2, 0.5],
...     [0.4, 0.5],
...     radius=[0.1, 0.05],
...     radius_minor=[0.15, 0.1],
...     angle=[math.pi, math.pi / 2],
... )
array([[ True, False],
       [False,  True]])
phasorpy.cursor.mask_from_polar_cursor(real, imag, phase_min, phase_max, modulation_min, modulation_max, /)[source]#

Return mask for polar cursor of polar coordinates.

Parameters:
  • real (array_like) – Real component of phasor coordinates.

  • imag (array_like) – Imaginary component of phasor coordinates.

  • phase_min (array_like, shape (n,)) – Lower bound of angular range of cursors in radians. Values should be in range [-pi, pi].

  • phase_max (array_like, shape (n,)) – Upper bound of angular range of cursors in radians. Values should be in range [-pi, pi].

  • modulation_min (array_like, shape (n,)) – Lower bound of radial range of cursors.

  • modulation_max (array_like, shape (n,)) – Upper bound of radial range of cursors.

Returns:

masks – Boolean array of shape (n, *real.shape). The first dimension is omitted if phase_* and modulation_* are scalars. Values are True if phasor coordinates are inside polar range cursor, else False.

Return type:

ndarray

Raises:

ValueError – The array shapes of phase and modulation, or phase_range and modulation_range do not match. The array shapes of phase_* or modulation_* have more than one dimension.

See also

Cursors

Examples

Create mask from a single polar cursor:

>>> mask_from_polar_cursor([0.2, 0.5], [0.4, 0.5], 1.1, 1.2, 0.4, 0.5)
array([ True, False])

Create masks for two polar cursors with different ranges:

>>> mask_from_polar_cursor(
...     [0.2, 0.5],
...     [0.4, 0.5],
...     [1.1, 0.7],
...     [1.2, 0.8],
...     [0.4, 0.7],
...     [0.5, 0.8],
... )
array([[ True, False],
       [False,  True]])
phasorpy.cursor.pseudo_color(*masks, intensity=None, colors=None, vmin=0.0, vmax=None)[source]#

Return pseudo-colored image from cursor masks.

Parameters:
  • *masks (array_like) – Boolean mask for each cursor.

  • intensity (array_like, optional) – Intensity used as base layer to blend cursor colors in “overlay” mode. If None, cursor masks are blended using “screen” mode.

  • vmin (float, optional) – Minimum value to normalize intensity. If None, the minimum value of intensity is used.

  • vmax (float, optional) – Maximum value to normalize intensity. If None, the maximum value of intensity is used.

  • colors (array_like, optional, shape (N, 3)) – RGB colors assigned to each cursor. The last dimension contains the normalized RGB floating point values. The default is phasorpy.color.CATEGORICAL.

Returns:

Pseudo-colored image of shape (*masks[0].shape, 3).

Return type:

ndarray

Raises:

ValueErrorcolors is not a (n, 3) shaped floating point array. The shapes of masks or mean cannot broadcast.

See also

Cursors

Examples

Create pseudo-color image from single mask:

>>> pseudo_color([True, False, True])
array([[0.8254, 0.09524, 0.127],
       [0, 0, 0],
       [0.8254, 0.09524, 0.127]]...)

Create pseudo-color image from two masks and intensity image:

>>> pseudo_color(
...     [True, False], [False, True], intensity=[0.4, 0.6], vmax=1.0
... )
array([[0.6603, 0.07619, 0.1016],
       [0.2762, 0.5302, 1]]...)