{ "cells": [ { "cell_type": "markdown", "id": "33070195-2d5f-4ee3-b6cb-a658209b1f4d", "metadata": {}, "source": [ "# Basic Plotting\n" ] }, { "cell_type": "markdown", "id": "8f2a265a-5258-47df-9da2-86afb69cf660", "metadata": {}, "source": [ "**BEFORE BEGINNING THIS EXERCISE** - Check that your kernel (upper right corner, above) is `NPL 2023b`. This should be the default kernel, but if it is not, click on that button and select `NPL 2023b`." ] }, { "cell_type": "markdown", "id": "4ef5d835-37b7-4a4a-84c1-8053093f1500", "metadata": {}, "source": [ "_______________\n", "This activity was developed primarily by Cecile Hannay and Jesse Nusbaumer." ] }, { "cell_type": "markdown", "id": "b35face4-1542-4ab0-8f04-8220a00b0086", "metadata": {}, "source": [ "_______________\n", "\n", "For the atmospheric data, we will look at common variables in the atmospheric diagnostics. This notebook covers 3 basic plotting examples:\n", "\n", "Exercise 1: Global lat/lon of surface temperature\n", "\n", "Exercise 2: Zonal mean of short wave cloud forcing\n", "\n", "Exercise 3: Temperature zonal mean with vertical levels\n", "\n", "Some of the plotting in these examples are based on the AMWG Diagnostics Framework (ADF) and some are natively from the `xarray` functionality. `xarray` will be used for the data I/O, analysis, and some plotting, `matplotlib` and `cartopy` will aid in plotting, and `numpy` for calculations" ] }, { "cell_type": "code", "execution_count": 1, "id": "72e6f251-c6ff-4478-adab-783ac1795e34", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import cartopy.crs as ccrs\n", "import cartopy.feature as cfeature\n", "import cftime\n", "import matplotlib as mpl\n", "import matplotlib.path as mpath\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import xarray as xr\n", "from matplotlib.gridspec import GridSpec\n", "from matplotlib.lines import Line2D\n", "from mpl_toolkits.axes_grid1 import make_axes_locatable" ] }, { "cell_type": "markdown", "id": "3d56ba02-c652-4a97-a466-d3633e53aeb1", "metadata": {}, "source": [ "The first step is to grab an atmosphere (CAM) history file from your CESM model run" ] }, { "cell_type": "code", "execution_count": 2, "id": "20d4eec8-5332-44a5-bd5c-910048c5d95f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'/glade/derecho/scratch/PUT_USER_NAME_HERE/archive/b1850.run_length/atm/hist/b1850.run_length.cam.h0.0003-07.nc'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Set your username here:\n", "username = \"PUT_USER_NAME_HERE\"\n", "\n", "# Here we point to the archive directory from your b1850.run_length simulation\n", "monthly_output_path = f\"/glade/derecho/scratch/{username}/archive/b1850.run_length/atm/hist\"\n", "\n", "# If you were unable to successfully run the b1850.run_length simulation, then feel free to use\n", "# this provided simulation data instead:\n", "#monthly_output_path = \"/glade/campaign/cesm/tutorial/tutorial_2023_archive/b1850.run_length/atm/hist\"\n", "\n", "# Name of history file to plot\n", "file_name = \"b1850.run_length.cam.h0.0003-07.nc\"\n", "\n", "files = os.path.join(monthly_output_path, file_name)\n", "files" ] }, { "cell_type": "code", "execution_count": 3, "id": "fa978aa8-bf89-4971-a59b-ae2fafb9e0a5", "metadata": {}, "outputs": [ { "ename": "FileNotFoundError", "evalue": "[Errno 2] No such file or directory: '/glade/derecho/scratch/PUT_USER_NAME_HERE/archive/b1850.run_length/atm/hist/b1850.run_length.cam.h0.0003-07.nc'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/file_manager.py:211\u001b[0m, in \u001b[0;36mCachingFileManager._acquire_with_cache_info\u001b[0;34m(self, needs_lock)\u001b[0m\n\u001b[1;32m 210\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 211\u001b[0m file \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_cache\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_key\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 212\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m:\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/lru_cache.py:56\u001b[0m, in \u001b[0;36mLRUCache.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_lock:\n\u001b[0;32m---> 56\u001b[0m value \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_cache\u001b[49m\u001b[43m[\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_cache\u001b[38;5;241m.\u001b[39mmove_to_end(key)\n", "\u001b[0;31mKeyError\u001b[0m: [, ('/glade/derecho/scratch/PUT_USER_NAME_HERE/archive/b1850.run_length/atm/hist/b1850.run_length.cam.h0.0003-07.nc',), 'r', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), 'da467520-dd8b-4048-a691-3445d0f0f93e']", "\nDuring handling of the above exception, another exception occurred:\n", "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m ds \u001b[38;5;241m=\u001b[39m \u001b[43mxr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_dataset\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m ds\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/api.py:566\u001b[0m, in \u001b[0;36mopen_dataset\u001b[0;34m(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, inline_array, chunked_array_type, from_array_kwargs, backend_kwargs, **kwargs)\u001b[0m\n\u001b[1;32m 554\u001b[0m decoders \u001b[38;5;241m=\u001b[39m _resolve_decoders_kwargs(\n\u001b[1;32m 555\u001b[0m decode_cf,\n\u001b[1;32m 556\u001b[0m open_backend_dataset_parameters\u001b[38;5;241m=\u001b[39mbackend\u001b[38;5;241m.\u001b[39mopen_dataset_parameters,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 562\u001b[0m decode_coords\u001b[38;5;241m=\u001b[39mdecode_coords,\n\u001b[1;32m 563\u001b[0m )\n\u001b[1;32m 565\u001b[0m overwrite_encoded_chunks \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moverwrite_encoded_chunks\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[0;32m--> 566\u001b[0m backend_ds \u001b[38;5;241m=\u001b[39m \u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_dataset\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 567\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilename_or_obj\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 568\u001b[0m \u001b[43m \u001b[49m\u001b[43mdrop_variables\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdrop_variables\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 569\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mdecoders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 570\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 571\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 572\u001b[0m ds \u001b[38;5;241m=\u001b[39m _dataset_from_backend_dataset(\n\u001b[1;32m 573\u001b[0m backend_ds,\n\u001b[1;32m 574\u001b[0m filename_or_obj,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 584\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 585\u001b[0m )\n\u001b[1;32m 586\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ds\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/netCDF4_.py:590\u001b[0m, in \u001b[0;36mNetCDF4BackendEntrypoint.open_dataset\u001b[0;34m(self, filename_or_obj, mask_and_scale, decode_times, concat_characters, decode_coords, drop_variables, use_cftime, decode_timedelta, group, mode, format, clobber, diskless, persist, lock, autoclose)\u001b[0m\n\u001b[1;32m 569\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mopen_dataset\u001b[39m( \u001b[38;5;66;03m# type: ignore[override] # allow LSP violation, not supporting **kwargs\u001b[39;00m\n\u001b[1;32m 570\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 571\u001b[0m filename_or_obj: \u001b[38;5;28mstr\u001b[39m \u001b[38;5;241m|\u001b[39m os\u001b[38;5;241m.\u001b[39mPathLike[Any] \u001b[38;5;241m|\u001b[39m BufferedIOBase \u001b[38;5;241m|\u001b[39m AbstractDataStore,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 587\u001b[0m autoclose\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[1;32m 588\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dataset:\n\u001b[1;32m 589\u001b[0m filename_or_obj \u001b[38;5;241m=\u001b[39m _normalize_path(filename_or_obj)\n\u001b[0;32m--> 590\u001b[0m store \u001b[38;5;241m=\u001b[39m \u001b[43mNetCDF4DataStore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 591\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilename_or_obj\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 592\u001b[0m \u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 593\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 594\u001b[0m \u001b[43m \u001b[49m\u001b[43mgroup\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mgroup\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 595\u001b[0m \u001b[43m \u001b[49m\u001b[43mclobber\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclobber\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 596\u001b[0m \u001b[43m \u001b[49m\u001b[43mdiskless\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdiskless\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 597\u001b[0m \u001b[43m \u001b[49m\u001b[43mpersist\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpersist\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 598\u001b[0m \u001b[43m \u001b[49m\u001b[43mlock\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlock\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 599\u001b[0m \u001b[43m \u001b[49m\u001b[43mautoclose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mautoclose\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 600\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 602\u001b[0m store_entrypoint \u001b[38;5;241m=\u001b[39m StoreBackendEntrypoint()\n\u001b[1;32m 603\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m close_on_error(store):\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/netCDF4_.py:391\u001b[0m, in \u001b[0;36mNetCDF4DataStore.open\u001b[0;34m(cls, filename, mode, format, group, clobber, diskless, persist, lock, lock_maker, autoclose)\u001b[0m\n\u001b[1;32m 385\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mdict\u001b[39m(\n\u001b[1;32m 386\u001b[0m clobber\u001b[38;5;241m=\u001b[39mclobber, diskless\u001b[38;5;241m=\u001b[39mdiskless, persist\u001b[38;5;241m=\u001b[39mpersist, \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mformat\u001b[39m\n\u001b[1;32m 387\u001b[0m )\n\u001b[1;32m 388\u001b[0m manager \u001b[38;5;241m=\u001b[39m CachingFileManager(\n\u001b[1;32m 389\u001b[0m netCDF4\u001b[38;5;241m.\u001b[39mDataset, filename, mode\u001b[38;5;241m=\u001b[39mmode, kwargs\u001b[38;5;241m=\u001b[39mkwargs\n\u001b[1;32m 390\u001b[0m )\n\u001b[0;32m--> 391\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mmanager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mgroup\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mgroup\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlock\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlock\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mautoclose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mautoclose\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/netCDF4_.py:338\u001b[0m, in \u001b[0;36mNetCDF4DataStore.__init__\u001b[0;34m(self, manager, group, mode, lock, autoclose)\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_group \u001b[38;5;241m=\u001b[39m group\n\u001b[1;32m 337\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_mode \u001b[38;5;241m=\u001b[39m mode\n\u001b[0;32m--> 338\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mformat \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mds\u001b[49m\u001b[38;5;241m.\u001b[39mdata_model\n\u001b[1;32m 339\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_filename \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mds\u001b[38;5;241m.\u001b[39mfilepath()\n\u001b[1;32m 340\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_remote \u001b[38;5;241m=\u001b[39m is_remote_uri(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_filename)\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/netCDF4_.py:400\u001b[0m, in \u001b[0;36mNetCDF4DataStore.ds\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 398\u001b[0m \u001b[38;5;129m@property\u001b[39m\n\u001b[1;32m 399\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mds\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m--> 400\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_acquire\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/netCDF4_.py:394\u001b[0m, in \u001b[0;36mNetCDF4DataStore._acquire\u001b[0;34m(self, needs_lock)\u001b[0m\n\u001b[1;32m 393\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_acquire\u001b[39m(\u001b[38;5;28mself\u001b[39m, needs_lock\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m):\n\u001b[0;32m--> 394\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_manager\u001b[38;5;241m.\u001b[39macquire_context(needs_lock) \u001b[38;5;28;01mas\u001b[39;00m root:\n\u001b[1;32m 395\u001b[0m ds \u001b[38;5;241m=\u001b[39m _nc4_require_group(root, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_group, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_mode)\n\u001b[1;32m 396\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ds\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/contextlib.py:135\u001b[0m, in \u001b[0;36m_GeneratorContextManager.__enter__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 133\u001b[0m \u001b[38;5;28;01mdel\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39margs, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkwds, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfunc\n\u001b[1;32m 134\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 135\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgen\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 136\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m:\n\u001b[1;32m 137\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgenerator didn\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt yield\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/file_manager.py:199\u001b[0m, in \u001b[0;36mCachingFileManager.acquire_context\u001b[0;34m(self, needs_lock)\u001b[0m\n\u001b[1;32m 196\u001b[0m \u001b[38;5;129m@contextlib\u001b[39m\u001b[38;5;241m.\u001b[39mcontextmanager\n\u001b[1;32m 197\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21macquire_context\u001b[39m(\u001b[38;5;28mself\u001b[39m, needs_lock\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m):\n\u001b[1;32m 198\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Context manager for acquiring a file.\"\"\"\u001b[39;00m\n\u001b[0;32m--> 199\u001b[0m file, cached \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_acquire_with_cache_info\u001b[49m\u001b[43m(\u001b[49m\u001b[43mneeds_lock\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 200\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 201\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m file\n", "File \u001b[0;32m/glade/u/apps/opt/conda/envs/npl-2023b/lib/python3.10/site-packages/xarray/backends/file_manager.py:217\u001b[0m, in \u001b[0;36mCachingFileManager._acquire_with_cache_info\u001b[0;34m(self, needs_lock)\u001b[0m\n\u001b[1;32m 215\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mcopy()\n\u001b[1;32m 216\u001b[0m kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmode\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_mode\n\u001b[0;32m--> 217\u001b[0m file \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_opener\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 218\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 219\u001b[0m \u001b[38;5;66;03m# ensure file doesn't get overridden when opened again\u001b[39;00m\n\u001b[1;32m 220\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_mode \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", "File \u001b[0;32msrc/netCDF4/_netCDF4.pyx:2464\u001b[0m, in \u001b[0;36mnetCDF4._netCDF4.Dataset.__init__\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32msrc/netCDF4/_netCDF4.pyx:2027\u001b[0m, in \u001b[0;36mnetCDF4._netCDF4._ensure_nc_success\u001b[0;34m()\u001b[0m\n", "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/glade/derecho/scratch/PUT_USER_NAME_HERE/archive/b1850.run_length/atm/hist/b1850.run_length.cam.h0.0003-07.nc'" ] } ], "source": [ "ds = xr.open_dataset(files)\n", "ds" ] }, { "cell_type": "markdown", "id": "39d93758-aedb-42ab-810c-257a37dae487", "metadata": {}, "source": [ "_______________\n", "## Exercise 1: Make a lat-lon plot of TS\n", "\n", "To highlight plotting the variables from the CESM atmosphere (CAM) file, the first example will plot a simple global lat/lon plot of surface temperature `TS`" ] }, { "cell_type": "markdown", "id": "1e6b83ad", "metadata": {}, "source": [ "### Grab data from first time stamp\n", "\n", "NOTE: This dataset has only one time" ] }, { "cell_type": "code", "execution_count": null, "id": "feb6d347-cbcb-407c-bb4d-6d89c69fcf32", "metadata": {}, "outputs": [], "source": [ "ts_0 = ds.TS.sel({\"time\": ds.TS.time.values[0]}).squeeze()\n", "ts_0" ] }, { "cell_type": "markdown", "id": "cf1a965c", "metadata": {}, "source": [ "The next step is to set up the map. Since we are plotting a global lat/lon, we will use the \"Plate Carree\" projection. " ] }, { "cell_type": "code", "execution_count": null, "id": "7b183aba-6eae-48ad-9545-f3c918fb99ff", "metadata": {}, "outputs": [], "source": [ "# define the colormap\n", "cmap = mpl.colormaps[\"jet\"]\n", "\n", "# set up the figure with a Plate Carree projection\n", "fig = plt.figure(figsize=(15, 10))\n", "\n", "ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())\n", "\n", "# Plot the first timeslice of TS\n", "img = ax.pcolormesh(ds.lon, ds.lat, ts_0, cmap=cmap, transform=ccrs.PlateCarree())\n", "\n", "plt.title(\"Surface Temperature\", fontsize=20)\n", "\n", "# Set up colorbar\n", "plt.colorbar(img, orientation=\"vertical\", fraction=0.0242, pad=0.01)\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "ccd1f942-a16d-490b-98e6-5f57e92a1cce", "metadata": {}, "source": [ "
\n", "
\n", "Click here for the solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_1.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "1bedaea9-73cf-4011-b928-e8c2de752737", "metadata": {}, "source": [ "**Question:**\n", "\n", "The colorbar limits are set automatically by `pcolormesh`. How could you change the arguments for the `pcolormesh` function to set the plotting limits?" ] }, { "cell_type": "markdown", "id": "e18f7699-44a7-46f9-9503-1d97fb9418f7", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "Choose a maximum temperature of 300K and minimum temperature of 225K.\n", " \n", "```python\n", "img = ax.pcolormesh(ds.lon, ds.lat, ts_0, vmax=300, vmin=225, cmap=cmap, transform=ccrs.PlateCarree())\n", "\n", "```\n", " \n", "
\n", "
\n" ] }, { "cell_type": "markdown", "id": "20dc7be8", "metadata": {}, "source": [ "**Question:**\n", "\n", "How could we change the central longitude?" ] }, { "cell_type": "markdown", "id": "26a14d27-a027-4774-87bf-63712f1f88b6", "metadata": {}, "source": [ "\n", "\n", "
\n", "
\n", "\n", " Click here for hints \n", "The default central longitude is 0. Try setting it to 180. Then try other values from 0-360.\n", "\n", "```python\n", "ax = fig.add_subplot(1,1,1, projection=ccrs.PlateCarree(central_longitude=180))\n", "```\n", " \n", "
\n", "
\n" ] }, { "cell_type": "markdown", "id": "c632aed7", "metadata": {}, "source": [ "A second quick example is for `xarray`'s built-in plotting which uses the `matplotlib` and `cartopy` in the background. `xarray` makes creating a basic plot fairly simple." ] }, { "cell_type": "code", "execution_count": null, "id": "6f48694b-1eae-4b88-87b3-9aec97ed7ffe", "metadata": {}, "outputs": [], "source": [ "# Xarray native plotting\n", "\n", "# Set up figure and axis\n", "fig, ax = plt.subplots(1, figsize=(20, 10))\n", "\n", "# Plot the data straight from the xarray dataset\n", "ts_0.plot.contourf(cmap=\"jet\", levels=np.arange(220, 321, 5))\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "c47469f3-3b57-41c9-9bb2-f56a295bf027", "metadata": {}, "source": [ "
\n", "
\n", "Click here for the solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_2.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "8d12294c-691b-491f-bf88-be4c267a5c73", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "id": "42b295a0-4675-4d4e-814f-5aac53b90973", "metadata": {}, "source": [ "## Exercise 2: Zonal plot of SWCF\n", "\n", "The second example will plot the short wave cloud forcing (`SWCF`) zonally." ] }, { "cell_type": "markdown", "id": "765089ca", "metadata": {}, "source": [ "Grab the variable data and mean over the the lon value" ] }, { "cell_type": "code", "execution_count": null, "id": "801cf760-f576-4cea-9dd6-0dadfc1788a1", "metadata": {}, "outputs": [], "source": [ "ds_swcf = ds.SWCF\n", "\n", "# Get all the dataset dimensions\n", "d = ds_swcf.dims\n", "\n", "# Grab all dimensions to mean the lon values from\n", "davgovr = [dim for dim in d if dim not in (\"lev\", \"lat\")]\n", "\n", "# Make new dataset of zonal mean values\n", "ds_swcf_zonal = ds_swcf.mean(dim=davgovr)\n", "\n", "# print some values of new zonally-averaged SWCF variable\n", "ds_swcf_zonal" ] }, { "cell_type": "code", "execution_count": null, "id": "b92a7bdd-b2dc-4a2c-a6e9-9b75e361492a", "metadata": {}, "outputs": [], "source": [ "# Create figure and axis\n", "fig, ax = plt.subplots(1, figsize=(12, 7))\n", "\n", "# Set Main title for subplots:\n", "plt.title(\"Short Wave Cloud Forcing\", fontsize=20)\n", "\n", "# Plot value on y-axis and latitude on the x-axis\n", "ax.plot(ds_swcf_zonal.lat, ds_swcf_zonal, c=\"goldenrod\")\n", "\n", "ax.set_xlim(\n", " [max([ds_swcf_zonal.lat.min(), -90.0]), min([ds_swcf_zonal.lat.max(), 90.0])]\n", ")\n", "\n", "ax.set_xlabel(\"Latitude\")\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "47ccd4c3-3c40-4b61-9ac1-3df14249eed1", "metadata": {}, "source": [ "
\n", "
\n", "Click here for the solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_3.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "a4cd24f4", "metadata": {}, "source": [ "**Question**\n", "\n", "What code could you add to set a legend for the plot line?" ] }, { "cell_type": "markdown", "id": "afcc9ee3-0312-4440-b720-a547382a960a", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "enter the following lines after the `ax.set_xlabel` command and before the `plt.show()` command. \n", " \n", "```python\n", "label = ds_swcf.time.values[0].strftime() # -> '0001-02-01 00:00:00'\n", "line = Line2D([0], [0], label=label,\n", " color=\"blue\")\n", " \n", "fig.legend(handles=[line],bbox_to_anchor=(-0.15, 0.15, 1.05, .102),loc=\"right\",\n", " borderaxespad=0.0,fontsize=16,frameon=False)\n", "```\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "dbe1163c-0ec0-4f9e-94df-4163078c8803", "metadata": {}, "source": [ "**Question**\n", "\n", "What else could you label the line legend, if anything?\n" ] }, { "cell_type": "markdown", "id": "a5cc83e2-3385-472f-864a-88307c6195c2", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "Try setting the label value to something else like your simulation run name, the season or month, etc.\n", " \n", "```\n", "label = 'Season '\n", "```\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "d7018dc2-c95b-4643-b078-d5033a6f236e", "metadata": {}, "source": [ "**Question**\n", "\n", "How can you change the color on the plot and the legend?" ] }, { "cell_type": "markdown", "id": "3bfc85e8-831b-4ead-a5e9-aa25ce2194ff", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "To change colors, try a different named color (e.g. \"red\" or \"goldenrod\"). You should make sure both the plot and the legend match or your plot won't make sense.\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "55a42e67-2609-4f07-8485-bc8f5035e14a", "metadata": {}, "source": [ "
\n", "
\n", "Click here for a solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_4.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "4d50620e-407d-44ef-bce5-e76c076bcbcd", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "id": "49402bdd-648e-4021-af0e-9280067b7d76", "metadata": {}, "source": [ "## Exercise 3: Plot of zonal T\n", "\n", "This example will plot the 3D zonal mean of temperature `T` with the pressure as the y-variable and latitude as the x-variable. We are showing you four different ways to make the same plot since each is valuable for plots with pressure on the y-axis and how to format those to get more information from the data.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "619d661b-84c9-4a5f-8366-36d8023f082e", "metadata": {}, "outputs": [], "source": [ "# Remove all dimensions of length one\n", "ds_t = ds.T.squeeze()\n", "ds_t" ] }, { "cell_type": "markdown", "id": "3eee4a65-9094-41e6-b905-b6623d62bde4", "metadata": {}, "source": [ "### Plot 1: Natively via xarray\n", "\n", "This plot uses the xarray native grids for the plot\n", "\n", " - y-axis is increasing with height\n", " - y-axis is not in log pressure" ] }, { "cell_type": "code", "execution_count": null, "id": "5d7c3b5c-96ec-4da6-af39-7c4460827f71", "metadata": {}, "outputs": [], "source": [ "# Average over all dimensions except `lev` and `lat`.\n", "d = ds_t.dims\n", "davgovr = [dim for dim in d if dim not in (\"lev\", \"lat\")]\n", "\n", "DS = ds_t.mean(dim=davgovr)\n", "DS.transpose(\"lat\", \"lev\", ...)\n", "fig, ax = plt.subplots(1, figsize=(20, 10))\n", "DS.plot.contourf(ax=ax, y=\"lev\", cmap=\"Spectral_r\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "5324e5a3-c6b4-4213-bf11-6184338a63e2", "metadata": {}, "source": [ "
\n", "
\n", "Click here for a solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_5.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "9b8a57a1-0e26-4740-8182-bf4da973c911", "metadata": {}, "source": [ "### Plot 2: Quick ADF style\n", "\n", "This plot uses the quick style of the AMWG Diagnostics Framework (ADF) packages.\n", "\n", " - y-axis is increasing with height\n", " - y-axis is not in log pressure" ] }, { "cell_type": "code", "execution_count": null, "id": "2440adfe-60ab-4feb-832c-496423057404", "metadata": {}, "outputs": [], "source": [ "# Average over all dimensions except `lev` and `lat`.\n", "d = ds_t.dims\n", "davgovr = [dim for dim in d if dim not in (\"lev\", \"lat\")]\n", "\n", "DS = ds_t.mean(dim=davgovr)\n", "\n", "lev = DS[\"lev\"]\n", "lat = DS[\"lat\"]\n", "mlev, mlat = np.meshgrid(lev, lat)\n", "\n", "# Generate zonal plot:\n", "fig, ax = plt.subplots(1, figsize=(15, 7))\n", "\n", "# Create zonal plot with vertical levels\n", "img = ax.contourf(mlat, mlev, DS.transpose(\"lat\", \"lev\"), cmap=\"Spectral_r\")\n", "\n", "# Format axis and ticks\n", "ax.set_xlabel(\"Latitude\")\n", "fig.colorbar(img, ax=ax, location=\"right\")" ] }, { "cell_type": "markdown", "id": "bd0ac9e7-4a8e-498a-be2b-3a7ddd8cca25", "metadata": {}, "source": [ "
\n", "
\n", "Click here for a solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_6.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "98f31b9b-db5d-4e2a-81f9-df146980dec0", "metadata": {}, "source": [ "**Questions**\n", "\n", "- What differences do you see between the ADF quick plot and the xarray native plot? \n", "- Why might you want to use one or the other?\n", "- Where, vertically, do high pressures occur and what does this mean for where the ground would be located on this plot?" ] }, { "cell_type": "markdown", "id": "96e8b966-f242-4e43-bb51-9deaa77a6bc6", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "Notice that the colorbar and axes labels are different between the two plots. Also note that the y-axis is going from lower to higher pressure values, but in the real atmosphere the highest pressures are near the surface (so the plot is inverted relative to the actual height of the layers above the Earth's surface). \n", " \n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "e866346a-2d31-4df9-955c-b7a2ae00b888", "metadata": {}, "source": [ "### Plot 3: ADF style with reversed y-axis\n", "\n", " - y-axis is decreasing with height\n", " - y-axis is not in log pressure" ] }, { "cell_type": "code", "execution_count": null, "id": "c08d64d9-40d9-4064-9b06-2b8489d916a0", "metadata": {}, "outputs": [], "source": [ "# Average over all dimensions except `lev` and `lat`.\n", "d = ds_t.dims\n", "davgovr = [dim for dim in d if dim not in (\"lev\", \"lat\")]\n", "\n", "DS = ds_t.mean(dim=davgovr)\n", "\n", "# print(DS.lev.min(),DS.lev.max())\n", "\n", "lev = DS[\"lev\"]\n", "lat = DS[\"lat\"]\n", "mlev, mlat = np.meshgrid(lev, lat)\n", "\n", "# Generate zonal plot:\n", "fig, ax = plt.subplots(1, figsize=(15, 7))\n", "\n", "# Create zonal plot with vertical levels\n", "img = ax.contourf(mlat, mlev, DS.transpose(\"lat\", \"lev\"), cmap=\"Spectral_r\")\n", "\n", "# Format axis and ticks\n", "plt.gca().invert_yaxis()\n", "ax.tick_params(which=\"minor\", length=4, color=\"r\")\n", "\n", "# Set up colorbar\n", "cbar_ax = fig.add_axes([0, 0, 0.1, 0.1])\n", "posn = ax.get_position()\n", "\n", "# Set position and size of colorbar position: [left, bottom, width, height]\n", "cbar_ax.set_position([posn.x0 + posn.width + 0.005, posn.y0, 0.02, posn.height])\n", "\n", "ax.set_xlabel(\"Latitude\")\n", "fig.colorbar(img, cax=cbar_ax, orientation=\"vertical\")" ] }, { "cell_type": "markdown", "id": "ba0aa084-f95e-4951-81b0-3951e8ed0b29", "metadata": {}, "source": [ "
\n", "
\n", "Click here for a solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_7.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "a0beeca6-4697-4bc8-b42d-e43ccceecbef", "metadata": {}, "source": [ "**Question:**\n", "\n", "- What differences do you see on the y-axis between the result from Plot 2 and Plot 3? " ] }, { "cell_type": "markdown", "id": "1dd69767-20ac-49ff-9c1f-ade44886de56", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "The plots are mirror images of each other because the y-axis has been flipped. Plot 2 has the highest pressures at the top of the y-axis while Plot 3 has the highest pressures at the bottom of the y-axis.\n", " \n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "8bd94a75-58cb-4b5d-a806-45b64c26e727", "metadata": {}, "source": [ "**Question:**\n", "\n", "- Where, vertically, do high pressures occur and what does this mean for where the ground would be located on these two figures ?" ] }, { "cell_type": "markdown", "id": "4b1b7ab1-20ff-4745-bad7-cf50c9b807b8", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "The highest pressures in the atmosphere occur at the ground where the most atmospheric mass is pressing downward. This means that Plot 2 is oriented so the location where the ground is is the top of the plot, or up. In Plot 3 the orientation is so that the ground would be at the bottom of the plot, or down. Thus Plot 3 is often more intuitive to read because it's oriented with the way we perceive the atmosphere.\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "84fc1ae8-74f3-4c4f-9171-18b5625f2d96", "metadata": {}, "source": [ "### Plot 4: Complex ADF style\n", "\n", " - y-axis is decreasing with height\n", " - y-axis is in log pressure" ] }, { "cell_type": "code", "execution_count": null, "id": "50564cf7-948e-4b77-9537-707b7358bf71", "metadata": {}, "outputs": [], "source": [ "# Average over all dimensions except `lev` and `lat`.\n", "d = ds_t.dims\n", "davgovr = [dim for dim in d if dim not in (\"lev\", \"lat\")]\n", "\n", "DS = ds_t.mean(dim=davgovr)\n", "\n", "# print(DS.lev.min(),DS.lev.max())\n", "\n", "lev = DS[\"lev\"]\n", "lat = DS[\"lat\"]\n", "mlev, mlat = np.meshgrid(lev, lat)\n", "\n", "# Generate zonal plot:\n", "fig, ax = plt.subplots(1, figsize=(15, 7))\n", "\n", "# Create zonal plot with vertical levels\n", "img = ax.contourf(mlat, mlev, DS.transpose(\"lat\", \"lev\"), cmap=\"Spectral_r\")\n", "\n", "# Format axis and ticks\n", "plt.yscale(\"log\")\n", "plt.gca().invert_yaxis()\n", "ax.tick_params(which=\"minor\", length=4, color=\"r\")\n", "\n", "# Set up colorbar\n", "cbar_ax = fig.add_axes([0, 0, 0.1, 0.1])\n", "posn = ax.get_position()\n", "\n", "# Set position and size of colorbar position: [left, bottom, width, height]\n", "cbar_ax.set_position([posn.x0 + posn.width + 0.005, posn.y0, 0.02, posn.height])\n", "\n", "ax.set_xlabel(\"Latitude\")\n", "fig.colorbar(img, cax=cbar_ax, orientation=\"vertical\")" ] }, { "cell_type": "markdown", "id": "5a8fb095-89fd-4112-9d4f-de5f4ee9f143", "metadata": {}, "source": [ "
\n", "
\n", "Click here for a solution
\n", "\n", "![plot example](../../../images/diagnostics/cam/basics_plot_8.png)\n", "\n", "*

Figure: Plotting solution.

*\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "4d7c9ee8-9445-489f-9b07-3ab67e45398d", "metadata": {}, "source": [ "**Question:**\n", "\n", "- What differences do you see on the y-axis between the result from Plot 3 and Plot 4? " ] }, { "cell_type": "markdown", "id": "f931e791-2f0a-423f-b44b-644686657767", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "The plots both have the y-axis oriented so that the highest pressures, or ground, is at the bottom of the plot. But the scale of the y-axis has changed so that in Plot 3 it is logarithmic.\n", " \n", "
\n", "
" ] }, { "cell_type": "markdown", "id": "6a6af568-90cf-4f8c-a3c8-5dcda30359fd", "metadata": {}, "source": [ "**Question:**\n", "\n", "- What does that mean in terms of which part of the atmosphere are emphasized?" ] }, { "cell_type": "markdown", "id": "0aa7131d-4337-4da2-8b8d-db9a69432142", "metadata": {}, "source": [ "
\n", "
\n", "\n", " Click here for hints \n", "\n", "With the logarithmic y-axis more of the upper atmosphere is shown on the figure. If you wanted to emphasize the boundary layer you might want to change the limits of the figure.\n", " \n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "id": "8c7c4e8c-4a4a-4f3e-a6d7-4b5e7725a2f7", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "NPL 2023b", "language": "python", "name": "npl-2023b" }, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }