Paul's Python CoursePPC

Project 5 of 12, for Yahya

Weather History Dashboard

A weather history dashboard for the Archive wall: a century of real Met Office readings resampled into years and drawn as four honest charts on one page.

About an hour and a half, in 16 steps.

Sign up free to open itLog in

Act 5 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • YahyaWe've got a hundred years of weather and the Archive wall has one chart on it, from 1974.
  • YahyaOur own station book has gaps and Fahrenheit in it, and for the wall I want a record anyone can check.
  • YahyaThe Met Office's station at Stornoway goes back to 1873, far north and wet, and I want four charts on one page.
  • PaulAnd honest ones, I expect.
  • YahyaObviously the bars start at zero and every axis says what it measures. Anyone who wants drama can read a novel.

stornoway.csv is real: the Met Office's monthly readings at Stornoway from 1925 to 2024, one row a month: month, tmax and tmin (the mean daily high and low, degrees C), frost (days), rain (mm), sun (hours) and estimated. A few months are missing a reading. load_station is written: it reads the file with the month as a date index and adds temp, the mean of tmax and tmin.

Write six functions in dashboard.py:

  • yearly(station): a DataFrame with one row a year, labelled by the year as a number, and three columns: temp, the mean of the year's twelve months; rain and sun, the year's totals. A year with a month missing for a reading gets NaN for that reading.
  • warming_chart(ax, temps): draws on ax. Take the century's average off every year, then draw three lines with a key: the differences (each year), their ten-year rolling average (ten-year average), and a line right across at 0 (century average). Labels: year and difference from average (degrees C).
  • rain_bars(ax, totals): one bar a year, on a scale that starts at zero. Labels: year and rain (mm).
  • rain_histogram(ax, rain): how many months had each amount of rain, in bins 20 mm wide from 0 to 300. Labels: rain in the month (mm) and months.
  • july_scatter(ax, station): one dot for each July with a sunshine record, its sunshine across and its temperature up. Labels: sunshine (hours) and temperature (degrees C).
  • dashboard(station): a figure of four axes, two by two, with each chart on one of them, a title on every chart, and a title for the whole page that names the station and the source. It returns the figure.

The headlines at the bottom are written; they save the dashboard as dashboard.png.

What it prints
Stornoway, 1925 to 2024: 1200 months
Warmest year: 2014 (9.52 degrees C). Coldest: 1979 (7.19 degrees C)
Wettest year: 1999 (1547 mm). Driest: 1968 (800 mm)
Last thirty years against the first thirty: +0.56 degrees C
Left out for a missing month: temperature 1927; sunshine 1925, 1926, 1927, 1928, 2004, 2007
Saved dashboard.png

What you learn

What's in it

  1. A line on a chart
  2. Two years on one chart
  3. Bars, counts and dots
  4. Six months, two charts
  5. Several charts on one page
  6. Two panels, two scales
  7. Months into years
  8. Two at a time
  9. A century on one line
  10. Charts that don't fib
  11. Where the scale starts
  12. How Paul would do it
  13. Fix Caitlin's version
  14. Make the dashboard
  15. Ship it