{ "cells": [ { "cell_type": "markdown", "id": "db9d24de", "metadata": {}, "source": [ "# AirNow and CAM-chem\n", "\n", "First we need to import the driver." ] }, { "cell_type": "code", "execution_count": 2, "id": "a467f463", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Please install h5py to open files from the Amazon S3 servers.\n", "Please install h5netcdf to open files from the Amazon S3 servers.\n" ] } ], "source": [ "from melodies_monet import driver" ] }, { "cell_type": "code", "execution_count": 3, "id": "a73507fa-e8a5-4006-bb96-91d4b6d3a77d", "metadata": {}, "outputs": [], "source": [ "# Needed if you want to make changes to `melodies_monet` and don't want to restart kernel:\n", "%load_ext autoreload\n", "\n", "%autoreload 2" ] }, { "cell_type": "markdown", "id": "e5ff022d", "metadata": {}, "source": [ "## Initiate the analysis class\n", "\n", "Now lets create an instance of the {mod}`melodies_monet.driver` {class}`~melodies_monet.driver.analysis` class.\n", "It consists of 4 main parts: model instances, observation instances, a paired instance of both.\n", "This will allow us to move things around the plotting function for spatial and overlays and more complex plots." ] }, { "cell_type": "code", "execution_count": 4, "id": "4d778036", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "analysis(\n", " control='control.yaml',\n", " control_dict=None,\n", " models={},\n", " obs={},\n", " paired={},\n", " start_time=None,\n", " end_time=None,\n", " download_maps=True,\n", " output_dir=None,\n", " debug=False,\n", ")" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an = driver.analysis()\n", "an" ] }, { "cell_type": "markdown", "id": "d1b59360", "metadata": {}, "source": [ "## Control File\n", "\n", "Read in the required yaml control file that sets up all the definitions of what we want to pair and plot." ] }, { "cell_type": "code", "execution_count": 5, "id": "17488a58", "metadata": { "tags": [ "hide-output" ] }, "outputs": [ { "data": { "text/plain": [ "{'analysis': {'start_time': '2019-09-01-00:00:00',\n", " 'end_time': '2019-09-09-00:00:00',\n", " 'output_dir': './output/camchem',\n", " 'download_maps': False,\n", " 'debug': False},\n", " 'model': {'cam-chem': {'files': 'example:camchem:fv',\n", " 'mod_type': 'cesm_fv',\n", " 'radius_of_influence': 150000.0,\n", " 'mapping': {'airnow': {'O3': 'OZONE'}},\n", " 'projection': 'None',\n", " 'plot_kwargs': {'color': 'dodgerblue', 'marker': '+', 'linestyle': '-.'}}},\n", " 'obs': {'airnow': {'use_airnow': True,\n", " 'filename': 'example:airnow:2019-09',\n", " 'obs_type': 'pt_sfc',\n", " 'variables': {'PM2.5': {'unit_scale': 1,\n", " 'unit_scale_method': '*',\n", " 'nan_value': -1.0,\n", " 'ylabel_plot': 'PM2.5 (ug/m3)',\n", " 'ty_scale': 2.0,\n", " 'vmin_plot': 0.0,\n", " 'vmax_plot': 22.0,\n", " 'vdiff_plot': 15.0,\n", " 'nlevels_plot': 23},\n", " 'OZONE': {'unit_scale': 1,\n", " 'unit_scale_method': '*',\n", " 'nan_value': -1.0,\n", " 'ylabel_plot': 'Ozone (ppbv)',\n", " 'vmin_plot': 15.0,\n", " 'vmax_plot': 55.0,\n", " 'vdiff_plot': 20.0,\n", " 'nlevels_plot': 21}}}},\n", " 'plots': {'plot_grp1': {'type': 'timeseries',\n", " 'fig_kwargs': {'figsize': [12, 6]},\n", " 'default_plot_kwargs': {'linewidth': 2.0, 'markersize': 10.0},\n", " 'text_kwargs': {'fontsize': 18.0},\n", " 'domain_type': ['all', 'epa_region'],\n", " 'domain_name': ['CONUS', 'R1'],\n", " 'data': ['airnow_cam-chem'],\n", " 'data_proc': {'rem_obs_nan': True,\n", " 'ts_select_time': 'time',\n", " 'ts_avg_window': 'H',\n", " 'set_axis': False}},\n", " 'plot_grp2': {'type': 'taylor',\n", " 'fig_kwargs': {'figsize': [8, 8]},\n", " 'default_plot_kwargs': {'linewidth': 2.0, 'markersize': 10.0},\n", " 'text_kwargs': {'fontsize': 16.0},\n", " 'domain_type': ['all', 'epa_region'],\n", " 'domain_name': ['CONUS', 'R1'],\n", " 'data': ['airnow_cam-chem'],\n", " 'data_proc': {'rem_obs_nan': True, 'set_axis': True}},\n", " 'plot_grp3': {'type': 'spatial_bias',\n", " 'fig_kwargs': {'states': True, 'figsize': [10, 5]},\n", " 'text_kwargs': {'fontsize': 16.0},\n", " 'domain_type': ['all', 'epa_region'],\n", " 'domain_name': ['CONUS', 'R1'],\n", " 'data': ['airnow_cam-chem'],\n", " 'data_proc': {'rem_obs_nan': True, 'set_axis': True}},\n", " 'plot_grp4': {'type': 'spatial_overlay',\n", " 'fig_kwargs': {'states': True, 'figsize': [10, 5]},\n", " 'text_kwargs': {'fontsize': 16.0},\n", " 'domain_type': ['all', 'epa_region'],\n", " 'domain_name': ['CONUS', 'R1'],\n", " 'data': ['airnow_cam-chem'],\n", " 'data_proc': {'rem_obs_nan': True, 'set_axis': True}},\n", " 'plot_grp5': {'type': 'boxplot',\n", " 'fig_kwargs': {'figsize': [8, 6]},\n", " 'text_kwargs': {'fontsize': 20.0},\n", " 'domain_type': ['all', 'epa_region'],\n", " 'domain_name': ['CONUS', 'R1'],\n", " 'data': ['airnow_cam-chem'],\n", " 'data_proc': {'rem_obs_nan': True, 'set_axis': False}}}}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an.control = 'control_camchem.yaml'\n", "an.read_control()\n", "an.control_dict" ] }, { "cell_type": "markdown", "id": "e75705ee", "metadata": {}, "source": [ "## Load the model data \n", "\n", "The driver will automatically loop through the \"models\" found in the model section of the control file and create model classes for each. Classes include the label, mapping information, and xarray object as well as the filenames. Note it can open multiple files easily by including wildcards. Here we are only opening one CAM-chem file." ] }, { "cell_type": "code", "execution_count": 6, "id": "3703cb9e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Downloading data from 'https://csl.noaa.gov/groups/csl4/modeldata/melodies-monet/data/example_model_data/cesmfv_example/CAM_chem_merra2_FCSD_1deg_QFED_world_201909-01-09_small_sfc.nc' to file 'C:\\Users\\zmoon\\AppData\\Local\\pooch\\pooch\\Cache\\f57b114fb465b23ee998209b50df7d9d-CAM_chem_merra2_FCSD_1deg_QFED_world_201909-01-09_small_sfc.nc'.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "cam-chem\n", "{'files': 'example:camchem:fv', 'mod_type': 'cesm_fv', 'radius_of_influence': 150000.0, 'mapping': {'airnow': {'O3': 'OZONE'}}, 'projection': 'None', 'plot_kwargs': {'color': 'dodgerblue', 'marker': '+', 'linestyle': '-.'}}\n", "example:camchem:fv\n", "**** Reading CESM model output...\n" ] } ], "source": [ "an.open_models()" ] }, { "cell_type": "code", "execution_count": 7, "id": "8a1ab3b8", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'cam-chem': model(\n", " model='cesm_fv',\n", " radius_of_influence=150000.0,\n", " mod_kwargs={},\n", " file_str='example:camchem:fv',\n", " label='cam-chem',\n", " obj=...,\n", " mapping={'airnow': {'O3': 'OZONE'}},\n", " label='cam-chem',\n", " ...\n", " )}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an.models" ] }, { "cell_type": "code", "execution_count": 8, "id": "21127894", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (time: 36, z: 1, lat: 192, lon: 288)\n",
"Coordinates:\n",
" * lat (lat) float64 -90.0 -89.06 -88.12 -87.17 ... 87.17 88.12 89.06 90.0\n",
" * z (z) float64 992.5\n",
" * lon (lon) float64 0.0 1.25 2.5 3.75 5.0 ... 355.0 356.2 357.5 358.8\n",
" * time (time) datetime64[ns] 2019-09-01T06:00:00 ... 2019-09-10\n",
"Data variables:\n",
" O3 (time, z, lat, lon) float32 dask.array<chunksize=(36, 1, 192, 288), meta=np.ndarray>\n",
" PM25 (time, z, lat, lon) float32 dask.array<chunksize=(36, 1, 192, 288), meta=np.ndarray>\n",
"Attributes:\n",
" Conventions: CF-1.0\n",
" source: CAM\n",
" case: fmerra.2.1003.FCSD.f09.qfedcmip.56L.001.branch02\n",
" logname: buchholz\n",
" host: cheyenne3\n",
" initial_file: /glade/p/cesmdata/cseg/inputdata/atm/cam/inic/fv/f.e20...\n",
" topography_file: /glade/p/cesmdata/cseg/inputdata/atm/cam/met/MERRA2/0....\n",
" model_doi_url: https://doi.org/10.5065/D67H1H0V\n",
" time_period_freq: hour_6\n",
" history: Mon Feb 28 16:25:23 2022: ncks -7 -L 1 --baa=4 --ppc d...\n",
" NCO: netCDF Operators version 5.0.6 (Homepage = http://nco....<xarray.Dataset>\n",
"Dimensions: (x: 3786, time: 2091, y: 1)\n",
"Coordinates:\n",
" * x (x) int64 0 1 2 3 4 5 6 7 ... 3779 3780 3781 3782 3783 3784 3785\n",
" * time (time) datetime64[ns] 2019-09-01 ... 2019-09-30T00:30:00\n",
" latitude (y, x) float64 47.65 47.51 49.02 53.3 ... 36.92 47.93 41.37\n",
" longitude (y, x) float64 -52.82 -52.79 -55.8 -60.36 ... -94.84 106.9 69.27\n",
" siteid (y, x) object '000010102' '000010401' ... 'UZB010001'\n",
"Dimensions without coordinates: y\n",
"Data variables: (12/30)\n",
" BARPR (time, y, x) float64 ...\n",
" BC (time, y, x) float64 ...\n",
" CO (time, y, x) float64 ...\n",
" NO (time, y, x) float64 ...\n",
" NO2 (time, y, x) float64 ...\n",
" NO2Y (time, y, x) float64 ...\n",
" ... ...\n",
" cmsa_name (y, x) float64 -1.0 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" msa_code (y, x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 3.306e+04 -1.0 -1.0\n",
" msa_name (y, x) object '' '' '' '' '' '' ... '' '' '' ' Miami, OK ' '' ''\n",
" state_name (y, x) object 'CC' 'CC' 'CC' 'CC' 'CC' 'CC' ... '' '' '' '' ''\n",
" epa_region (y, x) object 'CA' 'CA' 'CA' 'CA' 'CA' ... '' 'R6' 'DSMG' 'DSUZ'\n",
" time_local (time, y, x) datetime64[ns] ...\n",
"Attributes:\n",
" title: \n",
" format: NetCDF-4\n",
" date_created: 2021-06-07<xarray.Dataset>\n",
"Dimensions: (time: 2091, x: 3786)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2019-09-01 ... 2019-09-30T00:30:00\n",
" * x (x) int32 0 1 2 3 4 5 6 7 ... 3779 3780 3781 3782 3783 3784 3785\n",
"Data variables: (12/34)\n",
" BARPR (time, x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" BC (time, x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" CO (time, x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" NO (time, x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" NO2 (time, x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" NO2Y (time, x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" ... ...\n",
" cmsa_name (x) float64 -1.0 -1.0 -1.0 -1.0 -1.0 ... -1.0 -1.0 -1.0 -1.0\n",
" msa_code (x) float64 -1.0 -1.0 -1.0 -1.0 ... -1.0 3.306e+04 -1.0 -1.0\n",
" msa_name (x) object '' '' '' '' '' '' '' ... '' '' '' ' Miami, OK ' '' ''\n",
" state_name (x) object 'CC' 'CC' 'CC' 'CC' 'CC' 'CC' ... '' '' '' '' '' ''\n",
" epa_region (x) object 'CA' 'CA' 'CA' 'CA' 'CA' ... '' 'R6' 'DSMG' 'DSUZ'\n",
" siteid (x) object '000010102' '000010401' ... 'UB1010001' 'UZB010001'