-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_windprof_year.py
112 lines (93 loc) · 3.18 KB
/
check_windprof_year.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
'''
Raul Valenzuela
raul.valenzuela@colorado.edu
'''
import parse_data
import matplotlib.pyplot as plt
import numpy as np
import numpy.ma as ma
import matplotlib.gridspec as gsp
import matplotlib.dates as mdates
from rv_utilities import pandas2stack, add_colorbar
def plot_with_lines(year=None,target=None):
fig = plt.figure(figsize=(10,5))
gs = gsp.GridSpec(1, 2,
width_ratios=[2,1]
)
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
wprof = parse_data.windprof(year)
wp = np.squeeze(pandas2stack(wprof.dframe[target]))
wp_ma = ma.masked_where(np.isnan(wp),wp)
X,Y=wprof.time,wprof.hgt
ax1.pcolormesh(X,Y,wp_ma,vmin=0,vmax=360)
ax1.xaxis.set_major_locator(mdates.MonthLocator())
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%b\n%Y'))
ax1.set_xlabel(r'$ Time \rightarrow$')
ax1.set_ylabel('height gate')
for prof in range(wp.shape[1]):
x = wp[:,prof]
y = range(wp.shape[0])
ax2.plot(x,y,color='r',alpha=0.05)
# ax2.scatter(x,y,color='r',alpha=0.05)
ax2.set_yticklabels('')
ax2.set_xlabel(target)
ax1.set_title('BBY Windprof wdir')
plt.tight_layout()
plt.show(block=False)
def plot_with_hist(year=None,target=None,normalized=True,
pngsuffix=None):
name={'wdir':'Wind Direction',
'wspd':'Wind Speed'}
if target == 'wdir':
vmin,vmax = [0,360]
bins = np.arange(0,370,10)
hist_xticks = np.arange(0,400,40)
hist_xlim = [0,360]
elif target == 'wspd':
vmin,vmax = [0,30]
bins = np.arange(0,36,1)
hist_xticks = np.arange(0,40,5)
hist_xlim = [0,35]
fig = plt.figure(figsize=(20,5))
gs = gsp.GridSpec(1, 2,
width_ratios=[3,1]
)
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
wprof = parse_data.windprof(year)
wp = np.squeeze(pandas2stack(wprof.dframe[target]))
wp_ma = ma.masked_where(np.isnan(wp),wp)
X,Y = wprof.time,wprof.hgt
p = ax1.pcolormesh(X,Y,wp_ma,vmin=vmin,vmax=vmax)
add_colorbar(ax1,p)
ax1.xaxis.set_major_locator(mdates.MonthLocator())
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%b\n%Y'))
ax1.set_xlabel(r'$ Time \rightarrow$')
ax1.set_ylabel('Altitude [m] MSL')
ax1.set_title('BBY Windprof '+name[target])
array = np.empty((40,len(bins)-1))
for hgt in range(wp.shape[0]):
row = wp[hgt,:]
freq,bins=np.histogram(row[~np.isnan(row)],
bins=bins,
density=normalized)
array[hgt,:]=freq
x = bins
y = wprof.hgt
p = ax2.pcolormesh(x,y,array,cmap='viridis')
amin = np.amin(array)
amax = np.amax(array)
cbar = add_colorbar(ax2,p,size='4%',ticks=[amin,amax])
cbar.ax.set_yticklabels(['low','high'])
ax2.set_xticks(hist_xticks)
ax2.set_yticklabels('')
ax2.set_xlabel(name[target])
ax2.set_xlim(hist_xlim)
ax2.set_title('Normalized frequency')
plt.tight_layout()
if pngsuffix:
out_name = 'wprof_{}_{}.png'
plt.savefig(out_name.format(target,pngsuffix))
else:
plt.show(block=False)