oscarbranson / cbsyst

Python module for calculating carbon and boron solution chemistry.
MIT License
29 stars 17 forks source link

Error when using Bsys function #23

Closed douglascoenen closed 3 years ago

douglascoenen commented 3 years ago

Hello, Firstly, thank you very much for this great work! I have quickly compared the outputs to pyCO2sys and not only is a near 1:1, it is also about 100 times faster! Amazing!

However, I ran into a small issue when trying to execute the given example in the README. cbsyst.Csys and cbsyst.CBsys appear to run just fine, but when I try to run the following from you example:

  import cbsyst as cb
  import numpy as np

  pH = np.linspace(7,11,100)
  Bsw = cb.Bsys(pHtot=pH, BT=433., dBT=39.5)

It gives me the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/cbsyst/cbsyst.py", line 324, in Bsys
    ps.update(ABsys(pdict=ps))
  File "/usr/local/lib/python3.8/dist-packages/cbsyst/cbsyst.py", line 435, in ABsys
    ps.alphaB = alphaB_calc(ps.T)
AttributeError: 'Bunch' object has no attribute 'T'

So I went in the ABsys function and printed the Bunch object just before this line and found that there was indeed no attribute "T", but instead there was "T_in". So if I change the line from what it was to:

ps.alphaB = alphaB_calc(ps.T_in)

It works, but then the same kind of error arises when hitting this loop:

for k in ['ABO3', 'ABO4', 'ABT', 'Ca',
              'H', 'Mg', 'S', 'T', 'alphaB',
              'dBO3', 'dBO4', 'dBT', 'pHtot']:
        if not isinstance(ps[k], np.ndarray):
            ps[k] = np.array(ps[k], ndmin=1)

As in the current Bunch, there is no T and S, but T_in and S_in. So if you change them to give:

for k in ['ABO3', 'ABO4', 'ABT', 'Ca',
              'H', 'Mg', 'S_in', 'T_in', 'alphaB',
              'dBO3', 'dBO4', 'dBT', 'pHtot']:
        if not isinstance(ps[k], np.ndarray):
            ps[k] = np.array(ps[k], ndmin=1)

Then it works flawlessly. I do not know if it wise to change it like this, because I do not know how you treat the "in" and "out" of the physical properties of water samples. That is why I posted it here.

By the way, I run python 3.8.5.

Thanks, Douglas