Nathan Grigg

What I want from a weather app

I am always a little disappointed when I look up the current temperature on the internet or a weather app. One number can only tell you so much about what’s going on outside. We try to make up for it by reporting the high and low temperature for the day, but there’s a lot more to a function than one data point plus two extreme values. Luckily the University of Washington records the temperature on the roof of the ATG every minute and allows you do download it in csv format. From there, a little messing with gnuplot makes it readable, and I really know what the temperature is doing. Here’s an example:

Current Weather

The Python script

The Python script downloads the last 12 hours worth of temperature readings from the University of Washington weather station. The readings are available as a csv file. The script then extracts the useful information from the csv file and converts the times into a format that gnuplot understands. Also, it deals with time zone issues. It then feeds the data through gnuplot to draw the graph and outputs the graph to the user. It also caches the graph to prevent unnecessary strain on my or the weather station’s server.

The gnuplot instruction

The main plot command is

plot "-" using 1:2 smooth bezier lt 3 lw 2 notitle

The "-" means the data file will be given on stdin, but you could also use a filename here. The using 1:2 tells it to use columns 1 and 2 for the x and y data, respectively. Then smooth bezier tells it to smooth the data instead of just connecting all the dots. Color is controlled by lt 3 and line weight by lw 2. Counterintuitively, notitle eliminates the key.

Here is the entire gnuplot code:

 1 reset
 3 # configure svg output
 4 set term svg size 600 480 dynamic fname 'Helvetica'
 6 # tell it that the x-axis represents time
 7 set xdata time
 9 # set the format of the data file
10 set timefmt "%Y-%m-%d-%H-%M"
12 # set the format of the axis labels
13 set format x "%l%p"
15 # display y-axis labels on the right side with gridlines
16 set y2tics border
17 set noytics
18 set grid y2tics
20 # axis labels and plot title
21 set xlabel "Time"
22 set ylabel "degrees Fahrenheit"
23 set title "Last 12 hours temperature at UW weather station"
25 # draw the plot
26 plot "-" using 1:2 smooth bezier lt 3 lw 2 notitle