.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_star_to_mineralogy.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_star_to_mineralogy.py: Star to Mineralogy Pipeline ============================ The core workflow: create a star from spectroscopic dex measurements, view its composition, and calculate mantle mineralogy from a bulk silicate planet composition. .. GENERATED FROM PYTHON SOURCE LINES 9-12 Create a Star ------------- Stellar compositions are specified in dex notation — logarithmic abundances relative to the Sun. Positive values mean enriched, negative values mean depleted. .. GENERATED FROM PYTHON SOURCE LINES 12-27 .. code-block:: Python import matplotlib.pyplot as plt import stellar_geology as sg star = sg.Star( stellar_dex={"Fe": 0.1, "Mg": -0.05, "Si": -0.05}, name="Example Star", ) # View the star's composition as wt% oxides composition = star.get_composition(units="wtpt_oxides") print("Star composition (wt% oxides):") for oxide, pct in composition.items(): print(f" {oxide}: {pct:.2f}%") .. rst-class:: sphx-glr-script-out .. code-block:: none Star composition (wt% oxides): SiO2: 32.01% FeO: 46.02% MgO: 21.97% .. GENERATED FROM PYTHON SOURCE LINES 28-31 Calculate Mineralogy -------------------- Given a bulk silicate planet composition (wt% oxides), CIPW normative mineralogy predicts the equilibrium mineral assemblage. .. GENERATED FROM PYTHON SOURCE LINES 31-40 .. code-block:: Python bsp = {"SiO2": 45.0, "Al2O3": 4.0, "FeO": 8.0, "MgO": 38.0, "CaO": 3.5} mineralogy = sg.calculate_mineralogy(bsp) print("Mantle mineralogy (molar fractions):") for mineral, fraction in mineralogy.items(): print(f" {mineral}: {fraction:.4f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Mantle mineralogy (molar fractions): olivine: 0.1776 clinopyroxene: 0.0255 orthopyroxene: 0.0323 garnet: 0.0346 .. GENERATED FROM PYTHON SOURCE LINES 41-44 Normalize for ternary plotting ------------------------------ The ``plot_norm`` function normalizes olivine, clinopyroxene, and orthopyroxene to sum to 1 — ready for a ternary diagram. .. GENERATED FROM PYTHON SOURCE LINES 44-51 .. code-block:: Python ternary = sg.plot_norm(mineralogy) print("Ternary-normalized (ol + cpx + opx = 1):") for mineral, fraction in ternary.items(): print(f" {mineral}: {fraction:.4f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Ternary-normalized (ol + cpx + opx = 1): olivine: 0.7546 clinopyroxene: 0.1082 orthopyroxene: 0.1372 .. GENERATED FROM PYTHON SOURCE LINES 52-55 Visualize the mineral assemblage --------------------------------- A pie chart shows the relative proportions of each mineral phase in the predicted mantle. .. GENERATED FROM PYTHON SOURCE LINES 55-74 .. code-block:: Python # Filter out zero-fraction minerals for a cleaner chart nonzero = {m: f for m, f in mineralogy.items() if f > 0} minerals = list(nonzero.keys()) fractions = list(nonzero.values()) cmap = plt.colormaps["Set2"] colors = [cmap(i) for i in range(len(minerals))] fig, ax = plt.subplots(figsize=(6, 6)) ax.pie( fractions, labels=minerals, autopct="%.1f%%", colors=colors, startangle=140, ) ax.set_title("Mantle Mineralogy\n(CIPW normative, molar fractions)", fontweight="bold") plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_star_to_mineralogy_001.png :alt: Mantle Mineralogy (CIPW normative, molar fractions) :srcset: /auto_examples/images/sphx_glr_plot_star_to_mineralogy_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.044 seconds) .. _sphx_glr_download_auto_examples_plot_star_to_mineralogy.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_star_to_mineralogy.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_star_to_mineralogy.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_star_to_mineralogy.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_