Skip to content

Commit

Permalink
Merge branch 'release/0.3.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
morganjwilliams committed Jul 6, 2022
2 parents ff907cc + ba2e2dd commit b9d05d7
Show file tree
Hide file tree
Showing 33 changed files with 955 additions and 240 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
name: Unit Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.7, 3.8, 3.9]
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ recursive-include pyrolite/data/mineral *
recursive-include pyrolite/data/models *
recursive-include pyrolite/data/radii *
recursive-include pyrolite/data/timescale *
recursive-include pyrolite/data/testing *
recursive-include pyrolite/data/_config *
# global-exclude __pycache__
2 changes: 1 addition & 1 deletion binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ dependencies:
- scipy>=1.2
- pandas>=0.23
- pip:
- -e git+git://github.com/morganjwilliams/pyrolite.git@develop#egg=pyrolite[dev,skl]
- -e git+https://github.com/morganjwilliams/pyrolite.git@develop#egg=pyrolite[dev,skl]
43 changes: 39 additions & 4 deletions docs/source/dev/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,41 @@ All notable changes to this project will be documented here.

.. note:: Changes noted in this subsection are to be released in the next version.
If you're keen to check something out before its released, you can use a
`development install <development.html#development-installation>`__.
`development install <development.html#development-installation>`__ .

`0.3.2`_
--------------

