#!/usr/bin/python #Import Math import math as m #February 11th

advertisement
#!/usr/bin/python
#Import Math
import math as m
#February 11th 2014 09Z
serf = '/chinook/meteo/jwa5183/meteo473/milestone4/sref2014021109/p01.t09z.pgrb212.nc'
import netCDF4 as nc
ncfile = nc.Dataset(serf)
#Define Variables
lat = ncfile.variables['latitude'][:]
xlong = ncfile.variables['longitude'][:]
#User Input Varialbes
uselat=input("Enter Latitude in degrees N: ")
uselong=input("Enter Longitude in degrees E: ")
#Define The Great Circle
def g_cir_dis(lat,lon,clat,clon):
return
m.acos(m.sin((m.pi/180.)*(lat))*m.sin((m.pi/180.)*clat)+m.cos((m.pi/180.)*(lat))*m.cos((m.pi/180.)*c
lat)*m.cos((m.pi/180.)*(lon)-(m.pi/180.)*clon))*6371.
#Varialbes for Location Loop
j=0
i=0
k=0
l=0
mind = 9999999
shape = lat.shape
#Location Loop
while j < shape[0]:
while i < shape[1]:
cdistance = g_cir_dis(lat[j,i],xlong[j,i],uselat,uselong)
if cdistance < mind:
mind = cdistance
k=j
l=i
i = i +1
i=0
j=j+1
#Loop to Bring In The Other Files
ens = 01
prob = 0
while ens <= 21:
#Import File
serf =
'/chinook/meteo/jwa5183/meteo473/milestone4/sref2014021109/p%02d.t09z.pgrb212.nc' %(ens)
import netCDF4 as nc
ncfile = nc.Dataset(serf)
#Define Variables
lat = ncfile.variables['latitude'][:]
xlong = ncfile.variables['longitude'][:]
temp = ncfile.variables['TMP_2maboveground'][:]
tmp850 = ncfile.variables['TMP_850mb'][:]
hgt1000 = ncfile.variables['HGT_1000mb'][:]
hgt850 = ncfile.variables ['HGT_850mb'][:]
hgt700 = ncfile.variables ['HGT_700mb'][:]
Precp = ncfile.variables['APCP_surface'][:]
#Precipitation Converted to Inches
precpin = (Precp/1000)*39.3701
#Time and If Statemant Variables
time = 11 # 33 Hours out from the Initialization of The Model
fz = 0
t1 = time - 1
t2 = time - 2
t3 = time - 3
#Variables for Thicknesses
thick_1000_850 = hgt850-hgt1000
thick_850_700 = hgt700 - hgt850
#If Statements for Determining if There is Freezing Rain
if thick_1000_850[time,k,l] >= 1275 and thick_1000_850[time,k,l] <= 1315:
if thick_850_700[time,k,l] >= 1550 and thick_850_700[time,k,l] <= 1580:
if tmp850[time,k,l] > 273.15:
if temp[time,k,l] <= 273.15:
fz = fz + 1
#If Statements for Determining Total Freezing Rain Accumulation and if There Will Be Power Outages
if fz == 1:
total = precpin[t1,k,l] + precpin[t2,k,l] + precpin[t3,k,l] + precpin[time,k,l]
if total >= .25:
prob = prob +1
ens = ens + 1
code = (prob/21.0)*100
print 'The probability that there will be more than 0.25 inches of\nfreezing rain is %2.0f percent.' %
(code)
if code >= 75:
print 'High risk of power outages.'
elif code >= 50 and code < 75:
print 'Medium risk of power outages.'
elif code >= 25 and code < 50:
print 'Low risk of power outages'
else:
print 'Power outages unlikely.'
Download