Skip to content

Commit

Permalink
Update lattice strain fitting example
Browse files Browse the repository at this point in the history
  • Loading branch information
morganjwilliams committed Nov 1, 2024
1 parent 302c8e9 commit abfbe74
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ def reset_mpl(gallery_conf, fname):
)
+ "</dl>"
)
print(refcomps)
rst_prolog = """
.. |br| raw:: html
Expand Down
45 changes: 28 additions & 17 deletions docs/source/gallery/examples/geochem/mineral_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# get the Shannon ionic radii for the elements in the 2+ site
site2radii = [
get_ionic_radii("Na", charge=1, coordination=8),
*[get_ionic_radii(el, charge=2, coordination=8) for el in ["Ca", "Eu", "Sr"]],
*get_ionic_radii(["Ca", "Eu", "Sr"], charge=2, coordination=8),
]
# plot the relative paritioning curve for cations in the 2+ site
site2Ds = D_Ca * np.array(
Expand Down Expand Up @@ -89,7 +89,7 @@
#
site3labels = REE(dropPm=True)
# get the Shannon ionic radii for the elements in the 3+ site
site3radii = [get_ionic_radii(x, charge=3, coordination=8) for x in REE(dropPm=True)]
site3radii = get_ionic_radii([x for x in REE(dropPm=True)], charge=3, coordination=8)
site3Ds = D_La * np.array(
[strain_coefficient(rLa, rx, r0=r03, E=E_3, T=Tk) for rx in site3radii]
)
Expand All @@ -103,9 +103,7 @@
ax.annotate(
l, xy=(r, d), xycoords="data", ha="right", va="bottom", fontsize=fontsize
)
ax.set_yscale("log")
ax.set_ylabel("$D_X$")
ax.set_xlabel("Radii ($\AA$)")
ax.set(ylabel="$D_X$", xlabel="Radii ($\AA$)", yscale="log")
fig
########################################################################################
# As europium is commonly present as a mixture of both :math:`Eu^{2+}`
Expand Down Expand Up @@ -134,6 +132,8 @@
ax.legend(bbox_to_anchor=(1.05, 1))
fig
########################################################################################
# Fitting Lattice Strain Models
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Given the lattice strain model and a partitioning profile (for e.g. REE data),
# we can also fit a model to a given curve; here we fit to our REE data above,
# for which we have some known parameters to compare to:
Expand All @@ -158,8 +158,8 @@
#
from pyrolite.plot.spider import REE_v_radii

ax = REE_v_radii()

ax = REE_v_radii(index="radii")
ax.set(ylabel="$D_X$", xlabel="Radii ($\AA$)")
ax.plot(site3radii, site3Ds, label="True", color="k")
ax.plot(
site3radii,
Expand All @@ -169,18 +169,15 @@
color="0.5",
)

ax.plot(site3radii, fit_lattice_strain._opt(site3radii, _ri, _tk, _D, z=3), label="Fit")

ax.plot(
site3radii,
_lattice_opt_function(site3radii, _ri, _tk, _D, z=3),
label="Fit",
color="r",
)
ax.legend()
ax.figure
########################################################################################
# .. [#ref_1] Blundy, J., Wood, B., 1994. Prediction of crystal–melt partition coefficients
# from elastic moduli. Nature 372, 452.
# doi: `10.1038/372452A0 <https://doi.org/10.1038/372452A0>`__
#
# .. [#ref_2] Dohmen, R., Blundy, J., 2014. A predictive thermodynamic model for element partitioning
# between plagioclase and melt as a function of pressure, temperature and composition.
# American Journal of Science 314, 1319–1372.
# doi: `10.2475/09.2014.04 <https://doi.org/10.2475/09.2014.04>`__
#
# .. seealso::
#
Expand All @@ -191,4 +188,18 @@
# Functions:
# :func:`~pyrolite.mineral.lattice.strain_coefficient`,
# :func:`~pyrolite.mineral.lattice.youngs_modulus_approximation`,
# :func:`~pyrolite.mineral.lattice.fit_lattice_strain`
# :func:`~pyrolite.geochem.get_ionic_radii`
#
# References
# ~~~~~~~~~~~
# .. [#ref_1] Blundy, J., Wood, B., 1994. Prediction of crystal–melt partition coefficients
# from elastic moduli. Nature 372, 452.
# doi: `10.1038/372452A0 <https://doi.org/10.1038/372452A0>`__
#
# .. [#ref_2] Dohmen, R., Blundy, J., 2014. A predictive thermodynamic model for element partitioning
# between plagioclase and melt as a function of pressure, temperature and composition.
# American Journal of Science 314, 1319–1372.
# doi: `10.2475/09.2014.04 <https://doi.org/10.2475/09.2014.04>`__
#

30 changes: 16 additions & 14 deletions pyrolite/geochem/ind.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,18 +459,20 @@ def get_ionic_radii(
* Implement interpolation for coordination +/- charge.
"""
if isinstance(element, list):
return [
get_ionic_radii(
e,
charge=charge,
coordination=coordination,
variant=variant,
source=source,
pauling=pauling,
**kwargs,
)
for e in element
]
return np.array(
[
get_ionic_radii(
e,
charge=charge,
coordination=coordination,
variant=variant,
source=source,
pauling=pauling,
**kwargs,
)
for e in element
]
)

if "shannon" in source.lower():
df = __radii__["shannon"]
Expand All @@ -491,7 +493,7 @@ def get_ionic_radii(
if charge in df.loc[elfltr, "charge"].unique():
fltrs *= df.charge == charge
else:
logger.warn("Charge {:d} not in table.".format(int(charge)))
logger.warning("Charge {:d} not in table.".format(int(charge)))
# try to interpolate over charge?..
# interpolate_charge=True
else:
Expand All @@ -502,7 +504,7 @@ def get_ionic_radii(
if coordination in df.loc[elfltr, "coordination"].unique():
fltrs *= df.coordination == coordination
else:
logger.warn("Coordination {:d} not in table.".format(int(coordination)))
logger.warning("Coordination {:d} not in table.".format(int(coordination)))
# try to interpolate over coordination
# interpolate_coordination=True

Expand Down

0 comments on commit abfbe74

Please sign in to comment.