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.

[codepen_embed height=”703″ theme_id=”light” slug_hash=”eaWPGa” default_tab=”result” user=”aegis1980″]See the Pen eaWPGa by Jon Robinson (@aegis1980) on CodePen.[/codepen_embed]

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) PLANK_IRRADIANCE <- function (lambda,T=5800) { f <- pi * (Rsol/Re)^2.0; # 'f' accounts for lamberts law and distance of earth. f*PLANK_RADIANCE(lambda,T); }

### 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 function PLANK_RADIANCE(lambda, T) { 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)); } function PLANK_IRRADIANCE(lambda,T) { var f=Math.PI * Math.pow(Rsol/Re,2.0); return f*PLANK_RADIANCE(lambda,T); }

The only downside the Google Sheets custom function was I think it outsources all the calculations to their servers (rather than just do them on your local processor – maybe you can change that somewhere?) so for 50% of my 500+ wavelength value I got the *too-many-requests *error below when I *filled-down*:

## An aside

I really don’t quite get black-body radiation -it quite fascinating to think EVERYTHING glows. There is an interesting calculation on Wikipedia where it is used to work out a human’s wattage (~100W), a number which actually coincides, oddly-but-nicely, with something I was doing at work today.