{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Consolidation of Data Sources\n\nThis example shows how to use ACT to combine multiple\ndatasets to support ARM's AMF3.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\nfrom datetime import datetime\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport act\n\n# Get Surface Meteorology data from the ASOS stations\nstation = '1M4'\ntime_window = [datetime(2024, 10, 19), datetime(2024, 10, 24)]\nds_asos = act.discovery.get_asos_data(time_window, station=station, regions='AL')[station]\nds_asos = ds_asos.where(~np.isnan(ds_asos.tmpf), drop=True)\nds_asos['tmpf'].attrs['units'] = 'degF'\nds_asos.utils.change_units(variables='tmpf', desired_unit='degC', verbose=True)\n\n# Pull EPA data from AirNow\n# You need an account and token from https://docs.airnowapi.org/ first\nairnow_token = os.getenv('AIRNOW_API')\nif airnow_token is not None and len(airnow_token) > 0:\n latlon = '-87.453,34.179,-86.477,34.787'\n ds_airnow = act.discovery.get_airnow_bounded_obs(\n airnow_token, '2024-10-19T00', '2024-10-24T23', latlon, 'OZONE,PM25', data_type='B'\n )\n ds_airnow = act.utils.convert_2d_to_1d(ds_airnow, parse='sites')\n sites = ds_airnow['sites'].values\n airnow = True\n\n# Get NOAA PSL Data from Courtland\nresults = act.discovery.download_noaa_psl_data(\n site='ctd', instrument='Temp/RH', startdate='20241019', enddate='20241024'\n)\nds_noaa = act.io.read_psl_surface_met(results)\n\n# Place your username and token here\nusername = os.getenv('ARM_USERNAME')\ntoken = os.getenv('ARM_PASSWORD')\n\n# Download ARM data for the MET, OZONE, and SMPS\nif username is not None and token is not None and len(username) > 1:\n # Example to show how easy it is to download ARM data if a username/token are set\n results = act.discovery.download_arm_data(\n username, token, 'bnfmetM1.b1', '2024-10-19', '2024-10-24'\n )\n ds_arm = act.io.arm.read_arm_netcdf(results)\n\n results = act.discovery.download_arm_data(\n username, token, 'bnfaoso3M1.b1', '2024-10-19', '2024-10-24'\n )\n ds_o3 = act.io.arm.read_arm_netcdf(results, cleanup_qc=True)\n ds_o3.qcfilter.datafilter('o3', rm_assessments=['Suspect', 'Bad'], del_qc_var=False)\n\n results = act.discovery.download_arm_data(\n username, token, 'bnfaossmpsM1.b1', '2024-10-19', '2024-10-24'\n )\n ds_smps = act.io.arm.read_arm_netcdf(results)\n\n # Set up display and plot all the data\n display = act.plotting.TimeSeriesDisplay(\n {'ASOS': ds_asos, 'ARM': ds_arm, 'EPA': ds_airnow, 'NOAA': ds_noaa, 'ARM_O3': ds_o3},\n figsize=(12, 10),\n subplot_shape=(3,),\n )\n # Plot surface temperature from ASOS, NOAA, and ARM sites\n title = 'Comparison of ARM MET, NOAA Courtland, and Haleyville ASOS Station'\n display.plot('tmpf', dsname='ASOS', label='ASOS', subplot_index=(0,))\n display.plot('Temperature', dsname='NOAA', label='NOAA', subplot_index=(0,))\n display.plot('temp_mean', dsname='ARM', label='ARM', subplot_index=(0,), set_title=title)\n display.day_night_background(dsname='ARM', subplot_index=(0,))\n\n # Plot ARM and EPA Ozone data\n title = 'Comparison of ARM and EPA Ozone Measurements'\n display.plot('o3', dsname='ARM_O3', label='ARM', subplot_index=(1,))\n if airnow:\n display.plot('OZONE_sites_1', dsname='EPA', label='EPA' + sites[1], subplot_index=(1,))\n display.plot(\n 'OZONE_sites_2',\n dsname='EPA',\n label='EPA' + sites[2],\n subplot_index=(1,),\n set_title=title,\n )\n display.set_yrng([0, 70], subplot_index=(1,))\n display.day_night_background(dsname='ARM', subplot_index=(1,))\n\n # Plot ARM SMPS Concentrations and EPA PM2.5 data on different axes\n title = 'ARM SMPS Concentrations and EPA PM2.5'\n if airnow:\n display.plot('PM2.5_sites_0', dsname='EPA', label='EPA ' + sites[0], subplot_index=(2,))\n display.plot(\n 'PM2.5_sites_2',\n dsname='EPA',\n label='EPA ' + sites[2],\n subplot_index=(2,),\n set_title=title,\n )\n display.set_yrng([0, 25], subplot_index=(2,))\n ax2 = display.axes[2].twinx()\n ax2.plot(ds_smps['time'], ds_smps['total_N_conc'], label='ARM SMPS', color='purple')\n ax2.set_ylabel('ARM SMPS (' + ds_smps['total_N_conc'].attrs['units'] + ')')\n ax2.set_ylim([0, 7000])\n ax2.legend(loc=1)\n display.day_night_background(dsname='ARM', subplot_index=(2,))\n\n # Set legends\n for ax in display.axes:\n ax.legend(loc=2)\n\n plt.show()\nelse:\n pass" ] } ], "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 }