{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Consolidation of CoURAGE Data Sources\n\nThis example shows how to use ACT to combine multiple\ndatasets to support ARM's CoURAGE deployment in\nBaltimore, MD. Example uses ARM, EPA, and ASOS data.\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\nlat = (39.04, 39.6)\nlon = (-77.10, -76.04)\ntime_window = [datetime(2024, 12, 15), datetime(2024, 12, 20)]\nasos_dict = act.discovery.get_asos_data(time_window, lat_range=lat, lon_range=lon, regions='MD')\nasos_stations = asos_dict.keys()\n\n# Set up a dictionary to fill with data\ndata_dict = {}\n\n# Fill the dictionary with ASOS data\nfor s in asos_stations:\n ds = asos_dict[s]\n ds = ds.where(~np.isnan(ds.tmpf), drop=True)\n ds['tmpf'].attrs['units'] = 'degF'\n ds.utils.change_units(variables='tmpf', desired_unit='degC', verbose=True)\n data_dict[s] = ds\n\n# You need an account and token from https://docs.airnowapi.org/ first\n# And then you can download EPA data\nairnow_token = os.getenv('AIRNOW_API')\nif airnow_token is not None and len(airnow_token) > 0:\n latlon = '-76.905,39.185,-76.158,39.499'\n\n ds_airnow = act.discovery.get_airnow_bounded_obs(\n airnow_token, '2024-12-15T00', '2024-12-20T23', 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 data_dict['EPA'] = ds_airnow\n airnow = True\n\n# Place your username and token here\nusername = os.getenv('ARM_USERNAME')\ntoken = os.getenv('ARM_PASSWORD')\n\n# Download ARM data\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 sdate = '2024-12-15'\n edate = '2024-12-20'\n\n # Download and read ARM MET data\n results = act.discovery.download_arm_data(username, token, 'crgmetM1.b1', sdate, edate)\n ds_arm = act.io.arm.read_arm_netcdf(results)\n data_dict['ARM'] = ds_arm\n\n # Download and read ARM Ozone data\n results = act.discovery.download_arm_data(username, token, 'crgaoso3S2.a1', sdate, edate)\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 data_dict['ARM_O3'] = ds_o3\n\n # Download and read ARM SMPS data\n results = act.discovery.download_arm_data(username, token, 'crgaossmpsS2.b1', sdate, edate)\n ds_smps = act.io.arm.read_arm_netcdf(results)\n data_dict['ARM_SMPS'] = ds_smps\n\n # Set up plot and plot all surface temperature data\n display = act.plotting.TimeSeriesDisplay(data_dict, figsize=(12, 10), subplot_shape=(3,))\n for k in data_dict.keys():\n if 'ARM' not in k and k != 'EPA':\n display.plot('tmpf', dsname=k, label=k, subplot_index=(0,))\n elif k == 'ARM':\n display.plot('temp_mean', dsname=k, label=k, subplot_index=(0,))\n display.day_night_background(dsname='ARM', subplot_index=(0,))\n\n display.set_yrng([-5, 20], subplot_index=(0,))\n\n # Plot up 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(\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, 60], subplot_index=(1,))\n display.day_night_background(dsname='ARM', subplot_index=(1,))\n\n # Plot SMPS data\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('PM2.5_sites_1', dsname='EPA', label='EPA ' + sites[1], subplot_index=(2,))\n display.plot(\n 'PM2.5_sites_3',\n dsname='EPA',\n label='EPA ' + sites[3],\n subplot_index=(2,),\n set_title=title,\n )\n\n display.set_yrng([0, 30], subplot_index=(2,))\n plt.legend(loc=2)\n ax2 = display.axes[2].twinx()\n ax2.plot(ds_smps['time'], ds_smps['total_N_conc'], color='purple')\n ax2.set_ylabel('ARM SMPS (' + ds_smps['total_N_conc'].attrs['units'] + ')')\n display.day_night_background(dsname='ARM', subplot_index=(2,))\n\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 }