model_components¶
The model components used in KIPET are maintained here.
component_expression¶
data_component¶
element_blocks¶
expression¶
model_components¶
objectives¶
This file contains the object functions used throughout Kipet modules in one place. This should reduce the redundancy in using objective terms
Note
These methods are not complete in all cases and may not be used in future versions of KIPET.
- kipet.model_components.objectives.get_objective(model, *args, **kwargs)¶
Main method to gather the objective terms
- Parameters
model (ConcreteModel) – The model for which the objective will be built
args (tuple) – The arguments to be passed
kwargs (dict) – The arguments to be passed
- Returns
An objective component for the model
- Return type
Objective
- kipet.model_components.objectives.conc_objective(model, *args, **kwargs)¶
Method to build concentration terms in the objective function
- Parameters
ConcreteModel model (Pyomo) – This is the current model used in parameter fitting
args (tuple) – Arguments to be passed
kwargs (dict) – Arguments to be passed
- Returns
obj
- Return type
expression
- kipet.model_components.objectives.comp_objective(model, *args, **kwargs)¶
Method to build individual complementary state terms in the objective function
- Parameters
ConcreteModel model (Pyomo) – This is the current model used in parameter fitting
args (tuple) – Arguments to be passed
kwargs (dict) – Arguments to be passed
- Returns
obj
- Return type
expression
- kipet.model_components.objectives.spectra_objective(model, *args, **kwargs)¶
Method to build individual spectral terms in the objective function
- Parameters
ConcreteModel model (Pyomo) – This is the current model used in parameter fitting
args (tuple) – Arguments to be passed
kwargs (dict) – Arguments to be passed
- Returns
obj
- Return type
expression
- kipet.model_components.objectives.absorption_objective(model, *args, **kwargs)¶
Method to build individual absorption terms in the objective function
- Parameters
ConcreteModel model (Pyomo) – This is the current model used in parameter fitting
args (tuple) – Arguments to be passed
kwargs (dict) – Arguments to be passed
- Returns
obj
- Return type
expression
spectral_handler¶
Spectral Data Handling for Kipet
- class kipet.model_components.spectral_handler.SpectralData(name, data=None, file=None, remove_negatives=False)¶
This class is used to handle the spectral data used in a ReactionModel
Since spectral data is different from the state data and requires different methods to modify the data, a separate class was designed to house all of the spectra specific methods.
- Parameters
name (str) – The name for the data set
data (pandas.DataFrame) – The spectral data (D matrix)
remove_negatives (bool) – Option to set negative values to zero
- Methods
- __init__(name, data=None, file=None, remove_negatives=False)¶
Initialize a SpectralData instance
- Parameters
name (str) – The name for the data set
data (pandas.DataFrame) – The spectral data (D matrix)
remove_negatives (bool) – Option to set negative values to zero
- add_data(data)¶
Adds a dataset to a SpectralData instance.
This is used only if the SpectralData instance is created without a data attribute (not being None). This handles setting up the data_orig attribute as well and is therefore better than simply using setattr.
- Parameters
data (pandas.DataFrame) – The spectral data (D matrix)
- Returns
None
- reset()¶
Resets the data back to the originally supplied data
- Returns
None
- plot(data_set='data')¶
Plots spectral data in 3D plot.
Plots the modified or original data sets.
- Parameters
data_set (pandas.DataFrame) – attribute name of the spectral data
- Returns
None
- savitzky_golay(window=3, poly=2, deriv=0, in_place=True)¶
Implementation of the Savitzky-Golay filter for Kipet. Used for smoothing data, with the option to also differentiate the data. Can be used to remove high-frequency noise. Creates a least-squares fit of data within each time window with a high order polynomial centered centered at the middle of the window of points.
- Parameters
window (int) – The length of the window. Must be an odd integer number
poly (int) – Order of the polynoial used in the filter. Should be less than window_size-1
deriv (int) – (optional) The order of the derivative to compute (default = 0 means only smoothing)
in_place (bool) – Option to update the data in place
- Returns
DataFrame containing the smoothed data
- Return type
pandas.DataFrame
- References
This code is an amalgamation of those developed in the scipy.org cookbook and that employed in Matlab by WeiFeng Chen. Original paper: A. Savitzky, M. J. E. Golay, Smoothing and Differentiation of Data by Simplified Least Squares Procedures. Analytical Chemistry, 1964, 36 (8), pp 1627-1639.
- snv(offset=0, in_place=True)¶
Implementation of the Standard Normal Variate (SNV) filter for Kipet which is a weighted normalization method that is commonly used to remove scatter effects in spectroscopic data, this pre-processing step can be applied before the SG filter or used on its own. SNV can be sensitive to noisy entries in the spectra and can increase nonlinear behaviour between S and C as it is not a linear transformation.
- Parameters
offset (float) – User-defined offset which can be used to avoid over-normalization for samples with near-zero standard deviation. Guide for choosing this value is for something near the expected noise level to be specified. Default value is zero.
in_place (bool) – Option to update the data in place
- Returns
DataFrame containing pre-processed data
- Return type
pandas.DataFrame
- msc(reference_spectra=None, in_place=True)¶
Implementation of the Multiplicative Scatter Correction (MSC) filter for Kipet which is simple pre-processing method that attempts to remove scaling effects and offset effects in spectroscopic data. This pre-processing step can be applied before the SG filter or used on its own. This approach requires a reference spectrum which must be determined beforehand. In this implementation, the default reference spectrum is the average spectrum of the dataset provided, however an optional argument exists for user-defined reference spectra to be provided.
- Parameters
reference_spectra (pandas.DataFrame) – Optional user-provided reference spectra argument. Default is to automatically determine this using the average spectra values
in_place (bool) – Option to update the data in place
- Returns
DataFrame pre-processed data
- Return type
pandas.DataFrame
- baseline_shift(shift=None, in_place=True)¶
Implementation of basic baseline shift. 2 modes are avaliable: 1. Automatic mode that requires no user arguments. The method identifies the lowest value (NOTE THAT THIS ONLY WORKS IF LOWEST VALUE IS NEGATIVE) and shifts the spectra up until this value is at zero. 2. Baseline shift provided by user. User provides the number that is added to every wavelength value in the full spectral dataset.
- Parameters
shift (float) – user-defined baseline shift
in_place (bool) – Option to update the data in place
- Returns
DataFrame containing pre-processed data
- Return type
pandas.DataFrame
- decrease_wavelengths(A_set=2, specific_subset=None, in_place=True)¶
Takes in the original, full dataset and removes specific wavelengths, or only keeps every multiple of A_set. Returns a new, smaller dataset that should be easier to solve
- Parameters
A_set (int) – optional user-provided multiple of wavelengths to keep. i.e. if 3, every third value is kept. Default is 2.
specific_subset (array-like) – (optional) If the user already knows which wavelengths they would like to remove, then a list containing these can be included.
param bool in_place: Option to update the data in place
- Returns
DataFrame with the smaller dataset
- Return type
- decrease_times(A_set=2, in_place=True)¶
Takes in the original, full dataset and removes specific wavelengths, or only keeps every multiple of A_set. Returns a new, smaller dataset that should be easier to solve
- Parameters
A_set (array-like) – optional user-provided multiple of wavelengths to keep. i.e. if 3, every third value is kept. Default is 2.
param bool in_place: Option to update the data in place
- Returns
DataFrame with the smaller dataset
- Return type
pandas.DataFrame