Skip to main content

MyAMI specific ion interaction model for calculating stoichiometric equilibrium constants in modified seawater.

Project description

MyAMI

The MyAMI Specific Ion Interaction Model for correcting stoichiometric equilibrium constants (Ks) for variations in seawater composition, made available available as the pymyami python package.

This package is a re-factor of the MyAMI model published by Hain et al. (2015), which is available here. The key differences between the original model and this package are:

  • Speed: All calculations have been vectorised using NumPy, making MyAMI 2-3 orders of magnitude faster.
  • Direct Calculation: pymyami directly calculates correction factors using the MyAMI model. This differs from Hain et al. (2015), where the focus was on modifying parameters that could be input into the standard equations for calculating stoichiometric equilibrium products.
  • Correction Factor Focus: pymyami produces corrections factors (FX,MyAMI) that can be applied to adjust stoichiometric equilibrium constants for variations in seawater composition, following KX,corr = KX,empirical * FX,MyAMI. For the direct calculation of Ks, including the corrections calculated by pymyami, please see the Kgen project.
  • Available Ions: pymyami allows the modification of any ion in the model, rather than just Mg and Ca: Na+, K+, Mg2+, Ca2+, Sr2+, Cl-, B(OH)4-, HCO3-, CO32- and SO42-.
  • Parameter Transparrency: Wherever possible, parameter tables are now constructed on-the-fly from raw tables in the Appendix of Millero & Pierrot, 1998, making the origin of parameters explicit.
  • Pure Python: There is no longer interface code for interacting with other languages (i.e. MATLAB). This caused a substantial performance bottleneck, and is discouraged. The Kgen project provides a convenient interface to use pymyami in R and MATLAB.
  • Approximation Method: Where very fast calculations are required (e.g. Monte Carlo methods), pymyami uses a high-dimensional polynomial to approximate FX,MyAMI as a function of temperature, salinity, Mg and Ca. This is a very fast approximation, but is only accurate to within ~0.25%.

Kgen

pymyami only calculations correction factors that can be applied to stoichiometric equilibrium constants (Ks). If you are looking for a convenient way to adjust Ks for variations in seawater composition, please see the Kgen project.

Consistency with Hain et al. (2015)

The K correction factors calculated by pymyami are similar to those calculated by the code of Hain et al. (2015), although there are some notable deviations of up to 4%. A summary of maximum and average differences compared to Hain et al. (2015) follows:

  K0: 0.00% max, 0.00% avg
  K1: 0.92% max, 0.05% avg
  K2: 3.77% max, -0.07% avg
  KW: 2.35% max, -0.42% avg
  KB: 0.92% max, 0.05% avg
  KspA: 1.87% max, 0.04% avg
  KspC: 1.87% max, 0.04% avg
  KS: 1.83% max, 0.10% avg

Note that maximum deviations are seen when the change in Mg and Ca correlates, meaning that these deviations shouldn't be too important for palaeo-seawater calculations because the concentration of Mg and Ca tend to be anti-correlated through geological history.

These differences arise from typo corrections in the original code, and pymyami should be closer to the original MIAMI model of Millerot and Pierrot (1998).

Installation

The model is available as a PyPI package, which can be installed by:

pip install pymyami

Example Usage

from pymyami import calculate_seawater_correction, approximate_seawater_correction

# run the model to calculate correction factors
calculate_seawater_correction(TempC=35, Sal=36.2, Mg=0.03, Ca=0.012)

>>> {'KspC': 0.7843309390178521,
     'KspA': 0.7843309390178521,
     'K1': 1.002405617170862,
     'K2': 0.7885093392132683,
     'KW': 0.7459757009835559,
     'KB': 0.9382494946753764,
     'K0': 1.0056418412233974,
     'KS': 0.9573891319238595}

# use the polynomial approximation to calculate correction factors
approximate_seawater_correction(TempC=35, Sal=36.2, Mg=0.03, Ca=0.012)

>>> UserWarning: WARNING: using approximate MyAMI K correction factors instead of calculated ones. These are only accurate to within ~0.25%. Please dont use them for anything critical.

>>> {'K0': array(1.00565919),
     'K1': array(1.00238861),
     'K2': array(0.78858314),
     'KB': array(0.93815884),
     'KW': array(0.74594823),
     'KspC': array(0.78442705),
     'KspA': array(0.78442705),
     'KS': array(0.95738293)}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymyami-2.1.0.tar.gz (4.7 MB view details)

Uploaded Source

Built Distribution

pymyami-2.1.0-py3-none-any.whl (5.9 MB view details)

Uploaded Python 3

File details

Details for the file pymyami-2.1.0.tar.gz.

File metadata

  • Download URL: pymyami-2.1.0.tar.gz
  • Upload date:
  • Size: 4.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pymyami-2.1.0.tar.gz
Algorithm Hash digest
SHA256 e5b3111cbb4fbc7bcb351472ff88c4e9a81e5ff8b9ebdd951c36e1bd0c0fb767
MD5 639d4a4d3dfe019d1f281a0208537991
BLAKE2b-256 a48142d4ec32a34b4dcb45a4864835c7ec2e176564e763a81088d6a2389dc952

See more details on using hashes here.

File details

Details for the file pymyami-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: pymyami-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pymyami-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7089e33ba1912c67e2a846a8c53267b9b4a7f859cfcddb91d459db76fc4447b9
MD5 0079513828a3a6c8ea53ad03edd81881
BLAKE2b-256 aec87ff09631ef8146e45322f0bc96912049fffec82cb65ad5deb56544a17568

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page