@@ -1,244 +1,248 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import copy |
|
8 | import copy | |
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from IO.JROHeaderIO import SystemHeader, RadarControllerHeader |
|
14 | from IO.JROHeaderIO import SystemHeader, RadarControllerHeader | |
15 |
|
15 | |||
16 | class JROData: |
|
16 | class JROData: | |
17 |
|
17 | |||
18 | # m_BasicHeader = BasicHeader() |
|
18 | # m_BasicHeader = BasicHeader() | |
19 | # m_ProcessingHeader = ProcessingHeader() |
|
19 | # m_ProcessingHeader = ProcessingHeader() | |
20 |
|
20 | |||
21 | systemHeaderObj = SystemHeader() |
|
21 | systemHeaderObj = SystemHeader() | |
22 |
|
22 | |||
23 | radarControllerHeaderObj = RadarControllerHeader() |
|
23 | radarControllerHeaderObj = RadarControllerHeader() | |
24 |
|
24 | |||
25 | # data = None |
|
25 | # data = None | |
26 |
|
26 | |||
27 | type = None |
|
27 | type = None | |
28 |
|
28 | |||
29 | dtype = None |
|
29 | dtype = None | |
30 |
|
30 | |||
31 | nChannels = None |
|
31 | nChannels = None | |
32 |
|
32 | |||
33 | nHeights = None |
|
33 | nHeights = None | |
34 |
|
34 | |||
35 | nProfiles = None |
|
35 | nProfiles = None | |
36 |
|
36 | |||
37 | heightList = None |
|
37 | heightList = None | |
38 |
|
38 | |||
39 | channelList = None |
|
39 | channelList = None | |
40 |
|
40 | |||
41 | channelIndexList = None |
|
41 | channelIndexList = None | |
42 |
|
42 | |||
43 | flagNoData = True |
|
43 | flagNoData = True | |
44 |
|
44 | |||
45 | flagTimeBlock = False |
|
45 | flagTimeBlock = False | |
46 |
|
46 | |||
47 | utctime = None |
|
47 | utctime = None | |
48 |
|
48 | |||
49 | blocksize = None |
|
49 | blocksize = None | |
50 |
|
50 | |||
51 | nCode = None |
|
51 | nCode = None | |
52 |
|
52 | |||
53 | nBaud = None |
|
53 | nBaud = None | |
54 |
|
54 | |||
55 | code = None |
|
55 | code = None | |
56 |
|
56 | |||
57 | flagDecodeData = True #asumo q la data esta decodificada |
|
57 | flagDecodeData = True #asumo q la data esta decodificada | |
58 |
|
58 | |||
59 | flagDeflipData = True #asumo q la data esta sin flip |
|
59 | flagDeflipData = True #asumo q la data esta sin flip | |
60 |
|
60 | |||
61 | flagShiftFFT = False |
|
61 | flagShiftFFT = False | |
62 |
|
62 | |||
63 | ippSeconds = None |
|
63 | ippSeconds = None | |
64 |
|
64 | |||
65 | timeInterval = None |
|
65 | timeInterval = None | |
66 |
|
66 | |||
|
67 | set=None | |||
|
68 | ||||
|
69 | deltaHeight = None | |||
|
70 | ||||
67 | def __init__(self): |
|
71 | def __init__(self): | |
68 |
|
72 | |||
69 | raise ValueError, "This class has not been implemented" |
|
73 | raise ValueError, "This class has not been implemented" | |
70 |
|
74 | |||
71 | def copy(self, inputObj=None): |
|
75 | def copy(self, inputObj=None): | |
72 |
|
76 | |||
73 | if inputObj == None: |
|
77 | if inputObj == None: | |
74 | return copy.deepcopy(self) |
|
78 | return copy.deepcopy(self) | |
75 |
|
79 | |||
76 | for key in inputObj.__dict__.keys(): |
|
80 | for key in inputObj.__dict__.keys(): | |
77 | self.__dict__[key] = inputObj.__dict__[key] |
|
81 | self.__dict__[key] = inputObj.__dict__[key] | |
78 |
|
82 | |||
79 | def deepcopy(self): |
|
83 | def deepcopy(self): | |
80 |
|
84 | |||
81 | return copy.deepcopy(self) |
|
85 | return copy.deepcopy(self) | |
82 |
|
86 | |||
83 | class Voltage(JROData): |
|
87 | class Voltage(JROData): | |
84 |
|
88 | |||
85 | nCohInt = None |
|
89 | nCohInt = None | |
86 |
|
90 | |||
87 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
91 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
88 | data = None |
|
92 | data = None | |
89 |
|
93 | |||
90 | def __init__(self): |
|
94 | def __init__(self): | |
91 | ''' |
|
95 | ''' | |
92 | Constructor |
|
96 | Constructor | |
93 | ''' |
|
97 | ''' | |
94 |
|
98 | |||
95 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
99 | self.radarControllerHeaderObj = RadarControllerHeader() | |
96 |
|
100 | |||
97 | self.systemHeaderObj = SystemHeader() |
|
101 | self.systemHeaderObj = SystemHeader() | |
98 |
|
102 | |||
99 | self.type = "Voltage" |
|
103 | self.type = "Voltage" | |
100 |
|
104 | |||
101 | self.data = None |
|
105 | self.data = None | |
102 |
|
106 | |||
103 | self.dtype = None |
|
107 | self.dtype = None | |
104 |
|
108 | |||
105 | self.nChannels = 0 |
|
109 | self.nChannels = 0 | |
106 |
|
110 | |||
107 | self.nHeights = 0 |
|
111 | self.nHeights = 0 | |
108 |
|
112 | |||
109 | self.nProfiles = None |
|
113 | self.nProfiles = None | |
110 |
|
114 | |||
111 | self.heightList = None |
|
115 | self.heightList = None | |
112 |
|
116 | |||
113 | self.channelList = None |
|
117 | self.channelList = None | |
114 |
|
118 | |||
115 | self.channelIndexList = None |
|
119 | self.channelIndexList = None | |
116 |
|
120 | |||
117 | self.flagNoData = True |
|
121 | self.flagNoData = True | |
118 |
|
122 | |||
119 | self.flagTimeBlock = False |
|
123 | self.flagTimeBlock = False | |
120 |
|
124 | |||
121 | self.utctime = None |
|
125 | self.utctime = None | |
122 |
|
126 | |||
123 | self.nCohInt = None |
|
127 | self.nCohInt = None | |
124 |
|
128 | |||
125 | self.blocksize = None |
|
129 | self.blocksize = None | |
126 |
|
130 | |||
127 | class Spectra(JROData): |
|
131 | class Spectra(JROData): | |
128 |
|
132 | |||
129 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
133 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
130 | data_spc = None |
|
134 | data_spc = None | |
131 |
|
135 | |||
132 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
136 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
133 | data_cspc = None |
|
137 | data_cspc = None | |
134 |
|
138 | |||
135 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
139 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
136 | data_dc = None |
|
140 | data_dc = None | |
137 |
|
141 | |||
138 | nFFTPoints = None |
|
142 | nFFTPoints = None | |
139 |
|
143 | |||
140 | nPairs = None |
|
144 | nPairs = None | |
141 |
|
145 | |||
142 | pairsList = None |
|
146 | pairsList = None | |
143 |
|
147 | |||
144 | nIncohInt = None |
|
148 | nIncohInt = None | |
145 |
|
149 | |||
146 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
150 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
147 |
|
151 | |||
148 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
152 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
149 |
|
153 | |||
150 | def __init__(self): |
|
154 | def __init__(self): | |
151 | ''' |
|
155 | ''' | |
152 | Constructor |
|
156 | Constructor | |
153 | ''' |
|
157 | ''' | |
154 |
|
158 | |||
155 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
159 | self.radarControllerHeaderObj = RadarControllerHeader() | |
156 |
|
160 | |||
157 | self.systemHeaderObj = SystemHeader() |
|
161 | self.systemHeaderObj = SystemHeader() | |
158 |
|
162 | |||
159 | self.type = "Spectra" |
|
163 | self.type = "Spectra" | |
160 |
|
164 | |||
161 | # self.data = None |
|
165 | # self.data = None | |
162 |
|
166 | |||
163 | self.dtype = None |
|
167 | self.dtype = None | |
164 |
|
168 | |||
165 | self.nChannels = 0 |
|
169 | self.nChannels = 0 | |
166 |
|
170 | |||
167 | self.nHeights = 0 |
|
171 | self.nHeights = 0 | |
168 |
|
172 | |||
169 | self.nProfiles = None |
|
173 | self.nProfiles = None | |
170 |
|
174 | |||
171 | self.heightList = None |
|
175 | self.heightList = None | |
172 |
|
176 | |||
173 | self.channelList = None |
|
177 | self.channelList = None | |
174 |
|
178 | |||
175 | self.channelIndexList = None |
|
179 | self.channelIndexList = None | |
176 |
|
180 | |||
177 | self.flagNoData = True |
|
181 | self.flagNoData = True | |
178 |
|
182 | |||
179 | self.flagTimeBlock = False |
|
183 | self.flagTimeBlock = False | |
180 |
|
184 | |||
181 | self.utctime = None |
|
185 | self.utctime = None | |
182 |
|
186 | |||
183 | self.nIncohInt = None |
|
187 | self.nIncohInt = None | |
184 |
|
188 | |||
185 | self.blocksize = None |
|
189 | self.blocksize = None | |
186 |
|
190 | |||
187 | self.nFFTPoints = None |
|
191 | self.nFFTPoints = None | |
188 |
|
192 | |||
189 | self.wavelength = None |
|
193 | self.wavelength = None | |
190 |
|
194 | |||
191 | def getFrequencies(self): |
|
195 | def getFrequencies(self): | |
192 |
|
196 | |||
193 | xrange = numpy.arange(self.nFFTPoints) |
|
197 | xrange = numpy.arange(self.nFFTPoints) | |
194 | xrange = xrange |
|
198 | xrange = xrange | |
195 | return None |
|
199 | return None | |
196 |
|
200 | |||
197 |
|
201 | |||
198 | class SpectraHeis(JROData): |
|
202 | class SpectraHeis(JROData): | |
199 |
|
203 | |||
200 | data_spc = None |
|
204 | data_spc = None | |
201 |
|
205 | |||
202 | data_cspc = None |
|
206 | data_cspc = None | |
203 |
|
207 | |||
204 | data_dc = None |
|
208 | data_dc = None | |
205 |
|
209 | |||
206 | nFFTPoints = None |
|
210 | nFFTPoints = None | |
207 |
|
211 | |||
208 | nPairs = None |
|
212 | nPairs = None | |
209 |
|
213 | |||
210 | pairsList = None |
|
214 | pairsList = None | |
211 |
|
215 | |||
212 | nIncohInt = None |
|
216 | nIncohInt = None | |
213 |
|
217 | |||
214 | def __init__(self): |
|
218 | def __init__(self): | |
215 |
|
219 | |||
216 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
220 | self.radarControllerHeaderObj = RadarControllerHeader() | |
217 |
|
221 | |||
218 | self.systemHeaderObj = SystemHeader() |
|
222 | self.systemHeaderObj = SystemHeader() | |
219 |
|
223 | |||
220 | self.type = "SpectraHeis" |
|
224 | self.type = "SpectraHeis" | |
221 |
|
225 | |||
222 | self.dtype = None |
|
226 | self.dtype = None | |
223 |
|
227 | |||
224 | self.nChannels = 0 |
|
228 | self.nChannels = 0 | |
225 |
|
229 | |||
226 | self.nHeights = 0 |
|
230 | self.nHeights = 0 | |
227 |
|
231 | |||
228 | self.nProfiles = None |
|
232 | self.nProfiles = None | |
229 |
|
233 | |||
230 | self.heightList = None |
|
234 | self.heightList = None | |
231 |
|
235 | |||
232 | self.channelList = None |
|
236 | self.channelList = None | |
233 |
|
237 | |||
234 | self.channelIndexList = None |
|
238 | self.channelIndexList = None | |
235 |
|
239 | |||
236 | self.flagNoData = True |
|
240 | self.flagNoData = True | |
237 |
|
241 | |||
238 | self.flagTimeBlock = False |
|
242 | self.flagTimeBlock = False | |
239 |
|
243 | |||
240 | self.nPairs = 0 |
|
244 | self.nPairs = 0 | |
241 |
|
245 | |||
242 | self.utctime = None |
|
246 | self.utctime = None | |
243 |
|
247 | |||
244 | self.blocksize = None |
|
248 | self.blocksize = None |
@@ -1,883 +1,883 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @autor $Author$ |
|
4 | @autor $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 |
|
6 | |||
7 | ''' |
|
7 | ''' | |
8 |
|
8 | |||
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | import time |
|
11 | import time | |
12 | import datetime |
|
12 | import datetime | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | import matplotlib as mpl |
|
15 | import matplotlib as mpl | |
16 | mpl.use('TKAgg') |
|
16 | mpl.use('TKAgg') | |
17 | import matplotlib.pyplot as plt |
|
17 | import matplotlib.pyplot as plt | |
18 |
|
18 | |||
19 | import scitools.numpyutils as sn |
|
19 | import scitools.numpyutils as sn | |
20 |
|
20 | |||
21 | def cmap1_init(colormap='gray'): |
|
21 | def cmap1_init(colormap='gray'): | |
22 | pass |
|
22 | pass | |
23 |
|
23 | |||
24 | def setColormap(colormap='jet'): |
|
24 | def setColormap(colormap='jet'): | |
25 | pass |
|
25 | pass | |
26 |
|
26 | |||
27 | def savePlplot(filename,width,height): |
|
27 | def savePlplot(filename,width,height): | |
28 | pass |
|
28 | pass | |
29 |
|
29 | |||
30 | def initMatplotlib(indexFig,ncol,nrow,winTitle,width,height): |
|
30 | def initMatplotlib(indexFig,ncol,nrow,winTitle,width,height): | |
31 |
|
31 | |||
32 | plt.ioff() |
|
32 | plt.ioff() | |
33 | fig = plt.figure(indexFig) |
|
33 | fig = plt.figure(indexFig) | |
34 | fig.canvas.manager.set_window_title(winTitle) |
|
34 | fig.canvas.manager.set_window_title(winTitle) | |
35 | fig.canvas.manager.resize(width,height) |
|
35 | fig.canvas.manager.resize(width,height) | |
36 | # fig.add_subplot(nrow,ncol,1) |
|
36 | # fig.add_subplot(nrow,ncol,1) | |
37 | plt.ion() |
|
37 | plt.ion() | |
38 |
|
38 | |||
39 | def setNewPage(): |
|
39 | def setNewPage(): | |
40 | plt.clf() |
|
40 | plt.clf() | |
41 |
|
41 | |||
42 | def closePage(): |
|
42 | def closePage(): | |
43 | pass |
|
43 | pass | |
44 |
|
44 | |||
45 | def clearData(objGraph): |
|
45 | def clearData(objGraph): | |
46 | objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bc', 'bc') |
|
46 | objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bc', 'bc') | |
47 |
|
47 | |||
48 | objGraph.setColor(15) #Setting Line Color to White |
|
48 | objGraph.setColor(15) #Setting Line Color to White | |
49 |
|
49 | |||
50 | if objGraph.datatype == 'complex': |
|
50 | if objGraph.datatype == 'complex': | |
51 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real) |
|
51 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real) | |
52 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag) |
|
52 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag) | |
53 |
|
53 | |||
54 | if objGraph.datatype == 'real': |
|
54 | if objGraph.datatype == 'real': | |
55 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata) |
|
55 | objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata) | |
56 |
|
56 | |||
57 | objGraph.setColor(1) |
|
57 | objGraph.setColor(1) | |
58 |
|
58 | |||
59 | def setFigure(indexFig): |
|
59 | def setFigure(indexFig): | |
60 | plt.figure(indexFig) |
|
60 | plt.figure(indexFig) | |
61 |
|
61 | |||
62 | def refresh(): |
|
62 | def refresh(): | |
63 | plt.draw() |
|
63 | plt.draw() | |
64 |
|
64 | |||
65 | def show(): |
|
65 | def show(): | |
66 | plt.ioff() |
|
66 | plt.ioff() | |
67 | plt.show() |
|
67 | plt.show() | |
68 | plt.ion() |
|
68 | plt.ion() | |
69 |
|
69 | |||
70 | def setPlTitle(pltitle,color, szchar=0.7): |
|
70 | def setPlTitle(pltitle,color, szchar=0.7): | |
71 | pass |
|
71 | pass | |
72 |
|
72 | |||
73 | def setSubpages(ncol,nrow): |
|
73 | def setSubpages(ncol,nrow): | |
74 | pass |
|
74 | pass | |
75 |
|
75 | |||
76 | class BaseGraph: |
|
76 | class BaseGraph: | |
77 |
|
77 | |||
78 | __name = None |
|
78 | __name = None | |
79 | __xpos = None |
|
79 | __xpos = None | |
80 | __ypos = None |
|
80 | __ypos = None | |
81 | __subplot = None |
|
81 | __subplot = None | |
82 | __xg = None |
|
82 | __xg = None | |
83 | __yg = None |
|
83 | __yg = None | |
84 | __axesId = None |
|
84 | __axesId = None | |
85 | xdata = None |
|
85 | xdata = None | |
86 | ydata = None |
|
86 | ydata = None | |
87 | getGrid = True |
|
87 | getGrid = True | |
88 | xaxisIsTime = False |
|
88 | xaxisIsTime = False | |
89 | deltax = None |
|
89 | deltax = None | |
90 | xmin = None |
|
90 | xmin = None | |
91 | xmax = None |
|
91 | xmax = None | |
92 |
|
92 | |||
93 | def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0): |
|
93 | def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0): | |
94 |
|
94 | |||
95 | self.setName(name) |
|
95 | self.setName(name) | |
96 | self.setScreenPos(xpos, ypos) |
|
96 | self.setScreenPos(xpos, ypos) | |
97 | self.setSubPlot(subplot) |
|
97 | self.setSubPlot(subplot) | |
98 | self.setXYZrange(xrange,yrange,zrange) |
|
98 | self.setXYZrange(xrange,yrange,zrange) | |
99 | self.setSizeOfChar(szchar) |
|
99 | self.setSizeOfChar(szchar) | |
100 | self.setLabels(xlabel,ylabel,title) |
|
100 | self.setLabels(xlabel,ylabel,title) | |
101 | self.getGrid = True |
|
101 | self.getGrid = True | |
102 | self.xaxisIsTime = False |
|
102 | self.xaxisIsTime = False | |
103 | self.deltax = deltax |
|
103 | self.deltax = deltax | |
104 | pass |
|
104 | pass | |
105 |
|
105 | |||
106 | def makeAxes(self,indexFig,nrow,ncol,subplot): |
|
106 | def makeAxes(self,indexFig,nrow,ncol,subplot): | |
107 | fig = plt.figure(indexFig) |
|
107 | fig = plt.figure(indexFig) | |
108 | self.__axesId = fig.add_subplot(nrow,ncol,subplot) |
|
108 | self.__axesId = fig.add_subplot(nrow,ncol,subplot) | |
109 |
|
109 | |||
110 | def setParentAxesId(self,parent): |
|
110 | def setParentAxesId(self,parent): | |
111 | self.__axesId = parent.__axesId |
|
111 | self.__axesId = parent.__axesId | |
112 |
|
112 | |||
113 | def setName(self, name): |
|
113 | def setName(self, name): | |
114 | self.__name = name |
|
114 | self.__name = name | |
115 |
|
115 | |||
116 | def setScreenPos(self,xpos,ypos): |
|
116 | def setScreenPos(self,xpos,ypos): | |
117 | self.__xpos = xpos |
|
117 | self.__xpos = xpos | |
118 | self.__ypos = ypos |
|
118 | self.__ypos = ypos | |
119 |
|
119 | |||
120 | def setSubPlot(self,subplot): |
|
120 | def setSubPlot(self,subplot): | |
121 | self.__subplot = subplot |
|
121 | self.__subplot = subplot | |
122 |
|
122 | |||
123 | def setXYZrange(self,xrange,yrange,zrange): |
|
123 | def setXYZrange(self,xrange,yrange,zrange): | |
124 | self.xrange = xrange |
|
124 | self.xrange = xrange | |
125 | self.yrange = yrange |
|
125 | self.yrange = yrange | |
126 | self.zrange = zrange |
|
126 | self.zrange = zrange | |
127 |
|
127 | |||
128 | def setSizeOfChar(self,szchar): |
|
128 | def setSizeOfChar(self,szchar): | |
129 | self.__szchar = szchar |
|
129 | self.__szchar = szchar | |
130 |
|
130 | |||
131 | def setLabels(self,xlabel=None,ylabel=None,title=None): |
|
131 | def setLabels(self,xlabel=None,ylabel=None,title=None): | |
132 | if xlabel != None: self.xlabel = xlabel |
|
132 | if xlabel != None: self.xlabel = xlabel | |
133 | if ylabel != None: self.ylabel = ylabel |
|
133 | if ylabel != None: self.ylabel = ylabel | |
134 | if title != None: self.title = title |
|
134 | if title != None: self.title = title | |
135 |
|
135 | |||
136 | def setXYData(self,xdata=None,ydata=None,datatype='real'): |
|
136 | def setXYData(self,xdata=None,ydata=None,datatype='real'): | |
137 | if ((xdata != None) and (ydata != None)): |
|
137 | if ((xdata != None) and (ydata != None)): | |
138 | self.xdata = xdata |
|
138 | self.xdata = xdata | |
139 | self.ydata = ydata |
|
139 | self.ydata = ydata | |
140 | self.datatype = datatype |
|
140 | self.datatype = datatype | |
141 | if ((self.xdata == None) and (self.ydata == None)): |
|
141 | if ((self.xdata == None) and (self.ydata == None)): | |
142 | return None |
|
142 | return None | |
143 | return 1 |
|
143 | return 1 | |
144 |
|
144 | |||
145 | def setLineStyle(self, style): |
|
145 | def setLineStyle(self, style): | |
146 | pass |
|
146 | pass | |
147 |
|
147 | |||
148 | def setColor(self, color): |
|
148 | def setColor(self, color): | |
149 | pass |
|
149 | pass | |
150 |
|
150 | |||
151 | def setXAxisAsTime(self, value=False): |
|
151 | def setXAxisAsTime(self, value=False): | |
152 | self.xaxisIsTime = value |
|
152 | self.xaxisIsTime = value | |
153 |
|
153 | |||
154 | def basicLineTimePlot(self, x, y, colline=1): |
|
154 | def basicLineTimePlot(self, x, y, colline=1): | |
155 | ax = self.__axesId |
|
155 | ax = self.__axesId | |
156 | if self.setXYData() == None: |
|
156 | if self.setXYData() == None: | |
157 | ax.plot(x,y) |
|
157 | ax.plot(x,y) | |
158 | plt.tight_layout() |
|
158 | plt.tight_layout() | |
159 | else: |
|
159 | else: | |
160 | ax.lines[0].set_data(x,y) |
|
160 | ax.lines[0].set_data(x,y) | |
161 |
|
161 | |||
162 | def basicXYPlot(self, x, y): |
|
162 | def basicXYPlot(self, x, y): | |
163 | ax = self.__axesId |
|
163 | ax = self.__axesId | |
164 | if self.setXYData() == None: |
|
164 | if self.setXYData() == None: | |
165 | ax.plot(x,y) |
|
165 | ax.plot(x,y) | |
166 | else: |
|
166 | else: | |
167 | ax.lines[0].set_data(x,y) |
|
167 | ax.lines[0].set_data(x,y) | |
168 |
|
168 | |||
169 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
169 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
170 | pass |
|
170 | pass | |
171 |
|
171 | |||
172 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
172 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): | |
173 | pass |
|
173 | pass | |
174 |
|
174 | |||
175 | def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True): |
|
175 | def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True): | |
176 | ax = self.__axesId |
|
176 | ax = self.__axesId | |
177 | ax.pcolormesh(x,y,data.T,vmin=zmin,vmax=zmax) |
|
177 | ax.pcolormesh(x,y,data.T,vmin=zmin,vmax=zmax) | |
178 |
|
178 | |||
179 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): |
|
179 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): | |
180 | ax = self.__axesId |
|
180 | ax = self.__axesId | |
181 | cax, kw = mpl.colorbar.make_axes(ax) |
|
181 | cax, kw = mpl.colorbar.make_axes(ax) | |
182 | norm = mpl.colors.Normalize(vmin=ymin, vmax=ymax) |
|
182 | norm = mpl.colors.Normalize(vmin=ymin, vmax=ymax) | |
183 | cb = mpl.colorbar.ColorbarBase(cax,norm=norm,**kw) |
|
183 | cb = mpl.colorbar.ColorbarBase(cax,norm=norm,**kw) | |
184 | self.__colorbarId = cb |
|
184 | self.__colorbarId = cb | |
185 | cb.set_label(self.title) |
|
185 | cb.set_label(self.title) | |
186 |
|
186 | |||
187 | def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False): |
|
187 | def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False): | |
188 | ax = self.__axesId |
|
188 | ax = self.__axesId | |
189 | ax.set_xlim([xmin,xmax]) |
|
189 | ax.set_xlim([xmin,xmax]) | |
190 | ax.set_ylim([ymin,ymax]) |
|
190 | ax.set_ylim([ymin,ymax]) | |
191 |
|
191 | |||
192 | if not(nolabels): |
|
192 | if not(nolabels): | |
193 | ax.set_xlabel(self.xlabel) |
|
193 | ax.set_xlabel(self.xlabel) | |
194 | ax.set_ylabel(self.ylabel) |
|
194 | ax.set_ylabel(self.ylabel) | |
195 | ax.set_title(self.title) |
|
195 | ax.set_title(self.title) | |
196 |
|
196 | |||
197 | def delLabels(self): |
|
197 | def delLabels(self): | |
198 | pass |
|
198 | pass | |
199 |
|
199 | |||
200 | def plotImage(self,x,y,z,xrange,yrange,zrange): |
|
200 | def plotImage(self,x,y,z,xrange,yrange,zrange): | |
201 | pass |
|
201 | pass | |
202 |
|
202 | |||
203 |
|
203 | |||
204 | class LinearPlot(): |
|
204 | class LinearPlot(): | |
205 | linearObjDic = {} |
|
205 | linearObjDic = {} | |
206 | __xpos = None |
|
206 | __xpos = None | |
207 | __ypos = None |
|
207 | __ypos = None | |
208 | isPlotIni = None |
|
208 | isPlotIni = None | |
209 |
|
209 | |||
210 | def __init__(self, indexFig,nsubplot,winTitle): |
|
210 | def __init__(self, indexFig,nsubplot,winTitle): | |
211 | self.width = 700 |
|
211 | self.width = 700 | |
212 |
self.height = |
|
212 | self.height = 800 | |
213 | self.indexFig = indexFig |
|
213 | self.indexFig = indexFig | |
214 | self.ncol = 1 |
|
214 | self.ncol = 1 | |
215 | self.nrow = nsubplot |
|
215 | self.nrow = nsubplot | |
216 | initMatplotlib(indexFig,self.ncol,self.nrow,winTitle,self.width,self.height) |
|
216 | initMatplotlib(indexFig,self.ncol,self.nrow,winTitle,self.width,self.height) | |
217 |
|
217 | |||
218 | self.isPlotIni = False |
|
218 | self.isPlotIni = False | |
219 |
|
219 | |||
220 |
|
220 | |||
221 | def setFigure(self,indexFig): |
|
221 | def setFigure(self,indexFig): | |
222 | setFigure(indexFig) |
|
222 | setFigure(indexFig) | |
223 |
|
223 | |||
224 | def setNewPage(self, pltitle='No title'): |
|
224 | def setNewPage(self, pltitle='No title'): | |
225 | szchar = 0.7 |
|
225 | szchar = 0.7 | |
226 | # setNewPage() |
|
226 | # setNewPage() | |
227 | setPlTitle(pltitle,'black', szchar=szchar) |
|
227 | setPlTitle(pltitle,'black', szchar=szchar) | |
228 | setSubpages(self.ncol, self.nrow) |
|
228 | setSubpages(self.ncol, self.nrow) | |
229 |
|
229 | |||
230 | def setPosition(self): |
|
230 | def setPosition(self): | |
231 | xi = 0.07; xf = 0.9 |
|
231 | xi = 0.07; xf = 0.9 | |
232 | yi = 0.15; yf = 0.8 |
|
232 | yi = 0.15; yf = 0.8 | |
233 |
|
233 | |||
234 | xpos = [xi,xf] |
|
234 | xpos = [xi,xf] | |
235 | ypos = [yi,yf] |
|
235 | ypos = [yi,yf] | |
236 |
|
236 | |||
237 | self.__xpos = xpos |
|
237 | self.__xpos = xpos | |
238 | self.__ypos = ypos |
|
238 | self.__ypos = ypos | |
239 |
|
239 | |||
240 | return xpos,ypos |
|
240 | return xpos,ypos | |
241 |
|
241 | |||
242 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel): |
|
242 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel): | |
243 | szchar = 0.7 |
|
243 | szchar = 0.7 | |
244 | name = 'linear' |
|
244 | name = 'linear' | |
245 | key = name + '%d'%subplot |
|
245 | key = name + '%d'%subplot | |
246 | xrange = [xmin,xmax] |
|
246 | xrange = [xmin,xmax] | |
247 | yrange = [ymin,ymax] |
|
247 | yrange = [ymin,ymax] | |
248 |
|
248 | |||
249 | xpos,ypos = self.setPosition() |
|
249 | xpos,ypos = self.setPosition() | |
250 | linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange) |
|
250 | linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange) | |
251 | self.linearObjDic[key] = linearObj |
|
251 | self.linearObjDic[key] = linearObj | |
252 |
|
252 | |||
253 | def iniPlot(self,subplot): |
|
253 | def iniPlot(self,subplot): | |
254 | name = 'linear' |
|
254 | name = 'linear' | |
255 | key = name + '%d'%subplot |
|
255 | key = name + '%d'%subplot | |
256 |
|
256 | |||
257 | linearObj = self.linearObjDic[key] |
|
257 | linearObj = self.linearObjDic[key] | |
258 | linearObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
258 | linearObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) | |
259 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcnst', 'bcnstv') |
|
259 | linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcnst', 'bcnstv') | |
260 |
|
260 | |||
261 |
|
261 | |||
262 | def plot(self,subplot,x,y,type='abs'): |
|
262 | def plot(self,subplot,x,y,type='abs'): | |
263 | name = 'linear' |
|
263 | name = 'linear' | |
264 | key = name + '%d'%subplot |
|
264 | key = name + '%d'%subplot | |
265 |
|
265 | |||
266 | linearObj = self.linearObjDic[key] |
|
266 | linearObj = self.linearObjDic[key] | |
267 |
|
267 | |||
268 | if type.lower() == 'simple': |
|
268 | if type.lower() == 'simple': | |
269 | colline = 9 |
|
269 | colline = 9 | |
270 | linearObj.basicLineTimePlot(x, y) |
|
270 | linearObj.basicLineTimePlot(x, y) | |
271 | linearObj.setXYData(x,y,'real') |
|
271 | linearObj.setXYData(x,y,'real') | |
272 |
|
272 | |||
273 | def refresh(self): |
|
273 | def refresh(self): | |
274 | refresh() |
|
274 | refresh() | |
275 |
|
275 | |||
276 | def show(self): |
|
276 | def show(self): | |
277 | show() |
|
277 | show() | |
278 |
|
278 | |||
279 | class PcolorPlot: |
|
279 | class PcolorPlot: | |
280 |
|
280 | |||
281 | pcolorObjDic = {} |
|
281 | pcolorObjDic = {} | |
282 | colorbarObjDic = {} |
|
282 | colorbarObjDic = {} | |
283 | pwprofileObjDic = {} |
|
283 | pwprofileObjDic = {} | |
284 | showColorbar = None |
|
284 | showColorbar = None | |
285 | showPowerProfile = None |
|
285 | showPowerProfile = None | |
286 | XAxisAsTime = None |
|
286 | XAxisAsTime = None | |
287 | width = None |
|
287 | width = None | |
288 | height = None |
|
288 | height = None | |
289 | __spcxpos = None |
|
289 | __spcxpos = None | |
290 | __spcypos = None |
|
290 | __spcypos = None | |
291 | __cmapxpos = None |
|
291 | __cmapxpos = None | |
292 | __cmapypos = None |
|
292 | __cmapypos = None | |
293 | __profxpos = None |
|
293 | __profxpos = None | |
294 | __profypos = None |
|
294 | __profypos = None | |
295 | __lastTitle = None |
|
295 | __lastTitle = None | |
296 |
|
296 | |||
297 | def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
297 | def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): | |
298 |
|
298 | |||
299 | self.width = 460 |
|
299 | self.width = 460 | |
300 | self.height = 300 |
|
300 | self.height = 300 | |
301 | self.showColorbar = showColorbar |
|
301 | self.showColorbar = showColorbar | |
302 | self.showPowerProfile = showPowerProfile |
|
302 | self.showPowerProfile = showPowerProfile | |
303 | self.XAxisAsTime = XAxisAsTime |
|
303 | self.XAxisAsTime = XAxisAsTime | |
304 |
|
304 | |||
305 | ncol = int(numpy.sqrt(nsubplot)+0.9) |
|
305 | ncol = int(numpy.sqrt(nsubplot)+0.9) | |
306 | nrow = int(nsubplot*1./ncol + 0.9) |
|
306 | nrow = int(nsubplot*1./ncol + 0.9) | |
307 |
|
307 | |||
308 | self.ncol = ncol |
|
308 | self.ncol = ncol | |
309 | self.nrow = nrow |
|
309 | self.nrow = nrow | |
310 | self.indexFig = indexFig |
|
310 | self.indexFig = indexFig | |
311 |
|
311 | |||
312 | initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height) |
|
312 | initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height) | |
313 | setColormap(colormap) |
|
313 | setColormap(colormap) | |
314 |
|
314 | |||
315 | def setFigure(self,indexFig): |
|
315 | def setFigure(self,indexFig): | |
316 | setFigure(indexFig) |
|
316 | setFigure(indexFig) | |
317 |
|
317 | |||
318 | def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile |
|
318 | def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile | |
319 | if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075 |
|
319 | if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075 | |
320 | else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5 |
|
320 | else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5 | |
321 | yi = 0.15; yf = 0.80 |
|
321 | yi = 0.15; yf = 0.80 | |
322 |
|
322 | |||
323 | xpos = [xi,xf] |
|
323 | xpos = [xi,xf] | |
324 | ypos = [yi,yf] |
|
324 | ypos = [yi,yf] | |
325 |
|
325 | |||
326 | self.__spcxpos = xpos |
|
326 | self.__spcxpos = xpos | |
327 | self.__spcypos = ypos |
|
327 | self.__spcypos = ypos | |
328 |
|
328 | |||
329 | return xpos,ypos |
|
329 | return xpos,ypos | |
330 |
|
330 | |||
331 | def setColorbarScreenPos(self): |
|
331 | def setColorbarScreenPos(self): | |
332 |
|
332 | |||
333 | xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03 |
|
333 | xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03 | |
334 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
334 | yi = self.__spcypos[0]; yf = self.__spcypos[1] | |
335 |
|
335 | |||
336 | xpos = [xi,xf] |
|
336 | xpos = [xi,xf] | |
337 | ypos = [yi,yf] |
|
337 | ypos = [yi,yf] | |
338 |
|
338 | |||
339 | self.__cmapxpos = xpos |
|
339 | self.__cmapxpos = xpos | |
340 | self.__cmapypos = ypos |
|
340 | self.__cmapypos = ypos | |
341 |
|
341 | |||
342 | return xpos,ypos |
|
342 | return xpos,ypos | |
343 |
|
343 | |||
344 | def setPowerprofileScreenPos(self): |
|
344 | def setPowerprofileScreenPos(self): | |
345 |
|
345 | |||
346 | xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25 |
|
346 | xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25 | |
347 | yi = self.__spcypos[0]; yf = self.__spcypos[1] |
|
347 | yi = self.__spcypos[0]; yf = self.__spcypos[1] | |
348 |
|
348 | |||
349 | xpos = [xi,xf] |
|
349 | xpos = [xi,xf] | |
350 | ypos = [yi,yf] |
|
350 | ypos = [yi,yf] | |
351 |
|
351 | |||
352 | self.__profxpos = [xi,xf] |
|
352 | self.__profxpos = [xi,xf] | |
353 | self.__profypos = [yi,yf] |
|
353 | self.__profypos = [yi,yf] | |
354 |
|
354 | |||
355 | return xpos,ypos |
|
355 | return xpos,ypos | |
356 |
|
356 | |||
357 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel): |
|
357 | def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel): | |
358 |
|
358 | |||
359 | ''' |
|
359 | ''' | |
360 | Crea los objetos necesarios para un subplot |
|
360 | Crea los objetos necesarios para un subplot | |
361 | ''' |
|
361 | ''' | |
362 |
|
362 | |||
363 | # Config Spectra plot |
|
363 | # Config Spectra plot | |
364 |
|
364 | |||
365 | szchar = 0.7 |
|
365 | szchar = 0.7 | |
366 | name = 'spc' |
|
366 | name = 'spc' | |
367 | key = name + '%d'%subplot |
|
367 | key = name + '%d'%subplot | |
368 | xrange = [xmin,xmax] |
|
368 | xrange = [xmin,xmax] | |
369 | yrange = [ymin,ymax] |
|
369 | yrange = [ymin,ymax] | |
370 | zrange = [zmin,zmax] |
|
370 | zrange = [zmin,zmax] | |
371 |
|
371 | |||
372 | xpos,ypos = self.setSpectraPos() |
|
372 | xpos,ypos = self.setSpectraPos() | |
373 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange) |
|
373 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange) | |
374 | #pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
374 | #pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) | |
375 | self.pcolorObjDic[key] = pcolorObj |
|
375 | self.pcolorObjDic[key] = pcolorObj | |
376 |
|
376 | |||
377 | # Config Colorbar |
|
377 | # Config Colorbar | |
378 | if self.showColorbar: |
|
378 | if self.showColorbar: | |
379 | szchar = 0.65 |
|
379 | szchar = 0.65 | |
380 | name = 'colorbar' |
|
380 | name = 'colorbar' | |
381 | key = name + '%d'%subplot |
|
381 | key = name + '%d'%subplot | |
382 |
|
382 | |||
383 | xpos,ypos = self.setColorbarScreenPos() |
|
383 | xpos,ypos = self.setColorbarScreenPos() | |
384 | xrange = [0.,1.] |
|
384 | xrange = [0.,1.] | |
385 | yrange = [zmin,zmax] |
|
385 | yrange = [zmin,zmax] | |
386 | cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange) |
|
386 | cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange) | |
387 | self.colorbarObjDic[key] = cmapObj |
|
387 | self.colorbarObjDic[key] = cmapObj | |
388 |
|
388 | |||
389 | # Config Power profile |
|
389 | # Config Power profile | |
390 | if self.showPowerProfile: |
|
390 | if self.showPowerProfile: | |
391 | szchar = 0.55 |
|
391 | szchar = 0.55 | |
392 | name = 'pwprofile' |
|
392 | name = 'pwprofile' | |
393 | key = name + '%d'%subplot |
|
393 | key = name + '%d'%subplot | |
394 |
|
394 | |||
395 | xpos,ypos = self.setPowerprofileScreenPos() |
|
395 | xpos,ypos = self.setPowerprofileScreenPos() | |
396 | xrange = [zmin,zmax] |
|
396 | xrange = [zmin,zmax] | |
397 | yrange = [ymin,ymax] |
|
397 | yrange = [ymin,ymax] | |
398 | powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange) |
|
398 | powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange) | |
399 | #powObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
399 | #powObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) | |
400 | self.pwprofileObjDic[key] = powObj |
|
400 | self.pwprofileObjDic[key] = powObj | |
401 |
|
401 | |||
402 | def setNewPage(self, pltitle='No title'): |
|
402 | def setNewPage(self, pltitle='No title'): | |
403 | szchar = 0.7 |
|
403 | szchar = 0.7 | |
404 | setNewPage() |
|
404 | setNewPage() | |
405 | setPlTitle(pltitle,'black', szchar=szchar) |
|
405 | setPlTitle(pltitle,'black', szchar=szchar) | |
406 | setSubpages(self.ncol, self.nrow) |
|
406 | setSubpages(self.ncol, self.nrow) | |
407 |
|
407 | |||
408 | def closePage(self): |
|
408 | def closePage(self): | |
409 | closePage() |
|
409 | closePage() | |
410 |
|
410 | |||
411 | def show(self): |
|
411 | def show(self): | |
412 | show() |
|
412 | show() | |
413 |
|
413 | |||
414 | def iniPlot(self,subplot): |
|
414 | def iniPlot(self,subplot): | |
415 | ''' |
|
415 | ''' | |
416 | Inicializa los subplots con su frame, titulo, etc |
|
416 | Inicializa los subplots con su frame, titulo, etc | |
417 | ''' |
|
417 | ''' | |
418 |
|
418 | |||
419 | # Config Spectra plot |
|
419 | # Config Spectra plot | |
420 | name = 'spc' |
|
420 | name = 'spc' | |
421 | key = name + '%d'%subplot |
|
421 | key = name + '%d'%subplot | |
422 |
|
422 | |||
423 | pcolorObj = self.pcolorObjDic[key] |
|
423 | pcolorObj = self.pcolorObjDic[key] | |
424 | pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) |
|
424 | pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot) | |
425 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcnst', 'bcnstv') |
|
425 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcnst', 'bcnstv') | |
426 |
|
426 | |||
427 | # Config Colorbar |
|
427 | # Config Colorbar | |
428 | if self.showColorbar: |
|
428 | if self.showColorbar: | |
429 | name = 'colorbar' |
|
429 | name = 'colorbar' | |
430 | key = name + '%d'%subplot |
|
430 | key = name + '%d'%subplot | |
431 |
|
431 | |||
432 | cmapObj = self.colorbarObjDic[key] |
|
432 | cmapObj = self.colorbarObjDic[key] | |
433 | cmapObj.setParentAxesId(pcolorObj) |
|
433 | cmapObj.setParentAxesId(pcolorObj) | |
434 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') |
|
434 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') | |
435 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
435 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) | |
436 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') |
|
436 | # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') | |
437 |
|
437 | |||
438 | # Config Power profile |
|
438 | # Config Power profile | |
439 | if self.showPowerProfile: |
|
439 | if self.showPowerProfile: | |
440 | name = 'pwprofile' |
|
440 | name = 'pwprofile' | |
441 | key = name + '%d'%subplot |
|
441 | key = name + '%d'%subplot | |
442 |
|
442 | |||
443 | powObj = self.pwprofileObjDic[key] |
|
443 | powObj = self.pwprofileObjDic[key] | |
444 | powObj.setLineStyle(2) |
|
444 | powObj.setLineStyle(2) | |
445 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
445 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') | |
446 | powObj.setLineStyle(1) |
|
446 | powObj.setLineStyle(1) | |
447 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
447 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') | |
448 |
|
448 | |||
449 | def printTitle(self,pltitle): |
|
449 | def printTitle(self,pltitle): | |
450 |
|
450 | |||
451 | setPlTitle(pltitle,'black') |
|
451 | setPlTitle(pltitle,'black') | |
452 |
|
452 | |||
453 | def plot(self,subplot,x,y,z,subtitle=''): |
|
453 | def plot(self,subplot,x,y,z,subtitle=''): | |
454 | # Spectra plot |
|
454 | # Spectra plot | |
455 |
|
455 | |||
456 | name = 'spc' |
|
456 | name = 'spc' | |
457 | key = name + '%d'%subplot |
|
457 | key = name + '%d'%subplot | |
458 |
|
458 | |||
459 | # newx = [x[0],x[-1]] |
|
459 | # newx = [x[0],x[-1]] | |
460 | pcolorObj = self.pcolorObjDic[key] |
|
460 | pcolorObj = self.pcolorObjDic[key] | |
461 | # pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst') |
|
461 | # pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst') | |
462 |
|
462 | |||
463 | #pcolorObj.delLabels() |
|
463 | #pcolorObj.delLabels() | |
464 | pcolorObj.setLabels(title=subtitle) |
|
464 | pcolorObj.setLabels(title=subtitle) | |
465 |
|
465 | |||
466 | deltax = None; deltay = None |
|
466 | deltax = None; deltay = None | |
467 |
|
467 | |||
468 | pcolorObj.advPcolorPlot(z, |
|
468 | pcolorObj.advPcolorPlot(z, | |
469 | x, |
|
469 | x, | |
470 | y, |
|
470 | y, | |
471 | xmin=pcolorObj.xrange[0], |
|
471 | xmin=pcolorObj.xrange[0], | |
472 | xmax=pcolorObj.xrange[1], |
|
472 | xmax=pcolorObj.xrange[1], | |
473 | ymin=pcolorObj.yrange[0], |
|
473 | ymin=pcolorObj.yrange[0], | |
474 | ymax=pcolorObj.yrange[1], |
|
474 | ymax=pcolorObj.yrange[1], | |
475 | zmin=pcolorObj.zrange[0], |
|
475 | zmin=pcolorObj.zrange[0], | |
476 | zmax=pcolorObj.zrange[1], |
|
476 | zmax=pcolorObj.zrange[1], | |
477 | deltax=deltax, |
|
477 | deltax=deltax, | |
478 | deltay=deltay, |
|
478 | deltay=deltay, | |
479 | getGrid=pcolorObj.getGrid) |
|
479 | getGrid=pcolorObj.getGrid) | |
480 |
|
480 | |||
481 | #Solo se calcula la primera vez que se ingresa a la funcion |
|
481 | #Solo se calcula la primera vez que se ingresa a la funcion | |
482 | pcolorObj.getGrid = False |
|
482 | pcolorObj.getGrid = False | |
483 |
|
483 | |||
484 | #pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst', nolabels=True) |
|
484 | #pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst', nolabels=True) | |
485 |
|
485 | |||
486 | # Power Profile |
|
486 | # Power Profile | |
487 | if self.showPowerProfile: |
|
487 | if self.showPowerProfile: | |
488 | power = numpy.average(z, axis=0) |
|
488 | power = numpy.average(z, axis=0) | |
489 | name = 'pwprofile' |
|
489 | name = 'pwprofile' | |
490 | key = name + '%d'%subplot |
|
490 | key = name + '%d'%subplot | |
491 | powObj = self.pwprofileObjDic[key] |
|
491 | powObj = self.pwprofileObjDic[key] | |
492 |
|
492 | |||
493 | if powObj.setXYData() != None: |
|
493 | if powObj.setXYData() != None: | |
494 | #clearData(powObj) |
|
494 | #clearData(powObj) | |
495 | powObj.setLineStyle(2) |
|
495 | powObj.setLineStyle(2) | |
496 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
496 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') | |
497 | powObj.setLineStyle(1) |
|
497 | powObj.setLineStyle(1) | |
498 | else: |
|
498 | else: | |
499 | powObj.setXYData(power,y) |
|
499 | powObj.setXYData(power,y) | |
500 |
|
500 | |||
501 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
501 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') | |
502 | powObj.basicXYPlot(power,y) |
|
502 | powObj.basicXYPlot(power,y) | |
503 | powObj.setXYData(power,y) |
|
503 | powObj.setXYData(power,y) | |
504 |
|
504 | |||
505 | def savePlot(self,indexFig,filename): |
|
505 | def savePlot(self,indexFig,filename): | |
506 |
|
506 | |||
507 | width = self.width*self.ncol |
|
507 | width = self.width*self.ncol | |
508 | hei = self.height*self.nrow |
|
508 | hei = self.height*self.nrow | |
509 | savePlplot(filename,width,hei) |
|
509 | savePlplot(filename,width,hei) | |
510 |
|
510 | |||
511 | def refresh(self): |
|
511 | def refresh(self): | |
512 | refresh() |
|
512 | refresh() | |
513 |
|
513 | |||
514 | class RtiPlot: |
|
514 | class RtiPlot: | |
515 |
|
515 | |||
516 | pcolorObjDic = {} |
|
516 | pcolorObjDic = {} | |
517 | colorbarObjDic = {} |
|
517 | colorbarObjDic = {} | |
518 | pwprofileObjDic = {} |
|
518 | pwprofileObjDic = {} | |
519 | showColorbar = None |
|
519 | showColorbar = None | |
520 | showPowerProfile = None |
|
520 | showPowerProfile = None | |
521 | XAxisAsTime = None |
|
521 | XAxisAsTime = None | |
522 | widht = None |
|
522 | widht = None | |
523 | height = None |
|
523 | height = None | |
524 | __rtixpos = None |
|
524 | __rtixpos = None | |
525 | __rtiypos = None |
|
525 | __rtiypos = None | |
526 | __cmapxpos = None |
|
526 | __cmapxpos = None | |
527 | __cmapypos = None |
|
527 | __cmapypos = None | |
528 | __profxpos = None |
|
528 | __profxpos = None | |
529 | __profypos = None |
|
529 | __profypos = None | |
530 |
|
530 | |||
531 | def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): |
|
531 | def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime): | |
532 | self.width = 700 |
|
532 | self.width = 700 | |
533 | self.height = 150 |
|
533 | self.height = 150 | |
534 | self.showColorbar = showColorbar |
|
534 | self.showColorbar = showColorbar | |
535 | self.showPowerProfile = showPowerProfile |
|
535 | self.showPowerProfile = showPowerProfile | |
536 | self.XAxisAsTime = XAxisAsTime |
|
536 | self.XAxisAsTime = XAxisAsTime | |
537 |
|
537 | |||
538 | ncol = 1 |
|
538 | ncol = 1 | |
539 | nrow = nsubplot |
|
539 | nrow = nsubplot | |
540 | initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height) |
|
540 | initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height) | |
541 | setColormap(colormap) |
|
541 | setColormap(colormap) | |
542 | self.ncol = ncol |
|
542 | self.ncol = ncol | |
543 | self.nrow = nrow |
|
543 | self.nrow = nrow | |
544 |
|
544 | |||
545 | def setFigure(self,indexFig): |
|
545 | def setFigure(self,indexFig): | |
546 | setFigure(indexFig) |
|
546 | setFigure(indexFig) | |
547 |
|
547 | |||
548 | def setRtiScreenPos(self): |
|
548 | def setRtiScreenPos(self): | |
549 |
|
549 | |||
550 | if self.showPowerProfile: xi = 0.07; xf = 0.65 |
|
550 | if self.showPowerProfile: xi = 0.07; xf = 0.65 | |
551 | else: xi = 0.07; xf = 0.9 |
|
551 | else: xi = 0.07; xf = 0.9 | |
552 | yi = 0.15; yf = 0.80 |
|
552 | yi = 0.15; yf = 0.80 | |
553 |
|
553 | |||
554 | xpos = [xi,xf] |
|
554 | xpos = [xi,xf] | |
555 | ypos = [yi,yf] |
|
555 | ypos = [yi,yf] | |
556 |
|
556 | |||
557 | self.__rtixpos = xpos |
|
557 | self.__rtixpos = xpos | |
558 | self.__rtiypos = ypos |
|
558 | self.__rtiypos = ypos | |
559 |
|
559 | |||
560 | return xpos,ypos |
|
560 | return xpos,ypos | |
561 |
|
561 | |||
562 | def setColorbarScreenPos(self): |
|
562 | def setColorbarScreenPos(self): | |
563 |
|
563 | |||
564 | xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03 |
|
564 | xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03 | |
565 |
|
565 | |||
566 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
566 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] | |
567 |
|
567 | |||
568 | xpos = [xi,xf] |
|
568 | xpos = [xi,xf] | |
569 | ypos = [yi,yf] |
|
569 | ypos = [yi,yf] | |
570 |
|
570 | |||
571 | self.__cmapxpos = xpos |
|
571 | self.__cmapxpos = xpos | |
572 | self.__cmapypos = ypos |
|
572 | self.__cmapypos = ypos | |
573 |
|
573 | |||
574 | return xpos,ypos |
|
574 | return xpos,ypos | |
575 |
|
575 | |||
576 | def setPowerprofileScreenPos(self): |
|
576 | def setPowerprofileScreenPos(self): | |
577 |
|
577 | |||
578 | xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20 |
|
578 | xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20 | |
579 |
|
579 | |||
580 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] |
|
580 | yi = self.__rtiypos[0]; yf = self.__rtiypos[1] | |
581 |
|
581 | |||
582 | xpos = [xi,xf] |
|
582 | xpos = [xi,xf] | |
583 | ypos = [yi,yf] |
|
583 | ypos = [yi,yf] | |
584 |
|
584 | |||
585 | self.__profxpos = [xi,xf] |
|
585 | self.__profxpos = [xi,xf] | |
586 | self.__profypos = [yi,yf] |
|
586 | self.__profypos = [yi,yf] | |
587 |
|
587 | |||
588 | return xpos,ypos |
|
588 | return xpos,ypos | |
589 |
|
589 | |||
590 | def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone='lt',npoints=100): |
|
590 | def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone='lt',npoints=100): | |
591 | # Config Rti plot |
|
591 | # Config Rti plot | |
592 | szchar = 1.10 |
|
592 | szchar = 1.10 | |
593 | name = 'rti' |
|
593 | name = 'rti' | |
594 | key = name + '%d'%subplot |
|
594 | key = name + '%d'%subplot | |
595 |
|
595 | |||
596 | # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal] |
|
596 | # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal] | |
597 | thisDateTime = datetime.datetime.fromtimestamp(timedata) |
|
597 | thisDateTime = datetime.datetime.fromtimestamp(timedata) | |
598 | startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0) |
|
598 | startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0) | |
599 | endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59) |
|
599 | endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59) | |
600 | deltaTime = 0 |
|
600 | deltaTime = 0 | |
601 | if timezone == 'lt': |
|
601 | if timezone == 'lt': | |
602 | deltaTime = time.timezone |
|
602 | deltaTime = time.timezone | |
603 | startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime |
|
603 | startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime | |
604 | endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime |
|
604 | endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime | |
605 |
|
605 | |||
606 | xrange = [startTimeInSecs,endTimeInSecs] |
|
606 | xrange = [startTimeInSecs,endTimeInSecs] | |
607 | totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1. |
|
607 | totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1. | |
608 | deltax = totalTimeInXrange / npoints |
|
608 | deltax = totalTimeInXrange / npoints | |
609 |
|
609 | |||
610 | yrange = [ymin,ymax] |
|
610 | yrange = [ymin,ymax] | |
611 | zrange = [zmin,zmax] |
|
611 | zrange = [zmin,zmax] | |
612 |
|
612 | |||
613 | xpos,ypos = self.setRtiScreenPos() |
|
613 | xpos,ypos = self.setRtiScreenPos() | |
614 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax) |
|
614 | pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax) | |
615 | if self.XAxisAsTime: |
|
615 | if self.XAxisAsTime: | |
616 | pcolorObj.setXAxisAsTime(self.XAxisAsTime) |
|
616 | pcolorObj.setXAxisAsTime(self.XAxisAsTime) | |
617 | xopt = 'bcnstd' |
|
617 | xopt = 'bcnstd' | |
618 | yopt = 'bcnstv' |
|
618 | yopt = 'bcnstv' | |
619 | else: |
|
619 | else: | |
620 | xopt = 'bcnst' |
|
620 | xopt = 'bcnst' | |
621 | yopt = 'bcnstv' |
|
621 | yopt = 'bcnstv' | |
622 |
|
622 | |||
623 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
623 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) | |
624 | self.pcolorObjDic[key] = pcolorObj |
|
624 | self.pcolorObjDic[key] = pcolorObj | |
625 |
|
625 | |||
626 |
|
626 | |||
627 | # Config Colorbar |
|
627 | # Config Colorbar | |
628 | if self.showColorbar: |
|
628 | if self.showColorbar: | |
629 | szchar = 0.9 |
|
629 | szchar = 0.9 | |
630 | name = 'colorbar' |
|
630 | name = 'colorbar' | |
631 | key = name + '%d'%subplot |
|
631 | key = name + '%d'%subplot | |
632 |
|
632 | |||
633 | xpos,ypos = self.setColorbarScreenPos() |
|
633 | xpos,ypos = self.setColorbarScreenPos() | |
634 | xrange = [0.,1.] |
|
634 | xrange = [0.,1.] | |
635 | yrange = [zmin,zmax] |
|
635 | yrange = [zmin,zmax] | |
636 | cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange) |
|
636 | cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange) | |
637 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcm') |
|
637 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcm') | |
638 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) |
|
638 | cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1]) | |
639 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') |
|
639 | cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv') | |
640 | self.colorbarObjDic[key] = cmapObj |
|
640 | self.colorbarObjDic[key] = cmapObj | |
641 |
|
641 | |||
642 |
|
642 | |||
643 | # Config Power profile |
|
643 | # Config Power profile | |
644 | if self.showPowerProfile: |
|
644 | if self.showPowerProfile: | |
645 | szchar = 0.8 |
|
645 | szchar = 0.8 | |
646 | name = 'pwprofile' |
|
646 | name = 'pwprofile' | |
647 | key = name + '%d'%subplot |
|
647 | key = name + '%d'%subplot | |
648 |
|
648 | |||
649 | xpos,ypos = self.setPowerprofileScreenPos() |
|
649 | xpos,ypos = self.setPowerprofileScreenPos() | |
650 | xrange = [zmin,zmax] |
|
650 | xrange = [zmin,zmax] | |
651 | yrange = [ymin,ymax] |
|
651 | yrange = [ymin,ymax] | |
652 | powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange) |
|
652 | powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange) | |
653 | powObj.setLineStyle(2) |
|
653 | powObj.setLineStyle(2) | |
654 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
654 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') | |
655 | powObj.setLineStyle(1) |
|
655 | powObj.setLineStyle(1) | |
656 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
656 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') | |
657 | self.pwprofileObjDic[key] = powObj |
|
657 | self.pwprofileObjDic[key] = powObj | |
658 |
|
658 | |||
659 |
|
659 | |||
660 | def plot(self,subplot,x,y,z): |
|
660 | def plot(self,subplot,x,y,z): | |
661 | # RTI plot |
|
661 | # RTI plot | |
662 | name = 'rti' |
|
662 | name = 'rti' | |
663 | key = name + '%d'%subplot |
|
663 | key = name + '%d'%subplot | |
664 |
|
664 | |||
665 | data = numpy.reshape(z, (1,-1)) |
|
665 | data = numpy.reshape(z, (1,-1)) | |
666 | data = numpy.abs(data) |
|
666 | data = numpy.abs(data) | |
667 | data = 10*numpy.log10(data) |
|
667 | data = 10*numpy.log10(data) | |
668 | newx = [x,x+1] |
|
668 | newx = [x,x+1] | |
669 |
|
669 | |||
670 | pcolorObj = self.pcolorObjDic[key] |
|
670 | pcolorObj = self.pcolorObjDic[key] | |
671 |
|
671 | |||
672 | if pcolorObj.xaxisIsTime: |
|
672 | if pcolorObj.xaxisIsTime: | |
673 | xopt = 'bcstd' |
|
673 | xopt = 'bcstd' | |
674 | yopt = 'bcst' |
|
674 | yopt = 'bcst' | |
675 | else: |
|
675 | else: | |
676 | xopt = 'bcst' |
|
676 | xopt = 'bcst' | |
677 | yopt = 'bcst' |
|
677 | yopt = 'bcst' | |
678 |
|
678 | |||
679 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) |
|
679 | pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt) | |
680 |
|
680 | |||
681 | deltax = pcolorObj.deltax |
|
681 | deltax = pcolorObj.deltax | |
682 | deltay = None |
|
682 | deltay = None | |
683 |
|
683 | |||
684 | if pcolorObj.xmin == None and pcolorObj.xmax == None: |
|
684 | if pcolorObj.xmin == None and pcolorObj.xmax == None: | |
685 | pcolorObj.xmin = x |
|
685 | pcolorObj.xmin = x | |
686 | pcolorObj.xmax = x |
|
686 | pcolorObj.xmax = x | |
687 |
|
687 | |||
688 | if x >= pcolorObj.xmax: |
|
688 | if x >= pcolorObj.xmax: | |
689 | xmin = x |
|
689 | xmin = x | |
690 | xmax = x + deltax |
|
690 | xmax = x + deltax | |
691 | x = [x] |
|
691 | x = [x] | |
692 | pcolorObj.advPcolorPlot(data, |
|
692 | pcolorObj.advPcolorPlot(data, | |
693 | x, |
|
693 | x, | |
694 | y, |
|
694 | y, | |
695 | xmin=xmin, |
|
695 | xmin=xmin, | |
696 | xmax=xmax, |
|
696 | xmax=xmax, | |
697 | ymin=pcolorObj.yrange[0], |
|
697 | ymin=pcolorObj.yrange[0], | |
698 | ymax=pcolorObj.yrange[1], |
|
698 | ymax=pcolorObj.yrange[1], | |
699 | zmin=pcolorObj.zrange[0], |
|
699 | zmin=pcolorObj.zrange[0], | |
700 | zmax=pcolorObj.zrange[1], |
|
700 | zmax=pcolorObj.zrange[1], | |
701 | deltax=deltax, |
|
701 | deltax=deltax, | |
702 | deltay=deltay, |
|
702 | deltay=deltay, | |
703 | getGrid=pcolorObj.getGrid) |
|
703 | getGrid=pcolorObj.getGrid) | |
704 |
|
704 | |||
705 | pcolorObj.xmin = xmin |
|
705 | pcolorObj.xmin = xmin | |
706 | pcolorObj.xmax = xmax |
|
706 | pcolorObj.xmax = xmax | |
707 |
|
707 | |||
708 |
|
708 | |||
709 | # Power Profile |
|
709 | # Power Profile | |
710 | if self.showPowerProfile: |
|
710 | if self.showPowerProfile: | |
711 | data = numpy.reshape(data,(numpy.size(data))) |
|
711 | data = numpy.reshape(data,(numpy.size(data))) | |
712 | name = 'pwprofile' |
|
712 | name = 'pwprofile' | |
713 | key = name + '%d'%subplot |
|
713 | key = name + '%d'%subplot | |
714 | powObj = self.pwprofileObjDic[key] |
|
714 | powObj = self.pwprofileObjDic[key] | |
715 |
|
715 | |||
716 | if powObj.setXYData() != None: |
|
716 | if powObj.setXYData() != None: | |
717 | clearData(powObj) |
|
717 | clearData(powObj) | |
718 | powObj.setLineStyle(2) |
|
718 | powObj.setLineStyle(2) | |
719 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') |
|
719 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc') | |
720 | powObj.setLineStyle(1) |
|
720 | powObj.setLineStyle(1) | |
721 | else: |
|
721 | else: | |
722 | powObj.setXYData(data,y) |
|
722 | powObj.setXYData(data,y) | |
723 |
|
723 | |||
724 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') |
|
724 | powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc') | |
725 | powObj.basicXYPlot(data,y) |
|
725 | powObj.basicXYPlot(data,y) | |
726 | powObj.setXYData(data,y) |
|
726 | powObj.setXYData(data,y) | |
727 |
|
727 | |||
728 | def savePlot(self,indexFig,filename): |
|
728 | def savePlot(self,indexFig,filename): | |
729 |
|
729 | |||
730 | width = self.width*self.ncol |
|
730 | width = self.width*self.ncol | |
731 | hei = self.height*self.nrow |
|
731 | hei = self.height*self.nrow | |
732 | savePlplot(filename,width,hei) |
|
732 | savePlplot(filename,width,hei) | |
733 |
|
733 | |||
734 | def refresh(self): |
|
734 | def refresh(self): | |
735 | refresh() |
|
735 | refresh() | |
736 |
|
736 | |||
737 |
|
737 | |||
738 | if __name__ == '__main__': |
|
738 | if __name__ == '__main__': | |
739 |
|
739 | |||
740 | """ |
|
740 | """ | |
741 | Ejemplo1 |
|
741 | Ejemplo1 | |
742 | """ |
|
742 | """ | |
743 | #Setting the signal |
|
743 | #Setting the signal | |
744 | fs = 8000 |
|
744 | fs = 8000 | |
745 | f0 = 200 |
|
745 | f0 = 200 | |
746 | f1 = 400 |
|
746 | f1 = 400 | |
747 | T = 1./fs |
|
747 | T = 1./fs | |
748 | x = numpy.arange(160) |
|
748 | x = numpy.arange(160) | |
749 | y1 = numpy.sin(2*numpy.pi*f0*x*T) |
|
749 | y1 = numpy.sin(2*numpy.pi*f0*x*T) | |
750 | y2 = numpy.sin(2*numpy.pi*f1*x*T) |
|
750 | y2 = numpy.sin(2*numpy.pi*f1*x*T) | |
751 | signalList = [y1,y2] |
|
751 | signalList = [y1,y2] | |
752 |
|
752 | |||
753 | xmin = numpy.min(x) |
|
753 | xmin = numpy.min(x) | |
754 | xmax = numpy.max(x) |
|
754 | xmax = numpy.max(x) | |
755 | ymin = numpy.min(y1) - 10 |
|
755 | ymin = numpy.min(y1) - 10 | |
756 | ymax = numpy.max(y1) + 10 |
|
756 | ymax = numpy.max(y1) + 10 | |
757 |
|
757 | |||
758 | subplotTitle = "subplot no. " |
|
758 | subplotTitle = "subplot no. " | |
759 | xlabel = "" |
|
759 | xlabel = "" | |
760 | ylabel = "" |
|
760 | ylabel = "" | |
761 |
|
761 | |||
762 | indexFig = 1 |
|
762 | indexFig = 1 | |
763 |
nsubplot = |
|
763 | nsubplot = 6 | |
764 | winTitle = "figura" |
|
764 | winTitle = "figura" | |
765 |
|
765 | |||
766 | isPlotIni = False |
|
766 | isPlotIni = False | |
767 | isPlotConfig = False |
|
767 | isPlotConfig = False | |
768 | ntimes = 10 |
|
768 | ntimes = 100 | |
769 |
|
769 | |||
770 |
|
770 | |||
771 | # Instancia del objeto |
|
771 | # Instancia del objeto | |
772 | linearObj = LinearPlot(indexFig,nsubplot,winTitle) |
|
772 | linearObj = LinearPlot(indexFig,nsubplot,winTitle) | |
773 |
|
773 | |||
774 |
|
774 | |||
775 | for i in range(ntimes): |
|
775 | for i in range(ntimes): | |
776 | # Crea los subplots |
|
776 | # Crea los subplots | |
777 | if not(linearObj.isPlotIni): |
|
777 | if not(linearObj.isPlotIni): | |
778 | for index in range(nsubplot): |
|
778 | for index in range(nsubplot): | |
779 | indexplot = index + 1 |
|
779 | indexplot = index + 1 | |
780 | title = subplotTitle + '%d'%indexplot |
|
780 | title = subplotTitle + '%d'%indexplot | |
781 | linearObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel) |
|
781 | linearObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel) | |
782 | linearObj.isPlotIni = True |
|
782 | linearObj.isPlotIni = True | |
783 |
|
783 | |||
784 | # Inicializa el grafico en cada iteracion |
|
784 | # Inicializa el grafico en cada iteracion | |
785 | linearObj.setFigure(indexFig) |
|
785 | linearObj.setFigure(indexFig) | |
786 | linearObj.setNewPage("") |
|
786 | linearObj.setNewPage("") | |
787 |
|
787 | |||
788 | for index in range(nsubplot): |
|
788 | for index in range(nsubplot): | |
789 | subplot = index |
|
789 | subplot = index | |
790 | linearObj.iniPlot(subplot+1) |
|
790 | linearObj.iniPlot(subplot+1) | |
791 |
|
791 | |||
792 | #plotea los datos |
|
792 | #plotea los datos | |
793 | for channel in range(nsubplot): |
|
793 | for channel in range(nsubplot): | |
794 | data = y1 + numpy.random.rand(len(y1)) |
|
794 | data = y1 + numpy.random.rand(len(y1)) | |
795 | linearObj.plot(channel+1, x, data, type='simple') |
|
795 | linearObj.plot(channel+1, x, data, type='simple') | |
796 |
|
796 | |||
797 | linearObj.refresh() |
|
797 | linearObj.refresh() | |
798 |
|
798 | |||
799 | # linearObj.closePage() #descomentar esta linea para mas iteraciones |
|
799 | # linearObj.closePage() #descomentar esta linea para mas iteraciones | |
800 |
|
800 | |||
801 | time.sleep(0.05) |
|
801 | time.sleep(0.05) | |
802 |
|
802 | |||
803 | linearObj.show() |
|
803 | linearObj.show() | |
804 |
|
804 | |||
805 | print "example 1 completed" |
|
805 | print "example 1 completed" | |
806 |
|
806 | |||
807 |
|
807 | |||
808 |
|
808 | |||
809 | """ |
|
809 | """ | |
810 | Ejemplo2 |
|
810 | Ejemplo2 | |
811 | """ |
|
811 | """ | |
812 |
|
812 | |||
813 | # make these smaller to increase the resolution |
|
813 | # make these smaller to increase the resolution | |
814 | dx, dy = 0.05, 0.05 |
|
814 | dx, dy = 0.05, 0.05 | |
815 | x = numpy.arange(-3.0, 3.0001, dx) |
|
815 | x = numpy.arange(-3.0, 3.0001, dx) | |
816 | y = numpy.arange(-2.0, 2.0001, dy) |
|
816 | y = numpy.arange(-2.0, 2.0001, dy) | |
817 | # X,Y = numpy.meshgrid(x, y) |
|
817 | # X,Y = numpy.meshgrid(x, y) | |
818 | X,Y = sn.ndgrid(x, y) |
|
818 | X,Y = sn.ndgrid(x, y) | |
819 | Z = (1- X/2 + X**5 + Y**3)*numpy.exp(-X**2-Y**2) |
|
819 | Z = (1- X/2 + X**5 + Y**3)*numpy.exp(-X**2-Y**2) | |
820 |
|
820 | |||
821 | # Creating Object |
|
821 | # Creating Object | |
822 | indexPlot = 2 |
|
822 | indexPlot = 2 | |
823 | nsubplot = 1 |
|
823 | nsubplot = 1 | |
824 | winTitle = "mi grafico pcolor" |
|
824 | winTitle = "mi grafico pcolor" | |
825 | colormap = "br_green" |
|
825 | colormap = "br_green" | |
826 | showColorbar = True |
|
826 | showColorbar = True | |
827 | showPowerProfile = False |
|
827 | showPowerProfile = False | |
828 | XAxisAsTime = False |
|
828 | XAxisAsTime = False | |
829 |
|
829 | |||
830 | subplotTitle = "subplot no. " |
|
830 | subplotTitle = "subplot no. " | |
831 | xlabel = "" |
|
831 | xlabel = "" | |
832 | ylabel = "" |
|
832 | ylabel = "" | |
833 |
|
833 | |||
834 | xmin = -3.0 |
|
834 | xmin = -3.0 | |
835 | xmax = 3.0 |
|
835 | xmax = 3.0 | |
836 | ymin = -2.0 |
|
836 | ymin = -2.0 | |
837 | ymax = 2.0 |
|
837 | ymax = 2.0 | |
838 | zmin = -0.3 |
|
838 | zmin = -0.3 | |
839 | zmax = 1.0 |
|
839 | zmax = 1.0 | |
840 |
|
840 | |||
841 | isPlotIni = False |
|
841 | isPlotIni = False | |
842 | isPlotConfig = False |
|
842 | isPlotConfig = False | |
843 | ntimes = 10 |
|
843 | ntimes = 10 | |
844 |
|
844 | |||
845 |
|
845 | |||
846 | for i in range(ntimes): |
|
846 | for i in range(ntimes): | |
847 |
|
847 | |||
848 | # Instancia del objeto |
|
848 | # Instancia del objeto | |
849 | if not(isPlotConfig): |
|
849 | if not(isPlotConfig): | |
850 | pcolorObj = PcolorPlot(indexPlot, nsubplot, winTitle, colormap, showColorbar, showPowerProfile, XAxisAsTime) |
|
850 | pcolorObj = PcolorPlot(indexPlot, nsubplot, winTitle, colormap, showColorbar, showPowerProfile, XAxisAsTime) | |
851 | isPlotConfig = True |
|
851 | isPlotConfig = True | |
852 |
|
852 | |||
853 | # Crea los subplots |
|
853 | # Crea los subplots | |
854 | if not(isPlotIni): |
|
854 | if not(isPlotIni): | |
855 | for index in range(nsubplot): |
|
855 | for index in range(nsubplot): | |
856 | indexplot = index + 1 |
|
856 | indexplot = index + 1 | |
857 | title = subplotTitle + '%d'%indexplot |
|
857 | title = subplotTitle + '%d'%indexplot | |
858 | subplot = index |
|
858 | subplot = index | |
859 | pcolorObj.createObjects(indexplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel) |
|
859 | pcolorObj.createObjects(indexplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel) | |
860 | isPlotIni = True |
|
860 | isPlotIni = True | |
861 |
|
861 | |||
862 | # Inicializa el grafico en cada iteracion |
|
862 | # Inicializa el grafico en cada iteracion | |
863 | pcolorObj.setFigure(indexPlot) |
|
863 | pcolorObj.setFigure(indexPlot) | |
864 | pcolorObj.setNewPage("") |
|
864 | pcolorObj.setNewPage("") | |
865 |
|
865 | |||
866 | for index in range(nsubplot): |
|
866 | for index in range(nsubplot): | |
867 | subplot = index |
|
867 | subplot = index | |
868 | pcolorObj.iniPlot(subplot+1) |
|
868 | pcolorObj.iniPlot(subplot+1) | |
869 |
|
869 | |||
870 | #plotea los datos |
|
870 | #plotea los datos | |
871 | for channel in range(nsubplot): |
|
871 | for channel in range(nsubplot): | |
872 | data = Z+0.1*numpy.random.randn(len(x),len(y)) |
|
872 | data = Z+0.1*numpy.random.randn(len(x),len(y)) | |
873 | pcolorObj.plot(channel+1, x, y, data) |
|
873 | pcolorObj.plot(channel+1, x, y, data) | |
874 |
|
874 | |||
875 | pcolorObj.refresh() |
|
875 | pcolorObj.refresh() | |
876 |
|
876 | |||
877 | # pcolorObj.closePage() #descomentar esta linea para mas iteraciones |
|
877 | # pcolorObj.closePage() #descomentar esta linea para mas iteraciones | |
878 |
|
878 | |||
879 | time.sleep(1) |
|
879 | time.sleep(1) | |
880 |
|
880 | |||
881 | pcolorObj.show() |
|
881 | pcolorObj.show() | |
882 |
|
882 | |||
883 | print "example 2 completed" No newline at end of file |
|
883 | print "example 2 completed" |
@@ -1,1047 +1,1049 | |||||
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 | def getlastFileFromPath(path, ext): |
|
79 | def getlastFileFromPath(path, ext): | |
80 | """ |
|
80 | """ | |
81 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
81 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
82 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
82 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
83 |
|
83 | |||
84 | Input: |
|
84 | Input: | |
85 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
85 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
86 | ext : extension de los files contenidos en una carpeta |
|
86 | ext : extension de los files contenidos en una carpeta | |
87 |
|
87 | |||
88 | Return: |
|
88 | Return: | |
89 | El ultimo file de una determinada carpeta, no se considera el path. |
|
89 | El ultimo file de una determinada carpeta, no se considera el path. | |
90 | """ |
|
90 | """ | |
91 | validFilelist = [] |
|
91 | validFilelist = [] | |
92 | fileList = os.listdir(path) |
|
92 | fileList = os.listdir(path) | |
93 |
|
93 | |||
94 | # 0 1234 567 89A BCDE |
|
94 | # 0 1234 567 89A BCDE | |
95 | # H YYYY DDD SSS .ext |
|
95 | # H YYYY DDD SSS .ext | |
96 |
|
96 | |||
97 | for file in fileList: |
|
97 | for file in fileList: | |
98 | try: |
|
98 | try: | |
99 | year = int(file[1:5]) |
|
99 | year = int(file[1:5]) | |
100 | doy = int(file[5:8]) |
|
100 | doy = int(file[5:8]) | |
101 |
|
101 | |||
102 | if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue |
|
102 | if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue | |
103 | except: |
|
103 | except: | |
104 | continue |
|
104 | continue | |
105 |
|
105 | |||
106 | validFilelist.append(file) |
|
106 | validFilelist.append(file) | |
107 |
|
107 | |||
108 | if validFilelist: |
|
108 | if validFilelist: | |
109 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
109 | validFilelist = sorted( validFilelist, key=str.lower ) | |
110 | return validFilelist[-1] |
|
110 | return validFilelist[-1] | |
111 |
|
111 | |||
112 | return None |
|
112 | return None | |
113 |
|
113 | |||
114 | def checkForRealPath(path, year, doy, set, ext): |
|
114 | def checkForRealPath(path, year, doy, set, ext): | |
115 | """ |
|
115 | """ | |
116 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
116 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
117 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
117 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
118 | el path exacto de un determinado file. |
|
118 | el path exacto de un determinado file. | |
119 |
|
119 | |||
120 | Example : |
|
120 | Example : | |
121 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
121 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
122 |
|
122 | |||
123 | Entonces la funcion prueba con las siguientes combinaciones |
|
123 | Entonces la funcion prueba con las siguientes combinaciones | |
124 | .../.../x2009307/y2009307367.ext |
|
124 | .../.../x2009307/y2009307367.ext | |
125 | .../.../x2009307/Y2009307367.ext |
|
125 | .../.../x2009307/Y2009307367.ext | |
126 | .../.../X2009307/y2009307367.ext |
|
126 | .../.../X2009307/y2009307367.ext | |
127 | .../.../X2009307/Y2009307367.ext |
|
127 | .../.../X2009307/Y2009307367.ext | |
128 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
128 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
129 |
|
129 | |||
130 | Return: |
|
130 | Return: | |
131 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
131 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
132 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
132 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
133 | para el filename |
|
133 | para el filename | |
134 | """ |
|
134 | """ | |
135 | filepath = None |
|
135 | filepath = None | |
136 | find_flag = False |
|
136 | find_flag = False | |
137 | filename = None |
|
137 | filename = None | |
138 |
|
138 | |||
139 | if ext.lower() == ".r": #voltage |
|
139 | if ext.lower() == ".r": #voltage | |
140 | header1 = "dD" |
|
140 | header1 = "dD" | |
141 | header2 = "dD" |
|
141 | header2 = "dD" | |
142 | elif ext.lower() == ".pdata": #spectra |
|
142 | elif ext.lower() == ".pdata": #spectra | |
143 | header1 = "dD" |
|
143 | header1 = "dD" | |
144 | header2 = "pP" |
|
144 | header2 = "pP" | |
145 | else: |
|
145 | else: | |
146 | return None, filename |
|
146 | return None, filename | |
147 |
|
147 | |||
148 | for dir in header1: #barrido por las dos combinaciones posibles de "D" |
|
148 | for dir in header1: #barrido por las dos combinaciones posibles de "D" | |
149 | for fil in header2: #barrido por las dos combinaciones posibles de "D" |
|
149 | for fil in header2: #barrido por las dos combinaciones posibles de "D" | |
150 | doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
150 | doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
151 | filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
151 | filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
152 | filepath = os.path.join( path, doypath, filename ) #formo el path completo |
|
152 | filepath = os.path.join( path, doypath, filename ) #formo el path completo | |
153 | if os.path.exists( filepath ): #verifico que exista |
|
153 | if os.path.exists( filepath ): #verifico que exista | |
154 | find_flag = True |
|
154 | find_flag = True | |
155 | break |
|
155 | break | |
156 | if find_flag: |
|
156 | if find_flag: | |
157 | break |
|
157 | break | |
158 |
|
158 | |||
159 | if not(find_flag): |
|
159 | if not(find_flag): | |
160 | return None, filename |
|
160 | return None, filename | |
161 |
|
161 | |||
162 | return filepath, filename |
|
162 | return filepath, filename | |
163 |
|
163 | |||
164 | class JRODataIO: |
|
164 | class JRODataIO: | |
165 |
|
165 | |||
166 | c = 3E8 |
|
166 | c = 3E8 | |
167 |
|
167 | |||
168 | basicHeaderObj = BasicHeader() |
|
168 | basicHeaderObj = BasicHeader() | |
169 |
|
169 | |||
170 | systemHeaderObj = SystemHeader() |
|
170 | systemHeaderObj = SystemHeader() | |
171 |
|
171 | |||
172 | radarControllerHeaderObj = RadarControllerHeader() |
|
172 | radarControllerHeaderObj = RadarControllerHeader() | |
173 |
|
173 | |||
174 | processingHeaderObj = ProcessingHeader() |
|
174 | processingHeaderObj = ProcessingHeader() | |
175 |
|
175 | |||
176 | online = 0 |
|
176 | online = 0 | |
177 |
|
177 | |||
178 | dtype = None |
|
178 | dtype = None | |
179 |
|
179 | |||
180 | pathList = [] |
|
180 | pathList = [] | |
181 |
|
181 | |||
182 | filenameList = [] |
|
182 | filenameList = [] | |
183 |
|
183 | |||
184 | filename = None |
|
184 | filename = None | |
185 |
|
185 | |||
186 | ext = None |
|
186 | ext = None | |
187 |
|
187 | |||
188 | flagNoMoreFiles = 0 |
|
188 | flagNoMoreFiles = 0 | |
189 |
|
189 | |||
190 | flagIsNewFile = 1 |
|
190 | flagIsNewFile = 1 | |
191 |
|
191 | |||
192 | flagTimeBlock = 0 |
|
192 | flagTimeBlock = 0 | |
193 |
|
193 | |||
194 | flagIsNewBlock = 0 |
|
194 | flagIsNewBlock = 0 | |
195 |
|
195 | |||
196 | fp = None |
|
196 | fp = None | |
197 |
|
197 | |||
198 | firstHeaderSize = 0 |
|
198 | firstHeaderSize = 0 | |
199 |
|
199 | |||
200 | basicHeaderSize = 24 |
|
200 | basicHeaderSize = 24 | |
201 |
|
201 | |||
202 | versionFile = 1103 |
|
202 | versionFile = 1103 | |
203 |
|
203 | |||
204 | fileSize = None |
|
204 | fileSize = None | |
205 |
|
205 | |||
206 | ippSeconds = None |
|
206 | ippSeconds = None | |
207 |
|
207 | |||
208 | fileSizeByHeader = None |
|
208 | fileSizeByHeader = None | |
209 |
|
209 | |||
210 | fileIndex = None |
|
210 | fileIndex = None | |
211 |
|
211 | |||
212 | profileIndex = None |
|
212 | profileIndex = None | |
213 |
|
213 | |||
214 | blockIndex = None |
|
214 | blockIndex = None | |
215 |
|
215 | |||
216 | nTotalBlocks = None |
|
216 | nTotalBlocks = None | |
217 |
|
217 | |||
218 | maxTimeStep = 30 |
|
218 | maxTimeStep = 30 | |
219 |
|
219 | |||
220 | lastUTTime = None |
|
220 | lastUTTime = None | |
221 |
|
221 | |||
222 | datablock = None |
|
222 | datablock = None | |
223 |
|
223 | |||
224 | dataOutObj = None |
|
224 | dataOutObj = None | |
225 |
|
225 | |||
226 | blocksize = None |
|
226 | blocksize = None | |
227 |
|
227 | |||
|
228 | set = None | |||
|
229 | ||||
228 | def __init__(self): |
|
230 | def __init__(self): | |
229 | pass |
|
231 | pass | |
230 |
|
232 | |||
231 | class JRODataReader(JRODataIO): |
|
233 | class JRODataReader(JRODataIO): | |
232 |
|
234 | |||
233 | nReadBlocks = 0 |
|
235 | nReadBlocks = 0 | |
234 |
|
236 | |||
235 | delay = 60 #number of seconds waiting a new file |
|
237 | delay = 60 #number of seconds waiting a new file | |
236 |
|
238 | |||
237 | nTries = 3 #quantity tries |
|
239 | nTries = 3 #quantity tries | |
238 |
|
240 | |||
239 | nFiles = 3 #number of files for searching |
|
241 | nFiles = 3 #number of files for searching | |
240 |
|
242 | |||
241 |
|
243 | |||
242 | def __init__(self): |
|
244 | def __init__(self): | |
243 |
|
245 | |||
244 | pass |
|
246 | pass | |
245 |
|
247 | |||
246 | def createObjByDefault(self): |
|
248 | def createObjByDefault(self): | |
247 | """ |
|
249 | """ | |
248 |
|
250 | |||
249 | """ |
|
251 | """ | |
250 | raise ValueError, "This method has not been implemented" |
|
252 | raise ValueError, "This method has not been implemented" | |
251 |
|
253 | |||
252 | def getBlockDimension(self): |
|
254 | def getBlockDimension(self): | |
253 |
|
255 | |||
254 | raise ValueError, "No implemented" |
|
256 | raise ValueError, "No implemented" | |
255 |
|
257 | |||
256 | def __searchFilesOffLine(self, |
|
258 | def __searchFilesOffLine(self, | |
257 | path, |
|
259 | path, | |
258 | startDate, |
|
260 | startDate, | |
259 | endDate, |
|
261 | endDate, | |
260 | startTime=datetime.time(0,0,0), |
|
262 | startTime=datetime.time(0,0,0), | |
261 | endTime=datetime.time(23,59,59), |
|
263 | endTime=datetime.time(23,59,59), | |
262 | set=None, |
|
264 | set=None, | |
263 | expLabel="", |
|
265 | expLabel="", | |
264 | ext=".r"): |
|
266 | ext=".r"): | |
265 | dirList = [] |
|
267 | dirList = [] | |
266 | for thisPath in os.listdir(path): |
|
268 | for thisPath in os.listdir(path): | |
267 | if os.path.isdir(os.path.join(path,thisPath)): |
|
269 | if os.path.isdir(os.path.join(path,thisPath)): | |
268 | dirList.append(thisPath) |
|
270 | dirList.append(thisPath) | |
269 |
|
271 | |||
270 | if not(dirList): |
|
272 | if not(dirList): | |
271 | return None, None |
|
273 | return None, None | |
272 |
|
274 | |||
273 | pathList = [] |
|
275 | pathList = [] | |
274 | dateList = [] |
|
276 | dateList = [] | |
275 |
|
277 | |||
276 | thisDate = startDate |
|
278 | thisDate = startDate | |
277 |
|
279 | |||
278 | while(thisDate <= endDate): |
|
280 | while(thisDate <= endDate): | |
279 | year = thisDate.timetuple().tm_year |
|
281 | year = thisDate.timetuple().tm_year | |
280 | doy = thisDate.timetuple().tm_yday |
|
282 | doy = thisDate.timetuple().tm_yday | |
281 |
|
283 | |||
282 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
284 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
283 | if len(match) == 0: |
|
285 | if len(match) == 0: | |
284 | thisDate += datetime.timedelta(1) |
|
286 | thisDate += datetime.timedelta(1) | |
285 | continue |
|
287 | continue | |
286 |
|
288 | |||
287 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
289 | pathList.append(os.path.join(path,match[0],expLabel)) | |
288 | dateList.append(thisDate) |
|
290 | dateList.append(thisDate) | |
289 | thisDate += datetime.timedelta(1) |
|
291 | thisDate += datetime.timedelta(1) | |
290 |
|
292 | |||
291 | filenameList = [] |
|
293 | filenameList = [] | |
292 | for index in range(len(pathList)): |
|
294 | for index in range(len(pathList)): | |
293 |
|
295 | |||
294 | thisPath = pathList[index] |
|
296 | thisPath = pathList[index] | |
295 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
297 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
296 | fileList.sort() |
|
298 | fileList.sort() | |
297 |
|
299 | |||
298 | #Busqueda de datos en el rango de horas indicados |
|
300 | #Busqueda de datos en el rango de horas indicados | |
299 | thisDate = dateList[index] |
|
301 | thisDate = dateList[index] | |
300 | startDT = datetime.datetime.combine(thisDate, startTime) |
|
302 | startDT = datetime.datetime.combine(thisDate, startTime) | |
301 | endDT = datetime.datetime.combine(thisDate, endTime) |
|
303 | endDT = datetime.datetime.combine(thisDate, endTime) | |
302 |
|
304 | |||
303 | startUtSeconds = time.mktime(startDT.timetuple()) |
|
305 | startUtSeconds = time.mktime(startDT.timetuple()) | |
304 | endUtSeconds = time.mktime(endDT.timetuple()) |
|
306 | endUtSeconds = time.mktime(endDT.timetuple()) | |
305 |
|
307 | |||
306 | for file in fileList: |
|
308 | for file in fileList: | |
307 |
|
309 | |||
308 | filename = os.path.join(thisPath,file) |
|
310 | filename = os.path.join(thisPath,file) | |
309 |
|
311 | |||
310 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
312 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |
311 | filenameList.append(filename) |
|
313 | filenameList.append(filename) | |
312 |
|
314 | |||
313 | if not(filenameList): |
|
315 | if not(filenameList): | |
314 | return None, None |
|
316 | return None, None | |
315 |
|
317 | |||
316 | self.filenameList = filenameList |
|
318 | self.filenameList = filenameList | |
317 |
|
319 | |||
318 | return pathList, filenameList |
|
320 | return pathList, filenameList | |
319 |
|
321 | |||
320 | def __searchFilesOnLine(self, path, startDate=None, endDate=None, startTime=None, endTime=None, expLabel = "", ext = None): |
|
322 | def __searchFilesOnLine(self, path, startDate=None, endDate=None, startTime=None, endTime=None, expLabel = "", ext = None): | |
321 |
|
323 | |||
322 | """ |
|
324 | """ | |
323 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
325 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
324 | devuelve el archivo encontrado ademas de otros datos. |
|
326 | devuelve el archivo encontrado ademas de otros datos. | |
325 |
|
327 | |||
326 | Input: |
|
328 | Input: | |
327 | path : carpeta donde estan contenidos los files que contiene data |
|
329 | path : carpeta donde estan contenidos los files que contiene data | |
328 |
|
330 | |||
329 | startDate : Fecha inicial. Rechaza todos los directorios donde |
|
331 | startDate : Fecha inicial. Rechaza todos los directorios donde | |
330 | file end time < startDate (obejto datetime.date) |
|
332 | file end time < startDate (obejto datetime.date) | |
331 |
|
333 | |||
332 | endDate : Fecha final. Rechaza todos los directorios donde |
|
334 | endDate : Fecha final. Rechaza todos los directorios donde | |
333 | file start time > endDate (obejto datetime.date) |
|
335 | file start time > endDate (obejto datetime.date) | |
334 |
|
336 | |||
335 | startTime : Tiempo inicial. Rechaza todos los archivos donde |
|
337 | startTime : Tiempo inicial. Rechaza todos los archivos donde | |
336 | file end time < startTime (obejto datetime.time) |
|
338 | file end time < startTime (obejto datetime.time) | |
337 |
|
339 | |||
338 | endTime : Tiempo final. Rechaza todos los archivos donde |
|
340 | endTime : Tiempo final. Rechaza todos los archivos donde | |
339 | file start time > endTime (obejto datetime.time) |
|
341 | file start time > endTime (obejto datetime.time) | |
340 |
|
342 | |||
341 | expLabel : Nombre del subexperimento (subfolder) |
|
343 | expLabel : Nombre del subexperimento (subfolder) | |
342 |
|
344 | |||
343 | ext : extension de los files |
|
345 | ext : extension de los files | |
344 |
|
346 | |||
345 | Return: |
|
347 | Return: | |
346 | directory : eL directorio donde esta el file encontrado |
|
348 | directory : eL directorio donde esta el file encontrado | |
347 | filename : el ultimo file de una determinada carpeta |
|
349 | filename : el ultimo file de una determinada carpeta | |
348 | year : el anho |
|
350 | year : el anho | |
349 | doy : el numero de dia del anho |
|
351 | doy : el numero de dia del anho | |
350 | set : el set del archivo |
|
352 | set : el set del archivo | |
351 |
|
353 | |||
352 |
|
354 | |||
353 | """ |
|
355 | """ | |
354 | dirList = [] |
|
356 | dirList = [] | |
355 | pathList = [] |
|
357 | pathList = [] | |
356 | directory = None |
|
358 | directory = None | |
357 |
|
359 | |||
358 | #Filtra solo los directorios |
|
360 | #Filtra solo los directorios | |
359 | for thisPath in os.listdir(path): |
|
361 | for thisPath in os.listdir(path): | |
360 | if os.path.isdir(os.path.join(path, thisPath)): |
|
362 | if os.path.isdir(os.path.join(path, thisPath)): | |
361 | dirList.append(thisPath) |
|
363 | dirList.append(thisPath) | |
362 |
|
364 | |||
363 | if not(dirList): |
|
365 | if not(dirList): | |
364 | return None, None, None, None, None |
|
366 | return None, None, None, None, None | |
365 |
|
367 | |||
366 | dirList = sorted( dirList, key=str.lower ) |
|
368 | dirList = sorted( dirList, key=str.lower ) | |
367 |
|
369 | |||
368 | if startDate: |
|
370 | if startDate: | |
369 | startDateTime = datetime.datetime.combine(startDate, startTime) |
|
371 | startDateTime = datetime.datetime.combine(startDate, startTime) | |
370 | thisDateTime = startDateTime |
|
372 | thisDateTime = startDateTime | |
371 | if endDate == None: endDateTime = startDateTime |
|
373 | if endDate == None: endDateTime = startDateTime | |
372 | else: endDateTime = datetime.datetime.combine(endDate, endTime) |
|
374 | else: endDateTime = datetime.datetime.combine(endDate, endTime) | |
373 |
|
375 | |||
374 | while(thisDateTime <= endDateTime): |
|
376 | while(thisDateTime <= endDateTime): | |
375 | year = thisDateTime.timetuple().tm_year |
|
377 | year = thisDateTime.timetuple().tm_year | |
376 | doy = thisDateTime.timetuple().tm_yday |
|
378 | doy = thisDateTime.timetuple().tm_yday | |
377 |
|
379 | |||
378 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
380 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
379 | if len(match) == 0: |
|
381 | if len(match) == 0: | |
380 | thisDateTime += datetime.timedelta(1) |
|
382 | thisDateTime += datetime.timedelta(1) | |
381 | continue |
|
383 | continue | |
382 |
|
384 | |||
383 | pathList.append(os.path.join(path,match[0], expLabel)) |
|
385 | pathList.append(os.path.join(path,match[0], expLabel)) | |
384 | thisDateTime += datetime.timedelta(1) |
|
386 | thisDateTime += datetime.timedelta(1) | |
385 |
|
387 | |||
386 | if not(pathList): |
|
388 | if not(pathList): | |
387 | print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) |
|
389 | print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |
388 | return None, None, None, None, None |
|
390 | return None, None, None, None, None | |
389 |
|
391 | |||
390 | directory = pathList[0] |
|
392 | directory = pathList[0] | |
391 |
|
393 | |||
392 | else: |
|
394 | else: | |
393 | directory = dirList[-1] |
|
395 | directory = dirList[-1] | |
394 | directory = os.path.join(path,directory) |
|
396 | directory = os.path.join(path,directory) | |
395 |
|
397 | |||
396 | filename = getlastFileFromPath(directory, ext) |
|
398 | filename = getlastFileFromPath(directory, ext) | |
397 |
|
399 | |||
398 | if not(filename): |
|
400 | if not(filename): | |
399 | return None, None, None, None, None |
|
401 | return None, None, None, None, None | |
400 |
|
402 | |||
401 | if not(self.__verifyFile(os.path.join(directory, filename))): |
|
403 | if not(self.__verifyFile(os.path.join(directory, filename))): | |
402 | return None, None, None, None, None |
|
404 | return None, None, None, None, None | |
403 |
|
405 | |||
404 | year = int( filename[1:5] ) |
|
406 | year = int( filename[1:5] ) | |
405 | doy = int( filename[5:8] ) |
|
407 | doy = int( filename[5:8] ) | |
406 | set = int( filename[8:11] ) |
|
408 | set = int( filename[8:11] ) | |
407 |
|
409 | |||
408 | return directory, filename, year, doy, set |
|
410 | return directory, filename, year, doy, set | |
409 |
|
411 | |||
410 | def setup(self,dataOutObj=None, |
|
412 | def setup(self,dataOutObj=None, | |
411 | path=None, |
|
413 | path=None, | |
412 | startDate=None, |
|
414 | startDate=None, | |
413 | endDate=None, |
|
415 | endDate=None, | |
414 | startTime=datetime.time(0,0,0), |
|
416 | startTime=datetime.time(0,0,0), | |
415 | endTime=datetime.time(23,59,59), |
|
417 | endTime=datetime.time(23,59,59), | |
416 | set=0, |
|
418 | set=0, | |
417 | expLabel = "", |
|
419 | expLabel = "", | |
418 | ext = None, |
|
420 | ext = None, | |
419 | online = False, |
|
421 | online = False, | |
420 | delay = 60): |
|
422 | delay = 60): | |
421 |
|
423 | |||
422 | if path == None: |
|
424 | if path == None: | |
423 | raise ValueError, "The path is not valid" |
|
425 | raise ValueError, "The path is not valid" | |
424 |
|
426 | |||
425 | if ext == None: |
|
427 | if ext == None: | |
426 | ext = self.ext |
|
428 | ext = self.ext | |
427 |
|
429 | |||
428 | if dataOutObj == None: |
|
430 | if dataOutObj == None: | |
429 | dataOutObj = self.createObjByDefault() |
|
431 | dataOutObj = self.createObjByDefault() | |
430 |
|
432 | |||
431 | self.dataOutObj = dataOutObj |
|
433 | self.dataOutObj = dataOutObj | |
432 |
|
434 | |||
433 | if online: |
|
435 | if online: | |
434 | print "Searching files in online mode..." |
|
436 | print "Searching files in online mode..." | |
435 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) |
|
437 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) | |
436 |
|
438 | |||
437 | if not(doypath): |
|
439 | if not(doypath): | |
438 | for nTries in range( self.nTries ): |
|
440 | for nTries in range( self.nTries ): | |
439 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
441 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
440 | time.sleep( self.delay ) |
|
442 | time.sleep( self.delay ) | |
441 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=exp) |
|
443 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=exp) | |
442 | if doypath: |
|
444 | if doypath: | |
443 | break |
|
445 | break | |
444 |
|
446 | |||
445 | if not(doypath): |
|
447 | if not(doypath): | |
446 | print "There 'isn't valied files in %s" % path |
|
448 | print "There 'isn't valied files in %s" % path | |
447 | return None |
|
449 | return None | |
448 |
|
450 | |||
449 | self.year = year |
|
451 | self.year = year | |
450 | self.doy = doy |
|
452 | self.doy = doy | |
451 | self.set = set - 1 |
|
453 | self.set = set - 1 | |
452 | self.path = path |
|
454 | self.path = path | |
453 |
|
455 | |||
454 | else: |
|
456 | else: | |
455 | print "Searching files in offline mode ..." |
|
457 | print "Searching files in offline mode ..." | |
456 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) |
|
458 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) | |
457 |
|
459 | |||
458 | if not(pathList): |
|
460 | if not(pathList): | |
459 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
461 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
460 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
462 | datetime.datetime.combine(startDate,startTime).ctime(), | |
461 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
463 | datetime.datetime.combine(endDate,endTime).ctime()) | |
462 |
|
464 | |||
463 | sys.exit(-1) |
|
465 | sys.exit(-1) | |
464 |
|
466 | |||
465 |
|
467 | |||
466 | self.fileIndex = -1 |
|
468 | self.fileIndex = -1 | |
467 | self.pathList = pathList |
|
469 | self.pathList = pathList | |
468 | self.filenameList = filenameList |
|
470 | self.filenameList = filenameList | |
469 |
|
471 | |||
470 | self.online = online |
|
472 | self.online = online | |
471 | self.delay = delay |
|
473 | self.delay = delay | |
472 | ext = ext.lower() |
|
474 | ext = ext.lower() | |
473 | self.ext = ext |
|
475 | self.ext = ext | |
474 |
|
476 | |||
475 | if not(self.setNextFile()): |
|
477 | if not(self.setNextFile()): | |
476 | if (startDate!=None) and (endDate!=None): |
|
478 | if (startDate!=None) and (endDate!=None): | |
477 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
479 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
478 | elif startDate != None: |
|
480 | elif startDate != None: | |
479 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
481 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
480 | else: |
|
482 | else: | |
481 | print "No files" |
|
483 | print "No files" | |
482 |
|
484 | |||
483 | sys.exit(-1) |
|
485 | sys.exit(-1) | |
484 |
|
486 | |||
485 | # self.updateDataHeader() |
|
487 | # self.updateDataHeader() | |
486 |
|
488 | |||
487 | return self.dataOutObj |
|
489 | return self.dataOutObj | |
488 |
|
490 | |||
489 | def __setNextFileOffline(self): |
|
491 | def __setNextFileOffline(self): | |
490 |
|
492 | |||
491 | idFile = self.fileIndex |
|
493 | idFile = self.fileIndex | |
492 |
|
494 | |||
493 | while (True): |
|
495 | while (True): | |
494 | idFile += 1 |
|
496 | idFile += 1 | |
495 | if not(idFile < len(self.filenameList)): |
|
497 | if not(idFile < len(self.filenameList)): | |
496 | self.flagNoMoreFiles = 1 |
|
498 | self.flagNoMoreFiles = 1 | |
497 | print "No more Files" |
|
499 | print "No more Files" | |
498 | return 0 |
|
500 | return 0 | |
499 |
|
501 | |||
500 | filename = self.filenameList[idFile] |
|
502 | filename = self.filenameList[idFile] | |
501 |
|
503 | |||
502 | if not(self.__verifyFile(filename)): |
|
504 | if not(self.__verifyFile(filename)): | |
503 | continue |
|
505 | continue | |
504 |
|
506 | |||
505 | fileSize = os.path.getsize(filename) |
|
507 | fileSize = os.path.getsize(filename) | |
506 | fp = open(filename,'rb') |
|
508 | fp = open(filename,'rb') | |
507 | break |
|
509 | break | |
508 |
|
510 | |||
509 | self.flagIsNewFile = 1 |
|
511 | self.flagIsNewFile = 1 | |
510 | self.fileIndex = idFile |
|
512 | self.fileIndex = idFile | |
511 | self.filename = filename |
|
513 | self.filename = filename | |
512 | self.fileSize = fileSize |
|
514 | self.fileSize = fileSize | |
513 | self.fp = fp |
|
515 | self.fp = fp | |
514 |
|
516 | |||
515 | print "Setting the file: %s"%self.filename |
|
517 | print "Setting the file: %s"%self.filename | |
516 |
|
518 | |||
517 | return 1 |
|
519 | return 1 | |
518 |
|
520 | |||
519 | def __setNextFileOnline(self): |
|
521 | def __setNextFileOnline(self): | |
520 | """ |
|
522 | """ | |
521 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
523 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
522 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
524 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
523 | siguientes. |
|
525 | siguientes. | |
524 |
|
526 | |||
525 | Affected: |
|
527 | Affected: | |
526 | self.flagIsNewFile |
|
528 | self.flagIsNewFile | |
527 | self.filename |
|
529 | self.filename | |
528 | self.fileSize |
|
530 | self.fileSize | |
529 | self.fp |
|
531 | self.fp | |
530 | self.set |
|
532 | self.set | |
531 | self.flagNoMoreFiles |
|
533 | self.flagNoMoreFiles | |
532 |
|
534 | |||
533 | Return: |
|
535 | Return: | |
534 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
536 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
535 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
537 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
536 |
|
538 | |||
537 | Excepciones: |
|
539 | Excepciones: | |
538 | Si un determinado file no puede ser abierto |
|
540 | Si un determinado file no puede ser abierto | |
539 | """ |
|
541 | """ | |
540 | nFiles = 0 |
|
542 | nFiles = 0 | |
541 | fileOk_flag = False |
|
543 | fileOk_flag = False | |
542 | firstTime_flag = True |
|
544 | firstTime_flag = True | |
543 |
|
545 | |||
544 | self.set += 1 |
|
546 | self.set += 1 | |
545 |
|
547 | |||
546 | #busca el 1er file disponible |
|
548 | #busca el 1er file disponible | |
547 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
549 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
548 | if file: |
|
550 | if file: | |
549 | if self.__verifyFile(file, False): |
|
551 | if self.__verifyFile(file, False): | |
550 | fileOk_flag = True |
|
552 | fileOk_flag = True | |
551 |
|
553 | |||
552 | #si no encuentra un file entonces espera y vuelve a buscar |
|
554 | #si no encuentra un file entonces espera y vuelve a buscar | |
553 | if not(fileOk_flag): |
|
555 | if not(fileOk_flag): | |
554 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
556 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
555 |
|
557 | |||
556 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
558 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
557 | tries = self.nTries |
|
559 | tries = self.nTries | |
558 | else: |
|
560 | else: | |
559 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
561 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
560 |
|
562 | |||
561 | for nTries in range( tries ): |
|
563 | for nTries in range( tries ): | |
562 | if firstTime_flag: |
|
564 | if firstTime_flag: | |
563 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
565 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
564 | time.sleep( self.delay ) |
|
566 | time.sleep( self.delay ) | |
565 | else: |
|
567 | else: | |
566 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
568 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
567 |
|
569 | |||
568 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
570 | file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
569 | if file: |
|
571 | if file: | |
570 | if self.__verifyFile(file): |
|
572 | if self.__verifyFile(file): | |
571 | fileOk_flag = True |
|
573 | fileOk_flag = True | |
572 | break |
|
574 | break | |
573 |
|
575 | |||
574 | if fileOk_flag: |
|
576 | if fileOk_flag: | |
575 | break |
|
577 | break | |
576 |
|
578 | |||
577 | firstTime_flag = False |
|
579 | firstTime_flag = False | |
578 |
|
580 | |||
579 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
581 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename | |
580 | self.set += 1 |
|
582 | self.set += 1 | |
581 |
|
583 | |||
582 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
584 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
583 | self.set = 0 |
|
585 | self.set = 0 | |
584 | self.doy += 1 |
|
586 | self.doy += 1 | |
585 |
|
587 | |||
586 | if fileOk_flag: |
|
588 | if fileOk_flag: | |
587 | self.fileSize = os.path.getsize( file ) |
|
589 | self.fileSize = os.path.getsize( file ) | |
588 | self.filename = file |
|
590 | self.filename = file | |
589 | self.flagIsNewFile = 1 |
|
591 | self.flagIsNewFile = 1 | |
590 | if self.fp != None: self.fp.close() |
|
592 | if self.fp != None: self.fp.close() | |
591 | self.fp = open(file) |
|
593 | self.fp = open(file, 'rb') | |
592 | self.flagNoMoreFiles = 0 |
|
594 | self.flagNoMoreFiles = 0 | |
593 | print 'Setting the file: %s' % file |
|
595 | print 'Setting the file: %s' % file | |
594 | else: |
|
596 | else: | |
595 | self.fileSize = 0 |
|
597 | self.fileSize = 0 | |
596 | self.filename = None |
|
598 | self.filename = None | |
597 | self.flagIsNewFile = 0 |
|
599 | self.flagIsNewFile = 0 | |
598 | self.fp = None |
|
600 | self.fp = None | |
599 | self.flagNoMoreFiles = 1 |
|
601 | self.flagNoMoreFiles = 1 | |
600 | print 'No more Files' |
|
602 | print 'No more Files' | |
601 |
|
603 | |||
602 | return fileOk_flag |
|
604 | return fileOk_flag | |
603 |
|
605 | |||
604 |
|
606 | |||
605 | def setNextFile(self): |
|
607 | def setNextFile(self): | |
606 | if self.fp != None: |
|
608 | if self.fp != None: | |
607 | self.fp.close() |
|
609 | self.fp.close() | |
608 |
|
610 | |||
609 | if self.online: |
|
611 | if self.online: | |
610 | newFile = self.__setNextFileOnline() |
|
612 | newFile = self.__setNextFileOnline() | |
611 | else: |
|
613 | else: | |
612 | newFile = self.__setNextFileOffline() |
|
614 | newFile = self.__setNextFileOffline() | |
613 |
|
615 | |||
614 | if not(newFile): |
|
616 | if not(newFile): | |
615 | return 0 |
|
617 | return 0 | |
616 |
|
618 | |||
617 | self.__readFirstHeader() |
|
619 | self.__readFirstHeader() | |
618 | self.nReadBlocks = 0 |
|
620 | self.nReadBlocks = 0 | |
619 | return 1 |
|
621 | return 1 | |
620 |
|
622 | |||
621 | def __setNewBlock(self): |
|
623 | def __setNewBlock(self): | |
622 | if self.fp == None: |
|
624 | if self.fp == None: | |
623 | return 0 |
|
625 | return 0 | |
624 |
|
626 | |||
625 | if self.flagIsNewFile: |
|
627 | if self.flagIsNewFile: | |
626 | return 1 |
|
628 | return 1 | |
627 |
|
629 | |||
628 | self.lastUTTime = self.basicHeaderObj.utc |
|
630 | self.lastUTTime = self.basicHeaderObj.utc | |
629 | currentSize = self.fileSize - self.fp.tell() |
|
631 | currentSize = self.fileSize - self.fp.tell() | |
630 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
632 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
631 |
|
633 | |||
632 | if (currentSize >= neededSize): |
|
634 | if (currentSize >= neededSize): | |
633 | self.__rdBasicHeader() |
|
635 | self.__rdBasicHeader() | |
634 | return 1 |
|
636 | return 1 | |
635 |
|
637 | |||
636 | if not(self.setNextFile()): |
|
638 | if not(self.setNextFile()): | |
637 | return 0 |
|
639 | return 0 | |
638 |
|
640 | |||
639 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
641 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
640 |
|
642 | |||
641 | self.flagTimeBlock = 0 |
|
643 | self.flagTimeBlock = 0 | |
642 |
|
644 | |||
643 | if deltaTime > self.maxTimeStep: |
|
645 | if deltaTime > self.maxTimeStep: | |
644 | self.flagTimeBlock = 1 |
|
646 | self.flagTimeBlock = 1 | |
645 |
|
647 | |||
646 | return 1 |
|
648 | return 1 | |
647 |
|
649 | |||
648 |
|
650 | |||
649 | def readNextBlock(self): |
|
651 | def readNextBlock(self): | |
650 | if not(self.__setNewBlock()): |
|
652 | if not(self.__setNewBlock()): | |
651 | return 0 |
|
653 | return 0 | |
652 |
|
654 | |||
653 | if not(self.readBlock()): |
|
655 | if not(self.readBlock()): | |
654 | return 0 |
|
656 | return 0 | |
655 |
|
657 | |||
656 | return 1 |
|
658 | return 1 | |
657 |
|
659 | |||
658 | def __rdProcessingHeader(self, fp=None): |
|
660 | def __rdProcessingHeader(self, fp=None): | |
659 | if fp == None: |
|
661 | if fp == None: | |
660 | fp = self.fp |
|
662 | fp = self.fp | |
661 |
|
663 | |||
662 | self.processingHeaderObj.read(fp) |
|
664 | self.processingHeaderObj.read(fp) | |
663 |
|
665 | |||
664 | def __rdRadarControllerHeader(self, fp=None): |
|
666 | def __rdRadarControllerHeader(self, fp=None): | |
665 | if fp == None: |
|
667 | if fp == None: | |
666 | fp = self.fp |
|
668 | fp = self.fp | |
667 |
|
669 | |||
668 | self.radarControllerHeaderObj.read(fp) |
|
670 | self.radarControllerHeaderObj.read(fp) | |
669 |
|
671 | |||
670 | def __rdSystemHeader(self, fp=None): |
|
672 | def __rdSystemHeader(self, fp=None): | |
671 | if fp == None: |
|
673 | if fp == None: | |
672 | fp = self.fp |
|
674 | fp = self.fp | |
673 |
|
675 | |||
674 | self.systemHeaderObj.read(fp) |
|
676 | self.systemHeaderObj.read(fp) | |
675 |
|
677 | |||
676 | def __rdBasicHeader(self, fp=None): |
|
678 | def __rdBasicHeader(self, fp=None): | |
677 | if fp == None: |
|
679 | if fp == None: | |
678 | fp = self.fp |
|
680 | fp = self.fp | |
679 |
|
681 | |||
680 | self.basicHeaderObj.read(fp) |
|
682 | self.basicHeaderObj.read(fp) | |
681 |
|
683 | |||
682 |
|
684 | |||
683 | def __readFirstHeader(self): |
|
685 | def __readFirstHeader(self): | |
684 | self.__rdBasicHeader() |
|
686 | self.__rdBasicHeader() | |
685 | self.__rdSystemHeader() |
|
687 | self.__rdSystemHeader() | |
686 | self.__rdRadarControllerHeader() |
|
688 | self.__rdRadarControllerHeader() | |
687 | self.__rdProcessingHeader() |
|
689 | self.__rdProcessingHeader() | |
688 |
|
690 | |||
689 | self.firstHeaderSize = self.basicHeaderObj.size |
|
691 | self.firstHeaderSize = self.basicHeaderObj.size | |
690 |
|
692 | |||
691 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
693 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
692 | if datatype == 0: |
|
694 | if datatype == 0: | |
693 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
695 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
694 | elif datatype == 1: |
|
696 | elif datatype == 1: | |
695 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
697 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
696 | elif datatype == 2: |
|
698 | elif datatype == 2: | |
697 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
699 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
698 | elif datatype == 3: |
|
700 | elif datatype == 3: | |
699 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
701 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
700 | elif datatype == 4: |
|
702 | elif datatype == 4: | |
701 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
703 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
702 | elif datatype == 5: |
|
704 | elif datatype == 5: | |
703 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
705 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
704 | else: |
|
706 | else: | |
705 | raise ValueError, 'Data type was not defined' |
|
707 | raise ValueError, 'Data type was not defined' | |
706 |
|
708 | |||
707 | self.dtype = datatype_str |
|
709 | self.dtype = datatype_str | |
708 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
710 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
709 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
711 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
710 | # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
712 | # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
711 | # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
713 | # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
712 | self.getBlockDimension() |
|
714 | self.getBlockDimension() | |
713 |
|
715 | |||
714 |
|
716 | |||
715 | def __verifyFile(self, filename, msgFlag=True): |
|
717 | def __verifyFile(self, filename, msgFlag=True): | |
716 | msg = None |
|
718 | msg = None | |
717 | try: |
|
719 | try: | |
718 | fp = open(filename, 'rb') |
|
720 | fp = open(filename, 'rb') | |
719 | currentPosition = fp.tell() |
|
721 | currentPosition = fp.tell() | |
720 | except: |
|
722 | except: | |
721 | if msgFlag: |
|
723 | if msgFlag: | |
722 | print "The file %s can't be opened" % (filename) |
|
724 | print "The file %s can't be opened" % (filename) | |
723 | return False |
|
725 | return False | |
724 |
|
726 | |||
725 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
727 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
726 |
|
728 | |||
727 | if neededSize == 0: |
|
729 | if neededSize == 0: | |
728 | basicHeaderObj = BasicHeader() |
|
730 | basicHeaderObj = BasicHeader() | |
729 | systemHeaderObj = SystemHeader() |
|
731 | systemHeaderObj = SystemHeader() | |
730 | radarControllerHeaderObj = RadarControllerHeader() |
|
732 | radarControllerHeaderObj = RadarControllerHeader() | |
731 | processingHeaderObj = ProcessingHeader() |
|
733 | processingHeaderObj = ProcessingHeader() | |
732 |
|
734 | |||
733 | try: |
|
735 | try: | |
734 | if not( basicHeaderObj.read(fp) ): raise ValueError |
|
736 | if not( basicHeaderObj.read(fp) ): raise ValueError | |
735 | if not( systemHeaderObj.read(fp) ): raise ValueError |
|
737 | if not( systemHeaderObj.read(fp) ): raise ValueError | |
736 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError |
|
738 | if not( radarControllerHeaderObj.read(fp) ): raise ValueError | |
737 | if not( processingHeaderObj.read(fp) ): raise ValueError |
|
739 | if not( processingHeaderObj.read(fp) ): raise ValueError | |
738 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
740 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
739 |
|
741 | |||
740 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
742 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
741 |
|
743 | |||
742 | except: |
|
744 | except: | |
743 | if msgFlag: |
|
745 | if msgFlag: | |
744 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
746 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
745 |
|
747 | |||
746 | fp.close() |
|
748 | fp.close() | |
747 | return False |
|
749 | return False | |
748 | else: |
|
750 | else: | |
749 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
751 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
750 |
|
752 | |||
751 | fp.close() |
|
753 | fp.close() | |
752 | fileSize = os.path.getsize(filename) |
|
754 | fileSize = os.path.getsize(filename) | |
753 | currentSize = fileSize - currentPosition |
|
755 | currentSize = fileSize - currentPosition | |
754 | if currentSize < neededSize: |
|
756 | if currentSize < neededSize: | |
755 | if msgFlag and (msg != None): |
|
757 | if msgFlag and (msg != None): | |
756 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
758 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
757 | return False |
|
759 | return False | |
758 |
|
760 | |||
759 | return True |
|
761 | return True | |
760 |
|
762 | |||
761 | def getData(): |
|
763 | def getData(): | |
762 | pass |
|
764 | pass | |
763 |
|
765 | |||
764 | def hasNotDataInBuffer(): |
|
766 | def hasNotDataInBuffer(): | |
765 | pass |
|
767 | pass | |
766 |
|
768 | |||
767 | def readBlock(): |
|
769 | def readBlock(): | |
768 | pass |
|
770 | pass | |
769 |
|
771 | |||
770 | class JRODataWriter(JRODataIO): |
|
772 | class JRODataWriter(JRODataIO): | |
771 |
|
773 | |||
772 | """ |
|
774 | """ | |
773 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
775 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
774 | de los datos siempre se realiza por bloques. |
|
776 | de los datos siempre se realiza por bloques. | |
775 | """ |
|
777 | """ | |
776 |
|
778 | |||
777 | blockIndex = 0 |
|
779 | blockIndex = 0 | |
778 |
|
780 | |||
779 | path = None |
|
781 | path = None | |
780 |
|
782 | |||
781 | setFile = None |
|
783 | setFile = None | |
782 |
|
784 | |||
783 | profilesPerBlock = None |
|
785 | profilesPerBlock = None | |
784 |
|
786 | |||
785 | blocksPerFile = None |
|
787 | blocksPerFile = None | |
786 |
|
788 | |||
787 | nWriteBlocks = 0 |
|
789 | nWriteBlocks = 0 | |
788 |
|
790 | |||
789 | def __init__(self, dataOutObj=None): |
|
791 | def __init__(self, dataOutObj=None): | |
790 | raise ValueError, "Not implemented" |
|
792 | raise ValueError, "Not implemented" | |
791 |
|
793 | |||
792 |
|
794 | |||
793 | def hasAllDataInBuffer(self): |
|
795 | def hasAllDataInBuffer(self): | |
794 | raise ValueError, "Not implemented" |
|
796 | raise ValueError, "Not implemented" | |
795 |
|
797 | |||
796 |
|
798 | |||
797 | def setBlockDimension(self): |
|
799 | def setBlockDimension(self): | |
798 | raise ValueError, "Not implemented" |
|
800 | raise ValueError, "Not implemented" | |
799 |
|
801 | |||
800 |
|
802 | |||
801 | def writeBlock(self): |
|
803 | def writeBlock(self): | |
802 | raise ValueError, "No implemented" |
|
804 | raise ValueError, "No implemented" | |
803 |
|
805 | |||
804 |
|
806 | |||
805 | def putData(self): |
|
807 | def putData(self): | |
806 | raise ValueError, "No implemented" |
|
808 | raise ValueError, "No implemented" | |
807 |
|
809 | |||
808 |
|
810 | |||
809 | def __writeFirstHeader(self): |
|
811 | def __writeFirstHeader(self): | |
810 | """ |
|
812 | """ | |
811 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
813 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
812 |
|
814 | |||
813 | Affected: |
|
815 | Affected: | |
814 | __dataType |
|
816 | __dataType | |
815 |
|
817 | |||
816 | Return: |
|
818 | Return: | |
817 | None |
|
819 | None | |
818 | """ |
|
820 | """ | |
819 |
|
821 | |||
820 | # CALCULAR PARAMETROS |
|
822 | # CALCULAR PARAMETROS | |
821 |
|
823 | |||
822 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
824 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
823 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
825 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
824 |
|
826 | |||
825 | self.__writeBasicHeader() |
|
827 | self.__writeBasicHeader() | |
826 | self.__wrSystemHeader() |
|
828 | self.__wrSystemHeader() | |
827 | self.__wrRadarControllerHeader() |
|
829 | self.__wrRadarControllerHeader() | |
828 | self.__wrProcessingHeader() |
|
830 | self.__wrProcessingHeader() | |
829 | self.dtype = self.dataOutObj.dtype |
|
831 | self.dtype = self.dataOutObj.dtype | |
830 |
|
832 | |||
831 |
|
833 | |||
832 | def __writeBasicHeader(self, fp=None): |
|
834 | def __writeBasicHeader(self, fp=None): | |
833 | """ |
|
835 | """ | |
834 | Escribe solo el Basic header en el file creado |
|
836 | Escribe solo el Basic header en el file creado | |
835 |
|
837 | |||
836 | Return: |
|
838 | Return: | |
837 | None |
|
839 | None | |
838 | """ |
|
840 | """ | |
839 | if fp == None: |
|
841 | if fp == None: | |
840 | fp = self.fp |
|
842 | fp = self.fp | |
841 |
|
843 | |||
842 | self.basicHeaderObj.write(fp) |
|
844 | self.basicHeaderObj.write(fp) | |
843 |
|
845 | |||
844 |
|
846 | |||
845 | def __wrSystemHeader(self, fp=None): |
|
847 | def __wrSystemHeader(self, fp=None): | |
846 | """ |
|
848 | """ | |
847 | Escribe solo el System header en el file creado |
|
849 | Escribe solo el System header en el file creado | |
848 |
|
850 | |||
849 | Return: |
|
851 | Return: | |
850 | None |
|
852 | None | |
851 | """ |
|
853 | """ | |
852 | if fp == None: |
|
854 | if fp == None: | |
853 | fp = self.fp |
|
855 | fp = self.fp | |
854 |
|
856 | |||
855 | self.systemHeaderObj.write(fp) |
|
857 | self.systemHeaderObj.write(fp) | |
856 |
|
858 | |||
857 |
|
859 | |||
858 | def __wrRadarControllerHeader(self, fp=None): |
|
860 | def __wrRadarControllerHeader(self, fp=None): | |
859 | """ |
|
861 | """ | |
860 | Escribe solo el RadarController header en el file creado |
|
862 | Escribe solo el RadarController header en el file creado | |
861 |
|
863 | |||
862 | Return: |
|
864 | Return: | |
863 | None |
|
865 | None | |
864 | """ |
|
866 | """ | |
865 | if fp == None: |
|
867 | if fp == None: | |
866 | fp = self.fp |
|
868 | fp = self.fp | |
867 |
|
869 | |||
868 | self.radarControllerHeaderObj.write(fp) |
|
870 | self.radarControllerHeaderObj.write(fp) | |
869 |
|
871 | |||
870 |
|
872 | |||
871 | def __wrProcessingHeader(self, fp=None): |
|
873 | def __wrProcessingHeader(self, fp=None): | |
872 | """ |
|
874 | """ | |
873 | Escribe solo el Processing header en el file creado |
|
875 | Escribe solo el Processing header en el file creado | |
874 |
|
876 | |||
875 | Return: |
|
877 | Return: | |
876 | None |
|
878 | None | |
877 | """ |
|
879 | """ | |
878 | if fp == None: |
|
880 | if fp == None: | |
879 | fp = self.fp |
|
881 | fp = self.fp | |
880 |
|
882 | |||
881 | self.processingHeaderObj.write(fp) |
|
883 | self.processingHeaderObj.write(fp) | |
882 |
|
884 | |||
883 |
|
885 | |||
884 | def setNextFile(self): |
|
886 | def setNextFile(self): | |
885 | """ |
|
887 | """ | |
886 | Determina el siguiente file que sera escrito |
|
888 | Determina el siguiente file que sera escrito | |
887 |
|
889 | |||
888 | Affected: |
|
890 | Affected: | |
889 | self.filename |
|
891 | self.filename | |
890 | self.subfolder |
|
892 | self.subfolder | |
891 | self.fp |
|
893 | self.fp | |
892 | self.setFile |
|
894 | self.setFile | |
893 | self.flagIsNewFile |
|
895 | self.flagIsNewFile | |
894 |
|
896 | |||
895 | Return: |
|
897 | Return: | |
896 | 0 : Si el archivo no puede ser escrito |
|
898 | 0 : Si el archivo no puede ser escrito | |
897 | 1 : Si el archivo esta listo para ser escrito |
|
899 | 1 : Si el archivo esta listo para ser escrito | |
898 | """ |
|
900 | """ | |
899 | ext = self.ext |
|
901 | ext = self.ext | |
900 | path = self.path |
|
902 | path = self.path | |
901 |
|
903 | |||
902 | if self.fp != None: |
|
904 | if self.fp != None: | |
903 | self.fp.close() |
|
905 | self.fp.close() | |
904 |
|
906 | |||
905 | timeTuple = time.localtime( self.dataOutObj.dataUtcTime) |
|
907 | timeTuple = time.localtime( self.dataOutObj.dataUtcTime) | |
906 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
908 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
907 |
|
909 | |||
908 | doypath = os.path.join( path, subfolder ) |
|
910 | doypath = os.path.join( path, subfolder ) | |
909 | if not( os.path.exists(doypath) ): |
|
911 | if not( os.path.exists(doypath) ): | |
910 | os.mkdir(doypath) |
|
912 | os.mkdir(doypath) | |
911 | self.setFile = -1 #inicializo mi contador de seteo |
|
913 | self.setFile = -1 #inicializo mi contador de seteo | |
912 | else: |
|
914 | else: | |
913 | filesList = os.listdir( doypath ) |
|
915 | filesList = os.listdir( doypath ) | |
914 | if len( filesList ) > 0: |
|
916 | if len( filesList ) > 0: | |
915 | filesList = sorted( filesList, key=str.lower ) |
|
917 | filesList = sorted( filesList, key=str.lower ) | |
916 | filen = filesList[-1] |
|
918 | filen = filesList[-1] | |
917 | # el filename debera tener el siguiente formato |
|
919 | # el filename debera tener el siguiente formato | |
918 | # 0 1234 567 89A BCDE (hex) |
|
920 | # 0 1234 567 89A BCDE (hex) | |
919 | # x YYYY DDD SSS .ext |
|
921 | # x YYYY DDD SSS .ext | |
920 | if isNumber( filen[8:11] ): |
|
922 | if isNumber( filen[8:11] ): | |
921 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
923 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
922 | else: |
|
924 | else: | |
923 | self.setFile = -1 |
|
925 | self.setFile = -1 | |
924 | else: |
|
926 | else: | |
925 | self.setFile = -1 #inicializo mi contador de seteo |
|
927 | self.setFile = -1 #inicializo mi contador de seteo | |
926 |
|
928 | |||
927 | setFile = self.setFile |
|
929 | setFile = self.setFile | |
928 | setFile += 1 |
|
930 | setFile += 1 | |
929 |
|
931 | |||
930 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
932 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
931 | timeTuple.tm_year, |
|
933 | timeTuple.tm_year, | |
932 | timeTuple.tm_yday, |
|
934 | timeTuple.tm_yday, | |
933 | setFile, |
|
935 | setFile, | |
934 | ext ) |
|
936 | ext ) | |
935 |
|
937 | |||
936 | filename = os.path.join( path, subfolder, file ) |
|
938 | filename = os.path.join( path, subfolder, file ) | |
937 |
|
939 | |||
938 | fp = open( filename,'wb' ) |
|
940 | fp = open( filename,'wb' ) | |
939 |
|
941 | |||
940 | self.blockIndex = 0 |
|
942 | self.blockIndex = 0 | |
941 |
|
943 | |||
942 | #guardando atributos |
|
944 | #guardando atributos | |
943 | self.filename = filename |
|
945 | self.filename = filename | |
944 | self.subfolder = subfolder |
|
946 | self.subfolder = subfolder | |
945 | self.fp = fp |
|
947 | self.fp = fp | |
946 | self.setFile = setFile |
|
948 | self.setFile = setFile | |
947 | self.flagIsNewFile = 1 |
|
949 | self.flagIsNewFile = 1 | |
948 |
|
950 | |||
949 | self.getDataHeader() |
|
951 | self.getDataHeader() | |
950 |
|
952 | |||
951 | print 'Writing the file: %s'%self.filename |
|
953 | print 'Writing the file: %s'%self.filename | |
952 |
|
954 | |||
953 | self.__writeFirstHeader() |
|
955 | self.__writeFirstHeader() | |
954 |
|
956 | |||
955 | return 1 |
|
957 | return 1 | |
956 |
|
958 | |||
957 |
|
959 | |||
958 | def __setNewBlock(self): |
|
960 | def __setNewBlock(self): | |
959 | """ |
|
961 | """ | |
960 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
962 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
961 |
|
963 | |||
962 | Return: |
|
964 | Return: | |
963 | 0 : si no pudo escribir nada |
|
965 | 0 : si no pudo escribir nada | |
964 | 1 : Si escribio el Basic el First Header |
|
966 | 1 : Si escribio el Basic el First Header | |
965 | """ |
|
967 | """ | |
966 | if self.fp == None: |
|
968 | if self.fp == None: | |
967 | self.setNextFile() |
|
969 | self.setNextFile() | |
968 |
|
970 | |||
969 | if self.flagIsNewFile: |
|
971 | if self.flagIsNewFile: | |
970 | return 1 |
|
972 | return 1 | |
971 |
|
973 | |||
972 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
974 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
973 | self.__writeBasicHeader() |
|
975 | self.__writeBasicHeader() | |
974 | return 1 |
|
976 | return 1 | |
975 |
|
977 | |||
976 | if not( self.setNextFile() ): |
|
978 | if not( self.setNextFile() ): | |
977 | return 0 |
|
979 | return 0 | |
978 |
|
980 | |||
979 | return 1 |
|
981 | return 1 | |
980 |
|
982 | |||
981 |
|
983 | |||
982 | def writeNextBlock(self): |
|
984 | def writeNextBlock(self): | |
983 | """ |
|
985 | """ | |
984 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
986 | Selecciona el bloque siguiente de datos y los escribe en un file | |
985 |
|
987 | |||
986 | Return: |
|
988 | Return: | |
987 | 0 : Si no hizo pudo escribir el bloque de datos |
|
989 | 0 : Si no hizo pudo escribir el bloque de datos | |
988 | 1 : Si no pudo escribir el bloque de datos |
|
990 | 1 : Si no pudo escribir el bloque de datos | |
989 | """ |
|
991 | """ | |
990 | if not( self.__setNewBlock() ): |
|
992 | if not( self.__setNewBlock() ): | |
991 | return 0 |
|
993 | return 0 | |
992 |
|
994 | |||
993 | self.writeBlock() |
|
995 | self.writeBlock() | |
994 |
|
996 | |||
995 | return 1 |
|
997 | return 1 | |
996 |
|
998 | |||
997 |
|
999 | |||
998 | def getDataHeader(self): |
|
1000 | def getDataHeader(self): | |
999 | """Obtiene una copia del First Header Affected: self.basicHeaderObj self. |
|
1001 | """Obtiene una copia del First Header Affected: self.basicHeaderObj self. | |
1000 | systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self. |
|
1002 | systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self. | |
1001 | dtype Return: None |
|
1003 | dtype Return: None | |
1002 | """ |
|
1004 | """ | |
1003 |
|
1005 | |||
1004 | raise ValueError, "No implemented" |
|
1006 | raise ValueError, "No implemented" | |
1005 |
|
1007 | |||
1006 | def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): |
|
1008 | def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
1007 | """ |
|
1009 | """ | |
1008 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1010 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1009 |
|
1011 | |||
1010 | Inputs: |
|
1012 | Inputs: | |
1011 | path : el path destino en el cual se escribiran los files a crear |
|
1013 | path : el path destino en el cual se escribiran los files a crear | |
1012 | format : formato en el cual sera salvado un file |
|
1014 | format : formato en el cual sera salvado un file | |
1013 | set : el setebo del file |
|
1015 | set : el setebo del file | |
1014 |
|
1016 | |||
1015 | Return: |
|
1017 | Return: | |
1016 | 0 : Si no realizo un buen seteo |
|
1018 | 0 : Si no realizo un buen seteo | |
1017 | 1 : Si realizo un buen seteo |
|
1019 | 1 : Si realizo un buen seteo | |
1018 | """ |
|
1020 | """ | |
1019 |
|
1021 | |||
1020 | if ext == None: |
|
1022 | if ext == None: | |
1021 | ext = self.ext |
|
1023 | ext = self.ext | |
1022 |
|
1024 | |||
1023 | ext = ext.lower() |
|
1025 | ext = ext.lower() | |
1024 |
|
1026 | |||
1025 | self.ext = ext |
|
1027 | self.ext = ext | |
1026 |
|
1028 | |||
1027 | self.path = path |
|
1029 | self.path = path | |
1028 |
|
1030 | |||
1029 | self.setFile = set - 1 |
|
1031 | self.setFile = set - 1 | |
1030 |
|
1032 | |||
1031 | self.blocksPerFile = blocksPerFile |
|
1033 | self.blocksPerFile = blocksPerFile | |
1032 |
|
1034 | |||
1033 | self.profilesPerBlock = profilesPerBlock |
|
1035 | self.profilesPerBlock = profilesPerBlock | |
1034 |
|
1036 | |||
1035 | if not(self.setNextFile()): |
|
1037 | if not(self.setNextFile()): | |
1036 | print "There isn't a next file" |
|
1038 | print "There isn't a next file" | |
1037 | return 0 |
|
1039 | return 0 | |
1038 |
|
1040 | |||
1039 | self.setBlockDimension() |
|
1041 | self.setBlockDimension() | |
1040 |
|
1042 | |||
1041 | return 1 |
|
1043 | return 1 | |
1042 |
|
1044 | |||
1043 |
|
1045 | |||
1044 |
|
1046 | |||
1045 |
|
1047 | |||
1046 |
|
1048 | |||
1047 |
|
1049 |
@@ -1,905 +1,949 | |||||
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 |
|
9 | |||
10 | import pyfits |
|
10 | import pyfits | |
11 | import glob |
|
11 | import glob | |
12 | import fnmatch |
|
12 | import fnmatch | |
13 | import time, datetime |
|
13 | import time, datetime | |
14 |
|
14 | |||
15 | path = os.path.split(os.getcwd())[0] |
|
15 | path = os.path.split(os.getcwd())[0] | |
16 | sys.path.append(path) |
|
16 | sys.path.append(path) | |
17 |
|
17 | |||
18 | from JROHeaderIO import * |
|
18 | from JROHeaderIO import * | |
19 | from JRODataIO import JRODataReader |
|
19 | from JRODataIO import JRODataReader | |
20 | from JRODataIO import JRODataWriter |
|
20 | from JRODataIO import JRODataWriter | |
21 |
|
21 | |||
22 | from Data.JROData import Spectra |
|
22 | from Data.JROData import Spectra | |
23 |
|
23 | |||
24 | from Data.JROData import SpectraHeis |
|
24 | from Data.JROData import SpectraHeis | |
25 |
|
25 | |||
26 | class SpectraReader(JRODataReader): |
|
26 | class SpectraReader(JRODataReader): | |
27 | """ |
|
27 | """ | |
28 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
28 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
29 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
29 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
30 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
30 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
31 |
|
31 | |||
32 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
32 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
33 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
33 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
34 | canales * alturas (DC Channels) |
|
34 | canales * alturas (DC Channels) | |
35 |
|
35 | |||
36 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
36 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
37 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
37 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
38 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
38 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
39 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
39 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
40 |
|
40 | |||
41 | Example: |
|
41 | Example: | |
42 | dpath = "/home/myuser/data" |
|
42 | dpath = "/home/myuser/data" | |
43 |
|
43 | |||
44 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
44 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
45 |
|
45 | |||
46 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
46 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
47 |
|
47 | |||
48 | readerObj = SpectraReader() |
|
48 | readerObj = SpectraReader() | |
49 |
|
49 | |||
50 | readerObj.setup(dpath, startTime, endTime) |
|
50 | readerObj.setup(dpath, startTime, endTime) | |
51 |
|
51 | |||
52 | while(True): |
|
52 | while(True): | |
53 |
|
53 | |||
54 | readerObj.getData() |
|
54 | readerObj.getData() | |
55 |
|
55 | |||
56 | print readerObj.data_spc |
|
56 | print readerObj.data_spc | |
57 |
|
57 | |||
58 | print readerObj.data_cspc |
|
58 | print readerObj.data_cspc | |
59 |
|
59 | |||
60 | print readerObj.data_dc |
|
60 | print readerObj.data_dc | |
61 |
|
61 | |||
62 | if readerObj.flagNoMoreFiles: |
|
62 | if readerObj.flagNoMoreFiles: | |
63 | break |
|
63 | break | |
64 |
|
64 | |||
65 | """ |
|
65 | """ | |
66 |
|
66 | |||
67 | pts2read_SelfSpectra = 0 |
|
67 | pts2read_SelfSpectra = 0 | |
68 |
|
68 | |||
69 | pts2read_CrossSpectra = 0 |
|
69 | pts2read_CrossSpectra = 0 | |
70 |
|
70 | |||
71 | pts2read_DCchannels = 0 |
|
71 | pts2read_DCchannels = 0 | |
72 |
|
72 | |||
73 | ext = ".pdata" |
|
73 | ext = ".pdata" | |
74 |
|
74 | |||
75 | optchar = "P" |
|
75 | optchar = "P" | |
76 |
|
76 | |||
77 | dataOutObj = None |
|
77 | dataOutObj = None | |
78 |
|
78 | |||
79 | nRdChannels = None |
|
79 | nRdChannels = None | |
80 |
|
80 | |||
81 | nRdPairs = None |
|
81 | nRdPairs = None | |
82 |
|
82 | |||
83 | rdPairList = [] |
|
83 | rdPairList = [] | |
84 |
|
84 | |||
85 |
|
85 | |||
86 | def __init__(self, dataOutObj=None): |
|
86 | def __init__(self, dataOutObj=None): | |
87 | """ |
|
87 | """ | |
88 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
88 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
89 |
|
89 | |||
90 | Inputs: |
|
90 | Inputs: | |
91 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
91 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para | |
92 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
92 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
93 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
93 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
94 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
94 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
95 | bloque de datos. |
|
95 | bloque de datos. | |
96 | Si este parametro no es pasado se creara uno internamente. |
|
96 | Si este parametro no es pasado se creara uno internamente. | |
97 |
|
97 | |||
98 | Affected: |
|
98 | Affected: | |
99 | self.dataOutObj |
|
99 | self.dataOutObj | |
100 |
|
100 | |||
101 | Return : None |
|
101 | Return : None | |
102 | """ |
|
102 | """ | |
103 |
|
103 | |||
104 | self.pts2read_SelfSpectra = 0 |
|
104 | self.pts2read_SelfSpectra = 0 | |
105 |
|
105 | |||
106 | self.pts2read_CrossSpectra = 0 |
|
106 | self.pts2read_CrossSpectra = 0 | |
107 |
|
107 | |||
108 | self.pts2read_DCchannels = 0 |
|
108 | self.pts2read_DCchannels = 0 | |
109 |
|
109 | |||
110 | self.datablock = None |
|
110 | self.datablock = None | |
111 |
|
111 | |||
112 | self.utc = None |
|
112 | self.utc = None | |
113 |
|
113 | |||
114 | self.ext = ".pdata" |
|
114 | self.ext = ".pdata" | |
115 |
|
115 | |||
116 | self.optchar = "P" |
|
116 | self.optchar = "P" | |
117 |
|
117 | |||
118 | self.basicHeaderObj = BasicHeader() |
|
118 | self.basicHeaderObj = BasicHeader() | |
119 |
|
119 | |||
120 | self.systemHeaderObj = SystemHeader() |
|
120 | self.systemHeaderObj = SystemHeader() | |
121 |
|
121 | |||
122 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
122 | self.radarControllerHeaderObj = RadarControllerHeader() | |
123 |
|
123 | |||
124 | self.processingHeaderObj = ProcessingHeader() |
|
124 | self.processingHeaderObj = ProcessingHeader() | |
125 |
|
125 | |||
126 | self.online = 0 |
|
126 | self.online = 0 | |
127 |
|
127 | |||
128 | self.fp = None |
|
128 | self.fp = None | |
129 |
|
129 | |||
130 | self.idFile = None |
|
130 | self.idFile = None | |
131 |
|
131 | |||
132 | self.dtype = None |
|
132 | self.dtype = None | |
133 |
|
133 | |||
134 | self.fileSizeByHeader = None |
|
134 | self.fileSizeByHeader = None | |
135 |
|
135 | |||
136 | self.filenameList = [] |
|
136 | self.filenameList = [] | |
137 |
|
137 | |||
138 | self.filename = None |
|
138 | self.filename = None | |
139 |
|
139 | |||
140 | self.fileSize = None |
|
140 | self.fileSize = None | |
141 |
|
141 | |||
142 | self.firstHeaderSize = 0 |
|
142 | self.firstHeaderSize = 0 | |
143 |
|
143 | |||
144 | self.basicHeaderSize = 24 |
|
144 | self.basicHeaderSize = 24 | |
145 |
|
145 | |||
146 | self.pathList = [] |
|
146 | self.pathList = [] | |
147 |
|
147 | |||
148 | self.lastUTTime = 0 |
|
148 | self.lastUTTime = 0 | |
149 |
|
149 | |||
150 | self.maxTimeStep = 30 |
|
150 | self.maxTimeStep = 30 | |
151 |
|
151 | |||
152 | self.flagNoMoreFiles = 0 |
|
152 | self.flagNoMoreFiles = 0 | |
153 |
|
153 | |||
154 | self.set = 0 |
|
154 | self.set = 0 | |
155 |
|
155 | |||
156 | self.path = None |
|
156 | self.path = None | |
157 |
|
157 | |||
158 | self.delay = 3 #seconds |
|
158 | self.delay = 3 #seconds | |
159 |
|
159 | |||
160 | self.nTries = 3 #quantity tries |
|
160 | self.nTries = 3 #quantity tries | |
161 |
|
161 | |||
162 | self.nFiles = 3 #number of files for searching |
|
162 | self.nFiles = 3 #number of files for searching | |
163 |
|
163 | |||
164 | self.nReadBlocks = 0 |
|
164 | self.nReadBlocks = 0 | |
165 |
|
165 | |||
166 | self.flagIsNewFile = 1 |
|
166 | self.flagIsNewFile = 1 | |
167 |
|
167 | |||
168 | self.ippSeconds = 0 |
|
168 | self.ippSeconds = 0 | |
169 |
|
169 | |||
170 | self.flagTimeBlock = 0 |
|
170 | self.flagTimeBlock = 0 | |
171 |
|
171 | |||
172 | self.flagIsNewBlock = 0 |
|
172 | self.flagIsNewBlock = 0 | |
173 |
|
173 | |||
174 | self.nTotalBlocks = 0 |
|
174 | self.nTotalBlocks = 0 | |
175 |
|
175 | |||
176 | self.blocksize = 0 |
|
176 | self.blocksize = 0 | |
177 |
|
177 | |||
178 |
|
178 | |||
179 | def createObjByDefault(self): |
|
179 | def createObjByDefault(self): | |
180 |
|
180 | |||
181 | dataObj = Spectra() |
|
181 | dataObj = Spectra() | |
182 |
|
182 | |||
183 | return dataObj |
|
183 | return dataObj | |
184 |
|
184 | |||
185 | def __hasNotDataInBuffer(self): |
|
185 | def __hasNotDataInBuffer(self): | |
186 | return 1 |
|
186 | return 1 | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | def getBlockDimension(self): |
|
189 | def getBlockDimension(self): | |
190 | """ |
|
190 | """ | |
191 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
191 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
192 |
|
192 | |||
193 | Affected: |
|
193 | Affected: | |
194 | self.nRdChannels |
|
194 | self.nRdChannels | |
195 | self.nRdPairs |
|
195 | self.nRdPairs | |
196 | self.pts2read_SelfSpectra |
|
196 | self.pts2read_SelfSpectra | |
197 | self.pts2read_CrossSpectra |
|
197 | self.pts2read_CrossSpectra | |
198 | self.pts2read_DCchannels |
|
198 | self.pts2read_DCchannels | |
199 | self.blocksize |
|
199 | self.blocksize | |
200 | self.dataOutObj.nChannels |
|
200 | self.dataOutObj.nChannels | |
201 | self.dataOutObj.nPairs |
|
201 | self.dataOutObj.nPairs | |
202 |
|
202 | |||
203 | Return: |
|
203 | Return: | |
204 | None |
|
204 | None | |
205 | """ |
|
205 | """ | |
206 | self.nRdChannels = 0 |
|
206 | self.nRdChannels = 0 | |
207 | self.nRdPairs = 0 |
|
207 | self.nRdPairs = 0 | |
208 | self.rdPairList = [] |
|
208 | self.rdPairList = [] | |
209 |
|
209 | |||
210 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
210 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
211 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
211 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
212 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
212 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
213 | else: |
|
213 | else: | |
214 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
214 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
215 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
215 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
216 |
|
216 | |||
217 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
217 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
218 |
|
218 | |||
219 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
219 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
220 | self.blocksize = self.pts2read_SelfSpectra |
|
220 | self.blocksize = self.pts2read_SelfSpectra | |
221 |
|
221 | |||
222 | if self.processingHeaderObj.flag_cspc: |
|
222 | if self.processingHeaderObj.flag_cspc: | |
223 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
223 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
224 | self.blocksize += self.pts2read_CrossSpectra |
|
224 | self.blocksize += self.pts2read_CrossSpectra | |
225 |
|
225 | |||
226 | if self.processingHeaderObj.flag_dc: |
|
226 | if self.processingHeaderObj.flag_dc: | |
227 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
227 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
228 | self.blocksize += self.pts2read_DCchannels |
|
228 | self.blocksize += self.pts2read_DCchannels | |
229 |
|
229 | |||
230 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
230 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
231 |
|
231 | |||
232 |
|
232 | |||
233 | def readBlock(self): |
|
233 | def readBlock(self): | |
234 | """ |
|
234 | """ | |
235 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
235 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
236 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
236 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
237 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
237 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
238 | es seteado a 0 |
|
238 | es seteado a 0 | |
239 |
|
239 | |||
240 | Return: None |
|
240 | Return: None | |
241 |
|
241 | |||
242 | Variables afectadas: |
|
242 | Variables afectadas: | |
243 |
|
243 | |||
244 | self.flagIsNewFile |
|
244 | self.flagIsNewFile | |
245 | self.flagIsNewBlock |
|
245 | self.flagIsNewBlock | |
246 | self.nTotalBlocks |
|
246 | self.nTotalBlocks | |
247 | self.data_spc |
|
247 | self.data_spc | |
248 | self.data_cspc |
|
248 | self.data_cspc | |
249 | self.data_dc |
|
249 | self.data_dc | |
250 |
|
250 | |||
251 | Exceptions: |
|
251 | Exceptions: | |
252 | Si un bloque leido no es un bloque valido |
|
252 | Si un bloque leido no es un bloque valido | |
253 | """ |
|
253 | """ | |
254 | blockOk_flag = False |
|
254 | blockOk_flag = False | |
255 | fpointer = self.fp.tell() |
|
255 | fpointer = self.fp.tell() | |
256 |
|
256 | |||
257 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
257 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
258 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
258 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
259 |
|
259 | |||
260 | if self.processingHeaderObj.flag_cspc: |
|
260 | if self.processingHeaderObj.flag_cspc: | |
261 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
261 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
262 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
262 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
263 |
|
263 | |||
264 | if self.processingHeaderObj.flag_dc: |
|
264 | if self.processingHeaderObj.flag_dc: | |
265 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
265 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
266 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
266 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
267 |
|
267 | |||
268 |
|
268 | |||
269 | if not(self.processingHeaderObj.shif_fft): |
|
269 | if not(self.processingHeaderObj.shif_fft): | |
270 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
270 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
271 |
|
271 | |||
272 | if self.processingHeaderObj.flag_cspc: |
|
272 | if self.processingHeaderObj.flag_cspc: | |
273 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
273 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
274 |
|
274 | |||
275 |
|
275 | |||
276 | spc = numpy.transpose( spc, (0,2,1) ) |
|
276 | spc = numpy.transpose( spc, (0,2,1) ) | |
277 | self.data_spc = spc |
|
277 | self.data_spc = spc | |
278 |
|
278 | |||
279 | if self.processingHeaderObj.flag_cspc: |
|
279 | if self.processingHeaderObj.flag_cspc: | |
280 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
280 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
281 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
281 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
282 | else: |
|
282 | else: | |
283 | self.data_cspc = None |
|
283 | self.data_cspc = None | |
284 |
|
284 | |||
285 | if self.processingHeaderObj.flag_dc: |
|
285 | if self.processingHeaderObj.flag_dc: | |
286 | self.data_dc = dc['real'] + dc['imag']*1j |
|
286 | self.data_dc = dc['real'] + dc['imag']*1j | |
287 | else: |
|
287 | else: | |
288 | self.data_dc = None |
|
288 | self.data_dc = None | |
289 |
|
289 | |||
290 | self.flagIsNewFile = 0 |
|
290 | self.flagIsNewFile = 0 | |
291 | self.flagIsNewBlock = 1 |
|
291 | self.flagIsNewBlock = 1 | |
292 |
|
292 | |||
293 | self.nTotalBlocks += 1 |
|
293 | self.nTotalBlocks += 1 | |
294 | self.nReadBlocks += 1 |
|
294 | self.nReadBlocks += 1 | |
295 |
|
295 | |||
296 | return 1 |
|
296 | return 1 | |
297 |
|
297 | |||
298 |
|
298 | |||
299 | def getData(self): |
|
299 | def getData(self): | |
300 | """ |
|
300 | """ | |
301 | Copia el buffer de lectura a la clase "Spectra", |
|
301 | Copia el buffer de lectura a la clase "Spectra", | |
302 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
302 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
303 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
303 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
304 |
|
304 | |||
305 | Return: |
|
305 | Return: | |
306 | 0 : Si no hay mas archivos disponibles |
|
306 | 0 : Si no hay mas archivos disponibles | |
307 | 1 : Si hizo una buena copia del buffer |
|
307 | 1 : Si hizo una buena copia del buffer | |
308 |
|
308 | |||
309 | Affected: |
|
309 | Affected: | |
310 | self.dataOutObj |
|
310 | self.dataOutObj | |
311 |
|
311 | |||
312 | self.flagTimeBlock |
|
312 | self.flagTimeBlock | |
313 | self.flagIsNewBlock |
|
313 | self.flagIsNewBlock | |
314 | """ |
|
314 | """ | |
315 |
|
315 | |||
316 | if self.flagNoMoreFiles: return 0 |
|
316 | if self.flagNoMoreFiles: return 0 | |
317 |
|
317 | |||
318 | self.flagTimeBlock = 0 |
|
318 | self.flagTimeBlock = 0 | |
319 | self.flagIsNewBlock = 0 |
|
319 | self.flagIsNewBlock = 0 | |
320 |
|
320 | |||
321 | if self.__hasNotDataInBuffer(): |
|
321 | if self.__hasNotDataInBuffer(): | |
322 |
|
322 | |||
323 | if not( self.readNextBlock() ): |
|
323 | if not( self.readNextBlock() ): | |
324 | return 0 |
|
324 | return 0 | |
325 |
|
325 | |||
326 | # self.updateDataHeader() |
|
326 | # self.updateDataHeader() | |
327 |
|
327 | |||
328 | if self.flagNoMoreFiles == 1: |
|
328 | if self.flagNoMoreFiles == 1: | |
329 | print 'Process finished' |
|
329 | print 'Process finished' | |
330 | return 0 |
|
330 | return 0 | |
331 |
|
331 | |||
332 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
332 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
333 |
|
333 | |||
334 | if self.data_dc == None: |
|
334 | if self.data_dc == None: | |
335 | self.dataOutObj.flagNoData = True |
|
335 | self.dataOutObj.flagNoData = True | |
336 | return 0 |
|
336 | return 0 | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | self.dataOutObj.data_spc = self.data_spc |
|
339 | self.dataOutObj.data_spc = self.data_spc | |
340 |
|
340 | |||
341 | self.dataOutObj.data_cspc = self.data_cspc |
|
341 | self.dataOutObj.data_cspc = self.data_cspc | |
342 |
|
342 | |||
343 | self.dataOutObj.data_dc = self.data_dc |
|
343 | self.dataOutObj.data_dc = self.data_dc | |
344 |
|
344 | |||
345 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
345 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
346 |
|
346 | |||
347 | self.dataOutObj.flagNoData = False |
|
347 | self.dataOutObj.flagNoData = False | |
348 |
|
348 | |||
349 | self.dataOutObj.dtype = self.dtype |
|
349 | self.dataOutObj.dtype = self.dtype | |
350 |
|
350 | |||
351 | self.dataOutObj.nChannels = self.nRdChannels |
|
351 | self.dataOutObj.nChannels = self.nRdChannels | |
352 |
|
352 | |||
353 | self.dataOutObj.nPairs = self.nRdPairs |
|
353 | self.dataOutObj.nPairs = self.nRdPairs | |
354 |
|
354 | |||
355 | self.dataOutObj.pairsList = self.rdPairList |
|
355 | self.dataOutObj.pairsList = self.rdPairList | |
356 |
|
356 | |||
357 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
357 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
358 |
|
358 | |||
359 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
359 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
360 |
|
360 | |||
361 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
361 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
362 |
|
362 | |||
363 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt |
|
363 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt | |
364 |
|
364 | |||
365 |
|
365 | |||
366 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
366 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
367 |
|
367 | |||
368 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
368 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
369 |
|
369 | |||
370 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
370 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
371 |
|
371 | |||
372 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
372 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
373 |
|
373 | |||
374 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
374 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
375 |
|
375 | |||
376 | self.dataOutObj.ippSeconds = self.ippSeconds |
|
376 | self.dataOutObj.ippSeconds = self.ippSeconds | |
377 |
|
377 | |||
378 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOutObj.nFFTPoints |
|
378 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOutObj.nFFTPoints | |
379 |
|
379 | |||
380 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
380 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft | |
381 |
|
381 | |||
382 | # self.profileIndex += 1 |
|
382 | # self.profileIndex += 1 | |
383 |
|
383 | |||
384 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
384 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
385 |
|
385 | |||
386 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
386 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
387 |
|
387 | |||
388 | return self.dataOutObj.data_spc |
|
388 | return self.dataOutObj.data_spc | |
389 |
|
389 | |||
390 |
|
390 | |||
391 | class SpectraWriter(JRODataWriter): |
|
391 | class SpectraWriter(JRODataWriter): | |
392 |
|
392 | |||
393 | """ |
|
393 | """ | |
394 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
394 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
395 | de los datos siempre se realiza por bloques. |
|
395 | de los datos siempre se realiza por bloques. | |
396 | """ |
|
396 | """ | |
397 |
|
397 | |||
398 | ext = ".pdata" |
|
398 | ext = ".pdata" | |
399 |
|
399 | |||
400 | optchar = "P" |
|
400 | optchar = "P" | |
401 |
|
401 | |||
402 | shape_spc_Buffer = None |
|
402 | shape_spc_Buffer = None | |
403 |
|
403 | |||
404 | shape_cspc_Buffer = None |
|
404 | shape_cspc_Buffer = None | |
405 |
|
405 | |||
406 | shape_dc_Buffer = None |
|
406 | shape_dc_Buffer = None | |
407 |
|
407 | |||
408 | data_spc = None |
|
408 | data_spc = None | |
409 |
|
409 | |||
410 | data_cspc = None |
|
410 | data_cspc = None | |
411 |
|
411 | |||
412 | data_dc = None |
|
412 | data_dc = None | |
413 |
|
413 | |||
414 | wrPairList = [] |
|
414 | wrPairList = [] | |
415 |
|
415 | |||
416 | nWrPairs = 0 |
|
416 | nWrPairs = 0 | |
417 |
|
417 | |||
418 | nWrChannels = 0 |
|
418 | nWrChannels = 0 | |
419 |
|
419 | |||
420 | # dataOutObj = None |
|
420 | # dataOutObj = None | |
421 |
|
421 | |||
422 | def __init__(self, dataOutObj=None): |
|
422 | def __init__(self, dataOutObj=None): | |
423 | """ |
|
423 | """ | |
424 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
424 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
425 |
|
425 | |||
426 | Affected: |
|
426 | Affected: | |
427 | self.dataOutObj |
|
427 | self.dataOutObj | |
428 | self.basicHeaderObj |
|
428 | self.basicHeaderObj | |
429 | self.systemHeaderObj |
|
429 | self.systemHeaderObj | |
430 | self.radarControllerHeaderObj |
|
430 | self.radarControllerHeaderObj | |
431 | self.processingHeaderObj |
|
431 | self.processingHeaderObj | |
432 |
|
432 | |||
433 | Return: None |
|
433 | Return: None | |
434 | """ |
|
434 | """ | |
435 | if dataOutObj == None: |
|
435 | if dataOutObj == None: | |
436 | dataOutObj = Spectra() |
|
436 | dataOutObj = Spectra() | |
437 |
|
437 | |||
438 | if not( isinstance(dataOutObj, Spectra) ): |
|
438 | if not( isinstance(dataOutObj, Spectra) ): | |
439 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" |
|
439 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" | |
440 |
|
440 | |||
441 | self.dataOutObj = dataOutObj |
|
441 | self.dataOutObj = dataOutObj | |
442 |
|
442 | |||
443 | self.nTotalBlocks = 0 |
|
443 | self.nTotalBlocks = 0 | |
444 |
|
444 | |||
445 | self.nWrChannels = self.dataOutObj.nChannels |
|
445 | self.nWrChannels = self.dataOutObj.nChannels | |
446 |
|
446 | |||
447 | # if len(pairList) > 0: |
|
447 | # if len(pairList) > 0: | |
448 | # self.wrPairList = pairList |
|
448 | # self.wrPairList = pairList | |
449 | # |
|
449 | # | |
450 | # self.nWrPairs = len(pairList) |
|
450 | # self.nWrPairs = len(pairList) | |
451 |
|
451 | |||
452 | self.wrPairList = self.dataOutObj.pairsList |
|
452 | self.wrPairList = self.dataOutObj.pairsList | |
453 |
|
453 | |||
454 | self.nWrPairs = self.dataOutObj.nPairs |
|
454 | self.nWrPairs = self.dataOutObj.nPairs | |
455 |
|
455 | |||
456 | # self.data_spc = None |
|
456 | # self.data_spc = None | |
457 | # self.data_cspc = None |
|
457 | # self.data_cspc = None | |
458 | # self.data_dc = None |
|
458 | # self.data_dc = None | |
459 |
|
459 | |||
460 | # self.fp = None |
|
460 | # self.fp = None | |
461 |
|
461 | |||
462 | # self.flagIsNewFile = 1 |
|
462 | # self.flagIsNewFile = 1 | |
463 | # |
|
463 | # | |
464 | # self.nTotalBlocks = 0 |
|
464 | # self.nTotalBlocks = 0 | |
465 | # |
|
465 | # | |
466 | # self.flagIsNewBlock = 0 |
|
466 | # self.flagIsNewBlock = 0 | |
467 | # |
|
467 | # | |
468 | # self.flagNoMoreFiles = 0 |
|
468 | # self.flagNoMoreFiles = 0 | |
469 | # |
|
469 | # | |
470 | # self.setFile = None |
|
470 | # self.setFile = None | |
471 | # |
|
471 | # | |
472 | # self.dtype = None |
|
472 | # self.dtype = None | |
473 | # |
|
473 | # | |
474 | # self.path = None |
|
474 | # self.path = None | |
475 | # |
|
475 | # | |
476 | # self.noMoreFiles = 0 |
|
476 | # self.noMoreFiles = 0 | |
477 | # |
|
477 | # | |
478 | # self.filename = None |
|
478 | # self.filename = None | |
479 | # |
|
479 | # | |
480 | # self.basicHeaderObj = BasicHeader() |
|
480 | # self.basicHeaderObj = BasicHeader() | |
481 | # |
|
481 | # | |
482 | # self.systemHeaderObj = SystemHeader() |
|
482 | # self.systemHeaderObj = SystemHeader() | |
483 | # |
|
483 | # | |
484 | # self.radarControllerHeaderObj = RadarControllerHeader() |
|
484 | # self.radarControllerHeaderObj = RadarControllerHeader() | |
485 | # |
|
485 | # | |
486 | # self.processingHeaderObj = ProcessingHeader() |
|
486 | # self.processingHeaderObj = ProcessingHeader() | |
487 |
|
487 | |||
488 |
|
488 | |||
489 | def hasAllDataInBuffer(self): |
|
489 | def hasAllDataInBuffer(self): | |
490 | return 1 |
|
490 | return 1 | |
491 |
|
491 | |||
492 |
|
492 | |||
493 | def setBlockDimension(self): |
|
493 | def setBlockDimension(self): | |
494 | """ |
|
494 | """ | |
495 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
495 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
496 |
|
496 | |||
497 | Affected: |
|
497 | Affected: | |
498 | self.shape_spc_Buffer |
|
498 | self.shape_spc_Buffer | |
499 | self.shape_cspc_Buffer |
|
499 | self.shape_cspc_Buffer | |
500 | self.shape_dc_Buffer |
|
500 | self.shape_dc_Buffer | |
501 |
|
501 | |||
502 | Return: None |
|
502 | Return: None | |
503 | """ |
|
503 | """ | |
504 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, |
|
504 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, | |
505 | self.processingHeaderObj.nHeights, |
|
505 | self.processingHeaderObj.nHeights, | |
506 | self.processingHeaderObj.profilesPerBlock) |
|
506 | self.processingHeaderObj.profilesPerBlock) | |
507 |
|
507 | |||
508 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, |
|
508 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, | |
509 | self.processingHeaderObj.nHeights, |
|
509 | self.processingHeaderObj.nHeights, | |
510 | self.processingHeaderObj.profilesPerBlock) |
|
510 | self.processingHeaderObj.profilesPerBlock) | |
511 |
|
511 | |||
512 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, |
|
512 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, | |
513 | self.processingHeaderObj.nHeights) |
|
513 | self.processingHeaderObj.nHeights) | |
514 |
|
514 | |||
515 |
|
515 | |||
516 | def writeBlock(self): |
|
516 | def writeBlock(self): | |
517 | """ |
|
517 | """ | |
518 | Escribe el buffer en el file designado |
|
518 | Escribe el buffer en el file designado | |
519 |
|
519 | |||
520 | Affected: |
|
520 | Affected: | |
521 | self.data_spc |
|
521 | self.data_spc | |
522 | self.data_cspc |
|
522 | self.data_cspc | |
523 | self.data_dc |
|
523 | self.data_dc | |
524 | self.flagIsNewFile |
|
524 | self.flagIsNewFile | |
525 | self.flagIsNewBlock |
|
525 | self.flagIsNewBlock | |
526 | self.nTotalBlocks |
|
526 | self.nTotalBlocks | |
527 | self.nWriteBlocks |
|
527 | self.nWriteBlocks | |
528 |
|
528 | |||
529 | Return: None |
|
529 | Return: None | |
530 | """ |
|
530 | """ | |
531 |
|
531 | |||
532 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
532 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
533 | if not( self.processingHeaderObj.shif_fft ): |
|
533 | if not( self.processingHeaderObj.shif_fft ): | |
534 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
534 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
535 | data = spc.reshape((-1)) |
|
535 | data = spc.reshape((-1)) | |
536 | data.tofile(self.fp) |
|
536 | data.tofile(self.fp) | |
537 |
|
537 | |||
538 | if self.data_cspc != None: |
|
538 | if self.data_cspc != None: | |
539 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
539 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
540 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
540 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
541 | if not( self.processingHeaderObj.shif_fft ): |
|
541 | if not( self.processingHeaderObj.shif_fft ): | |
542 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
542 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
543 | data['real'] = cspc.real |
|
543 | data['real'] = cspc.real | |
544 | data['imag'] = cspc.imag |
|
544 | data['imag'] = cspc.imag | |
545 | data = data.reshape((-1)) |
|
545 | data = data.reshape((-1)) | |
546 | data.tofile(self.fp) |
|
546 | data.tofile(self.fp) | |
547 |
|
547 | |||
548 | if self.data_dc != None: |
|
548 | if self.data_dc != None: | |
549 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
549 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
550 | dc = self.data_dc |
|
550 | dc = self.data_dc | |
551 | data['real'] = dc.real |
|
551 | data['real'] = dc.real | |
552 | data['imag'] = dc.imag |
|
552 | data['imag'] = dc.imag | |
553 | data = data.reshape((-1)) |
|
553 | data = data.reshape((-1)) | |
554 | data.tofile(self.fp) |
|
554 | data.tofile(self.fp) | |
555 |
|
555 | |||
556 | self.data_spc.fill(0) |
|
556 | self.data_spc.fill(0) | |
557 | self.data_dc.fill(0) |
|
557 | self.data_dc.fill(0) | |
558 | if self.data_cspc != None: |
|
558 | if self.data_cspc != None: | |
559 | self.data_cspc.fill(0) |
|
559 | self.data_cspc.fill(0) | |
560 |
|
560 | |||
561 | self.flagIsNewFile = 0 |
|
561 | self.flagIsNewFile = 0 | |
562 | self.flagIsNewBlock = 1 |
|
562 | self.flagIsNewBlock = 1 | |
563 | self.nTotalBlocks += 1 |
|
563 | self.nTotalBlocks += 1 | |
564 | self.nWriteBlocks += 1 |
|
564 | self.nWriteBlocks += 1 | |
565 | self.blockIndex += 1 |
|
565 | self.blockIndex += 1 | |
566 |
|
566 | |||
567 |
|
567 | |||
568 | def putData(self): |
|
568 | def putData(self): | |
569 | """ |
|
569 | """ | |
570 | Setea un bloque de datos y luego los escribe en un file |
|
570 | Setea un bloque de datos y luego los escribe en un file | |
571 |
|
571 | |||
572 | Affected: |
|
572 | Affected: | |
573 | self.data_spc |
|
573 | self.data_spc | |
574 | self.data_cspc |
|
574 | self.data_cspc | |
575 | self.data_dc |
|
575 | self.data_dc | |
576 |
|
576 | |||
577 | Return: |
|
577 | Return: | |
578 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
578 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
579 | 1 : Si se escribio la data de un bloque en un file |
|
579 | 1 : Si se escribio la data de un bloque en un file | |
580 | """ |
|
580 | """ | |
581 | self.flagIsNewBlock = 0 |
|
581 | self.flagIsNewBlock = 0 | |
582 |
|
582 | |||
583 | if self.dataOutObj.flagNoData: |
|
583 | if self.dataOutObj.flagNoData: | |
584 | return 0 |
|
584 | return 0 | |
585 |
|
585 | |||
586 | if self.dataOutObj.flagTimeBlock: |
|
586 | if self.dataOutObj.flagTimeBlock: | |
587 | self.data_spc.fill(0) |
|
587 | self.data_spc.fill(0) | |
588 | self.data_cspc.fill(0) |
|
588 | self.data_cspc.fill(0) | |
589 | self.data_dc.fill(0) |
|
589 | self.data_dc.fill(0) | |
590 | self.setNextFile() |
|
590 | self.setNextFile() | |
591 |
|
591 | |||
592 | if self.flagIsNewFile == 0: |
|
592 | if self.flagIsNewFile == 0: | |
593 | self.getBasicHeader() |
|
593 | self.getBasicHeader() | |
594 |
|
594 | |||
595 | self.data_spc = self.dataOutObj.data_spc |
|
595 | self.data_spc = self.dataOutObj.data_spc | |
596 | self.data_cspc = self.dataOutObj.data_cspc |
|
596 | self.data_cspc = self.dataOutObj.data_cspc | |
597 | self.data_dc = self.dataOutObj.data_dc |
|
597 | self.data_dc = self.dataOutObj.data_dc | |
598 |
|
598 | |||
599 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
599 | # #self.processingHeaderObj.dataBlocksPerFile) | |
600 | if self.hasAllDataInBuffer(): |
|
600 | if self.hasAllDataInBuffer(): | |
601 | # self.getDataHeader() |
|
601 | # self.getDataHeader() | |
602 | self.writeNextBlock() |
|
602 | self.writeNextBlock() | |
603 |
|
603 | |||
604 | if self.flagNoMoreFiles: |
|
604 | if self.flagNoMoreFiles: | |
605 | #print 'Process finished' |
|
605 | #print 'Process finished' | |
606 | return 0 |
|
606 | return 0 | |
607 |
|
||||
608 | return 1 |
|
607 | return 1 | |
609 |
|
608 | |||
610 |
|
609 | |||
611 | def __getProcessFlags(self): |
|
610 | def __getProcessFlags(self): | |
612 |
|
611 | |||
613 | processFlags = 0 |
|
612 | processFlags = 0 | |
614 |
|
613 | |||
615 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
614 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
616 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
615 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
617 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
616 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
618 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
617 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
619 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
618 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
620 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
619 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
621 |
|
620 | |||
622 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
621 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
623 |
|
622 | |||
624 |
|
623 | |||
625 |
|
624 | |||
626 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
625 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
627 | PROCFLAG.DATATYPE_SHORT, |
|
626 | PROCFLAG.DATATYPE_SHORT, | |
628 | PROCFLAG.DATATYPE_LONG, |
|
627 | PROCFLAG.DATATYPE_LONG, | |
629 | PROCFLAG.DATATYPE_INT64, |
|
628 | PROCFLAG.DATATYPE_INT64, | |
630 | PROCFLAG.DATATYPE_FLOAT, |
|
629 | PROCFLAG.DATATYPE_FLOAT, | |
631 | PROCFLAG.DATATYPE_DOUBLE] |
|
630 | PROCFLAG.DATATYPE_DOUBLE] | |
632 |
|
631 | |||
633 |
|
632 | |||
634 | for index in range(len(dtypeList)): |
|
633 | for index in range(len(dtypeList)): | |
635 | if self.dataOutObj.dtype == dtypeList[index]: |
|
634 | if self.dataOutObj.dtype == dtypeList[index]: | |
636 | dtypeValue = datatypeValueList[index] |
|
635 | dtypeValue = datatypeValueList[index] | |
637 | break |
|
636 | break | |
638 |
|
637 | |||
639 | processFlags += dtypeValue |
|
638 | processFlags += dtypeValue | |
640 |
|
639 | |||
641 | if self.dataOutObj.flagDecodeData: |
|
640 | if self.dataOutObj.flagDecodeData: | |
642 | processFlags += PROCFLAG.DECODE_DATA |
|
641 | processFlags += PROCFLAG.DECODE_DATA | |
643 |
|
642 | |||
644 | if self.dataOutObj.flagDeflipData: |
|
643 | if self.dataOutObj.flagDeflipData: | |
645 | processFlags += PROCFLAG.DEFLIP_DATA |
|
644 | processFlags += PROCFLAG.DEFLIP_DATA | |
646 |
|
645 | |||
647 | if self.dataOutObj.code != None: |
|
646 | if self.dataOutObj.code != None: | |
648 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
647 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
649 |
|
648 | |||
650 | if self.dataOutObj.nIncohInt > 1: |
|
649 | if self.dataOutObj.nIncohInt > 1: | |
651 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
650 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
652 |
|
651 | |||
653 | if self.dataOutObj.data_dc != None: |
|
652 | if self.dataOutObj.data_dc != None: | |
654 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
653 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
655 |
|
654 | |||
656 | return processFlags |
|
655 | return processFlags | |
657 |
|
656 | |||
658 |
|
657 | |||
659 | def __getBlockSize(self): |
|
658 | def __getBlockSize(self): | |
660 | ''' |
|
659 | ''' | |
661 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
660 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
662 | ''' |
|
661 | ''' | |
663 |
|
662 | |||
664 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
663 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
665 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
664 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
666 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
665 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
667 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
666 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
668 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
667 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
669 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
668 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
670 |
|
669 | |||
671 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
670 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
672 | datatypeValueList = [1,2,4,8,4,8] |
|
671 | datatypeValueList = [1,2,4,8,4,8] | |
673 | for index in range(len(dtypeList)): |
|
672 | for index in range(len(dtypeList)): | |
674 | if self.dataOutObj.dtype == dtypeList[index]: |
|
673 | if self.dataOutObj.dtype == dtypeList[index]: | |
675 | datatypeValue = datatypeValueList[index] |
|
674 | datatypeValue = datatypeValueList[index] | |
676 | break |
|
675 | break | |
677 |
|
676 | |||
678 |
|
677 | |||
679 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints |
|
678 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints | |
680 |
|
679 | |||
681 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) |
|
680 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) | |
682 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
681 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
683 |
|
682 | |||
684 | if self.dataOutObj.data_cspc != None: |
|
683 | if self.dataOutObj.data_cspc != None: | |
685 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) |
|
684 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) | |
686 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
685 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
687 |
|
686 | |||
688 | if self.dataOutObj.data_dc != None: |
|
687 | if self.dataOutObj.data_dc != None: | |
689 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) |
|
688 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) | |
690 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
689 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
691 |
|
690 | |||
692 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
691 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
693 |
|
692 | |||
694 | return blocksize |
|
693 | return blocksize | |
695 |
|
694 | |||
696 |
|
695 | |||
697 | def getBasicHeader(self): |
|
696 | def getBasicHeader(self): | |
698 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
697 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
699 | self.basicHeaderObj.version = self.versionFile |
|
698 | self.basicHeaderObj.version = self.versionFile | |
700 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
699 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
701 |
|
700 | |||
702 | utc = numpy.floor(self.dataOutObj.utctime) |
|
701 | utc = numpy.floor(self.dataOutObj.utctime) | |
703 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 |
|
702 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 | |
704 |
|
703 | |||
705 | self.basicHeaderObj.utc = utc |
|
704 | self.basicHeaderObj.utc = utc | |
706 | self.basicHeaderObj.miliSecond = milisecond |
|
705 | self.basicHeaderObj.miliSecond = milisecond | |
707 | self.basicHeaderObj.timeZone = 0 |
|
706 | self.basicHeaderObj.timeZone = 0 | |
708 | self.basicHeaderObj.dstFlag = 0 |
|
707 | self.basicHeaderObj.dstFlag = 0 | |
709 | self.basicHeaderObj.errorCount = 0 |
|
708 | self.basicHeaderObj.errorCount = 0 | |
710 |
|
709 | |||
711 | def getDataHeader(self): |
|
710 | def getDataHeader(self): | |
712 |
|
711 | |||
713 | """ |
|
712 | """ | |
714 | Obtiene una copia del First Header |
|
713 | Obtiene una copia del First Header | |
715 |
|
714 | |||
716 | Affected: |
|
715 | Affected: | |
717 | self.systemHeaderObj |
|
716 | self.systemHeaderObj | |
718 | self.radarControllerHeaderObj |
|
717 | self.radarControllerHeaderObj | |
719 | self.dtype |
|
718 | self.dtype | |
720 |
|
719 | |||
721 | Return: |
|
720 | Return: | |
722 | None |
|
721 | None | |
723 | """ |
|
722 | """ | |
724 |
|
723 | |||
725 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
724 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
726 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
725 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
727 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
726 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
728 |
|
727 | |||
729 | self.getBasicHeader() |
|
728 | self.getBasicHeader() | |
730 |
|
729 | |||
731 | processingHeaderSize = 40 # bytes |
|
730 | processingHeaderSize = 40 # bytes | |
732 | self.processingHeaderObj.dtype = 0 # Voltage |
|
731 | self.processingHeaderObj.dtype = 0 # Voltage | |
733 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
732 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
734 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints |
|
733 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints | |
735 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
734 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
736 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
735 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
737 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
736 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
738 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt# Se requiere para determinar el valor de timeInterval |
|
737 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt# Se requiere para determinar el valor de timeInterval | |
739 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt |
|
738 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt | |
740 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels |
|
739 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels | |
741 |
|
740 | |||
742 | if self.processingHeaderObj.totalSpectra > 0: |
|
741 | if self.processingHeaderObj.totalSpectra > 0: | |
743 | channelList = [] |
|
742 | channelList = [] | |
744 | for channel in range(self.dataOutObj.nChannels): |
|
743 | for channel in range(self.dataOutObj.nChannels): | |
745 | channelList.append(channel) |
|
744 | channelList.append(channel) | |
746 | channelList.append(channel) |
|
745 | channelList.append(channel) | |
747 |
|
746 | |||
748 | pairsList = [] |
|
747 | pairsList = [] | |
749 | for pair in self.dataOutObj.pairsList: |
|
748 | for pair in self.dataOutObj.pairsList: | |
750 | pairsList.append(pair[0]) |
|
749 | pairsList.append(pair[0]) | |
751 | pairsList.append(pair[1]) |
|
750 | pairsList.append(pair[1]) | |
752 | spectraComb = channelList + pairsList |
|
751 | spectraComb = channelList + pairsList | |
753 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
752 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
754 | self.processingHeaderObj.spectraComb = spectraComb |
|
753 | self.processingHeaderObj.spectraComb = spectraComb | |
755 | sizeOfSpcComb = len(spectraComb) |
|
754 | sizeOfSpcComb = len(spectraComb) | |
756 | processingHeaderSize += sizeOfSpcComb |
|
755 | processingHeaderSize += sizeOfSpcComb | |
757 |
|
756 | |||
758 | if self.dataOutObj.code != None: |
|
757 | if self.dataOutObj.code != None: | |
759 | self.processingHeaderObj.code = self.dataOutObj.code |
|
758 | self.processingHeaderObj.code = self.dataOutObj.code | |
760 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
759 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
761 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
760 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
762 | nCodeSize = 4 # bytes |
|
761 | nCodeSize = 4 # bytes | |
763 | nBaudSize = 4 # bytes |
|
762 | nBaudSize = 4 # bytes | |
764 | codeSize = 4 # bytes |
|
763 | codeSize = 4 # bytes | |
765 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
764 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
766 | processingHeaderSize += sizeOfCode |
|
765 | processingHeaderSize += sizeOfCode | |
767 |
|
766 | |||
768 | if self.processingHeaderObj.nWindows != 0: |
|
767 | if self.processingHeaderObj.nWindows != 0: | |
769 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
768 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
770 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
769 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
771 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
770 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
772 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
771 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
773 | sizeOfFirstHeight = 4 |
|
772 | sizeOfFirstHeight = 4 | |
774 | sizeOfdeltaHeight = 4 |
|
773 | sizeOfdeltaHeight = 4 | |
775 | sizeOfnHeights = 4 |
|
774 | sizeOfnHeights = 4 | |
776 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
775 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
777 | processingHeaderSize += sizeOfWindows |
|
776 | processingHeaderSize += sizeOfWindows | |
778 |
|
777 | |||
779 | self.processingHeaderObj.size = processingHeaderSize |
|
778 | self.processingHeaderObj.size = processingHeaderSize | |
780 |
|
779 | |||
781 |
|
780 | |||
782 |
|
781 | |||
783 | class FITS: |
|
782 | class FITS: | |
784 | name=None |
|
783 | name=None | |
785 | format=None |
|
784 | format=None | |
786 | array =None |
|
785 | array =None | |
787 | data =None |
|
786 | data =None | |
788 | thdulist=None |
|
787 | thdulist=None | |
|
788 | prihdr=None | |||
|
789 | hdu=None | |||
789 |
|
790 | |||
790 | def __init__(self): |
|
791 | def __init__(self): | |
791 |
|
792 | |||
792 | pass |
|
793 | pass | |
793 |
|
794 | |||
794 | def setColF(self,name,format,array): |
|
795 | def setColF(self,name,format,array): | |
795 | self.name=name |
|
796 | self.name=name | |
796 | self.format=format |
|
797 | self.format=format | |
797 | self.array=array |
|
798 | self.array=array | |
798 | a1=numpy.array([self.array],dtype=numpy.float32) |
|
799 | a1=numpy.array([self.array],dtype=numpy.float32) | |
799 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) |
|
800 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
800 | return self.col1 |
|
801 | return self.col1 | |
801 |
|
802 | |||
802 | # def setColP(self,name,format,data): |
|
803 | # def setColP(self,name,format,data): | |
803 | # self.name=name |
|
804 | # self.name=name | |
804 | # self.format=format |
|
805 | # self.format=format | |
805 | # self.data=data |
|
806 | # self.data=data | |
806 | # a2=numpy.array([self.data],dtype=numpy.float32) |
|
807 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
807 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
808 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
808 | # return self.col2 |
|
809 | # return self.col2 | |
809 |
|
810 | |||
810 | def writeHeader(self,): |
|
|||
811 | pass |
|
|||
812 |
|
811 | |||
813 | def writeData(self,name,format,data): |
|
812 | def writeData(self,name,format,data): | |
814 | self.name=name |
|
813 | self.name=name | |
815 | self.format=format |
|
814 | self.format=format | |
816 | self.data=data |
|
815 | self.data=data | |
817 | a2=numpy.array([self.data],dtype=numpy.float32) |
|
816 | a2=numpy.array([self.data],dtype=numpy.float32) | |
818 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
817 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
819 | return self.col2 |
|
818 | return self.col2 | |
820 |
|
819 | |||
821 | def cFImage(self,n): |
|
820 | def cFImage(self,idblock,year,month,day,hour,minute,second): | |
822 |
self.hdu= pyfits.PrimaryHDU( |
|
821 | self.hdu= pyfits.PrimaryHDU(idblock) | |
|
822 | self.hdu.header.set("Year",year) | |||
|
823 | self.hdu.header.set("Month",month) | |||
|
824 | self.hdu.header.set("Day",day) | |||
|
825 | self.hdu.header.set("Hour",hour) | |||
|
826 | self.hdu.header.set("Minute",minute) | |||
|
827 | self.hdu.header.set("Second",second) | |||
823 | return self.hdu |
|
828 | return self.hdu | |
824 |
|
829 | |||
825 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): |
|
830 | ||
826 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) |
|
831 | def Ctable(self,colList): | |
|
832 | self.cols=pyfits.ColDefs(colList) | |||
827 | self.tbhdu = pyfits.new_table(self.cols) |
|
833 | self.tbhdu = pyfits.new_table(self.cols) | |
828 | return self.tbhdu |
|
834 | return self.tbhdu | |
829 |
|
835 | |||
|
836 | ||||
830 | def CFile(self,hdu,tbhdu): |
|
837 | def CFile(self,hdu,tbhdu): | |
831 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) |
|
838 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
832 |
|
839 | |||
833 | def wFile(self,filename): |
|
840 | def wFile(self,filename): | |
834 | self.thdulist.writeto(filename) |
|
841 | self.thdulist.writeto(filename) | |
835 |
|
842 | |||
836 | class SpectraHeisWriter(): |
|
843 | class SpectraHeisWriter(JRODataWriter): | |
837 | i=0 |
|
844 | set = None | |
|
845 | setFile = None | |||
|
846 | idblock = None | |||
|
847 | doypath = None | |||
|
848 | subfolder = None | |||
|
849 | ||||
838 | def __init__(self, dataOutObj): |
|
850 | def __init__(self, dataOutObj): | |
839 | self.wrObj = FITS() |
|
851 | self.wrObj = FITS() | |
840 | self.dataOutObj = dataOutObj |
|
852 | self.dataOutObj = dataOutObj | |
|
853 | self.nTotalBlocks=0 | |||
|
854 | self.set = None | |||
|
855 | self.setFile = 0 | |||
|
856 | self.idblock = 0 | |||
|
857 | self.wrpath = None | |||
|
858 | self.doypath = None | |||
|
859 | self.subfolder = None | |||
|
860 | ||||
841 |
|
861 | |||
842 | def isNumber(str): |
|
862 | def isNumber(str): | |
843 | """ |
|
863 | """ | |
844 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
864 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
845 |
|
865 | |||
846 | Excepciones: |
|
866 | Excepciones: | |
847 | Si un determinado string no puede ser convertido a numero |
|
867 | Si un determinado string no puede ser convertido a numero | |
848 | Input: |
|
868 | Input: | |
849 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
869 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
850 |
|
870 | |||
851 | Return: |
|
871 | Return: | |
852 | True : si el string es uno numerico |
|
872 | True : si el string es uno numerico | |
853 | False : no es un string numerico |
|
873 | False : no es un string numerico | |
854 | """ |
|
874 | """ | |
855 | try: |
|
875 | try: | |
856 | float( str ) |
|
876 | float( str ) | |
857 | return True |
|
877 | return True | |
858 | except: |
|
878 | except: | |
859 | return False |
|
879 | return False | |
860 |
|
880 | |||
861 |
def setup(self, wrpath |
|
881 | def setup(self, wrpath): | |
862 |
|
882 | |||
863 | if not(os.path.exists(wrpath)): |
|
883 | if not(os.path.exists(wrpath)): | |
864 | os.mkdir(wrpath) |
|
884 | os.mkdir(wrpath) | |
865 |
|
885 | |||
866 | self.wrpath = wrpath |
|
886 | self.wrpath = wrpath | |
867 | self.setFile = 0 |
|
887 | self.setFile = 0 | |
868 |
|
888 | |||
869 | def putData(self): |
|
889 | def putData(self): | |
870 | # self.wrObj.writeHeader(nChannels=self.dataOutObj.nChannels, nFFTPoints=self.dataOutObj.nFFTPoints) |
|
|||
871 | #name = self.dataOutObj.utctime |
|
|||
872 | name= time.localtime( self.dataOutObj.utctime) |
|
890 | name= time.localtime( self.dataOutObj.utctime) | |
873 | ext=".fits" |
|
891 | ext=".fits" | |
874 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) |
|
|||
875 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) |
|
|||
876 |
|
892 | |||
877 | doypath = os.path.join( self.wrpath, subfolder ) |
|
893 | if self.doypath == None: | |
878 | if not( os.path.exists(doypath) ): |
|
894 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) | |
879 | os.mkdir(doypath) |
|
895 | self.doypath = os.path.join( self.wrpath, self.subfolder ) | |
880 | self.setFile += 1 |
|
896 | os.mkdir(self.doypath) | |
881 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
897 | ||
882 |
|
898 | if self.set == None: | ||
883 | filename = os.path.join(self.wrpath,subfolder, file) |
|
899 | self.set = self.dataOutObj.set | |
884 |
|
900 | self.setFile = 0 | ||
885 |
|
|
901 | if self.set != self.dataOutObj.set: | |
886 | freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)/(2*self.dataOutObj.ippSeconds) |
|
902 | self.set = self.dataOutObj.set | |
887 |
|
903 | self.setFile = 0 | ||
888 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq) |
|
904 | ||
889 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[0,:])) |
|
905 | #make the filename | |
890 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[1,:])) |
|
906 | file = 'D%4.4d%3.3d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.set,self.setFile,ext) | |
891 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[2,:])) |
|
907 | ||
892 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[3,:])) |
|
908 | filename = os.path.join(self.wrpath,self.subfolder, file) | |
893 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[4,:])) |
|
909 | ||
894 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[5,:])) |
|
910 | idblock = numpy.array([self.idblock],dtype="int64") | |
895 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[6,:])) |
|
911 | header=self.wrObj.cFImage(idblock=idblock, | |
896 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[7,:])) |
|
912 | year=time.gmtime(self.dataOutObj.utctime).tm_year, | |
897 | #n=numpy.arange((100)) |
|
913 | month=time.gmtime(self.dataOutObj.utctime).tm_mon, | |
898 | n=self.dataOutObj.data_spc[6,:] |
|
914 | day=time.gmtime(self.dataOutObj.utctime).tm_mday, | |
899 | a=self.wrObj.cFImage(n) |
|
915 | hour=time.gmtime(self.dataOutObj.utctime).tm_hour, | |
900 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) |
|
916 | minute=time.gmtime(self.dataOutObj.utctime).tm_min, | |
901 | self.wrObj.CFile(a,b) |
|
917 | second=time.gmtime(self.dataOutObj.utctime).tm_sec) | |
|
918 | ||||
|
919 | c=3E8 | |||
|
920 | freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*1000)) | |||
|
921 | ||||
|
922 | colList = [] | |||
|
923 | ||||
|
924 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq) | |||
|
925 | ||||
|
926 | colList.append(colFreq) | |||
|
927 | ||||
|
928 | nchannel=self.dataOutObj.nChannels | |||
|
929 | ||||
|
930 | for i in range(nchannel): | |||
|
931 | col = self.wrObj.writeData(name="PCh"+str(i+1), | |||
|
932 | format=str(self.dataOutObj.nFFTPoints)+'E', | |||
|
933 | data=10*numpy.log10(self.dataOutObj.data_spc[i,:])) | |||
|
934 | ||||
|
935 | colList.append(col) | |||
|
936 | ||||
|
937 | data=self.wrObj.Ctable(colList=colList) | |||
|
938 | ||||
|
939 | self.wrObj.CFile(header,data) | |||
|
940 | ||||
902 | self.wrObj.wFile(filename) |
|
941 | self.wrObj.wFile(filename) | |
|
942 | ||||
|
943 | #update the setFile | |||
|
944 | self.setFile += 1 | |||
|
945 | self.idblock += 1 | |||
|
946 | ||||
903 | return 1 |
|
947 | return 1 | |
904 |
|
948 | |||
905 | No newline at end of file |
|
949 |
@@ -1,592 +1,602 | |||||
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 __getset(self,filename): | |||
|
233 | name = os.path.basename(filename) | |||
|
234 | basename,ext = os.path.splitext(name) | |||
|
235 | set = int(basename[8:]) | |||
|
236 | return set | |||
|
237 | ||||
232 | def getData(self): |
|
238 | def getData(self): | |
233 | """ |
|
239 | """ | |
234 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
240 | 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 |
|
241 | 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" |
|
242 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
237 |
|
243 | |||
238 | Ademas incrementa el contador del buffer en 1. |
|
244 | Ademas incrementa el contador del buffer en 1. | |
239 |
|
245 | |||
240 | Return: |
|
246 | Return: | |
241 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
247 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
242 | buffer. Si no hay mas archivos a leer retorna None. |
|
248 | buffer. Si no hay mas archivos a leer retorna None. | |
243 |
|
249 | |||
244 | Variables afectadas: |
|
250 | Variables afectadas: | |
245 | self.dataOutObj |
|
251 | self.dataOutObj | |
246 | self.profileIndex |
|
252 | self.profileIndex | |
247 |
|
253 | |||
248 | Affected: |
|
254 | Affected: | |
249 | self.dataOutObj |
|
255 | self.dataOutObj | |
250 | self.profileIndex |
|
256 | self.profileIndex | |
251 | self.flagTimeBlock |
|
257 | self.flagTimeBlock | |
252 | self.flagIsNewBlock |
|
258 | self.flagIsNewBlock | |
253 | """ |
|
259 | """ | |
254 | if self.flagNoMoreFiles: return 0 |
|
260 | if self.flagNoMoreFiles: return 0 | |
255 |
|
261 | |||
256 | self.flagTimeBlock = 0 |
|
262 | self.flagTimeBlock = 0 | |
257 | self.flagIsNewBlock = 0 |
|
263 | self.flagIsNewBlock = 0 | |
258 |
|
264 | |||
259 | if self.__hasNotDataInBuffer(): |
|
265 | if self.__hasNotDataInBuffer(): | |
260 |
|
266 | |||
261 | if not( self.readNextBlock() ): |
|
267 | if not( self.readNextBlock() ): | |
262 | return 0 |
|
268 | return 0 | |
263 |
|
269 | |||
264 | # self.updateDataHeader() |
|
270 | # self.updateDataHeader() | |
265 |
|
271 | |||
266 | if self.flagNoMoreFiles == 1: |
|
272 | if self.flagNoMoreFiles == 1: | |
267 | print 'Process finished' |
|
273 | print 'Process finished' | |
268 | return 0 |
|
274 | return 0 | |
269 |
|
275 | |||
270 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
276 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
271 |
|
277 | |||
272 | if self.datablock == None: |
|
278 | if self.datablock == None: | |
273 | self.dataOutObj.flagNoData = True |
|
279 | self.dataOutObj.flagNoData = True | |
274 | return 0 |
|
280 | return 0 | |
275 |
|
281 | |||
|
282 | self.dataOutObj.set = self.__getset(self.filename) | |||
|
283 | ||||
276 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] |
|
284 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] | |
277 |
|
285 | |||
278 | self.dataOutObj.dtype = self.dtype |
|
286 | self.dataOutObj.dtype = self.dtype | |
279 |
|
287 | |||
280 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels |
|
288 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels | |
281 |
|
289 | |||
282 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
290 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
283 |
|
291 | |||
284 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
292 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
285 |
|
293 | |||
286 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
294 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
287 |
|
295 | |||
288 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
296 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
289 |
|
297 | |||
290 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
298 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
291 |
|
299 | |||
292 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
300 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
293 |
|
301 | |||
294 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
302 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
295 |
|
303 | |||
296 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
304 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
297 |
|
305 | |||
298 | self.dataOutObj.ippSeconds = self.ippSeconds |
|
306 | self.dataOutObj.ippSeconds = self.ippSeconds | |
299 |
|
307 | |||
|
308 | self.dataOutObj.deltaHeight = self.processingHeaderObj.deltaHeight | |||
|
309 | ||||
300 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
310 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
301 |
|
311 | |||
302 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt |
|
312 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt | |
303 |
|
313 | |||
304 | self.dataOutObj.flagShiftFFT = False |
|
314 | self.dataOutObj.flagShiftFFT = False | |
305 |
|
315 | |||
306 | if self.processingHeaderObj.code != None: |
|
316 | if self.processingHeaderObj.code != None: | |
307 | self.dataOutObj.nCode = self.processingHeaderObj.nCode |
|
317 | self.dataOutObj.nCode = self.processingHeaderObj.nCode | |
308 |
|
318 | |||
309 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud |
|
319 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud | |
310 |
|
320 | |||
311 | self.dataOutObj.code = self.processingHeaderObj.code |
|
321 | self.dataOutObj.code = self.processingHeaderObj.code | |
312 |
|
322 | |||
313 | self.profileIndex += 1 |
|
323 | self.profileIndex += 1 | |
314 |
|
324 | |||
315 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
325 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
316 |
|
326 | |||
317 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
327 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
318 |
|
328 | |||
319 | self.dataOutObj.flagNoData = False |
|
329 | self.dataOutObj.flagNoData = False | |
320 |
|
330 | |||
321 | # print self.profileIndex, self.dataOutObj.utctime |
|
331 | # print self.profileIndex, self.dataOutObj.utctime | |
322 | # if self.profileIndex == 800: |
|
332 | # if self.profileIndex == 800: | |
323 | # a=1 |
|
333 | # a=1 | |
324 |
|
334 | |||
325 | return self.dataOutObj.data |
|
335 | return self.dataOutObj.data | |
326 |
|
336 | |||
327 |
|
337 | |||
328 | class VoltageWriter(JRODataWriter): |
|
338 | class VoltageWriter(JRODataWriter): | |
329 | """ |
|
339 | """ | |
330 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
340 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
331 | de los datos siempre se realiza por bloques. |
|
341 | de los datos siempre se realiza por bloques. | |
332 | """ |
|
342 | """ | |
333 |
|
343 | |||
334 | ext = ".r" |
|
344 | ext = ".r" | |
335 |
|
345 | |||
336 | optchar = "D" |
|
346 | optchar = "D" | |
337 |
|
347 | |||
338 | shapeBuffer = None |
|
348 | shapeBuffer = None | |
339 |
|
349 | |||
340 |
|
350 | |||
341 | def __init__(self, dataOutObj=None): |
|
351 | def __init__(self, dataOutObj=None): | |
342 | """ |
|
352 | """ | |
343 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
353 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
344 |
|
354 | |||
345 | Affected: |
|
355 | Affected: | |
346 | self.dataOutObj |
|
356 | self.dataOutObj | |
347 |
|
357 | |||
348 | Return: None |
|
358 | Return: None | |
349 | """ |
|
359 | """ | |
350 | if dataOutObj == None: |
|
360 | if dataOutObj == None: | |
351 | dataOutObj = Voltage() |
|
361 | dataOutObj = Voltage() | |
352 |
|
362 | |||
353 | if not( isinstance(dataOutObj, Voltage) ): |
|
363 | if not( isinstance(dataOutObj, Voltage) ): | |
354 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" |
|
364 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" | |
355 |
|
365 | |||
356 | self.dataOutObj = dataOutObj |
|
366 | self.dataOutObj = dataOutObj | |
357 |
|
367 | |||
358 | self.nTotalBlocks = 0 |
|
368 | self.nTotalBlocks = 0 | |
359 |
|
369 | |||
360 | self.profileIndex = 0 |
|
370 | self.profileIndex = 0 | |
361 |
|
371 | |||
362 | def hasAllDataInBuffer(self): |
|
372 | def hasAllDataInBuffer(self): | |
363 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
373 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
364 | return 1 |
|
374 | return 1 | |
365 | return 0 |
|
375 | return 0 | |
366 |
|
376 | |||
367 |
|
377 | |||
368 | def setBlockDimension(self): |
|
378 | def setBlockDimension(self): | |
369 | """ |
|
379 | """ | |
370 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
380 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
371 |
|
381 | |||
372 | Affected: |
|
382 | Affected: | |
373 | self.shape_spc_Buffer |
|
383 | self.shape_spc_Buffer | |
374 | self.shape_cspc_Buffer |
|
384 | self.shape_cspc_Buffer | |
375 | self.shape_dc_Buffer |
|
385 | self.shape_dc_Buffer | |
376 |
|
386 | |||
377 | Return: None |
|
387 | Return: None | |
378 | """ |
|
388 | """ | |
379 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
389 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
380 | self.processingHeaderObj.nHeights, |
|
390 | self.processingHeaderObj.nHeights, | |
381 | self.systemHeaderObj.nChannels) |
|
391 | self.systemHeaderObj.nChannels) | |
382 |
|
392 | |||
383 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
393 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
384 | self.processingHeaderObj.profilesPerBlock, |
|
394 | self.processingHeaderObj.profilesPerBlock, | |
385 | self.processingHeaderObj.nHeights), |
|
395 | self.processingHeaderObj.nHeights), | |
386 | dtype=numpy.dtype('complex')) |
|
396 | dtype=numpy.dtype('complex')) | |
387 |
|
397 | |||
388 |
|
398 | |||
389 | def writeBlock(self): |
|
399 | def writeBlock(self): | |
390 | """ |
|
400 | """ | |
391 | Escribe el buffer en el file designado |
|
401 | Escribe el buffer en el file designado | |
392 |
|
402 | |||
393 | Affected: |
|
403 | Affected: | |
394 | self.profileIndex |
|
404 | self.profileIndex | |
395 | self.flagIsNewFile |
|
405 | self.flagIsNewFile | |
396 | self.flagIsNewBlock |
|
406 | self.flagIsNewBlock | |
397 | self.nTotalBlocks |
|
407 | self.nTotalBlocks | |
398 | self.blockIndex |
|
408 | self.blockIndex | |
399 |
|
409 | |||
400 | Return: None |
|
410 | Return: None | |
401 | """ |
|
411 | """ | |
402 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
412 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
403 |
|
413 | |||
404 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
414 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
405 |
|
415 | |||
406 | data['real'] = junk.real |
|
416 | data['real'] = junk.real | |
407 | data['imag'] = junk.imag |
|
417 | data['imag'] = junk.imag | |
408 |
|
418 | |||
409 | data = data.reshape( (-1) ) |
|
419 | data = data.reshape( (-1) ) | |
410 |
|
420 | |||
411 | data.tofile( self.fp ) |
|
421 | data.tofile( self.fp ) | |
412 |
|
422 | |||
413 | self.datablock.fill(0) |
|
423 | self.datablock.fill(0) | |
414 |
|
424 | |||
415 | self.profileIndex = 0 |
|
425 | self.profileIndex = 0 | |
416 | self.flagIsNewFile = 0 |
|
426 | self.flagIsNewFile = 0 | |
417 | self.flagIsNewBlock = 1 |
|
427 | self.flagIsNewBlock = 1 | |
418 |
|
428 | |||
419 | self.blockIndex += 1 |
|
429 | self.blockIndex += 1 | |
420 | self.nTotalBlocks += 1 |
|
430 | self.nTotalBlocks += 1 | |
421 |
|
431 | |||
422 | def putData(self): |
|
432 | def putData(self): | |
423 | """ |
|
433 | """ | |
424 | Setea un bloque de datos y luego los escribe en un file |
|
434 | Setea un bloque de datos y luego los escribe en un file | |
425 |
|
435 | |||
426 | Affected: |
|
436 | Affected: | |
427 | self.flagIsNewBlock |
|
437 | self.flagIsNewBlock | |
428 | self.profileIndex |
|
438 | self.profileIndex | |
429 |
|
439 | |||
430 | Return: |
|
440 | Return: | |
431 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
441 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
432 | 1 : Si se escribio la data de un bloque en un file |
|
442 | 1 : Si se escribio la data de un bloque en un file | |
433 | """ |
|
443 | """ | |
434 | self.flagIsNewBlock = 0 |
|
444 | self.flagIsNewBlock = 0 | |
435 |
|
445 | |||
436 | if self.dataOutObj.flagNoData: |
|
446 | if self.dataOutObj.flagNoData: | |
437 | return 0 |
|
447 | return 0 | |
438 |
|
448 | |||
439 | if self.dataOutObj.flagTimeBlock: |
|
449 | if self.dataOutObj.flagTimeBlock: | |
440 |
|
450 | |||
441 | self.datablock.fill(0) |
|
451 | self.datablock.fill(0) | |
442 | self.profileIndex = 0 |
|
452 | self.profileIndex = 0 | |
443 | self.setNextFile() |
|
453 | self.setNextFile() | |
444 |
|
454 | |||
445 | if self.profileIndex == 0: |
|
455 | if self.profileIndex == 0: | |
446 | self.getBasicHeader() |
|
456 | self.getBasicHeader() | |
447 |
|
457 | |||
448 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data |
|
458 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data | |
449 |
|
459 | |||
450 | self.profileIndex += 1 |
|
460 | self.profileIndex += 1 | |
451 |
|
461 | |||
452 | if self.hasAllDataInBuffer(): |
|
462 | if self.hasAllDataInBuffer(): | |
453 | #if self.flagIsNewFile: |
|
463 | #if self.flagIsNewFile: | |
454 | self.writeNextBlock() |
|
464 | self.writeNextBlock() | |
455 | # self.getDataHeader() |
|
465 | # self.getDataHeader() | |
456 |
|
466 | |||
457 | if self.flagNoMoreFiles: |
|
467 | if self.flagNoMoreFiles: | |
458 | #print 'Process finished' |
|
468 | #print 'Process finished' | |
459 | return 0 |
|
469 | return 0 | |
460 |
|
470 | |||
461 | return 1 |
|
471 | return 1 | |
462 |
|
472 | |||
463 | def __getProcessFlags(self): |
|
473 | def __getProcessFlags(self): | |
464 |
|
474 | |||
465 | processFlags = 0 |
|
475 | processFlags = 0 | |
466 |
|
476 | |||
467 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
477 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
468 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
478 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
469 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
479 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
470 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
480 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
471 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
481 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
472 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
482 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
473 |
|
483 | |||
474 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
484 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
475 |
|
485 | |||
476 |
|
486 | |||
477 |
|
487 | |||
478 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
488 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
479 | PROCFLAG.DATATYPE_SHORT, |
|
489 | PROCFLAG.DATATYPE_SHORT, | |
480 | PROCFLAG.DATATYPE_LONG, |
|
490 | PROCFLAG.DATATYPE_LONG, | |
481 | PROCFLAG.DATATYPE_INT64, |
|
491 | PROCFLAG.DATATYPE_INT64, | |
482 | PROCFLAG.DATATYPE_FLOAT, |
|
492 | PROCFLAG.DATATYPE_FLOAT, | |
483 | PROCFLAG.DATATYPE_DOUBLE] |
|
493 | PROCFLAG.DATATYPE_DOUBLE] | |
484 |
|
494 | |||
485 |
|
495 | |||
486 | for index in range(len(dtypeList)): |
|
496 | for index in range(len(dtypeList)): | |
487 | if self.dataOutObj.dtype == dtypeList[index]: |
|
497 | if self.dataOutObj.dtype == dtypeList[index]: | |
488 | dtypeValue = datatypeValueList[index] |
|
498 | dtypeValue = datatypeValueList[index] | |
489 | break |
|
499 | break | |
490 |
|
500 | |||
491 | processFlags += dtypeValue |
|
501 | processFlags += dtypeValue | |
492 |
|
502 | |||
493 | if self.dataOutObj.flagDecodeData: |
|
503 | if self.dataOutObj.flagDecodeData: | |
494 | processFlags += PROCFLAG.DECODE_DATA |
|
504 | processFlags += PROCFLAG.DECODE_DATA | |
495 |
|
505 | |||
496 | if self.dataOutObj.flagDeflipData: |
|
506 | if self.dataOutObj.flagDeflipData: | |
497 | processFlags += PROCFLAG.DEFLIP_DATA |
|
507 | processFlags += PROCFLAG.DEFLIP_DATA | |
498 |
|
508 | |||
499 | if self.dataOutObj.code != None: |
|
509 | if self.dataOutObj.code != None: | |
500 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
510 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
501 |
|
511 | |||
502 | if self.dataOutObj.nCohInt > 1: |
|
512 | if self.dataOutObj.nCohInt > 1: | |
503 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
513 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
504 |
|
514 | |||
505 | return processFlags |
|
515 | return processFlags | |
506 |
|
516 | |||
507 |
|
517 | |||
508 | def __getBlockSize(self): |
|
518 | def __getBlockSize(self): | |
509 | ''' |
|
519 | ''' | |
510 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
520 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
511 | ''' |
|
521 | ''' | |
512 |
|
522 | |||
513 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
523 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
514 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
524 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
515 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
525 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
516 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
526 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
517 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
527 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
518 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
528 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
519 |
|
529 | |||
520 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
530 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
521 | datatypeValueList = [1,2,4,8,4,8] |
|
531 | datatypeValueList = [1,2,4,8,4,8] | |
522 | for index in range(len(dtypeList)): |
|
532 | for index in range(len(dtypeList)): | |
523 | if self.dataOutObj.dtype == dtypeList[index]: |
|
533 | if self.dataOutObj.dtype == dtypeList[index]: | |
524 | datatypeValue = datatypeValueList[index] |
|
534 | datatypeValue = datatypeValueList[index] | |
525 | break |
|
535 | break | |
526 |
|
536 | |||
527 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) |
|
537 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) | |
528 |
|
538 | |||
529 | return blocksize |
|
539 | return blocksize | |
530 |
|
540 | |||
531 |
|
541 | |||
532 | def getBasicHeader(self): |
|
542 | def getBasicHeader(self): | |
533 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
543 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
534 | self.basicHeaderObj.version = self.versionFile |
|
544 | self.basicHeaderObj.version = self.versionFile | |
535 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
545 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
536 |
|
546 | |||
537 | utc = numpy.floor(self.dataOutObj.utctime) |
|
547 | utc = numpy.floor(self.dataOutObj.utctime) | |
538 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 |
|
548 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 | |
539 |
|
549 | |||
540 | self.basicHeaderObj.utc = utc |
|
550 | self.basicHeaderObj.utc = utc | |
541 | self.basicHeaderObj.miliSecond = milisecond |
|
551 | self.basicHeaderObj.miliSecond = milisecond | |
542 | self.basicHeaderObj.timeZone = 0 |
|
552 | self.basicHeaderObj.timeZone = 0 | |
543 | self.basicHeaderObj.dstFlag = 0 |
|
553 | self.basicHeaderObj.dstFlag = 0 | |
544 | self.basicHeaderObj.errorCount = 0 |
|
554 | self.basicHeaderObj.errorCount = 0 | |
545 |
|
555 | |||
546 | def getDataHeader(self): |
|
556 | def getDataHeader(self): | |
547 |
|
557 | |||
548 | """ |
|
558 | """ | |
549 | Obtiene una copia del First Header |
|
559 | Obtiene una copia del First Header | |
550 |
|
560 | |||
551 | Affected: |
|
561 | Affected: | |
552 | self.systemHeaderObj |
|
562 | self.systemHeaderObj | |
553 | self.radarControllerHeaderObj |
|
563 | self.radarControllerHeaderObj | |
554 | self.dtype |
|
564 | self.dtype | |
555 |
|
565 | |||
556 | Return: |
|
566 | Return: | |
557 | None |
|
567 | None | |
558 | """ |
|
568 | """ | |
559 |
|
569 | |||
560 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
570 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
561 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
571 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
562 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
572 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
563 |
|
573 | |||
564 | self.getBasicHeader() |
|
574 | self.getBasicHeader() | |
565 |
|
575 | |||
566 | processingHeaderSize = 40 # bytes |
|
576 | processingHeaderSize = 40 # bytes | |
567 | self.processingHeaderObj.dtype = 0 # Voltage |
|
577 | self.processingHeaderObj.dtype = 0 # Voltage | |
568 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
578 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
569 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
579 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
570 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
580 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
571 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
581 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
572 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
582 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
573 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt |
|
583 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt | |
574 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
584 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
575 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
585 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
576 |
|
586 | |||
577 | if self.dataOutObj.code != None: |
|
587 | if self.dataOutObj.code != None: | |
578 | self.processingHeaderObj.code = self.dataOutObj.code |
|
588 | self.processingHeaderObj.code = self.dataOutObj.code | |
579 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
589 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
580 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
590 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
581 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
591 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
582 | processingHeaderSize += codesize |
|
592 | processingHeaderSize += codesize | |
583 |
|
593 | |||
584 | if self.processingHeaderObj.nWindows != 0: |
|
594 | if self.processingHeaderObj.nWindows != 0: | |
585 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
595 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
586 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
596 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
587 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
597 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
588 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
598 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
589 | processingHeaderSize += 12 |
|
599 | processingHeaderSize += 12 | |
590 |
|
600 | |||
591 | self.processingHeaderObj.size = processingHeaderSize |
|
601 | self.processingHeaderObj.size = processingHeaderSize | |
592 | No newline at end of file |
|
602 |
@@ -1,778 +1,859 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import time |
|
9 | import time | |
10 | import datetime |
|
10 | import datetime | |
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Data.JROData import Spectra, SpectraHeis |
|
14 | from Data.JROData import Spectra, SpectraHeis | |
15 | from IO.SpectraIO import SpectraWriter |
|
15 | from IO.SpectraIO import SpectraWriter,SpectraHeisWriter | |
16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure |
|
16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure | |
|
17 | from Graphics.BaseGraph_mpl import LinearPlot | |||
17 | #from JRONoise import Noise |
|
18 | #from JRONoise import Noise | |
18 |
|
19 | |||
19 | class SpectraProcessor: |
|
20 | class SpectraProcessor: | |
20 | ''' |
|
21 | ''' | |
21 | classdocs |
|
22 | classdocs | |
22 | ''' |
|
23 | ''' | |
23 |
|
24 | |||
24 | dataInObj = None |
|
25 | dataInObj = None | |
25 |
|
26 | |||
26 | dataOutObj = None |
|
27 | dataOutObj = None | |
27 |
|
28 | |||
28 | noiseObj = None |
|
29 | noiseObj = None | |
29 |
|
30 | |||
30 | integratorObjList = [] |
|
31 | integratorObjList = [] | |
31 |
|
32 | |||
32 | writerObjList = [] |
|
33 | writerObjList = [] | |
33 |
|
34 | |||
34 | integratorObjIndex = None |
|
35 | integratorObjIndex = None | |
35 |
|
36 | |||
36 | writerObjIndex = None |
|
37 | writerObjIndex = None | |
37 |
|
38 | |||
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
39 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage | |
39 |
|
40 | |||
40 | firstdatatime = None |
|
41 | firstdatatime = None | |
41 |
|
42 | |||
42 | def __init__(self): |
|
43 | def __init__(self): | |
43 | ''' |
|
44 | ''' | |
44 | Constructor |
|
45 | Constructor | |
45 | ''' |
|
46 | ''' | |
46 |
|
47 | |||
47 | self.integratorObjIndex = None |
|
48 | self.integratorObjIndex = None | |
48 | self.writerObjIndex = None |
|
49 | self.writerObjIndex = None | |
49 | self.plotObjIndex = None |
|
50 | self.plotObjIndex = None | |
50 | self.integratorOst = [] |
|
51 | self.integratorOst = [] | |
51 | self.plotObjList = [] |
|
52 | self.plotObjList = [] | |
52 | self.noiseObj = [] |
|
53 | self.noiseObj = [] | |
53 | self.writerObjList = [] |
|
54 | self.writerObjList = [] | |
54 | self.buffer = None |
|
55 | self.buffer = None | |
55 | self.firstdatatime = None |
|
56 | self.firstdatatime = None | |
56 | self.profIndex = 0 |
|
57 | self.profIndex = 0 | |
57 |
|
58 | |||
58 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None, wavelength=6): |
|
59 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None, wavelength=6): | |
59 |
|
60 | |||
60 | if dataInObj == None: |
|
61 | if dataInObj == None: | |
61 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
62 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" | |
62 |
|
63 | |||
63 | if dataInObj.type == "Voltage": |
|
64 | if dataInObj.type == "Voltage": | |
64 | if nFFTPoints == None: |
|
65 | if nFFTPoints == None: | |
65 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
66 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" | |
66 |
|
67 | |||
67 |
|
68 | |||
68 |
|
69 | |||
69 | if dataInObj.type == "Spectra": |
|
70 | if dataInObj.type == "Spectra": | |
70 | if nFFTPoints != None: |
|
71 | if nFFTPoints != None: | |
71 | raise ValueError, "The nFFTPoints cannot be selected to this object type" |
|
72 | raise ValueError, "The nFFTPoints cannot be selected to this object type" | |
72 |
|
73 | |||
73 | nFFTPoints = dataInObj.nFFTPoints |
|
74 | nFFTPoints = dataInObj.nFFTPoints | |
74 |
|
75 | |||
75 | if pairsList == None: |
|
76 | if pairsList == None: | |
76 | pairsList = dataInObj.pairsList |
|
77 | pairsList = dataInObj.pairsList | |
77 |
|
78 | |||
78 | if pairsList == None: |
|
79 | if pairsList == None: | |
79 | nPairs = 0 |
|
80 | nPairs = 0 | |
80 | else: |
|
81 | else: | |
81 | nPairs = len(pairsList) |
|
82 | nPairs = len(pairsList) | |
82 |
|
83 | |||
83 | self.dataInObj = dataInObj |
|
84 | self.dataInObj = dataInObj | |
84 |
|
85 | |||
85 | if dataOutObj == None: |
|
86 | if dataOutObj == None: | |
86 | dataOutObj = Spectra() |
|
87 | dataOutObj = Spectra() | |
87 |
|
88 | |||
88 | self.dataOutObj = dataOutObj |
|
89 | self.dataOutObj = dataOutObj | |
89 | self.dataOutObj.nFFTPoints = nFFTPoints |
|
90 | self.dataOutObj.nFFTPoints = nFFTPoints | |
90 | self.dataOutObj.pairsList = pairsList |
|
91 | self.dataOutObj.pairsList = pairsList | |
91 | self.dataOutObj.nPairs = nPairs |
|
92 | self.dataOutObj.nPairs = nPairs | |
92 | self.dataOutObj.wavelength = wavelength |
|
93 | self.dataOutObj.wavelength = wavelength | |
93 |
|
94 | |||
94 | return self.dataOutObj |
|
95 | return self.dataOutObj | |
95 |
|
96 | |||
96 | def init(self): |
|
97 | def init(self): | |
97 |
|
98 | |||
98 | """ |
|
99 | """ | |
99 |
|
100 | |||
100 | Este metodo reinicia los contadores de los objetos integrator, writer y plotter |
|
101 | Este metodo reinicia los contadores de los objetos integrator, writer y plotter | |
101 | y actualiza los parametros del objeto de salida dataOutObj a partir del objeto de entrada. |
|
102 | y actualiza los parametros del objeto de salida dataOutObj a partir del objeto de entrada. | |
102 |
|
103 | |||
103 | """ |
|
104 | """ | |
104 |
|
105 | |||
105 | self.dataOutObj.flagNoData = True |
|
106 | self.dataOutObj.flagNoData = True | |
106 |
|
107 | |||
107 | if self.dataInObj.flagNoData: |
|
108 | if self.dataInObj.flagNoData: | |
108 | return 0 |
|
109 | return 0 | |
109 |
|
110 | |||
110 | self.integratorObjIndex = 0 |
|
111 | self.integratorObjIndex = 0 | |
111 | self.writerObjIndex = 0 |
|
112 | self.writerObjIndex = 0 | |
112 | self.plotObjIndex = 0 |
|
113 | self.plotObjIndex = 0 | |
113 |
|
114 | |||
114 |
|
115 | |||
115 | if self.dataInObj.type == "Spectra": |
|
116 | if self.dataInObj.type == "Spectra": | |
116 |
|
117 | |||
117 | self.dataOutObj.copy(self.dataInObj) |
|
118 | self.dataOutObj.copy(self.dataInObj) | |
118 | self.dataOutObj.flagNoData = False |
|
119 | self.dataOutObj.flagNoData = False | |
119 | return |
|
120 | return | |
120 |
|
121 | |||
121 | if self.dataInObj.type == "Voltage": |
|
122 | if self.dataInObj.type == "Voltage": | |
122 |
|
123 | |||
123 | if self.buffer == None: |
|
124 | if self.buffer == None: | |
124 | self.buffer = numpy.zeros((self.dataInObj.nChannels, |
|
125 | self.buffer = numpy.zeros((self.dataInObj.nChannels, | |
125 | self.dataOutObj.nFFTPoints, |
|
126 | self.dataOutObj.nFFTPoints, | |
126 | self.dataInObj.nHeights), |
|
127 | self.dataInObj.nHeights), | |
127 | dtype='complex') |
|
128 | dtype='complex') | |
128 |
|
129 | |||
129 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
130 | self.buffer[:,self.profIndex,:] = self.dataInObj.data | |
130 | self.profIndex += 1 |
|
131 | self.profIndex += 1 | |
131 |
|
132 | |||
132 | if self.firstdatatime == None: |
|
133 | if self.firstdatatime == None: | |
133 | self.firstdatatime = self.dataInObj.utctime |
|
134 | self.firstdatatime = self.dataInObj.utctime | |
134 |
|
135 | |||
135 | if self.profIndex == self.dataOutObj.nFFTPoints: |
|
136 | if self.profIndex == self.dataOutObj.nFFTPoints: | |
136 |
|
137 | |||
137 | self.__updateObjFromInput() |
|
138 | self.__updateObjFromInput() | |
138 | self.__getFft() |
|
139 | self.__getFft() | |
139 |
|
140 | |||
140 | self.dataOutObj.flagNoData = False |
|
141 | self.dataOutObj.flagNoData = False | |
141 |
|
142 | |||
142 | self.buffer = None |
|
143 | self.buffer = None | |
143 | self.firstdatatime = None |
|
144 | self.firstdatatime = None | |
144 | self.profIndex = 0 |
|
145 | self.profIndex = 0 | |
145 |
|
146 | |||
146 | return |
|
147 | return | |
147 |
|
148 | |||
148 | #Other kind of data |
|
149 | #Other kind of data | |
149 | raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type) |
|
150 | raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type) | |
150 |
|
151 | |||
151 | def __getFft(self): |
|
152 | def __getFft(self): | |
152 | """ |
|
153 | """ | |
153 | Convierte valores de Voltaje a Spectra |
|
154 | Convierte valores de Voltaje a Spectra | |
154 |
|
155 | |||
155 | Affected: |
|
156 | Affected: | |
156 | self.dataOutObj.data_spc |
|
157 | self.dataOutObj.data_spc | |
157 | self.dataOutObj.data_cspc |
|
158 | self.dataOutObj.data_cspc | |
158 | self.dataOutObj.data_dc |
|
159 | self.dataOutObj.data_dc | |
159 | self.dataOutObj.heightList |
|
160 | self.dataOutObj.heightList | |
160 | self.dataOutObj.m_BasicHeader |
|
161 | self.dataOutObj.m_BasicHeader | |
161 | self.dataOutObj.m_ProcessingHeader |
|
162 | self.dataOutObj.m_ProcessingHeader | |
162 | self.dataOutObj.radarControllerHeaderObj |
|
163 | self.dataOutObj.radarControllerHeaderObj | |
163 | self.dataOutObj.systemHeaderObj |
|
164 | self.dataOutObj.systemHeaderObj | |
164 | self.profIndex |
|
165 | self.profIndex | |
165 | self.buffer |
|
166 | self.buffer | |
166 | self.dataOutObj.flagNoData |
|
167 | self.dataOutObj.flagNoData | |
167 | self.dataOutObj.dtype |
|
168 | self.dataOutObj.dtype | |
168 | self.dataOutObj.nPairs |
|
169 | self.dataOutObj.nPairs | |
169 | self.dataOutObj.nChannels |
|
170 | self.dataOutObj.nChannels | |
170 | self.dataOutObj.nProfiles |
|
171 | self.dataOutObj.nProfiles | |
171 | self.dataOutObj.systemHeaderObj.numChannels |
|
172 | self.dataOutObj.systemHeaderObj.numChannels | |
172 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
173 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
173 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
174 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
174 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
175 | self.dataOutObj.m_ProcessingHeader.numHeights | |
175 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
176 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
176 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
177 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
177 | """ |
|
178 | """ | |
178 |
|
179 | |||
179 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
180 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
180 | dc = fft_volt[:,0,:] |
|
181 | dc = fft_volt[:,0,:] | |
181 |
|
182 | |||
182 | #calculo de self-spectra |
|
183 | #calculo de self-spectra | |
183 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
184 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
184 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
185 | spc = fft_volt * numpy.conjugate(fft_volt) | |
185 | spc = spc.real |
|
186 | spc = spc.real | |
186 |
|
187 | |||
187 | blocksize = 0 |
|
188 | blocksize = 0 | |
188 | blocksize += dc.size |
|
189 | blocksize += dc.size | |
189 | blocksize += spc.size |
|
190 | blocksize += spc.size | |
190 |
|
191 | |||
191 | cspc = None |
|
192 | cspc = None | |
192 | pairIndex = 0 |
|
193 | pairIndex = 0 | |
193 | if self.dataOutObj.pairsList != None: |
|
194 | if self.dataOutObj.pairsList != None: | |
194 | #calculo de cross-spectra |
|
195 | #calculo de cross-spectra | |
195 | cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex') |
|
196 | cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex') | |
196 | for pair in self.dataOutObj.pairsList: |
|
197 | for pair in self.dataOutObj.pairsList: | |
197 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
198 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
198 | pairIndex += 1 |
|
199 | pairIndex += 1 | |
199 | blocksize += cspc.size |
|
200 | blocksize += cspc.size | |
200 |
|
201 | |||
201 | self.dataOutObj.data_spc = spc |
|
202 | self.dataOutObj.data_spc = spc | |
202 | self.dataOutObj.data_cspc = cspc |
|
203 | self.dataOutObj.data_cspc = cspc | |
203 | self.dataOutObj.data_dc = dc |
|
204 | self.dataOutObj.data_dc = dc | |
204 | self.dataOutObj.blockSize = blocksize |
|
205 | self.dataOutObj.blockSize = blocksize | |
205 |
|
206 | |||
206 | # self.getNoise() |
|
207 | # self.getNoise() | |
207 |
|
208 | |||
208 | def __updateObjFromInput(self): |
|
209 | def __updateObjFromInput(self): | |
209 |
|
210 | |||
210 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
211 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() | |
211 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
212 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() | |
212 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
213 | self.dataOutObj.channelList = self.dataInObj.channelList | |
213 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
214 | self.dataOutObj.heightList = self.dataInObj.heightList | |
214 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
215 | self.dataOutObj.dtype = self.dataInObj.dtype | |
215 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
216 | self.dataOutObj.nHeights = self.dataInObj.nHeights | |
216 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
217 | self.dataOutObj.nChannels = self.dataInObj.nChannels | |
217 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
218 | self.dataOutObj.nBaud = self.dataInObj.nBaud | |
218 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
219 | self.dataOutObj.nCode = self.dataInObj.nCode | |
219 | self.dataOutObj.code = self.dataInObj.code |
|
220 | self.dataOutObj.code = self.dataInObj.code | |
220 | self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints |
|
221 | self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints | |
221 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
222 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |
222 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
223 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock | |
223 | self.dataOutObj.utctime = self.firstdatatime |
|
224 | self.dataOutObj.utctime = self.firstdatatime | |
224 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
225 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada | |
225 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
226 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip | |
226 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
227 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT | |
227 | self.dataOutObj.nCohInt = self.dataInObj.nCohInt |
|
228 | self.dataOutObj.nCohInt = self.dataInObj.nCohInt | |
228 | self.dataOutObj.nIncohInt = 1 |
|
229 | self.dataOutObj.nIncohInt = 1 | |
229 | self.dataOutObj.ippSeconds = self.dataInObj.ippSeconds |
|
230 | self.dataOutObj.ippSeconds = self.dataInObj.ippSeconds | |
230 | self.dataOutObj.timeInterval = self.dataInObj.timeInterval*self.dataOutObj.nFFTPoints |
|
231 | self.dataOutObj.timeInterval = self.dataInObj.timeInterval*self.dataOutObj.nFFTPoints | |
231 |
|
232 | |||
232 | def addWriter(self, wrpath, blocksPerFile): |
|
233 | def addWriter(self, wrpath, blocksPerFile): | |
233 |
|
234 | |||
234 | objWriter = SpectraWriter(self.dataOutObj) |
|
235 | objWriter = SpectraWriter(self.dataOutObj) | |
235 | objWriter.setup(wrpath, blocksPerFile) |
|
236 | objWriter.setup(wrpath, blocksPerFile) | |
236 | self.writerObjList.append(objWriter) |
|
237 | self.writerObjList.append(objWriter) | |
237 |
|
238 | |||
238 | def addIntegrator(self,N,timeInterval): |
|
239 | def addIntegrator(self,N,timeInterval): | |
239 |
|
240 | |||
240 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
241 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
241 | self.integratorObjList.append(objIncohInt) |
|
242 | self.integratorObjList.append(objIncohInt) | |
242 |
|
243 | |||
243 | def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
244 | def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
244 | crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
245 | crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
245 | self.plotObjList.append(crossSpcObj) |
|
246 | self.plotObjList.append(crossSpcObj) | |
246 |
|
247 | |||
247 | def plotCrossSpc(self, idfigure=None, |
|
248 | def plotCrossSpc(self, idfigure=None, | |
248 | xmin=None, |
|
249 | xmin=None, | |
249 | xmax=None, |
|
250 | xmax=None, | |
250 | ymin=None, |
|
251 | ymin=None, | |
251 | ymax=None, |
|
252 | ymax=None, | |
252 | minvalue=None, |
|
253 | minvalue=None, | |
253 | maxvalue=None, |
|
254 | maxvalue=None, | |
254 | wintitle='', |
|
255 | wintitle='', | |
255 | driver='plplot', |
|
256 | driver='plplot', | |
256 | colormap='br_green', |
|
257 | colormap='br_green', | |
257 | colorbar=True, |
|
258 | colorbar=True, | |
258 | showprofile=False, |
|
259 | showprofile=False, | |
259 | save=False, |
|
260 | save=False, | |
260 | gpath=None, |
|
261 | gpath=None, | |
261 | pairsList = None): |
|
262 | pairsList = None): | |
262 |
|
263 | |||
263 | if self.dataOutObj.flagNoData: |
|
264 | if self.dataOutObj.flagNoData: | |
264 | return 0 |
|
265 | return 0 | |
265 |
|
266 | |||
266 | if pairsList == None: |
|
267 | if pairsList == None: | |
267 | pairsList = self.dataOutObj.pairsList |
|
268 | pairsList = self.dataOutObj.pairsList | |
268 |
|
269 | |||
269 | nframes = len(pairsList) |
|
270 | nframes = len(pairsList) | |
270 |
|
271 | |||
271 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
272 | x = numpy.arange(self.dataOutObj.nFFTPoints) | |
272 |
|
273 | |||
273 | y = self.dataOutObj.heightList |
|
274 | y = self.dataOutObj.heightList | |
274 |
|
275 | |||
275 | data_spc = self.dataOutObj.data_spc |
|
276 | data_spc = self.dataOutObj.data_spc | |
276 | data_cspc = self.dataOutObj.data_cspc |
|
277 | data_cspc = self.dataOutObj.data_cspc | |
277 |
|
278 | |||
278 | data = [] |
|
279 | data = [] | |
279 |
|
280 | |||
280 |
|
281 | |||
281 | if len(self.plotObjList) <= self.plotObjIndex: |
|
282 | if len(self.plotObjList) <= self.plotObjIndex: | |
282 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
283 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
283 |
|
284 | |||
284 |
|
285 | |||
285 |
|
286 | |||
286 |
|
287 | |||
287 |
|
288 | |||
288 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
289 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
289 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
290 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
290 | self.plotObjList.append(rtiObj) |
|
291 | self.plotObjList.append(rtiObj) | |
291 |
|
292 | |||
292 | def plotRti(self, idfigure=None, |
|
293 | def plotRti(self, idfigure=None, | |
293 | starttime=None, |
|
294 | starttime=None, | |
294 | endtime=None, |
|
295 | endtime=None, | |
295 | rangemin=None, |
|
296 | rangemin=None, | |
296 | rangemax=None, |
|
297 | rangemax=None, | |
297 | minvalue=None, |
|
298 | minvalue=None, | |
298 | maxvalue=None, |
|
299 | maxvalue=None, | |
299 | wintitle='', |
|
300 | wintitle='', | |
300 | driver='plplot', |
|
301 | driver='plplot', | |
301 | colormap='br_greeen', |
|
302 | colormap='br_greeen', | |
302 | colorbar=True, |
|
303 | colorbar=True, | |
303 | showprofile=False, |
|
304 | showprofile=False, | |
304 | xrangestep=None, |
|
305 | xrangestep=None, | |
305 | save=False, |
|
306 | save=False, | |
306 | gpath=None, |
|
307 | gpath=None, | |
307 | ratio=1, |
|
308 | ratio=1, | |
308 | channelList=None): |
|
309 | channelList=None): | |
309 |
|
310 | |||
310 | if self.dataOutObj.flagNoData: |
|
311 | if self.dataOutObj.flagNoData: | |
311 | return 0 |
|
312 | return 0 | |
312 |
|
313 | |||
313 | if channelList == None: |
|
314 | if channelList == None: | |
314 | channelList = self.dataOutObj.channelList |
|
315 | channelList = self.dataOutObj.channelList | |
315 |
|
316 | |||
316 | nframes = len(channelList) |
|
317 | nframes = len(channelList) | |
317 |
|
318 | |||
318 | if len(self.plotObjList) <= self.plotObjIndex: |
|
319 | if len(self.plotObjList) <= self.plotObjIndex: | |
319 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
320 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
320 |
|
321 | |||
321 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) |
|
322 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |
322 |
|
323 | |||
323 | data = numpy.average(data, axis=1) |
|
324 | data = numpy.average(data, axis=1) | |
324 |
|
325 | |||
325 | currenttime = self.dataOutObj.utctime - time.timezone |
|
326 | currenttime = self.dataOutObj.utctime - time.timezone | |
326 |
|
327 | |||
327 | range = self.dataOutObj.heightList |
|
328 | range = self.dataOutObj.heightList | |
328 |
|
329 | |||
329 |
|
330 | |||
330 | figuretitle = "RTI Plot for Spectra Data" #+ date |
|
331 | figuretitle = "RTI Plot for Spectra Data" #+ date | |
331 |
|
332 | |||
332 | cleardata = False |
|
333 | cleardata = False | |
333 |
|
334 | |||
334 | deltax = self.dataOutObj.timeInterval |
|
335 | deltax = self.dataOutObj.timeInterval | |
335 |
|
336 | |||
336 | plotObj = self.plotObjList[self.plotObjIndex] |
|
337 | plotObj = self.plotObjList[self.plotObjIndex] | |
337 |
|
338 | |||
338 | plotObj.plotPcolor(data=data, |
|
339 | plotObj.plotPcolor(data=data, | |
339 | x=currenttime, |
|
340 | x=currenttime, | |
340 | y=range, |
|
341 | y=range, | |
341 | channelList=channelList, |
|
342 | channelList=channelList, | |
342 | xmin=starttime, |
|
343 | xmin=starttime, | |
343 | xmax=endtime, |
|
344 | xmax=endtime, | |
344 | ymin=rangemin, |
|
345 | ymin=rangemin, | |
345 | ymax=rangemax, |
|
346 | ymax=rangemax, | |
346 | minvalue=minvalue, |
|
347 | minvalue=minvalue, | |
347 | maxvalue=maxvalue, |
|
348 | maxvalue=maxvalue, | |
348 | figuretitle=figuretitle, |
|
349 | figuretitle=figuretitle, | |
349 | xrangestep=xrangestep, |
|
350 | xrangestep=xrangestep, | |
350 | deltax=deltax, |
|
351 | deltax=deltax, | |
351 | save=save, |
|
352 | save=save, | |
352 | gpath=gpath, |
|
353 | gpath=gpath, | |
353 | ratio=ratio, |
|
354 | ratio=ratio, | |
354 | cleardata=cleardata |
|
355 | cleardata=cleardata | |
355 | ) |
|
356 | ) | |
356 |
|
357 | |||
357 |
|
358 | |||
358 |
|
359 | |||
359 | self.plotObjIndex += 1 |
|
360 | self.plotObjIndex += 1 | |
360 |
|
361 | |||
361 |
|
362 | |||
362 |
|
363 | |||
363 |
|
364 | |||
364 |
|
365 | |||
365 |
|
366 | |||
366 |
|
367 | |||
367 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
368 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
368 |
|
369 | |||
369 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
370 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
370 | self.plotObjList.append(spcObj) |
|
371 | self.plotObjList.append(spcObj) | |
371 |
|
372 | |||
372 | def plotSpc(self, idfigure=None, |
|
373 | def plotSpc(self, idfigure=None, | |
373 | xmin=None, |
|
374 | xmin=None, | |
374 | xmax=None, |
|
375 | xmax=None, | |
375 | ymin=None, |
|
376 | ymin=None, | |
376 | ymax=None, |
|
377 | ymax=None, | |
377 | minvalue=None, |
|
378 | minvalue=None, | |
378 | maxvalue=None, |
|
379 | maxvalue=None, | |
379 | wintitle='', |
|
380 | wintitle='', | |
380 | driver='plplot', |
|
381 | driver='plplot', | |
381 | colormap='br_green', |
|
382 | colormap='br_green', | |
382 | colorbar=True, |
|
383 | colorbar=True, | |
383 | showprofile=False, |
|
384 | showprofile=False, | |
384 | save=False, |
|
385 | save=False, | |
385 | gpath=None, |
|
386 | gpath=None, | |
386 | ratio=1, |
|
387 | ratio=1, | |
387 | channelList=None): |
|
388 | channelList=None): | |
388 |
|
389 | |||
389 | if self.dataOutObj.flagNoData: |
|
390 | if self.dataOutObj.flagNoData: | |
390 | return 0 |
|
391 | return 0 | |
391 |
|
392 | |||
392 | if channelList == None: |
|
393 | if channelList == None: | |
393 | channelList = self.dataOutObj.channelList |
|
394 | channelList = self.dataOutObj.channelList | |
394 |
|
395 | |||
395 | nframes = len(channelList) |
|
396 | nframes = len(channelList) | |
396 |
|
397 | |||
397 | if len(self.plotObjList) <= self.plotObjIndex: |
|
398 | if len(self.plotObjList) <= self.plotObjIndex: | |
398 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
399 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
399 |
|
400 | |||
400 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
401 | x = numpy.arange(self.dataOutObj.nFFTPoints) | |
401 |
|
402 | |||
402 | y = self.dataOutObj.heightList |
|
403 | y = self.dataOutObj.heightList | |
403 |
|
404 | |||
404 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) |
|
405 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |
405 | # noisedB = 10.*numpy.log10(noise) |
|
406 | # noisedB = 10.*numpy.log10(noise) | |
406 | noisedB = numpy.arange(len(channelList)+1) |
|
407 | noisedB = numpy.arange(len(channelList)+1) | |
407 | noisedB = noisedB *1.2 |
|
408 | noisedB = noisedB *1.2 | |
408 | titleList = [] |
|
409 | titleList = [] | |
409 | for i in range(len(noisedB)): |
|
410 | for i in range(len(noisedB)): | |
410 | title = "%.2f"%noisedB[i] |
|
411 | title = "%.2f"%noisedB[i] | |
411 | titleList.append(title) |
|
412 | titleList.append(title) | |
412 |
|
413 | |||
413 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
414 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
414 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
415 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
415 | figuretitle = "Spc Radar Data: %s"%dateTime |
|
416 | figuretitle = "Spc Radar Data: %s"%dateTime | |
416 |
|
417 | |||
417 | cleardata = True |
|
418 | cleardata = True | |
418 |
|
419 | |||
419 | plotObj = self.plotObjList[self.plotObjIndex] |
|
420 | plotObj = self.plotObjList[self.plotObjIndex] | |
420 |
|
421 | |||
421 | plotObj.plotPcolor(data=data, |
|
422 | plotObj.plotPcolor(data=data, | |
422 | x=x, |
|
423 | x=x, | |
423 | y=y, |
|
424 | y=y, | |
424 | channelList=channelList, |
|
425 | channelList=channelList, | |
425 | xmin=xmin, |
|
426 | xmin=xmin, | |
426 | xmax=xmax, |
|
427 | xmax=xmax, | |
427 | ymin=ymin, |
|
428 | ymin=ymin, | |
428 | ymax=ymax, |
|
429 | ymax=ymax, | |
429 | minvalue=minvalue, |
|
430 | minvalue=minvalue, | |
430 | maxvalue=maxvalue, |
|
431 | maxvalue=maxvalue, | |
431 | figuretitle=figuretitle, |
|
432 | figuretitle=figuretitle, | |
432 | xrangestep=None, |
|
433 | xrangestep=None, | |
433 | deltax=None, |
|
434 | deltax=None, | |
434 | save=save, |
|
435 | save=save, | |
435 | gpath=gpath, |
|
436 | gpath=gpath, | |
436 | cleardata=cleardata |
|
437 | cleardata=cleardata | |
437 | ) |
|
438 | ) | |
438 |
|
439 | |||
439 | self.plotObjIndex += 1 |
|
440 | self.plotObjIndex += 1 | |
440 |
|
441 | |||
441 |
|
442 | |||
442 | def writeData(self, wrpath, blocksPerFile): |
|
443 | def writeData(self, wrpath, blocksPerFile): | |
443 |
|
444 | |||
444 | if self.dataOutObj.flagNoData: |
|
445 | if self.dataOutObj.flagNoData: | |
445 | return 0 |
|
446 | return 0 | |
446 |
|
447 | |||
447 | if len(self.writerObjList) <= self.writerObjIndex: |
|
448 | if len(self.writerObjList) <= self.writerObjIndex: | |
448 | self.addWriter(wrpath, blocksPerFile) |
|
449 | self.addWriter(wrpath, blocksPerFile) | |
449 |
|
450 | |||
450 | self.writerObjList[self.writerObjIndex].putData() |
|
451 | self.writerObjList[self.writerObjIndex].putData() | |
451 |
|
452 | |||
452 | self.writerObjIndex += 1 |
|
453 | self.writerObjIndex += 1 | |
453 |
|
454 | |||
454 | def integrator(self, N=None, timeInterval=None): |
|
455 | def integrator(self, N=None, timeInterval=None): | |
455 |
|
456 | |||
456 | if self.dataOutObj.flagNoData: |
|
457 | if self.dataOutObj.flagNoData: | |
457 | return 0 |
|
458 | return 0 | |
458 |
|
459 | |||
459 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
460 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
460 | self.addIntegrator(N,timeInterval) |
|
461 | self.addIntegrator(N,timeInterval) | |
461 |
|
462 | |||
462 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
463 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
463 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime) |
|
464 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime) | |
464 |
|
465 | |||
465 | if myIncohIntObj.isReady: |
|
466 | if myIncohIntObj.isReady: | |
466 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
467 | self.dataOutObj.data_spc = myIncohIntObj.data | |
467 | self.dataOutObj.timeInterval *= myCohIntObj.nIncohInt |
|
468 | self.dataOutObj.timeInterval *= myCohIntObj.nIncohInt | |
468 | self.dataOutObj.nIncohInt = myIncohIntObj.navg * self.dataInObj.nIncohInt |
|
469 | self.dataOutObj.nIncohInt = myIncohIntObj.navg * self.dataInObj.nIncohInt | |
469 | self.dataOutObj.utctime = myIncohIntObj.firstdatatime |
|
470 | self.dataOutObj.utctime = myIncohIntObj.firstdatatime | |
470 | self.dataOutObj.flagNoData = False |
|
471 | self.dataOutObj.flagNoData = False | |
471 |
|
472 | |||
472 | """Calcular el ruido""" |
|
473 | """Calcular el ruido""" | |
473 | self.getNoise() |
|
474 | self.getNoise() | |
474 | else: |
|
475 | else: | |
475 | self.dataOutObj.flagNoData = True |
|
476 | self.dataOutObj.flagNoData = True | |
476 |
|
477 | |||
477 | self.integratorObjIndex += 1 |
|
478 | self.integratorObjIndex += 1 | |
478 |
|
479 | |||
479 |
|
480 | |||
480 | class SpectraHeisProcessor: |
|
481 | class SpectraHeisProcessor: | |
481 |
|
482 | |||
482 | def __init__(self): |
|
483 | def __init__(self): | |
483 |
|
484 | |||
484 | self.integratorObjIndex = None |
|
485 | self.integratorObjIndex = None | |
485 | self.writerObjIndex = None |
|
486 | self.writerObjIndex = None | |
486 | self.plotObjIndex = None |
|
487 | self.plotObjIndex = None | |
487 | self.integratorObjList = [] |
|
488 | self.integratorObjList = [] | |
488 | self.writerObjList = [] |
|
489 | self.writerObjList = [] | |
489 | self.plotObjList = [] |
|
490 | self.plotObjList = [] | |
490 | #self.noiseObj = Noise() |
|
491 | #self.noiseObj = Noise() | |
491 |
|
492 | |||
492 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
493 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): | |
493 |
|
494 | |||
494 | if nFFTPoints == None: |
|
495 | if nFFTPoints == None: | |
495 | nFFTPoints = self.dataInObj.nHeights |
|
496 | nFFTPoints = self.dataInObj.nHeights | |
496 |
|
497 | |||
497 | self.dataInObj = dataInObj |
|
498 | self.dataInObj = dataInObj | |
498 |
|
499 | |||
499 | if dataOutObj == None: |
|
500 | if dataOutObj == None: | |
500 | dataOutObj = SpectraHeis() |
|
501 | dataOutObj = SpectraHeis() | |
501 |
|
502 | |||
502 | self.dataOutObj = dataOutObj |
|
503 | self.dataOutObj = dataOutObj | |
503 |
|
504 | |||
504 | return self.dataOutObj |
|
505 | return self.dataOutObj | |
505 |
|
506 | |||
506 | def init(self): |
|
507 | def init(self): | |
507 |
|
508 | |||
508 | self.dataOutObj.flagNoData = True |
|
509 | self.dataOutObj.flagNoData = True | |
509 |
|
510 | |||
510 | if self.dataInObj.flagNoData: |
|
511 | if self.dataInObj.flagNoData: | |
511 | return 0 |
|
512 | return 0 | |
512 |
|
513 | |||
513 | self.integratorObjIndex = 0 |
|
514 | self.integratorObjIndex = 0 | |
514 | self.writerObjIndex = 0 |
|
515 | self.writerObjIndex = 0 | |
515 | self.plotObjIndex = 0 |
|
516 | self.plotObjIndex = 0 | |
516 |
|
517 | |||
517 | if self.dataInObj.type == "Voltage": |
|
518 | if self.dataInObj.type == "Voltage": | |
518 | self.__updateObjFromInput() |
|
519 | self.__updateObjFromInput() | |
519 | self.__getFft() |
|
520 | self.__getFft() | |
520 | self.dataOutObj.flagNoData = False |
|
521 | self.dataOutObj.flagNoData = False | |
521 | return |
|
522 | return | |
522 |
|
523 | |||
523 | #Other kind of data |
|
524 | #Other kind of data | |
524 | if self.dataInObj.type == "SpectraHeis": |
|
525 | if self.dataInObj.type == "SpectraHeis": | |
525 | self.dataOutObj.copy(self.dataInObj) |
|
526 | self.dataOutObj.copy(self.dataInObj) | |
526 | self.dataOutObj.flagNoData = False |
|
527 | self.dataOutObj.flagNoData = False | |
527 | return |
|
528 | return | |
528 |
|
529 | |||
529 | raise ValueError, "The type is not valid" |
|
530 | raise ValueError, "The type is not valid" | |
530 |
|
531 | |||
531 | def __updateObjFromInput(self): |
|
532 | def __updateObjFromInput(self): | |
532 |
|
533 | |||
533 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
534 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() | |
534 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
535 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() | |
535 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
536 | self.dataOutObj.channelList = self.dataInObj.channelList | |
536 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
537 | self.dataOutObj.heightList = self.dataInObj.heightList | |
537 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
538 | self.dataOutObj.dtype = self.dataInObj.dtype | |
538 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
539 | self.dataOutObj.nHeights = self.dataInObj.nHeights | |
539 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
540 | self.dataOutObj.nChannels = self.dataInObj.nChannels | |
540 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
541 | self.dataOutObj.nBaud = self.dataInObj.nBaud | |
541 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
542 | self.dataOutObj.nCode = self.dataInObj.nCode | |
542 | self.dataOutObj.code = self.dataInObj.code |
|
543 | self.dataOutObj.code = self.dataInObj.code | |
543 | self.dataOutObj.nProfiles = 1 |
|
544 | self.dataOutObj.nProfiles = 1 | |
544 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights |
|
545 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights | |
545 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
546 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |
546 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData |
|
547 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData | |
547 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
548 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock | |
548 | self.dataOutObj.utctime = self.dataInObj.utctime |
|
549 | self.dataOutObj.utctime = self.dataInObj.utctime | |
549 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
550 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada | |
550 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
551 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip | |
551 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
552 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT | |
552 | self.dataOutObj.nIncohInt = 1 |
|
553 | self.dataOutObj.nIncohInt = 1 | |
553 | self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds |
|
554 | self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds | |
|
555 | self.dataOutObj.set=self.dataInObj.set | |||
|
556 | self.dataOutObj.deltaHeight=self.dataInObj.deltaHeight | |||
554 |
|
557 | |||
555 | # def addWriter(self,wrpath,blocksPerfile): |
|
558 | # def addWriter(self,wrpath,blocksPerfile): | |
556 | def addWriter(self,wrpath): |
|
559 | def addWriter(self,wrpath): | |
557 | objWriter=SpectraHeisWriter(self.dataOutObj) |
|
560 | objWriter=SpectraHeisWriter(self.dataOutObj) | |
558 | objWriter.setup(wrpath) |
|
561 | objWriter.setup(wrpath) | |
559 | #objWriter.setup(wrpath,blocksPerfile) |
|
562 | #objWriter.setup(wrpath,blocksPerfile) | |
560 | self.writerObjList.append(objWriter) |
|
563 | self.writerObjList.append(objWriter) | |
561 |
|
564 | |||
562 | # def writedata(self,wrpath,blocksPerfile): |
|
565 | # def writedata(self,wrpath,blocksPerfile): | |
563 | def writedata(self,wrpath): |
|
566 | def writedata(self,wrpath): | |
564 | if self.dataOutObj.flagNoData: |
|
567 | if self.dataOutObj.flagNoData: | |
565 | return 0 |
|
568 | return 0 | |
566 |
|
569 | |||
567 | if len(self.writerObjList) <= self.writerObjIndex: |
|
570 | if len(self.writerObjList) <= self.writerObjIndex: | |
568 | #self.addWriter(wrpath, blocksPerFile) |
|
571 | #self.addWriter(wrpath, blocksPerFile) | |
569 | self.addWriter(wrpath) |
|
572 | self.addWriter(wrpath) | |
570 |
|
573 | |||
571 | self.writerObjList[self.writerObjIndex].putData() |
|
574 | self.writerObjList[self.writerObjIndex].putData() | |
572 |
|
575 | |||
573 | self.writerObjIndex += 1 |
|
576 | self.writerObjIndex += 1 | |
574 |
|
577 | |||
575 | def __getFft(self): |
|
578 | def __getFft(self): | |
576 |
|
579 | |||
577 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) |
|
580 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) | |
578 | #print fft_volt |
|
581 | #print fft_volt | |
579 | #calculo de self-spectra |
|
582 | #calculo de self-spectra | |
580 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
583 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
581 |
|
584 | |||
582 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
585 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) | |
583 | self.dataOutObj.data_spc = spc |
|
586 | self.dataOutObj.data_spc = spc | |
584 |
|
587 | |||
585 | def getSpectra(self): |
|
588 | def getSpectra(self): | |
586 |
|
589 | |||
587 | return self.dataOutObj.data_spc |
|
590 | return self.dataOutObj.data_spc | |
588 |
|
591 | |||
589 | def getFrecuencies(self): |
|
592 | def getFrecuencies(self): | |
590 |
|
593 | |||
591 | print self.nFFTPoints |
|
594 | print self.nFFTPoints | |
592 | return numpy.arange(int(self.nFFTPoints)) |
|
595 | return numpy.arange(int(self.nFFTPoints)) | |
593 |
|
596 | |||
594 | def addIntegrator(self,N,timeInterval): |
|
597 | def addIntegrator(self,N,timeInterval): | |
595 |
|
598 | |||
596 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
599 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
597 | self.integratorObjList.append(objIncohInt) |
|
600 | self.integratorObjList.append(objIncohInt) | |
598 |
|
601 | |||
599 | def integrator(self, N=None, timeInterval=None): |
|
602 | def integrator(self, N=None, timeInterval=None): | |
600 |
|
603 | |||
601 | if self.dataOutObj.flagNoData: |
|
604 | if self.dataOutObj.flagNoData: | |
602 | return 0 |
|
605 | return 0 | |
603 |
|
606 | |||
604 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
607 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
605 | self.addIntegrator(N,timeInterval) |
|
608 | self.addIntegrator(N,timeInterval) | |
606 |
|
609 | |||
607 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
610 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
608 |
myIncohIntObj.exe(data=self.dataOutObj.data_spc,time |
|
611 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime) | |
609 |
|
612 | |||
610 | if myIncohIntObj.isReady: |
|
613 | if myIncohIntObj.isReady: | |
611 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
614 | self.dataOutObj.data_spc = myIncohIntObj.data | |
612 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg |
|
615 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg | |
613 | self.dataOutObj.flagNoData = False |
|
616 | self.dataOutObj.flagNoData = False | |
614 |
|
617 | |||
615 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) |
|
618 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) | |
616 | # self.getNoise(type="sort", parm=16) |
|
619 | # self.getNoise(type="sort", parm=16) | |
617 |
|
620 | |||
618 | else: |
|
621 | else: | |
619 | self.dataOutObj.flagNoData = True |
|
622 | self.dataOutObj.flagNoData = True | |
620 |
|
623 | |||
621 | self.integratorObjIndex += 1 |
|
624 | self.integratorObjIndex += 1 | |
622 |
|
625 | |||
623 |
|
626 | |||
624 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
627 | def addScope(self, idfigure, nframes, wintitle, driver): | |
625 |
|
628 | |||
626 | if idfigure==None: |
|
629 | if idfigure==None: | |
627 | idfigure = self.plotObjIndex |
|
630 | idfigure = self.plotObjIndex | |
628 |
|
631 | |||
629 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
632 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) | |
630 | self.plotObjList.append(scopeObj) |
|
633 | self.plotObjList.append(scopeObj) | |
631 |
|
634 | |||
632 | def plotScope(self, |
|
635 | def plotScope(self, | |
633 | idfigure=None, |
|
636 | idfigure=None, | |
634 | minvalue=None, |
|
637 | minvalue=None, | |
635 | maxvalue=None, |
|
638 | maxvalue=None, | |
636 | xmin=None, |
|
639 | xmin=None, | |
637 | xmax=None, |
|
640 | xmax=None, | |
638 | wintitle='', |
|
641 | wintitle='', | |
639 | driver='plplot', |
|
642 | driver='plplot', | |
640 | save=False, |
|
643 | save=False, | |
641 | gpath=None, |
|
644 | gpath=None, | |
642 | titleList=None, |
|
645 | titleList=None, | |
643 | xlabelList=None, |
|
646 | xlabelList=None, | |
644 | ylabelList=None): |
|
647 | ylabelList=None): | |
645 |
|
648 | |||
646 | if self.dataOutObj.flagNoData: |
|
649 | if self.dataOutObj.flagNoData: | |
647 | return 0 |
|
650 | return 0 | |
648 |
|
651 | |||
649 | nframes = len(self.dataOutObj.channelList) |
|
652 | nframes = len(self.dataOutObj.channelList) | |
650 |
|
653 | |||
651 | if len(self.plotObjList) <= self.plotObjIndex: |
|
654 | if len(self.plotObjList) <= self.plotObjIndex: | |
652 | self.addScope(idfigure, nframes, wintitle, driver) |
|
655 | self.addScope(idfigure, nframes, wintitle, driver) | |
653 |
|
656 | |||
654 |
|
657 | |||
655 | data1D = self.dataOutObj.data_spc |
|
658 | data1D = self.dataOutObj.data_spc | |
656 |
|
659 | |||
657 | x = numpy.arange(self.dataOutObj.nHeights) |
|
660 | x = numpy.arange(self.dataOutObj.nHeights) | |
658 |
|
661 | |||
659 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
662 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
660 |
|
663 | |||
661 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
664 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
662 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
665 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
663 |
|
666 | |||
664 | figureTitle = "Scope Plot Radar Data: " + date |
|
667 | figureTitle = "Scope Plot Radar Data: " + date | |
665 |
|
668 | |||
666 | plotObj = self.plotObjList[self.plotObjIndex] |
|
669 | plotObj = self.plotObjList[self.plotObjIndex] | |
667 |
|
670 | |||
668 | plotObj.plot1DArray(data1D, |
|
671 | plotObj.plot1DArray(data1D, | |
669 | x, |
|
672 | x, | |
670 | self.dataOutObj.channelList, |
|
673 | self.dataOutObj.channelList, | |
671 | xmin, |
|
674 | xmin, | |
672 | xmax, |
|
675 | xmax, | |
673 | minvalue, |
|
676 | minvalue, | |
674 | maxvalue, |
|
677 | maxvalue, | |
675 | figureTitle, |
|
678 | figureTitle, | |
676 | save, |
|
679 | save, | |
677 | gpath) |
|
680 | gpath) | |
678 |
|
681 | |||
679 | self.plotObjIndex += 1 |
|
682 | self.plotObjIndex += 1 | |
680 |
|
683 | |||
|
684 | ||||
|
685 | def addPlotMatScope(self, indexPlot,nsubplot,winTitle): | |||
|
686 | linearObj = LinearPlot(indexPlot,nsubplot,winTitle) | |||
|
687 | self.plotObjList.append(linearObj) | |||
|
688 | ||||
|
689 | def plotMatScope(self, idfigure, | |||
|
690 | channelList=None, | |||
|
691 | wintitle="", | |||
|
692 | save=None, | |||
|
693 | gpath=None): | |||
|
694 | ||||
|
695 | if self.dataOutObj.flagNoData: | |||
|
696 | return 0 | |||
|
697 | ||||
|
698 | if channelList == None: | |||
|
699 | channelList = self.dataOutObj.channelList | |||
|
700 | ||||
|
701 | nchannels = len(channelList) | |||
|
702 | ||||
|
703 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |||
|
704 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
705 | winTitle = "Spectra Profile" #+ dateTime | |||
|
706 | ||||
|
707 | if len(self.plotObjList) <= self.plotObjIndex: | |||
|
708 | self.addPlotMatScope(idfigure,nchannels,winTitle) | |||
|
709 | c = 3E8 | |||
|
710 | x=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*self.dataOutObj.nHeights*1000)) | |||
|
711 | x= x/(10000.0) | |||
|
712 | ||||
|
713 | data = 10*numpy.log10(self.dataOutObj.data_spc) | |||
|
714 | ||||
|
715 | subplotTitle = "Channel No." | |||
|
716 | xlabel = "Frecuencias(hz)*10K" | |||
|
717 | ylabel = "Potencia(dB)" | |||
|
718 | ||||
|
719 | isPlotIni=False | |||
|
720 | isPlotConfig=False | |||
|
721 | ||||
|
722 | ntimes=2 | |||
|
723 | nsubplot= nchannels | |||
|
724 | ||||
|
725 | plotObj = self.plotObjList[self.plotObjIndex] | |||
|
726 | ||||
|
727 | # for i in range(ntimes): | |||
|
728 | #Creacion de Subplots | |||
|
729 | if not(plotObj.isPlotIni): | |||
|
730 | for index in range(nsubplot): | |||
|
731 | indexplot = index + 1 | |||
|
732 | title = subplotTitle + '%d'%indexplot | |||
|
733 | xmin = numpy.min(x) | |||
|
734 | xmax = numpy.max(x) | |||
|
735 | ymin = numpy.min(data[index,:]) | |||
|
736 | ymax = numpy.max(data[index,:]) | |||
|
737 | plotObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel) | |||
|
738 | plotObj.isPlotIni =True | |||
|
739 | ||||
|
740 | # Inicializa el grafico en cada itearcion | |||
|
741 | plotObj.setFigure(idfigure) | |||
|
742 | plotObj.setFigure("") | |||
|
743 | ||||
|
744 | for index in range(nsubplot): | |||
|
745 | subplot = index | |||
|
746 | plotObj.iniPlot(subplot+1) | |||
|
747 | #Ploteo de datos | |||
|
748 | ||||
|
749 | for channel in range(nsubplot): | |||
|
750 | y=data[channel,:] | |||
|
751 | plotObj.plot(channel+1,x,y,type='simple') | |||
|
752 | ||||
|
753 | plotObj.refresh() | |||
|
754 | ||||
|
755 | #time.sleep(0.05) | |||
|
756 | ||||
|
757 | # plotObj.show() | |||
|
758 | ||||
|
759 | self.plotObjIndex += 1 | |||
|
760 | #print "Ploteo Finalizado" | |||
|
761 | ||||
681 | def rti(self): |
|
762 | def rti(self): | |
682 | if self.dataOutObj.flagNoData: |
|
763 | if self.dataOutObj.flagNoData: | |
683 | return 0 |
|
764 | return 0 | |
684 |
|
765 | |||
685 | data=numpy.average(self.dataOutObj.data_spc,axis=1) |
|
766 | data=numpy.average(self.dataOutObj.data_spc,axis=1) | |
686 | data[0] |
|
767 | data[0] | |
687 | print data[0] |
|
768 | print data[0] | |
688 | x = numpy.arange(100000) |
|
769 | x = numpy.arange(100000) | |
689 |
|
770 | |||
690 | print "test" |
|
771 | print "test" | |
691 | #print self.dataOutObj.data_spc.average(axis=1) |
|
772 | #print self.dataOutObj.data_spc.average(axis=1) | |
692 |
|
773 | |||
693 | class IncoherentIntegration: |
|
774 | class IncoherentIntegration: | |
694 |
|
775 | |||
695 | integ_counter = None |
|
776 | integ_counter = None | |
696 | data = None |
|
777 | data = None | |
697 | navg = None |
|
778 | navg = None | |
698 | buffer = None |
|
779 | buffer = None | |
699 | nIncohInt = None |
|
780 | nIncohInt = None | |
700 | firstdatatime = None |
|
781 | firstdatatime = None | |
701 |
|
782 | |||
702 | def __init__(self, N = None, timeInterval = None): |
|
783 | def __init__(self, N = None, timeInterval = None): | |
703 | """ |
|
784 | """ | |
704 | N |
|
785 | N | |
705 | timeInterval - interval time [min], integer value |
|
786 | timeInterval - interval time [min], integer value | |
706 | """ |
|
787 | """ | |
707 |
|
788 | |||
708 | self.data = None |
|
789 | self.data = None | |
709 | self.navg = None |
|
790 | self.navg = None | |
710 | self.buffer = None |
|
791 | self.buffer = None | |
711 | self.timeOut = None |
|
792 | self.timeOut = None | |
712 | self.exitCondition = False |
|
793 | self.exitCondition = False | |
713 | self.isReady = False |
|
794 | self.isReady = False | |
714 | self.nIncohInt = N |
|
795 | self.nIncohInt = N | |
715 | self.integ_counter = 0 |
|
796 | self.integ_counter = 0 | |
716 | self.firstdatatime = None |
|
797 | self.firstdatatime = None | |
717 |
|
798 | |||
718 | if timeInterval!=None: |
|
799 | if timeInterval!=None: | |
719 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
800 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
720 |
|
801 | |||
721 | if ((timeInterval==None) and (N==None)): |
|
802 | if ((timeInterval==None) and (N==None)): | |
722 | print 'N = None ; timeInterval = None' |
|
803 | print 'N = None ; timeInterval = None' | |
723 | sys.exit(0) |
|
804 | sys.exit(0) | |
724 | elif timeInterval == None: |
|
805 | elif timeInterval == None: | |
725 | self.timeFlag = False |
|
806 | self.timeFlag = False | |
726 | else: |
|
807 | else: | |
727 | self.timeFlag = True |
|
808 | self.timeFlag = True | |
728 |
|
809 | |||
729 |
|
810 | |||
730 | def exe(self,data,datatime): |
|
811 | def exe(self,data,datatime): | |
731 | """ |
|
812 | """ | |
732 | data |
|
813 | data | |
733 |
|
814 | |||
734 | datatime [seconds] |
|
815 | datatime [seconds] | |
735 | """ |
|
816 | """ | |
736 | if self.firstdatatime == None or self.isReady: |
|
817 | if self.firstdatatime == None or self.isReady: | |
737 | self.firstdatatime = datatime |
|
818 | self.firstdatatime = datatime | |
738 |
|
819 | |||
739 | if self.timeFlag: |
|
820 | if self.timeFlag: | |
740 | if self.timeOut == None: |
|
821 | if self.timeOut == None: | |
741 | self.timeOut = datatime + self.timeIntervalInSeconds |
|
822 | self.timeOut = datatime + self.timeIntervalInSeconds | |
742 |
|
823 | |||
743 | if datatime < self.timeOut: |
|
824 | if datatime < self.timeOut: | |
744 | if self.buffer == None: |
|
825 | if self.buffer == None: | |
745 | self.buffer = data |
|
826 | self.buffer = data | |
746 | else: |
|
827 | else: | |
747 | self.buffer = self.buffer + data |
|
828 | self.buffer = self.buffer + data | |
748 | self.integ_counter += 1 |
|
829 | self.integ_counter += 1 | |
749 | else: |
|
830 | else: | |
750 | self.exitCondition = True |
|
831 | self.exitCondition = True | |
751 |
|
832 | |||
752 | else: |
|
833 | else: | |
753 | if self.integ_counter < self.nIncohInt: |
|
834 | if self.integ_counter < self.nIncohInt: | |
754 | if self.buffer == None: |
|
835 | if self.buffer == None: | |
755 | self.buffer = data |
|
836 | self.buffer = data | |
756 | else: |
|
837 | else: | |
757 | self.buffer = self.buffer + data |
|
838 | self.buffer = self.buffer + data | |
758 |
|
839 | |||
759 | self.integ_counter += 1 |
|
840 | self.integ_counter += 1 | |
760 |
|
841 | |||
761 | if self.integ_counter == self.nIncohInt: |
|
842 | if self.integ_counter == self.nIncohInt: | |
762 | self.exitCondition = True |
|
843 | self.exitCondition = True | |
763 |
|
844 | |||
764 | if self.exitCondition: |
|
845 | if self.exitCondition: | |
765 | self.data = self.buffer |
|
846 | self.data = self.buffer | |
766 | self.navg = self.integ_counter |
|
847 | self.navg = self.integ_counter | |
767 | self.isReady = True |
|
848 | self.isReady = True | |
768 | self.buffer = None |
|
849 | self.buffer = None | |
769 | self.timeOut = None |
|
850 | self.timeOut = None | |
770 | self.integ_counter = 0 |
|
851 | self.integ_counter = 0 | |
771 | self.exitCondition = False |
|
852 | self.exitCondition = False | |
772 |
|
853 | |||
773 | if self.timeFlag: |
|
854 | if self.timeFlag: | |
774 | self.buffer = data |
|
855 | self.buffer = data | |
775 | self.timeOut = datatime + self.timeIntervalInSeconds |
|
856 | self.timeOut = datatime + self.timeIntervalInSeconds | |
776 | else: |
|
857 | else: | |
777 | self.isReady = False |
|
858 | self.isReady = False | |
778 | No newline at end of file |
|
859 |
@@ -1,103 +1,112 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 31, 2012 |
|
2 | Created on Jul 31, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | import os, sys |
|
8 | import os, sys | |
9 | import time, datetime |
|
9 | import time, datetime | |
10 | #import pylab as pl |
|
10 | #import pylab as pl | |
11 |
|
11 | |||
12 | from Data.JROData import Voltage |
|
12 | from Data.JROData import Voltage | |
13 | from IO.VoltageIO import * |
|
13 | from IO.VoltageIO import * | |
14 |
|
14 | |||
15 | from Data.JROData import SpectraHeis |
|
15 | from Data.JROData import SpectraHeis | |
16 | from IO.SpectraIO import * |
|
16 | from IO.SpectraIO import * | |
17 |
|
17 | |||
18 | from Processing.VoltageProcessor import * |
|
18 | from Processing.VoltageProcessor import * | |
19 | from Processing.SpectraProcessor import * |
|
19 | from Processing.SpectraProcessor import * | |
20 |
|
20 | |||
21 | #from Graphics.BaseGraph_mpl import LinearPlot |
|
21 | #from Graphics.BaseGraph_mpl import LinearPlot | |
22 |
|
22 | |||
23 | class TestHeis(): |
|
23 | class TestHeis(): | |
24 | i=None |
|
24 | ||
25 | def __init__(self): |
|
25 | def __init__(self): | |
26 | self.setValues() |
|
26 | self.setValues() | |
27 | self.createObjects() |
|
27 | self.createObjects() | |
28 | self.testSChain() |
|
28 | self.testSChain() | |
29 | self.i=0 |
|
29 | self.i=0 | |
30 |
|
|
30 | ||
|
31 | ||||
|
32 | def VerifyArguments(self): | |||
|
33 | pass | |||
|
34 | ||||
|
35 | ||||
|
36 | ||||
31 |
def setValues( |
|
37 | def setValues(self): | |
32 |
|
38 | |||
33 | self.path="/home/roj-idl71/data" |
|
39 | ||
|
40 | ||||
|
41 | self.path="D:\\te" | |||
34 |
|
42 | |||
35 | #self.path = "" |
|
43 | #self.path = "" | |
36 |
self.startDate = datetime.date(2012, |
|
44 | # self.startDate = datetime.date(2012,10,1) | |
37 |
self.endDate = datetime.date(2012, |
|
45 | # self.endDate = datetime.date(2012,12,30) | |
|
46 | # | |||
|
47 | # self.startTime = datetime.time(0,0,0) | |||
|
48 | # self.endTime = datetime.time(23,0,0) | |||
|
49 | # | |||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | self.N=1000 | |||
38 |
|
54 | |||
39 | self.startTime = datetime.time(0,0,0) |
|
55 | self.wrpath = "D:\\te\\FITS" | |
40 | self.endTime = datetime.time(23,0,0) |
|
|||
41 |
|
56 | |||
|
57 | self.online | |||
42 |
|
58 | |||
|
59 | self.startDate = None | |||
|
60 | self.endDate = None | |||
|
61 | self.startTime = None | |||
|
62 | self.endTime = None | |||
|
63 | ||||
|
64 | # self.blocksPerFile = 1 | |||
43 | def createObjects( self ): |
|
65 | def createObjects( self ): | |
44 |
|
66 | |||
45 | self.readerObj = VoltageReader() |
|
67 | self.readerObj = VoltageReader() | |
46 | self.specProcObj = SpectraHeisProcessor() |
|
68 | self.specProcObj = SpectraHeisProcessor() | |
47 |
|
||||
48 | self.voltObj1 = self.readerObj.setup( |
|
69 | self.voltObj1 = self.readerObj.setup( | |
49 | path = self.path, |
|
70 | path = self.path, | |
50 | startDate = self.startDate, |
|
71 | startDate = self.startDate, | |
51 | endDate = self.endDate, |
|
72 | endDate = self.endDate, | |
52 | startTime = self.startTime, |
|
73 | startTime = self.startTime, | |
53 | endTime = self.endTime, |
|
74 | endTime = self.endTime, | |
54 | expLabel = '', |
|
75 | expLabel = '', | |
55 |
online = |
|
76 | online = self.online) | |
56 |
|
77 | |||
57 | if not(self.voltObj1): |
|
78 | if not(self.voltObj1): | |
58 | sys.exit(0) |
|
79 | sys.exit(0) | |
59 |
|
80 | |||
60 | self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights) |
|
81 | self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights) | |
61 |
|
||||
62 |
|
||||
63 | # |
|
|||
64 |
|
||||
65 | # |
|
82 | # | |
66 |
|
||||
67 | def testSChain( self ): |
|
83 | def testSChain( self ): | |
68 |
|
84 | |||
69 | ini = time.time() |
|
85 | ini = time.time() | |
70 | counter = 0 |
|
86 | counter = 0 | |
71 | while(True): |
|
87 | while(True): | |
72 | self.readerObj.getData() |
|
88 | self.readerObj.getData() | |
73 | self.specProcObj.init() |
|
|||
74 |
|
||||
75 | self.specProcObj.integrator(N=32) ## return self.dataOutObj |
|
|||
76 |
|
||||
77 |
|
89 | |||
|
90 | self.specProcObj.init() | |||
78 |
|
91 | |||
|
92 | self.specProcObj.integrator(self.N) ## return self.dataOutObj | |||
79 |
|
93 | |||
80 |
self.specProcObj. |
|
94 | self.specProcObj.writedata(self.wrpath) | |
81 | wintitle='test plot library', |
|
|||
82 | driver='plplot', |
|
|||
83 | minvalue = 30000.0, |
|
|||
84 | maxvalue = 5000000.0, |
|
|||
85 | save=True, |
|
|||
86 | gpath="/home/roj-idl71/PlotImage") |
|
|||
87 |
|
95 | |||
|
96 | self.specProcObj.plotMatScope(idfigure=1) | |||
88 |
|
97 | |||
89 |
if self.readerObj.flagNoMoreFiles: |
|
98 | if self.readerObj.flagNoMoreFiles: | |
90 | break |
|
99 | break | |
91 |
|
100 | |||
92 |
|
101 | |||
93 |
|
102 | |||
94 | if self.readerObj.flagIsNewBlock: |
|
103 | if self.readerObj.flagIsNewBlock: | |
95 | print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, |
|
104 | print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, | |
96 | datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),) |
|
105 | datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),) | |
97 |
|
106 | |||
98 |
|
107 | |||
99 |
|
108 | |||
100 | if __name__ == '__main__': |
|
109 | if __name__ == '__main__': | |
101 | TestHeis() |
|
110 | TestHeis() | |
102 |
|
111 | |||
103 | No newline at end of file |
|
112 |
General Comments 0
You need to be logged in to leave comments.
Login now