Skip to content

Commit

Permalink
Merge 7d69b61 into 27a1574
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrolexa committed May 23, 2023
2 parents 27a1574 + 7d69b61 commit b5cd202
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyrolite/data/models/sandstones/config_herron.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{"name": "Herron", "axes":{"x":"log(SiO2/Al2O3)","y":"log(Fe2O3/K2O)"},
"fields":
{"QA": {"name": "Quartz arenite", "poly": [[1.59, -1.0], [1.81, 1.5], [2.5, 1.5], [2.5, -1.0], [1.59, -1.0]]},
"FeSh": {"name": "Fe-shale", "poly": [[0.71, 1.5], [0.71, 0.6], [0.0, 0.6], [0.0, 1.5], [0.71, 1.5]]},
"FeSa": {"name": "Fe-sand", "poly": [[0.71, 0.6], [0.71, 1.5], [1.81, 1.5], [1.73, 0.6], [0.71, 0.6]]},
"S": {"name": "Shale", "poly": [[0.51, -0.3], [0.0, -0.3], [0.0, 0.6], [0.71, 0.6], [0.51, -0.3]]},
"G": {"name": "Graywacke", "poly": [[0.89, 0.6], [0.64, -0.49], [0.51, -0.3], [0.71, 0.6], [0.89, 0.6]]},
"A" : {"name": "Arkose", "poly": [[1.09, 0.05], [0.99, -1.0], [0.64, -0.49], [0.77, 0.05], [1.09, 0.05]]},
"SA" : {"name": "Subarkose", "poly":[[0.99, -1.0], [1.09, 0.05], [1.68, 0.05], [1.59, -1.0], [0.99, -1.0]]},
"SLA": {"name" : "Sublithic arenite", "poly":[[1.09, 0.05], [1.14, 0.6], [1.73, 0.6], [1.68, 0.05], [1.09, 0.05]]},
"LA" : {"name": "Lithic arenite", "poly":[[1.14, 0.6], [1.09, 0.05], [0.77, 0.05], [0.89, 0.6], [1.14, 0.6]]}
}
}
10 changes: 10 additions & 0 deletions pyrolite/data/models/sandstones/config_pettijohn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"name": "Pettijohn", "axes":{"x":"log(SiO2/Al2O3)","y":"log(Na2O/K2O)"},
"fields":
{"QA": {"name": "Quartz arenite", "poly": [[1.77, -1.09], [1.75, -0.99], [1.71, -0.84], [1.69, -0.7], [1.69, -0.58], [1.7, -0.44], [1.72, -0.31], [1.76, -0.19], [1.8, -0.1], [1.87, 0.0], [1.93, 0.07], [2.0, 0.03], [2.3, -0.18], [2.52, -0.37], [2.55, -0.42], [2.56, -0.49], [2.58, -0.67], [2.57, -0.83], [2.56, -0.97], [2.54, -1.04], [2.5, -1.07], [2.44, -1.09], [2.17, -1.09], [1.95, -1.09], [1.77, -1.09]]},
"G": {"name": "Graywacke", "poly": [[1.09, 0.56], [1.05, 0.53], [0.99, 0.49], [0.91, 0.4], [0.87, 0.32], [0.83, 0.21], [0.81, 0.1], [0.81, -0.01], [0.77, -0.12], [0.7, -0.21], [0.61, -0.29], [0.53, -0.35], [0.48, -0.38], [0.45, -0.3], [0.39, -0.09], [0.37, 0.07], [0.39, 0.23], [0.44, 0.41], [0.51, 0.5], [0.6, 0.6], [0.65, 0.64], [0.74, 0.67], [0.82, 0.69], [0.87, 0.68], [1.0, 0.61], [1.09, 0.56]]},
"A" : {"name": "Arkose", "poly": [[0.51, -0.47], [0.57, -0.44], [0.65, -0.4], [0.73, -0.34], [0.78, -0.28], [0.83, -0.23], [0.9, -0.18], [0.98, -0.16], [1.03, -0.15], [1.02, -0.18], [1.02, -0.34], [1.03, -0.48], [1.05, -0.62], [1.1, -0.77], [1.17, -0.98], [1.21, -1.07], [1.07, -1.05], [0.91, -0.99], [0.83, -0.92], [0.69, -0.81], [0.6, -0.68], [0.51, -0.47]]},
"SA" : {"name": "Subarkose", "poly":[[1.56, 0.31], [1.52, 0.27], [1.45, 0.17], [1.38, 0.06], [1.31, -0.13], [1.27, -0.24], [1.25, -0.39], [1.25, -0.56], [1.27, -0.68], [1.3, -0.84], [1.35, -1.0], [1.38, -1.09], [1.27, -1.08], [1.21, -1.07], [1.17, -0.98], [1.1, -0.77], [1.05, -0.62], [1.03, -0.48], [1.02, -0.34], [1.02, -0.18], [1.04, -0.05], [1.09, 0.08], [1.15, 0.21], [1.22, 0.32], [1.33, 0.44], [1.47, 0.37], [1.56, 0.31]]},
"SLA": {"name" : "Sublithic arenite", "poly":[[1.93, 0.07], [1.87, 0.0], [1.8, -0.1], [1.76, -0.19], [1.72, -0.31], [1.7, -0.44], [1.69, -0.58], [1.69, -0.7], [1.71, -0.84], [1.75, -0.99], [1.77, -1.09], [1.52, -1.1], [1.38, -1.09], [1.35, -1.0], [1.3, -0.84], [1.27, -0.68], [1.25, -0.56], [1.25, -0.39], [1.27, -0.24], [1.31, -0.13], [1.38, 0.06], [1.45, 0.17], [1.52, 0.27], [1.56, 0.31], [1.74, 0.2], [1.93, 0.07]]},
"LA" : {"name": "Lithic arenite", "poly":[[1.03, -0.15], [0.98, -0.16], [0.9, -0.18], [0.83, -0.23], [0.78, -0.28], [0.73, -0.34], [0.65, -0.4], [0.57, -0.44], [0.51, -0.47], [0.51, -0.46], [0.48, -0.38], [0.53, -0.35], [0.61, -0.29], [0.7, -0.21], [0.77, -0.12], [0.81, -0.01], [0.81, 0.1], [0.83, 0.21], [0.87, 0.32], [0.91, 0.4], [0.99, 0.49], [1.05, 0.53], [1.09, 0.56], [1.21, 0.5], [1.33, 0.44], [1.22, 0.32], [1.15, 0.21], [1.09, 0.08], [1.04, -0.05], [1.03, -0.15]]}
}
}
2 changes: 2 additions & 0 deletions pyrolite/plot/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .spinel import SpinelFeBivariate, SpinelTrivalentTernary
from .TAS import TAS
from .USDA_soil_texture import USDASoilTexture
from .sandstones import Pettijohn, Herron

