This is WELL beyond my small sphere of understanding but while reading around on solar spectra, I came across the Planck’s law for the theoretical black body radiation for an object (the sun in my case – and stars are a pretty close approximation…apparently).

On various graphs (like the one above), I had seen the black-body irradiance for the sun alongside the various measured spectra, so I wanted to include it on my graph – see this post. I decided to work it out for myself.

The radiance at whatever wavelength is solely dependent on temperature – in the case of our sun ~5800K (though the graph above has 6000K and I have seen elsewhere 5777K).

Planck’s law gives you radiance (in W/m²/sr), which is independent of any distances. I struggle with getting my head round radiance and find irradiance (in W/m²) a little more relatable. You can’t directly convert from radiance to irradiance since there are some other parameters to consider – this question on physics stack exchange helped. The conversion does mean it becomes an estimate since it requires the source (the sun) and point of interest (the earth) radii.

Graph below is just me screwing around on CodePen.

See the Pen eaWPGa by Jon Robinson (@aegis1980) on CodePen.light

If you are a physicist or physics student then this is probably all obvious, and if you are not I cannot imagine why you would be trying to do it, but I have included my maths below, for providence.

I have been screwing around with R, so here it is in that weird language:

### In R

```k <- 1.3806485279e-23; #Boltzmann constant m2 kg s-2 K-1
h <- 6.62607015e-34; #Planck constant J/s
c <- 2.99792458e8; #Speed of light m/s
Rsol <- 0.0046491; # radius on sun, in AU
Re <- 1.0; # distance to earth from sun, in AU (=1!)

# lamba = wavelength in nm,
# T = black body temp (K)
# output in W/m2/sr (not nm2)
PLANK_RADIANCE <- function (lambda, T) {
l <- lambda/1000000000.0; # nm > m
((2.0*h* (c ^ 2)))/(l^5.0)*(1/(exp((h*c)/(k*T*l))-1.0));
}

# lamba = wavelength in nm,
# T = black body temp (K). Sun ~ 5800K
# output in W/m2 (not nm2)
f <- pi * (Rsol/Re)^2.0; # 'f' accounts for lamberts law and distance of earth.
}

```

### In Javascript

I was going to use R for my graphs, but I ended up using Google Sheets as its graphs are regenerated in my posts. So, I ended up rewriting the above as a custom function in Google Sheets (which is surprisingly easy). So here it is in javascript. Function names in caps because that’s how Google Sheets likes it.

```var k=1.3806485279e-23;
var h=6.62607015e-34;
var c=2.99792458e8; //m/s
var Rsol = 0.0046491; //au
var Re = 1.0; //au

var l = lambda/1000000000.0; //convert from nm to m.
return ((2.0*h*Math.pow(c, 2.0))/Math.pow(l, 5.0))*(1/(Math.exp((h*c)/(k*T*l))-1.0));
}