pquad

The get_defaults function

get_defaults()[source]

Returns default frequencies to project intensities onto as well as default paths for locations of the pure and mixture spectroscopic data.

Returns

  • frequency_range (numpy.ndarray) – Frequencies over which to project the intensities.

  • pure_data_path (str) – Directory location where pure-component spectra are stored.

  • mixture_data_path (str) – Directory location where mixed-component spectra are stored.

The IR_DECONV class

class IR_DECONV(frequency_range, pure_data_path)[source]

Class for generating functions used to to deconvolute spectra

Parameters
  • frequency_range (numpy.narray) – Frequencies over which to project the intensities.

  • pure_data_path (str) – Directory location where pure component spectra are stored.

Variables
  • NUM_TARGETS (int) – Number of different pure commponent species.

  • PURE_DATA (list[numpy.ndarray]) – Original values of the of the experimental pure-component spectra. There is a separate numpy.ndarray for each pure-component. Each array has shape \((m+1)\)x\(n\) where \(m\) is the number of spectra for a pure component and \(n\) is the number of discrete intensities sampled by the spectrometer. nump.ndarray[0] corresponds to the frequencies over which the intensities are measured.

  • PURE_CONCENTRATIONS (list[numpy.ndarray]) – Concentrations (M) for each pure-component solution measured. There is a separate numpy.ndarry for each experimental pure-component and each array is of length \(m\).

  • PURE_FILES (list[str]) – Location to each file in pure_data_path.

  • FREQUENCY_RANGE (numpy.ndarray) – Numpy array of frequencies to project each spectra onto.

  • NUM_PURE_SPECTRA (list[int]) – Number of spectra for each pure-component.

  • PURE_STANDARDIZED (list[numpy.ndarray]) – List containing standardized sets of pure spectra where each set of spectra is represented by a \(m\)x\(n\) array where \(m\) is the the number of spectra for each pure-componet species and \(n\) is the length of FREQUENCY_RANGE.

  • PURE_NAMES (list[str]) – List of pure species names.

_get_PC_loadings(NUM_PCs)[source]

Returns principal component loadings after performing SVD on the matrix of pure spectra where \(pure-single_spectra = USV^T\)

Parameters

NUM_PCs (int) – The number of principal components of the spectra to keep.

Variables

TOTAL_EXPLAINED_VARIANCE (numpy.ndarray) – Total explained variance by the \(n\) principal components where \(n=NUM_PCs\)

Returns

PC_loadings – The first loadings of the first \(N\) principal components where \(N\) is equal to NUM_PCs. \(PC_loadings = V\)

Return type

numpy.ndarray

_get_PCs_and_regressors(NUM_PCs)[source]

Returns principal component loadings of the spectra as well as the matrix that multiplies the principal components of a given mixed spectra to return.

Parameters

NUM_PCs (int) – The number of principal components of the spectra to keep.

Returns

  • PC_loadings (numpy.ndarray) – The first loadings of the first \(N\) principal components where \(N\) is equal to the number of pure-component species on which model is trained.

  • PCs_2_concentrations (numpy.ndarray) – Regressed matrix to compute concentrations given the principal components of a mixed spectra.

_get_concentration_coefficients(concentrations)[source]

Get coefficients used in computing the individual spectra given their pure component conentrations. Also used in regressing parameters for computing pure component spectra.

Parameters

concentrations (float, np.ndarray, or list) – The concentration(s) whose pure-component spectra must be computed

Returns

concentration_coefficients – set of coefficients for computing pure-component spectra given the concentration of that pure-component

Return type

numpy.ndarray

_get_concentrations_2_pure_spectra()[source]

Returns regressed parameters for computing pure component spectra from individual concentrations

Returns

CONCENTRATIONS_2_PURE_SPECTRA – List of parameters to estimate pure-spectra given its concentration.

Return type

list[numpy.ndarray]

_get_pure_single_spectra()[source]

