Skip to content

Commit d5d8921

Browse files
committed
Fix some examples with fixes from docs
1 parent 23903e7 commit d5d8921

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

examples/hurrtracks.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
from __future__ import (absolute_import, division, print_function)
2-
31
"""
42
draw Atlantic Hurricane Tracks for storms that reached Cat 4 or 5.
53
part of the track for which storm is cat 4 or 5 is shown red.
64
ESRI shapefile data from http://nationalatlas.gov/mld/huralll.html
75
"""
6+
import os
87
import numpy as np
98
import matplotlib.pyplot as plt
10-
from mpl_toolkits.basemap import Basemap as Basemap
11-
# Lambert Conformal Conic maplt.
9+
from mpl_toolkits.basemap import Basemap
10+
# Lambert Conformal Conic map.
1211
m = Basemap(llcrnrlon=-100.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57.,
1312
projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60.,
1413
resolution ='l',area_thresh=1000.)
1514
# create figure.
1615
fig=plt.figure()
1716
# read shapefile.
1817
shp_info = m.readshapefile('huralll020','hurrtracks',drawbounds=False)
19-
print(shp_info)
2018
# find names of storms that reached Cat 4.
2119
names = []
2220
for shapedict in m.hurrtracks_info:
@@ -25,8 +23,6 @@
2523
if cat in ['H4','H5'] and name not in names:
2624
# only use named storms.
2725
if name != 'NOT NAMED': names.append(name)
28-
print(names)
29-
print(len(names))
3026
# plot tracks of those storms.
3127
for shapedict,shape in zip(m.hurrtracks_info,m.hurrtracks):
3228
name = shapedict['NAME']

examples/plothighsandlows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def main():
2727
"""Main function."""
2828

2929
# Plot 00 UTC today.
30-
url = "http://nomads.ncep.noaa.gov/dods/gfs_0p25/gfs%Y%m%d/gfs_0p25_00z"
30+
url = "http://nomads.ncep.noaa.gov/dods/gfs_0p50/gfs%Y%m%d/gfs_0p50_00z"
3131
date = dt.datetime.now()
3232

3333
# Open OPeNDAP dataset.

examples/plotsst.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
from __future__ import (absolute_import, division, print_function)
2-
31
from mpl_toolkits.basemap import Basemap
42
from netCDF4 import Dataset, date2index
53
import numpy as np
64
import matplotlib.pyplot as plt
75
from datetime import datetime
6+
try:
7+
from urllib.request import urlretrieve
8+
except ImportError:
9+
from urllib import urlretrieve
810
date = datetime(2007,12,15,0) # date to plot.
911
# open dataset.
10-
dataset = \
11-
Dataset('http://www.ncdc.noaa.gov/thredds/dodsC/OISST-V2-AVHRR_agg')
12+
sstpath, sstheader = urlretrieve("https://downloads.psl.noaa.gov/Datasets/noaa.oisst.v2.highres/sst.day.mean.{0}.nc".format(date.year))
13+
dataset = Dataset(sstpath)
1214
timevar = dataset.variables['time']
1315
timeindex = date2index(date,timevar) # find time index for desired date.
1416
# read sst. Will automatically create a masked array using
1517
# missing_value variable attribute. 'squeeze out' singleton dimensions.
1618
sst = dataset.variables['sst'][timeindex,:].squeeze()
1719
# read ice.
18-
ice = dataset.variables['ice'][timeindex,:].squeeze()
20+
dataset.close()
21+
icepath, iceheader = urlretrieve("https://downloads.psl.noaa.gov/Datasets/noaa.oisst.v2.highres/icec.day.mean.{0}.nc".format(date.year))
22+
dataset = Dataset(icepath)
23+
ice = dataset.variables['icec'][timeindex,:].squeeze()
1924
# read lats and lons (representing centers of grid boxes).
2025
lats = dataset.variables['lat'][:]
2126
lons = dataset.variables['lon'][:]
27+
dataset.close()
28+
latstep, lonstep = np.diff(lats[:2]), np.diff(lons[:2])
29+
lats = np.append(lats - 0.5 * latstep, lats[-1] + 0.5 * latstep)
30+
lons = np.append(lons - 0.5 * lonstep, lons[-1] + 0.5 * lonstep)
2231
lons, lats = np.meshgrid(lons,lats)
2332
# create figure, axes instances.
2433
fig = plt.figure()

0 commit comments

Comments
 (0)