From d03f056b94f4f31505158f788968f92b22adacf2 Mon Sep 17 00:00:00 2001 From: zbruick Date: Fri, 9 Aug 2019 10:02:15 -0600 Subject: [PATCH 1/4] Adds an example of ERA5 and GRIB data to the gallery --- doc/environment.yml | 1 + doc/examples/ERA5-GRIB-example.ipynb | 86 ++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 doc/examples/ERA5-GRIB-example.ipynb diff --git a/doc/environment.yml b/doc/environment.yml index 9aadfa745a1..596a8df6a7f 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -29,3 +29,4 @@ dependencies: - jupyter_client=5.3.1 - ipykernel=5.1.1 - pip + - cfgrib diff --git a/doc/examples/ERA5-GRIB-example.ipynb b/doc/examples/ERA5-GRIB-example.ipynb new file mode 100644 index 00000000000..808d6f619a0 --- /dev/null +++ b/doc/examples/ERA5-GRIB-example.ipynb @@ -0,0 +1,86 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import xarray as xr\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ds = xr.load_dataset('data/era5-2mt-2019-03-uk.grib', engine='cfgrib')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ds = ds - 273.15\n", + "ds.t2m[0].plot(cmap=plt.cm.coolwarm)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import cartopy.crs as ccrs\n", + "import cartopy\n", + "fig = plt.figure(figsize=(10,10))\n", + "ax = plt.axes(projection=ccrs.Robinson())\n", + "ax.coastlines(resolution='10m')\n", + "plot = ds.t2m[0].plot(cmap=plt.cm.coolwarm, transform=ccrs.PlateCarree(), cbar_kwargs={'shrink':0.6})\n", + "plt.title('ERA5 - 2m temperature British Isles March 2019')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ds.t2m.sel(longitude=0,latitude=51.5).plot()\n", + "plt.title('ERA5 - London 2m temperature March 2019')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 1c07b352d497ade95cbd54cdac2a04e2614cb4cc Mon Sep 17 00:00:00 2001 From: zbruick Date: Tue, 10 Sep 2019 15:36:58 -0600 Subject: [PATCH 2/4] Add markdown narrative cells to GRIB example --- doc/examples/ERA5-GRIB-example.ipynb | 47 ++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/doc/examples/ERA5-GRIB-example.ipynb b/doc/examples/ERA5-GRIB-example.ipynb index 808d6f619a0..9fdba414832 100644 --- a/doc/examples/ERA5-GRIB-example.ipynb +++ b/doc/examples/ERA5-GRIB-example.ipynb @@ -1,5 +1,19 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# GRIB Data Example " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "GRIB format is commonly used to disemminate atmospheric model data. With Xarray and the cfgrib engine, GRIB data can easily be analyzed and visualized." + ] + }, { "cell_type": "code", "execution_count": null, @@ -10,6 +24,13 @@ "import matplotlib.pyplot as plt" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To read GRIB data, you can use `xarray.load_dataset`. The only extra code you need is to specify the engine as `cfgrib`." + ] + }, { "cell_type": "code", "execution_count": null, @@ -19,6 +40,13 @@ "ds = xr.load_dataset('data/era5-2mt-2019-03-uk.grib', engine='cfgrib')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's create a simple plot of 2-m air temperature in degrees Celsius:" + ] + }, { "cell_type": "code", "execution_count": null, @@ -29,6 +57,13 @@ "ds.t2m[0].plot(cmap=plt.cm.coolwarm)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With CartoPy, we can create a more detailed plot, using built-in shapefiles to help provide geographic context:" + ] + }, { "cell_type": "code", "execution_count": null, @@ -45,13 +80,10 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "ds.t2m.sel(longitude=0,latitude=51.5).plot()\n", - "plt.title('ERA5 - London 2m temperature March 2019')" + "Finally, we can also pull out a time series for a given location easily:" ] }, { @@ -59,7 +91,10 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "ds.t2m.sel(longitude=0,latitude=51.5).plot()\n", + "plt.title('ERA5 - London 2m temperature March 2019')" + ] } ], "metadata": { From ec8389e20ecdddb06749f66e3cac9fc7218135a3 Mon Sep 17 00:00:00 2001 From: zbruick Date: Mon, 23 Sep 2019 13:06:57 -0600 Subject: [PATCH 3/4] Update load method to use xr.tutorial --- doc/examples/ERA5-GRIB-example.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/examples/ERA5-GRIB-example.ipynb b/doc/examples/ERA5-GRIB-example.ipynb index 9fdba414832..aa47e0f0b75 100644 --- a/doc/examples/ERA5-GRIB-example.ipynb +++ b/doc/examples/ERA5-GRIB-example.ipynb @@ -37,7 +37,7 @@ "metadata": {}, "outputs": [], "source": [ - "ds = xr.load_dataset('data/era5-2mt-2019-03-uk.grib', engine='cfgrib')" + "ds = xr.tutorial.load_dataset('data/era5-2mt-2019-03-uk.grib', engine='cfgrib')" ] }, { From 9e0388218542b934cce98346f688fd4b48f6a783 Mon Sep 17 00:00:00 2001 From: zbruick Date: Mon, 23 Sep 2019 14:19:55 -0600 Subject: [PATCH 4/4] Fix load method --- doc/examples/ERA5-GRIB-example.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/examples/ERA5-GRIB-example.ipynb b/doc/examples/ERA5-GRIB-example.ipynb index aa47e0f0b75..b82a07a64e6 100644 --- a/doc/examples/ERA5-GRIB-example.ipynb +++ b/doc/examples/ERA5-GRIB-example.ipynb @@ -37,7 +37,7 @@ "metadata": {}, "outputs": [], "source": [ - "ds = xr.tutorial.load_dataset('data/era5-2mt-2019-03-uk.grib', engine='cfgrib')" + "ds = xr.tutorial.load_dataset('era5-2mt-2019-03-uk.grib', engine='cfgrib')" ] }, {