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