Example usage
Here we will demonstrate how to use airpyllution to create a map with markers indicating current air pollution levels, tabulate historical air pollution data, and plot forecasted air pollution data.
The air pollution data is obtained from https://openweathermap.org/ and includes the pollution concentrations for carbon monoxide (CO), nitrogen monoxide (NO), nitrogen dioxide (NO2), ozone (O3), sulphur dioxide (SO2), ammonia (NH3), 2.5 micrometer particulate matter (PM2.5), and 10 micrometer particulate matter (PM10).
Imports
from airpyllution.airpyllution import get_air_pollution
from airpyllution.airpyllution import get_pollution_history
from airpyllution.airpyllution import get_pollution_forecast
Plot current air pollution
We’ll plot the current air pollution levels in Vancouver, BC by inputting the city’s latitude and longitude values into the function, as well as your OpenWeatherMap API key, and an optional title. Double-click on a pollutant in the legend to isolate it on the map. Hover over the pollutant’s marker to view its concentration.
Note: Due to software limitations, the interactive version of the map is not available on readthedocs.
lat, lon = 49.2497, -123.1193
pollution_map = get_air_pollution(lat, lon, api_key, "Current Air Pollution")
pollution_map.show()

Obtain historical air pollution data
Hourly historical pollution data can be tabulated from November 27th 2020. The start and end date must be entered in unix time, UTC time zone format; followed by the latitude and longitude of the location of interest, and finally your API key.
get_pollution_history(1606488670, 1606747870, lat, lon, api_key)
| co | no | no2 | o3 | so2 | pm2_5 | pm10 | nh3 | dt | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 260.35 | 0.02 | 15.94 | 40.05 | 5.36 | 2.49 | 4.55 | 0.59 | 2020-11-27 15:00:00 |
| 1 | 287.06 | 0.03 | 19.71 | 39.70 | 6.32 | 2.54 | 4.71 | 0.85 | 2020-11-27 16:00:00 |
| 2 | 290.39 | 0.03 | 20.05 | 43.27 | 6.74 | 2.48 | 4.61 | 0.90 | 2020-11-27 17:00:00 |
| 3 | 277.04 | 0.09 | 18.85 | 46.49 | 6.80 | 2.49 | 4.69 | 0.86 | 2020-11-27 18:00:00 |
| 4 | 263.69 | 0.12 | 16.62 | 49.35 | 5.90 | 2.42 | 4.56 | 0.71 | 2020-11-27 19:00:00 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 67 | 260.35 | 0.00 | 12.68 | 60.08 | 3.87 | 1.64 | 2.36 | 0.51 | 2020-11-30 10:00:00 |
| 68 | 247.00 | 0.00 | 9.94 | 63.66 | 3.52 | 1.81 | 2.27 | 0.41 | 2020-11-30 11:00:00 |
| 69 | 240.33 | 0.00 | 8.65 | 63.66 | 2.95 | 2.14 | 2.45 | 0.32 | 2020-11-30 12:00:00 |
| 70 | 236.99 | 0.00 | 7.37 | 67.23 | 2.38 | 2.06 | 2.32 | 0.25 | 2020-11-30 13:00:00 |
| 71 | 230.31 | 0.00 | 6.26 | 72.96 | 2.09 | 1.70 | 2.03 | 0.23 | 2020-11-30 14:00:00 |
72 rows × 9 columns
Plot forecasted air pollution data
Hourly pollutant concentrations can be forecasted 5 days into the future. All that is required is the latitude and longitude of the desired location and your API key.
import altair as alt
alt.renderers.enable("html");
pollution_forecast = get_pollution_forecast(lat, lon, api_key)
pollution_forecast