Beijing PM2.5 Pollution Historical Data

A couple weeks ago Beijing air pollution was off the charts, literally - the scale is 0-500, but all readings for Beijing were in the mid-700s. I have been vaguely following the PM2.5 readings since they have been in the news the last 3-4 years, but there is no historical data I can find to compare it to.

On the other hand, there are lots of places where it can be gotten online, but you have to remember to go there and get it, and trends are still not visible. It would be nice to have historical information available, but I could not find any for Beijing (Here is Hong Kong's). Overall daily records for Beijing are on the govenment site, but these are daily, not hourly, and not specific for PM2.5.

I was also surprised to learn there is a difference in the computation of the levels between the way it is calculated in the US and in China. While China standards are looser, they are not arbitrary. Chinese levels are based on WHO stage 1 levels. For a developing country just beginning to face its air pollution problem this is not an unreasonable choice. The difference is only in the lower levels: "Unhealthy", "Very Unhealthy", "Hazardous", and of course "Crazy Bad", are the same for both scales. The difference in mapping from concentration levels to AQI can be seen in this chart:


Since twitter uses a US Embassy feed, the AQI computation they use is the US version, and this is what is given by default in these graphs. By selecting "Scale: China" you can redisplay the page using the Chinese AQI values rather than the US ones. This is very good reference on what the AQI numbers mean and where they come from in China (vpn required, I think)

For my page, a cron job at gets the hourly feed from twitter and writes it into a database, where it is available for me or anyone else to review.

It also makes the current data available as text or as image,** so scripts or web pages can display the current values (it is displayed on my home page, and also on my desktop). And, it sends me an email when the numbers climb to "crazy bad". (sorry, I do not offer that service publicly).

The source code is available for anyone who is interested. Feel free to use it or adapt it, but please leave the attribution in the front of the file. In addition, it might be nice to drop me a note to let me know that someone besides me ever looks at this :-) You can view the code online and set up your own databases if you want:aqidata.php accesses a public site to get data for the previous few hours and stores it in a database. aqigraph.php (AKA index.php) displays the graph. There is even a status bar application for Ubuntu 12.04 that shows the current value in the status bar, and pops up a window showing recent values.

Future enhancements could include improving the interface - what, this is not great? Also, unfortunately I have no old source of data, so data only goes back to the time I wrote the script, January 24, 2013. If anyone knows of a source of older data I would love to have the chance to add it.

If I find a good online source I might try adding different locations within Beijing (other cities do not really interest me) which could be compared. Again, anyone who knows of a good source, please let me know.

Or, any other comments, requests, or suggestions are welcome too. I can be contacted through the form on my main website,


**To avoid caching the image you may need to do something like the following to get the current version to display:

 <img onerror="this.src = '/airquality/mostRecent.jpg?' + new Date().getTime();" src="asd.jpg">

Back to site