|
1 |
| -from netCDF4 import Dataset |
| 1 | +from netCDF4 import Dataset, num2date |
2 | 2 | import time, calendar, datetime, numpy
|
3 | 3 | from mpl_toolkits.basemap import Basemap
|
4 | 4 | import matplotlib.pyplot as plt
|
5 |
| -def datetomsecs(d): |
6 |
| - """convert from datetime to msecs since the unix epoch began""" |
7 |
| - return int(calendar.timegm(time.struct_time(d.timetuple()))*1000) |
8 |
| -# set date range |
9 |
| -date1 = datetime.datetime(2010,1,1,0) |
10 |
| -date2 = datetime.datetime(2010,1,8,0) |
11 |
| -t1 = datetomsecs(date1); t2 = datetomsecs(date2) |
12 |
| -# build constraint expression to get locations of floats in specified time |
13 |
| -# range. |
14 |
| -urlbase='http://dapper.pmel.noaa.gov/dapper/argo/argo_all.cdp' |
15 |
| -sel="?location.JULD,location.LATITUDE,location.LONGITUDE&location.JULD>%s&location.JULD<%s"%(t1,t2) |
16 |
| -# retrieve data |
17 |
| -dset = Dataset(urlbase+sel) |
18 |
| -lats = dset.variables['location.LATITUDE'][:] |
19 |
| -lons = dset.variables['location.LONGITUDE'][:] |
| 5 | +# data downloaded from |
| 6 | +# http://coastwatch.pfeg.noaa.gov/erddap/tabledap/apdrcArgoAll.html via |
| 7 | +# http://coastwatch.pfeg.noaa.gov/erddap/tabledap/apdrcArgoAll.nc?longitude,latitude,time&longitude>=0&longitude<=360&latitude>=-90&latitude<=90&time>=2010-01-01&time<=2010-01-08&distinct() |
| 8 | +dset = Dataset('apdrcArgoAll_af28_ee2b_1d10.nc') |
| 9 | +lats = dset.variables['latitude'][:] |
| 10 | +lons = dset.variables['longitude'][:] |
| 11 | +time = dset.variables['time'] |
| 12 | +times = time[:] |
| 13 | +t1 = times.min(); t2 = times.max() |
| 14 | +date1 = num2date(t1, units=time.units) |
| 15 | +date2 = num2date(t2, units=time.units) |
20 | 16 | # draw map with markers for float locations
|
21 | 17 | m = Basemap(projection='hammer',lon_0=180)
|
22 | 18 | x, y = m(lons,lats)
|
23 | 19 | m.drawmapboundary(fill_color='#99ffff')
|
24 | 20 | m.fillcontinents(color='#cc9966',lake_color='#99ffff')
|
25 | 21 | m.scatter(x,y,3,marker='o',color='k')
|
26 | 22 | plt.title('Locations of %s ARGO floats active between %s and %s' %\
|
27 |
| - (len(lats),date1.strftime('%Y%m%d'),date2.strftime('%Y%m%d'))) |
| 23 | + (len(lats),date1,date2),fontsize=12) |
28 | 24 | plt.show()
|
0 commit comments