File: hires.py

package info (click to toggle)
basemap 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 213,536 kB
  • sloc: python: 11,826; sh: 45; makefile: 41
file content (51 lines) | stat: -rw-r--r-- 1,518 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import print_function

import time
import pickle

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap


# Create figure.
fig = plt.figure()

# Create Basemap instance:
# - Use 'full' resolution coastlines.
# - Make sure that countries and rivers are loaded.
t0 = time.time()
bmap1 = Basemap(width=920000, height=1100000, resolution="f",
                projection="tmerc", lon_0=-4.2, lat_0=54.6)
bmap1.drawcountries()
bmap1.drawrivers()
t1 = time.time()
print("{0:.3f} secs to plot with a Basemap instance created at runtime".format(t1 - t0))

# Clear the figure.
plt.clf()

# Pickle the class instance.
with open("map.pickle", "wb") as fd:
    pickle.dump(bmap1, fd, protocol=-1)

# Read pickle back in and plot it again (should be much faster):
# - Draw coastlines and fill continents and lakes.
# - Draw political boundaries and rivers.
# - Draw parallels and meridians.
# - Draw map boundary and fill map background.
t0 = time.time()
with open("map.pickle", "rb") as fd:
    bmap2 = pickle.load(fd)
bmap2.drawcoastlines()
bmap2.fillcontinents(color="coral", lake_color="aqua")
bmap2.drawcountries(linewidth=1)
bmap2.drawrivers(color="b")
bmap2.drawparallels(np.arange(48, 65, 2), labels=[1, 1, 0, 0])
bmap2.drawmeridians(np.arange(-12, 13, 2), labels=[0, 0, 1, 1])
bmap2.drawmapboundary(fill_color="aqua")
t1 = time.time()
print("{0:.3f} secs to plot with a pickled Basemap instance".format(t1 - t0))

plt.title("High-Res British Isles", y=1.04)
plt.show()