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
ofrealnumbers First input spectrum.
- spec_21D array_like
ofrealnumbers 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.nanis returned for invalid inputs. If True, an error is raised for undefined spectral angle. Default is False.
- spec_11D array_like
- Returns:
floatSpectral angle in radians.
- Return type:
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 ... )