# Animation: Planck's law

Animation of how the spectral density of electromagnetic radiation emitted by a black body in thermal equilibrium varies at at different temperatures.

This is work in progress. Script is in `bash`.

Requires `gnuplot`.
Cookie for those who manages to do Planck’s law in `gmt` or `bc`.

``````#to-do:
# - SB-law - total energy
# - dominant Lambda - for each temperature
# - add some static curves, e.g. for the sun T=5800, and some others objects
# - legend becomes wider when T goes from two digits to three to four. Make wide enough or use printf??

cat <<eof > plancks-law.gpl
# input temperature via command line, e.g.:
# gnuplot -e "T=600" plancks-law.gpl
# constants
c=2.99792458e8
# Planck's constant
h=6.62606896e-34
# Boltzmann constant
k=1.3806504e-23
# Temperature - not in use. We get this from argument
#T=573
# Wavelength - not in use.
#L=1000e-9
# For Wien's displacement law
b=2.90e-3
# sigma, stefan-boltzmann constant
s=5.670374419e-8

set table

f(x)=((2*pi*h*c**2)/(x**5)*(1/(exp((h*c)/(x*k*T))-1)))

set samples 1000
set xrange [10e-9:15e-6]
plot f(x)
eof

cat <<eof > plancks-law-frame.sh
gmt set GMT_THEME minimal

echo "10e-9 ifg ultraviolet" > light.x
echo "400e-9 ifg visible" >> light.x
echo "750e-9 ifg infrared" >> light.x
echo "5e-6 ifg microwave" >> light.x

#pwd
gmt begin
gnuplot -e "T=\\${MOVIE_COL0}" \$(pwd)/plancks-law.gpl | gmt plot -W -R4e-09/5e-06/1e1/5e+14 -JX20c/10c -L+yb -Ggray -l"Temperature [K]: \\${MOVIE_COL0}"
gmt psbasemap -Bxclight.x -BwesN --MAP_GRID_PEN_PRIMARY=black,- --FONT_ANNOT_PRIMARY=6
gmt psbasemap -Bxafg+l"Wavelength" -Byafg+l"Watt/m@+2@+ m" -B+t"Radiated Power Density, Planck's law"
gmt end

rm light.x

eof

# generate values for input
seq 20 20 10000 > time

# run movie script
gmt movie plancks-law-frame.sh -Nplancks-law-gmt -Ttime -Fmp4 -Cuhd -L -P -Z

# clean up
rm time plancks-law.gpl plancks-law-frame.sh
``````
3 Likes

Great!!!

Just a question. What does gnuplot -e do?

1 Like

A fine question! I’m to be considered a beginner in `gnuplot` - make no mistake.

`gnuplot -e` passes an argument (the temperature in this case) to the script.

Best with an example:

``````\$ cat test.gpl
print 5+T

\$ gnuplot test.gpl
"test.gpl" line 1: undefined variable: T

\$ gnuplot -e T=5 test.gpl
10
``````

Ver. 2

``````#!/usr/bin/env bash
#Purpose: Animation of Planck’s law made in gmt from 20 K to 10.000 K
#Date: 20.12.2021
#Author: AnBj
#Requirements: gnuplot

#to-do:
# - add some static curves, e.g. for the sun T=5800, and some others objects
# - legend becomes wider when T goes from two digits to three to four. Make wide enough or use printf??
# - wanted to calculate Planck's law in bc, but bc does not supprt exp ^ (x/n) expressions - see https://stackoverflow.com/questions/28034126/cannot-get-complex-calculation-to-work-in-bc
# - include textual description of what kind of Lambda max we have; microwave, infrared, visible, UV, etc

#can do this with gmt?? gmt math -T20/10000/20 T 2 MUL =
#https://docs.generic-mapping-tools.org/latest/gmtmath.html
cat <<eof > plancks-law.gpl
# input temperature via command line, e.g.:
# gnuplot -e "T=600" plancks-law.gpl
# constants
c=2.99792458e8
# Planck's constant
h=6.62606896e-34
# Boltzmann constant
k=1.3806504e-23
# Temperature - not in use. We get this from argument
#T=573
# Wavelength - not in use.
#L=1000e-9
# For Wien's displacement law
b=2.90e-3
# sigma, stefan-boltzmann constant
s=5.670374419e-8

set table

f(x)=((2*pi*h*c**2)/(x**5)*(1/(exp((h*c)/(x*k*T))-1)))

set samples 1000
set xrange [10e-9:15e-6]
plot f(x)
eof

cat <<eof > plancks-law-frame.sh
gmt set GMT_THEME minimal

echo "10e-9 ifg ultraviolet" > light.x
echo "400e-9 ifg visible" >> light.x
echo "750e-9 ifg infrared" >> light.x
echo "5e-6 ifg microwave" >> light.x

#pwd
gmt begin
gnuplot -e "T=\\${MOVIE_COL0}" \$(pwd)/plancks-law.gpl | gmt plot -W -R4e-09/5e-06/1e1/3.5e+14 -JX20c/10c -L+yb -Ggray
gmt psbasemap -Bxclight.x -BwesN --MAP_GRID_PEN_PRIMARY=black,- --FONT_ANNOT_PRIMARY=6
echo "\\$(printf "%.20f" \\$(echo 2.9*10^-3/\\${MOVIE_COL0} | bc -l)) 3e15" | gmt plot -Sb0.02c -Gblack
gmt psbasemap -Bxafg+l"Wavelength [m]" -Byafg+l"Radiated energy [Watt/m@+2@+ m]" -B+t"Planck's law"
echo "4.9e-6 3.2e14 Temperature [K]: \\${MOVIE_COL0}" | gmt pstext -W -Gwhite -F+jRM
echo "4.9e-6 2.9e14 Total emitted energy [MW/m@+2@+]: \\$(printf "%.0f" \\$(echo 5.670374419*10^-8*\\${MOVIE_COL0}^4/10^6 | bc -l))" | gmt pstext -W -Gwhite -F+jRM
echo "4.9e-6 2.6e14 Dominant wavelength [nm]: \\$(printf "%.0f" \\$(echo 2.9*10^-3/\\${MOVIE_COL0}*10^9 | bc -l))" | gmt pstext -W -Gwhite -F+jRM
gmt end

rm light.x

eof

# generate values for input - these are the T-values; from 20 to 10.000 in steps of 20
#gmt version: gmt math -o0 -T20/10000/20 T = time
#(10000-20)/20=499 frames
seq -w 20 20 10000 > time

# run movie script
time gmt movie plancks-law-frame.sh -Nplancks-law-gmt-movie -Ttime -Fmp4 -Cuhd -L -P -Z

# clean up
rm time plancks-law.gpl plancks-law-frame.sh
``````
2 Likes