<div align="right">
<a href="https://github.com/PalaeoCarb/MyAMI/actions/workflows/test-myami.yml"><img src="https://github.com/PalaeoCarb/MyAMI/workflows/Check%20MyAMI%20Performance/badge.svg" height=18></a>
<a href="https://pypi.org/project/pymyami"><img src="https://badge.fury.io/py/pymyami.svg" height=18></a>
</div>
# 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)](https://doi.org/10.1002/2014GB004986), which is available [here](https://github.com/MathisHain/MyAMI). 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)](https://doi.org/10.1002/2014GB004986), 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* (F<sub>X,MyAMI</sub>) that can be applied to adjust stoichiometric equilibrium constants for variations in seawater composition, following K<sub>X,corr</sub> = K<sub>X,empirical</sub> * F<sub>X,MyAMI</sub>. For the direct calculation of Ks, including the corrections calculated by `pymyami`, please see the [Kgen](https://github.com/PalaeoCarb/Kgen) project.
- **Available Ions**: `pymyami` allows the modification of any ion in the model, rather than just Mg and Ca: Na<sup>+</sup>, K<sup>+</sup>, Mg<sup>2+</sup>, Ca<sup>2+</sup>, Sr<sup>2+</sup>, Cl<sup>-</sup>, B(OH)<sub>4</sub><sup>-</sup>, HCO<sub>3</sub><sup>-</sup>, CO<sub>3</sub><sup>2-</sup> and SO<sub>4</sub><sup>2-</sup>.
- **Parameter Transparrency**: Wherever possible, parameter tables are now constructed on-the-fly from raw tables in the Appendix of [Millero & Pierrot, 1998](https://doi.org/10.1023/A:1009656023546), 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](https://github.com/PalaeoCarb/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 F<sub>X,MyAMI</sub> 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](https://github.com/PalaeoCarb/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)](https://doi.org/10.1002/2014GB004986), 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:
```python
pip install pymyami
```
## Example Usage
```python
from pymyami impor t calc_Fcorr, approximate_Fcorr
# run the model to calculate correction factors
calc_Fcorr(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_Fcorr(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)}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/PalaeoCarb/MyAMI",
"name": "pymyami",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Oscar Branson",
"author_email": "ob266@cam.ac.uk",
"download_url": "https://files.pythonhosted.org/packages/91/ca/b85f5f828d83f3dc56e78d8342a334263d13027b06f91ff69864ae10ae89/pymyami-2.0a6.tar.gz",
"platform": null,
"description": "<div align=\"right\">\n<a href=\"https://github.com/PalaeoCarb/MyAMI/actions/workflows/test-myami.yml\"><img src=\"https://github.com/PalaeoCarb/MyAMI/workflows/Check%20MyAMI%20Performance/badge.svg\" height=18></a>\n<a href=\"https://pypi.org/project/pymyami\"><img src=\"https://badge.fury.io/py/pymyami.svg\" height=18></a>\n</div>\n\n# MyAMI\nThe MyAMI Specific Ion Interaction Model for correcting stoichiometric equilibrium constants (*Ks*) for variations in seawater composition, made available available as the `pymyami` python package.\n\nThis package is a re-factor of the MyAMI model published by [Hain et al. (2015)](https://doi.org/10.1002/2014GB004986), which is available [here](https://github.com/MathisHain/MyAMI). The key differences between the original model and this package are:\n- **Speed**: All calculations have been vectorised using NumPy, making MyAMI 2-3 orders of magnitude faster.\n- **Direct Calculation**: `pymyami` directly calculates correction factors using the MyAMI model. This differs from [Hain et al. (2015)](https://doi.org/10.1002/2014GB004986), where the focus was on modifying parameters that could be input into the standard equations for calculating stoichiometric equilibrium products.\n- **Correction Factor Focus**: `pymyami` produces *corrections factors* (F<sub>X,MyAMI</sub>) that can be applied to adjust stoichiometric equilibrium constants for variations in seawater composition, following K<sub>X,corr</sub> = K<sub>X,empirical</sub> * F<sub>X,MyAMI</sub>. For the direct calculation of Ks, including the corrections calculated by `pymyami`, please see the [Kgen](https://github.com/PalaeoCarb/Kgen) project.\n- **Available Ions**: `pymyami` allows the modification of any ion in the model, rather than just Mg and Ca: Na<sup>+</sup>, K<sup>+</sup>, Mg<sup>2+</sup>, Ca<sup>2+</sup>, Sr<sup>2+</sup>, Cl<sup>-</sup>, B(OH)<sub>4</sub><sup>-</sup>, HCO<sub>3</sub><sup>-</sup>, CO<sub>3</sub><sup>2-</sup> and SO<sub>4</sub><sup>2-</sup>.\n- **Parameter Transparrency**: Wherever possible, parameter tables are now constructed on-the-fly from raw tables in the Appendix of [Millero & Pierrot, 1998](https://doi.org/10.1023/A:1009656023546), making the origin of parameters explicit.\n- **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](https://github.com/PalaeoCarb/Kgen) project provides a convenient interface to use `pymyami` in R and MATLAB.\n- **Approximation Method**: Where very fast calculations are required (e.g. Monte Carlo methods), `pymyami` uses a high-dimensional polynomial to approximate F<sub>X,MyAMI</sub> as a function of temperature, salinity, Mg and Ca. This is a very fast approximation, but is only accurate to within ~0.25%.\n\n## Kgen\n`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](https://github.com/PalaeoCarb/Kgen) project.\n\n## Consistency with Hain et al. (2015)\nThe K correction factors calculated by `pymyami` are similar to those calculated by the code of [Hain et al. (2015)](https://doi.org/10.1002/2014GB004986), although there are some notable deviations of up to 4%. A summary of maximum and average differences compared to Hain et al. (2015) follows:\n```\n K0: 0.00% max, 0.00% avg\n K1: 0.92% max, 0.05% avg\n K2: 3.77% max, -0.07% avg\n KW: 2.35% max, -0.42% avg\n KB: 0.92% max, 0.05% avg\n KspA: 1.87% max, 0.04% avg\n KspC: 1.87% max, 0.04% avg\n KS: 1.83% max, 0.10% avg\n```\nNote 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.\n\nThese differences arise from typo corrections in the original code, and pymyami should be closer to the original MIAMI model of Millerot and Pierrot (1998).\n\n## Installation\n\nThe model is available as a PyPI package, which can be installed by:\n\n```python\npip install pymyami\n```\n\n## Example Usage\n```python\nfrom pymyami impor t calc_Fcorr, approximate_Fcorr\n\n# run the model to calculate correction factors\ncalc_Fcorr(TempC=35, Sal=36.2, Mg=0.03, Ca=0.012)\n\n>>> {'KspC': 0.7843309390178521,\n 'KspA': 0.7843309390178521,\n 'K1': 1.002405617170862,\n 'K2': 0.7885093392132683,\n 'KW': 0.7459757009835559,\n 'KB': 0.9382494946753764,\n 'K0': 1.0056418412233974,\n 'KS': 0.9573891319238595}\n\n# use the polynomial approximation to calculate correction factors\napproximate_Fcorr(TempC=35, Sal=36.2, Mg=0.03, Ca=0.012)\n\n>>> 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.\n\n>>> {'K0': array(1.00565919),\n 'K1': array(1.00238861),\n 'K2': array(0.78858314),\n 'KB': array(0.93815884),\n 'KW': array(0.74594823),\n 'KspC': array(0.78442705),\n 'KspA': array(0.78442705),\n 'KS': array(0.95738293)}\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "MyAMI specific ion interaction model for calculating stoichiometric equilibrium constants in modified seawater.",
"version": "2.0a6",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "e85f9a6318cc3196790e22058d602b55",
"sha256": "8c84db80c14647a3f75e840386a394c24c53a179afbf71c34acca6425fa6fa96"
},
"downloads": -1,
"filename": "pymyami-2.0a6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e85f9a6318cc3196790e22058d602b55",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 1645422,
"upload_time": "2022-12-19T11:51:58",
"upload_time_iso_8601": "2022-12-19T11:51:58.405259Z",
"url": "https://files.pythonhosted.org/packages/f7/4d/6efabc6045832d90a36b7e8bf9e9ea7f379a53be92e8223d254b86248a23/pymyami-2.0a6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "9b9169d11e14ea219523e431592f277e",
"sha256": "2ad4eebab672487d49eadfac9e21dbeed953e4bc96fb0695102d64fea4636d16"
},
"downloads": -1,
"filename": "pymyami-2.0a6.tar.gz",
"has_sig": false,
"md5_digest": "9b9169d11e14ea219523e431592f277e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 1641225,
"upload_time": "2022-12-19T11:52:04",
"upload_time_iso_8601": "2022-12-19T11:52:04.602308Z",
"url": "https://files.pythonhosted.org/packages/91/ca/b85f5f828d83f3dc56e78d8342a334263d13027b06f91ff69864ae10ae89/pymyami-2.0a6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-19 11:52:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "PalaeoCarb",
"github_project": "MyAMI",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": []
},
{
"name": "pandas",
"specs": []
},
{
"name": "matplotlib",
"specs": []
},
{
"name": "scikit-learn",
"specs": []
},
{
"name": "scipy",
"specs": []
}
],
"lcname": "pymyami"
}