Using Kgen to Generate Cross-Verified Apparent Equilibrium Constants
(K∗) for Seawater Carbonate Chemistry
Abstract
The state of acid-base equilibria in solutions is calculated using
apparent equilibrium constants (K∗ ’s). The accuracy of these
K∗ ’s is critical for calculations of environmental chemistry,
for example the dissociation of dissolved CO2 in seawater. The
K∗ ’s required to calculate seawater carbonate chemistry are
described by empirically determined functions, which are implemented
within software packages used to calculate solution carbon speciation.
Each of these software packages uses its own implementation of these
K∗ calculations. This fragmented approach to K∗
calculation results in unintended and difficult to resolve
discrepancies between outputs calculated by different pieces of
software, particularly because of the empirical nature of the K∗
functions which are subject to revisions and improvements over time.
We present ‘Kgen’, a collection of software to consistently calculate
seawater K∗ ’s in Python, R, and Matlab. Kgen provides a nearly
identical interface for each language and, through use of a Continuous
Integration/Continuous Delivery (CI/CD) pipeline, guarantees
consistency between languages by automatically cross-checking results
from all three implementations. Unifying the approach to K∗
calculation in this way provides an extensible platform for
verifiable K∗ generation, which can be easily integrated into
existing carbon speciation calculators to improve consistency of
results.