* **New Contributor**: `Angela Rodrigues <https://github.com/AngRodrigues>`__
* **Bugfix**: Edited docstrings and added ignore-warning for :mod:`numpydoc` warnings.
* **Bugfix**: Updated installation instructions and Binder configuration to use
secure protocols when installing via `git` (i.e. https://)
* **Bugfix**: Update CI builds so that tests can be run on MacOS.

:mod:`pyrolite.mineral`
~~~~~~~~~~~~~~~~~~~~~~~~~

* **Feature**: Added a TAS-based iron correction following Middlemost (1989).
* **Bugfix**: Fixed some errors in mineral formulae and handling leading to
inaccurate outputs from CIPW Norm.
* Split out volcanic from intrusive samples in the CIPW Norm volcanic rock comparison.
* Added SINCLAS abbreviations to the mineral dictionary associated with the CIPW
Norm, so alternate mineral naming systems can be compared.

:mod:`pyrolite.util`
~~~~~~~~~~~~~~~~~~~~~~~
* **PR Merged**: `Louise Schoneveld <https://github.com/lavender22>`__ submitted
a pull request to add bivariate and ternary classifier models for spinel
compositions (:class:`~pyrolite.util.classification.SpinelFeBivariate`,
:class:`~pyrolite.util.classification.SpinelTrivalentTernary`).
* **PR Merged**: `Angela Rodrigues <https://github.com/AngRodrigues>`__ submitted
a pull request to add the Jensen ternary cation classifier model for subalkalic
volcanic rocks (:class:`~pyrolite.util.classification.JensenPlot`,
:class:`~pyrolite.util.classification.JensenPlot`).
* Updated :func:`pyrolite.util.skl.vis.plot_confusion_matrix` to be able to plot on
existing axes, use an explicit class order and use rotation for e.g. long
x-axis class label names.
* Updated references to :func:`scipy.stats.gaussian_kde` after namespace deprecation.

`0.3.1`_
--------------
Expand All @@ -21,7 +55,7 @@ All notable changes to this project will be documented here.
Python 3.4). This will fix an issue blocking setting up a `conda-forge`
recipe (`#51 <https://github.com/morganjwilliams/pyrolite/issues/51>`__).
* Updated instances of redundant :mod:`numpy` types throughout to silence
depreciation warnings (using base types :class:`float`, :class:`int` except
deprecation warnings (using base types :class:`float`, :class:`int` except
where specific :mod:`numpy` types are required).
* Added a minimum :mod:`sympy` version requirement (v1.7) to avoid potential import
errors.
Expand Down Expand Up @@ -192,7 +226,7 @@ All notable changes to this project will be documented here.
argument.
* Updated automated pyrolite :mod:`matplotlib` style export to be more reliable.
* Changed the default shading for :func:`~pyrolite.plot.pyroplot.density` to suppress
error about upcoming :mod:`matplotlib` depreciation.
error about upcoming :mod:`matplotlib` deprecation.
* Ordering for contours, contour names and contour styles is now preserved for
:func:`~pyrolite.plot.density.density` and related functions.
* Updated :mod:`pyrolite.plot.templates.pearce` to use ratios from
Expand Down Expand Up @@ -1255,7 +1289,8 @@ All notable changes to this project will be documented here.
`GitHub <https://github.com/morganjwilliams/pyrolite/releases>`__ for reference,
but were :code:`alpha` versions which were never considered stable.

.. _Development: https://github.com/morganjwilliams/pyrolite/compare/0.3.1...develop
.. _Development: https://github.com/morganjwilliams/pyrolite/compare/0.3.2...develop
.. _0.3.2: https://github.com/morganjwilliams/pyrolite/compare/0.3.1...0.3.2
.. _0.3.1: https://github.com/morganjwilliams/pyrolite/compare/0.3.0...0.3.1
.. _0.3.0: https://github.com/morganjwilliams/pyrolite/compare/0.2.8...0.3.0
.. _0.2.8: https://github.com/morganjwilliams/pyrolite/compare/0.2.7...0.2.8
Expand Down
2 changes: 2 additions & 0 deletions docs/source/dev/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ comments, testing, bug reports, or feature requests.
* `Nicolas Piette-Lauziere <https://github.com/NicolasPietteLauziere>`__
* `Chetan Nathwani <https://github.com/ChetanNathwani>`__
* `Martin Bentley <https://github.com/mtb-za>`__
* `Tom Buckle <https://github.com/bomtuckle>`__
* `Angela Rodrigues <https://github.com/AngRodrigues>`__
2 changes: 1 addition & 1 deletion docs/source/dev/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ via pip directly from GitHub:

.. code-block:: bash
pip install --user git+git://github.com/morganjwilliams/pyrolite.git@develop#egg=pyrolite
pip install --user git+https://github.com/morganjwilliams/pyrolite.git@develop#egg=pyrolite
Tests
Expand Down
117 changes: 82 additions & 35 deletions docs/source/gallery/examples/geochem/CIPW.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,32 @@
# The function accepts a few keyword arguments, all to do with the iron compositions
# and related adjustment/corrections:
#
# :code:`Fe_correction = <callable>`
# For specifying the Fe-correction method/function. Currently only Le LeMaitre's
# correction method is implemented [LeMaitre1976]_ .
# :code:`Fe_correction = "LeMaitre" | "Middlemost"`
# For specifying the Fe-correction method/function. Currently includes LeMaitre's
# correction method [LeMaitre1976]_ (the default) and Middlemost's TAS-based
# correction [Middlemost1989]_ .
#
# :code:`Fe_correction_mode = 'volcanic'`
# For specificying the Fe-correction mode where relevant
# For specificying the Fe-correction mode, for LeMaitre's correction.
#
# :code:`adjust_all_Fe = False`
# Specifying whether you want to adjust all iron compositions, or only those
# which are partially specified (i.e. only have a singular value for one of
# FeO, Fe2O3, FeOT, Fe2O3T).
#
NORM = CIPW_norm(df.pyrochem.compositional, Fe_correction="Middlemost")
########################################################################################
# For the purpose of establishing the congruency of our algorithm with Verma's,
# we'll use :code:`adjust_all_Fe = True`. Notably, this won't make too much
# difference to the format of the output, but it will adjust the estimates of
# normative mineralogy depending on oxidation state.
# we'll use :code:`adjust_all_Fe = True` and LeMaitre's correction. Notably, this
# won't make too much difference to the format of the output, but it will adjust
# the estimates of normative mineralogy depending on oxidation state.
#
NORM = CIPW_norm(df.pyrochem.compositional, adjust_all_Fe=True)
NORM = CIPW_norm(
df.pyrochem.compositional,
adjust_all_Fe=True,
Fe_correction="LeMaitre",
Fe_correction_mode="volcanic",
)
########################################################################################
# Now we have the normative mineralogical outputs, we can have a look to see how
# these compare to some relevant geochemical inputs:
Expand Down Expand Up @@ -132,36 +140,70 @@
k: v for (k, v) in translation.items() if (df[v] > 0).sum() and (NORM[k] > 0).sum()
}
########################################################################################
import matplotlib.pyplot as plt
# To compare SINCLAS and the :mod:`pyrolite` NORM outputs, we'll construct a grid
# of plots which compare the respective mineralogical norms relative to a 1:1 line,
# and highlight discrepancies. As we'll do it twice below (once for samples labelled as
# volanic, and once for everything else), we may as well make a function of it.
#
# After that, let's take a look at the volcanic samples in isolation, which are the
# the key samples for which the NORM should be applied:
#
from pyrolite.plot.color import process_color

ncols = 4
nrows = len(minerals.keys()) // ncols + 1 if len(minerals.keys()) % ncols else 0

