[GRASS-dev] i.spec.unmix: getting end-members with pysptools

Yann Chemin ychemin at gmail.com
Wed Jan 28 07:07:18 PST 2015


Hi, for info, got an end-member extraction with pysptools

First you need to get a single ENVI formatted file having all spectral
bands in it.
r.out.gdal --o input=M3_mid output=A12_mid format=ENVI type=Float32

Then run the following script in Python adapted from the pysptools tutorials
(deps: python-sklearn, python-cvxopt)

--------------
import os
import os.path as osp
import numpy as np

import pysptools.util as util
import pysptools.eea as eea

def get_endmembers(data, header, q, path):
        print 'Endmembers extraction with NFINDR'
        ee = eea.NFINDR()
        U = ee.extract(data, q, maxit=5, normalize=True, ATGP_init=True)
        ee.plot(path, header)
        return U

data_path = '/home/yann/M3/A12'
sample = 'A12.hdr'
data_file = osp.join(data_path, sample)
data, header = util.load_ENVI_file(data_file)
# Maybe needed: Flipping to restore orientation
data = np.fliplr(data)
U = get_endmembers(data, header, 4, result_path)
------------------


Only issue so far is that the .hdr file should have information about the
wavelength value for each band (here example has 83 bands of Reflectance):

wavelength units = Nanometers (also accepts Micrometers)
z plot titles = {Wavelengths, Reflectance}
band names = {
Band 1, Band 2, Band 3,
Band 4, Band 5, Band 6, Band 7, Band 8, Band 9, Band 10, Band 11,
Band 12, Band 13, Band 14, Band 15, Band 16, Band 17, Band 18, Band 19,
Band 20, Band 21, Band 22, Band 23, Band 24, Band 25, Band 26, Band 27,
Band 28, Band 29, Band 30, Band 31, Band 32, Band 33, Band 34, Band 35,
Band 36, Band 37, Band 38, Band 39, Band 40, Band 41, Band 42, Band 43,
Band 44, Band 45, Band 46, Band 47, Band 48, Band 49, Band 50, Band 51,
Band 52, Band 53, Band 54, Band 55, Band 56, Band 57, Band 58, Band 59,
Band 60, Band 61, Band 62, Band 63, Band 64, Band 65, Band 66, Band 67,
Band 68, Band 69, Band 70, Band 71, Band 72, Band 73, Band 74, Band 75,
Band 76, Band 77, Band 78, Band 79, Band 80, Band 81, Band 82, Band 83}
wavelength = {
 540.84, 580.76, 620.69, 660.61, 700.54, 730.48, 750.44, 770.4, 790.37,
 810.33, 830.29, 850.25, 870.21, 890.17, 910.14, 930.1, 950.06, 970.02,
 989.98, 1009.95, 1029.91, 1049.87, 1069.83, 1089.79, 1109.76, 1129.72,
 1149.68, 1169.64, 1189.60, 1209.57, 1229.53, 1249.49, 1269.45, 1289.41,
 1309.38, 1329.34, 1349.30, 1369.26, 1389.22, 1409.19, 1429.15, 1449.11,
 1469.07, 1489.03, 1508.99, 1528.96, 1548.92, 1578.86, 1618.79, 1658.71,
 1698.63, 1738.56, 1778.48, 1818.40, 1858.33, 1898.25, 1938.18, 1978.10,
 2018.02, 2057.95, 2097.87, 2137.80, 2177.72, 2217.64, 2257.57, 2297.49,
 2337.42, 2377.34, 2417.26, 2457.19, 2497.11, 2537.03, 2576.96, 2616.88,
 2656.81, 2696.73, 2736.65, 2776.58, 2816.50, 2856.43, 2896.35, 2936.27,
 2976.20}

-- 
----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20150128/01e981d9/attachment.html>


More information about the grass-dev mailing list