swectral.spectral_angle#

swectral.spectral_angle(spec_1, spec_2, invalid_raise=False)[source]#

Compute the spectral angle between two one-dimensional spectra.

The spectral angle is defined as the angle (in radians) between two vectors in spectral space.

Parameters:
spec_11D array_like of real numbers

First input spectrum.

spec_21D array_like of real numbers

Second input spectrum.

invalid_raisebool, optional

Whether to raise an error when the spectral angle is undefined (e.g. when the values of one spectrum are all zeros).

If False, numpy.nan is returned for invalid inputs. If True, an error is raised for undefined spectral angle. Default is False.

Returns:
float

Spectral angle in radians.

Return type:

float

Examples

Basic usage:

>>> spectral_angle([1, 2, 3, 4], [2, 3, 4, 5])

Raise an error for invalid spectra:

>>> spectral_angle(
...     [1, 2, 3, 4],
...     [0, 0, 0, 0],
...     invalid_raise=True
... )