Skip to content

On graphing the stars

Try getting a new look on the sky and find a new graphing library for python.

Hello dear reader and a warm welcome to my first blog post to this project and also my first blog post ever. I am Jannik Baumgart and I want to bring life and light to a project, which kept me busy for a long time and will do so in the future.

While the Project Nahual will be a secret for a little bit longer, I want to share insights I learn on the way. This brings me to the topic “On graphing the stars”. Part of Nahual is the detailed modelling of solar wind, a phenomenon happening every second in our solar system and a reason for polar lights. Because looking at the sky to find data of a mostly invisible phenomenon is not very promissing, our Cyberspace seemed like the easier way.

Lo and behold! Since solar wind is also “weather” in some context the National Oceanic and Atmospheric Administration (NOAA) of the USA provides a solar wind prediction (https://www.swpc.noaa.gov/products/wsa-enlil-solar-wind-prediction). The data of their prediction is a product of the WSA-ENLIL model, which in turn takes satellite data and calculates the solar wind plasma velocity, density and polarity around the sun and our earth. They also provide a 2D visualization, which I already really like.

However since I plan to model changes in the solar wind, the basic visualization of precalculated data is not sufficient for me. Also moving in a 3-dimensional room with 2-dimensional view always takes brain capacity. Thankfully the NOAA provides the data to download. Because of this I was keen to build a visualization myself.

The challenge: visualize complex data in a 3-dimensional room with spheric coordinates over a timeframe.

Since as a hobby-analyst python is my home, my first stop was matplotlib, the standard graphing library for data in python. It is powerful and fits most needs, but definitely gave me a hard time. Between clunky function calls and misleading error messages, I repeatedly looked for alternatives and finally found the Plotly library.

Especially the plotly.express functions are easy to use and provide the opportunity to transform massive datasets to easily comprehensible graphs. To let you follow me here, I provided everything relevant as a download file.

For the following plotly example I provided drastically shortened and reformatted data (to save us all download time). It is now in cartesian and tidy format. With mainly the (optional) visual tweaking we get a wonderful 3D visualization out of plotly. This python code produces an HTML version. Down below is also a rendered video of the full dataset.

import pandas
import plotly.express

path = "wsa_enlil_data_cme_2022-02-03.csv"
data = pandas.read_csv(path)

scatter_default = {"x": "x_coord",
                   "y": "y_coord",
                   "z": "z_coord",
                   "animation_frame": "absolute_time",
                   "color": "velocity_[m/s]",
                   "range_color": [230000, 680000],
                   "size": "density_[kg/m3]",
                   "template": "plotly_dark",
                   "color_continuous_scale": "jet",
                   }

layout_default = {"title": {"text": "solar wind velocity"},
                  "scene_camera": {"up":{"x": 0, "y": 0, "z": 1},
                                   "center": {"x": 0, "y": 0, "z": 0},
                                   "eye": {"x": 0.8, "y": -0.4, "z": 0.25}
                                   }
                  }

traces_default = {"marker": {"opacity": 1,
                             "line": {"width": 0}
                             },
                  "selector": {"mode": "markers"}
                  }

fig = plotly.express.scatter_3d(data, **scatter_default)
fig.update_layout(**layout_default)
fig.update_traces(**traces_default)

fig.show()
Solar wind prediction visualization

On a closer look on either the code or the video you can see, that this visualization is not only in 3D, it also shows the solar wind plasma velocity and density together. While the color represents the velocity, the size of the datapoints represents the density.

Maybe now you also wondered why there is also only a sphere as well as a vertical and a horizontal plane. Unfortunately this is currently all the 3D data we get from the download. This is also an advantage of the chosen plot type. In the basic visualization you don’t know on which data you rely on and which data is just not there. In this example you can even differentiate the outer data points and could do so in the middle, when modifying the view. For the project I will need more datapoints. You will probably see a deep dive to the WSA-ENLIL model from me in the future.

In short: Python Plotly is pretty awesome when you come from matplotlib. The WSA-ENLIL model is awesome and the NOAA and the NASA are awesome to provide this for free. However there is still very much to do and you will get to see it, if you are interested.

Direct link to article and comments: https://nahual.eu/on-graphing-the-stars/

Leave a Reply

Your email address will not be published. Required fields are marked *