calculation_tools

This module contains various methods for performing critical calcultaions in KIPET.

beer_lambert

diagnostic_tools

Diagnostic Tools used in Kipet

Note

These methods should be checked for usefulness and possibly removed

kipet.calculation_tools.diagnostic_tools.rank(A, eps=1e-10)

obtains the rank of a matrix based on SVD

Parameters
  • A (numpy.ndarray) – A numpy matrix

  • eps (float) – the value of the singular values that corresponds to 0 when smaller than eps. Default = 1e-10

Return rank

The rank of the matrix

Return type

int

kipet.calculation_tools.diagnostic_tools.nullspace(A, atol=1e-13, rtol=0)

Obtains the nullspace of a matrix based on SVD. Taken from the SciPy cookbook

If A is an array with shape (m, k), then ns will be an array

with shape (k, n), where n is the estimated dimension of the nullspace of A. The columns of ns are a basis for the nullspace; each element in numpy.dot(A, ns) will be approximately zero.

Parameters
  • A (numpy.ndarray) – A numpy matrix

  • atol (float) – The absolute tolerance for a zero singular value. Singular values smaller than atol are considered to be zero.

  • rtol (float) – The relative tolerance. Singular values less than rtol*smax are considered to be zero, where smax is the largest singular value.

Return ns

Return type

numpy.ndarray

kipet.calculation_tools.diagnostic_tools.basic_pca(dataFrame, n=None, with_plots=False)

Runs basic component analysis based on SVD

Parameters
  • dataFrame (pandas.DataFrame) – spectral data

  • n (int) – number of largest singular-values to plot

  • with_plots (bool) – Argument for files with plots due to testing

Returns

None

kipet.calculation_tools.diagnostic_tools.perform_data_analysis(dataFrame, pseudo_equiv_matrix, rank_data)

Runs the analysis by Chen, et al, 2018, based upon the pseudo-equivalency matrix. User provides the data and the pseudo-equivalency matrix and the analysis provides suggested number of absorbing components as well as whether there are likely to be unwanted spectral contributions.

Parameters
  • dataFrame (pandas.DataFrame) – Spectral data

  • pseudo_equiv_matrix (list) – List containing the rows of the pseudo-equivalency matrix.

  • rank_data (int) – Rank of the data matrix, as determined from SVD (number of coloured species)

  • with_plots (bool) – Argument for files with plots due to testing

Returns

None

helper

Top Level helper classes for KIPET

class kipet.calculation_tools.helper.AttrDict(*args, **kwargs)

This class lets you use nested dicts like accessing attributes using a dot notation

Methods
__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

update(*args, **kwargs)

Method used to update the AttrDict using the same syntax as the dict class

Parameters
  • args (tuple) – The arguments (pass through)

  • kwargs (dict) – The keyword arguments (pass through)

Returns

None

class kipet.calculation_tools.helper.DosingPoint(component, time, conc, vol)

Small class to handle the dosing points in a cleaner manner

Parameters
  • component (str) – The name of the model component

  • time (float) – The time of the dosing

  • conc (tuple) – A tuple of the concentration (conc (float), units (str))

  • vol (tuple) – A tuple of the dosing volume (vol (float), units (str))

Methods
__init__(component, time, conc, vol)

Initialize self. See help(type(self)) for accurate signature.

property as_list

Return the dosing attributes as a list

Returns

List of dosing point attributes

Return type

list

interpolation

This module contains functions for ensuring that variables have congruent time indicies.

For many users who may have delved into older versions of KIPET, these were formerly found in the PyomoSimulator and Simulator classes.

kipet.calculation_tools.interpolation.interpolate_trajectory(t, tr)

Method for interpolating trajectories

Parameters
  • t (list) – the list of times

  • tr (pandas.DataFrame) – The trajectory data

Return float tr_val

The interpolated value

kipet.calculation_tools.interpolation.interpolate_trajectory2(t, data)

Takes some data and fills in the missing points using interpolation

Parameters
  • t (float) – The time point

  • data (pandas.DataFrame) – The data to interpolate with

Return df_interpolated

The data after interpolation

Return type

pandas.DataFrame

prob_gen_tools

Problem Generation tools for Kipet

kipet.calculation_tools.prob_gen_tools.gaussian_single_peak(wl, alpha, beta, gamma)

Helper function to generate absorption data based on Lorentzian parameters

Parameters
  • wl (float) – Wavelength

  • beta (float) – Beta

  • alpha (float) – Alpha

  • gamma (float) – gamma

Returns

The single peak

Return type

float

kipet.calculation_tools.prob_gen_tools.absorbance(wl, alphas, betas, gammas)

Helper function to generate absorption data based on Lorentzian parameters

Parameters
  • wl (float) – Wavelength

  • betas (array-like) – Beta

  • alphas (array-like) – Alpha

  • gammas (array-like) – gamma

Returns

The sum of single peaks

Return type

float

kipet.calculation_tools.prob_gen_tools.generate_absorbance_data(wl_span, parameters_dict)

Helper function to generate absorption data based on Lorentzian parameters

Parameters
  • wl_span (array-like) – Array of wavelengths

  • parameters_dict (dict) – The dictionary of alphas, betas, and gammas

Returns

data_frame

Return type

pandas.DataFrame

kipet.calculation_tools.prob_gen_tools.generate_random_absorbance_data(wl_span, component_peaks, component_widths=None, seed=None)

Helper function to generate absorption data based on Lorentzian parameters

Parameters
  • wl_span (array-like) – Array of wavelengths

  • component_peaks (dict) – Dictionary with number of component peaks

  • component_widths (dict) – Optional widths for components (otherwise 1000)

  • seed (int) – Random seed number

Returns

data_frame

Return type

pandas.DataFrame

kipet.calculation_tools.prob_gen_tools.add_noise_to_signal(signal, size)

Adds a random normally distributed noise to a clean signal. Used mostly in Kipet To noise absorbances or concentration profiles obtained from simulations. All values that are negative after the noise is added are set to zero

Parameters
  • signal (pandas.DataFrame) – The Z or S matrix to have noise added to it

  • size (float) – sigma (or size of distribution)

Returns: :return: Noised data :rtype: pandas.DataFrame

reduced_hessian