@@ -1,1060 +1,986 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime |
|
2 | import time, datetime | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 |
|
4 | |||
5 | class CrossSpectraPlot(Figure): |
|
5 | class CrossSpectraPlot(Figure): | |
6 |
|
6 | |||
7 | __isConfig = None |
|
7 | __isConfig = None | |
8 | __nsubplots = None |
|
8 | __nsubplots = None | |
9 |
|
9 | |||
10 | WIDTH = None |
|
10 | WIDTH = None | |
11 | HEIGHT = None |
|
11 | HEIGHT = None | |
12 | WIDTHPROF = None |
|
12 | WIDTHPROF = None | |
13 | HEIGHTPROF = None |
|
13 | HEIGHTPROF = None | |
14 | PREFIX = 'cspc' |
|
14 | PREFIX = 'cspc' | |
15 |
|
15 | |||
16 | def __init__(self): |
|
16 | def __init__(self): | |
17 |
|
17 | |||
18 | self.__isConfig = False |
|
18 | self.__isConfig = False | |
19 | self.__nsubplots = 4 |
|
19 | self.__nsubplots = 4 | |
20 |
|
20 | |||
21 | self.WIDTH = 250 |
|
21 | self.WIDTH = 250 | |
22 | self.HEIGHT = 250 |
|
22 | self.HEIGHT = 250 | |
23 | self.WIDTHPROF = 0 |
|
23 | self.WIDTHPROF = 0 | |
24 | self.HEIGHTPROF = 0 |
|
24 | self.HEIGHTPROF = 0 | |
25 |
|
25 | |||
26 | def getSubplots(self): |
|
26 | def getSubplots(self): | |
27 |
|
27 | |||
28 | ncol = 4 |
|
28 | ncol = 4 | |
29 | nrow = self.nplots |
|
29 | nrow = self.nplots | |
30 |
|
30 | |||
31 | return nrow, ncol |
|
31 | return nrow, ncol | |
32 |
|
32 | |||
33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
34 |
|
34 | |||
35 | self.__showprofile = showprofile |
|
35 | self.__showprofile = showprofile | |
36 | self.nplots = nplots |
|
36 | self.nplots = nplots | |
37 |
|
37 | |||
38 | ncolspan = 1 |
|
38 | ncolspan = 1 | |
39 | colspan = 1 |
|
39 | colspan = 1 | |
40 |
|
40 | |||
41 | self.createFigure(idfigure = idfigure, |
|
41 | self.createFigure(idfigure = idfigure, | |
42 | wintitle = wintitle, |
|
42 | wintitle = wintitle, | |
43 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
43 | widthplot = self.WIDTH + self.WIDTHPROF, | |
44 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
44 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
45 |
|
45 | |||
46 | nrow, ncol = self.getSubplots() |
|
46 | nrow, ncol = self.getSubplots() | |
47 |
|
47 | |||
48 | counter = 0 |
|
48 | counter = 0 | |
49 | for y in range(nrow): |
|
49 | for y in range(nrow): | |
50 | for x in range(ncol): |
|
50 | for x in range(ncol): | |
51 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
51 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
52 |
|
52 | |||
53 | counter += 1 |
|
53 | counter += 1 | |
54 |
|
54 | |||
55 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
55 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |
56 |
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
56 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
57 |
save=False, figpath='./', figfile=None |
|
57 | save=False, figpath='./', figfile=None): | |
58 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'): |
|
|||
59 |
|
58 | |||
60 | """ |
|
59 | """ | |
61 |
|
60 | |||
62 | Input: |
|
61 | Input: | |
63 | dataOut : |
|
62 | dataOut : | |
64 | idfigure : |
|
63 | idfigure : | |
65 | wintitle : |
|
64 | wintitle : | |
66 | channelList : |
|
65 | channelList : | |
67 | showProfile : |
|
66 | showProfile : | |
68 | xmin : None, |
|
67 | xmin : None, | |
69 | xmax : None, |
|
68 | xmax : None, | |
70 | ymin : None, |
|
69 | ymin : None, | |
71 | ymax : None, |
|
70 | ymax : None, | |
72 | zmin : None, |
|
71 | zmin : None, | |
73 | zmax : None |
|
72 | zmax : None | |
74 | """ |
|
73 | """ | |
75 |
|
74 | |||
76 | if pairsList == None: |
|
75 | if pairsList == None: | |
77 | pairsIndexList = dataOut.pairsIndexList |
|
76 | pairsIndexList = dataOut.pairsIndexList | |
78 | else: |
|
77 | else: | |
79 | pairsIndexList = [] |
|
78 | pairsIndexList = [] | |
80 | for pair in pairsList: |
|
79 | for pair in pairsList: | |
81 | if pair not in dataOut.pairsList: |
|
80 | if pair not in dataOut.pairsList: | |
82 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
81 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
83 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
82 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
84 |
|
83 | |||
85 | if pairsIndexList == []: |
|
84 | if pairsIndexList == []: | |
86 | return |
|
85 | return | |
87 |
|
86 | |||
88 | if len(pairsIndexList) > 4: |
|
87 | if len(pairsIndexList) > 4: | |
89 | pairsIndexList = pairsIndexList[0:4] |
|
88 | pairsIndexList = pairsIndexList[0:4] | |
90 |
|
89 | factor = dataOut.normFactor | ||
91 | factor = 1 |
|
|||
92 | if normalize: |
|
|||
93 | factor = dataOut.normFactor |
|
|||
94 | x = dataOut.getVelRange(1) |
|
90 | x = dataOut.getVelRange(1) | |
95 | y = dataOut.getHeiRange() |
|
91 | y = dataOut.getHeiRange() | |
96 | z = dataOut.data_spc[:,:,:]/factor |
|
92 | z = dataOut.data_spc[:,:,:]/factor | |
97 |
|
93 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | ||
98 | avg = numpy.average(z, axis=1) |
|
94 | avg = numpy.average(numpy.abs(z), axis=1) | |
99 | noise = dataOut.getNoise()/factor |
|
95 | noise = dataOut.getNoise()/factor | |
100 |
|
96 | |||
101 | zdB = 10*numpy.log10(z) |
|
97 | zdB = 10*numpy.log10(z) | |
102 | avgdB = 10*numpy.log10(avg) |
|
98 | avgdB = 10*numpy.log10(avg) | |
103 | noisedB = 10*numpy.log10(noise) |
|
99 | noisedB = 10*numpy.log10(noise) | |
104 |
|
100 | |||
105 |
|
101 | |||
106 | thisDatetime = dataOut.datatime |
|
102 | thisDatetime = dataOut.datatime | |
107 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
103 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
108 | xlabel = "Velocity (m/s)" |
|
104 | xlabel = "Velocity (m/s)" | |
109 | ylabel = "Range (Km)" |
|
105 | ylabel = "Range (Km)" | |
110 |
|
106 | |||
111 | if not self.__isConfig: |
|
107 | if not self.__isConfig: | |
112 |
|
108 | |||
113 | nplots = len(pairsIndexList) |
|
109 | nplots = len(pairsIndexList) | |
114 |
|
110 | |||
115 | self.setup(idfigure=idfigure, |
|
111 | self.setup(idfigure=idfigure, | |
116 | nplots=nplots, |
|
112 | nplots=nplots, | |
117 | wintitle=wintitle, |
|
113 | wintitle=wintitle, | |
118 | showprofile=showprofile) |
|
114 | showprofile=showprofile) | |
119 |
|
115 | |||
120 | if xmin == None: xmin = numpy.nanmin(x) |
|
116 | if xmin == None: xmin = numpy.nanmin(x) | |
121 | if xmax == None: xmax = numpy.nanmax(x) |
|
117 | if xmax == None: xmax = numpy.nanmax(x) | |
122 | if ymin == None: ymin = numpy.nanmin(y) |
|
118 | if ymin == None: ymin = numpy.nanmin(y) | |
123 | if ymax == None: ymax = numpy.nanmax(y) |
|
119 | if ymax == None: ymax = numpy.nanmax(y) | |
124 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
120 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
125 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
121 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
126 |
|
122 | |||
127 | self.__isConfig = True |
|
123 | self.__isConfig = True | |
128 |
|
124 | |||
129 | self.setWinTitle(title) |
|
125 | self.setWinTitle(title) | |
130 |
|
126 | |||
131 | for i in range(self.nplots): |
|
127 | for i in range(self.nplots): | |
132 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
128 | pair = dataOut.pairsList[pairsIndexList[i]] | |
133 |
|
129 | |||
134 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
130 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) | |
135 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
131 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) | |
136 | axes0 = self.axesList[i*self.__nsubplots] |
|
132 | axes0 = self.axesList[i*self.__nsubplots] | |
137 | axes0.pcolor(x, y, zdB, |
|
133 | axes0.pcolor(x, y, zdB, | |
138 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
134 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
139 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
135 | xlabel=xlabel, ylabel=ylabel, title=title, | |
140 |
ticksize=9 |
|
136 | ticksize=9, cblabel='') | |
141 |
|
137 | |||
142 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
138 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) | |
143 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
139 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) | |
144 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
140 | axes0 = self.axesList[i*self.__nsubplots+1] | |
145 | axes0.pcolor(x, y, zdB, |
|
141 | axes0.pcolor(x, y, zdB, | |
146 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
142 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
147 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
143 | xlabel=xlabel, ylabel=ylabel, title=title, | |
148 |
ticksize=9 |
|
144 | ticksize=9, cblabel='') | |
149 |
|
145 | |||
150 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
146 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
151 | coherence = numpy.abs(coherenceComplex) |
|
147 | coherence = numpy.abs(coherenceComplex) | |
152 |
|
|
148 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
153 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
149 | ||
154 |
|
150 | |||
155 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
151 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
156 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
152 | axes0 = self.axesList[i*self.__nsubplots+2] | |
157 | axes0.pcolor(x, y, coherence, |
|
153 | axes0.pcolor(x, y, coherence, | |
158 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
154 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
159 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
155 | xlabel=xlabel, ylabel=ylabel, title=title, | |
160 |
ticksize=9 |
|
156 | ticksize=9, cblabel='') | |
161 |
|
157 | |||
162 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
158 | title = "Phase %d%d" %(pair[0], pair[1]) | |
163 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
159 | axes0 = self.axesList[i*self.__nsubplots+3] | |
164 | axes0.pcolor(x, y, phase, |
|
160 | axes0.pcolor(x, y, phase, | |
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
161 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
162 | xlabel=xlabel, ylabel=ylabel, title=title, | |
167 |
ticksize=9, |
|
163 | ticksize=9, cblabel='', colormap='RdBu_r') | |
168 |
|
164 | |||
169 |
|
165 | |||
170 |
|
166 | |||
171 | self.draw() |
|
167 | self.draw() | |
172 |
|
168 | |||
173 | if save: |
|
169 | if save: | |
174 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
170 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
175 | if figfile == None: |
|
171 | if figfile == None: | |
176 | figfile = self.getFilename(name = date) |
|
172 | figfile = self.getFilename(name = date) | |
177 |
|
173 | |||
178 | self.saveFigure(figpath, figfile) |
|
174 | self.saveFigure(figpath, figfile) | |
179 |
|
175 | |||
180 |
|
176 | |||
181 | class RTIPlot(Figure): |
|
177 | class RTIPlot(Figure): | |
182 |
|
178 | |||
183 | __isConfig = None |
|
179 | __isConfig = None | |
184 | __nsubplots = None |
|
180 | __nsubplots = None | |
185 | __missing = 1E30 |
|
181 | ||
186 | WIDTHPROF = None |
|
182 | WIDTHPROF = None | |
187 | HEIGHTPROF = None |
|
183 | HEIGHTPROF = None | |
188 | PREFIX = 'rti' |
|
184 | PREFIX = 'rti' | |
189 |
|
185 | |||
190 | def __init__(self): |
|
186 | def __init__(self): | |
191 |
|
187 | |||
192 | self.timerange = 2*60*60 |
|
188 | self.timerange = 2*60*60 | |
193 | self.__isConfig = False |
|
189 | self.__isConfig = False | |
194 | self.__nsubplots = 1 |
|
190 | self.__nsubplots = 1 | |
195 |
|
191 | |||
196 | self.WIDTH = 800 |
|
192 | self.WIDTH = 800 | |
197 |
self.HEIGHT = |
|
193 | self.HEIGHT = 200 | |
198 | self.WIDTHPROF = 120 |
|
194 | self.WIDTHPROF = 120 | |
199 | self.HEIGHTPROF = 0 |
|
195 | self.HEIGHTPROF = 0 | |
200 | self.x_buffer = None |
|
|||
201 | self.avgdB_buffer = None |
|
|||
202 |
|
196 | |||
203 | def getSubplots(self): |
|
197 | def getSubplots(self): | |
204 |
|
198 | |||
205 | ncol = 1 |
|
199 | ncol = 1 | |
206 | nrow = self.nplots |
|
200 | nrow = self.nplots | |
207 |
|
201 | |||
208 | return nrow, ncol |
|
202 | return nrow, ncol | |
209 |
|
203 | |||
210 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
204 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
211 |
|
205 | |||
212 | self.__showprofile = showprofile |
|
206 | self.__showprofile = showprofile | |
213 | self.nplots = nplots |
|
207 | self.nplots = nplots | |
214 |
|
208 | |||
215 | ncolspan = 1 |
|
209 | ncolspan = 1 | |
216 | colspan = 1 |
|
210 | colspan = 1 | |
217 | widthplot = self.WIDTH |
|
|||
218 | heightplot = self.HEIGHT |
|
|||
219 | if showprofile: |
|
211 | if showprofile: | |
220 | ncolspan = 7 |
|
212 | ncolspan = 7 | |
221 | colspan = 6 |
|
213 | colspan = 6 | |
222 | self.__nsubplots = 2 |
|
214 | self.__nsubplots = 2 | |
223 | widthplot += self.WIDTHPROF |
|
|||
224 | heightplot += self.HEIGHTPROF |
|
|||
225 |
|
215 | |||
226 | self.createFigure(idfigure = idfigure, |
|
216 | self.createFigure(idfigure = idfigure, | |
227 | wintitle = wintitle, |
|
217 | wintitle = wintitle, | |
228 |
widthplot = |
|
218 | widthplot = self.WIDTH + self.WIDTHPROF, | |
229 |
heightplot = |
|
219 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
230 |
|
220 | |||
231 | nrow, ncol = self.getSubplots() |
|
221 | nrow, ncol = self.getSubplots() | |
232 |
|
222 | |||
233 | counter = 0 |
|
223 | counter = 0 | |
234 | for y in range(nrow): |
|
224 | for y in range(nrow): | |
235 | for x in range(ncol): |
|
225 | for x in range(ncol): | |
236 |
|
226 | |||
237 | if counter >= self.nplots: |
|
227 | if counter >= self.nplots: | |
238 | break |
|
228 | break | |
239 |
|
229 | |||
240 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
230 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
241 |
|
231 | |||
242 | if showprofile: |
|
232 | if showprofile: | |
243 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
233 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
244 |
|
234 | |||
245 | counter += 1 |
|
235 | counter += 1 | |
246 |
|
236 | |||
247 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
237 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
248 |
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
238 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
249 | timerange=None, |
|
239 | timerange=None, | |
250 | save=False, figpath='./', figfile=None): |
|
240 | save=False, figpath='./', figfile=None): | |
251 |
|
241 | |||
252 | """ |
|
242 | """ | |
253 |
|
243 | |||
254 | Input: |
|
244 | Input: | |
255 | dataOut : |
|
245 | dataOut : | |
256 | idfigure : |
|
246 | idfigure : | |
257 | wintitle : |
|
247 | wintitle : | |
258 | channelList : |
|
248 | channelList : | |
259 | showProfile : |
|
249 | showProfile : | |
260 | xmin : None, |
|
250 | xmin : None, | |
261 | xmax : None, |
|
251 | xmax : None, | |
262 | ymin : None, |
|
252 | ymin : None, | |
263 | ymax : None, |
|
253 | ymax : None, | |
264 | zmin : None, |
|
254 | zmin : None, | |
265 | zmax : None |
|
255 | zmax : None | |
266 | """ |
|
256 | """ | |
267 |
|
257 | |||
268 | if channelList == None: |
|
258 | if channelList == None: | |
269 | channelIndexList = dataOut.channelIndexList |
|
259 | channelIndexList = dataOut.channelIndexList | |
270 | else: |
|
260 | else: | |
271 | channelIndexList = [] |
|
261 | channelIndexList = [] | |
272 | for channel in channelList: |
|
262 | for channel in channelList: | |
273 | if channel not in dataOut.channelList: |
|
263 | if channel not in dataOut.channelList: | |
274 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
264 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
275 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
265 | channelIndexList.append(dataOut.channelList.index(channel)) | |
276 |
|
266 | |||
277 | if timerange != None: |
|
267 | if timerange != None: | |
278 | self.timerange = timerange |
|
268 | self.timerange = timerange | |
279 |
|
269 | |||
280 | tmin = None |
|
270 | tmin = None | |
281 | tmax = None |
|
271 | tmax = None | |
282 |
factor = |
|
272 | factor = dataOut.normFactor | |
283 | if normalize: |
|
|||
284 | factor = dataOut.normFactor |
|
|||
285 | x = dataOut.getTimeRange() |
|
273 | x = dataOut.getTimeRange() | |
286 | y = dataOut.getHeiRange() |
|
274 | y = dataOut.getHeiRange() | |
287 |
|
275 | |||
288 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
276 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
289 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
277 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
290 | avg = numpy.average(z, axis=1) |
|
278 | avg = numpy.average(z, axis=1) | |
|
279 | noise = dataOut.getNoise()/factor | |||
291 |
|
280 | |||
|
281 | # zdB = 10.*numpy.log10(z) | |||
292 | avgdB = 10.*numpy.log10(avg) |
|
282 | avgdB = 10.*numpy.log10(avg) | |
293 |
|
283 | noisedB = 10.*numpy.log10(noise) | ||
294 |
|
284 | |||
295 | thisDatetime = dataOut.datatime |
|
285 | thisDatetime = dataOut.datatime | |
296 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
286 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
297 | xlabel = "Velocity (m/s)" |
|
287 | xlabel = "Velocity (m/s)" | |
298 | ylabel = "Range (Km)" |
|
288 | ylabel = "Range (Km)" | |
299 |
|
289 | |||
300 | if not self.__isConfig: |
|
290 | if not self.__isConfig: | |
301 |
|
291 | |||
302 | nplots = len(channelIndexList) |
|
292 | nplots = len(channelIndexList) | |
303 |
|
293 | |||
304 | self.setup(idfigure=idfigure, |
|
294 | self.setup(idfigure=idfigure, | |
305 | nplots=nplots, |
|
295 | nplots=nplots, | |
306 | wintitle=wintitle, |
|
296 | wintitle=wintitle, | |
307 | showprofile=showprofile) |
|
297 | showprofile=showprofile) | |
308 |
|
298 | |||
309 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
299 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
310 | if ymin == None: ymin = numpy.nanmin(y) |
|
300 | if ymin == None: ymin = numpy.nanmin(y) | |
311 | if ymax == None: ymax = numpy.nanmax(y) |
|
301 | if ymax == None: ymax = numpy.nanmax(y) | |
312 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
302 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
313 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
303 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
314 |
|
304 | |||
315 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
305 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
316 | self.x_buffer = numpy.array([]) |
|
|||
317 | self.avgdB_buffer = numpy.array([]) |
|
|||
318 | self.__isConfig = True |
|
306 | self.__isConfig = True | |
319 |
|
307 | |||
320 |
|
308 | |||
321 | self.setWinTitle(title) |
|
309 | self.setWinTitle(title) | |
322 |
|
||||
323 | if len(self.avgdB_buffer)==0: |
|
|||
324 | self.avgdB_buffer = avgdB |
|
|||
325 | newxdim = 1 |
|
|||
326 | newydim = -1 |
|
|||
327 | else: |
|
|||
328 | if x[0]>self.x_buffer[-1]: |
|
|||
329 | gap = avgdB.copy() |
|
|||
330 | gap[:] = self.__missing |
|
|||
331 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, gap)) |
|
|||
332 |
|
310 | |||
333 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, avgdB)) |
|
|||
334 | newxdim = -1 |
|
|||
335 | newydim = len(y) |
|
|||
336 |
|
||||
337 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
|||
338 |
|
||||
339 | self.avgdB_buffer = numpy.ma.masked_inside(self.avgdB_buffer,0.99*self.__missing,1.01*self.__missing) |
|
|||
340 |
|
||||
341 | for i in range(self.nplots): |
|
311 | for i in range(self.nplots): | |
342 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
312 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
343 | axes = self.axesList[i*self.__nsubplots] |
|
313 | axes = self.axesList[i*self.__nsubplots] | |
344 |
zdB = |
|
314 | zdB = avgdB[i].reshape((1,-1)) | |
345 |
axes.pcolor( |
|
315 | axes.pcolor(x, y, zdB, | |
346 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
316 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
347 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
317 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
348 | ticksize=9, cblabel='', cbsize="1%") |
|
318 | ticksize=9, cblabel='', cbsize="1%") | |
349 |
|
319 | |||
350 | if self.__showprofile: |
|
320 | if self.__showprofile: | |
351 | axes = self.axesList[i*self.__nsubplots +1] |
|
321 | axes = self.axesList[i*self.__nsubplots +1] | |
352 | axes.pline(avgdB[i], y, |
|
322 | axes.pline(avgdB[i], y, | |
353 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
323 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
354 | xlabel='dB', ylabel='', title='', |
|
324 | xlabel='dB', ylabel='', title='', | |
355 | ytick_visible=False, |
|
325 | ytick_visible=False, | |
356 | grid='x') |
|
326 | grid='x') | |
357 |
|
327 | |||
358 | self.draw() |
|
328 | self.draw() | |
359 |
|
329 | |||
360 | if save: |
|
330 | if save: | |
361 |
|
331 | |||
362 | if figfile == None: |
|
332 | if figfile == None: | |
363 | figfile = self.getFilename(name = self.name) |
|
333 | figfile = self.getFilename(name = self.name) | |
364 |
|
334 | |||
365 | self.saveFigure(figpath, figfile) |
|
335 | self.saveFigure(figpath, figfile) | |
366 |
|
336 | |||
367 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
337 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
368 | self.__isConfig = False |
|
338 | self.__isConfig = False | |
369 |
|
339 | |||
370 | class SpectraPlot(Figure): |
|
340 | class SpectraPlot(Figure): | |
371 |
|
341 | |||
372 | __isConfig = None |
|
342 | __isConfig = None | |
373 | __nsubplots = None |
|
343 | __nsubplots = None | |
374 |
|
344 | |||
375 | WIDTHPROF = None |
|
345 | WIDTHPROF = None | |
376 | HEIGHTPROF = None |
|
346 | HEIGHTPROF = None | |
377 | PREFIX = 'spc' |
|
347 | PREFIX = 'spc' | |
378 |
|
348 | |||
379 | def __init__(self): |
|
349 | def __init__(self): | |
380 |
|
350 | |||
381 | self.__isConfig = False |
|
351 | self.__isConfig = False | |
382 | self.__nsubplots = 1 |
|
352 | self.__nsubplots = 1 | |
383 |
|
353 | |||
384 |
self.WIDTH = 2 |
|
354 | self.WIDTH = 230 | |
385 | self.HEIGHT = 250 |
|
355 | self.HEIGHT = 250 | |
386 | self.WIDTHPROF = 120 |
|
356 | self.WIDTHPROF = 120 | |
387 | self.HEIGHTPROF = 0 |
|
357 | self.HEIGHTPROF = 0 | |
388 |
|
358 | |||
389 | def getSubplots(self): |
|
359 | def getSubplots(self): | |
390 |
|
360 | |||
391 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
361 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
392 | nrow = int(self.nplots*1./ncol + 0.9) |
|
362 | nrow = int(self.nplots*1./ncol + 0.9) | |
393 |
|
363 | |||
394 | return nrow, ncol |
|
364 | return nrow, ncol | |
395 |
|
365 | |||
396 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
366 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
397 |
|
367 | |||
398 | self.__showprofile = showprofile |
|
368 | self.__showprofile = showprofile | |
399 | self.nplots = nplots |
|
369 | self.nplots = nplots | |
400 |
|
370 | |||
401 | ncolspan = 1 |
|
371 | ncolspan = 1 | |
402 | colspan = 1 |
|
372 | colspan = 1 | |
403 | widthplot = self.WIDTH |
|
|||
404 | heightplot = self.HEIGHT |
|
|||
405 | if showprofile: |
|
373 | if showprofile: | |
406 | ncolspan = 3 |
|
374 | ncolspan = 3 | |
407 | colspan = 2 |
|
375 | colspan = 2 | |
408 | self.__nsubplots = 2 |
|
376 | self.__nsubplots = 2 | |
409 | widthplot += self.WIDTHPROF |
|
377 | ||
410 | heightplot += self.HEIGHTPROF |
|
|||
411 |
|
||||
412 | self.createFigure(idfigure = idfigure, |
|
378 | self.createFigure(idfigure = idfigure, | |
413 | wintitle = wintitle, |
|
379 | wintitle = wintitle, | |
414 |
widthplot = |
|
380 | widthplot = self.WIDTH + self.WIDTHPROF, | |
415 |
heightplot = |
|
381 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
416 |
|
382 | |||
417 | nrow, ncol = self.getSubplots() |
|
383 | nrow, ncol = self.getSubplots() | |
418 |
|
384 | |||
419 | counter = 0 |
|
385 | counter = 0 | |
420 | for y in range(nrow): |
|
386 | for y in range(nrow): | |
421 | for x in range(ncol): |
|
387 | for x in range(ncol): | |
422 |
|
388 | |||
423 | if counter >= self.nplots: |
|
389 | if counter >= self.nplots: | |
424 | break |
|
390 | break | |
425 |
|
391 | |||
426 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
392 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
427 |
|
393 | |||
428 | if showprofile: |
|
394 | if showprofile: | |
429 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
395 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
430 |
|
396 | |||
431 | counter += 1 |
|
397 | counter += 1 | |
432 |
|
398 | |||
433 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
399 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
434 |
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
400 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
435 | save=False, figpath='./', figfile=None): |
|
401 | save=False, figpath='./', figfile=None): | |
436 |
|
402 | |||
437 | """ |
|
403 | """ | |
438 |
|
404 | |||
439 | Input: |
|
405 | Input: | |
440 | dataOut : |
|
406 | dataOut : | |
441 | idfigure : |
|
407 | idfigure : | |
442 | wintitle : |
|
408 | wintitle : | |
443 | channelList : |
|
409 | channelList : | |
444 | showProfile : |
|
410 | showProfile : | |
445 | xmin : None, |
|
411 | xmin : None, | |
446 | xmax : None, |
|
412 | xmax : None, | |
447 | ymin : None, |
|
413 | ymin : None, | |
448 | ymax : None, |
|
414 | ymax : None, | |
449 | zmin : None, |
|
415 | zmin : None, | |
450 | zmax : None |
|
416 | zmax : None | |
451 | """ |
|
417 | """ | |
452 |
|
418 | |||
453 | if channelList == None: |
|
419 | if channelList == None: | |
454 | channelIndexList = dataOut.channelIndexList |
|
420 | channelIndexList = dataOut.channelIndexList | |
455 | else: |
|
421 | else: | |
456 | channelIndexList = [] |
|
422 | channelIndexList = [] | |
457 | for channel in channelList: |
|
423 | for channel in channelList: | |
458 | if channel not in dataOut.channelList: |
|
424 | if channel not in dataOut.channelList: | |
459 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
425 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
460 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
426 | channelIndexList.append(dataOut.channelList.index(channel)) | |
461 |
factor = |
|
427 | factor = dataOut.normFactor | |
462 | if normalize: |
|
|||
463 | factor = dataOut.normFactor |
|
|||
464 | x = dataOut.getVelRange(1) |
|
428 | x = dataOut.getVelRange(1) | |
465 | y = dataOut.getHeiRange() |
|
429 | y = dataOut.getHeiRange() | |
466 |
|
430 | |||
467 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
431 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
468 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
432 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
469 | avg = numpy.average(z, axis=1) |
|
433 | avg = numpy.average(z, axis=1) | |
470 | noise = dataOut.getNoise()/factor |
|
434 | noise = dataOut.getNoise()/factor | |
471 |
|
435 | |||
472 | zdB = 10*numpy.log10(z) |
|
436 | zdB = 10*numpy.log10(z) | |
473 | avgdB = 10*numpy.log10(avg) |
|
437 | avgdB = 10*numpy.log10(avg) | |
474 | noisedB = 10*numpy.log10(noise) |
|
438 | noisedB = 10*numpy.log10(noise) | |
475 |
|
439 | |||
476 | thisDatetime = dataOut.datatime |
|
440 | thisDatetime = dataOut.datatime | |
477 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
441 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
478 | xlabel = "Velocity (m/s)" |
|
442 | xlabel = "Velocity (m/s)" | |
479 | ylabel = "Range (Km)" |
|
443 | ylabel = "Range (Km)" | |
480 |
|
444 | |||
481 | if not self.__isConfig: |
|
445 | if not self.__isConfig: | |
482 |
|
446 | |||
483 | nplots = len(channelIndexList) |
|
447 | nplots = len(channelIndexList) | |
484 |
|
448 | |||
485 | self.setup(idfigure=idfigure, |
|
449 | self.setup(idfigure=idfigure, | |
486 | nplots=nplots, |
|
450 | nplots=nplots, | |
487 | wintitle=wintitle, |
|
451 | wintitle=wintitle, | |
488 | showprofile=showprofile) |
|
452 | showprofile=showprofile) | |
489 |
|
453 | |||
490 | if xmin == None: xmin = numpy.nanmin(x) |
|
454 | if xmin == None: xmin = numpy.nanmin(x) | |
491 | if xmax == None: xmax = numpy.nanmax(x) |
|
455 | if xmax == None: xmax = numpy.nanmax(x) | |
492 | if ymin == None: ymin = numpy.nanmin(y) |
|
456 | if ymin == None: ymin = numpy.nanmin(y) | |
493 | if ymax == None: ymax = numpy.nanmax(y) |
|
457 | if ymax == None: ymax = numpy.nanmax(y) | |
494 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
458 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
495 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
459 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
496 |
|
460 | |||
497 | self.__isConfig = True |
|
461 | self.__isConfig = True | |
498 |
|
462 | |||
499 | self.setWinTitle(title) |
|
463 | self.setWinTitle(title) | |
500 |
|
464 | |||
501 | for i in range(self.nplots): |
|
465 | for i in range(self.nplots): | |
502 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) |
|
466 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) | |
503 | axes = self.axesList[i*self.__nsubplots] |
|
467 | axes = self.axesList[i*self.__nsubplots] | |
504 | axes.pcolor(x, y, zdB[i,:,:], |
|
468 | axes.pcolor(x, y, zdB[i,:,:], | |
505 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
469 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
506 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
470 | xlabel=xlabel, ylabel=ylabel, title=title, | |
507 | ticksize=9, cblabel='') |
|
471 | ticksize=9, cblabel='') | |
508 |
|
472 | |||
509 | if self.__showprofile: |
|
473 | if self.__showprofile: | |
510 | axes = self.axesList[i*self.__nsubplots +1] |
|
474 | axes = self.axesList[i*self.__nsubplots +1] | |
511 | axes.pline(avgdB[i], y, |
|
475 | axes.pline(avgdB[i], y, | |
512 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
476 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
513 | xlabel='dB', ylabel='', title='', |
|
477 | xlabel='dB', ylabel='', title='', | |
514 | ytick_visible=False, |
|
478 | ytick_visible=False, | |
515 | grid='x') |
|
479 | grid='x') | |
516 |
|
480 | |||
517 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
481 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
518 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
482 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
519 |
|
483 | |||
520 | self.draw() |
|
484 | self.draw() | |
521 |
|
485 | |||
522 | if save: |
|
486 | if save: | |
523 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
487 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
524 | if figfile == None: |
|
488 | if figfile == None: | |
525 | figfile = self.getFilename(name = date) |
|
489 | figfile = self.getFilename(name = date) | |
526 |
|
490 | |||
527 | self.saveFigure(figpath, figfile) |
|
491 | self.saveFigure(figpath, figfile) | |
528 |
|
492 | |||
529 | class Scope(Figure): |
|
493 | class Scope(Figure): | |
530 |
|
494 | |||
531 | __isConfig = None |
|
495 | __isConfig = None | |
532 |
|
496 | |||
533 | def __init__(self): |
|
497 | def __init__(self): | |
534 |
|
498 | |||
535 | self.__isConfig = False |
|
499 | self.__isConfig = False | |
536 | self.WIDTH = 600 |
|
500 | self.WIDTH = 600 | |
537 | self.HEIGHT = 200 |
|
501 | self.HEIGHT = 200 | |
538 |
|
502 | |||
539 | def getSubplots(self): |
|
503 | def getSubplots(self): | |
540 |
|
504 | |||
541 | nrow = self.nplots |
|
505 | nrow = self.nplots | |
542 | ncol = 3 |
|
506 | ncol = 3 | |
543 | return nrow, ncol |
|
507 | return nrow, ncol | |
544 |
|
508 | |||
545 | def setup(self, idfigure, nplots, wintitle): |
|
509 | def setup(self, idfigure, nplots, wintitle): | |
546 |
|
510 | |||
547 | self.nplots = nplots |
|
511 | self.nplots = nplots | |
548 |
|
512 | |||
549 | self.createFigure(idfigure, wintitle) |
|
513 | self.createFigure(idfigure, wintitle) | |
550 |
|
514 | |||
551 | nrow,ncol = self.getSubplots() |
|
515 | nrow,ncol = self.getSubplots() | |
552 | colspan = 3 |
|
516 | colspan = 3 | |
553 | rowspan = 1 |
|
517 | rowspan = 1 | |
554 |
|
518 | |||
555 | for i in range(nplots): |
|
519 | for i in range(nplots): | |
556 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
520 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
557 |
|
521 | |||
558 |
|
522 | |||
559 |
|
523 | |||
560 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
524 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
561 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
525 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
562 | figpath='./', figfile=None): |
|
526 | figpath='./', figfile=None): | |
563 |
|
527 | |||
564 | """ |
|
528 | """ | |
565 |
|
529 | |||
566 | Input: |
|
530 | Input: | |
567 | dataOut : |
|
531 | dataOut : | |
568 | idfigure : |
|
532 | idfigure : | |
569 | wintitle : |
|
533 | wintitle : | |
570 | channelList : |
|
534 | channelList : | |
571 | xmin : None, |
|
535 | xmin : None, | |
572 | xmax : None, |
|
536 | xmax : None, | |
573 | ymin : None, |
|
537 | ymin : None, | |
574 | ymax : None, |
|
538 | ymax : None, | |
575 | """ |
|
539 | """ | |
576 |
|
540 | |||
577 | if channelList == None: |
|
541 | if channelList == None: | |
578 | channelIndexList = dataOut.channelIndexList |
|
542 | channelIndexList = dataOut.channelIndexList | |
579 | else: |
|
543 | else: | |
580 | channelIndexList = [] |
|
544 | channelIndexList = [] | |
581 | for channel in channelList: |
|
545 | for channel in channelList: | |
582 | if channel not in dataOut.channelList: |
|
546 | if channel not in dataOut.channelList: | |
583 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
547 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
584 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
548 | channelIndexList.append(dataOut.channelList.index(channel)) | |
585 |
|
549 | |||
586 | x = dataOut.heightList |
|
550 | x = dataOut.heightList | |
587 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
551 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
588 | y = y.real |
|
552 | y = y.real | |
589 |
|
553 | |||
590 | thisDatetime = dataOut.datatime |
|
554 | thisDatetime = dataOut.datatime | |
591 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
555 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
592 | xlabel = "Range (Km)" |
|
556 | xlabel = "Range (Km)" | |
593 | ylabel = "Intensity" |
|
557 | ylabel = "Intensity" | |
594 |
|
558 | |||
595 | if not self.__isConfig: |
|
559 | if not self.__isConfig: | |
596 | nplots = len(channelIndexList) |
|
560 | nplots = len(channelIndexList) | |
597 |
|
561 | |||
598 | self.setup(idfigure=idfigure, |
|
562 | self.setup(idfigure=idfigure, | |
599 | nplots=nplots, |
|
563 | nplots=nplots, | |
600 | wintitle=wintitle) |
|
564 | wintitle=wintitle) | |
601 |
|
565 | |||
602 | if xmin == None: xmin = numpy.nanmin(x) |
|
566 | if xmin == None: xmin = numpy.nanmin(x) | |
603 | if xmax == None: xmax = numpy.nanmax(x) |
|
567 | if xmax == None: xmax = numpy.nanmax(x) | |
604 | if ymin == None: ymin = numpy.nanmin(y) |
|
568 | if ymin == None: ymin = numpy.nanmin(y) | |
605 | if ymax == None: ymax = numpy.nanmax(y) |
|
569 | if ymax == None: ymax = numpy.nanmax(y) | |
606 |
|
570 | |||
607 | self.__isConfig = True |
|
571 | self.__isConfig = True | |
608 |
|
572 | |||
609 | self.setWinTitle(title) |
|
573 | self.setWinTitle(title) | |
610 |
|
574 | |||
611 | for i in range(len(self.axesList)): |
|
575 | for i in range(len(self.axesList)): | |
612 | title = "Channel %d" %(i) |
|
576 | title = "Channel %d" %(i) | |
613 | axes = self.axesList[i] |
|
577 | axes = self.axesList[i] | |
614 | ychannel = y[i,:] |
|
578 | ychannel = y[i,:] | |
615 | axes.pline(x, ychannel, |
|
579 | axes.pline(x, ychannel, | |
616 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
580 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
617 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
581 | xlabel=xlabel, ylabel=ylabel, title=title) | |
618 |
|
582 | |||
619 | self.draw() |
|
583 | self.draw() | |
620 |
|
584 | |||
621 | if save: |
|
585 | if save: | |
622 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
586 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
623 | if figfile == None: |
|
587 | if figfile == None: | |
624 | figfile = self.getFilename(name = date) |
|
588 | figfile = self.getFilename(name = date) | |
625 |
|
589 | |||
626 | self.saveFigure(figpath, figfile) |
|
590 | self.saveFigure(figpath, figfile) | |
627 |
|
591 | |||
628 | class ProfilePlot(Figure): |
|
592 | class ProfilePlot(Figure): | |
629 | __isConfig = None |
|
593 | __isConfig = None | |
630 | __nsubplots = None |
|
594 | __nsubplots = None | |
631 |
|
595 | |||
632 | WIDTHPROF = None |
|
596 | WIDTHPROF = None | |
633 | HEIGHTPROF = None |
|
597 | HEIGHTPROF = None | |
634 | PREFIX = 'spcprofile' |
|
598 | PREFIX = 'spcprofile' | |
635 |
|
599 | |||
636 | def __init__(self): |
|
600 | def __init__(self): | |
637 | self.__isConfig = False |
|
601 | self.__isConfig = False | |
638 | self.__nsubplots = 1 |
|
602 | self.__nsubplots = 1 | |
639 |
|
603 | |||
640 | self.WIDTH = 300 |
|
604 | self.WIDTH = 300 | |
641 | self.HEIGHT = 500 |
|
605 | self.HEIGHT = 500 | |
642 |
|
606 | |||
643 | def getSubplots(self): |
|
607 | def getSubplots(self): | |
644 | ncol = 1 |
|
608 | ncol = 1 | |
645 | nrow = 1 |
|
609 | nrow = 1 | |
646 |
|
610 | |||
647 | return nrow, ncol |
|
611 | return nrow, ncol | |
648 |
|
612 | |||
649 | def setup(self, idfigure, nplots, wintitle): |
|
613 | def setup(self, idfigure, nplots, wintitle): | |
650 |
|
614 | |||
651 | self.nplots = nplots |
|
615 | self.nplots = nplots | |
652 |
|
616 | |||
653 | ncolspan = 1 |
|
617 | ncolspan = 1 | |
654 | colspan = 1 |
|
618 | colspan = 1 | |
655 |
|
619 | |||
656 | self.createFigure(idfigure = idfigure, |
|
620 | self.createFigure(idfigure = idfigure, | |
657 | wintitle = wintitle, |
|
621 | wintitle = wintitle, | |
658 | widthplot = self.WIDTH, |
|
622 | widthplot = self.WIDTH, | |
659 | heightplot = self.HEIGHT) |
|
623 | heightplot = self.HEIGHT) | |
660 |
|
624 | |||
661 | nrow, ncol = self.getSubplots() |
|
625 | nrow, ncol = self.getSubplots() | |
662 |
|
626 | |||
663 | counter = 0 |
|
627 | counter = 0 | |
664 | for y in range(nrow): |
|
628 | for y in range(nrow): | |
665 | for x in range(ncol): |
|
629 | for x in range(ncol): | |
666 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
630 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
667 |
|
631 | |||
668 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
632 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
669 |
xmin=None, xmax=None, ymin=None, ymax=None, |
|
633 | xmin=None, xmax=None, ymin=None, ymax=None, | |
670 | save=False, figpath='./', figfile=None): |
|
634 | save=False, figpath='./', figfile=None): | |
671 |
|
635 | |||
672 | if channelList == None: |
|
636 | if channelList == None: | |
673 | channelIndexList = dataOut.channelIndexList |
|
637 | channelIndexList = dataOut.channelIndexList | |
674 | channelList = dataOut.channelList |
|
638 | channelList = dataOut.channelList | |
675 | else: |
|
639 | else: | |
676 | channelIndexList = [] |
|
640 | channelIndexList = [] | |
677 | for channel in channelList: |
|
641 | for channel in channelList: | |
678 | if channel not in dataOut.channelList: |
|
642 | if channel not in dataOut.channelList: | |
679 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
643 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
680 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
644 | channelIndexList.append(dataOut.channelList.index(channel)) | |
681 |
|
645 | |||
682 |
factor = |
|
646 | factor = dataOut.normFactor | |
683 | if normalize: |
|
|||
684 | factor = dataOut.normFactor |
|
|||
685 | y = dataOut.getHeiRange() |
|
647 | y = dataOut.getHeiRange() | |
686 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
648 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
687 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
649 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
688 | avg = numpy.average(x, axis=1) |
|
650 | avg = numpy.average(x, axis=1) | |
689 |
|
651 | |||
690 | avgdB = 10*numpy.log10(avg) |
|
652 | avgdB = 10*numpy.log10(avg) | |
691 |
|
653 | |||
692 | thisDatetime = dataOut.datatime |
|
654 | thisDatetime = dataOut.datatime | |
693 | title = "Power Profile" |
|
655 | title = "Power Profile" | |
694 | xlabel = "dB" |
|
656 | xlabel = "dB" | |
695 | ylabel = "Range (Km)" |
|
657 | ylabel = "Range (Km)" | |
696 |
|
658 | |||
697 | if not self.__isConfig: |
|
659 | if not self.__isConfig: | |
698 |
|
660 | |||
699 | nplots = 1 |
|
661 | nplots = 1 | |
700 |
|
662 | |||
701 | self.setup(idfigure=idfigure, |
|
663 | self.setup(idfigure=idfigure, | |
702 | nplots=nplots, |
|
664 | nplots=nplots, | |
703 | wintitle=wintitle) |
|
665 | wintitle=wintitle) | |
704 |
|
666 | |||
705 | if ymin == None: ymin = numpy.nanmin(y) |
|
667 | if ymin == None: ymin = numpy.nanmin(y) | |
706 | if ymax == None: ymax = numpy.nanmax(y) |
|
668 | if ymax == None: ymax = numpy.nanmax(y) | |
707 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
669 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 | |
708 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
670 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 | |
709 |
|
671 | |||
710 | self.__isConfig = True |
|
672 | self.__isConfig = True | |
711 |
|
673 | |||
712 | self.setWinTitle(title) |
|
674 | self.setWinTitle(title) | |
713 |
|
675 | |||
714 |
|
676 | |||
715 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
677 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
716 | axes = self.axesList[0] |
|
678 | axes = self.axesList[0] | |
717 |
|
679 | |||
718 | legendlabels = ["channel %d"%x for x in channelList] |
|
680 | legendlabels = ["channel %d"%x for x in channelList] | |
719 | axes.pmultiline(avgdB, y, |
|
681 | axes.pmultiline(avgdB, y, | |
720 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
682 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
721 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
683 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
722 | ytick_visible=True, nxticks=5, |
|
684 | ytick_visible=True, nxticks=5, | |
723 | grid='x') |
|
685 | grid='x') | |
724 |
|
686 | |||
725 | self.draw() |
|
687 | self.draw() | |
726 |
|
688 | |||
727 | if save: |
|
689 | if save: | |
728 | date = thisDatetime.strftime("%Y%m%d") |
|
690 | date = thisDatetime.strftime("%Y%m%d") | |
729 | if figfile == None: |
|
691 | if figfile == None: | |
730 | figfile = self.getFilename(name = date) |
|
692 | figfile = self.getFilename(name = date) | |
731 |
|
693 | |||
732 | self.saveFigure(figpath, figfile) |
|
694 | self.saveFigure(figpath, figfile) | |
733 |
|
695 | |||
734 | class CoherenceMap(Figure): |
|
696 | class CoherenceMap(Figure): | |
735 | __isConfig = None |
|
697 | __isConfig = None | |
736 | __nsubplots = None |
|
698 | __nsubplots = None | |
737 |
|
699 | |||
738 | WIDTHPROF = None |
|
700 | WIDTHPROF = None | |
739 | HEIGHTPROF = None |
|
701 | HEIGHTPROF = None | |
740 | PREFIX = 'cmap' |
|
702 | PREFIX = 'coherencemap' | |
741 | __missing = 1E30 |
|
|||
742 |
|
703 | |||
743 | def __init__(self): |
|
704 | def __init__(self): | |
744 | self.timerange = 2*60*60 |
|
705 | self.timerange = 2*60*60 | |
745 | self.__isConfig = False |
|
706 | self.__isConfig = False | |
746 | self.__nsubplots = 1 |
|
707 | self.__nsubplots = 1 | |
747 |
|
708 | |||
748 | self.WIDTH = 800 |
|
709 | self.WIDTH = 800 | |
749 | self.HEIGHT = 200 |
|
710 | self.HEIGHT = 200 | |
750 | self.WIDTHPROF = 120 |
|
711 | self.WIDTHPROF = 120 | |
751 | self.HEIGHTPROF = 0 |
|
712 | self.HEIGHTPROF = 0 | |
752 | self.x_buffer = None |
|
|||
753 | self.coherence_buffer = None |
|
|||
754 | self.phase_buffer = None |
|
|||
755 |
|
713 | |||
756 | def getSubplots(self): |
|
714 | def getSubplots(self): | |
757 | ncol = 1 |
|
715 | ncol = 1 | |
758 | nrow = self.nplots*2 |
|
716 | nrow = self.nplots*2 | |
759 |
|
717 | |||
760 | return nrow, ncol |
|
718 | return nrow, ncol | |
761 |
|
719 | |||
762 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
720 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
763 | self.__showprofile = showprofile |
|
721 | self.__showprofile = showprofile | |
764 | self.nplots = nplots |
|
722 | self.nplots = nplots | |
765 |
|
723 | |||
766 | ncolspan = 1 |
|
724 | ncolspan = 1 | |
767 | colspan = 1 |
|
725 | colspan = 1 | |
768 | if showprofile: |
|
726 | if showprofile: | |
769 | ncolspan = 7 |
|
727 | ncolspan = 7 | |
770 | colspan = 6 |
|
728 | colspan = 6 | |
771 | self.__nsubplots = 2 |
|
729 | self.__nsubplots = 2 | |
772 |
|
730 | |||
773 | self.createFigure(idfigure = idfigure, |
|
731 | self.createFigure(idfigure = idfigure, | |
774 | wintitle = wintitle, |
|
732 | wintitle = wintitle, | |
775 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
733 | widthplot = self.WIDTH + self.WIDTHPROF, | |
776 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
734 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
777 |
|
735 | |||
778 | nrow, ncol = self.getSubplots() |
|
736 | nrow, ncol = self.getSubplots() | |
779 |
|
737 | |||
780 | for y in range(nrow): |
|
738 | for y in range(nrow): | |
781 | for x in range(ncol): |
|
739 | for x in range(ncol): | |
782 |
|
740 | |||
783 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
741 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
784 |
|
742 | |||
785 | if showprofile: |
|
743 | if showprofile: | |
786 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
744 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
787 |
|
745 | |||
788 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
746 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |
789 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
747 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
790 | timerange=None, |
|
748 | timerange=None, | |
791 |
save=False, figpath='./', figfile=None |
|
749 | save=False, figpath='./', figfile=None): | |
792 | coherence_cmap='jet', phase_cmap='RdBu_r'): |
|
|||
793 |
|
750 | |||
794 | if pairsList == None: |
|
751 | if pairsList == None: | |
795 | pairsIndexList = dataOut.pairsIndexList |
|
752 | pairsIndexList = dataOut.pairsIndexList | |
796 | else: |
|
753 | else: | |
797 | pairsIndexList = [] |
|
754 | pairsIndexList = [] | |
798 | for pair in pairsList: |
|
755 | for pair in pairsList: | |
799 | if pair not in dataOut.pairsList: |
|
756 | if pair not in dataOut.pairsList: | |
800 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
757 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
801 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
758 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
802 |
|
759 | |||
803 | if timerange != None: |
|
760 | if timerange != None: | |
804 | self.timerange = timerange |
|
761 | self.timerange = timerange | |
805 |
|
762 | |||
806 | if pairsIndexList == []: |
|
763 | if pairsIndexList == []: | |
807 | return |
|
764 | return | |
808 |
|
765 | |||
809 | if len(pairsIndexList) > 4: |
|
766 | if len(pairsIndexList) > 4: | |
810 | pairsIndexList = pairsIndexList[0:4] |
|
767 | pairsIndexList = pairsIndexList[0:4] | |
811 |
|
768 | |||
812 | tmin = None |
|
769 | tmin = None | |
813 | tmax = None |
|
770 | tmax = None | |
814 | x = dataOut.getTimeRange() |
|
771 | x = dataOut.getTimeRange() | |
815 | y = dataOut.getHeiRange() |
|
772 | y = dataOut.getHeiRange() | |
816 |
|
773 | |||
817 | thisDatetime = dataOut.datatime |
|
774 | thisDatetime = dataOut.datatime | |
818 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
775 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
819 | xlabel = "" |
|
776 | xlabel = "" | |
820 | ylabel = "Range (Km)" |
|
777 | ylabel = "Range (Km)" | |
821 |
|
778 | |||
822 | if not self.__isConfig: |
|
779 | if not self.__isConfig: | |
823 | nplots = len(pairsIndexList) |
|
780 | nplots = len(pairsIndexList) | |
824 | self.setup(idfigure=idfigure, |
|
781 | self.setup(idfigure=idfigure, | |
825 | nplots=nplots, |
|
782 | nplots=nplots, | |
826 | wintitle=wintitle, |
|
783 | wintitle=wintitle, | |
827 | showprofile=showprofile) |
|
784 | showprofile=showprofile) | |
828 |
|
785 | |||
829 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
786 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
830 | if ymin == None: ymin = numpy.nanmin(y) |
|
787 | if ymin == None: ymin = numpy.nanmin(y) | |
831 | if ymax == None: ymax = numpy.nanmax(y) |
|
788 | if ymax == None: ymax = numpy.nanmax(y) | |
832 |
|
789 | |||
833 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
790 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
834 | self.x_buffer = numpy.array([]) |
|
791 | ||
835 | self.coherence_buffer = numpy.array([]) |
|
|||
836 | self.phase_buffer = numpy.array([]) |
|
|||
837 | self.__isConfig = True |
|
792 | self.__isConfig = True | |
838 |
|
793 | |||
839 | self.setWinTitle(title) |
|
794 | self.setWinTitle(title) | |
840 |
|
795 | |||
|
796 | for i in range(self.nplots): | |||
|
797 | ||||
|
798 | pair = dataOut.pairsList[pairsIndexList[i]] | |||
|
799 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |||
|
800 | coherence = numpy.abs(coherenceComplex) | |||
|
801 | avg = numpy.average(coherence, axis=0) | |||
|
802 | z = avg.reshape((1,-1)) | |||
841 |
|
803 | |||
842 | pairArray = numpy.array(dataOut.pairsList) |
|
804 | counter = 0 | |
843 | pairArray = pairArray[pairsIndexList] |
|
|||
844 | pair0ids = pairArray[:,0] |
|
|||
845 | pair1ids = pairArray[:,1] |
|
|||
846 |
|
||||
847 | coherenceComplex = dataOut.data_cspc[pairsIndexList,:,:]/numpy.sqrt(dataOut.data_spc[pair0ids,:,:]*dataOut.data_spc[pair1ids,:,:]) |
|
|||
848 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=1) |
|
|||
849 | coherence = numpy.abs(avgcoherenceComplex) |
|
|||
850 |
|
||||
851 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
|||
852 |
|
||||
853 | if len(self.coherence_buffer)==0: |
|
|||
854 | self.coherence_buffer = coherence |
|
|||
855 | self.phase_buffer = phase |
|
|||
856 | newxdim = 1 |
|
|||
857 | newydim = -1 |
|
|||
858 | else: |
|
|||
859 | if x[0]>self.x_buffer[-1]: |
|
|||
860 | gap = coherence.copy() |
|
|||
861 | gap[:] = self.__missing |
|
|||
862 | self.coherence_buffer = numpy.hstack((self.coherence_buffer, gap)) |
|
|||
863 | self.phase_buffer = numpy.hstack((self.phase_buffer, gap)) |
|
|||
864 |
|
805 | |||
865 | self.coherence_buffer = numpy.hstack((self.coherence_buffer, coherence)) |
|
806 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
866 | self.phase_buffer = numpy.hstack((self.phase_buffer, phase)) |
|
|||
867 | newxdim = -1 |
|
|||
868 | newydim = len(y) |
|
|||
869 |
|
||||
870 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
|||
871 |
|
||||
872 | self.coherence_buffer = numpy.ma.masked_inside(self.coherence_buffer,0.99*self.__missing,1.01*self.__missing) |
|
|||
873 | self.phase_buffer = numpy.ma.masked_inside(self.phase_buffer,0.99*self.__missing,1.01*self.__missing) |
|
|||
874 |
|
||||
875 |
|
||||
876 | for i in range(self.nplots): |
|
|||
877 | counter = 0 |
|
|||
878 | z = self.coherence_buffer[i,:].reshape((newxdim,newydim)) |
|
|||
879 | title = "Coherence %d%d: %s" %(pair0ids[i], pair1ids[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
|||
880 | axes = self.axesList[i*self.__nsubplots*2] |
|
807 | axes = self.axesList[i*self.__nsubplots*2] | |
881 |
axes.pcolor( |
|
808 | axes.pcolor(x, y, z, | |
882 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
809 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
883 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
810 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
884 |
ticksize=9, cblabel='', |
|
811 | ticksize=9, cblabel='', cbsize="1%") | |
885 |
|
812 | |||
886 | if self.__showprofile: |
|
813 | if self.__showprofile: | |
887 | counter += 1 |
|
814 | counter += 1 | |
888 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
815 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
889 |
axes.pline( |
|
816 | axes.pline(avg, y, | |
890 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
817 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, | |
891 | xlabel='', ylabel='', title='', ticksize=7, |
|
818 | xlabel='', ylabel='', title='', ticksize=7, | |
892 | ytick_visible=False, nxticks=5, |
|
819 | ytick_visible=False, nxticks=5, | |
893 | grid='x') |
|
820 | grid='x') | |
894 |
|
821 | |||
895 | counter += 1 |
|
822 | counter += 1 | |
896 |
|
823 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | ||
897 | z = self.phase_buffer[i,:].reshape((newxdim,newydim)) |
|
824 | avg = numpy.average(phase, axis=0) | |
|
825 | z = avg.reshape((1,-1)) | |||
898 |
|
826 | |||
899 |
title = "Phase %d%d: %s" %(pair |
|
827 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
900 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
828 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
901 |
axes.pcolor( |
|
829 | axes.pcolor(x, y, z, | |
902 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
830 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
903 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
831 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
904 |
ticksize=9, cblabel='', colormap= |
|
832 | ticksize=9, cblabel='', colormap='RdBu', cbsize="1%") | |
905 |
|
833 | |||
906 | if self.__showprofile: |
|
834 | if self.__showprofile: | |
907 | counter += 1 |
|
835 | counter += 1 | |
908 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
836 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
909 |
axes.pline( |
|
837 | axes.pline(avg, y, | |
910 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
838 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
911 | xlabel='', ylabel='', title='', ticksize=7, |
|
839 | xlabel='', ylabel='', title='', ticksize=7, | |
912 | ytick_visible=False, nxticks=4, |
|
840 | ytick_visible=False, nxticks=4, | |
913 | grid='x') |
|
841 | grid='x') | |
914 |
|
842 | |||
915 | self.draw() |
|
843 | self.draw() | |
916 |
|
844 | |||
917 | if save: |
|
845 | if save: | |
918 |
|
846 | |||
919 | if figfile == None: |
|
847 | if figfile == None: | |
920 | figfile = self.getFilename(name = self.name) |
|
848 | figfile = self.getFilename(name = self.name) | |
921 |
|
849 | |||
922 | self.saveFigure(figpath, figfile) |
|
850 | self.saveFigure(figpath, figfile) | |
923 |
|
851 | |||
924 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
852 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
925 | self.__isConfig = False |
|
853 | self.__isConfig = False | |
926 |
|
854 | |||
927 | class RTIfromNoise(Figure): |
|
855 | class RTIfromNoise(Figure): | |
928 |
|
856 | |||
929 | __isConfig = None |
|
857 | __isConfig = None | |
930 | __nsubplots = None |
|
858 | __nsubplots = None | |
931 |
|
859 | |||
932 | PREFIX = 'rtinoise' |
|
860 | PREFIX = 'rtinoise' | |
933 |
|
861 | |||
934 | def __init__(self): |
|
862 | def __init__(self): | |
935 |
|
863 | |||
936 | self.timerange = 24*60*60 |
|
864 | self.timerange = 24*60*60 | |
937 | self.__isConfig = False |
|
865 | self.__isConfig = False | |
938 | self.__nsubplots = 1 |
|
866 | self.__nsubplots = 1 | |
939 |
|
867 | |||
940 | self.WIDTH = 820 |
|
868 | self.WIDTH = 820 | |
941 | self.HEIGHT = 200 |
|
869 | self.HEIGHT = 200 | |
942 | self.WIDTHPROF = 120 |
|
870 | self.WIDTHPROF = 120 | |
943 | self.HEIGHTPROF = 0 |
|
871 | self.HEIGHTPROF = 0 | |
944 | self.xdata = None |
|
872 | self.xdata = None | |
945 | self.ydata = None |
|
873 | self.ydata = None | |
946 |
|
874 | |||
947 | def getSubplots(self): |
|
875 | def getSubplots(self): | |
948 |
|
876 | |||
949 | ncol = 1 |
|
877 | ncol = 1 | |
950 | nrow = 1 |
|
878 | nrow = 1 | |
951 |
|
879 | |||
952 | return nrow, ncol |
|
880 | return nrow, ncol | |
953 |
|
881 | |||
954 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
882 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
955 |
|
883 | |||
956 | self.__showprofile = showprofile |
|
884 | self.__showprofile = showprofile | |
957 | self.nplots = nplots |
|
885 | self.nplots = nplots | |
958 |
|
886 | |||
959 | ncolspan = 7 |
|
887 | ncolspan = 7 | |
960 | colspan = 6 |
|
888 | colspan = 6 | |
961 | self.__nsubplots = 2 |
|
889 | self.__nsubplots = 2 | |
962 |
|
890 | |||
963 | self.createFigure(idfigure = idfigure, |
|
891 | self.createFigure(idfigure = idfigure, | |
964 | wintitle = wintitle, |
|
892 | wintitle = wintitle, | |
965 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
893 | widthplot = self.WIDTH+self.WIDTHPROF, | |
966 | heightplot = self.HEIGHT+self.HEIGHTPROF) |
|
894 | heightplot = self.HEIGHT+self.HEIGHTPROF) | |
967 |
|
895 | |||
968 | nrow, ncol = self.getSubplots() |
|
896 | nrow, ncol = self.getSubplots() | |
969 |
|
897 | |||
970 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
898 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
971 |
|
899 | |||
972 |
|
900 | |||
973 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
901 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
974 |
xmin=None, xmax=None, ymin=None, ymax=None, |
|
902 | xmin=None, xmax=None, ymin=None, ymax=None, | |
975 | timerange=None, |
|
903 | timerange=None, | |
976 | save=False, figpath='./', figfile=None): |
|
904 | save=False, figpath='./', figfile=None): | |
977 |
|
905 | |||
978 | if channelList == None: |
|
906 | if channelList == None: | |
979 | channelIndexList = dataOut.channelIndexList |
|
907 | channelIndexList = dataOut.channelIndexList | |
980 | channelList = dataOut.channelList |
|
908 | channelList = dataOut.channelList | |
981 | else: |
|
909 | else: | |
982 | channelIndexList = [] |
|
910 | channelIndexList = [] | |
983 | for channel in channelList: |
|
911 | for channel in channelList: | |
984 | if channel not in dataOut.channelList: |
|
912 | if channel not in dataOut.channelList: | |
985 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
913 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
986 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
914 | channelIndexList.append(dataOut.channelList.index(channel)) | |
987 |
|
915 | |||
988 | if timerange != None: |
|
916 | if timerange != None: | |
989 | self.timerange = timerange |
|
917 | self.timerange = timerange | |
990 |
|
918 | |||
991 | tmin = None |
|
919 | tmin = None | |
992 | tmax = None |
|
920 | tmax = None | |
993 | x = dataOut.getTimeRange() |
|
921 | x = dataOut.getTimeRange() | |
994 | y = dataOut.getHeiRange() |
|
922 | y = dataOut.getHeiRange() | |
995 |
factor = |
|
923 | factor = dataOut.normFactor | |
996 | if normalize: |
|
|||
997 | factor = dataOut.normFactor |
|
|||
998 | noise = dataOut.getNoise()/factor |
|
924 | noise = dataOut.getNoise()/factor | |
999 | noisedB = 10*numpy.log10(noise) |
|
925 | noisedB = 10*numpy.log10(noise) | |
1000 |
|
926 | |||
1001 | thisDatetime = dataOut.datatime |
|
927 | thisDatetime = dataOut.datatime | |
1002 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
928 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1003 | xlabel = "" |
|
929 | xlabel = "" | |
1004 | ylabel = "Range (Km)" |
|
930 | ylabel = "Range (Km)" | |
1005 |
|
931 | |||
1006 | if not self.__isConfig: |
|
932 | if not self.__isConfig: | |
1007 |
|
933 | |||
1008 | nplots = 1 |
|
934 | nplots = 1 | |
1009 |
|
935 | |||
1010 | self.setup(idfigure=idfigure, |
|
936 | self.setup(idfigure=idfigure, | |
1011 | nplots=nplots, |
|
937 | nplots=nplots, | |
1012 | wintitle=wintitle, |
|
938 | wintitle=wintitle, | |
1013 | showprofile=showprofile) |
|
939 | showprofile=showprofile) | |
1014 |
|
940 | |||
1015 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
941 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1016 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
942 | if ymin == None: ymin = numpy.nanmin(noisedB) | |
1017 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
943 | if ymax == None: ymax = numpy.nanmax(noisedB) | |
1018 |
|
944 | |||
1019 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
945 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1020 | self.__isConfig = True |
|
946 | self.__isConfig = True | |
1021 |
|
947 | |||
1022 | self.xdata = numpy.array([]) |
|
948 | self.xdata = numpy.array([]) | |
1023 | self.ydata = numpy.array([]) |
|
949 | self.ydata = numpy.array([]) | |
1024 |
|
950 | |||
1025 | self.setWinTitle(title) |
|
951 | self.setWinTitle(title) | |
1026 |
|
952 | |||
1027 |
|
953 | |||
1028 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
954 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1029 |
|
955 | |||
1030 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
956 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
1031 | axes = self.axesList[0] |
|
957 | axes = self.axesList[0] | |
1032 |
|
958 | |||
1033 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
959 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1034 |
|
960 | |||
1035 | if len(self.ydata)==0: |
|
961 | if len(self.ydata)==0: | |
1036 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
962 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1037 | else: |
|
963 | else: | |
1038 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
964 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1039 |
|
965 | |||
1040 |
|
966 | |||
1041 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
967 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1042 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
968 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1043 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
969 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1044 | XAxisAsTime=True |
|
970 | XAxisAsTime=True | |
1045 | ) |
|
971 | ) | |
1046 |
|
972 | |||
1047 | self.draw() |
|
973 | self.draw() | |
1048 |
|
974 | |||
1049 | if save: |
|
975 | if save: | |
1050 |
|
976 | |||
1051 | if figfile == None: |
|
977 | if figfile == None: | |
1052 | figfile = self.getFilename(name = self.name) |
|
978 | figfile = self.getFilename(name = self.name) | |
1053 |
|
979 | |||
1054 | self.saveFigure(figpath, figfile) |
|
980 | self.saveFigure(figpath, figfile) | |
1055 |
|
981 | |||
1056 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
982 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1057 | self.__isConfig = False |
|
983 | self.__isConfig = False | |
1058 | del self.xdata |
|
984 | del self.xdata | |
1059 | del self.ydata |
|
985 | del self.ydata | |
1060 | No newline at end of file |
|
986 |
General Comments 0
You need to be logged in to leave comments.
Login now