Skip to content

Commit f988c1a

Browse files
committed
Fix URLs in examples using broken addcyclic
1 parent 41cfd4f commit f988c1a

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

examples/fcstmaps.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@
33
from __future__ import unicode_literals
44
# this example reads today's numerical weather forecasts
55
# from the NOAA OpenDAP servers and makes a multi-panel plot.
6+
import datetime as dt
67
import numpy as np
78
import matplotlib.pyplot as plt
89
import sys
910
import numpy.ma as ma
10-
import datetime
1111
from mpl_toolkits.basemap import Basemap, addcyclic
1212
from netCDF4 import Dataset as NetCDFFile, num2date
1313

1414

1515
# today's date is default.
1616
if len(sys.argv) > 1:
17-
YYYYMMDD = sys.argv[1]
17+
date = dt.datetime.strptime(sys.argv[1], "%Y%m%d")
1818
else:
19-
YYYYMMDD = datetime.datetime.today().strftime('%Y%m%d')
19+
date = dt.datetime.today()
2020

2121
# set OpenDAP server URL.
2222
try:
23-
URLbase="http://nomads.ncep.noaa.gov:9090/dods/gfs/gfs"
24-
URL=URLbase+YYYYMMDD+'/gfs_00z'
25-
print(URL)
26-
data = NetCDFFile(URL)
23+
urlbase = "http://nomads.ncep.noaa.gov/dods/gfs_0p25/gfs%Y%m%d/gfs_0p25_00z"
24+
data = NetCDFFile(date.strftime(urlbase))
2725
except:
2826
msg = """
2927
opendap server not providing the requested data.

examples/fcstmaps_axesgrid.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,32 @@
44
# this example reads today's numerical weather forecasts
55
# from the NOAA OpenDAP servers and makes a multi-panel plot.
66
# This version demonstrates the use of the AxesGrid toolkit.
7+
import datetime as dt
78
import numpy as np
89
import matplotlib.pyplot as plt
910
import sys
1011
import numpy.ma as ma
11-
import datetime
1212
from mpl_toolkits.basemap import Basemap, addcyclic
1313
from mpl_toolkits.axes_grid1 import AxesGrid
1414
from netCDF4 import Dataset as NetCDFFile, num2date
1515

1616

1717
# today's date is default.
1818
if len(sys.argv) > 1:
19-
YYYYMMDD = sys.argv[1]
19+
date = dt.datetime.strptime(sys.argv[1], "%Y%m%d")
2020
else:
21-
YYYYMMDD = datetime.datetime.today().strftime('%Y%m%d')
21+
date = dt.datetime.today()
2222

2323
# set OpenDAP server URL.
2424
try:
25-
URLbase="http://nomads.ncep.noaa.gov:9090/dods/gfs/gfs"
26-
URL=URLbase+YYYYMMDD+'/gfs_00z'
27-
print(URL)
28-
data = NetCDFFile(URL)
25+
urlbase = "http://nomads.ncep.noaa.gov/dods/gfs_0p25/gfs%Y%m%d/gfs_0p25_00z"
26+
data = NetCDFFile(date.strftime(urlbase))
2927
except:
3028
msg = """
3129
opendap server not providing the requested data.
3230
Try another date by providing YYYYMMDD on command line."""
3331
raise IOError(msg)
3432

35-
3633
# read lats,lons,times.
3734

3835
print(data.variables.keys())

examples/plothighsandlows.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
plot H's and L's on a sea-level pressure map
55
(uses scipy.ndimage.filters and netcdf4-python)
66
"""
7+
import datetime as dt
78
import numpy as np
89
import matplotlib.pyplot as plt
9-
from datetime import datetime
1010
from mpl_toolkits.basemap import Basemap, addcyclic
1111
from scipy.ndimage.filters import minimum_filter, maximum_filter
1212
from netCDF4 import Dataset
@@ -22,15 +22,11 @@ def extrema(mat,mode='wrap',window=10):
2222
return np.nonzero(mat == mn), np.nonzero(mat == mx)
2323

2424
# plot 00 UTC today.
25-
date = datetime.now().strftime('%Y%m%d')+'00'
25+
urlbase = "http://nomads.ncep.noaa.gov/dods/gfs_0p25/gfs%Y%m%d/gfs_0p25_00z"
26+
date = dt.datetime.now()
2627

2728
# open OpenDAP dataset.
28-
#data=Dataset("http://nomads.ncep.noaa.gov:9090/dods/gfs/gfs/%s/gfs_%sz_anl" %\
29-
# (date[0:8],date[8:10]))
30-
data=Dataset("http://nomads.ncep.noaa.gov:9090/dods/gfs_hd/gfs_hd%s/gfs_hd_%sz"%\
31-
(date[0:8],date[8:10]))
32-
33-
29+
data = Dataset(date.strftime(urlbase))
3430

3531
# read lats,lons.
3632
lats = data.variables['lat'][:]

0 commit comments

Comments
 (0)