def setUp(self): self.C = get_reference_composition("Chondrite_PON") els = [i for i in REE() if not i == "Pm"] vals = self.C[els] self.df = pd.DataFrame({k: v for (k, v) in zip(els, vals)}, index=[0]) self.df.loc[1, :] = self.df.loc[0, :] self.default_degree = 3
def setUp(self): self.fromdir = temp_path() / ("testmelts" + self.__class__.__name__) self.fromdir.mkdir(parents=True) Gale_MORB = get_reference_composition("MORB_Gale2013") majors = [ "SiO2", "Al2O3", "FeO", "MnO", "MgO", "CaO", "Na2O", "TiO2", "K2O", "P2O5", ] MORB = Gale_MORB.comp.loc[:, majors].apply(pd.to_numeric) MORB = MORB.append(MORB).reset_index().drop(columns="index") MORB["Title"] = [ "{}_{}".format(Gale_MORB.name, ix).replace("_", "") for ix in MORB.index.values.astype(str) ] MORB["Initial Temperature"] = 1300 MORB["Final Temperature"] = 800 MORB["Initial Pressure"] = 5000 MORB["Final Pressure"] = 5000 MORB["Log fO2 Path"] = "FMQ" MORB["Increment Temperature"] = -5 MORB["Increment Pressure"] = 0 self.df = MORB self.env = ENV
def isobaricGaleMORBexample(T0=1300, T1=800, P0=5000, P1=5000, fO2="FMQ", title=None): Gale_MORB = get_reference_composition("MORB_Gale2013") majors = [ "SiO2", "Al2O3", "FeO", "MnO", "MgO", "CaO", "Na2O", "TiO2", "K2O", "P2O5", ] MORB = Gale_MORB.comp[majors].reset_index(drop=True) if title is not None: MORB["Title"] = title MORB["Initial Temperature"] = T0 MORB["Final Temperature"] = T1 MORB["Initial Pressure"] = P0 MORB["Final Pressure"] = P1 MORB["Log fO2 Path"] = fO2 MORB["Increment Temperature"] = -5 MORB["Increment Pressure"] = 0 return MORB
def setUp(self): self.C = get_reference_composition("PM_PON") self.C.set_units("ppm") els = [i for i in REE() if not i == "Pm"] vals = self.C[els] self.df = pd.DataFrame({k: v for (k, v) in zip(els, vals)}, index=[0]) self.df = self.df.pyrochem.normalize_to("Chondrite_PON", units="ppm") self.df.loc[1, :] = self.df.loc[0, :] self.default_degree = 3
def test_norm_n_normto(self): """Check that norm indicator _n can be used with a specific norm.""" df = self.df.copy() ratio = "Li/B_n" for norm_to in [ "Chondrite_PON", get_reference_composition("Chondrite_PON"), (1.0, 2.0), ]: with self.subTest(norm_to=norm_to): r = get_ratio(df, ratio=ratio, norm_to=norm_to)
def test_norm_n_normto(self): """Check that norm indicator _n can be used with a specific norm.""" df = self.df.copy() ratio = "Li/B_n" values = df["Li"].values / df["B"].values for norm_to in [ "Chondrite_PON", get_reference_composition("Chondrite_PON"), (1.0, 2.0), 4.5, ]: with self.subTest(norm_to=norm_to): r = get_ratio(df, ratio=ratio, norm_to=norm_to) self.assertFalse(np.isclose(values, r.values).any())
def test_pyrochem_denormalize_from_composition(self): obj = self.df.copy(deep=True).pyrochem.compositional out = obj.pyrochem.denormalize_from( get_reference_composition("Chondrite_PON"))
""" Spiderplots & Density Spiderplots ================================== """ import numpy as np import pandas as pd import matplotlib.pyplot as plt # sphinx_gallery_thumbnail_number = 4 ######################################################################################## # Here we'll set up an example which uses EMORB as a starting point: # from pyrolite.geochem.norm import get_reference_composition ref = get_reference_composition( "EMORB_SM89") # EMORB composition as a starting point ref.set_units("ppm") df = ref.comp.pyrochem.compositional ######################################################################################## # Basic spider plots are straightforward to produce: import pyrolite.plot df.pyroplot.spider(color="k") plt.show() ######################################################################################## # Typically we'll normalise trace element compositions to a reference composition # to be able to link the diagram to 'relative enrichement' occuring during geological # processes: # normdf = df.pyrochem.normalize_to("PM_PON", units="ppm") normdf.pyroplot.spider(color="k", unity_line=True)
""" Normalization ============== A selection of reference compositions are included in pyrolite, and can be easily accessed with :func:`pyrolite.geochem.norm.get_reference_composition` (see the list at the bottom of the page for a complete list): """ import pandas as pd import matplotlib.pyplot as plt import pyrolite.plot from pyrolite.geochem.ind import REE from pyrolite.geochem.norm import get_reference_composition, all_reference_compositions ######################################################################################## chondrite = get_reference_composition("Chondrite_PON") ######################################################################################## # To use the compositions with a specific set of units, you can change them with # :func:`~pyrolite.geochem.norm.Composition.set_units`: # CI = chondrite.set_units("ppm") ######################################################################################### # The :func:`~pyrolite.geochem.pyrochem.normalize_to` method can be used to # normalise DataFrames to a given reference (e.g. for spiderplots): # fig, ax = plt.subplots(1) for name, ref in list(all_reference_compositions().items())[::2]: if name != "Chondrite_PON": ref.set_units("ppm") df = ref.comp.pyrochem.REE.pyrochem.normalize_to(CI, units="ppm")
def test_default(self): rc = "Chondrite_PON" out = get_reference_composition(rc) self.assertIsInstance(out, Composition)
def test_pyrochem_normalize_to_composition(self): obj = self.df.copy(deep=True) out = obj.pyrochem.normalize_to( get_reference_composition("Chondrite_PON"))