Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarbranson committed Sep 14, 2023
2 parents c71623e + 5608f8e commit 72e2c61
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cbsyst/__init__.py
Expand Up @@ -2,4 +2,4 @@
from cbsyst.helpers import data_out, Bunch, pH_scale_converter
from kgen import calc_Ks

VERSION = '0.4.8'
VERSION = '0.4.9'
22 changes: 11 additions & 11 deletions cbsyst/cbsyst.py
Expand Up @@ -17,10 +17,10 @@ def Csys(
CO2=None, HCO3=None, CO3=None,
pCO2=None, fCO2=None,
BT=None,
Ca=None, Mg=None,
Ca=0.0102821, Mg=0.0528171,
T_in=25.0, T_out=None,
S_in=35.0, S_out=None,
P_in=None, P_out=None,
P_in=0.0, P_out=None,
PT=0.0, SiT=0.0,
ST=None, FT=None,
pHsws=None, pHfree=None, pHNBS=None,
Expand Down Expand Up @@ -261,9 +261,9 @@ def Bsys(
alphaB=None,
T_in=25.0,
S_in=35.0,
P_in=None,
Ca=None,
Mg=None,
P_in=0.0,
Ca=0.0102821,
Mg=0.0528171,
ST=None,
FT=None,
pHsws=None,
Expand Down Expand Up @@ -429,9 +429,9 @@ def ABsys(
alphaB=None,
T_in=25.0,
S_in=35.0,
P_in=None,
Ca=None,
Mg=None,
P_in=0.0,
Ca=0.0102821,
Mg=0.0528171,
ST=None,
FT=None,
pHsws=None,
Expand Down Expand Up @@ -599,12 +599,12 @@ def CBsys(
alphaB=None,
T_in=25.0,
S_in=35.0,
P_in=None,
P_in=0.0,
T_out=None,
S_out=None,
P_out=None,
Ca=None,
Mg=None,
Ca=0.0102821,
Mg=0.0528171,
PT=0.0,
SiT=0.0,
ST=None,
Expand Down
26 changes: 16 additions & 10 deletions cbsyst/helpers.py
Expand Up @@ -32,7 +32,10 @@ def data_out(cbdat, path=None, include_constants=False):
"""

cols = [
"pH",
"pHtot",
"pHfree",
"pHsws",
"pHNBS",
"DIC",
"fCO2",
"pCO2",
Expand All @@ -49,33 +52,36 @@ def data_out(cbdat, path=None, include_constants=False):
"ABT",
"ABO3",
"ABO4",
"T",
"S",
"P",
"T_in",
"S_in",
"P_in",
"T_out",
"S_out",
"P_out",
"Ca",
"Mg",
]

consts = ["K0", "K1", "K2", "KB", "KW", "KS", "KspA", "KspC"]

size = cbdat.pH.size
size = cbdat.pHtot.size
out = pd.DataFrame(index=range(size))

for c in cols:
if c in cbdat and cbdat[c] is not None:
if (np.ndim(cbdat[c]) == 1) & (cbdat[c].size == 1):
if (np.ndim(cbdat[c]) == 1) and (cbdat[c].size == 1):
cbdat[c] = cbdat[c][0]
if c in cbdat:
out.loc[:, c] = cbdat[c]

if include_constants:
for c in consts:
if c in cbdat.Ks and cbdat.Ks[c] is not None:
if (np.ndim(cbdat.Ks[c]) == 1) & (cbdat.Ks[c].size == 1):
if (np.ndim(cbdat.Ks[c]) == 1) and (cbdat.Ks[c].size == 1):
cbdat.Ks[c] = cbdat.Ks[c][0]
out.loc[:, "p" + c] = -np.log10(cbdat.Ks[c])
if "alphaB" in cbdat and cbdat.alphaB is not None:
if (np.ndim(cbdat.alphaB) == 1) & (cbdat.alphaB.size == 1):
if (np.ndim(cbdat.alphaB) == 1) and (cbdat.alphaB.size == 1):
cbdat.alphaB = cbdat.alphaB[0]
out.loc[:, "alphaB"] = cbdat.alphaB

Expand Down Expand Up @@ -369,12 +375,12 @@ def pH_scale_converter(pH, scale, Temp, Sal, Press=None, ST=None, FT=None):
FT = calc_FT(Sal)
TempK = Temp + 273.15

Ks = kgen.calc_Ks(TempC=Temp, Sal=Sal, Pres=Press)
Ks = Bunch(kgen.calc_Ks(temp_c=Temp, sal=Sal, p_bar=Press))

inp = [None, None, None, None]
inp[np.argwhere(scale == np.array(pH_scales))[0, 0]] = pH

return calc_pH_scales(*inp, TS, FT, TempK, Sal, Ks)
return calc_pH_scales(*inp, ST, FT, TempK, Sal, Ks)


# TODO: function that correct pH for temperature
Expand Down

0 comments on commit 72e2c61

Please sign in to comment.