Stellar Luminosities from the Stefan-Boltzmann Equation

Stellar Luminosities from the Stefan-Boltzmann Equation#

William Cerny, Imad Pasha, Yasmeen Asali, Sebastian Monzon (Yale University)

Description: Practice with basic python and data types by inferring the properties of stars with the Stefan-Boltzmann law

Intended Audience: Early Undergraduate

tags: stefan-boltzmann, basic-python, lists

Requirements: requirements.txt (optional)

Last Updated: July 18, 2025

Learning Objectives

  1. Understand how to perform operations on Python variables to carry out computations.

  2. Understand different data types and how to convert between them when needed.

  3. Be able to write, save, and run a basic Python script.

  4. Enable user input to a script for dynamic calculations.

Introduction#

Stars, to zeroth order, can be considered spherically-symmetric blackbodies. Under those conditions, their luminosities can be computed via the Stefan-Boltzmann law:

\[ L = 4\pi R^2 \sigma T^4 \]

where \(R\) is the radius, \(T\) is the effective temperature of the star, and \(\sigma\) is the Stefan-Boltzmann constant, \(\sigma = 5.67 * 10^{-8} \rm \ W/m^{2}/K^{4}\).

The goal of this exercise is to write a code in Python to calculate the luminosity (\(L\)) of a star according to the formula described above.

Basic Scripting#

Here we will create a simple script to hold our calculation, using several variables to aid in our computation.

Dynamic Scripting#

Let’s now improve the usability of our code. Instead of hard-coding (i.e., setting) the values of \(T\) and \(R\) within the script, we will have the script ask for these values from the user when the script is run.

Note

Having users input values at runtime is not the most common way to take dynamic inputs to code. However, it is very useful for highly “interactive” programs like this one.

Fun with Units (Bonus)#

In this bonus exercise, we’ll use the astropy library to handle units more elegantly. The astropy.units module, which we typically import as

import astropy.units as u 

is very useful for handling unit conversions. Meanwhile, the astropy.constants library, e.g.,

import astropy.constants as ac 

provides most constants used in physics and astronomy. You can attach units to a value by multiplying:

some_temperature = 5000 * u.K # Kelvin 

where most of the unit name shorthands are what you would expect.

Practice with List Indexing#

Let’s imagine you have data for bright stars that looks a bit like:

star_names = ["Sirius", "Canopus", "Rigil Kentaurus", "Arcturus", "Vega", "Capella", "Rigel", "Procyon", "Achernar", "Betelgeuse", "Acrux", "Altair", "Aldebaran", "Spica", "Antares", "Pollux", "Fomalhaut", "Deneb", "Regulus", "Adhara"]

star_temperatures =  [9940, 7400, 5800, 4300, 9600, 4900, 12100, 6550, 14600, 3500, 28000, 7700, 3900, 22200, 3400, 4940, 8550, 8525, 12300, 20800]

star_radii = [1.711e9, 7.8e8, 1.227e9, 2.785e9, 2.364e9, 1.192e9, 7.6e8, 7.43e8, 1.586e9, 9.52e10, 6.01e9, 1.656e9, 4.28e9, 7.739e8, 8.12e9, 1.927e9, 1.834e9, 8.48e9, 3.919e9, 4.66e9]