@@ -1,326 +1,328 | |||
|
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 SpectraHeisScope(Figure): |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | isConfig = None |
|
17 | 17 | __nsubplots = None |
|
18 | 18 | |
|
19 | 19 | WIDTHPROF = None |
|
20 | 20 | HEIGHTPROF = None |
|
21 | 21 | PREFIX = 'spc' |
|
22 | 22 | |
|
23 | 23 | def __init__(self): |
|
24 | 24 | |
|
25 | 25 | self.isConfig = False |
|
26 | 26 | self.__nsubplots = 1 |
|
27 | 27 | |
|
28 | 28 | self.WIDTH = 230 |
|
29 | 29 | self.HEIGHT = 250 |
|
30 | 30 | self.WIDTHPROF = 120 |
|
31 | 31 | self.HEIGHTPROF = 0 |
|
32 | 32 | self.counter_imagwr = 0 |
|
33 | 33 | |
|
34 | 34 | self.PLOT_CODE = SPEC_CODE |
|
35 | 35 | |
|
36 | 36 | def getSubplots(self): |
|
37 | 37 | |
|
38 | 38 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
39 | 39 | nrow = int(self.nplots*1./ncol + 0.9) |
|
40 | 40 | |
|
41 | 41 | return nrow, ncol |
|
42 | 42 | |
|
43 | 43 | def setup(self, id, nplots, wintitle, show): |
|
44 | 44 | |
|
45 | 45 | showprofile = False |
|
46 | 46 | self.__showprofile = showprofile |
|
47 | 47 | self.nplots = nplots |
|
48 | 48 | |
|
49 | 49 | ncolspan = 1 |
|
50 | 50 | colspan = 1 |
|
51 | 51 | if showprofile: |
|
52 | 52 | ncolspan = 3 |
|
53 | 53 | colspan = 2 |
|
54 | 54 | self.__nsubplots = 2 |
|
55 | 55 | |
|
56 | 56 | self.createFigure(id = id, |
|
57 | 57 | wintitle = wintitle, |
|
58 | 58 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
59 | 59 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
60 | 60 | show = show) |
|
61 | 61 | |
|
62 | 62 | nrow, ncol = self.getSubplots() |
|
63 | 63 | |
|
64 | 64 | counter = 0 |
|
65 | 65 | for y in range(nrow): |
|
66 | 66 | for x in range(ncol): |
|
67 | 67 | |
|
68 | 68 | if counter >= self.nplots: |
|
69 | 69 | break |
|
70 | 70 | |
|
71 | 71 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
72 | 72 | |
|
73 | 73 | if showprofile: |
|
74 | 74 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
75 | 75 | |
|
76 | 76 | counter += 1 |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
80 | 80 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
81 | 81 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
82 | 82 | server=None, folder=None, username=None, password=None, |
|
83 | 83 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
84 | 84 | |
|
85 | 85 | """ |
|
86 | 86 | |
|
87 | 87 | Input: |
|
88 | 88 | dataOut : |
|
89 | 89 | id : |
|
90 | 90 | wintitle : |
|
91 | 91 | channelList : |
|
92 | 92 | xmin : None, |
|
93 | 93 | xmax : None, |
|
94 | 94 | ymin : None, |
|
95 | 95 | ymax : None, |
|
96 | 96 | """ |
|
97 | 97 | |
|
98 | 98 | if dataOut.realtime: |
|
99 | 99 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
100 | 100 | print 'Skipping this plot function' |
|
101 | 101 | return |
|
102 | 102 | |
|
103 | 103 | if channelList == None: |
|
104 | 104 | channelIndexList = dataOut.channelIndexList |
|
105 | 105 | else: |
|
106 | 106 | channelIndexList = [] |
|
107 | 107 | for channel in channelList: |
|
108 | 108 | if channel not in dataOut.channelList: |
|
109 | 109 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
110 | 110 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
111 | 111 | |
|
112 | 112 | # x = dataOut.heightList |
|
113 | 113 | c = 3E8 |
|
114 | 114 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
115 | 115 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
116 | 116 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
117 | 117 | #para 1Mhz descomentar la siguiente linea |
|
118 | 118 | #x= x/(10000.0) |
|
119 | 119 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
120 | 120 | # y = y.real |
|
121 | 121 | factor = dataOut.normFactor |
|
122 | 122 | data = dataOut.data_spc / factor |
|
123 | 123 | datadB = 10.*numpy.log10(data) |
|
124 | 124 | y = datadB |
|
125 | 125 | |
|
126 | 126 | #thisDatetime = dataOut.datatime |
|
127 | 127 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
128 | 128 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
129 | 129 | xlabel = "" |
|
130 | 130 | #para 1Mhz descomentar la siguiente linea |
|
131 | 131 | #xlabel = "Frequency x 10000" |
|
132 | 132 | ylabel = "Intensity (dB)" |
|
133 | 133 | |
|
134 | 134 | if not self.isConfig: |
|
135 | 135 | nplots = len(channelIndexList) |
|
136 | 136 | |
|
137 | 137 | self.setup(id=id, |
|
138 | 138 | nplots=nplots, |
|
139 | 139 | wintitle=wintitle, |
|
140 | 140 | show=show) |
|
141 | 141 | |
|
142 | 142 | if xmin == None: xmin = numpy.nanmin(x) |
|
143 | 143 | if xmax == None: xmax = numpy.nanmax(x) |
|
144 | 144 | if ymin == None: ymin = numpy.nanmin(y) |
|
145 | 145 | if ymax == None: ymax = numpy.nanmax(y) |
|
146 | 146 | |
|
147 | 147 | self.FTP_WEI = ftp_wei |
|
148 | 148 | self.EXP_CODE = exp_code |
|
149 | 149 | self.SUB_EXP_CODE = sub_exp_code |
|
150 | 150 | self.PLOT_POS = plot_pos |
|
151 | 151 | |
|
152 | 152 | self.isConfig = True |
|
153 | 153 | |
|
154 | 154 | self.setWinTitle(title) |
|
155 | 155 | |
|
156 | 156 | for i in range(len(self.axesList)): |
|
157 | 157 | ychannel = y[i,:] |
|
158 | 158 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
159 | 159 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime) |
|
160 | 160 | axes = self.axesList[i] |
|
161 | 161 | axes.pline(x, ychannel, |
|
162 | 162 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
163 | 163 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
164 | 164 | |
|
165 | 165 | |
|
166 | 166 | self.draw() |
|
167 | 167 | |
|
168 | 168 | self.save(figpath=figpath, |
|
169 | 169 | figfile=figfile, |
|
170 | 170 | save=save, |
|
171 | 171 | ftp=ftp, |
|
172 | 172 | wr_period=wr_period, |
|
173 | 173 | thisDatetime=thisDatetime) |
|
174 | 174 | |
|
175 | 175 | class RTIfromSpectraHeis(Figure): |
|
176 | 176 | |
|
177 | 177 | isConfig = None |
|
178 | 178 | __nsubplots = None |
|
179 | 179 | |
|
180 | 180 | PREFIX = 'rtinoise' |
|
181 | 181 | |
|
182 | 182 | def __init__(self): |
|
183 | 183 | |
|
184 | 184 | self.timerange = 24*60*60 |
|
185 | 185 | self.isConfig = False |
|
186 | 186 | self.__nsubplots = 1 |
|
187 | 187 | |
|
188 | 188 | self.WIDTH = 820 |
|
189 | 189 | self.HEIGHT = 200 |
|
190 | 190 | self.WIDTHPROF = 120 |
|
191 | 191 | self.HEIGHTPROF = 0 |
|
192 | 192 | self.counter_imagwr = 0 |
|
193 | 193 | self.xdata = None |
|
194 | 194 | self.ydata = None |
|
195 | 195 | self.figfile = None |
|
196 | 196 | |
|
197 | 197 | self.PLOT_CODE = RTI_CODE |
|
198 | 198 | |
|
199 | 199 | def getSubplots(self): |
|
200 | 200 | |
|
201 | 201 | ncol = 1 |
|
202 | 202 | nrow = 1 |
|
203 | 203 | |
|
204 | 204 | return nrow, ncol |
|
205 | 205 | |
|
206 | 206 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
207 | 207 | |
|
208 | 208 | self.__showprofile = showprofile |
|
209 | 209 | self.nplots = nplots |
|
210 | 210 | |
|
211 | 211 | ncolspan = 7 |
|
212 | 212 | colspan = 6 |
|
213 | 213 | self.__nsubplots = 2 |
|
214 | 214 | |
|
215 | 215 | self.createFigure(id = id, |
|
216 | 216 | wintitle = wintitle, |
|
217 | 217 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
218 | 218 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
219 | 219 | show = show) |
|
220 | 220 | |
|
221 | 221 | nrow, ncol = self.getSubplots() |
|
222 | 222 | |
|
223 | 223 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
224 | 224 | |
|
225 | 225 | |
|
226 | 226 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
227 | 227 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
228 | 228 | timerange=None, |
|
229 | 229 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
230 | 230 | server=None, folder=None, username=None, password=None, |
|
231 | 231 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
232 | 232 | |
|
233 | 233 | if channelList == None: |
|
234 | 234 | channelIndexList = dataOut.channelIndexList |
|
235 | 235 | channelList = dataOut.channelList |
|
236 | 236 | else: |
|
237 | 237 | channelIndexList = [] |
|
238 | 238 | for channel in channelList: |
|
239 | 239 | if channel not in dataOut.channelList: |
|
240 | 240 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
241 | 241 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
242 | 242 | |
|
243 | 243 | if timerange != None: |
|
244 | 244 | self.timerange = timerange |
|
245 | 245 | |
|
246 | 246 | x = dataOut.getTimeRange() |
|
247 | 247 | y = dataOut.getHeiRange() |
|
248 | 248 | |
|
249 | 249 | factor = dataOut.normFactor |
|
250 | 250 | data = dataOut.data_spc / factor |
|
251 | 251 | data = numpy.average(data,axis=1) |
|
252 | 252 | datadB = 10*numpy.log10(data) |
|
253 | 253 | |
|
254 | 254 | # factor = dataOut.normFactor |
|
255 | 255 | # noise = dataOut.getNoise()/factor |
|
256 | 256 | # noisedB = 10*numpy.log10(noise) |
|
257 | 257 | |
|
258 | 258 | #thisDatetime = dataOut.datatime |
|
259 | 259 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
260 | 260 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
261 | 261 | xlabel = "Local Time" |
|
262 | 262 | ylabel = "Intensity (dB)" |
|
263 | 263 | |
|
264 | 264 | if not self.isConfig: |
|
265 | 265 | |
|
266 | 266 | nplots = 1 |
|
267 | 267 | |
|
268 | 268 | self.setup(id=id, |
|
269 | 269 | nplots=nplots, |
|
270 | 270 | wintitle=wintitle, |
|
271 | 271 | showprofile=showprofile, |
|
272 | 272 | show=show) |
|
273 | 273 | |
|
274 | 274 | self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax) |
|
275 | 275 | |
|
276 | 276 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
277 | 277 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
278 | 278 | |
|
279 | 279 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
280 | 280 | self.isConfig = True |
|
281 | 281 | self.figfile = figfile |
|
282 | 282 | self.xdata = numpy.array([]) |
|
283 | 283 | self.ydata = numpy.array([]) |
|
284 | 284 | |
|
285 | 285 | self.FTP_WEI = ftp_wei |
|
286 | 286 | self.EXP_CODE = exp_code |
|
287 | 287 | self.SUB_EXP_CODE = sub_exp_code |
|
288 | 288 | self.PLOT_POS = plot_pos |
|
289 | 289 | |
|
290 | 290 | self.setWinTitle(title) |
|
291 | 291 | |
|
292 | 292 | |
|
293 | 293 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
294 | 294 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
295 | 295 | |
|
296 | 296 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
297 | 297 | axes = self.axesList[0] |
|
298 | 298 | |
|
299 | 299 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
300 | 300 | |
|
301 | 301 | if len(self.ydata)==0: |
|
302 | 302 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
303 | 303 | else: |
|
304 | 304 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
305 | 305 | |
|
306 | 306 | |
|
307 | 307 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
308 | 308 | xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax, |
|
309 | 309 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
310 | 310 | XAxisAsTime=True |
|
311 | 311 | ) |
|
312 | 312 | |
|
313 | 313 | self.draw() |
|
314 | 314 | |
|
315 | update_figfile = False | |
|
316 | ||
|
315 | 317 | if dataOut.ltctime >= self.tmax: |
|
316 | 318 | self.counter_imagwr = wr_period |
|
317 | 319 | self.isConfig = False |
|
318 | 320 | update_figfile = True |
|
319 | 321 | |
|
320 | 322 | self.save(figpath=figpath, |
|
321 | 323 | figfile=figfile, |
|
322 | 324 | save=save, |
|
323 | 325 | ftp=ftp, |
|
324 | 326 | wr_period=wr_period, |
|
325 | 327 | thisDatetime=thisDatetime, |
|
326 | 328 | update_figfile=update_figfile) |
General Comments 0
You need to be logged in to leave comments.
Login now