Returns the pure spectra and concentrations in a format X and y, respectively, where X is all spectra and y is the corresponding concentration vectors.

Returns

  • X (numpy.ndarray) – Array of concatenated pure-component spectra of dimensions \(m\)x\(n\) where \(m\) is the number of spectra and \(n\) is the number of discrete frequencies

  • y (numpy.ndarray) – Array of concatenated pure-component concentrations of dimensions \(m\)x\(n\) where \(m\) is the number of spectra and \(n\) the number of pure-component species.

get_standardized_spectra(DATA)[source]

Returns standardize spectra by projecting the intensities onto the same set of frequencies.

Parameters

DATA (list[numpy.ndarray]) – Spectra to be standardized. Must contain the experimental frequencies of the spectra to be standardized as the first entry of each ndarry and all following entries are the spectra. Each ndarray should there for be of shape (>1,n) where n is the number of frequencies sampled by the spectrometer.

Returns

STANDARDIZED_SPECTRA – List containing standardized sets of spectra in DATA projected onto FREQUENCY_RANGE.

Return type

list[numpy.ndarray]

The IR_Results class

class IR_Results(NUM_PCs, frequency_range, pure_data_path)[source]

Child class of IR_DECONV for deconvoluting experimental spectra whose intensity increaeses monotonically with concentration.

Parameters
  • NUM_PCs (int) – The number of principal components of the spectra to keep.

  • frequency_range (numpy.narray) – Frequencies over which to project the intensities.

  • pure_data_path (str) – Directory location where pure component spectra are stored.

Variables
  • pca_loadings (numpy.ndarray) – The first loadings of the first \(N\) principal components where \(N\) is equal to the number of pure-component species on which model is trained.

  • PCs_2_concentrations (numpy.ndarray) – Regressed matrix to compute concentrations given the principal components of a mixed spectra.

_visualize_data(figure_directory)[source]

Plots visualization of the input data.

Parameters

figure_directory (str) – Directory where figures should be saved. In place of a directory, keywords ‘fit’ or ‘print’ can also be provided. These do not save the images but sends them to the gui; ‘fit’ adjusts the figure size to the screen it is being viewed on.

Returns

Return type

Figures describing the data and results of the model.

get_95PI(spectra)[source]

Returns prediction interval of the predicted concentrations.

Parameters

spectra (numpy.ndarray) – Standardized mixed spectra. Usually this is IR_Results.MIXTURE_STANDARDIZED.

Returns

prediction_interval – Prediction interval at the 95% confidence level such that 95% of error bars of the predicted concentrations should overlap the parity line.

Return type

numpy.ndarray or list[numpy.ndarray]

get_deconvoluted_spectra(spectra)[source]

Given standardized mixed spectra return the corresponding deconvolute and return the corresponding pure-component spectra

Parameters

spectra (numpy.ndarray) – Standardized mixed spectra. Usually this is IR_Results.MIXTURE_STANDARDIZED.

Returns

reordered_spectra – Pure-component spectra that make up the mixed spectra. If multiple mixed spectra are provided the numpy arrays are ordered alphabetically by IR_Results.MIXTURE_FILES. Each numpy array is ordered alphabetically by IR_Results.PURE_FILES.

Return type

list[numpy.ndarray] or list[list[numpy.ndarray]]

get_mixture_figures(figure_directory)[source]

Returns parity plot and visualizes input data for the case the case where concentrations in the mixture are known.

Parameters

figure_directory (str) – Directory where figures should be saved. In place of a directory, keywords ‘fit’ or ‘print’ can also be provided. These do not save the images but sends them to the gui; ‘fit’ adjusts the figure size to the screen it is being viewed on.

Returns

Return type

Figures describing the data and results of the model.

get_predictions(spectra)[source]

Returns predicted concentrations of the pure-component species that make up the mixed spectra.

Parameters

spectra (numpy.ndarray) – Standardized mixed spectra. Usually this is IR_Results.MIXTURE_STANDARDIZED.

Returns

