-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibraries.html
More file actions
345 lines (309 loc) · 29.6 KB
/
libraries.html
File metadata and controls
345 lines (309 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Spectral Libraries — Spectral Python 0.21 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Class/Function Glossary" href="class_func_glossary.html" />
<link rel="prev" title="Spectral Algorithms" href="algorithms.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="py-modindex.html" title="Python Module Index"
>modules</a></li>
<li class="right" >
<a href="class_func_glossary.html" title="Class/Function Glossary"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="algorithms.html" title="Spectral Algorithms"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Spectral Python 0.21 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="user_guide.html" accesskey="U">Spectral Python (SPy) User Guide</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="spectral-libraries">
<span id="libraries"></span><h1>Spectral Libraries<a class="headerlink" href="#spectral-libraries" title="Permalink to this headline">¶</a></h1>
<div class="toctree-wrapper compound">
</div>
<div class="section" id="ecostress-spectral-library">
<h2>ECOSTRESS Spectral Library<a class="headerlink" href="#ecostress-spectral-library" title="Permalink to this headline">¶</a></h2>
<p>The ECOSTRESS spectral library provides over 3,000 high-resolution spectra for
numerous classes of materials <a class="reference internal" href="#meerdink2019" id="id1"><span>[Meerdink2019]</span></a>. The spectra and associated metadata
are provided as a large set of ASCII text files. SPy provides the ability to
import the ECOSTRESS library spectra and a subset of the associated metadata into
a relational databased that can be easily accessed from Python.</p>
<p>You will first need to get a copy of the ECOSTRESS spectral library data files,
which can be requested <a class="reference external" href="http://speclib.jpl.nasa.gov">here</a>. Once you have
acquired the library data, you can import the data in to an <code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite</span></code>
database as follows:</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [1]: </span><span class="n">db</span> <span class="o">=</span> <span class="n">spy</span><span class="o">.</span><span class="n">EcostressDatabase</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="s1">'ecostress.db'</span><span class="p">,</span> <span class="s1">'./eco_data_ver1'</span><span class="p">)</span>
<span class="go">Importing ./eco_data_ver1/vegetation.tree.betula.lenta.tir.bele-1-55.ucsb.nicolet.spectrum.txt.</span>
<span class="go">Importing ./eco_data_ver1/vegetation.tree.quercus.lobata.tir.vh282.ucsb.nicolet.spectrum.txt.</span>
<span class="go">Importing ./eco_data_ver1/nonphotosyntheticvegetation.branches.adenostoma.fasciculatum.vswir.vh334.ucsb.asd.spectrum.txt.</span>
<span class="go">Importing ./eco_data_ver1/mineral.silicate.cyclosilicate.fine.tir.cs-2a.jpl.nicolet.spectrum.txt.</span>
<span class="go">Importing ./eco_data_ver1/mineral.hydroxide.none.fine.tir.goethite_1.jhu.nicolet.spectrum.txt.</span>
<span class="go">---// snip //---</span>
<span class="go">Importing ./eco_data_ver1/mineral.silicate.inosilicate.coarse.vswir.in-8a.jpl.perkin.spectrum.txt.</span>
<span class="go">Importing ./eco_data_ver1/vegetation.shrub.aloe.arborescens.tir.jpl077.jpl.nicolet.spectrum.txt.</span>
<span class="go">Importing ./eco_data_ver1/mineral.silicate.phyllosilicate.coarse.tir.ps-12f.jpl.nicolet.spectrum.txt.</span>
<span class="go">Processed 3403 files.</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The ECOSTRESS library supercedes the older ASTER spectral library
<a class="reference internal" href="#baldridge2009" id="id2"><span>[Baldridge2009]</span></a>. To import data from version 2.0 of the ASTER library,
follow the precedure above but with <a class="reference internal" href="class_func_ref.html#spectral.database.AsterDatabase" title="spectral.database.AsterDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsterDatabase</span></code></a> instead of
<a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a>.</p>
</div>
<p>Once the database has been created, it can be accessed by instantiating an
<a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a> object for the database file (it can also be
accessed by using sqlite external to Python). The current implementation of the
SPy database contains two tables: <cite>Samples</cite> and <cite>Spectra</cite>. There is a one-to-one
relationship between rows in the two tables but they have been separate to support
potential future changes to the database. The schemas for the tables are in the
<code class="xref py py-attr docutils literal notranslate"><span class="pre">schemas</span></code> attribute of the database object:</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [2]: </span><span class="n">db</span> <span class="o">=</span> <span class="n">EcostressDatabase</span><span class="p">(</span><span class="s1">'ecostress.db'</span><span class="p">)</span>
<span class="gp">In [3]: </span><span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">db</span><span class="o">.</span><span class="n">schemas</span><span class="p">:</span>
<span class="gp"> ...: </span> <span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="gp"> ...: </span>
<span class="go">CREATE TABLE Samples (SampleID INTEGER PRIMARY KEY, Name TEXT, Type TEXT, Class TEXT, SubClass TEXT, ParticleSize TEXT, SampleNum TEXT, Owner TEXT, Origin TEXT, Phase TEXT, Description TEXT)</span>
<span class="go">CREATE TABLE Spectra (SpectrumID INTEGER PRIMARY KEY, SampleID INTEGER, SensorCalibrationID INTEGER, Instrument TEXT, Environment TEXT, Measurement TEXT, XUnit TEXT, YUnit TEXT, MinWavelength FLOAT, MaxWavelength FLOAT, NumValues INTEGER, XData BLOB, YData BLOB)</span>
</pre></div>
</div>
<p>Descriptions of most of the <cite>Sample</cite> table columns can be found in the ECOSTRESS
Spectral Library documentation. The sample spectra and bands are stored in
<cite>BLOB</cite> objects in the database, so you probably don’t want to access them directly.
The recommended method is to use either the <code class="xref py py-meth docutils literal notranslate"><span class="pre">get_spectrum</span></code>
or <code class="xref py py-meth docutils literal notranslate"><span class="pre">get_signature</span></code> method of <a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a>,
both of which take a <cite>SpectrumID</cite> as their argument.</p>
<p>As a simple example, suppose you want to find all samples that have “stone” in
their name (this isn’t the best way to find stones in the library but it makes
for an easy example). There are three ways you can issue queries through the
<a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a> object. You can call its <code class="xref py py-meth docutils literal notranslate"><span class="pre">print_query</span></code>
method to print query results to the command line. You can call its
<code class="xref py py-meth docutils literal notranslate"><span class="pre">query</span></code> method to return query results in
tuples. Lastly, you can use the <code class="xref py py-attr docutils literal notranslate"><span class="pre">cursor</span></code> attribute of the <a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a>
object to issue the query.</p>
<pre class="literal-block">In [4]: db.print_query('SELECT COUNT() FROM Samples WHERE Name LIKE "%stone%"')
78
In [5]: db.print_query('SELECT SampleID, Name FROM Samples WHERE Name LIKE "%stone%" limit 10')
14|Limestone Breccia
73|Argillaceous Limestone
167|Arkosic Sandstone
171|Limestone CaCO3
203|Limestone CaCO3
237|Greywacke Sandstone
275|Gray/dark brown extremely stoney coarse sandy
279|Sandstone (Red)
280|Gray Sandstone
384|Dolomitic Limestone</pre>
<p>Next, let’s retrieve and plot one of the results (we will take the last one).</p>
<pre class="literal-block">In [6]: f = plt.figure()
In [7]: s = db.get_signature(384)
In [8]: import pylab as plt
In [9]: plt.plot(s.x, s.y)
Out[9]: [<matplotlib.lines.Line2D at 0x7f61aab7dcc0>]
In [10]: plt.title(s.sample_name)
Out[10]: Text(0.5, 1, 'Dolomitic Limestone')
In [11]: plt.grid(1)</pre>
<a class="reference internal image-reference" href="_images/limestone.png"><img alt="_images/limestone.png" class="align-center" src="_images/limestone.png" style="width: 512.0px; height: 384.0px;" /></a>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p>Module <code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></p>
<blockquote>
<div><p>The sqlite3 module is included with Python 2.5+. Details on sqlite3
<code class="xref py py-obj docutils literal notranslate"><span class="pre">connection</span></code> and <code class="xref py py-obj docutils literal notranslate"><span class="pre">cursor</span></code> objects can be found in the
<a class="reference external" href="http://docs.python.org/library/sqlite3.html">Python sqlite3 documentation</a>.</p>
</div></blockquote>
</div>
</div>
<div class="section" id="envi-spectral-libraries">
<h2>ENVI Spectral Libraries<a class="headerlink" href="#envi-spectral-libraries" title="Permalink to this headline">¶</a></h2>
<p>While the <a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a> provides a Python interface to the
ECOSTRESS Spectral Library, there may be times where you want to repeatedly access
a small, fixed subset of the spectra in the library and do not want to repeatedly
query the database. The ENVI file format enables storage of spectral libraries
(see <a class="reference internal" href="fileio.html#envi-format"><span class="std std-ref">ENVI Headers</span></a>). SPy can read these files into a SPy
<a class="reference internal" href="class_func_ref.html#spectral.io.envi.SpectralLibrary" title="spectral.io.envi.SpectralLibrary"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpectralLibrary</span></code></a> object.</p>
<p>To enable easy creation of custom spectral libraries, the <a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a>
has a <code class="xref py py-meth docutils literal notranslate"><span class="pre">create_envi_spectral_library</span></code> method that
generates a spectral library that can easily be saved to ENVI format. Spectra
in the ECOSTRESS library have varying numbers of samples over varying spectral
ranges. To generate the library we want to save to ENVI format, we need to specify
a band discretization to which we want all of the desired spectra resampled.
Let’s pick the bands from our sample hyperspectral image.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [12]: </span><span class="n">bands</span> <span class="o">=</span> <span class="n">aviris</span><span class="o">.</span><span class="n">read_aviris_bands</span><span class="p">(</span><span class="s1">'92AV3C.spc'</span><span class="p">)</span>
<span class="gp">In [13]: </span><span class="nb">print</span><span class="p">(</span><span class="n">bands</span><span class="o">.</span><span class="n">centers</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">bands</span><span class="o">.</span><span class="n">centers</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="go">400.019989 2498.959961</span>
</pre></div>
</div>
<p>We see from the output above that the bands range from about 400 - 2,500 <cite>nm</cite>
(we’re ignoring the fact that the bands at both ends have a finite width).
We would like to find library spectra that cover the entire spectral range for
our image, so we’ll check the band limits for the library spectra. But first,
let’s check the units of the spectra in the library.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [14]: </span><span class="n">db</span><span class="o">.</span><span class="n">print_query</span><span class="p">(</span><span class="s1">'SELECT DISTINCT Measurement, XUnit, YUnit FROM Samples, Spectra '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'WHERE Samples.SampleID = Spectra.SampleID AND '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'Name LIKE "</span><span class="si">%s</span><span class="s1">tone%"'</span><span class="p">)</span>
<span class="gp"> ....: </span>
<span class="go">Hemispherical reflectance|Wavelength (micrometers)|Reflectance (percent)</span>
<span class="go">Directional (10 Degree) Hemispherical Reflectance|Wavelength (micrometers)|Reflectance (percent)</span>
<span class="go">Reflectance|Wavelength (micrometers)|Reflectance (percent)</span>
<span class="go">Directional (10 degree) Hemispherical Reflectance|Wavelength (micrometers)|Reflectance (percent)</span>
<span class="go">Directional (10 degree) hemispherical reflectance|Wavelength (micrometers)|Reflectance (percent)</span>
<span class="go">Directional hemispherical reflectance|Wavelength (micrometers)|Reflectance (percent)</span>
</pre></div>
</div>
<p>We see that all spectra are measures of reflectance but wavelengths are in units
of micrometers, whereas our sample image bands are in nanometers. To properly
query the spectra, we will need to specify the band limits in micrometers.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [15]: </span><span class="n">db</span><span class="o">.</span><span class="n">print_query</span><span class="p">(</span><span class="s1">'SELECT COUNT() FROM Samples, Spectra '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'WHERE Samples.SampleID = Spectra.SampleID AND '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'Name LIKE "</span><span class="si">%s</span><span class="s1">tone%" AND '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'MinWavelength <= 0.4 AND MaxWavelength >= 2.5'</span><span class="p">)</span>
<span class="gp"> ....: </span>
<span class="go">59</span>
</pre></div>
</div>
<p>So it appears that 59 of the 78 “stone” spectra cover the desired band limits.
To create a new, resampled spectral library for these spectra, we call the
<a class="reference internal" href="class_func_ref.html#spectral.database.EcostressDatabase" title="spectral.database.EcostressDatabase"><code class="xref py py-class docutils literal notranslate"><span class="pre">EcostressDatabase</span></code></a> <code class="xref py py-meth docutils literal notranslate"><span class="pre">create_envi_spectral_library</span></code>
method, passing it the list of spectrum IDs and our output band schema (in micrometers).
Since our bands are defined in nanometers, we will convert them before calling
the method.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [16]: </span><span class="n">rows</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s1">'SELECT SpectrumID FROM Samples, Spectra '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'WHERE Samples.SampleID = Spectra.SampleID AND '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'Name LIKE "</span><span class="si">%s</span><span class="s1">tone%" AND '</span> <span class="o">+</span>
<span class="gp"> ....: </span> <span class="s1">'MinWavelength <= 0.4 AND MaxWavelength >= 2.5'</span><span class="p">)</span>
<span class="gp"> ....: </span>
<span class="gp">In [17]: </span><span class="n">ids</span> <span class="o">=</span> <span class="p">[</span><span class="n">r</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">rows</span><span class="p">]</span>
<span class="gp">In [18]: </span><span class="nb">print</span><span class="p">(</span><span class="n">ids</span><span class="p">)</span>
<span class="go">[14, 73, 167, 171, 203, 237, 275, 279, 384, 502, 532, 582, 601, 682, 744, 766, 788, 789, 1064, 1114, 1121, 1218, 1404, 1429, 1433, 1459, 1551, 1563, 1615, 1624, 1631, 1652, 1669, 1745, 1903, 1929, 2153, 2155, 2200, 2254, 2271, 2308, 2375, 2472, 2602, 2626, 2653, 2717, 2740, 2811, 2880, 3002, 3033, 3059, 3069, 3189, 3234, 3314, 3339]</span>
<span class="gp">In [19]: </span><span class="n">bands</span><span class="o">.</span><span class="n">centers</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="o">/</span> <span class="mf">1000.</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">bands</span><span class="o">.</span><span class="n">centers</span><span class="p">]</span>
<span class="gp">In [20]: </span><span class="n">bands</span><span class="o">.</span><span class="n">bandwidths</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="o">/</span> <span class="mf">1000.</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">bands</span><span class="o">.</span><span class="n">bandwidths</span><span class="p">]</span>
<span class="gp">In [21]: </span><span class="n">lib</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">create_envi_spectral_library</span><span class="p">(</span><span class="n">ids</span><span class="p">,</span> <span class="n">bands</span><span class="p">)</span>
</pre></div>
</div>
<p>Now that we’ve created a resampled library of spectra, let’s plot the last
spectrum in the resampled library.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [22]: </span><span class="n">f</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="gp">In [23]: </span><span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get_signature</span><span class="p">(</span><span class="n">ids</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="gp">In [24]: </span><span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="s1">'k-'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'original'</span><span class="p">);</span>
<span class="gp">In [25]: </span><span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">bands</span><span class="o">.</span><span class="n">centers</span><span class="p">,</span> <span class="n">lib</span><span class="o">.</span><span class="n">spectra</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="s1">'r-'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'resampled'</span><span class="p">);</span>
<span class="gp">In [26]: </span><span class="n">plt</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">In [27]: </span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s1">'upper left'</span><span class="p">);</span>
<span class="gp">In [28]: </span><span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">);</span>
<span class="gp">In [29]: </span><span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s1">'Resampled </span><span class="si">%s</span><span class="s1"> spectrum'</span> <span class="o">%</span> <span class="n">lib</span><span class="o">.</span><span class="n">names</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]);</span>
</pre></div>
</div>
<a class="reference internal image-reference" href="_images/spectrum_resampled.png"><img alt="_images/spectrum_resampled.png" class="align-center" src="_images/spectrum_resampled.png" style="width: 512.0px; height: 384.0px;" /></a>
<p>The resampled spectral library can be used with any image that uses the same
band calibration to which we resampled the spectra. We can also save the library
for future use. But before we save the library, we need to change the band units to the units
used in the band calibration (we need to convert from micrometers to nanometers).</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [30]: </span><span class="n">lib</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">centers</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1000.</span> <span class="o">*</span> <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">lib</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">centers</span><span class="p">]</span>
<span class="gp">In [31]: </span><span class="n">lib</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">bandwidths</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1000.</span> <span class="o">*</span> <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">lib</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">bandwidths</span><span class="p">]</span>
<span class="gp">In [32]: </span><span class="n">lib</span><span class="o">.</span><span class="n">bands</span><span class="o">.</span><span class="n">band_unit</span> <span class="o">=</span> <span class="s1">'nm'</span>
<span class="gp">In [33]: </span><span class="n">lib</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s1">'stones'</span><span class="p">,</span> <span class="s1">'Stone spectra from the ECOSTRESS library'</span><span class="p">)</span>
</pre></div>
</div>
<p>Saving the library with the name “stones” creates two files: “stones.sli” and
“stones.hdr”. The first file contains the resampled spectra and the second is the
header file that we use to open the library.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [34]: </span><span class="n">mylib</span> <span class="o">=</span> <span class="n">envi</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">'stones.hdr'</span><span class="p">)</span>
<span class="gp">In [35]: </span><span class="n">mylib</span>
<span class="gh">Out[35]: </span><span class="go"><spectral.io.envi.SpectralLibrary at 0x7f61aab7f7b8></span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="baldridge2009"><span class="brackets"><a class="fn-backref" href="#id2">Baldridge2009</a></span></dt>
<dd><p>Baldridge, A. M., Hook, S. J., Grove, C. I. and G. Rivera, 2008(9).
The ASTER Spectral Library Version 2.0. In press Remote Sensing of Environment</p>
</dd>
<dt class="label" id="meerdink2019"><span class="brackets"><a class="fn-backref" href="#id1">Meerdink2019</a></span></dt>
<dd><p>Meerdink, S. K., Hook, S. J., Roberts, D. A., & Abbott, E. A. (2019).
The ECOSTRESS spectral library version 1.0. Remote Sensing of Environment, 230(111196), 1–8.</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Spectral Libraries</a><ul>
<li><a class="reference internal" href="#ecostress-spectral-library">ECOSTRESS Spectral Library</a></li>
<li><a class="reference internal" href="#envi-spectral-libraries">ENVI Spectral Libraries</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="algorithms.html"
title="previous chapter">Spectral Algorithms</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="class_func_glossary.html"
title="next chapter">Class/Function Glossary</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="py-modindex.html" title="Python Module Index"
>modules</a></li>
<li class="right" >
<a href="class_func_glossary.html" title="Class/Function Glossary"
>next</a> |</li>
<li class="right" >
<a href="algorithms.html" title="Spectral Algorithms"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Spectral Python 0.21 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="user_guide.html" >Spectral Python (SPy) User Guide</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2014, Thomas Boggs.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-47389515-2', 'spectralpython.net');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
</body>
</html>