Finite Source Simulation Code

Infinite Source Simulation Code

Utils

pnptransport.utils.evaluate_arrhenius(a0: float, Ea: float, temp: float) → float

Evaluate an Arrhenius variable

\[A = A_0 \exp\left( -\frac{E_{\mathrm{a}}}{k_{\mathrm{B}} T} \right)\]
Parameters:
  • a0 (float) – The exponential prefactor
  • Ea (float) – An activation energy in eV
  • temp (float) – The temperature
Returns:

x – The evaluated variable

Return type:

float

pnptransport.utils.fit_arrhenius(temperature_axis, y, **kwargs)

Fits the experimental data to an Arrhenius relationship

Parameters:
  • temperature_axis ([double]) – The temperature axis
  • y ([double]) – The dependent variable
  • **kwargs
    inverse_temp: boolean
    True if the units of the temperature are 1/T
    temp_units: string
    The units of the temperature. Valid units are K and °C
pnptransport.utils.format_pid_hhmmss_csv(path_to_csv: str)

This function process the input csv so that a column with the time in seconds is added based on the input time column in hh:mm:ss

Parameters:path_to_csv (str) – The pid csv file
pnptransport.utils.format_time_str(time_s: float)

Returns a formatted time string

Parameters:time_s (float) – The time in seconds
Returns:timeStr – A string representing the time
Return type:str
pnptransport.utils.geometric_series_spaced(max_val: float, min_delta: float, steps: int, reverse: bool = False, **kwargs) → numpy.ndarray

Produces an array of values spaced according to a geometric series

\[S_n = a + a r + a r^2 + ... + a r^{n-2} + a r^{n-1}\]

For which \(S_n = a (1-r^n) / (1-r)\)

Here, a is the minimum increment (min_delta) and n is the number of steps and r is determined using Newton’s method

Example:

import pnptransport.utils as utils

utils.geometric_series_spaced(max_val=3600, min_delta=1, steps=10)
# output:
# array([0.00000000e+00, 1.00000000e+00, 3.33435191e+00, 8.78355077e+00,
# 2.15038985e+01, 5.11976667e+01, 1.20513371e+02, 2.82320618e+02,
# 6.60035676e+02, 1.54175554e+03, 3.60000000e+03])
Parameters:
  • max_val (float) – The maximum value the series will take
  • min_delta (float) – The minimum delta value it will take
  • steps (int) – The number of values in the array
  • reverse (bool) – If true solve for r = 1 / p
  • **kwargs (keyword arguments) –
    n_iterations: int
    The number of Newton iterations to estimate r
Returns:

A vector with geometrically spaced values

Return type:

np.ndarray

pnptransport.utils.get_indices_at_values(x: numpy.array, requested_values: numpy.array) → numpy.ndarray

Constructs an array of valid indices in the x array corresponding to the requested values

Parameters:
  • x (np.array) – The array from which the indices will be drawn
  • requested_values (np.array) –
Returns:

An array with the indices corresponding to the requested values

Return type:

np.array

pnptransport.utils.latex_format(x, digits=2) → str

Creates a LaTeX string for matplotlib plots.

Parameters:
  • x (str) – The value to be formatted
  • digits (int) – The number of digits to round up to.
Returns:

The math-ready string

Return type:

str

pnptransport.utils.latex_format_with_error(num, err)

Parses a measurement quantity and it’s error as a LaTeX string to use in matplotlib texts.

Parameters:
  • num (float) – The measured quantity to parse
  • err (float) – The error associated error.
Returns:

The quantity and its error formatted as a LaTeX string

Return type:

str

pnptransport.utils.latex_order_of_magnitude(num: float, dollar=False)

Returns a LaTeX string with the order of magnitude of the number (10x)

Parameters:
  • num (float) – The number
  • dollar (bool) – If true, enclose string between $. Default False
Returns:

The LaTeX-format string with the order of magnitude of the number.

Return type:

str

pnptransport.utils.tau_c(D: float, E: float, L: float, T: float) → float

Estimates the characteristic constant for the Nernst-Planck equation in the low concentration approximation

\[\tau_c = \frac{L}{\mu E} + \frac{D}{\mu^2 E^2} \left[2 \pm \left( 1 + \frac{q E}{kT} L \right)^{1/2}\right]\]

Since \(\mu = qD/kT\)

\[\tau_c = \left( \frac{L}{D} \right) X + \left( \frac{1}{D} \right) X^2 \left[ 2 \pm \left( 1 + \frac{L}{X} \right)^{1/2} \right],\]

with \(X = kT/qE\)

When \(\mu E \tau_c\) is negligible, compared with the diffusive term \(2\sqrt{D\tau_c}\), it returns

\[\tau_c = \frac{L^2}{4D}\]
Parameters:
  • D (float) – The diffusion coefficient in cm2/s
  • E (float) – The electric field in MV/cm = 1E6 V/cm
  • L (float) – The distance in cm
  • T (float) – The temperature in °C
