File: plotargo.py

package info (click to toggle)
basemap 1.0.3%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 198,876 kB
  • sloc: ansic: 13,091; python: 10,301; sh: 1,961; makefile: 27
file content (28 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download
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
from netCDF4 import Dataset
import time, calendar, datetime, numpy
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
def datetomsecs(d):
    """convert from datetime to msecs since the unix epoch began"""
    return int(calendar.timegm(time.struct_time(d.timetuple()))*1000)
# set date range
date1 = datetime.datetime(2010,1,1,0)
date2 = datetime.datetime(2010,1,8,0)
t1 = datetomsecs(date1); t2 = datetomsecs(date2)
# build constraint expression to get locations of floats in specified time
# range.
urlbase='http://dapper.pmel.noaa.gov/dapper/argo/argo_all.cdp'
sel="?location.JULD,location.LATITUDE,location.LONGITUDE&location.JULD>%s&location.JULD<%s"%(t1,t2)
# retrieve data
dset = Dataset(urlbase+sel)
lats = dset.variables['location.LATITUDE'][:]
lons = dset.variables['location.LONGITUDE'][:]
# draw map with markers for float locations
m = Basemap(projection='hammer',lon_0=180)
x, y = m(lons,lats)
m.drawmapboundary(fill_color='#99ffff')
m.fillcontinents(color='#cc9966',lake_color='#99ffff')
m.scatter(x,y,3,marker='o',color='k')
plt.title('Locations of %s ARGO floats active between %s and %s' %\
        (len(lats),date1.strftime('%Y%m%d'),date2.strftime('%Y%m%d')))
plt.show()