phasorpy.cursors#
Select regions of interest (cursors) from phasor coordinates.
The phasorpy.cursors
module provides functions to:
create masks for regions of interests in the phasor space:
create pseudo-color image from average signal and cursor masks:
- phasorpy.cursors.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_* or radius have more than one dimension.
See also
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.cursors.mask_from_elliptic_cursor(real, imag, center_real, center_imag, /, *, radius=0.05, radius_minor=None, angle=None, align_semicircle=False)[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, optional, shape (n,)) – Rotation angles of semi-major axes of ellipses in radians. By default, the ellipses are automatically oriented depending on align_semicircle.
align_semicircle (bool, optional) – Determines orientation of ellipses if angle is not provided. If true, align the minor axes of the ellipses with the closest tangent on the universal semicircle, else the unit circle (default).
- Returns:
masks – Boolean array of shape (n, *real.shape). The first dimension is omitted if center*, radius*, 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*, radius*, or angle have more than one dimension.
See also
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.cursors.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,)) – Minimum of angular range of cursors in radians. Values should be between -pi and pi.
phase_max (array_like, shape (n,)) – Maximum of angular range of cursors in radians. Values should be between -pi and pi.
modulation_min (array_like, shape (n,)) – Minimum of radial range of cursors.
modulation_max (array_like, shape (n,)) – Maximum 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
Example
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.cursors.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)) – 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:
ValueError – colors is not a (n, 3) shaped floating point array. The shapes of masks or mean cannot broadcast.
See also
Example
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]]...)