cbsyst

Python module for calculating carbon and boron solution chemistry.

https://github.com/oscarbranson/cbsyst

Science Score: 59.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    2 of 6 committers (33.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.3%) to scientific vocabulary

Keywords

boron carbon isotope ocean oceanography python
Last synced: 5 months ago · JSON representation

Repository

Python module for calculating carbon and boron solution chemistry.

Basic Info
  • Host: GitHub
  • Owner: oscarbranson
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 26.9 MB
Statistics
  • Stars: 29
  • Watchers: 12
  • Forks: 18
  • Open Issues: 14
  • Releases: 11
Topics
boron carbon isotope ocean oceanography python
Created over 8 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog Contributing

README.md

GHA PyPI version conda-forge version DOI
CBsyst

A Python module for calculating seawater carbon and boron chemistry.

This will be particularly useful for anyone thinking about oceans in the distant past, when Mg and Ca concentrations were different. I use Mathis Hain's MyAMI model to adjust speciation constants for Mg and Ca concentration.

**Tested* in the modern ocean against GLODAPv2 data (see below). Performs as well as Matlab CO2SYS.*

Work in Progress:

If anyone wants to help with any of this, please do contribute! A full list of bite-sized tasks that need doing is available on the Issues page.

Acknowledgement

The development of cbsyst has been greatly aided by CO2SYS, and the Matlab conversion of CO2SYS. In particular, these programs represent a gargantuan effort to find the most appropriate coefficient formulations and parameterisations from typo-prone literature. CO2SYS has also provided an invaluable benchmark throughout development.

Data Comparison

I have used the GLODAPv2 data set to test how well cbsyst works with modern seawater.

Method:

Import the entire GLODAPv2 data set, remove all data where flag != 2 (2 = good data), and exclude all rows that don't have all of (salinity, temperature, pressure, tco2, talk, phosphate, silicate and phtsinsitutp) - i.e. salinity, temperature, pressure, nutrients and all three measured carbonate parameters. The resulting dataset contains 79,896 bottle samples. The code used to process the raw GLODAPv2 data is available here.

Next, calculate the carbonate system from sets of two of the measured carbonate parameters, and compare the calculated third parameter to the measured third parameter (i.e. calculate Alkalinity from pH and DIC, then compared calculated vs. measured Alkalinities). The code for making these comparison plots is here.

Results:

Calculated pH (from DIC and Alkalinity) is offset from measured values by -0.00061 (-0.029/+0.029). Calculated vs Measured pH

Calculated Alkalinity (from pH and DIC) is offset from measured values by 0.23 (-12/+11) umol/kg. Calculated vs Measured TA

Calculated DIC (from pH and Alkalinity) is offset from measured values by -0.22 (-11/+11) umol/kg. Calculated vs Measured DIC

Reported statistics are median ±95% confidence intervals extracted from the residuals (n = 79,896).

Data are idential to within rouding errors as values calculated by Matlab CO2SYS (v1.1).

Conclusions:

cbsyst does a good job of fitting the GLODAPv2 dataset!

Technical Details

Constants

Constants calculated by an adaptation of Mathis Hain's MyAMI model. The original MyAMI code is available on GitHub. A stripped-down version of MyAMI is packaged with cbsyst. It has been modified to make it faster (by vectorising) and more 'Pythonic'. All the Matlab interface code has been removed.

Constants not provided by MyAMI (KP1, KP2, KP3, KSi, KF) are formulated following Dickson, Sabine & Christian's (2007) 'Guide to best practices for ocean CO2 measurements.'.

Pressure corrections are applied to the calculated constants following Eqns. 38-40 of Millero et al (2007), using (typo-corrected) constants in their Table 5. All constants are on the pH Total scale.

Calculations

Speciation calculations follow Zeebe and Wolf-Gladrow (2001). Carbon speciation calculations are described in Appendix B, except where Alkalinity is involved, in which cases the formulations of Ernie Lewis' CO2SYS are used. Boron speciation calculations in Eqns. 3.4.43 - 3.4.46.

Boron isotopes are calculated in terms of fractional abundances instead of delta values, as outlines here. Delta values can be provided as an input, and are given as an output.

Installation

Requires Python 3.5+. Does not work in 2.7. Sorry.

PyPi

bash pip install cbsyst

Conda-Forge

bash conda install cbsyst -c conda-forge

Example Usage

