Skip to content

Time Lag Analysis Core Calculation Implementation

This document details the time_lag_analysis function within calculations.py, which implements the core calculations for time lag analysis. This function converts experimental permeation data into gas transport parameters.

Core Calculation Steps

The time_lag_analysis function implements four key computational steps:

  1. Linear Regression of Steady-State Data
  2. Time Lag Calculation
  3. Diffusion Coefficient Determination
  4. Permeability and Solubility Calculation

These steps form the analytical core of the time lag method (covered in 02-Theoretical-Background), following data preprocessing and stabilisation time detection (covered in 03-Data-Management-and-Processing).

Implementation in the time_lag_analysis Function

1. Linear Regression of Steady-State Data

First, the steady-state region of flux is filtered. This corresponds to a linear change of cumulative flux against time as seen in the plot in 02-Theoretical-Background.

# Filter to steady-state data
df_ss = df[df['t / s'] > stabilisation_time_s]

Next, the core calculation uses NumPy's polyfit function to perform linear regression on the filtered portion of the cumulative flux curve.

# Fitting straight line to the steady-state data
slope, intercept = np.polyfit(df_ss['t / s'], df_ss['cumulative flux / cm^3(STP) cm^-2'], 1)

This fits the data to the linear equation , where:

  • is the cumulative flux (cumulative flux / cm^3(STP) cm^-2)
  • is the time (t / s)
  • is the slope variable
  • is the intercept variable

The variables returned from polyfit have important physical meaning:

  • slope: Represents the steady-state flux through the membrane.
  • intercept: Represents the y-intercept of the extrapolated steady-state line. This is important for calculating the time lag.

2. Time Lag Calculation

The time lag is calculated by finding the x-intercept of the steady-state line by setting :

Rearranging for gives:

# Calculate time lag
time_lag = -intercept / slope   # [s]

3. Diffusion Coefficient Determination

The diffusion coefficient is calculated using the formula introduced in 02-Theoretical-Background:

# Calculate diffusion coefficient
diffusion_coefficient = thickness**2 / (6 * time_lag)   # [cm^2 s^-1]

4. Permeability and Solubility Calculation

The derived formulae in 02-Theoretical-Background is used to calculate permeability , solubility coefficient and solubility .

Permeability is calculed with:

where is the steady-state flux and is the pressure.

# Calculate permeability
permeability = thickness * slope / pressure   # [cm^3(STP) cm cm^-2 s^-1 bar^-1]

The solubility coefficient is calculted with:

# Calculate solubility coefficient
solubility_coefficient = permeability / diffusion_coefficient   # [cm^3(STP) cm^-3 bar^-1]

# Calculate solubility (concentration)
solubility = solubility_coefficient * pressure

Finally, the solubility can be calculated from:

# Calculate solubility (concentration)
solubility = solubility_coefficient * pressure