Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ docs/_build/

.DS_Store
.ruff_cache
.pytest_cache/
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
include evo/Data/*.txt
include evo/input/*.yaml
include evo/data/*.txt
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ Single pressure and decompression can be run for OH, COH, SOH, COHS and COHSN sy

EVo can be set up using either melt volatile contents, or for a set amount of atomic volatile which is preferable for conducting experiments over a wide range of fO2 values.

### Prerequisites

This programme requires Python 3 to run.

Installation/Usage:
*******************
## Installation/Usage:

To install locally, EVo must be downloaded from GitHub using

Expand All @@ -33,16 +28,18 @@ From this point, EVo can either be imported into your python scripts as a regula
`import evo`

and run using
`evo.main(<chem_file>, <env_file>, <output_options_file>, folder=<output folder name>)`
`evo.run_evo(<chem_file>, <env_file>, <output_options_file>, folder=<output folder name>)`

Or EVo can be run directly from the terminal from inside the `evo` directory:
Or EVo can be run directly from the terminal:
```
cd EVO/evo
python dgs.py input/chem.yaml input/env.yaml --output-options input/output.yaml
python evo input_files/chem.yaml input_files/env.yaml --output-options input_files/output.yaml
```

The model should run and produce an output file `outputs/dgs_output_*.csv`, and a set of graphs in an 'outputs' folder, if a decompression run has been selected.

The settings are controlled by a set of config files, found in the `input_files` folder.
You should edit these as described below to set up your decompression experiment.

### Choosing run options in the env.yaml file

The different run types, model parameters and input values are all set in the env.yaml file. Run types are toggled on or off using True/False, as are the various requirements. You will be warned in the terminal window if the run type you have chosen, and the input parameters selected, do not match. A summary of which parameters are required for which run type will also be given below.
Expand Down
2 changes: 1 addition & 1 deletion evo/input/chem.yaml → input_files/chem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ P2O5: 0.51
# K2O: 0
# P2O5: 0
# NIO: 0
# CR2O3: 0
# CR2O3: 0
6 changes: 3 additions & 3 deletions evo/input/env.yaml → input_files/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ LOSS_FRAC: 0.9999
DENSITY_MODEL: spera2000
# Relate fo2 to Fe2/Fe3 ratio; pick from kc1991 (Kress & Carmicheal 1991), r2013 (Righter et al., 2013))
FO2_MODEL: kc1991
# Rock buffer definitions, options: frost1991;
# Rock buffer definitions, options: frost1991;
FMQ_MODEL: frost1991

# select solubility laws from options. Some options do not include OH-, CO3, CH4 species.
# OH system models, pick from: burguisser2015 (H2O only);
# OH system models, pick from: burguisser2015 (H2O only);
H2O_MODEL: burguisser2015
# H2 model, pick from: burguisser2015 (ONLY USE TO COMPARE TO DCOMPRESS; ERROR!); gaillard2003
H2_MODEL: gaillard2003
Expand Down Expand Up @@ -104,4 +104,4 @@ NITROGEN_SET: False
NITROGEN_START: 0.0001

GRAPHITE_SATURATED: False
GRAPHITE_START: 0.0001
GRAPHITE_START: 0.0001
2 changes: 1 addition & 1 deletion evo/input/output.yaml → input_files/output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Plt_gas_species_wt: False
Plt_gas_species_mol: True

Plt_gas_fraction: True
Plt_fo2_dFMQ: False
Plt_fo2_dFMQ: False
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ requires = ['setuptools>=40.8.0']
build-backend = 'setuptools.build_meta'

[tool.setuptools]
packages = ["evo"]

[tool.setuptools.packages.find]
where = ["src"]
include = ["evo*"]

[tool.setuptools.package-data]
"evo" = ["data/*.txt"]

[project]
name = "EVo"
Expand All @@ -14,6 +20,7 @@ license = {file = "LICENSE"}
classifiers = ["License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python :: 3"]
requires-python = ">=3.9"
scripts = { evo = "evo:main" }

dependencies = ["numpy>=1.21.0",
"scipy>=1.7.0",
Expand Down
4 changes: 3 additions & 1 deletion evo/__init__.py → src/evo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
method.
"""

from .dgs import main as main
from evo.dgs import run_evo as run_evo

__all__ = ["run_evo"]
42 changes: 42 additions & 0 deletions src/evo/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import argparse

from evo.dgs import run_evo


def main(argv=None):
my_parser = argparse.ArgumentParser(
prog="dgs", description="Run EVo: a thermodynamic magma degassing model"
)

# Add the arguments
my_parser.add_argument("chem", metavar="chem.yaml", help="the magma chemistry file")

my_parser.add_argument(
"env", metavar="env.yaml", help="the run environment settings file"
)

my_parser.add_argument(
"--output-options",
help="use selected output options from output.yaml file",
)

my_parser.add_argument(
"-o", "--output", help="the folder location to write the results to"
)

# Parse in files
args = my_parser.parse_args(argv)

f_chem = args.chem # set chemical compositions file
f_env = args.env # set environment file

if args.output_options:
f_out = args.output_options # set output file as an optional input
run_evo(f_chem, f_env, f_out, folder=args.output)
else:
f_out = None
run_evo(f_chem, f_env, f_out, folder=args.output)


if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 1 addition & 42 deletions evo/dgs.py → src/evo/dgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
# ------------------------------------------------------------------------

# python main [ ensure these are on your system ]
import argparse
import time
from pathlib import Path

Expand All @@ -75,7 +74,7 @@
# ------------------------------------------------------------------------


def main(f_chem, f_env, f_out, folder="outputs"):
def run_evo(f_chem, f_env, f_out, folder="outputs"):
"""Main function for EVo.

Call to run the model.
Expand Down Expand Up @@ -212,43 +211,3 @@ def main(f_chem, f_env, f_out, folder="outputs"):
writeout_figs(sys, melt, gas, out, sys.P_track)

return df


if __name__ == "__main__":
# -------------------------------------------------------------------
# SYSTEM SETUP ------------------------------------------------------
# -------------------------------------------------------------------

# Create the parser
my_parser = argparse.ArgumentParser(
prog="dgs", description="Run EVo: a thermodynamic magma degassing model"
)

# Add the arguments
my_parser.add_argument("chem", metavar="chem.yaml", help="the magma chemistry file")

my_parser.add_argument(
"env", metavar="env.yaml", help="the run environment settings file"
)

my_parser.add_argument(
"--output-options",
help="use selected output options from output.yaml file",
)

my_parser.add_argument(
"-o", "--output", help="the folder location to write the results to"
)

# Parse in files
args = my_parser.parse_args()

f_chem = args.chem # set chemical compositions file
f_env = args.env # set environment file

if args.output_options:
f_out = args.output_options # set output file as an optional input
main(f_chem, f_env, f_out, folder=args.output)
else:
f_out = None
main(f_chem, f_env, f_out, folder=args.output)
62 changes: 31 additions & 31 deletions evo/dgs_classes.py → src/evo/dgs_classes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# dgs_classes

import copy
import importlib.resources
import inspect
import itertools
import re
import sys
from pathlib import Path

import numpy as np

Expand Down Expand Up @@ -812,7 +812,7 @@ def get_G(self, T):

Calculates the GfF for a given temperature, to use in calculations
of equilibrium constants. Reads in critical data for the species
from the Data folder, linearly interpolating between temperatures.
from the 'data' folder, linearly interpolating between temperatures.

Parameters
----------
Expand All @@ -825,37 +825,37 @@ def get_G(self, T):
Gibbs free energy of formation
"""

# Open the file for data for the molecule
file_path = Path(__file__).parent / f"Data/{self.Mol}.txt"

path = open(file_path) # Opens the file for data for the molecule

Temp_ref = [] # To store temperatures which need to be interpolated
del_G_ref = [] # To store values of G which need to be interpolated
inter_count = 0

# iterate through file to find correct values according to T provided.
for aRow in path:
values = aRow.split("\t")
if not aRow.startswith("#"): # takes out descriptive headers
if T - float(values[0]) == 0:
# can find K with values in table, no interpolation needed
# adds name of mol. and delG. of form. to the del_G dictionary
self.delG = float(values[6])
break
elif inter_count == 1:
# adds in the upper table values for interpolation
Temp_ref.append(float(values[0]))
del_G_ref.append(float(values[6]))
break
elif T - float(values[0]) <= 99:
Temp_ref.append(float(values[0]))
del_G_ref.append(float(values[6]))
inter_count += 1
filename = f"{self.Mol}.txt"

data_file = importlib.resources.files("evo") / "data" / filename

with data_file.open("r", encoding="utf-8") as path:
Temp_ref = [] # To store temperatures for interpolation
del_G_ref = [] # To store values of G for interpolation
inter_count = 0

# Iterate through file to find correct values according to T provided.
for aRow in path:
values = aRow.split("\t")
if not aRow.startswith("#"): # Skips descriptive headers
if T - float(values[0]) == 0:
# Exact match found, no interpolation needed
self.delG = float(values[6])
return self.delG
elif inter_count == 1:
# Adds in the upper table values for interpolation
Temp_ref.append(float(values[0]))
del_G_ref.append(float(values[6]))
break
elif T - float(values[0]) <= 99:
Temp_ref.append(float(values[0]))
del_G_ref.append(float(values[6]))
inter_count += 1

# Perform interpolation if needed
if len(Temp_ref) == 2:
# interpolate between 2 and returns value for Gf.
self.delG = np.interp(T, Temp_ref, del_G_ref)
path.close()

return self.delG


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions evo/multirun.py → src/evo/multirun.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import yaml

from evo.dgs import main
from evo.dgs import run_evo


def amend_env(file, **kwargs):
Expand Down Expand Up @@ -72,7 +72,7 @@ def multirun(**kwargs):
onerun = {}

# Runs EVo
main("chem.yaml", "multirun.yaml", None)
run_evo("chem.yaml", "multirun.yaml", None)

# Copies the dgs_output file into a separate file ready to be run again.
copyfile("Output/dgs_output.csv", f"Output/output_{run_name}.csv")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions testing_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import evo

evo.main("input_files/chem.yaml", "input_files/env.yaml", None, folder="testing_things")
Loading