Using the model and choosing a solver#
Start from the example notebook and change its soil, climate or rock inputs for your scenario.
Prepare a simulation#
Use the same time grid for all inputs, with dt in days. The notebook
follows this order:
Set temperature and rainfall, then calculate potential evapotranspiration with
smew.hydroclimatic.Calculate vegetation with
smew.vegetation.veg()and soil moisture, infiltration and water losses withsmew.moisture.moisture_balance().Calculate soil organic carbon and respiration with
smew.organic_carbon.respiration().Set the initial chemistry with
smew.ic: usef_CEC_to_concwhen exchange fractions and pH are known, orconc_to_f_CECwhen dissolved concentrations and pH are known.Run
smew.biogeochem.biogeochem_balance()with the rock properties. The result contains time series such asresult["pH"],result["Alk"]andresult["M_rock"].
Choose the mode#
Python mode is useful for inspecting calculations and testing changes to an equation. Compiled mode runs faster for longer simulations or many scenarios. Both use the same equation source.
Put this before importing SMEW or Numba, in the first notebook cell or at the top of your script:
import os
# "1": Python mode for experiments; "0": compiled mode for speed.
os.environ["NUMBA_DISABLE_JIT"] = "1"
import smew
Restart the notebook kernel and run all cells after changing the setting;
for a script, start a new run. Without this setting, SMEW tries compiled mode.
If the native extensions are missing or cannot load, SMEW logs an error
with the original error and automatically uses Python/SciPy fsolve for
chemistry calculations. Other numerical helpers can still use Numba.
See Installation and builds for installation options.
The first compiled calculation in each Python session includes preparation time, so run it once before measuring execution speed.
Comparisons#
When comparing modes or equation changes, use the same temperature and
rainfall time series and allow for small rounding differences. The modes
generate random rainfall separately, so the same random seed alone does not
ensure identical rain. Check mass balances and sensitivity to dt as well
as whether the solver converges.
For warnings or failed calculations, see When a simulation fails.