logger = Handle(__name__)

Expand All @@ -27,4 +28,5 @@
"FeldsparTernary",
"SpinelFeBivariate",
"SpinelTrivalentTernary",
"sandstones",
]
134 changes: 134 additions & 0 deletions pyrolite/plot/templates/sandstones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import matplotlib.pyplot as plt
import numpy as np

from ...util.classification import Pettijohn as PJclassifier
from ...util.classification import Herron as Herronclassifier
from ...util.log import Handle
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 Pettijohn(
ax=None,
add_labels=False,
which_labels="ID",
relim=True,
color="k",
**kwargs
):
"""
Adds the Pettijohn (1973) [#ref_1] sandstones classification diagram.
Parameters
----------
ax : :class:`matplotlib.axes.Axes`
Axes to add the template on to.
add_labels : :class:`bool`
Whether to add labels at polygon centroids.
which_labels : :class:`str`
Which data to use for field labels - field 'name' or 'ID'.
relim : :class:`bool`
Whether to relimit axes to fit the built in ranges for this diagram.
color : :class:`str`
Line color for the diagram.
Returns
-------
ax : :class:`matplotlib.axes.Axes`
References
-----------
.. [#ref_1] Pettijohn, F. J., Potter, P. E. and Siever, R. (1973).
Sand and Sandstone. New York, Springer-Verlag. 618p.
doi: {Pettijohn1973}
"""
PJ_xlim, PJ_ylim = (0, 2.5), (-1.5, 1)
if ax is None:
xlim, ylim = PJ_xlim, PJ_ylim
else:
# if the axes limits are not defaults, update to reflect the axes
ax_defaults = (0, 1)
ax_xlim, ax_ylim = ax.get_xlim(), ax.get_ylim()
xlim, ylim = (
[ax_xlim, PJ_xlim][np.allclose(ax_xlim, ax_defaults)],
[ax_ylim, PJ_ylim][np.allclose(ax_ylim, ax_defaults)],
)
ax = init_axes(ax=ax, **kwargs)

tas = PJclassifier()
tas.add_to_axes(ax=ax, add_labels=add_labels, which_labels=which_labels, **kwargs)
if relim:
ax.set_xlim(xlim)
ax.set_ylim(ylim)
return ax


