|
2 | 2 | from netCDF4 import Dataset, date2index, num2date |
3 | 3 | import numpy as np |
4 | 4 | import matplotlib.pyplot as plt |
5 | | -import datetime |
6 | | -# create datetime object for desired time |
7 | | -date = datetime.datetime(2007,12,15,0) |
8 | | -# open dataset. |
9 | | -dataset =\ |
10 | | -Dataset('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst2/totalAmsrAgg') |
11 | | -# find index of desired time. |
12 | | -time = dataset.variables['time'] |
13 | | -nt = date2index(date, time, calendar='standard') |
| 5 | +date = '20071215' # date to plot. |
| 6 | +# open dataset for that date. |
| 7 | +dataset = \ |
| 8 | +Dataset('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst2/%s/AVHRR-AMSR/amsr-avhrr-v2.%s.nc'%\ |
| 9 | + (date[0:4],date)) |
14 | 10 | # read sst. Will automatically create a masked array using |
15 | | -# missing_value variable attribute. |
16 | | -sst = dataset.variables['sst'][nt] |
| 11 | +# missing_value variable attribute. 'squeeze out' singleton dimensions. |
| 12 | +sst = dataset.variables['sst'][:].squeeze() |
17 | 13 | # read ice. |
18 | | -ice = dataset.variables['ice'][nt] |
| 14 | +ice = dataset.variables['ice'][:].squeeze() |
19 | 15 | # read lats and lons (representing centers of grid boxes). |
20 | 16 | lats = dataset.variables['lat'][:] |
21 | 17 | lons = dataset.variables['lon'][:] |
|
28 | 24 | lats = (lats - 0.5*delat).tolist() |
29 | 25 | lats.append(lats[-1]+delat) |
30 | 26 | lats = np.array(lats,np.float64) |
31 | | -# creat figure, axes instances. |
| 27 | +# create figure, axes instances. |
32 | 28 | fig = plt.figure() |
33 | 29 | ax = fig.add_axes([0.05,0.05,0.9,0.9]) |
34 | 30 | # create Basemap instance for Robinson projection. |
|
51 | 47 | cb = m.colorbar(im1,"bottom", size="5%", pad="2%") |
52 | 48 | # add a title. |
53 | 49 | ax.set_title('SST and ICE analysis for %s'%date) |
54 | | -plt.savefig('plotsst.png') |
| 50 | +plt.show() |
0 commit comments