{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Airnow Data\n\nThis example shows the different ways to pull\nair quality information from EPA's AirNow API for\na station near to SGP\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n\nimport matplotlib.pyplot as plt\n\nimport act\n\n# You need an account and token from https://docs.airnowapi.org/ first\ntoken = os.getenv('AIRNOW_API')\n\nif token is not None and len(token) > 0:\n # This first example will get the forcasted values for the date passed\n # at stations within 100 miles of the Zipcode. Can also use latlon instead as\n # results = act.discovery.get_airnow_forecast(token, '2022-05-01', distance=100,\n # latlon=[41.958, -88.12])\n # If the username and token are not set, use the existing sample file\n results = act.discovery.get_airnow_forecast(token, '2022-05-01', zipcode=74630, distance=100)\n\n # The results show a dataset with air quality information from Oklahoma City\n # The data is not indexed by time and just a rudimentary xarray object from\n # converted from a pandas DataFrame. Note that the AirNow API labels the data\n # returned as AQI.\n print(results)\n\n # This call gives the daily average for Ozone, PM2.5 and PM10\n results = act.discovery.get_airnow_obs(token, date='2022-05-01', zipcode=74630, distance=100)\n print(results)\n\n # This call will get all the station data for a time period within\n # the bounding box provided. This will return the object with time\n # as a coordinate and can be used with ACT Plotting to plot after\n # squeezing the dimensions. It can be a 2D time series\n lat_lon = '-98.172,35.879,-96.76,37.069'\n results = act.discovery.get_airnow_bounded_obs(\n token, '2022-05-01T00', '2022-05-01T12', lat_lon, 'OZONE,PM25', data_type='B'\n )\n # Reduce to 1D timeseries\n results = results.squeeze(dim='sites', drop=False)\n print(results)\n\n # Plot out data but note that Ozone was not return in the results\n display = act.plotting.TimeSeriesDisplay(results)\n display.plot('PM2.5', label='PM2.5')\n display.plot('AQI', label='AQI')\n plt.legend()\n plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.3" } }, "nbformat": 4, "nbformat_minor": 0 }