@update_docstring_references
def Herron(
ax=None,
add_labels=False,
which_labels="ID",
relim=True,
color="k",
**kwargs
):
"""
Adds the Herron (1988) [#ref_1] sandstones classification diagram.
Parameters
----------
ax : :class:`matplotlib.axes.Axes`
Axes to add the template on to.
add_labels : :class:`bool`
Whether to add labels at polygon centroids.
which_labels : :class:`str`
Which data to use for field labels - field 'name' or 'ID'.
relim : :class:`bool`
Whether to relimit axes to fit the built in ranges for this diagram.
color : :class:`str`
Line color for the diagram.
Returns
-------
ax : :class:`matplotlib.axes.Axes`
References
-----------
.. [#ref_1] Herron, M.M. (1988).
Geochemical classification of terrigenous sands and shales
from core or log data.
Journal of Sedimentary Research, 58(5), pp.820-829.
doi: {Herron1988}
"""
Herron_xlim, Herron_ylim = (0, 2.5), (-1.5, 2)
if ax is None:
xlim, ylim = Herron_xlim, Herron_ylim
else:
# if the axes limits are not defaults, update to reflect the axes
ax_defaults = (0, 1)
ax_xlim, ax_ylim = ax.get_xlim(), ax.get_ylim()
xlim, ylim = (
[ax_xlim, Herron_xlim][np.allclose(ax_xlim, ax_defaults)],
[ax_ylim, Herron_ylim][np.allclose(ax_ylim, ax_defaults)],
)
ax = init_axes(ax=ax, **kwargs)

tas = Herronclassifier()
tas.add_to_axes(ax=ax, add_labels=add_labels, which_labels=which_labels, **kwargs)
if relim:
ax.set_xlim(xlim)
ax.set_ylim(ylim)
return ax


Pettijohn.__doc__ = Pettijohn.__doc__.format(
Pettijohn1973=sphinx_doi_link("10.1007/978-1-4615-9974-6"),
)
Herron.__doc__ = Herron.__doc__.format(
Herron1988=sphinx_doi_link("10.1306/212F8E77-2B24-11D7-8648000102C1865D"),
)
75 changes: 75 additions & 0 deletions pyrolite/util/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,75 @@ def __init__(self, **kwargs):
super().__init__(**poly_config)


@update_docstring_references
class Pettijohn(PolygonClassifier):
"""
Pettijohn (1973) sandstones classification
[#ref_1]_.
Parameters
-----------
name : :class:`str`
A name for the classifier model.
axes : :class:`list` | :class:`tuple`
Names of the axes corresponding to the polygon coordinates.
fields : :class:`dict`
Dictionary describing indiviudal polygons, with identifiers as keys and
dictionaries containing 'name' and 'fields' items.
References
-----------
.. [#ref_1] Pettijohn, F. J., Potter, P. E. and Siever, R. (1973).
Sand and Sandstone. New York, Springer-Verlag. 618p.
doi: {Pettijohn1973}
"""

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

with open(src, "r") as f:
config = json.load(f)

poly_config = {**config, **kwargs}
super().__init__(**poly_config)


@update_docstring_references
class Herron(PolygonClassifier):
"""
Herron (1988) sandstones classification
[#ref_1]_.
Parameters
-----------
name : :class:`str`
A name for the classifier model.
axes : :class:`list` | :class:`tuple`
Names of the axes corresponding to the polygon coordinates.
fields : :class:`dict`
Dictionary describing indiviudal polygons, with identifiers as keys and
dictionaries containing 'name' and 'fields' items.
References
-----------
.. [#ref_1] Herron, M.M. (1988).
Geochemical classification of terrigenous sands and shales
from core or log data.
Journal of Sedimentary Research, 58(5), pp.820-829.
doi: {Herron1988}
"""

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

with open(src, "r") as f:
config = json.load(f)

poly_config = {**config, **kwargs}
super().__init__(**poly_config)



TAS.__doc__ = TAS.__doc__.format(
LeBas1992=sphinx_doi_link("10.1007/BF01160698"),
Middlemost1994=sphinx_doi_link("10.1016/0012-8252(94)90029-9"),
Expand All @@ -707,3 +776,9 @@ def __init__(self, **kwargs):
Streckeisen1974=sphinx_doi_link("10.1007/BF01820841"),
LeMaitre2002=sphinx_doi_link("10.1017/CBO9780511535581"),
)
Pettijohn.__doc__ = Pettijohn.__doc__.format(
Pettijohn1973=sphinx_doi_link("10.1007/978-1-4615-9974-6"),
)
Herron.__doc__ = Herron.__doc__.format(
Herron1988=sphinx_doi_link("10.1306/212F8E77-2B24-11D7-8648000102C1865D"),
)

0 comments on commit b5cd202

Please sign in to comment.