From abfbe745d60207c003eb31e2a00eb861a6592c0e Mon Sep 17 00:00:00 2001 From: Morgan Williams Date: Fri, 1 Nov 2024 15:01:38 +1100 Subject: [PATCH] Update lattice strain fitting example --- docs/source/conf.py | 1 - .../examples/geochem/mineral_lattice.py | 45 ++++++++++++------- pyrolite/geochem/ind.py | 30 +++++++------ 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index b6541deb..9aaae93f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -343,7 +343,6 @@ def reset_mpl(gallery_conf, fname): ) + "" ) -print(refcomps) rst_prolog = """ .. |br| raw:: html diff --git a/docs/source/gallery/examples/geochem/mineral_lattice.py b/docs/source/gallery/examples/geochem/mineral_lattice.py index b5ab8ead..0d85c43e 100644 --- a/docs/source/gallery/examples/geochem/mineral_lattice.py +++ b/docs/source/gallery/examples/geochem/mineral_lattice.py @@ -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( @@ -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] ) @@ -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+}` @@ -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: @@ -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, @@ -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 `__ -# -# .. [#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 `__ # # .. seealso:: # @@ -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 `__ +# +# .. [#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 `__ +# + diff --git a/pyrolite/geochem/ind.py b/pyrolite/geochem/ind.py index 6243d852..5090b541 100644 --- a/pyrolite/geochem/ind.py +++ b/pyrolite/geochem/ind.py @@ -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"] @@ -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: @@ -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