Spectro function and classes
This module supports the functions convex_hull_removal and the
classes SpectrumConvexHullQuotient, FeaturesConvexHullQuotient and USGS06SpecLib.
See the file test_hull.py
for a SpectrumConvexHullQuotient and FeaturesConvexHullQuotient example. The file test_spectro.py is the example for the USGS06SpecLib class.
Note
The ENVI file reader is not available for Python 3.3 and make the USGS library reader useless. To turn around the problem you can use a JSON version of the USGS library. Following is the explaination on how to do this.
To run the USGS06SpecLib class on Python 3.3 you need a JSON version of the library:
- Download the ENVI version of the library.
- Run the program USGS_ENVI_to_JSON.py on it. You can find the program in the util folder.
- And use the class spectro.JSONReader to load the JSON file, see test_hull.py for an example.
FeaturesConvexHullQuotient
-
class spectro.FeaturesConvexHullQuotient(spectrum, wvl, startContinuum=None, stopContinuum=None, baseline=0)
Remove the convex-hull of the signal by hull quotient.
Auto-extract the features and calculate their associated
statistics. A baseline can be applied to avoid non-significant features.
If you want to restrict the analysis to one continuum, just set the intervale
with the startContinuum and stopContinuum parameters. It is up to you
to ascertain that the continuum interval defined by startContinuum and
stopContinuum do not cross the spectrum. The bilateral function can be use
to remove small spectrum noises before extracting the features.
- Parameters:
- spectrum: list
- 1D HSI data (p), a spectrum.
- wvl: list
- Wavelength of each band (p x 1).
- startContinuum: float
- The wavelength value of the starting left continuum.
- stopContinuum: float
- The wavelength value of the ending right continuum.
- baseline: float
- Features extracted above the baseline are rejected,
features extracted below the baseline are kept.
- Reference:
- Kokaly F. Raymond, PRISM: Processing Routines in IDL for Spectroscopic
Measurements (Installation Manual and User’s Guide, Version 1.0),
U.S. Geological Survey,Reston, Virginia: 2011.
-
display(plot_name, feature='all')
Display the hull quotient graph of the feature
to the IPython Notebook using matplotlib.
- Parameters:
- plot_name: string
- Title name.
- suffix: string
- Add a suffix to the title.
-
display_convex_hull_quotient(plot_name, suffix=None)
Display the hull quotient graph to the IPython
Notebook using matplotlib.
- Parameters:
- plot_name: string
- Title name.
- suffix: string
- Add a suffix to the title.
-
get_absorbtion_depth(feat_no)
- Returns: float
- The absorbtion value at the feature minimum.
-
get_absorbtion_wavelength(feat_no)
- Returns: float
- The wavelength at the feature minimum.
-
get_area(feat_no)
- Returns: float
- The feature area.
-
get_continuum_removed_spectrum(feat_no)
- Returns: list
- Feature spectrum with convex hull removed (p).
-
get_continuum_slope(feat_no)
- Returns: float
- The feature continuum slope.
-
get_continuum_start_wavelength(feat_no)
- Returns: float
- The continuum left start wavelength value.
-
get_continuum_stop_wavelength(feat_no)
- Returns: float
- The continuum right end wavelength value.
-
get_full_width_at_half_maximum(feat_no)
- Returns: float
- Width at half maximum.
-
get_number_of_kept_features()
- Returns: int
- The number of features that are kept (below the baseline).
Only theses features have a statistic report.
-
plot(path, plot_name, feature='all')
Plot the hull quotient graph of the feature using matplotlib.
- Parameters:
- path: string
- The path where to put the plot.
- plot_name: string
- File name.
- suffix: string
- Add a suffix to the file name.
-
plot_convex_hull_quotient(path, plot_name, suffix=None)
Plot the hull quotient graph using matplotlib.
- Parameters:
- path: string
- The path where to put the plot.
- plot_name: string
- File name.
- suffix: string
- Add a suffix to the file name.
-
print_stats(feat_no)
Print a statistic summary for a kept feature.
- Parameters:
- feat_no: int or ‘all’
- The feature number, if feat_no=’all’, print
stats for all the kept features.
SpectrumConvexHullQuotient
-
class spectro.SpectrumConvexHullQuotient(spectrum, wvl, normalize=False)
Remove the convex-hull of the signal by hull quotient.
- Parameters:
- spectrum: list
- 1D HSI data (p), a spectrum.
- wvl: list
- Wavelength of each band (p x 1).
- Reference:
- Clark, R.N. and T.L. Roush (1984) Reflectance Spectroscopy: Quantitative
Analysis Techniques for Remote Sensing Applications, J. Geophys. Res., 89,
6329-6340.
-
display(plot_name, suffix=None)
Display the hull quotient graph to the IPython
Notebook using matplotlib.
- Parameters:
- plot_name: string
- File name.
- suffix: string
- Add a suffix to the title.
-
get_continuum_removed_spectrum()
- Returns: list
- Spectrum with convex hull removed (p).
-
get_hull_x()
- Returns: list
- Convex hull x values (p).
-
get_hull_y()
- Returns: list
- Convex hull y values (p).
-
plot(path, plot_name, suffix=None)
Plot the hull quotient graph using matplotlib.
- Parameters:
- path: string
- The path where to put the plot.
- plot_name: string
- File name.
- suffix: string
- Add a suffix to the file name.
convex_hull_removal
-
spectro.convex_hull_removal(pixel, wvl)
Remove the convex-hull of the signal by hull quotient.
- Parameters:
- pixel: list
- 1D HSI data (p), a pixel.
- wvl: list
- Wavelength of each band (p x 1).
- Results: list
- Data with convex hull removed (p).
- Reference:
- Clark, R.N. and T.L. Roush (1984) Reflectance Spectroscopy: Quantitative
Analysis Techniques for Remote Sensing Applications, J. Geophys. Res., 89,
6329-6340.
USGS06SpecLib
-
class spectro.EnviReader(fname)
Open a ENVI version of the USGS library and
return the data and the header.
- The ENVI version is made of two files:
- s06av95a_envi.hdr
- s06av95a_envi.sli
- You create the reader this way (on Windows):
- rd = EnviReader(r’c:\somepath\s06av95a_envi.hdr’)
- And pass it to the SpecLib class this way:
- lib = SpecLib(rd)
-
class spectro.JSONReader(fname)
Open a JSON version of the USGS library and
return the data and the header.
- The JSON version is made of two files:
- s06av95a_envi.jdata
- s06av95a_envi.jhead
- You create the reader this way (on Windows):
- rd = JSONReader(r’c:\somepath\s06av95a_envi’)
- And pass it to the SpecLib class this way:
- lib = SpecLib(rd)
-
class spectro.USGS06SpecLib(reader)
Load the library and add get and search functionnality.
- Parameters:
- reader: EnviReader or JSONReader instance
-
distance_match(s, distfn='SAM')
Scan the library and return the index of the spectrum that
have the smallest distance to ‘s’.
- Parameters:
- s: list
- A spectrum.
- distfn: function [default ‘SAM’]
- One of the function: SAM, SID, chebyshev, NormXCorr.
- Returns: tuple
- Spectrum, index.
-
get(idx)
Return the spectrum at index idx.
Indexing start at zero.
- Parameters:
- idx: int
- The index of the spectrum to fetch.
- Returns: list
- Spectrum (p).
-
get_next()
Iterator, scan the library and return at each step:
spectrum, mineral, sample_id, description and index.
- Return: tuple
- Spectrum, mineral, sample_id, description and index.
-
get_substance(substance, sample=None)
Iterator, scan the library, verify the conditions ‘substance’
and/or ‘sample’ and if true return:
spectrum, sample_id, description and index.
- Parameters:
- substance: string
- A substance name.
- sample: string [default None]
- A sample.
- Returns: tuple
- Spectrum, mineral, sample_id, description and index.