oscarbranson / cbsyst Goto Github PK
View Code? Open in Web Editor NEWPython module for calculating carbon and boron solution chemistry.
License: MIT License
Python module for calculating carbon and boron solution chemistry.
License: MIT License
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
Relatively simple, needs to happen.
Trivial, but not done yet.
Thought: when is the most efficient place to do this?
At present, there are no options for different constants in cbsyst. Do people want/need choices?
Request constants in the comments below. If they get traction (i.e. lots of +1's), we'll implement them.
Constants as a function of Temperature and Salinity:
Pressure Corrections
All pressure correction parameters from Millero (2007), with modifications:
Conserved Seawater Compositions:
As a function of salinity:
Implement it... using uncertainties package?
This is low priority but would be nice.
Current incompatibility stems from repeated use of 'Extended Tuple Unpacking' (using *) in numerous function inputs throughout.
Can be solved with a generator wrapper (as described here).
Note: To run tests in python 2.x, you need to remove the python 2 incompatability warning in setup.py
cbsyst errors out when some inputs are set to None due to a bug in the current version of Kgen.
Steps to reproduce:
Install cbsyst
python3.10 -m venv .environment
source .environment/bin/activate
pip install cbsyst
Run a test
python
from cbsyst import Csys
result = Csys(pHtot=8.0,DIC=2000/1e6,unit="mol") // Produces error in kgen
Currently, input and output conditions are the same.
It would be good to be able to separate input/output T, S, P conditions.
This should be relatively simple and inexpensive, and involve a second call to MyAMI_get_Ks and re-calculating the final speciations.
Suggest wrapping this in a separate function which takes Ks, and outputs all conditions from a single parameter combination (e.g. DIC and H for Csys).
A lot of the solvers in carbon_fns.py would be sped up by vectorising.
At the moment, most serially apply zero_finder functions to solve for H.
The following functions in cbsyst/carbon_fns.py need to be vecotrised:
To fix deviation from GLODAPv2 at depth.
cbsyst
should not be used to calculate C system at different [Mg] and [Ca] conditions until this issue is resolved. Modern ocean calculations are unaffected by this problem.
Output of MyAMI_K_calc is incorrect at non-ambient [Ca] and [Mg] (c.v. sensitivies listed in Hain et al, 2015).
This is an underlying issue in MyAMI. Hain's original code produces different K values when using PyMyAMI.m compared to MyAMI_V1.py.
Main difference in code is that PyMyAMI.m calculates correction factor for experimental condition directly, while MyAMI_V1.py calculates a grid of corrected Ks at different (T,S) conditions, fits a K_conditional function to it, and then returns parameters to be used for K calculation across a temperature range. Uncertain why these produce different results.
Dear developers,
thank you for your help and your work!
I have following issue, when I am running the script(s).
partially initialized module 'cbsyst' has no attribute 'Bsys' (most likely due to a circular import)
Do you have any clou, how to solve that problem?
best regards, Matthias
Currently using CO2SYS method. Consider others:
After Orr et al (2015).
This is shelved for the moment - revisit later if it becomes an issue
At the moment, the Xsys functions can only take single combinations of input parameters.
It might be useful to allow for the calculation of multiple combinations of input combinations at once (a la CO2SYS.m).
However, algorithms currently identify parameters to be calculated by whether they are 'None' or not, so this would require a major re-tooling.
I reckon the effort involved here would be much greater than the inconvenience for the user having to run the function twice for different sets of input parameters.
How often do people actually use the ability of CO2SYS.m to take more than one combination of input parameters?
In the list of input from the Bsys or CBsys functions, the alphaB
parametre can be manually typed. However, this parametre is never really used. The ps
Bunch object is automatically updated using the alphaB_calc
function (dependant on temperature, based on the Hoenisch book) and simply ignores the alphaB
parametre (i.e. cbsyst.py, line 692 and 1037).
Would it be possible to make a simple statement checking if the alphaB
is given, and if not calculate it?
CO2 can become negative under high pH, high TA:
cb.Csys(pHtot=10.5, TA=2300).CO2
# array([-9.01237887e-06])
Csys hangs if pH is too high:
cb.Csys(pHtot=11, TA=2300)
# does not run
Suspect that slight negative trend in DIC predicted from TA and pH could be because of incorrect K temperature sensitivity.
Check this!
Current vectorised fsolve calls in carbon_fns produce incorrect values when multiple parameters are passed. Identified from Luecker et al (2000) test data. Unclear why.
Solution:
import cbsyst as cb
cb.Csys(pHtot=5., pCO2=300, T_in=26, S_in=33)
Yields a TA of -8.92526313.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.