# Convex hull and features extraction¶

This is a quick overview of the convex hull removal and features extraction functions. They are part of the spectro module.

The overall goal is to extract the spectrum features. To identify a spectral feature by its wavelength position and shape, it must be isolated from effects like level changes and slopes. The first step is to normalize the spectrum by applying it a continuum removal algorithm. There is two ways of doing it: by division in reflectance, transmittance, and emittance spectra or by subtraction with absorbance or absorption coefficient spectra. The former is what is implemented by the pysptools library (see SpectrumConvexHullQuotient class).

The script listed below open the USGS 2006 library and read four spectra. They are:

    * Biotite WS660
    * Chalcedony CU91-6A
    * Kaolinite CM7
    * Gibbsite HS423.3B

Next, the script compute the convex hull removal algorithm on these spectra.

When the convex hull is removed, the absorption features can be isolated and identified. In fact, a call to the init class method FeaturesConvexHullQuotient() do all the job in one call. The figures shows, for each spectrum, the features extracted. The number of features extracted can be controled by ajusting the baseline parameter. This parameter may be different spectrum by spectrum. The class FeaturesConvexHullQuotient have a method to output the features statistics.

In [1]:

    %matplotlib inline
    import os
    import pysptools.spectro as spectro

    class SpecLib(object):

        def __init__(self, lib_name):
            rd = spectro.EnviReader(lib_name)
            self.lib = spectro.USGS06SpecLib(rd)

        def get(self, substance, sample):
            for spectrum, sample_id, descrip, idx in self.lib.get_substance(substance, sample):
                return spectrum

        def get_wvl(self):
            return self.lib.get_wvl()

    def display_convex_hull(lib, substance, sample):
        spectrum = lib.get(substance, sample)
        wvl = lib.get_wvl()

        schq = spectro.SpectrumConvexHullQuotient(spectrum, wvl)
        display_name = '{0}_{1}'.format(substance, sample)
        schq.display(display_name)

    def extract_and_display_features(lib, baseline, substance, sample):
        """
        Process the s06av95a_envi file and extract the <substance> and/or <sample>
        features according to the <baseline> value.
        """
        spectrum = lib.get(substance, sample)
        wvl = lib.get_wvl()
        fea = spectro.FeaturesConvexHullQuotient(spectrum, wvl, baseline=baseline)
        display_name = '{0}_{1}'.format(substance, sample)
        fea.display(display_name, feature='all')

    substances = [('Biotite', 'WS660'),
                ('Chalcedony', 'CU91-6A'),
                ('Kaolinite', 'CM7'),
                ('Gibbsite', 'HS423.3B')]

    data_path = '../usgs'

    hdr_name = 's06av95a_envi.hdr'
    lib_path = os.path.join(data_path, hdr_name)

    lib = SpecLib(lib_path)
    base = 0.93
    for substance,sample in substances:
        print 'Convex hull and features for {0} {1}'.format(substance,sample)
        display_convex_hull(lib, substance, sample)
        extract_and_display_features(lib, base, substance, sample)

    Convex hull and features for Biotite WS660

    Convex hull and features for Chalcedony CU91-6A

    Convex hull and features for Kaolinite CM7

    Convex hull and features for Gibbsite HS423.3B

    <matplotlib.figure.Figure at 0xab9d438>