How much does CO2 absorb?

It would be useful to figure out what percentage of Earth’s outgoing longwave radiation CO2 absorbs.

It’s necessary to have line-by-line CO2 spectrum data. I got my data here.

I cleaned up the data, and uploaded it to pastebin. Should you download it or copy/paste it, you need to save it co2.csv .

I made a program to analyze the data and plot a pretty chart. You will need gnuplot (sudo apt install gnuplot). Copy and paste the following text into a new file called

# Zoe Phin, 2019/11/13

gas=$2; GAS=`echo $gas | tr [:lower:] [:upper:]`
declare -A color; color[co2]=green; color[h2o]=blue

awk -v FLUX=$1 ' BEGIN { PI=atan2(0,-1); 
    c=299792458; h=6.62607015E-34; k=1.38106485E-23; s=5.670367e-8
function P(T,w) { return (2*PI*h*c^2/(w/1e6)^5*1/(exp(h*c/(k*T*w/1e6))-1))/1e7 }
!/^#/{  SR = P((FLUX/s)^0.25, $1)
    if (SR > 0.005) printf "%.4f %.4f %.4f\n", $1, SR, SR*$3
    for (w = 40.005; w <= 104.12; w+=0.005) {
        printf "%.4f %.4f 0\n", w, P((FLUX/s)^0.25, w)
}' ${gas}.csv > ${gas}.dat

awk '{D=$1-LW; printf "%.9f\n", D*LG; LW=$1;LG=$3}' co2.dat |\
    awk -v FLUX=$1 '{G+=$1}END{print G*10" "G*10/FLUX}'

echo "set term png size 740,460
unset key; set title '${GAS} Absorption'
set ylabel 'Spectral Radiance (W/m²/μm)'
set xlabel 'Wavelength (μm)'
set xrange [2.8:104.2]
set logscale x
set mxtics 10; set mytics 5; set xtics out
plot '${gas}.dat' using 1:2 w boxes fs solid 1.0 fc 'black',\
     ''           using 1:3 w boxes fs solid 1.0 fc '${color[$gas]}'    
" | gnuplot > ${gas}-spectrum.png

The program takes 2 arguments. The first is Earth’s outgoing surface flux. I will use the value found in the latest NASA’s Energy Budget. The second argument is the type of gas. I intend to make other gases available in the future, but for now only “co2” is available. Now we run:

> bash 398.2 co2

The result is:

20.4858 0.051446

The first number is in W/m², and the second is a proportion to the flux you used. Here is what the plot looks like:

The answer is to our question is 5.14% (20.49 W/m²)


Published by Zoe Phin