fig, ax = plt.subplots(
nrows,
ncols,
figsize=(ncols * 2.5, nrows * 2),
)
fig.suptitle("Comparing pyrolite's CIPW Norm to SINCLAS/IgRoCS", fontsize=16)
ax = ax.flat

for ix, (b, a) in enumerate(minerals.items()):
ax[ix].set_title("\n".join(b.split()), y=0.9, va="top")
if a in df.columns and b in NORM.columns:
c = process_color(
np.abs((df[a] / NORM[b]) - 1),
cmap="RdBu_r",
norm=plt.Normalize(vmin=0, vmax=0.1),
)["c"]
ax[ix].scatter(df[a], NORM[b], c=c)
ax[ix].plot([0, df[a].max()], [0, df[a].max()], color="k", ls="--")

for a in ax:
a.set(xticks=[], yticks=[]) # turn off the ticks
if not a.collections: # turn off the axis for empty axes
a.axis("off")
plt.tight_layout()
def compare_NORMs(SINCLAS_outputs, NORM_outputs, name=""):
"""
Create a grid of axes comparing the outputs of SINCLAS and `pyrolite`'s NORM,
after translating the column names to the appropriate form.
"""
ncols = 4
nrows = len(minerals.keys()) // ncols + 1 if len(minerals.keys()) % ncols else 0

fig, ax = plt.subplots(nrows, ncols, figsize=(ncols * 2.5, nrows * 2))
fig.suptitle(
" - ".join(
["Comparing pyrolite's CIPW Norm to SINCLAS/IgRoCS"] + [name]
if name
else []
),
fontsize=16,
y=1.01,
)
ax = ax.flat
for ix, (b, a) in enumerate(minerals.items()):
ax[ix].set_title("\n".join(b.split()), y=0.9, va="top")
if a in SINCLAS_outputs.columns and b in NORM_outputs.columns:
# colour by deviation from unity
c = process_color(
np.abs((SINCLAS_outputs[a] / NORM_outputs[b]) - 1),
cmap="RdBu_r",
norm=plt.Normalize(vmin=0, vmax=0.1),
)["c"]
ax[ix].scatter(SINCLAS_outputs[a], NORM_outputs[b], c=c)
# add a 1:1 line
ax[ix].plot(
[0, SINCLAS_outputs[a].max()],
[0, SINCLAS_outputs[a].max()],
color="k",
ls="--",
)

for a in ax:
a.set(xticks=[], yticks=[]) # turn off the ticks
if not a.collections: # turn off the axis for empty axes
a.axis("off")
return fig, ax


volcanic_filter = df.loc[:, "ROCK_TYPE"].str.lower().str.startswith("volc")
fig, ax = compare_NORMs(df.loc[volcanic_filter, :], NORM.loc[volcanic_filter])


########################################################################################
# And everything else:
#
fig, ax = compare_NORMs(df.loc[~volcanic_filter, :], NORM.loc[~volcanic_filter])
plt.show()
########################################################################################
# These normative mineralogical components could be input into mineralogical
# classifiers, as mentioned above. For example, the IUGS QAP classifier:
Expand Down Expand Up @@ -219,3 +261,8 @@
# Contributions to Mineralogy and Petrology 56, no. 2 (1 January 1976): 181–89.
# `doi: doi.org/10.1007/BF00399603 <https://doi.org/10.1007/BF00399603>`__
#
# .. [Middlemost1989] Middlemost, Eric A. K. (1989). Iron Oxidation Ratios,
# Norms and the Classification of Volcanic Rocks.
# Chemical Geology 77, 1: 19–26.
# `doi: doi.org/10.1016/0009-2541(89)90011-9. <https://doi.org/10.1016/0009-2541(89)90011-9.>`__
#
5 changes: 3 additions & 2 deletions docs/source/gallery/examples/geochem/convert_chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
:func:`~pyrolite.geochem.transform.convert_chemistry` function. Note that by default
pyrolite assumes that data are in the same units.
"""
import pyrolite.geochem
import pandas as pd

pd.set_option("precision", 3) # smaller outputs
import pyrolite.geochem

pd.set_option("display.precision", 3) # smaller outputs
########################################################################################
# Here we create some synthetic data to work with, which has some variables in Wt% and
# some in ppm. Notably some elements are present in more than one column (Ca, Na):
Expand Down
7 changes: 4 additions & 3 deletions docs/source/gallery/examples/geochem/indexes_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
==================================
"""
import pyrolite.geochem
import pandas as pd

pd.set_option("precision", 3) # smaller outputs
import pyrolite.geochem

