Near Infrared Spectroscopy’s use for the Differentiation of Amazonian Tree Species Complexes of Protium (Burseraceae)
Advisor: Dr. Noble
Internship Location: Naval Postgraduate School Physics Department
Onsite Mentor: Paul Fine
The purpose of this project is to resolve a species complex within the genus Protium (Burseraceae), and to attempt to relate a specimen’s spectral reading to its phylogeny. The resolution of a Protium (Burseraceae) species complex will help scientists studying the Amazon to have a better understanding of a wide range of geographically diverse samples, and the successful use of NIR as a substitute for DNA analysis will support NIR as a faster and cheaper method of studying Protium (Burseraceae) specimens. If successful, the NIR data collected from each specimen can be related to its phylogeny and generalized through a computer model to create an effective method of placing specimens into a phylogeny without phylogenetic data.
Using NIR technology via UC Berkeley’s Fieldspec4, a sample of multiple cryptic species of Protium (Burseraceae) will be scanned for their spectra and compared to one another to identify and differentiate species within the complex. After implementing ViewSpecPro and R programs to compare and analyze the spectral data, the project will shift to creating linear relations between spectra and previously found DNA data from each specimen. An accurate relation of spectra to phylogeny has never been achieved for Protium (Burseraceae) species, however, there is strong evidence that NIR could be used to distinguish cryptic Protium (Burseraceae) species. Based on this, it is expected that the Protium (Burseraceae) species complex studied in this project will be successfully resolved, but a reliable model for predicting phylogeny is unlikely to be generated from the same sample.
Project Blog
Post 1: Introduction
Hey! I’m Aaron, and welcome to my Senior Project Blog! Over the last few weeks, I have been studying protium(Burseraceae) trees with Dr. Fine’s lab at UC Berkeley, and in this thread, I will be outlining my research process. But first, a little background:
Growing up as a rock climber in the Bay Area, most of my favorite childhood memories are of the forests, mountains, and wildlife surrounding my house. I have always been fascinated by the many ecosystems existing in California’s coastal forests, and in the last few years, I’ve witnessed firsthand how delicate these forest ecosystems really are. My project is heavily influenced by what I have observed in the forest surrounding my favorite climbing crag, Castle Rock, and how climate change has devastated forests around the world.
Since I started high school, climate change has done noticeable damage in the Santa Cruz mountains, severely stunting the growth of California Bay Laurels. In their stead, many smaller shrubs have started growing in the area, painting the ground an orange-green color instead of the Bay Laurel’s yellow. With that small change, banana slugs, which were once a staple of these mountains, have begun rapidly migrating and dying in our state parks. Without the Bay Laurel’s yellow leaves, they can no longer camouflage in one of the only places that they inhabit. Neither the California Bay Laurel nor the Banana Slug is currently endangered, but their story shows the fragility of ecosystems and the importance of understanding the nature around us before we harm it.
Inspired by this message, I sought out a project that would help scientists around the world to study the effects of climate change in forest ecosystems, specifically the Amazon. The Amazon Rainforest is the most biologically diverse place in the world, and every year, scientists from every corner of the globe study its plants and animals to understand the effects of climate change. Although my talents do not lie in ecology, with Dr. Fine’s help and my knowledge of Computer Science and Statistics, I settled on a project that would help these scientists to more effectively study the Amazon and hopefully fight climate change.
Across the Amazon Basin exists an incredibly diverse genus of plants, protium(Burseraceae), that is found in great number across essentially the entire Amazon Rainforest. As a result of its high population and diversity in species and location, this genus is a prime candidate for generalized ecological studies in the Amazon. My project focuses on helping scientists to conduct such studies by resolving certain protium(Burseraceae) species complexes and providing a tool that can quickly discriminate between species in the field without damaging samples.
I hope to achieve this goal by using UC Berkeley’s FieldSpec-4 machine, a powerful spectrometer, to take NIR (near-infrared) spectral readings across a wide range of wavelengths to identify “species signatures” that can be used to identity plant species with little more than a 2-3 second scan of a leaf. If successful, such a cheap, fast, and simple method of species identification can transform how scientists study the Amazon and plants in general. I will explain more about my data collection and analysis in my next post, but until then, stay tuned and stay excited!
Post 2: Blog 1: The Data
Welcome back to my blog! Today is all about data: what is measured, how it’s measured, and why it’s important. We will begin with a brief introduction to the basics of NIR (near-infrared) spectrometry and then delve into more complex topics as you become more comfortable with the technical aspects of my project.
So starting at the beginning, how have I been collecting my data, and what is the FieldSpec-4? The FS-4 is an incredibly powerful and precise spectroradiometer available for rent within UC Berkeley’s ecology department. For the purpose of my project, it can be understood as a spectrometer capable of outputting a spectral distribution across a wide range of wavelengths. The analysis of this spectral distribution is the focus of my project. Looking at the image below, you will see that the X axis indicates the wavelengths of light measured by the machine, which spans from 300 nm all the way to 2500 nm, showing how light interacts with the surface of the plant across a wide spectrum. The Y axis, on the other hand, indicates something a little less intuitive and will require us to discuss how measurements are taken with the FS-4 to be explained clearly.
To scan specimens with the FS-4, it is first necessary to calibrate the device. This is done by taking a “blank” measurement of a white reference, indicating to the device what 100% light saturation should be measured at. After calibration, using the device to analyze a sample returns an arbitrarily calculated reflectance value based on how much light was reflected off the plant at different wavelengths compared to the scan of the white reference. Referring back to the graph, this means that the shape of the graph represents how much light is returned to the device across every measured wavelength. In this graph specifically, I have layered all the readings I have collected from a single specimen over one another for easier analysis. At first glance, this graph and the technology used to generate it don’t seem revolutionary, but I believe that it is the future of ecology.
Before the introduction of NIR spectroradiometry to the field, the only way to analyze specimens was from a purely biological standpoint. Studies on DNA and other lab tests were necessary to uncover even the most basic differences between species, all while destroying specimens in the process. My method of analysis allows me to quickly collect data without harming my specimens and conduct data analysis that would be simply impossible on more complex types of data, such as DNA.
To prove this I’d like to refer one last time to the graph, you will see that across all the measurements the general shape of the graph remains the same while the total amount of light tends to fluctuate, shiting the entire graph from scan to scan up and down. Although this is a bit annoying for my analysis, the fluctuation is not a problem for identifying the species of plant in the scan as the shape of the graph is evidence enough that all the readings on this graph are not only from the same species but the same individual with how similar the shapes of all the readings are to each other. This means that even if scanned off a living plant in conditions where light is constantly fluctuating, such as the jungle, my method of analysis can still be effective for species identification far from any lab.
Now that we’ve established what we are measuring, how we’re measuring it, and what we are looking for, it’s time to introduce my favorite part of this project: the software. I will cover more advanced topics and a lot of the code that I wrote myself in future blogs, but for your understanding of what the data actually looks like before I analyze it, I would like to describe the ViewSpecPro software. Before I converted my readings from the scans of specimen 17 into a readable file format and fed them to my program to be displayed as a graph for you, I had to understand what the raw data returned by the device was. ViewSpecPro is the preferred software of specialists studying spectra for this exact purpose. This software allows me to read the .asd files returned by the FS-4 and export them into file formats that are much more effective for analysis, such as .txt and .csv. ViewSpecPro also has a library of incredibly powerful mathematical functions that it can execute on raw data before exporting it. In a project where only the shape of the graph is relevant, I have found that analyzing the first derivative is by far the most effective method of comparing graph shapes, and the ViewSpecPro software allows me to export the raw data as a first derivative before I even analyze it, saving a lot of trouble with my analysis. But that’s a teaser for next time, I will go into greater detail about this software, my code, and more in my next post. I'll see you all then!
Post 3: Blog 2: Software
Welcome back everyone! Today’s topic, as you might’ve read in my last post, is software! From cataloging hundreds of specimens to analyzing thousands of readings, my project wouldn’t be possible without its fair share of automation and coding. In this post, I will discuss everything from R to bash, but to pick up where I left off in my last post, I’ll start with a quick review of the ViewSpecPro software.
ViewSpecPro
Simply put, this program operates by allowing its user to easily manipulate .asd files, or the raw data, that is outputted by the FS-4. And in my project, it's use has become integral to any data analysis that I wish to perform. This is due to its replacement of the hsdar package in R. Historically, analysis of NIR spectra has relied heavily on a recently outdated package called “hsdar”, for which there is not yet a replacement at the time of this project. As a result, to manipulate my spectra, I was forced to adapt and create a new method of analysis before even seeing my spectra on the screen. The first step to achieving this was converting my data into a readable and easily manipulable file format, for which ViewSpecPro was the perfect tool. ViewSpecPro offers the only lossless method for converting .asd files to .txt/.csv files via the ASCII Export tool, which makes this software the cornerstone of all my analysis for this project, despite its simplicity and questionable design.
Upon uploading and selecting the file(s) that I wanted to export from the ViewSpecPro environment, the program would direct me to a menu where I could indicate several parameters such as the data format, field separator, and derivative that I wished to copy into a new .txt file. The .txt files generated through this process would then finally be ready for analysis through R, but not before overcoming the next hurdle of my project: organization.
Automating File Organization
It seems silly to mention when worrying about topics like discriminatory algorithms, but working with large datasets of extremely similar data is a challenge on its own. As shown in the image, every protium specimen requires 36 files split between 4 directories at a minimum for data analysis to be even remotely possible. Without having this exact identical naming convention and file structure between ALL collected specimens, the same code could not be run on each specimen, which would make my analysis impossibly inefficient. This realization resulted in me writing several bash scripts to optimize and automate the organization of the thousands of files needed for my project. A bash script is a typically short and simple program written in a language intended for use in a computer’s terminal/command line. Its main purpose is to automate any tasks requiring repetitive action regarding file organization/manipulation-- perfect for my project. Once all my files were organized, and I could manipulate them quickly and without risk of error using bash scripts, I could move on to the first steps of analyzing my spectra. From this moment, the rest of my project relies on my coding in R.
Graph Generation
When I was finally ready to begin coding in R, the first thing I had to do to start my analysis was generate reflectance graphs for all of my data, but without the hsdar package, this would be the first of many processes that I would have to code manually. Luckily, through the use of the .txt files I generated in ViewSpecPro and R’s basic functions, I came up with a primitive way to generate graphs by scanning .txt files line by line. I would break each line into string chunks via the field separator (commas) and then convert said strings into integers. Once I was left with only integers, I finally had the actual readings taken by the FS-4, extracted from the .txt file, which I could collect in a vector and graph with the plot() function. In this way, I was able to create a general method for not only graphing .asd spectra without the hsdar package, but also for manipulating any spectral data from the .txt files I generated with ViewSpecPro.
Thank you for reading!
In my next post, I plan to delve deeper into how this code became the basis for all my data analysis and discuss more about the inner workings of R. Stay tuned to read more about my methodology, datasheets, interns, and my meeting with the Harvard ecology department!
Post 4: Blog 3: Data Collection and Teamwork
Hello again! In my last post, I discussed some of my early challenges with using technology to collect and analyze my data. And I, somewhat prematurely, promised to delve deeper into R and my code in today’s post. But without giving a summary of my methodology for data collection, it will be difficult to outline what I designed my analysis around. So today’s post is all about context and a fairly unique aspect of my project: teamwork.
Teamwork
Spectral data is a fairly new trend in ecological lab work, and my research is part of a much larger project headed by Dr. Fine and his lab. As a result, much of my time is spent working with other people involved in this project and other spectra-focused projects, to learn how to adopt and properly use this technology for ecology. In my immediate network for this project are two professors (Stephanie and Dr. Fine) and two interns (Kate and Alondra). I have to mention that Stephanie is not officially attached to our research, but her help as an expert on spectra has been invaluable.
The basic breakdown of our team's duties is simple: Dr. Fine and I work with researchers from the Harvard ecology department that help us design our data collection/analysis methodology, Stephanie and I work on the analysis of the specimens, and Kate, Alondra, and I work with the FS-4 to collect readings from the specimens and organize our samples. Together, we’ve managed to design an incredibly large and complex project, part of which has become my senior project.
Data Collection
The method for data collection that Dr. Fine and I came up with and Kate, Alondra, and I practiced is as follows:
We take 12 readings per specimen, spread across 3 leaves; 4 scans per leaf, of which 2 are adaxial (top) and 2 are abaxial (bottom). The scans are ALWAYS taken and recorded in a strict order:
Leaf 1
bottom
bottom
top
top
Leaf 2
bottom
bottom
top
top
Leaf 3
bottom
bottom
top
top
In this way, analysis can be easily automated according to the order of the scans, and when necessary, the data can be adjusted to only look at certain factors. For example, I have on a few occasions looked at only 1 leaf per specimen or at only the adaxial or abaxial measurements.
This system for measurement order is also coupled with a meticulously made datasheet for each specimen AND each reading. This may seem like overkill, but when dealing with so many files, it is almost impossible to keep track of any change without being this careful and precise at every step. Mistakes happen, and the only way to fix them is to have a record of all of them. In the image below, you can see that, along with the file name and specimen code (specimen species for these readings will be added later by Dr. Fine), there is also a record of any slight deviation from the typical order that can be used to account for any mistakes in the analysis.
For the purpose of my analysis, this data sheet is used to relate my file names to their respective specimens, and to then properly sort my files to search for individual, population, and species-level differences. But it also serves as an incredibly useful record of all the conditions that could be causing differences between my readings. How that is used, however, is a discussion for next time. Stay tuned for a deeper dive into my code and the specific protium (Burseraceae) species that I’ve been studying for this project, and I'll see you all next week!
Post 5: Blog 4: Lobo and Blanco
Hello everyone, and welcome back to my blog! As you all know by now, the purpose of my research is to use NIR spectra to discriminate between species of protium (Burseraceae) and to create a model that can quickly identify species from spectra alone. Given the difficulty of this task, I began my project with fairly low expectations regarding the success of my discriminating algorithm, but today, I will be sharing one of the more exciting success stories from this project to date: species discrimination! Over the course of the last few weeks, I’ve scanned and analyzed countless species, but my focus remained on a particular cryptic species that Dr. Fine told me to investigate: Protium subserratum. This species complex is currently considered to be a single, incredibly common species of native tree in the Amazon, and it is found in nearly every corner of the jungle.
From my analysis of the spectra my team collected of Protium subserratum, Dr. Fine and I have concluded that Protium subserratum is, in fact, two separate species that we have denoted as lobo and blanco.
Although my LDA analysis and discriminating algorithm have not yet been validated for other species and species complexes, the differences in spectra between lobo and blanco are so apparent that they can be seen and identified with the naked eye. Because of this, my analysis of this species complex’s spectra only relied on the absolute basics. Using the datasheet below, I averaged an individual’s readings into one “individual signature” and then compiled those signatures into a broader “species signature.” Once those steps were coded and completed, it was immediately obvious by comparing the signatures of lobo and blanco how different the two species were.
Layered readings for blanco are displayed on the left, and readings for lobo are displayed on the right. From these graphs, it is apparent that Protium subserratum features two distinct spectral groups.
Lobo and Blanco are, however, incredibly rare cases. Although it is amazing when it occurs, the spectra from two species of protium (Burseraceae) can almost never be differentiated with the naked eye, much less spectra from one species complex. Since my initial identification, Lobo and Blanco have remained the only two species of protium (Burseraceae) that I can identify without the use of a computer algorithm. Because of this issue, the question becomes how to differentiate graphs of species that can not be seen so easily. To which, the answer that I will cover in my next blog is LDA (Linear Discriminant Analysis). I hope you’ve enjoyed reading about this taxonomical development in the species of Protium subserratum, and I hope that you’ll stick around until next week to learn about LDA and how I’ve implemented it in my project. Thank you for reading!
Post 6: Blog 5: LDA
Welcome back everyone! Last time we talked about the two distinct spectral groups I’ve found within Protium subserratum (Lobo and Blanco) and what that could mean for the possible success of my project’s greatest goal: a species-identifying algorithm. Lobo and Blanco prove that at least in some cases of protium (Burseraceae) species, spectra alone is enough to discriminate at the species level. Additionally, since Lobo and Blanco are found within one species, a cryptic species, their existence also proves that spectra alone is enough to discriminate between potential species within at least some species complexes of protium (Burseraceae). This exists as a proof of concept for my goal for this project and thus begs the question of how this fact can be taken and expanded upon to build a generalized algorithm. The simple answer is LDA (Linear Discriminant Analysis).
LDA is a fairly simple algorithm that becomes increasingly complex as more degrees of freedom are introduced. At its core, LDA is designed for the purpose of maximizing separation between two or more known groups, seemingly a perfect algorithm for my goal. It works by trying to condense a number of factors (variables) into a single discriminant score, which can then be used to discriminate between different classes.
The discriminant score is calculated according to the following formula:
LD = a1 X1+a2 X2+...anXn
Where “a" represents a calculated coefficient according to the LDA algorithm, and "X” represents the value of a variable. The function of the coefficient in this formula is to “weight” the importance of every variable and thus produce a discriminant score that has no real-world value, but is objectively the most polarizing value for that particular data point in the context of the rest of the data fed into the LDA algorithm.
The way that these coefficients are calculated is a bit too complicated to explain in this brief overview, but I will explore them further in future blog posts where I discuss the issues with implementing LDA into my project. What is important to remember for this post is that LDA uses these coefficients to essentially rank all the variables in order of separability, and that the discriminant score is the resulting linear combination of all the variables with their “weighting”.
So far, the basic methodology that my project has been using for this type of analysis is a direct implementation of LDA, where each wavelength is its own variable and the reflectance reading at that wavelength is the value of that variable. By generating a table of all these variables according to this convention and then separating them by class, which in this case is their species, I can calculate my weighted coefficients by running the table through an LDA function. With these coefficients, I can then generate discriminant scores for each one of my specimens and plot them accordingly. In theory, this would allow me to discriminate between any number of protium (Burseraceae) species, provided that I have enough measurements and they have statistically different reflectance measurements.
In my next post, I will cover why, with a seemingly effective methodology like this, a consistent discrimination algorithm still hasn’t been achieved in my project. This is mostly to do with the sheer number of variables that I would have to account for and the general noise that comes from taking spectral scans, but let’s save that conversation for next time. I’ll see you then!
Post 7: Blog 6: Continued Research
Welcome back to my blog! Last time, I introduced some of the more basic math behind LDA and covered how LDA would ideally function in my project. Unfortunately, for several reasons, the direct application of LDA that I initially wanted to use in this project is not possible. So today’s blog post is all about why that is and what I’ve been working on to improve my LDA model’s ability to discriminate between specimens.
Nearly all the issues with direct LDA implementation in my project can be traced to the nature of reflectance sampling. Unavoidable discrepancies in light saturation result in random variation in absolute reflectance between readings, and the use of the first derivative to eliminate that issue results in extra noise in the measurements. For me to use LDA effectively despite these issues, I have been forced to be much more selective with what wavelengths I can analyze.
As you may recall from my last post, each reflectance measurement at a wavelength is a variable fed into my LDA algorithm. This means that even if I only consider looking at wavelengths from 1000 to 2500 nm, I would still have to feed my LDA algorithm 1500 unique variables, expecting the function to then rank and return 1500 “weighting” coefficients. This, especially in files with very little variation at certain wavelengths, only exacerbates my issues with noise. To mitigate this issue, it is necessary to drastically reduce how many variables are fed into the algorithm and to be much more selective with what wavelengths are chosen. Although I am still in the process of picking the correct wavelengths to focus on, Dr. Fine and I have discussed using LDA a second time to first identify which wavelengths are the most important to separation via their weighting coefficients and to then perform the actual LDA analysis using only the most significant wavelengths. This idea, however, is much more difficult to implement than we originally thought, so with the help of Stephanie, we have been developing a simplified algorithm for selecting significant wavelengths before conducting the LDA.
I will share my last updates on the success of this pre-LDA algorithm in my next and possibly final post! I hope you’ve enjoyed learning about my senior project and will tune in for my last post!
Post 8: Blog 7: Goodbye!
Hello readers! Unfortunately, this will be my final blog post for my senior project. It’s been an incredible experience, and I appreciate you guys for tuning in and following me on my research journey. For this final blog, I’d like to share an update on the current state of my research and provide a rough outline of where the project will take me in the coming months.
As I mentioned in my last post, my project’s recent focus has been on the development of a pre-LDA algorithm. The objective of which would be to prepare data for Linear Discriminant Analysis. Although this goal has not been achieved yet, Stephanie and I have been working on developing our pre-LDA algorithm and improving my existing LDA. I hope that in the next few weeks, I will be able to transition from training my LDA algorithm on the limited NEW52 dataset to the expanded one that Kate, Alondra, and Dr. Fine created.
With a successful pre-LDA algorithm, I will be able to quickly parse and prepare reflectance data for my LDA, which will improve both the effectiveness of my LDA and the speed with which my algorithm can be trained. While I cannot predict what will occur when I transition my algorithm from the training stage to the application stage on the new dataset, I am confident that the fixes required at such a late stage of algorithm development will be minimal.
My goal is to, by the end of my internship in July, have a working identification tool that will use spectral data and LDA to classify protium (Burseraceae) specimens with sufficient accuracy. But looking beyond July, there’s potential for future researchers to refine my model and integrate larger datasets with more complex analysis to expand my project to more species and even other genera.
I am excited to continue working on my research and to see how it will evolve and grow as it gets adopted by other ecologists. Although this is my final blog post, I hope that one day you will see an application of my research outside of this blog and senior project. But until then, thank you all so much for reading--Goodbye!