@@ -1,188 +1,188 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | import copy |
|
5 | 5 | |
|
6 | 6 | from figure import Figure, isRealtime |
|
7 | 7 | |
|
8 | 8 | class CorrelationPlot(Figure): |
|
9 | 9 | |
|
10 | 10 | isConfig = None |
|
11 | 11 | __nsubplots = None |
|
12 | 12 | |
|
13 | 13 | WIDTHPROF = None |
|
14 | 14 | HEIGHTPROF = None |
|
15 | 15 | PREFIX = 'corr' |
|
16 | 16 | |
|
17 | 17 | def __init__(self): |
|
18 | 18 | |
|
19 | 19 | self.isConfig = False |
|
20 | 20 | self.__nsubplots = 1 |
|
21 | 21 | |
|
22 | 22 | self.WIDTH = 280 |
|
23 | 23 | self.HEIGHT = 250 |
|
24 | 24 | self.WIDTHPROF = 120 |
|
25 | 25 | self.HEIGHTPROF = 0 |
|
26 | 26 | self.counter_imagwr = 0 |
|
27 | 27 | |
|
28 | 28 | self.PLOT_CODE = 1 |
|
29 | 29 | self.FTP_WEI = None |
|
30 | 30 | self.EXP_CODE = None |
|
31 | 31 | self.SUB_EXP_CODE = None |
|
32 | 32 | self.PLOT_POS = None |
|
33 | 33 | |
|
34 | 34 | def getSubplots(self): |
|
35 | 35 | |
|
36 | 36 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
37 | 37 | nrow = int(self.nplots*1./ncol + 0.9) |
|
38 | 38 | |
|
39 | 39 | return nrow, ncol |
|
40 | 40 | |
|
41 | 41 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
42 | 42 | |
|
43 | 43 | showprofile = False |
|
44 | 44 | self.__showprofile = showprofile |
|
45 | 45 | self.nplots = nplots |
|
46 | 46 | |
|
47 | 47 | ncolspan = 1 |
|
48 | 48 | colspan = 1 |
|
49 | 49 | if showprofile: |
|
50 | 50 | ncolspan = 3 |
|
51 | 51 | colspan = 2 |
|
52 | 52 | self.__nsubplots = 2 |
|
53 | 53 | |
|
54 | 54 | self.createFigure(id = id, |
|
55 | 55 | wintitle = wintitle, |
|
56 | 56 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
57 | 57 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
58 | 58 | show=show) |
|
59 | 59 | |
|
60 | 60 | nrow, ncol = self.getSubplots() |
|
61 | 61 | |
|
62 | 62 | counter = 0 |
|
63 | 63 | for y in range(nrow): |
|
64 | 64 | for x in range(ncol): |
|
65 | 65 | |
|
66 | 66 | if counter >= self.nplots: |
|
67 | 67 | break |
|
68 | 68 | |
|
69 | 69 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
70 | 70 | |
|
71 | 71 | if showprofile: |
|
72 | 72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
73 | 73 | |
|
74 | 74 | counter += 1 |
|
75 | 75 | |
|
76 | 76 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
77 | 77 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
78 | 78 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
79 | 79 | server=None, folder=None, username=None, password=None, |
|
80 | 80 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
81 | 81 | |
|
82 | 82 | """ |
|
83 | 83 | |
|
84 | 84 | Input: |
|
85 | 85 | dataOut : |
|
86 | 86 | id : |
|
87 | 87 | wintitle : |
|
88 | 88 | channelList : |
|
89 | 89 | showProfile : |
|
90 | 90 | xmin : None, |
|
91 | 91 | xmax : None, |
|
92 | 92 | ymin : None, |
|
93 | 93 | ymax : None, |
|
94 | 94 | zmin : None, |
|
95 | 95 | zmax : None |
|
96 | 96 | """ |
|
97 | 97 | |
|
98 | 98 | if dataOut.flagNoData: |
|
99 | 99 | return None |
|
100 | 100 | |
|
101 | 101 | if realtime: |
|
102 | 102 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
103 | 103 | print 'Skipping this plot function' |
|
104 | 104 | return |
|
105 | 105 | |
|
106 | 106 | if channelList == None: |
|
107 | 107 | channelIndexList = dataOut.channelIndexList |
|
108 | 108 | else: |
|
109 | 109 | channelIndexList = [] |
|
110 | 110 | for channel in channelList: |
|
111 | 111 | if channel not in dataOut.channelList: |
|
112 | 112 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
113 | 113 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
114 | 114 | |
|
115 | 115 | factor = dataOut.normFactor |
|
116 | 116 | lenfactor = factor.shape[1] |
|
117 | 117 | x = dataOut.getLagTRange(1) |
|
118 | 118 | y = dataOut.getHeiRange() |
|
119 | 119 | |
|
120 | 120 | z = copy.copy(dataOut.data_corr[:,:,0,:]) |
|
121 | 121 | for i in range(dataOut.data_corr.shape[0]): |
|
122 | 122 | z[i,:,:] = z[i,:,:]/factor[i,:] |
|
123 | 123 | zdB = numpy.abs(z) |
|
124 | 124 | |
|
125 | 125 | avg = numpy.average(z, axis=1) |
|
126 | 126 | # avg = numpy.nanmean(z, axis=1) |
|
127 | 127 | # noise = dataOut.noise/factor |
|
128 | 128 | |
|
129 | 129 | #thisDatetime = dataOut.datatime |
|
130 | 130 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
131 | 131 | title = wintitle + " Correlation" |
|
132 | 132 | xlabel = "Lag T (s)" |
|
133 | 133 | ylabel = "Range (Km)" |
|
134 | 134 | |
|
135 | 135 | if not self.isConfig: |
|
136 | 136 | |
|
137 | 137 | nplots = dataOut.data_corr.shape[0] |
|
138 | 138 | |
|
139 | 139 | self.setup(id=id, |
|
140 | 140 | nplots=nplots, |
|
141 | 141 | wintitle=wintitle, |
|
142 | 142 | showprofile=showprofile, |
|
143 | 143 | show=show) |
|
144 | 144 | |
|
145 | 145 | if xmin == None: xmin = numpy.nanmin(x) |
|
146 | 146 | if xmax == None: xmax = numpy.nanmax(x) |
|
147 | 147 | if ymin == None: ymin = numpy.nanmin(y) |
|
148 | 148 | if ymax == None: ymax = numpy.nanmax(y) |
|
149 | 149 | if zmin == None: zmin = 0 |
|
150 | 150 | if zmax == None: zmax = 1 |
|
151 | 151 | |
|
152 | 152 | self.FTP_WEI = ftp_wei |
|
153 | 153 | self.EXP_CODE = exp_code |
|
154 | 154 | self.SUB_EXP_CODE = sub_exp_code |
|
155 | 155 | self.PLOT_POS = plot_pos |
|
156 | 156 | |
|
157 | 157 | self.isConfig = True |
|
158 | 158 | |
|
159 | 159 | self.setWinTitle(title) |
|
160 | 160 | |
|
161 | 161 | for i in range(self.nplots): |
|
162 | 162 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
163 |
title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0] |
|
|
163 | title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime) | |
|
164 | 164 | axes = self.axesList[i*self.__nsubplots] |
|
165 | 165 | axes.pcolor(x, y, zdB[i,:,:], |
|
166 | 166 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
167 | 167 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
168 | 168 | ticksize=9, cblabel='') |
|
169 | 169 | |
|
170 | 170 | # if self.__showprofile: |
|
171 | 171 | # axes = self.axesList[i*self.__nsubplots +1] |
|
172 | 172 | # axes.pline(avgdB[i], y, |
|
173 | 173 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
174 | 174 | # xlabel='dB', ylabel='', title='', |
|
175 | 175 | # ytick_visible=False, |
|
176 | 176 | # grid='x') |
|
177 | 177 | # |
|
178 | 178 | # noiseline = numpy.repeat(noisedB[i], len(y)) |
|
179 | 179 | # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
180 | 180 | |
|
181 | 181 | self.draw() |
|
182 | 182 | |
|
183 | 183 | self.save(figpath=figpath, |
|
184 | 184 | figfile=figfile, |
|
185 | 185 | save=save, |
|
186 | 186 | ftp=ftp, |
|
187 | 187 | wr_period=wr_period, |
|
188 | 188 | thisDatetime=thisDatetime) |
@@ -1,1363 +1,1363 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | |
|
5 | 5 | from figure import Figure, isRealtime |
|
6 | 6 | from plotting_codes import * |
|
7 | 7 | |
|
8 | 8 | class MomentsPlot(Figure): |
|
9 | 9 | |
|
10 | 10 | isConfig = None |
|
11 | 11 | __nsubplots = None |
|
12 | 12 | |
|
13 | 13 | WIDTHPROF = None |
|
14 | 14 | HEIGHTPROF = None |
|
15 | 15 | PREFIX = 'prm' |
|
16 | 16 | |
|
17 | 17 | def __init__(self): |
|
18 | 18 | |
|
19 | 19 | self.isConfig = False |
|
20 | 20 | self.__nsubplots = 1 |
|
21 | 21 | |
|
22 | 22 | self.WIDTH = 280 |
|
23 | 23 | self.HEIGHT = 250 |
|
24 | 24 | self.WIDTHPROF = 120 |
|
25 | 25 | self.HEIGHTPROF = 0 |
|
26 | 26 | self.counter_imagwr = 0 |
|
27 | 27 | |
|
28 | 28 | self.PLOT_CODE = MOMENTS_CODE |
|
29 | 29 | |
|
30 | 30 | self.FTP_WEI = None |
|
31 | 31 | self.EXP_CODE = None |
|
32 | 32 | self.SUB_EXP_CODE = None |
|
33 | 33 | self.PLOT_POS = None |
|
34 | 34 | |
|
35 | 35 | def getSubplots(self): |
|
36 | 36 | |
|
37 | 37 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
38 | 38 | nrow = int(self.nplots*1./ncol + 0.9) |
|
39 | 39 | |
|
40 | 40 | return nrow, ncol |
|
41 | 41 | |
|
42 | 42 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
43 | 43 | |
|
44 | 44 | self.__showprofile = showprofile |
|
45 | 45 | self.nplots = nplots |
|
46 | 46 | |
|
47 | 47 | ncolspan = 1 |
|
48 | 48 | colspan = 1 |
|
49 | 49 | if showprofile: |
|
50 | 50 | ncolspan = 3 |
|
51 | 51 | colspan = 2 |
|
52 | 52 | self.__nsubplots = 2 |
|
53 | 53 | |
|
54 | 54 | self.createFigure(id = id, |
|
55 | 55 | wintitle = wintitle, |
|
56 | 56 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
57 | 57 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
58 | 58 | show=show) |
|
59 | 59 | |
|
60 | 60 | nrow, ncol = self.getSubplots() |
|
61 | 61 | |
|
62 | 62 | counter = 0 |
|
63 | 63 | for y in range(nrow): |
|
64 | 64 | for x in range(ncol): |
|
65 | 65 | |
|
66 | 66 | if counter >= self.nplots: |
|
67 | 67 | break |
|
68 | 68 | |
|
69 | 69 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
70 | 70 | |
|
71 | 71 | if showprofile: |
|
72 | 72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
73 | 73 | |
|
74 | 74 | counter += 1 |
|
75 | 75 | |
|
76 | 76 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
77 | 77 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
78 | 78 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
79 | 79 | server=None, folder=None, username=None, password=None, |
|
80 | 80 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
81 | 81 | |
|
82 | 82 | """ |
|
83 | 83 | |
|
84 | 84 | Input: |
|
85 | 85 | dataOut : |
|
86 | 86 | id : |
|
87 | 87 | wintitle : |
|
88 | 88 | channelList : |
|
89 | 89 | showProfile : |
|
90 | 90 | xmin : None, |
|
91 | 91 | xmax : None, |
|
92 | 92 | ymin : None, |
|
93 | 93 | ymax : None, |
|
94 | 94 | zmin : None, |
|
95 | 95 | zmax : None |
|
96 | 96 | """ |
|
97 | 97 | |
|
98 | 98 | if dataOut.flagNoData: |
|
99 | 99 | return None |
|
100 | 100 | |
|
101 | 101 | if realtime: |
|
102 | 102 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
103 | 103 | print 'Skipping this plot function' |
|
104 | 104 | return |
|
105 | 105 | |
|
106 | 106 | if channelList == None: |
|
107 | 107 | channelIndexList = dataOut.channelIndexList |
|
108 | 108 | else: |
|
109 | 109 | channelIndexList = [] |
|
110 | 110 | for channel in channelList: |
|
111 | 111 | if channel not in dataOut.channelList: |
|
112 | 112 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
113 | 113 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
114 | 114 | |
|
115 | 115 | factor = dataOut.normFactor |
|
116 | 116 | x = dataOut.abscissaList |
|
117 | 117 | y = dataOut.heightList |
|
118 | 118 | |
|
119 | 119 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
120 | 120 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
121 | 121 | avg = numpy.average(z, axis=1) |
|
122 | 122 | noise = dataOut.noise/factor |
|
123 | 123 | |
|
124 | 124 | zdB = 10*numpy.log10(z) |
|
125 | 125 | avgdB = 10*numpy.log10(avg) |
|
126 | 126 | noisedB = 10*numpy.log10(noise) |
|
127 | 127 | |
|
128 | 128 | #thisDatetime = dataOut.datatime |
|
129 | 129 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
130 | 130 | title = wintitle + " Parameters" |
|
131 | 131 | xlabel = "Velocity (m/s)" |
|
132 | 132 | ylabel = "Range (Km)" |
|
133 | 133 | |
|
134 | 134 | if not self.isConfig: |
|
135 | 135 | |
|
136 | 136 | nplots = len(channelIndexList) |
|
137 | 137 | |
|
138 | 138 | self.setup(id=id, |
|
139 | 139 | nplots=nplots, |
|
140 | 140 | wintitle=wintitle, |
|
141 | 141 | showprofile=showprofile, |
|
142 | 142 | show=show) |
|
143 | 143 | |
|
144 | 144 | if xmin == None: xmin = numpy.nanmin(x) |
|
145 | 145 | if xmax == None: xmax = numpy.nanmax(x) |
|
146 | 146 | if ymin == None: ymin = numpy.nanmin(y) |
|
147 | 147 | if ymax == None: ymax = numpy.nanmax(y) |
|
148 | 148 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
149 | 149 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
150 | 150 | |
|
151 | 151 | self.FTP_WEI = ftp_wei |
|
152 | 152 | self.EXP_CODE = exp_code |
|
153 | 153 | self.SUB_EXP_CODE = sub_exp_code |
|
154 | 154 | self.PLOT_POS = plot_pos |
|
155 | 155 | |
|
156 | 156 | self.isConfig = True |
|
157 | 157 | |
|
158 | 158 | self.setWinTitle(title) |
|
159 | 159 | |
|
160 | 160 | for i in range(self.nplots): |
|
161 | 161 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
162 |
title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i] |
|
|
162 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime) | |
|
163 | 163 | axes = self.axesList[i*self.__nsubplots] |
|
164 | 164 | axes.pcolor(x, y, zdB[i,:,:], |
|
165 | 165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
166 | 166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
167 | 167 | ticksize=9, cblabel='') |
|
168 | 168 | #Mean Line |
|
169 | 169 | mean = dataOut.data_param[i, 1, :] |
|
170 | 170 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
171 | 171 | |
|
172 | 172 | if self.__showprofile: |
|
173 | 173 | axes = self.axesList[i*self.__nsubplots +1] |
|
174 | 174 | axes.pline(avgdB[i], y, |
|
175 | 175 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
176 | 176 | xlabel='dB', ylabel='', title='', |
|
177 | 177 | ytick_visible=False, |
|
178 | 178 | grid='x') |
|
179 | 179 | |
|
180 | 180 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
181 | 181 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
182 | 182 | |
|
183 | 183 | self.draw() |
|
184 | 184 | |
|
185 | 185 | self.save(figpath=figpath, |
|
186 | 186 | figfile=figfile, |
|
187 | 187 | save=save, |
|
188 | 188 | ftp=ftp, |
|
189 | 189 | wr_period=wr_period, |
|
190 | 190 | thisDatetime=thisDatetime) |
|
191 | 191 | |
|
192 | 192 | |
|
193 | 193 | |
|
194 | 194 | class SkyMapPlot(Figure): |
|
195 | 195 | |
|
196 | 196 | __isConfig = None |
|
197 | 197 | __nsubplots = None |
|
198 | 198 | |
|
199 | 199 | WIDTHPROF = None |
|
200 | 200 | HEIGHTPROF = None |
|
201 | 201 | PREFIX = 'mmap' |
|
202 | 202 | |
|
203 | 203 | def __init__(self): |
|
204 | 204 | |
|
205 | 205 | self.__isConfig = False |
|
206 | 206 | self.__nsubplots = 1 |
|
207 | 207 | |
|
208 | 208 | # self.WIDTH = 280 |
|
209 | 209 | # self.HEIGHT = 250 |
|
210 | 210 | self.WIDTH = 600 |
|
211 | 211 | self.HEIGHT = 600 |
|
212 | 212 | self.WIDTHPROF = 120 |
|
213 | 213 | self.HEIGHTPROF = 0 |
|
214 | 214 | self.counter_imagwr = 0 |
|
215 | 215 | |
|
216 | 216 | self.PLOT_CODE = MSKYMAP_CODE |
|
217 | 217 | |
|
218 | 218 | self.FTP_WEI = None |
|
219 | 219 | self.EXP_CODE = None |
|
220 | 220 | self.SUB_EXP_CODE = None |
|
221 | 221 | self.PLOT_POS = None |
|
222 | 222 | |
|
223 | 223 | def getSubplots(self): |
|
224 | 224 | |
|
225 | 225 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
226 | 226 | nrow = int(self.nplots*1./ncol + 0.9) |
|
227 | 227 | |
|
228 | 228 | return nrow, ncol |
|
229 | 229 | |
|
230 | 230 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
231 | 231 | |
|
232 | 232 | self.__showprofile = showprofile |
|
233 | 233 | self.nplots = nplots |
|
234 | 234 | |
|
235 | 235 | ncolspan = 1 |
|
236 | 236 | colspan = 1 |
|
237 | 237 | |
|
238 | 238 | self.createFigure(id = id, |
|
239 | 239 | wintitle = wintitle, |
|
240 | 240 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
241 | 241 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
242 | 242 | show=show) |
|
243 | 243 | |
|
244 | 244 | nrow, ncol = 1,1 |
|
245 | 245 | counter = 0 |
|
246 | 246 | x = 0 |
|
247 | 247 | y = 0 |
|
248 | 248 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
249 | 249 | |
|
250 | 250 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
251 | 251 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
252 | 252 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
253 | 253 | server=None, folder=None, username=None, password=None, |
|
254 | 254 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
255 | 255 | |
|
256 | 256 | """ |
|
257 | 257 | |
|
258 | 258 | Input: |
|
259 | 259 | dataOut : |
|
260 | 260 | id : |
|
261 | 261 | wintitle : |
|
262 | 262 | channelList : |
|
263 | 263 | showProfile : |
|
264 | 264 | xmin : None, |
|
265 | 265 | xmax : None, |
|
266 | 266 | ymin : None, |
|
267 | 267 | ymax : None, |
|
268 | 268 | zmin : None, |
|
269 | 269 | zmax : None |
|
270 | 270 | """ |
|
271 | 271 | |
|
272 | 272 | arrayParameters = dataOut.data_param[0,:] |
|
273 | 273 | error = arrayParameters[:,-1] |
|
274 | 274 | indValid = numpy.where(error == 0)[0] |
|
275 | 275 | finalMeteor = arrayParameters[indValid,:] |
|
276 | 276 | finalAzimuth = finalMeteor[:,4] |
|
277 | 277 | finalZenith = finalMeteor[:,5] |
|
278 | 278 | |
|
279 | 279 | x = finalAzimuth*numpy.pi/180 |
|
280 | 280 | y = finalZenith |
|
281 | 281 | |
|
282 | 282 | |
|
283 | 283 | #thisDatetime = dataOut.datatime |
|
284 | 284 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
285 | 285 | title = wintitle + " Parameters" |
|
286 | 286 | xlabel = "Zonal Zenith Angle (deg) " |
|
287 | 287 | ylabel = "Meridional Zenith Angle (deg)" |
|
288 | 288 | |
|
289 | 289 | if not self.__isConfig: |
|
290 | 290 | |
|
291 | 291 | nplots = 1 |
|
292 | 292 | |
|
293 | 293 | self.setup(id=id, |
|
294 | 294 | nplots=nplots, |
|
295 | 295 | wintitle=wintitle, |
|
296 | 296 | showprofile=showprofile, |
|
297 | 297 | show=show) |
|
298 | 298 | |
|
299 | 299 | self.FTP_WEI = ftp_wei |
|
300 | 300 | self.EXP_CODE = exp_code |
|
301 | 301 | self.SUB_EXP_CODE = sub_exp_code |
|
302 | 302 | self.PLOT_POS = plot_pos |
|
303 | 303 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
304 | 304 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
305 | 305 | self.__isConfig = True |
|
306 | 306 | |
|
307 | 307 | self.setWinTitle(title) |
|
308 | 308 | |
|
309 | 309 | i = 0 |
|
310 | 310 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
311 | 311 | |
|
312 | 312 | axes = self.axesList[i*self.__nsubplots] |
|
313 | 313 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
314 | 314 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
315 | 315 | axes.polar(x, y, |
|
316 | 316 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
317 | 317 | ticksize=9, cblabel='') |
|
318 | 318 | |
|
319 | 319 | self.draw() |
|
320 | 320 | |
|
321 | 321 | self.save(figpath=figpath, |
|
322 | 322 | figfile=figfile, |
|
323 | 323 | save=save, |
|
324 | 324 | ftp=ftp, |
|
325 | 325 | wr_period=wr_period, |
|
326 | 326 | thisDatetime=thisDatetime) |
|
327 | 327 | |
|
328 | 328 | |
|
329 | 329 | class WindProfilerPlot(Figure): |
|
330 | 330 | |
|
331 | 331 | __isConfig = None |
|
332 | 332 | __nsubplots = None |
|
333 | 333 | |
|
334 | 334 | WIDTHPROF = None |
|
335 | 335 | HEIGHTPROF = None |
|
336 | 336 | PREFIX = 'wind' |
|
337 | 337 | |
|
338 | 338 | def __init__(self): |
|
339 | 339 | |
|
340 | 340 | self.timerange = None |
|
341 | 341 | self.__isConfig = False |
|
342 | 342 | self.__nsubplots = 1 |
|
343 | 343 | |
|
344 | 344 | self.WIDTH = 800 |
|
345 | 345 | self.HEIGHT = 150 |
|
346 | 346 | self.WIDTHPROF = 120 |
|
347 | 347 | self.HEIGHTPROF = 0 |
|
348 | 348 | self.counter_imagwr = 0 |
|
349 | 349 | |
|
350 | 350 | self.PLOT_CODE = WIND_CODE |
|
351 | 351 | |
|
352 | 352 | self.FTP_WEI = None |
|
353 | 353 | self.EXP_CODE = None |
|
354 | 354 | self.SUB_EXP_CODE = None |
|
355 | 355 | self.PLOT_POS = None |
|
356 | 356 | self.tmin = None |
|
357 | 357 | self.tmax = None |
|
358 | 358 | |
|
359 | 359 | self.xmin = None |
|
360 | 360 | self.xmax = None |
|
361 | 361 | |
|
362 | 362 | self.figfile = None |
|
363 | 363 | |
|
364 | 364 | def getSubplots(self): |
|
365 | 365 | |
|
366 | 366 | ncol = 1 |
|
367 | 367 | nrow = self.nplots |
|
368 | 368 | |
|
369 | 369 | return nrow, ncol |
|
370 | 370 | |
|
371 | 371 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
372 | 372 | |
|
373 | 373 | self.__showprofile = showprofile |
|
374 | 374 | self.nplots = nplots |
|
375 | 375 | |
|
376 | 376 | ncolspan = 1 |
|
377 | 377 | colspan = 1 |
|
378 | 378 | |
|
379 | 379 | self.createFigure(id = id, |
|
380 | 380 | wintitle = wintitle, |
|
381 | 381 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
382 | 382 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
383 | 383 | show=show) |
|
384 | 384 | |
|
385 | 385 | nrow, ncol = self.getSubplots() |
|
386 | 386 | |
|
387 | 387 | counter = 0 |
|
388 | 388 | for y in range(nrow): |
|
389 | 389 | if counter >= self.nplots: |
|
390 | 390 | break |
|
391 | 391 | |
|
392 | 392 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
393 | 393 | counter += 1 |
|
394 | 394 | |
|
395 | 395 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', |
|
396 | 396 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
397 | 397 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
398 | 398 | timerange=None, SNRthresh = None, |
|
399 | 399 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
400 | 400 | server=None, folder=None, username=None, password=None, |
|
401 | 401 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
402 | 402 | """ |
|
403 | 403 | |
|
404 | 404 | Input: |
|
405 | 405 | dataOut : |
|
406 | 406 | id : |
|
407 | 407 | wintitle : |
|
408 | 408 | channelList : |
|
409 | 409 | showProfile : |
|
410 | 410 | xmin : None, |
|
411 | 411 | xmax : None, |
|
412 | 412 | ymin : None, |
|
413 | 413 | ymax : None, |
|
414 | 414 | zmin : None, |
|
415 | 415 | zmax : None |
|
416 | 416 | """ |
|
417 | 417 | |
|
418 | 418 | if channelList == None: |
|
419 | 419 | channelIndexList = dataOut.channelIndexList |
|
420 | 420 | else: |
|
421 | 421 | channelIndexList = [] |
|
422 | 422 | for channel in channelList: |
|
423 | 423 | if channel not in dataOut.channelList: |
|
424 | 424 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
425 | 425 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
426 | 426 | |
|
427 | 427 | # if timerange is not None: |
|
428 | 428 | # self.timerange = timerange |
|
429 | 429 | # |
|
430 | 430 | # tmin = None |
|
431 | 431 | # tmax = None |
|
432 | 432 | |
|
433 | 433 | x = dataOut.getTimeRange1() |
|
434 | 434 | # y = dataOut.heightList |
|
435 | 435 | y = dataOut.heightList |
|
436 | 436 | |
|
437 | 437 | z = dataOut.data_output.copy() |
|
438 | 438 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
439 | 439 | nplotsw = nplots |
|
440 | 440 | |
|
441 | 441 | #If there is a SNR function defined |
|
442 | 442 | if dataOut.data_SNR is not None: |
|
443 | 443 | nplots += 1 |
|
444 | 444 | SNR = dataOut.data_SNR |
|
445 | 445 | SNRavg = numpy.average(SNR, axis=0) |
|
446 | 446 | |
|
447 | 447 | SNRdB = 10*numpy.log10(SNR) |
|
448 | 448 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
449 | 449 | |
|
450 | 450 | if SNRthresh == None: SNRthresh = -5.0 |
|
451 | 451 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
452 | 452 | |
|
453 | 453 | for i in range(nplotsw): |
|
454 | 454 | z[i,ind] = numpy.nan |
|
455 | 455 | |
|
456 | 456 | |
|
457 | 457 | # showprofile = False |
|
458 | 458 | # thisDatetime = dataOut.datatime |
|
459 | 459 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
460 | 460 | title = wintitle + "Wind" |
|
461 | 461 | xlabel = "" |
|
462 | 462 | ylabel = "Range (Km)" |
|
463 | 463 | |
|
464 | 464 | if not self.__isConfig: |
|
465 | 465 | |
|
466 | 466 | self.setup(id=id, |
|
467 | 467 | nplots=nplots, |
|
468 | 468 | wintitle=wintitle, |
|
469 | 469 | showprofile=showprofile, |
|
470 | 470 | show=show) |
|
471 | 471 | |
|
472 | 472 | if timerange is not None: |
|
473 | 473 | self.timerange = timerange |
|
474 | 474 | |
|
475 | 475 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
476 | 476 | |
|
477 | 477 | if ymin == None: ymin = numpy.nanmin(y) |
|
478 | 478 | if ymax == None: ymax = numpy.nanmax(y) |
|
479 | 479 | |
|
480 | 480 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) |
|
481 | 481 | #if numpy.isnan(zmax): zmax = 50 |
|
482 | 482 | if zmin == None: zmin = -zmax |
|
483 | 483 | |
|
484 | 484 | if nplotsw == 3: |
|
485 | 485 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
486 | 486 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
487 | 487 | |
|
488 | 488 | if dataOut.data_SNR is not None: |
|
489 | 489 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
490 | 490 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
491 | 491 | |
|
492 | 492 | |
|
493 | 493 | self.FTP_WEI = ftp_wei |
|
494 | 494 | self.EXP_CODE = exp_code |
|
495 | 495 | self.SUB_EXP_CODE = sub_exp_code |
|
496 | 496 | self.PLOT_POS = plot_pos |
|
497 | 497 | |
|
498 | 498 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
499 | 499 | self.__isConfig = True |
|
500 | 500 | self.figfile = figfile |
|
501 | 501 | |
|
502 | 502 | self.setWinTitle(title) |
|
503 | 503 | |
|
504 | 504 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
505 | 505 | x[1] = self.xmax |
|
506 | 506 | |
|
507 | 507 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
508 | 508 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
509 | 509 | zmaxVector = [zmax, zmax, zmax_ver] |
|
510 | 510 | zminVector = [zmin, zmin, zmin_ver] |
|
511 | 511 | windFactor = [1,1,100] |
|
512 | 512 | |
|
513 | 513 | for i in range(nplotsw): |
|
514 | 514 | |
|
515 | 515 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
516 | 516 | axes = self.axesList[i*self.__nsubplots] |
|
517 | 517 | |
|
518 | 518 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
519 | 519 | |
|
520 | 520 | axes.pcolorbuffer(x, y, z1, |
|
521 | 521 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
522 | 522 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
523 | 523 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" ) |
|
524 | 524 | |
|
525 | 525 | if dataOut.data_SNR is not None: |
|
526 | 526 | i += 1 |
|
527 | 527 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
528 | 528 | axes = self.axesList[i*self.__nsubplots] |
|
529 | 529 | |
|
530 | 530 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
531 | 531 | |
|
532 | 532 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
533 | 533 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
534 | 534 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
535 | 535 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
536 | 536 | |
|
537 | 537 | self.draw() |
|
538 | 538 | |
|
539 | 539 | if x[1] >= self.axesList[0].xmax: |
|
540 | 540 | self.counter_imagwr = wr_period |
|
541 | 541 | self.__isConfig = False |
|
542 | 542 | self.figfile = None |
|
543 | 543 | |
|
544 | 544 | self.save(figpath=figpath, |
|
545 | 545 | figfile=figfile, |
|
546 | 546 | save=save, |
|
547 | 547 | ftp=ftp, |
|
548 | 548 | wr_period=wr_period, |
|
549 | 549 | thisDatetime=thisDatetime, |
|
550 | 550 | update_figfile=False) |
|
551 | 551 | |
|
552 | 552 | |
|
553 | 553 | class ParametersPlot(Figure): |
|
554 | 554 | |
|
555 | 555 | __isConfig = None |
|
556 | 556 | __nsubplots = None |
|
557 | 557 | |
|
558 | 558 | WIDTHPROF = None |
|
559 | 559 | HEIGHTPROF = None |
|
560 | 560 | PREFIX = 'prm' |
|
561 | 561 | |
|
562 | 562 | def __init__(self): |
|
563 | 563 | |
|
564 | 564 | self.timerange = 2*60*60 |
|
565 | 565 | self.__isConfig = False |
|
566 | 566 | self.__nsubplots = 1 |
|
567 | 567 | |
|
568 | 568 | self.WIDTH = 800 |
|
569 | 569 | self.HEIGHT = 150 |
|
570 | 570 | self.WIDTHPROF = 120 |
|
571 | 571 | self.HEIGHTPROF = 0 |
|
572 | 572 | self.counter_imagwr = 0 |
|
573 | 573 | |
|
574 | 574 | self.PLOT_CODE = PARMS_CODE |
|
575 | 575 | |
|
576 | 576 | self.FTP_WEI = None |
|
577 | 577 | self.EXP_CODE = None |
|
578 | 578 | self.SUB_EXP_CODE = None |
|
579 | 579 | self.PLOT_POS = None |
|
580 | 580 | self.tmin = None |
|
581 | 581 | self.tmax = None |
|
582 | 582 | |
|
583 | 583 | self.xmin = None |
|
584 | 584 | self.xmax = None |
|
585 | 585 | |
|
586 | 586 | self.figfile = None |
|
587 | 587 | |
|
588 | 588 | def getSubplots(self): |
|
589 | 589 | |
|
590 | 590 | ncol = 1 |
|
591 | 591 | nrow = self.nplots |
|
592 | 592 | |
|
593 | 593 | return nrow, ncol |
|
594 | 594 | |
|
595 | 595 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
596 | 596 | |
|
597 | 597 | self.__showprofile = showprofile |
|
598 | 598 | self.nplots = nplots |
|
599 | 599 | |
|
600 | 600 | ncolspan = 1 |
|
601 | 601 | colspan = 1 |
|
602 | 602 | |
|
603 | 603 | self.createFigure(id = id, |
|
604 | 604 | wintitle = wintitle, |
|
605 | 605 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
606 | 606 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
607 | 607 | show=show) |
|
608 | 608 | |
|
609 | 609 | nrow, ncol = self.getSubplots() |
|
610 | 610 | |
|
611 | 611 | counter = 0 |
|
612 | 612 | for y in range(nrow): |
|
613 | 613 | for x in range(ncol): |
|
614 | 614 | |
|
615 | 615 | if counter >= self.nplots: |
|
616 | 616 | break |
|
617 | 617 | |
|
618 | 618 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
619 | 619 | |
|
620 | 620 | if showprofile: |
|
621 | 621 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
622 | 622 | |
|
623 | 623 | counter += 1 |
|
624 | 624 | |
|
625 | 625 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
626 | 626 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
627 | 627 | parameterIndex = None, onlyPositive = False, |
|
628 | 628 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, |
|
629 | 629 | DOP = True, |
|
630 | 630 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
631 | 631 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
632 | 632 | server=None, folder=None, username=None, password=None, |
|
633 | 633 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
634 | 634 | |
|
635 | 635 | """ |
|
636 | 636 | |
|
637 | 637 | Input: |
|
638 | 638 | dataOut : |
|
639 | 639 | id : |
|
640 | 640 | wintitle : |
|
641 | 641 | channelList : |
|
642 | 642 | showProfile : |
|
643 | 643 | xmin : None, |
|
644 | 644 | xmax : None, |
|
645 | 645 | ymin : None, |
|
646 | 646 | ymax : None, |
|
647 | 647 | zmin : None, |
|
648 | 648 | zmax : None |
|
649 | 649 | """ |
|
650 | 650 | |
|
651 | 651 | data_param = getattr(dataOut, parameterObject) |
|
652 | 652 | |
|
653 | 653 | if channelList == None: |
|
654 | 654 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
655 | 655 | else: |
|
656 | 656 | channelIndexList = numpy.array(channelList) |
|
657 | 657 | |
|
658 | 658 | nchan = len(channelIndexList) #Number of channels being plotted |
|
659 | 659 | |
|
660 | 660 | if nchan < 1: |
|
661 | 661 | return |
|
662 | 662 | |
|
663 | 663 | nGraphsByChannel = 0 |
|
664 | 664 | |
|
665 | 665 | if SNR: |
|
666 | 666 | nGraphsByChannel += 1 |
|
667 | 667 | if DOP: |
|
668 | 668 | nGraphsByChannel += 1 |
|
669 | 669 | |
|
670 | 670 | if nGraphsByChannel < 1: |
|
671 | 671 | return |
|
672 | 672 | |
|
673 | 673 | nplots = nGraphsByChannel*nchan |
|
674 | 674 | |
|
675 | 675 | if timerange is not None: |
|
676 | 676 | self.timerange = timerange |
|
677 | 677 | |
|
678 | 678 | #tmin = None |
|
679 | 679 | #tmax = None |
|
680 | 680 | if parameterIndex == None: |
|
681 | 681 | parameterIndex = 1 |
|
682 | 682 | |
|
683 | 683 | x = dataOut.getTimeRange1() |
|
684 | 684 | y = dataOut.heightList |
|
685 | 685 | z = data_param[channelIndexList,parameterIndex,:].copy() |
|
686 | 686 | |
|
687 | 687 | zRange = dataOut.abscissaList |
|
688 | 688 | # nChannels = z.shape[0] #Number of wind dimensions estimated |
|
689 | 689 | # thisDatetime = dataOut.datatime |
|
690 | 690 | |
|
691 | 691 | if dataOut.data_SNR is not None: |
|
692 | 692 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
693 | 693 | SNRdB = 10*numpy.log10(SNRarray) |
|
694 | 694 | # SNRavgdB = 10*numpy.log10(SNRavg) |
|
695 | 695 | ind = numpy.where(SNRdB < 10**(SNRthresh/10)) |
|
696 | 696 | z[ind] = numpy.nan |
|
697 | 697 | |
|
698 | 698 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
699 | 699 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
700 | 700 | xlabel = "" |
|
701 | 701 | ylabel = "Range (Km)" |
|
702 | 702 | |
|
703 | 703 | if (SNR and not onlySNR): nplots = 2*nplots |
|
704 | 704 | |
|
705 | 705 | if onlyPositive: |
|
706 | 706 | colormap = "jet" |
|
707 | 707 | zmin = 0 |
|
708 | 708 | else: colormap = "RdBu_r" |
|
709 | 709 | |
|
710 | 710 | if not self.__isConfig: |
|
711 | 711 | |
|
712 | 712 | self.setup(id=id, |
|
713 | 713 | nplots=nplots, |
|
714 | 714 | wintitle=wintitle, |
|
715 | 715 | showprofile=showprofile, |
|
716 | 716 | show=show) |
|
717 | 717 | |
|
718 | 718 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
719 | 719 | |
|
720 | 720 | if ymin == None: ymin = numpy.nanmin(y) |
|
721 | 721 | if ymax == None: ymax = numpy.nanmax(y) |
|
722 | 722 | if zmin == None: zmin = numpy.nanmin(zRange) |
|
723 | 723 | if zmax == None: zmax = numpy.nanmax(zRange) |
|
724 | 724 | |
|
725 | 725 | if SNR: |
|
726 | 726 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
727 | 727 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
728 | 728 | |
|
729 | 729 | self.FTP_WEI = ftp_wei |
|
730 | 730 | self.EXP_CODE = exp_code |
|
731 | 731 | self.SUB_EXP_CODE = sub_exp_code |
|
732 | 732 | self.PLOT_POS = plot_pos |
|
733 | 733 | |
|
734 | 734 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
735 | 735 | self.__isConfig = True |
|
736 | 736 | self.figfile = figfile |
|
737 | 737 | |
|
738 | 738 | self.setWinTitle(title) |
|
739 | 739 | |
|
740 | 740 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
741 | 741 | x[1] = self.xmax |
|
742 | 742 | |
|
743 | 743 | for i in range(nchan): |
|
744 | 744 | |
|
745 | 745 | if (SNR and not onlySNR): j = 2*i |
|
746 | 746 | else: j = i |
|
747 | 747 | |
|
748 | 748 | j = nGraphsByChannel*i |
|
749 | 749 | |
|
750 | 750 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
751 | 751 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
752 | 752 | |
|
753 | 753 | if not onlySNR: |
|
754 | 754 | axes = self.axesList[j*self.__nsubplots] |
|
755 | 755 | z1 = z[i,:].reshape((1,-1)) |
|
756 | 756 | axes.pcolorbuffer(x, y, z1, |
|
757 | 757 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
758 | 758 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
759 | 759 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
760 | 760 | |
|
761 | 761 | if DOP: |
|
762 |
title = "%s Channel %d: %s" %(parameterName, channelIndexList[i] |
|
|
762 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
763 | 763 | |
|
764 | 764 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
765 | 765 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
766 | 766 | axes = self.axesList[j] |
|
767 | 767 | z1 = z[i,:].reshape((1,-1)) |
|
768 | 768 | axes.pcolorbuffer(x, y, z1, |
|
769 | 769 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
770 | 770 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
771 | 771 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
772 | 772 | |
|
773 | 773 | if SNR: |
|
774 |
title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i] |
|
|
774 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
775 | 775 | axes = self.axesList[(j)*self.__nsubplots] |
|
776 | 776 | if not onlySNR: |
|
777 | 777 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
778 | 778 | |
|
779 | 779 | axes = self.axesList[(j + nGraphsByChannel-1)] |
|
780 | 780 | |
|
781 | 781 | z1 = SNRdB[i,:].reshape((1,-1)) |
|
782 | 782 | axes.pcolorbuffer(x, y, z1, |
|
783 | 783 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
784 | 784 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
785 | 785 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
786 | 786 | |
|
787 | 787 | |
|
788 | 788 | |
|
789 | 789 | self.draw() |
|
790 | 790 | |
|
791 | 791 | if x[1] >= self.axesList[0].xmax: |
|
792 | 792 | self.counter_imagwr = wr_period |
|
793 | 793 | self.__isConfig = False |
|
794 | 794 | self.figfile = None |
|
795 | 795 | |
|
796 | 796 | self.save(figpath=figpath, |
|
797 | 797 | figfile=figfile, |
|
798 | 798 | save=save, |
|
799 | 799 | ftp=ftp, |
|
800 | 800 | wr_period=wr_period, |
|
801 | 801 | thisDatetime=thisDatetime, |
|
802 | 802 | update_figfile=False) |
|
803 | 803 | |
|
804 | 804 | class SpectralFittingPlot(Figure): |
|
805 | 805 | |
|
806 | 806 | __isConfig = None |
|
807 | 807 | __nsubplots = None |
|
808 | 808 | |
|
809 | 809 | WIDTHPROF = None |
|
810 | 810 | HEIGHTPROF = None |
|
811 | 811 | PREFIX = 'prm' |
|
812 | 812 | |
|
813 | 813 | |
|
814 | 814 | N = None |
|
815 | 815 | ippSeconds = None |
|
816 | 816 | |
|
817 | 817 | def __init__(self): |
|
818 | 818 | self.__isConfig = False |
|
819 | 819 | self.__nsubplots = 1 |
|
820 | 820 | |
|
821 | 821 | self.PLOT_CODE = SPECFIT_CODE |
|
822 | 822 | |
|
823 | 823 | self.WIDTH = 450 |
|
824 | 824 | self.HEIGHT = 250 |
|
825 | 825 | self.WIDTHPROF = 0 |
|
826 | 826 | self.HEIGHTPROF = 0 |
|
827 | 827 | |
|
828 | 828 | def getSubplots(self): |
|
829 | 829 | |
|
830 | 830 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
831 | 831 | nrow = int(self.nplots*1./ncol + 0.9) |
|
832 | 832 | |
|
833 | 833 | return nrow, ncol |
|
834 | 834 | |
|
835 | 835 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
836 | 836 | |
|
837 | 837 | showprofile = False |
|
838 | 838 | self.__showprofile = showprofile |
|
839 | 839 | self.nplots = nplots |
|
840 | 840 | |
|
841 | 841 | ncolspan = 5 |
|
842 | 842 | colspan = 4 |
|
843 | 843 | if showprofile: |
|
844 | 844 | ncolspan = 5 |
|
845 | 845 | colspan = 4 |
|
846 | 846 | self.__nsubplots = 2 |
|
847 | 847 | |
|
848 | 848 | self.createFigure(id = id, |
|
849 | 849 | wintitle = wintitle, |
|
850 | 850 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
851 | 851 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
852 | 852 | show=show) |
|
853 | 853 | |
|
854 | 854 | nrow, ncol = self.getSubplots() |
|
855 | 855 | |
|
856 | 856 | counter = 0 |
|
857 | 857 | for y in range(nrow): |
|
858 | 858 | for x in range(ncol): |
|
859 | 859 | |
|
860 | 860 | if counter >= self.nplots: |
|
861 | 861 | break |
|
862 | 862 | |
|
863 | 863 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
864 | 864 | |
|
865 | 865 | if showprofile: |
|
866 | 866 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
867 | 867 | |
|
868 | 868 | counter += 1 |
|
869 | 869 | |
|
870 | 870 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
871 | 871 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
872 | 872 | save=False, figpath='./', figfile=None, show=True): |
|
873 | 873 | |
|
874 | 874 | """ |
|
875 | 875 | |
|
876 | 876 | Input: |
|
877 | 877 | dataOut : |
|
878 | 878 | id : |
|
879 | 879 | wintitle : |
|
880 | 880 | channelList : |
|
881 | 881 | showProfile : |
|
882 | 882 | xmin : None, |
|
883 | 883 | xmax : None, |
|
884 | 884 | zmin : None, |
|
885 | 885 | zmax : None |
|
886 | 886 | """ |
|
887 | 887 | |
|
888 | 888 | if cutHeight==None: |
|
889 | 889 | h=270 |
|
890 | 890 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
891 | 891 | cutHeight = dataOut.heightList[heightindex] |
|
892 | 892 | |
|
893 | 893 | factor = dataOut.normFactor |
|
894 | 894 | x = dataOut.abscissaList[:-1] |
|
895 | 895 | #y = dataOut.getHeiRange() |
|
896 | 896 | |
|
897 | 897 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
898 | 898 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
899 | 899 | avg = numpy.average(z, axis=1) |
|
900 | 900 | listChannels = z.shape[0] |
|
901 | 901 | |
|
902 | 902 | #Reconstruct Function |
|
903 | 903 | if fit==True: |
|
904 | 904 | groupArray = dataOut.groupList |
|
905 | 905 | listChannels = groupArray.reshape((groupArray.size)) |
|
906 | 906 | listChannels.sort() |
|
907 | 907 | spcFitLine = numpy.zeros(z.shape) |
|
908 | 908 | constants = dataOut.constants |
|
909 | 909 | |
|
910 | 910 | nGroups = groupArray.shape[0] |
|
911 | 911 | nChannels = groupArray.shape[1] |
|
912 | 912 | nProfiles = z.shape[1] |
|
913 | 913 | |
|
914 | 914 | for f in range(nGroups): |
|
915 | 915 | groupChann = groupArray[f,:] |
|
916 | 916 | p = dataOut.data_param[f,:,heightindex] |
|
917 | 917 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
918 | 918 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
919 | 919 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
920 | 920 | spcFitLine[groupChann,:] = fitLineAux |
|
921 | 921 | # spcFitLine = spcFitLine/factor |
|
922 | 922 | |
|
923 | 923 | z = z[listChannels,:] |
|
924 | 924 | spcFitLine = spcFitLine[listChannels,:] |
|
925 | 925 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
926 | 926 | |
|
927 | 927 | zdB = 10*numpy.log10(z) |
|
928 | 928 | #thisDatetime = dataOut.datatime |
|
929 | 929 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
930 | 930 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
931 | 931 | xlabel = "Velocity (m/s)" |
|
932 | 932 | ylabel = "Spectrum" |
|
933 | 933 | |
|
934 | 934 | if not self.__isConfig: |
|
935 | 935 | |
|
936 | 936 | nplots = listChannels.size |
|
937 | 937 | |
|
938 | 938 | self.setup(id=id, |
|
939 | 939 | nplots=nplots, |
|
940 | 940 | wintitle=wintitle, |
|
941 | 941 | showprofile=showprofile, |
|
942 | 942 | show=show) |
|
943 | 943 | |
|
944 | 944 | if xmin == None: xmin = numpy.nanmin(x) |
|
945 | 945 | if xmax == None: xmax = numpy.nanmax(x) |
|
946 | 946 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
947 | 947 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
948 | 948 | |
|
949 | 949 | self.__isConfig = True |
|
950 | 950 | |
|
951 | 951 | self.setWinTitle(title) |
|
952 | 952 | for i in range(self.nplots): |
|
953 | 953 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
954 |
title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i] |
|
|
954 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]) | |
|
955 | 955 | axes = self.axesList[i*self.__nsubplots] |
|
956 | 956 | if fit == False: |
|
957 | 957 | axes.pline(x, zdB[i,:], |
|
958 | 958 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
959 | 959 | xlabel=xlabel, ylabel=ylabel, title=title |
|
960 | 960 | ) |
|
961 | 961 | if fit == True: |
|
962 | 962 | fitline=spcFitLinedB[i,:] |
|
963 | 963 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
964 | 964 | legendlabels=['Data','Fitting'] |
|
965 | 965 | axes.pmultilineyaxis(x, y, |
|
966 | 966 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
967 | 967 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
968 | 968 | legendlabels=legendlabels, marker=None, |
|
969 | 969 | linestyle='solid', grid='both') |
|
970 | 970 | |
|
971 | 971 | self.draw() |
|
972 | 972 | |
|
973 | 973 | self.save(figpath=figpath, |
|
974 | 974 | figfile=figfile, |
|
975 | 975 | save=save, |
|
976 | 976 | ftp=ftp, |
|
977 | 977 | wr_period=wr_period, |
|
978 | 978 | thisDatetime=thisDatetime) |
|
979 | 979 | |
|
980 | 980 | |
|
981 | 981 | class EWDriftsPlot(Figure): |
|
982 | 982 | |
|
983 | 983 | __isConfig = None |
|
984 | 984 | __nsubplots = None |
|
985 | 985 | |
|
986 | 986 | WIDTHPROF = None |
|
987 | 987 | HEIGHTPROF = None |
|
988 | 988 | PREFIX = 'drift' |
|
989 | 989 | |
|
990 | 990 | def __init__(self): |
|
991 | 991 | |
|
992 | 992 | self.timerange = 2*60*60 |
|
993 | 993 | self.isConfig = False |
|
994 | 994 | self.__nsubplots = 1 |
|
995 | 995 | |
|
996 | 996 | self.WIDTH = 800 |
|
997 | 997 | self.HEIGHT = 150 |
|
998 | 998 | self.WIDTHPROF = 120 |
|
999 | 999 | self.HEIGHTPROF = 0 |
|
1000 | 1000 | self.counter_imagwr = 0 |
|
1001 | 1001 | |
|
1002 | 1002 | self.PLOT_CODE = EWDRIFT_CODE |
|
1003 | 1003 | |
|
1004 | 1004 | self.FTP_WEI = None |
|
1005 | 1005 | self.EXP_CODE = None |
|
1006 | 1006 | self.SUB_EXP_CODE = None |
|
1007 | 1007 | self.PLOT_POS = None |
|
1008 | 1008 | self.tmin = None |
|
1009 | 1009 | self.tmax = None |
|
1010 | 1010 | |
|
1011 | 1011 | self.xmin = None |
|
1012 | 1012 | self.xmax = None |
|
1013 | 1013 | |
|
1014 | 1014 | self.figfile = None |
|
1015 | 1015 | |
|
1016 | 1016 | def getSubplots(self): |
|
1017 | 1017 | |
|
1018 | 1018 | ncol = 1 |
|
1019 | 1019 | nrow = self.nplots |
|
1020 | 1020 | |
|
1021 | 1021 | return nrow, ncol |
|
1022 | 1022 | |
|
1023 | 1023 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1024 | 1024 | |
|
1025 | 1025 | self.__showprofile = showprofile |
|
1026 | 1026 | self.nplots = nplots |
|
1027 | 1027 | |
|
1028 | 1028 | ncolspan = 1 |
|
1029 | 1029 | colspan = 1 |
|
1030 | 1030 | |
|
1031 | 1031 | self.createFigure(id = id, |
|
1032 | 1032 | wintitle = wintitle, |
|
1033 | 1033 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1034 | 1034 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1035 | 1035 | show=show) |
|
1036 | 1036 | |
|
1037 | 1037 | nrow, ncol = self.getSubplots() |
|
1038 | 1038 | |
|
1039 | 1039 | counter = 0 |
|
1040 | 1040 | for y in range(nrow): |
|
1041 | 1041 | if counter >= self.nplots: |
|
1042 | 1042 | break |
|
1043 | 1043 | |
|
1044 | 1044 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1045 | 1045 | counter += 1 |
|
1046 | 1046 | |
|
1047 | 1047 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1048 | 1048 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1049 | 1049 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1050 | 1050 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1051 | 1051 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1052 | 1052 | server=None, folder=None, username=None, password=None, |
|
1053 | 1053 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1054 | 1054 | """ |
|
1055 | 1055 | |
|
1056 | 1056 | Input: |
|
1057 | 1057 | dataOut : |
|
1058 | 1058 | id : |
|
1059 | 1059 | wintitle : |
|
1060 | 1060 | channelList : |
|
1061 | 1061 | showProfile : |
|
1062 | 1062 | xmin : None, |
|
1063 | 1063 | xmax : None, |
|
1064 | 1064 | ymin : None, |
|
1065 | 1065 | ymax : None, |
|
1066 | 1066 | zmin : None, |
|
1067 | 1067 | zmax : None |
|
1068 | 1068 | """ |
|
1069 | 1069 | |
|
1070 | 1070 | if timerange is not None: |
|
1071 | 1071 | self.timerange = timerange |
|
1072 | 1072 | |
|
1073 | 1073 | tmin = None |
|
1074 | 1074 | tmax = None |
|
1075 | 1075 | |
|
1076 | 1076 | x = dataOut.getTimeRange1() |
|
1077 | 1077 | # y = dataOut.heightList |
|
1078 | 1078 | y = dataOut.heightList |
|
1079 | 1079 | |
|
1080 | 1080 | z = dataOut.data_output |
|
1081 | 1081 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1082 | 1082 | nplotsw = nplots |
|
1083 | 1083 | |
|
1084 | 1084 | #If there is a SNR function defined |
|
1085 | 1085 | if dataOut.data_SNR is not None: |
|
1086 | 1086 | nplots += 1 |
|
1087 | 1087 | SNR = dataOut.data_SNR |
|
1088 | 1088 | |
|
1089 | 1089 | if SNR_1: |
|
1090 | 1090 | SNR += 1 |
|
1091 | 1091 | |
|
1092 | 1092 | SNRavg = numpy.average(SNR, axis=0) |
|
1093 | 1093 | |
|
1094 | 1094 | SNRdB = 10*numpy.log10(SNR) |
|
1095 | 1095 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1096 | 1096 | |
|
1097 | 1097 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1098 | 1098 | |
|
1099 | 1099 | for i in range(nplotsw): |
|
1100 | 1100 | z[i,ind] = numpy.nan |
|
1101 | 1101 | |
|
1102 | 1102 | |
|
1103 | 1103 | showprofile = False |
|
1104 | 1104 | # thisDatetime = dataOut.datatime |
|
1105 | 1105 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1106 | 1106 | title = wintitle + " EW Drifts" |
|
1107 | 1107 | xlabel = "" |
|
1108 | 1108 | ylabel = "Height (Km)" |
|
1109 | 1109 | |
|
1110 | 1110 | if not self.__isConfig: |
|
1111 | 1111 | |
|
1112 | 1112 | self.setup(id=id, |
|
1113 | 1113 | nplots=nplots, |
|
1114 | 1114 | wintitle=wintitle, |
|
1115 | 1115 | showprofile=showprofile, |
|
1116 | 1116 | show=show) |
|
1117 | 1117 | |
|
1118 | 1118 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1119 | 1119 | |
|
1120 | 1120 | if ymin == None: ymin = numpy.nanmin(y) |
|
1121 | 1121 | if ymax == None: ymax = numpy.nanmax(y) |
|
1122 | 1122 | |
|
1123 | 1123 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1124 | 1124 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1125 | 1125 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1126 | 1126 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1127 | 1127 | |
|
1128 | 1128 | if dataOut.data_SNR is not None: |
|
1129 | 1129 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1130 | 1130 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1131 | 1131 | |
|
1132 | 1132 | self.FTP_WEI = ftp_wei |
|
1133 | 1133 | self.EXP_CODE = exp_code |
|
1134 | 1134 | self.SUB_EXP_CODE = sub_exp_code |
|
1135 | 1135 | self.PLOT_POS = plot_pos |
|
1136 | 1136 | |
|
1137 | 1137 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1138 | 1138 | self.__isConfig = True |
|
1139 | 1139 | |
|
1140 | 1140 | |
|
1141 | 1141 | self.setWinTitle(title) |
|
1142 | 1142 | |
|
1143 | 1143 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1144 | 1144 | x[1] = self.xmax |
|
1145 | 1145 | |
|
1146 | 1146 | strWind = ['Zonal','Vertical'] |
|
1147 | 1147 | strCb = 'Velocity (m/s)' |
|
1148 | 1148 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1149 | 1149 | zminVector = [zminZonal, zminVertical] |
|
1150 | 1150 | |
|
1151 | 1151 | for i in range(nplotsw): |
|
1152 | 1152 | |
|
1153 | 1153 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1154 | 1154 | axes = self.axesList[i*self.__nsubplots] |
|
1155 | 1155 | |
|
1156 | 1156 | z1 = z[i,:].reshape((1,-1)) |
|
1157 | 1157 | |
|
1158 | 1158 | axes.pcolorbuffer(x, y, z1, |
|
1159 | 1159 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1160 | 1160 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1161 | 1161 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1162 | 1162 | |
|
1163 | 1163 | if dataOut.data_SNR is not None: |
|
1164 | 1164 | i += 1 |
|
1165 | 1165 | if SNR_1: |
|
1166 | 1166 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1167 | 1167 | else: |
|
1168 | 1168 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1169 | 1169 | axes = self.axesList[i*self.__nsubplots] |
|
1170 | 1170 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1171 | 1171 | |
|
1172 | 1172 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1173 | 1173 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1174 | 1174 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1175 | 1175 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1176 | 1176 | |
|
1177 | 1177 | self.draw() |
|
1178 | 1178 | |
|
1179 | 1179 | if x[1] >= self.axesList[0].xmax: |
|
1180 | 1180 | self.counter_imagwr = wr_period |
|
1181 | 1181 | self.__isConfig = False |
|
1182 | 1182 | self.figfile = None |
|
1183 | 1183 | |
|
1184 | 1184 | |
|
1185 | 1185 | |
|
1186 | 1186 | |
|
1187 | 1187 | class PhasePlot(Figure): |
|
1188 | 1188 | |
|
1189 | 1189 | __isConfig = None |
|
1190 | 1190 | __nsubplots = None |
|
1191 | 1191 | |
|
1192 | 1192 | PREFIX = 'mphase' |
|
1193 | 1193 | |
|
1194 | 1194 | def __init__(self): |
|
1195 | 1195 | |
|
1196 | 1196 | self.timerange = 24*60*60 |
|
1197 | 1197 | self.__isConfig = False |
|
1198 | 1198 | self.__nsubplots = 1 |
|
1199 | 1199 | self.counter_imagwr = 0 |
|
1200 | 1200 | self.WIDTH = 600 |
|
1201 | 1201 | self.HEIGHT = 300 |
|
1202 | 1202 | self.WIDTHPROF = 120 |
|
1203 | 1203 | self.HEIGHTPROF = 0 |
|
1204 | 1204 | self.xdata = None |
|
1205 | 1205 | self.ydata = None |
|
1206 | 1206 | |
|
1207 | 1207 | self.PLOT_CODE = MPHASE_CODE |
|
1208 | 1208 | |
|
1209 | 1209 | self.FTP_WEI = None |
|
1210 | 1210 | self.EXP_CODE = None |
|
1211 | 1211 | self.SUB_EXP_CODE = None |
|
1212 | 1212 | self.PLOT_POS = None |
|
1213 | 1213 | |
|
1214 | 1214 | |
|
1215 | 1215 | self.filename_phase = None |
|
1216 | 1216 | |
|
1217 | 1217 | self.figfile = None |
|
1218 | 1218 | |
|
1219 | 1219 | def getSubplots(self): |
|
1220 | 1220 | |
|
1221 | 1221 | ncol = 1 |
|
1222 | 1222 | nrow = 1 |
|
1223 | 1223 | |
|
1224 | 1224 | return nrow, ncol |
|
1225 | 1225 | |
|
1226 | 1226 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1227 | 1227 | |
|
1228 | 1228 | self.__showprofile = showprofile |
|
1229 | 1229 | self.nplots = nplots |
|
1230 | 1230 | |
|
1231 | 1231 | ncolspan = 7 |
|
1232 | 1232 | colspan = 6 |
|
1233 | 1233 | self.__nsubplots = 2 |
|
1234 | 1234 | |
|
1235 | 1235 | self.createFigure(id = id, |
|
1236 | 1236 | wintitle = wintitle, |
|
1237 | 1237 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1238 | 1238 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1239 | 1239 | show=show) |
|
1240 | 1240 | |
|
1241 | 1241 | nrow, ncol = self.getSubplots() |
|
1242 | 1242 | |
|
1243 | 1243 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1244 | 1244 | |
|
1245 | 1245 | |
|
1246 | 1246 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1247 | 1247 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1248 | 1248 | timerange=None, |
|
1249 | 1249 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
1250 | 1250 | server=None, folder=None, username=None, password=None, |
|
1251 | 1251 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1252 | 1252 | |
|
1253 | 1253 | |
|
1254 | 1254 | tmin = None |
|
1255 | 1255 | tmax = None |
|
1256 | 1256 | x = dataOut.getTimeRange1() |
|
1257 | 1257 | y = dataOut.getHeiRange() |
|
1258 | 1258 | |
|
1259 | 1259 | |
|
1260 | 1260 | #thisDatetime = dataOut.datatime |
|
1261 | 1261 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1262 | 1262 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1263 | 1263 | xlabel = "Local Time" |
|
1264 | 1264 | ylabel = "Phase" |
|
1265 | 1265 | |
|
1266 | 1266 | |
|
1267 | 1267 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1268 | 1268 | phase_beacon = dataOut.data_output |
|
1269 | 1269 | |
|
1270 | 1270 | |
|
1271 | 1271 | if not self.__isConfig: |
|
1272 | 1272 | |
|
1273 | 1273 | self.nplots = phase_beacon.size |
|
1274 | 1274 | |
|
1275 | 1275 | self.setup(id=id, |
|
1276 | 1276 | nplots=self.nplots, |
|
1277 | 1277 | wintitle=wintitle, |
|
1278 | 1278 | showprofile=showprofile, |
|
1279 | 1279 | show=show) |
|
1280 | 1280 | |
|
1281 | 1281 | if timerange is not None: |
|
1282 | 1282 | self.timerange = timerange |
|
1283 | 1283 | |
|
1284 | 1284 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1285 | 1285 | |
|
1286 | 1286 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1287 | 1287 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1288 | 1288 | |
|
1289 | 1289 | self.FTP_WEI = ftp_wei |
|
1290 | 1290 | self.EXP_CODE = exp_code |
|
1291 | 1291 | self.SUB_EXP_CODE = sub_exp_code |
|
1292 | 1292 | self.PLOT_POS = plot_pos |
|
1293 | 1293 | |
|
1294 | 1294 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1295 | 1295 | self.__isConfig = True |
|
1296 | 1296 | self.figfile = figfile |
|
1297 | 1297 | self.xdata = numpy.array([]) |
|
1298 | 1298 | self.ydata = numpy.array([]) |
|
1299 | 1299 | |
|
1300 | 1300 | #open file beacon phase |
|
1301 | 1301 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1302 | 1302 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1303 | 1303 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1304 | 1304 | #self.save_phase(self.filename_phase) |
|
1305 | 1305 | |
|
1306 | 1306 | |
|
1307 | 1307 | #store data beacon phase |
|
1308 | 1308 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1309 | 1309 | |
|
1310 | 1310 | self.setWinTitle(title) |
|
1311 | 1311 | |
|
1312 | 1312 | |
|
1313 | 1313 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1314 | 1314 | |
|
1315 | 1315 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] |
|
1316 | 1316 | |
|
1317 | 1317 | axes = self.axesList[0] |
|
1318 | 1318 | |
|
1319 | 1319 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1320 | 1320 | |
|
1321 | 1321 | if len(self.ydata)==0: |
|
1322 | 1322 | self.ydata = phase_beacon.reshape(-1,1) |
|
1323 | 1323 | else: |
|
1324 | 1324 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1325 | 1325 | |
|
1326 | 1326 | |
|
1327 | 1327 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1328 | 1328 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1329 | 1329 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1330 | 1330 | XAxisAsTime=True, grid='both' |
|
1331 | 1331 | ) |
|
1332 | 1332 | |
|
1333 | 1333 | self.draw() |
|
1334 | 1334 | |
|
1335 | 1335 | if x[1] >= self.axesList[0].xmax: |
|
1336 | 1336 | self.counter_imagwr = wr_period |
|
1337 | 1337 | del self.xdata |
|
1338 | 1338 | del self.ydata |
|
1339 | 1339 | self.__isConfig = False |
|
1340 | 1340 | |
|
1341 | 1341 | if self.figfile == None: |
|
1342 | 1342 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1343 | 1343 | self.figfile = self.getFilename(name = str_datetime) |
|
1344 | 1344 | |
|
1345 | 1345 | if figpath != '': |
|
1346 | 1346 | self.counter_imagwr += 1 |
|
1347 | 1347 | if (self.counter_imagwr>=wr_period): |
|
1348 | 1348 | # store png plot to local folder |
|
1349 | 1349 | self.saveFigure(figpath, self.figfile) |
|
1350 | 1350 | # store png plot to FTP server according to RT-Web format |
|
1351 | 1351 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1352 | 1352 | ftp_filename = os.path.join(figpath, name) |
|
1353 | 1353 | self.saveFigure(figpath, ftp_filename) |
|
1354 | 1354 | self.counter_imagwr = 0 |
|
1355 | 1355 | self.figfile = None |
|
1356 | 1356 | |
|
1357 | 1357 | self.save(figpath=figpath, |
|
1358 | 1358 | figfile=figfile, |
|
1359 | 1359 | save=save, |
|
1360 | 1360 | ftp=ftp, |
|
1361 | 1361 | wr_period=wr_period, |
|
1362 | 1362 | thisDatetime=thisDatetime, |
|
1363 | 1363 | update_figfile=False) |
@@ -1,1334 +1,1334 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | from figure import Figure, isRealtime |
|
11 | 11 | from plotting_codes import * |
|
12 | 12 | |
|
13 | 13 | class SpectraPlot(Figure): |
|
14 | 14 | |
|
15 | 15 | isConfig = None |
|
16 | 16 | __nsubplots = None |
|
17 | 17 | |
|
18 | 18 | WIDTHPROF = None |
|
19 | 19 | HEIGHTPROF = None |
|
20 | 20 | PREFIX = 'spc' |
|
21 | 21 | |
|
22 | 22 | def __init__(self): |
|
23 | 23 | |
|
24 | 24 | self.isConfig = False |
|
25 | 25 | self.__nsubplots = 1 |
|
26 | 26 | |
|
27 | 27 | self.WIDTH = 280 |
|
28 | 28 | self.HEIGHT = 250 |
|
29 | 29 | self.WIDTHPROF = 120 |
|
30 | 30 | self.HEIGHTPROF = 0 |
|
31 | 31 | self.counter_imagwr = 0 |
|
32 | 32 | |
|
33 | 33 | self.PLOT_CODE = SPEC_CODE |
|
34 | 34 | |
|
35 | 35 | self.FTP_WEI = None |
|
36 | 36 | self.EXP_CODE = None |
|
37 | 37 | self.SUB_EXP_CODE = None |
|
38 | 38 | self.PLOT_POS = None |
|
39 | 39 | |
|
40 | 40 | self.__xfilter_ena = False |
|
41 | 41 | self.__yfilter_ena = False |
|
42 | 42 | |
|
43 | 43 | def getSubplots(self): |
|
44 | 44 | |
|
45 | 45 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
46 | 46 | nrow = int(self.nplots*1./ncol + 0.9) |
|
47 | 47 | |
|
48 | 48 | return nrow, ncol |
|
49 | 49 | |
|
50 | 50 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
51 | 51 | |
|
52 | 52 | self.__showprofile = showprofile |
|
53 | 53 | self.nplots = nplots |
|
54 | 54 | |
|
55 | 55 | ncolspan = 1 |
|
56 | 56 | colspan = 1 |
|
57 | 57 | if showprofile: |
|
58 | 58 | ncolspan = 3 |
|
59 | 59 | colspan = 2 |
|
60 | 60 | self.__nsubplots = 2 |
|
61 | 61 | |
|
62 | 62 | self.createFigure(id = id, |
|
63 | 63 | wintitle = wintitle, |
|
64 | 64 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
65 | 65 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
66 | 66 | show=show) |
|
67 | 67 | |
|
68 | 68 | nrow, ncol = self.getSubplots() |
|
69 | 69 | |
|
70 | 70 | counter = 0 |
|
71 | 71 | for y in range(nrow): |
|
72 | 72 | for x in range(ncol): |
|
73 | 73 | |
|
74 | 74 | if counter >= self.nplots: |
|
75 | 75 | break |
|
76 | 76 | |
|
77 | 77 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
78 | 78 | |
|
79 | 79 | if showprofile: |
|
80 | 80 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
81 | 81 | |
|
82 | 82 | counter += 1 |
|
83 | 83 | |
|
84 | 84 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
85 | 85 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
86 | 86 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
87 | 87 | server=None, folder=None, username=None, password=None, |
|
88 | 88 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
89 | 89 | |
|
90 | 90 | """ |
|
91 | 91 | |
|
92 | 92 | Input: |
|
93 | 93 | dataOut : |
|
94 | 94 | id : |
|
95 | 95 | wintitle : |
|
96 | 96 | channelList : |
|
97 | 97 | showProfile : |
|
98 | 98 | xmin : None, |
|
99 | 99 | xmax : None, |
|
100 | 100 | ymin : None, |
|
101 | 101 | ymax : None, |
|
102 | 102 | zmin : None, |
|
103 | 103 | zmax : None |
|
104 | 104 | """ |
|
105 | 105 | |
|
106 | 106 | if realtime: |
|
107 | 107 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
108 | 108 | print 'Skipping this plot function' |
|
109 | 109 | return |
|
110 | 110 | |
|
111 | 111 | if channelList == None: |
|
112 | 112 | channelIndexList = dataOut.channelIndexList |
|
113 | 113 | else: |
|
114 | 114 | channelIndexList = [] |
|
115 | 115 | for channel in channelList: |
|
116 | 116 | if channel not in dataOut.channelList: |
|
117 | 117 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
118 | 118 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
119 | 119 | |
|
120 | 120 | factor = dataOut.normFactor |
|
121 | 121 | |
|
122 | 122 | x = dataOut.getVelRange(1) |
|
123 | 123 | y = dataOut.getHeiRange() |
|
124 | 124 | |
|
125 | 125 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
126 | 126 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
127 | 127 | zdB = 10*numpy.log10(z) |
|
128 | 128 | |
|
129 | 129 | avg = numpy.average(z, axis=1) |
|
130 | 130 | avgdB = 10*numpy.log10(avg) |
|
131 | 131 | |
|
132 | 132 | noise = dataOut.getNoise()/factor |
|
133 | 133 | noisedB = 10*numpy.log10(noise) |
|
134 | 134 | |
|
135 | 135 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
136 | 136 | title = wintitle + " Spectra" |
|
137 | 137 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
138 | 138 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
139 | 139 | |
|
140 | 140 | xlabel = "Velocity (m/s)" |
|
141 | 141 | ylabel = "Range (Km)" |
|
142 | 142 | |
|
143 | 143 | if not self.isConfig: |
|
144 | 144 | |
|
145 | 145 | nplots = len(channelIndexList) |
|
146 | 146 | |
|
147 | 147 | self.setup(id=id, |
|
148 | 148 | nplots=nplots, |
|
149 | 149 | wintitle=wintitle, |
|
150 | 150 | showprofile=showprofile, |
|
151 | 151 | show=show) |
|
152 | 152 | |
|
153 | 153 | if xmin == None: xmin = numpy.nanmin(x) |
|
154 | 154 | if xmax == None: xmax = numpy.nanmax(x) |
|
155 | 155 | if ymin == None: ymin = numpy.nanmin(y) |
|
156 | 156 | if ymax == None: ymax = numpy.nanmax(y) |
|
157 | 157 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
158 | 158 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
159 | 159 | |
|
160 | 160 | self.FTP_WEI = ftp_wei |
|
161 | 161 | self.EXP_CODE = exp_code |
|
162 | 162 | self.SUB_EXP_CODE = sub_exp_code |
|
163 | 163 | self.PLOT_POS = plot_pos |
|
164 | 164 | |
|
165 | 165 | self.isConfig = True |
|
166 | 166 | |
|
167 | 167 | self.setWinTitle(title) |
|
168 | 168 | |
|
169 | 169 | for i in range(self.nplots): |
|
170 | 170 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
171 |
title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i] |
|
|
171 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime) | |
|
172 | 172 | if len(dataOut.beam.codeList) != 0: |
|
173 | 173 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[i]+1, noisedB[i], dataOut.beam.azimuthList[i], dataOut.beam.zenithList[i], str_datetime) |
|
174 | 174 | |
|
175 | 175 | axes = self.axesList[i*self.__nsubplots] |
|
176 | 176 | axes.pcolor(x, y, zdB[i,:,:], |
|
177 | 177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
178 | 178 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
179 | 179 | ticksize=9, cblabel='') |
|
180 | 180 | |
|
181 | 181 | if self.__showprofile: |
|
182 | 182 | axes = self.axesList[i*self.__nsubplots +1] |
|
183 | 183 | axes.pline(avgdB[i,:], y, |
|
184 | 184 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
185 | 185 | xlabel='dB', ylabel='', title='', |
|
186 | 186 | ytick_visible=False, |
|
187 | 187 | grid='x') |
|
188 | 188 | |
|
189 | 189 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
190 | 190 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
191 | 191 | |
|
192 | 192 | self.draw() |
|
193 | 193 | |
|
194 | 194 | if figfile == None: |
|
195 | 195 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
196 | 196 | name = str_datetime |
|
197 | 197 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
198 | 198 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
199 | 199 | figfile = self.getFilename(name) |
|
200 | 200 | |
|
201 | 201 | self.save(figpath=figpath, |
|
202 | 202 | figfile=figfile, |
|
203 | 203 | save=save, |
|
204 | 204 | ftp=ftp, |
|
205 | 205 | wr_period=wr_period, |
|
206 | 206 | thisDatetime=thisDatetime) |
|
207 | 207 | |
|
208 | 208 | class CrossSpectraPlot(Figure): |
|
209 | 209 | |
|
210 | 210 | isConfig = None |
|
211 | 211 | __nsubplots = None |
|
212 | 212 | |
|
213 | 213 | WIDTH = None |
|
214 | 214 | HEIGHT = None |
|
215 | 215 | WIDTHPROF = None |
|
216 | 216 | HEIGHTPROF = None |
|
217 | 217 | PREFIX = 'cspc' |
|
218 | 218 | |
|
219 | 219 | def __init__(self): |
|
220 | 220 | |
|
221 | 221 | self.isConfig = False |
|
222 | 222 | self.__nsubplots = 4 |
|
223 | 223 | self.counter_imagwr = 0 |
|
224 | 224 | self.WIDTH = 250 |
|
225 | 225 | self.HEIGHT = 250 |
|
226 | 226 | self.WIDTHPROF = 0 |
|
227 | 227 | self.HEIGHTPROF = 0 |
|
228 | 228 | |
|
229 | 229 | self.PLOT_CODE = CROSS_CODE |
|
230 | 230 | self.FTP_WEI = None |
|
231 | 231 | self.EXP_CODE = None |
|
232 | 232 | self.SUB_EXP_CODE = None |
|
233 | 233 | self.PLOT_POS = None |
|
234 | 234 | |
|
235 | 235 | def getSubplots(self): |
|
236 | 236 | |
|
237 | 237 | ncol = 4 |
|
238 | 238 | nrow = self.nplots |
|
239 | 239 | |
|
240 | 240 | return nrow, ncol |
|
241 | 241 | |
|
242 | 242 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
243 | 243 | |
|
244 | 244 | self.__showprofile = showprofile |
|
245 | 245 | self.nplots = nplots |
|
246 | 246 | |
|
247 | 247 | ncolspan = 1 |
|
248 | 248 | colspan = 1 |
|
249 | 249 | |
|
250 | 250 | self.createFigure(id = id, |
|
251 | 251 | wintitle = wintitle, |
|
252 | 252 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
253 | 253 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
254 | 254 | show=True) |
|
255 | 255 | |
|
256 | 256 | nrow, ncol = self.getSubplots() |
|
257 | 257 | |
|
258 | 258 | counter = 0 |
|
259 | 259 | for y in range(nrow): |
|
260 | 260 | for x in range(ncol): |
|
261 | 261 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
262 | 262 | |
|
263 | 263 | counter += 1 |
|
264 | 264 | |
|
265 | 265 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
266 | 266 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
267 | 267 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, |
|
268 | 268 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
269 | 269 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
270 | 270 | server=None, folder=None, username=None, password=None, |
|
271 | 271 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
272 | 272 | |
|
273 | 273 | """ |
|
274 | 274 | |
|
275 | 275 | Input: |
|
276 | 276 | dataOut : |
|
277 | 277 | id : |
|
278 | 278 | wintitle : |
|
279 | 279 | channelList : |
|
280 | 280 | showProfile : |
|
281 | 281 | xmin : None, |
|
282 | 282 | xmax : None, |
|
283 | 283 | ymin : None, |
|
284 | 284 | ymax : None, |
|
285 | 285 | zmin : None, |
|
286 | 286 | zmax : None |
|
287 | 287 | """ |
|
288 | 288 | |
|
289 | 289 | if pairsList == None: |
|
290 | 290 | pairsIndexList = dataOut.pairsIndexList |
|
291 | 291 | else: |
|
292 | 292 | pairsIndexList = [] |
|
293 | 293 | for pair in pairsList: |
|
294 | 294 | if pair not in dataOut.pairsList: |
|
295 | 295 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) |
|
296 | 296 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
297 | 297 | |
|
298 | 298 | if not pairsIndexList: |
|
299 | 299 | return |
|
300 | 300 | |
|
301 | 301 | if len(pairsIndexList) > 4: |
|
302 | 302 | pairsIndexList = pairsIndexList[0:4] |
|
303 | 303 | |
|
304 | 304 | factor = dataOut.normFactor |
|
305 | 305 | x = dataOut.getVelRange(1) |
|
306 | 306 | y = dataOut.getHeiRange() |
|
307 | 307 | z = dataOut.data_spc[:,:,:]/factor |
|
308 | 308 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
309 | 309 | |
|
310 | 310 | noise = dataOut.noise/factor |
|
311 | 311 | |
|
312 | 312 | zdB = 10*numpy.log10(z) |
|
313 | 313 | noisedB = 10*numpy.log10(noise) |
|
314 | 314 | |
|
315 | 315 | if coh_min == None: |
|
316 | 316 | coh_min = 0.0 |
|
317 | 317 | if coh_max == None: |
|
318 | 318 | coh_max = 1.0 |
|
319 | 319 | |
|
320 | 320 | if phase_min == None: |
|
321 | 321 | phase_min = -180 |
|
322 | 322 | if phase_max == None: |
|
323 | 323 | phase_max = 180 |
|
324 | 324 | |
|
325 | 325 | #thisDatetime = dataOut.datatime |
|
326 | 326 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
327 | 327 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
328 | 328 | xlabel = "Velocity (m/s)" |
|
329 | 329 | ylabel = "Range (Km)" |
|
330 | 330 | |
|
331 | 331 | if not self.isConfig: |
|
332 | 332 | |
|
333 | 333 | nplots = len(pairsIndexList) |
|
334 | 334 | |
|
335 | 335 | self.setup(id=id, |
|
336 | 336 | nplots=nplots, |
|
337 | 337 | wintitle=wintitle, |
|
338 | 338 | showprofile=False, |
|
339 | 339 | show=show) |
|
340 | 340 | |
|
341 | 341 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
342 | 342 | avgdB = 10*numpy.log10(avg) |
|
343 | 343 | |
|
344 | 344 | if xmin == None: xmin = numpy.nanmin(x) |
|
345 | 345 | if xmax == None: xmax = numpy.nanmax(x) |
|
346 | 346 | if ymin == None: ymin = numpy.nanmin(y) |
|
347 | 347 | if ymax == None: ymax = numpy.nanmax(y) |
|
348 | 348 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
349 | 349 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
350 | 350 | |
|
351 | 351 | self.FTP_WEI = ftp_wei |
|
352 | 352 | self.EXP_CODE = exp_code |
|
353 | 353 | self.SUB_EXP_CODE = sub_exp_code |
|
354 | 354 | self.PLOT_POS = plot_pos |
|
355 | 355 | |
|
356 | 356 | self.isConfig = True |
|
357 | 357 | |
|
358 | 358 | self.setWinTitle(title) |
|
359 | 359 | |
|
360 | 360 | for i in range(self.nplots): |
|
361 | 361 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
362 | 362 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
363 | 363 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
364 | 364 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
365 | 365 | axes0 = self.axesList[i*self.__nsubplots] |
|
366 | 366 | axes0.pcolor(x, y, zdB, |
|
367 | 367 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
368 | 368 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
369 | 369 | ticksize=9, colormap=power_cmap, cblabel='') |
|
370 | 370 | |
|
371 | 371 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
372 | 372 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
373 | 373 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
374 | 374 | axes0.pcolor(x, y, zdB, |
|
375 | 375 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
376 | 376 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
377 | 377 | ticksize=9, colormap=power_cmap, cblabel='') |
|
378 | 378 | |
|
379 | 379 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
380 | 380 | coherence = numpy.abs(coherenceComplex) |
|
381 | 381 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
382 | 382 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
383 | 383 | |
|
384 | 384 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
385 | 385 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
386 | 386 | axes0.pcolor(x, y, coherence, |
|
387 | 387 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, |
|
388 | 388 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
389 | 389 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
390 | 390 | |
|
391 | 391 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
392 | 392 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
393 | 393 | axes0.pcolor(x, y, phase, |
|
394 | 394 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
395 | 395 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
396 | 396 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
397 | 397 | |
|
398 | 398 | |
|
399 | 399 | |
|
400 | 400 | self.draw() |
|
401 | 401 | |
|
402 | 402 | self.save(figpath=figpath, |
|
403 | 403 | figfile=figfile, |
|
404 | 404 | save=save, |
|
405 | 405 | ftp=ftp, |
|
406 | 406 | wr_period=wr_period, |
|
407 | 407 | thisDatetime=thisDatetime) |
|
408 | 408 | |
|
409 | 409 | |
|
410 | 410 | class RTIPlot(Figure): |
|
411 | 411 | |
|
412 | 412 | __isConfig = None |
|
413 | 413 | __nsubplots = None |
|
414 | 414 | |
|
415 | 415 | WIDTHPROF = None |
|
416 | 416 | HEIGHTPROF = None |
|
417 | 417 | PREFIX = 'rti' |
|
418 | 418 | |
|
419 | 419 | def __init__(self): |
|
420 | 420 | |
|
421 | 421 | self.timerange = None |
|
422 | 422 | self.__isConfig = False |
|
423 | 423 | self.__nsubplots = 1 |
|
424 | 424 | |
|
425 | 425 | self.WIDTH = 800 |
|
426 | 426 | self.HEIGHT = 150 |
|
427 | 427 | self.WIDTHPROF = 120 |
|
428 | 428 | self.HEIGHTPROF = 0 |
|
429 | 429 | self.counter_imagwr = 0 |
|
430 | 430 | |
|
431 | 431 | self.PLOT_CODE = RTI_CODE |
|
432 | 432 | |
|
433 | 433 | self.FTP_WEI = None |
|
434 | 434 | self.EXP_CODE = None |
|
435 | 435 | self.SUB_EXP_CODE = None |
|
436 | 436 | self.PLOT_POS = None |
|
437 | 437 | self.tmin = None |
|
438 | 438 | self.tmax = None |
|
439 | 439 | |
|
440 | 440 | self.xmin = None |
|
441 | 441 | self.xmax = None |
|
442 | 442 | |
|
443 | 443 | self.figfile = None |
|
444 | 444 | |
|
445 | 445 | def getSubplots(self): |
|
446 | 446 | |
|
447 | 447 | ncol = 1 |
|
448 | 448 | nrow = self.nplots |
|
449 | 449 | |
|
450 | 450 | return nrow, ncol |
|
451 | 451 | |
|
452 | 452 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
453 | 453 | |
|
454 | 454 | self.__showprofile = showprofile |
|
455 | 455 | self.nplots = nplots |
|
456 | 456 | |
|
457 | 457 | ncolspan = 1 |
|
458 | 458 | colspan = 1 |
|
459 | 459 | if showprofile: |
|
460 | 460 | ncolspan = 7 |
|
461 | 461 | colspan = 6 |
|
462 | 462 | self.__nsubplots = 2 |
|
463 | 463 | |
|
464 | 464 | self.createFigure(id = id, |
|
465 | 465 | wintitle = wintitle, |
|
466 | 466 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
467 | 467 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
468 | 468 | show=show) |
|
469 | 469 | |
|
470 | 470 | nrow, ncol = self.getSubplots() |
|
471 | 471 | |
|
472 | 472 | counter = 0 |
|
473 | 473 | for y in range(nrow): |
|
474 | 474 | for x in range(ncol): |
|
475 | 475 | |
|
476 | 476 | if counter >= self.nplots: |
|
477 | 477 | break |
|
478 | 478 | |
|
479 | 479 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
480 | 480 | |
|
481 | 481 | if showprofile: |
|
482 | 482 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
483 | 483 | |
|
484 | 484 | counter += 1 |
|
485 | 485 | |
|
486 | 486 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
487 | 487 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
488 | 488 | timerange=None, |
|
489 | 489 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
490 | 490 | server=None, folder=None, username=None, password=None, |
|
491 | 491 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
492 | 492 | |
|
493 | 493 | """ |
|
494 | 494 | |
|
495 | 495 | Input: |
|
496 | 496 | dataOut : |
|
497 | 497 | id : |
|
498 | 498 | wintitle : |
|
499 | 499 | channelList : |
|
500 | 500 | showProfile : |
|
501 | 501 | xmin : None, |
|
502 | 502 | xmax : None, |
|
503 | 503 | ymin : None, |
|
504 | 504 | ymax : None, |
|
505 | 505 | zmin : None, |
|
506 | 506 | zmax : None |
|
507 | 507 | """ |
|
508 | 508 | |
|
509 | 509 | if channelList == None: |
|
510 | 510 | channelIndexList = dataOut.channelIndexList |
|
511 | 511 | else: |
|
512 | 512 | channelIndexList = [] |
|
513 | 513 | for channel in channelList: |
|
514 | 514 | if channel not in dataOut.channelList: |
|
515 | 515 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
516 | 516 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
517 | 517 | |
|
518 | 518 | # if timerange != None: |
|
519 | 519 | # self.timerange = timerange |
|
520 | 520 | |
|
521 | 521 | #tmin = None |
|
522 | 522 | #tmax = None |
|
523 | 523 | factor = dataOut.normFactor |
|
524 | 524 | x = dataOut.getTimeRange() |
|
525 | 525 | y = dataOut.getHeiRange() |
|
526 | 526 | |
|
527 | 527 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
528 | 528 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
529 | 529 | avg = numpy.average(z, axis=1) |
|
530 | 530 | |
|
531 | 531 | avgdB = 10.*numpy.log10(avg) |
|
532 | 532 | |
|
533 | 533 | |
|
534 | 534 | # thisDatetime = dataOut.datatime |
|
535 | 535 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
536 | 536 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
537 | 537 | xlabel = "" |
|
538 | 538 | ylabel = "Range (Km)" |
|
539 | 539 | |
|
540 | 540 | if not self.__isConfig: |
|
541 | 541 | |
|
542 | 542 | nplots = len(channelIndexList) |
|
543 | 543 | |
|
544 | 544 | self.setup(id=id, |
|
545 | 545 | nplots=nplots, |
|
546 | 546 | wintitle=wintitle, |
|
547 | 547 | showprofile=showprofile, |
|
548 | 548 | show=show) |
|
549 | 549 | |
|
550 | 550 | if timerange != None: |
|
551 | 551 | self.timerange = timerange |
|
552 | 552 | |
|
553 | 553 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
554 | 554 | |
|
555 | 555 | noise = dataOut.noise/factor |
|
556 | 556 | noisedB = 10*numpy.log10(noise) |
|
557 | 557 | |
|
558 | 558 | if ymin == None: ymin = numpy.nanmin(y) |
|
559 | 559 | if ymax == None: ymax = numpy.nanmax(y) |
|
560 | 560 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
561 | 561 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
562 | 562 | |
|
563 | 563 | self.FTP_WEI = ftp_wei |
|
564 | 564 | self.EXP_CODE = exp_code |
|
565 | 565 | self.SUB_EXP_CODE = sub_exp_code |
|
566 | 566 | self.PLOT_POS = plot_pos |
|
567 | 567 | |
|
568 | 568 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
569 | 569 | self.__isConfig = True |
|
570 | 570 | self.figfile = figfile |
|
571 | 571 | |
|
572 | 572 | self.setWinTitle(title) |
|
573 | 573 | |
|
574 | 574 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
575 | 575 | x[1] = self.xmax |
|
576 | 576 | |
|
577 | 577 | for i in range(self.nplots): |
|
578 |
title = "Channel %d: %s" %(dataOut.channelList[i] |
|
|
578 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
579 | 579 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
580 | 580 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
581 | 581 | axes = self.axesList[i*self.__nsubplots] |
|
582 | 582 | zdB = avgdB[i].reshape((1,-1)) |
|
583 | 583 | axes.pcolorbuffer(x, y, zdB, |
|
584 | 584 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
585 | 585 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
586 | 586 | ticksize=9, cblabel='', cbsize="1%") |
|
587 | 587 | |
|
588 | 588 | if self.__showprofile: |
|
589 | 589 | axes = self.axesList[i*self.__nsubplots +1] |
|
590 | 590 | axes.pline(avgdB[i], y, |
|
591 | 591 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
592 | 592 | xlabel='dB', ylabel='', title='', |
|
593 | 593 | ytick_visible=False, |
|
594 | 594 | grid='x') |
|
595 | 595 | |
|
596 | 596 | self.draw() |
|
597 | 597 | |
|
598 | 598 | if x[1] >= self.axesList[0].xmax: |
|
599 | 599 | self.counter_imagwr = wr_period |
|
600 | 600 | self.__isConfig = False |
|
601 | 601 | self.figfile = None |
|
602 | 602 | |
|
603 | 603 | self.save(figpath=figpath, |
|
604 | 604 | figfile=figfile, |
|
605 | 605 | save=save, |
|
606 | 606 | ftp=ftp, |
|
607 | 607 | wr_period=wr_period, |
|
608 | 608 | thisDatetime=thisDatetime, |
|
609 | 609 | update_figfile=False) |
|
610 | 610 | |
|
611 | 611 | class CoherenceMap(Figure): |
|
612 | 612 | isConfig = None |
|
613 | 613 | __nsubplots = None |
|
614 | 614 | |
|
615 | 615 | WIDTHPROF = None |
|
616 | 616 | HEIGHTPROF = None |
|
617 | 617 | PREFIX = 'cmap' |
|
618 | 618 | |
|
619 | 619 | def __init__(self): |
|
620 | 620 | self.timerange = 2*60*60 |
|
621 | 621 | self.isConfig = False |
|
622 | 622 | self.__nsubplots = 1 |
|
623 | 623 | |
|
624 | 624 | self.WIDTH = 800 |
|
625 | 625 | self.HEIGHT = 150 |
|
626 | 626 | self.WIDTHPROF = 120 |
|
627 | 627 | self.HEIGHTPROF = 0 |
|
628 | 628 | self.counter_imagwr = 0 |
|
629 | 629 | |
|
630 | 630 | self.PLOT_CODE = COH_CODE |
|
631 | 631 | |
|
632 | 632 | self.FTP_WEI = None |
|
633 | 633 | self.EXP_CODE = None |
|
634 | 634 | self.SUB_EXP_CODE = None |
|
635 | 635 | self.PLOT_POS = None |
|
636 | 636 | self.counter_imagwr = 0 |
|
637 | 637 | |
|
638 | 638 | self.xmin = None |
|
639 | 639 | self.xmax = None |
|
640 | 640 | |
|
641 | 641 | def getSubplots(self): |
|
642 | 642 | ncol = 1 |
|
643 | 643 | nrow = self.nplots*2 |
|
644 | 644 | |
|
645 | 645 | return nrow, ncol |
|
646 | 646 | |
|
647 | 647 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
648 | 648 | self.__showprofile = showprofile |
|
649 | 649 | self.nplots = nplots |
|
650 | 650 | |
|
651 | 651 | ncolspan = 1 |
|
652 | 652 | colspan = 1 |
|
653 | 653 | if showprofile: |
|
654 | 654 | ncolspan = 7 |
|
655 | 655 | colspan = 6 |
|
656 | 656 | self.__nsubplots = 2 |
|
657 | 657 | |
|
658 | 658 | self.createFigure(id = id, |
|
659 | 659 | wintitle = wintitle, |
|
660 | 660 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
661 | 661 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
662 | 662 | show=True) |
|
663 | 663 | |
|
664 | 664 | nrow, ncol = self.getSubplots() |
|
665 | 665 | |
|
666 | 666 | for y in range(nrow): |
|
667 | 667 | for x in range(ncol): |
|
668 | 668 | |
|
669 | 669 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
670 | 670 | |
|
671 | 671 | if showprofile: |
|
672 | 672 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
673 | 673 | |
|
674 | 674 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
675 | 675 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
676 | 676 | timerange=None, |
|
677 | 677 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
678 | 678 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
679 | 679 | server=None, folder=None, username=None, password=None, |
|
680 | 680 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
681 | 681 | |
|
682 | 682 | if pairsList == None: |
|
683 | 683 | pairsIndexList = dataOut.pairsIndexList |
|
684 | 684 | else: |
|
685 | 685 | pairsIndexList = [] |
|
686 | 686 | for pair in pairsList: |
|
687 | 687 | if pair not in dataOut.pairsList: |
|
688 | 688 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
689 | 689 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
690 | 690 | |
|
691 | 691 | if pairsIndexList == []: |
|
692 | 692 | return |
|
693 | 693 | |
|
694 | 694 | if len(pairsIndexList) > 4: |
|
695 | 695 | pairsIndexList = pairsIndexList[0:4] |
|
696 | 696 | |
|
697 | 697 | # tmin = None |
|
698 | 698 | # tmax = None |
|
699 | 699 | x = dataOut.getTimeRange() |
|
700 | 700 | y = dataOut.getHeiRange() |
|
701 | 701 | |
|
702 | 702 | #thisDatetime = dataOut.datatime |
|
703 | 703 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
704 | 704 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
705 | 705 | xlabel = "" |
|
706 | 706 | ylabel = "Range (Km)" |
|
707 | 707 | |
|
708 | 708 | if not self.isConfig: |
|
709 | 709 | nplots = len(pairsIndexList) |
|
710 | 710 | self.setup(id=id, |
|
711 | 711 | nplots=nplots, |
|
712 | 712 | wintitle=wintitle, |
|
713 | 713 | showprofile=showprofile, |
|
714 | 714 | show=show) |
|
715 | 715 | |
|
716 | 716 | if timerange != None: |
|
717 | 717 | self.timerange = timerange |
|
718 | 718 | |
|
719 | 719 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
720 | 720 | |
|
721 | 721 | if ymin == None: ymin = numpy.nanmin(y) |
|
722 | 722 | if ymax == None: ymax = numpy.nanmax(y) |
|
723 | 723 | if zmin == None: zmin = 0. |
|
724 | 724 | if zmax == None: zmax = 1. |
|
725 | 725 | |
|
726 | 726 | self.FTP_WEI = ftp_wei |
|
727 | 727 | self.EXP_CODE = exp_code |
|
728 | 728 | self.SUB_EXP_CODE = sub_exp_code |
|
729 | 729 | self.PLOT_POS = plot_pos |
|
730 | 730 | |
|
731 | 731 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
732 | 732 | |
|
733 | 733 | self.isConfig = True |
|
734 | 734 | |
|
735 | 735 | self.setWinTitle(title) |
|
736 | 736 | |
|
737 | 737 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
738 | 738 | x[1] = self.xmax |
|
739 | 739 | |
|
740 | 740 | for i in range(self.nplots): |
|
741 | 741 | |
|
742 | 742 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
743 | 743 | |
|
744 | 744 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
745 | 745 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
746 | 746 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
747 | 747 | |
|
748 | 748 | |
|
749 | 749 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
750 | 750 | coherence = numpy.abs(avgcoherenceComplex) |
|
751 | 751 | |
|
752 | 752 | z = coherence.reshape((1,-1)) |
|
753 | 753 | |
|
754 | 754 | counter = 0 |
|
755 | 755 | |
|
756 | 756 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
757 | 757 | axes = self.axesList[i*self.__nsubplots*2] |
|
758 | 758 | axes.pcolorbuffer(x, y, z, |
|
759 | 759 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
760 | 760 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
761 | 761 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
762 | 762 | |
|
763 | 763 | if self.__showprofile: |
|
764 | 764 | counter += 1 |
|
765 | 765 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
766 | 766 | axes.pline(coherence, y, |
|
767 | 767 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
768 | 768 | xlabel='', ylabel='', title='', ticksize=7, |
|
769 | 769 | ytick_visible=False, nxticks=5, |
|
770 | 770 | grid='x') |
|
771 | 771 | |
|
772 | 772 | counter += 1 |
|
773 | 773 | |
|
774 | 774 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
775 | 775 | |
|
776 | 776 | z = phase.reshape((1,-1)) |
|
777 | 777 | |
|
778 | 778 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
779 | 779 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
780 | 780 | axes.pcolorbuffer(x, y, z, |
|
781 | 781 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
782 | 782 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
783 | 783 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
784 | 784 | |
|
785 | 785 | if self.__showprofile: |
|
786 | 786 | counter += 1 |
|
787 | 787 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
788 | 788 | axes.pline(phase, y, |
|
789 | 789 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
790 | 790 | xlabel='', ylabel='', title='', ticksize=7, |
|
791 | 791 | ytick_visible=False, nxticks=4, |
|
792 | 792 | grid='x') |
|
793 | 793 | |
|
794 | 794 | self.draw() |
|
795 | 795 | |
|
796 | 796 | if x[1] >= self.axesList[0].xmax: |
|
797 | 797 | self.counter_imagwr = wr_period |
|
798 | 798 | self.__isConfig = False |
|
799 | 799 | self.figfile = None |
|
800 | 800 | |
|
801 | 801 | self.save(figpath=figpath, |
|
802 | 802 | figfile=figfile, |
|
803 | 803 | save=save, |
|
804 | 804 | ftp=ftp, |
|
805 | 805 | wr_period=wr_period, |
|
806 | 806 | thisDatetime=thisDatetime, |
|
807 | 807 | update_figfile=False) |
|
808 | 808 | |
|
809 | 809 | class PowerProfilePlot(Figure): |
|
810 | 810 | |
|
811 | 811 | isConfig = None |
|
812 | 812 | __nsubplots = None |
|
813 | 813 | |
|
814 | 814 | WIDTHPROF = None |
|
815 | 815 | HEIGHTPROF = None |
|
816 | 816 | PREFIX = 'spcprofile' |
|
817 | 817 | |
|
818 | 818 | def __init__(self): |
|
819 | 819 | self.isConfig = False |
|
820 | 820 | self.__nsubplots = 1 |
|
821 | 821 | |
|
822 | 822 | self.PLOT_CODE = POWER_CODE |
|
823 | 823 | |
|
824 | 824 | self.WIDTH = 300 |
|
825 | 825 | self.HEIGHT = 500 |
|
826 | 826 | self.counter_imagwr = 0 |
|
827 | 827 | |
|
828 | 828 | def getSubplots(self): |
|
829 | 829 | ncol = 1 |
|
830 | 830 | nrow = 1 |
|
831 | 831 | |
|
832 | 832 | return nrow, ncol |
|
833 | 833 | |
|
834 | 834 | def setup(self, id, nplots, wintitle, show): |
|
835 | 835 | |
|
836 | 836 | self.nplots = nplots |
|
837 | 837 | |
|
838 | 838 | ncolspan = 1 |
|
839 | 839 | colspan = 1 |
|
840 | 840 | |
|
841 | 841 | self.createFigure(id = id, |
|
842 | 842 | wintitle = wintitle, |
|
843 | 843 | widthplot = self.WIDTH, |
|
844 | 844 | heightplot = self.HEIGHT, |
|
845 | 845 | show=show) |
|
846 | 846 | |
|
847 | 847 | nrow, ncol = self.getSubplots() |
|
848 | 848 | |
|
849 | 849 | counter = 0 |
|
850 | 850 | for y in range(nrow): |
|
851 | 851 | for x in range(ncol): |
|
852 | 852 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
853 | 853 | |
|
854 | 854 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
855 | 855 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
856 | 856 | save=False, figpath='./', figfile=None, show=True, |
|
857 | 857 | ftp=False, wr_period=1, server=None, |
|
858 | 858 | folder=None, username=None, password=None): |
|
859 | 859 | |
|
860 | 860 | |
|
861 | 861 | if channelList == None: |
|
862 | 862 | channelIndexList = dataOut.channelIndexList |
|
863 | 863 | channelList = dataOut.channelList |
|
864 | 864 | else: |
|
865 | 865 | channelIndexList = [] |
|
866 | 866 | for channel in channelList: |
|
867 | 867 | if channel not in dataOut.channelList: |
|
868 | 868 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
869 | 869 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
870 | 870 | |
|
871 | 871 | factor = dataOut.normFactor |
|
872 | 872 | |
|
873 | 873 | y = dataOut.getHeiRange() |
|
874 | 874 | |
|
875 | 875 | #for voltage |
|
876 | 876 | if dataOut.type == 'Voltage': |
|
877 | 877 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
878 | 878 | x = x.real |
|
879 | 879 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
880 | 880 | |
|
881 | 881 | #for spectra |
|
882 | 882 | if dataOut.type == 'Spectra': |
|
883 | 883 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
884 | 884 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
885 | 885 | x = numpy.average(x, axis=1) |
|
886 | 886 | |
|
887 | 887 | |
|
888 | 888 | xdB = 10*numpy.log10(x) |
|
889 | 889 | |
|
890 | 890 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
891 | 891 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
892 | 892 | xlabel = "dB" |
|
893 | 893 | ylabel = "Range (Km)" |
|
894 | 894 | |
|
895 | 895 | if not self.isConfig: |
|
896 | 896 | |
|
897 | 897 | nplots = 1 |
|
898 | 898 | |
|
899 | 899 | self.setup(id=id, |
|
900 | 900 | nplots=nplots, |
|
901 | 901 | wintitle=wintitle, |
|
902 | 902 | show=show) |
|
903 | 903 | |
|
904 | 904 | if ymin == None: ymin = numpy.nanmin(y) |
|
905 | 905 | if ymax == None: ymax = numpy.nanmax(y) |
|
906 | 906 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
907 | 907 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
908 | 908 | |
|
909 | 909 | self.__isConfig = True |
|
910 | 910 | |
|
911 | 911 | self.setWinTitle(title) |
|
912 | 912 | |
|
913 | 913 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
914 | 914 | axes = self.axesList[0] |
|
915 | 915 | |
|
916 | 916 | legendlabels = ["channel %d"%x for x in channelList] |
|
917 | 917 | axes.pmultiline(xdB, y, |
|
918 | 918 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
919 | 919 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
920 | 920 | ytick_visible=True, nxticks=5, |
|
921 | 921 | grid='x') |
|
922 | 922 | |
|
923 | 923 | self.draw() |
|
924 | 924 | |
|
925 | 925 | self.save(figpath=figpath, |
|
926 | 926 | figfile=figfile, |
|
927 | 927 | save=save, |
|
928 | 928 | ftp=ftp, |
|
929 | 929 | wr_period=wr_period, |
|
930 | 930 | thisDatetime=thisDatetime) |
|
931 | 931 | |
|
932 | 932 | class Noise(Figure): |
|
933 | 933 | |
|
934 | 934 | isConfig = None |
|
935 | 935 | __nsubplots = None |
|
936 | 936 | |
|
937 | 937 | PREFIX = 'noise' |
|
938 | 938 | |
|
939 | 939 | def __init__(self): |
|
940 | 940 | |
|
941 | 941 | self.timerange = 24*60*60 |
|
942 | 942 | self.isConfig = False |
|
943 | 943 | self.__nsubplots = 1 |
|
944 | 944 | self.counter_imagwr = 0 |
|
945 | 945 | self.WIDTH = 600 |
|
946 | 946 | self.HEIGHT = 300 |
|
947 | 947 | self.WIDTHPROF = 120 |
|
948 | 948 | self.HEIGHTPROF = 0 |
|
949 | 949 | self.xdata = None |
|
950 | 950 | self.ydata = None |
|
951 | 951 | |
|
952 | 952 | self.PLOT_CODE = NOISE_CODE |
|
953 | 953 | |
|
954 | 954 | self.FTP_WEI = None |
|
955 | 955 | self.EXP_CODE = None |
|
956 | 956 | self.SUB_EXP_CODE = None |
|
957 | 957 | self.PLOT_POS = None |
|
958 | 958 | self.figfile = None |
|
959 | 959 | |
|
960 | 960 | self.xmin = None |
|
961 | 961 | self.xmax = None |
|
962 | 962 | |
|
963 | 963 | def getSubplots(self): |
|
964 | 964 | |
|
965 | 965 | ncol = 1 |
|
966 | 966 | nrow = 1 |
|
967 | 967 | |
|
968 | 968 | return nrow, ncol |
|
969 | 969 | |
|
970 | 970 | def openfile(self, filename): |
|
971 | 971 | dirname = os.path.dirname(filename) |
|
972 | 972 | |
|
973 | 973 | if not os.path.exists(dirname): |
|
974 | 974 | os.mkdir(dirname) |
|
975 | 975 | |
|
976 | 976 | f = open(filename,'w+') |
|
977 | 977 | f.write('\n\n') |
|
978 | 978 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
979 | 979 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
980 | 980 | f.close() |
|
981 | 981 | |
|
982 | 982 | def save_data(self, filename_phase, data, data_datetime): |
|
983 | 983 | |
|
984 | 984 | f=open(filename_phase,'a') |
|
985 | 985 | |
|
986 | 986 | timetuple_data = data_datetime.timetuple() |
|
987 | 987 | day = str(timetuple_data.tm_mday) |
|
988 | 988 | month = str(timetuple_data.tm_mon) |
|
989 | 989 | year = str(timetuple_data.tm_year) |
|
990 | 990 | hour = str(timetuple_data.tm_hour) |
|
991 | 991 | minute = str(timetuple_data.tm_min) |
|
992 | 992 | second = str(timetuple_data.tm_sec) |
|
993 | 993 | |
|
994 | 994 | data_msg = '' |
|
995 | 995 | for i in range(len(data)): |
|
996 | 996 | data_msg += str(data[i]) + ' ' |
|
997 | 997 | |
|
998 | 998 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
999 | 999 | f.close() |
|
1000 | 1000 | |
|
1001 | 1001 | |
|
1002 | 1002 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1003 | 1003 | |
|
1004 | 1004 | self.__showprofile = showprofile |
|
1005 | 1005 | self.nplots = nplots |
|
1006 | 1006 | |
|
1007 | 1007 | ncolspan = 7 |
|
1008 | 1008 | colspan = 6 |
|
1009 | 1009 | self.__nsubplots = 2 |
|
1010 | 1010 | |
|
1011 | 1011 | self.createFigure(id = id, |
|
1012 | 1012 | wintitle = wintitle, |
|
1013 | 1013 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1014 | 1014 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1015 | 1015 | show=show) |
|
1016 | 1016 | |
|
1017 | 1017 | nrow, ncol = self.getSubplots() |
|
1018 | 1018 | |
|
1019 | 1019 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1020 | 1020 | |
|
1021 | 1021 | |
|
1022 | 1022 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1023 | 1023 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1024 | 1024 | timerange=None, |
|
1025 | 1025 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1026 | 1026 | server=None, folder=None, username=None, password=None, |
|
1027 | 1027 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1028 | 1028 | |
|
1029 | 1029 | if channelList == None: |
|
1030 | 1030 | channelIndexList = dataOut.channelIndexList |
|
1031 | 1031 | channelList = dataOut.channelList |
|
1032 | 1032 | else: |
|
1033 | 1033 | channelIndexList = [] |
|
1034 | 1034 | for channel in channelList: |
|
1035 | 1035 | if channel not in dataOut.channelList: |
|
1036 | 1036 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1037 | 1037 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1038 | 1038 | |
|
1039 | 1039 | x = dataOut.getTimeRange() |
|
1040 | 1040 | #y = dataOut.getHeiRange() |
|
1041 | 1041 | factor = dataOut.normFactor |
|
1042 | 1042 | noise = dataOut.noise/factor |
|
1043 | 1043 | noisedB = 10*numpy.log10(noise) |
|
1044 | 1044 | |
|
1045 | 1045 | #thisDatetime = dataOut.datatime |
|
1046 | 1046 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1047 | 1047 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1048 | 1048 | xlabel = "" |
|
1049 | 1049 | ylabel = "Intensity (dB)" |
|
1050 | 1050 | |
|
1051 | 1051 | if not self.isConfig: |
|
1052 | 1052 | |
|
1053 | 1053 | nplots = 1 |
|
1054 | 1054 | |
|
1055 | 1055 | self.setup(id=id, |
|
1056 | 1056 | nplots=nplots, |
|
1057 | 1057 | wintitle=wintitle, |
|
1058 | 1058 | showprofile=showprofile, |
|
1059 | 1059 | show=show) |
|
1060 | 1060 | |
|
1061 | 1061 | if timerange != None: |
|
1062 | 1062 | self.timerange = timerange |
|
1063 | 1063 | |
|
1064 | 1064 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1065 | 1065 | |
|
1066 | 1066 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1067 | 1067 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1068 | 1068 | |
|
1069 | 1069 | self.FTP_WEI = ftp_wei |
|
1070 | 1070 | self.EXP_CODE = exp_code |
|
1071 | 1071 | self.SUB_EXP_CODE = sub_exp_code |
|
1072 | 1072 | self.PLOT_POS = plot_pos |
|
1073 | 1073 | |
|
1074 | 1074 | |
|
1075 | 1075 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1076 | 1076 | self.isConfig = True |
|
1077 | 1077 | self.figfile = figfile |
|
1078 | 1078 | self.xdata = numpy.array([]) |
|
1079 | 1079 | self.ydata = numpy.array([]) |
|
1080 | 1080 | |
|
1081 | 1081 | #open file beacon phase |
|
1082 | 1082 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1083 | 1083 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1084 | 1084 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1085 | 1085 | |
|
1086 | 1086 | self.setWinTitle(title) |
|
1087 | 1087 | |
|
1088 | 1088 | |
|
1089 | 1089 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1090 | 1090 | |
|
1091 |
legendlabels = ["channel %d"%(idchannel |
|
|
1091 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] | |
|
1092 | 1092 | axes = self.axesList[0] |
|
1093 | 1093 | |
|
1094 | 1094 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1095 | 1095 | |
|
1096 | 1096 | if len(self.ydata)==0: |
|
1097 | 1097 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1098 | 1098 | else: |
|
1099 | 1099 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1100 | 1100 | |
|
1101 | 1101 | |
|
1102 | 1102 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1103 | 1103 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1104 | 1104 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1105 | 1105 | XAxisAsTime=True, grid='both' |
|
1106 | 1106 | ) |
|
1107 | 1107 | |
|
1108 | 1108 | self.draw() |
|
1109 | 1109 | |
|
1110 | 1110 | if x[1] >= self.axesList[0].xmax: |
|
1111 | 1111 | self.counter_imagwr = wr_period |
|
1112 | 1112 | del self.xdata |
|
1113 | 1113 | del self.ydata |
|
1114 | 1114 | self.__isConfig = False |
|
1115 | 1115 | self.figfile = None |
|
1116 | 1116 | |
|
1117 | 1117 | self.save(figpath=figpath, |
|
1118 | 1118 | figfile=figfile, |
|
1119 | 1119 | save=save, |
|
1120 | 1120 | ftp=ftp, |
|
1121 | 1121 | wr_period=wr_period, |
|
1122 | 1122 | thisDatetime=thisDatetime, |
|
1123 | 1123 | update_figfile=False) |
|
1124 | 1124 | |
|
1125 | 1125 | #store data beacon phase |
|
1126 | 1126 | if save: |
|
1127 | 1127 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1128 | 1128 | |
|
1129 | 1129 | class BeaconPhase(Figure): |
|
1130 | 1130 | |
|
1131 | 1131 | __isConfig = None |
|
1132 | 1132 | __nsubplots = None |
|
1133 | 1133 | |
|
1134 | 1134 | PREFIX = 'beacon_phase' |
|
1135 | 1135 | |
|
1136 | 1136 | def __init__(self): |
|
1137 | 1137 | |
|
1138 | 1138 | self.timerange = 24*60*60 |
|
1139 | 1139 | self.__isConfig = False |
|
1140 | 1140 | self.__nsubplots = 1 |
|
1141 | 1141 | self.counter_imagwr = 0 |
|
1142 | 1142 | self.WIDTH = 600 |
|
1143 | 1143 | self.HEIGHT = 300 |
|
1144 | 1144 | self.WIDTHPROF = 120 |
|
1145 | 1145 | self.HEIGHTPROF = 0 |
|
1146 | 1146 | self.xdata = None |
|
1147 | 1147 | self.ydata = None |
|
1148 | 1148 | |
|
1149 | 1149 | self.PLOT_CODE = BEACON_CODE |
|
1150 | 1150 | |
|
1151 | 1151 | self.FTP_WEI = None |
|
1152 | 1152 | self.EXP_CODE = None |
|
1153 | 1153 | self.SUB_EXP_CODE = None |
|
1154 | 1154 | self.PLOT_POS = None |
|
1155 | 1155 | |
|
1156 | 1156 | self.filename_phase = None |
|
1157 | 1157 | |
|
1158 | 1158 | self.figfile = None |
|
1159 | 1159 | |
|
1160 | 1160 | self.xmin = None |
|
1161 | 1161 | self.xmax = None |
|
1162 | 1162 | |
|
1163 | 1163 | def getSubplots(self): |
|
1164 | 1164 | |
|
1165 | 1165 | ncol = 1 |
|
1166 | 1166 | nrow = 1 |
|
1167 | 1167 | |
|
1168 | 1168 | return nrow, ncol |
|
1169 | 1169 | |
|
1170 | 1170 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1171 | 1171 | |
|
1172 | 1172 | self.__showprofile = showprofile |
|
1173 | 1173 | self.nplots = nplots |
|
1174 | 1174 | |
|
1175 | 1175 | ncolspan = 7 |
|
1176 | 1176 | colspan = 6 |
|
1177 | 1177 | self.__nsubplots = 2 |
|
1178 | 1178 | |
|
1179 | 1179 | self.createFigure(id = id, |
|
1180 | 1180 | wintitle = wintitle, |
|
1181 | 1181 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1182 | 1182 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1183 | 1183 | show=show) |
|
1184 | 1184 | |
|
1185 | 1185 | nrow, ncol = self.getSubplots() |
|
1186 | 1186 | |
|
1187 | 1187 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1188 | 1188 | |
|
1189 | 1189 | def save_phase(self, filename_phase): |
|
1190 | 1190 | f = open(filename_phase,'w+') |
|
1191 | 1191 | f.write('\n\n') |
|
1192 | 1192 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1193 | 1193 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1194 | 1194 | f.close() |
|
1195 | 1195 | |
|
1196 | 1196 | def save_data(self, filename_phase, data, data_datetime): |
|
1197 | 1197 | f=open(filename_phase,'a') |
|
1198 | 1198 | timetuple_data = data_datetime.timetuple() |
|
1199 | 1199 | day = str(timetuple_data.tm_mday) |
|
1200 | 1200 | month = str(timetuple_data.tm_mon) |
|
1201 | 1201 | year = str(timetuple_data.tm_year) |
|
1202 | 1202 | hour = str(timetuple_data.tm_hour) |
|
1203 | 1203 | minute = str(timetuple_data.tm_min) |
|
1204 | 1204 | second = str(timetuple_data.tm_sec) |
|
1205 | 1205 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1206 | 1206 | f.close() |
|
1207 | 1207 | |
|
1208 | 1208 | |
|
1209 | 1209 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1210 | 1210 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1211 | 1211 | timerange=None, |
|
1212 | 1212 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1213 | 1213 | server=None, folder=None, username=None, password=None, |
|
1214 | 1214 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1215 | 1215 | |
|
1216 | 1216 | if pairsList == None: |
|
1217 | 1217 | pairsIndexList = dataOut.pairsIndexList |
|
1218 | 1218 | else: |
|
1219 | 1219 | pairsIndexList = [] |
|
1220 | 1220 | for pair in pairsList: |
|
1221 | 1221 | if pair not in dataOut.pairsList: |
|
1222 | 1222 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1223 | 1223 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1224 | 1224 | |
|
1225 | 1225 | if pairsIndexList == []: |
|
1226 | 1226 | return |
|
1227 | 1227 | |
|
1228 | 1228 | # if len(pairsIndexList) > 4: |
|
1229 | 1229 | # pairsIndexList = pairsIndexList[0:4] |
|
1230 | 1230 | |
|
1231 | 1231 | x = dataOut.getTimeRange() |
|
1232 | 1232 | #y = dataOut.getHeiRange() |
|
1233 | 1233 | |
|
1234 | 1234 | |
|
1235 | 1235 | #thisDatetime = dataOut.datatime |
|
1236 | 1236 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1237 | 1237 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1238 | 1238 | xlabel = "Local Time" |
|
1239 | 1239 | ylabel = "Phase" |
|
1240 | 1240 | |
|
1241 | 1241 | nplots = len(pairsIndexList) |
|
1242 | 1242 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1243 | 1243 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1244 | 1244 | for i in range(nplots): |
|
1245 | 1245 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1246 | 1246 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1247 | 1247 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1248 | 1248 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1249 | 1249 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1250 | 1250 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1251 | 1251 | |
|
1252 | 1252 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1253 | 1253 | #print phase[dataOut.beacon_heiIndexList] |
|
1254 | 1254 | |
|
1255 | 1255 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1256 | 1256 | |
|
1257 | 1257 | if not self.__isConfig: |
|
1258 | 1258 | |
|
1259 | 1259 | nplots = len(pairsIndexList) |
|
1260 | 1260 | |
|
1261 | 1261 | self.setup(id=id, |
|
1262 | 1262 | nplots=nplots, |
|
1263 | 1263 | wintitle=wintitle, |
|
1264 | 1264 | showprofile=showprofile, |
|
1265 | 1265 | show=show) |
|
1266 | 1266 | |
|
1267 | 1267 | if timerange != None: |
|
1268 | 1268 | self.timerange = timerange |
|
1269 | 1269 | |
|
1270 | 1270 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1271 | 1271 | |
|
1272 | 1272 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1273 | 1273 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1274 | 1274 | |
|
1275 | 1275 | self.FTP_WEI = ftp_wei |
|
1276 | 1276 | self.EXP_CODE = exp_code |
|
1277 | 1277 | self.SUB_EXP_CODE = sub_exp_code |
|
1278 | 1278 | self.PLOT_POS = plot_pos |
|
1279 | 1279 | |
|
1280 | 1280 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1281 | 1281 | self.__isConfig = True |
|
1282 | 1282 | self.figfile = figfile |
|
1283 | 1283 | self.xdata = numpy.array([]) |
|
1284 | 1284 | self.ydata = numpy.array([]) |
|
1285 | 1285 | |
|
1286 | 1286 | #open file beacon phase |
|
1287 | 1287 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1288 | 1288 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1289 | 1289 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1290 | 1290 | #self.save_phase(self.filename_phase) |
|
1291 | 1291 | |
|
1292 | 1292 | |
|
1293 | 1293 | #store data beacon phase |
|
1294 | 1294 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1295 | 1295 | |
|
1296 | 1296 | self.setWinTitle(title) |
|
1297 | 1297 | |
|
1298 | 1298 | |
|
1299 | 1299 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1300 | 1300 | |
|
1301 | 1301 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1302 | 1302 | |
|
1303 | 1303 | axes = self.axesList[0] |
|
1304 | 1304 | |
|
1305 | 1305 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1306 | 1306 | |
|
1307 | 1307 | if len(self.ydata)==0: |
|
1308 | 1308 | self.ydata = phase_beacon.reshape(-1,1) |
|
1309 | 1309 | else: |
|
1310 | 1310 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1311 | 1311 | |
|
1312 | 1312 | |
|
1313 | 1313 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1314 | 1314 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1315 | 1315 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1316 | 1316 | XAxisAsTime=True, grid='both' |
|
1317 | 1317 | ) |
|
1318 | 1318 | |
|
1319 | 1319 | self.draw() |
|
1320 | 1320 | |
|
1321 | 1321 | if x[1] >= self.axesList[0].xmax: |
|
1322 | 1322 | self.counter_imagwr = wr_period |
|
1323 | 1323 | del self.xdata |
|
1324 | 1324 | del self.ydata |
|
1325 | 1325 | self.__isConfig = False |
|
1326 | 1326 | self.figfile = None |
|
1327 | 1327 | |
|
1328 | 1328 | self.save(figpath=figpath, |
|
1329 | 1329 | figfile=figfile, |
|
1330 | 1330 | save=save, |
|
1331 | 1331 | ftp=ftp, |
|
1332 | 1332 | wr_period=wr_period, |
|
1333 | 1333 | thisDatetime=thisDatetime, |
|
1334 | 1334 | update_figfile=False) |
General Comments 0
You need to be logged in to leave comments.
Login now