Cool stuff in this tutorial:
1) use iris package to understand netcdf
In [1]:
fname = '~brodzik/cartopy-tutorial/resources/HadCRUT/fogg_mean_surface_temp.nc'
In [2]:
!ncdump -h $fname
In [3]:
import iris
cube = iris.load_cube(fname)
In [4]:
cube
Out[4]:
In [5]:
print(cube.coord('decade').points)
In [6]:
print(cube.coord('month_number').points)
In [7]:
print(cube.coord('time'))
In [8]:
%matplotlib notebook
import cartopy.crs as ccrs
import iris.plot as iplt
import matplotlib.pyplot as plt
In [9]:
plt.figure()
october_cube = cube.extract(iris.Constraint(month_number=10))
ax1 = plt.subplot(211, projection=ccrs.Robinson())
iplt.pcolormesh(october_cube)
plt.title('pcolormesh')
ax1.coastlines()
ax1.set_global()
ax2 = plt.subplot(212, projection=ccrs.Robinson())
iplt.contourf(october_cube)
plt.title('contourf')
ax2.coastlines()
ax2.set_global()
plt.tight_layout()
plt.show()
In [10]:
# Our calculated geolocated raster image extents.
extent = [-13636707, 17044670,
-6308712, 8565930]
plt.figure()
fname = '/Users/brodzik/cartopy-tutorial/resources/640px-Around_the_World_in_Eighty_Days_map.png'
rob = ccrs.Robinson(central_longitude=11.25)
ax = plt.axes(projection=rob)
ax.gridlines(color='gray', linestyle='--')
ax.coastlines()
img = plt.imread(fname)
ax.imshow(img, extent=extent, transform=rob, origin='upper')
ax.set_global()
plt.tight_layout()
plt.show()
In [11]:
plt.figure()
# this kills the kernel, not sure why:
#ax = plt.axes(projection=ccrs.LambertAzimuthalEqualArea(central_latitude=90.))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.gridlines(color='gray', linestyle='--')
ax.coastlines()
img = plt.imread(fname)
ax.imshow(img, extent=extent, transform=rob, origin='upper')
ax.set_global()
plt.tight_layout()
plt.show()
In [18]:
plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree())
ax.gridlines(color='gray', linestyle='--')
ax.coastlines()
# wikipedia image
img = plt.imread(fname)
ax.imshow(img, extent=extent, transform=rob, origin='upper')
# October 1870s mean surf temps
iplt.contourf(october_cube, alpha=0.25)
plt.title('October 1870s decadal mean surface temps')
ax.set_global()
plt.tight_layout()
plt.show()
In [ ]: