Skip to content

Commit

Permalink
Minor updates + tests for JensenPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
morganjwilliams committed Jul 6, 2022
1 parent a9540cb commit c2f97dc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 30 deletions.
2 changes: 2 additions & 0 deletions pyrolite/plot/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ...util.log import Handle
from .feldspar import FeldsparTernary
from .jensen import JensenPlot
from .pearce import pearceThNbYb, pearceTiNbYb
from .QAP import QAP
from .TAS import TAS
Expand All @@ -18,6 +19,7 @@
__all__ = [
"pearceThNbYb",
"pearceTiNbYb",
"JensenPlot",
"TAS",
"USDASoilTexture",
"QAP",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import matplotlib.pyplot as plt
import numpy as np

from ...util.classification import USDASoilTexture as USDAclassifier
from ...util.classification import JensenPlot as _JensenPlot
from ...util.log import Handle
from ...util.meta import (sphinx_doi_link, subkwargs, update_docstring_references)
from ...util.meta import sphinx_doi_link, subkwargs, update_docstring_references
from ...util.plot.axes import init_axes

logger = Handle(__name__)


@update_docstring_references
def Jensen_Plot(ax=None, add_labels=False, color="k", **kwargs):
def JensenPlot(ax=None, add_labels=False, color="k", **kwargs):
"""
Jensen Plot for classification of sub-alkaline volcanic rocks
[#ref_1]_.
Jensen Plot for classification of sub-alkaline volcanic rocks [#ref_1]_.
Parameters
----------
Expand All @@ -30,20 +29,20 @@ def Jensen_Plot(ax=None, add_labels=False, color="k", **kwargs):
References
----------
.. [#ref_1] Jensen, L. S. (1976) A new cation plot for classifying sub-alkaline volcanic rocks.
.. [#ref_1] Jensen, L. S. (1976). A new cation plot for classifying
sub-alkaline volcanic rocks.
Ontario Division of Mines. Miscellaneous Paper No. 66.
Notes
-----
Diagram used for the classification classification of subalkalic volcanic rocks.
The diagram is constructed for molar cation percentages of Al, Fe+Ti and Mg, on account of these elements' stability upon metamorphism.
This particular version uses updated labels relative to Jensen (1976), in which the fields have been extended to the full range of the ternary plot.
Diagram used for the classification classification of subalkalic volcanic rocks.
The diagram is constructed for molar cation percentages of Al, Fe+Ti and Mg,
on account of these elements' stability upon metamorphism.
This particular version uses updated labels relative to Jensen (1976),
in which the fields have been extended to the full range of the ternary plot.
"""
ax = init_axes(ax=ax, projection="ternary", **kwargs)

clf = JensenPlot()
clf = _JensenPlot()
clf.add_to_axes(ax=ax, color=color, add_labels=add_labels, **kwargs)
return ax



32 changes: 19 additions & 13 deletions pyrolite/util/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class TAS(PolygonClassifier):
References
-----------
.. [#ref_1] Le Bas, M.J., Le Maitre, R.W., Woolley, A.R., 1992.
.. [#ref_1] Le Bas, M.J., Le Maitre, R.W., Woolley, A.R. (1992).
The construction of the Total Alkali-Silica chemical
classification of volcanic rocks.
Mineralogy and Petrology 46, 1–22.
Expand Down Expand Up @@ -495,11 +495,11 @@ class QAP(PolygonClassifier):
References
-----------
.. [#ref_1] Streckeisen, A. Classification and nomenclature of plutonic rocks
recommendations of the IUGS subcommission on the systematics of
Igneous Rocks. Geol Rundsch 63, 773–786 (1974).
.. [#ref_1] Streckeisen, A. (1974). Classification and nomenclature of plutonic
rocks: recommendations of the IUGS subcommission on the systematics
of Igneous Rocks. Geol Rundsch 63, 773–786.
doi: {Streckeisen1974}
.. [#ref_2] Le Maitre,R.W. 2002. Igneous Rocks: A Classification and Glossary
.. [#ref_2] Le Maitre,R.W. (2002). Igneous Rocks: A Classification and Glossary
of Terms : Recommendations of International Union of Geological
Sciences Subcommission on the Systematics of Igneous Rocks.
Cambridge University Press, 236pp
Expand Down Expand Up @@ -576,10 +576,11 @@ def predict(self, df: pd.DataFrame):
out.loc[perkalkaline_where] = "Peralkaline"
return out


@update_docstring_references
class JensenPlot(PolygonClassifier):
"""
Jensen Plot for classification of subalkaline volcanic rocks
[#ref_1]_.
Jensen Plot for classification of subalkaline volcanic rocks [#ref_1]_.
Parameters
-----------
Expand All @@ -593,14 +594,21 @@ class JensenPlot(PolygonClassifier):
References
-----------
.. [#ref_1] Jensen, L. S. (1976) A new cation plot for classifying sub-alkaline volcanic rocks.
.. [#ref_1] Jensen, L. S. (1976). A new cation plot for classifying
sub-alkaline volcanic rocks.
Ontario Division of Mines. Miscellaneous Paper No. 66.
Notes
-----
Diagram used for the classification classification of subalkalic volcanic rocks.
The diagram is constructed for molar cation percentages of Al, Fe+Ti and Mg,
on account of these elements' stability upon metamorphism.
This particular version uses updated labels relative to Jensen (1976),
in which the fields have been extended to the full range of the ternary plot.
"""

def __init__(self, **kwargs):
src = (
pyrolite_datafolder(subfolder="models") / "JensenPlot" / "config.json"
)
src = pyrolite_datafolder(subfolder="models") / "JensenPlot" / "config.json"

with open(src, "r") as f:
config = json.load(f)
Expand All @@ -609,8 +617,6 @@ def __init__(self, **kwargs):
super().__init__(**poly_config)




class SpinelTrivalentTernary(PolygonClassifier):
"""
Spinel Trivalent Ternary classification - designed for data in atoms per formula unit
Expand Down
4 changes: 2 additions & 2 deletions test/plot/templates/plot_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import matplotlib.pyplot as plt

from pyrolite.plot.templates import (QAP, TAS, FeldsparTernary,
from pyrolite.plot.templates import (QAP, TAS, FeldsparTernary, JensenPlot,
USDASoilTexture, pearceThNbYb,
pearceTiNbYb)

Expand Down Expand Up @@ -58,7 +58,7 @@ def tearDown(self):

class TestTernaryDiagrams(unittest.TestCase):
def test_ternary_default(self):
for diagram in [QAP, FeldsparTernary, USDASoilTexture]:
for diagram in [QAP, FeldsparTernary, USDASoilTexture, JensenPlot]:
fig, axes = plt.subplots(1)
for a in [None, axes]:
with self.subTest(diagram=diagram, a=a):
Expand Down
30 changes: 29 additions & 1 deletion test/util/util_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pyrolite.comp.codata import renormalise
from pyrolite.util.classification import *
from pyrolite.util.synthetic import normal_frame
from pyrolite.util.synthetic import normal_frame, random_cov_matrix


class TestTAS(unittest.TestCase):
Expand Down Expand Up @@ -127,6 +127,34 @@ def test_classifer_predict(self):
self.assertFalse(pd.isnull(classes).all())


class TestJensenPlot(unittest.TestCase):
def setUp(self):
self.df = normal_frame(
columns=["Ti + Fe(tot) mol%", "Al mol%", "Mg mol%"],
mean=[0.07, 0.15, 0.12],
cov=random_cov_matrix(2, sigmas=[0.5, 0.7]),
size=100,
)

def test_classifer_build(self):
cm = JensenPlot()

def test_classifer_add_to_axes(self):
cm = JensenPlot()
fig, ax = plt.subplots(1)
for a in [None, ax]:
with self.subTest(a=a):
cm.add_to_axes(
ax=a, alpha=0.4, color="k", linewidth=0.5, add_labels=True
)

def test_classifer_predict(self):
df = self.df
cm = JensenPlot()
classes = cm.predict(df)
self.assertFalse(pd.isnull(classes).all())


class TestPeralkalinity(unittest.TestCase):
"""Test the peralkalinity classifier."""

Expand Down

0 comments on commit c2f97dc

Please sign in to comment.