##// END OF EJS Templates
Se corrigieron errores en VoltageProcessor.py en el metodo de plotRTI. Se agrego el metodo de plotCrossSpc al modulo SpectraProcessor.py para graficos de Espectros, Coherencia y Fase, de la misma forma se han agregado clases al modulo schainPlotTypes.
Daniel Valdez -
r156:2d289a1e62b6
parent child
Show More
@@ -1,229 +1,230
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import copy
8 import copy
9 import numpy
9 import numpy
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from IO.JROHeaderIO import SystemHeader, RadarControllerHeader
14 from IO.JROHeaderIO import SystemHeader, RadarControllerHeader
15
15
16 class JROData:
16 class JROData:
17
17
18 # m_BasicHeader = BasicHeader()
18 # m_BasicHeader = BasicHeader()
19 # m_ProcessingHeader = ProcessingHeader()
19 # m_ProcessingHeader = ProcessingHeader()
20
20
21 systemHeaderObj = SystemHeader()
21 systemHeaderObj = SystemHeader()
22
22
23 radarControllerHeaderObj = RadarControllerHeader()
23 radarControllerHeaderObj = RadarControllerHeader()
24
24
25 # data = None
25 # data = None
26
26
27 type = None
27 type = None
28
28
29 dtype = None
29 dtype = None
30
30
31 nChannels = None
31 nChannels = None
32
32
33 nHeights = None
33 nHeights = None
34
34
35 nProfiles = None
35 nProfiles = None
36
36
37 heightList = None
37 heightList = None
38
38
39 channelList = None
39 channelList = None
40
40
41 channelIndexList = None
41 channelIndexList = None
42
42
43 flagNoData = True
43 flagNoData = True
44
44
45 flagTimeBlock = False
45 flagTimeBlock = False
46
46
47 utctime = None
47 utctime = None
48
48
49 blocksize = None
49 blocksize = None
50
50
51 nCode = None
51 nCode = None
52
52
53 nBaud = None
53 nBaud = None
54
54
55 code = None
55 code = None
56
56
57 flagDecodeData = True #asumo q la data esta decodificada
57 flagDecodeData = True #asumo q la data esta decodificada
58
58
59 flagDeflipData = True #asumo q la data esta sin flip
59 flagDeflipData = True #asumo q la data esta sin flip
60
60
61 flagShiftFFT = False
61 flagShiftFFT = False
62
62
63 ippSeconds = None
63 ippSeconds = None
64
64
65 timeInterval = None
65
66
66 def __init__(self):
67 def __init__(self):
67
68
68 raise ValueError, "This class has not been implemented"
69 raise ValueError, "This class has not been implemented"
69
70
70 def copy(self, inputObj=None):
71 def copy(self, inputObj=None):
71
72
72 if inputObj == None:
73 if inputObj == None:
73 return copy.deepcopy(self)
74 return copy.deepcopy(self)
74
75
75 for key in inputObj.__dict__.keys():
76 for key in inputObj.__dict__.keys():
76 self.__dict__[key] = inputObj.__dict__[key]
77 self.__dict__[key] = inputObj.__dict__[key]
77
78
78 def deepcopy(self):
79 def deepcopy(self):
79
80
80 return copy.deepcopy(self)
81 return copy.deepcopy(self)
81
82
82 class Voltage(JROData):
83 class Voltage(JROData):
83
84
84 nCohInt = None
85 nCohInt = None
85
86
86 #data es un numpy array de 2 dmensiones (canales, alturas)
87 #data es un numpy array de 2 dmensiones (canales, alturas)
87 data = None
88 data = None
88
89
89 def __init__(self):
90 def __init__(self):
90 '''
91 '''
91 Constructor
92 Constructor
92 '''
93 '''
93
94
94 self.radarControllerHeaderObj = RadarControllerHeader()
95 self.radarControllerHeaderObj = RadarControllerHeader()
95
96
96 self.systemHeaderObj = SystemHeader()
97 self.systemHeaderObj = SystemHeader()
97
98
98 self.type = "Voltage"
99 self.type = "Voltage"
99
100
100 self.data = None
101 self.data = None
101
102
102 self.dtype = None
103 self.dtype = None
103
104
104 self.nChannels = 0
105 self.nChannels = 0
105
106
106 self.nHeights = 0
107 self.nHeights = 0
107
108
108 self.nProfiles = None
109 self.nProfiles = None
109
110
110 self.heightList = None
111 self.heightList = None
111
112
112 self.channelList = None
113 self.channelList = None
113
114
114 self.channelIndexList = None
115 self.channelIndexList = None
115
116
116 self.flagNoData = True
117 self.flagNoData = True
117
118
118 self.flagTimeBlock = False
119 self.flagTimeBlock = False
119
120
120 self.utctime = None
121 self.utctime = None
121
122
122 self.nCohInt = None
123 self.nCohInt = None
123
124
124 self.blocksize = None
125 self.blocksize = None
125
126
126 class Spectra(JROData):
127 class Spectra(JROData):
127
128
128 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
129 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
129 data_spc = None
130 data_spc = None
130
131
131 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
132 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
132 data_cspc = None
133 data_cspc = None
133
134
134 #data es un numpy array de 2 dmensiones (canales, alturas)
135 #data es un numpy array de 2 dmensiones (canales, alturas)
135 data_dc = None
136 data_dc = None
136
137
137 nFFTPoints = None
138 nFFTPoints = None
138
139
139 nPairs = None
140 nPairs = None
140
141
141 pairsList = None
142 pairsList = None
142
143
143 nIncohInt = None
144 nIncohInt = None
144
145
145 def __init__(self):
146 def __init__(self):
146 '''
147 '''
147 Constructor
148 Constructor
148 '''
149 '''
149
150
150 self.radarControllerHeaderObj = RadarControllerHeader()
151 self.radarControllerHeaderObj = RadarControllerHeader()
151
152
152 self.systemHeaderObj = SystemHeader()
153 self.systemHeaderObj = SystemHeader()
153
154
154 self.type = "Spectra"
155 self.type = "Spectra"
155
156
156 # self.data = None
157 # self.data = None
157
158
158 self.dtype = None
159 self.dtype = None
159
160
160 self.nChannels = 0
161 self.nChannels = 0
161
162
162 self.nHeights = 0
163 self.nHeights = 0
163
164
164 self.nProfiles = None
165 self.nProfiles = None
165
166
166 self.heightList = None
167 self.heightList = None
167
168
168 self.channelList = None
169 self.channelList = None
169
170
170 self.channelIndexList = None
171 self.channelIndexList = None
171
172
172 self.flagNoData = True
173 self.flagNoData = True
173
174
174 self.flagTimeBlock = False
175 self.flagTimeBlock = False
175
176
176 self.utctime = None
177 self.utctime = None
177
178
178 self.nIncohInt = None
179 self.nIncohInt = None
179
180
180 self.blocksize = None
181 self.blocksize = None
181
182
182
183
183 class SpectraHeis(JROData):
184 class SpectraHeis(JROData):
184
185
185 data_spc = None
186 data_spc = None
186
187
187 data_cspc = None
188 data_cspc = None
188
189
189 data_dc = None
190 data_dc = None
190
191
191 nFFTPoints = None
192 nFFTPoints = None
192
193
193 nPairs = None
194 nPairs = None
194
195
195 pairsList = None
196 pairsList = None
196
197
197 nIncohInt = None
198 nIncohInt = None
198
199
199 def __init__(self):
200 def __init__(self):
200
201
201 self.radarControllerHeaderObj = RadarControllerHeader()
202 self.radarControllerHeaderObj = RadarControllerHeader()
202
203
203 self.systemHeaderObj = SystemHeader()
204 self.systemHeaderObj = SystemHeader()
204
205
205 self.type = "SpectraHeis"
206 self.type = "SpectraHeis"
206
207
207 self.dtype = None
208 self.dtype = None
208
209
209 self.nChannels = 0
210 self.nChannels = 0
210
211
211 self.nHeights = 0
212 self.nHeights = 0
212
213
213 self.nProfiles = None
214 self.nProfiles = None
214
215
215 self.heightList = None
216 self.heightList = None
216
217
217 self.channelList = None
218 self.channelList = None
218
219
219 self.channelIndexList = None
220 self.channelIndexList = None
220
221
221 self.flagNoData = True
222 self.flagNoData = True
222
223
223 self.flagTimeBlock = False
224 self.flagTimeBlock = False
224
225
225 self.nPairs = 0
226 self.nPairs = 0
226
227
227 self.utctime = None
228 self.utctime = None
228
229
229 self.blocksize = None
230 self.blocksize = None
@@ -1,400 +1,391
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import time
3 import time
4 import os
4 import os
5 from schainPlotLib import Driver
5 from schainPlotLib import Driver
6
6
7 class Figure:
7 class Figure:
8
8
9 __isDriverOpen = False
9 __isDriverOpen = False
10 __isFigureOpen = False
10 __isFigureOpen = False
11 __isConfig = False
11 __isConfig = False
12
12
13 drvObj = None
13 drvObj = None
14 driver = None
14 driver = None
15 idfigure = None
15 idfigure = None
16 nframes = None
16 nframes = None
17 wintitle = None
17 wintitle = None
18 colormap = None
18 colormap = None
19 overplot = None
19 overplot = None
20 colorbar = None
20 colorbar = None
21
21
22 frameObjList = []
22 frameObjList = []
23
23
24 xw = None
24 xw = None
25 yw = None
25 yw = None
26
26
27 xmin = None
27 xmin = None
28 xmax = None
28 xmax = None
29 ymin = None
29 ymin = None
30 ymax = None
30 ymax = None
31
31
32 minvalue = None
32 minvalue = None
33 maxvalue = None
33 maxvalue = None
34 deltax = None
34 deltax = None
35 deltay = None
35 deltay = None
36
36
37
37
38 figuretitle = ""
38 figuretitle = ""
39 xrangestep = None
39 xrangestep = None
40
40
41 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args):
41 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args):
42
42
43 self.__isDriverOpen = False
43 self.__isDriverOpen = False
44 self.__isFigureOpen = False
44 self.__isFigureOpen = False
45 self.__isConfig = False
45 self.__isConfig = False
46
46
47 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
47 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
48 self.driver = driver
48 self.driver = driver
49 self.idfigure = idfigure
49 self.idfigure = idfigure
50 self.nframes = nframes
50 self.nframes = nframes
51 self.wintitle = wintitle
51 self.wintitle = wintitle
52 self.colormap = colormap
52 self.colormap = colormap
53 self.overplot = overplot
53 self.overplot = overplot
54 self.colorbar = colorbar
54 self.colorbar = colorbar
55
55
56 self.xw = xw
56 self.xw = xw
57 self.yw = yw
57 self.yw = yw
58
58
59 self.frameObjList = []
59 self.frameObjList = []
60
60
61 # self.showGraph1 = args[0]
62 # self.showGraph2 = args[1]
63
64 self.drvObj.driver.setFigure()
61 self.drvObj.driver.setFigure()
65 self.drvObj.driver.setColormap(colormap)
62 self.drvObj.driver.setColormap(colormap)
66
63
67 def __openDriver(self):
64 def __openDriver(self):
68
65
69 self.drvObj.driver.openDriver()
66 self.drvObj.driver.openDriver()
70
67
71 def __newPage(self):
68 def __newPage(self):
72
69
73
70
74 self.drvObj.driver.openPage()
71 self.drvObj.driver.openPage()
75 nrows, ncolumns = self.getSubplots()
72 nrows, ncolumns = self.getSubplots()
76 self.drvObj.driver.setFigTitle(self.figuretitle)
73 self.drvObj.driver.setFigTitle(self.figuretitle)
77 self.drvObj.driver.setSubPlots(nrows, ncolumns)
74 self.drvObj.driver.setSubPlots(nrows, ncolumns)
78
75
79 def __closePage(self):
76 def __closePage(self):
80
77
81 self.drvObj.driver.closeFigure()
78 self.drvObj.driver.closeFigure()
82
79
83 def selectFigure(self):
80 def selectFigure(self):
84
81
85 self.drvObj.driver.selectFigure()
82 self.drvObj.driver.selectFigure()
86
83
87 def __isOutOfXRange(self,x):
84 def __isOutOfXRange(self,x):
88 try:
85 try:
89 if ((x>=self.xmin) and (x<self.xmax)):
86 if ((x>=self.xmin) and (x<self.xmax)):
90 return 0
87 return 0
91 except:
88 except:
92 return 0
89 return 0
93
90
94 return 1
91 return 1
95
92
96 def changeXRange(self,x):
93 def changeXRange(self,x):
97
94
98 pass
95 pass
99
96
100 def __refresh(self):
97 def __refresh(self):
101 self.drvObj.driver.refresh()
98 self.drvObj.driver.refresh()
102
99
103 def createFrames(self):
100 def createFrames(self):
104
101
105 self.frameObjList = []
102 self.frameObjList = []
106
103
107 raise ValueError, "No implemented"
104 raise ValueError, "No implemented"
108
105
109 def save(self,filename):
106 def save(self,filename):
110
107
111 self.drvObj.driver.save(filename)
108 self.drvObj.driver.save(filename)
112
109
113 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'):
110 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'):
114
111
115 nx, ny = data1D.shape
112 nx, ny = data1D.shape
116
113
117 if channelList == None:
114 if channelList == None:
118 channelList = range(nx)
115 channelList = range(nx)
119
116
120 if x == None:
117 if x == None:
121 x = numpy.arange(data1D.size)
118 x = numpy.arange(data1D.size)
122
119
123 if figuretitle == None:
120 if figuretitle == None:
124 self.figuretitle = ""
121 self.figuretitle = ""
125 else:
122 else:
126 self.figuretitle = figuretitle
123 self.figuretitle = figuretitle
127
124
128 if not(self.__isDriverOpen):
125 if not(self.__isDriverOpen):
129 self.__openDriver()
126 self.__openDriver()
130 self.__isDriverOpen = True
127 self.__isDriverOpen = True
131
128
132 if not(self.__isConfig):
129 if not(self.__isConfig):
133 self.xmin = xmin
130 self.xmin = xmin
134 self.xmax = xmax
131 self.xmax = xmax
135 self.minvalue = minvalue
132 self.minvalue = minvalue
136 self.maxvalue = maxvalue
133 self.maxvalue = maxvalue
137
134
138 if self.xmin == None: self.xmin = numpy.min(x)
135 if self.xmin == None: self.xmin = numpy.min(x)
139 if self.xmax == None: self.xmax = numpy.max(x)
136 if self.xmax == None: self.xmax = numpy.max(x)
140 if self.minvalue == None: self.minvalue = numpy.min(data1D)
137 if self.minvalue == None: self.minvalue = numpy.min(data1D)
141 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
138 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
142
139
143 self.createFrames()
140 self.createFrames()
144 self.__isConfig = True
141 self.__isConfig = True
145
142
146 if not(self.__isOutOfXRange(x)):
143
147 self.changeXRange(x)
148
149 if self.__isFigureOpen:
150 self.drvObj.driver.closePage()
151 self.__isFigureOpen = False
152
144
153 self.selectFigure()
145 self.selectFigure()
154 self.__newPage()
146 self.__newPage()
155
147
148
156 for channel in channelList:
149 for channel in channelList:
157 frameObj = self.frameObjList[channel]
150 frameObj = self.frameObjList[channel]
158 frameObj.init(xmin=self.xmin,
151 frameObj.init(xmin=self.xmin,
159 xmax=self.xmax,
152 xmax=self.xmax,
160 ymin=self.minvalue,
153 ymin=self.minvalue,
161 ymax=self.maxvalue,
154 ymax=self.maxvalue,
162 minvalue=self.minvalue,
155 minvalue=self.minvalue,
163 maxvalue=self.maxvalue)
156 maxvalue=self.maxvalue)
164
157
165 for channel in channelList:
158 for channel in channelList:
166 dataCh = data1D[channel,:]
159 dataCh = data1D[channel,:]
167 frameObj = self.frameObjList[channel]
160 frameObj = self.frameObjList[channel]
168 # frameObj.clearData()
169 frameObj.plot(x, dataCh)
161 frameObj.plot(x, dataCh)
170
162
171 # frameObj.refresh()
172 self.__refresh()
163 self.__refresh()
173
164
165
174 if save:
166 if save:
175 # self.colorplotObj.setFigure(indexPlot)
176
177 path = gpath
167 path = gpath
178 now = datetime.datetime.now()
168 now = datetime.datetime.now()
179 file = "scope_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
169 file = "scope_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
180 filename = os.path.join(path,file)
170 filename = os.path.join(path,file)
181 self.save(filename)
171 self.save(filename)
182
172
183 self.__closePage()
173 self.__closePage()
184
174
185
175
186 def plotPcolor(self,data,
176 def plotPcolor(self,data,
187 x=None,
177 x=None,
188 y=None,
178 y=None,
189 channelList=None,
179 channelList=None,
190 xmin=None,
180 xmin=None,
191 xmax=None,
181 xmax=None,
192 ymin=None,
182 ymin=None,
193 ymax=None,
183 ymax=None,
194 minvalue=None,
184 minvalue=None,
195 maxvalue=None,
185 maxvalue=None,
196 figuretitle=None,
186 figuretitle=None,
197 xrangestep=None,
187 xrangestep=None,
198 deltax=None,
188 deltax=None,
199 save=False,
189 save=False,
200 gpath='./',
190 gpath='./',
201 clearData=False,
191 cleardata=False,
202 *args):
192 *args):
203
193
204
194
205 if figuretitle == None:
195 if figuretitle == None:
206 self.figuretitle = ""
196 self.figuretitle = ""
207 else:
197 else:
208 self.figuretitle = figuretitle
198 self.figuretitle = figuretitle
209
199
210
200
211 if not(self.__isDriverOpen):
201 if not(self.__isDriverOpen):
212 self.__openDriver()
202 self.__openDriver()
213 self.__isDriverOpen = True
203 self.__isDriverOpen = True
214
204
215 if not(self.__isConfig):
205 if not(self.__isConfig):
216
206
217 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax)
207 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax)
218
208
219 self.createFrames()
209 self.createFrames()
220 self.__isConfig = True
210 self.__isConfig = True
221
211
222 if (self.__isOutOfXRange(x)):
212 if (self.__isOutOfXRange(x)):
223
213
224 if not(self.changeXRange(x)):
214 if not(self.changeXRange(x)):
225 return 0
215 return 0
226
216
227 self.__closePage()
217 self.__closePage()
218 self.__isFigureOpen = False
228
219
229 self.selectFigure()
220 self.selectFigure()
230
221
231 if not(self.__isFigureOpen):
222 if not(self.__isFigureOpen):
232 self.__newPage()
223 self.__newPage()
233 self.__isFigureOpen = True
224 self.__isFigureOpen = True
234
225
235 for channel in channelList:
226 for channel in channelList:
236 if len(args) != 0: value = args[0][channel]
227 if len(args) != 0: value = args[0][channel]
237 else: value = args
228 else: value = args
238
229
239 frameObj = self.frameObjList[channel]
230 frameObj = self.frameObjList[channel]
240 frameObj.init(self.xmin,
231 frameObj.init(self.xmin,
241 self.xmax,
232 self.xmax,
242 self.ymin,
233 self.ymin,
243 self.ymax,
234 self.ymax,
244 self.minvalue,
235 self.minvalue,
245 self.maxvalue,
236 self.maxvalue,
246 self.deltax,
237 self.deltax,
247 self.deltay,
238 self.deltay,
248 self.colorbar,
239 self.colorbar,
249 value)
240 value)
250
241
251
242
252 for channel in channelList:
243 for channel in channelList:
253 dataCh = data[channel,:]
244 dataCh = data[channel,:]
254 frameObj = self.frameObjList[channel]
245 frameObj = self.frameObjList[channel]
255 frameObj.plot(x, y, dataCh)
246 frameObj.plot(x, y, dataCh)
256
247
257
248
258 self.__refresh()
249 self.__refresh()
259 if clearData == True:
250 if cleardata == True:
260 self.__closePage()
251 self.__closePage()
261 self.__isFigureOpen = False
252 self.__isFigureOpen = False
262
253
263
254
264
255
265
256
266 class Frame:
257 class Frame:
267
258
268 drvObj = None
259 drvObj = None
269 idFrame = None
260 idFrame = None
270 nplots = None
261 nplots = None
271 plotObjList = []
262 plotObjList = []
272 title = ""
263 title = ""
273
264
274 def __init__(self,drvObj, idframe):
265 def __init__(self,drvObj, idframe):
275
266
276 self.drvObj = drvObj
267 self.drvObj = drvObj
277 self.idframe = idframe
268 self.idframe = idframe
278 nplots = None
269 nplots = None
279 self.plotObjList = []
270 self.plotObjList = []
280
271
281 self.createPlots()
272 self.createPlots()
282
273
283 def createPlots(self):
274 def createPlots(self):
284 raise ValueError, "No implemented"
275 raise ValueError, "No implemented"
285
276
286 def getScreenPosMainPlot(self):
277 def getScreenPosMainPlot(self):
287 raise ValueError, "No implemented"
278 raise ValueError, "No implemented"
288
279
289 def getScreenPosGraph1(self):
280 def getScreenPosGraph1(self):
290 raise ValueError, "No implemented"
281 raise ValueError, "No implemented"
291
282
292 def getScreenPos(self, nplot):
283 def getScreenPos(self, nplot):
293
284
294 if nplot == 0:
285 if nplot == 0:
295 xi, yi, xw, yw = self.getScreenPosMainPlot()
286 xi, yi, xw, yw = self.getScreenPosMainPlot()
296
287
297 if nplot == 1:
288 if nplot == 1:
298 xi, yi, xw, yw = self.getScreenPosGraph1()
289 xi, yi, xw, yw = self.getScreenPosGraph1()
299
290
300 return xi, yi, xw, yw
291 return xi, yi, xw, yw
301
292
302
293
303 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
294 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
304
295
305 for plotObj in self.plotObjList:
296 for plotObj in self.plotObjList:
306 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
297 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
307 plotObj.plotBox()
298 plotObj.plotBox()
308
299
309
300
310
301
311 class Plot:
302 class Plot:
312
303
313 drvObj = None
304 drvObj = None
314 idframe = None
305 idframe = None
315 idplot = None
306 idplot = None
316 xi = None
307 xi = None
317 yi = None
308 yi = None
318 xw = None
309 xw = None
319 yw = None
310 yw = None
320
311
321 title = ""
312 title = ""
322 xlabel = ""
313 xlabel = ""
323 ylabel = ""
314 ylabel = ""
324 xaxisastime = None
315 xaxisastime = None
325 timefmt = None
316 timefmt = None
326 xopt = ""
317 xopt = ""
327 yopt = ""
318 yopt = ""
328 xpos = None
319 xpos = None
329 ypos = None
320 ypos = None
330 szchar = None
321 szchar = None
331 idframe = None
322 idframe = None
332 idplot = None
323 idplot = None
333 colorbar = None
324 colorbar = None
334 cbxpos = None
325 cbxpos = None
335 cbypos = None
326 cbypos = None
336
327
337 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
328 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
338
329
339 self.drvObj = drvObj
330 self.drvObj = drvObj
340 self.idframe = idframe
331 self.idframe = idframe
341 self.idplot = idplot
332 self.idplot = idplot
342 self.xi = xi
333 self.xi = xi
343 self.yi = yi
334 self.yi = yi
344 self.xw = xw
335 self.xw = xw
345 self.yw = yw
336 self.yw = yw
346
337
347
338
348 def plotBox(self):
339 def plotBox(self):
349
340
350 self.drvObj.driver.plotBox(self.idframe,
341 self.drvObj.driver.plotBox(self.idframe,
351 self.xpos,
342 self.xpos,
352 self.ypos,
343 self.ypos,
353 self.xmin,
344 self.xmin,
354 self.xmax,
345 self.xmax,
355 self.ymin,
346 self.ymin,
356 self.ymax,
347 self.ymax,
357 self.minvalue,
348 self.minvalue,
358 self.maxvalue,
349 self.maxvalue,
359 self.xopt,
350 self.xopt,
360 self.yopt,
351 self.yopt,
361 self.szchar,
352 self.szchar,
362 self.xaxisastime,
353 self.xaxisastime,
363 self.timefmt)
354 self.timefmt)
364
355
365 self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title)
356 self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title)
366
357
367 if self.colorbar:
358 if self.colorbar:
368 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
359 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
369
360
370 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
361 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
371
362
372 self.drvObj.driver.pcolor(self.idframe,
363 self.drvObj.driver.pcolor(self.idframe,
373 self.xpos,
364 self.xpos,
374 self.ypos,
365 self.ypos,
375 z,
366 z,
376 x,
367 x,
377 y,
368 y,
378 self.xmin,
369 self.xmin,
379 self.xmax,
370 self.xmax,
380 self.ymin,
371 self.ymin,
381 self.ymax,
372 self.ymax,
382 self.minvalue,
373 self.minvalue,
383 self.maxvalue,
374 self.maxvalue,
384 deltax,
375 deltax,
385 deltay,
376 deltay,
386 getGrid,
377 getGrid,
387 self.xaxisastime,
378 self.xaxisastime,
388 self.timefmt)
379 self.timefmt)
389
380
390 def plotBasicLine(self,x, y, color):
381 def plotBasicLine(self,x, y, color):
391 """
382 """
392 Inputs:
383 Inputs:
393 x:
384 x:
394
385
395 y:
386 y:
396
387
397 color:
388 color:
398 """
389 """
399 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
390 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
400 No newline at end of file
391
@@ -1,530 +1,665
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import time
3 import time
4 from schainPlot import *
4 from schainPlot import *
5
5
6 class CrossSpc(Figure):
7 overplot = 0
8 xw = 900
9 yw = 650
10 showprofile = False
11 signalA = None
12 signalB = None
13 coherence = None
14 phase = None
15
16 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
17 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
18
19 self.showprofile = showprofile
20 self.signalA = None
21 self.signalB = None
22 self.coherence = None
23 self.phase = None
24
25 def getSubplots(self):
26 nrows = self.nframes
27 ncolumns = 1
28 return nrows, ncolumns
29
30 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
31
32 if xmin == None: xmin = numpy.min(x)
33 if xmax == None: xmax = numpy.max(x)
34 if ymin == None: ymin = numpy.min(y)
35 if ymax == None: ymax = numpy.max(y)
36 if minvalue == None: minvalue = 20.
37 if maxvalue == None: maxvalue = 90.
38
39 self.signalA = self.data[0]
40 self.signalB = self.data[1]
41 self.coherence = self.data[2]
42 self.phase = self.data[3]
43
44 self.xmin = xmin
45 self.xmax = xmax
46 self.minrange = ymin
47 self.maxrange = ymax
48 self.ymin = ymin
49 self.ymax = ymax
50 self.minvalue = minvalue
51 self.maxvalue = maxvalue
52
53 def changeXRange(self, *args):
54 pass
55
56 def createFrames(self):
57 self.frameObjList = []
58
59 for frame in range(self.nframes):
60 frameObj = CrossSpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
61 self.frameObjList.append(frameObj)
62
63
64 class CrossSpcFrame(Frame):
65 def __init__(self):
66 self.drvObj = drvObj
67 self.idframe = idframe
68 self.nplots = 4
69
70 if showprofile:
71 self.nplots += 4
72
73 self.colorbar = colorbar
74 self.showprofile = showprofile
75 self.createPlots()
76
77 def createPlots(self):
78 plotObjList = []
79 idplot = 0
80 counter_plot = 0
81 for i in range(self.nplots):
82 xi, yi, xw, yw = self.getScreenPos(idplot)
83 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
84 plotObjList.append(plotObj)
85
86 if self.showprofile:
87 xi, yi, xw, yw = self.getScreenPos(idplot)
88 type = "pwbox"
89 title = ""
90 xlabel = "dB"
91 ylabel = ""
92 idplot += 1
93 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
94 plotObjList.append(plotObj)
95 idplot += 1
96
97 self.plotObjList = plotObjList
98
99 def getScreenPos(self,idplot):
100 pass
101
102 def getScreenPosMainPlot(self):
103 xi = 0.15
104
105 if self.showprofile:
106 xw = 0.55
107
108 else:
109 xw = 0.65
110
111 if self.colorbar:
112 xw = xw - 0.06
113
114 yi = 0.20; yw = 0.75
115
116 return xi, yi, xw, yw
117
118 def getScreenPosGraph1(self):
119 if self.colorbar:
120 xi = 0.65 + 0.08
121 else:
122 xi = 0.75 + 0.05
123
124 xw = xi + 0.2
125
126 yi = 0.2; yw = 0.75
127
128 return xi, yi, xw, yw
129
130 def plot(self,x, y, data):
131 plotObj = self.plotObjList[0]
132 plotObj.plot(x,y,data)
133
134 if self.showprofile:
135 plotObj = self.plotObjList[1]
136 avg_data = numpy.average(data, axis=0)
137 plotObj.plot(avg_data,y)
138
139
6 class SpcFigure(Figure):
140 class SpcFigure(Figure):
7 overplot = 0
141 overplot = 0
8 xw = 800
142 xw = 900
9 yw = 650
143 yw = 650
10 showprofile = False
144 showprofile = False
11
145
12 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
146 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
13 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
147 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
14
148
15 self.showprofile = showprofile
149 self.showprofile = showprofile
16
150
17 def getSubplots(self):
151 def getSubplots(self):
18 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
152 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
19 nrows = int(self.nframes*1./ncolumns + 0.9)
153 nrows = int(self.nframes*1./ncolumns + 0.9)
20
154
21 return nrows, ncolumns
155 return nrows, ncolumns
22
156
23 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
157 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
24
158
25 if xmin == None: xmin = numpy.min(x)
159 if xmin == None: xmin = numpy.min(x)
26 if xmax == None: xmax = numpy.max(x)
160 if xmax == None: xmax = numpy.max(x)
27 if ymin == None: ymin = numpy.min(y)
161 if ymin == None: ymin = numpy.min(y)
28 if ymax == None: ymax = numpy.max(y)
162 if ymax == None: ymax = numpy.max(y)
29 if minvalue == None: minvalue = 20.
163 if minvalue == None: minvalue = 20.
30 if maxvalue == None: maxvalue = 90.
164 if maxvalue == None: maxvalue = 90.
31
165
32 self.xmin = xmin
166 self.xmin = xmin
33 self.xmax = xmax
167 self.xmax = xmax
34 self.minrange = ymin
168 self.minrange = ymin
35 self.maxrange = ymax
169 self.maxrange = ymax
36 self.ymin = ymin
170 self.ymin = ymin
37 self.ymax = ymax
171 self.ymax = ymax
38 self.minvalue = minvalue
172 self.minvalue = minvalue
39 self.maxvalue = maxvalue
173 self.maxvalue = maxvalue
40
174
41
175
42 def changeXRange(self, *args):
176 def changeXRange(self, *args):
43 pass
177 pass
44
178
45 def createFrames(self):
179 def createFrames(self):
46
180
47 self.frameObjList = []
181 self.frameObjList = []
48
182
49 for frame in range(self.nframes):
183 for frame in range(self.nframes):
50 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
184 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
51 self.frameObjList.append(frameObj)
185 self.frameObjList.append(frameObj)
52
186
53 class SpcFrame(Frame):
187 class SpcFrame(Frame):
54 def __init__(self,drvObj,idframe,colorbar,showprofile):
188 def __init__(self,drvObj,idframe,colorbar,showprofile):
55 self.drvObj = drvObj
189 self.drvObj = drvObj
56 self.idframe = idframe
190 self.idframe = idframe
57 self.nplots = 1
191 self.nplots = 1
58
192
59 if showprofile:
193 if showprofile:
60 self.nplots += 1
194 self.nplots += 1
61
195
62 self.colorbar = colorbar
196 self.colorbar = colorbar
63 self.showprofile = showprofile
197 self.showprofile = showprofile
64 self.createPlots()
198 self.createPlots()
65
199
66 def createPlots(self):
200 def createPlots(self):
67 plotObjList = []
201 plotObjList = []
68 idplot = 0
202 idplot = 0
69 xi, yi, xw, yw = self.getScreenPos(idplot)
203 xi, yi, xw, yw = self.getScreenPos(idplot)
70 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
204 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
71 plotObjList.append(plotObj)
205 plotObjList.append(plotObj)
72
206
73 if self.showprofile:
207 if self.showprofile:
74 idplot = 1
208 idplot = 1
75 xi, yi, xw, yw = self.getScreenPos(idplot)
209 xi, yi, xw, yw = self.getScreenPos(idplot)
76 type = "pwbox"
210 type = "pwbox"
77 title = ""
211 title = ""
78 xlabel = "dB"
212 xlabel = "dB"
79 ylabel = ""
213 ylabel = ""
80 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
214 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
81 plotObjList.append(plotObj)
215 plotObjList.append(plotObj)
82
216
83 self.plotObjList = plotObjList
217 self.plotObjList = plotObjList
84
218
85 def getScreenPosMainPlot(self):
219 def getScreenPosMainPlot(self):
86 xi = 0.15
220 xi = 0.15
87
221
88 if self.showprofile:
222 if self.showprofile:
89 xw = 0.65
223 xw = 0.55
90
224
91 else:
225 else:
92 xw = 0.75
226 xw = 0.65
93
227
94 if self.colorbar:
228 if self.colorbar:
95 xw = xw - 0.06
229 xw = xw - 0.06
96
230
97 yi = 0.20; yw = 0.75
231 yi = 0.20; yw = 0.75
98
232
99 return xi, yi, xw, yw
233 return xi, yi, xw, yw
100
234
101 def getScreenPosGraph1(self):
235 def getScreenPosGraph1(self):
102 if self.colorbar:
236 if self.colorbar:
103 xi = 0.65 + 0.08
237 xi = 0.65 + 0.08
104 else:
238 else:
105 xi = 0.75 + 0.05
239 xi = 0.75 + 0.05
106
240
107 xw = xi + 0.2
241 xw = xi + 0.2
108
242
109 yi = 0.2; yw = 0.75
243 yi = 0.2; yw = 0.75
110
244
111 return xi, yi, xw, yw
245 return xi, yi, xw, yw
112
246
113 def plot(self,x, y, data):
247 def plot(self,x, y, data):
114 plotObj = self.plotObjList[0]
248 plotObj = self.plotObjList[0]
115 plotObj.plot(x,y,data)
249 plotObj.plot(x,y,data)
116
250
117 if self.showprofile:
251 if self.showprofile:
118 plotObj = self.plotObjList[1]
252 plotObj = self.plotObjList[1]
119 plotObj.plot(data,y)
253 avg_data = numpy.average(data, axis=0)
254 plotObj.plot(avg_data,y)
120
255
121 class SpcPlot(Plot):
256 class SpcPlot(Plot):
122
257
123 getGrid = True
258 getGrid = True
124
259
125 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
260 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
126 self.drvObj = drvObj
261 self.drvObj = drvObj
127 self.idframe = idframe
262 self.idframe = idframe
128 self.idplot = idplot
263 self.idplot = idplot
129 self.xi = xi
264 self.xi = xi
130 self.yi = yi
265 self.yi = yi
131 self.xw = xw
266 self.xw = xw
132 self.yw = yw
267 self.yw = yw
133 self.colorbar = colorbar
268 self.colorbar = colorbar
134
269
135 if self.colorbar:
270 if self.colorbar:
136 cbxi = xw + 0.03
271 cbxi = xw + 0.03
137 cbxw = cbxi + 0.03
272 cbxw = cbxi + 0.03
138 cbyi = yi
273 cbyi = yi
139 cbyw = yw
274 cbyw = yw
140 self.cbxpos = [cbxi,cbxw]
275 self.cbxpos = [cbxi,cbxw]
141 self.cbypos = [cbyi,cbyw]
276 self.cbypos = [cbyi,cbyw]
142
277
143 self.xpos = [self.xi,self.xw]
278 self.xpos = [self.xi,self.xw]
144 self.ypos = [self.yi,self.yw]
279 self.ypos = [self.yi,self.yw]
145 self.xaxisastime = False
280 self.xaxisastime = False
146 self.timefmt = None
281 self.timefmt = None
147 self.xopt = "bcnst"
282 self.xopt = "bcnst"
148 self.yopt = "bcnstv"
283 self.yopt = "bcnstv"
149
284
150 self.szchar = 0.8
285 self.szchar = 0.7
151 self.strforchannel = "Channel %d"%self.idframe
286 self.strforchannel = "Channel %d"%self.idframe
152 self.xlabel = "m/s"
287 self.xlabel = "m/s"
153 self.ylabel = "Range (Km)"
288 self.ylabel = "Range (Km)"
154
289
155 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
290 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
156 self.xmin = xmin
291 self.xmin = xmin
157 self.xmax = xmax
292 self.xmax = xmax
158 self.ymin = ymin
293 self.ymin = ymin
159 self.ymax = ymax
294 self.ymax = ymax
160 self.minvalue = minvalue
295 self.minvalue = minvalue
161 self.maxvalue = maxvalue
296 self.maxvalue = maxvalue
162 self.colorbar = args[2]
297 self.colorbar = args[2]
163 self.title = "%s - %s"%(self.strforchannel,args[3])
298 self.title = "%s - %s"%(self.strforchannel,args[3])
164
299
165
300
166
301
167 def plot(self, x, y, data):
302 def plot(self, x, y, data):
168 z = data
303 z = data
169 deltax = None
304 deltax = None
170 deltay = None
305 deltay = None
171 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
306 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
172 self.getGrid = False
307 self.getGrid = False
173
308
174
309
175 class RTIFigure(Figure):
310 class RTIFigure(Figure):
176 overplot = 1
311 overplot = 1
177 xw = 700
312 xw = 700
178 yw = 650
313 yw = 650
179 showprofile = False
314 showprofile = False
180 starttime = None
315 starttime = None
181 endtime = None
316 endtime = None
182 minrange = None
317 minrange = None
183 maxrange = None
318 maxrange = None
184 minvalue = None
319 minvalue = None
185 maxvalue = None
320 maxvalue = None
186 xrangestepinsecs = None
321 xrangestepinsecs = None
187
322
188
323
189 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
324 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
190 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
325 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
191
326
192 self.showprofile = showprofile
327 self.showprofile = showprofile
193
328
194 def getSubplots(self):
329 def getSubplots(self):
195 nrows = self.nframes
330 nrows = self.nframes
196 ncolumns = 1
331 ncolumns = 1
197 return nrows, ncolumns
332 return nrows, ncolumns
198
333
199 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep, deltax):
334 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep, deltax):
200
335
201 self.starttime = xmin
336 self.starttime = xmin
202 self.endtime = xmax
337 self.endtime = xmax
203
338
204 cdatetime = datetime.datetime.utcfromtimestamp(x)
339 cdatetime = datetime.datetime.utcfromtimestamp(x)
205
340
206 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
341 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
207 if ((xrangestep == 0) or (xrangestep == None)):
342 if ((xrangestep == 0) or (xrangestep == None)):
208 maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second)
343 maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second)
209 self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple())
344 self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple())
210 npoints = 1000.
345 npoints = 1000.
211 if xrangestep == 1:
346 if xrangestep == 1:
212 maxdatetime = mindatetime + datetime.timedelta(hours=1)
347 maxdatetime = mindatetime + datetime.timedelta(hours=1)
213 self.xrangestepinsecs = 60*60.
348 self.xrangestepinsecs = 60*60.
214 npoints = 500.
349 npoints = 500.
215 if xrangestep == 2:
350 if xrangestep == 2:
216 maxdatetime = mindatetime + datetime.timedelta(minutes=1)
351 maxdatetime = mindatetime + datetime.timedelta(minutes=1)
217 self.xrangestepinsecs = 60.
352 self.xrangestepinsecs = 60.
218 npoints = 250.
353 npoints = 250.
219 if xrangestep == 3:
354 if xrangestep == 3:
220 maxdatetime = mindatetime + datetime.timedelta(seconds=1)
355 maxdatetime = mindatetime + datetime.timedelta(seconds=1)
221 self.xrangestepinsecs = 1.
356 self.xrangestepinsecs = 1.
222 npoints = 125.
357 npoints = 125.
223
358
224 xmin = time.mktime(mindatetime.timetuple())
359 xmin = time.mktime(mindatetime.timetuple())
225 xmax = time.mktime(maxdatetime.timetuple())
360 xmax = time.mktime(maxdatetime.timetuple())
226
361
227 deltax1 = (xmax-xmin) / npoints
362 deltax1 = (xmax-xmin) / npoints
228 # deltax = timeInterval
363 # deltax = timeInterval
229
364
230
365
231 if ymin == None: ymin = numpy.min(y)
366 if ymin == None: ymin = numpy.min(y)
232 if ymax == None: ymax = numpy.max(y)
367 if ymax == None: ymax = numpy.max(y)
233
368
234 if minvalue == None: minvalue = 0.
369 if minvalue == None: minvalue = 0.
235 if maxvalue == None: maxvalue = 50.
370 if maxvalue == None: maxvalue = 50.
236
371
237 self.xmin = xmin
372 self.xmin = xmin
238 self.xmax = xmax
373 self.xmax = xmax
239 self.minrange = ymin
374 self.minrange = ymin
240 self.maxrange = ymax
375 self.maxrange = ymax
241 self.ymin = ymin
376 self.ymin = ymin
242 self.ymax = ymax
377 self.ymax = ymax
243 self.minvalue = minvalue
378 self.minvalue = minvalue
244 self.maxvalue = maxvalue
379 self.maxvalue = maxvalue
245 self.xrangestep = xrangestep
380 self.xrangestep = xrangestep
246 self.deltax = deltax
381 self.deltax = deltax
247
382
248 def changeXRange(self,x):
383 def changeXRange(self,x):
249
384
250 cdatetime = datetime.datetime.utcfromtimestamp(x)
385 cdatetime = datetime.datetime.utcfromtimestamp(x)
251
386
252 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
387 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
253 if self.xrangestep == 1:
388 if self.xrangestep == 1:
254 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second)
389 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second)
255
390
256 if self.xrangestep == 2:
391 if self.xrangestep == 2:
257 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second)
392 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second)
258
393
259 if self.xrangestep == 3:
394 if self.xrangestep == 3:
260 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
395 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
261
396
262 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
397 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
263 self.xmax = self.xmin + self.xrangestepinsecs
398 self.xmax = self.xmin + self.xrangestepinsecs
264
399
265 self.figuretitle = "%s %s : %s"%(self.figuretitle,
400 self.figuretitle = "%s %s : %s"%(self.figuretitle,
266 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
401 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
267 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
402 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
268 return 1
403 return 1
269
404
270 return 0
405 return 0
271
406
272 def createFrames(self):
407 def createFrames(self):
273
408
274 self.frameObjList = []
409 self.frameObjList = []
275
410
276 for frame in range(self.nframes):
411 for frame in range(self.nframes):
277 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
412 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
278 self.frameObjList.append(frameObj)
413 self.frameObjList.append(frameObj)
279
414
280 class RTIFrame(Frame):
415 class RTIFrame(Frame):
281 def __init__(self,drvObj,idframe,colorbar,showprofile):
416 def __init__(self,drvObj,idframe,colorbar,showprofile):
282 self.drvObj = drvObj
417 self.drvObj = drvObj
283 self.idframe = idframe
418 self.idframe = idframe
284 self.nplots = 1
419 self.nplots = 1
285
420
286 if showprofile:
421 if showprofile:
287 self.nplots += 1
422 self.nplots += 1
288
423
289 self.colorbar = colorbar
424 self.colorbar = colorbar
290 self.showprofile = showprofile
425 self.showprofile = showprofile
291 self.createPlots()
426 self.createPlots()
292
427
293 def createPlots(self):
428 def createPlots(self):
294 plotObjList = []
429 plotObjList = []
295
430
296 idplot = 0
431 idplot = 0
297 xi, yi, xw, yw = self.getScreenPos(idplot)
432 xi, yi, xw, yw = self.getScreenPos(idplot)
298
433
299 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
434 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
300 plotObjList.append(plotObj)
435 plotObjList.append(plotObj)
301
436
302 if self.showprofile:
437 if self.showprofile:
303 idplot = 1
438 idplot = 1
304 xi, yi, xw, yw = self.getScreenPos(idplot)
439 xi, yi, xw, yw = self.getScreenPos(idplot)
305 type = "pwbox"
440 type = "pwbox"
306 title = ""
441 title = ""
307 xlabel = "dB"
442 xlabel = "dB"
308 ylabel = ""
443 ylabel = ""
309 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
444 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
310 plotObjList.append(plotObj)
445 plotObjList.append(plotObj)
311
446
312 self.plotObjList = plotObjList
447 self.plotObjList = plotObjList
313
448
314 def getScreenPosMainPlot(self):
449 def getScreenPosMainPlot(self):
315 xi = 0.07
450 xi = 0.07
316 if self.showprofile:
451 if self.showprofile:
317 xw = 0.65
452 xw = 0.65
318 else:
453 else:
319 xw = 0.9
454 xw = 0.9
320
455
321 if self.colorbar:
456 if self.colorbar:
322 xw = xw - 0.06
457 xw = xw - 0.06
323
458
324 yi = 0.20; yw = 0.75
459 yi = 0.20; yw = 0.75
325
460
326 return xi, yi, xw, yw
461 return xi, yi, xw, yw
327
462
328 def getScreenPosGraph1(self):
463 def getScreenPosGraph1(self):
329 if self.colorbar:
464 if self.colorbar:
330 xi = 0.65 + 0.08
465 xi = 0.65 + 0.08
331 else:
466 else:
332 xi = 0.9 + 0.05
467 xi = 0.9 + 0.05
333
468
334 xw = xi + 0.2
469 xw = xi + 0.2
335
470
336 yi = 0.2; yw = 0.75
471 yi = 0.2; yw = 0.75
337
472
338 return xi, yi, xw, yw
473 return xi, yi, xw, yw
339
474
340 def plot(self, currenttime, range, data):
475 def plot(self, currenttime, range, data):
341 plotObj = self.plotObjList[0]
476 plotObj = self.plotObjList[0]
342 plotObj.plot(currenttime,range,data)
477 plotObj.plot(currenttime,range,data)
343
478
344 if self.showprofile:
479 if self.showprofile:
345 plotObj = self.plotObjList[1]
480 plotObj = self.plotObjList[1]
346 plotObj.plot(data,range)
481 plotObj.plot(data,range)
347
482
348
483
349 class RTIPlot(Plot):
484 class RTIPlot(Plot):
350 deltax = None
485 deltax = None
351 deltay = None
486 deltay = None
352 xrange = [None,None]
487 xrange = [None,None]
353 xminpos = None
488 xminpos = None
354 xmaxpos = None
489 xmaxpos = None
355 xg = None
490 xg = None
356 yg = None
491 yg = None
357
492
358 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
493 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
359 self.drvObj = drvObj
494 self.drvObj = drvObj
360 self.idframe = idframe
495 self.idframe = idframe
361 self.idplot = idplot
496 self.idplot = idplot
362 self.xi = xi
497 self.xi = xi
363 self.yi = yi
498 self.yi = yi
364 self.xw = xw
499 self.xw = xw
365 self.yw = yw
500 self.yw = yw
366 self.colorbar = colorbar
501 self.colorbar = colorbar
367
502
368 if self.colorbar:
503 if self.colorbar:
369 cbxi = xw + 0.03
504 cbxi = xw + 0.03
370 cbxw = cbxi + 0.03
505 cbxw = cbxi + 0.03
371 cbyi = yi
506 cbyi = yi
372 cbyw = yw
507 cbyw = yw
373 self.cbxpos = [cbxi,cbxw]
508 self.cbxpos = [cbxi,cbxw]
374 self.cbypos = [cbyi,cbyw]
509 self.cbypos = [cbyi,cbyw]
375
510
376 self.xpos = [self.xi,self.xw]
511 self.xpos = [self.xi,self.xw]
377 self.ypos = [self.yi,self.yw]
512 self.ypos = [self.yi,self.yw]
378 self.xaxisastime = True
513 self.xaxisastime = True
379 self.timefmt = "%H:%M"
514 self.timefmt = "%H:%M:%S"
380 self.xopt = "bcnstd"
515 self.xopt = "bcnstd"
381 self.yopt = "bcnstv"
516 self.yopt = "bcnstv"
382
517
383 self.szchar = 1.0
518 self.szchar = 1.0
384 self.title = "Channel %d"%self.idframe
519 self.title = "Channel %d"%self.idframe
385 self.xlabel = "Local Time"
520 self.xlabel = "Local Time"
386 self.ylabel = "Range (Km)"
521 self.ylabel = "Range (Km)"
387
522
388
523
389 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
524 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
390 self.xmin = xmin
525 self.xmin = xmin
391 self.xmax = xmax
526 self.xmax = xmax
392 self.ymin = ymin
527 self.ymin = ymin
393 self.ymax = ymax
528 self.ymax = ymax
394 self.minvalue = minvalue
529 self.minvalue = minvalue
395 self.maxvalue = maxvalue
530 self.maxvalue = maxvalue
396 self.deltax = deltax
531 self.deltax = deltax
397 self.deltay = deltay
532 self.deltay = deltay
398 self.colorbar = colorbar
533 self.colorbar = colorbar
399
534
400 def plot(self, currenttime, range, data):
535 def plot(self, currenttime, range, data):
401
536
402 if self.xmaxpos == None:
537 if self.xmaxpos == None:
403 self.xmaxpos = currenttime
538 self.xmaxpos = currenttime
404
539
405 # if currenttime >= self.xmaxpos:
540 # if currenttime >= self.xmaxpos:
406
541
407 self.xminpos = currenttime
542 self.xminpos = currenttime
408 self.xmaxpos = currenttime + self.deltax
543 self.xmaxpos = currenttime + self.deltax
409 x = [currenttime]
544 x = [currenttime]
410 y = range
545 y = range
411 z = numpy.reshape(data, (1,-1))
546 z = numpy.reshape(data, (1,-1))
412 getGrid = True
547 getGrid = True
413
548
414 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
549 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
415
550
416
551
417 class ScopeFigure(Figure):
552 class ScopeFigure(Figure):
418 overplot = 0
553 overplot = 0
419 xw = 700
554 xw = 700
420 yw = 650
555 yw = 650
421 colorbar = None
556 colorbar = None
422
557
423 def __init__(self,idfigure,nframes,wintitle,driver):
558 def __init__(self,idfigure,nframes,wintitle,driver):
424 colormap = None
559 colormap = None
425 colorbar = False
560 colorbar = False
426
561
427 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
562 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
428
563
429
564
430 def getSubplots(self):
565 def getSubplots(self):
431 nrows = self.nframes
566 nrows = self.nframes
432 ncolumns = 1
567 ncolumns = 1
433 return nrows, ncolumns
568 return nrows, ncolumns
434
569
435 def createFrames(self):
570 def createFrames(self):
436
571
437 self.frameObjList = []
572 self.frameObjList = []
438
573
439 for frame in range(self.nframes):
574 for frame in range(self.nframes):
440 frameObj = ScopeFrame(self.drvObj,frame + 1)
575 frameObj = ScopeFrame(self.drvObj,frame + 1)
441 self.frameObjList.append(frameObj)
576 self.frameObjList.append(frameObj)
442
577
443
578
444 class ScopeFrame(Frame):
579 class ScopeFrame(Frame):
445 # plotObjList = []
580 # plotObjList = []
446 xlabel = ""
581 xlabel = ""
447 ylabel = ""
582 ylabel = ""
448 title = ""
583 title = ""
449 def __init__(self,drvObj,idframe):
584 def __init__(self,drvObj,idframe):
450 self.drvObj = drvObj
585 self.drvObj = drvObj
451 self.idframe = idframe
586 self.idframe = idframe
452 self.nplots = 1 #nplots/frame
587 self.nplots = 1 #nplots/frame
453 self.createPlots()
588 self.createPlots()
454 # Frame.__init__(self, drvObj, idframe)
589 # Frame.__init__(self, drvObj, idframe)
455
590
456 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
591 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
457 xi = 0.08; xw = 0.9
592 xi = 0.08; xw = 0.9
458 yi = 0.20; yw = 0.75
593 yi = 0.20; yw = 0.75
459 return xi,yi,xw,yw
594 return xi,yi,xw,yw
460
595
461 def createPlots(self):
596 def createPlots(self):
462 plotObjList = []
597 plotObjList = []
463 for idplot in range(self.nplots):
598 for idplot in range(self.nplots):
464 xi, yi, xw, yw = self.getScreenPos(idplot)
599 xi, yi, xw, yw = self.getScreenPos(idplot)
465 type = "scopebox"
600 type = "scopebox"
466 title = "Channel %d"%self.idframe
601 title = "Channel %d"%self.idframe
467 xlabel = "range (Km)"
602 xlabel = "range (Km)"
468 ylabel = "intensity"
603 ylabel = "intensity"
469 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
604 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
470 plotObjList.append(plotObj)
605 plotObjList.append(plotObj)
471 self.plotObjList = plotObjList
606 self.plotObjList = plotObjList
472 # self.plotObjList.append(plotObj)
607 # self.plotObjList.append(plotObj)
473
608
474 def plot(self, x, y, z=None):
609 def plot(self, x, y, z=None):
475 for plotObj in self.plotObjList:
610 for plotObj in self.plotObjList:
476 plotObj.plot(x, y)
611 plotObj.plot(x, y)
477
612
478
613
479 class Plot1D(Plot):
614 class Plot1D(Plot):
480 # type, title, xlabel, ylabel
615 # type, title, xlabel, ylabel
481 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel):
616 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel):
482 self.drvObj = drvObj
617 self.drvObj = drvObj
483 self.idframe = idframe
618 self.idframe = idframe
484 self.idplot = idplot
619 self.idplot = idplot
485 self.xi = xi
620 self.xi = xi
486 self.yi = yi
621 self.yi = yi
487 self.xw = xw
622 self.xw = xw
488 self.yw = yw
623 self.yw = yw
489 self.xpos = [self.xi,self.xw]
624 self.xpos = [self.xi,self.xw]
490 self.ypos = [self.yi,self.yw]
625 self.ypos = [self.yi,self.yw]
491 self.xaxisastime = False
626 self.xaxisastime = False
492 self.timefmt = None
627 self.timefmt = None
493 self.xopt = "bcnst"
628 self.xopt = "bcnst"
494 self.yopt = "bcnstv"
629 self.yopt = "bcnstv"
495 self.szchar = 1.0
630 self.szchar = 0.7
496 self.type = type
631 self.type = type
497 self.title = title
632 self.title = title
498 self.xlabel = xlabel
633 self.xlabel = xlabel
499 self.ylabel = ylabel
634 self.ylabel = ylabel
500
635
501
636
502
637
503 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
638 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
504 if self.type == "pwbox":
639 if self.type == "pwbox":
505 self.xmin = minvalue
640 self.xmin = minvalue
506 self.xmax = maxvalue
641 self.xmax = maxvalue
507 self.ymin = ymin
642 self.ymin = ymin
508 self.ymax = ymax
643 self.ymax = ymax
509 self.minvalue = minvalue
644 self.minvalue = minvalue
510 self.maxvalue = maxvalue
645 self.maxvalue = maxvalue
511
646
512 else:
647 else:
513 self.xmin = xmin
648 self.xmin = xmin
514 self.xmax = xmax
649 self.xmax = xmax
515 self.ymin = ymin
650 self.ymin = ymin
516 self.ymax = ymax
651 self.ymax = ymax
517 self.minvalue = minvalue
652 self.minvalue = minvalue
518 self.maxvalue = maxvalue
653 self.maxvalue = maxvalue
519
654
520 self.colorbar = False
655 self.colorbar = False
521
656
522 def plot(self,x,y):
657 def plot(self,x,y):
523 if y.dtype == "complex128":
658 if y.dtype == "complex128":
524 color="blue"
659 color="blue"
525 self.plotBasicLine(x, y.real, color)
660 self.plotBasicLine(x, y.real, color)
526 color="red"
661 color="red"
527 self.plotBasicLine(x, y.imag, color)
662 self.plotBasicLine(x, y.imag, color)
528 else:
663 else:
529 color="blue"
664 color="blue"
530 self.plotBasicLine(x, y, color)
665 self.plotBasicLine(x, y, color)
@@ -1,584 +1,592
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9 import glob
9 import glob
10 import fnmatch
10 import fnmatch
11 import time, datetime
11 import time, datetime
12
12
13 path = os.path.split(os.getcwd())[0]
13 path = os.path.split(os.getcwd())[0]
14 sys.path.append(path)
14 sys.path.append(path)
15
15
16 from JROHeaderIO import *
16 from JROHeaderIO import *
17 from JRODataIO import JRODataReader
17 from JRODataIO import JRODataReader
18 from JRODataIO import JRODataWriter
18 from JRODataIO import JRODataWriter
19
19
20 from Data.JROData import Voltage
20 from Data.JROData import Voltage
21
21
22 class VoltageReader(JRODataReader):
22 class VoltageReader(JRODataReader):
23 """
23 """
24 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
24 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
25 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
25 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
26 perfiles*alturas*canales) son almacenados en la variable "buffer".
26 perfiles*alturas*canales) son almacenados en la variable "buffer".
27
27
28 perfiles * alturas * canales
28 perfiles * alturas * canales
29
29
30 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
30 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
31 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
31 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
32 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
32 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
33 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
33 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
34
34
35 Example:
35 Example:
36
36
37 dpath = "/home/myuser/data"
37 dpath = "/home/myuser/data"
38
38
39 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
39 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
40
40
41 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
41 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
42
42
43 readerObj = VoltageReader()
43 readerObj = VoltageReader()
44
44
45 readerObj.setup(dpath, startTime, endTime)
45 readerObj.setup(dpath, startTime, endTime)
46
46
47 while(True):
47 while(True):
48
48
49 #to get one profile
49 #to get one profile
50 profile = readerObj.getData()
50 profile = readerObj.getData()
51
51
52 #print the profile
52 #print the profile
53 print profile
53 print profile
54
54
55 #If you want to see all datablock
55 #If you want to see all datablock
56 print readerObj.datablock
56 print readerObj.datablock
57
57
58 if readerObj.flagNoMoreFiles:
58 if readerObj.flagNoMoreFiles:
59 break
59 break
60
60
61 """
61 """
62
62
63 ext = ".r"
63 ext = ".r"
64
64
65 optchar = "D"
65 optchar = "D"
66 dataOutObj = None
66 dataOutObj = None
67
67
68
68
69 def __init__(self, dataOutObj=None):
69 def __init__(self, dataOutObj=None):
70 """
70 """
71 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
71 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
72
72
73 Input:
73 Input:
74 dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para
74 dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para
75 almacenar un perfil de datos cada vez que se haga un requerimiento
75 almacenar un perfil de datos cada vez que se haga un requerimiento
76 (getData). El perfil sera obtenido a partir del buffer de datos,
76 (getData). El perfil sera obtenido a partir del buffer de datos,
77 si el buffer esta vacio se hara un nuevo proceso de lectura de un
77 si el buffer esta vacio se hara un nuevo proceso de lectura de un
78 bloque de datos.
78 bloque de datos.
79 Si este parametro no es pasado se creara uno internamente.
79 Si este parametro no es pasado se creara uno internamente.
80
80
81 Variables afectadas:
81 Variables afectadas:
82 self.dataOutObj
82 self.dataOutObj
83
83
84 Return:
84 Return:
85 None
85 None
86 """
86 """
87
87
88 self.datablock = None
88 self.datablock = None
89
89
90 self.utc = 0
90 self.utc = 0
91
91
92 self.ext = ".r"
92 self.ext = ".r"
93
93
94 self.optchar = "D"
94 self.optchar = "D"
95
95
96 self.basicHeaderObj = BasicHeader()
96 self.basicHeaderObj = BasicHeader()
97
97
98 self.systemHeaderObj = SystemHeader()
98 self.systemHeaderObj = SystemHeader()
99
99
100 self.radarControllerHeaderObj = RadarControllerHeader()
100 self.radarControllerHeaderObj = RadarControllerHeader()
101
101
102 self.processingHeaderObj = ProcessingHeader()
102 self.processingHeaderObj = ProcessingHeader()
103
103
104 self.online = 0
104 self.online = 0
105
105
106 self.fp = None
106 self.fp = None
107
107
108 self.idFile = None
108 self.idFile = None
109
109
110 self.dtype = None
110 self.dtype = None
111
111
112 self.fileSizeByHeader = None
112 self.fileSizeByHeader = None
113
113
114 self.filenameList = []
114 self.filenameList = []
115
115
116 self.filename = None
116 self.filename = None
117
117
118 self.fileSize = None
118 self.fileSize = None
119
119
120 self.firstHeaderSize = 0
120 self.firstHeaderSize = 0
121
121
122 self.basicHeaderSize = 24
122 self.basicHeaderSize = 24
123
123
124 self.pathList = []
124 self.pathList = []
125
125
126 self.filenameList = []
126 self.filenameList = []
127
127
128 self.lastUTTime = 0
128 self.lastUTTime = 0
129
129
130 self.maxTimeStep = 30
130 self.maxTimeStep = 30
131
131
132 self.flagNoMoreFiles = 0
132 self.flagNoMoreFiles = 0
133
133
134 self.set = 0
134 self.set = 0
135
135
136 self.path = None
136 self.path = None
137
137
138 self.profileIndex = 9999
138 self.profileIndex = 9999
139
139
140 self.delay = 3 #seconds
140 self.delay = 3 #seconds
141
141
142 self.nTries = 3 #quantity tries
142 self.nTries = 3 #quantity tries
143
143
144 self.nFiles = 3 #number of files for searching
144 self.nFiles = 3 #number of files for searching
145
145
146 self.nReadBlocks = 0
146 self.nReadBlocks = 0
147
147
148 self.flagIsNewFile = 1
148 self.flagIsNewFile = 1
149
149
150 self.ippSeconds = 0
150 self.ippSeconds = 0
151
151
152 self.flagTimeBlock = 0
152 self.flagTimeBlock = 0
153
153
154 self.flagIsNewBlock = 0
154 self.flagIsNewBlock = 0
155
155
156 self.nTotalBlocks = 0
156 self.nTotalBlocks = 0
157
157
158 self.blocksize = 0
158 self.blocksize = 0
159
159
160 def createObjByDefault(self):
160 def createObjByDefault(self):
161
161
162 dataObj = Voltage()
162 dataObj = Voltage()
163
163
164 return dataObj
164 return dataObj
165
165
166 def __hasNotDataInBuffer(self):
166 def __hasNotDataInBuffer(self):
167 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
167 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
168 return 1
168 return 1
169 return 0
169 return 0
170
170
171
171
172 def getBlockDimension(self):
172 def getBlockDimension(self):
173 """
173 """
174 Obtiene la cantidad de puntos a leer por cada bloque de datos
174 Obtiene la cantidad de puntos a leer por cada bloque de datos
175
175
176 Affected:
176 Affected:
177 self.blocksize
177 self.blocksize
178
178
179 Return:
179 Return:
180 None
180 None
181 """
181 """
182 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
182 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
183 self.blocksize = pts2read
183 self.blocksize = pts2read
184
184
185
185
186 def readBlock(self):
186 def readBlock(self):
187 """
187 """
188 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
188 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
189 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
189 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
190 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
190 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
191 es seteado a 0
191 es seteado a 0
192
192
193 Inputs:
193 Inputs:
194 None
194 None
195
195
196 Return:
196 Return:
197 None
197 None
198
198
199 Affected:
199 Affected:
200 self.profileIndex
200 self.profileIndex
201 self.datablock
201 self.datablock
202 self.flagIsNewFile
202 self.flagIsNewFile
203 self.flagIsNewBlock
203 self.flagIsNewBlock
204 self.nTotalBlocks
204 self.nTotalBlocks
205
205
206 Exceptions:
206 Exceptions:
207 Si un bloque leido no es un bloque valido
207 Si un bloque leido no es un bloque valido
208 """
208 """
209
209
210 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
210 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
211
211
212 try:
212 try:
213 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
213 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
214 except:
214 except:
215 print "The read block (%3d) has not enough data" %self.nReadBlocks
215 print "The read block (%3d) has not enough data" %self.nReadBlocks
216 return 0
216 return 0
217
217
218 junk = numpy.transpose(junk, (2,0,1))
218 junk = numpy.transpose(junk, (2,0,1))
219 self.datablock = junk['real'] + junk['imag']*1j
219 self.datablock = junk['real'] + junk['imag']*1j
220
220
221 self.profileIndex = 0
221 self.profileIndex = 0
222
222
223 self.flagIsNewFile = 0
223 self.flagIsNewFile = 0
224 self.flagIsNewBlock = 1
224 self.flagIsNewBlock = 1
225
225
226 self.nTotalBlocks += 1
226 self.nTotalBlocks += 1
227 self.nReadBlocks += 1
227 self.nReadBlocks += 1
228
228
229 return 1
229 return 1
230
230
231
231
232 def getData(self):
232 def getData(self):
233 """
233 """
234 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
234 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
235 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
235 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
236 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
236 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
237
237
238 Ademas incrementa el contador del buffer en 1.
238 Ademas incrementa el contador del buffer en 1.
239
239
240 Return:
240 Return:
241 data : retorna un perfil de voltages (alturas * canales) copiados desde el
241 data : retorna un perfil de voltages (alturas * canales) copiados desde el
242 buffer. Si no hay mas archivos a leer retorna None.
242 buffer. Si no hay mas archivos a leer retorna None.
243
243
244 Variables afectadas:
244 Variables afectadas:
245 self.dataOutObj
245 self.dataOutObj
246 self.profileIndex
246 self.profileIndex
247
247
248 Affected:
248 Affected:
249 self.dataOutObj
249 self.dataOutObj
250 self.profileIndex
250 self.profileIndex
251 self.flagTimeBlock
251 self.flagTimeBlock
252 self.flagIsNewBlock
252 self.flagIsNewBlock
253 """
253 """
254 if self.flagNoMoreFiles: return 0
254 if self.flagNoMoreFiles: return 0
255
255
256 self.flagTimeBlock = 0
256 self.flagTimeBlock = 0
257 self.flagIsNewBlock = 0
257 self.flagIsNewBlock = 0
258
258
259 if self.__hasNotDataInBuffer():
259 if self.__hasNotDataInBuffer():
260
260
261 if not( self.readNextBlock() ):
261 if not( self.readNextBlock() ):
262 return 0
262 return 0
263
263
264 # self.updateDataHeader()
264 # self.updateDataHeader()
265
265
266 if self.flagNoMoreFiles == 1:
266 if self.flagNoMoreFiles == 1:
267 print 'Process finished'
267 print 'Process finished'
268 return 0
268 return 0
269
269
270 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
270 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
271
271
272 if self.datablock == None:
272 if self.datablock == None:
273 self.dataOutObj.flagNoData = True
273 self.dataOutObj.flagNoData = True
274 return 0
274 return 0
275
275
276 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
276 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
277
277
278 self.dataOutObj.dtype = self.dtype
278 self.dataOutObj.dtype = self.dtype
279
279
280 self.dataOutObj.nChannels = self.systemHeaderObj.nChannels
280 self.dataOutObj.nChannels = self.systemHeaderObj.nChannels
281
281
282 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
282 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
283
283
284 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
284 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
285
285
286 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
286 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
287
287
288 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
288 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
289
289
290 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
290 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
291
291
292 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
292 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
293
293
294 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
294 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
295
295
296 self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
296 self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
297
297
298 self.dataOutObj.ippSeconds = self.ippSeconds
299
300 self.dataOutObj.timeInterval = self.ippSeconds
301
298 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
302 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
299
303
300 self.dataOutObj.flagShiftFFT = False
304 self.dataOutObj.flagShiftFFT = False
301
305
302 if self.processingHeaderObj.code != None:
306 if self.processingHeaderObj.code != None:
303 self.dataOutObj.nCode = self.processingHeaderObj.nCode
307 self.dataOutObj.nCode = self.processingHeaderObj.nCode
304
308
305 self.dataOutObj.nBaud = self.processingHeaderObj.nBaud
309 self.dataOutObj.nBaud = self.processingHeaderObj.nBaud
306
310
307 self.dataOutObj.code = self.processingHeaderObj.code
311 self.dataOutObj.code = self.processingHeaderObj.code
308
312
309 self.profileIndex += 1
313 self.profileIndex += 1
310
314
311 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
315 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
312
316
313 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
317 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
314
318
315 self.dataOutObj.flagNoData = False
319 self.dataOutObj.flagNoData = False
320
321 # print self.profileIndex, self.dataOutObj.utctime
322 # if self.profileIndex == 800:
323 # a=1
316
324
317 return self.dataOutObj.data
325 return self.dataOutObj.data
318
326
319
327
320 class VoltageWriter(JRODataWriter):
328 class VoltageWriter(JRODataWriter):
321 """
329 """
322 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
330 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
323 de los datos siempre se realiza por bloques.
331 de los datos siempre se realiza por bloques.
324 """
332 """
325
333
326 ext = ".r"
334 ext = ".r"
327
335
328 optchar = "D"
336 optchar = "D"
329
337
330 shapeBuffer = None
338 shapeBuffer = None
331
339
332
340
333 def __init__(self, dataOutObj=None):
341 def __init__(self, dataOutObj=None):
334 """
342 """
335 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
343 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
336
344
337 Affected:
345 Affected:
338 self.dataOutObj
346 self.dataOutObj
339
347
340 Return: None
348 Return: None
341 """
349 """
342 if dataOutObj == None:
350 if dataOutObj == None:
343 dataOutObj = Voltage()
351 dataOutObj = Voltage()
344
352
345 if not( isinstance(dataOutObj, Voltage) ):
353 if not( isinstance(dataOutObj, Voltage) ):
346 raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object"
354 raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object"
347
355
348 self.dataOutObj = dataOutObj
356 self.dataOutObj = dataOutObj
349
357
350 self.nTotalBlocks = 0
358 self.nTotalBlocks = 0
351
359
352 self.profileIndex = 0
360 self.profileIndex = 0
353
361
354 def hasAllDataInBuffer(self):
362 def hasAllDataInBuffer(self):
355 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
363 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
356 return 1
364 return 1
357 return 0
365 return 0
358
366
359
367
360 def setBlockDimension(self):
368 def setBlockDimension(self):
361 """
369 """
362 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
370 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
363
371
364 Affected:
372 Affected:
365 self.shape_spc_Buffer
373 self.shape_spc_Buffer
366 self.shape_cspc_Buffer
374 self.shape_cspc_Buffer
367 self.shape_dc_Buffer
375 self.shape_dc_Buffer
368
376
369 Return: None
377 Return: None
370 """
378 """
371 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
379 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
372 self.processingHeaderObj.nHeights,
380 self.processingHeaderObj.nHeights,
373 self.systemHeaderObj.nChannels)
381 self.systemHeaderObj.nChannels)
374
382
375 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
383 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
376 self.processingHeaderObj.profilesPerBlock,
384 self.processingHeaderObj.profilesPerBlock,
377 self.processingHeaderObj.nHeights),
385 self.processingHeaderObj.nHeights),
378 dtype=numpy.dtype('complex'))
386 dtype=numpy.dtype('complex'))
379
387
380
388
381 def writeBlock(self):
389 def writeBlock(self):
382 """
390 """
383 Escribe el buffer en el file designado
391 Escribe el buffer en el file designado
384
392
385 Affected:
393 Affected:
386 self.profileIndex
394 self.profileIndex
387 self.flagIsNewFile
395 self.flagIsNewFile
388 self.flagIsNewBlock
396 self.flagIsNewBlock
389 self.nTotalBlocks
397 self.nTotalBlocks
390 self.blockIndex
398 self.blockIndex
391
399
392 Return: None
400 Return: None
393 """
401 """
394 data = numpy.zeros( self.shapeBuffer, self.dtype )
402 data = numpy.zeros( self.shapeBuffer, self.dtype )
395
403
396 junk = numpy.transpose(self.datablock, (1,2,0))
404 junk = numpy.transpose(self.datablock, (1,2,0))
397
405
398 data['real'] = junk.real
406 data['real'] = junk.real
399 data['imag'] = junk.imag
407 data['imag'] = junk.imag
400
408
401 data = data.reshape( (-1) )
409 data = data.reshape( (-1) )
402
410
403 data.tofile( self.fp )
411 data.tofile( self.fp )
404
412
405 self.datablock.fill(0)
413 self.datablock.fill(0)
406
414
407 self.profileIndex = 0
415 self.profileIndex = 0
408 self.flagIsNewFile = 0
416 self.flagIsNewFile = 0
409 self.flagIsNewBlock = 1
417 self.flagIsNewBlock = 1
410
418
411 self.blockIndex += 1
419 self.blockIndex += 1
412 self.nTotalBlocks += 1
420 self.nTotalBlocks += 1
413
421
414 def putData(self):
422 def putData(self):
415 """
423 """
416 Setea un bloque de datos y luego los escribe en un file
424 Setea un bloque de datos y luego los escribe en un file
417
425
418 Affected:
426 Affected:
419 self.flagIsNewBlock
427 self.flagIsNewBlock
420 self.profileIndex
428 self.profileIndex
421
429
422 Return:
430 Return:
423 0 : Si no hay data o no hay mas files que puedan escribirse
431 0 : Si no hay data o no hay mas files que puedan escribirse
424 1 : Si se escribio la data de un bloque en un file
432 1 : Si se escribio la data de un bloque en un file
425 """
433 """
426 self.flagIsNewBlock = 0
434 self.flagIsNewBlock = 0
427
435
428 if self.dataOutObj.flagNoData:
436 if self.dataOutObj.flagNoData:
429 return 0
437 return 0
430
438
431 if self.dataOutObj.flagTimeBlock:
439 if self.dataOutObj.flagTimeBlock:
432
440
433 self.datablock.fill(0)
441 self.datablock.fill(0)
434 self.profileIndex = 0
442 self.profileIndex = 0
435 self.setNextFile()
443 self.setNextFile()
436
444
437 if self.profileIndex == 0:
445 if self.profileIndex == 0:
438 self.getBasicHeader()
446 self.getBasicHeader()
439
447
440 self.datablock[:,self.profileIndex,:] = self.dataOutObj.data
448 self.datablock[:,self.profileIndex,:] = self.dataOutObj.data
441
449
442 self.profileIndex += 1
450 self.profileIndex += 1
443
451
444 if self.hasAllDataInBuffer():
452 if self.hasAllDataInBuffer():
445 #if self.flagIsNewFile:
453 #if self.flagIsNewFile:
446 self.writeNextBlock()
454 self.writeNextBlock()
447 # self.getDataHeader()
455 # self.getDataHeader()
448
456
449 if self.flagNoMoreFiles:
457 if self.flagNoMoreFiles:
450 #print 'Process finished'
458 #print 'Process finished'
451 return 0
459 return 0
452
460
453 return 1
461 return 1
454
462
455 def __getProcessFlags(self):
463 def __getProcessFlags(self):
456
464
457 processFlags = 0
465 processFlags = 0
458
466
459 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
467 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
460 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
468 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
461 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
469 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
462 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
470 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
463 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
471 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
464 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
472 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
465
473
466 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
474 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
467
475
468
476
469
477
470 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
478 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
471 PROCFLAG.DATATYPE_SHORT,
479 PROCFLAG.DATATYPE_SHORT,
472 PROCFLAG.DATATYPE_LONG,
480 PROCFLAG.DATATYPE_LONG,
473 PROCFLAG.DATATYPE_INT64,
481 PROCFLAG.DATATYPE_INT64,
474 PROCFLAG.DATATYPE_FLOAT,
482 PROCFLAG.DATATYPE_FLOAT,
475 PROCFLAG.DATATYPE_DOUBLE]
483 PROCFLAG.DATATYPE_DOUBLE]
476
484
477
485
478 for index in range(len(dtypeList)):
486 for index in range(len(dtypeList)):
479 if self.dataOutObj.dtype == dtypeList[index]:
487 if self.dataOutObj.dtype == dtypeList[index]:
480 dtypeValue = datatypeValueList[index]
488 dtypeValue = datatypeValueList[index]
481 break
489 break
482
490
483 processFlags += dtypeValue
491 processFlags += dtypeValue
484
492
485 if self.dataOutObj.flagDecodeData:
493 if self.dataOutObj.flagDecodeData:
486 processFlags += PROCFLAG.DECODE_DATA
494 processFlags += PROCFLAG.DECODE_DATA
487
495
488 if self.dataOutObj.flagDeflipData:
496 if self.dataOutObj.flagDeflipData:
489 processFlags += PROCFLAG.DEFLIP_DATA
497 processFlags += PROCFLAG.DEFLIP_DATA
490
498
491 if self.dataOutObj.code != None:
499 if self.dataOutObj.code != None:
492 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
500 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
493
501
494 if self.dataOutObj.nCohInt > 1:
502 if self.dataOutObj.nCohInt > 1:
495 processFlags += PROCFLAG.COHERENT_INTEGRATION
503 processFlags += PROCFLAG.COHERENT_INTEGRATION
496
504
497 return processFlags
505 return processFlags
498
506
499
507
500 def __getBlockSize(self):
508 def __getBlockSize(self):
501 '''
509 '''
502 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
510 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
503 '''
511 '''
504
512
505 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
513 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
506 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
514 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
507 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
515 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
508 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
516 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
509 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
517 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
510 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
518 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
511
519
512 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
520 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
513 datatypeValueList = [1,2,4,8,4,8]
521 datatypeValueList = [1,2,4,8,4,8]
514 for index in range(len(dtypeList)):
522 for index in range(len(dtypeList)):
515 if self.dataOutObj.dtype == dtypeList[index]:
523 if self.dataOutObj.dtype == dtypeList[index]:
516 datatypeValue = datatypeValueList[index]
524 datatypeValue = datatypeValueList[index]
517 break
525 break
518
526
519 blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2)
527 blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2)
520
528
521 return blocksize
529 return blocksize
522
530
523
531
524 def getBasicHeader(self):
532 def getBasicHeader(self):
525 self.basicHeaderObj.size = self.basicHeaderSize #bytes
533 self.basicHeaderObj.size = self.basicHeaderSize #bytes
526 self.basicHeaderObj.version = self.versionFile
534 self.basicHeaderObj.version = self.versionFile
527 self.basicHeaderObj.dataBlock = self.nTotalBlocks
535 self.basicHeaderObj.dataBlock = self.nTotalBlocks
528
536
529 utc = numpy.floor(self.dataOutObj.utctime)
537 utc = numpy.floor(self.dataOutObj.utctime)
530 milisecond = (self.dataOutObj.utctime - utc)* 1000.0
538 milisecond = (self.dataOutObj.utctime - utc)* 1000.0
531
539
532 self.basicHeaderObj.utc = utc
540 self.basicHeaderObj.utc = utc
533 self.basicHeaderObj.miliSecond = milisecond
541 self.basicHeaderObj.miliSecond = milisecond
534 self.basicHeaderObj.timeZone = 0
542 self.basicHeaderObj.timeZone = 0
535 self.basicHeaderObj.dstFlag = 0
543 self.basicHeaderObj.dstFlag = 0
536 self.basicHeaderObj.errorCount = 0
544 self.basicHeaderObj.errorCount = 0
537
545
538 def getDataHeader(self):
546 def getDataHeader(self):
539
547
540 """
548 """
541 Obtiene una copia del First Header
549 Obtiene una copia del First Header
542
550
543 Affected:
551 Affected:
544 self.systemHeaderObj
552 self.systemHeaderObj
545 self.radarControllerHeaderObj
553 self.radarControllerHeaderObj
546 self.dtype
554 self.dtype
547
555
548 Return:
556 Return:
549 None
557 None
550 """
558 """
551
559
552 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
560 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
553 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
561 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
554 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
562 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
555
563
556 self.getBasicHeader()
564 self.getBasicHeader()
557
565
558 processingHeaderSize = 40 # bytes
566 processingHeaderSize = 40 # bytes
559 self.processingHeaderObj.dtype = 0 # Voltage
567 self.processingHeaderObj.dtype = 0 # Voltage
560 self.processingHeaderObj.blockSize = self.__getBlockSize()
568 self.processingHeaderObj.blockSize = self.__getBlockSize()
561 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
569 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
562 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
570 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
563 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
571 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
564 self.processingHeaderObj.processFlags = self.__getProcessFlags()
572 self.processingHeaderObj.processFlags = self.__getProcessFlags()
565 self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt
573 self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt
566 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
574 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
567 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
575 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
568
576
569 if self.dataOutObj.code != None:
577 if self.dataOutObj.code != None:
570 self.processingHeaderObj.code = self.dataOutObj.code
578 self.processingHeaderObj.code = self.dataOutObj.code
571 self.processingHeaderObj.nCode = self.dataOutObj.nCode
579 self.processingHeaderObj.nCode = self.dataOutObj.nCode
572 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
580 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
573 codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud)
581 codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud)
574 processingHeaderSize += codesize
582 processingHeaderSize += codesize
575
583
576 if self.processingHeaderObj.nWindows != 0:
584 if self.processingHeaderObj.nWindows != 0:
577 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
585 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
578 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
586 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
579 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
587 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
580 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
588 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
581 processingHeaderSize += 12
589 processingHeaderSize += 12
582
590
583 self.processingHeaderObj.size = processingHeaderSize
591 self.processingHeaderObj.size = processingHeaderSize
584 No newline at end of file
592
@@ -1,597 +1,638
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9 import time
9 import time
10 import datetime
10 import datetime
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Data.JROData import Spectra, SpectraHeis
14 from Data.JROData import Spectra, SpectraHeis
15 from IO.SpectraIO import SpectraWriter
15 from IO.SpectraIO import SpectraWriter
16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure
16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure
17 #from JRONoise import Noise
17 #from JRONoise import Noise
18
18
19 class SpectraProcessor:
19 class SpectraProcessor:
20 '''
20 '''
21 classdocs
21 classdocs
22 '''
22 '''
23
23
24 dataInObj = None
24 dataInObj = None
25
25
26 dataOutObj = None
26 dataOutObj = None
27
27
28 noiseObj = None
28 noiseObj = None
29
29
30 integratorObjList = []
30 integratorObjList = []
31
31
32 writerObjList = []
32 writerObjList = []
33
33
34 integratorObjIndex = None
34 integratorObjIndex = None
35
35
36 writerObjIndex = None
36 writerObjIndex = None
37
37
38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39
39
40
40
41 def __init__(self):
41 def __init__(self):
42 '''
42 '''
43 Constructor
43 Constructor
44 '''
44 '''
45
45
46 self.integratorObjIndex = None
46 self.integratorObjIndex = None
47 self.writerObjIndex = None
47 self.writerObjIndex = None
48 self.plotObjIndex = None
48 self.plotObjIndex = None
49 self.integratorOst = []
49 self.integratorOst = []
50 self.plotObjList = []
50 self.plotObjList = []
51 self.noiseObj = []
51 self.noiseObj = []
52 self.writerObjList = []
52 self.writerObjList = []
53 self.buffer = None
53 self.buffer = None
54 self.profIndex = 0
54 self.profIndex = 0
55
55
56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None):
57
57
58 if dataInObj == None:
58 if dataInObj == None:
59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
60
60
61 if dataInObj.type == "Voltage":
61 if dataInObj.type == "Voltage":
62 if nFFTPoints == None:
62 if nFFTPoints == None:
63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
64
64
65
65
66
66
67 if dataInObj.type == "Spectra":
67 if dataInObj.type == "Spectra":
68 if nFFTPoints != None:
68 if nFFTPoints != None:
69 raise ValueError, "The nFFTPoints cannot be selected to this object type"
69 raise ValueError, "The nFFTPoints cannot be selected to this object type"
70
70
71 nFFTPoints = dataInObj.nFFTPoints
71 nFFTPoints = dataInObj.nFFTPoints
72
72
73 if pairList == None:
73 if pairsList == None:
74 pairList = self.dataInObj.pairList
74 pairsList = dataInObj.pairsList
75
75
76 if pairList == None:
76 if pairsList == None:
77 nPairs = 0
77 nPairs = 0
78 else:
78 else:
79 nPairs = len(pairList)
79 nPairs = len(pairsList)
80
80
81 self.dataInObj = dataInObj
81 self.dataInObj = dataInObj
82
82
83 if dataOutObj == None:
83 if dataOutObj == None:
84 dataOutObj = Spectra()
84 dataOutObj = Spectra()
85
85
86 self.dataOutObj = dataOutObj
86 self.dataOutObj = dataOutObj
87 self.dataOutObj.nFFTPoints = nFFTPoints
87 self.dataOutObj.nFFTPoints = nFFTPoints
88 self.dataOutObj.pairList = pairList
88 self.dataOutObj.pairsList = pairsList
89 self.dataOutObj.nPairs = nPairs
89 self.dataOutObj.nPairs = nPairs
90
90
91 return self.dataOutObj
91 return self.dataOutObj
92
92
93 def init(self):
93 def init(self):
94
94
95 self.dataOutObj.flagNoData = True
95 self.dataOutObj.flagNoData = True
96
96
97 if self.dataInObj.flagNoData:
97 if self.dataInObj.flagNoData:
98 return 0
98 return 0
99
99
100 self.integratorObjIndex = 0
100 self.integratorObjIndex = 0
101 self.writerObjIndex = 0
101 self.writerObjIndex = 0
102 self.plotObjIndex = 0
102 self.plotObjIndex = 0
103
103
104
104
105 if self.dataInObj.type == "Spectra":
105 if self.dataInObj.type == "Spectra":
106
106
107 self.dataOutObj.copy(self.dataInObj)
107 self.dataOutObj.copy(self.dataInObj)
108 self.dataOutObj.flagNoData = False
108 self.dataOutObj.flagNoData = False
109 return
109 return
110
110
111 if self.dataInObj.type == "Voltage":
111 if self.dataInObj.type == "Voltage":
112
112
113 if self.buffer == None:
113 if self.buffer == None:
114 self.buffer = numpy.zeros((self.dataInObj.nChannels,
114 self.buffer = numpy.zeros((self.dataInObj.nChannels,
115 self.dataOutObj.nFFTPoints,
115 self.dataOutObj.nFFTPoints,
116 self.dataInObj.nHeights),
116 self.dataInObj.nHeights),
117 dtype='complex')
117 dtype='complex')
118
118
119 self.buffer[:,self.profIndex,:] = self.dataInObj.data
119 self.buffer[:,self.profIndex,:] = self.dataInObj.data
120 self.profIndex += 1
120 self.profIndex += 1
121
121
122 if self.profIndex == self.dataOutObj.nFFTPoints:
122 if self.profIndex == self.dataOutObj.nFFTPoints:
123
123
124 self.__updateObjFromInput()
124 self.__updateObjFromInput()
125 self.__getFft()
125 self.__getFft()
126
126
127 self.dataOutObj.flagNoData = False
127 self.dataOutObj.flagNoData = False
128
128
129 self.buffer = None
129 self.buffer = None
130 self.profIndex = 0
130 self.profIndex = 0
131
131
132 return
132 return
133
133
134 #Other kind of data
134 #Other kind of data
135 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
135 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
136
136
137 def __getFft(self):
137 def __getFft(self):
138 """
138 """
139 Convierte valores de Voltaje a Spectra
139 Convierte valores de Voltaje a Spectra
140
140
141 Affected:
141 Affected:
142 self.dataOutObj.data_spc
142 self.dataOutObj.data_spc
143 self.dataOutObj.data_cspc
143 self.dataOutObj.data_cspc
144 self.dataOutObj.data_dc
144 self.dataOutObj.data_dc
145 self.dataOutObj.heightList
145 self.dataOutObj.heightList
146 self.dataOutObj.m_BasicHeader
146 self.dataOutObj.m_BasicHeader
147 self.dataOutObj.m_ProcessingHeader
147 self.dataOutObj.m_ProcessingHeader
148 self.dataOutObj.radarControllerHeaderObj
148 self.dataOutObj.radarControllerHeaderObj
149 self.dataOutObj.systemHeaderObj
149 self.dataOutObj.systemHeaderObj
150 self.profIndex
150 self.profIndex
151 self.buffer
151 self.buffer
152 self.dataOutObj.flagNoData
152 self.dataOutObj.flagNoData
153 self.dataOutObj.dtype
153 self.dataOutObj.dtype
154 self.dataOutObj.nPairs
154 self.dataOutObj.nPairs
155 self.dataOutObj.nChannels
155 self.dataOutObj.nChannels
156 self.dataOutObj.nProfiles
156 self.dataOutObj.nProfiles
157 self.dataOutObj.systemHeaderObj.numChannels
157 self.dataOutObj.systemHeaderObj.numChannels
158 self.dataOutObj.m_ProcessingHeader.totalSpectra
158 self.dataOutObj.m_ProcessingHeader.totalSpectra
159 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
159 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
160 self.dataOutObj.m_ProcessingHeader.numHeights
160 self.dataOutObj.m_ProcessingHeader.numHeights
161 self.dataOutObj.m_ProcessingHeader.spectraComb
161 self.dataOutObj.m_ProcessingHeader.spectraComb
162 self.dataOutObj.m_ProcessingHeader.shif_fft
162 self.dataOutObj.m_ProcessingHeader.shif_fft
163 """
163 """
164
164
165 fft_volt = numpy.fft.fft(self.buffer,axis=1)
165 fft_volt = numpy.fft.fft(self.buffer,axis=1)
166 dc = fft_volt[:,0,:]
166 dc = fft_volt[:,0,:]
167
167
168 #calculo de self-spectra
168 #calculo de self-spectra
169 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
169 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
170 spc = fft_volt * numpy.conjugate(fft_volt)
170 spc = fft_volt * numpy.conjugate(fft_volt)
171 spc = spc.real
171 spc = spc.real
172
172
173 blocksize = 0
173 blocksize = 0
174 blocksize += dc.size
174 blocksize += dc.size
175 blocksize += spc.size
175 blocksize += spc.size
176
176
177 cspc = None
177 cspc = None
178 pairIndex = 0
178 pairIndex = 0
179 if self.dataOutObj.pairList != None:
179 if self.dataOutObj.pairsList != None:
180 #calculo de cross-spectra
180 #calculo de cross-spectra
181 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
181 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
182 for pair in self.pairList:
182 for pair in self.dataOutObj.pairsList:
183 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
183 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
184 pairIndex += 1
184 pairIndex += 1
185 blocksize += cspc.size
185 blocksize += cspc.size
186
186
187 self.dataOutObj.data_spc = spc
187 self.dataOutObj.data_spc = spc
188 self.dataOutObj.data_cspc = cspc
188 self.dataOutObj.data_cspc = cspc
189 self.dataOutObj.data_dc = dc
189 self.dataOutObj.data_dc = dc
190 self.dataOutObj.blockSize = blocksize
190 self.dataOutObj.blockSize = blocksize
191
191
192 # self.getNoise()
192 # self.getNoise()
193
193
194 def __updateObjFromInput(self):
194 def __updateObjFromInput(self):
195
195
196 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
196 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
197 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
197 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
198 self.dataOutObj.channelList = self.dataInObj.channelList
198 self.dataOutObj.channelList = self.dataInObj.channelList
199 self.dataOutObj.heightList = self.dataInObj.heightList
199 self.dataOutObj.heightList = self.dataInObj.heightList
200 self.dataOutObj.dtype = self.dataInObj.dtype
200 self.dataOutObj.dtype = self.dataInObj.dtype
201 self.dataOutObj.nHeights = self.dataInObj.nHeights
201 self.dataOutObj.nHeights = self.dataInObj.nHeights
202 self.dataOutObj.nChannels = self.dataInObj.nChannels
202 self.dataOutObj.nChannels = self.dataInObj.nChannels
203 self.dataOutObj.nBaud = self.dataInObj.nBaud
203 self.dataOutObj.nBaud = self.dataInObj.nBaud
204 self.dataOutObj.nCode = self.dataInObj.nCode
204 self.dataOutObj.nCode = self.dataInObj.nCode
205 self.dataOutObj.code = self.dataInObj.code
205 self.dataOutObj.code = self.dataInObj.code
206 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
206 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
207 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
207 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
208 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
208 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
209 self.dataOutObj.utctime = self.dataInObj.utctime
209 self.dataOutObj.utctime = self.dataInObj.utctime
210 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
210 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
211 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
211 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
212 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
212 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
213 self.dataOutObj.nIncohInt = 1
213 self.dataOutObj.nIncohInt = 1
214
214
215 def addWriter(self, wrpath, blocksPerFile):
215 def addWriter(self, wrpath, blocksPerFile):
216
216
217 objWriter = SpectraWriter(self.dataOutObj)
217 objWriter = SpectraWriter(self.dataOutObj)
218 objWriter.setup(wrpath, blocksPerFile)
218 objWriter.setup(wrpath, blocksPerFile)
219 self.writerObjList.append(objWriter)
219 self.writerObjList.append(objWriter)
220
220
221 def addIntegrator(self,N,timeInterval):
221 def addIntegrator(self,N,timeInterval):
222
222
223 objIncohInt = IncoherentIntegration(N,timeInterval)
223 objIncohInt = IncoherentIntegration(N,timeInterval)
224 self.integratorObjList.append(objIncohInt)
224 self.integratorObjList.append(objIncohInt)
225
226 def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
227 crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
228 self.plotObjList.append(crossSpcObj)
229
230 def plotCrossSpc(self, idfigure=None,
231 xmin=None,
232 xmax=None,
233 ymin=None,
234 ymax=None,
235 minvalue=None,
236 maxvalue=None,
237 wintitle='',
238 driver='plplot',
239 colormap='br_green',
240 colorbar=True,
241 showprofile=False,
242 save=False,
243 gpath=None,
244 pairsList = None):
245
246 if self.dataOutObj.flagNoData:
247 return 0
248
249 if pairsList == None:
250 pairsList = self.dataOutObj.pairsList
251
252 nframes = len(pairsList)
253
254 x = numpy.arange(self.dataOutObj.nFFTPoints)
255
256 y = self.dataOutObj.heightList
257
258
259
260
261 if len(self.plotObjList) <= self.plotObjIndex:
262 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
263
264
265
225
266
226 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
267 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
227
268
228 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
269 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
229 self.plotObjList.append(spcObj)
270 self.plotObjList.append(spcObj)
230
271
231 def plotSpc(self, idfigure=None,
272 def plotSpc(self, idfigure=None,
232 xmin=None,
273 xmin=None,
233 xmax=None,
274 xmax=None,
234 ymin=None,
275 ymin=None,
235 ymax=None,
276 ymax=None,
236 minvalue=None,
277 minvalue=None,
237 maxvalue=None,
278 maxvalue=None,
238 wintitle='',
279 wintitle='',
239 driver='plplot',
280 driver='plplot',
240 colormap='br_green',
281 colormap='br_green',
241 colorbar=True,
282 colorbar=True,
242 showprofile=False,
283 showprofile=False,
243 save=False,
284 save=False,
244 gpath=None,
285 gpath=None,
245 channelList = None):
286 channelList = None):
246
287
247 if self.dataOutObj.flagNoData:
288 if self.dataOutObj.flagNoData:
248 return 0
289 return 0
249
290
250 if channelList == None:
291 if channelList == None:
251 channelList = self.dataOutObj.channelList
292 channelList = self.dataOutObj.channelList
252
293
253 nframes = len(channelList)
294 nframes = len(channelList)
254
295
255 if len(self.plotObjList) <= self.plotObjIndex:
296 if len(self.plotObjList) <= self.plotObjIndex:
256 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
297 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
257
298
258 x = numpy.arange(self.dataOutObj.nFFTPoints)
299 x = numpy.arange(self.dataOutObj.nFFTPoints)
259
300
260 y = self.dataOutObj.heightList
301 y = self.dataOutObj.heightList
261
302
262 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
303 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
263 # noisedB = 10.*numpy.log10(noise)
304 # noisedB = 10.*numpy.log10(noise)
264 noisedB = numpy.arange(len(channelList)+1)
305 noisedB = numpy.arange(len(channelList)+1)
265 noisedB = noisedB *1.2
306 noisedB = noisedB *1.2
266 titleList = []
307 titleList = []
267 for i in range(len(noisedB)):
308 for i in range(len(noisedB)):
268 title = "%.2f"%noisedB[i]
309 title = "%.2f"%noisedB[i]
269 titleList.append(title)
310 titleList.append(title)
270
311
271 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
312 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
272 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
313 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
273 figuretitle = "Spc Radar Data: %s"%dateTime
314 figuretitle = "Spc Radar Data: %s"%dateTime
274
315
275 cleardata = True
316 cleardata = True
276
317
277 plotObj = self.plotObjList[self.plotObjIndex]
318 plotObj = self.plotObjList[self.plotObjIndex]
278
319
279 plotObj.plotPcolor(data,
320 plotObj.plotPcolor(data=data,
280 x=x,
321 x=x,
281 y=y,
322 y=y,
282 channelList=channelList,
323 channelList=channelList,
283 xmin=xmin,
324 xmin=xmin,
284 xmax=xmax,
325 xmax=xmax,
285 ymin=ymin,
326 ymin=ymin,
286 ymax=ymax,
327 ymax=ymax,
287 minvalue=minvalue,
328 minvalue=minvalue,
288 maxvalue=maxvalue,
329 maxvalue=maxvalue,
289 figuretitle=figuretitle,
330 figuretitle=figuretitle,
290 xrangestep=None,
331 xrangestep=None,
291 deltax=None,
332 deltax=None,
292 save=False,
333 save=save,
293 gpath='./',
334 gpath=gpath,
294 clearData=True
335 cleardata=cleardata
295 )
336 )
296
337
297 self.plotObjIndex += 1
338 self.plotObjIndex += 1
298
339
299
340
300 def writeData(self, wrpath, blocksPerFile):
341 def writeData(self, wrpath, blocksPerFile):
301
342
302 if self.dataOutObj.flagNoData:
343 if self.dataOutObj.flagNoData:
303 return 0
344 return 0
304
345
305 if len(self.writerObjList) <= self.writerObjIndex:
346 if len(self.writerObjList) <= self.writerObjIndex:
306 self.addWriter(wrpath, blocksPerFile)
347 self.addWriter(wrpath, blocksPerFile)
307
348
308 self.writerObjList[self.writerObjIndex].putData()
349 self.writerObjList[self.writerObjIndex].putData()
309
350
310 self.writerObjIndex += 1
351 self.writerObjIndex += 1
311
352
312 def integrator(self, N=None, timeInterval=None):
353 def integrator(self, N=None, timeInterval=None):
313
354
314 if self.dataOutObj.flagNoData:
355 if self.dataOutObj.flagNoData:
315 return 0
356 return 0
316
357
317 if len(self.integratorObjList) <= self.integratorObjIndex:
358 if len(self.integratorObjList) <= self.integratorObjIndex:
318 self.addIntegrator(N,timeInterval)
359 self.addIntegrator(N,timeInterval)
319
360
320 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
361 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
321 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
362 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
322
363
323 if myIncohIntObj.isReady:
364 if myIncohIntObj.isReady:
324 self.dataOutObj.data_spc = myIncohIntObj.data
365 self.dataOutObj.data_spc = myIncohIntObj.data
325 self.dataOutObj.nAvg = myIncohIntObj.navg
366 self.dataOutObj.nAvg = myIncohIntObj.navg
326 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
367 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
327 self.dataOutObj.flagNoData = False
368 self.dataOutObj.flagNoData = False
328
369
329 """Calcular el ruido"""
370 """Calcular el ruido"""
330 self.getNoise()
371 self.getNoise()
331 else:
372 else:
332 self.dataOutObj.flagNoData = True
373 self.dataOutObj.flagNoData = True
333
374
334 self.integratorObjIndex += 1
375 self.integratorObjIndex += 1
335
376
336
377
337 class SpectraHeisProcessor:
378 class SpectraHeisProcessor:
338
379
339 def __init__(self):
380 def __init__(self):
340
381
341 self.integratorObjIndex = None
382 self.integratorObjIndex = None
342 self.writerObjIndex = None
383 self.writerObjIndex = None
343 self.plotObjIndex = None
384 self.plotObjIndex = None
344 self.integratorObjList = []
385 self.integratorObjList = []
345 self.writerObjList = []
386 self.writerObjList = []
346 self.plotObjList = []
387 self.plotObjList = []
347 #self.noiseObj = Noise()
388 #self.noiseObj = Noise()
348
389
349 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
390 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
350
391
351 if nFFTPoints == None:
392 if nFFTPoints == None:
352 nFFTPoints = self.dataInObj.nHeights
393 nFFTPoints = self.dataInObj.nHeights
353
394
354 self.dataInObj = dataInObj
395 self.dataInObj = dataInObj
355
396
356 if dataOutObj == None:
397 if dataOutObj == None:
357 dataOutObj = SpectraHeis()
398 dataOutObj = SpectraHeis()
358
399
359 self.dataOutObj = dataOutObj
400 self.dataOutObj = dataOutObj
360
401
361 return self.dataOutObj
402 return self.dataOutObj
362
403
363 def init(self):
404 def init(self):
364
405
365 self.dataOutObj.flagNoData = True
406 self.dataOutObj.flagNoData = True
366
407
367 if self.dataInObj.flagNoData:
408 if self.dataInObj.flagNoData:
368 return 0
409 return 0
369
410
370 self.integratorObjIndex = 0
411 self.integratorObjIndex = 0
371 self.writerObjIndex = 0
412 self.writerObjIndex = 0
372 self.plotObjIndex = 0
413 self.plotObjIndex = 0
373
414
374 if self.dataInObj.type == "Voltage":
415 if self.dataInObj.type == "Voltage":
375 self.__updateObjFromInput()
416 self.__updateObjFromInput()
376 self.__getFft()
417 self.__getFft()
377 self.dataOutObj.flagNoData = False
418 self.dataOutObj.flagNoData = False
378 return
419 return
379
420
380 #Other kind of data
421 #Other kind of data
381 if self.dataInObj.type == "SpectraHeis":
422 if self.dataInObj.type == "SpectraHeis":
382 self.dataOutObj.copy(self.dataInObj)
423 self.dataOutObj.copy(self.dataInObj)
383 self.dataOutObj.flagNoData = False
424 self.dataOutObj.flagNoData = False
384 return
425 return
385
426
386 raise ValueError, "The type is not valid"
427 raise ValueError, "The type is not valid"
387
428
388 def __updateObjFromInput(self):
429 def __updateObjFromInput(self):
389
430
390 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
431 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
391 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
432 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
392 self.dataOutObj.channelList = self.dataInObj.channelList
433 self.dataOutObj.channelList = self.dataInObj.channelList
393 self.dataOutObj.heightList = self.dataInObj.heightList
434 self.dataOutObj.heightList = self.dataInObj.heightList
394 self.dataOutObj.dtype = self.dataInObj.dtype
435 self.dataOutObj.dtype = self.dataInObj.dtype
395 self.dataOutObj.nHeights = self.dataInObj.nHeights
436 self.dataOutObj.nHeights = self.dataInObj.nHeights
396 self.dataOutObj.nChannels = self.dataInObj.nChannels
437 self.dataOutObj.nChannels = self.dataInObj.nChannels
397 self.dataOutObj.nBaud = self.dataInObj.nBaud
438 self.dataOutObj.nBaud = self.dataInObj.nBaud
398 self.dataOutObj.nCode = self.dataInObj.nCode
439 self.dataOutObj.nCode = self.dataInObj.nCode
399 self.dataOutObj.code = self.dataInObj.code
440 self.dataOutObj.code = self.dataInObj.code
400 self.dataOutObj.nProfiles = 1
441 self.dataOutObj.nProfiles = 1
401 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
442 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
402 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
443 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
403 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
444 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
404 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
445 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
405 self.dataOutObj.utctime = self.dataInObj.utctime
446 self.dataOutObj.utctime = self.dataInObj.utctime
406 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
447 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
407 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
448 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
408 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
449 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
409 self.dataOutObj.nIncohInt = 1
450 self.dataOutObj.nIncohInt = 1
410
451
411 def __getFft(self):
452 def __getFft(self):
412
453
413 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
454 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
414 #print fft_volt
455 #print fft_volt
415 #calculo de self-spectra
456 #calculo de self-spectra
416 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
457 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
417
458
418 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
459 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
419 self.dataOutObj.data_spc = spc
460 self.dataOutObj.data_spc = spc
420
461
421 def getSpectra(self):
462 def getSpectra(self):
422
463
423 return self.dataOutObj.data_spc
464 return self.dataOutObj.data_spc
424
465
425 def getFrecuencies(self):
466 def getFrecuencies(self):
426
467
427 print self.nFFTPoints
468 print self.nFFTPoints
428 return numpy.arange(int(self.nFFTPoints))
469 return numpy.arange(int(self.nFFTPoints))
429
470
430 def addIntegrator(self,N,timeInterval):
471 def addIntegrator(self,N,timeInterval):
431
472
432 objIncohInt = IncoherentIntegration(N,timeInterval)
473 objIncohInt = IncoherentIntegration(N,timeInterval)
433 self.integratorObjList.append(objIncohInt)
474 self.integratorObjList.append(objIncohInt)
434
475
435 def integrator(self, N=None, timeInterval=None):
476 def integrator(self, N=None, timeInterval=None):
436
477
437 if self.dataOutObj.flagNoData:
478 if self.dataOutObj.flagNoData:
438 return 0
479 return 0
439
480
440 if len(self.integratorObjList) <= self.integratorObjIndex:
481 if len(self.integratorObjList) <= self.integratorObjIndex:
441 self.addIntegrator(N,timeInterval)
482 self.addIntegrator(N,timeInterval)
442
483
443 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
484 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
444 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
485 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
445
486
446 if myIncohIntObj.isReady:
487 if myIncohIntObj.isReady:
447 self.dataOutObj.data_spc = myIncohIntObj.data
488 self.dataOutObj.data_spc = myIncohIntObj.data
448 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
489 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
449 self.dataOutObj.flagNoData = False
490 self.dataOutObj.flagNoData = False
450
491
451 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
492 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
452 # self.getNoise(type="sort", parm=16)
493 # self.getNoise(type="sort", parm=16)
453
494
454 else:
495 else:
455 self.dataOutObj.flagNoData = True
496 self.dataOutObj.flagNoData = True
456
497
457 self.integratorObjIndex += 1
498 self.integratorObjIndex += 1
458
499
459
500
460 def addScope(self, idfigure, nframes, wintitle, driver):
501 def addScope(self, idfigure, nframes, wintitle, driver):
461
502
462 if idfigure==None:
503 if idfigure==None:
463 idfigure = self.plotObjIndex
504 idfigure = self.plotObjIndex
464
505
465 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
506 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
466 self.plotObjList.append(scopeObj)
507 self.plotObjList.append(scopeObj)
467
508
468 def plotScope(self,
509 def plotScope(self,
469 idfigure=None,
510 idfigure=None,
470 minvalue=None,
511 minvalue=None,
471 maxvalue=None,
512 maxvalue=None,
472 xmin=None,
513 xmin=None,
473 xmax=None,
514 xmax=None,
474 wintitle='',
515 wintitle='',
475 driver='plplot',
516 driver='plplot',
476 save=False,
517 save=False,
477 gpath=None,
518 gpath=None,
478 titleList=None,
519 titleList=None,
479 xlabelList=None,
520 xlabelList=None,
480 ylabelList=None):
521 ylabelList=None):
481
522
482 if self.dataOutObj.flagNoData:
523 if self.dataOutObj.flagNoData:
483 return 0
524 return 0
484
525
485 nframes = len(self.dataOutObj.channelList)
526 nframes = len(self.dataOutObj.channelList)
486
527
487 if len(self.plotObjList) <= self.plotObjIndex:
528 if len(self.plotObjList) <= self.plotObjIndex:
488 self.addScope(idfigure, nframes, wintitle, driver)
529 self.addScope(idfigure, nframes, wintitle, driver)
489
530
490
531
491 data1D = self.dataOutObj.data_spc
532 data1D = self.dataOutObj.data_spc
492
533
493 x = numpy.arange(self.dataOutObj.nHeights)
534 x = numpy.arange(self.dataOutObj.nHeights)
494
535
495 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
536 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
496
537
497 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
538 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
498 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
539 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
499
540
500 figureTitle = "Scope Plot Radar Data: " + date
541 figureTitle = "Scope Plot Radar Data: " + date
501
542
502 plotObj = self.plotObjList[self.plotObjIndex]
543 plotObj = self.plotObjList[self.plotObjIndex]
503
544
504 plotObj.plot1DArray(data1D,
545 plotObj.plot1DArray(data1D,
505 x,
546 x,
506 self.dataOutObj.channelList,
547 self.dataOutObj.channelList,
507 xmin,
548 xmin,
508 xmax,
549 xmax,
509 minvalue,
550 minvalue,
510 maxvalue,
551 maxvalue,
511 figureTitle,
552 figureTitle,
512 save,
553 save,
513 gpath)
554 gpath)
514
555
515 self.plotObjIndex += 1
556 self.plotObjIndex += 1
516
557
517 class IncoherentIntegration:
558 class IncoherentIntegration:
518
559
519 integ_counter = None
560 integ_counter = None
520 data = None
561 data = None
521 navg = None
562 navg = None
522 buffer = None
563 buffer = None
523 nIncohInt = None
564 nIncohInt = None
524
565
525 def __init__(self, N = None, timeInterval = None):
566 def __init__(self, N = None, timeInterval = None):
526 """
567 """
527 N
568 N
528 timeInterval - interval time [min], integer value
569 timeInterval - interval time [min], integer value
529 """
570 """
530
571
531 self.data = None
572 self.data = None
532 self.navg = None
573 self.navg = None
533 self.buffer = None
574 self.buffer = None
534 self.timeOut = None
575 self.timeOut = None
535 self.exitCondition = False
576 self.exitCondition = False
536 self.isReady = False
577 self.isReady = False
537 self.nIncohInt = N
578 self.nIncohInt = N
538 self.integ_counter = 0
579 self.integ_counter = 0
539 if timeInterval!=None:
580 if timeInterval!=None:
540 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
581 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
541
582
542 if ((timeInterval==None) and (N==None)):
583 if ((timeInterval==None) and (N==None)):
543 print 'N = None ; timeInterval = None'
584 print 'N = None ; timeInterval = None'
544 sys.exit(0)
585 sys.exit(0)
545 elif timeInterval == None:
586 elif timeInterval == None:
546 self.timeFlag = False
587 self.timeFlag = False
547 else:
588 else:
548 self.timeFlag = True
589 self.timeFlag = True
549
590
550
591
551 def exe(self,data,timeOfData):
592 def exe(self,data,timeOfData):
552 """
593 """
553 data
594 data
554
595
555 timeOfData [seconds]
596 timeOfData [seconds]
556 """
597 """
557
598
558 if self.timeFlag:
599 if self.timeFlag:
559 if self.timeOut == None:
600 if self.timeOut == None:
560 self.timeOut = timeOfData + self.timeIntervalInSeconds
601 self.timeOut = timeOfData + self.timeIntervalInSeconds
561
602
562 if timeOfData < self.timeOut:
603 if timeOfData < self.timeOut:
563 if self.buffer == None:
604 if self.buffer == None:
564 self.buffer = data
605 self.buffer = data
565 else:
606 else:
566 self.buffer = self.buffer + data
607 self.buffer = self.buffer + data
567 self.integ_counter += 1
608 self.integ_counter += 1
568 else:
609 else:
569 self.exitCondition = True
610 self.exitCondition = True
570
611
571 else:
612 else:
572 if self.integ_counter < self.nIncohInt:
613 if self.integ_counter < self.nIncohInt:
573 if self.buffer == None:
614 if self.buffer == None:
574 self.buffer = data
615 self.buffer = data
575 else:
616 else:
576 self.buffer = self.buffer + data
617 self.buffer = self.buffer + data
577
618
578 self.integ_counter += 1
619 self.integ_counter += 1
579
620
580 if self.integ_counter == self.nIncohInt:
621 if self.integ_counter == self.nIncohInt:
581 self.exitCondition = True
622 self.exitCondition = True
582
623
583 if self.exitCondition:
624 if self.exitCondition:
584 self.data = self.buffer
625 self.data = self.buffer
585 self.navg = self.integ_counter
626 self.navg = self.integ_counter
586 self.isReady = True
627 self.isReady = True
587 self.buffer = None
628 self.buffer = None
588 self.timeOut = None
629 self.timeOut = None
589 self.integ_counter = 0
630 self.integ_counter = 0
590 self.exitCondition = False
631 self.exitCondition = False
591
632
592 if self.timeFlag:
633 if self.timeFlag:
593 self.buffer = data
634 self.buffer = data
594 self.timeOut = timeOfData + self.timeIntervalInSeconds
635 self.timeOut = timeOfData + self.timeIntervalInSeconds
595 else:
636 else:
596 self.isReady = False
637 self.isReady = False
597 No newline at end of file
638
@@ -1,372 +1,377
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os
7 import os
8 import sys
8 import sys
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11 import time
11 import time
12
12
13 path = os.path.split(os.getcwd())[0]
13 path = os.path.split(os.getcwd())[0]
14 sys.path.append(path)
14 sys.path.append(path)
15
15
16 from Data.JROData import Voltage
16 from Data.JROData import Voltage
17 from IO.VoltageIO import VoltageWriter
17 from IO.VoltageIO import VoltageWriter
18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
19
19
20 class VoltageProcessor:
20 class VoltageProcessor:
21
21
22 dataInObj = None
22 dataInObj = None
23 dataOutObj = None
23 dataOutObj = None
24 integratorObjIndex = None
24 integratorObjIndex = None
25 writerObjIndex = None
25 writerObjIndex = None
26 integratorObjList = None
26 integratorObjList = None
27 writerObjList = None
27 writerObjList = None
28
28
29 def __init__(self):
29 def __init__(self):
30 self.integratorObjIndex = None
30 self.integratorObjIndex = None
31 self.writerObjIndex = None
31 self.writerObjIndex = None
32 self.plotObjIndex = None
32 self.plotObjIndex = None
33 self.integratorObjList = []
33 self.integratorObjList = []
34 self.writerObjList = []
34 self.writerObjList = []
35 self.plotObjList = []
35 self.plotObjList = []
36
36
37 def setup(self,dataInObj=None,dataOutObj=None):
37 def setup(self,dataInObj=None,dataOutObj=None):
38 self.dataInObj = dataInObj
38 self.dataInObj = dataInObj
39
39
40 if self.dataOutObj == None:
40 if self.dataOutObj == None:
41 dataOutObj = Voltage()
41 dataOutObj = Voltage()
42
42
43 self.dataOutObj = dataOutObj
43 self.dataOutObj = dataOutObj
44
44
45 return self.dataOutObj
45 return self.dataOutObj
46
46
47 def init(self):
47 def init(self):
48 self.integratorObjIndex = 0
48 self.integratorObjIndex = 0
49 self.writerObjIndex = 0
49 self.writerObjIndex = 0
50 self.plotObjIndex = 0
50 self.plotObjIndex = 0
51
51
52 if not(self.dataInObj.flagNoData):
52 if not(self.dataInObj.flagNoData):
53 self.dataOutObj.copy(self.dataInObj)
53 self.dataOutObj.copy(self.dataInObj)
54 # No necesita copiar en cada init() los atributos de dataInObj
54 # No necesita copiar en cada init() los atributos de dataInObj
55 # la copia deberia hacerse por cada nuevo bloque de datos
55 # la copia deberia hacerse por cada nuevo bloque de datos
56
56
57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
59 self.plotObjList.append(rtiObj)
59 self.plotObjList.append(rtiObj)
60
60
61 def plotRti(self, idfigure=None,
61 def plotRti(self, idfigure=None,
62 starttime=None,
62 starttime=None,
63 endtime=None,
63 endtime=None,
64 rangemin=None,
64 rangemin=None,
65 rangemax=None,
65 rangemax=None,
66 minvalue=None,
66 minvalue=None,
67 maxvalue=None,
67 maxvalue=None,
68 wintitle='',
68 wintitle='',
69 driver='plplot',
69 driver='plplot',
70 colormap='br_green',
70 colormap='br_greeen',
71 colorbar=True,
71 colorbar=True,
72 showprofile=False,
72 showprofile=False,
73 xrangestep=None,
73 xrangestep=None,
74 save=False,
74 save=False,
75 gpath=None):
75 gpath=None):
76
76
77 if self.dataOutObj.flagNoData:
77 if self.dataOutObj.flagNoData:
78 return 0
78 return 0
79
79
80 nframes = len(self.dataOutObj.channelList)
80 nframes = len(self.dataOutObj.channelList)
81
81
82 if len(self.plotObjList) <= self.plotObjIndex:
82 if len(self.plotObjList) <= self.plotObjIndex:
83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
84
84
85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
86 data = 10*numpy.log10(data.real)
86 data = 10*numpy.log10(data.real)
87
87
88 # currenttime = self.dataOutObj.utctime
88 # currenttime = self.dataOutObj.utctime
89 # if timezone == "lt":
89 # if timezone == "lt":
90 currenttime = self.dataOutObj.utctime - time.timezone
90 currenttime = self.dataOutObj.utctime - time.timezone
91
91
92 range = self.dataOutObj.heightList
92 range = self.dataOutObj.heightList
93
93
94 channelList = self.dataOutObj.channelList
94 channelList = self.dataOutObj.channelList
95
95
96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
99
99
100 figuretitle = "RTI Plot Radar Data" #+ date
100 figuretitle = "RTI Plot Radar Data" #+ date
101
101
102 plotObj = self.plotObjList[self.plotObjIndex]
102 plotObj = self.plotObjList[self.plotObjIndex]
103
103
104 cleardata = False
104 cleardata = False
105
105
106 plotObj.plotPcolor(data,
106 deltax = self.dataOutObj.timeInterval
107 currenttime,
107
108 range,
108 plotObj.plotPcolor(data=data,
109 channelList,
109 x=currenttime,
110 starttime,
110 y=range,
111 endtime,
111 channelList=channelList,
112 rangemin,
112 xmin=starttime,
113 rangemax,
113 xmax=endtime,
114 minvalue,
114 ymin=rangemin,
115 maxvalue,
115 ymax=rangemax,
116 figuretitle,
116 minvalue=minvalue,
117 xrangestep,
117 maxvalue=maxvalue,
118 save,
118 figuretitle=figuretitle,
119 gpath,
119 xrangestep=xrangestep,
120 cleardata)
120 deltax=deltax,
121 save=save,
122 gpath=gpath,
123 cleardata=cleardata)
124
121
125
122 self.plotObjIndex += 1
126 self.plotObjIndex += 1
123
127
124 def addScope(self, idfigure, nframes, wintitle, driver):
128 def addScope(self, idfigure, nframes, wintitle, driver):
125 if idfigure==None:
129 if idfigure==None:
126 idfigure = self.plotObjIndex
130 idfigure = self.plotObjIndex
127
131
128 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
132 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
129 self.plotObjList.append(scopeObj)
133 self.plotObjList.append(scopeObj)
130
134
131 def plotScope(self,
135 def plotScope(self,
132 idfigure=None,
136 idfigure=None,
133 minvalue=None,
137 minvalue=None,
134 maxvalue=None,
138 maxvalue=None,
135 xmin=None,
139 xmin=None,
136 xmax=None,
140 xmax=None,
137 wintitle='',
141 wintitle='',
138 driver='plplot',
142 driver='plplot',
139 save=False,
143 save=False,
140 gpath=None,
144 gpath=None,
141 titleList=None,
145 titleList=None,
142 xlabelList=None,
146 xlabelList=None,
143 ylabelList=None,
147 ylabelList=None,
144 type="power"):
148 type="power"):
145
149
146 if self.dataOutObj.flagNoData:
150 if self.dataOutObj.flagNoData:
147 return 0
151 return 0
148
152
149 nframes = len(self.dataOutObj.channelList)
153 nframes = len(self.dataOutObj.channelList)
150
154
151 if len(self.plotObjList) <= self.plotObjIndex:
155 if len(self.plotObjList) <= self.plotObjIndex:
152 self.addScope(idfigure, nframes, wintitle, driver)
156 self.addScope(idfigure, nframes, wintitle, driver)
153
157
154
158
155 if type=="power":
159 if type=="power":
156 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
160 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
157 data1D = data1D.real
161 data1D = data1D.real
158
162
159 if type =="iq":
163 if type =="iq":
160 data1D = self.dataOutObj.data
164 data1D = self.dataOutObj.data
161
165
162 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
166 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
163
167
164 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
168 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
165 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
169 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
166
170
167 figureTitle = "Scope Plot Radar Data: " + date
171 figureTitle = "Scope Plot Radar Data: " + date
168
172
169 plotObj = self.plotObjList[self.plotObjIndex]
173 plotObj = self.plotObjList[self.plotObjIndex]
170
174
171 plotObj.plot1DArray(data1D,
175 plotObj.plot1DArray(data1D=data1D,
172 self.dataOutObj.heightList,
176 x=self.dataOutObj.heightList,
173 self.dataOutObj.channelList,
177 channelList=self.dataOutObj.channelList,
174 xmin,
178 xmin=xmin,
175 xmax,
179 xmax=xmax,
176 minvalue,
180 minvalue=minvalue,
177 maxvalue,
181 maxvalue=maxvalue,
178 figureTitle,
182 figureTitle=figureTitle,
179 save,
183 save=save,
180 gpath)
184 gpath=gpath)
185
181
186
182 self.plotObjIndex += 1
187 self.plotObjIndex += 1
183
188
184
189
185 def addIntegrator(self, *args):
190 def addIntegrator(self, *args):
186 objCohInt = CoherentIntegrator(*args)
191 objCohInt = CoherentIntegrator(*args)
187 self.integratorObjList.append(objCohInt)
192 self.integratorObjList.append(objCohInt)
188
193
189 def addWriter(self, *args):
194 def addWriter(self, *args):
190 writerObj = VoltageWriter(self.dataOutObj)
195 writerObj = VoltageWriter(self.dataOutObj)
191 writerObj.setup(*args)
196 writerObj.setup(*args)
192 self.writerObjList.append(writerObj)
197 self.writerObjList.append(writerObj)
193
198
194 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
199 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
195
200
196 if self.dataOutObj.flagNoData:
201 if self.dataOutObj.flagNoData:
197 return 0
202 return 0
198
203
199 if len(self.writerObjList) <= self.writerObjIndex:
204 if len(self.writerObjList) <= self.writerObjIndex:
200 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
205 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
201
206
202 self.writerObjList[self.writerObjIndex].putData()
207 self.writerObjList[self.writerObjIndex].putData()
203
208
204 self.writerObjIndex += 1
209 self.writerObjIndex += 1
205
210
206 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
211 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
207
212
208 if self.dataOutObj.flagNoData:
213 if self.dataOutObj.flagNoData:
209 return 0
214 return 0
210
215
211 if len(self.integratorObjList) <= self.integratorObjIndex:
216 if len(self.integratorObjList) <= self.integratorObjIndex:
212 self.addIntegrator(nCohInt, timeInterval, overlapping)
217 self.addIntegrator(nCohInt, timeInterval, overlapping)
213
218
214 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
219 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
215 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
220 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
216
221
217 self.dataOutObj.flagNoData = True
222 self.dataOutObj.flagNoData = True
218
223
219 if myCohIntObj.isReady:
224 if myCohIntObj.isReady:
220 self.dataOutObj.flagNoData = False
225 self.dataOutObj.flagNoData = False
221
226
222
227
223
228
224 class CoherentIntegrator:
229 class CoherentIntegrator:
225
230
226
231
227 __profIndex = 0
232 __profIndex = 0
228 __withOverapping = False
233 __withOverapping = False
229
234
230 __isByTime = False
235 __isByTime = False
231 __initime = None
236 __initime = None
232 __integrationtime = None
237 __integrationtime = None
233
238
234 __buffer = None
239 __buffer = None
235
240
236 isReady = False
241 isReady = False
237 nCohInt = None
242 nCohInt = None
238
243
239
244
240 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
245 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
241
246
242 """
247 """
243 Set the parameters of the integration class.
248 Set the parameters of the integration class.
244
249
245 Inputs:
250 Inputs:
246
251
247 nCohInt : Number of coherent integrations
252 nCohInt : Number of coherent integrations
248 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
253 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
249 overlapping :
254 overlapping :
250
255
251 """
256 """
252
257
253 self.__buffer = None
258 self.__buffer = None
254 self.isReady = False
259 self.isReady = False
255
260
256 if nCohInt == None and timeInterval == None:
261 if nCohInt == None and timeInterval == None:
257 raise ValueError, "nCohInt or timeInterval should be specified ..."
262 raise ValueError, "nCohInt or timeInterval should be specified ..."
258
263
259 if nCohInt != None:
264 if nCohInt != None:
260 self.nCohInt = nCohInt
265 self.nCohInt = nCohInt
261 self.__isByTime = False
266 self.__isByTime = False
262 else:
267 else:
263 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
268 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
264 self.__isByTime = True
269 self.__isByTime = True
265
270
266 if overlapping:
271 if overlapping:
267 self.__withOverapping = True
272 self.__withOverapping = True
268 self.__buffer = None
273 self.__buffer = None
269 else:
274 else:
270 self.__withOverapping = False
275 self.__withOverapping = False
271 self.__buffer = 0
276 self.__buffer = 0
272
277
273 self.__profIndex = 0
278 self.__profIndex = 0
274
279
275 def putData(self, data):
280 def putData(self, data):
276
281
277 """
282 """
278 Add a profile to the __buffer and increase in one the __profileIndex
283 Add a profile to the __buffer and increase in one the __profileIndex
279
284
280 """
285 """
281 if not self.__withOverapping:
286 if not self.__withOverapping:
282 self.__buffer += data
287 self.__buffer += data
283 self.__profIndex += 1
288 self.__profIndex += 1
284 return
289 return
285
290
286 #Overlapping data
291 #Overlapping data
287 nChannels, nHeis = data.shape
292 nChannels, nHeis = data.shape
288 data = numpy.reshape(data, (1, nChannels, nHeis))
293 data = numpy.reshape(data, (1, nChannels, nHeis))
289
294
290 if self.__buffer == None:
295 if self.__buffer == None:
291 self.__buffer = data
296 self.__buffer = data
292 self.__profIndex += 1
297 self.__profIndex += 1
293 return
298 return
294
299
295 if self.__profIndex < self.nCohInt:
300 if self.__profIndex < self.nCohInt:
296 self.__buffer = numpy.vstack((self.__buffer, data))
301 self.__buffer = numpy.vstack((self.__buffer, data))
297 self.__profIndex += 1
302 self.__profIndex += 1
298 return
303 return
299
304
300 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
305 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
301 self.__buffer[self.nCohInt-1] = data
306 self.__buffer[self.nCohInt-1] = data
302 #self.__profIndex = self.nCohInt
307 #self.__profIndex = self.nCohInt
303 return
308 return
304
309
305
310
306 def pushData(self):
311 def pushData(self):
307 """
312 """
308 Return the sum of the last profiles and the profiles used in the sum.
313 Return the sum of the last profiles and the profiles used in the sum.
309
314
310 Affected:
315 Affected:
311
316
312 self.__profileIndex
317 self.__profileIndex
313
318
314 """
319 """
315
320
316 if not self.__withOverapping:
321 if not self.__withOverapping:
317 data = self.__buffer
322 data = self.__buffer
318 nCohInt = self.__profIndex
323 nCohInt = self.__profIndex
319
324
320 self.__buffer = 0
325 self.__buffer = 0
321 self.__profIndex = 0
326 self.__profIndex = 0
322
327
323 return data, nCohInt
328 return data, nCohInt
324
329
325 #Overlapping data
330 #Overlapping data
326 data = numpy.sum(self.__buffer, axis=0)
331 data = numpy.sum(self.__buffer, axis=0)
327 nCohInt = self.__profIndex
332 nCohInt = self.__profIndex
328
333
329 return data, nCohInt
334 return data, nCohInt
330
335
331 def byProfiles(self, data):
336 def byProfiles(self, data):
332
337
333 self.isReady = False
338 self.isReady = False
334 avg_data = None
339 avg_data = None
335
340
336 self.putData(data)
341 self.putData(data)
337
342
338 if self.__profIndex == self.nCohInt:
343 if self.__profIndex == self.nCohInt:
339 avg_data, nCohInt = self.pushData()
344 avg_data, nCohInt = self.pushData()
340 self.isReady = True
345 self.isReady = True
341
346
342 return avg_data
347 return avg_data
343
348
344 def byTime(self, data, datatime):
349 def byTime(self, data, datatime):
345
350
346 self.isReady = False
351 self.isReady = False
347 avg_data = None
352 avg_data = None
348
353
349 if self.__initime == None:
354 if self.__initime == None:
350 self.__initime = datatime
355 self.__initime = datatime
351
356
352 self.putData(data)
357 self.putData(data)
353
358
354 if (datatime - self.__initime) >= self.__integrationtime:
359 if (datatime - self.__initime) >= self.__integrationtime:
355 avg_data, nCohInt = self.pushData()
360 avg_data, nCohInt = self.pushData()
356 self.nCohInt = nCohInt
361 self.nCohInt = nCohInt
357 self.isReady = True
362 self.isReady = True
358
363
359 return avg_data
364 return avg_data
360
365
361 def exe(self, data, datatime=None):
366 def exe(self, data, datatime=None):
362
367
363 if not self.__isByTime:
368 if not self.__isByTime:
364 avg_data = self.byProfiles(data)
369 avg_data = self.byProfiles(data)
365 else:
370 else:
366 avg_data = self.byTime(data, datatime)
371 avg_data = self.byTime(data, datatime)
367
372
368 self.data = avg_data
373 self.data = avg_data
369
374
370 return avg_data
375 return avg_data
371
376
372
377
General Comments 0
You need to be logged in to leave comments. Login now