{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## ERA-5 Data and Graphics Preparation for the Science-on-a-Sphere" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview:\n", "\n", "1. Programmatically request a specific date from the [RDA ERA-5 THREDDS repository](https://rda.ucar.edu/thredds/catalog/files/g/ds633.0/catalog.html)\n", "1. Re-arrange the order of the longitudinal dimension in the dataset\n", "1. Use Cartopy's `add_cyclic_point` method to avoid a blank seam at the dateline\n", "1. Create 24 hours worth of Science-on-a-Sphere-ready plots\n", "1. Create a set of labels for each plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prerequisites\n", "\n", "| Concepts | Importance | Notes |\n", "| --- | --- | --- |\n", "| Xarray | Necessary | |\n", "\n", "* **Time to learn**: 30 minutes\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import numpy as np\n", "import pandas as pd\n", "from pandas.tseries.offsets import MonthEnd,MonthBegin\n", "import cartopy.feature as cfeature\n", "import cartopy.crs as ccrs\n", "import cartopy.util as cutil\n", "import requests\n", "from datetime import datetime, timedelta\n", "import warnings\n", "import metpy.calc as mpcalc\n", "from metpy.units import units\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "warnings.simplefilter(\"ignore\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Programmatically request a specific date from the [RDA ERA-5 THREDDS repository](https://rda.ucar.edu/thredds/catalog/files/g/ds633.0/catalog.html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next several cells set the date/time, creates the URL strings, and retrieves selected grids from RDA." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Select your date and time here\n", "year = 1978\n", "month = 1\n", "day = 26\n", "hour = 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
open_mfdataset
method, this method does not reliably work when reading from a THREDDS server such as RDA's. Therefore, please restrict your temporal range to no more than one calendar day in this notebook.\n",
" Axes
. We don't want that included on the sphere-projected graphic either.DataArray
as its arguments."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def make_sos_map (i, z):\n",
" res = '110m'\n",
" dpi = 100\n",
" fig = plt.figure(figsize=(2048/dpi, 1024/dpi))\n",
" ax = plt.subplot(1,1,1,projection=ccrs.PlateCarree(), frameon=False)\n",
" ax.set_global()\n",
" ax.add_feature(cfeature.COASTLINE.with_scale(res))\n",
" ax.add_feature(cfeature.BORDERS.with_scale(res))\n",
" ax.add_feature(cfeature.STATES.with_scale(res))\n",
"\n",
" # add cyclic points to data and longitudes\n",
" # latitudes are unchanged in 1-dimension\n",
" SLP2d, clons= cutil.add_cyclic_point(SLP.isel(time=i), lons)\n",
" z2d, clons = cutil.add_cyclic_point(z, lons)\n",
"\n",
" # Height (Z) contour fills\n",
"\n",
" CF = ax.contourf(clons,lats,z2d,levels=zLevels,cmap=plt.get_cmap('viridis'), extend='both') \n",
"\n",
" # SLP contour lines\n",
" CL = ax.contour(clons,lats,SLP2d,slpLevels,linewidths=1.25,colors='chocolate', transform=proj_data)\n",
" ax.clabel(CL, inline_spacing=0.2, fontsize=8, fmt='%.0f')\n",
" fig.tight_layout(pad=.01)\n",
" frameNum = str(i).zfill(2)\n",
" fig.savefig('ERA5_780126' + frameNum + '.png')\n",
" plt.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open a handle to a text file that will contain each plot's title."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"inc
to 1 so all hours are processed.