{ "metadata": { "name": "", "signature": "sha256:84e2561541ceb06e17ac6918f6f5b1b16ac7953d71b5e7fa2939794d551a6fdf" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Cartopy Basics in IPython Notebook\n", "==================================\n", "\n", "*Author: Brian M Hamlin - 'darkblue_b'*\n", "\n", "* Import a netCDF world weather history from OSGeo Live sample data sets.\n", "* Plot one day using various mapping projections\n", "\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from netCDF4 import Dataset\n", "import numpy as np" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "my_example_nc_file = '/home/user/data/netcdf/txxETCCDI_yr_MIROC5_historical_r2i1p1_1850-2012.nc'\n", "fh = Dataset(my_example_nc_file, mode='r')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "lons = fh.variables['lon'][:]\n", "lats = fh.variables['lat'][:]\n", "tmax = fh.variables['txxETCCDI'][:]\n", "\n", "tmax_units = fh.variables['txxETCCDI'].units\n", "fh.close()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import Cartopy, Display Example Maps\n", "-------------------------------------\n", "* some examples will display warnings, software under construction!\n", "* note: you need a working Internet connection to get more natural_earth display sizes\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import cartopy.crs as ccrs\n" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.Mollweide())\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.Robinson())\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.GOOGLE_MERCATOR)\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.NorthPolarStereo())\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.Miller())\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.TransverseMercator())\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.EuroPP())\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "ax = plt.axes(projection=ccrs.LambertCylindrical () )\n", "ax.contourf( lons, lats, tmax[1],\n", " transform=ccrs.PlateCarree(),\n", " cmap='spectral')\n", "ax.coastlines()\n", "ax.set_global()\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }