spectralpython/spectral

Handling of bad bands

pythonic2020 opened this issue · 7 comments

I see that SPy 0.19 implemented plotting support for bad bands lists. Are there some examples of how to implement this? I'd like to not only plot spectra from a cube with bad bands omitted, but also perform spectral analyses on only good bands. I could use numpy to extract only good bands to a new array, but is there an easier way?

Thank you in advance.

The band band list is indicated as "bbl" in the ENVI header. It is an array with as many elements as there are bands in the image. Typically a value of 0 is used for bad bands and 1 for good bands. One might use it to indicate atmospheric absorption bands but it's really up to you. Calling it a "bad band list" is really a bit of a misnomer.

For example, if you had 4 bands in an image and the third band is "bad", you would put this in the header file:

bbl = {1, 1, 0, 1}

Currently, the only way the bbl is used in SPy is by not plotting bands where the bbl equals zero in spectral plots.

If you want to read only the good bands from a file, you could do it like this:

inds = np.argwhere(np.equal(img.metadata['bbl'], 1)).squeeze()
data = img.read_bands(inds)

Got it. I'll set the band bands in ENVI before importing to SPy. Many thanks! :-)

Beautiful! Great job.

Figure_2

Are bad bands automatically ignored for all spectral processing routines in SPy?

No. As I mentioned above, the spectral plots are the only place where the bbl is currently used. To ignore bad bands in algorithms, you would need to filter them out first.

Got it. Thanks for the " .metadata['bbl']" idea. I had been searching for some method like that. It works perfectly for wavelength, fwhm, etc. in envi header. Thanks again!

Yes, all of the ENVI header parameters are in the "metadata" attribute of the image. But a few are easily accessed elsewhere. For example, the wavelengths are in the "bands.centers" attribute and the fwhm is in the "bands.bandwidths" attribute.

Wow. Just what I needed. Perfect! Many thanks!