From: <js...@us...> - 2009-01-26 19:48:53
|
Revision: 6831 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6831&view=rev Author: jswhit Date: 2009-01-26 19:48:47 +0000 (Mon, 26 Jan 2009) Log Message: ----------- update URL, use new date2index function. Modified Paths: -------------- trunk/toolkits/basemap/examples/plotsst.py Modified: trunk/toolkits/basemap/examples/plotsst.py =================================================================== --- trunk/toolkits/basemap/examples/plotsst.py 2009-01-26 19:48:04 UTC (rev 6830) +++ trunk/toolkits/basemap/examples/plotsst.py 2009-01-26 19:48:47 UTC (rev 6831) @@ -1,26 +1,30 @@ -from mpl_toolkits.basemap import Basemap, NetCDFFile +from mpl_toolkits.basemap import Basemap, NetCDFFile, date2index, num2date import numpy as np import matplotlib.pyplot as plt -import sys +import sys, datetime # read in sea-surface temperature and ice data # can be a local file, a URL for a remote opendap dataset, -# or (if PyNIO is installed) a GRIB or HDF file. if len(sys.argv) == 1: date = '20071215' else: date = sys.argv[1] -if date[0:4] > '2005': - ncfile = NetCDFFile('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst/'+date[0:4]+'/AVHRR/sst4-navy-eot.'+date+'.nc') -else: - ncfile = NetCDFFile('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst/'+date[0:4]+'/AVHRR/sst4-path-eot.'+date+'.nc') +# convert datestring to datetime object. +date = datetime.datetime(int(date[0:4]),int(date[4:6]),int(date[6:8])) +print date +# open dataset. +dataset = NetCDFFile('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst/totalAagg') +# find index of desired time. +time = dataset.variables['time'] +nt = date2index(date, time) +print num2date(time[nt],time.units) # read sst. Will automatically create a masked array using # missing_value variable attribute. -sst = ncfile.variables['sst'][:] +sst = dataset.variables['sst'][nt] # read ice. -ice = ncfile.variables['ice'][:] +ice = dataset.variables['ice'][nt] # read lats and lons (representing centers of grid boxes). -lats = ncfile.variables['lat'][:] -lons = ncfile.variables['lon'][:] +lats = dataset.variables['lat'][:] +lons = dataset.variables['lon'][:] # shift lats, lons so values represent edges of grid boxes # (as pcolor expects). delon = lons[1]-lons[0] @@ -34,7 +38,6 @@ # create Basemap instance for mollweide projection. # coastlines not used, so resolution set to None to skip # continent processing (this speeds things up a bit) -#m = Basemap(projection='ortho',lon_0=-110,lat_0=20,resolution=None) m = Basemap(projection='moll',lon_0=lons.mean(),lat_0=0,resolution=None) # compute map projection coordinates of grid. x, y = m(*np.meshgrid(lons, lats)) @@ -42,7 +45,7 @@ # color background of map projection region. # missing values over land will show up this color. m.drawmapboundary(fill_color='0.3') -# plot ice, then with pcolor +# plot sst, then ice with pcolor im1 = m.pcolor(x,y,sst,shading='flat',cmap=plt.cm.jet) im2 = m.pcolor(x,y,ice,shading='flat',cmap=plt.cm.gist_gray) # draw parallels and meridians, but don't bother labelling them. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |