matatu blog

Brian writes about computing

The Earth from Space

Feb 28, 2019

on your desktop

Al Gore once said that he wanted to put a spaceship up that would have a continuous complete picture of earth from space. So that we could just watch it. Or maybe watch ourselves?

Years later this led to NASA's Triana mission (which became NOAA's DISCOVR), which involved putting a spacecraft at the L-1 Lagrange point - the point in space where the gravitational pull from the Sun and the Earth are the same.

DISCOVR sits there from far away and watches us. New images are generated every two hours by NASA's EPIC instrument.

But what if we want a closer picture, and one that is updated more often?

Well, GOES 16 is a nice geostationary spacecraft from which we can get a new picture every few minutes! You can get the latest one from the same URL. That means it's super easy to make it into a continuously updating background for your desktop!

However, the image is just a little too nice to be a background.

Therefore I have to tone it down a bit -- that is turn down the brightness.

Also, I want to add some clocks, because I like to know what time it is when I am working. I want one clock on the east coast and one clock on the west coast.

Enter GraphicsMagick. On OS/X brew install graphicsmagick will give you the gm command.

After that, first let's reduce the brightness and saturation. The way to reduce the brightness is to use convert with the -modulate parameter. The first number is the brightness, the second one is saturation. 100 is the max.

Second -- I like having the time in the background -- and I'd like that for two time zones so that I can easily see what time it is in California.

Finally, osascript on OS/X can set the background. For linux, you'd want something like xsetroot.

I wrapped my script in another one to call it every two minutes.

#!/bin/sh -e

# Get the latest file
url=https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/1250x750.jpg
curl -s $url > in.jpg

# Darken it
gm convert -modulate 40,40,100 in.jpg darker.jpg

# Add timestamps
now=`date +%s`
cali=$(TZ=US/Pacific date +'%l:%M %p')
philly=$(TZ=US/Eastern date +'%l:%M %p')
gm convert darker.jpg -font Courier -pointsize 40 -box black -fill '#bbbbff' \
-draw "text 25,240 '$cali'" \
-draw "text 870,175 '$philly'" \
"file-$now.jpg"

# update background, and schedule for removal
cwd=`pwd`
osascript -e "tell application \"Finder\" to "\
"set desktop picture to POSIX file \"$cwd/file-$now.jpg\""
mv $cwd/$file-$new.jpg last.jpg    
while true; do
  ./get-latest
  sleep 120
done    

Here's the result.

Conclusions

  • GraphicsMagick can lighten images and add text
  • NASA and NOAA provide cool pictures
  • Writing scripts to get cool pictures and manipulate them is fun