.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_unit_conversions.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_unit_conversions.py: Composition Unit Conversions ============================= The same stellar composition viewed in different unit systems. ``stellar_geology`` supports wt%, mol%, and mole fraction representations. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Start with a star slightly enriched in iron. .. GENERATED FROM PYTHON SOURCE LINES 10-19 .. code-block:: Python import matplotlib.pyplot as plt import stellar_geology as sg star = sg.Star( stellar_dex={"Fe": 0.15, "Mg": 0.05, "Si": -0.02}, name="HD 10700", ) .. GENERATED FROM PYTHON SOURCE LINES 20-23 Weight percent oxides --------------------- The most common representation in geochemistry. .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python wtpt = star.get_composition(units="wtpt_oxides") .. GENERATED FROM PYTHON SOURCE LINES 27-30 Mole fraction oxides -------------------- Useful for thermodynamic calculations. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python molfrac = star.get_composition(units="molfrac_oxides") .. GENERATED FROM PYTHON SOURCE LINES 34-37 Mole fraction on a single-oxygen basis --------------------------------------- Common in mineral physics and mantle geochemistry. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python single_o = star.get_composition(units="molfrac_singleO") .. GENERATED FROM PYTHON SOURCE LINES 41-44 Compare all three unit systems ------------------------------ The same composition looks quite different depending on the unit system. Weight percent emphasizes heavy oxides (FeO, SiO2), while mole fraction emphasizes the most abundant molecules. .. GENERATED FROM PYTHON SOURCE LINES 44-66 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(12, 4)) axes[0].bar(list(wtpt.keys()), list(wtpt.values()), color="#5e4fa2") axes[0].set_title("wt% oxides") axes[0].set_ylabel("wt%") axes[0].tick_params(axis="x", rotation=45) axes[1].bar(list(molfrac.keys()), list(molfrac.values()), color="#3288bd") axes[1].set_title("Mole fraction oxides") axes[1].set_ylabel("Mole fraction") axes[1].tick_params(axis="x", rotation=45) # Single-O basis uses element names (Si, Fe, Mg) rather than oxide formulas axes[2].bar(list(single_o.keys()), list(single_o.values()), color="#66c2a5") axes[2].set_title("Mole frac. (single-O)") axes[2].set_ylabel("Mole fraction") axes[2].tick_params(axis="x", rotation=45) fig.suptitle(f"{star.name} — Three unit systems", fontweight="bold") fig.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_unit_conversions_001.png :alt: HD 10700 — Three unit systems, wt% oxides, Mole fraction oxides, Mole frac. (single-O) :srcset: /auto_examples/images/sphx_glr_plot_unit_conversions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.411 seconds) .. _sphx_glr_download_auto_examples_plot_unit_conversions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_unit_conversions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_unit_conversions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_unit_conversions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_