@@ -1,1362 +1,1363 | |||||
1 | import os |
|
1 | import os | |
2 | import datetime |
|
2 | import datetime | |
3 | import numpy |
|
3 | import numpy | |
4 |
|
4 | |||
5 | from figure import Figure, isRealtime |
|
5 | from figure import Figure, isRealtime | |
6 | from plotting_codes import * |
|
6 | from plotting_codes import * | |
7 |
|
7 | |||
8 | class MomentsPlot(Figure): |
|
8 | class MomentsPlot(Figure): | |
9 |
|
9 | |||
10 | isConfig = None |
|
10 | isConfig = None | |
11 | __nsubplots = None |
|
11 | __nsubplots = None | |
12 |
|
12 | |||
13 | WIDTHPROF = None |
|
13 | WIDTHPROF = None | |
14 | HEIGHTPROF = None |
|
14 | HEIGHTPROF = None | |
15 | PREFIX = 'prm' |
|
15 | PREFIX = 'prm' | |
16 |
|
16 | |||
17 | def __init__(self): |
|
17 | def __init__(self): | |
18 |
|
18 | |||
19 | self.isConfig = False |
|
19 | self.isConfig = False | |
20 | self.__nsubplots = 1 |
|
20 | self.__nsubplots = 1 | |
21 |
|
21 | |||
22 | self.WIDTH = 280 |
|
22 | self.WIDTH = 280 | |
23 | self.HEIGHT = 250 |
|
23 | self.HEIGHT = 250 | |
24 | self.WIDTHPROF = 120 |
|
24 | self.WIDTHPROF = 120 | |
25 | self.HEIGHTPROF = 0 |
|
25 | self.HEIGHTPROF = 0 | |
26 | self.counter_imagwr = 0 |
|
26 | self.counter_imagwr = 0 | |
27 |
|
27 | |||
28 | self.PLOT_CODE = MOMENTS_CODE |
|
28 | self.PLOT_CODE = MOMENTS_CODE | |
29 |
|
29 | |||
30 | self.FTP_WEI = None |
|
30 | self.FTP_WEI = None | |
31 | self.EXP_CODE = None |
|
31 | self.EXP_CODE = None | |
32 | self.SUB_EXP_CODE = None |
|
32 | self.SUB_EXP_CODE = None | |
33 | self.PLOT_POS = None |
|
33 | self.PLOT_POS = None | |
34 |
|
34 | |||
35 | def getSubplots(self): |
|
35 | def getSubplots(self): | |
36 |
|
36 | |||
37 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
37 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
38 | nrow = int(self.nplots*1./ncol + 0.9) |
|
38 | nrow = int(self.nplots*1./ncol + 0.9) | |
39 |
|
39 | |||
40 | return nrow, ncol |
|
40 | return nrow, ncol | |
41 |
|
41 | |||
42 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
42 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
43 |
|
43 | |||
44 | self.__showprofile = showprofile |
|
44 | self.__showprofile = showprofile | |
45 | self.nplots = nplots |
|
45 | self.nplots = nplots | |
46 |
|
46 | |||
47 | ncolspan = 1 |
|
47 | ncolspan = 1 | |
48 | colspan = 1 |
|
48 | colspan = 1 | |
49 | if showprofile: |
|
49 | if showprofile: | |
50 | ncolspan = 3 |
|
50 | ncolspan = 3 | |
51 | colspan = 2 |
|
51 | colspan = 2 | |
52 | self.__nsubplots = 2 |
|
52 | self.__nsubplots = 2 | |
53 |
|
53 | |||
54 | self.createFigure(id = id, |
|
54 | self.createFigure(id = id, | |
55 | wintitle = wintitle, |
|
55 | wintitle = wintitle, | |
56 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
56 | widthplot = self.WIDTH + self.WIDTHPROF, | |
57 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
57 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
58 | show=show) |
|
58 | show=show) | |
59 |
|
59 | |||
60 | nrow, ncol = self.getSubplots() |
|
60 | nrow, ncol = self.getSubplots() | |
61 |
|
61 | |||
62 | counter = 0 |
|
62 | counter = 0 | |
63 | for y in range(nrow): |
|
63 | for y in range(nrow): | |
64 | for x in range(ncol): |
|
64 | for x in range(ncol): | |
65 |
|
65 | |||
66 | if counter >= self.nplots: |
|
66 | if counter >= self.nplots: | |
67 | break |
|
67 | break | |
68 |
|
68 | |||
69 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
69 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
70 |
|
70 | |||
71 | if showprofile: |
|
71 | if showprofile: | |
72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
73 |
|
73 | |||
74 | counter += 1 |
|
74 | counter += 1 | |
75 |
|
75 | |||
76 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
76 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
77 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
77 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
78 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
78 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
79 | server=None, folder=None, username=None, password=None, |
|
79 | server=None, folder=None, username=None, password=None, | |
80 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
80 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
81 |
|
81 | |||
82 | """ |
|
82 | """ | |
83 |
|
83 | |||
84 | Input: |
|
84 | Input: | |
85 | dataOut : |
|
85 | dataOut : | |
86 | id : |
|
86 | id : | |
87 | wintitle : |
|
87 | wintitle : | |
88 | channelList : |
|
88 | channelList : | |
89 | showProfile : |
|
89 | showProfile : | |
90 | xmin : None, |
|
90 | xmin : None, | |
91 | xmax : None, |
|
91 | xmax : None, | |
92 | ymin : None, |
|
92 | ymin : None, | |
93 | ymax : None, |
|
93 | ymax : None, | |
94 | zmin : None, |
|
94 | zmin : None, | |
95 | zmax : None |
|
95 | zmax : None | |
96 | """ |
|
96 | """ | |
97 |
|
97 | |||
98 | if dataOut.flagNoData: |
|
98 | if dataOut.flagNoData: | |
99 | return None |
|
99 | return None | |
100 |
|
100 | |||
101 | if realtime: |
|
101 | if realtime: | |
102 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
102 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
103 | print 'Skipping this plot function' |
|
103 | print 'Skipping this plot function' | |
104 | return |
|
104 | return | |
105 |
|
105 | |||
106 | if channelList == None: |
|
106 | if channelList == None: | |
107 | channelIndexList = dataOut.channelIndexList |
|
107 | channelIndexList = dataOut.channelIndexList | |
108 | else: |
|
108 | else: | |
109 | channelIndexList = [] |
|
109 | channelIndexList = [] | |
110 | for channel in channelList: |
|
110 | for channel in channelList: | |
111 | if channel not in dataOut.channelList: |
|
111 | if channel not in dataOut.channelList: | |
112 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
112 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
113 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
113 | channelIndexList.append(dataOut.channelList.index(channel)) | |
114 |
|
114 | |||
115 | factor = dataOut.normFactor |
|
115 | factor = dataOut.normFactor | |
116 | x = dataOut.abscissaList |
|
116 | x = dataOut.abscissaList | |
117 | y = dataOut.heightList |
|
117 | y = dataOut.heightList | |
118 |
|
118 | |||
119 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
119 | z = dataOut.data_pre[channelIndexList,:,:]/factor | |
120 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
120 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
121 | avg = numpy.average(z, axis=1) |
|
121 | avg = numpy.average(z, axis=1) | |
122 | noise = dataOut.noise/factor |
|
122 | noise = dataOut.noise/factor | |
123 |
|
123 | |||
124 | zdB = 10*numpy.log10(z) |
|
124 | zdB = 10*numpy.log10(z) | |
125 | avgdB = 10*numpy.log10(avg) |
|
125 | avgdB = 10*numpy.log10(avg) | |
126 | noisedB = 10*numpy.log10(noise) |
|
126 | noisedB = 10*numpy.log10(noise) | |
127 |
|
127 | |||
128 | #thisDatetime = dataOut.datatime |
|
128 | #thisDatetime = dataOut.datatime | |
129 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
129 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
130 | title = wintitle + " Parameters" |
|
130 | title = wintitle + " Parameters" | |
131 | xlabel = "Velocity (m/s)" |
|
131 | xlabel = "Velocity (m/s)" | |
132 | ylabel = "Range (Km)" |
|
132 | ylabel = "Range (Km)" | |
133 |
|
133 | |||
134 | if not self.isConfig: |
|
134 | if not self.isConfig: | |
135 |
|
135 | |||
136 | nplots = len(channelIndexList) |
|
136 | nplots = len(channelIndexList) | |
137 |
|
137 | |||
138 | self.setup(id=id, |
|
138 | self.setup(id=id, | |
139 | nplots=nplots, |
|
139 | nplots=nplots, | |
140 | wintitle=wintitle, |
|
140 | wintitle=wintitle, | |
141 | showprofile=showprofile, |
|
141 | showprofile=showprofile, | |
142 | show=show) |
|
142 | show=show) | |
143 |
|
143 | |||
144 | if xmin == None: xmin = numpy.nanmin(x) |
|
144 | if xmin == None: xmin = numpy.nanmin(x) | |
145 | if xmax == None: xmax = numpy.nanmax(x) |
|
145 | if xmax == None: xmax = numpy.nanmax(x) | |
146 | if ymin == None: ymin = numpy.nanmin(y) |
|
146 | if ymin == None: ymin = numpy.nanmin(y) | |
147 | if ymax == None: ymax = numpy.nanmax(y) |
|
147 | if ymax == None: ymax = numpy.nanmax(y) | |
148 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
148 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
149 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
149 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
150 |
|
150 | |||
151 | self.FTP_WEI = ftp_wei |
|
151 | self.FTP_WEI = ftp_wei | |
152 | self.EXP_CODE = exp_code |
|
152 | self.EXP_CODE = exp_code | |
153 | self.SUB_EXP_CODE = sub_exp_code |
|
153 | self.SUB_EXP_CODE = sub_exp_code | |
154 | self.PLOT_POS = plot_pos |
|
154 | self.PLOT_POS = plot_pos | |
155 |
|
155 | |||
156 | self.isConfig = True |
|
156 | self.isConfig = True | |
157 |
|
157 | |||
158 | self.setWinTitle(title) |
|
158 | self.setWinTitle(title) | |
159 |
|
159 | |||
160 | for i in range(self.nplots): |
|
160 | for i in range(self.nplots): | |
161 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
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]+1, noisedB[i], str_datetime) |
|
162 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) | |
163 | axes = self.axesList[i*self.__nsubplots] |
|
163 | axes = self.axesList[i*self.__nsubplots] | |
164 | axes.pcolor(x, y, zdB[i,:,:], |
|
164 | axes.pcolor(x, y, zdB[i,:,:], | |
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
166 | xlabel=xlabel, ylabel=ylabel, title=title, | |
167 | ticksize=9, cblabel='') |
|
167 | ticksize=9, cblabel='') | |
168 | #Mean Line |
|
168 | #Mean Line | |
169 | mean = dataOut.data_param[i, 1, :] |
|
169 | mean = dataOut.data_param[i, 1, :] | |
170 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
170 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) | |
171 |
|
171 | |||
172 | if self.__showprofile: |
|
172 | if self.__showprofile: | |
173 | axes = self.axesList[i*self.__nsubplots +1] |
|
173 | axes = self.axesList[i*self.__nsubplots +1] | |
174 | axes.pline(avgdB[i], y, |
|
174 | axes.pline(avgdB[i], y, | |
175 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
175 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
176 | xlabel='dB', ylabel='', title='', |
|
176 | xlabel='dB', ylabel='', title='', | |
177 | ytick_visible=False, |
|
177 | ytick_visible=False, | |
178 | grid='x') |
|
178 | grid='x') | |
179 |
|
179 | |||
180 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
180 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
181 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
181 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
182 |
|
182 | |||
183 | self.draw() |
|
183 | self.draw() | |
184 |
|
184 | |||
185 | self.save(figpath=figpath, |
|
185 | self.save(figpath=figpath, | |
186 | figfile=figfile, |
|
186 | figfile=figfile, | |
187 | save=save, |
|
187 | save=save, | |
188 | ftp=ftp, |
|
188 | ftp=ftp, | |
189 | wr_period=wr_period, |
|
189 | wr_period=wr_period, | |
190 | thisDatetime=thisDatetime) |
|
190 | thisDatetime=thisDatetime) | |
191 |
|
191 | |||
192 |
|
192 | |||
193 |
|
193 | |||
194 | class SkyMapPlot(Figure): |
|
194 | class SkyMapPlot(Figure): | |
195 |
|
195 | |||
196 | __isConfig = None |
|
196 | __isConfig = None | |
197 | __nsubplots = None |
|
197 | __nsubplots = None | |
198 |
|
198 | |||
199 | WIDTHPROF = None |
|
199 | WIDTHPROF = None | |
200 | HEIGHTPROF = None |
|
200 | HEIGHTPROF = None | |
201 | PREFIX = 'mmap' |
|
201 | PREFIX = 'mmap' | |
202 |
|
202 | |||
203 | def __init__(self): |
|
203 | def __init__(self): | |
204 |
|
204 | |||
205 | self.__isConfig = False |
|
205 | self.__isConfig = False | |
206 | self.__nsubplots = 1 |
|
206 | self.__nsubplots = 1 | |
207 |
|
207 | |||
208 | # self.WIDTH = 280 |
|
208 | # self.WIDTH = 280 | |
209 | # self.HEIGHT = 250 |
|
209 | # self.HEIGHT = 250 | |
210 | self.WIDTH = 600 |
|
210 | self.WIDTH = 600 | |
211 | self.HEIGHT = 600 |
|
211 | self.HEIGHT = 600 | |
212 | self.WIDTHPROF = 120 |
|
212 | self.WIDTHPROF = 120 | |
213 | self.HEIGHTPROF = 0 |
|
213 | self.HEIGHTPROF = 0 | |
214 | self.counter_imagwr = 0 |
|
214 | self.counter_imagwr = 0 | |
215 |
|
215 | |||
216 | self.PLOT_CODE = MSKYMAP_CODE |
|
216 | self.PLOT_CODE = MSKYMAP_CODE | |
217 |
|
217 | |||
218 | self.FTP_WEI = None |
|
218 | self.FTP_WEI = None | |
219 | self.EXP_CODE = None |
|
219 | self.EXP_CODE = None | |
220 | self.SUB_EXP_CODE = None |
|
220 | self.SUB_EXP_CODE = None | |
221 | self.PLOT_POS = None |
|
221 | self.PLOT_POS = None | |
222 |
|
222 | |||
223 | def getSubplots(self): |
|
223 | def getSubplots(self): | |
224 |
|
224 | |||
225 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
225 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
226 | nrow = int(self.nplots*1./ncol + 0.9) |
|
226 | nrow = int(self.nplots*1./ncol + 0.9) | |
227 |
|
227 | |||
228 | return nrow, ncol |
|
228 | return nrow, ncol | |
229 |
|
229 | |||
230 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
230 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): | |
231 |
|
231 | |||
232 | self.__showprofile = showprofile |
|
232 | self.__showprofile = showprofile | |
233 | self.nplots = nplots |
|
233 | self.nplots = nplots | |
234 |
|
234 | |||
235 | ncolspan = 1 |
|
235 | ncolspan = 1 | |
236 | colspan = 1 |
|
236 | colspan = 1 | |
237 |
|
237 | |||
238 | self.createFigure(id = id, |
|
238 | self.createFigure(id = id, | |
239 | wintitle = wintitle, |
|
239 | wintitle = wintitle, | |
240 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
240 | widthplot = self.WIDTH, #+ self.WIDTHPROF, | |
241 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
241 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, | |
242 | show=show) |
|
242 | show=show) | |
243 |
|
243 | |||
244 | nrow, ncol = 1,1 |
|
244 | nrow, ncol = 1,1 | |
245 | counter = 0 |
|
245 | counter = 0 | |
246 | x = 0 |
|
246 | x = 0 | |
247 | y = 0 |
|
247 | y = 0 | |
248 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
248 | self.addAxes(1, 1, 0, 0, 1, 1, True) | |
249 |
|
249 | |||
250 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
250 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
251 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
251 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
252 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
252 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
253 | server=None, folder=None, username=None, password=None, |
|
253 | server=None, folder=None, username=None, password=None, | |
254 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
254 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
255 |
|
255 | |||
256 | """ |
|
256 | """ | |
257 |
|
257 | |||
258 | Input: |
|
258 | Input: | |
259 | dataOut : |
|
259 | dataOut : | |
260 | id : |
|
260 | id : | |
261 | wintitle : |
|
261 | wintitle : | |
262 | channelList : |
|
262 | channelList : | |
263 | showProfile : |
|
263 | showProfile : | |
264 | xmin : None, |
|
264 | xmin : None, | |
265 | xmax : None, |
|
265 | xmax : None, | |
266 | ymin : None, |
|
266 | ymin : None, | |
267 | ymax : None, |
|
267 | ymax : None, | |
268 | zmin : None, |
|
268 | zmin : None, | |
269 | zmax : None |
|
269 | zmax : None | |
270 | """ |
|
270 | """ | |
271 |
|
271 | |||
272 | arrayParameters = dataOut.data_param[0,:] |
|
272 | arrayParameters = dataOut.data_param[0,:] | |
273 | error = arrayParameters[:,-1] |
|
273 | error = arrayParameters[:,-1] | |
274 | indValid = numpy.where(error == 0)[0] |
|
274 | indValid = numpy.where(error == 0)[0] | |
275 | finalMeteor = arrayParameters[indValid,:] |
|
275 | finalMeteor = arrayParameters[indValid,:] | |
276 | finalAzimuth = finalMeteor[:,4] |
|
276 | finalAzimuth = finalMeteor[:,4] | |
277 | finalZenith = finalMeteor[:,5] |
|
277 | finalZenith = finalMeteor[:,5] | |
278 |
|
278 | |||
279 | x = finalAzimuth*numpy.pi/180 |
|
279 | x = finalAzimuth*numpy.pi/180 | |
280 | y = finalZenith |
|
280 | y = finalZenith | |
281 |
|
281 | |||
282 |
|
282 | |||
283 | #thisDatetime = dataOut.datatime |
|
283 | #thisDatetime = dataOut.datatime | |
284 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
284 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
285 | title = wintitle + " Parameters" |
|
285 | title = wintitle + " Parameters" | |
286 | xlabel = "Zonal Zenith Angle (deg) " |
|
286 | xlabel = "Zonal Zenith Angle (deg) " | |
287 | ylabel = "Meridional Zenith Angle (deg)" |
|
287 | ylabel = "Meridional Zenith Angle (deg)" | |
288 |
|
288 | |||
289 | if not self.__isConfig: |
|
289 | if not self.__isConfig: | |
290 |
|
290 | |||
291 | nplots = 1 |
|
291 | nplots = 1 | |
292 |
|
292 | |||
293 | self.setup(id=id, |
|
293 | self.setup(id=id, | |
294 | nplots=nplots, |
|
294 | nplots=nplots, | |
295 | wintitle=wintitle, |
|
295 | wintitle=wintitle, | |
296 | showprofile=showprofile, |
|
296 | showprofile=showprofile, | |
297 | show=show) |
|
297 | show=show) | |
298 |
|
298 | |||
299 | self.FTP_WEI = ftp_wei |
|
299 | self.FTP_WEI = ftp_wei | |
300 | self.EXP_CODE = exp_code |
|
300 | self.EXP_CODE = exp_code | |
301 | self.SUB_EXP_CODE = sub_exp_code |
|
301 | self.SUB_EXP_CODE = sub_exp_code | |
302 | self.PLOT_POS = plot_pos |
|
302 | self.PLOT_POS = plot_pos | |
303 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
303 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
304 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
304 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
305 | self.__isConfig = True |
|
305 | self.__isConfig = True | |
306 |
|
306 | |||
307 | self.setWinTitle(title) |
|
307 | self.setWinTitle(title) | |
308 |
|
308 | |||
309 | i = 0 |
|
309 | i = 0 | |
310 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
310 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
311 |
|
311 | |||
312 | axes = self.axesList[i*self.__nsubplots] |
|
312 | axes = self.axesList[i*self.__nsubplots] | |
313 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
313 | nevents = axes.x_buffer.shape[0] + x.shape[0] | |
314 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
314 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) | |
315 | axes.polar(x, y, |
|
315 | axes.polar(x, y, | |
316 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
316 | title=title, xlabel=xlabel, ylabel=ylabel, | |
317 | ticksize=9, cblabel='') |
|
317 | ticksize=9, cblabel='') | |
318 |
|
318 | |||
319 | self.draw() |
|
319 | self.draw() | |
320 |
|
320 | |||
321 | self.save(figpath=figpath, |
|
321 | self.save(figpath=figpath, | |
322 | figfile=figfile, |
|
322 | figfile=figfile, | |
323 | save=save, |
|
323 | save=save, | |
324 | ftp=ftp, |
|
324 | ftp=ftp, | |
325 | wr_period=wr_period, |
|
325 | wr_period=wr_period, | |
326 | thisDatetime=thisDatetime) |
|
326 | thisDatetime=thisDatetime) | |
327 |
|
327 | |||
328 |
|
328 | |||
329 | class WindProfilerPlot(Figure): |
|
329 | class WindProfilerPlot(Figure): | |
330 |
|
330 | |||
331 | __isConfig = None |
|
331 | __isConfig = None | |
332 | __nsubplots = None |
|
332 | __nsubplots = None | |
333 |
|
333 | |||
334 | WIDTHPROF = None |
|
334 | WIDTHPROF = None | |
335 | HEIGHTPROF = None |
|
335 | HEIGHTPROF = None | |
336 | PREFIX = 'wind' |
|
336 | PREFIX = 'wind' | |
337 |
|
337 | |||
338 | def __init__(self): |
|
338 | def __init__(self): | |
339 |
|
339 | |||
340 | self.timerange = None |
|
340 | self.timerange = None | |
341 | self.__isConfig = False |
|
341 | self.__isConfig = False | |
342 | self.__nsubplots = 1 |
|
342 | self.__nsubplots = 1 | |
343 |
|
343 | |||
344 | self.WIDTH = 800 |
|
344 | self.WIDTH = 800 | |
345 | self.HEIGHT = 150 |
|
345 | self.HEIGHT = 150 | |
346 | self.WIDTHPROF = 120 |
|
346 | self.WIDTHPROF = 120 | |
347 | self.HEIGHTPROF = 0 |
|
347 | self.HEIGHTPROF = 0 | |
348 | self.counter_imagwr = 0 |
|
348 | self.counter_imagwr = 0 | |
349 |
|
349 | |||
350 | self.PLOT_CODE = WIND_CODE |
|
350 | self.PLOT_CODE = WIND_CODE | |
351 |
|
351 | |||
352 | self.FTP_WEI = None |
|
352 | self.FTP_WEI = None | |
353 | self.EXP_CODE = None |
|
353 | self.EXP_CODE = None | |
354 | self.SUB_EXP_CODE = None |
|
354 | self.SUB_EXP_CODE = None | |
355 | self.PLOT_POS = None |
|
355 | self.PLOT_POS = None | |
356 | self.tmin = None |
|
356 | self.tmin = None | |
357 | self.tmax = None |
|
357 | self.tmax = None | |
358 |
|
358 | |||
359 | self.xmin = None |
|
359 | self.xmin = None | |
360 | self.xmax = None |
|
360 | self.xmax = None | |
361 |
|
361 | |||
362 | self.figfile = None |
|
362 | self.figfile = None | |
363 |
|
363 | |||
364 | def getSubplots(self): |
|
364 | def getSubplots(self): | |
365 |
|
365 | |||
366 | ncol = 1 |
|
366 | ncol = 1 | |
367 | nrow = self.nplots |
|
367 | nrow = self.nplots | |
368 |
|
368 | |||
369 | return nrow, ncol |
|
369 | return nrow, ncol | |
370 |
|
370 | |||
371 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
371 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
372 |
|
372 | |||
373 | self.__showprofile = showprofile |
|
373 | self.__showprofile = showprofile | |
374 | self.nplots = nplots |
|
374 | self.nplots = nplots | |
375 |
|
375 | |||
376 | ncolspan = 1 |
|
376 | ncolspan = 1 | |
377 | colspan = 1 |
|
377 | colspan = 1 | |
378 |
|
378 | |||
379 | self.createFigure(id = id, |
|
379 | self.createFigure(id = id, | |
380 | wintitle = wintitle, |
|
380 | wintitle = wintitle, | |
381 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
381 | widthplot = self.WIDTH + self.WIDTHPROF, | |
382 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
382 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
383 | show=show) |
|
383 | show=show) | |
384 |
|
384 | |||
385 | nrow, ncol = self.getSubplots() |
|
385 | nrow, ncol = self.getSubplots() | |
386 |
|
386 | |||
387 | counter = 0 |
|
387 | counter = 0 | |
388 | for y in range(nrow): |
|
388 | for y in range(nrow): | |
389 | if counter >= self.nplots: |
|
389 | if counter >= self.nplots: | |
390 | break |
|
390 | break | |
391 |
|
391 | |||
392 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
392 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) | |
393 | counter += 1 |
|
393 | counter += 1 | |
394 |
|
394 | |||
395 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', |
|
395 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', | |
396 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
396 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
397 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
397 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, | |
398 | timerange=None, SNRthresh = None, |
|
398 | timerange=None, SNRthresh = None, | |
399 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
399 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
400 | server=None, folder=None, username=None, password=None, |
|
400 | server=None, folder=None, username=None, password=None, | |
401 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
401 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
402 | """ |
|
402 | """ | |
403 |
|
403 | |||
404 | Input: |
|
404 | Input: | |
405 | dataOut : |
|
405 | dataOut : | |
406 | id : |
|
406 | id : | |
407 | wintitle : |
|
407 | wintitle : | |
408 | channelList : |
|
408 | channelList : | |
409 | showProfile : |
|
409 | showProfile : | |
410 | xmin : None, |
|
410 | xmin : None, | |
411 | xmax : None, |
|
411 | xmax : None, | |
412 | ymin : None, |
|
412 | ymin : None, | |
413 | ymax : None, |
|
413 | ymax : None, | |
414 | zmin : None, |
|
414 | zmin : None, | |
415 | zmax : None |
|
415 | zmax : None | |
416 | """ |
|
416 | """ | |
417 |
|
417 | |||
418 | if channelList == None: |
|
418 | if channelList == None: | |
419 | channelIndexList = dataOut.channelIndexList |
|
419 | channelIndexList = dataOut.channelIndexList | |
420 | else: |
|
420 | else: | |
421 | channelIndexList = [] |
|
421 | channelIndexList = [] | |
422 | for channel in channelList: |
|
422 | for channel in channelList: | |
423 | if channel not in dataOut.channelList: |
|
423 | if channel not in dataOut.channelList: | |
424 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
424 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
425 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
425 | channelIndexList.append(dataOut.channelList.index(channel)) | |
426 |
|
426 | |||
427 | # if timerange != None: |
|
427 | # if timerange != None: | |
428 | # self.timerange = timerange |
|
428 | # self.timerange = timerange | |
429 | # |
|
429 | # | |
430 | # tmin = None |
|
430 | # tmin = None | |
431 | # tmax = None |
|
431 | # tmax = None | |
432 |
|
432 | |||
433 | x = dataOut.getTimeRange1() |
|
433 | x = dataOut.getTimeRange1() | |
434 | # y = dataOut.heightList |
|
434 | # y = dataOut.heightList | |
435 | y = dataOut.heightList |
|
435 | y = dataOut.heightList | |
436 |
|
436 | |||
437 | z = dataOut.data_output.copy() |
|
437 | z = dataOut.data_output.copy() | |
438 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
438 | nplots = z.shape[0] #Number of wind dimensions estimated | |
439 | nplotsw = nplots |
|
439 | nplotsw = nplots | |
440 |
|
440 | |||
441 | #If there is a SNR function defined |
|
441 | #If there is a SNR function defined | |
442 | if dataOut.data_SNR != None: |
|
442 | if dataOut.data_SNR != None: | |
443 | nplots += 1 |
|
443 | nplots += 1 | |
444 | SNR = dataOut.data_SNR |
|
444 | SNR = dataOut.data_SNR | |
445 | SNRavg = numpy.average(SNR, axis=0) |
|
445 | SNRavg = numpy.average(SNR, axis=0) | |
446 |
|
446 | |||
447 | SNRdB = 10*numpy.log10(SNR) |
|
447 | SNRdB = 10*numpy.log10(SNR) | |
448 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
448 | SNRavgdB = 10*numpy.log10(SNRavg) | |
449 |
|
449 | |||
450 | if SNRthresh == None: SNRthresh = -5.0 |
|
450 | if SNRthresh == None: SNRthresh = -5.0 | |
451 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
451 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] | |
452 |
|
452 | |||
453 | for i in range(nplotsw): |
|
453 | for i in range(nplotsw): | |
454 | z[i,ind] = numpy.nan |
|
454 | z[i,ind] = numpy.nan | |
455 |
|
455 | |||
456 |
|
456 | |||
457 | # showprofile = False |
|
457 | # showprofile = False | |
458 | # thisDatetime = dataOut.datatime |
|
458 | # thisDatetime = dataOut.datatime | |
459 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
459 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
460 | title = wintitle + "Wind" |
|
460 | title = wintitle + "Wind" | |
461 | xlabel = "" |
|
461 | xlabel = "" | |
462 | ylabel = "Range (Km)" |
|
462 | ylabel = "Range (Km)" | |
463 |
|
463 | |||
464 | if not self.__isConfig: |
|
464 | if not self.__isConfig: | |
465 |
|
465 | |||
466 | self.setup(id=id, |
|
466 | self.setup(id=id, | |
467 | nplots=nplots, |
|
467 | nplots=nplots, | |
468 | wintitle=wintitle, |
|
468 | wintitle=wintitle, | |
469 | showprofile=showprofile, |
|
469 | showprofile=showprofile, | |
470 | show=show) |
|
470 | show=show) | |
471 |
|
471 | |||
472 | if timerange != None: |
|
472 | if timerange != None: | |
473 | self.timerange = timerange |
|
473 | self.timerange = timerange | |
474 |
|
474 | |||
475 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
475 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
476 |
|
476 | |||
477 | if ymin == None: ymin = numpy.nanmin(y) |
|
477 | if ymin == None: ymin = numpy.nanmin(y) | |
478 | if ymax == None: ymax = numpy.nanmax(y) |
|
478 | if ymax == None: ymax = numpy.nanmax(y) | |
479 |
|
479 | |||
480 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) |
|
480 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) | |
481 | #if numpy.isnan(zmax): zmax = 50 |
|
481 | #if numpy.isnan(zmax): zmax = 50 | |
482 | if zmin == None: zmin = -zmax |
|
482 | if zmin == None: zmin = -zmax | |
483 |
|
483 | |||
484 | if nplotsw == 3: |
|
484 | if nplotsw == 3: | |
485 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
485 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) | |
486 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
486 | if zmin_ver == None: zmin_ver = -zmax_ver | |
487 |
|
487 | |||
488 | if dataOut.data_SNR != None: |
|
488 | if dataOut.data_SNR != None: | |
489 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
489 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) | |
490 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
490 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) | |
491 |
|
491 | |||
492 |
|
492 | |||
493 | self.FTP_WEI = ftp_wei |
|
493 | self.FTP_WEI = ftp_wei | |
494 | self.EXP_CODE = exp_code |
|
494 | self.EXP_CODE = exp_code | |
495 | self.SUB_EXP_CODE = sub_exp_code |
|
495 | self.SUB_EXP_CODE = sub_exp_code | |
496 | self.PLOT_POS = plot_pos |
|
496 | self.PLOT_POS = plot_pos | |
497 |
|
497 | |||
498 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
498 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
499 | self.__isConfig = True |
|
499 | self.__isConfig = True | |
500 | self.figfile = figfile |
|
500 | self.figfile = figfile | |
501 |
|
501 | |||
502 | self.setWinTitle(title) |
|
502 | self.setWinTitle(title) | |
503 |
|
503 | |||
504 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
504 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
505 | x[1] = self.xmax |
|
505 | x[1] = self.xmax | |
506 |
|
506 | |||
507 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
507 | strWind = ['Zonal', 'Meridional', 'Vertical'] | |
508 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
508 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] | |
509 | zmaxVector = [zmax, zmax, zmax_ver] |
|
509 | zmaxVector = [zmax, zmax, zmax_ver] | |
510 | zminVector = [zmin, zmin, zmin_ver] |
|
510 | zminVector = [zmin, zmin, zmin_ver] | |
511 | windFactor = [1,1,100] |
|
511 | windFactor = [1,1,100] | |
512 |
|
512 | |||
513 | for i in range(nplotsw): |
|
513 | for i in range(nplotsw): | |
514 |
|
514 | |||
515 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
515 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
516 | axes = self.axesList[i*self.__nsubplots] |
|
516 | axes = self.axesList[i*self.__nsubplots] | |
517 |
|
517 | |||
518 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
518 | z1 = z[i,:].reshape((1,-1))*windFactor[i] | |
519 |
|
519 | |||
520 | axes.pcolorbuffer(x, y, z1, |
|
520 | axes.pcolorbuffer(x, y, z1, | |
521 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
521 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], | |
522 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
522 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
523 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" ) |
|
523 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" ) | |
524 |
|
524 | |||
525 | if dataOut.data_SNR != None: |
|
525 | if dataOut.data_SNR != None: | |
526 | i += 1 |
|
526 | i += 1 | |
527 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
527 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
528 | axes = self.axesList[i*self.__nsubplots] |
|
528 | axes = self.axesList[i*self.__nsubplots] | |
529 |
|
529 | |||
530 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
530 | SNRavgdB = SNRavgdB.reshape((1,-1)) | |
531 |
|
531 | |||
532 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
532 | axes.pcolorbuffer(x, y, SNRavgdB, | |
533 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
533 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
534 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
534 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
535 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
535 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") | |
536 |
|
536 | |||
537 | self.draw() |
|
537 | self.draw() | |
538 |
|
538 | |||
539 | if x[1] >= self.axesList[0].xmax: |
|
539 | if x[1] >= self.axesList[0].xmax: | |
540 | self.counter_imagwr = wr_period |
|
540 | self.counter_imagwr = wr_period | |
541 | self.__isConfig = False |
|
541 | self.__isConfig = False | |
542 | self.figfile = None |
|
542 | self.figfile = None | |
543 |
|
543 | |||
544 | self.save(figpath=figpath, |
|
544 | self.save(figpath=figpath, | |
545 | figfile=figfile, |
|
545 | figfile=figfile, | |
546 | save=save, |
|
546 | save=save, | |
547 | ftp=ftp, |
|
547 | ftp=ftp, | |
548 | wr_period=wr_period, |
|
548 | wr_period=wr_period, | |
549 | thisDatetime=thisDatetime, |
|
549 | thisDatetime=thisDatetime, | |
550 | update_figfile=False) |
|
550 | update_figfile=False) | |
551 |
|
551 | |||
552 |
|
552 | |||
553 | class ParametersPlot(Figure): |
|
553 | class ParametersPlot(Figure): | |
554 |
|
554 | |||
555 | __isConfig = None |
|
555 | __isConfig = None | |
556 | __nsubplots = None |
|
556 | __nsubplots = None | |
557 |
|
557 | |||
558 | WIDTHPROF = None |
|
558 | WIDTHPROF = None | |
559 | HEIGHTPROF = None |
|
559 | HEIGHTPROF = None | |
560 | PREFIX = 'prm' |
|
560 | PREFIX = 'prm' | |
561 |
|
561 | |||
562 | def __init__(self): |
|
562 | def __init__(self): | |
563 |
|
563 | |||
564 | self.timerange = 2*60*60 |
|
564 | self.timerange = 2*60*60 | |
565 | self.__isConfig = False |
|
565 | self.__isConfig = False | |
566 | self.__nsubplots = 1 |
|
566 | self.__nsubplots = 1 | |
567 |
|
567 | |||
568 | self.WIDTH = 800 |
|
568 | self.WIDTH = 800 | |
569 | self.HEIGHT = 150 |
|
569 | self.HEIGHT = 150 | |
570 | self.WIDTHPROF = 120 |
|
570 | self.WIDTHPROF = 120 | |
571 | self.HEIGHTPROF = 0 |
|
571 | self.HEIGHTPROF = 0 | |
572 | self.counter_imagwr = 0 |
|
572 | self.counter_imagwr = 0 | |
573 |
|
573 | |||
574 | self.PLOT_CODE = PARMS_CODE |
|
574 | self.PLOT_CODE = PARMS_CODE | |
575 |
|
575 | |||
576 | self.FTP_WEI = None |
|
576 | self.FTP_WEI = None | |
577 | self.EXP_CODE = None |
|
577 | self.EXP_CODE = None | |
578 | self.SUB_EXP_CODE = None |
|
578 | self.SUB_EXP_CODE = None | |
579 | self.PLOT_POS = None |
|
579 | self.PLOT_POS = None | |
580 | self.tmin = None |
|
580 | self.tmin = None | |
581 | self.tmax = None |
|
581 | self.tmax = None | |
582 |
|
582 | |||
583 | self.xmin = None |
|
583 | self.xmin = None | |
584 | self.xmax = None |
|
584 | self.xmax = None | |
585 |
|
585 | |||
586 | self.figfile = None |
|
586 | self.figfile = None | |
587 |
|
587 | |||
588 | def getSubplots(self): |
|
588 | def getSubplots(self): | |
589 |
|
589 | |||
590 | ncol = 1 |
|
590 | ncol = 1 | |
591 | nrow = self.nplots |
|
591 | nrow = self.nplots | |
592 |
|
592 | |||
593 | return nrow, ncol |
|
593 | return nrow, ncol | |
594 |
|
594 | |||
595 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
595 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
596 |
|
596 | |||
597 | self.__showprofile = showprofile |
|
597 | self.__showprofile = showprofile | |
598 | self.nplots = nplots |
|
598 | self.nplots = nplots | |
599 |
|
599 | |||
600 | ncolspan = 1 |
|
600 | ncolspan = 1 | |
601 | colspan = 1 |
|
601 | colspan = 1 | |
602 |
|
602 | |||
603 | self.createFigure(id = id, |
|
603 | self.createFigure(id = id, | |
604 | wintitle = wintitle, |
|
604 | wintitle = wintitle, | |
605 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
605 | widthplot = self.WIDTH + self.WIDTHPROF, | |
606 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
606 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
607 | show=show) |
|
607 | show=show) | |
608 |
|
608 | |||
609 | nrow, ncol = self.getSubplots() |
|
609 | nrow, ncol = self.getSubplots() | |
610 |
|
610 | |||
611 | counter = 0 |
|
611 | counter = 0 | |
612 | for y in range(nrow): |
|
612 | for y in range(nrow): | |
613 | for x in range(ncol): |
|
613 | for x in range(ncol): | |
614 |
|
614 | |||
615 | if counter >= self.nplots: |
|
615 | if counter >= self.nplots: | |
616 | break |
|
616 | break | |
617 |
|
617 | |||
618 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
618 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
619 |
|
619 | |||
620 | if showprofile: |
|
620 | if showprofile: | |
621 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
621 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
622 |
|
622 | |||
623 | counter += 1 |
|
623 | counter += 1 | |
624 |
|
624 | |||
625 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
625 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
626 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
626 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, | |
627 | parameterIndex = None, onlyPositive = False, |
|
627 | parameterIndex = None, onlyPositive = False, | |
628 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, |
|
628 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, | |
629 | DOP = True, |
|
629 | DOP = True, | |
630 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
630 | zlabel = "", parameterName = "", parameterObject = "data_param", | |
631 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
631 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
632 | server=None, folder=None, username=None, password=None, |
|
632 | server=None, folder=None, username=None, password=None, | |
633 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
633 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
634 |
|
634 | |||
635 | """ |
|
635 | """ | |
636 |
|
636 | |||
637 | Input: |
|
637 | Input: | |
638 | dataOut : |
|
638 | dataOut : | |
639 | id : |
|
639 | id : | |
640 | wintitle : |
|
640 | wintitle : | |
641 | channelList : |
|
641 | channelList : | |
642 | showProfile : |
|
642 | showProfile : | |
643 | xmin : None, |
|
643 | xmin : None, | |
644 | xmax : None, |
|
644 | xmax : None, | |
645 | ymin : None, |
|
645 | ymin : None, | |
646 | ymax : None, |
|
646 | ymax : None, | |
647 | zmin : None, |
|
647 | zmin : None, | |
648 | zmax : None |
|
648 | zmax : None | |
649 | """ |
|
649 | """ | |
650 |
|
650 | |||
651 | data_param = getattr(dataOut, parameterObject) |
|
651 | data_param = getattr(dataOut, parameterObject) | |
652 |
|
652 | |||
653 | if channelList == None: |
|
653 | if channelList == None: | |
654 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
654 | channelIndexList = numpy.arange(data_param.shape[0]) | |
655 | else: |
|
655 | else: | |
656 | channelIndexList = numpy.array(channelList) |
|
656 | channelIndexList = numpy.array(channelList) | |
657 |
|
657 | |||
658 | nchan = len(channelIndexList) #Number of channels being plotted |
|
658 | nchan = len(channelIndexList) #Number of channels being plotted | |
659 |
|
659 | |||
660 | if nchan < 1: |
|
660 | if nchan < 1: | |
661 | return |
|
661 | return | |
662 |
|
662 | |||
663 | nGraphsByChannel = 0 |
|
663 | nGraphsByChannel = 0 | |
664 |
|
664 | |||
665 | if SNR: |
|
665 | if SNR: | |
666 | nGraphsByChannel += 1 |
|
666 | nGraphsByChannel += 1 | |
667 | if DOP: |
|
667 | if DOP: | |
668 | nGraphsByChannel += 1 |
|
668 | nGraphsByChannel += 1 | |
669 |
|
669 | |||
670 | if nGraphsByChannel < 1: |
|
670 | if nGraphsByChannel < 1: | |
671 | return |
|
671 | return | |
672 |
|
672 | |||
673 | nplots = nGraphsByChannel*nchan |
|
673 | nplots = nGraphsByChannel*nchan | |
674 |
|
674 | |||
675 | if timerange != None: |
|
675 | if timerange != None: | |
676 | self.timerange = timerange |
|
676 | self.timerange = timerange | |
677 |
|
677 | |||
678 | #tmin = None |
|
678 | #tmin = None | |
679 | #tmax = None |
|
679 | #tmax = None | |
680 | if parameterIndex == None: |
|
680 | if parameterIndex == None: | |
681 | parameterIndex = 1 |
|
681 | parameterIndex = 1 | |
682 |
|
682 | |||
683 | x = dataOut.getTimeRange1() |
|
683 | x = dataOut.getTimeRange1() | |
684 | y = dataOut.heightList |
|
684 | y = dataOut.heightList | |
685 | z = data_param[channelIndexList,parameterIndex,:].copy() |
|
685 | z = data_param[channelIndexList,parameterIndex,:].copy() | |
686 |
|
686 | |||
687 | zRange = dataOut.abscissaList |
|
687 | zRange = dataOut.abscissaList | |
688 | # nChannels = z.shape[0] #Number of wind dimensions estimated |
|
688 | # nChannels = z.shape[0] #Number of wind dimensions estimated | |
689 | # thisDatetime = dataOut.datatime |
|
689 | # thisDatetime = dataOut.datatime | |
690 |
|
690 | |||
691 | if dataOut.data_SNR != None: |
|
691 | if dataOut.data_SNR != None: | |
692 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
692 | SNRarray = dataOut.data_SNR[channelIndexList,:] | |
693 | SNRdB = 10*numpy.log10(SNRarray) |
|
693 | SNRdB = 10*numpy.log10(SNRarray) | |
694 | # SNRavgdB = 10*numpy.log10(SNRavg) |
|
694 | # SNRavgdB = 10*numpy.log10(SNRavg) | |
695 | ind = numpy.where(SNRdB < 10**(SNRthresh/10)) |
|
695 | ind = numpy.where(SNRdB < 10**(SNRthresh/10)) | |
696 | z[ind] = numpy.nan |
|
696 | z[ind] = numpy.nan | |
697 |
|
697 | |||
698 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
698 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
699 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
699 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
700 | xlabel = "" |
|
700 | xlabel = "" | |
701 | ylabel = "Range (Km)" |
|
701 | ylabel = "Range (Km)" | |
702 |
|
702 | |||
703 | if (SNR and not onlySNR): nplots = 2*nplots |
|
703 | if (SNR and not onlySNR): nplots = 2*nplots | |
704 |
|
704 | |||
705 | if onlyPositive: |
|
705 | if onlyPositive: | |
706 | colormap = "jet" |
|
706 | colormap = "jet" | |
707 | zmin = 0 |
|
707 | zmin = 0 | |
708 | else: colormap = "RdBu_r" |
|
708 | else: colormap = "RdBu_r" | |
709 |
|
709 | |||
710 | if not self.__isConfig: |
|
710 | if not self.__isConfig: | |
711 |
|
711 | |||
712 | self.setup(id=id, |
|
712 | self.setup(id=id, | |
713 | nplots=nplots, |
|
713 | nplots=nplots, | |
714 | wintitle=wintitle, |
|
714 | wintitle=wintitle, | |
715 | showprofile=showprofile, |
|
715 | showprofile=showprofile, | |
716 | show=show) |
|
716 | show=show) | |
717 |
|
717 | |||
718 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
718 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
719 |
|
719 | |||
720 | if ymin == None: ymin = numpy.nanmin(y) |
|
720 | if ymin == None: ymin = numpy.nanmin(y) | |
721 | if ymax == None: ymax = numpy.nanmax(y) |
|
721 | if ymax == None: ymax = numpy.nanmax(y) | |
722 | if zmin == None: zmin = numpy.nanmin(zRange) |
|
722 | if zmin == None: zmin = numpy.nanmin(zRange) | |
723 | if zmax == None: zmax = numpy.nanmax(zRange) |
|
723 | if zmax == None: zmax = numpy.nanmax(zRange) | |
724 |
|
724 | |||
725 | if SNR: |
|
725 | if SNR: | |
726 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
726 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) | |
727 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
727 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) | |
728 |
|
728 | |||
729 | self.FTP_WEI = ftp_wei |
|
729 | self.FTP_WEI = ftp_wei | |
730 | self.EXP_CODE = exp_code |
|
730 | self.EXP_CODE = exp_code | |
731 | self.SUB_EXP_CODE = sub_exp_code |
|
731 | self.SUB_EXP_CODE = sub_exp_code | |
732 | self.PLOT_POS = plot_pos |
|
732 | self.PLOT_POS = plot_pos | |
733 |
|
733 | |||
734 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
734 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
735 | self.__isConfig = True |
|
735 | self.__isConfig = True | |
736 | self.figfile = figfile |
|
736 | self.figfile = figfile | |
737 |
|
737 | |||
738 | self.setWinTitle(title) |
|
738 | self.setWinTitle(title) | |
739 |
|
739 | |||
740 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
740 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
741 | x[1] = self.xmax |
|
741 | x[1] = self.xmax | |
742 |
|
742 | |||
743 | for i in range(nchan): |
|
743 | for i in range(nchan): | |
744 |
|
744 | |||
745 | if (SNR and not onlySNR): j = 2*i |
|
745 | if (SNR and not onlySNR): j = 2*i | |
746 | else: j = i |
|
746 | else: j = i | |
747 |
|
747 | |||
748 | j = nGraphsByChannel*i |
|
748 | j = nGraphsByChannel*i | |
749 |
|
749 | |||
750 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
750 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
751 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
751 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |
752 |
|
752 | |||
753 | if not onlySNR: |
|
753 | if not onlySNR: | |
754 | axes = self.axesList[j*self.__nsubplots] |
|
754 | axes = self.axesList[j*self.__nsubplots] | |
755 | z1 = z[i,:].reshape((1,-1)) |
|
755 | z1 = z[i,:].reshape((1,-1)) | |
756 | axes.pcolorbuffer(x, y, z1, |
|
756 | axes.pcolorbuffer(x, y, z1, | |
757 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
757 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
758 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
758 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, | |
759 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
759 | ticksize=9, cblabel=zlabel, cbsize="1%") | |
760 |
|
760 | |||
761 | if DOP: |
|
761 | if DOP: | |
762 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
762 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
763 |
|
763 | |||
764 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
764 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
765 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
765 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |
766 | axes = self.axesList[j] |
|
766 | axes = self.axesList[j] | |
767 | z1 = z[i,:].reshape((1,-1)) |
|
767 | z1 = z[i,:].reshape((1,-1)) | |
768 | axes.pcolorbuffer(x, y, z1, |
|
768 | axes.pcolorbuffer(x, y, z1, | |
769 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
769 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
770 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
770 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, | |
771 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
771 | ticksize=9, cblabel=zlabel, cbsize="1%") | |
772 |
|
772 | |||
773 | if SNR: |
|
773 | if SNR: | |
774 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
774 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
775 | axes = self.axesList[(j)*self.__nsubplots] |
|
775 | axes = self.axesList[(j)*self.__nsubplots] | |
776 | if not onlySNR: |
|
776 | if not onlySNR: | |
777 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
777 | axes = self.axesList[(j + 1)*self.__nsubplots] | |
778 |
|
778 | |||
779 | axes = self.axesList[(j + nGraphsByChannel-1)] |
|
779 | axes = self.axesList[(j + nGraphsByChannel-1)] | |
780 |
|
780 | |||
781 | z1 = SNRdB[i,:].reshape((1,-1)) |
|
781 | z1 = SNRdB[i,:].reshape((1,-1)) | |
782 | axes.pcolorbuffer(x, y, z1, |
|
782 | axes.pcolorbuffer(x, y, z1, | |
783 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
783 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
784 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
784 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", | |
785 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
785 | ticksize=9, cblabel=zlabel, cbsize="1%") | |
786 |
|
786 | |||
787 |
|
787 | |||
788 |
|
788 | |||
789 | self.draw() |
|
789 | self.draw() | |
790 |
|
790 | |||
791 | if x[1] >= self.axesList[0].xmax: |
|
791 | if x[1] >= self.axesList[0].xmax: | |
792 | self.counter_imagwr = wr_period |
|
792 | self.counter_imagwr = wr_period | |
793 | self.__isConfig = False |
|
793 | self.__isConfig = False | |
794 | self.figfile = None |
|
794 | self.figfile = None | |
795 |
|
795 | |||
796 | self.save(figpath=figpath, |
|
796 | self.save(figpath=figpath, | |
797 | figfile=figfile, |
|
797 | figfile=figfile, | |
798 | save=save, |
|
798 | save=save, | |
799 | ftp=ftp, |
|
799 | ftp=ftp, | |
800 | wr_period=wr_period, |
|
800 | wr_period=wr_period, | |
801 | thisDatetime=thisDatetime, |
|
801 | thisDatetime=thisDatetime, | |
802 | update_figfile=False) |
|
802 | update_figfile=False) | |
803 |
|
803 | |||
804 | class SpectralFittingPlot(Figure): |
|
804 | class SpectralFittingPlot(Figure): | |
805 |
|
805 | |||
806 | __isConfig = None |
|
806 | __isConfig = None | |
807 | __nsubplots = None |
|
807 | __nsubplots = None | |
808 |
|
808 | |||
809 | WIDTHPROF = None |
|
809 | WIDTHPROF = None | |
810 | HEIGHTPROF = None |
|
810 | HEIGHTPROF = None | |
811 | PREFIX = 'prm' |
|
811 | PREFIX = 'prm' | |
812 |
|
812 | |||
813 |
|
813 | |||
814 | N = None |
|
814 | N = None | |
815 | ippSeconds = None |
|
815 | ippSeconds = None | |
816 |
|
816 | |||
817 | def __init__(self): |
|
817 | def __init__(self): | |
818 | self.__isConfig = False |
|
818 | self.__isConfig = False | |
819 | self.__nsubplots = 1 |
|
819 | self.__nsubplots = 1 | |
820 |
|
820 | |||
821 | self.PLOT_CODE = SPECFIT_CODE |
|
821 | self.PLOT_CODE = SPECFIT_CODE | |
822 |
|
822 | |||
823 | self.WIDTH = 450 |
|
823 | self.WIDTH = 450 | |
824 | self.HEIGHT = 250 |
|
824 | self.HEIGHT = 250 | |
825 | self.WIDTHPROF = 0 |
|
825 | self.WIDTHPROF = 0 | |
826 | self.HEIGHTPROF = 0 |
|
826 | self.HEIGHTPROF = 0 | |
827 |
|
827 | |||
828 | def getSubplots(self): |
|
828 | def getSubplots(self): | |
829 |
|
829 | |||
830 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
830 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
831 | nrow = int(self.nplots*1./ncol + 0.9) |
|
831 | nrow = int(self.nplots*1./ncol + 0.9) | |
832 |
|
832 | |||
833 | return nrow, ncol |
|
833 | return nrow, ncol | |
834 |
|
834 | |||
835 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
835 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): | |
836 |
|
836 | |||
837 | showprofile = False |
|
837 | showprofile = False | |
838 | self.__showprofile = showprofile |
|
838 | self.__showprofile = showprofile | |
839 | self.nplots = nplots |
|
839 | self.nplots = nplots | |
840 |
|
840 | |||
841 | ncolspan = 5 |
|
841 | ncolspan = 5 | |
842 | colspan = 4 |
|
842 | colspan = 4 | |
843 | if showprofile: |
|
843 | if showprofile: | |
844 | ncolspan = 5 |
|
844 | ncolspan = 5 | |
845 | colspan = 4 |
|
845 | colspan = 4 | |
846 | self.__nsubplots = 2 |
|
846 | self.__nsubplots = 2 | |
847 |
|
847 | |||
848 | self.createFigure(id = id, |
|
848 | self.createFigure(id = id, | |
849 | wintitle = wintitle, |
|
849 | wintitle = wintitle, | |
850 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
850 | widthplot = self.WIDTH + self.WIDTHPROF, | |
851 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
851 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
852 | show=show) |
|
852 | show=show) | |
853 |
|
853 | |||
854 | nrow, ncol = self.getSubplots() |
|
854 | nrow, ncol = self.getSubplots() | |
855 |
|
855 | |||
856 | counter = 0 |
|
856 | counter = 0 | |
857 | for y in range(nrow): |
|
857 | for y in range(nrow): | |
858 | for x in range(ncol): |
|
858 | for x in range(ncol): | |
859 |
|
859 | |||
860 | if counter >= self.nplots: |
|
860 | if counter >= self.nplots: | |
861 | break |
|
861 | break | |
862 |
|
862 | |||
863 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
863 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
864 |
|
864 | |||
865 | if showprofile: |
|
865 | if showprofile: | |
866 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
866 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
867 |
|
867 | |||
868 | counter += 1 |
|
868 | counter += 1 | |
869 |
|
869 | |||
870 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
870 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, | |
871 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
871 | xmin=None, xmax=None, ymin=None, ymax=None, | |
872 | save=False, figpath='./', figfile=None, show=True): |
|
872 | save=False, figpath='./', figfile=None, show=True): | |
873 |
|
873 | |||
874 | """ |
|
874 | """ | |
875 |
|
875 | |||
876 | Input: |
|
876 | Input: | |
877 | dataOut : |
|
877 | dataOut : | |
878 | id : |
|
878 | id : | |
879 | wintitle : |
|
879 | wintitle : | |
880 | channelList : |
|
880 | channelList : | |
881 | showProfile : |
|
881 | showProfile : | |
882 | xmin : None, |
|
882 | xmin : None, | |
883 | xmax : None, |
|
883 | xmax : None, | |
884 | zmin : None, |
|
884 | zmin : None, | |
885 | zmax : None |
|
885 | zmax : None | |
886 | """ |
|
886 | """ | |
887 |
|
887 | |||
888 | if cutHeight==None: |
|
888 | if cutHeight==None: | |
889 | h=270 |
|
889 | h=270 | |
890 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
890 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() | |
891 | cutHeight = dataOut.heightList[heightindex] |
|
891 | cutHeight = dataOut.heightList[heightindex] | |
892 |
|
892 | |||
893 | factor = dataOut.normFactor |
|
893 | factor = dataOut.normFactor | |
894 | x = dataOut.abscissaList[:-1] |
|
894 | x = dataOut.abscissaList[:-1] | |
895 | #y = dataOut.getHeiRange() |
|
895 | #y = dataOut.getHeiRange() | |
896 |
|
896 | |||
897 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
897 | z = dataOut.data_pre[:,:,heightindex]/factor | |
898 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
898 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
899 | avg = numpy.average(z, axis=1) |
|
899 | avg = numpy.average(z, axis=1) | |
900 | listChannels = z.shape[0] |
|
900 | listChannels = z.shape[0] | |
901 |
|
901 | |||
902 | #Reconstruct Function |
|
902 | #Reconstruct Function | |
903 | if fit==True: |
|
903 | if fit==True: | |
904 | groupArray = dataOut.groupList |
|
904 | groupArray = dataOut.groupList | |
905 | listChannels = groupArray.reshape((groupArray.size)) |
|
905 | listChannels = groupArray.reshape((groupArray.size)) | |
906 | listChannels.sort() |
|
906 | listChannels.sort() | |
907 | spcFitLine = numpy.zeros(z.shape) |
|
907 | spcFitLine = numpy.zeros(z.shape) | |
908 | constants = dataOut.constants |
|
908 | constants = dataOut.constants | |
909 |
|
909 | |||
910 | nGroups = groupArray.shape[0] |
|
910 | nGroups = groupArray.shape[0] | |
911 | nChannels = groupArray.shape[1] |
|
911 | nChannels = groupArray.shape[1] | |
912 | nProfiles = z.shape[1] |
|
912 | nProfiles = z.shape[1] | |
913 |
|
913 | |||
914 | for f in range(nGroups): |
|
914 | for f in range(nGroups): | |
915 | groupChann = groupArray[f,:] |
|
915 | groupChann = groupArray[f,:] | |
916 | p = dataOut.data_param[f,:,heightindex] |
|
916 | p = dataOut.data_param[f,:,heightindex] | |
917 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
917 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) | |
918 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
918 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles | |
919 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
919 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) | |
920 | spcFitLine[groupChann,:] = fitLineAux |
|
920 | spcFitLine[groupChann,:] = fitLineAux | |
921 | # spcFitLine = spcFitLine/factor |
|
921 | # spcFitLine = spcFitLine/factor | |
922 |
|
922 | |||
923 | z = z[listChannels,:] |
|
923 | z = z[listChannels,:] | |
924 | spcFitLine = spcFitLine[listChannels,:] |
|
924 | spcFitLine = spcFitLine[listChannels,:] | |
925 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
925 | spcFitLinedB = 10*numpy.log10(spcFitLine) | |
926 |
|
926 | |||
927 | zdB = 10*numpy.log10(z) |
|
927 | zdB = 10*numpy.log10(z) | |
928 | #thisDatetime = dataOut.datatime |
|
928 | #thisDatetime = dataOut.datatime | |
929 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
929 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
930 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
930 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
931 | xlabel = "Velocity (m/s)" |
|
931 | xlabel = "Velocity (m/s)" | |
932 | ylabel = "Spectrum" |
|
932 | ylabel = "Spectrum" | |
933 |
|
933 | |||
934 | if not self.__isConfig: |
|
934 | if not self.__isConfig: | |
935 |
|
935 | |||
936 | nplots = listChannels.size |
|
936 | nplots = listChannels.size | |
937 |
|
937 | |||
938 | self.setup(id=id, |
|
938 | self.setup(id=id, | |
939 | nplots=nplots, |
|
939 | nplots=nplots, | |
940 | wintitle=wintitle, |
|
940 | wintitle=wintitle, | |
941 | showprofile=showprofile, |
|
941 | showprofile=showprofile, | |
942 | show=show) |
|
942 | show=show) | |
943 |
|
943 | |||
944 | if xmin == None: xmin = numpy.nanmin(x) |
|
944 | if xmin == None: xmin = numpy.nanmin(x) | |
945 | if xmax == None: xmax = numpy.nanmax(x) |
|
945 | if xmax == None: xmax = numpy.nanmax(x) | |
946 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
946 | if ymin == None: ymin = numpy.nanmin(zdB) | |
947 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
947 | if ymax == None: ymax = numpy.nanmax(zdB)+2 | |
948 |
|
948 | |||
949 | self.__isConfig = True |
|
949 | self.__isConfig = True | |
950 |
|
950 | |||
951 | self.setWinTitle(title) |
|
951 | self.setWinTitle(title) | |
952 | for i in range(self.nplots): |
|
952 | for i in range(self.nplots): | |
953 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
953 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) | |
954 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1) |
|
954 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1) | |
955 | axes = self.axesList[i*self.__nsubplots] |
|
955 | axes = self.axesList[i*self.__nsubplots] | |
956 | if fit == False: |
|
956 | if fit == False: | |
957 | axes.pline(x, zdB[i,:], |
|
957 | axes.pline(x, zdB[i,:], | |
958 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
958 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
959 | xlabel=xlabel, ylabel=ylabel, title=title |
|
959 | xlabel=xlabel, ylabel=ylabel, title=title | |
960 | ) |
|
960 | ) | |
961 | if fit == True: |
|
961 | if fit == True: | |
962 | fitline=spcFitLinedB[i,:] |
|
962 | fitline=spcFitLinedB[i,:] | |
963 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
963 | y=numpy.vstack([zdB[i,:],fitline] ) | |
964 | legendlabels=['Data','Fitting'] |
|
964 | legendlabels=['Data','Fitting'] | |
965 | axes.pmultilineyaxis(x, y, |
|
965 | axes.pmultilineyaxis(x, y, | |
966 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
966 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
967 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
967 | xlabel=xlabel, ylabel=ylabel, title=title, | |
968 | legendlabels=legendlabels, marker=None, |
|
968 | legendlabels=legendlabels, marker=None, | |
969 | linestyle='solid', grid='both') |
|
969 | linestyle='solid', grid='both') | |
970 |
|
970 | |||
971 | self.draw() |
|
971 | self.draw() | |
972 |
|
972 | |||
973 | self.save(figpath=figpath, |
|
973 | self.save(figpath=figpath, | |
974 | figfile=figfile, |
|
974 | figfile=figfile, | |
975 | save=save, |
|
975 | save=save, | |
976 | ftp=ftp, |
|
976 | ftp=ftp, | |
977 | wr_period=wr_period, |
|
977 | wr_period=wr_period, | |
978 | thisDatetime=thisDatetime) |
|
978 | thisDatetime=thisDatetime) | |
979 |
|
979 | |||
980 |
|
980 | |||
981 | class EWDriftsPlot(Figure): |
|
981 | class EWDriftsPlot(Figure): | |
982 |
|
982 | |||
983 | __isConfig = None |
|
983 | __isConfig = None | |
984 | __nsubplots = None |
|
984 | __nsubplots = None | |
985 |
|
985 | |||
986 | WIDTHPROF = None |
|
986 | WIDTHPROF = None | |
987 | HEIGHTPROF = None |
|
987 | HEIGHTPROF = None | |
988 | PREFIX = 'drift' |
|
988 | PREFIX = 'drift' | |
989 |
|
989 | |||
990 | def __init__(self): |
|
990 | def __init__(self): | |
991 |
|
991 | |||
992 | self.timerange = 2*60*60 |
|
992 | self.timerange = 2*60*60 | |
993 | self.isConfig = False |
|
993 | self.isConfig = False | |
994 | self.__nsubplots = 1 |
|
994 | self.__nsubplots = 1 | |
995 |
|
995 | |||
996 | self.WIDTH = 800 |
|
996 | self.WIDTH = 800 | |
997 | self.HEIGHT = 150 |
|
997 | self.HEIGHT = 150 | |
998 | self.WIDTHPROF = 120 |
|
998 | self.WIDTHPROF = 120 | |
999 | self.HEIGHTPROF = 0 |
|
999 | self.HEIGHTPROF = 0 | |
1000 | self.counter_imagwr = 0 |
|
1000 | self.counter_imagwr = 0 | |
1001 |
|
1001 | |||
1002 | self.PLOT_CODE = EWDRIFT_CODE |
|
1002 | self.PLOT_CODE = EWDRIFT_CODE | |
1003 |
|
1003 | |||
1004 | self.FTP_WEI = None |
|
1004 | self.FTP_WEI = None | |
1005 | self.EXP_CODE = None |
|
1005 | self.EXP_CODE = None | |
1006 | self.SUB_EXP_CODE = None |
|
1006 | self.SUB_EXP_CODE = None | |
1007 | self.PLOT_POS = None |
|
1007 | self.PLOT_POS = None | |
1008 | self.tmin = None |
|
1008 | self.tmin = None | |
1009 | self.tmax = None |
|
1009 | self.tmax = None | |
1010 |
|
1010 | |||
1011 | self.xmin = None |
|
1011 | self.xmin = None | |
1012 | self.xmax = None |
|
1012 | self.xmax = None | |
1013 |
|
1013 | |||
1014 | self.figfile = None |
|
1014 | self.figfile = None | |
1015 |
|
1015 | |||
1016 | def getSubplots(self): |
|
1016 | def getSubplots(self): | |
1017 |
|
1017 | |||
1018 | ncol = 1 |
|
1018 | ncol = 1 | |
1019 | nrow = self.nplots |
|
1019 | nrow = self.nplots | |
1020 |
|
1020 | |||
1021 | return nrow, ncol |
|
1021 | return nrow, ncol | |
1022 |
|
1022 | |||
1023 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1023 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1024 |
|
1024 | |||
1025 | self.__showprofile = showprofile |
|
1025 | self.__showprofile = showprofile | |
1026 | self.nplots = nplots |
|
1026 | self.nplots = nplots | |
1027 |
|
1027 | |||
1028 | ncolspan = 1 |
|
1028 | ncolspan = 1 | |
1029 | colspan = 1 |
|
1029 | colspan = 1 | |
1030 |
|
1030 | |||
1031 | self.createFigure(id = id, |
|
1031 | self.createFigure(id = id, | |
1032 | wintitle = wintitle, |
|
1032 | wintitle = wintitle, | |
1033 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1033 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1034 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1034 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1035 | show=show) |
|
1035 | show=show) | |
1036 |
|
1036 | |||
1037 | nrow, ncol = self.getSubplots() |
|
1037 | nrow, ncol = self.getSubplots() | |
1038 |
|
1038 | |||
1039 | counter = 0 |
|
1039 | counter = 0 | |
1040 | for y in range(nrow): |
|
1040 | for y in range(nrow): | |
1041 | if counter >= self.nplots: |
|
1041 | if counter >= self.nplots: | |
1042 | break |
|
1042 | break | |
1043 |
|
1043 | |||
1044 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1044 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) | |
1045 | counter += 1 |
|
1045 | counter += 1 | |
1046 |
|
1046 | |||
1047 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1047 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1048 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1048 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
1049 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1049 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, | |
1050 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1050 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, | |
1051 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1051 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
1052 | server=None, folder=None, username=None, password=None, |
|
1052 | server=None, folder=None, username=None, password=None, | |
1053 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1053 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1054 | """ |
|
1054 | """ | |
1055 |
|
1055 | |||
1056 | Input: |
|
1056 | Input: | |
1057 | dataOut : |
|
1057 | dataOut : | |
1058 | id : |
|
1058 | id : | |
1059 | wintitle : |
|
1059 | wintitle : | |
1060 | channelList : |
|
1060 | channelList : | |
1061 | showProfile : |
|
1061 | showProfile : | |
1062 | xmin : None, |
|
1062 | xmin : None, | |
1063 | xmax : None, |
|
1063 | xmax : None, | |
1064 | ymin : None, |
|
1064 | ymin : None, | |
1065 | ymax : None, |
|
1065 | ymax : None, | |
1066 | zmin : None, |
|
1066 | zmin : None, | |
1067 | zmax : None |
|
1067 | zmax : None | |
1068 | """ |
|
1068 | """ | |
1069 |
|
1069 | |||
1070 | if timerange != None: |
|
1070 | if timerange != None: | |
1071 | self.timerange = timerange |
|
1071 | self.timerange = timerange | |
1072 |
|
1072 | |||
1073 | tmin = None |
|
1073 | tmin = None | |
1074 | tmax = None |
|
1074 | tmax = None | |
1075 |
|
1075 | |||
1076 | x = dataOut.getTimeRange1() |
|
1076 | x = dataOut.getTimeRange1() | |
1077 | # y = dataOut.heightList |
|
1077 | # y = dataOut.heightList | |
1078 | y = dataOut.heightList |
|
1078 | y = dataOut.heightList | |
1079 |
|
1079 | |||
1080 | z = dataOut.data_output |
|
1080 | z = dataOut.data_output | |
1081 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1081 | nplots = z.shape[0] #Number of wind dimensions estimated | |
1082 | nplotsw = nplots |
|
1082 | nplotsw = nplots | |
1083 |
|
1083 | |||
1084 | #If there is a SNR function defined |
|
1084 | #If there is a SNR function defined | |
1085 | if dataOut.data_SNR != None: |
|
1085 | if dataOut.data_SNR != None: | |
1086 | nplots += 1 |
|
1086 | nplots += 1 | |
1087 | SNR = dataOut.data_SNR |
|
1087 | SNR = dataOut.data_SNR | |
1088 |
|
1088 | |||
1089 | if SNR_1: |
|
1089 | if SNR_1: | |
1090 | SNR += 1 |
|
1090 | SNR += 1 | |
1091 |
|
1091 | |||
1092 | SNRavg = numpy.average(SNR, axis=0) |
|
1092 | SNRavg = numpy.average(SNR, axis=0) | |
1093 |
|
1093 | |||
1094 | SNRdB = 10*numpy.log10(SNR) |
|
1094 | SNRdB = 10*numpy.log10(SNR) | |
1095 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1095 | SNRavgdB = 10*numpy.log10(SNRavg) | |
1096 |
|
1096 | |||
1097 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1097 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] | |
1098 |
|
1098 | |||
1099 | for i in range(nplotsw): |
|
1099 | for i in range(nplotsw): | |
1100 | z[i,ind] = numpy.nan |
|
1100 | z[i,ind] = numpy.nan | |
1101 |
|
1101 | |||
1102 |
|
1102 | |||
1103 | showprofile = False |
|
1103 | showprofile = False | |
1104 | # thisDatetime = dataOut.datatime |
|
1104 | # thisDatetime = dataOut.datatime | |
1105 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1105 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) | |
1106 | title = wintitle + " EW Drifts" |
|
1106 | title = wintitle + " EW Drifts" | |
1107 | xlabel = "" |
|
1107 | xlabel = "" | |
1108 | ylabel = "Height (Km)" |
|
1108 | ylabel = "Height (Km)" | |
1109 |
|
1109 | |||
1110 | if not self.__isConfig: |
|
1110 | if not self.__isConfig: | |
1111 |
|
1111 | |||
1112 | self.setup(id=id, |
|
1112 | self.setup(id=id, | |
1113 | nplots=nplots, |
|
1113 | nplots=nplots, | |
1114 | wintitle=wintitle, |
|
1114 | wintitle=wintitle, | |
1115 | showprofile=showprofile, |
|
1115 | showprofile=showprofile, | |
1116 | show=show) |
|
1116 | show=show) | |
1117 |
|
1117 | |||
1118 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1118 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
1119 |
|
1119 | |||
1120 | if ymin == None: ymin = numpy.nanmin(y) |
|
1120 | if ymin == None: ymin = numpy.nanmin(y) | |
1121 | if ymax == None: ymax = numpy.nanmax(y) |
|
1121 | if ymax == None: ymax = numpy.nanmax(y) | |
1122 |
|
1122 | |||
1123 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1123 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) | |
1124 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1124 | if zminZonal == None: zminZonal = -zmaxZonal | |
1125 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1125 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) | |
1126 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1126 | if zminVertical == None: zminVertical = -zmaxVertical | |
1127 |
|
1127 | |||
1128 | if dataOut.data_SNR != None: |
|
1128 | if dataOut.data_SNR != None: | |
1129 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1129 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) | |
1130 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1130 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) | |
1131 |
|
1131 | |||
1132 | self.FTP_WEI = ftp_wei |
|
1132 | self.FTP_WEI = ftp_wei | |
1133 | self.EXP_CODE = exp_code |
|
1133 | self.EXP_CODE = exp_code | |
1134 | self.SUB_EXP_CODE = sub_exp_code |
|
1134 | self.SUB_EXP_CODE = sub_exp_code | |
1135 | self.PLOT_POS = plot_pos |
|
1135 | self.PLOT_POS = plot_pos | |
1136 |
|
1136 | |||
1137 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1137 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1138 | self.__isConfig = True |
|
1138 | self.__isConfig = True | |
1139 |
|
1139 | |||
1140 |
|
1140 | |||
1141 | self.setWinTitle(title) |
|
1141 | self.setWinTitle(title) | |
1142 |
|
1142 | |||
1143 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1143 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
1144 | x[1] = self.xmax |
|
1144 | x[1] = self.xmax | |
1145 |
|
1145 | |||
1146 | strWind = ['Zonal','Vertical'] |
|
1146 | strWind = ['Zonal','Vertical'] | |
1147 | strCb = 'Velocity (m/s)' |
|
1147 | strCb = 'Velocity (m/s)' | |
1148 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1148 | zmaxVector = [zmaxZonal, zmaxVertical] | |
1149 | zminVector = [zminZonal, zminVertical] |
|
1149 | zminVector = [zminZonal, zminVertical] | |
1150 |
|
1150 | |||
1151 | for i in range(nplotsw): |
|
1151 | for i in range(nplotsw): | |
1152 |
|
1152 | |||
1153 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1153 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1154 | axes = self.axesList[i*self.__nsubplots] |
|
1154 | axes = self.axesList[i*self.__nsubplots] | |
1155 |
|
1155 | |||
1156 | z1 = z[i,:].reshape((1,-1)) |
|
1156 | z1 = z[i,:].reshape((1,-1)) | |
1157 |
|
1157 | |||
1158 | axes.pcolorbuffer(x, y, z1, |
|
1158 | axes.pcolorbuffer(x, y, z1, | |
1159 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1159 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], | |
1160 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1160 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1161 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1161 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") | |
1162 |
|
1162 | |||
1163 | if dataOut.data_SNR != None: |
|
1163 | if dataOut.data_SNR != None: | |
1164 | i += 1 |
|
1164 | i += 1 | |
1165 | if SNR_1: |
|
1165 | if SNR_1: | |
1166 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1166 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1167 | else: |
|
1167 | else: | |
1168 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1168 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1169 | axes = self.axesList[i*self.__nsubplots] |
|
1169 | axes = self.axesList[i*self.__nsubplots] | |
1170 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1170 | SNRavgdB = SNRavgdB.reshape((1,-1)) | |
1171 |
|
1171 | |||
1172 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1172 | axes.pcolorbuffer(x, y, SNRavgdB, | |
1173 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1173 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
1174 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1174 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1175 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1175 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") | |
1176 |
|
1176 | |||
1177 | self.draw() |
|
1177 | self.draw() | |
1178 |
|
1178 | |||
1179 | if x[1] >= self.axesList[0].xmax: |
|
1179 | if x[1] >= self.axesList[0].xmax: | |
1180 | self.counter_imagwr = wr_period |
|
1180 | self.counter_imagwr = wr_period | |
1181 | self.__isConfig = False |
|
1181 | self.__isConfig = False | |
1182 | self.figfile = None |
|
1182 | self.figfile = None | |
1183 |
|
1183 | |||
1184 |
|
1184 | |||
1185 |
|
1185 | |||
1186 |
|
1186 | |||
1187 | class PhasePlot(Figure): |
|
1187 | class PhasePlot(Figure): | |
1188 |
|
1188 | |||
1189 | __isConfig = None |
|
1189 | __isConfig = None | |
1190 | __nsubplots = None |
|
1190 | __nsubplots = None | |
1191 |
|
1191 | |||
1192 | PREFIX = 'mphase' |
|
1192 | PREFIX = 'mphase' | |
1193 |
|
1193 | |||
1194 | def __init__(self): |
|
1194 | def __init__(self): | |
1195 |
|
1195 | |||
1196 | self.timerange = 24*60*60 |
|
1196 | self.timerange = 24*60*60 | |
1197 | self.__isConfig = False |
|
1197 | self.__isConfig = False | |
1198 | self.__nsubplots = 1 |
|
1198 | self.__nsubplots = 1 | |
1199 | self.counter_imagwr = 0 |
|
1199 | self.counter_imagwr = 0 | |
1200 | self.WIDTH = 600 |
|
1200 | self.WIDTH = 600 | |
1201 | self.HEIGHT = 300 |
|
1201 | self.HEIGHT = 300 | |
1202 | self.WIDTHPROF = 120 |
|
1202 | self.WIDTHPROF = 120 | |
1203 | self.HEIGHTPROF = 0 |
|
1203 | self.HEIGHTPROF = 0 | |
1204 | self.xdata = None |
|
1204 | self.xdata = None | |
1205 | self.ydata = None |
|
1205 | self.ydata = None | |
1206 |
|
1206 | |||
1207 | self.PLOT_CODE = MPHASE_CODE |
|
1207 | self.PLOT_CODE = MPHASE_CODE | |
1208 |
|
1208 | |||
1209 | self.FTP_WEI = None |
|
1209 | self.FTP_WEI = None | |
1210 | self.EXP_CODE = None |
|
1210 | self.EXP_CODE = None | |
1211 | self.SUB_EXP_CODE = None |
|
1211 | self.SUB_EXP_CODE = None | |
1212 | self.PLOT_POS = None |
|
1212 | self.PLOT_POS = None | |
1213 |
|
1213 | |||
1214 |
|
1214 | |||
1215 | self.filename_phase = None |
|
1215 | self.filename_phase = None | |
1216 |
|
1216 | |||
1217 | self.figfile = None |
|
1217 | self.figfile = None | |
1218 |
|
1218 | |||
1219 | def getSubplots(self): |
|
1219 | def getSubplots(self): | |
1220 |
|
1220 | |||
1221 | ncol = 1 |
|
1221 | ncol = 1 | |
1222 | nrow = 1 |
|
1222 | nrow = 1 | |
1223 |
|
1223 | |||
1224 | return nrow, ncol |
|
1224 | return nrow, ncol | |
1225 |
|
1225 | |||
1226 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1226 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1227 |
|
1227 | |||
1228 | self.__showprofile = showprofile |
|
1228 | self.__showprofile = showprofile | |
1229 | self.nplots = nplots |
|
1229 | self.nplots = nplots | |
1230 |
|
1230 | |||
1231 | ncolspan = 7 |
|
1231 | ncolspan = 7 | |
1232 | colspan = 6 |
|
1232 | colspan = 6 | |
1233 | self.__nsubplots = 2 |
|
1233 | self.__nsubplots = 2 | |
1234 |
|
1234 | |||
1235 | self.createFigure(id = id, |
|
1235 | self.createFigure(id = id, | |
1236 | wintitle = wintitle, |
|
1236 | wintitle = wintitle, | |
1237 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1237 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1238 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1238 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1239 | show=show) |
|
1239 | show=show) | |
1240 |
|
1240 | |||
1241 | nrow, ncol = self.getSubplots() |
|
1241 | nrow, ncol = self.getSubplots() | |
1242 |
|
1242 | |||
1243 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1243 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1244 |
|
1244 | |||
1245 |
|
1245 | |||
1246 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1246 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1247 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1247 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1248 | timerange=None, |
|
1248 | timerange=None, | |
1249 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
1249 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
1250 | server=None, folder=None, username=None, password=None, |
|
1250 | server=None, folder=None, username=None, password=None, | |
1251 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1251 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1252 |
|
1252 | |||
1253 |
|
1253 | |||
1254 | if timerange != None: |
|
|||
1255 | self.timerange = timerange |
|
|||
1256 |
|
||||
1257 | tmin = None |
|
1254 | tmin = None | |
1258 | tmax = None |
|
1255 | tmax = None | |
1259 | x = dataOut.getTimeRange1() |
|
1256 | x = dataOut.getTimeRange1() | |
1260 | y = dataOut.getHeiRange() |
|
1257 | y = dataOut.getHeiRange() | |
1261 |
|
1258 | |||
1262 |
|
1259 | |||
1263 | #thisDatetime = dataOut.datatime |
|
1260 | #thisDatetime = dataOut.datatime | |
1264 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1261 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1265 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1262 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1266 | xlabel = "Local Time" |
|
1263 | xlabel = "Local Time" | |
1267 | ylabel = "Phase" |
|
1264 | ylabel = "Phase" | |
1268 |
|
1265 | |||
1269 |
|
1266 | |||
1270 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1267 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
1271 | phase_beacon = dataOut.data_output |
|
1268 | phase_beacon = dataOut.data_output | |
1272 |
|
1269 | |||
1273 |
|
1270 | |||
1274 | if not self.__isConfig: |
|
1271 | if not self.__isConfig: | |
1275 |
|
1272 | |||
1276 | self.nplots = phase_beacon.size |
|
1273 | self.nplots = phase_beacon.size | |
1277 |
|
1274 | |||
1278 | self.setup(id=id, |
|
1275 | self.setup(id=id, | |
1279 | nplots=self.nplots, |
|
1276 | nplots=self.nplots, | |
1280 | wintitle=wintitle, |
|
1277 | wintitle=wintitle, | |
1281 | showprofile=showprofile, |
|
1278 | showprofile=showprofile, | |
1282 | show=show) |
|
1279 | show=show) | |
1283 |
|
|
1280 | ||
1284 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1281 | if timerange != None: | |
|
1282 | self.timerange = timerange | |||
|
1283 | ||||
|
1284 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |||
|
1285 | ||||
1285 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1286 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 | |
1286 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1287 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 | |
1287 |
|
1288 | |||
1288 | self.FTP_WEI = ftp_wei |
|
1289 | self.FTP_WEI = ftp_wei | |
1289 | self.EXP_CODE = exp_code |
|
1290 | self.EXP_CODE = exp_code | |
1290 | self.SUB_EXP_CODE = sub_exp_code |
|
1291 | self.SUB_EXP_CODE = sub_exp_code | |
1291 | self.PLOT_POS = plot_pos |
|
1292 | self.PLOT_POS = plot_pos | |
1292 |
|
1293 | |||
1293 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1294 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1294 | self.__isConfig = True |
|
1295 | self.__isConfig = True | |
1295 | self.figfile = figfile |
|
1296 | self.figfile = figfile | |
1296 | self.xdata = numpy.array([]) |
|
1297 | self.xdata = numpy.array([]) | |
1297 | self.ydata = numpy.array([]) |
|
1298 | self.ydata = numpy.array([]) | |
1298 |
|
1299 | |||
1299 | #open file beacon phase |
|
1300 | #open file beacon phase | |
1300 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1301 | path = '%s%03d' %(self.PREFIX, self.id) | |
1301 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1302 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
1302 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1303 | self.filename_phase = os.path.join(figpath,beacon_file) | |
1303 | #self.save_phase(self.filename_phase) |
|
1304 | #self.save_phase(self.filename_phase) | |
1304 |
|
1305 | |||
1305 |
|
1306 | |||
1306 | #store data beacon phase |
|
1307 | #store data beacon phase | |
1307 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1308 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
1308 |
|
1309 | |||
1309 | self.setWinTitle(title) |
|
1310 | self.setWinTitle(title) | |
1310 |
|
1311 | |||
1311 |
|
1312 | |||
1312 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1313 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1313 |
|
1314 | |||
1314 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] |
|
1315 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] | |
1315 |
|
1316 | |||
1316 | axes = self.axesList[0] |
|
1317 | axes = self.axesList[0] | |
1317 |
|
1318 | |||
1318 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1319 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1319 |
|
1320 | |||
1320 | if len(self.ydata)==0: |
|
1321 | if len(self.ydata)==0: | |
1321 | self.ydata = phase_beacon.reshape(-1,1) |
|
1322 | self.ydata = phase_beacon.reshape(-1,1) | |
1322 | else: |
|
1323 | else: | |
1323 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1324 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
1324 |
|
1325 | |||
1325 |
|
1326 | |||
1326 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1327 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1327 |
xmin= |
|
1328 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
1328 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1329 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1329 | XAxisAsTime=True, grid='both' |
|
1330 | XAxisAsTime=True, grid='both' | |
1330 | ) |
|
1331 | ) | |
1331 |
|
1332 | |||
1332 | self.draw() |
|
1333 | self.draw() | |
1333 |
|
1334 | |||
1334 | if x[1] >= self.axesList[0].xmax: |
|
1335 | if x[1] >= self.axesList[0].xmax: | |
1335 | self.counter_imagwr = wr_period |
|
1336 | self.counter_imagwr = wr_period | |
1336 | del self.xdata |
|
1337 | del self.xdata | |
1337 | del self.ydata |
|
1338 | del self.ydata | |
1338 | self.__isConfig = False |
|
1339 | self.__isConfig = False | |
1339 |
|
1340 | |||
1340 | if self.figfile == None: |
|
1341 | if self.figfile == None: | |
1341 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1342 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1342 | self.figfile = self.getFilename(name = str_datetime) |
|
1343 | self.figfile = self.getFilename(name = str_datetime) | |
1343 |
|
1344 | |||
1344 | if figpath != '': |
|
1345 | if figpath != '': | |
1345 | self.counter_imagwr += 1 |
|
1346 | self.counter_imagwr += 1 | |
1346 | if (self.counter_imagwr>=wr_period): |
|
1347 | if (self.counter_imagwr>=wr_period): | |
1347 | # store png plot to local folder |
|
1348 | # store png plot to local folder | |
1348 | self.saveFigure(figpath, self.figfile) |
|
1349 | self.saveFigure(figpath, self.figfile) | |
1349 | # store png plot to FTP server according to RT-Web format |
|
1350 | # store png plot to FTP server according to RT-Web format | |
1350 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1351 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1351 | ftp_filename = os.path.join(figpath, name) |
|
1352 | ftp_filename = os.path.join(figpath, name) | |
1352 | self.saveFigure(figpath, ftp_filename) |
|
1353 | self.saveFigure(figpath, ftp_filename) | |
1353 | self.counter_imagwr = 0 |
|
1354 | self.counter_imagwr = 0 | |
1354 | self.figfile = None |
|
1355 | self.figfile = None | |
1355 |
|
1356 | |||
1356 | self.save(figpath=figpath, |
|
1357 | self.save(figpath=figpath, | |
1357 | figfile=figfile, |
|
1358 | figfile=figfile, | |
1358 | save=save, |
|
1359 | save=save, | |
1359 | ftp=ftp, |
|
1360 | ftp=ftp, | |
1360 | wr_period=wr_period, |
|
1361 | wr_period=wr_period, | |
1361 | thisDatetime=thisDatetime, |
|
1362 | thisDatetime=thisDatetime, | |
1362 | update_figfile=False) |
|
1363 | update_figfile=False) |
@@ -1,1005 +1,1005 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time |
|
2 | import time | |
3 | import os |
|
3 | import os | |
4 | import h5py |
|
4 | import h5py | |
5 | import re |
|
5 | import re | |
6 | import tables |
|
6 | import tables | |
7 |
|
7 | |||
8 | from schainpy.model.data.jrodata import * |
|
8 | from schainpy.model.data.jrodata import * | |
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
10 | from schainpy.model.io.jroIO_base import * |
|
10 | from schainpy.model.io.jroIO_base import * | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class HDF5Reader(ProcessingUnit): |
|
13 | class HDF5Reader(ProcessingUnit): | |
14 |
|
14 | |||
15 | ext = ".hdf5" |
|
15 | ext = ".hdf5" | |
16 |
|
16 | |||
17 | optchar = "D" |
|
17 | optchar = "D" | |
18 |
|
18 | |||
19 | timezone = None |
|
19 | timezone = None | |
20 |
|
20 | |||
21 | secStart = None |
|
21 | secStart = None | |
22 |
|
22 | |||
23 | secEnd = None |
|
23 | secEnd = None | |
24 |
|
24 | |||
25 | fileIndex = None |
|
25 | fileIndex = None | |
26 |
|
26 | |||
27 | blockIndex = None |
|
27 | blockIndex = None | |
28 |
|
28 | |||
29 | blocksPerFile = None |
|
29 | blocksPerFile = None | |
30 |
|
30 | |||
31 | path = None |
|
31 | path = None | |
32 |
|
32 | |||
33 | #List of Files |
|
33 | #List of Files | |
34 |
|
34 | |||
35 | filenameList = None |
|
35 | filenameList = None | |
36 |
|
36 | |||
37 | datetimeList = None |
|
37 | datetimeList = None | |
38 |
|
38 | |||
39 | #Hdf5 File |
|
39 | #Hdf5 File | |
40 |
|
40 | |||
41 | fpMetadata = None |
|
41 | fpMetadata = None | |
42 |
|
42 | |||
43 | pathMeta = None |
|
43 | pathMeta = None | |
44 |
|
44 | |||
45 | listMetaname = None |
|
45 | listMetaname = None | |
46 |
|
46 | |||
47 | listMeta = None |
|
47 | listMeta = None | |
48 |
|
48 | |||
49 | listDataname = None |
|
49 | listDataname = None | |
50 |
|
50 | |||
51 | listData = None |
|
51 | listData = None | |
52 |
|
52 | |||
53 | listShapes = None |
|
53 | listShapes = None | |
54 |
|
54 | |||
55 | fp = None |
|
55 | fp = None | |
56 |
|
56 | |||
57 | #dataOut reconstruction |
|
57 | #dataOut reconstruction | |
58 |
|
58 | |||
59 | dataOut = None |
|
59 | dataOut = None | |
60 |
|
60 | |||
61 | nRecords = None |
|
61 | nRecords = None | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | def __init__(self): |
|
64 | def __init__(self): | |
65 | self.dataOut = self.__createObjByDefault() |
|
65 | self.dataOut = self.__createObjByDefault() | |
66 | return |
|
66 | return | |
67 |
|
67 | |||
68 | def __createObjByDefault(self): |
|
68 | def __createObjByDefault(self): | |
69 |
|
69 | |||
70 | dataObj = Parameters() |
|
70 | dataObj = Parameters() | |
71 |
|
71 | |||
72 | return dataObj |
|
72 | return dataObj | |
73 |
|
73 | |||
74 | def setup(self,path=None, |
|
74 | def setup(self,path=None, | |
75 | startDate=None, |
|
75 | startDate=None, | |
76 | endDate=None, |
|
76 | endDate=None, | |
77 | startTime=datetime.time(0,0,0), |
|
77 | startTime=datetime.time(0,0,0), | |
78 | endTime=datetime.time(23,59,59), |
|
78 | endTime=datetime.time(23,59,59), | |
79 | walk=True, |
|
79 | walk=True, | |
80 | timezone='ut', |
|
80 | timezone='ut', | |
81 | all=0, |
|
81 | all=0, | |
82 | online=False, |
|
82 | online=False, | |
83 | ext=None): |
|
83 | ext=None): | |
84 |
|
84 | |||
85 | if ext==None: |
|
85 | if ext==None: | |
86 | ext = self.ext |
|
86 | ext = self.ext | |
87 | self.timezone = timezone |
|
87 | self.timezone = timezone | |
88 | # self.all = all |
|
88 | # self.all = all | |
89 | # self.online = online |
|
89 | # self.online = online | |
90 | self.path = path |
|
90 | self.path = path | |
91 |
|
91 | |||
92 | startDateTime = datetime.datetime.combine(startDate,startTime) |
|
92 | startDateTime = datetime.datetime.combine(startDate,startTime) | |
93 | endDateTime = datetime.datetime.combine(endDate,endTime) |
|
93 | endDateTime = datetime.datetime.combine(endDate,endTime) | |
94 | secStart = (startDateTime-datetime.datetime(1970,1,1)).total_seconds() |
|
94 | secStart = (startDateTime-datetime.datetime(1970,1,1)).total_seconds() | |
95 | secEnd = (endDateTime-datetime.datetime(1970,1,1)).total_seconds() |
|
95 | secEnd = (endDateTime-datetime.datetime(1970,1,1)).total_seconds() | |
96 |
|
96 | |||
97 | self.secStart = secStart |
|
97 | self.secStart = secStart | |
98 | self.secEnd = secEnd |
|
98 | self.secEnd = secEnd | |
99 |
|
99 | |||
100 | if not(online): |
|
100 | if not(online): | |
101 | #Busqueda de archivos offline |
|
101 | #Busqueda de archivos offline | |
102 | self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, secStart, secEnd, walk) |
|
102 | self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, secStart, secEnd, walk) | |
103 | else: |
|
103 | else: | |
104 | self.__searchFilesOnline(path, walk) |
|
104 | self.__searchFilesOnline(path, walk) | |
105 |
|
105 | |||
106 | if not(self.filenameList): |
|
106 | if not(self.filenameList): | |
107 | print "There is no files into the folder: %s"%(path) |
|
107 | print "There is no files into the folder: %s"%(path) | |
108 | sys.exit(-1) |
|
108 | sys.exit(-1) | |
109 |
|
109 | |||
110 | # self.__getExpParameters() |
|
110 | # self.__getExpParameters() | |
111 |
|
111 | |||
112 | self.fileIndex = -1 |
|
112 | self.fileIndex = -1 | |
113 |
|
113 | |||
114 | self.__setNextFileOffline() |
|
114 | self.__setNextFileOffline() | |
115 |
|
115 | |||
116 | self.__readMetadata() |
|
116 | self.__readMetadata() | |
117 |
|
117 | |||
118 | self.blockIndex = 0 |
|
118 | self.blockIndex = 0 | |
119 |
|
119 | |||
120 | return |
|
120 | return | |
121 |
|
121 | |||
122 | def __searchFilesOffline(self, |
|
122 | def __searchFilesOffline(self, | |
123 | path, |
|
123 | path, | |
124 | startDate, |
|
124 | startDate, | |
125 | endDate, |
|
125 | endDate, | |
126 | ext, |
|
126 | ext, | |
127 | startTime=datetime.time(0,0,0), |
|
127 | startTime=datetime.time(0,0,0), | |
128 | endTime=datetime.time(23,59,59), |
|
128 | endTime=datetime.time(23,59,59), | |
129 | secStart = 0, |
|
129 | secStart = 0, | |
130 | secEnd = numpy.inf, |
|
130 | secEnd = numpy.inf, | |
131 | walk=True): |
|
131 | walk=True): | |
132 |
|
132 | |||
133 | # self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
133 | # self.__setParameters(path, startDate, endDate, startTime, endTime, walk) | |
134 | # |
|
134 | # | |
135 | # self.__checkPath() |
|
135 | # self.__checkPath() | |
136 | # |
|
136 | # | |
137 | # self.__findDataForDates() |
|
137 | # self.__findDataForDates() | |
138 | # |
|
138 | # | |
139 | # self.__selectDataForTimes() |
|
139 | # self.__selectDataForTimes() | |
140 | # |
|
140 | # | |
141 | # for i in range(len(self.filenameList)): |
|
141 | # for i in range(len(self.filenameList)): | |
142 | # print "%s" %(self.filenameList[i]) |
|
142 | # print "%s" %(self.filenameList[i]) | |
143 |
|
143 | |||
144 | pathList = [] |
|
144 | pathList = [] | |
145 |
|
145 | |||
146 | if not walk: |
|
146 | if not walk: | |
147 | #pathList.append(path) |
|
147 | #pathList.append(path) | |
148 | multi_path = path.split(',') |
|
148 | multi_path = path.split(',') | |
149 | for single_path in multi_path: |
|
149 | for single_path in multi_path: | |
150 | pathList.append(single_path) |
|
150 | pathList.append(single_path) | |
151 |
|
151 | |||
152 | else: |
|
152 | else: | |
153 | #dirList = [] |
|
153 | #dirList = [] | |
154 | multi_path = path.split(',') |
|
154 | multi_path = path.split(',') | |
155 | for single_path in multi_path: |
|
155 | for single_path in multi_path: | |
156 | dirList = [] |
|
156 | dirList = [] | |
157 | for thisPath in os.listdir(single_path): |
|
157 | for thisPath in os.listdir(single_path): | |
158 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
158 | if not os.path.isdir(os.path.join(single_path,thisPath)): | |
159 | continue |
|
159 | continue | |
160 | if not isDoyFolder(thisPath): |
|
160 | if not isDoyFolder(thisPath): | |
161 | continue |
|
161 | continue | |
162 |
|
162 | |||
163 | dirList.append(thisPath) |
|
163 | dirList.append(thisPath) | |
164 |
|
164 | |||
165 | if not(dirList): |
|
165 | if not(dirList): | |
166 | return None, None |
|
166 | return None, None | |
167 |
|
167 | |||
168 | thisDate = startDate |
|
168 | thisDate = startDate | |
169 |
|
169 | |||
170 | while(thisDate <= endDate): |
|
170 | while(thisDate <= endDate): | |
171 | year = thisDate.timetuple().tm_year |
|
171 | year = thisDate.timetuple().tm_year | |
172 | doy = thisDate.timetuple().tm_yday |
|
172 | doy = thisDate.timetuple().tm_yday | |
173 |
|
173 | |||
174 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
174 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') | |
175 | if len(matchlist) == 0: |
|
175 | if len(matchlist) == 0: | |
176 | thisDate += datetime.timedelta(1) |
|
176 | thisDate += datetime.timedelta(1) | |
177 | continue |
|
177 | continue | |
178 | for match in matchlist: |
|
178 | for match in matchlist: | |
179 | pathList.append(os.path.join(single_path,match)) |
|
179 | pathList.append(os.path.join(single_path,match)) | |
180 |
|
180 | |||
181 | thisDate += datetime.timedelta(1) |
|
181 | thisDate += datetime.timedelta(1) | |
182 |
|
182 | |||
183 | if pathList == []: |
|
183 | if pathList == []: | |
184 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
184 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
185 | return None, None |
|
185 | return None, None | |
186 |
|
186 | |||
187 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
187 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) | |
188 |
|
188 | |||
189 | filenameList = [] |
|
189 | filenameList = [] | |
190 | datetimeList = [] |
|
190 | datetimeList = [] | |
191 | pathDict = {} |
|
191 | pathDict = {} | |
192 | filenameList_to_sort = [] |
|
192 | filenameList_to_sort = [] | |
193 |
|
193 | |||
194 | for i in range(len(pathList)): |
|
194 | for i in range(len(pathList)): | |
195 |
|
195 | |||
196 | thisPath = pathList[i] |
|
196 | thisPath = pathList[i] | |
197 |
|
197 | |||
198 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
198 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
199 | fileList.sort() |
|
199 | fileList.sort() | |
200 | pathDict.setdefault(fileList[0]) |
|
200 | pathDict.setdefault(fileList[0]) | |
201 | pathDict[fileList[0]] = i |
|
201 | pathDict[fileList[0]] = i | |
202 | filenameList_to_sort.append(fileList[0]) |
|
202 | filenameList_to_sort.append(fileList[0]) | |
203 |
|
203 | |||
204 | filenameList_to_sort.sort() |
|
204 | filenameList_to_sort.sort() | |
205 |
|
205 | |||
206 | for file in filenameList_to_sort: |
|
206 | for file in filenameList_to_sort: | |
207 | thisPath = pathList[pathDict[file]] |
|
207 | thisPath = pathList[pathDict[file]] | |
208 |
|
208 | |||
209 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
209 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
210 | fileList.sort() |
|
210 | fileList.sort() | |
211 |
|
211 | |||
212 | for file in fileList: |
|
212 | for file in fileList: | |
213 |
|
213 | |||
214 | filename = os.path.join(thisPath,file) |
|
214 | filename = os.path.join(thisPath,file) | |
215 | thisDatetime = self.__isFileinThisTime(filename, secStart, secEnd) |
|
215 | thisDatetime = self.__isFileinThisTime(filename, secStart, secEnd) | |
216 |
|
216 | |||
217 | if not(thisDatetime): |
|
217 | if not(thisDatetime): | |
218 | continue |
|
218 | continue | |
219 |
|
219 | |||
220 | filenameList.append(filename) |
|
220 | filenameList.append(filename) | |
221 | datetimeList.append(thisDatetime) |
|
221 | datetimeList.append(thisDatetime) | |
222 |
|
222 | |||
223 | if not(filenameList): |
|
223 | if not(filenameList): | |
224 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
224 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
225 | return None, None |
|
225 | return None, None | |
226 |
|
226 | |||
227 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
227 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |
228 |
|
228 | |||
229 |
|
229 | |||
230 | for i in range(len(filenameList)): |
|
230 | for i in range(len(filenameList)): | |
231 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
231 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
232 |
|
232 | |||
233 | self.filenameList = filenameList |
|
233 | self.filenameList = filenameList | |
234 | self.datetimeList = datetimeList |
|
234 | self.datetimeList = datetimeList | |
235 |
|
235 | |||
236 | return pathList, filenameList |
|
236 | return pathList, filenameList | |
237 |
|
237 | |||
238 | def __isFileinThisTime(self, filename, startSeconds, endSeconds): |
|
238 | def __isFileinThisTime(self, filename, startSeconds, endSeconds): | |
239 | """ |
|
239 | """ | |
240 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
240 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
241 |
|
241 | |||
242 | Inputs: |
|
242 | Inputs: | |
243 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
243 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
244 |
|
244 | |||
245 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
245 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
246 |
|
246 | |||
247 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
247 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
248 |
|
248 | |||
249 | Return: |
|
249 | Return: | |
250 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
250 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
251 | fecha especificado, de lo contrario retorna False. |
|
251 | fecha especificado, de lo contrario retorna False. | |
252 |
|
252 | |||
253 | Excepciones: |
|
253 | Excepciones: | |
254 | Si el archivo no existe o no puede ser abierto |
|
254 | Si el archivo no existe o no puede ser abierto | |
255 | Si la cabecera no puede ser leida. |
|
255 | Si la cabecera no puede ser leida. | |
256 |
|
256 | |||
257 | """ |
|
257 | """ | |
258 |
|
258 | |||
259 | try: |
|
259 | try: | |
260 | fp = fp = h5py.File(filename,'r') |
|
260 | fp = fp = h5py.File(filename,'r') | |
261 | except IOError: |
|
261 | except IOError: | |
262 | traceback.print_exc() |
|
262 | traceback.print_exc() | |
263 | raise IOError, "The file %s can't be opened" %(filename) |
|
263 | raise IOError, "The file %s can't be opened" %(filename) | |
264 |
|
264 | |||
265 | grp = fp['Data'] |
|
265 | grp = fp['Data'] | |
266 | timeAux = grp['time'] |
|
266 | timeAux = grp['time'] | |
267 | time0 = timeAux[:][0].astype(numpy.float) #Time Vector |
|
267 | time0 = timeAux[:][0].astype(numpy.float) #Time Vector | |
268 |
|
268 | |||
269 | fp.close() |
|
269 | fp.close() | |
270 |
|
270 | |||
271 | if self.timezone == 'lt': |
|
271 | if self.timezone == 'lt': | |
272 | time0 -= 5*3600 |
|
272 | time0 -= 5*3600 | |
273 |
|
273 | |||
274 | boolTimer = numpy.logical_and(time0 >= startSeconds,time0 < endSeconds) |
|
274 | boolTimer = numpy.logical_and(time0 >= startSeconds,time0 < endSeconds) | |
275 |
|
275 | |||
276 | if not (numpy.any(boolTimer)): |
|
276 | if not (numpy.any(boolTimer)): | |
277 | return None |
|
277 | return None | |
278 |
|
278 | |||
279 | thisDatetime = datetime.datetime.utcfromtimestamp(time0[0]) |
|
279 | thisDatetime = datetime.datetime.utcfromtimestamp(time0[0]) | |
280 | return thisDatetime |
|
280 | return thisDatetime | |
281 |
|
281 | |||
282 | def __checkPath(self): |
|
282 | def __checkPath(self): | |
283 | if os.path.exists(self.path): |
|
283 | if os.path.exists(self.path): | |
284 | self.status = 1 |
|
284 | self.status = 1 | |
285 | else: |
|
285 | else: | |
286 | self.status = 0 |
|
286 | self.status = 0 | |
287 | print 'Path:%s does not exists'%self.path |
|
287 | print 'Path:%s does not exists'%self.path | |
288 |
|
288 | |||
289 | return |
|
289 | return | |
290 |
|
290 | |||
291 | def __setNextFileOffline(self): |
|
291 | def __setNextFileOffline(self): | |
292 | idFile = self.fileIndex |
|
292 | idFile = self.fileIndex | |
293 | idFile += 1 |
|
293 | idFile += 1 | |
294 |
|
294 | |||
295 | if not(idFile < len(self.filenameList)): |
|
295 | if not(idFile < len(self.filenameList)): | |
296 | print "No more Files" |
|
296 | print "No more Files" | |
297 | return 0 |
|
297 | return 0 | |
298 |
|
298 | |||
299 | filename = self.filenameList[idFile] |
|
299 | filename = self.filenameList[idFile] | |
300 |
|
300 | |||
301 | filePointer = h5py.File(filename,'r') |
|
301 | filePointer = h5py.File(filename,'r') | |
302 |
|
302 | |||
303 | self.flagIsNewFile = 1 |
|
303 | self.flagIsNewFile = 1 | |
304 | self.fileIndex = idFile |
|
304 | self.fileIndex = idFile | |
305 | self.filename = filename |
|
305 | self.filename = filename | |
306 |
|
306 | |||
307 | self.fp = filePointer |
|
307 | self.fp = filePointer | |
308 |
|
308 | |||
309 | print "Setting the file: %s"%self.filename |
|
309 | print "Setting the file: %s"%self.filename | |
310 |
|
310 | |||
311 | self.__readMetadata() |
|
311 | self.__readMetadata() | |
312 | self.__setBlockList() |
|
312 | self.__setBlockList() | |
313 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] |
|
313 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] | |
314 | self.nRecords = self.fp['Data'].attrs['nRecords'] |
|
314 | self.nRecords = self.fp['Data'].attrs['nRecords'] | |
315 | self.blockIndex = 0 |
|
315 | self.blockIndex = 0 | |
316 | return 1 |
|
316 | return 1 | |
317 |
|
317 | |||
318 | def __setBlockList(self): |
|
318 | def __setBlockList(self): | |
319 | ''' |
|
319 | ''' | |
320 | self.fp |
|
320 | self.fp | |
321 | self.startDateTime |
|
321 | self.startDateTime | |
322 | self.endDateTime |
|
322 | self.endDateTime | |
323 |
|
323 | |||
324 | self.blockList |
|
324 | self.blockList | |
325 | self.blocksPerFile |
|
325 | self.blocksPerFile | |
326 |
|
326 | |||
327 | ''' |
|
327 | ''' | |
328 | filePointer = self.fp |
|
328 | filePointer = self.fp | |
329 | secStart = self.secStart |
|
329 | secStart = self.secStart | |
330 | secEnd = self.secEnd |
|
330 | secEnd = self.secEnd | |
331 |
|
331 | |||
332 | grp = filePointer['Data'] |
|
332 | grp = filePointer['Data'] | |
333 | timeVector = grp['time'].value.astype(numpy.float)[0] |
|
333 | timeVector = grp['time'].value.astype(numpy.float)[0] | |
334 |
|
334 | |||
335 | if self.timezone == 'lt': |
|
335 | if self.timezone == 'lt': | |
336 | timeVector -= 5*3600 |
|
336 | timeVector -= 5*3600 | |
337 |
|
337 | |||
338 | ind = numpy.where(numpy.logical_and(timeVector >= secStart , timeVector < secEnd))[0] |
|
338 | ind = numpy.where(numpy.logical_and(timeVector >= secStart , timeVector < secEnd))[0] | |
339 |
|
339 | |||
340 | self.blockList = ind |
|
340 | self.blockList = ind | |
341 | self.blocksPerFile = len(ind) |
|
341 | self.blocksPerFile = len(ind) | |
342 |
|
342 | |||
343 | return |
|
343 | return | |
344 |
|
344 | |||
345 | def __readMetadata(self): |
|
345 | def __readMetadata(self): | |
346 | ''' |
|
346 | ''' | |
347 | self.pathMeta |
|
347 | self.pathMeta | |
348 |
|
348 | |||
349 | self.listShapes |
|
349 | self.listShapes | |
350 | self.listMetaname |
|
350 | self.listMetaname | |
351 | self.listMeta |
|
351 | self.listMeta | |
352 |
|
352 | |||
353 | ''' |
|
353 | ''' | |
354 |
|
354 | |||
355 | grp = self.fp['Data'] |
|
355 | grp = self.fp['Data'] | |
356 | pathMeta = os.path.join(self.path, grp.attrs['metadata']) |
|
356 | pathMeta = os.path.join(self.path, grp.attrs['metadata']) | |
357 |
|
357 | |||
358 | if pathMeta == self.pathMeta: |
|
358 | if pathMeta == self.pathMeta: | |
359 | return |
|
359 | return | |
360 | else: |
|
360 | else: | |
361 | self.pathMeta = pathMeta |
|
361 | self.pathMeta = pathMeta | |
362 |
|
362 | |||
363 | filePointer = h5py.File(self.pathMeta,'r') |
|
363 | filePointer = h5py.File(self.pathMeta,'r') | |
364 | groupPointer = filePointer['Metadata'] |
|
364 | groupPointer = filePointer['Metadata'] | |
365 |
|
365 | |||
366 | listMetaname = [] |
|
366 | listMetaname = [] | |
367 | listMetadata = [] |
|
367 | listMetadata = [] | |
368 | for item in groupPointer.items(): |
|
368 | for item in groupPointer.items(): | |
369 | name = item[0] |
|
369 | name = item[0] | |
370 |
|
370 | |||
371 | if name=='array dimensions': |
|
371 | if name=='array dimensions': | |
372 | table = groupPointer[name][:] |
|
372 | table = groupPointer[name][:] | |
373 | listShapes = {} |
|
373 | listShapes = {} | |
374 | for shapes in table: |
|
374 | for shapes in table: | |
375 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4]]) |
|
375 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4]]) | |
376 | else: |
|
376 | else: | |
377 | data = groupPointer[name].value |
|
377 | data = groupPointer[name].value | |
378 | listMetaname.append(name) |
|
378 | listMetaname.append(name) | |
379 | listMetadata.append(data) |
|
379 | listMetadata.append(data) | |
380 |
|
380 | |||
381 | if name=='type': |
|
381 | if name=='type': | |
382 | self.__initDataOut(data) |
|
382 | self.__initDataOut(data) | |
383 |
|
383 | |||
384 | filePointer.close() |
|
384 | filePointer.close() | |
385 |
|
385 | |||
386 | self.listShapes = listShapes |
|
386 | self.listShapes = listShapes | |
387 | self.listMetaname = listMetaname |
|
387 | self.listMetaname = listMetaname | |
388 | self.listMeta = listMetadata |
|
388 | self.listMeta = listMetadata | |
389 |
|
389 | |||
390 | return |
|
390 | return | |
391 |
|
391 | |||
392 | def __readData(self): |
|
392 | def __readData(self): | |
393 | grp = self.fp['Data'] |
|
393 | grp = self.fp['Data'] | |
394 | listdataname = [] |
|
394 | listdataname = [] | |
395 | listdata = [] |
|
395 | listdata = [] | |
396 |
|
396 | |||
397 | for item in grp.items(): |
|
397 | for item in grp.items(): | |
398 | name = item[0] |
|
398 | name = item[0] | |
399 |
|
399 | |||
400 | if name == 'time': |
|
400 | if name == 'time': | |
401 | listdataname.append('utctime') |
|
401 | listdataname.append('utctime') | |
402 | timeAux = grp[name].value.astype(numpy.float)[0] |
|
402 | timeAux = grp[name].value.astype(numpy.float)[0] | |
403 | listdata.append(timeAux) |
|
403 | listdata.append(timeAux) | |
404 | continue |
|
404 | continue | |
405 |
|
405 | |||
406 | listdataname.append(name) |
|
406 | listdataname.append(name) | |
407 | array = self.__setDataArray(self.nRecords, grp[name],self.listShapes[name]) |
|
407 | array = self.__setDataArray(self.nRecords, grp[name],self.listShapes[name]) | |
408 | listdata.append(array) |
|
408 | listdata.append(array) | |
409 |
|
409 | |||
410 | self.listDataname = listdataname |
|
410 | self.listDataname = listdataname | |
411 | self.listData = listdata |
|
411 | self.listData = listdata | |
412 | return |
|
412 | return | |
413 |
|
413 | |||
414 | def __setDataArray(self, nRecords, dataset, shapes): |
|
414 | def __setDataArray(self, nRecords, dataset, shapes): | |
415 |
|
415 | |||
416 | nChannels = shapes[0] #Dimension 0 |
|
416 | nChannels = shapes[0] #Dimension 0 | |
417 |
|
417 | |||
418 | nPoints = shapes[1] #Dimension 1, number of Points or Parameters |
|
418 | nPoints = shapes[1] #Dimension 1, number of Points or Parameters | |
419 |
|
419 | |||
420 | nSamples = shapes[2] #Dimension 2, number of samples or ranges |
|
420 | nSamples = shapes[2] #Dimension 2, number of samples or ranges | |
421 |
|
421 | |||
422 | mode = shapes[3] |
|
422 | mode = shapes[3] | |
423 |
|
423 | |||
424 | # if nPoints>1: |
|
424 | # if nPoints>1: | |
425 | # arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) |
|
425 | # arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) | |
426 | # else: |
|
426 | # else: | |
427 | # arrayData = numpy.zeros((nRecords,nChannels,nSamples)) |
|
427 | # arrayData = numpy.zeros((nRecords,nChannels,nSamples)) | |
428 | # |
|
428 | # | |
429 | # chn = 'channel' |
|
429 | # chn = 'channel' | |
430 | # |
|
430 | # | |
431 | # for i in range(nChannels): |
|
431 | # for i in range(nChannels): | |
432 | # |
|
432 | # | |
433 | # data = dataset[chn + str(i)].value |
|
433 | # data = dataset[chn + str(i)].value | |
434 | # |
|
434 | # | |
435 | # if nPoints>1: |
|
435 | # if nPoints>1: | |
436 | # data = numpy.rollaxis(data,2) |
|
436 | # data = numpy.rollaxis(data,2) | |
437 | # |
|
437 | # | |
438 | # arrayData[:,i,:] = data |
|
438 | # arrayData[:,i,:] = data | |
439 |
|
439 | |||
440 | arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) |
|
440 | arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) | |
441 | doSqueeze = False |
|
441 | doSqueeze = False | |
442 | if mode == 0: |
|
442 | if mode == 0: | |
443 | strds = 'channel' |
|
443 | strds = 'channel' | |
444 | nDatas = nChannels |
|
444 | nDatas = nChannels | |
445 | newShapes = (nRecords,nPoints,nSamples) |
|
445 | newShapes = (nRecords,nPoints,nSamples) | |
446 | if nPoints == 1: |
|
446 | if nPoints == 1: | |
447 | doSqueeze = True |
|
447 | doSqueeze = True | |
448 | axisSqueeze = 2 |
|
448 | axisSqueeze = 2 | |
449 | else: |
|
449 | else: | |
450 | strds = 'param' |
|
450 | strds = 'param' | |
451 | nDatas = nPoints |
|
451 | nDatas = nPoints | |
452 | newShapes = (nRecords,nChannels,nSamples) |
|
452 | newShapes = (nRecords,nChannels,nSamples) | |
453 | if nChannels == 1: |
|
453 | if nChannels == 1: | |
454 | doSqueeze = True |
|
454 | doSqueeze = True | |
455 | axisSqueeze = 1 |
|
455 | axisSqueeze = 1 | |
456 |
|
456 | |||
457 | for i in range(nDatas): |
|
457 | for i in range(nDatas): | |
458 |
|
458 | |||
459 | data = dataset[strds + str(i)].value |
|
459 | data = dataset[strds + str(i)].value | |
460 | data = data.reshape(newShapes) |
|
460 | data = data.reshape(newShapes) | |
461 |
|
461 | |||
462 | if mode == 0: |
|
462 | if mode == 0: | |
463 | arrayData[:,i,:,:] = data |
|
463 | arrayData[:,i,:,:] = data | |
464 | else: |
|
464 | else: | |
465 | arrayData[:,:,i,:] = data |
|
465 | arrayData[:,:,i,:] = data | |
466 |
|
466 | |||
467 | if doSqueeze: |
|
467 | if doSqueeze: | |
468 | arrayData = numpy.squeeze(arrayData, axis=axisSqueeze) |
|
468 | arrayData = numpy.squeeze(arrayData, axis=axisSqueeze) | |
469 |
|
469 | |||
470 | return arrayData |
|
470 | return arrayData | |
471 |
|
471 | |||
472 | def __initDataOut(self, type): |
|
472 | def __initDataOut(self, type): | |
473 |
|
473 | |||
474 | # if type =='Parameters': |
|
474 | # if type =='Parameters': | |
475 | # self.dataOut = Parameters() |
|
475 | # self.dataOut = Parameters() | |
476 | # elif type =='Spectra': |
|
476 | # elif type =='Spectra': | |
477 | # self.dataOut = Spectra() |
|
477 | # self.dataOut = Spectra() | |
478 | # elif type =='Voltage': |
|
478 | # elif type =='Voltage': | |
479 | # self.dataOut = Voltage() |
|
479 | # self.dataOut = Voltage() | |
480 | # elif type =='Correlation': |
|
480 | # elif type =='Correlation': | |
481 | # self.dataOut = Correlation() |
|
481 | # self.dataOut = Correlation() | |
482 |
|
482 | |||
483 | return |
|
483 | return | |
484 |
|
484 | |||
485 | def __setDataOut(self): |
|
485 | def __setDataOut(self): | |
486 | listMeta = self.listMeta |
|
486 | listMeta = self.listMeta | |
487 | listMetaname = self.listMetaname |
|
487 | listMetaname = self.listMetaname | |
488 | listDataname = self.listDataname |
|
488 | listDataname = self.listDataname | |
489 | listData = self.listData |
|
489 | listData = self.listData | |
490 |
|
490 | |||
491 | blockIndex = self.blockIndex |
|
491 | blockIndex = self.blockIndex | |
492 | blockList = self.blockList |
|
492 | blockList = self.blockList | |
493 |
|
493 | |||
494 | for i in range(len(listMeta)): |
|
494 | for i in range(len(listMeta)): | |
495 | setattr(self.dataOut,listMetaname[i],listMeta[i]) |
|
495 | setattr(self.dataOut,listMetaname[i],listMeta[i]) | |
496 |
|
496 | |||
497 | for j in range(len(listData)): |
|
497 | for j in range(len(listData)): | |
498 | if listDataname[j]=='utctime': |
|
498 | if listDataname[j]=='utctime': | |
499 | # setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex]]) |
|
499 | # setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex]]) | |
500 | setattr(self.dataOut,'utctimeInit',listData[j][blockList[blockIndex]]) |
|
500 | setattr(self.dataOut,'utctimeInit',listData[j][blockList[blockIndex]]) | |
501 | continue |
|
501 | continue | |
502 |
|
502 | |||
503 | setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex],:]) |
|
503 | setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex],:]) | |
504 |
|
504 | |||
505 | return self.dataOut.data_param |
|
505 | return self.dataOut.data_param | |
506 |
|
506 | |||
507 | def getData(self): |
|
507 | def getData(self): | |
508 |
|
508 | |||
509 | # if self.flagNoMoreFiles: |
|
509 | # if self.flagNoMoreFiles: | |
510 | # self.dataOut.flagNoData = True |
|
510 | # self.dataOut.flagNoData = True | |
511 | # print 'Process finished' |
|
511 | # print 'Process finished' | |
512 | # return 0 |
|
512 | # return 0 | |
513 | # |
|
513 | # | |
514 | if self.blockIndex==self.blocksPerFile: |
|
514 | if self.blockIndex==self.blocksPerFile: | |
515 | if not( self.__setNextFileOffline() ): |
|
515 | if not( self.__setNextFileOffline() ): | |
516 | self.dataOut.flagNoData = True |
|
516 | self.dataOut.flagNoData = True | |
517 | return 0 |
|
517 | return 0 | |
518 |
|
518 | |||
519 | # |
|
519 | # | |
520 | # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
520 | # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers | |
521 | # self.dataOut.flagNoData = True |
|
521 | # self.dataOut.flagNoData = True | |
522 | # return 0 |
|
522 | # return 0 | |
523 |
|
523 | |||
524 | self.__readData() |
|
524 | self.__readData() | |
525 | self.__setDataOut() |
|
525 | self.__setDataOut() | |
526 | self.dataOut.flagNoData = False |
|
526 | self.dataOut.flagNoData = False | |
527 |
|
527 | |||
528 | self.blockIndex += 1 |
|
528 | self.blockIndex += 1 | |
529 |
|
529 | |||
530 | return |
|
530 | return | |
531 |
|
531 | |||
532 | def run(self, **kwargs): |
|
532 | def run(self, **kwargs): | |
533 |
|
533 | |||
534 | if not(self.isConfig): |
|
534 | if not(self.isConfig): | |
535 | self.setup(**kwargs) |
|
535 | self.setup(**kwargs) | |
536 | # self.setObjProperties() |
|
536 | # self.setObjProperties() | |
537 | self.isConfig = True |
|
537 | self.isConfig = True | |
538 |
|
538 | |||
539 | self.getData() |
|
539 | self.getData() | |
540 |
|
540 | |||
541 | return |
|
541 | return | |
542 |
|
542 | |||
543 | class HDF5Writer(Operation): |
|
543 | class HDF5Writer(Operation): | |
544 |
|
544 | |||
545 | ext = ".hdf5" |
|
545 | ext = ".hdf5" | |
546 |
|
546 | |||
547 | optchar = "D" |
|
547 | optchar = "D" | |
548 |
|
548 | |||
549 | metaoptchar = "M" |
|
549 | metaoptchar = "M" | |
550 |
|
550 | |||
551 | metaFile = None |
|
551 | metaFile = None | |
552 |
|
552 | |||
553 | filename = None |
|
553 | filename = None | |
554 |
|
554 | |||
555 | path = None |
|
555 | path = None | |
556 |
|
556 | |||
557 | setFile = None |
|
557 | setFile = None | |
558 |
|
558 | |||
559 | fp = None |
|
559 | fp = None | |
560 |
|
560 | |||
561 | grp = None |
|
561 | grp = None | |
562 |
|
562 | |||
563 | ds = None |
|
563 | ds = None | |
564 |
|
564 | |||
565 | firsttime = True |
|
565 | firsttime = True | |
566 |
|
566 | |||
567 | #Configurations |
|
567 | #Configurations | |
568 |
|
568 | |||
569 | blocksPerFile = None |
|
569 | blocksPerFile = None | |
570 |
|
570 | |||
571 | blockIndex = None |
|
571 | blockIndex = None | |
572 |
|
572 | |||
573 | dataOut = None |
|
573 | dataOut = None | |
574 |
|
574 | |||
575 | #Data Arrays |
|
575 | #Data Arrays | |
576 |
|
576 | |||
577 | dataList = None |
|
577 | dataList = None | |
578 |
|
578 | |||
579 | metadataList = None |
|
579 | metadataList = None | |
580 |
|
580 | |||
581 | arrayDim = None |
|
581 | arrayDim = None | |
582 |
|
582 | |||
583 | tableDim = None |
|
583 | tableDim = None | |
584 |
|
584 | |||
585 | # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')] |
|
585 | # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')] | |
586 |
|
586 | |||
587 | dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')] |
|
587 | dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')] | |
588 |
|
588 | |||
589 | mode = None |
|
589 | mode = None | |
590 |
|
590 | |||
591 | nDatas = None #Number of datasets to be stored per array |
|
591 | nDatas = None #Number of datasets to be stored per array | |
592 |
|
592 | |||
593 | nDims = None #Number Dimensions in each dataset |
|
593 | nDims = None #Number Dimensions in each dataset | |
594 |
|
594 | |||
595 | nDimsForDs = None |
|
595 | nDimsForDs = None | |
596 |
|
596 | |||
597 | def __init__(self): |
|
597 | def __init__(self): | |
598 |
|
598 | |||
599 | Operation.__init__(self) |
|
599 | Operation.__init__(self) | |
600 | self.isConfig = False |
|
600 | self.isConfig = False | |
601 | return |
|
601 | return | |
602 |
|
602 | |||
603 |
|
603 | |||
604 | def setup(self, dataOut, **kwargs): |
|
604 | def setup(self, dataOut, **kwargs): | |
605 |
|
605 | |||
606 | self.path = kwargs['path'] |
|
606 | self.path = kwargs['path'] | |
607 |
|
607 | |||
608 | if kwargs.has_key('ext'): |
|
608 | if kwargs.has_key('ext'): | |
609 | self.ext = kwargs['ext'] |
|
609 | self.ext = kwargs['ext'] | |
610 |
|
610 | |||
611 | if kwargs.has_key('blocksPerFile'): |
|
611 | if kwargs.has_key('blocksPerFile'): | |
612 | self.blocksPerFile = kwargs['blocksPerFile'] |
|
612 | self.blocksPerFile = kwargs['blocksPerFile'] | |
613 | else: |
|
613 | else: | |
614 | self.blocksPerFile = 10 |
|
614 | self.blocksPerFile = 10 | |
615 |
|
615 | |||
616 | self.metadataList = kwargs['metadataList'] |
|
616 | self.metadataList = kwargs['metadataList'] | |
617 |
|
617 | |||
618 | self.dataList = kwargs['dataList'] |
|
618 | self.dataList = kwargs['dataList'] | |
619 |
|
619 | |||
620 | self.dataOut = dataOut |
|
620 | self.dataOut = dataOut | |
621 |
|
621 | |||
622 | if kwargs.has_key('mode'): |
|
622 | if kwargs.has_key('mode'): | |
623 | mode = kwargs['mode'] |
|
623 | mode = kwargs['mode'] | |
624 |
|
624 | |||
625 | if type(mode) == int: |
|
625 | if type(mode) == int: | |
626 | mode = numpy.zeros(len(self.dataList)) + mode |
|
626 | mode = numpy.zeros(len(self.dataList)) + mode | |
627 | else: |
|
627 | else: | |
628 | mode = numpy.zeros(len(self.dataList)) |
|
628 | mode = numpy.zeros(len(self.dataList)) | |
629 |
|
629 | |||
630 | self.mode = mode |
|
630 | self.mode = mode | |
631 |
|
631 | |||
632 | arrayDim = numpy.zeros((len(self.dataList),5)) |
|
632 | arrayDim = numpy.zeros((len(self.dataList),5)) | |
633 |
|
633 | |||
634 | #Table dimensions |
|
634 | #Table dimensions | |
635 |
|
635 | |||
636 | dtype0 = self.dtype |
|
636 | dtype0 = self.dtype | |
637 |
|
637 | |||
638 | tableList = [] |
|
638 | tableList = [] | |
639 |
|
639 | |||
640 | for i in range(len(self.dataList)): |
|
640 | for i in range(len(self.dataList)): | |
641 |
|
641 | |||
642 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
642 | dataAux = getattr(self.dataOut, self.dataList[i]) | |
643 |
|
643 | |||
644 | if type(dataAux)==float or type(dataAux)==int: |
|
644 | if type(dataAux)==float or type(dataAux)==int: | |
645 | arrayDim[i,0] = 1 |
|
645 | arrayDim[i,0] = 1 | |
646 | else: |
|
646 | else: | |
647 | arrayDim0 = dataAux.shape |
|
647 | arrayDim0 = dataAux.shape | |
648 | arrayDim[i,0] = len(arrayDim0) |
|
648 | arrayDim[i,0] = len(arrayDim0) | |
649 | arrayDim[i,4] = mode[i] |
|
649 | arrayDim[i,4] = mode[i] | |
650 |
|
650 | |||
651 | if len(arrayDim0) == 3: |
|
651 | if len(arrayDim0) == 3: | |
652 | arrayDim[i,1:-1] = numpy.array(arrayDim0) |
|
652 | arrayDim[i,1:-1] = numpy.array(arrayDim0) | |
653 | elif len(arrayDim0) == 2: |
|
653 | elif len(arrayDim0) == 2: | |
654 | arrayDim[i,2:-1] = numpy.array(arrayDim0) #nHeights |
|
654 | arrayDim[i,2:-1] = numpy.array(arrayDim0) #nHeights | |
655 | elif len(arrayDim0) == 1: |
|
655 | elif len(arrayDim0) == 1: | |
656 | arrayDim[i,3] = arrayDim0 |
|
656 | arrayDim[i,3] = arrayDim0 | |
657 | elif len(arrayDim0) == 0: |
|
657 | elif len(arrayDim0) == 0: | |
658 | arrayDim[i,0] = 1 |
|
658 | arrayDim[i,0] = 1 | |
659 | arrayDim[i,3] = 1 |
|
659 | arrayDim[i,3] = 1 | |
660 |
|
660 | |||
661 | table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0) |
|
661 | table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0) | |
662 | tableList.append(table) |
|
662 | tableList.append(table) | |
663 |
|
663 | |||
664 | self.arrayDim = arrayDim |
|
664 | self.arrayDim = arrayDim | |
665 | self.tableDim = numpy.array(tableList, dtype = dtype0) |
|
665 | self.tableDim = numpy.array(tableList, dtype = dtype0) | |
666 | self.blockIndex = 0 |
|
666 | self.blockIndex = 0 | |
667 |
|
667 | |||
668 | return |
|
668 | return | |
669 |
|
669 | |||
670 | def putMetadata(self): |
|
670 | def putMetadata(self): | |
671 |
|
671 | |||
672 | fp = self.createMetadataFile() |
|
672 | fp = self.createMetadataFile() | |
673 | self.writeMetadata(fp) |
|
673 | self.writeMetadata(fp) | |
674 | fp.close() |
|
674 | fp.close() | |
675 | return |
|
675 | return | |
676 |
|
676 | |||
677 | def createMetadataFile(self): |
|
677 | def createMetadataFile(self): | |
678 | ext = self.ext |
|
678 | ext = self.ext | |
679 | path = self.path |
|
679 | path = self.path | |
680 | setFile = self.setFile |
|
680 | setFile = self.setFile | |
681 |
|
681 | |||
682 | timeTuple = time.localtime(self.dataOut.utctime) |
|
682 | timeTuple = time.localtime(self.dataOut.utctime) | |
683 |
|
683 | |||
684 | subfolder = '' |
|
684 | subfolder = '' | |
685 | fullpath = os.path.join( path, subfolder ) |
|
685 | fullpath = os.path.join( path, subfolder ) | |
686 |
|
686 | |||
687 | if not( os.path.exists(fullpath) ): |
|
687 | if not( os.path.exists(fullpath) ): | |
688 | os.mkdir(fullpath) |
|
688 | os.mkdir(fullpath) | |
689 | setFile = -1 #inicializo mi contador de seteo |
|
689 | setFile = -1 #inicializo mi contador de seteo | |
690 |
|
690 | |||
691 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
691 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
692 | fullpath = os.path.join( path, subfolder ) |
|
692 | fullpath = os.path.join( path, subfolder ) | |
693 |
|
693 | |||
694 | if not( os.path.exists(fullpath) ): |
|
694 | if not( os.path.exists(fullpath) ): | |
695 | os.mkdir(fullpath) |
|
695 | os.mkdir(fullpath) | |
696 | setFile = -1 #inicializo mi contador de seteo |
|
696 | setFile = -1 #inicializo mi contador de seteo | |
697 |
|
697 | |||
698 | else: |
|
698 | else: | |
699 | filesList = os.listdir( fullpath ) |
|
699 | filesList = os.listdir( fullpath ) | |
700 | filesList = sorted( filesList, key=str.lower ) |
|
700 | filesList = sorted( filesList, key=str.lower ) | |
701 | if len( filesList ) > 0: |
|
701 | if len( filesList ) > 0: | |
702 | filesList = [k for k in filesList if 'M' in k] |
|
702 | filesList = [k for k in filesList if 'M' in k] | |
703 | filen = filesList[-1] |
|
703 | filen = filesList[-1] | |
704 | # el filename debera tener el siguiente formato |
|
704 | # el filename debera tener el siguiente formato | |
705 | # 0 1234 567 89A BCDE (hex) |
|
705 | # 0 1234 567 89A BCDE (hex) | |
706 | # x YYYY DDD SSS .ext |
|
706 | # x YYYY DDD SSS .ext | |
707 | if isNumber( filen[8:11] ): |
|
707 | if isNumber( filen[8:11] ): | |
708 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
708 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
709 | else: |
|
709 | else: | |
710 | setFile = -1 |
|
710 | setFile = -1 | |
711 | else: |
|
711 | else: | |
712 | setFile = -1 #inicializo mi contador de seteo |
|
712 | setFile = -1 #inicializo mi contador de seteo | |
713 |
|
713 | |||
714 | setFile += 1 |
|
714 | setFile += 1 | |
715 |
|
715 | |||
716 | file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar, |
|
716 | file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar, | |
717 | timeTuple.tm_year, |
|
717 | timeTuple.tm_year, | |
718 | timeTuple.tm_yday, |
|
718 | timeTuple.tm_yday, | |
719 | setFile, |
|
719 | setFile, | |
720 | ext ) |
|
720 | ext ) | |
721 |
|
721 | |||
722 | filename = os.path.join( path, subfolder, file ) |
|
722 | filename = os.path.join( path, subfolder, file ) | |
723 | self.metaFile = file |
|
723 | self.metaFile = file | |
724 | #Setting HDF5 File |
|
724 | #Setting HDF5 File | |
725 | fp = h5py.File(filename,'w') |
|
725 | fp = h5py.File(filename,'w') | |
726 |
|
726 | |||
727 | return fp |
|
727 | return fp | |
728 |
|
728 | |||
729 | def writeMetadata(self, fp): |
|
729 | def writeMetadata(self, fp): | |
730 |
|
730 | |||
731 | grp = fp.create_group("Metadata") |
|
731 | grp = fp.create_group("Metadata") | |
732 | grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype) |
|
732 | grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype) | |
733 |
|
733 | |||
734 | for i in range(len(self.metadataList)): |
|
734 | for i in range(len(self.metadataList)): | |
735 | grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i])) |
|
735 | grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i])) | |
736 | return |
|
736 | return | |
737 |
|
737 | |||
738 | def setNextFile(self): |
|
738 | def setNextFile(self): | |
739 |
|
739 | |||
740 | ext = self.ext |
|
740 | ext = self.ext | |
741 | path = self.path |
|
741 | path = self.path | |
742 | setFile = self.setFile |
|
742 | setFile = self.setFile | |
743 | mode = self.mode |
|
743 | mode = self.mode | |
744 |
|
744 | |||
745 | timeTuple = time.localtime(self.dataOut.utctime) |
|
745 | timeTuple = time.localtime(self.dataOut.utctime) | |
746 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
746 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
747 |
|
747 | |||
748 | fullpath = os.path.join( path, subfolder ) |
|
748 | fullpath = os.path.join( path, subfolder ) | |
749 |
|
749 | |||
750 | if os.path.exists(fullpath): |
|
750 | if os.path.exists(fullpath): | |
751 | filesList = os.listdir( fullpath ) |
|
751 | filesList = os.listdir( fullpath ) | |
752 | filesList = [k for k in filesList if 'D' in k] |
|
752 | filesList = [k for k in filesList if 'D' in k] | |
753 | if len( filesList ) > 0: |
|
753 | if len( filesList ) > 0: | |
754 | filesList = sorted( filesList, key=str.lower ) |
|
754 | filesList = sorted( filesList, key=str.lower ) | |
755 | filen = filesList[-1] |
|
755 | filen = filesList[-1] | |
756 | # el filename debera tener el siguiente formato |
|
756 | # el filename debera tener el siguiente formato | |
757 | # 0 1234 567 89A BCDE (hex) |
|
757 | # 0 1234 567 89A BCDE (hex) | |
758 | # x YYYY DDD SSS .ext |
|
758 | # x YYYY DDD SSS .ext | |
759 | if isNumber( filen[8:11] ): |
|
759 | if isNumber( filen[8:11] ): | |
760 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
760 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
761 | else: |
|
761 | else: | |
762 | setFile = -1 |
|
762 | setFile = -1 | |
763 | else: |
|
763 | else: | |
764 | setFile = -1 #inicializo mi contador de seteo |
|
764 | setFile = -1 #inicializo mi contador de seteo | |
765 |
|
765 | |||
766 | setFile += 1 |
|
766 | setFile += 1 | |
767 |
|
767 | |||
768 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
768 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
769 | timeTuple.tm_year, |
|
769 | timeTuple.tm_year, | |
770 | timeTuple.tm_yday, |
|
770 | timeTuple.tm_yday, | |
771 | setFile, |
|
771 | setFile, | |
772 | ext ) |
|
772 | ext ) | |
773 |
|
773 | |||
774 | filename = os.path.join( path, subfolder, file ) |
|
774 | filename = os.path.join( path, subfolder, file ) | |
775 |
|
775 | |||
776 | #Setting HDF5 File |
|
776 | #Setting HDF5 File | |
777 | fp = h5py.File(filename,'w') |
|
777 | fp = h5py.File(filename,'w') | |
778 | grp = fp.create_group("Data") |
|
778 | grp = fp.create_group("Data") | |
779 | grp.attrs['metadata'] = self.metaFile |
|
779 | grp.attrs['metadata'] = self.metaFile | |
780 |
|
780 | |||
781 | # grp.attrs['blocksPerFile'] = 0 |
|
781 | # grp.attrs['blocksPerFile'] = 0 | |
782 |
|
782 | |||
783 | ds = [] |
|
783 | ds = [] | |
784 | data = [] |
|
784 | data = [] | |
785 | nDimsForDs = [] |
|
785 | nDimsForDs = [] | |
786 |
|
786 | |||
787 | nDatas = numpy.zeros(len(self.dataList)) |
|
787 | nDatas = numpy.zeros(len(self.dataList)) | |
788 | nDims = self.arrayDim[:,0] |
|
788 | nDims = self.arrayDim[:,0] | |
789 |
|
789 | |||
790 | nDim1 = self.arrayDim[:,2] |
|
790 | nDim1 = self.arrayDim[:,2] | |
791 | nDim0 = self.arrayDim[:,3] |
|
791 | nDim0 = self.arrayDim[:,3] | |
792 |
|
792 | |||
793 | for i in range(len(self.dataList)): |
|
793 | for i in range(len(self.dataList)): | |
794 |
|
794 | |||
795 | if nDims[i]==1: |
|
795 | if nDims[i]==1: | |
796 | # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20') |
|
796 | # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20') | |
797 | ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64) |
|
797 | ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64) | |
798 | ds.append(ds0) |
|
798 | ds.append(ds0) | |
799 | data.append([]) |
|
799 | data.append([]) | |
800 | nDimsForDs.append(nDims[i]) |
|
800 | nDimsForDs.append(nDims[i]) | |
801 | else: |
|
801 | else: | |
802 |
|
802 | |||
803 | if mode[i]==0: |
|
803 | if mode[i]==0: | |
804 | strMode = "channel" |
|
804 | strMode = "channel" | |
805 | nDatas[i] = self.arrayDim[i,1] |
|
805 | nDatas[i] = self.arrayDim[i,1] | |
806 | else: |
|
806 | else: | |
807 | strMode = "param" |
|
807 | strMode = "param" | |
808 | nDatas[i] = self.arrayDim[i,2] |
|
808 | nDatas[i] = self.arrayDim[i,2] | |
809 |
|
809 | |||
810 | if nDims[i]==2: |
|
810 | if nDims[i]==2: | |
811 | nDatas[i] = self.arrayDim[i,2] |
|
811 | nDatas[i] = self.arrayDim[i,2] | |
812 |
|
812 | |||
813 | grp0 = grp.create_group(self.dataList[i]) |
|
813 | grp0 = grp.create_group(self.dataList[i]) | |
814 |
|
814 | |||
815 | for j in range(int(nDatas[i])): |
|
815 | for j in range(int(nDatas[i])): | |
816 | tableName = strMode + str(j) |
|
816 | tableName = strMode + str(j) | |
817 |
|
817 | |||
818 | if nDims[i] == 3: |
|
818 | if nDims[i] == 3: | |
819 | ds0 = grp0.create_dataset(tableName, (nDim1[i],nDim0[i],1) , data = numpy.zeros((nDim1[i],nDim0[i],1)) ,maxshape=(None,nDim0[i],None), chunks=True) |
|
819 | ds0 = grp0.create_dataset(tableName, (nDim1[i],nDim0[i],1) , data = numpy.zeros((nDim1[i],nDim0[i],1)) ,maxshape=(None,nDim0[i],None), chunks=True) | |
820 | else: |
|
820 | else: | |
821 | ds0 = grp0.create_dataset(tableName, (1,nDim0[i]), data = numpy.zeros((1,nDim0[i])) , maxshape=(None,nDim0[i]), chunks=True) |
|
821 | ds0 = grp0.create_dataset(tableName, (1,nDim0[i]), data = numpy.zeros((1,nDim0[i])) , maxshape=(None,nDim0[i]), chunks=True) | |
822 |
|
822 | |||
823 | ds.append(ds0) |
|
823 | ds.append(ds0) | |
824 | data.append([]) |
|
824 | data.append([]) | |
825 | nDimsForDs.append(nDims[i]) |
|
825 | nDimsForDs.append(nDims[i]) | |
826 | self.nDatas = nDatas |
|
826 | self.nDatas = nDatas | |
827 | self.nDims = nDims |
|
827 | self.nDims = nDims | |
828 | self.nDimsForDs = nDimsForDs |
|
828 | self.nDimsForDs = nDimsForDs | |
829 | #Saving variables |
|
829 | #Saving variables | |
830 | print 'Writing the file: %s'%filename |
|
830 | print 'Writing the file: %s'%filename | |
831 | self.filename = filename |
|
831 | self.filename = filename | |
832 | self.fp = fp |
|
832 | self.fp = fp | |
833 | self.grp = grp |
|
833 | self.grp = grp | |
834 | self.grp.attrs.modify('nRecords', 1) |
|
834 | self.grp.attrs.modify('nRecords', 1) | |
835 | self.ds = ds |
|
835 | self.ds = ds | |
836 | self.data = data |
|
836 | self.data = data | |
837 |
|
837 | |||
838 | self.setFile = setFile |
|
838 | self.setFile = setFile | |
839 | self.firsttime = True |
|
839 | self.firsttime = True | |
840 | self.blockIndex = 0 |
|
840 | self.blockIndex = 0 | |
841 | return |
|
841 | return | |
842 |
|
842 | |||
843 | def putData(self): |
|
843 | def putData(self): | |
844 |
|
844 | |||
845 | if not self.firsttime: |
|
845 | if not self.firsttime: | |
846 | self.fp.flush() |
|
|||
847 | self.fp.close() |
|
|||
848 | self.readBlock() |
|
846 | self.readBlock() | |
849 |
|
847 | |||
850 | if self.blockIndex == self.blocksPerFile: |
|
848 | if self.blockIndex == self.blocksPerFile: | |
851 |
|
849 | |||
852 | self.setNextFile() |
|
850 | self.setNextFile() | |
853 |
|
851 | |||
854 | self.setBlock() |
|
852 | self.setBlock() | |
855 | self.writeBlock() |
|
853 | self.writeBlock() | |
856 |
|
854 | |||
|
855 | self.fp.flush() | |||
|
856 | self.fp.close() | |||
857 |
|
857 | |||
858 | return |
|
858 | return | |
859 |
|
859 | |||
860 | def readBlock(self): |
|
860 | def readBlock(self): | |
861 |
|
861 | |||
862 | ''' |
|
862 | ''' | |
863 | data Array configured |
|
863 | data Array configured | |
864 |
|
864 | |||
865 |
|
865 | |||
866 | self.data |
|
866 | self.data | |
867 | ''' |
|
867 | ''' | |
868 | ds = self.ds |
|
868 | ds = self.ds | |
869 | #Setting HDF5 File |
|
869 | #Setting HDF5 File | |
870 | fp = h5py.File(self.filename,'r+') |
|
870 | fp = h5py.File(self.filename,'r+') | |
871 | grp = fp["Data"] |
|
871 | grp = fp["Data"] | |
872 | ind = 0 |
|
872 | ind = 0 | |
873 |
|
873 | |||
874 | # grp.attrs['blocksPerFile'] = 0 |
|
874 | # grp.attrs['blocksPerFile'] = 0 | |
875 | for i in range(len(self.dataList)): |
|
875 | for i in range(len(self.dataList)): | |
876 |
|
876 | |||
877 | if self.nDims[i]==1: |
|
877 | if self.nDims[i]==1: | |
878 | ds0 = grp[self.dataList[i]] |
|
878 | ds0 = grp[self.dataList[i]] | |
879 | ds[ind] = ds0 |
|
879 | ds[ind] = ds0 | |
880 | ind += 1 |
|
880 | ind += 1 | |
881 | else: |
|
881 | else: | |
882 | if self.mode[i]==0: |
|
882 | if self.mode[i]==0: | |
883 | strMode = "channel" |
|
883 | strMode = "channel" | |
884 | else: |
|
884 | else: | |
885 | strMode = "param" |
|
885 | strMode = "param" | |
886 |
|
886 | |||
887 | grp0 = grp[self.dataList[i]] |
|
887 | grp0 = grp[self.dataList[i]] | |
888 |
|
888 | |||
889 | for j in range(int(self.nDatas[i])): |
|
889 | for j in range(int(self.nDatas[i])): | |
890 | tableName = strMode + str(j) |
|
890 | tableName = strMode + str(j) | |
891 | ds0 = grp0[tableName] |
|
891 | ds0 = grp0[tableName] | |
892 | ds[ind] = ds0 |
|
892 | ds[ind] = ds0 | |
893 | ind += 1 |
|
893 | ind += 1 | |
894 |
|
894 | |||
895 |
|
895 | |||
896 | self.fp = fp |
|
896 | self.fp = fp | |
897 | self.grp = grp |
|
897 | self.grp = grp | |
898 | self.ds = ds |
|
898 | self.ds = ds | |
899 |
|
899 | |||
900 | return |
|
900 | return | |
901 |
|
901 | |||
902 |
|
902 | |||
903 | def setBlock(self): |
|
903 | def setBlock(self): | |
904 | ''' |
|
904 | ''' | |
905 | data Array configured |
|
905 | data Array configured | |
906 |
|
906 | |||
907 |
|
907 | |||
908 | self.data |
|
908 | self.data | |
909 | ''' |
|
909 | ''' | |
910 | #Creating Arrays |
|
910 | #Creating Arrays | |
911 | data = self.data |
|
911 | data = self.data | |
912 | nDatas = self.nDatas |
|
912 | nDatas = self.nDatas | |
913 | nDims = self.nDims |
|
913 | nDims = self.nDims | |
914 | mode = self.mode |
|
914 | mode = self.mode | |
915 | ind = 0 |
|
915 | ind = 0 | |
916 |
|
916 | |||
917 | for i in range(len(self.dataList)): |
|
917 | for i in range(len(self.dataList)): | |
918 | dataAux = getattr(self.dataOut,self.dataList[i]) |
|
918 | dataAux = getattr(self.dataOut,self.dataList[i]) | |
919 |
|
919 | |||
920 | if nDims[i] == 1: |
|
920 | if nDims[i] == 1: | |
921 | # data[ind] = numpy.array([str(dataAux)]).reshape((1,1)) |
|
921 | # data[ind] = numpy.array([str(dataAux)]).reshape((1,1)) | |
922 | data[ind] = dataAux |
|
922 | data[ind] = dataAux | |
923 | # if not self.firsttime: |
|
923 | # if not self.firsttime: | |
924 | # data[ind] = numpy.hstack((self.ds[ind][:], self.data[ind])) |
|
924 | # data[ind] = numpy.hstack((self.ds[ind][:], self.data[ind])) | |
925 | ind += 1 |
|
925 | ind += 1 | |
926 | else: |
|
926 | else: | |
927 | for j in range(int(nDatas[i])): |
|
927 | for j in range(int(nDatas[i])): | |
928 | if (mode[i] == 0) or (nDims[i] == 2): #In case division per channel or Dimensions is only 1 |
|
928 | if (mode[i] == 0) or (nDims[i] == 2): #In case division per channel or Dimensions is only 1 | |
929 | data[ind] = dataAux[j,:] |
|
929 | data[ind] = dataAux[j,:] | |
930 | else: |
|
930 | else: | |
931 | data[ind] = dataAux[:,j,:] |
|
931 | data[ind] = dataAux[:,j,:] | |
932 |
|
932 | |||
933 | # if nDims[i] == 3: |
|
933 | # if nDims[i] == 3: | |
934 | # data[ind] = data[ind].reshape((data[ind].shape[0],data[ind].shape[1],1)) |
|
934 | # data[ind] = data[ind].reshape((data[ind].shape[0],data[ind].shape[1],1)) | |
935 |
|
935 | |||
936 | # if not self.firsttime: |
|
936 | # if not self.firsttime: | |
937 | # data[ind] = numpy.dstack((self.ds[ind][:], data[ind])) |
|
937 | # data[ind] = numpy.dstack((self.ds[ind][:], data[ind])) | |
938 |
|
938 | |||
939 | # else: |
|
939 | # else: | |
940 | # data[ind] = data[ind].reshape((1,data[ind].shape[0])) |
|
940 | # data[ind] = data[ind].reshape((1,data[ind].shape[0])) | |
941 |
|
941 | |||
942 | # if not self.firsttime: |
|
942 | # if not self.firsttime: | |
943 | # data[ind] = numpy.vstack((self.ds[ind][:], data[ind])) |
|
943 | # data[ind] = numpy.vstack((self.ds[ind][:], data[ind])) | |
944 | ind += 1 |
|
944 | ind += 1 | |
945 |
|
945 | |||
946 | self.data = data |
|
946 | self.data = data | |
947 | return |
|
947 | return | |
948 |
|
948 | |||
949 | def writeBlock(self): |
|
949 | def writeBlock(self): | |
950 | ''' |
|
950 | ''' | |
951 | Saves the block in the HDF5 file |
|
951 | Saves the block in the HDF5 file | |
952 | ''' |
|
952 | ''' | |
953 | for i in range(len(self.ds)): |
|
953 | for i in range(len(self.ds)): | |
954 | if self.firsttime: |
|
954 | if self.firsttime: | |
955 | # self.ds[i].resize(self.data[i].shape) |
|
955 | # self.ds[i].resize(self.data[i].shape) | |
956 | # self.ds[i][self.blockIndex,:] = self.data[i] |
|
956 | # self.ds[i][self.blockIndex,:] = self.data[i] | |
957 | if type(self.data[i]) == numpy.ndarray: |
|
957 | if type(self.data[i]) == numpy.ndarray: | |
958 | nDims1 = len(self.ds[i].shape) |
|
958 | nDims1 = len(self.ds[i].shape) | |
959 |
|
959 | |||
960 | if nDims1 == 3: |
|
960 | if nDims1 == 3: | |
961 | self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1)) |
|
961 | self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1)) | |
962 |
|
962 | |||
963 | self.ds[i].resize(self.data[i].shape) |
|
963 | self.ds[i].resize(self.data[i].shape) | |
964 | self.ds[i][:] = self.data[i] |
|
964 | self.ds[i][:] = self.data[i] | |
965 | else: |
|
965 | else: | |
966 | if self.nDimsForDs[i] == 1: |
|
966 | if self.nDimsForDs[i] == 1: | |
967 | self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1)) |
|
967 | self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1)) | |
968 | self.ds[i][0,-1] = self.data[i] |
|
968 | self.ds[i][0,-1] = self.data[i] | |
969 | elif self.nDimsForDs[i] == 2: |
|
969 | elif self.nDimsForDs[i] == 2: | |
970 | self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1])) |
|
970 | self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1])) | |
971 | self.ds[i][self.blockIndex,:] = self.data[i] |
|
971 | self.ds[i][self.blockIndex,:] = self.data[i] | |
972 | elif self.nDimsForDs[i] == 3: |
|
972 | elif self.nDimsForDs[i] == 3: | |
973 |
|
973 | |||
974 | dataShape = self.data[i].shape |
|
974 | dataShape = self.data[i].shape | |
975 | dsShape = self.ds[i].shape |
|
975 | dsShape = self.ds[i].shape | |
976 |
|
976 | |||
977 | if dataShape[0]==dsShape[0]: |
|
977 | if dataShape[0]==dsShape[0]: | |
978 | self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1)) |
|
978 | self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1)) | |
979 | self.ds[i][:,:,-1] = self.data[i] |
|
979 | self.ds[i][:,:,-1] = self.data[i] | |
980 | else: |
|
980 | else: | |
981 | self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1],self.ds[i].shape[2])) |
|
981 | self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1],self.ds[i].shape[2])) | |
982 | self.ds[i][dsShape[0]:,:,0] = self.data[i] |
|
982 | self.ds[i][dsShape[0]:,:,0] = self.data[i] | |
983 | # self.ds[i].append(self.data[i]) |
|
983 | # self.ds[i].append(self.data[i]) | |
984 | # self.fp.flush() |
|
984 | # self.fp.flush() | |
985 | # if not self.firsttime: |
|
985 | # if not self.firsttime: | |
986 | # self.fp.root.Data._v_attrs.nRecords = self.blockIndex |
|
986 | # self.fp.root.Data._v_attrs.nRecords = self.blockIndex | |
987 |
|
987 | |||
988 | # if self.firsttime: |
|
988 | # if self.firsttime: | |
989 | # self.fp.close() |
|
989 | # self.fp.close() | |
990 | # self.readBlock2() |
|
990 | # self.readBlock2() | |
991 |
|
991 | |||
992 | self.blockIndex += 1 |
|
992 | self.blockIndex += 1 | |
993 | self.firsttime = False |
|
993 | self.firsttime = False | |
994 | return |
|
994 | return | |
995 |
|
995 | |||
996 | def run(self, dataOut, **kwargs): |
|
996 | def run(self, dataOut, **kwargs): | |
997 | if not(self.isConfig): |
|
997 | if not(self.isConfig): | |
998 | self.setup(dataOut, **kwargs) |
|
998 | self.setup(dataOut, **kwargs) | |
999 | self.isConfig = True |
|
999 | self.isConfig = True | |
1000 | self.putMetadata() |
|
1000 | self.putMetadata() | |
1001 | self.setNextFile() |
|
1001 | self.setNextFile() | |
1002 |
|
1002 | |||
1003 | self.putData() |
|
1003 | self.putData() | |
1004 | return |
|
1004 | return | |
1005 |
|
1005 |
General Comments 0
You need to be logged in to leave comments.
Login now