Having looked at the options using tools of increasing complexity we come to using my favourite tool for LIBS Analysis - Python. I like Python because it is reasonably easy to start, and it encourages experimentation - not everything has to be right before you can start getting something out of it.
I use WinPython as it offers (at least on Windows) a version that works out of the box.
The source files for these tutorials are Jupyter notebooks which enable me to combine the code and the explanation together. The files are available from the Elementia Consulting Github if you want to try/adapt these for your own use.
The beauty of Jupyter notebooks is that they allow the combining together of Python script and an explanation of what is happening. If you are viewing this on the libs-info website, then the file won't be interactive - you will just the output. If you download the notebook files from the Github, then they can be run live and the results seen.
If you are only interested in the techniques used, then you can skip the Python code lines and their explanation. The pure code commentary will be marked with italics
In the next could of lines, we initialise the Python code that we need to run the calculations. We will be using the Bokeh for the charts
import pandas as pd
import numpy as np
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
from bokeh.models import Range1d
from IPython.display import display, Markdown, HTML
from elementia.tutorial_fns import calculate_cross_validation, calculate_intensity_cv, calculate_sum_cv
output_notebook()
For this work we will use the following samples, and analyse for Sodium (Na)
Sample | Na. Conc (ppm) |
---|---|
OREAS45e | 594 |
OREAS501b | 20848 |
OREAS601 | 14543 |
OREAS921 | 6068 |
OREAS603 | 4283 |
OREAS933 | 1515 |
OREAS903 | 301 |
To do this, we use the Python Data Analysis Library (PANDAS). This package is included in most Python implementations.
PANDAS has a read_csv function that handles the import of the file, placing into a PANDAS dataframe, which has a range of usefule features which we will take advantage of - the first of which is that we can use the column heading to label the data
conc_data = pd.read_csv('.\\files\\Na_concs.csv')
print(conc_data)
In this case we will import the same source CSV file as we have used previously and plot all the spectra
If you are using notebook file, then the tools to the left of the chart allow zooming, panning and saving the image to file
# load the data from file
spectra_data = pd.read_csv('.\\files\\OREAS_source.csv')
# and display the first 5 lines
print(spectra_data.head(5))
#use the Bokeh library, start a chart (or figure)
p1 = figure()
#on our new figure, display the intensities we have loaded from the files. One of the many beauties of the PANDAS library we used to do
# the import is that it allows us to use the column labels from the file to represent the columns of data.
p1.line(x=spectra_data['Wavelength (nm)'], y=spectra_data['501b_6'], legend='OREAS 501b', color='red')
p1.line(x=spectra_data['Wavelength (nm)'], y=spectra_data['601_7'], legend='OREAS 601', color='orange')
p1.line(x=spectra_data['Wavelength (nm)'], y=spectra_data['921_7'], legend='OREAS 921', color='yellow')
p1.line(x=spectra_data['Wavelength (nm)'], y=spectra_data['603_7'], legend='OREAS 603', color='green')
p1.line(x=spectra_data['Wavelength (nm)'], y=spectra_data['933_5'], legend='OREAS 933', color='blue')
p1.line(x=spectra_data['Wavelength (nm)'], y=spectra_data['45e_7'], legend='OREAS 45e', color='indigo')
p1.line(x=spectra_data['Wavelength (nm)'], y=spectra_data['903_5'], legend='OREAS 903', color='violet')
show(p1)