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:

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

  • calculate fractions of three or four known components by using higher harmonic information (not implemented)

  • calculate fractions of two or three known components by resolving graphically with histogram:

  • blindly resolve fractions of n components by using harmonic information (not implemented)

phasorpy.components.graphical_component_analysis(real, imag, components_real, components_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.

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

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

  • radius (float, optional, default: 0.05) – Radius of the cursor in phasor coordinates.

  • 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 the components, ordered 0-1 (2 components) or 0-1, 0-2, 1-2 (3 components).

Return type:

tuple of ndarray

Raises:

ValueError – The array shapes of real and imag, or components_real and components_imag do not match. The number of components is not 2 or 3. Fraction values are not in 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:

>>> graphical_component_analysis(
...     [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]),)

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

>>> graphical_component_analysis(
...     [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]),
 array([0, 1, 0, 0, 0, 0]),
 array([0, 1, 2, 0, 0, 0]))
phasorpy.components.two_fractions_from_phasor(real, imag, components_real, components_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.

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

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

Returns:

fraction – Fractions of first component.

Return type:

ndarray

Raises:

ValueError – If the real and/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

>>> two_fractions_from_phasor(
...     [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])