Returns:

The characteristic time in s

Return type:

float

Confidence Intervals Methods

pnptransport.confidence.confidence_interval(res: scipy.optimize.optimize.OptimizeResult, **kwargs)

This function estimates the confidence interval for the optimized parameters from the fit.

Parameters:
  • res (OptimizeResult) – The optimized result from least_squares minimization
  • **kwargs
    confidence: float
    The confidence level (default 0.95)
Returns:

ci: The confidence interval

Return type:

np.ndarray

pnptransport.confidence.confint(n: int, pars: numpy.ndarray, pcov: numpy.ndarray, confidence: float = 0.95, **kwargs)

This function returns the confidence interval for each parameter

Parameters:
  • n (int) – The number of data points
  • pars (np.ndarray) – The array with the fitted parameters
  • pcov (np.ndarray) – The covariance matrix
  • confidence (float) – The confidence interval
Returns:

The matrix with the confindence intervals for the parameters

Return type:

np.ndarray

pnptransport.confidence.get_rsquared(x: numpy.ndarray, y: numpy.ndarray, popt: numpy.ndarray, func: Callable[[numpy.ndarray, numpy.ndarray], numpy.ndarray])

This function estimates R2 for the fitting

Reference:
http://bagrow.info/dsv/LEC10_notes_2014-02-13.html
Parameters:
  • x (np.ndarray) – The experimetnal x points
  • y (np.ndarray) – The experimental y points
  • popt (np.ndarray) – The best fit parameters
  • func (Callable[[np.ndarray, np.ndarray]) – The fitted function
Returns:

The value of R2

Return type:

float

pnptransport.confidence.mean_squared_error(yd: numpy.ndarray, ym: numpy.ndarray)

This function estimates the mean squared error of a fitting.

Parameters:
  • yd (np.ndarray) – The observed data points
  • ym (np.ndarray) – The datapoints from the model
Returns:

The mean squared error

Return type:

float

pnptransport.confidence.predband(x: numpy.ndarray, xd: numpy.ndarray, yd: numpy.ndarray, p: numpy.ndarray, func: Callable[[numpy.ndarray, numpy.ndarray], numpy.ndarray], conf: float = 0.95)

This function estimates the prediction bands for the specified function without using the jacobian of the fit https://codereview.stackexchange.com/questions/84414/obtaining-prediction-bands-for-regression-model

Parameters:
  • x (np.ndarray) – The requested data points for the prediction bands
  • xd (np.ndarray) – The experimental values for x
  • yd (np.ndarray) – The experimental values for y
  • p (np.ndarray) – The fitted parameters
  • func (Callable[[np.ndarray, np.ndarray], np.ndarray]) – The optimized function
  • conf (float) – The confidence level
Returns:

  • np.ndarray – The value of the function at the requested points (x)
  • np.ndarray – The lower prediction band
  • np.ndarray – The upper prediction band

pnptransport.confidence.predint(x: numpy.ndarray, xd: numpy.ndarray, yd: numpy.ndarray, func: Callable[[numpy.ndarray, numpy.ndarray], numpy.ndarray], res: scipy.optimize.optimize.OptimizeResult, **kwargs)

This function estimates the prediction bands for the fit (see https://www.mathworks.com/help/curvefit/confidence-and-prediction-bounds.html)

Parameters:
  • x (np.ndarray) – The requested x points for the bands
  • xd (np.ndarray) – The x datapoints
  • yd (np.ndarray) – The y datapoints
  • func (Callable[[np.ndarray, np.ndarray]) – The fitted function
  • res (OptimizeResult) – The optimzied result from least_squares minimization
  • kwargs (dict) –
    confidence: float
    The confidence level (default 0.95)
    simulateneous: bool
    True if the bound type is simultaneous, false otherwise
    mode: [functional, observation]
    Default observation
pnptransport.confidence.predint_multi(x: numpy.ndarray, xd: numpy.ndarray, yd: numpy.ndarray, func: Callable[[numpy.ndarray, numpy.ndarray], numpy.ndarray], res: scipy.optimize.optimize.OptimizeResult, **kwargs)

This function estimates the prediction bands for the fit

(See https://www.mathworks.com/help/curvefit/confidence-and-prediction-bounds.html)

Parameters:
  • x (np.ndarray) – The requested x points for the bands
  • xd (np.ndarray) – The x datapoints
  • yd (np.ndarray) – The y datapoints
  • func (Callable[[np.ndarray, np.ndarray]) – The fitted function
  • res (OptimizeResult) – The optimzied result from least_squares minimization
  • kwargs (dict) –
    confidence: float
    The confidence level (default 0.95)
    simultaneous: bool
    True if the bound type is simultaneous, false otherwise
    mode: [functional, observation]
    Default observation
Returns:

  • np.ndarray – The predicted values.
  • np.ndarray – The lower bound for the predicted values.
  • np.ndarray – The upper bound for the predicted values.

Transport HD5 Storage System

HD5 Storage