phasorpy.components#

Component analysis of phasor coordinates.

The phasorpy.components module provides functions to:

  • calculate fractions of two known components by projecting onto the line between the components (phasor_component_fraction())

  • calculate phasor coordinates of second component if only one is known (not implemented)

  • calculate fractions of multiple known components by using higher harmonic information (phasor_component_fit())

  • calculate fractions of two or three known components by resolving graphically with histogram (phasor_component_graphical())

  • blindly resolve fractions of multiple components by using harmonic information (phasor_component_blind(), not implemented)

  • calculate phasor coordinates from fractional intensities of components (phasor_from_component())

phasorpy.components.phasor_component_fit(mean, real, imag, component_real, component_imag, /, **kwargs)[source]#

Return fractions of multiple components from phasor coordinates.

Component fractions are obtained from the least-squares solution of a linear matrix equation that relates phasor coordinates from one or multiple harmonics to component fractions according to [2].

Up to 2 * number harmonics + 1 components can be fit to multi-harmonic phasor coordinates, that is up to three components for single harmonic phasor coordinates.

Parameters:
  • mean (array_like) – Intensity of phasor coordinates.

  • real (array_like) – Real component of phasor coordinates. Harmonics, if any, must be in the first dimension.

  • imag (array_like) – Imaginary component of phasor coordinates. Harmonics, if any, must be in the first dimension.

  • component_real (array_like) – Real coordinates of components. Must be one or two-dimensional with harmonics in the first dimension.

  • component_imag (array_like) – Imaginary coordinates of components. Must be one or two-dimensional with harmonics in the first dimension.

  • **kwargs (optional) – Additional arguments passed to scipy.linalg.lstsq().

Returns:

fractions – Component fractions. Fractions may not exactly add up to 1.0.

Return type:

ndarray

Raises:

ValueError – The array shapes of real and imag do not match. The array shapes of component_real and component_imag do not match. The number of harmonics in the components does not match the ones in the phasor coordinates. The system is underdetermined; the component matrix having more columns than rows.

Notes

For now, calculation of fractions of components from different channels or frequencies is not supported. Only one set of components can be analyzed and is broadcast to all channels/frequencies.

The method builds a linear matrix equation, \(A\mathbf{x} = \mathbf{b}\), where \(A\) consists of the phasor coordinates of individual components, \(\mathbf{x}\) are the unknown fractions, and \(\mathbf{b}\) represents the measured phasor coordinates in the mixture. The least-squares solution of this linear matrix equation yields the fractions.

References

Example

>>> phasor_component_fit(
...     [1, 1, 1], [0.6, 0.5, 0.4], [0.4, 0.3, 0.2], [0.2, 0.9], [0.4, 0.3]
... )
array([[0.4644, 0.5356, 0.6068],
       [0.5559, 0.4441, 0.3322]])
phasorpy.components.phasor_component_fraction(real, imag, component_real, component_imag, /)[source]#

Return fraction of first of two components from phasor coordinates.

Return the relative distance (normalized by the distance between the two components) to the second component for each phasor coordinate projected onto the line between two components.

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

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

  • component_real (array_like, shape (2,)) – Real coordinates of first and second components.

  • component_imag (array_like, shape (2,)) – Imaginary coordinates of first and second components.

Returns:

fraction – Fractions of first component.

Return type:

ndarray

Raises:

ValueError – If the real or imaginary coordinates of the known components are not of size 2.

Notes

The fraction of the second component is 1.0 - fraction.

For now, calculation of fraction of components from different channels or frequencies is not supported. Only one pair of components can be analyzed and will be broadcast to all channels/frequencies.

Examples

>>> phasor_component_fraction(
...     [0.6, 0.5, 0.4], [0.4, 0.3, 0.2], [0.2, 0.9], [0.4, 0.3]
... )
array([0.44, 0.56, 0.68])
phasorpy.components.phasor_component_graphical(real, imag, component_real, component_imag, /, *, radius=0.05, fractions=None)[source]#

Return fractions of two or three components from phasor coordinates.

The graphical method is based on moving circular cursors along the line between pairs of components and quantifying the phasors for each fraction.

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

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

  • component_real (array_like, shape (2,) or (3,)) – Real coordinates for two or three components.

  • component_imag (array_like, shape (2,) or (3,)) – Imaginary coordinates for two or three components.

  • radius (float, optional, default: 0.05) – Radius of cursor.

  • fractions (array_like or int, optional) – Number of equidistant fractions, or 1D array of fraction values. Fraction values must be in range [0.0, 1.0]. If an integer, numpy.linspace(0.0, 1.0, fractions) fraction values are used. If None (default), the number of fractions is determined from the longest distance between any pair of components and the radius of the cursor (see Notes below).

Returns:

counts – Counts along each line segment connecting components. Ordered 0-1 (2 components) or 0-1, 0-2, 1-2 (3 components). Shaped (number fractions,) (2 components) or (3, number fractions) (3 components).

Return type:

ndarray

Raises:

ValueError – The array shapes of real and imag, or component_real and component_imag do not match. The number of components is not 2 or 3. Fraction values are out of range [0.0, 1.0].

Notes

For now, calculation of fraction of components from different channels or frequencies is not supported. Only one set of components can be analyzed and will be broadcast to all channels/frequencies.

The graphical method was first introduced in [1].

If no fractions are provided, the number of fractions (\(N\)) used is determined from the longest distance between any pair of components (\(D\)) and the radius of the cursor (\(R\)):

\[N = \frac{2 \cdot D}{R} + 1\]

The fractions can be retrieved by:

fractions = numpy.linspace(0.0, 1.0, len(counts[0]))

References

Examples

Count the number of phasors between two components:

>>> phasor_component_graphical(
...     [0.6, 0.3], [0.35, 0.38], [0.2, 0.9], [0.4, 0.3], fractions=6
... )
array([0, 0, 1, 0, 1, 0], dtype=uint8)

Count the number of phasors between the combinations of three components:

>>> phasor_component_graphical(
...     [0.4, 0.5],
...     [0.2, 0.3],
...     [0.0, 0.2, 0.9],
...     [0.0, 0.4, 0.3],
...     fractions=6,
... )
array([[0, 1, 1, 1, 1, 0],
       [0, 1, 0, 0, 0, 0],
       [0, 1, 2, 0, 0, 0]], dtype=uint8)
phasorpy.components.phasor_from_component(component_real, component_imag, fraction, /, axis=0, dtype=None)[source]#

Return phasor coordinates from fractional intensities of components.

Return the dot products of the fractional intensities of components with the real and imaginary phasor coordinates of the components.

Multi-dimensional component arrays are currently not supported.

Parameters:
  • component_real (array_like, shape (n,)) – Real coordinates of components. At least two components are required.

  • component_imag (array_like, shape (n,)) – Imaginary coordinates of components.

  • fraction (array_like) – Fractional intensities of components. Fractions are normalized to sum to one along axis.

  • axis (int, optional, default: 0) – Axis of components in fraction.

  • dtype (dtype_like, optional) – Floating point data type used for calculation and output values. Either float32 or float64. The default is float64.

Returns:

  • real (ndarray) – Real component of phasor coordinates.

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

Examples

Calculate phasor coordinates from two components and their fractional intensities:

>>> phasor_from_component(
...     [0.6, 0.4], [0.3, 0.2], [[1.0, 0.2, 0.9], [0.0, 0.8, 0.1]]
... )
(array([0.6, 0.44, 0.58]), array([0.3, 0.22, 0.29]))