-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathestofs.py
168 lines (142 loc) · 6.3 KB
/
estofs.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
from netCDF4 import num2date
import numpy as np
import xarray as xr
from siphon.catalog import TDSCatalog
from datetime import datetime
import datetime as dt
from xarray.backends import NetCDF4DataStore
import cartopy
from mpl_toolkits.axes_grid1 import make_axes_locatable
from scipy.ndimage import gaussian_filter
import metpy.calc as mpcalc
import numpy.ma as ma
from metpy.units import units
import scipy.ndimage as ndimage
import matplotlib.patches as mpatches
from scipy.ndimage.filters import generic_filter as gf
q_levs = [0.01,0.05,0.1,0.25,0.5,0.75,1,1.25]
qarlevs = [0.01,0.05,0.1,0.25,0.5,0.75,1,1.25,1.5,1.75,2,2.5,3,3.5,4,4.5,5,6,7,8,9,10]
qaslevs = [0.01,0.05,0.1,0.25,0.5,0.75,1,1.25,1.5,1.75,2,2.5,3,3.5,4,4.5]
qazlevs = [0.01,0.05,0.1,0.25,0.5,0.75,1,1.25,1.5,1.75,2,2.5]
q_levs_r = [0.01,0.05,0.1,0.25,0.5,0.75,1,1.25,1.5,1.75,2,2.5,3]
qr_cols = ['#cfffbf','#a7ff8a','#85ff5c','#60ff2b','#40ff00','#ffff00','#e6e600','#cccc00','#e4cc00']
qs_cols = ['#b8ffff','#82ffff','#00ffff','#00cccc','#00adad','#007575','#0087f5','#0039f5','#1d00f5']
qi_cols = ['#eeccff','#dd99ff','#cc66ff','#bb33ff','#aa00ff','#8800cc','#660099','#440066','#6600cc']
qz_cols = ['#ff0066','#ff0080','#ff33cc','#ff00bf','#cc0099','#990073','#66004d','#b30000','#ff3333']
qra_cols = ['#cfffbf','#a7ff8a','#85ff5c','#60ff2b','#40ff00','#40ff00','#ffff00','#e6e600','#cccc00','#e4cc00','#ffcc00','#ff9500','#ff4800','#ff2900','#ff1200','#ff0000','#cc0000','#990000','#990033','#b3003b','#ff3333','#ff6666','#ffffff']
qrs_cols = ['#b8ffff','#82ffff','#00ffff','#00cccc','#00adad','#007575','#0087f5','#0039f5','#1d00f5','#4f01f6','#7a00f5','#9e00f5','#b833ff','#d280ff','#cc00f1','#ad00cc','#820099','#4700b3']
qzr_cols = ['#ff0066','#ff33cc','#ff00bf','#cc0099','#990073','#66004d','#b30000','#ff3333','#ff6666','#ff9999','#ffcccc']
qip_cols = ['#eeccff','#dd99ff','#cc66ff','#bb33ff','#aa00ff','#8800cc','#660099','#440066','#6600cc','#9933ff','#bf80ff','#e6ccff','#ffffff']
def wet_bulb(temp,dewpoint):
tdd = temp-dewpoint
wet_bulb = temp-((1/3)*tdd)
return wet_bulb
def fram(ice,wet_bulb,velocity):
ilr_p = ice
ilr_t = (-0.0071*(wet_bulb**3))-(0.039*(wet_bulb**2))-(0.3904*wet_bulb)+0.5545
ilr_v = (0.0014*(velocity**2))+(0.0027*velocity)+0.7574
cond_1 = np.ma.masked_where(wet_bulb>-0.35,ice)
cond_2 = np.ma.masked_where((wet_bulb<-0.35) & (velocity>12.),ice)
cond_3 = np.ma.masked_where((wet_bulb<-0.35) & (velocity<=12.),ice)
cond_1 = cond_1.filled(0)
cond_2 = cond_2.filled(0)
cond_3 = cond_3.filled(0)
ilr_1 = (0.7*ilr_p)+(0.29*ilr_t)+(0.01*ilr_v)
ilr_2 = (0.73*ilr_p)+(0.01*ilr_t)+(0.26*ilr_v)
ilr_3 = (0.79*ilr_p)+(0.2*ilr_t)+(0.01*ilr_v)
accretion_1 = cond_1*ilr_1
accretion_2 = cond_2*ilr_2
accretion_3 = cond_3*ilr_3
total_accretion=accretion_1+accretion_2+accretion_3
return total_accretion
def mkdir_p(mypath):
'''Creates a directory. equivalent to using mkdir -p on the command line'''
from errno import EEXIST
from os import makedirs,path
try:
makedirs(mypath)
except OSError as exc: # Python >2.5
if exc.errno == EEXIST and path.isdir(mypath):
pass
else: raise
startTime=datetime.now()
year = startTime.year
if startTime.month <10:
month = '0'+str(startTime.month)
else:
month = str(startTime.month)
if startTime.day <10:
day = '0'+str(startTime.day)
else:
day = str(startTime.day)
if startTime.hour <10:
hour = '0'+str(startTime.hour)
else:
hour = str(startTime.hour)
mdate = str(year)+str(month)+str(day)
def get_init_hr(hour):
if int(hour) <8:
init_hour = '00'
elif int(hour) <13:
init_hour = '06'
elif int(hour) <20:
init_hour = '12'
elif int(hour) <24:
init_hour = '18'
else:
init_hour = '00'
return(init_hour)
init_hour = get_init_hr(hour)
init_hr=init_hour
url='http://nomads.ncep.noaa.gov:80/dods/estofs/'+mdate+'/estofs_conus.east_'+init_hour+'z'
# Create new directory
output_dir = str(year)+str(month)+str(day)+'_'+str(init_hour)+'00'
mkdir_p(output_dir)
mkdir_p(output_dir+'/ESTOFS')
ds = xr.open_dataset(url)
times = ds['etsrgsfc'].metpy.time
init_time = ds['time'][0]
#total_precip=ds['apcpsfc'].squeeze()*.0393700787402
#lats = np.arange(25,50,0.25)
for i in range(0,180):
#fc_hr = init_hr+dt.timedelta(hours=1*i)
forecast_hour = times[0].values
data = ds.metpy.parse_cf()
data = data.isel(time=i)
#Rename variables to useful things
data = data.rename({
'etsrgsfc':'surge'
})
time = data['surge'].metpy.time
surge = data['surge'].squeeze()*3.28084
print(np.max(surge))
x, y = surge.metpy.coordinates('x', 'y')
dtfs = str(time.dt.strftime('%Y-%m-%d_%H%MZ').item())
print(dtfs)
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(111,projection=ccrs.PlateCarree())
ax.coastlines(resolution='10m')
ax.add_feature(cfeature.BORDERS.with_scale('10m'))
ax.add_feature(cfeature.STATES.with_scale('10m'))
try:
probc = ax.contourf(x,y,surge,levels=np.linspace(-5,10,30),cmap='BrBG',alpha=0.8)
cbar = fig.colorbar(probc, orientation='horizontal',aspect=80,ax=ax,pad=0.01,extendrect=False,ticks=range(-5,15,1))
except:
print('not enough surge :)')
ax.set_title('Extratropical Storm Surge (ft)',fontsize=14)
ax.set_title('Valid: '+time.dt.strftime('%a %b %d %H:%MZ').item(),fontsize=11,loc='right')
ax.set_title('ESTOFS Init: '+init_time.dt.strftime('%Y-%m-%d %H:%MZ').item(),fontsize=11,loc='left')
plt.savefig(output_dir+'/ESTOFS/us_surge_'+dtfs+'.png')
ax.set_extent((260, 295, 25, 50))#, crs = zH5_crs) # Set a title and show the plot
plt.savefig(output_dir+'/ESTOFS/ec_surge_'+dtfs+'.png')
ax.set_extent((281,295,39,49))#, crs = zH5_crs) # Set a title and show the plot
plt.savefig(output_dir+'/ESTOFS/ne_surge_'+dtfs+'.png')
ax.set_extent((289,291,43,45))#, crs = zH5_crs) # Set a title and show the plot
plt.savefig(output_dir+'/ESTOFS/me_surge_'+dtfs+'.png')
plt.close()
plt.clf()