What is the best way, in the Spectral Python Module, to apply the spectral algorithms to spectra - that is to calculate principal components, spectral angles etc for spectra read from an ASTER or ENVI Spectral library? All module algorithms seem tailored to the image class.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Most algorithms will accept a numpy array with shape (R, C, B) as an argument, where R, C, and B are the number of rows, columns, and bands, respectively. If you create an ENVI spectral library, the spectra member contains the library spectra and has shape (N, B), where N and B are the number of spectra and bands. So you just need to reshape the array to have 3 dimensions to use it in a function that accepts a 3-dimensional array. For example:
The np.newaxis argument just adds a dummy index so that the array passed to the principal_components function will have shape (1, N, B). You can also use None where I used np.newaxis and the effect is the same (but I think np.newaxis makes it more clear).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What is the best way, in the Spectral Python Module, to apply the spectral algorithms to spectra - that is to calculate principal components, spectral angles etc for spectra read from an ASTER or ENVI Spectral library? All module algorithms seem tailored to the image class.
Most algorithms will accept a numpy array with shape (R, C, B) as an argument, where R, C, and B are the number of rows, columns, and bands, respectively. If you create an ENVI spectral library, the
spectra
member contains the library spectra and has shape (N, B), where N and B are the number of spectra and bands. So you just need to reshape the array to have 3 dimensions to use it in a function that accepts a 3-dimensional array. For example:The
np.newaxis
argument just adds a dummy index so that the array passed to theprincipal_components
function will have shape (1, N, B). You can also useNone
where I usednp.newaxis
and the effect is the same (but I thinknp.newaxis
makes it more clear).