{ "cells": [ { "cell_type": "markdown", "id": "0437cc3b-56bf-4d13-bd46-8078db9fe565", "metadata": {}, "source": [ "# AirNow and CAM-chem SE (unstructured grid)\n", "\n", "Here we show a quick example of how to compare unstructured grid model output to surface observations. Note that the sample file provided here shouldn't be used for scientific analysis. For scientific applications, the community MUSICAv0 CONUS simulates are available at https://doi.org/10.5065/tgbj-yv18. \n", "\n", "First we need to import the driver." ] }, { "cell_type": "code", "execution_count": null, "id": "9eb4abaa-bc07-4718-865b-6e044df7f283", "metadata": {}, "outputs": [], "source": [ "from melodies_monet import driver" ] }, { "cell_type": "markdown", "id": "425728d5-f2cc-49ac-89a1-fb031d56eb1f", "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": 3, "id": "33c9cdf5-d071-45b8-99f2-246415dfb0b5", "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": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an = driver.analysis()\n", "an" ] }, { "cell_type": "markdown", "id": "9119cc72-fa4f-416a-83a7-a0b6a8e9de2c", "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": 4, "id": "3b0679bf-623a-439a-a067-0070008355ed", "metadata": { "tags": [ "hide-output" ] }, "outputs": [ { "data": { "text/plain": [ "{'analysis': {'start_time': '2019-09-05-00:00:00',\n", " 'end_time': '2019-09-06-00:00:00',\n", " 'output_dir': './output/airnow_camchemse',\n", " 'download_maps': False,\n", " 'debug': True},\n", " 'model': {'cam-chem-se': {'files': 'example:camchem:se',\n", " 'mod_type': 'cesm_se',\n", " 'scrip_file': 'example:camchem:se_scrip',\n", " 'radius_of_influence': 18000,\n", " 'mapping': {'airnow': {'O3_SRF': '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-se'],\n", " 'data_proc': {'rem_obs_nan': True,\n", " 'ts_select_time': 'time_local',\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-se'],\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-se'],\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-se'],\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-se'],\n", " 'data_proc': {'rem_obs_nan': True, 'set_axis': False}}},\n", " 'stats': {'stat_list': ['R2', 'MB', 'RMSE'],\n", " 'output_table': False,\n", " 'domain_type': ['all', 'epa_region'],\n", " 'domain_name': ['CONUS', 'R1'],\n", " 'data': ['airnow_cesm_se']}}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an.control = 'control_camchem_se.yaml'\n", "an.read_control()\n", "an.control_dict" ] }, { "cell_type": "markdown", "id": "a0e0ff3a-b915-42d0-9e81-aee532083481", "metadata": { "tags": [] }, "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": 5, "id": "5747d74c-a3cf-4283-a678-1b6d43b05ace", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cam-chem-se\n", "{'files': 'example:camchem:se', 'mod_type': 'cesm_se', 'scrip_file': 'example:camchem:se_scrip', 'radius_of_influence': 18000, 'mapping': {'airnow': {'O3_SRF': 'OZONE'}}, 'projection': 'None', 'plot_kwargs': {'color': 'dodgerblue', 'marker': '+', 'linestyle': '-.'}}\n", "example:camchem:se\n", "**** Reading CESM SE model output...\n" ] } ], "source": [ "an.open_models()" ] }, { "cell_type": "code", "execution_count": 6, "id": "c1ad0af0-52b6-4a1c-a19b-a1c3a4782186", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'cam-chem-se': model(\n", " model='cesm_se',\n", " radius_of_influence=18000,\n", " mod_kwargs={'var_list': ['O3_SRF', 'lat', 'lon'], 'scrip_file': '/glade/u/home/cdswk/.cache/pooch/8834f0b10a87870342f40e37c461b326-ne0CONUS_ne30x8_np4_SCRIP.nc'},\n", " file_str='example:camchem:se',\n", " label='cam-chem-se',\n", " obj=...,\n", " mapping={'airnow': {'O3_SRF': 'OZONE'}},\n", " label='cam-chem-se',\n", " ...\n", " )}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an.models" ] }, { "cell_type": "code", "execution_count": 7, "id": "dc91455c-5237-4af4-9d57-280f0158d4b5", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (time: 24, z: 1, ncol: 174098)\n",
"Coordinates:\n",
" * z (z) float64 992.6\n",
" * time (time) datetime64[ns] 2019-09-05 ... 2019-09-05T23:00:00\n",
"Dimensions without coordinates: ncol\n",
"Data variables:\n",
" O3_SRF (time, z, ncol) float32 dask.array<chunksize=(24, 1, 174098), meta=np.ndarray>\n",
" lat (ncol) float64 dask.array<chunksize=(174098,), meta=np.ndarray>\n",
" lon (ncol) float64 dask.array<chunksize=(174098,), meta=np.ndarray>\n",
"Attributes: (12/13)\n",
" ne: 0\n",
" np: 4\n",
" Conventions: CF-1.0\n",
" comment: Sample file created for MUSICA tutorial by Du...\n",
" source: CAM\n",
" case: f.e22.FCcotagsNudged.ne0CONUSne30x8.cesm220.2...\n",
" ... ...\n",
" initial_file: /glade/p/acom/MUSICA/restart/ne0CONUSne30x8/f...\n",
" topography_file: /glade/p/cesmdata/cseg/inputdata/atm/cam/topo...\n",
" model_doi_url: https://doi.org/10.5065/D67H1H0V\n",
" time_period_freq: hour_1\n",
" mio_has_unstructured_grid: True\n",
" mio_scrip_file: /glade/u/home/cdswk/.cache/pooch/8834f0b10a87...<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) int64 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'