Visualizing the Speed of Light with Python

Creating simple visualization showing the time and distance of light traveling in outer space step by step

Boriharn K
Towards Data Science

--

Photo by Zetong Li on Unsplash

I was taught in science class that light is super fast. Its speed, in a vacuum, is approximately 3 x 10⁸ meters per second (186,282 miles per second). Light takes about 8.3 minutes to travel from the Sun to Earth. I had to remember all this information with my imagination since it is impossible to observe the speed of light.

Recently, I found an article called Visualizing the Speed of Light (Fast, but Slow). There is a video showing the speed of light in real-time traveling in the Solar System. This is a genius way to show how fast the speed of light is.

Outer space is enormous, and there are many astronomical objects. Thus, it will be useful to create a visualization selecting astronomical objects that we want. This article will show how to make simple animation showing light with its time while moving in space with Python.

An example of visualization in this article. The distance and time that sunlight travels to the Outer Planets. Animation by the author. Wallpaper photo by Eduardo Rosal on Unsplash.

Let’s get started.

The Inner Planets

Firstly, we are going to visualize the light traveling from the Sun to the Inner Planets, which are Mercury, Venus, Earth, and Mars.

Create DataFrame

We will manually create a simple DataFrame on Python with pd.DataFrame. I gathered the data used in this article by myself. Various astronomical data can be found on Wikipedia. If something is not correct, please let me know in the comment.

After importing libraries, create three lists: object name, distance, and radius. Then, create a DataFrame from these three lists.

The distance is aphelion, the point in the orbit farthest from the Sun. It can be changed to perihelion, the point in the orbit nearest to the Sun, or semi-major axis, the mean value of perihelion and aphelion. The radius is for calculating the size later.

Total time can be calculated by dividing the distance by the speed of light (299,792,458 m/s). The following code shows how to get the total number of times in minutes which will be used to create a list of the distance of light.

To work with Plotly, which will be explained next, we need to create a DataFrame with a group of data at each minute. We can multiply the number of minutes with the object DataFrame and concatenate them. Then, create the time and Y-axis column.

Manually create a Light DataFrame. This DataFrame is for showing the movement of light in the animation.

Concatenate the object and light DataFrame together. The visualization will be in two dimensions. Thus, we can calculate the area of each object by multiplying radius² with the number Pi.

The sun is too enormous compared with the planets in the Solar System. If we directly plot them, there will be too much difference in the scatter size. We should increase the area of the other planets before plotting to show the bodies in the animation. Please, take into account that the obtained size in the result will not be to scale.

The astronomical unit (AU) is a unit of length. 1 AU is equal to the distance from the Sun to Earth. To make the result more informative, create an AU column by dividing the distance of each object by 149,597,871 km. Lastly, create a text column for annotation.

Visualization

Here comes the visualization part. We will use Plotly, a Python graphing library, which is easy to use for making interactive graphs. Plotly is powerful for plotting graphs due to its functions for customizing.

As an example, let’s start with a simple interactive scatter plot.

Visualization of the speed of light with the distance of the Inner Planets using Plotly. Image by the author.

To improve the result, define a dictionary of each celestial object with color. The color codes below are used as examples.

The following code shows how to improve the result by assigning the color to each astronomical object and adding a background wallpaper. The wallpaper is retrieved from Unsplash by Eduardo Rosal.

Voila!!…

The distance and time that sunlight travels to the Inner Planets. Distance to scale. Size not to scale. Animation by the author. Wallpaper photo by Eduardo Rosal on Unsplash.

Now, let’s go further by applying the codes to other celestial objects.

The Outer Planets

The Outer Planets are Jupiter, Saturn, Uranus, and Neptune. Compared with the inner planets, these planets are much larger. They are called gas giants since they are primarily made of gases and liquids.

Manually create a DataFrame of the Sun and the Outer Planets.

Define a function to simplify the steps to get a DataFrame for plotting.

Apply the function

Create a column to deal with the size and a text column for annotation.

Visualize the data.

Ta-daaaaa

The distance and time that sunlight travels to the Outer Planets. Distance to scale. Size not to scale. Animation by the author. Wallpaper photo by Eduardo Rosal on Unsplash.

The sun to FarFarOut

I’m always curious what is the farthest object that orbits the Sun. With quick research, it is an object called FarFarOut. The name sounds very interesting to me. It is a trans-Neptunian object, a minor planet that orbits the Sun at a greater average distance than Neptune. Thus, we will also plot Neptune to compare the result. Let’s see how far FarFarOut is.

Create a DataFrame.

Due to the distance between the Sun and FarFarOut being long, the speed of light will be used in kilometer per hour units to speed up the result.

Create a column to deal with the size and a text column for annotation. The time unit is in hours. FarFarOut is too small when they are plotted. We can use ^ (caret symbol) to point to its position.

Visualize the data.

The distance and time that sunlight travels to FarFarOut. Distance to scale. Size not to scale. Animation by the author. Wallpaper photo by Eduardo Rosal on Unsplash.

Each planet with its moon.

The planets with the moons in the Solar System are Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. Here I will plot some of their moons: Moon, Deimos, Callisto, Iapetus, Oberon, and Neso, respectively.

If you want to experiment with their other natural satellites, the code can be modified.

Create a list of the planets and moons and a dictionary to assign Y-axis values.

Apply the function.

Assign the Y-axis values to the objects with the dictionary. Create a column to deal with the size and a text column for annotation.

Finally, visualize the data.

Voila!!…

The distance and time that light travel from planets to their moon. Distance to scale. Size not to scale. Animation by the author. Wallpaper photo by Eduardo Rosal on Unsplash.

About the data

As I mentioned, I gathered the astronomical data used in this article by manually looking them up on Wikipedia. These data can be changed in the future. If something is not correct or up to date, please let me know in the comment.

Moreover, the astronomical sizes, in reality, are too different such as the Sun and the Moon. This is a limit when they are scaled for plotting. Thus, be aware that some results in this article are not to scale.

Summary

This article has shown how to create a simple animation to visualize the speed of light. Other celestial objects can be plotted by applying the same method. If you have a suggestion or question, please feel free to leave a comment.

Thanks for reading.

These are other articles about data visualization that you may find interesting.

  • 8 Visualizations with Python to Handle Multiple Time-Series Data (link)
  • Visualizing the Invisible SO2 with NASA Data and Python (link)
  • Image Color Extraction with Python in 4 Steps (link)

Reference

--

--

a data visualization enthusiast | I also care about environmental issues.