-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLNC_plot_v2.py
More file actions
193 lines (151 loc) · 5.85 KB
/
LNC_plot_v2.py
File metadata and controls
193 lines (151 loc) · 5.85 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
def depol_plot(fig, ax, xdata, ydata, data, fsize = 21):
import matplotlib.pyplot as plt
import matplotlib.colors as colors
#set colormap to be the same as 'jet' with the addition of white color for
#depol ratios set to identiacally zero because they couldn't be calculated
cdict = {'red': ((0,1,1),
(0.0001, 1, 0),
(0.35, 0, 0),
(0.66, 1, 1),
(0.89,1, 1),
(1, 0.5, 0.5)),
'green': ((0,1,1),
(0.0001, 1, 0),
(0.125,0, 0),
(0.375,1, 1),
(0.64,1, 1),
(0.91,0,0),
(1, 0, 0)),
'blue': ((0,1,1),
(0.0001,1,0.5),
(0.11, 1, 1),
(0.34, 1, 1),
(0.65,0, 0),
(1, 0, 0))}
my_cmap = colors.LinearSegmentedColormap('my_colormap',cdict,1064)
im = ax.imshow(data, vmin=0, vmax=0.5, cmap = my_cmap)
forceAspect(ax,ar)
altticks(ax, ydata, fsize = fsize)
ax.set_ylabel('Altitude [m]', fontsize = fsize+4, labelpad = 15)
for line in ax.yaxis.get_ticklines():
line.set_markersize(10)
line.set_markeredgewidth(1)
ax.axis('tight')
return im
def backscatter_plot(fig, ax, xdata, ydata, data, fsize = 21):
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np
im = ax.imshow(data, norm = colors.LogNorm(vmin = 1, vmax = 10),
cmap = plt.cm.jet)
forceAspect(ax,ar)
altticks(ax, ydata, fsize = fsize, tcolor = 'w')
ax.set_ylabel('Altitude [m]', fontsize = fsize+4, labelpad = 15)
for line in ax.yaxis.get_ticklines():
line.set_markersize(10)
line.set_markeredgewidth(1)
ax.axis('tight')
return im
def forceAspect(ax,aspect=1):
im = ax.get_images()
extent = im[0].get_extent()
ax.set_aspect(abs((extent[1]-extent[0])/(extent[3]-extent[2]))/aspect)
def dateticks(ax, axisdat,numticks = 10, fsize = 21, tcolor = 'k'):
import matplotlib.pyplot as plt
from time import strftime
dold = axisdat[0].strftime('%d')
tickmarks = []
ticklabels = []
n = 0
l = len(axisdat)
hours = ['06','12','18']
# hours = ['03','06','09','12','15','18','21']
for d in axisdat:
dtemp = d.strftime('%d')
if dtemp != dold:
ticklabels.append(d.strftime('%H\n%b %d'))
tickmarks.append(n)
else:
htemp = d.strftime('%H')
mtemp = d.strftime('%M')
if htemp in hours and mtemp == '00':
ticklabels.append(d.strftime('%H'))
tickmarks.append(n)
dold = dtemp
n += 1
plt.xticks(tickmarks,ticklabels,fontsize = fsize)
for line in ax.xaxis.get_ticklines():
line.set_color(tcolor)
line.set_markersize(10)
line.set_markeredgewidth(2)
def altticks(ax, axisdat, numticks = 5, fsize = 21, tcolor = 'k'):
import matplotlib.pyplot as plt
numpoints = len(axisdat)
step = numpoints//numticks
tickmarks = range(0,numpoints,step)
ticklabels = [str(int(t)) for t in axisdat[::step]]
plt.yticks(tickmarks,ticklabels, fontsize = fsize)
for line in ax.yaxis.get_ticklines():
line.set_color(tcolor)
line.set_markersize(10)
line.set_markeredgewidth(3)
if __name__ == '__main__':
import pandas as pan
import os
import LNC_tools_v2 as LNC
import matplotlib.pyplot as plt
import numpy as np
os.chdir('F:\CORALNet\Data\ASCII Files')
#set date(s) for plot title
## days = list(set(t.strftime('%B %d, %Y') for t in xdata))
## days.sort()
## sdays = list(set(t.strftime('%Y%m%d') for t in xdata))
## sdays.sort()
##
## if len(days) == 1:
## titledays = days[0]
## savedays = sdays[0]
## else:
## titledays = '%s - %s'%(days[0],days[-1])
## savedays = '%s-%s'%(sdays[0],sdays[-1])
##
## title = 'Depolarization Ratio: %s'%titledays
## savetitle = 'Depolrat_%s'%savedays
#create figure and plot image of depolarization ratios
fsize = 18 #baseline font size
ar = 2.0 #aspect ratio
figheight = 12 #inches
plt.rc('font', family='serif', size=fsize)
## cbar = fig.colorbar(im, orientation = 'horizontal', pad = 0.15, aspect = 40)
## cbar.ax.tick_params(labelsize = font)
##
## t = ax.set_title(title, fontsize = fsize+10)
## t.set_y(1.1)
##
## plt.subplots_adjust(top = 0.86, bottom = 0.01, left = 0.09, right = 0.95)
##
fig = plt.figure()
for n in range(1,3):
filename = LNC.get_files('Select file to be plotted', filetype = ('.pickle','*.pickle'))
df = pan.load(filename[1:-1])
datetime = df.index
alt = df.columns
ax = fig.add_subplot(2,1,n)
if n == 1:
im = backscatter_plot(fig, ax, datetime,alt[::-1],df.T[::-1], fsize = fsize)
cbar = fig.colorbar(im, orientation = 'vertical', aspect = 6)
cbar.ax.tick_params(labelsize = fsize)
dateticks(ax, datetime, fsize = fsize, tcolor = 'w')
ax.set_xticklabels([])
if n == 2:
im = depol_plot(fig, ax, datetime,alt[::-1],df.T[::-1], fsize = fsize)
cbar = fig.colorbar(im, orientation = 'vertical', aspect = 6)
cbar.set_ticks(np.arange(0,0.6,0.1))
cbar.set_ticklabels(np.arange(0,0.6,0.1))
#set axis ranges and tickmarks based on data ranges
dateticks(ax, datetime, fsize = fsize)
ax.set_xlabel('Time [PDT]',fontsize = fsize+4)
fig.autofmt_xdate()
##plt.savefig(savetitle,dpi = 100, edgecolor = 'b', bbox_inches = 'tight')
fig.set_size_inches(figheight*ar,figheight)
plt.show()