Skip to content

Commit

Permalink
feat: Update version number to 0.14.0 with simplified
Browse files Browse the repository at this point in the history
gas exchange connections setup and documentation improvements
  • Loading branch information
uliw committed Jun 20, 2024
1 parent 904ce82 commit febaf48
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Changelog
- 0.14.0.x simplified the setup of the gas exchange connections, documentation improvements
- 0.13.0.8 added new testing framework, and 16 unit tests. Updated the documentation
- 0.13.0.7 the isotope fractionation factor has been renamed from =alpha= to =epsilon=
- 0.13.0.5 =tinmestep= keyword is now deprecated and should be replaced with =max_timestep=. =min_time_step= is now a configurable option.
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
1 Changelog
-----------

- 0.14.0.x simplified the setup of the gas exchange connections, documentation improvements

- 0.13.0.8 added new testing framework, and 16 unit tests. Updated the documentation

- 0.13.0.7 the isotope fractionation factor has been renamed from ``alpha`` to ``epsilon``
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
<img alt="Documentation Status" src="https://readthedocs.org/projects/esbmtk/badge/?version=latest" />
</a>

<a href="https://img.shields.io/badge/Python-3.11-blue.svg">
<img alt="Python 3.11 ready" src="https://www.python.org" />
</a>

<a href="https://doi.org/10.5281/zenodo.11959366">
<img alt=Zenodo DOI src="https://zenodo.org/badge/DOI/10.5281/zenodo.11959366.svg" alt="DOI"></a>


# ESBMTK - The Earth Sciences Box Modeling Toolkit

Expand Down
7 changes: 3 additions & 4 deletions docs/manual/manual-1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ which is easily encoded as a Python function
a function of time. After Glover 2011, Modeling
Methods for Marine Science.
:param C: tp.List of initial concentrations mol/m*3
:param C_0: tp.List of initial concentrations mol/m*3
:param time: array of time points
:params V: lits of surface and deep ocean volume [m^3]
:params V: list of surface and deep ocean volume [m^3]
:param F_w: River (weathering) flux of PO4 mol/s
:param thx: thermohaline circulation in m*3/s
:returns dCdt: tp.List of concentration changes mol/s
Expand Down Expand Up @@ -167,7 +167,6 @@ In the first step, one needs to define a model object that describes fundamental
ConnectionProperties, # the connection class
SourceProperties, # the source class
SinkProperties, # sink class
Q_, # Quantity operator
)
Next we use the :py:class:`esbmtk.esbmtk.Model()` class to create a model instance that defines basic model properties. Note that units are automatically translated into model units. While convenient, there are some important caveats:
Expand Down Expand Up @@ -208,7 +207,7 @@ Most ESBMTK classes accept quantities, strings that represent quantities as well
# boundary conditions
F_w = M.set_flux("45 Gmol", "year", M.P) # P @280 ppm (Filipelli 2002)
tau = Q_("100 year") # PO4 residence time in surface boxq
tau = Q_("100 year") # PO4 residence time in surface box
F_b = 0.01 # About 1% of the exported P is buried in the deep ocean
thc = "20*Sv" # Thermohaline circulation in Sverdrup
Expand Down
33 changes: 4 additions & 29 deletions docs/manual/manual-3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Apart from density, this class will provide access to a host of instance paramet
concentration_unit="mol/kg",
opt_k_carbonic=13, # Use Millero 2006
opt_pH_scale=1, # 1:total, 3:free scale
opt_buffers_mode=2, # carbonate, borate water alkalinity only
)
Caveats
Expand Down Expand Up @@ -217,40 +216,17 @@ ESBMTK implements gas exchange across the Air-Sea interface as a :py:class:`esbm
name="CO2_At",
species=M.CO2,
species_ppm="280 ppm",
register=M,
)
Species2Species( # Example for CO2
source=M.CO2_At, # GasReservoir
sink=M.L_b.DIC, # Reservoir
species=M.CO2,
ref_species=M.H_b.CO2aq,
solubility=M.H_b.swc.SA_co2,
area=M.L_b.area, # surface area
id="L_b_GEX", # connection id
piston_velocity="4.8 m/d",
water_vapor_pressure=M.H_b.swc.p_H2O,
register=M,
ctype="gasexchange",
id="L_b_GEX", # connection id
)
Defining gas transfer for O2 uses the same approach, but note the use of the ``solubility`` and ``ref_species`` keywords. At present, ESBMTK only carries the solubility constants for CO\ :sub:`2`\ and O\ :sub:`2`\.

.. code:: ipython
Species2Species( # Example for O2
source=M.O2_At, # GasReservoir
sink=M.L_b.O2, # Reservoir
species=M.O2,
ref_species=M.L_b.O2,
solubility=M._b.swc.SA_o2,
area=M._b.area,
piston_velocity="4.8 m/d",
water_vapor_pressure=M.L_b.swc.p_H2O,
id=f"O2_gas_exchange_L_b",
register=M,
ctype="gasexchange",
)
Defining gas transfer for O2 uses the same approach.

pCO\ :sub:`2`\ Dependent Weathering
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -271,11 +247,10 @@ where :math:`A` denotes the area, :math:`f_0` the weathering flux at :math:`p_{0
source=M.Fw.DIC, # source of flux
sink=M.L_b.DIC,
reservoir_ref=M.CO2_At, # pCO2
ctype="weathering",
id="wca",
scale=1, # optional, defaults to 1
ex=0.2, # exponent c
pco2_0="280 ppm", # reference pCO2
rate="12 Tmol/a", # rate at pco2_0
register=M,
ctype="weathering",
id="wca",
)
3 changes: 1 addition & 2 deletions tests/po4_1_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ConnectionProperties, # the connection class
SourceProperties, # the source class
SinkProperties, # sink class
Q_, # Quantity operator
)
# define the basic model parameters
M = Model(
Expand All @@ -19,7 +18,7 @@
tau * 12
# boundary conditions
F_w = M.set_flux("45 Gmol", "year", M.P) # P @280 ppm (Filipelli 2002)
tau = Q_("100 year") # PO4 residence time in surface boxq
tau = Q_("100 year") # PO4 residence time in surface box
F_b = 0.01 # About 1% of the exported P is buried in the deep ocean
thc = "20*Sv" # Thermohaline circulation in Sverdrup
# Source definitions
Expand Down
3 changes: 1 addition & 2 deletions tests/po4_2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ConnectionProperties, # the connection class
SourceProperties, # the source class
SinkProperties, # sink class
Q_, # Quantity operator
)
# define the basic model parameters
M = Model(
Expand All @@ -19,7 +18,7 @@
tau * 12
# boundary conditions
F_w = M.set_flux("45 Gmol", "year", M.P) # P @280 ppm (Filipelli 2002)
tau = Q_("100 year") # PO4 residence time in surface boxq
tau = Q_("100 year") # PO4 residence time in surface box
F_b = 0.01 # About 1% of the exported P is buried in the deep ocean
thc = "20*Sv" # Thermohaline circulation in Sverdrup
# Source definitions
Expand Down
17 changes: 9 additions & 8 deletions tests/test_pH.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from esbmtk import Model, Reservoir, get_hplus
import PyCO2SYS as pyco2


def test_manual_ph_calculation():
""" Test convergence of interative pH calculation
"""
"""Test convergence of interative pH calculation"""
M = Model(
stop="1 yr",
max_timestep="1 d",
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_manual_ph_calculation():
"S": 35,
},
)

