-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
338 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pandas as pd | ||
from pyrolite.util.alphamelts.meltsfile import to_meltsfile | ||
from pyrolite.util.alphamelts.automation import MeltsProcess, make_meltsfolder | ||
# %% testdf | ||
import numpy as np | ||
from pyrolite.util.synthetic import test_df | ||
|
||
df = test_df(cols=["SiO2", "CaO", "MgO", "FeO", "TiO2", "Na2O", "K2O", "P2O5"]) | ||
df["Sample"] = np.arange(df.index.size) | ||
# %% setup dataframe | ||
# taking a dataframe with oxide/element headers, set up experiment info | ||
df["Title"] = df.Sample | ||
df["Initial Pressure"] = 7000 | ||
df["Initial Temperature"] = 1350 | ||
df["Final Temperature"] = 1000 | ||
df["Increment Temperature"] = -3 | ||
df["Log fO2 Path"] = "FMQ" | ||
# %% autorun | ||
# we can create melts files from each of these data rows, and run an automated experiment | ||
for ix in df.index: | ||
meltsfile = to_meltsfile( # write | ||
df.loc[ix, :], # take the specific row | ||
writetraces=False, # ignore trace element data | ||
modes=[ | ||
"isobaric", | ||
"fractionate solids", | ||
], # conduct an isobaric experiment where solids are fractionated | ||
exclude=["P2O5", "K2O"], # exclude potassium and phosphorous | ||
) | ||
# create an experiment folder to work in, add the meltsfile and environment file | ||
experiment_folder = make_meltsfolder( | ||
meltsfile, df.loc[ix, "Title"], env="pyrolite_envfile.txt" | ||
) | ||
# set up a melts process to run this automatically | ||
process = MeltsProcess( | ||
meltsfile=df.loc[ix, "Title"] + ".melts", # | ||
env="pyrolite_envfile.txt", | ||
fromdir=str(experiment_folder), | ||
) | ||
# run some commands as you would in alphaMELTS, | ||
# if it errors all hope is lost (for now), and you'll have to run it manually | ||
process.write(3, 1, 4, wait=True, log=False) | ||
# end the experiment | ||
process.terminate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pyrolite.util.alphamelts.env import MELTS_Env | ||
# %% Env | ||
# set up an environment for an experiment stepping down temperature from 1350 to 1000 | ||
# in 3 degree steps | ||
env = MELTS_Env() | ||
env.MINP = 7000 | ||
env.MAXP = 7000 | ||
env.MINT = 1000 | ||
env.MAXT = 1350 | ||
env.DELTAT = -3 | ||
# %% save file | ||
# you can directly export these parameters to an envrionment file here: | ||
with open("pyrolite_envfile.txt", "w") as f: | ||
f.write(env.to_envfile(unset_variables=False)) | ||
# then pass this to alphamelts using run_alphamelts.command -f pyrolite_envfile.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pyrolite.util.alphamelts.download import install_melts | ||
from pyrolite.util.meta import pyrolite_datafolder, stream_log | ||
|
||
# Here we can do a conditonal install - only downloading alphamelts if it doesnt exist | ||
if not (pyrolite_datafolder(subfolder="alphamelts") / "localinstall").exists(): | ||
stream_log("pyrolite.util.alphamelts", level="INFO") # logger for output info | ||
install_melts(local=True) # install a copy of melts to pyrolite data folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import matplotlib.pyplot as plt | ||
from pyrolite.geochem.ind import __common_oxides__ | ||
from pyrolite.util.alphamelts.tables import MeltsOutput | ||
|
||
# %% --- | ||
# say you have a folder containing melts tables | ||
output = MeltsOutput(folder, kelvin=False) # tables in degrees C | ||
|
||
# this object has a number of useful attributes | ||
|
||
output.tables # list of tables accessible from the object | ||
|
||
{"bulkcomp", "liquidcomp", "phasemass", "phasevol", "solidcomp", "system", "tracecomp"} | ||
|
||
output.phasenames # get the names of phases which appear in the experiment | ||
|
||
{"clinopyroxene_0", "feldspar_0", "liquid_0", "olivine_0", "spinel_0"} | ||
|
||
output.phases # dictionary of phasename : phase composition tables (<df>) | ||
|
||
{ | ||
"liquid_0": "<df>", | ||
"spinel_0": "<df>", | ||
"feldspar_0": "<df>", | ||
"clinopyroxene_0": "<df>", | ||
"olivine_0": "<df>", | ||
} | ||
|
||
# e.g. access the phase Volume table using: | ||
output.phasevol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Automating alphaMELTS runs | ||
============================= | ||
|
||
pyrolite includes some utilities to help you run alphaMELTS with a little less hassle, | ||
especially for established workflows or repetitive calculations. | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/automation.py | ||
:language: python | ||
:end-before: # %% testdf | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/automation.py | ||
:language: python | ||
:start-after: # %% setup dataframe | ||
:end-before: # %% autorun | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/automation.py | ||
:language: python | ||
:start-after: # %% autorun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
alphaMELTS Environment | ||
------------------------ | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/env.py | ||
:language: python | ||
:end-before: # %% Env | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/env.py | ||
:language: python | ||
:start-after: # %% Env | ||
:end-before: # %% save file | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/env.py | ||
:language: python | ||
:start-after: # %% save file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Local Installation of alphaMELTS | ||
---------------------------------- | ||
|
||
pyrolite can download and manage its own version of alphaMELTS (without any real | ||
'installation', *per-se*), and use this for :mod:`~pyrolite.util.alphamelts.automation` | ||
purposes. | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/install.py | ||
:language: python | ||
|
||
.. warning:: This 'local install' method still requires that you have Perl installed, | ||
as it uses the Perl :code:`run_alphamelts.command` script. If you're on | ||
Windows, you can use `Strawberry Perl <http://strawberryperl.com/>`__ | ||
for this purpose. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
alphaMELTS Tables | ||
-------------------- | ||
|
||
To automatically import alphaMELTS tables as :class:`~pandas.DataFrame`s, you can use | ||
:class:`~pyrolite.util.alphamelts.tables.MeltsOutput`, from which you can then | ||
develop plots and interrogate data. | ||
|
||
.. literalinclude:: ../../../../examples/alphamelts/tables.py | ||
:language: python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.