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