7 thoughts on “How much does CO2 absorb?

  1. Hi Zoe.
    I thought your small piece of code would be a good exercise to translate into python. How wrong can you get?
    I hope you don’t mind if I ask a few 🙂 questions?

    Does gas=$2 and FLUX=$1 refer to the variable assignments in the bashfile command?

    What are the headers for the data in co2.csv?

    What do the variables: c,h,k,s mean?

    Define function P(T,w) RETURN calculation of equation (where is the equation from??)

    What does this ‘!/^#/’ do?

    Is this the correct pseudo code for what follows?

    SR = call P with FLUX to the power 0.25 and FLUX i.e. $1??
    If SR > 0.005 then BREAK and print to file (FLUX, SR, SR*$3) (what is $3??)
    loop w = 40.005 to 104.12 STEP 0.005
    call function P with FLUX / s power 0.25 and write “w ,function result, w” to file?

    co2.csv is the input and co2.dat is the output seems clear (ish)

    I can’t follow:
    “awk ‘{D=$1-LW; printf “%.9f\n”, D*LG; LW=$1;LG=$3}’ co2.dat |\
    awk -v FLUX=$1 ‘{G+=$1}END{print G*10″ “G*10/FLUX}'”
    Although I assume it’s some printing commands?

    The plotting commands are clear. However, I end up with a square edge on the outgoing surface flux plot at the higher end of the spectrum.

    Apologies for the dumbass questions!


    1. Without looking at the code and with little time …

      ‘!/^#/’ Is a selector that means: NOT lines that start with # (no comments)

      In awk, $N means Nth column. No relation to bash command/function parameters. $0 means all columns.

      P(T,w) is Planck’s Law for wavelengths, and I use adjustments for microns. I know it’s correct because the sums at all wavelengths adds up to Stefan-Boltzmann Law. c,h,k are Planck’s Law params.
      s is sigma of Stefan-Boltzmann Law

      The commands you can’t follow are trying to add up to final W/m^2.

      The 3 columns of pastebin file are:
      Micron, Transmission, Absorption

      Only $1 and $3 matter.

      I want you to know that while I did everything the correct way, as climate scientists would do, it may not be the objective correct way. I.e. I did it by the book, but the book may be “whack”.

      Also, I later discovered the data is not for all temperatures, pressures, heights in the atmosphere.

      I reworked the analysis in this article (without publishing) using the best data available, and I got something like 5.9% for the atmosphere at an average height. I used US Standard Atmosphere as the base, and I’m slowly learning it’s completely outdated – even though used by nearly everybody.

      I would like to redo this article, but I’m still investigating what the proper base should be.

      You can replicate the code but please don’t think this is the final word. Everything could change.

      May I recommend a little simple tutorial:

      Maybe I’ll make my own tutorial sometime.

      Make sure you are using GAWK, not mawk, as I didn’t notice my install had.


  2. Thanks for the quick answer, Zoe.
    I’ll be sure to look at the awk tutorial!
    I’m afraid I am a python nerd and I am interested in how python data structures and computational methods could apply to your code. Purely because it was beautifully and concisely written.
    I wasn’t, in this case, interested in the science 🙂
    If I get anywhere with it, I’l let you know.
    In the meantime, I’m looking at how long the ball is actually in play in SPFL football matches……..I’m also a football stats nerd!

    Liked by 1 person

  3. Hi Zoe,
    After a few hours, I managed to hack your code into python.
    It turned out some astronomy nerds have a library called PyAstronomy which kindly works out Planck’s law which is the same as yours without the big long calculation and all the variable declarations.
    Thanks for the pointers on awk. I had no idea it was so powerful.
    I have always been skeptical of ‘back radiation’ or DLR (Downward Long radiation)
    Does CO2 ‘trap’ heat? No. that is just dumb. Does it absorb ‘heat’? That’s just the same as trapping it.
    Does it react to energy at certain wavelengths? Yes. Energy is used to do work. Oscillation of covalent bonds.
    Energy can neither be created or destroyed. So does it re-emit from this interaction with CO2 at the same frequencies? I don’t think so.
    Big questions which I don’t know the answer to.
    Nice to see your ‘musings’ getting more hits!

    Liked by 1 person

  4. Your style is very unique in comparison to other folks I’ve read stuff from. Many thanks for posting when you’ve got the opportunity. Guess I will just bookmark this blog.

    Liked by 1 person

  5. I love your site.
    You have explored all the questions I am starting to ask, and I found you through ’emissivity’. I’d just posted about the earth being a baked potato in space heated by sunlight, but starting off at 5000K or so. Humans need neat ideas to understand the concepts.
    Lots of yummy mind chewing. And you seem a lot cleverer than me, damn! even though I used to be straight ‘A’s. (I’m 60 now and am straight ‘C’s). I haven’t even got my Pi going yet, I’m still trying to come up with a good explanation of Computers for a 6 year old. A ‘logic analysing code-messaging machine’ doesn’t quite cut it. I’m going with a ‘deciding’ machine or something.

    Have you come across Dr Roger Higgs? I guess but I will post anyway. He is coming at this from a geological angle.
    Bye !
    Peterg, Uk.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: