|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# GRIB Data Example " |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "markdown", |
| 12 | + "metadata": {}, |
| 13 | + "source": [ |
| 14 | + "GRIB format is commonly used to disemminate atmospheric model data. With Xarray and the cfgrib engine, GRIB data can easily be analyzed and visualized." |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "code", |
| 19 | + "execution_count": null, |
| 20 | + "metadata": {}, |
| 21 | + "outputs": [], |
| 22 | + "source": [ |
| 23 | + "import xarray as xr\n", |
| 24 | + "import matplotlib.pyplot as plt" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "markdown", |
| 29 | + "metadata": {}, |
| 30 | + "source": [ |
| 31 | + "To read GRIB data, you can use `xarray.load_dataset`. The only extra code you need is to specify the engine as `cfgrib`." |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": null, |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "ds = xr.tutorial.load_dataset('era5-2mt-2019-03-uk.grib', engine='cfgrib')" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "markdown", |
| 45 | + "metadata": {}, |
| 46 | + "source": [ |
| 47 | + "Let's create a simple plot of 2-m air temperature in degrees Celsius:" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": null, |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [], |
| 55 | + "source": [ |
| 56 | + "ds = ds - 273.15\n", |
| 57 | + "ds.t2m[0].plot(cmap=plt.cm.coolwarm)" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "markdown", |
| 62 | + "metadata": {}, |
| 63 | + "source": [ |
| 64 | + "With CartoPy, we can create a more detailed plot, using built-in shapefiles to help provide geographic context:" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "metadata": {}, |
| 71 | + "outputs": [], |
| 72 | + "source": [ |
| 73 | + "import cartopy.crs as ccrs\n", |
| 74 | + "import cartopy\n", |
| 75 | + "fig = plt.figure(figsize=(10,10))\n", |
| 76 | + "ax = plt.axes(projection=ccrs.Robinson())\n", |
| 77 | + "ax.coastlines(resolution='10m')\n", |
| 78 | + "plot = ds.t2m[0].plot(cmap=plt.cm.coolwarm, transform=ccrs.PlateCarree(), cbar_kwargs={'shrink':0.6})\n", |
| 79 | + "plt.title('ERA5 - 2m temperature British Isles March 2019')" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "markdown", |
| 84 | + "metadata": {}, |
| 85 | + "source": [ |
| 86 | + "Finally, we can also pull out a time series for a given location easily:" |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "cell_type": "code", |
| 91 | + "execution_count": null, |
| 92 | + "metadata": {}, |
| 93 | + "outputs": [], |
| 94 | + "source": [ |
| 95 | + "ds.t2m.sel(longitude=0,latitude=51.5).plot()\n", |
| 96 | + "plt.title('ERA5 - London 2m temperature March 2019')" |
| 97 | + ] |
| 98 | + } |
| 99 | + ], |
| 100 | + "metadata": { |
| 101 | + "kernelspec": { |
| 102 | + "display_name": "Python 3", |
| 103 | + "language": "python", |
| 104 | + "name": "python3" |
| 105 | + }, |
| 106 | + "language_info": { |
| 107 | + "codemirror_mode": { |
| 108 | + "name": "ipython", |
| 109 | + "version": 3 |
| 110 | + }, |
| 111 | + "file_extension": ".py", |
| 112 | + "mimetype": "text/x-python", |
| 113 | + "name": "python", |
| 114 | + "nbconvert_exporter": "python", |
| 115 | + "pygments_lexer": "ipython3", |
| 116 | + "version": "3.7.3" |
| 117 | + } |
| 118 | + }, |
| 119 | + "nbformat": 4, |
| 120 | + "nbformat_minor": 4 |
| 121 | +} |
0 commit comments