Map Projection (using PyGMT)
Compared to Cartopy package, PyGMT provides higher resolution map projection.
Monthly dataset
Read data and calculate the monthly average as if you were programming with the Cartopy pakage.
Monthly temperature plots on a map
Pygmt install
The map projection uses PyGMT package.
You can simply command $ conda install -n env_weclim -c conda-forge pygmt
.
The information on PyGMT installation is available here.
Map plots
The background map can be drawn using the following commends:
import pygmt
def read_maps(dat,lons,lats,minlon,maxlon,minlat,maxlat,titleX):
#define etopo data file
topo_data = '@earth_relief_30s' #30 arc second global relief (SRTM15+V2.1 @ 1.0 km)
# Visualization
fig = pygmt.Figure()
# make color pallets
pygmt.makecpt(
cmap='topo',
series='-8000/8000/1000',
continuous=True
)
#plot high res topography
fig.grdimage(
grid=topo_data,
region=[minlon, maxlon, minlat, maxlat],
projection='M4i',
shading=True,
frame=True
)
# plot coastlines
fig.coast(
region=[minlon, maxlon, minlat, maxlat],
projection='M4i',
shorelines=True,
frame=True
)
fig.coast(borders=["2/0.5p,red"])
# plot topo contour lines
fig.grdcontour(
grid=topo_data,
interval=4000,
annotation="4000+f6p",
limit="-8000/0",
pen="a0.15p"
)
## Plot colorbar
# Default is horizontal colorbar
fig.colorbar(
frame='+l"Topography (m)"',
position="x11.5c/6.6c+w6c+jTC+v"
)
# Color options and data range
pygmt.makecpt(cmap="jet", series=[-20,40])
# Plot temperature at each weather station
fig.plot(
x=lons,
y=lats,
style='c0.1i',
color=dat['TAIR'],
cmap=True,
pen='black',
label='something'
)
# Main and colorbar titles
fig.basemap(frame=["a", f'WSne+t"{titleX}"'])
fig.colorbar(frame='af+l"Air Temperature (oC)"')
return(fig)
dat
are temperature data for all locations including longitude lons
and latitude lats
information. maxlat
minlat
maxlon
minlon
are the range of map area.
fig.coast(borders=["2/0.5p,red"])
: borders options are 1 (National boundaries), 2 (State boundaries within the America), 3 (Marine boundaries), and a (All boundaries).
fig.basemap(frame=["a", f'WSne+t"{titleX}"'])
: Wsne
is the title positioning.
Sample program for maps
Source file: maps.pygmt.py
Create animation
PNG files can be converted to animated images (gif file).
Here, -delay N
is the frame rate of N/100 (seconds) and -loop M
is the number of loop of the animation image.
You can check the animation image as $ animate XX.gif
.