Snowpiles

Here’s a fun little visualization: the total seasonal snowfall in the continental US for 2017–2018 so far, shown as a relief map:

Animated snow accumulation

Here’s how I made it. First, a Python scraper to pull down the data from the Weather Service:

from datetime import timedelta, date
import urllib

def daterange(start_date, end_date):
    for n in range(int ((end_date - start_date).days)):
        yield start_date + timedelta(n)

start_date = date(2017, 10, 1)
end_date = date(2018, 1, 12)
n = 0
for single_date in daterange(start_date, end_date):
    # print single_date.strftime("%Y%m%d")
    fileToGet = "sfav2_CONUS_2017093012_to_{}12.tif".format(single_date.strftime("%Y%m%d"))
    urlToGet = "http://www.nohrsc.noaa.gov/snowfall/data/{}/".format(single_date.strftime("%Y%m"))+fileToGet

    pad = format(n, '04')
    urllib.urlretrieve (urlToGet, "{}-{}".format(pad,fileToGet))
    n = n+1

Then, everything’s in shell scripts. Convert the WGS84 rasters to Albers:

for i in *.tif; do
    gdalwarp -t_srs "EPSG:102003" -srcnodata "-99999" "$i" ./warped/$i;
    done

Turn those rasters into hillshade frames:

for i in *.tif; do
    gdaldem hillshade -z 5000 "$i" ./hillshade/$i;
    done

I used ImageMagick to turn the TIF images into GIFs, then sew the frames up into an animation:

for i in *.tif; do
    convert $i -crop 1311x850+196+164 +repage -resize 50% $i.gif;
    done

convert -delay 8 -loop 0 *.gif animated.gif 

Finally, gifsicle to shrink the final output size.

gifsicle -O3 animated.gif --colors 64 --use-colormap 'gray' -o animated-small.gif