predictions – Predicted concentrations

Return type

numpy.ndarray or list[numpy.ndarray]

get_reaction_figures(figure_directory='fit')[source]

Returns parity plot and visualizes input data for the case the case where concentrations in the mixture are unknown.

Parameters

figure_directory (str) – Directory where figures should be saved. In place of a directory, keywords ‘fit’ or ‘print’ can also be provided. These do not save the images but sends them to the gui; ‘fit’ adjusts the figure size to the screen it is being viewed on.

Returns

Return type

Figures describing the data and results of the model.

plot_deconvoluted_spectra(figure_directory='print')[source]

Returns deconvoluted spectra plot for when concentrations in the mixture are known.

Parameters

figure_directory (str) – Directory where figures should be saved. In place of a directory, keywords ‘fit’ or ‘print’ can also be provided. These do not save the images but sends them to the gui; ‘fit’ adjusts the figure size to the screen it is being viewed on.

Returns

  • Comparison plot of deconvolated spectra vs the spectra for the

  • pure-species in the mixture

plot_parity_plot(figure_directory='print')[source]

Returns parity plot for the case the case where concentrations in the mixture are known.

Parameters

figure_directory (str) – Directory where figures should be saved. In place of a directory, keywords ‘fit’ or ‘print’ can also be provided. These do not save the images but sends them to the gui; ‘fit’ adjusts the figure size to the screen it is being viewed on.

Returns

Return type

Parity Plot of predicted vs. actual concentrations.

save_deconvoluted_spectra(figure_directory='print')[source]

Saves deconvoluted spectra for when concentrations in the mixture are known.

Parameters

figure_directory (str) – Directory where figures should be saved.

Returns

Return type

Saves deconvoluted and pure spectra for the species.

save_parity_data(figure_directory)[source]

saves parity data for the case the case where concentrations in the mixture are known.

Parameters

figure_directory (str) – Directory where data should be saved.

Returns

Return type

saves parity plot.

save_reaction_data(figure_directory='fit')[source]

Returns parity plot and visualizes input data for the case the case where concentrations in the mixture are unknown.

Parameters

figure_directory (str) – Directory where figures should be saved.

Returns

Return type

Saves data describing predicted concentrations.

set_mixture_data(mixture_data_path, contains_concentrations=True)[source]

Instantiates the mixture data that needs to deconvoluted from the file(s) in mixture_data_path. A path to a folder of files, a single file, or a numpy array can be passed.

Parameters

mixture_data_path (str or numpy.array) – Directory or file where mixture data is stored. A numpy.array is also accepted.

Variables
  • PURE_DATA_IN_MIXTURE (list[numpy.ndarray]) – List containing unstandardized single-spectra data. Read from the mixture files by numpy.load.txt. Instantiated if contains_concentrations=True.

  • MIXTURE_DATA (list[numpy.ndarray]) – List containing unstandardized mixture spectra directly from .csv files. Read by numpy.loadtxt.

  • MIXTURE_CONCENTRATIONS (list[numpy.ndarray]) – List containing pure-component concentrations. Instantiated if contains_concentrations=True.

  • MIXTURE_FILES (list[str]) –

  • containing file(s) in mixture_data_path. (List) –

  • PURE_DATA_IN_MIXTURE_STANDARDIZED (list[numpy.ndarray]) – List containing standardized pure-component spectra projected onto FREQUENCY_RANGE. Instantiated if contains_concentrations=True.

  • MIXTURE_STANDARDIZED (numpy.ndarray) – List containing standardized mixture spectra projected onto FREQUENCY_RANGE. If data is from mixture(s) with concentration data then it is a 2-D array. If data is from reaction data it is either an array of objects which obejct is a numpy or it is a 3-D array if all reaction files have the same number of spectra.

  • NUM_MIXED (int) – Length of MIXTURE_FILES

  • MIXTURE_INFO (list[str]) – Data from the first row of the mixture.csv files if contains_concentrations=False