File: garp.py

package info (click to toggle)
basemap 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 212,272 kB
  • sloc: python: 9,541; ansic: 266; makefile: 39; sh: 23
file content (65 lines) | stat: -rw-r--r-- 2,264 bytes parent folder | download | duplicates (3)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import (absolute_import, division, print_function)

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

def get_input(prompt):
    if sys.hexversion > 0x03000000:
        return input(prompt)
    else:
        return raw_input(prompt)

# the shortest route from the center of the map
# to any other point is a straight line in the azimuthal
# equidistant projection. Such lines show the true scale
# on the earth's surface.
# So, for the specified point, this script draws a map that shows
# in which direction to depart for other points on earth and how far
# it will be to reach that destination.
# The specified point shows up as a red dot in the center of the map.

# user enters the lon/lat of the point, and it's name
lon_0 = float(get_input('input reference lon (degrees):'))
lat_0 = float(get_input('input reference lat (degrees):'))
location = get_input('name of location:')

# no width/height or lat/lon corners specified, so whole world
# is plotted in a circle.
m = Basemap(resolution='c',projection='aeqd',lat_0=lat_0,lon_0=lon_0)

# draw coastlines and fill continents.
# **it's easy to make this fail with global aeqd plots.
#  For example, if the center point is at the North Pole,
#  the continent filling routines get confused and fills
#  the outside of Antartica instead of the inside**

#m.drawmapboundary(fill_color='white')
#m.drawcoastlines(linewidth=0.5)
#m.fillcontinents(color='black',lake_color='white')
#m.drawparallels(np.arange(-80,81,20),color='0.7')
#m.drawmeridians(np.arange(-180,180,20),color='0.7')

# draw lsmask instead of drawing continents (slower, but more robust).

m.drawlsmask(land_color='black',ocean_color='white',lakes=True,resolution='l',grid=5)
m.drawparallels(np.arange(-80,81,20),color='0.7')
m.drawmeridians(np.arange(-180,180,20),color='0.7')
m.drawmapboundary()

# blue marble background (pretty, but slow).

#m.bluemarble(scale=0.5)
#m.drawparallels(np.arange(-80,81,20),color='0.5')
#m.drawmeridians(np.arange(-180,180,20),color='0.5')
#m.drawmapboundary(color='0.5')

# draw a red dot at the center.
xpt, ypt = m(lon_0, lat_0)
m.plot([xpt],[ypt],'ro') 

# draw the title.
plt.title('The World According to Garp in '+location)

plt.show()