Solar Spectrum

I wrote some code to generate a solar spectrum chart from official data. Thought I’d share it with you …

ssi.sh:

# Zoe Phin
# 2020/12/20

require() {
    sudo apt-get install curl nco gnuplot
}

download() {
    curl -o ssi.nc https://www.ncei.noaa.gov/data/solar-spectral-irradiance/access/daily/ssi_v02r01_daily_s20190101_e20191231_c20200226.nc
}

yearavg() {
    ncks --trd -HC -v SSI ssi.nc | awk -F '[= ]' '
        { D[$4]+=$6 } END { for (d in D) printf "%.4f %11.9f\n", d/1000, D[d]/365*1000 }
    ' | sort -n | sed 1d | awk '
        BEGIN { pi=atan2(0,-1); c=299792458; h=6.62607015E-34; k=1.38106485E-23 
            r=695700000; d=149597870700 }
        function P(T,w) { return ((2*pi*h*c^2/(w/1e6)^5)/(exp(h*c/(k*T*(w/1e6)))-1))/1e6 }
        { printf "%s %.9f\n", $0, P(5772,$1)*(r/d)^2 }
    ' > ssi.csv
}

plot() {
    echo 'set term png size 740,370
        set xrange [0:2.5]
        set mxtics 5
        set grid xtics ytics
        set ylabel "Radiance (W/m²/μm)"
        set xlabel "Wavelength (μm)"

        plot "ssi.csv" u 1:2 t "Solar Spectrum" w l lw 1 lc rgb "orange",\
             "" u 1:3 t "5772K Blackbody" w l lw 1 lc rgb "black"
    ' | gnuplot > solar.png
}

Run it:

$ source ssi.sh
$ require
$ download
$ yearavg
$ plot

or

$ . ssi.sh; require && download && yearavg && plot

Data and image contained in ssi.csv and solar.png

Enjoy 🙂 and Happy Holidays! -Zoe

Update

I also made a version for nanometer wavelenths rather than microns …

ssi-nm.sh:

# Zoe Phin
# 2020/12/22

require() {
    sudo apt-get install curl nco gnuplot
}

download() {
    curl -o ssi.nc https://www.ncei.noaa.gov/data/solar-spectral-irradiance/access/daily/ssi_v02r01_daily_s20190101_e20191231_c20200226.nc
}

yearavg() {
    ncks --trd -HC -v SSI ssi.nc | awk -F '[= ]' '
        { D[$4]+=$6 } END { for (d in D) printf "%.4f %11.9f\n", d, D[d]/365 }
    ' | sort -n | sed 1d | awk '
        BEGIN { pi=atan2(0,-1); c=299792458; h=6.62607015E-34; k=1.38106485E-23 
            r=695700000; d=149597870700 }
        function P(T,w) { return ((2*pi*h*c^2/(w/1e9)^5)/(exp(h*c/(k*T*(w/1e9)))-1))/1e9 }
        { printf "%s %.9f\n", $0, P(5772,$1)*(r/d)^2 }
    ' > ssi.csv
}

plot() {
    echo 'set term png size 740,370
        set xrange [0:2500]
        set xtics 200; set mxtics 2
        set ytics 0.2; set mytics 2
        set format y "%.1f"
        set grid xtics ytics
        set ylabel "Radiance (W/m²/nm)"
        set xlabel "Wavelength (nm)"

        plot "ssi.csv" u 1:2 t "Solar Spectrum" w l lw 1 lc rgb "orange",\
             "" u 1:3 t "5772K Blackbody" w l lw 1 lc rgb "black"
    ' | gnuplot > ssi-nm.png
}

Run:

$ . ssi-nm.sh; require && download && yearavg && plot

Published by Zoe Phin

https://phzoe.com

7 thoughts on “Solar Spectrum

  1. You are gradually making me a convert. As soon as I finish restoring the OS on a suicidal Mac mini, I’ll be loading Linux/Freaks on a Dell i7 that suffered a debilitating drive stroke. I can no longer stand not getting in on terse, productive code that up and harvests useful data without so much as a by-your-leave. Many thanks–especially for the derivative of the population growth curve. THAT is a treasure! It takes some of the terror out of staring up an almost vertical slope and wondering whether it will flatten before or after the background radiation curve starts looking vertical in an ominously Malthusian sense.

    Liked by 2 people

        1. Wikipedia uses nanometers. 2nd chart matches it perfectly.
          First chart is in microns, both wavelength and radiance.

          Use my code to modify for your needs 🙂

          Like

  2. The OECD DAC Rio Markers for Climate Handbook gives examples of projects within all sectors that would be eligible for at least a significant climate score. For example, activities in the health sector that incorporate renewable energy sources such as using solar panels to heat water in hospitals could justify a significant mitigation score, while integrating climate education into school curricula could even justify a principal score depending on the design of the program. The fact that very little of the funding channeled toward social sectors is marked as climate-related, suggests that there is significant unexplored opportunity to align projects in these sectors with the goals of the Paris Agreement. The substantial share of funding flowing to sectors such as infrastructure that is not climate-related is particularly concerning as transitioning to a more climate-friendly development model means that all ODA activities in these productive sectors should be undertaken with climate change objectives in mind. Of total funding flowing to infrastructure, 42% is not marked with either climate marker. Similarly, only 16% of funds channeled toward activities in the industry, construction, and mining sector were marked as climate-related in 2018.

    Like

    1. This one works really well, (no surprise), and it denotes that the sun is surfaced by condensed matter, else no ‘blackbody’ curve could be produced. Gaseous Campfire in the Sky myth busted. What’s that now, six down and sixty to go?

      Like

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

<span>%d</span> bloggers like this: