THE REGEX KING

jeff sisson's blog (email me)

sunrise sunset photos

12 Jul 2019

I wanted to rig up some way to automatically take a photo of every sunrise and sunset. New York City has spectacular sunsets, but I’ve always felt weird about taking photos of them because I experience an “observer effect” where I feel like the sunset doesn’t hit you as hard if you’re busy documenting it. Knowing that a camera will be capturing the sunset automatically is ne way to enjoy it without a lens while still knowing that if I want to return to savor it later, I can.

(I’d always assumed that part of reason we have good sunsets here is the poor air quality, but it turns out this isn’t true! Check out this comprehensive tour thru why clean skies lead to better sunsets from Stephen F. Corfidi at NOAA.)

To take the sunrise/sunset photos, I bought a Raspberry Pi Zero W, which is a cheap, small linux computer that has a camera attached and is small enough that it can be mounted to a window with suction cups.

The Raspberry Pi makes it easy to take a photo on demand with a command line utility called raspistill. But I needed a way to take the photos at precisely sunrise and sunset. I’d always heard of the terms “civil twilight” or “nautical twilight”, and Wikipedia has a great illustration of the differences between these different types of light that occur at sunrise and sunset; the main difference between these is the angle of the sun. For my purposes, I wanted to take a photo when the top of the sun was at the horizon line.

To make this happen, I found a clever open source command line program called sunwait. You give it your latitude/longitude, whether you’re interested in sunrise or sunset, and what kind of twilight you’re interested in (e.g. daylight | civil | nautical | astronomical) and it very simply waits from now until the correct moment occurs. This makes it suitable for use in a program that runs on a schedule (e.g. cron) — you can run your program at the same time every day and sunwait will wait to do whatever you want to do afterwards until the correct sunrise/sunset moment.

Here’s what my script that I use to take the photo looks like:

# this halts the script until the sunrise/sunset event has happened,
# at the "daylight" setting, which is when the top of the sun is at
# zero degrees
/home/pi/sunwait-master/sunwait wait $SUNTIME daylight $LATITUDE $LONGITUDE;
# this takes the picture, with a watermark showing the date/time
/usr/bin/raspistill --rotation 270 --height 2000 \
	-ae 90,0xff,0x808000 --annotate "$(date)" \
	--timeout 4000 --nopreview --output $FILENAME;
# ...then I upload the jpeg to my web server automatically

And here’s an example of a sunrise on a day that started out cloudy and became dreamy:

In the longer term, I want to try to figure out how to use these images to divine further data about the current weather conditions (e.g. cloud identification), but for now I’m completely content looking at the day’s sunrise & sunset! You see them update daily near the bottom of the page on Big Boy Weather.

  • Bennett on : Hey Jeff is there a page where you can see all the past sunsets? Or maybe not because thats a lotta images

  • Jeff on : I was saving the images for a while, but at some point that broke (it ate up too much space because each image is pretty big) and when I went to fix it I kind of took it as a signal that maybe the images should be ephemeral anyways!

Write a comment...