pd.set_option("display.precision", 3) # smaller outputs
########################################################################################
from pyrolite.util.synthetic import normal_frame

Expand Down Expand Up @@ -73,7 +74,7 @@
########################################################################################
# All elements (up to U):
#
from pyrolite.geochem.ind import common_elements, common_oxides, REE, REY
from pyrolite.geochem.ind import REE, REY, common_elements, common_oxides

common_elements() # string return

Expand Down
12 changes: 4 additions & 8 deletions docs/source/gallery/examples/geochem/mineral_mindb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
compositions.
"""
import pandas as pd
from pyrolite.mineral.mindb import (
list_groups,
list_minerals,
list_formulae,
get_mineral,
get_mineral_group,
)

pd.set_option("precision", 3) # smaller outputs
from pyrolite.mineral.mindb import (get_mineral, get_mineral_group,
list_formulae, list_groups, list_minerals)

pd.set_option("display.precision", 3) # smaller outputs
########################################################################################
# From the database, you can get the list of its contents using a few utility
# functions:
Expand Down
9 changes: 6 additions & 3 deletions docs/source/gallery/examples/geochem/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
Unit Scaling
=============
"""
import pyrolite.geochem
import pandas as pd

pd.set_option("precision", 3) # smaller outputs
import pyrolite.geochem

pd.set_option("display.precision", 3) # smaller outputs
########################################################################################
from pyrolite.util.synthetic import normal_frame

df = normal_frame(columns=['CaO', 'MgO', 'SiO2', 'FeO', 'Ni', 'Ti', 'La', 'Lu', 'Mg/Fe'])
df = normal_frame(
columns=["CaO", "MgO", "SiO2", "FeO", "Ni", "Ti", "La", "Lu", "Mg/Fe"]
)
########################################################################################
cols = ["Ni", "NiO", "La", "La2O3"]
df.head(2).pyrochem.convert_chemistry(to=cols)[cols] # these are in ppm!
33 changes: 29 additions & 4 deletions docs/source/gallery/examples/plotting/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
# First let's build a simple total-alkali vs silica (
# :func:`~pyrolite.plot.templates.TAS`) diagram:
#
from pyrolite.plot.templates import TAS
from pyrolite.plot.templates import TAS, SpinelFeBivariate
from pyrolite.util.plot.axes import share_axes

# sphinx_gallery_thumbnail_number = 2
# sphinx_gallery_thumbnail_number = 3


ax = TAS(linewidth=0.5, add_labels=True)
plt.show()
########################################################################################
# The other templates currently included in :mod:`pyrolite` are the
# For distinguishing Fe-rich variants of spinel phases, the bivariate spinel
# diagram can be useful:
#
ax = SpinelFeBivariate(linewidth=0.5, add_labels=True)
plt.show()
########################################################################################
# The other bivariate templates currently included in :mod:`pyrolite` are the
# :func:`~pyrolite.plot.templates.pearceThNbYb` and
# :func:`~pyrolite.plot.templates.pearceTiNbYb` diagrams.
# We can create some axes and add these templates to them:
Expand All @@ -44,7 +50,13 @@
# the :func:`~pyrolite.plot.templates.QAP` and
# :func:`~pyrolite.plot.templates.USDASoilTexture` diagrams:
#
from pyrolite.plot.templates import QAP, FeldsparTernary, USDASoilTexture
from pyrolite.plot.templates import (
QAP,
FeldsparTernary,
JensenPlot,
SpinelTrivalentTernary,
USDASoilTexture,
)

ax = QAP(linewidth=0.4)
plt.show()
Expand All @@ -63,6 +75,19 @@
plt.tight_layout()
plt.show()
########################################################################################
# For general spinel phase discrimination, a ternary classification diagram can
# be used to give labels based on trivalent cationic content (:math:`\mathrm{Cr^{3+}}`,
# :math:`\mathrm{Al^{3+}}`, :math:`\mathrm{Fe^{3+}}`):
#
SpinelTrivalentTernary(linewidth=0.4, add_labels=True, figsize=(6, 6))
plt.show()
########################################################################################
# The Jensen plot is another cationic ternary discrimination diagram (Jensen, 1976),
# for subalkaline volcanic rocks:
#
JensenPlot(linewidth=0.4, add_labels=True, figsize=(7, 7))
plt.show()
########################################################################################
# References and other notes for diagram templates can be found within the docstrings
# and within the pyrolite documentation:
#
Expand Down
Loading

0 comments on commit b9d05d7

Please sign in to comment.