This repository contains the back-end of the Virtual FTIR Spectrometer.
-
wsgi.py
- This file is used for deployment by Gunicorn and Nginx on the server.
-
app.py
- Contains a program that accepts API calls for both spectrum generation and background sample generation. This program accepts JSON through a
fetch()
orcURL
command and returns JSON of X and Y coordinates.
- Contains a program that accepts API calls for both spectrum generation and background sample generation. This program accepts JSON through a
-
processing.py
- This module contains four functions:
process_spectrum
,generate_background
,generate_spectrum
, andfind_peaks
. These functions are used for the generation and anaylsis of realistic spectra. Find more details about each function here.
- This module contains four functions:
-
processing_utils.py
- This utility module contains helper functions for the
processing.py
module. These functions include functions to approxiamate physical components of an FTIR Spectrometer, approximate realistic noise, check user parameters, and calculate the resolution of the spectra. Find more details about the individual functions here.
- This utility module contains helper functions for the
-
download_hitran.py
- This script downloads HITRAN data files locally. This is useful so the Flask application doesn't need to download data files during user queries.
Information on how to run the back-end can be found in the repository's wiki page.
NOTE: Make sure in the frontend that
src/dictionaries/constants.js
has the proper fetch URLs uncommented.
A note on vocabulary: in this documentation "ideal spectrum" means either a background or sample spectrum with no noise and is unaffected by the physical components of the spectrometer.
There are two sets of parameters the server can receive based on what request is being made. If the request is for Spectrum or Background, the parameters will include:
beamsplitter
detector
window
source
resolution
zeroFill
scan
mole
molecule
pressure
waveMax
waveMin
beamsplitter
, detector
, window
, and source
are used to select which component spectra will be used in process_spectra
(details). resolution
and zeroFill
are used by calc_wstep
to determine the resolution of the spectrum (details). scan
is used by multiscan
and determines the number of scans to be simulated (details). The rest of the parameters (mole
, molecule
, pressure
, waveMax
, waveMin
) are used in generate_spectrum
to create the spectrum (details).
For Find Peaks requests, the parameters will include:
x-data
y-data
lowerbound
upperbound
threshold
x-data
and y-data
contain the x and y-values for the spectrum to analyze. lowerbound
gives the lowest x-value in the range to analyze; upperbpund
gives the higest x-value in the range to analyze. threshold
gives the lowest y-value to consider a 'peak' in the data.
-
Sample
- Sample recives a list of parameters from the POST Request in the form of a JSON. After running some basic parameter checking, Sample calls
generate_spectrum
. This function returns an ideal spectrum in the form of a RADIS Spectrum object based on the user selected parameters. This ideal spectrum is then passed to theprocess_spectrum
function which alters the spectrum to more closly resemble a realistic spectrum. For more detail on this function, go here. Then the x and y values from the resulting spectrum are sent back to the user.
- Sample recives a list of parameters from the POST Request in the form of a JSON. After running some basic parameter checking, Sample calls
-
Background
- Background takes in parameters, checks them, and calls
generate_spectrum
the same as Spectrum. After these preliminary steps, Background then callsgenerate_background
to get a spectrum where all the y-values are 1 (details). By callinggenerate_spectrum
and then callinggenerate_background
with the resulting spectrum, the x-values and overall resolution of the spectrum is accurate; the background data lines up with a sample spectrum with the same parameters. From here, the spectrum is sent toprocess_spectrum
so it will more closely resemble a real spectrum. Like Spectrum, this function sends the x and y-values of the resulting spectrum back to the user.
- Background takes in parameters, checks them, and calls
-
Find Peaks
- Find Peaks simply calls the
find_peaks
function using the parameters the user selected. For more details onfind_peaks
, see thefind_peaks
breakdown.
- Find Peaks simply calls the
- This function takes an ideal spectrum and returns a spectrum that is approximately the spectrum that would be generated by a physical spectrometer. This is achieved by creating additional spectra based on mathematical functions that approximate the behavior of FTIR components. The user chooses which of these spectra will be used by picking a Beamsplitter, Cell Window, Detector, and a source (Globar or Tungsten) for the Blackbody Spectrum. Those spectra are then multiplied into the base spectrum and realistic noise is added. Find more detail on the component functions here and find more detail about noise generation here.
- This function takes the wavenumbers (x-values) of a spectra and sets all y-values to one to simulate an ideal background spectrum.
- This function utilizes RADIS and the
calc_spectrum
function provided (details) to calculate an ideal spectrum based on the parameters provided in theparams
parameter and the resolution determined bycalc_wstep
(details).
- This function takes the x and y-values of a spectrum and finds all the peaks in the data using RADIS tools. Then the desired (emmission) peaks are returned from that data based on the minimum value for a y-value to be considered a peak (
threshold
).
- This function sets the y-values for the given spectrum to 1 in order to emulate a background sample.
- This function serves as a sanity check for the parameters sent in by the user. They are thoroughly checked on the frontend before the post request to this server is made.
- This function calculates the appropriate spectrum resolution/wstep based on the user given parameters
resolution
andzero_fill
. This function is based off of scientific data collected by the RastonLab.
- The purpose of this function is to add noise to the given spectra while limiting the amount of memory space used at any given time. The amount of noise added in total is determined by the
num_scans
variable. The amount of noise added in a particular iteration is determined by the value ofscans_per_group
, which is currently set to10
. In each iteration, a 2d array is created containing random numbers determined bynp.random.normal
; in this 2d array there is a column for each x-value in the provided spectra and a row for each scan being simulated. All of these values are added together and then divided by the total number of scans (for normalization purposes). The resulting 1d array is then added into the spectrum.
- This function is a helper function that generates all the the component spectra. It was created to reduce the amount of code in the
process_spectrum
. Additionally, this function normalizes the blackbody spectrum and both detector spectra. For more detail on this, see Component Functions.
These functions were designed to emulate several physical components within a real FTIR Spectrometer and their effect on spectra. This was accomplished by analyzing the data collected by the RastonLab depicting how each physical component alters the spectra. Then a mathematical function was created for each component through curve fitting. These functions are then used to create y-values that correspond to the list of x-values from the ideal spectrum. These x-y value pairs are then used to make Spectrum objects for each component (get_component_spectra
).
Following are the graphs associated with each function. Some functions may have more details as necessary.
NOTE: In many of these functions, there is a variable named x_um
that is set equal to 10000 / spectrum
. This (and any other instance of 10000 / spectrum
) is there to handle unit conversions.
-
This function takes a parameter called
source_temp
. This temperature is either1200
, which is associated with Globar, or3400
, which is associated with Tungsten. The spectrum that is generated with this function is normalized to 1 using the RADIS normalize function
-
The spectrum generated by this function is normalized to 2 using the RADIS normalize function, multiplying the resulting y-values by 2, and then making a new spectrum using those new y-values.
When this Detector is chosen, the spectrum for
__sapphire
is also multiplied into the spectrum.-
NOTE: This function takes a large number to the
6903.57039
power. The size of this exponent is unavoidable due to the curve fitting technique used to generate this function. As a result, this function invokes anOverflow Error
at runtime. There have not been any noticeable problems caused by this error.
-
-
The spectrum generated with this function is normalized to 1 using the RADIS normalize function
When this Detector is chosen, the spectrum for
__ZnSe
is also mulitiplied into the spectrum, regardless of whether or not__ZnSe
was multiplied in earlier.