Skip to content

Commit 53eb5bd

Browse files
author
Jeffrey Whitaker
committed
fix example.
1 parent d324703 commit 53eb5bd

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

doc/users/figures/plotsst.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22
from netCDF4 import Dataset, date2index, num2date
33
import numpy as np
44
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))
1410
# 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()
1713
# read ice.
18-
ice = dataset.variables['ice'][nt]
14+
ice = dataset.variables['ice'][:].squeeze()
1915
# read lats and lons (representing centers of grid boxes).
2016
lats = dataset.variables['lat'][:]
2117
lons = dataset.variables['lon'][:]
@@ -28,7 +24,7 @@
2824
lats = (lats - 0.5*delat).tolist()
2925
lats.append(lats[-1]+delat)
3026
lats = np.array(lats,np.float64)
31-
# creat figure, axes instances.
27+
# create figure, axes instances.
3228
fig = plt.figure()
3329
ax = fig.add_axes([0.05,0.05,0.9,0.9])
3430
# create Basemap instance for Robinson projection.
@@ -51,4 +47,4 @@
5147
cb = m.colorbar(im1,"bottom", size="5%", pad="2%")
5248
# add a title.
5349
ax.set_title('SST and ICE analysis for %s'%date)
54-
plt.savefig('plotsst.png')
50+
plt.show()

0 commit comments

Comments
 (0)