Plotting Spectral Signatures with Mutant and Gnuplot 5.0

Hey folks!

The last two days I had a little time to test a QGIS plugin my friend Werner Macho developed in the course of his master thesis .
His goal was to do multitemporal data analysis of multispectral raster files (e.g. Landsat files). The result is a tool called Mutant (MUlti Temporal ANalysis Tool for Rasterdata). It allows you to display raster layer values at the current mouse position and much more. Today I want to show you how you can use it to display the values of a hyperspectral data set and thereupon how you can plot the spectral signatures with the help of Gnuplot. So lets start!

You can install the plugin over the QGIS plugin manager. It’s listed in the official repository. Just search for Mutant.
After that, simply load a multi- or hyperspectral raster layer. In my case I take a file delivered by the APEX sensor. It has 288 bands with a range from 400 nm to 2500 nm.
Mutant is pretty self-explaining. In the table tab you get the values per band. The graph tab shows the values in a xy diagram. Here you can see the spectral signature of an object/pixel. Using the qwt library is pretty fast/near realtime when you change the position of the mouse cursor on your raster. Under options you should now set that the plot catches values only when the mouse is clicked. This is important to getting the data of your wanted pixel ready for exporting. The time tab is for multitemporal analysis – very useful, but not treated in this blogpost.



Exporting and Editing Spectral Information from Mutant

Now select a pixel of your interest. I my case i take one from which I know it is from a corn field. On the graph you can see a typical signature with low values in the visible spectrum and higher values in the shortwave infrared. There can also be seen two peaks around band 150 and band 200. This is due to some data errors. We will have to remove them in the following process.
In the table section you have now the possibility to export the values as a CSV table.

For editing the CSV I recommend to use Notepad++. With the Alt-key hold you can select columns. My CSV file looks like this:

APEX_STRBR110910_a01_Rw_R Band 001,0,
APEX_STRBR110910_a01_Rw_R Band 002,0.00358474813402,
APEX_STRBR110910_a01_Rw_R Band 003,0.00719787273556,
APEX_STRBR110910_a01_Rw_R Band 004,0.010097052902,
APEX_STRBR110910_a01_Rw_R Band 005,0.0116811329499,
APEX_STRBR110910_a01_Rw_R Band 006,0.0123249711469,
APEX_STRBR110910_a01_Rw_R Band 007,0.0129347108305,
APEX_STRBR110910_a01_Rw_R Band 008,0.0143983680755,

I removed the first part and replaced the commas with tabs, so that it looks like that:

001    0    
002    0.00358474813402    
003    0.00719787273556    
004    0.010097052902    
005    0.0116811329499    
006    0.0123249711469    
007    0.0129347108305    
008    0.0143983680755    

Now the data is ready for being plotted with Gnuplot or R.


Plotting with Gnuplot

Gnuplot is a commandline-based open source software for the graphical depiction of data and mathematical functions.  Gnuplot scripts have the file extension .plt, so we create new file called spectral-signature.plt.
We now edit the file with Notepad++ and start to write our short script:


When we now save the script and start it we get the following result:




We still have to optimize some things. We want to replace the band number with the actual wavelength, we want to remove the errors and we want to compare different spectral signatures in one plot.
The changes are quick and easy. First we replace  the first column of the band number with the actual number of the wavelength in Notepad++. You normally find the wavelength in your data specifications.
The second part is that I simply replace the values with the errors with blank lines in my data file. For adding some more spectral signature we just go back to Mutant and export some more CSV files from different pixel. We copy the columns with the values in new columns in our data file.

My main CSV file looks like this after the modification:

1.271957    0.453942209482        0.428693234921         0.428693234921         0.425805985928         0.425805985928    
1.282467    0.458551138639        0.433166712523         0.433166712523         0.430072486401         0.430072486401    
1.292145    0.45969954133        0.437388390303         0.437388390303         0.434899836779         0.434899836779    
1.300883    0.456142693758        0.438401371241         0.438401371241         0.437062174082         0.437062174082    
1.310541    0.439118653536        0.425513148308         0.425513148308         0.424490660429         0.424490660429    
1.319239    0.410930931568        0.402338802814         0.402338802814         0.401629149914         0.401629149914    
1.328987    0.384620368481        0.378790527582         0.378790527582         0.377752780914         0.377752780914    
1.338643    0.370515078306        0.367329269648         0.367329269648         0.365032434464         0.365032434464    
1.348351    0.392174750566        0.38186571002         0.38186571002         0.37617701292         0.37617701292    
1.462725    0.0678672268987        0.0658679902554        0.0658679902554        0.0645860359073        0.0645860359073    
1.470393    0.0824475362897        0.0798962712288        0.0798962712288        0.0762986540794        0.0762986540794    
1.480141    0.0913990363479        0.0875252783298        0.0875252783298        0.0824609026313        0.0824609026313  

The Gnuplot script also gets edited:



After starting the script we get our final result with the different spectral sigantures of corn compared in one plot:



There are a billion more ways to alter your graphs. You can change nearly everything in your depiction.
Just google some more commands for the gnuplot script and change your line colors or whatever!
Have fun! 🙂



About This Author

Simon is a research assistant in the field of remote sensing at Technical University of Munich (TUM). Currently he is working on methods to describe reed ecosystem parameters with the help of hyperpectral and LiDAR data. Besides geoinformatics he loves to do outdoor activities such as hiking and climbing.

Post A Reply