-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_realtime.py
64 lines (52 loc) · 2.19 KB
/
get_realtime.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
from subprocess import call
import numpy as np
from datetime import datetime, timedelta
from netCDF4 import Dataset, num2date
import glob
import sys
"""
get_realtime.py
Author: Greg Blumberg (OU/CIMMS/SoM)
Email: [email protected]
This script downloads the needed upper air data and put it
into the needed CSV files produce the colorized SPC UA plots.
The data comes from the unidata2.new.ssec.wisc.edu link and
is downloaded by WGET. You'll need WGET to run this script.
Inputs:
1.) YYYYMMDD (i.e. 20150217)
2.) HR (i.e. 12 or 00)
"""
yyyymmdd = sys.argv[1]
hr = sys.argv[2]
link = 'http://unidata2-new.ssec.wisc.edu/decoded/netcdf/upperair/Upperair_%Y%m%d_0000.nc'
link = link.replace('%Y%m%d', yyyymmdd)
call(['wget', link])
units = 'seconds since 1970-01-01 00:00:00+00:00'
now_dataset = Dataset(link.split('/')[-1])
now_dts = num2date(now_dataset.variables['synTime'][:], units)
print now_dataset.variables.keys()
now_stations = []
for s in now_dataset.variables['staName'][:]:
now_stations.append(''.join(s))
dt = datetime.strptime(yyyymmdd+hr, '%Y%m%d%H')
idx = np.where(now_dts == dt)[0]
lat = now_dataset.variables['staLat'][idx]
lon = now_dataset.variables['staLon'][idx]
alt = now_dataset.variables['staElev'][idx]
wmoID = now_dataset.variables['wmoStaNum'][idx]
presMand = now_dataset.variables['prMan'][idx,:]
tmpcMand = now_dataset.variables['tpMan'][idx,:] - 273.15
dwpcMand = -1. * (now_dataset.variables['tdMan'][idx,:] - tmpcMand)
hghtMand = now_dataset.variables['htMan'][idx,:]
wspdMand = now_dataset.variables['wsMan'][idx,:] * 1.94384
wdirMand = now_dataset.variables['wdMan'][idx,:]
now_stations = np.asarray(now_stations)[idx]
now_stations = np.where(now_stations == '', '--', now_stations)
out = open(yyyymmdd+hr + '.csv', 'w')
for i, sta in enumerate(zip(now_stations, wmoID)):
for l in xrange(len(presMand[i])):
if type(presMand[i,l]) != np.ma.core.MaskedConstant:
line = ','.join([str(sta[1]), str(sta[0]),str(lat[i]),str(lon[i]),str(alt[i]), str(presMand[i,l]), str(tmpcMand[i,l]), str(dwpcMand[i,l]), str(hghtMand[i,l]), str(wspdMand[i,l]), str(wdirMand[i,l])])
print line
out.write(line + '\n')
out.close()