hplus0 = M.S_b.swc.hplus
hplus = hplus0 * 10
for i in range(10):
Expand All @@ -52,11 +52,12 @@ def test_manual_ph_calculation():
M.S_b.swc.KW,
M.S_b.swc.KB,
)

assert abs(hplus0 - hplus) < 1e-12


def test_pyco2sys_ph_calculation():
""" Compare result of pH computation with the value
"""Compare result of pH computation with the value
provided by pyCO2sys
"""
M = Model(
Expand Down Expand Up @@ -97,15 +98,15 @@ def test_pyco2sys_ph_calculation():
temperature=M.S_b.swc.temperature,
pressure=M.S_b.swc.pressure * 10,
par1_type=1,
par1=M.S_b.TA.c[0] * 1E6,
par1=M.S_b.TA.c[0] * 1e6,
par2_type=2,
par2=M.S_b.DIC.c[0] * 1E6,
par2=M.S_b.DIC.c[0] * 1e6,
opt_k_carbonic=M.opt_k_carbonic,
opt_pH_scale=M.opt_pH_scale,
opt_buffers_mode=M.opt_buffers_mode,
)
results = pyco2.sys(**params)
pH = results['pH']
pH = results["pH"]

hplus0 = M.S_b.swc.hplus
hplus = hplus0 * 10
Expand Down
2 changes: 0 additions & 2 deletions tests/test_po4_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import po4_1_test # import script

M = po4_1_test.M # get model handle
tol = 1e-12 # tolerance

test_values = [ # result, reference value
(M.S_b.PO4.c[-1], 0.0000149597179598576),
(M.D_b.PO4.c[-1], 0.0000219990964241379),
Expand Down
3 changes: 0 additions & 3 deletions tests/test_po4_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
import po4_2_test # import script

M = po4_2_test.M # get model handle
tol = 1e-12 # tolerance

test_values = [ # result, reference value
(M.S_b.PO4.c[-1], 3.3378336265779095e-05),
(M.D_b.PO4.c[-1], 4.9100854586867445e-05),
]

# run tests
@pytest.mark.parametrize("test_input, expected", test_values)
def test_values(test_input, expected):
Expand Down
3 changes: 0 additions & 3 deletions tests/test_po4_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import po4_3_test # import script

M = po4_3_test.M # get model handle
tol = 1e-12 # tolerance

test_values = [ # result, reference value
(M.S_b.PO4.c[-1], 1.4999891897165636e-05),
(M.S_b.DIC.c[-1], 0.0015899885410995674),
(M.D_b.PO4.c[-1], 2.2058362084399994e-05),
(M.D_b.DIC.c[-1], 0.002338186380946409),
]

# run tests
@pytest.mark.parametrize("test_input, expected", test_values)
def test_values(test_input, expected):
Expand Down

0 comments on commit febaf48

Please sign in to comment.