```python import cbsyst as cb import numpy as np

Create pH master variable for demo

pH = np.linspace(7,11,100) # pH on Total scale

Example Usage

-------------

The following functions can be used to calculate the

speciation of C and B in seawater, and the isotope

fractionation of B, given minimal input parameters.

See the docstring for each function for info on

required minimal parameters.

Carbon system only

Csw = cb.Csys(pHtot=pH, DIC=2000.)

Boron system only

Bsw = cb.Bsys(pHtot=pH, BT=433., dBT=39.5)

Carbon and Boron systems

CBsw = cb.CBsys(pHtot=pH, DIC=2000., BT=433., dBT=39.5)

NOTE:

At present, each function call can only be used to

calculate a single minimal-parameter combination -

i.e. you can't pass it multiple arrays of parameters

with different combinations of parameters, as in

the Matlab CO2SYS code.

Example Output

--------------

The functions return a Bunch (modified dict with '.'

attribute access) containing all system parameters

and constants.

Output for a single input condition shown for clarity:

out = cb.CBsys(pHtot=8.1, DIC=2000., BT=433., dBT=39.5) out

{'ABO3': array([ 0.80882931]), 'ABO4': array([ 0.80463763]), 'ABT': array([ 0.80781778]), 'BO3': array([ 328.50895695]), 'BO4': array([ 104.49104305]), 'BT': array([ 433.]), 'CO2': array([ 9.7861814]), 'CO3': array([ 238.511253]), 'Ca': array([ 0.0102821]), 'DIC': array([ 2000.]), 'H': array([ 7.94328235e-09]), 'HCO3': array([ 1751.7025656]), 'Ks': {'K0': array([ 0.02839188]), 'K1': array([ 1.42182814e-06]), 'K2': array([ 1.08155475e-09]), 'KB': array([ 2.52657299e-09]), 'KS': array([ 0.10030207]), 'KW': array([ 6.06386369e-14]), 'KspA': array([ 6.48175907e-07]), 'KspC': array([ 4.27235093e-07])}, 'Mg': array([ 0.0528171]), 'S': array([ 35.]), 'T': array([ 25.]), 'TA': array([ 2333.21612227]), 'alphaB': array([ 1.02725]), 'dBO3': array([ 46.30877684]), 'dBO4': array([ 18.55320208]), 'dBT': array([ 39.5]), 'deltas': True, 'fCO2': array([ 344.68238018]), 'pCO2': array([ 345.78871573]), 'pHtot': array([ 8.1]), 'pdict': None}

All of the calculated output arrays will be the same length as the longest

input array.

Access individual parameters by:

out.CO3

array([ 238.511253])

Output data for external use:

df = cb.dataout(out, 'exampleexport.csv')

This returns a pandas.DataFrame object with all C and B parameters.

It also saves the data to the specified file. The extension of the

file determined the format it is saved in (see data_out docstring).

```

Technical Note: Whats is a Bunch?

For code readability and convenience, I've used Bunch objects instead of traditional dicts. A Bunch is a modification of a dict, which allows attribute access via the dot (.) operator. Apart from that, it works exactly like a normal dict (all the usual methods are available transparrently).

Example: ```python from cbsyst.helpers import Bunch

Make a bunch

bun = Bunch({'a': 1, 'b': 2})

Access items of bunch...

as a dict:

bun['a']

1

as a Bunch:

bun.a

1 ```

Owner

  • Name: Oscar
  • Login: oscarbranson
  • Kind: user
  • Location: Cambridge, UK
  • Company: University of Cambridge

Scientist studying biomineral formation, ocean chemistry and climate. Coding is a tool, forgive my transgressions.

GitHub Events

Total
  • Create event: 2
  • Issues event: 2
  • Release event: 2
  • Delete event: 1
  • Push event: 14
  • Fork event: 1
Last Year
  • Create event: 2
  • Issues event: 2
  • Release event: 2
  • Delete event: 1
  • Push event: 14
  • Fork event: 1

Committers

Last synced: 6 months ago

All Time
  • Total Commits: 428
  • Total Committers: 6
  • Avg Commits per committer: 71.333
  • Development Distribution Score (DDS): 0.227
Past Year
  • Commits: 5
  • Committers: 1
  • Avg Commits per committer: 5.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Oscar Branson o****n@g****m 331
Oscar Branson o****6@c****k 77
rossidae r****1@s****k 10
Filipe Fernandes o****f@g****m 8
Douglas Coenen d****n@y****r 1
danielgaskell 4****l@u****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 26
  • Total pull requests: 14
  • Average time to close issues: 6 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 4
  • Total pull request authors: 5
  • Average comments per issue: 1.08
  • Average comments per pull request: 1.29
  • Merged pull requests: 12
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • oscarbranson (22)
  • douglascoenen (2)
  • matthiasbirkich (1)
  • rossidae (1)
Pull Request Authors
  • oscarbranson (6)
  • rossidae (4)
  • ocefpaf (3)
  • douglascoenen (1)
  • danielgaskell (1)
Top Labels
Issue Labels
enhancement (8) bug (4) low-priority (2) fatal (1)
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 106 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 1
    (may contain duplicates)
  • Total versions: 34
  • Total maintainers: 1
proxy.golang.org: github.com/oscarbranson/cbsyst
  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago
pypi.org: cbsyst

Tools for calculating ocean C and B chemistry.

  • Versions: 18
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 106 Last month
Rankings
Dependent packages count: 7.3%
Forks count: 9.4%
Stargazers count: 12.7%
Average: 14.4%
Downloads: 20.4%
Dependent repos count: 22.1%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: cbsyst
  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 34.0%
Forks count: 36.7%
Average: 41.6%
Stargazers count: 44.6%
Dependent packages count: 51.2%
Last synced: 6 months ago

Dependencies

.github/workflows/tests.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
requirements.txt pypi
  • kgen >=0.0.2
  • numpy >=1.13
  • pandas >=0.19
  • scipy >=0.18
  • tqdm >=4.14
  • uncertainties >=3.0
setup.py pypi