.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_planet_compositions.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_planet_compositions.py: Create a Planet from a Star =========================== The core workflow: create a star from spectroscopic dex measurements, calculate a derivative bulk silicate planet composition, and visualize its chemistry. .. GENERATED FROM PYTHON SOURCE LINES 7-8 .. code-block:: Python :dedent: 1 .. GENERATED FROM PYTHON SOURCE LINES 10-13 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 13-29 .. code-block:: Python import stellar_geology as sg import pandas as pd import plotly.graph_objects as go 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 30-33 Calculate a dervative bulk silicate planet composition ------------------------------------------------------ To get from a `Star()` to a bulk silicate planet composition, we simply create a `Planet()` object from our star, which then allows us to access its bulk composition and bulk silicate composition. .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python planet = sg.Planet().from_star(star) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Let's look at the bulk planet composition first ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python bulk = planet.get_composition( which="bulk_planet", units="molfrac_elements" ) .. GENERATED FROM PYTHON SOURCE LINES 44-47 Now, the bulk _silicate_ composition ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To do this, we provide a fractionation factor to partition elements between the core and bulk silicate planet via the argument `alphas`. `alphas` is a dictionary that looks like: {"Fe": 0.3, "Ni": 0.1}. In that case, 30% of the planet's Fe and 10% of its Ni will go into the metallic core. "Fe" is required at a minimum, but additional elements may be passed here. .. GENERATED FROM PYTHON SOURCE LINES 47-58 .. code-block:: Python # first let's set the alpha value for our planet planet.set_alphas({"Fe": 0.3}) # now we can calculate the planet's bulk silicate composition bsp = planet.get_composition( which="bulk_silicate_planet", units="molfrac_elements" ) bsp .. rst-class:: sphx-glr-script-out .. code-block:: none {'Si': 0.4515931220452917, 'Fe': 0.08629480080357436, 'Mg': 0.462112077151134} .. GENERATED FROM PYTHON SOURCE LINES 59-62 Now let's visualize these compositions -------------------------------------- First we use stellar_geology's ternary_plot, which is a wrapper for plotly's go.Scatterternary. Any argu ments that you can pass to go.Scatterternary are accepted by sg.ternary_plot and will be passed along. Try passing `ternary=dict(bgcolor="#333333")` as an argument in the ternary_plot() call. .. GENERATED FROM PYTHON SOURCE LINES 64-70 .. raw:: html
💡 Note: ``ternary_plot`` creates interactive plots, even right here on the ReadTheDocs web page! Try clicking on one of the markers in the legend.
  .. GENERATED FROM PYTHON SOURCE LINES 70-86 .. code-block:: Python fig = sg.ternary_plot( bsp, a="Si", b="Fe", c="Mg", title="Planetary compositions, molar fraction", name="BSP", width=650, base_marker=dict(size=20, color="#ff5252", line=dict(color="#000000", width=1.5) ), ) fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 87-90 Add more to the plot ^^^^^^^^^^^^^^^^^^^^ sg.ternary_plot() returns a plotly figure object, so we can add to the plot as we would normally with plotly's go.Scatterternary. Let's add our bulk planet composition. .. GENERATED FROM PYTHON SOURCE LINES 90-104 .. code-block:: Python fig.add_trace(go.Scatterternary( a=[bulk["Si"]], b=[bulk["Fe"]], c=[bulk["Mg"]], mode="markers", name="Bulk Planet", marker=dict( size=20, color="#ffcd40", line=dict(color="#000000", width=1.5) ) )) fig .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.214 seconds) .. _sphx_glr_download_auto_examples_plot_planet_compositions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_planet_compositions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_planet_compositions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_planet_compositions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_