Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version 1.0.3 (not yet released)
--------------------------------
version 1.0.3 (git tag v1.0.3)
------------------------------
* fix some more python 3 compatibility issues (all examples now
work with python 3.2).
* added alpha keyword to fillcontinents (to set transparency).
* update geos from 3.3.1 to 3.3.3.
* upgrade proj4 source to version 4.8.0, pyproj to version 1.9.2.
Expand Down
7 changes: 4 additions & 3 deletions examples/allskymap.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
"""
AllSkyMap is a subclass of Basemap, specialized for handling common plotting
tasks for celestial data.
Expand Down Expand Up @@ -35,9 +36,9 @@ def angle_symbol(angle, round_to=1.0):
"""
value = np.round(angle / round_to) * round_to
if pl.rcParams['text.usetex'] and not pl.rcParams['text.latex.unicode']:
return r"$%0.0f^\circ$" % value
return r'$%0.0f^\circ$' % value
else:
return u"%0.0f\u00b0" % value
return '%0.0f\N{DEGREE SIGN}' % value


class AllSkyMap(Basemap):
Expand Down Expand Up @@ -224,7 +225,7 @@ def geodesic(self, lon1, lat1, lon2, lat2, del_s=.01, clip=True, **kwargs):
# If there are multiple segments and no color args, reconcile the
# colors, which mpl will have autoset to different values.
# *** Does this screw up mpl's color set sequence for later lines?
if not kwargs.has_key('c') or kwargs.has_key('color'):
if 'c' not in kwargs or 'color' in kwargs:
if len(lines) > 1:
c1 = lines[0].get_color()
for line in lines[1:]:
Expand Down
11 changes: 7 additions & 4 deletions examples/allskymap_cr_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
Created 2011-02-07 by Tom Loredo
"""

from cStringIO import StringIO
try:
from cStringIO import StringIO
except:
from io import StringIO
import numpy as np
from numpy import cos, sin, arccos, deg2rad, rad2deg
import csv, re
import csv, re, sys

import matplotlib.pyplot as plt
from allskymap import AllSkyMap
Expand Down Expand Up @@ -110,7 +113,7 @@ def gcangle(self, src):
# Make an integer ID from Year+Day (presumes none on same day!).
src = Source(id, row[0], row[1], row[7], row[8], E=float(row[4]))
CRs[src.id] = src
print 'Parsed data for', len(CRs), 'UHE CRs...'
sys.stdout.write('Parsed data for %s UHE CRs...\n'%len(CRs))

# Partly fictitious candidate source locations.
# src.id src.l_deg src.b_deg src.xProj src.yProj
Expand Down Expand Up @@ -141,7 +144,7 @@ def gcangle(self, src):
for row in CandTable:
src = Source(row[0], 0, 0, row[1], row[2])
cands[src.id] = src
print 'Parsed data for', len(cands), 'candidate sources...'
sys.stdout.write('Parsed data for %s candidate sources...\n' % len(cands))

# Calculate the separation matrix; track the closest candidate to each CR.
sepn = {}
Expand Down
13 changes: 1 addition & 12 deletions examples/animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@
# times for March 1993 'storm of the century'
date1 = datetime.datetime(1993,3,10,0)
date2 = datetime.datetime(1993,3,17,0)
print date1, date2

# set OpenDAP server URL.
URL="http://nomad2.ncep.noaa.gov:9090/dods/reanalyses/reanalysis-2/6hr/pgb/pgb"
print URL
try:
data = NetCDFFile(URL)
except:
raise IOError, 'opendap server not providing the requested data'
raise IOError('opendap server not providing the requested data')

# read lats,lons,times.
print data.variables.keys()
latitudes = data.variables['lat'][:]
longitudes = data.variables['lon'][:].tolist()
times = data.variables['time']
ntime1 = date2index(date1,times,calendar='standard')
ntime2 = date2index(date2,times,calendar='standard')
print 'ntime1,ntime2:',ntime1,ntime2
print num2date(times[ntime1],times.units,calendar='standard'), num2date(times[ntime2],times.units,calendar='standard')
# get sea level pressure and 10-m wind data.
slpdata = data.variables['presmsl']
udata = data.variables['ugrdprs']
Expand All @@ -50,12 +45,6 @@
longitudes.append(360.); longitudes = np.array(longitudes)
# make 2-d grid of lons, lats
lons, lats = np.meshgrid(longitudes,latitudes)
print 'min/max slp,u,v'
print slp.min(), slp.max()
print uin.min(), uin.max()
print vin.min(), vin.max()
print 'dates'
print dates
# make orthographic basemap.
m = Basemap(resolution='c',projection='ortho',lat_0=60.,lon_0=-60.)
uin = udata[ntime1:ntime2+1,0,:,:]
Expand Down
11 changes: 6 additions & 5 deletions examples/contour_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mpl_toolkits.basemap import Basemap, shiftgrid
import numpy as np
import matplotlib.pyplot as plt
import sys

# examples of filled contour plots on map projections.

Expand Down Expand Up @@ -34,7 +35,7 @@
meridians = np.arange(-360.,360.,30.)
m.drawmeridians(meridians)
plt.title('Sinusoidal Filled Contour Demo')
print 'plotting with sinusoidal basemap ...'
sys.stdout.write('plotting with sinusoidal basemap ...\n')

# create new figure
fig=plt.figure()
Expand All @@ -56,7 +57,7 @@
meridians = np.arange(-360.,360.,30.)
m.drawmeridians(meridians)
plt.title('Mollweide Filled Contour Demo')
print 'plotting with mollweide basemap ...'
sys.stdout.write('plotting with mollweide basemap ...\n')

# create new figure
fig=plt.figure()
Expand All @@ -78,7 +79,7 @@
meridians = np.arange(-360.,360.,60.)
m.drawmeridians(meridians,labels=[0,0,0,1])
plt.title('Robinson Filled Contour Demo')
print 'plotting with robinson basemap ...'
sys.stdout.write('plotting with robinson basemap ...\n')

# create new figure
fig=plt.figure()
Expand All @@ -100,7 +101,7 @@
meridians = np.arange(10.,360.,20.)
m.drawmeridians(meridians,labels=[1,1,1,1])
plt.title('Azimuthal Equidistant Filled Contour Demo',y=1.075)
print 'plotting with azimuthal equidistant basemap ...'
sys.stdout.write('plotting with azimuthal equidistant basemap ...\n')

# create new figure
fig=plt.figure()
Expand All @@ -123,5 +124,5 @@
meridians = np.arange(0.,360.,20.)
m.drawmeridians(meridians)
plt.title('Orthographic Filled Contour Demo')
print 'plotting with orthographic basemap ..'
sys.stdout.write('plotting with orthographic basemap ..\n')
plt.show()
12 changes: 7 additions & 5 deletions examples/fcstmaps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function
from __future__ import unicode_literals
# this example reads today's numerical weather forecasts
# from the NOAA OpenDAP servers and makes a multi-panel plot.
import numpy as np
Expand Down Expand Up @@ -29,12 +31,12 @@
msg = """
opendap server not providing the requested data.
Try another date by providing YYYYMMDD on command line."""
raise IOError, msg
raise IOError(msg)


# read lats,lons,times.

print data.variables.keys()
print(data.variables.keys())
latitudes = data.variables['lat']
longitudes = data.variables['lon']
fcsttimes = data.variables['time']
Expand All @@ -49,8 +51,8 @@
for fdate in fdates:
fdiff = fdate-fdates[0]
fcsthrs.append(fdiff.days*24. + fdiff.seconds/3600.)
print fcsthrs
print verifdates
print(fcsthrs)
print(verifdates)
lats = latitudes[:]
nlats = len(lats)
lons1 = longitudes[:]
Expand Down Expand Up @@ -85,7 +87,7 @@
plt.title('%d-h forecast valid '%fcsthr+verifdates[nt],fontsize=9)
# figure title
plt.figtext(0.5,0.95,
u"2-m temp (\N{DEGREE SIGN}C) forecasts from %s"%verifdates[0],
"2-m temp (\N{DEGREE SIGN}C) forecasts from %s"%verifdates[0],
horizontalalignment='center',fontsize=14)
# a single colorbar.
cax = plt.axes([0.1, 0.05, 0.8, 0.025])
Expand Down
11 changes: 6 additions & 5 deletions examples/fcstmaps_axesgrid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# this example reads today's numerical weather forecasts
# from the NOAA OpenDAP servers and makes a multi-panel plot.
# This version demonstrates the use of the AxesGrid toolkit.
Expand Down Expand Up @@ -31,12 +32,12 @@
msg = """
opendap server not providing the requested data.
Try another date by providing YYYYMMDD on command line."""
raise IOError, msg
raise IOError(msg)


# read lats,lons,times.

print data.variables.keys()
print(data.variables.keys())
latitudes = data.variables['lat']
longitudes = data.variables['lon']
fcsttimes = data.variables['time']
Expand All @@ -51,8 +52,8 @@
for fdate in fdates:
fdiff = fdate-fdates[0]
fcsthrs.append(fdiff.days*24. + fdiff.seconds/3600.)
print fcsthrs
print verifdates
print(fcsthrs)
print(verifdates)
lats = latitudes[:]
nlats = len(lats)
lons1 = longitudes[:]
Expand Down Expand Up @@ -99,7 +100,7 @@
ax.set_title('%d-h forecast valid '%fcsthr+verifdates[nt],fontsize=9)
# figure title
plt.figtext(0.5,0.95,
u"2-m temp (\N{DEGREE SIGN}C) forecasts from %s"%verifdates[0],
"2-m temp (\N{DEGREE SIGN}C) forecasts from %s"%verifdates[0],
horizontalalignment='center',fontsize=14)
# a single colorbar.
cbar = fig.colorbar(cs, cax=grid.cbar_axes[0], orientation='horizontal')
Expand Down
5 changes: 3 additions & 2 deletions examples/fillstates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap as Basemap
Expand Down Expand Up @@ -64,13 +65,13 @@
'Montana': 2.39,
'Wyoming': 1.96,
'Alaska': 0.42}
print shp_info
print(shp_info)
# choose a color for each state based on population density.
colors={}
statenames=[]
cmap = plt.cm.hot # use 'hot' colormap
vmin = 0; vmax = 450 # set range.
print m.states_info[0].keys()
print(m.states_info[0].keys())
for shapedict in m.states_info:
statename = shapedict['NAME']
# skip DC and Puerto Rico.
Expand Down
13 changes: 10 additions & 3 deletions examples/garp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
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
Expand All @@ -12,9 +19,9 @@
# 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(raw_input('input reference lon (degrees):'))
lat_0 = float(raw_input('input reference lat (degrees):'))
location = raw_input('name of location:')
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.
Expand Down
9 changes: 8 additions & 1 deletion examples/geos_demo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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)

# create Basemap instance for Geostationary (satellite view) projection.
lon_0 = float(raw_input('enter reference longitude (lon_0):'))
lon_0 = float(get_input('enter reference longitude (lon_0):'))

# map with land/sea mask plotted
fig=plt.figure()
Expand Down
15 changes: 8 additions & 7 deletions examples/hires.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import print_function
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
import cPickle, time
import pickle, time

# create figure with aqua background (will be oceans)
fig = plt.figure()
Expand All @@ -15,16 +16,16 @@
# make sure countries and rivers are loaded
m.drawcountries()
m.drawrivers()
print time.clock()-t1,' secs to create original Basemap instance'
print(time.clock()-t1,' secs to create original Basemap instance')

# cPickle the class instance.
cPickle.dump(m,open('map.pickle','wb'),-1)
# pickle the class instance.
pickle.dump(m,open('map.pickle','wb'),-1)

# clear the figure
plt.clf()
# read cPickle back in and plot it again (should be much faster).
# read pickle back in and plot it again (should be much faster).
t1 = time.clock()
m2 = cPickle.load(open('map.pickle','rb'))
m2 = pickle.load(open('map.pickle','rb'))
# draw coastlines and fill continents.
m.drawcoastlines()
# fill continents and lakes
Expand All @@ -36,7 +37,7 @@
m.drawmapboundary(fill_color='aqua')
# draw major rivers.
m.drawrivers(color='b')
print time.clock()-t1,' secs to plot using using a pickled Basemap instance'
print(time.clock()-t1,' secs to plot using using a pickled Basemap instance')
# draw parallels
circles = np.arange(48,65,2).tolist()
m.drawparallels(circles,labels=[1,1,0,0])
Expand Down
7 changes: 4 additions & 3 deletions examples/hurrtracks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
"""
draw Atlantic Hurricane Tracks for storms that reached Cat 4 or 5.
part of the track for which storm is cat 4 or 5 is shown red.
Expand All @@ -14,7 +15,7 @@
fig=plt.figure()
# read shapefile.
shp_info = m.readshapefile('huralll020','hurrtracks',drawbounds=False)
print shp_info
print(shp_info)
# find names of storms that reached Cat 4.
names = []
for shapedict in m.hurrtracks_info:
Expand All @@ -23,8 +24,8 @@
if cat in ['H4','H5'] and name not in names:
# only use named storms.
if name != 'NOT NAMED': names.append(name)
print names
print len(names)
print(names)
print(len(names))
# plot tracks of those storms.
for shapedict,shape in zip(m.hurrtracks_info,m.hurrtracks):
name = shapedict['NAME']
Expand Down
13 changes: 10 additions & 3 deletions examples/nsper_demo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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)

# create Basemap instance for Near-Sided Perspective (satellite view) projection.
lon_0 = float(raw_input('enter reference longitude (lon_0):'))
lat_0 = float(raw_input('enter reference latitude (lat_0):'))
h = float(raw_input('enter altitude of camera in km (h):'))
lon_0 = float(get_input('enter reference longitude (lon_0):'))
lat_0 = float(get_input('enter reference latitude (lat_0):'))
h = float(get_input('enter altitude of camera in km (h):'))
h=h*1000.

# map with continents drawn and filled.
Expand Down
Loading