.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "source/auto_examples/discovery/plot_airnow.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_source_auto_examples_discovery_plot_airnow.py: Airnow Data ----------- This example shows the different ways to pull air quality information from EPA's AirNow API for a station near to SGP .. GENERATED FROM PYTHON SOURCE LINES 10-54 .. image-sg:: /source/auto_examples/discovery/images/sphx_glr_plot_airnow_001.png :alt: act_datastream AQI on 20220501 :srcset: /source/auto_examples/discovery/images/sphx_glr_plot_airnow_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Size: 776B Dimensions: (index: 8) Coordinates: * index (index) int64 64B 0 1 2 3 4 5 6 7 Data variables: DateIssue (index) object 64B '2022-04-29' ... '2022-04-29' DateForecast (index) object 64B '2022-05-01' ... '2022-05-04' ReportingArea (index) object 64B 'Oklahoma City' ... 'Oklahoma City' StateCode (index) object 64B 'OK' 'OK' 'OK' 'OK' 'OK' 'OK' 'OK' 'OK' Latitude (index) float64 64B 35.47 35.47 35.47 ... 35.47 35.47 35.47 Longitude (index) float64 64B -97.51 -97.51 -97.51 ... -97.51 -97.51 ParameterName (index) object 64B 'O3' 'PM2.5' 'O3' ... 'O3' 'PM2.5' AQI (index) int64 64B 50 40 30 20 50 30 30 20 CategoryNumber (index) int64 64B 1 1 1 1 1 1 1 1 CategoryName (index) object 64B 'Good' 'Good' 'Good' ... 'Good' 'Good' ActionDay (index) bool 8B False False False ... False False False Discussion (index) object 64B 'Southerly winds today will bring mois... Size: 288B Dimensions: (index: 3) Coordinates: * index (index) int64 24B 0 1 2 Data variables: DateObserved (index) object 24B '2022-05-01' '2022-05-01' '2022-05-01' HourObserved (index) int64 24B 0 0 0 LocalTimeZone (index) object 24B 'CST' 'CST' 'CST' ReportingArea (index) object 24B 'Oklahoma City' ... 'Oklahoma City' StateCode (index) object 24B 'OK' 'OK' 'OK' Latitude (index) float64 24B 35.47 35.47 35.47 Longitude (index) float64 24B -97.51 -97.51 -97.51 ParameterName (index) object 24B 'OZONE' 'PM2.5' 'PM10' AQI (index) int64 24B 51 39 21 CategoryNumber (index) int64 24B 2 1 1 CategoryName (index) object 24B 'Moderate' 'Good' 'Good' Size: 584B Dimensions: (time: 13) Coordinates: sites 0: # This first example will get the forcasted values for the date passed # at stations within 100 miles of the Zipcode. Can also use latlon instead as # results = act.discovery.get_airnow_forecast(token, '2022-05-01', distance=100, # latlon=[41.958, -88.12]) # If the username and token are not set, use the existing sample file results = act.discovery.get_airnow_forecast(token, '2022-05-01', zipcode=74630, distance=100) # The results show a dataset with air quality information from Oklahoma City # The data is not indexed by time and just a rudimentary xarray object from # converted from a pandas DataFrame. Note that the AirNow API labels the data # returned as AQI. print(results) # This call gives the daily average for Ozone, PM2.5 and PM10 results = act.discovery.get_airnow_obs(token, date='2022-05-01', zipcode=74630, distance=100) print(results) # This call will get all the station data for a time period within # the bounding box provided. This will return the object with time # as a coordinate and can be used with ACT Plotting to plot after # squeezing the dimensions. It can be a 2D time series lat_lon = '-98.172,35.879,-96.76,37.069' results = act.discovery.get_airnow_bounded_obs( token, '2022-05-01T00', '2022-05-01T12', lat_lon, 'OZONE,PM25', data_type='B' ) # Reduce to 1D timeseries results = results.squeeze(dim='sites', drop=False) print(results) # Plot out data but note that Ozone was not return in the results display = act.plotting.TimeSeriesDisplay(results) display.plot('PM2.5', label='PM2.5') display.plot('AQI', label='AQI') plt.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 24.437 seconds) .. _sphx_glr_download_source_auto_examples_discovery_plot_airnow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_airnow.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_airnow.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_airnow.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_