@@ -1,219 +1,229 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import copy |
|
8 | import copy | |
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from IO.JROHeaderIO import SystemHeader, RadarControllerHeader |
|
14 | from IO.JROHeaderIO import SystemHeader, RadarControllerHeader | |
15 |
|
15 | |||
16 | class JROData: |
|
16 | class JROData: | |
17 |
|
17 | |||
18 | # m_BasicHeader = BasicHeader() |
|
18 | # m_BasicHeader = BasicHeader() | |
19 | # m_ProcessingHeader = ProcessingHeader() |
|
19 | # m_ProcessingHeader = ProcessingHeader() | |
20 |
|
20 | |||
21 | systemHeaderObj = SystemHeader() |
|
21 | systemHeaderObj = SystemHeader() | |
22 |
|
22 | |||
23 | radarControllerHeaderObj = RadarControllerHeader() |
|
23 | radarControllerHeaderObj = RadarControllerHeader() | |
24 |
|
24 | |||
25 | # data = None |
|
25 | # data = None | |
26 |
|
26 | |||
27 | type = None |
|
27 | type = None | |
28 |
|
28 | |||
29 | dtype = None |
|
29 | dtype = None | |
30 |
|
30 | |||
31 | nChannels = None |
|
31 | nChannels = None | |
32 |
|
32 | |||
33 | nHeights = None |
|
33 | nHeights = None | |
34 |
|
34 | |||
35 | nProfiles = None |
|
35 | nProfiles = None | |
36 |
|
36 | |||
37 | heightList = None |
|
37 | heightList = None | |
38 |
|
38 | |||
39 | channelList = None |
|
39 | channelList = None | |
40 |
|
40 | |||
41 | channelIndexList = None |
|
41 | channelIndexList = None | |
42 |
|
42 | |||
43 |
flagNoData = |
|
43 | flagNoData = True | |
44 |
|
44 | |||
45 | flagTimeBlock = False |
|
45 | flagTimeBlock = False | |
46 |
|
46 | |||
47 |
|
|
47 | utctime = None | |
|
48 | ||||
|
49 | blocksize = None | |||
48 |
|
50 | |||
49 | nCode = None |
|
51 | nCode = None | |
50 |
|
52 | |||
51 | nBaud = None |
|
53 | nBaud = None | |
52 |
|
54 | |||
53 | code = None |
|
55 | code = None | |
54 |
|
56 | |||
55 | flagDecodeData = True #asumo q la data esta decodificada |
|
57 | flagDecodeData = True #asumo q la data esta decodificada | |
56 |
|
58 | |||
57 | flagDeflipData = True #asumo q la data esta sin flip |
|
59 | flagDeflipData = True #asumo q la data esta sin flip | |
58 |
|
60 | |||
59 | flagShiftFFT = False |
|
61 | flagShiftFFT = False | |
60 |
|
62 | |||
61 | ippSeconds = None |
|
63 | ippSeconds = None | |
62 |
|
64 | |||
63 |
|
65 | |||
64 | def __init__(self): |
|
66 | def __init__(self): | |
65 |
|
67 | |||
66 | raise ValueError, "This class has not been implemented" |
|
68 | raise ValueError, "This class has not been implemented" | |
67 |
|
69 | |||
68 | def copy(self, inputObj=None): |
|
70 | def copy(self, inputObj=None): | |
69 |
|
71 | |||
70 | if inputObj == None: |
|
72 | if inputObj == None: | |
71 | return copy.deepcopy(self) |
|
73 | return copy.deepcopy(self) | |
72 |
|
74 | |||
73 | for key in inputObj.__dict__.keys(): |
|
75 | for key in inputObj.__dict__.keys(): | |
74 | self.__dict__[key] = inputObj.__dict__[key] |
|
76 | self.__dict__[key] = inputObj.__dict__[key] | |
75 |
|
77 | |||
76 | def deepcopy(self): |
|
78 | def deepcopy(self): | |
77 |
|
79 | |||
78 | return copy.deepcopy(self) |
|
80 | return copy.deepcopy(self) | |
79 |
|
81 | |||
80 | class Voltage(JROData): |
|
82 | class Voltage(JROData): | |
81 |
|
83 | |||
82 | nCohInt = None |
|
84 | nCohInt = None | |
83 |
|
85 | |||
84 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
86 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
85 | data = None |
|
87 | data = None | |
86 |
|
88 | |||
87 | def __init__(self): |
|
89 | def __init__(self): | |
88 | ''' |
|
90 | ''' | |
89 | Constructor |
|
91 | Constructor | |
90 | ''' |
|
92 | ''' | |
91 |
|
93 | |||
92 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
94 | self.radarControllerHeaderObj = RadarControllerHeader() | |
93 |
|
95 | |||
94 | self.systemHeaderObj = SystemHeader() |
|
96 | self.systemHeaderObj = SystemHeader() | |
95 |
|
97 | |||
96 | self.type = "Voltage" |
|
98 | self.type = "Voltage" | |
97 |
|
99 | |||
98 | self.data = None |
|
100 | self.data = None | |
99 |
|
101 | |||
100 | self.dtype = None |
|
102 | self.dtype = None | |
101 |
|
103 | |||
102 | self.nChannels = 0 |
|
104 | self.nChannels = 0 | |
103 |
|
105 | |||
104 | self.nHeights = 0 |
|
106 | self.nHeights = 0 | |
105 |
|
107 | |||
106 | self.nProfiles = None |
|
108 | self.nProfiles = None | |
107 |
|
109 | |||
108 | self.heightList = None |
|
110 | self.heightList = None | |
109 |
|
111 | |||
110 | self.channelList = None |
|
112 | self.channelList = None | |
111 |
|
113 | |||
112 | self.channelIndexList = None |
|
114 | self.channelIndexList = None | |
113 |
|
115 | |||
114 | self.flagNoData = True |
|
116 | self.flagNoData = True | |
115 |
|
117 | |||
116 | self.flagTimeBlock = False |
|
118 | self.flagTimeBlock = False | |
117 |
|
119 | |||
118 |
self. |
|
120 | self.utctime = None | |
119 |
|
121 | |||
120 | self.nCohInt = None |
|
122 | self.nCohInt = None | |
|
123 | ||||
|
124 | self.blocksize = None | |||
121 |
|
125 | |||
122 | class Spectra(JROData): |
|
126 | class Spectra(JROData): | |
123 |
|
127 | |||
124 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
128 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
125 | data_spc = None |
|
129 | data_spc = None | |
126 |
|
130 | |||
127 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
131 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
128 | data_cspc = None |
|
132 | data_cspc = None | |
129 |
|
133 | |||
130 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
134 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
131 | data_dc = None |
|
135 | data_dc = None | |
132 |
|
136 | |||
133 | nFFTPoints = None |
|
137 | nFFTPoints = None | |
134 |
|
138 | |||
135 | nPairs = None |
|
139 | nPairs = None | |
136 |
|
140 | |||
137 | pairsList = None |
|
141 | pairsList = None | |
138 |
|
142 | |||
139 | nIncohInt = None |
|
143 | nIncohInt = None | |
140 |
|
144 | |||
141 | def __init__(self): |
|
145 | def __init__(self): | |
142 | ''' |
|
146 | ''' | |
143 | Constructor |
|
147 | Constructor | |
144 | ''' |
|
148 | ''' | |
145 |
|
149 | |||
146 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
150 | self.radarControllerHeaderObj = RadarControllerHeader() | |
147 |
|
151 | |||
148 | self.systemHeaderObj = SystemHeader() |
|
152 | self.systemHeaderObj = SystemHeader() | |
149 |
|
153 | |||
150 | self.type = "Spectra" |
|
154 | self.type = "Spectra" | |
151 |
|
155 | |||
152 | # self.data = None |
|
156 | # self.data = None | |
153 |
|
157 | |||
154 | self.dtype = None |
|
158 | self.dtype = None | |
155 |
|
159 | |||
156 | self.nChannels = 0 |
|
160 | self.nChannels = 0 | |
157 |
|
161 | |||
158 | self.nHeights = 0 |
|
162 | self.nHeights = 0 | |
159 |
|
163 | |||
160 | self.nProfiles = None |
|
164 | self.nProfiles = None | |
161 |
|
165 | |||
162 | self.heightList = None |
|
166 | self.heightList = None | |
163 |
|
167 | |||
164 | self.channelList = None |
|
168 | self.channelList = None | |
165 |
|
169 | |||
166 | self.channelIndexList = None |
|
170 | self.channelIndexList = None | |
167 |
|
171 | |||
168 | self.flagNoData = True |
|
172 | self.flagNoData = True | |
169 |
|
173 | |||
170 | self.flagTimeBlock = False |
|
174 | self.flagTimeBlock = False | |
171 |
|
175 | |||
172 |
self. |
|
176 | self.utctime = None | |
173 |
|
177 | |||
174 | self.nIncohInt = None |
|
178 | self.nIncohInt = None | |
175 |
|
179 | |||
|
180 | self.blocksize = None | |||
|
181 | ||||
176 |
|
182 | |||
177 | class SpectraHeis(JROData): |
|
183 | class SpectraHeis(JROData): | |
178 |
|
184 | |||
179 | data_spc = None |
|
185 | data_spc = None | |
180 |
|
186 | |||
181 | data_cspc = None |
|
187 | data_cspc = None | |
182 |
|
188 | |||
183 | data_dc = None |
|
189 | data_dc = None | |
184 |
|
190 | |||
185 | nFFTPoints = None |
|
191 | nFFTPoints = None | |
186 |
|
192 | |||
187 | nPairs = None |
|
193 | nPairs = None | |
188 |
|
194 | |||
189 | pairsList = None |
|
195 | pairsList = None | |
190 |
|
196 | |||
191 | nIncohInt = None |
|
197 | nIncohInt = None | |
192 |
|
198 | |||
193 | def __init__(self): |
|
199 | def __init__(self): | |
194 |
|
200 | |||
195 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
201 | self.radarControllerHeaderObj = RadarControllerHeader() | |
196 |
|
202 | |||
197 | self.systemHeaderObj = SystemHeader() |
|
203 | self.systemHeaderObj = SystemHeader() | |
198 |
|
204 | |||
199 | self.type = "SpectraHeis" |
|
205 | self.type = "SpectraHeis" | |
200 |
|
206 | |||
201 | self.dtype = None |
|
207 | self.dtype = None | |
202 |
|
208 | |||
203 | self.nChannels = 0 |
|
209 | self.nChannels = 0 | |
204 |
|
210 | |||
205 | self.nHeights = 0 |
|
211 | self.nHeights = 0 | |
206 |
|
212 | |||
207 | self.nProfiles = None |
|
213 | self.nProfiles = None | |
208 |
|
214 | |||
209 | self.heightList = None |
|
215 | self.heightList = None | |
210 |
|
216 | |||
211 | self.channelList = None |
|
217 | self.channelList = None | |
212 |
|
218 | |||
213 | self.channelIndexList = None |
|
219 | self.channelIndexList = None | |
214 |
|
220 | |||
215 | self.flagNoData = True |
|
221 | self.flagNoData = True | |
216 |
|
222 | |||
217 | self.flagTimeBlock = False |
|
223 | self.flagTimeBlock = False | |
218 |
|
224 | |||
219 | self.nPairs = 0 |
|
225 | self.nPairs = 0 | |
|
226 | ||||
|
227 | self.utctime = None | |||
|
228 | ||||
|
229 | self.blocksize = None |
@@ -1,351 +1,393 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import time |
|
3 | import time | |
4 | import os |
|
4 | import os | |
5 | from schainPlotLib import Driver |
|
5 | from schainPlotLib import Driver | |
6 |
|
6 | |||
7 | class Figure: |
|
7 | class Figure: | |
|
8 | ||||
8 | __isDriverOpen = False |
|
9 | __isDriverOpen = False | |
9 | __isFigureOpen = False |
|
10 | __isFigureOpen = False | |
10 | __isConfig = False |
|
11 | __isConfig = False | |
|
12 | ||||
11 | drvObj = None |
|
13 | drvObj = None | |
|
14 | driver = None | |||
12 | idfigure = None |
|
15 | idfigure = None | |
13 | nframes = None |
|
16 | nframes = None | |
14 | wintitle = None |
|
17 | wintitle = None | |
15 | colormap = None |
|
18 | colormap = None | |
16 | driver = None |
|
|||
17 | overplot = None |
|
19 | overplot = None | |
|
20 | colorbar = None | |||
|
21 | ||||
|
22 | frameObjList = [] | |||
|
23 | ||||
|
24 | xw = None | |||
|
25 | yw = None | |||
|
26 | ||||
18 | xmin = None |
|
27 | xmin = None | |
19 | xmax = None |
|
28 | xmax = None | |
20 | ymin = None |
|
29 | ymin = None | |
21 | ymax = None |
|
30 | ymax = None | |
|
31 | ||||
22 | minvalue = None |
|
32 | minvalue = None | |
23 | maxvalue = None |
|
33 | maxvalue = None | |
24 | deltax = None |
|
34 | deltax = None | |
25 | deltay = None |
|
35 | deltay = None | |
26 | frameObjList = [] |
|
36 | ||
|
37 | ||||
27 | figuretitle = "" |
|
38 | figuretitle = "" | |
28 | xrangestep = None |
|
39 | xrangestep = None | |
29 |
|
40 | |||
30 | def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args): |
|
41 | def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args): | |
31 |
|
42 | |||
|
43 | self.__isDriverOpen = False | |||
|
44 | self.__isFigureOpen = False | |||
|
45 | self.__isConfig = False | |||
|
46 | ||||
32 | self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar) |
|
47 | self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar) | |
33 | self.driver = driver |
|
48 | self.driver = driver | |
34 | self.idfigure = idfigure |
|
49 | self.idfigure = idfigure | |
35 | self.xw = xw |
|
|||
36 | self.yw = yw |
|
|||
37 | self.nframes = nframes |
|
50 | self.nframes = nframes | |
38 | self.wintitle = wintitle |
|
51 | self.wintitle = wintitle | |
39 | self.colormap = colormap |
|
52 | self.colormap = colormap | |
40 | self.overplot = overplot |
|
53 | self.overplot = overplot | |
41 | self.colorbar = colorbar |
|
54 | self.colorbar = colorbar | |
|
55 | ||||
|
56 | self.xw = xw | |||
|
57 | self.yw = yw | |||
|
58 | ||||
|
59 | self.frameObjList = [] | |||
|
60 | ||||
42 | # self.showGraph1 = args[0] |
|
61 | # self.showGraph1 = args[0] | |
43 | # self.showGraph2 = args[1] |
|
62 | # self.showGraph2 = args[1] | |
44 |
|
63 | |||
45 | self.drvObj.driver.setFigure() |
|
64 | self.drvObj.driver.setFigure() | |
46 | self.drvObj.driver.setColormap(colormap) |
|
65 | self.drvObj.driver.setColormap(colormap) | |
47 |
|
||||
48 |
|
||||
49 |
|
66 | |||
50 | def __openDriver(self): |
|
67 | def __openDriver(self): | |
|
68 | ||||
51 | self.drvObj.driver.openDriver() |
|
69 | self.drvObj.driver.openDriver() | |
52 |
|
70 | |||
53 | def __initFigure(self): |
|
71 | def __initFigure(self): | |
|
72 | ||||
54 | nrows, ncolumns = self.getSubplots() |
|
73 | nrows, ncolumns = self.getSubplots() | |
55 | self.drvObj.driver.openFigure() |
|
74 | self.drvObj.driver.openFigure() | |
56 | self.drvObj.driver.setFigTitle(self.figuretitle) |
|
75 | self.drvObj.driver.setFigTitle(self.figuretitle) | |
57 | self.drvObj.driver.setSubPlots(nrows, ncolumns) |
|
76 | self.drvObj.driver.setSubPlots(nrows, ncolumns) | |
58 |
|
77 | |||
|
78 | def selectFigure(self): | |||
|
79 | ||||
|
80 | self.drvObj.driver.selectFigure() | |||
|
81 | ||||
59 | def __isOutOfXRange(self,x): |
|
82 | def __isOutOfXRange(self,x): | |
60 | try: |
|
83 | try: | |
61 | if ((x>=self.xmin) and (x<self.xmax)): |
|
84 | if ((x>=self.xmin) and (x<self.xmax)): | |
62 | return 0 |
|
85 | return 0 | |
63 | except: |
|
86 | except: | |
64 | return 0 |
|
87 | return 0 | |
65 |
|
88 | |||
66 | return 1 |
|
89 | return 1 | |
67 |
|
90 | |||
68 | def changeXRange(self,x): |
|
91 | def changeXRange(self,x): | |
69 |
|
92 | |||
70 | pass |
|
93 | pass | |
71 |
|
94 | |||
72 | def __refresh(self): |
|
95 | def __refresh(self): | |
73 | self.drvObj.driver.refresh() |
|
96 | self.drvObj.driver.refresh() | |
74 |
|
97 | |||
75 | def createFrames(self): |
|
98 | def createFrames(self): | |
76 | raise ValueError, "No implemented" |
|
99 | raise ValueError, "No implemented" | |
77 |
|
100 | |||
78 | def save(self,filename): |
|
101 | def save(self,filename): | |
|
102 | ||||
79 | self.drvObj.driver.save(filename) |
|
103 | self.drvObj.driver.save(filename) | |
80 |
|
104 | |||
81 | def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'): |
|
105 | def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'): | |
82 |
|
106 | |||
83 | nx, ny = data1D.shape |
|
107 | nx, ny = data1D.shape | |
84 |
|
108 | |||
85 | if channelList == None: |
|
109 | if channelList == None: | |
86 | channelList = range(nx) |
|
110 | channelList = range(nx) | |
87 |
|
111 | |||
88 | if x == None: |
|
112 | if x == None: | |
89 | x = numpy.arange(data1D.size) |
|
113 | x = numpy.arange(data1D.size) | |
90 |
|
114 | |||
91 | if figuretitle == None: |
|
115 | if figuretitle == None: | |
92 | self.figuretitle = "" |
|
116 | self.figuretitle = "" | |
93 | else: |
|
117 | else: | |
94 | self.figuretitle = figuretitle |
|
118 | self.figuretitle = figuretitle | |
95 |
|
119 | |||
96 | if not(self.__isDriverOpen): |
|
120 | if not(self.__isDriverOpen): | |
97 | self.__openDriver() |
|
121 | self.__openDriver() | |
98 | self.__isDriverOpen = True |
|
122 | self.__isDriverOpen = True | |
99 |
|
123 | |||
100 | if not(self.__isConfig): |
|
124 | if not(self.__isConfig): | |
101 | self.xmin = xmin |
|
125 | self.xmin = xmin | |
102 | self.xmax = xmax |
|
126 | self.xmax = xmax | |
103 | self.minvalue = minvalue |
|
127 | self.minvalue = minvalue | |
104 | self.maxvalue = maxvalue |
|
128 | self.maxvalue = maxvalue | |
105 |
|
129 | |||
106 | if self.xmin == None: self.xmin = numpy.min(x) |
|
130 | if self.xmin == None: self.xmin = numpy.min(x) | |
107 | if self.xmax == None: self.xmax = numpy.max(x) |
|
131 | if self.xmax == None: self.xmax = numpy.max(x) | |
108 | if self.minvalue == None: self.minvalue = numpy.min(data1D) |
|
132 | if self.minvalue == None: self.minvalue = numpy.min(data1D) | |
109 | if self.maxvalue == None: self.maxvalue = numpy.max(data1D) |
|
133 | if self.maxvalue == None: self.maxvalue = numpy.max(data1D) | |
110 |
|
134 | |||
111 | self.createFrames() |
|
135 | self.createFrames() | |
112 | self.__isConfig = True |
|
136 | self.__isConfig = True | |
113 |
|
137 | |||
114 | if not(self.__isOutOfXRange(x)): |
|
138 | if not(self.__isOutOfXRange(x)): | |
115 | self.changeXRange(x) |
|
139 | self.changeXRange(x) | |
116 |
|
140 | |||
117 | if self.__isFigureOpen: |
|
141 | if self.__isFigureOpen: | |
118 | self.drvObj.driver.closePage() |
|
142 | self.drvObj.driver.closePage() | |
119 | self.__isFigureOpen = False |
|
143 | self.__isFigureOpen = False | |
120 |
|
144 | |||
121 |
|
145 | self.selectFigure() | ||
122 | self.__initFigure() |
|
146 | self.__initFigure() | |
123 |
|
147 | |||
124 | for channel in channelList: |
|
148 | for channel in channelList: | |
125 | frameObj = self.frameObjList[channel] |
|
149 | frameObj = self.frameObjList[channel] | |
126 | frameObj.init(xmin=self.xmin, |
|
150 | frameObj.init(xmin=self.xmin, | |
127 | xmax=self.xmax, |
|
151 | xmax=self.xmax, | |
128 | ymin=self.minvalue, |
|
152 | ymin=self.minvalue, | |
129 | ymax=self.maxvalue, |
|
153 | ymax=self.maxvalue, | |
130 | minvalue=self.minvalue, |
|
154 | minvalue=self.minvalue, | |
131 | maxvalue=self.maxvalue) |
|
155 | maxvalue=self.maxvalue) | |
132 |
|
156 | |||
133 | for channel in channelList: |
|
157 | for channel in channelList: | |
134 | dataCh = data1D[channel,:] |
|
158 | dataCh = data1D[channel,:] | |
135 | frameObj = self.frameObjList[channel] |
|
159 | frameObj = self.frameObjList[channel] | |
136 | # frameObj.clearData() |
|
160 | # frameObj.clearData() | |
137 | frameObj.plot(x, dataCh) |
|
161 | frameObj.plot(x, dataCh) | |
138 |
|
162 | |||
139 | # frameObj.refresh() |
|
163 | # frameObj.refresh() | |
140 | self.__refresh() |
|
164 | self.__refresh() | |
141 |
|
165 | |||
142 |
|
166 | |||
143 |
|
167 | |||
144 | if save: |
|
168 | if save: | |
145 | # self.colorplotObj.setFigure(indexPlot) |
|
169 | # self.colorplotObj.setFigure(indexPlot) | |
146 |
|
170 | |||
147 | path = gpath |
|
171 | path = gpath | |
148 | now = datetime.datetime.now() |
|
172 | now = datetime.datetime.now() | |
149 | file = "scope_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond) |
|
173 | file = "scope_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond) | |
150 | filename = os.path.join(path,file) |
|
174 | filename = os.path.join(path,file) | |
151 | self.save(filename) |
|
175 | self.save(filename) | |
152 |
|
176 | |||
153 |
|
177 | |||
154 |
|
178 | |||
155 |
|
179 | |||
156 | def plotPcolor(self,data, |
|
180 | def plotPcolor(self,data, | |
157 | x=None, |
|
181 | x=None, | |
158 | y=None, |
|
182 | y=None, | |
159 | channelList=None, |
|
183 | channelList=None, | |
160 | xmin=None, |
|
184 | xmin=None, | |
161 | xmax=None, |
|
185 | xmax=None, | |
162 | ymin=None, |
|
186 | ymin=None, | |
163 | ymax=None, |
|
187 | ymax=None, | |
164 | minvalue=None, |
|
188 | minvalue=None, | |
165 | maxvalue=None, |
|
189 | maxvalue=None, | |
166 | figuretitle=None, |
|
190 | figuretitle=None, | |
167 | xrangestep=None, |
|
191 | xrangestep=None, | |
168 | deltax=None, |
|
192 | deltax=None, | |
169 | save=False, |
|
193 | save=False, | |
170 | gpath='./', |
|
194 | gpath='./', | |
171 | clearData=False, |
|
195 | clearData=False, | |
172 | *args): |
|
196 | *args): | |
173 |
|
197 | |||
174 |
|
198 | |||
175 | if figuretitle == None: |
|
199 | if figuretitle == None: | |
176 | self.figuretitle = "" |
|
200 | self.figuretitle = "" | |
177 | else: |
|
201 | else: | |
178 | self.figuretitle = figuretitle |
|
202 | self.figuretitle = figuretitle | |
179 |
|
203 | |||
180 |
|
204 | |||
181 |
|
205 | |||
182 | if not(self.__isDriverOpen): |
|
206 | if not(self.__isDriverOpen): | |
183 | self.__openDriver() |
|
207 | self.__openDriver() | |
184 | self.__isDriverOpen = True |
|
208 | self.__isDriverOpen = True | |
185 |
|
209 | |||
186 | if not(self.__isConfig): |
|
210 | if not(self.__isConfig): | |
187 |
|
211 | |||
188 | self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax) |
|
212 | self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax) | |
189 |
|
213 | |||
190 | self.createFrames() |
|
214 | self.createFrames() | |
191 | self.__isConfig = True |
|
215 | self.__isConfig = True | |
192 |
|
216 | |||
193 | if (self.__isOutOfXRange(x)): |
|
217 | if (self.__isOutOfXRange(x)): | |
194 |
|
218 | |||
195 | if not(self.changeXRange(x)): |
|
219 | if not(self.changeXRange(x)): | |
196 | return 0 |
|
220 | return 0 | |
197 |
|
221 | |||
198 | self.__isFigureOpen = False |
|
222 | self.__isFigureOpen = False | |
199 |
|
223 | |||
200 | if not(self.__isFigureOpen): |
|
224 | if not(self.__isFigureOpen): | |
201 |
|
225 | |||
202 |
|
226 | |||
203 | self.__initFigure() |
|
227 | self.__initFigure() | |
204 | self.__isFigureOpen = True |
|
228 | self.__isFigureOpen = True | |
205 |
|
229 | |||
206 | for channel in channelList: |
|
230 | for channel in channelList: | |
207 | if len(args) != 0: value = args[0][channel] |
|
231 | if len(args) != 0: value = args[0][channel] | |
208 | else: value = args |
|
232 | else: value = args | |
209 |
|
233 | |||
210 | frameObj = self.frameObjList[channel] |
|
234 | frameObj = self.frameObjList[channel] | |
211 | frameObj.init(self.xmin, |
|
235 | frameObj.init(self.xmin, | |
212 | self.xmax, |
|
236 | self.xmax, | |
213 | self.ymin, |
|
237 | self.ymin, | |
214 | self.ymax, |
|
238 | self.ymax, | |
215 | self.minvalue, |
|
239 | self.minvalue, | |
216 | self.maxvalue, |
|
240 | self.maxvalue, | |
217 | self.deltax, |
|
241 | self.deltax, | |
218 | self.deltay, |
|
242 | self.deltay, | |
219 | self.colorbar, |
|
243 | self.colorbar, | |
220 | value) |
|
244 | value) | |
|
245 | self.selectFigure() | |||
221 |
|
246 | |||
222 | for channel in channelList: |
|
247 | for channel in channelList: | |
223 | dataCh = data[channel,:] |
|
248 | dataCh = data[channel,:] | |
224 | frameObj = self.frameObjList[channel] |
|
249 | frameObj = self.frameObjList[channel] | |
225 | frameObj.plot(x, y, dataCh) |
|
250 | frameObj.plot(x, y, dataCh) | |
226 |
|
251 | |||
227 |
|
252 | |||
228 | self.__refresh() |
|
253 | self.__refresh() | |
229 | if clearData == True: |
|
254 | if clearData == True: | |
230 | self.__isFigureOpen = False |
|
255 | self.__isFigureOpen = False | |
231 |
|
256 | |||
232 |
|
257 | |||
233 |
|
258 | |||
234 | class Frame: |
|
259 | class Frame: | |
|
260 | ||||
|
261 | drvObj = None | |||
|
262 | idFrame = None | |||
235 | nplots = None |
|
263 | nplots = None | |
236 | plotObjList = [] |
|
264 | plotObjList = [] | |
237 | title = "" |
|
265 | title = "" | |
238 |
|
266 | |||
239 | def __init__(self,drvObj, idframe): |
|
267 | def __init__(self,drvObj, idframe): | |
|
268 | ||||
240 | self.drvObj = drvObj |
|
269 | self.drvObj = drvObj | |
241 | self.idframe = idframe |
|
270 | self.idframe = idframe | |
|
271 | nplots = None | |||
|
272 | self.plotObjList = [] | |||
|
273 | ||||
242 | self.createPlots() |
|
274 | self.createPlots() | |
243 |
|
275 | |||
244 | def createPlots(self): |
|
276 | def createPlots(self): | |
245 | raise ValueError, "No implemented" |
|
277 | raise ValueError, "No implemented" | |
246 |
|
278 | |||
247 | def getScreenPosMainPlot(self): |
|
279 | def getScreenPosMainPlot(self): | |
248 | raise ValueError, "No implemented" |
|
280 | raise ValueError, "No implemented" | |
249 |
|
281 | |||
250 | def getScreenPosGraph1(self): |
|
282 | def getScreenPosGraph1(self): | |
251 | raise ValueError, "No implemented" |
|
283 | raise ValueError, "No implemented" | |
252 |
|
284 | |||
253 | def getScreenPos(self, nplot): |
|
285 | def getScreenPos(self, nplot): | |
254 |
|
286 | |||
255 | if nplot == 0: |
|
287 | if nplot == 0: | |
256 | xi, yi, xw, yw = self.getScreenPosMainPlot() |
|
288 | xi, yi, xw, yw = self.getScreenPosMainPlot() | |
257 |
|
289 | |||
258 | if nplot == 1: |
|
290 | if nplot == 1: | |
259 | xi, yi, xw, yw = self.getScreenPosGraph1() |
|
291 | xi, yi, xw, yw = self.getScreenPosGraph1() | |
260 |
|
292 | |||
261 | return xi, yi, xw, yw |
|
293 | return xi, yi, xw, yw | |
262 |
|
294 | |||
263 |
|
295 | |||
264 | def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args): |
|
296 | def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args): | |
265 |
|
297 | |||
266 | for plotObj in self.plotObjList: |
|
298 | for plotObj in self.plotObjList: | |
267 | plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args) |
|
299 | plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args) | |
268 | plotObj.plotBox() |
|
300 | plotObj.plotBox() | |
269 |
|
301 | |||
270 |
|
302 | |||
271 |
|
303 | |||
272 | class Plot: |
|
304 | class Plot: | |
|
305 | ||||
|
306 | drvObj = None | |||
|
307 | idframe = None | |||
|
308 | idplot = None | |||
|
309 | xi = None | |||
|
310 | yi = None | |||
|
311 | xw = None | |||
|
312 | yw = None | |||
|
313 | ||||
273 | title = "" |
|
314 | title = "" | |
274 | xlabel = "" |
|
315 | xlabel = "" | |
275 | ylabel = "" |
|
316 | ylabel = "" | |
276 | xaxisastime = None |
|
317 | xaxisastime = None | |
277 | timefmt = None |
|
318 | timefmt = None | |
278 | xopt = "" |
|
319 | xopt = "" | |
279 | yopt = "" |
|
320 | yopt = "" | |
280 | xpos = None |
|
321 | xpos = None | |
281 | ypos = None |
|
322 | ypos = None | |
282 | szchar = None |
|
323 | szchar = None | |
283 | idframe = None |
|
324 | idframe = None | |
284 | idplot = None |
|
325 | idplot = None | |
285 | colorbar = None |
|
326 | colorbar = None | |
286 | cbxpos = None |
|
327 | cbxpos = None | |
287 | cbypos = None |
|
328 | cbypos = None | |
288 |
|
329 | |||
289 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): |
|
330 | def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw): | |
|
331 | ||||
290 | self.drvObj = drvObj |
|
332 | self.drvObj = drvObj | |
291 | self.idframe = idframe |
|
333 | self.idframe = idframe | |
292 | self.idplot = idplot |
|
334 | self.idplot = idplot | |
293 | self.xi = xi |
|
335 | self.xi = xi | |
294 | self.yi = yi |
|
336 | self.yi = yi | |
295 | self.xw = xw |
|
337 | self.xw = xw | |
296 | self.yw = yw |
|
338 | self.yw = yw | |
297 |
|
339 | |||
298 |
|
340 | |||
299 | def plotBox(self): |
|
341 | def plotBox(self): | |
300 |
|
342 | |||
301 | self.drvObj.driver.plotBox(self.idframe, |
|
343 | self.drvObj.driver.plotBox(self.idframe, | |
302 | self.xpos, |
|
344 | self.xpos, | |
303 | self.ypos, |
|
345 | self.ypos, | |
304 | self.xmin, |
|
346 | self.xmin, | |
305 | self.xmax, |
|
347 | self.xmax, | |
306 | self.ymin, |
|
348 | self.ymin, | |
307 | self.ymax, |
|
349 | self.ymax, | |
308 | self.minvalue, |
|
350 | self.minvalue, | |
309 | self.maxvalue, |
|
351 | self.maxvalue, | |
310 | self.xopt, |
|
352 | self.xopt, | |
311 | self.yopt, |
|
353 | self.yopt, | |
312 | self.szchar, |
|
354 | self.szchar, | |
313 | self.xaxisastime, |
|
355 | self.xaxisastime, | |
314 | self.timefmt) |
|
356 | self.timefmt) | |
315 |
|
357 | |||
316 | self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title) |
|
358 | self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title) | |
317 |
|
359 | |||
318 | if self.colorbar: |
|
360 | if self.colorbar: | |
319 | self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos) |
|
361 | self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos) | |
320 |
|
362 | |||
321 | def plotPcolor(self, x, y, z, deltax, deltay, getGrid): |
|
363 | def plotPcolor(self, x, y, z, deltax, deltay, getGrid): | |
322 |
|
364 | |||
323 | self.drvObj.driver.pcolor(self.idframe, |
|
365 | self.drvObj.driver.pcolor(self.idframe, | |
324 | self.xpos, |
|
366 | self.xpos, | |
325 | self.ypos, |
|
367 | self.ypos, | |
326 | z, |
|
368 | z, | |
327 | x, |
|
369 | x, | |
328 | y, |
|
370 | y, | |
329 | self.xmin, |
|
371 | self.xmin, | |
330 | self.xmax, |
|
372 | self.xmax, | |
331 | self.ymin, |
|
373 | self.ymin, | |
332 | self.ymax, |
|
374 | self.ymax, | |
333 | self.minvalue, |
|
375 | self.minvalue, | |
334 | self.maxvalue, |
|
376 | self.maxvalue, | |
335 | deltax, |
|
377 | deltax, | |
336 | deltay, |
|
378 | deltay, | |
337 | getGrid, |
|
379 | getGrid, | |
338 | self.xaxisastime, |
|
380 | self.xaxisastime, | |
339 | self.timefmt) |
|
381 | self.timefmt) | |
340 |
|
382 | |||
341 | def plotBasicLine(self,x, y, color): |
|
383 | def plotBasicLine(self,x, y, color): | |
342 | """ |
|
384 | """ | |
343 | Inputs: |
|
385 | Inputs: | |
344 | x: |
|
386 | x: | |
345 |
|
387 | |||
346 | y: |
|
388 | y: | |
347 |
|
389 | |||
348 | color: |
|
390 | color: | |
349 | """ |
|
391 | """ | |
350 | self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color) |
|
392 | self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color) | |
351 | No newline at end of file |
|
393 |
@@ -1,512 +1,515 | |||||
1 | import plplot |
|
1 | import plplot | |
2 | import numpy |
|
2 | import numpy | |
3 | import sys |
|
3 | import sys | |
4 | import plplot #condicional |
|
4 | import plplot #condicional | |
5 |
|
5 | |||
6 | import matplotlib as mpl |
|
6 | import matplotlib as mpl | |
7 | #mpl.use('TKAgg') |
|
7 | #mpl.use('TKAgg') | |
8 | import matplotlib.pyplot as plt |
|
8 | import matplotlib.pyplot as plt | |
9 |
|
9 | |||
10 | class Driver: |
|
10 | class Driver: | |
11 | def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): |
|
11 | def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): | |
12 | if driver == "plplot": |
|
12 | if driver == "plplot": | |
13 | self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) |
|
13 | self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) | |
14 | elif driver == "mpl": |
|
14 | elif driver == "mpl": | |
15 | self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) |
|
15 | self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar) | |
16 | else: |
|
16 | else: | |
17 | raise ValueError, "The driver: %s is not defined"%driver |
|
17 | raise ValueError, "The driver: %s is not defined"%driver | |
18 |
|
18 | |||
19 | class PlplotDriver: |
|
19 | class PlplotDriver: | |
20 |
|
20 | |||
21 | __isDriverOpen = False |
|
21 | __isDriverOpen = False | |
22 | pldriver = None |
|
22 | pldriver = None | |
23 | __xg = None |
|
23 | __xg = None | |
24 | __yg = None |
|
24 | __yg = None | |
25 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): |
|
25 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): | |
26 |
|
26 | |||
27 | if idfigure == None: |
|
27 | if idfigure == None: | |
28 | raise ValueError, 'idfigure input must be defined' |
|
28 | raise ValueError, 'idfigure input must be defined' | |
29 |
|
29 | |||
30 | self.idfigure = idfigure |
|
30 | self.idfigure = idfigure | |
31 | self.xw = xw |
|
31 | self.xw = xw | |
32 | self.yw = yw |
|
32 | self.yw = yw | |
33 | self.wintitle = wintitle |
|
33 | self.wintitle = wintitle | |
34 | self.overplot = overplot |
|
34 | self.overplot = overplot | |
35 | self.colormap = colormap |
|
35 | self.colormap = colormap | |
36 | self.colorbar = colorbar |
|
36 | self.colorbar = colorbar | |
37 |
|
37 | |||
38 | def setFigure(self): |
|
38 | def setFigure(self): | |
39 | """ |
|
39 | """ | |
40 | previous configuration to open(init) the plplot driver |
|
40 | previous configuration to open(init) the plplot driver | |
41 | """ |
|
41 | """ | |
42 | plplot.plsstrm(self.idfigure) |
|
42 | plplot.plsstrm(self.idfigure) | |
43 | plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL) |
|
43 | plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL) | |
44 | plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw)) |
|
44 | plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw)) | |
45 |
|
45 | |||
|
46 | def selectFigure(self): | |||
|
47 | ||||
|
48 | plplot.plsstrm(self.idfigure) | |||
46 |
|
49 | |||
47 | def openDriver(self, pldriver=None): |
|
50 | def openDriver(self, pldriver=None): | |
48 | if pldriver == None: |
|
51 | if pldriver == None: | |
49 | if sys.platform == "linux": |
|
52 | if sys.platform == "linux": | |
50 | pldriver = "xcairo" |
|
53 | pldriver = "xcairo" | |
51 |
|
54 | |||
52 | if sys.platform == "linux2": |
|
55 | if sys.platform == "linux2": | |
53 | pldriver = "xcairo" |
|
56 | pldriver = "xcairo" | |
54 |
|
57 | |||
55 | elif sys.platform == "darwin": |
|
58 | elif sys.platform == "darwin": | |
56 | pldriver = "xwin" |
|
59 | pldriver = "xwin" | |
57 |
|
60 | |||
58 | else: |
|
61 | else: | |
59 | pldriver = "" |
|
62 | pldriver = "" | |
60 |
|
63 | |||
61 | plplot.plsdev("xwin") #para pruebas |
|
64 | plplot.plsdev("xwin") #para pruebas | |
62 | plplot.plscolbg(255,255,255) |
|
65 | plplot.plscolbg(255,255,255) | |
63 | plplot.plscol0(1,0,0,0) |
|
66 | plplot.plscol0(1,0,0,0) | |
64 | plplot.plinit() |
|
67 | plplot.plinit() | |
65 | plplot.plspause(False) |
|
68 | plplot.plspause(False) | |
66 |
|
69 | |||
67 | self.pldriver = pldriver |
|
70 | self.pldriver = pldriver | |
68 |
|
71 | |||
69 | def closeDriver(self): |
|
72 | def closeDriver(self): | |
70 | pass |
|
73 | pass | |
71 |
|
74 | |||
72 | def openPage(self): |
|
75 | def openPage(self): | |
73 | plplot.plbop() |
|
76 | plplot.plbop() | |
74 | plplot.pladv(0) |
|
77 | plplot.pladv(0) | |
75 |
|
78 | |||
76 | def closePage(self): |
|
79 | def closePage(self): | |
77 | plplot.pleop() |
|
80 | plplot.pleop() | |
78 |
|
81 | |||
79 | def openFigure(self): |
|
82 | def openFigure(self): | |
80 | plplot.plbop() |
|
83 | plplot.plbop() | |
81 | plplot.pladv(0) |
|
84 | plplot.pladv(0) | |
82 |
|
85 | |||
83 | def closeFigure(self): |
|
86 | def closeFigure(self): | |
84 | plplot.pleop() |
|
87 | plplot.pleop() | |
85 |
|
88 | |||
86 | def setSubPlots(self,nrows, ncolumns): |
|
89 | def setSubPlots(self,nrows, ncolumns): | |
87 | plplot.plssub(ncolumns,nrows) |
|
90 | plplot.plssub(ncolumns,nrows) | |
88 |
|
91 | |||
89 | def setPlotLabels(self, id, xlabel, ylabel, title): |
|
92 | def setPlotLabels(self, id, xlabel, ylabel, title): | |
90 | plplot.pllab(xlabel, ylabel, title) |
|
93 | plplot.pllab(xlabel, ylabel, title) | |
91 |
|
94 | |||
92 | def setFigTitle(self, title,color="black", szchar=0.55): |
|
95 | def setFigTitle(self, title,color="black", szchar=0.55): | |
93 | self.setSubPlots(1, 0) |
|
96 | self.setSubPlots(1, 0) | |
94 | plplot.pladv(0) |
|
97 | plplot.pladv(0) | |
95 | plplot.plvpor(0., 1., 0., 1.) |
|
98 | plplot.plvpor(0., 1., 0., 1.) | |
96 |
|
99 | |||
97 | if color == "black": |
|
100 | if color == "black": | |
98 | plplot.plcol0(1) |
|
101 | plplot.plcol0(1) | |
99 | if color == "white": |
|
102 | if color == "white": | |
100 | plplot.plcol0(15) |
|
103 | plplot.plcol0(15) | |
101 |
|
104 | |||
102 | plplot.plschr(0.0,szchar) |
|
105 | plplot.plschr(0.0,szchar) | |
103 | plplot.plmtex("t",-1., 0.5, 0.5, title) |
|
106 | plplot.plmtex("t",-1., 0.5, 0.5, title) | |
104 |
|
107 | |||
105 | def plotColorbar(self, minvalue, maxvalue, xpos, ypos): |
|
108 | def plotColorbar(self, minvalue, maxvalue, xpos, ypos): | |
106 | # plplot.pladv(id) |
|
109 | # plplot.pladv(id) | |
107 | # plplot.plschr(0.0,szchar-0.05) |
|
110 | # plplot.plschr(0.0,szchar-0.05) | |
108 | xmin = 0; xmax = 1 |
|
111 | xmin = 0; xmax = 1 | |
109 | ymin = minvalue; ymax = maxvalue |
|
112 | ymin = minvalue; ymax = maxvalue | |
110 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
113 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
111 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) |
|
114 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) | |
112 | plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0) |
|
115 | plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0) | |
113 |
|
116 | |||
114 | data = numpy.arange(256) |
|
117 | data = numpy.arange(256) | |
115 | data = numpy.reshape(data, (1,-1)) |
|
118 | data = numpy.reshape(data, (1,-1)) | |
116 |
|
119 | |||
117 | plplot.plimage(data, |
|
120 | plplot.plimage(data, | |
118 | float(xmin), |
|
121 | float(xmin), | |
119 | float(xmax), |
|
122 | float(xmax), | |
120 | float(ymin), |
|
123 | float(ymin), | |
121 | float(ymax), |
|
124 | float(ymax), | |
122 | 0., |
|
125 | 0., | |
123 | 255., |
|
126 | 255., | |
124 | float(xmin), |
|
127 | float(xmin), | |
125 | float(xmax), |
|
128 | float(xmax), | |
126 | float(ymin), |
|
129 | float(ymin), | |
127 | float(ymax)) |
|
130 | float(ymax)) | |
128 |
|
131 | |||
129 |
|
132 | |||
130 | def __getGrid(self, x, y, deltax=None, deltay=None): |
|
133 | def __getGrid(self, x, y, deltax=None, deltay=None): | |
131 |
|
134 | |||
132 | if not(len(x)>0 and len(y)>0): |
|
135 | if not(len(x)>0 and len(y)>0): | |
133 | raise ValueError, "x axis and y axis are empty" |
|
136 | raise ValueError, "x axis and y axis are empty" | |
134 |
|
137 | |||
135 | if deltax == None: deltax = x[-1] - x[-2] |
|
138 | if deltax == None: deltax = x[-1] - x[-2] | |
136 | if deltay == None: deltay = y[-1] - y[-2] |
|
139 | if deltay == None: deltay = y[-1] - y[-2] | |
137 |
|
140 | |||
138 | x1 = numpy.append(x, x[-1] + deltax) |
|
141 | x1 = numpy.append(x, x[-1] + deltax) | |
139 | y1 = numpy.append(y, y[-1] + deltay) |
|
142 | y1 = numpy.append(y, y[-1] + deltay) | |
140 |
|
143 | |||
141 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
144 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |
142 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
145 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |
143 |
|
146 | |||
144 | return xg, yg |
|
147 | return xg, yg | |
145 |
|
148 | |||
146 |
|
149 | |||
147 | def pcolor(self, id, xpos, ypos, data, x, y, xmin, xmax, ymin, ymax, zmin, zmax, deltax=None, deltay=None, getGrid=True, xaxisastime = False, timefmt="%H:%M"): |
|
150 | def pcolor(self, id, xpos, ypos, data, x, y, xmin, xmax, ymin, ymax, zmin, zmax, deltax=None, deltay=None, getGrid=True, xaxisastime = False, timefmt="%H:%M"): | |
148 |
|
151 | |||
149 | plplot.pladv(id) |
|
152 | plplot.pladv(id) | |
150 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
153 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
151 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) |
|
154 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) | |
152 |
|
155 | |||
153 | if xaxisastime: |
|
156 | if xaxisastime: | |
154 | timedelta = (xmax - xmin + 1)/8. |
|
157 | timedelta = (xmax - xmin + 1)/8. | |
155 |
|
158 | |||
156 | if getGrid: |
|
159 | if getGrid: | |
157 | self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay) |
|
160 | self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay) | |
158 |
|
161 | |||
159 | if deltax == None: deltax = x[-1] - x[0] |
|
162 | if deltax == None: deltax = x[-1] - x[0] | |
160 | # if deltay == None: deltay = y[-1] - y[-2] |
|
163 | # if deltay == None: deltay = y[-1] - y[-2] | |
161 |
|
164 | |||
162 | xmin = x[0] |
|
165 | xmin = x[0] | |
163 | xmax = xmin + deltax |
|
166 | xmax = xmin + deltax | |
164 |
|
167 | |||
165 | plplot.plimagefr(data, |
|
168 | plplot.plimagefr(data, | |
166 | float(xmin), |
|
169 | float(xmin), | |
167 | float(xmax), |
|
170 | float(xmax), | |
168 | float(ymin), |
|
171 | float(ymin), | |
169 | float(ymax), |
|
172 | float(ymax), | |
170 | 0., |
|
173 | 0., | |
171 | 0., |
|
174 | 0., | |
172 | float(zmin), |
|
175 | float(zmin), | |
173 | float(zmax), |
|
176 | float(zmax), | |
174 | plplot.pltr2, |
|
177 | plplot.pltr2, | |
175 | self.__xg, |
|
178 | self.__xg, | |
176 | self.__yg) |
|
179 | self.__yg) | |
177 |
|
180 | |||
178 | if xaxisastime: |
|
181 | if xaxisastime: | |
179 | plplot.pltimefmt(timefmt) |
|
182 | plplot.pltimefmt(timefmt) | |
180 | xopt = "bcstd" |
|
183 | xopt = "bcstd" | |
181 | yopt = "bcst" |
|
184 | yopt = "bcst" | |
182 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) |
|
185 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) | |
183 | else: |
|
186 | else: | |
184 | xopt = "bcst" |
|
187 | xopt = "bcst" | |
185 | yopt = "bcst" |
|
188 | yopt = "bcst" | |
186 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
189 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | |
187 |
|
190 | |||
188 |
|
191 | |||
189 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): |
|
192 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): | |
190 | """ |
|
193 | """ | |
191 | xopt, yopt: entradas que no se aplican en MPL |
|
194 | xopt, yopt: entradas que no se aplican en MPL | |
192 | """ |
|
195 | """ | |
193 | plplot.pladv(id) |
|
196 | plplot.pladv(id) | |
194 | plplot.plschr(0.0,szchar-0.05) |
|
197 | plplot.plschr(0.0,szchar-0.05) | |
195 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
198 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
196 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) |
|
199 | plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) | |
197 | if xaxisastime: |
|
200 | if xaxisastime: | |
198 | plplot.pltimefmt(timefmt) |
|
201 | plplot.pltimefmt(timefmt) | |
199 | timedelta = (xmax - xmin + 1)/8. |
|
202 | timedelta = (xmax - xmin + 1)/8. | |
200 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) |
|
203 | plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) | |
201 | else: |
|
204 | else: | |
202 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
205 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | |
203 |
|
206 | |||
204 | def refresh(self): |
|
207 | def refresh(self): | |
205 | plplot.plflush() |
|
208 | plplot.plflush() | |
206 |
|
209 | |||
207 | def show(self): |
|
210 | def show(self): | |
208 | plplot.plspause(True) |
|
211 | plplot.plspause(True) | |
209 | plplot.plend() |
|
212 | plplot.plend() | |
210 |
|
213 | |||
211 | def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): |
|
214 | def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): | |
212 |
|
215 | |||
213 | """ |
|
216 | """ | |
214 | Inputs: |
|
217 | Inputs: | |
215 | x: datos en el eje x |
|
218 | x: datos en el eje x | |
216 |
|
219 | |||
217 | y: datos en el eje y |
|
220 | y: datos en el eje y | |
218 |
|
221 | |||
219 | xmin, xmax: intervalo de datos en el eje x |
|
222 | xmin, xmax: intervalo de datos en el eje x | |
220 |
|
223 | |||
221 | ymin, ymax: intervalo de datos en el eje y |
|
224 | ymin, ymax: intervalo de datos en el eje y | |
222 |
|
225 | |||
223 | color: color de la linea a dibujarse |
|
226 | color: color de la linea a dibujarse | |
224 |
|
227 | |||
225 | id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada |
|
228 | id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada | |
226 | plot esta definido por xpos, ypos. |
|
229 | plot esta definido por xpos, ypos. | |
227 |
|
230 | |||
228 | xpos,ypos: coordenadas que indican la posicion del plot en el frame |
|
231 | xpos,ypos: coordenadas que indican la posicion del plot en el frame | |
229 |
|
232 | |||
230 | """ |
|
233 | """ | |
231 |
|
234 | |||
232 | plplot.pladv(id) |
|
235 | plplot.pladv(id) | |
233 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) |
|
236 | plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | |
234 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) |
|
237 | plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) | |
235 |
|
238 | |||
236 | if color == "blue": |
|
239 | if color == "blue": | |
237 | colline = 9 |
|
240 | colline = 9 | |
238 | if color == "green": |
|
241 | if color == "green": | |
239 | colline = 3 |
|
242 | colline = 3 | |
240 |
|
243 | |||
241 | plplot.plcol0(colline) |
|
244 | plplot.plcol0(colline) | |
242 | plplot.plline(x, y) |
|
245 | plplot.plline(x, y) | |
243 | plplot.plcol0(1) |
|
246 | plplot.plcol0(1) | |
244 | plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) |
|
247 | plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) | |
245 |
|
248 | |||
246 | def save(self, filename): |
|
249 | def save(self, filename): | |
247 | curr_strm = plplot.plgstrm() |
|
250 | curr_strm = plplot.plgstrm() | |
248 | save_strm = plplot.plmkstrm() |
|
251 | save_strm = plplot.plmkstrm() | |
249 | plplot.plsetopt("geometry", "%dx%d"%(self.xw,self.yw)) |
|
252 | plplot.plsetopt("geometry", "%dx%d"%(self.xw,self.yw)) | |
250 | plplot.plsdev("png") |
|
253 | plplot.plsdev("png") | |
251 | plplot.plsfnam(filename) |
|
254 | plplot.plsfnam(filename) | |
252 | plplot.plcpstrm(curr_strm,0) |
|
255 | plplot.plcpstrm(curr_strm,0) | |
253 | plplot.plreplot() |
|
256 | plplot.plreplot() | |
254 | plplot.plend1() |
|
257 | plplot.plend1() | |
255 | plplot.plsstrm(curr_strm) |
|
258 | plplot.plsstrm(curr_strm) | |
256 |
|
259 | |||
257 | def setColormap(self, colormap="gray"): |
|
260 | def setColormap(self, colormap="gray"): | |
258 |
|
261 | |||
259 | if colormap == None: |
|
262 | if colormap == None: | |
260 | return |
|
263 | return | |
261 |
|
264 | |||
262 | ncolor = None |
|
265 | ncolor = None | |
263 | rgb_lvl = None |
|
266 | rgb_lvl = None | |
264 |
|
267 | |||
265 | # Routine for defining a specific color map 1 in HLS space. |
|
268 | # Routine for defining a specific color map 1 in HLS space. | |
266 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
269 | # if gray is true, use basic grayscale variation from half-dark to light. | |
267 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
270 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |
268 |
|
271 | |||
269 | # Independent variable of control points. |
|
272 | # Independent variable of control points. | |
270 | i = numpy.array((0., 1.)) |
|
273 | i = numpy.array((0., 1.)) | |
271 | if colormap=="gray": |
|
274 | if colormap=="gray": | |
272 | ncolor = 256 |
|
275 | ncolor = 256 | |
273 | # Hue for control points. Doesn't matter since saturation is zero. |
|
276 | # Hue for control points. Doesn't matter since saturation is zero. | |
274 | h = numpy.array((0., 0.)) |
|
277 | h = numpy.array((0., 0.)) | |
275 | # Lightness ranging from half-dark (for interest) to light. |
|
278 | # Lightness ranging from half-dark (for interest) to light. | |
276 | l = numpy.array((0.5, 1.)) |
|
279 | l = numpy.array((0.5, 1.)) | |
277 | # Gray scale has zero saturation |
|
280 | # Gray scale has zero saturation | |
278 | s = numpy.array((0., 0.)) |
|
281 | s = numpy.array((0., 0.)) | |
279 |
|
282 | |||
280 | # number of cmap1 colours is 256 in this case. |
|
283 | # number of cmap1 colours is 256 in this case. | |
281 | plplot.plscmap1n(ncolor) |
|
284 | plplot.plscmap1n(ncolor) | |
282 | # Interpolate between control points to set up cmap1. |
|
285 | # Interpolate between control points to set up cmap1. | |
283 | plplot.plscmap1l(0, i, h, l, s) |
|
286 | plplot.plscmap1l(0, i, h, l, s) | |
284 |
|
287 | |||
285 | return None |
|
288 | return None | |
286 |
|
289 | |||
287 | if colormap == 'jet': |
|
290 | if colormap == 'jet': | |
288 | ncolor = 256 |
|
291 | ncolor = 256 | |
289 | pos = numpy.zeros((ncolor)) |
|
292 | pos = numpy.zeros((ncolor)) | |
290 | r = numpy.zeros((ncolor)) |
|
293 | r = numpy.zeros((ncolor)) | |
291 | g = numpy.zeros((ncolor)) |
|
294 | g = numpy.zeros((ncolor)) | |
292 | b = numpy.zeros((ncolor)) |
|
295 | b = numpy.zeros((ncolor)) | |
293 |
|
296 | |||
294 | for i in range(ncolor): |
|
297 | for i in range(ncolor): | |
295 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 |
|
298 | if(i <= 35.0/100*(ncolor-1)): rf = 0.0 | |
296 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 |
|
299 | elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31 | |
297 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 |
|
300 | elif (i <= 89.0/100*(ncolor-1)): rf = 1.0 | |
298 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 |
|
301 | else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22 | |
299 |
|
302 | |||
300 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 |
|
303 | if(i <= 12.0/100*(ncolor-1)): gf = 0.0 | |
301 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 |
|
304 | elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26 | |
302 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 |
|
305 | elif(i <= 64.0/100*(ncolor-1)): gf = 1.0 | |
303 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 |
|
306 | elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27 | |
304 | else: gf = 0.0 |
|
307 | else: gf = 0.0 | |
305 |
|
308 | |||
306 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 |
|
309 | if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5 | |
307 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 |
|
310 | elif(i <= 34.0/100*(ncolor-1)): bf = 1.0 | |
308 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 |
|
311 | elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31 | |
309 | else: bf = 0 |
|
312 | else: bf = 0 | |
310 |
|
313 | |||
311 | r[i] = rf |
|
314 | r[i] = rf | |
312 | g[i] = gf |
|
315 | g[i] = gf | |
313 | b[i] = bf |
|
316 | b[i] = bf | |
314 |
|
317 | |||
315 | pos[i] = float(i)/float(ncolor-1) |
|
318 | pos[i] = float(i)/float(ncolor-1) | |
316 |
|
319 | |||
317 |
|
320 | |||
318 | plplot.plscmap1n(ncolor) |
|
321 | plplot.plscmap1n(ncolor) | |
319 | plplot.plscmap1l(1, pos, r, g, b) |
|
322 | plplot.plscmap1l(1, pos, r, g, b) | |
320 |
|
323 | |||
321 |
|
324 | |||
322 |
|
325 | |||
323 | if colormap=="br_green": |
|
326 | if colormap=="br_green": | |
324 | ncolor = 256 |
|
327 | ncolor = 256 | |
325 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
328 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
326 | h = numpy.array((240., 0.)) |
|
329 | h = numpy.array((240., 0.)) | |
327 | # Lightness and saturation are constant (values taken from C example). |
|
330 | # Lightness and saturation are constant (values taken from C example). | |
328 | l = numpy.array((0.6, 0.6)) |
|
331 | l = numpy.array((0.6, 0.6)) | |
329 | s = numpy.array((0.8, 0.8)) |
|
332 | s = numpy.array((0.8, 0.8)) | |
330 |
|
333 | |||
331 | # number of cmap1 colours is 256 in this case. |
|
334 | # number of cmap1 colours is 256 in this case. | |
332 | plplot.plscmap1n(ncolor) |
|
335 | plplot.plscmap1n(ncolor) | |
333 | # Interpolate between control points to set up cmap1. |
|
336 | # Interpolate between control points to set up cmap1. | |
334 | plplot.plscmap1l(0, i, h, l, s) |
|
337 | plplot.plscmap1l(0, i, h, l, s) | |
335 |
|
338 | |||
336 | return None |
|
339 | return None | |
337 |
|
340 | |||
338 | if colormap=="tricolor": |
|
341 | if colormap=="tricolor": | |
339 | ncolor = 3 |
|
342 | ncolor = 3 | |
340 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
343 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
341 | h = numpy.array((240., 0.)) |
|
344 | h = numpy.array((240., 0.)) | |
342 | # Lightness and saturation are constant (values taken from C example). |
|
345 | # Lightness and saturation are constant (values taken from C example). | |
343 | l = numpy.array((0.6, 0.6)) |
|
346 | l = numpy.array((0.6, 0.6)) | |
344 | s = numpy.array((0.8, 0.8)) |
|
347 | s = numpy.array((0.8, 0.8)) | |
345 |
|
348 | |||
346 | # number of cmap1 colours is 256 in this case. |
|
349 | # number of cmap1 colours is 256 in this case. | |
347 | plplot.plscmap1n(ncolor) |
|
350 | plplot.plscmap1n(ncolor) | |
348 | # Interpolate between control points to set up cmap1. |
|
351 | # Interpolate between control points to set up cmap1. | |
349 | plplot.plscmap1l(0, i, h, l, s) |
|
352 | plplot.plscmap1l(0, i, h, l, s) | |
350 |
|
353 | |||
351 | return None |
|
354 | return None | |
352 |
|
355 | |||
353 | if colormap == 'rgb' or colormap == 'rgb666': |
|
356 | if colormap == 'rgb' or colormap == 'rgb666': | |
354 |
|
357 | |||
355 | color_sz = 6 |
|
358 | color_sz = 6 | |
356 | ncolor = color_sz*color_sz*color_sz |
|
359 | ncolor = color_sz*color_sz*color_sz | |
357 | pos = numpy.zeros((ncolor)) |
|
360 | pos = numpy.zeros((ncolor)) | |
358 | r = numpy.zeros((ncolor)) |
|
361 | r = numpy.zeros((ncolor)) | |
359 | g = numpy.zeros((ncolor)) |
|
362 | g = numpy.zeros((ncolor)) | |
360 | b = numpy.zeros((ncolor)) |
|
363 | b = numpy.zeros((ncolor)) | |
361 | ind = 0 |
|
364 | ind = 0 | |
362 | for ri in range(color_sz): |
|
365 | for ri in range(color_sz): | |
363 | for gi in range(color_sz): |
|
366 | for gi in range(color_sz): | |
364 | for bi in range(color_sz): |
|
367 | for bi in range(color_sz): | |
365 | r[ind] = ri/(color_sz-1.0) |
|
368 | r[ind] = ri/(color_sz-1.0) | |
366 | g[ind] = gi/(color_sz-1.0) |
|
369 | g[ind] = gi/(color_sz-1.0) | |
367 | b[ind] = bi/(color_sz-1.0) |
|
370 | b[ind] = bi/(color_sz-1.0) | |
368 | pos[ind] = ind/(ncolor-1.0) |
|
371 | pos[ind] = ind/(ncolor-1.0) | |
369 | ind += 1 |
|
372 | ind += 1 | |
370 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
373 | rgb_lvl = [6,6,6] #Levels for RGB colors | |
371 |
|
374 | |||
372 | if colormap == 'rgb676': |
|
375 | if colormap == 'rgb676': | |
373 | ncolor = 6*7*6 |
|
376 | ncolor = 6*7*6 | |
374 | pos = numpy.zeros((ncolor)) |
|
377 | pos = numpy.zeros((ncolor)) | |
375 | r = numpy.zeros((ncolor)) |
|
378 | r = numpy.zeros((ncolor)) | |
376 | g = numpy.zeros((ncolor)) |
|
379 | g = numpy.zeros((ncolor)) | |
377 | b = numpy.zeros((ncolor)) |
|
380 | b = numpy.zeros((ncolor)) | |
378 | ind = 0 |
|
381 | ind = 0 | |
379 | for ri in range(8): |
|
382 | for ri in range(8): | |
380 | for gi in range(8): |
|
383 | for gi in range(8): | |
381 | for bi in range(4): |
|
384 | for bi in range(4): | |
382 | r[ind] = ri/(6-1.0) |
|
385 | r[ind] = ri/(6-1.0) | |
383 | g[ind] = gi/(7-1.0) |
|
386 | g[ind] = gi/(7-1.0) | |
384 | b[ind] = bi/(6-1.0) |
|
387 | b[ind] = bi/(6-1.0) | |
385 | pos[ind] = ind/(ncolor-1.0) |
|
388 | pos[ind] = ind/(ncolor-1.0) | |
386 | ind += 1 |
|
389 | ind += 1 | |
387 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
390 | rgb_lvl = [6,7,6] #Levels for RGB colors | |
388 |
|
391 | |||
389 | if colormap == 'rgb685': |
|
392 | if colormap == 'rgb685': | |
390 | ncolor = 6*8*5 |
|
393 | ncolor = 6*8*5 | |
391 | pos = numpy.zeros((ncolor)) |
|
394 | pos = numpy.zeros((ncolor)) | |
392 | r = numpy.zeros((ncolor)) |
|
395 | r = numpy.zeros((ncolor)) | |
393 | g = numpy.zeros((ncolor)) |
|
396 | g = numpy.zeros((ncolor)) | |
394 | b = numpy.zeros((ncolor)) |
|
397 | b = numpy.zeros((ncolor)) | |
395 | ind = 0 |
|
398 | ind = 0 | |
396 | for ri in range(8): |
|
399 | for ri in range(8): | |
397 | for gi in range(8): |
|
400 | for gi in range(8): | |
398 | for bi in range(4): |
|
401 | for bi in range(4): | |
399 | r[ind] = ri/(6-1.0) |
|
402 | r[ind] = ri/(6-1.0) | |
400 | g[ind] = gi/(8-1.0) |
|
403 | g[ind] = gi/(8-1.0) | |
401 | b[ind] = bi/(5-1.0) |
|
404 | b[ind] = bi/(5-1.0) | |
402 | pos[ind] = ind/(ncolor-1.0) |
|
405 | pos[ind] = ind/(ncolor-1.0) | |
403 | ind += 1 |
|
406 | ind += 1 | |
404 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
407 | rgb_lvl = [6,8,5] #Levels for RGB colors | |
405 |
|
408 | |||
406 | if colormap == 'rgb884': |
|
409 | if colormap == 'rgb884': | |
407 | ncolor = 8*8*4 |
|
410 | ncolor = 8*8*4 | |
408 | pos = numpy.zeros((ncolor)) |
|
411 | pos = numpy.zeros((ncolor)) | |
409 | r = numpy.zeros((ncolor)) |
|
412 | r = numpy.zeros((ncolor)) | |
410 | g = numpy.zeros((ncolor)) |
|
413 | g = numpy.zeros((ncolor)) | |
411 | b = numpy.zeros((ncolor)) |
|
414 | b = numpy.zeros((ncolor)) | |
412 | ind = 0 |
|
415 | ind = 0 | |
413 | for ri in range(8): |
|
416 | for ri in range(8): | |
414 | for gi in range(8): |
|
417 | for gi in range(8): | |
415 | for bi in range(4): |
|
418 | for bi in range(4): | |
416 | r[ind] = ri/(8-1.0) |
|
419 | r[ind] = ri/(8-1.0) | |
417 | g[ind] = gi/(8-1.0) |
|
420 | g[ind] = gi/(8-1.0) | |
418 | b[ind] = bi/(4-1.0) |
|
421 | b[ind] = bi/(4-1.0) | |
419 | pos[ind] = ind/(ncolor-1.0) |
|
422 | pos[ind] = ind/(ncolor-1.0) | |
420 | ind += 1 |
|
423 | ind += 1 | |
421 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
424 | rgb_lvl = [8,8,4] #Levels for RGB colors | |
422 |
|
425 | |||
423 | if ncolor == None: |
|
426 | if ncolor == None: | |
424 | raise ValueError, "The colormap selected is not valid" |
|
427 | raise ValueError, "The colormap selected (%s) is not valid" %(colormap) | |
425 |
|
428 | |||
426 | plplot.plscmap1n(ncolor) |
|
429 | plplot.plscmap1n(ncolor) | |
427 | plplot.plscmap1l(1, pos, r, g, b) |
|
430 | plplot.plscmap1l(1, pos, r, g, b) | |
428 |
|
431 | |||
429 | return rgb_lvl |
|
432 | return rgb_lvl | |
430 |
|
433 | |||
431 |
|
434 | |||
432 | class MplDriver: |
|
435 | class MplDriver: | |
433 | # fig = None |
|
436 | # fig = None | |
434 | nrows = None |
|
437 | nrows = None | |
435 | ncolumns = None |
|
438 | ncolumns = None | |
436 | __axesId = None |
|
439 | __axesId = None | |
437 | __setData = None |
|
440 | __setData = None | |
438 |
|
441 | |||
439 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): |
|
442 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar): | |
440 |
|
443 | |||
441 | if idfigure == None: |
|
444 | if idfigure == None: | |
442 | raise ValueError, 'idfigure input must be defined' |
|
445 | raise ValueError, 'idfigure input must be defined' | |
443 | self.idfigure = idfigure |
|
446 | self.idfigure = idfigure | |
444 | self.xw = xw |
|
447 | self.xw = xw | |
445 | self.yw = yw |
|
448 | self.yw = yw | |
446 | self.wintitle = wintitle |
|
449 | self.wintitle = wintitle | |
447 | self.overplot = overplot |
|
450 | self.overplot = overplot | |
448 | self.colormap = colormap |
|
451 | self.colormap = colormap | |
449 | self.colorbar = colorbar |
|
452 | self.colorbar = colorbar | |
450 | self.__axesId = {} |
|
453 | self.__axesId = {} | |
451 |
|
454 | |||
452 | def setFigure(self): |
|
455 | def setFigure(self): | |
453 | plt.ioff() |
|
456 | plt.ioff() | |
454 | fig = plt.figure(self.idfigure) |
|
457 | fig = plt.figure(self.idfigure) | |
455 | fig.canvas.manager.set_window_title(self.wintitle) |
|
458 | fig.canvas.manager.set_window_title(self.wintitle) | |
456 | fig.canvas.resize(self.xw,self.yw) |
|
459 | fig.canvas.resize(self.xw,self.yw) | |
457 | plt.ion() |
|
460 | plt.ion() | |
458 |
|
461 | |||
459 |
|
462 | |||
460 | def setColormap(self, colormap): |
|
463 | def setColormap(self, colormap): | |
461 | pass |
|
464 | pass | |
462 |
|
465 | |||
463 | def openDriver(self): |
|
466 | def openDriver(self): | |
464 | pass |
|
467 | pass | |
465 |
|
468 | |||
466 | def openFigure(self): |
|
469 | def openFigure(self): | |
467 | pass |
|
470 | pass | |
468 |
|
471 | |||
469 | def setFigTitle(self,title): |
|
472 | def setFigTitle(self,title): | |
470 | fig = plt.figure(self.idfigure) |
|
473 | fig = plt.figure(self.idfigure) | |
471 | fig.suptitle(title,fontsize=11, fontweight='bold') |
|
474 | fig.suptitle(title,fontsize=11, fontweight='bold') | |
472 |
|
475 | |||
473 | def setSubPlots(self,nrows,ncolumns): |
|
476 | def setSubPlots(self,nrows,ncolumns): | |
474 | fig = plt.figure(self.idfigure) |
|
477 | fig = plt.figure(self.idfigure) | |
475 | self.nrows = nrows |
|
478 | self.nrows = nrows | |
476 | self.ncolumns = ncolumns |
|
479 | self.ncolumns = ncolumns | |
477 | #self.__axesId = fig.add_subplot(nrows,ncolumns) |
|
480 | #self.__axesId = fig.add_subplot(nrows,ncolumns) | |
478 |
|
481 | |||
479 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar, xaxisastime, timefmt): |
|
482 | def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar, xaxisastime, timefmt): | |
480 | fig = plt.figure(self.idfigure) |
|
483 | fig = plt.figure(self.idfigure) | |
481 | ax = fig.add_subplot(self.nrows,self.ncolumns,id) |
|
484 | ax = fig.add_subplot(self.nrows,self.ncolumns,id) | |
482 | ax.set_xlim([xmin,xmax]) |
|
485 | ax.set_xlim([xmin,xmax]) | |
483 | ax.set_ylim([ymin,ymax]) |
|
486 | ax.set_ylim([ymin,ymax]) | |
484 | self.__axesId.setdefault(id) |
|
487 | self.__axesId.setdefault(id) | |
485 | self.__axesId[id] = ax |
|
488 | self.__axesId[id] = ax | |
486 |
|
489 | |||
487 |
|
490 | |||
488 | def setPlotLabels(self, id, xlabel, ylabel, title): |
|
491 | def setPlotLabels(self, id, xlabel, ylabel, title): | |
489 | ax = self.__axesId[id] |
|
492 | ax = self.__axesId[id] | |
490 | ax.set_xlabel(xlabel) |
|
493 | ax.set_xlabel(xlabel) | |
491 | ax.set_ylabel(ylabel) |
|
494 | ax.set_ylabel(ylabel) | |
492 | ax.set_title(title) |
|
495 | ax.set_title(title) | |
493 |
|
496 | |||
494 | def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): |
|
497 | def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color): | |
495 | ax = self.__axesId[id] |
|
498 | ax = self.__axesId[id] | |
496 |
|
499 | |||
497 | if self.__setData == None: |
|
500 | if self.__setData == None: | |
498 | ax.plot(x,y,color) |
|
501 | ax.plot(x,y,color) | |
499 | self.__setData = True |
|
502 | self.__setData = True | |
500 | else: |
|
503 | else: | |
501 | ax.lines[0].set_data(x,y) |
|
504 | ax.lines[0].set_data(x,y) | |
502 |
|
505 | |||
503 | def refresh(self): |
|
506 | def refresh(self): | |
504 | plt.draw() |
|
507 | plt.draw() | |
505 |
|
508 | |||
506 |
|
509 | |||
507 | def plotColorbar(self): |
|
510 | def plotColorbar(self): | |
508 | pass |
|
511 | pass | |
509 |
|
512 | |||
510 |
|
513 | |||
511 | def closePage(self): |
|
514 | def closePage(self): | |
512 | pass No newline at end of file |
|
515 | pass |
@@ -1,763 +1,763 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import glob |
|
8 | import glob | |
9 | import time |
|
9 | import time | |
10 | import numpy |
|
10 | import numpy | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import time, datetime |
|
12 | import time, datetime | |
13 |
|
13 | |||
14 | path = os.path.split(os.getcwd())[0] |
|
14 | path = os.path.split(os.getcwd())[0] | |
15 | sys.path.append(path) |
|
15 | sys.path.append(path) | |
16 |
|
16 | |||
17 | from JROHeaderIO import * |
|
17 | from JROHeaderIO import * | |
18 | from Data.JROData import JROData |
|
18 | from Data.JROData import JROData | |
19 |
|
19 | |||
20 | def isNumber(str): |
|
20 | def isNumber(str): | |
21 | """ |
|
21 | """ | |
22 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
22 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
23 |
|
23 | |||
24 | Excepciones: |
|
24 | Excepciones: | |
25 | Si un determinado string no puede ser convertido a numero |
|
25 | Si un determinado string no puede ser convertido a numero | |
26 | Input: |
|
26 | Input: | |
27 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
27 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
28 |
|
28 | |||
29 | Return: |
|
29 | Return: | |
30 | True : si el string es uno numerico |
|
30 | True : si el string es uno numerico | |
31 | False : no es un string numerico |
|
31 | False : no es un string numerico | |
32 | """ |
|
32 | """ | |
33 | try: |
|
33 | try: | |
34 | float( str ) |
|
34 | float( str ) | |
35 | return True |
|
35 | return True | |
36 | except: |
|
36 | except: | |
37 | return False |
|
37 | return False | |
38 |
|
38 | |||
39 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
39 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
40 | """ |
|
40 | """ | |
41 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
41 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
42 |
|
42 | |||
43 | Inputs: |
|
43 | Inputs: | |
44 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
44 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
45 |
|
45 | |||
46 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
46 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
47 | segundos contados desde 01/01/1970. |
|
47 | segundos contados desde 01/01/1970. | |
48 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
48 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
49 | segundos contados desde 01/01/1970. |
|
49 | segundos contados desde 01/01/1970. | |
50 |
|
50 | |||
51 | Return: |
|
51 | Return: | |
52 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
52 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
53 | fecha especificado, de lo contrario retorna False. |
|
53 | fecha especificado, de lo contrario retorna False. | |
54 |
|
54 | |||
55 | Excepciones: |
|
55 | Excepciones: | |
56 | Si el archivo no existe o no puede ser abierto |
|
56 | Si el archivo no existe o no puede ser abierto | |
57 | Si la cabecera no puede ser leida. |
|
57 | Si la cabecera no puede ser leida. | |
58 |
|
58 | |||
59 | """ |
|
59 | """ | |
60 | basicHeaderObj = BasicHeader() |
|
60 | basicHeaderObj = BasicHeader() | |
61 |
|
61 | |||
62 | try: |
|
62 | try: | |
63 | fp = open(filename,'rb') |
|
63 | fp = open(filename,'rb') | |
64 | except: |
|
64 | except: | |
65 | raise IOError, "The file %s can't be opened" %(filename) |
|
65 | raise IOError, "The file %s can't be opened" %(filename) | |
66 |
|
66 | |||
67 | sts = basicHeaderObj.read(fp) |
|
67 | sts = basicHeaderObj.read(fp) | |
68 | fp.close() |
|
68 | fp.close() | |
69 |
|
69 | |||
70 | if not(sts): |
|
70 | if not(sts): | |
71 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
71 | print "Skipping the file %s because it has not a valid header" %(filename) | |
72 | return 0 |
|
72 | return 0 | |
73 |
|
73 | |||
74 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
74 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
75 | return 0 |
|
75 | return 0 | |
76 |
|
76 | |||
77 | return 1 |
|
77 | return 1 | |
78 |
|
78 | |||
79 |
|
79 | |||
80 |
|
80 | |||
81 |
|
81 | |||
82 | class JRODataIO: |
|
82 | class JRODataIO: | |
83 |
|
83 | |||
84 | c = 3E8 |
|
84 | c = 3E8 | |
85 |
|
85 | |||
86 | basicHeaderObj = BasicHeader() |
|
86 | basicHeaderObj = BasicHeader() | |
87 |
|
87 | |||
88 | systemHeaderObj = SystemHeader() |
|
88 | systemHeaderObj = SystemHeader() | |
89 |
|
89 | |||
90 | radarControllerHeaderObj = RadarControllerHeader() |
|
90 | radarControllerHeaderObj = RadarControllerHeader() | |
91 |
|
91 | |||
92 | processingHeaderObj = ProcessingHeader() |
|
92 | processingHeaderObj = ProcessingHeader() | |
93 |
|
93 | |||
94 | online = 0 |
|
94 | online = 0 | |
95 |
|
95 | |||
96 | dtype = None |
|
96 | dtype = None | |
97 |
|
97 | |||
98 | pathList = [] |
|
98 | pathList = [] | |
99 |
|
99 | |||
100 | filenameList = [] |
|
100 | filenameList = [] | |
101 |
|
101 | |||
102 | filename = None |
|
102 | filename = None | |
103 |
|
103 | |||
104 | ext = None |
|
104 | ext = None | |
105 |
|
105 | |||
106 | flagNoMoreFiles = 0 |
|
106 | flagNoMoreFiles = 0 | |
107 |
|
107 | |||
108 | flagIsNewFile = 1 |
|
108 | flagIsNewFile = 1 | |
109 |
|
109 | |||
110 | flagTimeBlock = 0 |
|
110 | flagTimeBlock = 0 | |
111 |
|
111 | |||
112 | flagIsNewBlock = 0 |
|
112 | flagIsNewBlock = 0 | |
113 |
|
113 | |||
114 | fp = None |
|
114 | fp = None | |
115 |
|
115 | |||
116 | firstHeaderSize = 0 |
|
116 | firstHeaderSize = 0 | |
117 |
|
117 | |||
118 | basicHeaderSize = 24 |
|
118 | basicHeaderSize = 24 | |
119 |
|
119 | |||
120 | versionFile = 1103 |
|
120 | versionFile = 1103 | |
121 |
|
121 | |||
122 | fileSize = None |
|
122 | fileSize = None | |
123 |
|
123 | |||
124 | ippSeconds = None |
|
124 | ippSeconds = None | |
125 |
|
125 | |||
126 | fileSizeByHeader = None |
|
126 | fileSizeByHeader = None | |
127 |
|
127 | |||
128 | fileIndex = None |
|
128 | fileIndex = None | |
129 |
|
129 | |||
130 | profileIndex = None |
|
130 | profileIndex = None | |
131 |
|
131 | |||
132 | blockIndex = None |
|
132 | blockIndex = None | |
133 |
|
133 | |||
134 | nTotalBlocks = None |
|
134 | nTotalBlocks = None | |
135 |
|
135 | |||
136 | maxTimeStep = 30 |
|
136 | maxTimeStep = 30 | |
137 |
|
137 | |||
138 | lastUTTime = None |
|
138 | lastUTTime = None | |
139 |
|
139 | |||
140 | datablock = None |
|
140 | datablock = None | |
141 |
|
141 | |||
142 | dataOutObj = None |
|
142 | dataOutObj = None | |
143 |
|
143 | |||
144 | blocksize = None |
|
144 | blocksize = None | |
145 |
|
145 | |||
146 | def __init__(self): |
|
146 | def __init__(self): | |
147 | pass |
|
147 | pass | |
148 |
|
148 | |||
149 | class JRODataReader(JRODataIO): |
|
149 | class JRODataReader(JRODataIO): | |
150 |
|
150 | |||
151 | nReadBlocks = 0 |
|
151 | nReadBlocks = 0 | |
152 |
|
152 | |||
153 | def __init__(self): |
|
153 | def __init__(self): | |
154 |
|
154 | |||
155 | pass |
|
155 | pass | |
156 |
|
156 | |||
157 | def createObjByDefault(self): |
|
157 | def createObjByDefault(self): | |
158 | """ |
|
158 | """ | |
159 |
|
159 | |||
160 | """ |
|
160 | """ | |
161 | raise ValueError, "This method has not been implemented" |
|
161 | raise ValueError, "This method has not been implemented" | |
162 |
|
162 | |||
163 | def getBlockDimension(self): |
|
163 | def getBlockDimension(self): | |
164 |
|
164 | |||
165 | raise ValueError, "No implemented" |
|
165 | raise ValueError, "No implemented" | |
166 |
|
166 | |||
167 | def __searchFilesOffLine(self, |
|
167 | def __searchFilesOffLine(self, | |
168 | path, |
|
168 | path, | |
169 | startDate, |
|
169 | startDate, | |
170 | endDate, |
|
170 | endDate, | |
171 | startTime=datetime.time(0,0,0), |
|
171 | startTime=datetime.time(0,0,0), | |
172 | endTime=datetime.time(23,59,59), |
|
172 | endTime=datetime.time(23,59,59), | |
173 | set=None, |
|
173 | set=None, | |
174 | expLabel="", |
|
174 | expLabel="", | |
175 | ext=".r"): |
|
175 | ext=".r"): | |
176 | dirList = [] |
|
176 | dirList = [] | |
177 | for thisPath in os.listdir(path): |
|
177 | for thisPath in os.listdir(path): | |
178 | if os.path.isdir(os.path.join(path,thisPath)): |
|
178 | if os.path.isdir(os.path.join(path,thisPath)): | |
179 | dirList.append(thisPath) |
|
179 | dirList.append(thisPath) | |
180 |
|
180 | |||
181 | if not(dirList): |
|
181 | if not(dirList): | |
182 | return None, None |
|
182 | return None, None | |
183 |
|
183 | |||
184 | pathList = [] |
|
184 | pathList = [] | |
185 | dateList = [] |
|
185 | dateList = [] | |
186 |
|
186 | |||
187 | thisDate = startDate |
|
187 | thisDate = startDate | |
188 |
|
188 | |||
189 | while(thisDate <= endDate): |
|
189 | while(thisDate <= endDate): | |
190 | year = thisDate.timetuple().tm_year |
|
190 | year = thisDate.timetuple().tm_year | |
191 | doy = thisDate.timetuple().tm_yday |
|
191 | doy = thisDate.timetuple().tm_yday | |
192 |
|
192 | |||
193 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
193 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
194 | if len(match) == 0: |
|
194 | if len(match) == 0: | |
195 | thisDate += datetime.timedelta(1) |
|
195 | thisDate += datetime.timedelta(1) | |
196 | continue |
|
196 | continue | |
197 |
|
197 | |||
198 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
198 | pathList.append(os.path.join(path,match[0],expLabel)) | |
199 | dateList.append(thisDate) |
|
199 | dateList.append(thisDate) | |
200 | thisDate += datetime.timedelta(1) |
|
200 | thisDate += datetime.timedelta(1) | |
201 |
|
201 | |||
202 | filenameList = [] |
|
202 | filenameList = [] | |
203 | for index in range(len(pathList)): |
|
203 | for index in range(len(pathList)): | |
204 |
|
204 | |||
205 | thisPath = pathList[index] |
|
205 | thisPath = pathList[index] | |
206 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
206 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
207 | fileList.sort() |
|
207 | fileList.sort() | |
208 |
|
208 | |||
209 | #Busqueda de datos en el rango de horas indicados |
|
209 | #Busqueda de datos en el rango de horas indicados | |
210 | thisDate = dateList[index] |
|
210 | thisDate = dateList[index] | |
211 | startDT = datetime.datetime.combine(thisDate, startTime) |
|
211 | startDT = datetime.datetime.combine(thisDate, startTime) | |
212 | endDT = datetime.datetime.combine(thisDate, endTime) |
|
212 | endDT = datetime.datetime.combine(thisDate, endTime) | |
213 |
|
213 | |||
214 | startUtSeconds = time.mktime(startDT.timetuple()) |
|
214 | startUtSeconds = time.mktime(startDT.timetuple()) | |
215 | endUtSeconds = time.mktime(endDT.timetuple()) |
|
215 | endUtSeconds = time.mktime(endDT.timetuple()) | |
216 |
|
216 | |||
217 | for file in fileList: |
|
217 | for file in fileList: | |
218 |
|
218 | |||
219 | filename = os.path.join(thisPath,file) |
|
219 | filename = os.path.join(thisPath,file) | |
220 |
|
220 | |||
221 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
221 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
222 | filenameList.append(filename) |
|
222 | filenameList.append(filename) | |
223 |
|
223 | |||
224 | if not(filenameList): |
|
224 | if not(filenameList): | |
225 | return None, None |
|
225 | return None, None | |
226 |
|
226 | |||
227 | self.filenameList = filenameList |
|
227 | self.filenameList = filenameList | |
228 |
|
228 | |||
229 | return pathList, filenameList |
|
229 | return pathList, filenameList | |
230 |
|
230 | |||
231 | def setup(self,dataOutObj=None, |
|
231 | def setup(self,dataOutObj=None, | |
232 | path=None, |
|
232 | path=None, | |
233 | startDate=None, |
|
233 | startDate=None, | |
234 | endDate=None, |
|
234 | endDate=None, | |
235 | startTime=datetime.time(0,0,0), |
|
235 | startTime=datetime.time(0,0,0), | |
236 | endTime=datetime.time(23,59,59), |
|
236 | endTime=datetime.time(23,59,59), | |
237 | set=0, |
|
237 | set=0, | |
238 | expLabel = "", |
|
238 | expLabel = "", | |
239 | ext = None, |
|
239 | ext = None, | |
240 | online = 0): |
|
240 | online = 0): | |
241 |
|
241 | |||
242 | if path == None: |
|
242 | if path == None: | |
243 | raise ValueError, "The path is not valid" |
|
243 | raise ValueError, "The path is not valid" | |
244 |
|
244 | |||
245 | if ext == None: |
|
245 | if ext == None: | |
246 | ext = self.ext |
|
246 | ext = self.ext | |
247 |
|
247 | |||
248 | if dataOutObj == None: |
|
248 | if dataOutObj == None: | |
249 | dataOutObj = self.createObjByDefault() |
|
249 | dataOutObj = self.createObjByDefault() | |
250 |
|
250 | |||
251 | self.dataOutObj = dataOutObj |
|
251 | self.dataOutObj = dataOutObj | |
252 |
|
252 | |||
253 | if online: |
|
253 | if online: | |
254 | pass |
|
254 | pass | |
255 |
|
255 | |||
256 | else: |
|
256 | else: | |
257 | print "Searching files in offline mode" |
|
257 | print "Searching files in offline mode ..." | |
258 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) |
|
258 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) | |
259 |
|
259 | |||
260 | if not(pathList): |
|
260 | if not(pathList): | |
261 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
261 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
262 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
262 | datetime.datetime.combine(startDate,startTime).ctime(), | |
263 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
263 | datetime.datetime.combine(endDate,endTime).ctime()) | |
264 |
|
264 | |||
265 | sys.exit(-1) |
|
265 | sys.exit(-1) | |
266 |
|
266 | |||
267 |
|
267 | |||
268 | self.fileIndex = -1 |
|
268 | self.fileIndex = -1 | |
269 | self.pathList = pathList |
|
269 | self.pathList = pathList | |
270 | self.filenameList = filenameList |
|
270 | self.filenameList = filenameList | |
271 |
|
271 | |||
272 | self.online = online |
|
272 | self.online = online | |
273 | ext = ext.lower() |
|
273 | ext = ext.lower() | |
274 | self.ext = ext |
|
274 | self.ext = ext | |
275 |
|
275 | |||
276 | if not(self.setNextFile()): |
|
276 | if not(self.setNextFile()): | |
277 | if (startDate!=None) and (endDate!=None): |
|
277 | if (startDate!=None) and (endDate!=None): | |
278 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
278 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
279 | elif startDate != None: |
|
279 | elif startDate != None: | |
280 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
280 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
281 | else: |
|
281 | else: | |
282 | print "No files" |
|
282 | print "No files" | |
283 |
|
283 | |||
284 | sys.exit(-1) |
|
284 | sys.exit(-1) | |
285 |
|
285 | |||
286 | # self.updateDataHeader() |
|
286 | # self.updateDataHeader() | |
287 |
|
287 | |||
288 | return self.dataOutObj |
|
288 | return self.dataOutObj | |
289 |
|
289 | |||
290 | def __setNextFileOffline(self): |
|
290 | def __setNextFileOffline(self): | |
291 | idFile = self.fileIndex |
|
291 | idFile = self.fileIndex | |
292 |
|
292 | |||
293 | while (True): |
|
293 | while (True): | |
294 | idFile += 1 |
|
294 | idFile += 1 | |
295 | if not(idFile < len(self.filenameList)): |
|
295 | if not(idFile < len(self.filenameList)): | |
296 | self.flagNoMoreFiles = 1 |
|
296 | self.flagNoMoreFiles = 1 | |
297 | print "No more Files" |
|
297 | print "No more Files" | |
298 | return 0 |
|
298 | return 0 | |
299 |
|
299 | |||
300 | filename = self.filenameList[idFile] |
|
300 | filename = self.filenameList[idFile] | |
301 |
|
301 | |||
302 | if not(self.__verifyFile(filename)): |
|
302 | if not(self.__verifyFile(filename)): | |
303 | continue |
|
303 | continue | |
304 |
|
304 | |||
305 | fileSize = os.path.getsize(filename) |
|
305 | fileSize = os.path.getsize(filename) | |
306 | fp = open(filename,'rb') |
|
306 | fp = open(filename,'rb') | |
307 | break |
|
307 | break | |
308 |
|
308 | |||
309 | self.flagIsNewFile = 1 |
|
309 | self.flagIsNewFile = 1 | |
310 | self.fileIndex = idFile |
|
310 | self.fileIndex = idFile | |
311 | self.filename = filename |
|
311 | self.filename = filename | |
312 | self.fileSize = fileSize |
|
312 | self.fileSize = fileSize | |
313 | self.fp = fp |
|
313 | self.fp = fp | |
314 |
|
314 | |||
315 | print "Setting the file: %s"%self.filename |
|
315 | print "Setting the file: %s"%self.filename | |
316 |
|
316 | |||
317 | return 1 |
|
317 | return 1 | |
318 |
|
318 | |||
319 |
|
319 | |||
320 |
|
320 | |||
321 | def setNextFile(self): |
|
321 | def setNextFile(self): | |
322 | if self.fp != None: |
|
322 | if self.fp != None: | |
323 | self.fp.close() |
|
323 | self.fp.close() | |
324 |
|
324 | |||
325 | if self.online: |
|
325 | if self.online: | |
326 | newFile = self.__setNextFileOnline() |
|
326 | newFile = self.__setNextFileOnline() | |
327 | else: |
|
327 | else: | |
328 | newFile = self.__setNextFileOffline() |
|
328 | newFile = self.__setNextFileOffline() | |
329 |
|
329 | |||
330 | if not(newFile): |
|
330 | if not(newFile): | |
331 | return 0 |
|
331 | return 0 | |
332 |
|
332 | |||
333 | self.__readFirstHeader() |
|
333 | self.__readFirstHeader() | |
334 | self.nReadBlocks = 0 |
|
334 | self.nReadBlocks = 0 | |
335 | return 1 |
|
335 | return 1 | |
336 |
|
336 | |||
337 | def __setNewBlock(self): |
|
337 | def __setNewBlock(self): | |
338 | if self.fp == None: |
|
338 | if self.fp == None: | |
339 | return 0 |
|
339 | return 0 | |
340 |
|
340 | |||
341 | if self.flagIsNewFile: |
|
341 | if self.flagIsNewFile: | |
342 | return 1 |
|
342 | return 1 | |
343 |
|
343 | |||
344 | self.lastUTTime = self.basicHeaderObj.utc |
|
344 | self.lastUTTime = self.basicHeaderObj.utc | |
345 | currentSize = self.fileSize - self.fp.tell() |
|
345 | currentSize = self.fileSize - self.fp.tell() | |
346 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
346 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
347 |
|
347 | |||
348 | if (currentSize >= neededSize): |
|
348 | if (currentSize >= neededSize): | |
349 | self.__rdBasicHeader() |
|
349 | self.__rdBasicHeader() | |
350 | return 1 |
|
350 | return 1 | |
351 |
|
351 | |||
352 | if not(self.setNextFile()): |
|
352 | if not(self.setNextFile()): | |
353 | return 0 |
|
353 | return 0 | |
354 |
|
354 | |||
355 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
355 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
356 |
|
356 | |||
357 | self.flagTimeBlock = 0 |
|
357 | self.flagTimeBlock = 0 | |
358 |
|
358 | |||
359 | if deltaTime > self.maxTimeStep: |
|
359 | if deltaTime > self.maxTimeStep: | |
360 | self.flagTimeBlock = 1 |
|
360 | self.flagTimeBlock = 1 | |
361 |
|
361 | |||
362 | return 1 |
|
362 | return 1 | |
363 |
|
363 | |||
364 |
|
364 | |||
365 | def readNextBlock(self): |
|
365 | def readNextBlock(self): | |
366 | if not(self.__setNewBlock()): |
|
366 | if not(self.__setNewBlock()): | |
367 | return 0 |
|
367 | return 0 | |
368 |
|
368 | |||
369 | if not(self.readBlock()): |
|
369 | if not(self.readBlock()): | |
370 | return 0 |
|
370 | return 0 | |
371 |
|
371 | |||
372 | return 1 |
|
372 | return 1 | |
373 |
|
373 | |||
374 | def __rdProcessingHeader(self, fp=None): |
|
374 | def __rdProcessingHeader(self, fp=None): | |
375 | if fp == None: |
|
375 | if fp == None: | |
376 | fp = self.fp |
|
376 | fp = self.fp | |
377 |
|
377 | |||
378 | self.processingHeaderObj.read(fp) |
|
378 | self.processingHeaderObj.read(fp) | |
379 |
|
379 | |||
380 | def __rdRadarControllerHeader(self, fp=None): |
|
380 | def __rdRadarControllerHeader(self, fp=None): | |
381 | if fp == None: |
|
381 | if fp == None: | |
382 | fp = self.fp |
|
382 | fp = self.fp | |
383 |
|
383 | |||
384 | self.radarControllerHeaderObj.read(fp) |
|
384 | self.radarControllerHeaderObj.read(fp) | |
385 |
|
385 | |||
386 | def __rdSystemHeader(self, fp=None): |
|
386 | def __rdSystemHeader(self, fp=None): | |
387 | if fp == None: |
|
387 | if fp == None: | |
388 | fp = self.fp |
|
388 | fp = self.fp | |
389 |
|
389 | |||
390 | self.systemHeaderObj.read(fp) |
|
390 | self.systemHeaderObj.read(fp) | |
391 |
|
391 | |||
392 | def __rdBasicHeader(self, fp=None): |
|
392 | def __rdBasicHeader(self, fp=None): | |
393 | if fp == None: |
|
393 | if fp == None: | |
394 | fp = self.fp |
|
394 | fp = self.fp | |
395 |
|
395 | |||
396 | self.basicHeaderObj.read(fp) |
|
396 | self.basicHeaderObj.read(fp) | |
397 |
|
397 | |||
398 |
|
398 | |||
399 | def __readFirstHeader(self): |
|
399 | def __readFirstHeader(self): | |
400 | self.__rdBasicHeader() |
|
400 | self.__rdBasicHeader() | |
401 | self.__rdSystemHeader() |
|
401 | self.__rdSystemHeader() | |
402 | self.__rdRadarControllerHeader() |
|
402 | self.__rdRadarControllerHeader() | |
403 | self.__rdProcessingHeader() |
|
403 | self.__rdProcessingHeader() | |
404 |
|
404 | |||
405 | self.firstHeaderSize = self.basicHeaderObj.size |
|
405 | self.firstHeaderSize = self.basicHeaderObj.size | |
406 |
|
406 | |||
407 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
407 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
408 | if datatype == 0: |
|
408 | if datatype == 0: | |
409 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
409 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
410 | elif datatype == 1: |
|
410 | elif datatype == 1: | |
411 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
411 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
412 | elif datatype == 2: |
|
412 | elif datatype == 2: | |
413 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
413 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
414 | elif datatype == 3: |
|
414 | elif datatype == 3: | |
415 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
415 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
416 | elif datatype == 4: |
|
416 | elif datatype == 4: | |
417 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
417 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
418 | elif datatype == 5: |
|
418 | elif datatype == 5: | |
419 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
419 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
420 | else: |
|
420 | else: | |
421 | raise ValueError, 'Data type was not defined' |
|
421 | raise ValueError, 'Data type was not defined' | |
422 |
|
422 | |||
423 | self.dtype = datatype_str |
|
423 | self.dtype = datatype_str | |
424 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
424 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
425 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
425 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
426 | # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
426 | # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
427 | # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
427 | # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
428 | self.getBlockDimension() |
|
428 | self.getBlockDimension() | |
429 |
|
429 | |||
430 |
|
430 | |||
431 | def __verifyFile(self, filename, msgFlag=True): |
|
431 | def __verifyFile(self, filename, msgFlag=True): | |
432 | msg = None |
|
432 | msg = None | |
433 | try: |
|
433 | try: | |
434 | fp = open(filename, 'rb') |
|
434 | fp = open(filename, 'rb') | |
435 | currentPosition = fp.tell() |
|
435 | currentPosition = fp.tell() | |
436 | except: |
|
436 | except: | |
437 | if msgFlag: |
|
437 | if msgFlag: | |
438 | print "The file %s can't be opened" % (filename) |
|
438 | print "The file %s can't be opened" % (filename) | |
439 | return False |
|
439 | return False | |
440 |
|
440 | |||
441 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
441 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
442 |
|
442 | |||
443 | if neededSize == 0: |
|
443 | if neededSize == 0: | |
444 | basicHeaderObj = BasicHeader() |
|
444 | basicHeaderObj = BasicHeader() | |
445 | systemHeaderObj = SystemHeader() |
|
445 | systemHeaderObj = SystemHeader() | |
446 | radarControllerHeaderObj = RadarControllerHeader() |
|
446 | radarControllerHeaderObj = RadarControllerHeader() | |
447 | processingHeaderObj = ProcessingHeader() |
|
447 | processingHeaderObj = ProcessingHeader() | |
448 |
|
448 | |||
449 | try: |
|
449 | try: | |
450 | if not( basicHeaderObj.read(fp) ): raise ValueError |
|
450 | if not( basicHeaderObj.read(fp) ): raise ValueError | |
451 | if not( systemHeaderObj.read(fp) ): raise ValueError |
|
451 | if not( systemHeaderObj.read(fp) ): raise ValueError | |
452 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError |
|
452 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError | |
453 | if not( processingHeaderObj.read(fp) ): raise ValueError |
|
453 | if not( processingHeaderObj.read(fp) ): raise ValueError | |
454 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
454 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
455 |
|
455 | |||
456 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
456 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
457 |
|
457 | |||
458 | except: |
|
458 | except: | |
459 | if msgFlag: |
|
459 | if msgFlag: | |
460 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
460 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
461 |
|
461 | |||
462 | fp.close() |
|
462 | fp.close() | |
463 | return False |
|
463 | return False | |
464 | else: |
|
464 | else: | |
465 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
465 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
466 |
|
466 | |||
467 | fp.close() |
|
467 | fp.close() | |
468 | fileSize = os.path.getsize(filename) |
|
468 | fileSize = os.path.getsize(filename) | |
469 | currentSize = fileSize - currentPosition |
|
469 | currentSize = fileSize - currentPosition | |
470 | if currentSize < neededSize: |
|
470 | if currentSize < neededSize: | |
471 | if msgFlag and (msg != None): |
|
471 | if msgFlag and (msg != None): | |
472 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
472 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
473 | return False |
|
473 | return False | |
474 |
|
474 | |||
475 | return True |
|
475 | return True | |
476 |
|
476 | |||
477 | def getData(): |
|
477 | def getData(): | |
478 | pass |
|
478 | pass | |
479 |
|
479 | |||
480 | def hasNotDataInBuffer(): |
|
480 | def hasNotDataInBuffer(): | |
481 | pass |
|
481 | pass | |
482 |
|
482 | |||
483 | def readBlock(): |
|
483 | def readBlock(): | |
484 | pass |
|
484 | pass | |
485 |
|
485 | |||
486 | class JRODataWriter(JRODataIO): |
|
486 | class JRODataWriter(JRODataIO): | |
487 |
|
487 | |||
488 | """ |
|
488 | """ | |
489 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
489 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
490 | de los datos siempre se realiza por bloques. |
|
490 | de los datos siempre se realiza por bloques. | |
491 | """ |
|
491 | """ | |
492 |
|
492 | |||
493 | blockIndex = 0 |
|
493 | blockIndex = 0 | |
494 |
|
494 | |||
495 | path = None |
|
495 | path = None | |
496 |
|
496 | |||
497 | setFile = None |
|
497 | setFile = None | |
498 |
|
498 | |||
499 | profilesPerBlock = None |
|
499 | profilesPerBlock = None | |
500 |
|
500 | |||
501 | blocksPerFile = None |
|
501 | blocksPerFile = None | |
502 |
|
502 | |||
503 | nWriteBlocks = 0 |
|
503 | nWriteBlocks = 0 | |
504 |
|
504 | |||
505 | def __init__(self, dataOutObj=None): |
|
505 | def __init__(self, dataOutObj=None): | |
506 | raise ValueError, "Not implemented" |
|
506 | raise ValueError, "Not implemented" | |
507 |
|
507 | |||
508 |
|
508 | |||
509 | def hasAllDataInBuffer(self): |
|
509 | def hasAllDataInBuffer(self): | |
510 | raise ValueError, "Not implemented" |
|
510 | raise ValueError, "Not implemented" | |
511 |
|
511 | |||
512 |
|
512 | |||
513 | def setBlockDimension(self): |
|
513 | def setBlockDimension(self): | |
514 | raise ValueError, "Not implemented" |
|
514 | raise ValueError, "Not implemented" | |
515 |
|
515 | |||
516 |
|
516 | |||
517 | def writeBlock(self): |
|
517 | def writeBlock(self): | |
518 | raise ValueError, "No implemented" |
|
518 | raise ValueError, "No implemented" | |
519 |
|
519 | |||
520 |
|
520 | |||
521 | def putData(self): |
|
521 | def putData(self): | |
522 | raise ValueError, "No implemented" |
|
522 | raise ValueError, "No implemented" | |
523 |
|
523 | |||
524 |
|
524 | |||
525 | def __writeFirstHeader(self): |
|
525 | def __writeFirstHeader(self): | |
526 | """ |
|
526 | """ | |
527 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
527 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
528 |
|
528 | |||
529 | Affected: |
|
529 | Affected: | |
530 | __dataType |
|
530 | __dataType | |
531 |
|
531 | |||
532 | Return: |
|
532 | Return: | |
533 | None |
|
533 | None | |
534 | """ |
|
534 | """ | |
535 |
|
535 | |||
536 | # CALCULAR PARAMETROS |
|
536 | # CALCULAR PARAMETROS | |
537 |
|
537 | |||
538 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
538 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
539 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
539 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
540 |
|
540 | |||
541 | self.__writeBasicHeader() |
|
541 | self.__writeBasicHeader() | |
542 | self.__wrSystemHeader() |
|
542 | self.__wrSystemHeader() | |
543 | self.__wrRadarControllerHeader() |
|
543 | self.__wrRadarControllerHeader() | |
544 | self.__wrProcessingHeader() |
|
544 | self.__wrProcessingHeader() | |
545 | self.dtype = self.dataOutObj.dtype |
|
545 | self.dtype = self.dataOutObj.dtype | |
546 |
|
546 | |||
547 |
|
547 | |||
548 | def __writeBasicHeader(self, fp=None): |
|
548 | def __writeBasicHeader(self, fp=None): | |
549 | """ |
|
549 | """ | |
550 | Escribe solo el Basic header en el file creado |
|
550 | Escribe solo el Basic header en el file creado | |
551 |
|
551 | |||
552 | Return: |
|
552 | Return: | |
553 | None |
|
553 | None | |
554 | """ |
|
554 | """ | |
555 | if fp == None: |
|
555 | if fp == None: | |
556 | fp = self.fp |
|
556 | fp = self.fp | |
557 |
|
557 | |||
558 | self.basicHeaderObj.write(fp) |
|
558 | self.basicHeaderObj.write(fp) | |
559 |
|
559 | |||
560 |
|
560 | |||
561 | def __wrSystemHeader(self, fp=None): |
|
561 | def __wrSystemHeader(self, fp=None): | |
562 | """ |
|
562 | """ | |
563 | Escribe solo el System header en el file creado |
|
563 | Escribe solo el System header en el file creado | |
564 |
|
564 | |||
565 | Return: |
|
565 | Return: | |
566 | None |
|
566 | None | |
567 | """ |
|
567 | """ | |
568 | if fp == None: |
|
568 | if fp == None: | |
569 | fp = self.fp |
|
569 | fp = self.fp | |
570 |
|
570 | |||
571 | self.systemHeaderObj.write(fp) |
|
571 | self.systemHeaderObj.write(fp) | |
572 |
|
572 | |||
573 |
|
573 | |||
574 | def __wrRadarControllerHeader(self, fp=None): |
|
574 | def __wrRadarControllerHeader(self, fp=None): | |
575 | """ |
|
575 | """ | |
576 | Escribe solo el RadarController header en el file creado |
|
576 | Escribe solo el RadarController header en el file creado | |
577 |
|
577 | |||
578 | Return: |
|
578 | Return: | |
579 | None |
|
579 | None | |
580 | """ |
|
580 | """ | |
581 | if fp == None: |
|
581 | if fp == None: | |
582 | fp = self.fp |
|
582 | fp = self.fp | |
583 |
|
583 | |||
584 | self.radarControllerHeaderObj.write(fp) |
|
584 | self.radarControllerHeaderObj.write(fp) | |
585 |
|
585 | |||
586 |
|
586 | |||
587 | def __wrProcessingHeader(self, fp=None): |
|
587 | def __wrProcessingHeader(self, fp=None): | |
588 | """ |
|
588 | """ | |
589 | Escribe solo el Processing header en el file creado |
|
589 | Escribe solo el Processing header en el file creado | |
590 |
|
590 | |||
591 | Return: |
|
591 | Return: | |
592 | None |
|
592 | None | |
593 | """ |
|
593 | """ | |
594 | if fp == None: |
|
594 | if fp == None: | |
595 | fp = self.fp |
|
595 | fp = self.fp | |
596 |
|
596 | |||
597 | self.processingHeaderObj.write(fp) |
|
597 | self.processingHeaderObj.write(fp) | |
598 |
|
598 | |||
599 |
|
599 | |||
600 | def setNextFile(self): |
|
600 | def setNextFile(self): | |
601 | """ |
|
601 | """ | |
602 | Determina el siguiente file que sera escrito |
|
602 | Determina el siguiente file que sera escrito | |
603 |
|
603 | |||
604 | Affected: |
|
604 | Affected: | |
605 | self.filename |
|
605 | self.filename | |
606 | self.subfolder |
|
606 | self.subfolder | |
607 | self.fp |
|
607 | self.fp | |
608 | self.setFile |
|
608 | self.setFile | |
609 | self.flagIsNewFile |
|
609 | self.flagIsNewFile | |
610 |
|
610 | |||
611 | Return: |
|
611 | Return: | |
612 | 0 : Si el archivo no puede ser escrito |
|
612 | 0 : Si el archivo no puede ser escrito | |
613 | 1 : Si el archivo esta listo para ser escrito |
|
613 | 1 : Si el archivo esta listo para ser escrito | |
614 | """ |
|
614 | """ | |
615 | ext = self.ext |
|
615 | ext = self.ext | |
616 | path = self.path |
|
616 | path = self.path | |
617 |
|
617 | |||
618 | if self.fp != None: |
|
618 | if self.fp != None: | |
619 | self.fp.close() |
|
619 | self.fp.close() | |
620 |
|
620 | |||
621 | timeTuple = time.localtime( self.dataOutObj.dataUtcTime) |
|
621 | timeTuple = time.localtime( self.dataOutObj.dataUtcTime) | |
622 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
622 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
623 |
|
623 | |||
624 | doypath = os.path.join( path, subfolder ) |
|
624 | doypath = os.path.join( path, subfolder ) | |
625 | if not( os.path.exists(doypath) ): |
|
625 | if not( os.path.exists(doypath) ): | |
626 | os.mkdir(doypath) |
|
626 | os.mkdir(doypath) | |
627 | self.setFile = -1 #inicializo mi contador de seteo |
|
627 | self.setFile = -1 #inicializo mi contador de seteo | |
628 | else: |
|
628 | else: | |
629 | filesList = os.listdir( doypath ) |
|
629 | filesList = os.listdir( doypath ) | |
630 | if len( filesList ) > 0: |
|
630 | if len( filesList ) > 0: | |
631 | filesList = sorted( filesList, key=str.lower ) |
|
631 | filesList = sorted( filesList, key=str.lower ) | |
632 | filen = filesList[-1] |
|
632 | filen = filesList[-1] | |
633 | # el filename debera tener el siguiente formato |
|
633 | # el filename debera tener el siguiente formato | |
634 | # 0 1234 567 89A BCDE (hex) |
|
634 | # 0 1234 567 89A BCDE (hex) | |
635 | # x YYYY DDD SSS .ext |
|
635 | # x YYYY DDD SSS .ext | |
636 | if isNumber( filen[8:11] ): |
|
636 | if isNumber( filen[8:11] ): | |
637 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
637 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
638 | else: |
|
638 | else: | |
639 | self.setFile = -1 |
|
639 | self.setFile = -1 | |
640 | else: |
|
640 | else: | |
641 | self.setFile = -1 #inicializo mi contador de seteo |
|
641 | self.setFile = -1 #inicializo mi contador de seteo | |
642 |
|
642 | |||
643 | setFile = self.setFile |
|
643 | setFile = self.setFile | |
644 | setFile += 1 |
|
644 | setFile += 1 | |
645 |
|
645 | |||
646 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
646 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
647 | timeTuple.tm_year, |
|
647 | timeTuple.tm_year, | |
648 | timeTuple.tm_yday, |
|
648 | timeTuple.tm_yday, | |
649 | setFile, |
|
649 | setFile, | |
650 | ext ) |
|
650 | ext ) | |
651 |
|
651 | |||
652 | filename = os.path.join( path, subfolder, file ) |
|
652 | filename = os.path.join( path, subfolder, file ) | |
653 |
|
653 | |||
654 | fp = open( filename,'wb' ) |
|
654 | fp = open( filename,'wb' ) | |
655 |
|
655 | |||
656 | self.blockIndex = 0 |
|
656 | self.blockIndex = 0 | |
657 |
|
657 | |||
658 | #guardando atributos |
|
658 | #guardando atributos | |
659 | self.filename = filename |
|
659 | self.filename = filename | |
660 | self.subfolder = subfolder |
|
660 | self.subfolder = subfolder | |
661 | self.fp = fp |
|
661 | self.fp = fp | |
662 | self.setFile = setFile |
|
662 | self.setFile = setFile | |
663 | self.flagIsNewFile = 1 |
|
663 | self.flagIsNewFile = 1 | |
664 |
|
664 | |||
665 | self.getDataHeader() |
|
665 | self.getDataHeader() | |
666 |
|
666 | |||
667 | print 'Writing the file: %s'%self.filename |
|
667 | print 'Writing the file: %s'%self.filename | |
668 |
|
668 | |||
669 | self.__writeFirstHeader() |
|
669 | self.__writeFirstHeader() | |
670 |
|
670 | |||
671 | return 1 |
|
671 | return 1 | |
672 |
|
672 | |||
673 |
|
673 | |||
674 | def __setNewBlock(self): |
|
674 | def __setNewBlock(self): | |
675 | """ |
|
675 | """ | |
676 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
676 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
677 |
|
677 | |||
678 | Return: |
|
678 | Return: | |
679 | 0 : si no pudo escribir nada |
|
679 | 0 : si no pudo escribir nada | |
680 | 1 : Si escribio el Basic el First Header |
|
680 | 1 : Si escribio el Basic el First Header | |
681 | """ |
|
681 | """ | |
682 | if self.fp == None: |
|
682 | if self.fp == None: | |
683 | self.setNextFile() |
|
683 | self.setNextFile() | |
684 |
|
684 | |||
685 | if self.flagIsNewFile: |
|
685 | if self.flagIsNewFile: | |
686 | return 1 |
|
686 | return 1 | |
687 |
|
687 | |||
688 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
688 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
689 | self.__writeBasicHeader() |
|
689 | self.__writeBasicHeader() | |
690 | return 1 |
|
690 | return 1 | |
691 |
|
691 | |||
692 | if not( self.setNextFile() ): |
|
692 | if not( self.setNextFile() ): | |
693 | return 0 |
|
693 | return 0 | |
694 |
|
694 | |||
695 | return 1 |
|
695 | return 1 | |
696 |
|
696 | |||
697 |
|
697 | |||
698 | def writeNextBlock(self): |
|
698 | def writeNextBlock(self): | |
699 | """ |
|
699 | """ | |
700 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
700 | Selecciona el bloque siguiente de datos y los escribe en un file | |
701 |
|
701 | |||
702 | Return: |
|
702 | Return: | |
703 | 0 : Si no hizo pudo escribir el bloque de datos |
|
703 | 0 : Si no hizo pudo escribir el bloque de datos | |
704 | 1 : Si no pudo escribir el bloque de datos |
|
704 | 1 : Si no pudo escribir el bloque de datos | |
705 | """ |
|
705 | """ | |
706 | if not( self.__setNewBlock() ): |
|
706 | if not( self.__setNewBlock() ): | |
707 | return 0 |
|
707 | return 0 | |
708 |
|
708 | |||
709 | self.writeBlock() |
|
709 | self.writeBlock() | |
710 |
|
710 | |||
711 | return 1 |
|
711 | return 1 | |
712 |
|
712 | |||
713 |
|
713 | |||
714 | def getDataHeader(self): |
|
714 | def getDataHeader(self): | |
715 | """Obtiene una copia del First Header Affected: self.basicHeaderObj self. |
|
715 | """Obtiene una copia del First Header Affected: self.basicHeaderObj self. | |
716 | systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self. |
|
716 | systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self. | |
717 | dtype Return: None |
|
717 | dtype Return: None | |
718 | """ |
|
718 | """ | |
719 |
|
719 | |||
720 | raise ValueError, "No implemented" |
|
720 | raise ValueError, "No implemented" | |
721 |
|
721 | |||
722 | def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): |
|
722 | def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
723 | """ |
|
723 | """ | |
724 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
724 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
725 |
|
725 | |||
726 | Inputs: |
|
726 | Inputs: | |
727 | path : el path destino en el cual se escribiran los files a crear |
|
727 | path : el path destino en el cual se escribiran los files a crear | |
728 | format : formato en el cual sera salvado un file |
|
728 | format : formato en el cual sera salvado un file | |
729 | set : el setebo del file |
|
729 | set : el setebo del file | |
730 |
|
730 | |||
731 | Return: |
|
731 | Return: | |
732 | 0 : Si no realizo un buen seteo |
|
732 | 0 : Si no realizo un buen seteo | |
733 | 1 : Si realizo un buen seteo |
|
733 | 1 : Si realizo un buen seteo | |
734 | """ |
|
734 | """ | |
735 |
|
735 | |||
736 | if ext == None: |
|
736 | if ext == None: | |
737 | ext = self.ext |
|
737 | ext = self.ext | |
738 |
|
738 | |||
739 | ext = ext.lower() |
|
739 | ext = ext.lower() | |
740 |
|
740 | |||
741 | self.ext = ext |
|
741 | self.ext = ext | |
742 |
|
742 | |||
743 | self.path = path |
|
743 | self.path = path | |
744 |
|
744 | |||
745 | self.setFile = set - 1 |
|
745 | self.setFile = set - 1 | |
746 |
|
746 | |||
747 | self.blocksPerFile = blocksPerFile |
|
747 | self.blocksPerFile = blocksPerFile | |
748 |
|
748 | |||
749 | self.profilesPerBlock = profilesPerBlock |
|
749 | self.profilesPerBlock = profilesPerBlock | |
750 |
|
750 | |||
751 | if not(self.setNextFile()): |
|
751 | if not(self.setNextFile()): | |
752 | print "There isn't a next file" |
|
752 | print "There isn't a next file" | |
753 | return 0 |
|
753 | return 0 | |
754 |
|
754 | |||
755 | self.setBlockDimension() |
|
755 | self.setBlockDimension() | |
756 |
|
756 | |||
757 | return 1 |
|
757 | return 1 | |
758 |
|
758 | |||
759 |
|
759 | |||
760 |
|
760 | |||
761 |
|
761 | |||
762 |
|
762 | |||
763 |
|
763 |
@@ -1,777 +1,777 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import glob |
|
9 | import glob | |
10 | import fnmatch |
|
10 | import fnmatch | |
11 | import time, datetime |
|
11 | import time, datetime | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from JROHeaderIO import * |
|
16 | from JROHeaderIO import * | |
17 | from JRODataIO import JRODataReader |
|
17 | from JRODataIO import JRODataReader | |
18 | from JRODataIO import JRODataWriter |
|
18 | from JRODataIO import JRODataWriter | |
19 |
|
19 | |||
20 | from Data.JROData import Spectra |
|
20 | from Data.JROData import Spectra | |
21 |
|
21 | |||
22 | class SpectraReader(JRODataReader): |
|
22 | class SpectraReader(JRODataReader): | |
23 | """ |
|
23 | """ | |
24 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
24 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
26 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
26 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
27 |
|
27 | |||
28 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
28 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
29 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
29 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
30 | canales * alturas (DC Channels) |
|
30 | canales * alturas (DC Channels) | |
31 |
|
31 | |||
32 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
32 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
33 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
33 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
34 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
34 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
35 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
35 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
36 |
|
36 | |||
37 | Example: |
|
37 | Example: | |
38 | dpath = "/home/myuser/data" |
|
38 | dpath = "/home/myuser/data" | |
39 |
|
39 | |||
40 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
40 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
41 |
|
41 | |||
42 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
42 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
43 |
|
43 | |||
44 | readerObj = SpectraReader() |
|
44 | readerObj = SpectraReader() | |
45 |
|
45 | |||
46 | readerObj.setup(dpath, startTime, endTime) |
|
46 | readerObj.setup(dpath, startTime, endTime) | |
47 |
|
47 | |||
48 | while(True): |
|
48 | while(True): | |
49 |
|
49 | |||
50 | readerObj.getData() |
|
50 | readerObj.getData() | |
51 |
|
51 | |||
52 | print readerObj.data_spc |
|
52 | print readerObj.data_spc | |
53 |
|
53 | |||
54 | print readerObj.data_cspc |
|
54 | print readerObj.data_cspc | |
55 |
|
55 | |||
56 | print readerObj.data_dc |
|
56 | print readerObj.data_dc | |
57 |
|
57 | |||
58 | if readerObj.flagNoMoreFiles: |
|
58 | if readerObj.flagNoMoreFiles: | |
59 | break |
|
59 | break | |
60 |
|
60 | |||
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | pts2read_SelfSpectra = 0 |
|
63 | pts2read_SelfSpectra = 0 | |
64 |
|
64 | |||
65 | pts2read_CrossSpectra = 0 |
|
65 | pts2read_CrossSpectra = 0 | |
66 |
|
66 | |||
67 | pts2read_DCchannels = 0 |
|
67 | pts2read_DCchannels = 0 | |
68 |
|
68 | |||
69 | ext = ".pdata" |
|
69 | ext = ".pdata" | |
70 |
|
70 | |||
71 | optchar = "P" |
|
71 | optchar = "P" | |
72 |
|
72 | |||
73 | dataOutObj = None |
|
73 | dataOutObj = None | |
74 |
|
74 | |||
75 | nRdChannels = None |
|
75 | nRdChannels = None | |
76 |
|
76 | |||
77 | nRdPairs = None |
|
77 | nRdPairs = None | |
78 |
|
78 | |||
79 | rdPairList = [] |
|
79 | rdPairList = [] | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | def __init__(self, dataOutObj=None): |
|
82 | def __init__(self, dataOutObj=None): | |
83 | """ |
|
83 | """ | |
84 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
84 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
85 |
|
85 | |||
86 | Inputs: |
|
86 | Inputs: | |
87 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
87 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para | |
88 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
88 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
89 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
89 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
90 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
90 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
91 | bloque de datos. |
|
91 | bloque de datos. | |
92 | Si este parametro no es pasado se creara uno internamente. |
|
92 | Si este parametro no es pasado se creara uno internamente. | |
93 |
|
93 | |||
94 | Affected: |
|
94 | Affected: | |
95 | self.dataOutObj |
|
95 | self.dataOutObj | |
96 |
|
96 | |||
97 | Return : None |
|
97 | Return : None | |
98 | """ |
|
98 | """ | |
99 |
|
99 | |||
100 | self.pts2read_SelfSpectra = 0 |
|
100 | self.pts2read_SelfSpectra = 0 | |
101 |
|
101 | |||
102 | self.pts2read_CrossSpectra = 0 |
|
102 | self.pts2read_CrossSpectra = 0 | |
103 |
|
103 | |||
104 | self.pts2read_DCchannels = 0 |
|
104 | self.pts2read_DCchannels = 0 | |
105 |
|
105 | |||
106 | self.datablock = None |
|
106 | self.datablock = None | |
107 |
|
107 | |||
108 | self.utc = None |
|
108 | self.utc = None | |
109 |
|
109 | |||
110 | self.ext = ".pdata" |
|
110 | self.ext = ".pdata" | |
111 |
|
111 | |||
112 | self.optchar = "P" |
|
112 | self.optchar = "P" | |
113 |
|
113 | |||
114 | self.basicHeaderObj = BasicHeader() |
|
114 | self.basicHeaderObj = BasicHeader() | |
115 |
|
115 | |||
116 | self.systemHeaderObj = SystemHeader() |
|
116 | self.systemHeaderObj = SystemHeader() | |
117 |
|
117 | |||
118 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
118 | self.radarControllerHeaderObj = RadarControllerHeader() | |
119 |
|
119 | |||
120 | self.processingHeaderObj = ProcessingHeader() |
|
120 | self.processingHeaderObj = ProcessingHeader() | |
121 |
|
121 | |||
122 | self.online = 0 |
|
122 | self.online = 0 | |
123 |
|
123 | |||
124 | self.fp = None |
|
124 | self.fp = None | |
125 |
|
125 | |||
126 | self.idFile = None |
|
126 | self.idFile = None | |
127 |
|
127 | |||
128 | self.dtype = None |
|
128 | self.dtype = None | |
129 |
|
129 | |||
130 | self.fileSizeByHeader = None |
|
130 | self.fileSizeByHeader = None | |
131 |
|
131 | |||
132 | self.filenameList = [] |
|
132 | self.filenameList = [] | |
133 |
|
133 | |||
134 | self.filename = None |
|
134 | self.filename = None | |
135 |
|
135 | |||
136 | self.fileSize = None |
|
136 | self.fileSize = None | |
137 |
|
137 | |||
138 | self.firstHeaderSize = 0 |
|
138 | self.firstHeaderSize = 0 | |
139 |
|
139 | |||
140 | self.basicHeaderSize = 24 |
|
140 | self.basicHeaderSize = 24 | |
141 |
|
141 | |||
142 | self.pathList = [] |
|
142 | self.pathList = [] | |
143 |
|
143 | |||
144 | self.lastUTTime = 0 |
|
144 | self.lastUTTime = 0 | |
145 |
|
145 | |||
146 | self.maxTimeStep = 30 |
|
146 | self.maxTimeStep = 30 | |
147 |
|
147 | |||
148 | self.flagNoMoreFiles = 0 |
|
148 | self.flagNoMoreFiles = 0 | |
149 |
|
149 | |||
150 | self.set = 0 |
|
150 | self.set = 0 | |
151 |
|
151 | |||
152 | self.path = None |
|
152 | self.path = None | |
153 |
|
153 | |||
154 | self.delay = 3 #seconds |
|
154 | self.delay = 3 #seconds | |
155 |
|
155 | |||
156 | self.nTries = 3 #quantity tries |
|
156 | self.nTries = 3 #quantity tries | |
157 |
|
157 | |||
158 | self.nFiles = 3 #number of files for searching |
|
158 | self.nFiles = 3 #number of files for searching | |
159 |
|
159 | |||
160 | self.nReadBlocks = 0 |
|
160 | self.nReadBlocks = 0 | |
161 |
|
161 | |||
162 | self.flagIsNewFile = 1 |
|
162 | self.flagIsNewFile = 1 | |
163 |
|
163 | |||
164 | self.ippSeconds = 0 |
|
164 | self.ippSeconds = 0 | |
165 |
|
165 | |||
166 | self.flagTimeBlock = 0 |
|
166 | self.flagTimeBlock = 0 | |
167 |
|
167 | |||
168 | self.flagIsNewBlock = 0 |
|
168 | self.flagIsNewBlock = 0 | |
169 |
|
169 | |||
170 | self.nTotalBlocks = 0 |
|
170 | self.nTotalBlocks = 0 | |
171 |
|
171 | |||
172 | self.blocksize = 0 |
|
172 | self.blocksize = 0 | |
173 |
|
173 | |||
174 |
|
174 | |||
175 | def createObjByDefault(self): |
|
175 | def createObjByDefault(self): | |
176 |
|
176 | |||
177 | dataObj = Spectra() |
|
177 | dataObj = Spectra() | |
178 |
|
178 | |||
179 | return dataObj |
|
179 | return dataObj | |
180 |
|
180 | |||
181 | def __hasNotDataInBuffer(self): |
|
181 | def __hasNotDataInBuffer(self): | |
182 | return 1 |
|
182 | return 1 | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | def getBlockDimension(self): |
|
185 | def getBlockDimension(self): | |
186 | """ |
|
186 | """ | |
187 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
187 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
188 |
|
188 | |||
189 | Affected: |
|
189 | Affected: | |
190 | self.nRdChannels |
|
190 | self.nRdChannels | |
191 | self.nRdPairs |
|
191 | self.nRdPairs | |
192 | self.pts2read_SelfSpectra |
|
192 | self.pts2read_SelfSpectra | |
193 | self.pts2read_CrossSpectra |
|
193 | self.pts2read_CrossSpectra | |
194 | self.pts2read_DCchannels |
|
194 | self.pts2read_DCchannels | |
195 | self.blocksize |
|
195 | self.blocksize | |
196 | self.dataOutObj.nChannels |
|
196 | self.dataOutObj.nChannels | |
197 | self.dataOutObj.nPairs |
|
197 | self.dataOutObj.nPairs | |
198 |
|
198 | |||
199 | Return: |
|
199 | Return: | |
200 | None |
|
200 | None | |
201 | """ |
|
201 | """ | |
202 | self.nRdChannels = 0 |
|
202 | self.nRdChannels = 0 | |
203 | self.nRdPairs = 0 |
|
203 | self.nRdPairs = 0 | |
204 | self.rdPairList = [] |
|
204 | self.rdPairList = [] | |
205 |
|
205 | |||
206 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
206 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
207 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
207 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
208 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
208 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
209 | else: |
|
209 | else: | |
210 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
210 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
211 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
211 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
212 |
|
212 | |||
213 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
213 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
214 |
|
214 | |||
215 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
215 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
216 | self.blocksize = self.pts2read_SelfSpectra |
|
216 | self.blocksize = self.pts2read_SelfSpectra | |
217 |
|
217 | |||
218 | if self.processingHeaderObj.flag_cspc: |
|
218 | if self.processingHeaderObj.flag_cspc: | |
219 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
219 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
220 | self.blocksize += self.pts2read_CrossSpectra |
|
220 | self.blocksize += self.pts2read_CrossSpectra | |
221 |
|
221 | |||
222 | if self.processingHeaderObj.flag_dc: |
|
222 | if self.processingHeaderObj.flag_dc: | |
223 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
223 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
224 | self.blocksize += self.pts2read_DCchannels |
|
224 | self.blocksize += self.pts2read_DCchannels | |
225 |
|
225 | |||
226 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
226 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
227 |
|
227 | |||
228 |
|
228 | |||
229 | def readBlock(self): |
|
229 | def readBlock(self): | |
230 | """ |
|
230 | """ | |
231 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
231 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
232 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
232 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
233 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
233 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
234 | es seteado a 0 |
|
234 | es seteado a 0 | |
235 |
|
235 | |||
236 | Return: None |
|
236 | Return: None | |
237 |
|
237 | |||
238 | Variables afectadas: |
|
238 | Variables afectadas: | |
239 |
|
239 | |||
240 | self.flagIsNewFile |
|
240 | self.flagIsNewFile | |
241 | self.flagIsNewBlock |
|
241 | self.flagIsNewBlock | |
242 | self.nTotalBlocks |
|
242 | self.nTotalBlocks | |
243 | self.data_spc |
|
243 | self.data_spc | |
244 | self.data_cspc |
|
244 | self.data_cspc | |
245 | self.data_dc |
|
245 | self.data_dc | |
246 |
|
246 | |||
247 | Exceptions: |
|
247 | Exceptions: | |
248 | Si un bloque leido no es un bloque valido |
|
248 | Si un bloque leido no es un bloque valido | |
249 | """ |
|
249 | """ | |
250 | blockOk_flag = False |
|
250 | blockOk_flag = False | |
251 | fpointer = self.fp.tell() |
|
251 | fpointer = self.fp.tell() | |
252 |
|
252 | |||
253 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
253 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
254 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
254 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
255 |
|
255 | |||
256 | if self.processingHeaderObj.flag_cspc: |
|
256 | if self.processingHeaderObj.flag_cspc: | |
257 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
257 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
258 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
258 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
259 |
|
259 | |||
260 | if self.processingHeaderObj.flag_dc: |
|
260 | if self.processingHeaderObj.flag_dc: | |
261 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
261 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
262 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
262 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
263 |
|
263 | |||
264 |
|
264 | |||
265 | if not(self.processingHeaderObj.shif_fft): |
|
265 | if not(self.processingHeaderObj.shif_fft): | |
266 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
266 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
267 |
|
267 | |||
268 | if self.processingHeaderObj.flag_cspc: |
|
268 | if self.processingHeaderObj.flag_cspc: | |
269 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
269 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
270 |
|
270 | |||
271 |
|
271 | |||
272 | spc = numpy.transpose( spc, (0,2,1) ) |
|
272 | spc = numpy.transpose( spc, (0,2,1) ) | |
273 | self.data_spc = spc |
|
273 | self.data_spc = spc | |
274 |
|
274 | |||
275 | if self.processingHeaderObj.flag_cspc: |
|
275 | if self.processingHeaderObj.flag_cspc: | |
276 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
276 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
277 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
277 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
278 | else: |
|
278 | else: | |
279 | self.data_cspc = None |
|
279 | self.data_cspc = None | |
280 |
|
280 | |||
281 | if self.processingHeaderObj.flag_dc: |
|
281 | if self.processingHeaderObj.flag_dc: | |
282 | self.data_dc = dc['real'] + dc['imag']*1j |
|
282 | self.data_dc = dc['real'] + dc['imag']*1j | |
283 | else: |
|
283 | else: | |
284 | self.data_dc = None |
|
284 | self.data_dc = None | |
285 |
|
285 | |||
286 | self.flagIsNewFile = 0 |
|
286 | self.flagIsNewFile = 0 | |
287 | self.flagIsNewBlock = 1 |
|
287 | self.flagIsNewBlock = 1 | |
288 |
|
288 | |||
289 | self.nTotalBlocks += 1 |
|
289 | self.nTotalBlocks += 1 | |
290 | self.nReadBlocks += 1 |
|
290 | self.nReadBlocks += 1 | |
291 |
|
291 | |||
292 | return 1 |
|
292 | return 1 | |
293 |
|
293 | |||
294 |
|
294 | |||
295 | def getData(self): |
|
295 | def getData(self): | |
296 | """ |
|
296 | """ | |
297 | Copia el buffer de lectura a la clase "Spectra", |
|
297 | Copia el buffer de lectura a la clase "Spectra", | |
298 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
298 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
299 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
299 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
300 |
|
300 | |||
301 | Return: |
|
301 | Return: | |
302 | 0 : Si no hay mas archivos disponibles |
|
302 | 0 : Si no hay mas archivos disponibles | |
303 | 1 : Si hizo una buena copia del buffer |
|
303 | 1 : Si hizo una buena copia del buffer | |
304 |
|
304 | |||
305 | Affected: |
|
305 | Affected: | |
306 | self.dataOutObj |
|
306 | self.dataOutObj | |
307 |
|
307 | |||
308 | self.flagTimeBlock |
|
308 | self.flagTimeBlock | |
309 | self.flagIsNewBlock |
|
309 | self.flagIsNewBlock | |
310 | """ |
|
310 | """ | |
311 |
|
311 | |||
312 | if self.flagNoMoreFiles: return 0 |
|
312 | if self.flagNoMoreFiles: return 0 | |
313 |
|
313 | |||
314 | self.flagTimeBlock = 0 |
|
314 | self.flagTimeBlock = 0 | |
315 | self.flagIsNewBlock = 0 |
|
315 | self.flagIsNewBlock = 0 | |
316 |
|
316 | |||
317 | if self.__hasNotDataInBuffer(): |
|
317 | if self.__hasNotDataInBuffer(): | |
318 |
|
318 | |||
319 | if not( self.readNextBlock() ): |
|
319 | if not( self.readNextBlock() ): | |
320 | return 0 |
|
320 | return 0 | |
321 |
|
321 | |||
322 | # self.updateDataHeader() |
|
322 | # self.updateDataHeader() | |
323 |
|
323 | |||
324 | if self.flagNoMoreFiles == 1: |
|
324 | if self.flagNoMoreFiles == 1: | |
325 | print 'Process finished' |
|
325 | print 'Process finished' | |
326 | return 0 |
|
326 | return 0 | |
327 |
|
327 | |||
328 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
328 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
329 |
|
329 | |||
330 | if self.data_dc == None: |
|
330 | if self.data_dc == None: | |
331 | self.dataOutObj.flagNoData = True |
|
331 | self.dataOutObj.flagNoData = True | |
332 | return 0 |
|
332 | return 0 | |
333 |
|
333 | |||
334 |
|
334 | |||
335 | self.dataOutObj.data_spc = self.data_spc |
|
335 | self.dataOutObj.data_spc = self.data_spc | |
336 |
|
336 | |||
337 | self.dataOutObj.data_cspc = self.data_cspc |
|
337 | self.dataOutObj.data_cspc = self.data_cspc | |
338 |
|
338 | |||
339 | self.dataOutObj.data_dc = self.data_dc |
|
339 | self.dataOutObj.data_dc = self.data_dc | |
340 |
|
340 | |||
341 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
341 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
342 |
|
342 | |||
343 | self.dataOutObj.flagNoData = False |
|
343 | self.dataOutObj.flagNoData = False | |
344 |
|
344 | |||
345 | self.dataOutObj.dtype = self.dtype |
|
345 | self.dataOutObj.dtype = self.dtype | |
346 |
|
346 | |||
347 | self.dataOutObj.nChannels = self.nRdChannels |
|
347 | self.dataOutObj.nChannels = self.nRdChannels | |
348 |
|
348 | |||
349 | self.dataOutObj.nPairs = self.nRdPairs |
|
349 | self.dataOutObj.nPairs = self.nRdPairs | |
350 |
|
350 | |||
351 | self.dataOutObj.pairsList = self.rdPairList |
|
351 | self.dataOutObj.pairsList = self.rdPairList | |
352 |
|
352 | |||
353 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
353 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
354 |
|
354 | |||
355 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
355 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
356 |
|
356 | |||
357 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
357 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
358 |
|
358 | |||
359 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt |
|
359 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt | |
360 |
|
360 | |||
361 |
|
361 | |||
362 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
362 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
363 |
|
363 | |||
364 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
364 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
365 |
|
365 | |||
366 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
366 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
367 |
|
367 | |||
368 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
368 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
369 |
|
369 | |||
370 |
self.dataOutObj. |
|
370 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
371 |
|
371 | |||
372 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
372 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft | |
373 |
|
373 | |||
374 | # self.profileIndex += 1 |
|
374 | # self.profileIndex += 1 | |
375 |
|
375 | |||
376 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
376 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
377 |
|
377 | |||
378 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
378 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
379 |
|
379 | |||
380 | return self.dataOutObj.data_spc |
|
380 | return self.dataOutObj.data_spc | |
381 |
|
381 | |||
382 |
|
382 | |||
383 | class SpectraWriter(JRODataWriter): |
|
383 | class SpectraWriter(JRODataWriter): | |
384 |
|
384 | |||
385 | """ |
|
385 | """ | |
386 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
386 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
387 | de los datos siempre se realiza por bloques. |
|
387 | de los datos siempre se realiza por bloques. | |
388 | """ |
|
388 | """ | |
389 |
|
389 | |||
390 | ext = ".pdata" |
|
390 | ext = ".pdata" | |
391 |
|
391 | |||
392 | optchar = "P" |
|
392 | optchar = "P" | |
393 |
|
393 | |||
394 | shape_spc_Buffer = None |
|
394 | shape_spc_Buffer = None | |
395 |
|
395 | |||
396 | shape_cspc_Buffer = None |
|
396 | shape_cspc_Buffer = None | |
397 |
|
397 | |||
398 | shape_dc_Buffer = None |
|
398 | shape_dc_Buffer = None | |
399 |
|
399 | |||
400 | data_spc = None |
|
400 | data_spc = None | |
401 |
|
401 | |||
402 | data_cspc = None |
|
402 | data_cspc = None | |
403 |
|
403 | |||
404 | data_dc = None |
|
404 | data_dc = None | |
405 |
|
405 | |||
406 | wrPairList = [] |
|
406 | wrPairList = [] | |
407 |
|
407 | |||
408 | nWrPairs = 0 |
|
408 | nWrPairs = 0 | |
409 |
|
409 | |||
410 | nWrChannels = 0 |
|
410 | nWrChannels = 0 | |
411 |
|
411 | |||
412 | # dataOutObj = None |
|
412 | # dataOutObj = None | |
413 |
|
413 | |||
414 | def __init__(self, dataOutObj=None): |
|
414 | def __init__(self, dataOutObj=None): | |
415 | """ |
|
415 | """ | |
416 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
416 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
417 |
|
417 | |||
418 | Affected: |
|
418 | Affected: | |
419 | self.dataOutObj |
|
419 | self.dataOutObj | |
420 | self.basicHeaderObj |
|
420 | self.basicHeaderObj | |
421 | self.systemHeaderObj |
|
421 | self.systemHeaderObj | |
422 | self.radarControllerHeaderObj |
|
422 | self.radarControllerHeaderObj | |
423 | self.processingHeaderObj |
|
423 | self.processingHeaderObj | |
424 |
|
424 | |||
425 | Return: None |
|
425 | Return: None | |
426 | """ |
|
426 | """ | |
427 | if dataOutObj == None: |
|
427 | if dataOutObj == None: | |
428 | dataOutObj = Spectra() |
|
428 | dataOutObj = Spectra() | |
429 |
|
429 | |||
430 | if not( isinstance(dataOutObj, Spectra) ): |
|
430 | if not( isinstance(dataOutObj, Spectra) ): | |
431 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" |
|
431 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" | |
432 |
|
432 | |||
433 | self.dataOutObj = dataOutObj |
|
433 | self.dataOutObj = dataOutObj | |
434 |
|
434 | |||
435 | self.nTotalBlocks = 0 |
|
435 | self.nTotalBlocks = 0 | |
436 |
|
436 | |||
437 | self.nWrChannels = self.dataOutObj.nChannels |
|
437 | self.nWrChannels = self.dataOutObj.nChannels | |
438 |
|
438 | |||
439 | # if len(pairList) > 0: |
|
439 | # if len(pairList) > 0: | |
440 | # self.wrPairList = pairList |
|
440 | # self.wrPairList = pairList | |
441 | # |
|
441 | # | |
442 | # self.nWrPairs = len(pairList) |
|
442 | # self.nWrPairs = len(pairList) | |
443 |
|
443 | |||
444 | self.wrPairList = self.dataOutObj.pairsList |
|
444 | self.wrPairList = self.dataOutObj.pairsList | |
445 |
|
445 | |||
446 | self.nWrPairs = self.dataOutObj.nPairs |
|
446 | self.nWrPairs = self.dataOutObj.nPairs | |
447 |
|
447 | |||
448 |
|
448 | |||
449 |
|
449 | |||
450 |
|
450 | |||
451 |
|
451 | |||
452 | # self.data_spc = None |
|
452 | # self.data_spc = None | |
453 | # self.data_cspc = None |
|
453 | # self.data_cspc = None | |
454 | # self.data_dc = None |
|
454 | # self.data_dc = None | |
455 |
|
455 | |||
456 | # self.fp = None |
|
456 | # self.fp = None | |
457 |
|
457 | |||
458 | # self.flagIsNewFile = 1 |
|
458 | # self.flagIsNewFile = 1 | |
459 | # |
|
459 | # | |
460 | # self.nTotalBlocks = 0 |
|
460 | # self.nTotalBlocks = 0 | |
461 | # |
|
461 | # | |
462 | # self.flagIsNewBlock = 0 |
|
462 | # self.flagIsNewBlock = 0 | |
463 | # |
|
463 | # | |
464 | # self.flagNoMoreFiles = 0 |
|
464 | # self.flagNoMoreFiles = 0 | |
465 | # |
|
465 | # | |
466 | # self.setFile = None |
|
466 | # self.setFile = None | |
467 | # |
|
467 | # | |
468 | # self.dtype = None |
|
468 | # self.dtype = None | |
469 | # |
|
469 | # | |
470 | # self.path = None |
|
470 | # self.path = None | |
471 | # |
|
471 | # | |
472 | # self.noMoreFiles = 0 |
|
472 | # self.noMoreFiles = 0 | |
473 | # |
|
473 | # | |
474 | # self.filename = None |
|
474 | # self.filename = None | |
475 | # |
|
475 | # | |
476 | # self.basicHeaderObj = BasicHeader() |
|
476 | # self.basicHeaderObj = BasicHeader() | |
477 | # |
|
477 | # | |
478 | # self.systemHeaderObj = SystemHeader() |
|
478 | # self.systemHeaderObj = SystemHeader() | |
479 | # |
|
479 | # | |
480 | # self.radarControllerHeaderObj = RadarControllerHeader() |
|
480 | # self.radarControllerHeaderObj = RadarControllerHeader() | |
481 | # |
|
481 | # | |
482 | # self.processingHeaderObj = ProcessingHeader() |
|
482 | # self.processingHeaderObj = ProcessingHeader() | |
483 |
|
483 | |||
484 |
|
484 | |||
485 | def hasAllDataInBuffer(self): |
|
485 | def hasAllDataInBuffer(self): | |
486 | return 1 |
|
486 | return 1 | |
487 |
|
487 | |||
488 |
|
488 | |||
489 | def setBlockDimension(self): |
|
489 | def setBlockDimension(self): | |
490 | """ |
|
490 | """ | |
491 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
491 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
492 |
|
492 | |||
493 | Affected: |
|
493 | Affected: | |
494 | self.shape_spc_Buffer |
|
494 | self.shape_spc_Buffer | |
495 | self.shape_cspc_Buffer |
|
495 | self.shape_cspc_Buffer | |
496 | self.shape_dc_Buffer |
|
496 | self.shape_dc_Buffer | |
497 |
|
497 | |||
498 | Return: None |
|
498 | Return: None | |
499 | """ |
|
499 | """ | |
500 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, |
|
500 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, | |
501 | self.processingHeaderObj.nHeights, |
|
501 | self.processingHeaderObj.nHeights, | |
502 | self.processingHeaderObj.profilesPerBlock) |
|
502 | self.processingHeaderObj.profilesPerBlock) | |
503 |
|
503 | |||
504 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, |
|
504 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, | |
505 | self.processingHeaderObj.nHeights, |
|
505 | self.processingHeaderObj.nHeights, | |
506 | self.processingHeaderObj.profilesPerBlock) |
|
506 | self.processingHeaderObj.profilesPerBlock) | |
507 |
|
507 | |||
508 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, |
|
508 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, | |
509 | self.processingHeaderObj.nHeights) |
|
509 | self.processingHeaderObj.nHeights) | |
510 |
|
510 | |||
511 |
|
511 | |||
512 | def writeBlock(self): |
|
512 | def writeBlock(self): | |
513 | """ |
|
513 | """ | |
514 | Escribe el buffer en el file designado |
|
514 | Escribe el buffer en el file designado | |
515 |
|
515 | |||
516 | Affected: |
|
516 | Affected: | |
517 | self.data_spc |
|
517 | self.data_spc | |
518 | self.data_cspc |
|
518 | self.data_cspc | |
519 | self.data_dc |
|
519 | self.data_dc | |
520 | self.flagIsNewFile |
|
520 | self.flagIsNewFile | |
521 | self.flagIsNewBlock |
|
521 | self.flagIsNewBlock | |
522 | self.nTotalBlocks |
|
522 | self.nTotalBlocks | |
523 | self.nWriteBlocks |
|
523 | self.nWriteBlocks | |
524 |
|
524 | |||
525 | Return: None |
|
525 | Return: None | |
526 | """ |
|
526 | """ | |
527 |
|
527 | |||
528 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
528 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
529 | if not( self.processingHeaderObj.shif_fft ): |
|
529 | if not( self.processingHeaderObj.shif_fft ): | |
530 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
530 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
531 | data = spc.reshape((-1)) |
|
531 | data = spc.reshape((-1)) | |
532 | data.tofile(self.fp) |
|
532 | data.tofile(self.fp) | |
533 |
|
533 | |||
534 | if self.data_cspc != None: |
|
534 | if self.data_cspc != None: | |
535 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
535 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
536 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
536 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
537 | if not( self.processingHeaderObj.shif_fft ): |
|
537 | if not( self.processingHeaderObj.shif_fft ): | |
538 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
538 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
539 | data['real'] = cspc.real |
|
539 | data['real'] = cspc.real | |
540 | data['imag'] = cspc.imag |
|
540 | data['imag'] = cspc.imag | |
541 | data = data.reshape((-1)) |
|
541 | data = data.reshape((-1)) | |
542 | data.tofile(self.fp) |
|
542 | data.tofile(self.fp) | |
543 |
|
543 | |||
544 | if self.data_dc != None: |
|
544 | if self.data_dc != None: | |
545 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
545 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
546 | dc = self.data_dc |
|
546 | dc = self.data_dc | |
547 | data['real'] = dc.real |
|
547 | data['real'] = dc.real | |
548 | data['imag'] = dc.imag |
|
548 | data['imag'] = dc.imag | |
549 | data = data.reshape((-1)) |
|
549 | data = data.reshape((-1)) | |
550 | data.tofile(self.fp) |
|
550 | data.tofile(self.fp) | |
551 |
|
551 | |||
552 | self.data_spc.fill(0) |
|
552 | self.data_spc.fill(0) | |
553 | self.data_dc.fill(0) |
|
553 | self.data_dc.fill(0) | |
554 | if self.data_cspc != None: |
|
554 | if self.data_cspc != None: | |
555 | self.data_cspc.fill(0) |
|
555 | self.data_cspc.fill(0) | |
556 |
|
556 | |||
557 | self.flagIsNewFile = 0 |
|
557 | self.flagIsNewFile = 0 | |
558 | self.flagIsNewBlock = 1 |
|
558 | self.flagIsNewBlock = 1 | |
559 | self.nTotalBlocks += 1 |
|
559 | self.nTotalBlocks += 1 | |
560 | self.nWriteBlocks += 1 |
|
560 | self.nWriteBlocks += 1 | |
561 | self.blockIndex += 1 |
|
561 | self.blockIndex += 1 | |
562 |
|
562 | |||
563 |
|
563 | |||
564 | def putData(self): |
|
564 | def putData(self): | |
565 | """ |
|
565 | """ | |
566 | Setea un bloque de datos y luego los escribe en un file |
|
566 | Setea un bloque de datos y luego los escribe en un file | |
567 |
|
567 | |||
568 | Affected: |
|
568 | Affected: | |
569 | self.data_spc |
|
569 | self.data_spc | |
570 | self.data_cspc |
|
570 | self.data_cspc | |
571 | self.data_dc |
|
571 | self.data_dc | |
572 |
|
572 | |||
573 | Return: |
|
573 | Return: | |
574 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
574 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
575 | 1 : Si se escribio la data de un bloque en un file |
|
575 | 1 : Si se escribio la data de un bloque en un file | |
576 | """ |
|
576 | """ | |
577 | self.flagIsNewBlock = 0 |
|
577 | self.flagIsNewBlock = 0 | |
578 |
|
578 | |||
579 | if self.dataOutObj.flagNoData: |
|
579 | if self.dataOutObj.flagNoData: | |
580 | return 0 |
|
580 | return 0 | |
581 |
|
581 | |||
582 | if self.dataOutObj.flagTimeBlock: |
|
582 | if self.dataOutObj.flagTimeBlock: | |
583 | self.data_spc.fill(0) |
|
583 | self.data_spc.fill(0) | |
584 | self.data_cspc.fill(0) |
|
584 | self.data_cspc.fill(0) | |
585 | self.data_dc.fill(0) |
|
585 | self.data_dc.fill(0) | |
586 | self.setNextFile() |
|
586 | self.setNextFile() | |
587 |
|
587 | |||
588 | if self.flagIsNewFile == 0: |
|
588 | if self.flagIsNewFile == 0: | |
589 | self.getBasicHeader() |
|
589 | self.getBasicHeader() | |
590 |
|
590 | |||
591 | self.data_spc = self.dataOutObj.data_spc |
|
591 | self.data_spc = self.dataOutObj.data_spc | |
592 | self.data_cspc = self.dataOutObj.data_cspc |
|
592 | self.data_cspc = self.dataOutObj.data_cspc | |
593 | self.data_dc = self.dataOutObj.data_dc |
|
593 | self.data_dc = self.dataOutObj.data_dc | |
594 |
|
594 | |||
595 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
595 | # #self.processingHeaderObj.dataBlocksPerFile) | |
596 | if self.hasAllDataInBuffer(): |
|
596 | if self.hasAllDataInBuffer(): | |
597 | # self.getDataHeader() |
|
597 | # self.getDataHeader() | |
598 | self.writeNextBlock() |
|
598 | self.writeNextBlock() | |
599 |
|
599 | |||
600 | if self.flagNoMoreFiles: |
|
600 | if self.flagNoMoreFiles: | |
601 | #print 'Process finished' |
|
601 | #print 'Process finished' | |
602 | return 0 |
|
602 | return 0 | |
603 |
|
603 | |||
604 | return 1 |
|
604 | return 1 | |
605 |
|
605 | |||
606 |
|
606 | |||
607 | def __getProcessFlags(self): |
|
607 | def __getProcessFlags(self): | |
608 |
|
608 | |||
609 | processFlags = 0 |
|
609 | processFlags = 0 | |
610 |
|
610 | |||
611 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
611 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
612 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
612 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
613 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
613 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
614 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
614 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
615 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
615 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
616 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
616 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
617 |
|
617 | |||
618 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
618 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
619 |
|
619 | |||
620 |
|
620 | |||
621 |
|
621 | |||
622 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
622 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
623 | PROCFLAG.DATATYPE_SHORT, |
|
623 | PROCFLAG.DATATYPE_SHORT, | |
624 | PROCFLAG.DATATYPE_LONG, |
|
624 | PROCFLAG.DATATYPE_LONG, | |
625 | PROCFLAG.DATATYPE_INT64, |
|
625 | PROCFLAG.DATATYPE_INT64, | |
626 | PROCFLAG.DATATYPE_FLOAT, |
|
626 | PROCFLAG.DATATYPE_FLOAT, | |
627 | PROCFLAG.DATATYPE_DOUBLE] |
|
627 | PROCFLAG.DATATYPE_DOUBLE] | |
628 |
|
628 | |||
629 |
|
629 | |||
630 | for index in range(len(dtypeList)): |
|
630 | for index in range(len(dtypeList)): | |
631 | if self.dataOutObj.dtype == dtypeList[index]: |
|
631 | if self.dataOutObj.dtype == dtypeList[index]: | |
632 | dtypeValue = datatypeValueList[index] |
|
632 | dtypeValue = datatypeValueList[index] | |
633 | break |
|
633 | break | |
634 |
|
634 | |||
635 | processFlags += dtypeValue |
|
635 | processFlags += dtypeValue | |
636 |
|
636 | |||
637 | if self.dataOutObj.flagDecodeData: |
|
637 | if self.dataOutObj.flagDecodeData: | |
638 | processFlags += PROCFLAG.DECODE_DATA |
|
638 | processFlags += PROCFLAG.DECODE_DATA | |
639 |
|
639 | |||
640 | if self.dataOutObj.flagDeflipData: |
|
640 | if self.dataOutObj.flagDeflipData: | |
641 | processFlags += PROCFLAG.DEFLIP_DATA |
|
641 | processFlags += PROCFLAG.DEFLIP_DATA | |
642 |
|
642 | |||
643 | if self.dataOutObj.code != None: |
|
643 | if self.dataOutObj.code != None: | |
644 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
644 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
645 |
|
645 | |||
646 | if self.dataOutObj.nIncohInt > 1: |
|
646 | if self.dataOutObj.nIncohInt > 1: | |
647 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
647 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
648 |
|
648 | |||
649 | if self.dataOutObj.data_dc != None: |
|
649 | if self.dataOutObj.data_dc != None: | |
650 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
650 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
651 |
|
651 | |||
652 | return processFlags |
|
652 | return processFlags | |
653 |
|
653 | |||
654 |
|
654 | |||
655 | def __getBlockSize(self): |
|
655 | def __getBlockSize(self): | |
656 | ''' |
|
656 | ''' | |
657 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
657 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
658 | ''' |
|
658 | ''' | |
659 |
|
659 | |||
660 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
660 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
661 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
661 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
662 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
662 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
663 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
663 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
664 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
664 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
665 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
665 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
666 |
|
666 | |||
667 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
667 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
668 | datatypeValueList = [1,2,4,8,4,8] |
|
668 | datatypeValueList = [1,2,4,8,4,8] | |
669 | for index in range(len(dtypeList)): |
|
669 | for index in range(len(dtypeList)): | |
670 | if self.dataOutObj.dtype == dtypeList[index]: |
|
670 | if self.dataOutObj.dtype == dtypeList[index]: | |
671 | datatypeValue = datatypeValueList[index] |
|
671 | datatypeValue = datatypeValueList[index] | |
672 | break |
|
672 | break | |
673 |
|
673 | |||
674 |
|
674 | |||
675 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints |
|
675 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints | |
676 |
|
676 | |||
677 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) |
|
677 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) | |
678 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
678 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
679 |
|
679 | |||
680 | if self.dataOutObj.data_cspc != None: |
|
680 | if self.dataOutObj.data_cspc != None: | |
681 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) |
|
681 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) | |
682 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
682 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
683 |
|
683 | |||
684 | if self.dataOutObj.data_dc != None: |
|
684 | if self.dataOutObj.data_dc != None: | |
685 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) |
|
685 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) | |
686 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
686 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
687 |
|
687 | |||
688 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
688 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
689 |
|
689 | |||
690 | return blocksize |
|
690 | return blocksize | |
691 |
|
691 | |||
692 |
|
692 | |||
693 | def getBasicHeader(self): |
|
693 | def getBasicHeader(self): | |
694 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
694 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
695 | self.basicHeaderObj.version = self.versionFile |
|
695 | self.basicHeaderObj.version = self.versionFile | |
696 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
696 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
697 |
|
697 | |||
698 |
utc = numpy.floor(self.dataOutObj. |
|
698 | utc = numpy.floor(self.dataOutObj.utctime) | |
699 |
milisecond = (self.dataOutObj. |
|
699 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 | |
700 |
|
700 | |||
701 | self.basicHeaderObj.utc = utc |
|
701 | self.basicHeaderObj.utc = utc | |
702 | self.basicHeaderObj.miliSecond = milisecond |
|
702 | self.basicHeaderObj.miliSecond = milisecond | |
703 | self.basicHeaderObj.timeZone = 0 |
|
703 | self.basicHeaderObj.timeZone = 0 | |
704 | self.basicHeaderObj.dstFlag = 0 |
|
704 | self.basicHeaderObj.dstFlag = 0 | |
705 | self.basicHeaderObj.errorCount = 0 |
|
705 | self.basicHeaderObj.errorCount = 0 | |
706 |
|
706 | |||
707 | def getDataHeader(self): |
|
707 | def getDataHeader(self): | |
708 |
|
708 | |||
709 | """ |
|
709 | """ | |
710 | Obtiene una copia del First Header |
|
710 | Obtiene una copia del First Header | |
711 |
|
711 | |||
712 | Affected: |
|
712 | Affected: | |
713 | self.systemHeaderObj |
|
713 | self.systemHeaderObj | |
714 | self.radarControllerHeaderObj |
|
714 | self.radarControllerHeaderObj | |
715 | self.dtype |
|
715 | self.dtype | |
716 |
|
716 | |||
717 | Return: |
|
717 | Return: | |
718 | None |
|
718 | None | |
719 | """ |
|
719 | """ | |
720 |
|
720 | |||
721 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
721 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
722 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
722 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
723 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
723 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
724 |
|
724 | |||
725 | self.getBasicHeader() |
|
725 | self.getBasicHeader() | |
726 |
|
726 | |||
727 | processingHeaderSize = 40 # bytes |
|
727 | processingHeaderSize = 40 # bytes | |
728 | self.processingHeaderObj.dtype = 0 # Voltage |
|
728 | self.processingHeaderObj.dtype = 0 # Voltage | |
729 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
729 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
730 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints |
|
730 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints | |
731 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
731 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
732 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
732 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
733 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
733 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
734 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra |
|
734 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra | |
735 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt |
|
735 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt | |
736 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels |
|
736 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels | |
737 |
|
737 | |||
738 | if self.processingHeaderObj.totalSpectra > 0: |
|
738 | if self.processingHeaderObj.totalSpectra > 0: | |
739 | channelList = [] |
|
739 | channelList = [] | |
740 | for channel in range(self.dataOutObj.nChannels): |
|
740 | for channel in range(self.dataOutObj.nChannels): | |
741 | channelList.append(channel) |
|
741 | channelList.append(channel) | |
742 | channelList.append(channel) |
|
742 | channelList.append(channel) | |
743 |
|
743 | |||
744 | pairsList = [] |
|
744 | pairsList = [] | |
745 | for pair in self.dataOutObj.pairsList: |
|
745 | for pair in self.dataOutObj.pairsList: | |
746 | pairsList.append(pair[0]) |
|
746 | pairsList.append(pair[0]) | |
747 | pairsList.append(pair[1]) |
|
747 | pairsList.append(pair[1]) | |
748 | spectraComb = channelList + pairsList |
|
748 | spectraComb = channelList + pairsList | |
749 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
749 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
750 | self.processingHeaderObj.spectraComb = spectraComb |
|
750 | self.processingHeaderObj.spectraComb = spectraComb | |
751 | sizeOfSpcComb = len(spectraComb) |
|
751 | sizeOfSpcComb = len(spectraComb) | |
752 | processingHeaderSize += sizeOfSpcComb |
|
752 | processingHeaderSize += sizeOfSpcComb | |
753 |
|
753 | |||
754 | if self.dataOutObj.code != None: |
|
754 | if self.dataOutObj.code != None: | |
755 | self.processingHeaderObj.code = self.dataOutObj.code |
|
755 | self.processingHeaderObj.code = self.dataOutObj.code | |
756 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
756 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
757 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
757 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
758 | nCodeSize = 4 # bytes |
|
758 | nCodeSize = 4 # bytes | |
759 | nBaudSize = 4 # bytes |
|
759 | nBaudSize = 4 # bytes | |
760 | codeSize = 4 # bytes |
|
760 | codeSize = 4 # bytes | |
761 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
761 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
762 | processingHeaderSize += sizeOfCode |
|
762 | processingHeaderSize += sizeOfCode | |
763 |
|
763 | |||
764 | if self.processingHeaderObj.nWindows != 0: |
|
764 | if self.processingHeaderObj.nWindows != 0: | |
765 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
765 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
766 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
766 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
767 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
767 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
768 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
768 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
769 | sizeOfFirstHeight = 4 |
|
769 | sizeOfFirstHeight = 4 | |
770 | sizeOfdeltaHeight = 4 |
|
770 | sizeOfdeltaHeight = 4 | |
771 | sizeOfnHeights = 4 |
|
771 | sizeOfnHeights = 4 | |
772 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
772 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
773 | processingHeaderSize += sizeOfWindows |
|
773 | processingHeaderSize += sizeOfWindows | |
774 |
|
774 | |||
775 | self.processingHeaderObj.size = processingHeaderSize |
|
775 | self.processingHeaderObj.size = processingHeaderSize | |
776 |
|
776 | |||
777 | No newline at end of file |
|
777 |
@@ -1,584 +1,584 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import glob |
|
9 | import glob | |
10 | import fnmatch |
|
10 | import fnmatch | |
11 | import time, datetime |
|
11 | import time, datetime | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from JROHeaderIO import * |
|
16 | from JROHeaderIO import * | |
17 | from JRODataIO import JRODataReader |
|
17 | from JRODataIO import JRODataReader | |
18 | from JRODataIO import JRODataWriter |
|
18 | from JRODataIO import JRODataWriter | |
19 |
|
19 | |||
20 | from Data.JROData import Voltage |
|
20 | from Data.JROData import Voltage | |
21 |
|
21 | |||
22 | class VoltageReader(JRODataReader): |
|
22 | class VoltageReader(JRODataReader): | |
23 | """ |
|
23 | """ | |
24 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
24 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
26 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
26 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
27 |
|
27 | |||
28 | perfiles * alturas * canales |
|
28 | perfiles * alturas * canales | |
29 |
|
29 | |||
30 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
30 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
31 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
31 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
32 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
32 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
33 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
33 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
34 |
|
34 | |||
35 | Example: |
|
35 | Example: | |
36 |
|
36 | |||
37 | dpath = "/home/myuser/data" |
|
37 | dpath = "/home/myuser/data" | |
38 |
|
38 | |||
39 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
39 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
40 |
|
40 | |||
41 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
41 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
42 |
|
42 | |||
43 | readerObj = VoltageReader() |
|
43 | readerObj = VoltageReader() | |
44 |
|
44 | |||
45 | readerObj.setup(dpath, startTime, endTime) |
|
45 | readerObj.setup(dpath, startTime, endTime) | |
46 |
|
46 | |||
47 | while(True): |
|
47 | while(True): | |
48 |
|
48 | |||
49 | #to get one profile |
|
49 | #to get one profile | |
50 | profile = readerObj.getData() |
|
50 | profile = readerObj.getData() | |
51 |
|
51 | |||
52 | #print the profile |
|
52 | #print the profile | |
53 | print profile |
|
53 | print profile | |
54 |
|
54 | |||
55 | #If you want to see all datablock |
|
55 | #If you want to see all datablock | |
56 | print readerObj.datablock |
|
56 | print readerObj.datablock | |
57 |
|
57 | |||
58 | if readerObj.flagNoMoreFiles: |
|
58 | if readerObj.flagNoMoreFiles: | |
59 | break |
|
59 | break | |
60 |
|
60 | |||
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | ext = ".r" |
|
63 | ext = ".r" | |
64 |
|
64 | |||
65 | optchar = "D" |
|
65 | optchar = "D" | |
66 | dataOutObj = None |
|
66 | dataOutObj = None | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | def __init__(self, dataOutObj=None): |
|
69 | def __init__(self, dataOutObj=None): | |
70 | """ |
|
70 | """ | |
71 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
71 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
72 |
|
72 | |||
73 | Input: |
|
73 | Input: | |
74 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
74 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para | |
75 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
75 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
76 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
76 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
77 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
77 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
78 | bloque de datos. |
|
78 | bloque de datos. | |
79 | Si este parametro no es pasado se creara uno internamente. |
|
79 | Si este parametro no es pasado se creara uno internamente. | |
80 |
|
80 | |||
81 | Variables afectadas: |
|
81 | Variables afectadas: | |
82 | self.dataOutObj |
|
82 | self.dataOutObj | |
83 |
|
83 | |||
84 | Return: |
|
84 | Return: | |
85 | None |
|
85 | None | |
86 | """ |
|
86 | """ | |
87 |
|
87 | |||
88 | self.datablock = None |
|
88 | self.datablock = None | |
89 |
|
89 | |||
90 | self.utc = 0 |
|
90 | self.utc = 0 | |
91 |
|
91 | |||
92 | self.ext = ".r" |
|
92 | self.ext = ".r" | |
93 |
|
93 | |||
94 | self.optchar = "D" |
|
94 | self.optchar = "D" | |
95 |
|
95 | |||
96 | self.basicHeaderObj = BasicHeader() |
|
96 | self.basicHeaderObj = BasicHeader() | |
97 |
|
97 | |||
98 | self.systemHeaderObj = SystemHeader() |
|
98 | self.systemHeaderObj = SystemHeader() | |
99 |
|
99 | |||
100 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
100 | self.radarControllerHeaderObj = RadarControllerHeader() | |
101 |
|
101 | |||
102 | self.processingHeaderObj = ProcessingHeader() |
|
102 | self.processingHeaderObj = ProcessingHeader() | |
103 |
|
103 | |||
104 | self.online = 0 |
|
104 | self.online = 0 | |
105 |
|
105 | |||
106 | self.fp = None |
|
106 | self.fp = None | |
107 |
|
107 | |||
108 | self.idFile = None |
|
108 | self.idFile = None | |
109 |
|
109 | |||
110 | self.dtype = None |
|
110 | self.dtype = None | |
111 |
|
111 | |||
112 | self.fileSizeByHeader = None |
|
112 | self.fileSizeByHeader = None | |
113 |
|
113 | |||
114 | self.filenameList = [] |
|
114 | self.filenameList = [] | |
115 |
|
115 | |||
116 | self.filename = None |
|
116 | self.filename = None | |
117 |
|
117 | |||
118 | self.fileSize = None |
|
118 | self.fileSize = None | |
119 |
|
119 | |||
120 | self.firstHeaderSize = 0 |
|
120 | self.firstHeaderSize = 0 | |
121 |
|
121 | |||
122 | self.basicHeaderSize = 24 |
|
122 | self.basicHeaderSize = 24 | |
123 |
|
123 | |||
124 | self.pathList = [] |
|
124 | self.pathList = [] | |
125 |
|
125 | |||
126 | self.filenameList = [] |
|
126 | self.filenameList = [] | |
127 |
|
127 | |||
128 | self.lastUTTime = 0 |
|
128 | self.lastUTTime = 0 | |
129 |
|
129 | |||
130 | self.maxTimeStep = 30 |
|
130 | self.maxTimeStep = 30 | |
131 |
|
131 | |||
132 | self.flagNoMoreFiles = 0 |
|
132 | self.flagNoMoreFiles = 0 | |
133 |
|
133 | |||
134 | self.set = 0 |
|
134 | self.set = 0 | |
135 |
|
135 | |||
136 | self.path = None |
|
136 | self.path = None | |
137 |
|
137 | |||
138 | self.profileIndex = 9999 |
|
138 | self.profileIndex = 9999 | |
139 |
|
139 | |||
140 | self.delay = 3 #seconds |
|
140 | self.delay = 3 #seconds | |
141 |
|
141 | |||
142 | self.nTries = 3 #quantity tries |
|
142 | self.nTries = 3 #quantity tries | |
143 |
|
143 | |||
144 | self.nFiles = 3 #number of files for searching |
|
144 | self.nFiles = 3 #number of files for searching | |
145 |
|
145 | |||
146 | self.nReadBlocks = 0 |
|
146 | self.nReadBlocks = 0 | |
147 |
|
147 | |||
148 | self.flagIsNewFile = 1 |
|
148 | self.flagIsNewFile = 1 | |
149 |
|
149 | |||
150 | self.ippSeconds = 0 |
|
150 | self.ippSeconds = 0 | |
151 |
|
151 | |||
152 | self.flagTimeBlock = 0 |
|
152 | self.flagTimeBlock = 0 | |
153 |
|
153 | |||
154 | self.flagIsNewBlock = 0 |
|
154 | self.flagIsNewBlock = 0 | |
155 |
|
155 | |||
156 | self.nTotalBlocks = 0 |
|
156 | self.nTotalBlocks = 0 | |
157 |
|
157 | |||
158 | self.blocksize = 0 |
|
158 | self.blocksize = 0 | |
159 |
|
159 | |||
160 | def createObjByDefault(self): |
|
160 | def createObjByDefault(self): | |
161 |
|
161 | |||
162 | dataObj = Voltage() |
|
162 | dataObj = Voltage() | |
163 |
|
163 | |||
164 | return dataObj |
|
164 | return dataObj | |
165 |
|
165 | |||
166 | def __hasNotDataInBuffer(self): |
|
166 | def __hasNotDataInBuffer(self): | |
167 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
167 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
168 | return 1 |
|
168 | return 1 | |
169 | return 0 |
|
169 | return 0 | |
170 |
|
170 | |||
171 |
|
171 | |||
172 | def getBlockDimension(self): |
|
172 | def getBlockDimension(self): | |
173 | """ |
|
173 | """ | |
174 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
174 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
175 |
|
175 | |||
176 | Affected: |
|
176 | Affected: | |
177 | self.blocksize |
|
177 | self.blocksize | |
178 |
|
178 | |||
179 | Return: |
|
179 | Return: | |
180 | None |
|
180 | None | |
181 | """ |
|
181 | """ | |
182 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
182 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
183 | self.blocksize = pts2read |
|
183 | self.blocksize = pts2read | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | def readBlock(self): |
|
186 | def readBlock(self): | |
187 | """ |
|
187 | """ | |
188 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
188 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
189 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
189 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
190 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
190 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
191 | es seteado a 0 |
|
191 | es seteado a 0 | |
192 |
|
192 | |||
193 | Inputs: |
|
193 | Inputs: | |
194 | None |
|
194 | None | |
195 |
|
195 | |||
196 | Return: |
|
196 | Return: | |
197 | None |
|
197 | None | |
198 |
|
198 | |||
199 | Affected: |
|
199 | Affected: | |
200 | self.profileIndex |
|
200 | self.profileIndex | |
201 | self.datablock |
|
201 | self.datablock | |
202 | self.flagIsNewFile |
|
202 | self.flagIsNewFile | |
203 | self.flagIsNewBlock |
|
203 | self.flagIsNewBlock | |
204 | self.nTotalBlocks |
|
204 | self.nTotalBlocks | |
205 |
|
205 | |||
206 | Exceptions: |
|
206 | Exceptions: | |
207 | Si un bloque leido no es un bloque valido |
|
207 | Si un bloque leido no es un bloque valido | |
208 | """ |
|
208 | """ | |
209 |
|
209 | |||
210 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
210 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
211 |
|
211 | |||
212 | try: |
|
212 | try: | |
213 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
213 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
214 | except: |
|
214 | except: | |
215 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
215 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
216 | return 0 |
|
216 | return 0 | |
217 |
|
217 | |||
218 | junk = numpy.transpose(junk, (2,0,1)) |
|
218 | junk = numpy.transpose(junk, (2,0,1)) | |
219 | self.datablock = junk['real'] + junk['imag']*1j |
|
219 | self.datablock = junk['real'] + junk['imag']*1j | |
220 |
|
220 | |||
221 | self.profileIndex = 0 |
|
221 | self.profileIndex = 0 | |
222 |
|
222 | |||
223 | self.flagIsNewFile = 0 |
|
223 | self.flagIsNewFile = 0 | |
224 | self.flagIsNewBlock = 1 |
|
224 | self.flagIsNewBlock = 1 | |
225 |
|
225 | |||
226 | self.nTotalBlocks += 1 |
|
226 | self.nTotalBlocks += 1 | |
227 | self.nReadBlocks += 1 |
|
227 | self.nReadBlocks += 1 | |
228 |
|
228 | |||
229 | return 1 |
|
229 | return 1 | |
230 |
|
230 | |||
231 |
|
231 | |||
232 | def getData(self): |
|
232 | def getData(self): | |
233 | """ |
|
233 | """ | |
234 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
234 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
235 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
235 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
236 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
236 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
237 |
|
237 | |||
238 | Ademas incrementa el contador del buffer en 1. |
|
238 | Ademas incrementa el contador del buffer en 1. | |
239 |
|
239 | |||
240 | Return: |
|
240 | Return: | |
241 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
241 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
242 | buffer. Si no hay mas archivos a leer retorna None. |
|
242 | buffer. Si no hay mas archivos a leer retorna None. | |
243 |
|
243 | |||
244 | Variables afectadas: |
|
244 | Variables afectadas: | |
245 | self.dataOutObj |
|
245 | self.dataOutObj | |
246 | self.profileIndex |
|
246 | self.profileIndex | |
247 |
|
247 | |||
248 | Affected: |
|
248 | Affected: | |
249 | self.dataOutObj |
|
249 | self.dataOutObj | |
250 | self.profileIndex |
|
250 | self.profileIndex | |
251 | self.flagTimeBlock |
|
251 | self.flagTimeBlock | |
252 | self.flagIsNewBlock |
|
252 | self.flagIsNewBlock | |
253 | """ |
|
253 | """ | |
254 | if self.flagNoMoreFiles: return 0 |
|
254 | if self.flagNoMoreFiles: return 0 | |
255 |
|
255 | |||
256 | self.flagTimeBlock = 0 |
|
256 | self.flagTimeBlock = 0 | |
257 | self.flagIsNewBlock = 0 |
|
257 | self.flagIsNewBlock = 0 | |
258 |
|
258 | |||
259 | if self.__hasNotDataInBuffer(): |
|
259 | if self.__hasNotDataInBuffer(): | |
260 |
|
260 | |||
261 | if not( self.readNextBlock() ): |
|
261 | if not( self.readNextBlock() ): | |
262 | return 0 |
|
262 | return 0 | |
263 |
|
263 | |||
264 | # self.updateDataHeader() |
|
264 | # self.updateDataHeader() | |
265 |
|
265 | |||
266 | if self.flagNoMoreFiles == 1: |
|
266 | if self.flagNoMoreFiles == 1: | |
267 | print 'Process finished' |
|
267 | print 'Process finished' | |
268 | return 0 |
|
268 | return 0 | |
269 |
|
269 | |||
270 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
270 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
271 |
|
271 | |||
272 | if self.datablock == None: |
|
272 | if self.datablock == None: | |
273 | self.dataOutObj.flagNoData = True |
|
273 | self.dataOutObj.flagNoData = True | |
274 | return 0 |
|
274 | return 0 | |
275 |
|
275 | |||
276 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] |
|
276 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] | |
277 |
|
277 | |||
278 | self.dataOutObj.dtype = self.dtype |
|
278 | self.dataOutObj.dtype = self.dtype | |
279 |
|
279 | |||
280 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels |
|
280 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels | |
281 |
|
281 | |||
282 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
282 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
283 |
|
283 | |||
284 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
284 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
285 |
|
285 | |||
286 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
286 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
287 |
|
287 | |||
288 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
288 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
289 |
|
289 | |||
290 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
290 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
291 |
|
291 | |||
292 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
292 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
293 |
|
293 | |||
294 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
294 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
295 |
|
295 | |||
296 |
self.dataOutObj. |
|
296 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
297 |
|
297 | |||
298 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt |
|
298 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt | |
299 |
|
299 | |||
300 | self.dataOutObj.flagShiftFFT = False |
|
300 | self.dataOutObj.flagShiftFFT = False | |
301 |
|
301 | |||
302 | if self.processingHeaderObj.code != None: |
|
302 | if self.processingHeaderObj.code != None: | |
303 | self.dataOutObj.nCode = self.processingHeaderObj.nCode |
|
303 | self.dataOutObj.nCode = self.processingHeaderObj.nCode | |
304 |
|
304 | |||
305 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud |
|
305 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud | |
306 |
|
306 | |||
307 | self.dataOutObj.code = self.processingHeaderObj.code |
|
307 | self.dataOutObj.code = self.processingHeaderObj.code | |
308 |
|
308 | |||
309 | self.profileIndex += 1 |
|
309 | self.profileIndex += 1 | |
310 |
|
310 | |||
311 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
311 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
312 |
|
312 | |||
313 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
313 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
314 |
|
314 | |||
315 | self.dataOutObj.flagNoData = False |
|
315 | self.dataOutObj.flagNoData = False | |
316 |
|
316 | |||
317 | return self.dataOutObj.data |
|
317 | return self.dataOutObj.data | |
318 |
|
318 | |||
319 |
|
319 | |||
320 | class VoltageWriter(JRODataWriter): |
|
320 | class VoltageWriter(JRODataWriter): | |
321 | """ |
|
321 | """ | |
322 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
322 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
323 | de los datos siempre se realiza por bloques. |
|
323 | de los datos siempre se realiza por bloques. | |
324 | """ |
|
324 | """ | |
325 |
|
325 | |||
326 | ext = ".r" |
|
326 | ext = ".r" | |
327 |
|
327 | |||
328 | optchar = "D" |
|
328 | optchar = "D" | |
329 |
|
329 | |||
330 | shapeBuffer = None |
|
330 | shapeBuffer = None | |
331 |
|
331 | |||
332 |
|
332 | |||
333 | def __init__(self, dataOutObj=None): |
|
333 | def __init__(self, dataOutObj=None): | |
334 | """ |
|
334 | """ | |
335 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
335 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
336 |
|
336 | |||
337 | Affected: |
|
337 | Affected: | |
338 | self.dataOutObj |
|
338 | self.dataOutObj | |
339 |
|
339 | |||
340 | Return: None |
|
340 | Return: None | |
341 | """ |
|
341 | """ | |
342 | if dataOutObj == None: |
|
342 | if dataOutObj == None: | |
343 | dataOutObj = Voltage() |
|
343 | dataOutObj = Voltage() | |
344 |
|
344 | |||
345 | if not( isinstance(dataOutObj, Voltage) ): |
|
345 | if not( isinstance(dataOutObj, Voltage) ): | |
346 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" |
|
346 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" | |
347 |
|
347 | |||
348 | self.dataOutObj = dataOutObj |
|
348 | self.dataOutObj = dataOutObj | |
349 |
|
349 | |||
350 | self.nTotalBlocks = 0 |
|
350 | self.nTotalBlocks = 0 | |
351 |
|
351 | |||
352 | self.profileIndex = 0 |
|
352 | self.profileIndex = 0 | |
353 |
|
353 | |||
354 | def hasAllDataInBuffer(self): |
|
354 | def hasAllDataInBuffer(self): | |
355 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
355 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
356 | return 1 |
|
356 | return 1 | |
357 | return 0 |
|
357 | return 0 | |
358 |
|
358 | |||
359 |
|
359 | |||
360 | def setBlockDimension(self): |
|
360 | def setBlockDimension(self): | |
361 | """ |
|
361 | """ | |
362 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
362 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
363 |
|
363 | |||
364 | Affected: |
|
364 | Affected: | |
365 | self.shape_spc_Buffer |
|
365 | self.shape_spc_Buffer | |
366 | self.shape_cspc_Buffer |
|
366 | self.shape_cspc_Buffer | |
367 | self.shape_dc_Buffer |
|
367 | self.shape_dc_Buffer | |
368 |
|
368 | |||
369 | Return: None |
|
369 | Return: None | |
370 | """ |
|
370 | """ | |
371 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
371 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
372 | self.processingHeaderObj.nHeights, |
|
372 | self.processingHeaderObj.nHeights, | |
373 | self.systemHeaderObj.nChannels) |
|
373 | self.systemHeaderObj.nChannels) | |
374 |
|
374 | |||
375 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
375 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
376 | self.processingHeaderObj.profilesPerBlock, |
|
376 | self.processingHeaderObj.profilesPerBlock, | |
377 | self.processingHeaderObj.nHeights), |
|
377 | self.processingHeaderObj.nHeights), | |
378 | dtype=numpy.dtype('complex')) |
|
378 | dtype=numpy.dtype('complex')) | |
379 |
|
379 | |||
380 |
|
380 | |||
381 | def writeBlock(self): |
|
381 | def writeBlock(self): | |
382 | """ |
|
382 | """ | |
383 | Escribe el buffer en el file designado |
|
383 | Escribe el buffer en el file designado | |
384 |
|
384 | |||
385 | Affected: |
|
385 | Affected: | |
386 | self.profileIndex |
|
386 | self.profileIndex | |
387 | self.flagIsNewFile |
|
387 | self.flagIsNewFile | |
388 | self.flagIsNewBlock |
|
388 | self.flagIsNewBlock | |
389 | self.nTotalBlocks |
|
389 | self.nTotalBlocks | |
390 | self.blockIndex |
|
390 | self.blockIndex | |
391 |
|
391 | |||
392 | Return: None |
|
392 | Return: None | |
393 | """ |
|
393 | """ | |
394 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
394 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
395 |
|
395 | |||
396 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
396 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
397 |
|
397 | |||
398 | data['real'] = junk.real |
|
398 | data['real'] = junk.real | |
399 | data['imag'] = junk.imag |
|
399 | data['imag'] = junk.imag | |
400 |
|
400 | |||
401 | data = data.reshape( (-1) ) |
|
401 | data = data.reshape( (-1) ) | |
402 |
|
402 | |||
403 | data.tofile( self.fp ) |
|
403 | data.tofile( self.fp ) | |
404 |
|
404 | |||
405 | self.datablock.fill(0) |
|
405 | self.datablock.fill(0) | |
406 |
|
406 | |||
407 | self.profileIndex = 0 |
|
407 | self.profileIndex = 0 | |
408 | self.flagIsNewFile = 0 |
|
408 | self.flagIsNewFile = 0 | |
409 | self.flagIsNewBlock = 1 |
|
409 | self.flagIsNewBlock = 1 | |
410 |
|
410 | |||
411 | self.blockIndex += 1 |
|
411 | self.blockIndex += 1 | |
412 | self.nTotalBlocks += 1 |
|
412 | self.nTotalBlocks += 1 | |
413 |
|
413 | |||
414 | def putData(self): |
|
414 | def putData(self): | |
415 | """ |
|
415 | """ | |
416 | Setea un bloque de datos y luego los escribe en un file |
|
416 | Setea un bloque de datos y luego los escribe en un file | |
417 |
|
417 | |||
418 | Affected: |
|
418 | Affected: | |
419 | self.flagIsNewBlock |
|
419 | self.flagIsNewBlock | |
420 | self.profileIndex |
|
420 | self.profileIndex | |
421 |
|
421 | |||
422 | Return: |
|
422 | Return: | |
423 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
423 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
424 | 1 : Si se escribio la data de un bloque en un file |
|
424 | 1 : Si se escribio la data de un bloque en un file | |
425 | """ |
|
425 | """ | |
426 | self.flagIsNewBlock = 0 |
|
426 | self.flagIsNewBlock = 0 | |
427 |
|
427 | |||
428 | if self.dataOutObj.flagNoData: |
|
428 | if self.dataOutObj.flagNoData: | |
429 | return 0 |
|
429 | return 0 | |
430 |
|
430 | |||
431 | if self.dataOutObj.flagTimeBlock: |
|
431 | if self.dataOutObj.flagTimeBlock: | |
432 |
|
432 | |||
433 | self.datablock.fill(0) |
|
433 | self.datablock.fill(0) | |
434 | self.profileIndex = 0 |
|
434 | self.profileIndex = 0 | |
435 | self.setNextFile() |
|
435 | self.setNextFile() | |
436 |
|
436 | |||
437 | if self.profileIndex == 0: |
|
437 | if self.profileIndex == 0: | |
438 | self.getBasicHeader() |
|
438 | self.getBasicHeader() | |
439 |
|
439 | |||
440 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data |
|
440 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data | |
441 |
|
441 | |||
442 | self.profileIndex += 1 |
|
442 | self.profileIndex += 1 | |
443 |
|
443 | |||
444 | if self.hasAllDataInBuffer(): |
|
444 | if self.hasAllDataInBuffer(): | |
445 | #if self.flagIsNewFile: |
|
445 | #if self.flagIsNewFile: | |
446 | self.writeNextBlock() |
|
446 | self.writeNextBlock() | |
447 | # self.getDataHeader() |
|
447 | # self.getDataHeader() | |
448 |
|
448 | |||
449 | if self.flagNoMoreFiles: |
|
449 | if self.flagNoMoreFiles: | |
450 | #print 'Process finished' |
|
450 | #print 'Process finished' | |
451 | return 0 |
|
451 | return 0 | |
452 |
|
452 | |||
453 | return 1 |
|
453 | return 1 | |
454 |
|
454 | |||
455 | def __getProcessFlags(self): |
|
455 | def __getProcessFlags(self): | |
456 |
|
456 | |||
457 | processFlags = 0 |
|
457 | processFlags = 0 | |
458 |
|
458 | |||
459 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
459 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
460 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
460 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
461 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
461 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
462 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
462 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
463 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
463 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
464 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
464 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
465 |
|
465 | |||
466 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
466 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
467 |
|
467 | |||
468 |
|
468 | |||
469 |
|
469 | |||
470 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
470 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
471 | PROCFLAG.DATATYPE_SHORT, |
|
471 | PROCFLAG.DATATYPE_SHORT, | |
472 | PROCFLAG.DATATYPE_LONG, |
|
472 | PROCFLAG.DATATYPE_LONG, | |
473 | PROCFLAG.DATATYPE_INT64, |
|
473 | PROCFLAG.DATATYPE_INT64, | |
474 | PROCFLAG.DATATYPE_FLOAT, |
|
474 | PROCFLAG.DATATYPE_FLOAT, | |
475 | PROCFLAG.DATATYPE_DOUBLE] |
|
475 | PROCFLAG.DATATYPE_DOUBLE] | |
476 |
|
476 | |||
477 |
|
477 | |||
478 | for index in range(len(dtypeList)): |
|
478 | for index in range(len(dtypeList)): | |
479 | if self.dataOutObj.dtype == dtypeList[index]: |
|
479 | if self.dataOutObj.dtype == dtypeList[index]: | |
480 | dtypeValue = datatypeValueList[index] |
|
480 | dtypeValue = datatypeValueList[index] | |
481 | break |
|
481 | break | |
482 |
|
482 | |||
483 | processFlags += dtypeValue |
|
483 | processFlags += dtypeValue | |
484 |
|
484 | |||
485 | if self.dataOutObj.flagDecodeData: |
|
485 | if self.dataOutObj.flagDecodeData: | |
486 | processFlags += PROCFLAG.DECODE_DATA |
|
486 | processFlags += PROCFLAG.DECODE_DATA | |
487 |
|
487 | |||
488 | if self.dataOutObj.flagDeflipData: |
|
488 | if self.dataOutObj.flagDeflipData: | |
489 | processFlags += PROCFLAG.DEFLIP_DATA |
|
489 | processFlags += PROCFLAG.DEFLIP_DATA | |
490 |
|
490 | |||
491 | if self.dataOutObj.code != None: |
|
491 | if self.dataOutObj.code != None: | |
492 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
492 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
493 |
|
493 | |||
494 | if self.dataOutObj.nCohInt > 1: |
|
494 | if self.dataOutObj.nCohInt > 1: | |
495 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
495 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
496 |
|
496 | |||
497 | return processFlags |
|
497 | return processFlags | |
498 |
|
498 | |||
499 |
|
499 | |||
500 | def __getBlockSize(self): |
|
500 | def __getBlockSize(self): | |
501 | ''' |
|
501 | ''' | |
502 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
502 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
503 | ''' |
|
503 | ''' | |
504 |
|
504 | |||
505 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
505 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
506 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
506 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
507 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
507 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
508 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
508 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
509 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
509 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
510 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
510 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
511 |
|
511 | |||
512 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
512 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
513 | datatypeValueList = [1,2,4,8,4,8] |
|
513 | datatypeValueList = [1,2,4,8,4,8] | |
514 | for index in range(len(dtypeList)): |
|
514 | for index in range(len(dtypeList)): | |
515 | if self.dataOutObj.dtype == dtypeList[index]: |
|
515 | if self.dataOutObj.dtype == dtypeList[index]: | |
516 | datatypeValue = datatypeValueList[index] |
|
516 | datatypeValue = datatypeValueList[index] | |
517 | break |
|
517 | break | |
518 |
|
518 | |||
519 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) |
|
519 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) | |
520 |
|
520 | |||
521 | return blocksize |
|
521 | return blocksize | |
522 |
|
522 | |||
523 |
|
523 | |||
524 | def getBasicHeader(self): |
|
524 | def getBasicHeader(self): | |
525 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
525 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
526 | self.basicHeaderObj.version = self.versionFile |
|
526 | self.basicHeaderObj.version = self.versionFile | |
527 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
527 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
528 |
|
528 | |||
529 |
utc = numpy.floor(self.dataOutObj. |
|
529 | utc = numpy.floor(self.dataOutObj.utctime) | |
530 |
milisecond = (self.dataOutObj. |
|
530 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 | |
531 |
|
531 | |||
532 | self.basicHeaderObj.utc = utc |
|
532 | self.basicHeaderObj.utc = utc | |
533 | self.basicHeaderObj.miliSecond = milisecond |
|
533 | self.basicHeaderObj.miliSecond = milisecond | |
534 | self.basicHeaderObj.timeZone = 0 |
|
534 | self.basicHeaderObj.timeZone = 0 | |
535 | self.basicHeaderObj.dstFlag = 0 |
|
535 | self.basicHeaderObj.dstFlag = 0 | |
536 | self.basicHeaderObj.errorCount = 0 |
|
536 | self.basicHeaderObj.errorCount = 0 | |
537 |
|
537 | |||
538 | def getDataHeader(self): |
|
538 | def getDataHeader(self): | |
539 |
|
539 | |||
540 | """ |
|
540 | """ | |
541 | Obtiene una copia del First Header |
|
541 | Obtiene una copia del First Header | |
542 |
|
542 | |||
543 | Affected: |
|
543 | Affected: | |
544 | self.systemHeaderObj |
|
544 | self.systemHeaderObj | |
545 | self.radarControllerHeaderObj |
|
545 | self.radarControllerHeaderObj | |
546 | self.dtype |
|
546 | self.dtype | |
547 |
|
547 | |||
548 | Return: |
|
548 | Return: | |
549 | None |
|
549 | None | |
550 | """ |
|
550 | """ | |
551 |
|
551 | |||
552 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
552 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
553 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
553 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
554 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
554 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
555 |
|
555 | |||
556 | self.getBasicHeader() |
|
556 | self.getBasicHeader() | |
557 |
|
557 | |||
558 | processingHeaderSize = 40 # bytes |
|
558 | processingHeaderSize = 40 # bytes | |
559 | self.processingHeaderObj.dtype = 0 # Voltage |
|
559 | self.processingHeaderObj.dtype = 0 # Voltage | |
560 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
560 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
561 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
561 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
562 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
562 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
563 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
563 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
564 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
564 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
565 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt |
|
565 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt | |
566 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
566 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
567 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
567 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
568 |
|
568 | |||
569 | if self.dataOutObj.code != None: |
|
569 | if self.dataOutObj.code != None: | |
570 | self.processingHeaderObj.code = self.dataOutObj.code |
|
570 | self.processingHeaderObj.code = self.dataOutObj.code | |
571 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
571 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
572 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
572 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
573 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
573 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
574 | processingHeaderSize += codesize |
|
574 | processingHeaderSize += codesize | |
575 |
|
575 | |||
576 | if self.processingHeaderObj.nWindows != 0: |
|
576 | if self.processingHeaderObj.nWindows != 0: | |
577 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
577 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
578 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
578 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
579 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
579 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
580 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
580 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
581 | processingHeaderSize += 12 |
|
581 | processingHeaderSize += 12 | |
582 |
|
582 | |||
583 | self.processingHeaderObj.size = processingHeaderSize |
|
583 | self.processingHeaderObj.size = processingHeaderSize | |
584 | No newline at end of file |
|
584 |
@@ -1,541 +1,596 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import time |
|
9 | import time | |
10 | import datetime |
|
10 | import datetime | |
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Data.JROData import SpectraHeis |
|
14 | from Data.JROData import Spectra, SpectraHeis | |
15 | from IO.SpectraIO import SpectraWriter |
|
15 | from IO.SpectraIO import SpectraWriter | |
16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure |
|
16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure | |
17 | #from JRONoise import Noise |
|
17 | #from JRONoise import Noise | |
18 |
|
18 | |||
19 | class SpectraProcessor: |
|
19 | class SpectraProcessor: | |
20 | ''' |
|
20 | ''' | |
21 | classdocs |
|
21 | classdocs | |
22 | ''' |
|
22 | ''' | |
23 |
|
23 | |||
24 | dataInObj = None |
|
24 | dataInObj = None | |
25 |
|
25 | |||
26 | dataOutObj = None |
|
26 | dataOutObj = None | |
27 |
|
27 | |||
28 | noiseObj = None |
|
28 | noiseObj = None | |
29 |
|
29 | |||
30 | integratorObjList = [] |
|
30 | integratorObjList = [] | |
31 |
|
31 | |||
32 | writerObjList = [] |
|
32 | writerObjList = [] | |
33 |
|
33 | |||
34 | integratorObjIndex = None |
|
34 | integratorObjIndex = None | |
35 |
|
35 | |||
36 | writerObjIndex = None |
|
36 | writerObjIndex = None | |
37 |
|
37 | |||
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | def __init__(self): |
|
41 | def __init__(self): | |
42 | ''' |
|
42 | ''' | |
43 | Constructor |
|
43 | Constructor | |
44 | ''' |
|
44 | ''' | |
45 |
|
45 | |||
46 | self.integratorObjIndex = None |
|
46 | self.integratorObjIndex = None | |
47 | self.writerObjIndex = None |
|
47 | self.writerObjIndex = None | |
48 | self.plotObjIndex = None |
|
48 | self.plotObjIndex = None | |
49 | self.integratorOst = [] |
|
49 | self.integratorOst = [] | |
50 | self.plotObjList = [] |
|
50 | self.plotObjList = [] | |
51 |
self.noiseObj = |
|
51 | self.noiseObj = [] | |
52 |
self.writerObjLi |
|
52 | self.writerObjList = [] | |
53 | self.buffer = None |
|
53 | self.buffer = None | |
54 | self.profIndex = 0 |
|
54 | self.profIndex = 0 | |
55 |
|
55 | |||
56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): | |
57 |
|
57 | |||
58 | if dataInObj == None: |
|
58 | if dataInObj == None: | |
59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" | |
60 |
|
60 | |||
61 | if dataInObj.type == "Voltage": |
|
61 | if dataInObj.type == "Voltage": | |
62 | if nFFTPoints == None: |
|
62 | if nFFTPoints == None: | |
63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" | |
64 |
|
|
64 | ||
|
65 | ||||
|
66 | ||||
|
67 | if dataInObj.type == "Spectra": | |||
|
68 | if nFFTPoints != None: | |||
|
69 | raise ValueError, "The nFFTPoints cannot be selected to this object type" | |||
|
70 | ||||
65 | nFFTPoints = dataInObj.nFFTPoints |
|
71 | nFFTPoints = dataInObj.nFFTPoints | |
|
72 | ||||
|
73 | if pairList == None: | |||
|
74 | pairList = self.dataInObj.pairList | |||
|
75 | ||||
|
76 | if pairList == None: | |||
|
77 | nPairs = 0 | |||
|
78 | else: | |||
|
79 | nPairs = len(pairList) | |||
66 |
|
80 | |||
67 | self.dataInObj = dataInObj |
|
81 | self.dataInObj = dataInObj | |
68 |
|
82 | |||
69 | if dataOutObj == None: |
|
83 | if dataOutObj == None: | |
70 | dataOutObj = Spectra() |
|
84 | dataOutObj = Spectra() | |
71 |
|
85 | |||
72 | self.dataOutObj = dataOutObj |
|
86 | self.dataOutObj = dataOutObj | |
|
87 | self.dataOutObj.nFFTPoints = nFFTPoints | |||
|
88 | self.dataOutObj.pairList = pairList | |||
|
89 | self.dataOutObj.nPairs = nPairs | |||
73 |
|
90 | |||
74 | return self.dataOutObj |
|
91 | return self.dataOutObj | |
75 |
|
92 | |||
76 | def init(self): |
|
93 | def init(self): | |
77 |
|
94 | |||
|
95 | self.dataOutObj.flagNoData = True | |||
|
96 | ||||
|
97 | if self.dataInObj.flagNoData: | |||
|
98 | return 0 | |||
|
99 | ||||
78 | self.integratorObjIndex = 0 |
|
100 | self.integratorObjIndex = 0 | |
79 | self.writerObjIndex = 0 |
|
101 | self.writerObjIndex = 0 | |
80 | self.plotObjIndex = 0 |
|
102 | self.plotObjIndex = 0 | |
|
103 | ||||
|
104 | ||||
|
105 | if self.dataInObj.type == "Spectra": | |||
|
106 | ||||
|
107 | self.dataOutObj.copy(self.dataInObj) | |||
|
108 | self.dataOutObj.flagNoData = False | |||
|
109 | return | |||
|
110 | ||||
81 | if self.dataInObj.type == "Voltage": |
|
111 | if self.dataInObj.type == "Voltage": | |
82 |
|
112 | |||
83 | if self.buffer == None: |
|
113 | if self.buffer == None: | |
84 | self.buffer = numpy.zeros((self.nChannels, |
|
114 | self.buffer = numpy.zeros((self.dataInObj.nChannels, | |
85 | self.nFFTPoints, |
|
115 | self.dataOutObj.nFFTPoints, | |
86 | self.dataInObj.nHeights), |
|
116 | self.dataInObj.nHeights), | |
87 | dtype='complex') |
|
117 | dtype='complex') | |
88 |
|
118 | |||
89 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
119 | self.buffer[:,self.profIndex,:] = self.dataInObj.data | |
90 | self.profIndex += 1 |
|
120 | self.profIndex += 1 | |
91 |
|
121 | |||
92 | if self.profIndex == self.nFFTPoints: |
|
122 | if self.profIndex == self.dataOutObj.nFFTPoints: | |
|
123 | ||||
|
124 | self.__updateObjFromInput() | |||
93 | self.__getFft() |
|
125 | self.__getFft() | |
|
126 | ||||
94 | self.dataOutObj.flagNoData = False |
|
127 | self.dataOutObj.flagNoData = False | |
95 |
|
128 | |||
96 | self.buffer = None |
|
129 | self.buffer = None | |
97 | self.profIndex = 0 |
|
130 | self.profIndex = 0 | |
98 | return |
|
|||
99 |
|
131 | |||
100 | self.dataOutObj.flagNoData = True |
|
|||
101 |
|
||||
102 | return |
|
|||
103 |
|
||||
104 | #Other kind of data |
|
|||
105 | if self.dataInObj.type == "Spectra": |
|
|||
106 | self.dataOutObj.copy(self.dataInObj) |
|
|||
107 | self.dataOutObj.flagNoData = False |
|
|||
108 | return |
|
132 | return | |
109 |
|
133 | |||
110 | raise ValueError, "The dtype is not valid" |
|
134 | #Other kind of data | |
|
135 | raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type) | |||
111 |
|
136 | |||
112 | def __getFft(self): |
|
137 | def __getFft(self): | |
113 | """ |
|
138 | """ | |
114 | Convierte valores de Voltaje a Spectra |
|
139 | Convierte valores de Voltaje a Spectra | |
115 |
|
140 | |||
116 | Affected: |
|
141 | Affected: | |
117 | self.dataOutObj.data_spc |
|
142 | self.dataOutObj.data_spc | |
118 | self.dataOutObj.data_cspc |
|
143 | self.dataOutObj.data_cspc | |
119 | self.dataOutObj.data_dc |
|
144 | self.dataOutObj.data_dc | |
120 | self.dataOutObj.heightList |
|
145 | self.dataOutObj.heightList | |
121 | self.dataOutObj.m_BasicHeader |
|
146 | self.dataOutObj.m_BasicHeader | |
122 | self.dataOutObj.m_ProcessingHeader |
|
147 | self.dataOutObj.m_ProcessingHeader | |
123 | self.dataOutObj.radarControllerHeaderObj |
|
148 | self.dataOutObj.radarControllerHeaderObj | |
124 | self.dataOutObj.systemHeaderObj |
|
149 | self.dataOutObj.systemHeaderObj | |
125 | self.profIndex |
|
150 | self.profIndex | |
126 | self.buffer |
|
151 | self.buffer | |
127 | self.dataOutObj.flagNoData |
|
152 | self.dataOutObj.flagNoData | |
128 | self.dataOutObj.dtype |
|
153 | self.dataOutObj.dtype | |
129 | self.dataOutObj.nPairs |
|
154 | self.dataOutObj.nPairs | |
130 | self.dataOutObj.nChannels |
|
155 | self.dataOutObj.nChannels | |
131 | self.dataOutObj.nProfiles |
|
156 | self.dataOutObj.nProfiles | |
132 | self.dataOutObj.systemHeaderObj.numChannels |
|
157 | self.dataOutObj.systemHeaderObj.numChannels | |
133 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
158 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
134 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
159 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
135 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
160 | self.dataOutObj.m_ProcessingHeader.numHeights | |
136 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
161 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
137 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
162 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
138 | """ |
|
163 | """ | |
139 |
|
||||
140 | if self.dataInObj.flagNoData: |
|
|||
141 | return 0 |
|
|||
142 |
|
164 | |||
143 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
165 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
144 | dc = fft_volt[:,0,:] |
|
166 | dc = fft_volt[:,0,:] | |
145 |
|
167 | |||
146 | #calculo de self-spectra |
|
168 | #calculo de self-spectra | |
147 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
169 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
148 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
170 | spc = fft_volt * numpy.conjugate(fft_volt) | |
149 | spc = spc.real |
|
171 | spc = spc.real | |
150 |
|
172 | |||
151 | blocksize = 0 |
|
173 | blocksize = 0 | |
152 | blocksize += dc.size |
|
174 | blocksize += dc.size | |
153 | blocksize += spc.size |
|
175 | blocksize += spc.size | |
154 |
|
176 | |||
155 | cspc = None |
|
177 | cspc = None | |
156 | pairIndex = 0 |
|
178 | pairIndex = 0 | |
157 | if self.pairList != None: |
|
179 | if self.dataOutObj.pairList != None: | |
158 | #calculo de cross-spectra |
|
180 | #calculo de cross-spectra | |
159 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') |
|
181 | cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex') | |
160 | for pair in self.pairList: |
|
182 | for pair in self.pairList: | |
161 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
183 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
162 | pairIndex += 1 |
|
184 | pairIndex += 1 | |
163 | blocksize += cspc.size |
|
185 | blocksize += cspc.size | |
164 |
|
186 | |||
165 | self.dataOutObj.data_spc = spc |
|
187 | self.dataOutObj.data_spc = spc | |
166 | self.dataOutObj.data_cspc = cspc |
|
188 | self.dataOutObj.data_cspc = cspc | |
167 | self.dataOutObj.data_dc = dc |
|
189 | self.dataOutObj.data_dc = dc | |
168 |
self.dataOutObj |
|
190 | self.dataOutObj.blockSize = blocksize | |
169 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc |
|
|||
170 |
|
191 | |||
171 | # self.getNoise() |
|
192 | # self.getNoise() | |
|
193 | ||||
|
194 | def __updateObjFromInput(self): | |||
|
195 | ||||
|
196 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() | |||
|
197 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() | |||
|
198 | self.dataOutObj.channelList = self.dataInObj.channelList | |||
|
199 | self.dataOutObj.heightList = self.dataInObj.heightList | |||
|
200 | self.dataOutObj.dtype = self.dataInObj.dtype | |||
|
201 | self.dataOutObj.nHeights = self.dataInObj.nHeights | |||
|
202 | self.dataOutObj.nChannels = self.dataInObj.nChannels | |||
|
203 | self.dataOutObj.nBaud = self.dataInObj.nBaud | |||
|
204 | self.dataOutObj.nCode = self.dataInObj.nCode | |||
|
205 | self.dataOutObj.code = self.dataInObj.code | |||
|
206 | self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints | |||
|
207 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |||
|
208 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock | |||
|
209 | self.dataOutObj.utctime = self.dataInObj.utctime | |||
|
210 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada | |||
|
211 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip | |||
|
212 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT | |||
|
213 | self.dataOutObj.nIncohInt = 1 | |||
172 |
|
214 | |||
173 | def addWriter(self, wrpath, blocksPerFile): |
|
215 | def addWriter(self, wrpath, blocksPerFile): | |
|
216 | ||||
174 | objWriter = SpectraWriter(self.dataOutObj) |
|
217 | objWriter = SpectraWriter(self.dataOutObj) | |
175 | objWriter.setup(wrpath, blocksPerFile) |
|
218 | objWriter.setup(wrpath, blocksPerFile) | |
176 | self.writerObjList.append(objWriter) |
|
219 | self.writerObjList.append(objWriter) | |
177 |
|
220 | |||
178 | def addIntegrator(self,N,timeInterval): |
|
221 | def addIntegrator(self,N,timeInterval): | |
179 |
|
222 | |||
180 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
223 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
181 | self.integratorObjList.append(objIncohInt) |
|
224 | self.integratorObjList.append(objIncohInt) | |
182 |
|
225 | |||
183 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
226 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
|
227 | ||||
184 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
228 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
185 | self.plotObjList.append(spcObj) |
|
229 | self.plotObjList.append(spcObj) | |
186 |
|
230 | |||
187 | def plotSpc(self, idfigure=None, |
|
231 | def plotSpc(self, idfigure=None, | |
188 | xmin=None, |
|
232 | xmin=None, | |
189 | xmax=None, |
|
233 | xmax=None, | |
190 | ymin=None, |
|
234 | ymin=None, | |
191 | ymax=None, |
|
235 | ymax=None, | |
192 | minvalue=None, |
|
236 | minvalue=None, | |
193 | maxvalue=None, |
|
237 | maxvalue=None, | |
194 | wintitle='', |
|
238 | wintitle='', | |
195 | driver='plplot', |
|
239 | driver='plplot', | |
196 |
colormap='br_gree |
|
240 | colormap='br_green', | |
197 | colorbar=True, |
|
241 | colorbar=True, | |
198 | showprofile=False, |
|
242 | showprofile=False, | |
199 | save=False, |
|
243 | save=False, | |
200 |
gpath=None |
|
244 | gpath=None, | |
|
245 | channelList = None): | |||
201 |
|
246 | |||
202 | if self.dataOutObj.flagNoData: |
|
247 | if self.dataOutObj.flagNoData: | |
203 | return 0 |
|
248 | return 0 | |
204 |
|
249 | |||
205 | nframes = len(self.dataOutObj.channelList) |
|
250 | if channelList == None: | |
|
251 | channelList = self.dataOutObj.channelList | |||
|
252 | ||||
|
253 | nframes = len(channelList) | |||
206 |
|
254 | |||
207 | if len(self.plotObjList) <= self.plotObjIndex: |
|
255 | if len(self.plotObjList) <= self.plotObjIndex: | |
208 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
256 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
209 |
|
257 | |||
210 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
258 | x = numpy.arange(self.dataOutObj.nFFTPoints) | |
211 |
|
259 | |||
212 | y = self.dataOutObj.heightList |
|
260 | y = self.dataOutObj.heightList | |
213 |
|
261 | |||
214 | channelList = self.dataOutObj.channelList |
|
|||
215 |
|
||||
216 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) |
|
262 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |
217 | # noisedB = 10.*numpy.log10(noise) |
|
263 | # noisedB = 10.*numpy.log10(noise) | |
218 | noisedB = numpy.arange(len(channelList)+1) |
|
264 | noisedB = numpy.arange(len(channelList)+1) | |
219 | noisedB = noisedB *1.2 |
|
265 | noisedB = noisedB *1.2 | |
220 | titleList = [] |
|
266 | titleList = [] | |
221 | for i in range(len(noisedB)): |
|
267 | for i in range(len(noisedB)): | |
222 | title = "%.2f"%noisedB[i] |
|
268 | title = "%.2f"%noisedB[i] | |
223 | titleList.append(title) |
|
269 | titleList.append(title) | |
224 |
|
270 | |||
225 |
thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj. |
|
271 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
226 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
272 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
227 | figuretitle = "Spc Radar Data: %s"%dateTime |
|
273 | figuretitle = "Spc Radar Data: %s"%dateTime | |
228 |
|
274 | |||
229 | cleardata = True |
|
275 | cleardata = True | |
230 |
|
276 | |||
231 | plotObj = self.plotObjList[self.plotObjIndex] |
|
277 | plotObj = self.plotObjList[self.plotObjIndex] | |
232 |
|
278 | |||
233 | plotObj.plotPcolor(data, |
|
279 | plotObj.plotPcolor(data, | |
234 | x, |
|
280 | x, | |
235 | y, |
|
281 | y, | |
236 | channelList, |
|
282 | channelList, | |
237 | xmin, |
|
283 | xmin, | |
238 | xmax, |
|
284 | xmax, | |
239 | ymin, |
|
285 | ymin, | |
240 | ymax, |
|
286 | ymax, | |
241 | minvalue, |
|
287 | minvalue, | |
242 | maxvalue, |
|
288 | maxvalue, | |
243 | figuretitle, |
|
289 | figuretitle, | |
244 | None, |
|
290 | None, | |
245 | save, |
|
291 | save, | |
246 | gpath, |
|
292 | gpath, | |
247 | cleardata, |
|
293 | cleardata, | |
248 | titleList) |
|
294 | titleList) | |
249 |
|
295 | |||
250 | self.plotObjIndex += 1 |
|
296 | self.plotObjIndex += 1 | |
251 |
|
297 | |||
252 |
|
298 | |||
253 | def writeData(self, wrpath, blocksPerFile): |
|
299 | def writeData(self, wrpath, blocksPerFile): | |
|
300 | ||||
254 | if self.dataOutObj.flagNoData: |
|
301 | if self.dataOutObj.flagNoData: | |
255 |
|
|
302 | return 0 | |
256 |
|
303 | |||
257 | if len(self.writerObjList) <= self.writerObjIndex: |
|
304 | if len(self.writerObjList) <= self.writerObjIndex: | |
258 | self.addWriter(wrpath, blocksPerFile) |
|
305 | self.addWriter(wrpath, blocksPerFile) | |
259 |
|
306 | |||
260 | self.writerObjList[self.writerObjIndex].putData() |
|
307 | self.writerObjList[self.writerObjIndex].putData() | |
261 |
|
308 | |||
262 | self.writerObjIndex += 1 |
|
309 | self.writerObjIndex += 1 | |
263 |
|
310 | |||
264 | def integrator(self, N=None, timeInterval=None): |
|
311 | def integrator(self, N=None, timeInterval=None): | |
265 |
|
312 | |||
266 | if self.dataOutObj.flagNoData: |
|
313 | if self.dataOutObj.flagNoData: | |
267 | return 0 |
|
314 | return 0 | |
268 |
|
315 | |||
269 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
316 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
270 | self.addIntegrator(N,timeInterval) |
|
317 | self.addIntegrator(N,timeInterval) | |
271 |
|
318 | |||
272 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
319 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
273 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
320 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) | |
274 |
|
321 | |||
275 | if myIncohIntObj.isReady: |
|
322 | if myIncohIntObj.isReady: | |
276 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
323 | self.dataOutObj.data_spc = myIncohIntObj.data | |
277 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
324 | self.dataOutObj.nAvg = myIncohIntObj.navg | |
278 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
325 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg | |
279 | self.dataOutObj.flagNoData = False |
|
326 | self.dataOutObj.flagNoData = False | |
280 |
|
327 | |||
281 | """Calcular el ruido""" |
|
328 | """Calcular el ruido""" | |
282 | self.getNoise() |
|
329 | self.getNoise() | |
283 | else: |
|
330 | else: | |
284 | self.dataOutObj.flagNoData = True |
|
331 | self.dataOutObj.flagNoData = True | |
285 |
|
332 | |||
286 | self.integratorObjIndex += 1 |
|
333 | self.integratorObjIndex += 1 | |
287 |
|
334 | |||
288 |
|
335 | |||
289 | class SpectraHeisProcessor: |
|
336 | class SpectraHeisProcessor: | |
290 |
|
337 | |||
291 | def __init__(self): |
|
338 | def __init__(self): | |
292 |
|
339 | |||
293 | self.integratorObjIndex = None |
|
340 | self.integratorObjIndex = None | |
294 | self.writerObjIndex = None |
|
341 | self.writerObjIndex = None | |
295 | self.plotObjIndex = None |
|
342 | self.plotObjIndex = None | |
296 | self.integratorObjList = [] |
|
343 | self.integratorObjList = [] | |
297 | self.writerObjList = [] |
|
344 | self.writerObjList = [] | |
298 | self.plotObjList = [] |
|
345 | self.plotObjList = [] | |
299 | #self.noiseObj = Noise() |
|
346 | #self.noiseObj = Noise() | |
300 |
|
347 | |||
301 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
348 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): | |
302 |
|
349 | |||
303 | if nFFTPoints == None: |
|
350 | if nFFTPoints == None: | |
304 | nFFTPoints = self.dataInObj.nHeights |
|
351 | nFFTPoints = self.dataInObj.nHeights | |
305 |
|
352 | |||
306 | self.dataInObj = dataInObj |
|
353 | self.dataInObj = dataInObj | |
307 |
|
354 | |||
308 | if dataOutObj == None: |
|
355 | if dataOutObj == None: | |
309 | dataOutObj = SpectraHeis() |
|
356 | dataOutObj = SpectraHeis() | |
310 |
|
357 | |||
311 | self.dataOutObj = dataOutObj |
|
358 | self.dataOutObj = dataOutObj | |
312 |
|
359 | |||
313 | return self.dataOutObj |
|
360 | return self.dataOutObj | |
314 |
|
361 | |||
315 | def init(self): |
|
362 | def init(self): | |
|
363 | ||||
|
364 | self.dataOutObj.flagNoData = True | |||
|
365 | ||||
|
366 | if self.dataInObj.flagNoData: | |||
|
367 | return 0 | |||
|
368 | ||||
316 | self.integratorObjIndex = 0 |
|
369 | self.integratorObjIndex = 0 | |
317 | self.writerObjIndex = 0 |
|
370 | self.writerObjIndex = 0 | |
318 | self.plotObjIndex = 0 |
|
371 | self.plotObjIndex = 0 | |
319 |
|
372 | |||
320 | if self.dataInObj.type == "Voltage": |
|
373 | if self.dataInObj.type == "Voltage": | |
|
374 | self.__updateObjFromInput() | |||
321 | self.__getFft() |
|
375 | self.__getFft() | |
322 | self.__updateFromObj() |
|
|||
323 | self.dataOutObj.flagNoData = False |
|
376 | self.dataOutObj.flagNoData = False | |
324 | return |
|
377 | return | |
325 |
|
378 | |||
326 | #Other kind of data |
|
379 | #Other kind of data | |
327 | if self.dataInObj.type == "SpectraHeis": |
|
380 | if self.dataInObj.type == "SpectraHeis": | |
328 | self.dataOutObj.copy(self.dataInObj) |
|
381 | self.dataOutObj.copy(self.dataInObj) | |
329 | self.dataOutObj.flagNoData = False |
|
382 | self.dataOutObj.flagNoData = False | |
330 | return |
|
383 | return | |
331 |
|
384 | |||
332 | raise ValueError, "The type is not valid" |
|
385 | raise ValueError, "The type is not valid" | |
333 |
|
386 | |||
334 |
def __update |
|
387 | def __updateObjFromInput(self): | |
|
388 | ||||
335 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
389 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() | |
336 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
390 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() | |
337 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
391 | self.dataOutObj.channelList = self.dataInObj.channelList | |
338 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
392 | self.dataOutObj.heightList = self.dataInObj.heightList | |
339 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
393 | self.dataOutObj.dtype = self.dataInObj.dtype | |
340 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
394 | self.dataOutObj.nHeights = self.dataInObj.nHeights | |
341 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
395 | self.dataOutObj.nChannels = self.dataInObj.nChannels | |
342 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
396 | self.dataOutObj.nBaud = self.dataInObj.nBaud | |
343 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
397 | self.dataOutObj.nCode = self.dataInObj.nCode | |
344 | self.dataOutObj.code = self.dataInObj.code |
|
398 | self.dataOutObj.code = self.dataInObj.code | |
345 | self.dataOutObj.nProfiles = 1 |
|
399 | self.dataOutObj.nProfiles = 1 | |
346 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights |
|
400 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights | |
347 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
401 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |
348 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData |
|
402 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData | |
349 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
403 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock | |
350 |
self.dataOutObj. |
|
404 | self.dataOutObj.utctime = self.dataInObj.utctime | |
351 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
405 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada | |
352 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
406 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip | |
353 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
407 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT | |
354 | self.dataOutObj.nIncohInt = 1 |
|
408 | self.dataOutObj.nIncohInt = 1 | |
355 |
|
409 | |||
356 | def __getFft(self): |
|
410 | def __getFft(self): | |
357 | if self.dataInObj.flagNoData: |
|
|||
358 | return 0 |
|
|||
359 |
|
411 | |||
360 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) |
|
412 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) | |
361 | #print fft_volt |
|
413 | #print fft_volt | |
362 | #calculo de self-spectra |
|
414 | #calculo de self-spectra | |
363 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
415 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
364 |
|
416 | |||
365 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
417 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) | |
366 | self.dataOutObj.data_spc = spc |
|
418 | self.dataOutObj.data_spc = spc | |
367 |
|
419 | |||
368 | def getSpectra(self): |
|
420 | def getSpectra(self): | |
369 |
|
421 | |||
370 | return self.dataOutObj.data_spc |
|
422 | return self.dataOutObj.data_spc | |
371 |
|
423 | |||
372 | def getFrecuencies(self): |
|
424 | def getFrecuencies(self): | |
373 |
|
425 | |||
374 | print self.nFFTPoints |
|
426 | print self.nFFTPoints | |
375 | return numpy.arange(int(self.nFFTPoints)) |
|
427 | return numpy.arange(int(self.nFFTPoints)) | |
376 |
|
428 | |||
377 | def addIntegrator(self,N,timeInterval): |
|
429 | def addIntegrator(self,N,timeInterval): | |
|
430 | ||||
378 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
431 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
379 | self.integratorObjList.append(objIncohInt) |
|
432 | self.integratorObjList.append(objIncohInt) | |
380 |
|
433 | |||
381 | def integrator(self, N=None, timeInterval=None): |
|
434 | def integrator(self, N=None, timeInterval=None): | |
|
435 | ||||
382 | if self.dataOutObj.flagNoData: |
|
436 | if self.dataOutObj.flagNoData: | |
383 | return 0 |
|
437 | return 0 | |
384 |
|
438 | |||
385 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
439 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
386 | self.addIntegrator(N,timeInterval) |
|
440 | self.addIntegrator(N,timeInterval) | |
387 |
|
441 | |||
388 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
442 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
389 |
myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj. |
|
443 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime) | |
390 |
|
444 | |||
391 | if myIncohIntObj.isReady: |
|
445 | if myIncohIntObj.isReady: | |
392 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
446 | self.dataOutObj.data_spc = myIncohIntObj.data | |
393 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg |
|
447 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg | |
394 | self.dataOutObj.flagNoData = False |
|
448 | self.dataOutObj.flagNoData = False | |
395 |
|
449 | |||
396 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) |
|
450 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) | |
397 | # self.getNoise(type="sort", parm=16) |
|
451 | # self.getNoise(type="sort", parm=16) | |
398 |
|
452 | |||
399 | else: |
|
453 | else: | |
400 | self.dataOutObj.flagNoData = True |
|
454 | self.dataOutObj.flagNoData = True | |
401 |
|
455 | |||
402 | self.integratorObjIndex += 1 |
|
456 | self.integratorObjIndex += 1 | |
403 |
|
457 | |||
404 |
|
458 | |||
405 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
459 | def addScope(self, idfigure, nframes, wintitle, driver): | |
|
460 | ||||
406 | if idfigure==None: |
|
461 | if idfigure==None: | |
407 | idfigure = self.plotObjIndex |
|
462 | idfigure = self.plotObjIndex | |
408 |
|
463 | |||
409 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
464 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) | |
410 | self.plotObjList.append(scopeObj) |
|
465 | self.plotObjList.append(scopeObj) | |
411 |
|
466 | |||
412 | def plotScope(self, |
|
467 | def plotScope(self, | |
413 | idfigure=None, |
|
468 | idfigure=None, | |
414 | minvalue=None, |
|
469 | minvalue=None, | |
415 | maxvalue=None, |
|
470 | maxvalue=None, | |
416 | xmin=None, |
|
471 | xmin=None, | |
417 | xmax=None, |
|
472 | xmax=None, | |
418 | wintitle='', |
|
473 | wintitle='', | |
419 | driver='plplot', |
|
474 | driver='plplot', | |
420 | save=False, |
|
475 | save=False, | |
421 | gpath=None, |
|
476 | gpath=None, | |
422 | titleList=None, |
|
477 | titleList=None, | |
423 | xlabelList=None, |
|
478 | xlabelList=None, | |
424 | ylabelList=None): |
|
479 | ylabelList=None): | |
425 |
|
480 | |||
426 | if self.dataOutObj.flagNoData: |
|
481 | if self.dataOutObj.flagNoData: | |
427 | return 0 |
|
482 | return 0 | |
428 |
|
483 | |||
429 | nframes = len(self.dataOutObj.channelList) |
|
484 | nframes = len(self.dataOutObj.channelList) | |
430 |
|
485 | |||
431 | if len(self.plotObjList) <= self.plotObjIndex: |
|
486 | if len(self.plotObjList) <= self.plotObjIndex: | |
432 | self.addScope(idfigure, nframes, wintitle, driver) |
|
487 | self.addScope(idfigure, nframes, wintitle, driver) | |
433 |
|
488 | |||
434 |
|
489 | |||
435 | data1D = self.dataOutObj.data_spc |
|
490 | data1D = self.dataOutObj.data_spc | |
436 |
|
491 | |||
437 | x = numpy.arange(self.dataOutObj.nHeights) |
|
492 | x = numpy.arange(self.dataOutObj.nHeights) | |
438 |
|
493 | |||
439 |
thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj. |
|
494 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
440 |
|
495 | |||
441 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
496 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
442 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
497 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
443 |
|
498 | |||
444 | figureTitle = "Scope Plot Radar Data: " + date |
|
499 | figureTitle = "Scope Plot Radar Data: " + date | |
445 |
|
500 | |||
446 | plotObj = self.plotObjList[self.plotObjIndex] |
|
501 | plotObj = self.plotObjList[self.plotObjIndex] | |
447 |
|
502 | |||
448 | plotObj.plot1DArray(data1D, |
|
503 | plotObj.plot1DArray(data1D, | |
449 | x, |
|
504 | x, | |
450 | self.dataOutObj.channelList, |
|
505 | self.dataOutObj.channelList, | |
451 | xmin, |
|
506 | xmin, | |
452 | xmax, |
|
507 | xmax, | |
453 | minvalue, |
|
508 | minvalue, | |
454 | maxvalue, |
|
509 | maxvalue, | |
455 | figureTitle, |
|
510 | figureTitle, | |
456 | save, |
|
511 | save, | |
457 | gpath) |
|
512 | gpath) | |
458 |
|
513 | |||
459 | self.plotObjIndex += 1 |
|
514 | self.plotObjIndex += 1 | |
460 |
|
515 | |||
461 | class IncoherentIntegration: |
|
516 | class IncoherentIntegration: | |
462 |
|
517 | |||
463 | integ_counter = None |
|
518 | integ_counter = None | |
464 | data = None |
|
519 | data = None | |
465 | navg = None |
|
520 | navg = None | |
466 | buffer = None |
|
521 | buffer = None | |
467 | nIncohInt = None |
|
522 | nIncohInt = None | |
468 |
|
523 | |||
469 | def __init__(self, N = None, timeInterval = None): |
|
524 | def __init__(self, N = None, timeInterval = None): | |
470 | """ |
|
525 | """ | |
471 | N |
|
526 | N | |
472 | timeInterval - interval time [min], integer value |
|
527 | timeInterval - interval time [min], integer value | |
473 | """ |
|
528 | """ | |
474 |
|
529 | |||
475 | self.data = None |
|
530 | self.data = None | |
476 | self.navg = None |
|
531 | self.navg = None | |
477 | self.buffer = None |
|
532 | self.buffer = None | |
478 | self.timeOut = None |
|
533 | self.timeOut = None | |
479 | self.exitCondition = False |
|
534 | self.exitCondition = False | |
480 | self.isReady = False |
|
535 | self.isReady = False | |
481 | self.nIncohInt = N |
|
536 | self.nIncohInt = N | |
482 | self.integ_counter = 0 |
|
537 | self.integ_counter = 0 | |
483 | if timeInterval!=None: |
|
538 | if timeInterval!=None: | |
484 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
539 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
485 |
|
540 | |||
486 | if ((timeInterval==None) and (N==None)): |
|
541 | if ((timeInterval==None) and (N==None)): | |
487 | print 'N = None ; timeInterval = None' |
|
542 | print 'N = None ; timeInterval = None' | |
488 | sys.exit(0) |
|
543 | sys.exit(0) | |
489 | elif timeInterval == None: |
|
544 | elif timeInterval == None: | |
490 | self.timeFlag = False |
|
545 | self.timeFlag = False | |
491 | else: |
|
546 | else: | |
492 | self.timeFlag = True |
|
547 | self.timeFlag = True | |
493 |
|
548 | |||
494 |
|
549 | |||
495 | def exe(self,data,timeOfData): |
|
550 | def exe(self,data,timeOfData): | |
496 | """ |
|
551 | """ | |
497 | data |
|
552 | data | |
498 |
|
553 | |||
499 | timeOfData [seconds] |
|
554 | timeOfData [seconds] | |
500 | """ |
|
555 | """ | |
501 |
|
556 | |||
502 | if self.timeFlag: |
|
557 | if self.timeFlag: | |
503 | if self.timeOut == None: |
|
558 | if self.timeOut == None: | |
504 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
559 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
505 |
|
560 | |||
506 | if timeOfData < self.timeOut: |
|
561 | if timeOfData < self.timeOut: | |
507 | if self.buffer == None: |
|
562 | if self.buffer == None: | |
508 | self.buffer = data |
|
563 | self.buffer = data | |
509 | else: |
|
564 | else: | |
510 | self.buffer = self.buffer + data |
|
565 | self.buffer = self.buffer + data | |
511 | self.integ_counter += 1 |
|
566 | self.integ_counter += 1 | |
512 | else: |
|
567 | else: | |
513 | self.exitCondition = True |
|
568 | self.exitCondition = True | |
514 |
|
569 | |||
515 | else: |
|
570 | else: | |
516 | if self.integ_counter < self.nIncohInt: |
|
571 | if self.integ_counter < self.nIncohInt: | |
517 | if self.buffer == None: |
|
572 | if self.buffer == None: | |
518 | self.buffer = data |
|
573 | self.buffer = data | |
519 | else: |
|
574 | else: | |
520 | self.buffer = self.buffer + data |
|
575 | self.buffer = self.buffer + data | |
521 |
|
576 | |||
522 | self.integ_counter += 1 |
|
577 | self.integ_counter += 1 | |
523 |
|
578 | |||
524 | if self.integ_counter == self.nIncohInt: |
|
579 | if self.integ_counter == self.nIncohInt: | |
525 | self.exitCondition = True |
|
580 | self.exitCondition = True | |
526 |
|
581 | |||
527 | if self.exitCondition: |
|
582 | if self.exitCondition: | |
528 | self.data = self.buffer |
|
583 | self.data = self.buffer | |
529 | self.navg = self.integ_counter |
|
584 | self.navg = self.integ_counter | |
530 | self.isReady = True |
|
585 | self.isReady = True | |
531 | self.buffer = None |
|
586 | self.buffer = None | |
532 | self.timeOut = None |
|
587 | self.timeOut = None | |
533 | self.integ_counter = 0 |
|
588 | self.integ_counter = 0 | |
534 | self.exitCondition = False |
|
589 | self.exitCondition = False | |
535 |
|
590 | |||
536 | if self.timeFlag: |
|
591 | if self.timeFlag: | |
537 | self.buffer = data |
|
592 | self.buffer = data | |
538 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
593 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
539 | else: |
|
594 | else: | |
540 | self.isReady = False |
|
595 | self.isReady = False | |
541 | No newline at end of file |
|
596 |
@@ -1,372 +1,372 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os |
|
7 | import os | |
8 | import sys |
|
8 | import sys | |
9 | import numpy |
|
9 | import numpy | |
10 | import datetime |
|
10 | import datetime | |
11 | import time |
|
11 | import time | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from Data.JROData import Voltage |
|
16 | from Data.JROData import Voltage | |
17 | from IO.VoltageIO import VoltageWriter |
|
17 | from IO.VoltageIO import VoltageWriter | |
18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure |
|
18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure | |
19 |
|
19 | |||
20 | class VoltageProcessor: |
|
20 | class VoltageProcessor: | |
21 |
|
21 | |||
22 | dataInObj = None |
|
22 | dataInObj = None | |
23 | dataOutObj = None |
|
23 | dataOutObj = None | |
24 | integratorObjIndex = None |
|
24 | integratorObjIndex = None | |
25 | writerObjIndex = None |
|
25 | writerObjIndex = None | |
26 | integratorObjList = None |
|
26 | integratorObjList = None | |
27 | writerObjList = None |
|
27 | writerObjList = None | |
28 |
|
28 | |||
29 | def __init__(self): |
|
29 | def __init__(self): | |
30 | self.integratorObjIndex = None |
|
30 | self.integratorObjIndex = None | |
31 | self.writerObjIndex = None |
|
31 | self.writerObjIndex = None | |
32 | self.plotObjIndex = None |
|
32 | self.plotObjIndex = None | |
33 | self.integratorObjList = [] |
|
33 | self.integratorObjList = [] | |
34 | self.writerObjList = [] |
|
34 | self.writerObjList = [] | |
35 | self.plotObjList = [] |
|
35 | self.plotObjList = [] | |
36 |
|
36 | |||
37 | def setup(self,dataInObj=None,dataOutObj=None): |
|
37 | def setup(self,dataInObj=None,dataOutObj=None): | |
38 | self.dataInObj = dataInObj |
|
38 | self.dataInObj = dataInObj | |
39 |
|
39 | |||
40 | if self.dataOutObj == None: |
|
40 | if self.dataOutObj == None: | |
41 | dataOutObj = Voltage() |
|
41 | dataOutObj = Voltage() | |
42 |
|
42 | |||
43 | self.dataOutObj = dataOutObj |
|
43 | self.dataOutObj = dataOutObj | |
44 |
|
44 | |||
45 | return self.dataOutObj |
|
45 | return self.dataOutObj | |
46 |
|
46 | |||
47 | def init(self): |
|
47 | def init(self): | |
48 | self.integratorObjIndex = 0 |
|
48 | self.integratorObjIndex = 0 | |
49 | self.writerObjIndex = 0 |
|
49 | self.writerObjIndex = 0 | |
50 | self.plotObjIndex = 0 |
|
50 | self.plotObjIndex = 0 | |
51 |
|
51 | |||
52 | if not(self.dataInObj.flagNoData): |
|
52 | if not(self.dataInObj.flagNoData): | |
53 | self.dataOutObj.copy(self.dataInObj) |
|
53 | self.dataOutObj.copy(self.dataInObj) | |
54 | # No necesita copiar en cada init() los atributos de dataInObj |
|
54 | # No necesita copiar en cada init() los atributos de dataInObj | |
55 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
55 | # la copia deberia hacerse por cada nuevo bloque de datos | |
56 |
|
56 | |||
57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
58 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
58 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
59 | self.plotObjList.append(rtiObj) |
|
59 | self.plotObjList.append(rtiObj) | |
60 |
|
60 | |||
61 | def plotRti(self, idfigure=None, |
|
61 | def plotRti(self, idfigure=None, | |
62 | starttime=None, |
|
62 | starttime=None, | |
63 | endtime=None, |
|
63 | endtime=None, | |
64 | rangemin=None, |
|
64 | rangemin=None, | |
65 | rangemax=None, |
|
65 | rangemax=None, | |
66 | minvalue=None, |
|
66 | minvalue=None, | |
67 | maxvalue=None, |
|
67 | maxvalue=None, | |
68 | wintitle='', |
|
68 | wintitle='', | |
69 | driver='plplot', |
|
69 | driver='plplot', | |
70 | colormap='br_greeen', |
|
70 | colormap='br_greeen', | |
71 | colorbar=True, |
|
71 | colorbar=True, | |
72 | showprofile=False, |
|
72 | showprofile=False, | |
73 | xrangestep=None, |
|
73 | xrangestep=None, | |
74 | save=False, |
|
74 | save=False, | |
75 | gpath=None): |
|
75 | gpath=None): | |
76 |
|
76 | |||
77 | if self.dataOutObj.flagNoData: |
|
77 | if self.dataOutObj.flagNoData: | |
78 | return 0 |
|
78 | return 0 | |
79 |
|
79 | |||
80 | nframes = len(self.dataOutObj.channelList) |
|
80 | nframes = len(self.dataOutObj.channelList) | |
81 |
|
81 | |||
82 | if len(self.plotObjList) <= self.plotObjIndex: |
|
82 | if len(self.plotObjList) <= self.plotObjIndex: | |
83 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
83 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
84 |
|
84 | |||
85 | data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
85 | data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) | |
86 | data = 10*numpy.log10(data.real) |
|
86 | data = 10*numpy.log10(data.real) | |
87 |
|
87 | |||
88 |
# currenttime = self.dataOutObj. |
|
88 | # currenttime = self.dataOutObj.utctime | |
89 | # if timezone == "lt": |
|
89 | # if timezone == "lt": | |
90 |
currenttime = self.dataOutObj. |
|
90 | currenttime = self.dataOutObj.utctime - time.timezone | |
91 |
|
91 | |||
92 | range = self.dataOutObj.heightList |
|
92 | range = self.dataOutObj.heightList | |
93 |
|
93 | |||
94 | channelList = self.dataOutObj.channelList |
|
94 | channelList = self.dataOutObj.channelList | |
95 |
|
95 | |||
96 |
thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj. |
|
96 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
97 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
97 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
98 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) |
|
98 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) | |
99 |
|
99 | |||
100 | figuretitle = "RTI Plot Radar Data" #+ date |
|
100 | figuretitle = "RTI Plot Radar Data" #+ date | |
101 |
|
101 | |||
102 | plotObj = self.plotObjList[self.plotObjIndex] |
|
102 | plotObj = self.plotObjList[self.plotObjIndex] | |
103 |
|
103 | |||
104 | cleardata = False |
|
104 | cleardata = False | |
105 |
|
105 | |||
106 | plotObj.plotPcolor(data, |
|
106 | plotObj.plotPcolor(data, | |
107 | currenttime, |
|
107 | currenttime, | |
108 | range, |
|
108 | range, | |
109 | channelList, |
|
109 | channelList, | |
110 | starttime, |
|
110 | starttime, | |
111 | endtime, |
|
111 | endtime, | |
112 | rangemin, |
|
112 | rangemin, | |
113 | rangemax, |
|
113 | rangemax, | |
114 | minvalue, |
|
114 | minvalue, | |
115 | maxvalue, |
|
115 | maxvalue, | |
116 | figuretitle, |
|
116 | figuretitle, | |
117 | xrangestep, |
|
117 | xrangestep, | |
118 | save, |
|
118 | save, | |
119 | gpath, |
|
119 | gpath, | |
120 | cleardata) |
|
120 | cleardata) | |
121 |
|
121 | |||
122 | self.plotObjIndex += 1 |
|
122 | self.plotObjIndex += 1 | |
123 |
|
123 | |||
124 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
124 | def addScope(self, idfigure, nframes, wintitle, driver): | |
125 | if idfigure==None: |
|
125 | if idfigure==None: | |
126 | idfigure = self.plotObjIndex |
|
126 | idfigure = self.plotObjIndex | |
127 |
|
127 | |||
128 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
128 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) | |
129 | self.plotObjList.append(scopeObj) |
|
129 | self.plotObjList.append(scopeObj) | |
130 |
|
130 | |||
131 | def plotScope(self, |
|
131 | def plotScope(self, | |
132 | idfigure=None, |
|
132 | idfigure=None, | |
133 | minvalue=None, |
|
133 | minvalue=None, | |
134 | maxvalue=None, |
|
134 | maxvalue=None, | |
135 | xmin=None, |
|
135 | xmin=None, | |
136 | xmax=None, |
|
136 | xmax=None, | |
137 | wintitle='', |
|
137 | wintitle='', | |
138 | driver='plplot', |
|
138 | driver='plplot', | |
139 | save=False, |
|
139 | save=False, | |
140 | gpath=None, |
|
140 | gpath=None, | |
141 | titleList=None, |
|
141 | titleList=None, | |
142 | xlabelList=None, |
|
142 | xlabelList=None, | |
143 | ylabelList=None, |
|
143 | ylabelList=None, | |
144 | type="power"): |
|
144 | type="power"): | |
145 |
|
145 | |||
146 | if self.dataOutObj.flagNoData: |
|
146 | if self.dataOutObj.flagNoData: | |
147 | return 0 |
|
147 | return 0 | |
148 |
|
148 | |||
149 | nframes = len(self.dataOutObj.channelList) |
|
149 | nframes = len(self.dataOutObj.channelList) | |
150 |
|
150 | |||
151 | if len(self.plotObjList) <= self.plotObjIndex: |
|
151 | if len(self.plotObjList) <= self.plotObjIndex: | |
152 | self.addScope(idfigure, nframes, wintitle, driver) |
|
152 | self.addScope(idfigure, nframes, wintitle, driver) | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | if type=="power": |
|
155 | if type=="power": | |
156 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
156 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) | |
157 | data1D = data1D.real |
|
157 | data1D = data1D.real | |
158 |
|
158 | |||
159 | if type =="iq": |
|
159 | if type =="iq": | |
160 | data1D = self.dataOutObj.data |
|
160 | data1D = self.dataOutObj.data | |
161 |
|
161 | |||
162 |
thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj. |
|
162 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
163 |
|
163 | |||
164 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
164 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
165 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
165 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
166 |
|
166 | |||
167 | figureTitle = "Scope Plot Radar Data: " + date |
|
167 | figureTitle = "Scope Plot Radar Data: " + date | |
168 |
|
168 | |||
169 | plotObj = self.plotObjList[self.plotObjIndex] |
|
169 | plotObj = self.plotObjList[self.plotObjIndex] | |
170 |
|
170 | |||
171 | plotObj.plot1DArray(data1D, |
|
171 | plotObj.plot1DArray(data1D, | |
172 | self.dataOutObj.heightList, |
|
172 | self.dataOutObj.heightList, | |
173 | self.dataOutObj.channelList, |
|
173 | self.dataOutObj.channelList, | |
174 | xmin, |
|
174 | xmin, | |
175 | xmax, |
|
175 | xmax, | |
176 | minvalue, |
|
176 | minvalue, | |
177 | maxvalue, |
|
177 | maxvalue, | |
178 | figureTitle, |
|
178 | figureTitle, | |
179 | save, |
|
179 | save, | |
180 | gpath) |
|
180 | gpath) | |
181 |
|
181 | |||
182 | self.plotObjIndex += 1 |
|
182 | self.plotObjIndex += 1 | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | def addIntegrator(self, *args): |
|
185 | def addIntegrator(self, *args): | |
186 | objCohInt = CoherentIntegrator(*args) |
|
186 | objCohInt = CoherentIntegrator(*args) | |
187 | self.integratorObjList.append(objCohInt) |
|
187 | self.integratorObjList.append(objCohInt) | |
188 |
|
188 | |||
189 | def addWriter(self, *args): |
|
189 | def addWriter(self, *args): | |
190 | writerObj = VoltageWriter(self.dataOutObj) |
|
190 | writerObj = VoltageWriter(self.dataOutObj) | |
191 | writerObj.setup(*args) |
|
191 | writerObj.setup(*args) | |
192 | self.writerObjList.append(writerObj) |
|
192 | self.writerObjList.append(writerObj) | |
193 |
|
193 | |||
194 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): |
|
194 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): | |
195 |
|
195 | |||
196 | if self.dataOutObj.flagNoData: |
|
196 | if self.dataOutObj.flagNoData: | |
197 | return 0 |
|
197 | return 0 | |
198 |
|
198 | |||
199 | if len(self.writerObjList) <= self.writerObjIndex: |
|
199 | if len(self.writerObjList) <= self.writerObjIndex: | |
200 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) |
|
200 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) | |
201 |
|
201 | |||
202 | self.writerObjList[self.writerObjIndex].putData() |
|
202 | self.writerObjList[self.writerObjIndex].putData() | |
203 |
|
203 | |||
204 | self.writerObjIndex += 1 |
|
204 | self.writerObjIndex += 1 | |
205 |
|
205 | |||
206 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
206 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): | |
207 |
|
207 | |||
208 | if self.dataOutObj.flagNoData: |
|
208 | if self.dataOutObj.flagNoData: | |
209 | return 0 |
|
209 | return 0 | |
210 |
|
210 | |||
211 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
211 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
212 | self.addIntegrator(nCohInt, timeInterval, overlapping) |
|
212 | self.addIntegrator(nCohInt, timeInterval, overlapping) | |
213 |
|
213 | |||
214 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
214 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
215 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) |
|
215 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) | |
216 |
|
216 | |||
217 | self.dataOutObj.flagNoData = True |
|
217 | self.dataOutObj.flagNoData = True | |
218 |
|
218 | |||
219 | if myCohIntObj.isReady: |
|
219 | if myCohIntObj.isReady: | |
220 | self.dataOutObj.flagNoData = False |
|
220 | self.dataOutObj.flagNoData = False | |
221 |
|
221 | |||
222 |
|
222 | |||
223 |
|
223 | |||
224 | class CoherentIntegrator: |
|
224 | class CoherentIntegrator: | |
225 |
|
225 | |||
226 |
|
226 | |||
227 | __profIndex = 0 |
|
227 | __profIndex = 0 | |
228 | __withOverapping = False |
|
228 | __withOverapping = False | |
229 |
|
229 | |||
230 | __isByTime = False |
|
230 | __isByTime = False | |
231 | __initime = None |
|
231 | __initime = None | |
232 | __integrationtime = None |
|
232 | __integrationtime = None | |
233 |
|
233 | |||
234 | __buffer = None |
|
234 | __buffer = None | |
235 |
|
235 | |||
236 | isReady = False |
|
236 | isReady = False | |
237 | nCohInt = None |
|
237 | nCohInt = None | |
238 |
|
238 | |||
239 |
|
239 | |||
240 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
240 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): | |
241 |
|
241 | |||
242 | """ |
|
242 | """ | |
243 | Set the parameters of the integration class. |
|
243 | Set the parameters of the integration class. | |
244 |
|
244 | |||
245 | Inputs: |
|
245 | Inputs: | |
246 |
|
246 | |||
247 | nCohInt : Number of coherent integrations |
|
247 | nCohInt : Number of coherent integrations | |
248 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work |
|
248 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work | |
249 | overlapping : |
|
249 | overlapping : | |
250 |
|
250 | |||
251 | """ |
|
251 | """ | |
252 |
|
252 | |||
253 | self.__buffer = None |
|
253 | self.__buffer = None | |
254 | self.isReady = False |
|
254 | self.isReady = False | |
255 |
|
255 | |||
256 | if nCohInt == None and timeInterval == None: |
|
256 | if nCohInt == None and timeInterval == None: | |
257 | raise ValueError, "nCohInt or timeInterval should be specified ..." |
|
257 | raise ValueError, "nCohInt or timeInterval should be specified ..." | |
258 |
|
258 | |||
259 | if nCohInt != None: |
|
259 | if nCohInt != None: | |
260 | self.nCohInt = nCohInt |
|
260 | self.nCohInt = nCohInt | |
261 | self.__isByTime = False |
|
261 | self.__isByTime = False | |
262 | else: |
|
262 | else: | |
263 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
263 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
264 | self.__isByTime = True |
|
264 | self.__isByTime = True | |
265 |
|
265 | |||
266 | if overlapping: |
|
266 | if overlapping: | |
267 | self.__withOverapping = True |
|
267 | self.__withOverapping = True | |
268 | self.__buffer = None |
|
268 | self.__buffer = None | |
269 | else: |
|
269 | else: | |
270 | self.__withOverapping = False |
|
270 | self.__withOverapping = False | |
271 | self.__buffer = 0 |
|
271 | self.__buffer = 0 | |
272 |
|
272 | |||
273 | self.__profIndex = 0 |
|
273 | self.__profIndex = 0 | |
274 |
|
274 | |||
275 | def putData(self, data): |
|
275 | def putData(self, data): | |
276 |
|
276 | |||
277 | """ |
|
277 | """ | |
278 | Add a profile to the __buffer and increase in one the __profileIndex |
|
278 | Add a profile to the __buffer and increase in one the __profileIndex | |
279 |
|
279 | |||
280 | """ |
|
280 | """ | |
281 | if not self.__withOverapping: |
|
281 | if not self.__withOverapping: | |
282 | self.__buffer += data |
|
282 | self.__buffer += data | |
283 | self.__profIndex += 1 |
|
283 | self.__profIndex += 1 | |
284 | return |
|
284 | return | |
285 |
|
285 | |||
286 | #Overlapping data |
|
286 | #Overlapping data | |
287 | nChannels, nHeis = data.shape |
|
287 | nChannels, nHeis = data.shape | |
288 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
288 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
289 |
|
289 | |||
290 | if self.__buffer == None: |
|
290 | if self.__buffer == None: | |
291 | self.__buffer = data |
|
291 | self.__buffer = data | |
292 | self.__profIndex += 1 |
|
292 | self.__profIndex += 1 | |
293 | return |
|
293 | return | |
294 |
|
294 | |||
295 | if self.__profIndex < self.nCohInt: |
|
295 | if self.__profIndex < self.nCohInt: | |
296 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
296 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
297 | self.__profIndex += 1 |
|
297 | self.__profIndex += 1 | |
298 | return |
|
298 | return | |
299 |
|
299 | |||
300 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
300 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
301 | self.__buffer[self.nCohInt-1] = data |
|
301 | self.__buffer[self.nCohInt-1] = data | |
302 | #self.__profIndex = self.nCohInt |
|
302 | #self.__profIndex = self.nCohInt | |
303 | return |
|
303 | return | |
304 |
|
304 | |||
305 |
|
305 | |||
306 | def pushData(self): |
|
306 | def pushData(self): | |
307 | """ |
|
307 | """ | |
308 | Return the sum of the last profiles and the profiles used in the sum. |
|
308 | Return the sum of the last profiles and the profiles used in the sum. | |
309 |
|
309 | |||
310 | Affected: |
|
310 | Affected: | |
311 |
|
311 | |||
312 | self.__profileIndex |
|
312 | self.__profileIndex | |
313 |
|
313 | |||
314 | """ |
|
314 | """ | |
315 |
|
315 | |||
316 | if not self.__withOverapping: |
|
316 | if not self.__withOverapping: | |
317 | data = self.__buffer |
|
317 | data = self.__buffer | |
318 | nCohInt = self.__profIndex |
|
318 | nCohInt = self.__profIndex | |
319 |
|
319 | |||
320 | self.__buffer = 0 |
|
320 | self.__buffer = 0 | |
321 | self.__profIndex = 0 |
|
321 | self.__profIndex = 0 | |
322 |
|
322 | |||
323 | return data, nCohInt |
|
323 | return data, nCohInt | |
324 |
|
324 | |||
325 | #Overlapping data |
|
325 | #Overlapping data | |
326 | data = numpy.sum(self.__buffer, axis=0) |
|
326 | data = numpy.sum(self.__buffer, axis=0) | |
327 | nCohInt = self.__profIndex |
|
327 | nCohInt = self.__profIndex | |
328 |
|
328 | |||
329 | return data, nCohInt |
|
329 | return data, nCohInt | |
330 |
|
330 | |||
331 | def byProfiles(self, data): |
|
331 | def byProfiles(self, data): | |
332 |
|
332 | |||
333 | self.isReady = False |
|
333 | self.isReady = False | |
334 | avg_data = None |
|
334 | avg_data = None | |
335 |
|
335 | |||
336 | self.putData(data) |
|
336 | self.putData(data) | |
337 |
|
337 | |||
338 | if self.__profIndex == self.nCohInt: |
|
338 | if self.__profIndex == self.nCohInt: | |
339 | avg_data, nCohInt = self.pushData() |
|
339 | avg_data, nCohInt = self.pushData() | |
340 | self.isReady = True |
|
340 | self.isReady = True | |
341 |
|
341 | |||
342 | return avg_data |
|
342 | return avg_data | |
343 |
|
343 | |||
344 | def byTime(self, data, datatime): |
|
344 | def byTime(self, data, datatime): | |
345 |
|
345 | |||
346 | self.isReady = False |
|
346 | self.isReady = False | |
347 | avg_data = None |
|
347 | avg_data = None | |
348 |
|
348 | |||
349 | if self.__initime == None: |
|
349 | if self.__initime == None: | |
350 | self.__initime = datatime |
|
350 | self.__initime = datatime | |
351 |
|
351 | |||
352 | self.putData(data) |
|
352 | self.putData(data) | |
353 |
|
353 | |||
354 | if (datatime - self.__initime) >= self.__integrationtime: |
|
354 | if (datatime - self.__initime) >= self.__integrationtime: | |
355 | avg_data, nCohInt = self.pushData() |
|
355 | avg_data, nCohInt = self.pushData() | |
356 | self.nCohInt = nCohInt |
|
356 | self.nCohInt = nCohInt | |
357 | self.isReady = True |
|
357 | self.isReady = True | |
358 |
|
358 | |||
359 | return avg_data |
|
359 | return avg_data | |
360 |
|
360 | |||
361 | def exe(self, data, datatime=None): |
|
361 | def exe(self, data, datatime=None): | |
362 |
|
362 | |||
363 | if not self.__isByTime: |
|
363 | if not self.__isByTime: | |
364 | avg_data = self.byProfiles(data) |
|
364 | avg_data = self.byProfiles(data) | |
365 | else: |
|
365 | else: | |
366 | avg_data = self.byTime(data, datatime) |
|
366 | avg_data = self.byTime(data, datatime) | |
367 |
|
367 | |||
368 | self.data = avg_data |
|
368 | self.data = avg_data | |
369 |
|
369 | |||
370 | return avg_data |
|
370 | return avg_data | |
371 |
|
371 | |||
372 |
|
372 |
General Comments 0
You need to be logged in to leave comments.
Login now