Skip to content

Description:

  • Geospatial data processing to produce maps and other geospatial data analyses.

Resources:

Source and license:

import cartopy.feature as cfeature
land_50m = cfeature.NaturalEarthFeature('physical', 'land', '50m',
edgecolor='face',
facecolor=cfeature.COLORS['land'])
import cartopy.feature
sorted(cartopy.feature.COLORS.keys())
Output
['land', 'land_alt1', 'water']
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from pathlib import Path
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
dir = Path('/tmp/ganymede_demo/')
dir.mkdir(parents=True, exist_ok=True)
# Save the plot by calling plt.savefig() BEFORE plt.show()
plt.savefig('/tmp/ganymede_demo/coastlines.pdf')
plt.savefig('/tmp/ganymede_demo/coastlines.png')
Figure drawn by code cell 3
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()
ny_lon, ny_lat = -75, 43
delhi_lon, delhi_lat = 77.23, 28.61
plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat],
color='blue', linewidth=2, marker='o',
transform=ccrs.Geodetic(),
)
plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat],
color='gray', linestyle='--',
transform=ccrs.PlateCarree(),
)
plt.text(ny_lon - 3, ny_lat - 12, 'New York',
horizontalalignment='right',
transform=ccrs.Geodetic())
plt.text(delhi_lon + 3, delhi_lat - 12, 'Delhi',
horizontalalignment='left',
transform=ccrs.Geodetic())
Output
Text(80.23, 16.61, 'Delhi')
Figure drawn by code cell 4

Draw filled contours of sea surface temperature from a netCDF file (from cartopy’s sample data)

Data: HadISST, Met Office Hadley Centre (Rayner et al. 2003, doi:10.1029/2002JD002670), © British Crown Copyright, Met Office; see https://www.metoffice.gov.uk/hadobs/hadisst/ for its terms.

import matplotlib.pyplot as plt
from scipy.io import netcdf_file
from cartopy import config
import cartopy.crs as ccrs
# get the path of the file. It ships in cartopy's sample data directory.
fname = config["repo_data_dir"] / 'netcdf' / 'HadISST1_SST_update.nc'
dataset = netcdf_file(fname, maskandscale=True, mmap=False)
sst = dataset.variables['sst'][0, :, :]
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
ax = plt.axes(projection=ccrs.PlateCarree())
plt.contourf(lons, lats, sst, 60,
transform=ccrs.PlateCarree())
ax.coastlines()
Figure drawn by code cell 5

Show a satellite image of Hurricane Miriam (from cartopy’s sample data) in its geographic position

Image: NASA (Aqua/MODIS).

import os
import matplotlib.pyplot as plt
from cartopy import config
import cartopy.crs as ccrs
fig = plt.figure(figsize=(8, 12))
# get the path of the file. It ships in cartopy's sample data directory.
fname = config["repo_data_dir"] / 'raster' / 'sample' / 'Miriam.A2012270.2050.2km.jpg'
img_extent = (-120.67660000000001, -106.32104523100001, 13.2301484511245, 30.766899999999502)
img = plt.imread(fname)
ax = plt.axes(projection=ccrs.PlateCarree())
plt.title('Hurricane Miriam from the Aqua/MODIS satellite\n'
'2012 09/26/2012 20:50 UTC')
ax.use_sticky_edges = False
# set a margin around the data
ax.set_xmargin(0.05)
ax.set_ymargin(0.10)
# add the image. Because this image was a tif, the "origin" of the image is in the
# upper left corner
ax.imshow(img, origin='upper', extent=img_extent, transform=ccrs.PlateCarree())
ax.coastlines(resolution='50m', color='black', linewidth=1)
# mark a known place to help us geo-locate ourselves
ax.plot(-117.1625, 32.715, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(-117, 33, 'San Diego', transform=ccrs.Geodetic())
plt.show()
Figure drawn by code cell 6

ganymede is made by Eugo