-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnowcastROFTS_NWWIII.py
94 lines (76 loc) · 2.76 KB
/
nowcastROFTS_NWWIII.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
import netCDF4
import datetime as dt
import time
def fixForLenght(item):
if len(item) == 2:
pass
else:
item = '0' + item
return item
def getDate():
currentTime = dt.datetime.now()
year = str(currentTime.year)
month = fixForLenght(str(currentTime.month))
day = fixForLenght(str(currentTime.day))
return year + month + day
def plotData(data, lat, lon, title="Plot Of The World"):
plt.figure()
m=Basemap(projection='mill',lat_ts=10,llcrnrlon=lon.min(), urcrnrlon=lon.max(),llcrnrlat=lat.min(),urcrnrlat=lat.max(), resolution='c')
x, y = m(*np.meshgrid(lon,lat))
m.pcolormesh(x,y,data,shading='flat',cmap=plt.cm.jet)
m.colorbar(location='right')
m.drawcoastlines()
m.fillcontinents()
m.drawmapboundary()
m.drawparallels(np.arange(-90.,120.,30.),labels=[1,0,0,0])
m.drawmeridians(np.arange(-180.,180.,60.),labels=[0,0,0,1])
plt.title(title)
plt.show()
def saveFile(inputFile, fileName):
outputFile = netCDF4.Dataset(fileName, mode="w", format="NETCDF3_CLASSIC")
#Copy dimensions
for dname, the_dim in inputFile.dimensions.items():
print(dname, len(the_dim))
outputFile.createDimension(dname, len(the_dim))
#Copy variables
for v_name, varin in inputFile.variables.items():
outVar = outputFile.createVariable(v_name, varin.datatype, varin.dimensions)
print(varin.datatype)
outVar[:] = varin[:]
outputFile.close()
def main():
#mydate = '20150422'
mydate = time.strftime("%Y%m%d")
mydate = getDate()
# NWWIII
url='http://nomads.ncep.noaa.gov:9090/dods/wave/nww3/nww3'+mydate+'/nww3'+mydate+'_00z'
# Extract the significant wave height of combined wind waves and swell
print("Start on NWWIII")
file = netCDF4.Dataset(url)
# saveFile(file, "NWWIII_TEST.nc")
print("Got data from NWWIII")
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
data = file.variables['htsgwsfc'][1,:,:]
file.close()
title = mydate + ': NWW3 Significant Wave Height from NOMADS'
plotData(data, lat, lon, title)
# ROFTS
url='http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global'+mydate+ '/rtofs_glo_3dz_nowcast_daily_temp'
print("Starting on ROFTS")
file = netCDF4.Dataset(url)
# saveFile(file, "ROFTS_TEST.nc")
print("Got data from ROFTS")
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
data = file.variables['temperature'][1,1,:,:]
file.close()
print("Starting on plotting ROFTS")
title = mydate + ': Global RTOFS SST from NOMADS'
plotData(data, lat, lon, title)
if __name__ == '__main__':
main()