Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.4"
rev: v0.15.15
hooks:
- id: ruff
args: [--fix, --show-fixes]
types_or: [python]
- id: ruff-check
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
11 changes: 9 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The current implementation has been developed in Python 3 and tested on Windows,
Installation/Usage:
*******************

EVo can be used through local installation, either through a CLI or as a library.
EVo can be used through local installation, either through a CLI, as a library, or with a webapp.

To install locally, EVo must be downloaded from GitHub using
::
Expand All @@ -19,7 +19,7 @@ into the project directory where you wish to use EVo. EVo must then be locally p
::

cd EVO
python -m pip install .
python -m pip install ".[streamlit]"

From this point, EVo can either be imported into your python scripts as a regular module using
::
Expand All @@ -37,6 +37,13 @@ Or EVo can be run directly from the terminal from inside the `evo` directory:
cd EVO/evo
python dgs.py input/chem.yaml input/env.yaml --output input/output.yaml

Alternatively you can interact with EVo using the webapp interface, by running:
::

cd EVO/webapp
streamlit run streamlit-app.py


.. toctree::
:maxdepth: 2
:caption: Contents:
Expand Down
97 changes: 59 additions & 38 deletions examples/evo_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"import evo\n",
"import evo.plots as evoplots"
]
Expand All @@ -47,18 +48,20 @@
"metadata": {},
"outputs": [],
"source": [
"composition = pd.Series({\n",
" \"SIO2\": 47.95,\n",
" \"TIO2\": 1.67,\n",
" \"AL2O3\": 17.32,\n",
" \"FEO\": 10.24,\n",
" \"MNO\": 0.17,\n",
" \"MGO\": 5.76,\n",
" \"CAO\": 10.93,\n",
" \"NA2O\": 3.45,\n",
" \"K2O\": 1.99,\n",
" \"P2O5\": 0.51,\n",
"})"
"composition = pd.Series(\n",
" {\n",
" \"SIO2\": 47.95,\n",
" \"TIO2\": 1.67,\n",
" \"AL2O3\": 17.32,\n",
" \"FEO\": 10.24,\n",
" \"MNO\": 0.17,\n",
" \"MGO\": 5.76,\n",
" \"CAO\": 10.93,\n",
" \"NA2O\": 3.45,\n",
" \"K2O\": 1.99,\n",
" \"P2O5\": 0.51,\n",
" }\n",
")"
]
},
{
Expand Down Expand Up @@ -90,35 +93,40 @@
"source": [
"# Set up fixed model parameters\n",
"\n",
"model = {\"COMPOSITION\": \"basalt\",\n",
" \"FIND_SATURATION\": True,\n",
" \"GAS_SYS\": \"cohs\",\n",
" \"FE_SYSTEM\": True,\n",
" \"FO2_buffer_SET\": True,\n",
" \"FH2_SET\": False,\n",
" \"WTH2O_SET\": True,\n",
" \"WTCO2_SET\": True,\n",
" \"SULFUR_SET\": True}\n",
"model = {\n",
" \"COMPOSITION\": \"basalt\",\n",
" \"FIND_SATURATION\": True,\n",
" \"GAS_SYS\": \"cohs\",\n",
" \"FE_SYSTEM\": True,\n",
" \"FO2_buffer_SET\": True,\n",
" \"FH2_SET\": False,\n",
" \"WTH2O_SET\": True,\n",
" \"WTCO2_SET\": True,\n",
" \"SULFUR_SET\": True,\n",
"}\n",
"\n",
"# Then merge with the input parameters for use with EVo.\n",
"\n",
"# Starting conditions\n",
"fo2_buffer = \"FMQ\" # reference buffer (IW, FMQ or NNO)\n",
"dfo2 = 0 # offset from buffer in log units\n",
"temp_k = 1473 # temperature, K\n",
"h2o_wt_perc = 2.0 # dissolved H2O in the melt, wt%\n",
"co2_wt_perc = 0.15 # dissolved CO2 in the melt, wt%\n",
"s_ppm = 3000 # dissolved S in the melt, ppm\n",
"fo2_buffer = \"FMQ\" # reference buffer (IW, FMQ or NNO)\n",
"dfo2 = 0 # offset from buffer in log units\n",
"temp_k = 1473 # temperature, K\n",
"h2o_wt_perc = 2.0 # dissolved H2O in the melt, wt%\n",
"co2_wt_perc = 0.15 # dissolved CO2 in the melt, wt%\n",
"s_ppm = 3000 # dissolved S in the melt, ppm\n",
"\n",
"env = pd.Series(model | {\n",
" 'FO2_buffer': fo2_buffer,\n",
" 'FO2_buffer_START': dfo2,\n",
" 'T_START': temp_k,\n",
" # Volatile inputs as melt wt fractions (EVo uses wt fraction internally)\n",
" 'WTH2O_START': h2o_wt_perc / 100,\n",
" 'WTCO2_START': co2_wt_perc / 100,\n",
" 'SULFUR_START': s_ppm / 1e6\n",
"})"
"env = pd.Series(\n",
" model\n",
" | {\n",
" \"FO2_buffer\": fo2_buffer,\n",
" \"FO2_buffer_START\": dfo2,\n",
" \"T_START\": temp_k,\n",
" # Volatile inputs as melt wt fractions (EVo uses wt fraction internally)\n",
" \"WTH2O_START\": h2o_wt_perc / 100,\n",
" \"WTCO2_START\": co2_wt_perc / 100,\n",
" \"SULFUR_START\": s_ppm / 1e6,\n",
" }\n",
")"
]
},
{
Expand Down Expand Up @@ -177,7 +185,20 @@
"outputs": [],
"source": [
"# Pressure, gas fraction, major gas species, and melt residuals\n",
"df[[\"P\", \"Gas_wt\", \"Exsol_vol%\", \"mH2O\", \"mCO2\", \"mSO2\", \"mH2S\", \"H2O_melt\", \"CO2_melt\", \"Stot_melt\"]]"
"df[\n",
" [\n",
" \"P\",\n",
" \"Gas_wt\",\n",
" \"Exsol_vol%\",\n",
" \"mH2O\",\n",
" \"mCO2\",\n",
" \"mSO2\",\n",
" \"mH2S\",\n",
" \"H2O_melt\",\n",
" \"CO2_melt\",\n",
" \"Stot_melt\",\n",
" ]\n",
"]"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies = ["numpy>=1.21.0",

[project.optional-dependencies]
dev = ["ruff", "pre-commit"]
web = ["streamlit"]
test = ["pytest"]
docs = ["sphinx==5.3.0", "sphinx_rtd_theme"]

Expand Down
6 changes: 4 additions & 2 deletions src/evo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
EVo

A Python model for volcanic degassing, using the equilibrium constants and mass balance
method.
"""

from evo.dgs import run_evo as run_evo
from evo.dgs import run_evo
from evo.multirun import multirun

__all__ = ["run_evo"]
__all__ = ["multirun", "run_evo"]
21 changes: 9 additions & 12 deletions src/evo/dgs_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,8 @@ def __init__(self, run, sys, melt, mol):
self.melt = melt
self.delG = 0 # Gibbs Free energy of formation
self.Y = 0 # Fugacity coefficient
self.y_constants = (
{}
) # Stores any constants needed for the activity coefficient calculation
# Store constants needed for the activity coefficient calculation
self.y_constants = {}

def get_G(self, T):
"""
Expand Down Expand Up @@ -1256,11 +1255,11 @@ def melt_composition(self, gas, mols):
elif self.run.GAS_SYS == "COH":
H2O, O2, H2, CO, CO2, CH4 = mols
elif self.run.GAS_SYS == "SOH":
H2O, O2, H2, S2, SO2, H2S = mols
H2O, O2, H2, S2 = mols[:4]
elif self.run.GAS_SYS == "COHS":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S = mols
H2O, O2, H2, CO, CO2, CH4, S2 = mols[:7]
elif self.run.GAS_SYS == "COHSN":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S, N2 = mols
H2O, O2, H2, CO, CO2, CH4, S2 = mols[:7]

self.h2o.append(
sl.h2o_melt(gas.mH2O[-1], H2O, self.sys.P, name=self.sys.run.H2O_MODEL)
Expand Down Expand Up @@ -1483,9 +1482,7 @@ def __init__(self, sys):
self.mS2 = []
self.mN2 = []
self.atomicM = {}
self.wt = (
{}
) # Temporary store for the results of converting mole frac to weight frac
self.wt = {} # Store for the results of converting mole frac to weight frac
self.Wt = {} # Store of weight fractions at each pressure step
self.f = {} # Store the fugacity of a species at each step.
self.M = [] # Stores the mean molecular weight of the gas phase
Expand Down Expand Up @@ -1549,7 +1546,7 @@ def get_WgT(self, melt, mols):
) * sum(mjMj)

elif self.sys.run.GAS_SYS == "SOH":
H2O, O2, H2, S2, SO2, H2S = mols
H2O, O2, H2 = mols[:3]
lst = {
"o2": self.mO2[-1],
"h2": self.mH2[-1],
Expand Down Expand Up @@ -1581,7 +1578,7 @@ def get_WgT(self, melt, mols):
) * sum(mjMj)

elif self.sys.run.GAS_SYS == "COHS":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S = mols
H2O, O2, H2, CO, CO2, CH4 = mols[:6]
lst = {
"o2": self.mO2[-1],
"h2": self.mH2[-1],
Expand Down Expand Up @@ -1624,7 +1621,7 @@ def get_WgT(self, melt, mols):
) * sum(mjMj)

elif self.sys.run.GAS_SYS == "COHSN":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S, N2 = mols
H2O, O2, H2, CO, CO2, CH4 = mols[:6]
lst = {
"o2": self.mO2[-1],
"h2": self.mH2[-1],
Expand Down
20 changes: 10 additions & 10 deletions src/evo/fixed_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,23 @@ def sat_pressure(run, sys, gas, melt, mols):
sys.atomicM["h"] = run.ATOMIC_H / 1e6

elif run.GAS_SYS == "COH":
H2O, O2, H2, CO, CO2, CH4 = mols
H2O, O2, H2, CO, CO2, _ = mols
sys.atomicM["c"] = run.ATOMIC_C / 1e6
sys.atomicM["h"] = run.ATOMIC_H / 1e6

elif run.GAS_SYS == "SOH":
H2O, O2, H2, S2, SO2, H2S = mols
H2O, O2, H2, _, _, _ = mols
sys.atomicM["h"] = run.ATOMIC_H / 1e6
sys.atomicM["s"] = run.ATOMIC_S / 1e6

elif run.GAS_SYS == "COHS":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S = mols
H2O, O2, H2, CO, CO2, _, _, _, _ = mols
sys.atomicM["c"] = run.ATOMIC_C / 1e6
sys.atomicM["h"] = run.ATOMIC_H / 1e6
sys.atomicM["s"] = run.ATOMIC_S / 1e6

elif run.GAS_SYS == "COHSN":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S, N2 = mols
H2O, O2, H2, CO, CO2, _, _, _, _, _ = mols
sys.atomicM["c"] = run.ATOMIC_C / 1e6
sys.atomicM["h"] = run.ATOMIC_H / 1e6
sys.atomicM["n"] = run.ATOMIC_N / 1e6
Expand Down Expand Up @@ -388,7 +388,7 @@ def fixed_weights_oh(guesses: list[float]):
gamma = sg.find_Y(P_sat, sys.T, sys.SC)[:10]
fugacities = get_f(P_sat, melt_h2o, melt_co2, melt_s, melt_n, sys, melt, gamma)

h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y, s2_y, so2_y, h2s_y, n2_y = gamma
h2o_y, o2_y, h2_y = gamma[:3]
O2.Y = o2_y

mH2O, mO2, mH2 = get_molfrac(P_sat, fugacities, gamma)
Expand Down Expand Up @@ -448,7 +448,7 @@ def fixed_weights_coh(guesses: list[float]):
gamma = sg.find_Y(P_sat, sys.T, sys.SC)[:10]
fugacities = get_f(P_sat, melt_h2o, melt_co2, melt_s, melt_n, sys, melt, gamma)

h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y, s2_y, so2_y, h2s_y, n2_y = gamma
h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y = gamma[:6]
O2.Y = o2_y

mH2O, mO2, mH2, mCO, mCO2, mCH4 = get_molfrac(P_sat, fugacities, gamma)
Expand Down Expand Up @@ -548,7 +548,7 @@ def fixed_weights_soh(guesses: list[float]):
gamma = sg.find_Y(P_sat, sys.T, sys.SC)[:10]
fugacities = get_f(P_sat, melt_h2o, melt_co2, melt_s, melt_n, sys, melt, gamma)

h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y, s2_y, so2_y, h2s_y, n2_y = gamma
h2o_y, o2_y, h2_y, _, _, _, s2_y, _, _, _ = gamma
O2.Y = o2_y

mH2O, mO2, mH2, mS2, mSO2, mH2S = get_molfrac(P_sat, fugacities, gamma)
Expand Down Expand Up @@ -629,7 +629,7 @@ def fixed_weights_cohs(guesses: list[float]):
gamma = sg.find_Y(P_sat, sys.T, sys.SC)[:10]
fugacities = get_f(P_sat, melt_h2o, melt_co2, melt_s, melt_n, sys, melt, gamma)

h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y, s2_y, so2_y, h2s_y, n2_y = gamma
h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y, s2_y = gamma[:7]
O2.Y = gamma[1]

mH2O, mO2, mH2, mCO, mCO2, mCH4, mS2, mSO2, mH2S = get_molfrac(
Expand Down Expand Up @@ -768,7 +768,7 @@ def fixed_weights_cohsn(guesses: list[float]):
gamma = sg.find_Y(P_sat, sys.T, sys.SC)[:10]
fugacities = get_f(P_sat, melt_h2o, melt_co2, melt_s, melt_n, sys, melt, gamma)

h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y, s2_y, so2_y, h2s_y, n2_y = gamma
h2o_y, o2_y, h2_y, co_y, co2_y, ch4_y, s2_y = gamma[:7]
O2.Y = o2_y

mH2O, mO2, mH2, mCO, mCO2, mCH4, mS2, mSO2, mH2S, mN2 = get_molfrac(
Expand Down Expand Up @@ -1139,7 +1139,7 @@ def fixed_weights_cohsn(guesses: list[float]):
values = [mH2O, mO2, mH2, mCO, mCO2, mCH4, mS2, mSO2, mH2S, mN2]

# add gas speciation to lists to act as initial guess for first 'proper' P step
for ls, val in zip(lists, values):
for ls, val in zip(lists, values, strict=False):
ls.append(val)

for ls in empty_list:
Expand Down
12 changes: 5 additions & 7 deletions src/evo/init_cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ def get_inputs(sys, run, melt, gas, mols) -> tuple[float, ...]:
"""

if run.GAS_SYS == "COH":
H2O, O2, H2, CO, CO2, CH4 = mols
H2O, O2, H2, _, CO2, _ = mols
elif run.GAS_SYS == "SOH":
H2O, O2, H2, S2, SO2, H2S = mols
H2O, O2, H2, S2 = mols[:4]
elif run.GAS_SYS == "COHS":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S = mols
H2O, O2, H2, _, CO2, _, S2 = mols[:7]
elif run.GAS_SYS == "COHSN":
H2O, O2, H2, CO, CO2, CH4, S2, SO2, H2S, N2 = mols
H2O, O2, H2, _, CO2, _, S2 = mols[:7]

if run.FH2_SET is True:
mH2 = run.FH2_START / (H2.Y * sys.P)
Expand Down Expand Up @@ -180,9 +180,7 @@ def get_inputs(sys, run, melt, gas, mols) -> tuple[float, ...]:
)
graph_melt = (
(run.WTCO2_START - co2_melt) / cnst.m["co2"]
) * cnst.m[
"c"
] # wt frac graphite in melt
) * cnst.m["c"] # wt frac graphite in melt
melt.graphite_sat = True
melt.graph_current = graph_melt / cnst.m["c"]
run.WTCO2_START = co2_melt
Expand Down
Loading
Loading