Return concentrations of two components from phasor coordinates.
Calculate the absolute concentration of the first component and,
optionally, the second component of a two-component system from
phasor coordinates, using an intensity calibration based on a solution
of known concentration according to [4].
The algorithm uses geometric line-line intersections in phasor space
to determine fractional contributions and scale them to absolute
concentrations.
Parameters:
mean (array_like) – Mean intensity of phasor coordinates.
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 the two components.
The first component is the calibrated component, whose pure solution
is used as the reference;
component_imag (array_like, shape (2,)) – Imaginary coordinates of the two components.
reference_mean (float) – Mean fluorescence intensity of calibration solution.
The calibration solution must contain only the first component at a
known concentration.
reference_real (float) – Real coordinate of calibration solution phasor.
reference_imag (float) – Imaginary coordinate of calibration solution phasor.
reference_concentration (float) – Known concentration of calibration solution.
Same units as the returned concentrations.
brightness_ratio (float, optional) – Ratio of molecular brightness of second to first component.
If provided, the second-component concentration is also returned.
Returns:
conc_first (ndarray) – Absolute concentration of first component.
conc_second (ndarray) – Absolute concentration of second component.
Only returned when brightness_ratio is provided.
Raises:
ValueError – If component_real values are equal (degenerate component line).
If component_real or component_imag do not have shape (2,).
If reference_mean is zero (cannot normalize).
If reference_concentration is not positive.
If brightness_ratio is not positive.
The algorithm is based on the concandfrac procedure from SimFCS and
the method described in [4].
The implementation has been validated against the published cellular NADH
concentration, but no independent theoretical or cross-instrument
validation has been performed.
Users applying the method to other analytes or instrument platforms
are encouraged to verify results against known standards.
The calibration solution must contain only component 0 (no component 1)
at a precisely known concentration (reference_concentration).
It must be acquired under identical instrument settings as the sample
(same laser power, detector gain, acquisition time, and objective),
because the algorithm relates pixel mean intensities directly to the
calibration mean intensity. The mean intensity of the calibration solution
should be comparable to the typical pixel mean intensities of the sample.
The calibration factor \(k\) relates the component-0 phasor
position to an absolute concentration:
where \(g_0\) is the real coordinate of the component-0 phasor,
\(g_\text{cal}\) is the intersection of the line from \(g_0\)
through the origin with the line connecting the component-1 phasor
scaled by \(m=0.5\) and the calibration phasor scaled by
\(m=0.5\), and \(c_\text{ref}\) is the reference concentration.
For each pixel, a normalized intensity is computed:
\[m = \frac{I}{I_\text{ref} + I}\]
where \(I\) is the pixel mean intensity and
\(I_\text{ref} = 2 \cdot \text{reference_mean}\) is twice the
fluorescence-only mean intensity of the calibration solution.
where \(g_\text{pix}\) is the real coordinate of the intersection of
the line from \(g_0\) through the origin with the line from the
intensity-scaled component-1 phasor \(g_1 \cdot m\) through
the measured phasor.
Note: The absolute value in the \(c_0\) formula is required for phasor
geometries where \(g_\text{pix}\) falls outside the interval
\([0, g_0]\) (as is typical for NADH), but has not been validated
for other analytes or geometries.
When brightness_ratio \(\varepsilon = \varepsilon_1 / \varepsilon_0\)
is provided, the component-0 fraction \(f_0\) at each pixel is
determined by the intersection \(g_\text{frac}\) of the line from
the origin through the measured phasor with the component line:
\[f_0 = \frac{g_1 - g_\text{frac}}
{g_1 - g_0}\]
The component-1 concentration and total concentration are then:
Verify the calibration self-consistency:
when mean=2*reference_mean (intensity modulation m=0.5)
and the pixel phasor equals the reference phasor scaled by 0.5, the
result equals reference_concentration:
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*numberharmonics+1 components can be fitted 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 arguments passed to scipy.linalg.lstsq().
Returns:
fractions – Component fractions.
Fractions may not exactly add up to 1.0.
Return type:
ndarray
Raises:
ValueError – If the array shapes of real and imag do not match.
If the array shapes of component_real and component_imag do not
match.
If the number of harmonics in the components does not match the
ones in the phasor coordinates.
If the system is underdetermined; the component matrix having more
columns than rows.
Calculation of fractions of components from different channels
or frequencies is not supported yet. 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.
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.
If the two components have identical coordinates.
If the component coordinates contain NaN or infinite values.
The fraction of the second component is 1.0-fraction.
Calculation of fractions of components from different channels
or frequencies is not supported yet. Only one pair of components
can be analyzed and is broadcast to all channels/frequencies.
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 the range [0.0, 1.0].
If an integer, numpy.linspace(0.0,1.0,fractions) fraction values
are used.
By 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 (numberfractions,) (2 components) or
(3,numberfractions) (3 components).
Return type:
ndarray
Raises:
ValueError – If the array shapes of real and imag, or component_real and
component_imag do not match.
If the number of components is not 2 or 3.
If the radius is not positive.
If the component coordinates contain NaN or infinite values.
If fractions values are out of range [0, 1].
Calculation of fractions of components from different channels
or frequencies is not supported yet. Only one set of components
can be analyzed and is broadcast to all channels/frequencies.
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:
Return mean value coordinates of phasor coordinates from components.
The mean value coordinates of phasor coordinates with respect to three or
more components spanning an arbitrary simple polygon are computed using
the stable method described in [3].
For three components, mean value coordinates are equivalent to
barycentric coordinates.
Parameters:
real (array_like) – Real component of phasor coordinates.
imag (array_like) – Imaginary component of phasor coordinates.
component_real (array_like) – Real coordinates of at least three components.
component_imag (array_like) – Imaginary coordinates of at least three components.
dtype (dtype_like, optional) – Floating point data type used for calculation and output values.
Either float32 or float64. The default is float64.
num_threads (int, optional) – Number of OpenMP threads to use for parallelization.
By default, multithreading is disabled.
If zero, up to half of logical CPUs are used.
OpenMP may not be available on all platforms.
Returns:
fractions – Mean value coordinates for each phasor coordinate.
Return type:
ndarray
Raises:
ValueError – If the array shapes of real and imag do not match.
If the array shapes of component_real and component_imag do not
match.
Notes
Calculation of fractions of components from different channels
or frequencies is not supported yet. Only one set of components
can be analyzed and is broadcast to all channels/frequencies.
For three components, this function returns the same result as
phasor_component_fit(). For more than three components,
the system is underdetermined and the mean value coordinates represent
one of multiple solutions. However, the special properties of the mean
value coordinates make them particularly useful for interpolating and
visualizing multi-component data.
References
Examples
Calculate the barycentric coordinates of a phasor coordinate
in a triangle defined by three components:
Return phasor coordinates from fractional intensities of components.
Return the dot products of the fractional intensities with the real and
imaginary phasor coordinates of the components.
Multidimensional component arrays are not supported yet.
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 1 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.
Raises:
ValueError – If dtype is not a floating-point type.
If the array shapes of component_real and component_imag do not
match.
If the fraction array has less than two components along axis.
If the component coordinates contain NaN or infinite values.