@@ -1,737 +1,736 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 2, 2014 |
|
2 | Created on Jul 2, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import numpy |
|
7 | import numpy | |
8 |
|
8 | |||
9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter | |
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
12 | from schainpy.model.data.jrodata import Voltage |
|
12 | from schainpy.model.data.jrodata import Voltage | |
13 | import zmq |
|
13 | import zmq | |
14 | import tempfile |
|
14 | import tempfile | |
15 | from StringIO import StringIO |
|
15 | from StringIO import StringIO | |
16 | # from _sha import blocksize |
|
16 | # from _sha import blocksize | |
17 |
|
17 | |||
18 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
18 | class VoltageReader(JRODataReader, ProcessingUnit): | |
19 | """ |
|
19 | """ | |
20 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
20 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
21 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
21 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
22 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
22 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
23 |
|
23 | |||
24 | perfiles * alturas * canales |
|
24 | perfiles * alturas * canales | |
25 |
|
25 | |||
26 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
26 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
27 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
27 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
28 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
28 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
29 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
29 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
30 |
|
30 | |||
31 | Example: |
|
31 | Example: | |
32 |
|
32 | |||
33 | dpath = "/home/myuser/data" |
|
33 | dpath = "/home/myuser/data" | |
34 |
|
34 | |||
35 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
35 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
36 |
|
36 | |||
37 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
37 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
38 |
|
38 | |||
39 | readerObj = VoltageReader() |
|
39 | readerObj = VoltageReader() | |
40 |
|
40 | |||
41 | readerObj.setup(dpath, startTime, endTime) |
|
41 | readerObj.setup(dpath, startTime, endTime) | |
42 |
|
42 | |||
43 | while(True): |
|
43 | while(True): | |
44 |
|
44 | |||
45 | #to get one profile |
|
45 | #to get one profile | |
46 | profile = readerObj.getData() |
|
46 | profile = readerObj.getData() | |
47 |
|
47 | |||
48 | #print the profile |
|
48 | #print the profile | |
49 | print profile |
|
49 | print profile | |
50 |
|
50 | |||
51 | #If you want to see all datablock |
|
51 | #If you want to see all datablock | |
52 | print readerObj.datablock |
|
52 | print readerObj.datablock | |
53 |
|
53 | |||
54 | if readerObj.flagNoMoreFiles: |
|
54 | if readerObj.flagNoMoreFiles: | |
55 | break |
|
55 | break | |
56 |
|
56 | |||
57 | """ |
|
57 | """ | |
58 |
|
58 | |||
59 | ext = ".r" |
|
59 | ext = ".r" | |
60 |
|
60 | |||
61 | optchar = "D" |
|
61 | optchar = "D" | |
62 | dataOut = None |
|
62 | dataOut = None | |
63 |
|
63 | |||
64 | def __init__(self, **kwargs): |
|
64 | def __init__(self, **kwargs): | |
65 | """ |
|
65 | """ | |
66 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
66 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
67 |
|
67 | |||
68 | Input: |
|
68 | Input: | |
69 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
69 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
70 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
70 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
71 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
71 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
72 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
72 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
73 | bloque de datos. |
|
73 | bloque de datos. | |
74 | Si este parametro no es pasado se creara uno internamente. |
|
74 | Si este parametro no es pasado se creara uno internamente. | |
75 |
|
75 | |||
76 | Variables afectadas: |
|
76 | Variables afectadas: | |
77 | self.dataOut |
|
77 | self.dataOut | |
78 |
|
78 | |||
79 | Return: |
|
79 | Return: | |
80 | None |
|
80 | None | |
81 | """ |
|
81 | """ | |
82 |
|
82 | |||
83 | ProcessingUnit.__init__(self, **kwargs) |
|
83 | ProcessingUnit.__init__(self, **kwargs) | |
84 |
|
84 | |||
85 | self.isConfig = False |
|
85 | self.isConfig = False | |
86 |
|
86 | |||
87 | self.datablock = None |
|
87 | self.datablock = None | |
88 |
|
88 | |||
89 | self.utc = 0 |
|
89 | self.utc = 0 | |
90 |
|
90 | |||
91 | self.ext = ".r" |
|
91 | self.ext = ".r" | |
92 |
|
92 | |||
93 | self.optchar = "D" |
|
93 | self.optchar = "D" | |
94 |
|
94 | |||
95 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
95 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
96 |
|
96 | |||
97 | self.systemHeaderObj = SystemHeader() |
|
97 | self.systemHeaderObj = SystemHeader() | |
98 |
|
98 | |||
99 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
99 | self.radarControllerHeaderObj = RadarControllerHeader() | |
100 |
|
100 | |||
101 | self.processingHeaderObj = ProcessingHeader() |
|
101 | self.processingHeaderObj = ProcessingHeader() | |
102 |
|
102 | |||
103 | self.online = 0 |
|
103 | self.online = 0 | |
104 |
|
104 | |||
105 | self.fp = None |
|
105 | self.fp = None | |
106 |
|
106 | |||
107 | self.idFile = None |
|
107 | self.idFile = None | |
108 |
|
108 | |||
109 | self.dtype = None |
|
109 | self.dtype = None | |
110 |
|
110 | |||
111 | self.fileSizeByHeader = None |
|
111 | self.fileSizeByHeader = None | |
112 |
|
112 | |||
113 | self.filenameList = [] |
|
113 | self.filenameList = [] | |
114 |
|
114 | |||
115 | self.filename = None |
|
115 | self.filename = None | |
116 |
|
116 | |||
117 | self.fileSize = None |
|
117 | self.fileSize = None | |
118 |
|
118 | |||
119 | self.firstHeaderSize = 0 |
|
119 | self.firstHeaderSize = 0 | |
120 |
|
120 | |||
121 | self.basicHeaderSize = 24 |
|
121 | self.basicHeaderSize = 24 | |
122 |
|
122 | |||
123 | self.pathList = [] |
|
123 | self.pathList = [] | |
124 |
|
124 | |||
125 | self.filenameList = [] |
|
125 | self.filenameList = [] | |
126 |
|
126 | |||
127 | self.lastUTTime = 0 |
|
127 | self.lastUTTime = 0 | |
128 |
|
128 | |||
129 | self.maxTimeStep = 30 |
|
129 | self.maxTimeStep = 30 | |
130 |
|
130 | |||
131 | self.flagNoMoreFiles = 0 |
|
131 | self.flagNoMoreFiles = 0 | |
132 |
|
132 | |||
133 | self.set = 0 |
|
133 | self.set = 0 | |
134 |
|
134 | |||
135 | self.path = None |
|
135 | self.path = None | |
136 |
|
136 | |||
137 | self.profileIndex = 2**32-1 |
|
137 | self.profileIndex = 2**32-1 | |
138 |
|
138 | |||
139 | self.delay = 3 #seconds |
|
139 | self.delay = 3 #seconds | |
140 |
|
140 | |||
141 | self.nTries = 3 #quantity tries |
|
141 | self.nTries = 3 #quantity tries | |
142 |
|
142 | |||
143 | self.nFiles = 3 #number of files for searching |
|
143 | self.nFiles = 3 #number of files for searching | |
144 |
|
144 | |||
145 | self.nReadBlocks = 0 |
|
145 | self.nReadBlocks = 0 | |
146 |
|
146 | |||
147 | self.flagIsNewFile = 1 |
|
147 | self.flagIsNewFile = 1 | |
148 |
|
148 | |||
149 | self.__isFirstTimeOnline = 1 |
|
149 | self.__isFirstTimeOnline = 1 | |
150 |
|
150 | |||
151 | # self.ippSeconds = 0 |
|
151 | # self.ippSeconds = 0 | |
152 |
|
152 | |||
153 | self.flagDiscontinuousBlock = 0 |
|
153 | self.flagDiscontinuousBlock = 0 | |
154 |
|
154 | |||
155 | self.flagIsNewBlock = 0 |
|
155 | self.flagIsNewBlock = 0 | |
156 |
|
156 | |||
157 | self.nTotalBlocks = 0 |
|
157 | self.nTotalBlocks = 0 | |
158 |
|
158 | |||
159 | self.blocksize = 0 |
|
159 | self.blocksize = 0 | |
160 |
|
160 | |||
161 | self.dataOut = self.createObjByDefault() |
|
161 | self.dataOut = self.createObjByDefault() | |
162 |
|
162 | |||
163 | self.nTxs = 1 |
|
163 | self.nTxs = 1 | |
164 |
|
164 | |||
165 | self.txIndex = 0 |
|
165 | self.txIndex = 0 | |
166 |
|
166 | |||
167 | def createObjByDefault(self): |
|
167 | def createObjByDefault(self): | |
168 |
|
168 | |||
169 | dataObj = Voltage() |
|
169 | dataObj = Voltage() | |
170 |
|
170 | |||
171 | return dataObj |
|
171 | return dataObj | |
172 |
|
172 | |||
173 | def __hasNotDataInBuffer(self): |
|
173 | def __hasNotDataInBuffer(self): | |
174 |
|
174 | |||
175 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs: |
|
175 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs: | |
176 | return 1 |
|
176 | return 1 | |
177 |
|
177 | |||
178 | return 0 |
|
178 | return 0 | |
179 |
|
179 | |||
180 |
|
180 | |||
181 | def getBlockDimension(self): |
|
181 | def getBlockDimension(self): | |
182 | """ |
|
182 | """ | |
183 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
183 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
184 |
|
184 | |||
185 | Affected: |
|
185 | Affected: | |
186 | self.blocksize |
|
186 | self.blocksize | |
187 |
|
187 | |||
188 | Return: |
|
188 | Return: | |
189 | None |
|
189 | None | |
190 | """ |
|
190 | """ | |
191 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
191 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
192 | self.blocksize = pts2read |
|
192 | self.blocksize = pts2read | |
193 |
|
193 | |||
194 |
|
194 | |||
195 |
|
195 | |||
196 | def readBlock(self): |
|
196 | def readBlock(self): | |
197 | """ |
|
197 | """ | |
198 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
198 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
199 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
199 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
200 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
200 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
201 | es seteado a 0 |
|
201 | es seteado a 0 | |
202 |
|
202 | |||
203 | Inputs: |
|
203 | Inputs: | |
204 | None |
|
204 | None | |
205 |
|
205 | |||
206 | Return: |
|
206 | Return: | |
207 | None |
|
207 | None | |
208 |
|
208 | |||
209 | Affected: |
|
209 | Affected: | |
210 | self.profileIndex |
|
210 | self.profileIndex | |
211 | self.datablock |
|
211 | self.datablock | |
212 | self.flagIsNewFile |
|
212 | self.flagIsNewFile | |
213 | self.flagIsNewBlock |
|
213 | self.flagIsNewBlock | |
214 | self.nTotalBlocks |
|
214 | self.nTotalBlocks | |
215 |
|
215 | |||
216 | Exceptions: |
|
216 | Exceptions: | |
217 | Si un bloque leido no es un bloque valido |
|
217 | Si un bloque leido no es un bloque valido | |
218 | """ |
|
218 | """ | |
219 |
|
219 | |||
220 | # if self.server is not None: |
|
220 | # if self.server is not None: | |
221 | # self.zBlock = self.receiver.recv() |
|
221 | # self.zBlock = self.receiver.recv() | |
222 | # self.zHeader = self.zBlock[:24] |
|
222 | # self.zHeader = self.zBlock[:24] | |
223 | # self.zDataBlock = self.zBlock[24:] |
|
223 | # self.zDataBlock = self.zBlock[24:] | |
224 | # junk = numpy.fromstring(self.zDataBlock, numpy.dtype([('real','<i4'),('imag','<i4')])) |
|
224 | # junk = numpy.fromstring(self.zDataBlock, numpy.dtype([('real','<i4'),('imag','<i4')])) | |
225 | # self.processingHeaderObj.profilesPerBlock = 240 |
|
225 | # self.processingHeaderObj.profilesPerBlock = 240 | |
226 | # self.processingHeaderObj.nHeights = 248 |
|
226 | # self.processingHeaderObj.nHeights = 248 | |
227 | # self.systemHeaderObj.nChannels |
|
227 | # self.systemHeaderObj.nChannels | |
228 | # else: |
|
228 | # else: | |
229 | current_pointer_location = self.fp.tell() |
|
229 | current_pointer_location = self.fp.tell() | |
230 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
230 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
231 |
|
231 | |||
232 | try: |
|
232 | try: | |
233 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
233 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
234 | except: |
|
234 | except: | |
235 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
235 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
236 |
|
236 | |||
237 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
237 | if self.waitDataBlock(pointer_location=current_pointer_location): | |
238 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
238 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
239 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
239 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
240 | # return 0 |
|
240 | # return 0 | |
241 |
|
241 | |||
242 | #Dimensions : nChannels, nProfiles, nSamples |
|
242 | #Dimensions : nChannels, nProfiles, nSamples | |
243 |
|
243 | |||
244 | junk = numpy.transpose(junk, (2,0,1)) |
|
244 | junk = numpy.transpose(junk, (2,0,1)) | |
245 | self.datablock = junk['real'] + junk['imag']*1j |
|
245 | self.datablock = junk['real'] + junk['imag']*1j | |
246 |
|
246 | |||
247 | self.profileIndex = 0 |
|
247 | self.profileIndex = 0 | |
248 |
|
248 | |||
249 | self.flagIsNewFile = 0 |
|
249 | self.flagIsNewFile = 0 | |
250 | self.flagIsNewBlock = 1 |
|
250 | self.flagIsNewBlock = 1 | |
251 |
|
251 | |||
252 | self.nTotalBlocks += 1 |
|
252 | self.nTotalBlocks += 1 | |
253 | self.nReadBlocks += 1 |
|
253 | self.nReadBlocks += 1 | |
254 |
|
254 | |||
255 | return 1 |
|
255 | return 1 | |
256 |
|
256 | |||
257 | def getFirstHeader(self): |
|
257 | def getFirstHeader(self): | |
258 |
|
258 | |||
259 | self.getBasicHeader() |
|
259 | self.getBasicHeader() | |
260 |
|
260 | |||
261 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
261 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
262 |
|
262 | |||
263 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
263 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
264 |
|
264 | |||
265 | if self.nTxs > 1: |
|
265 | if self.nTxs > 1: | |
266 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
266 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
267 |
|
||||
268 | #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. |
|
267 | #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. | |
269 |
|
268 | |||
270 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
|
269 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt | |
271 | # |
|
270 | # | |
272 | # if self.radarControllerHeaderObj.code is not None: |
|
271 | # if self.radarControllerHeaderObj.code is not None: | |
273 | # |
|
272 | # | |
274 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
273 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
275 | # |
|
274 | # | |
276 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
275 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
277 | # |
|
276 | # | |
278 | # self.dataOut.code = self.radarControllerHeaderObj.code |
|
277 | # self.dataOut.code = self.radarControllerHeaderObj.code | |
279 |
|
278 | |||
280 | self.dataOut.dtype = self.dtype |
|
279 | self.dataOut.dtype = self.dtype | |
281 |
|
280 | |||
282 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
281 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
283 |
|
282 | |||
284 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight |
|
283 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
285 |
|
284 | |||
286 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
285 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
287 |
|
286 | |||
288 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
287 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
289 |
|
288 | |||
290 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada |
|
289 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada | |
291 |
|
290 | |||
292 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip |
|
291 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip | |
293 |
|
292 | |||
294 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
293 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
295 |
|
294 | |||
296 | def reshapeData(self): |
|
295 | def reshapeData(self): | |
297 |
|
296 | |||
298 | if self.nTxs < 0: |
|
297 | if self.nTxs < 0: | |
299 | return |
|
298 | return | |
300 |
|
299 | |||
301 | if self.nTxs == 1: |
|
300 | if self.nTxs == 1: | |
302 | return |
|
301 | return | |
303 |
|
302 | |||
304 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0: |
|
303 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0: | |
305 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %(1./self.nTxs, self.processingHeaderObj.profilesPerBlock) |
|
304 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %(1./self.nTxs, self.processingHeaderObj.profilesPerBlock) | |
306 |
|
305 | |||
307 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
306 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: | |
308 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %(self.nTxs, self.processingHeaderObj.nHeights) |
|
307 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %(self.nTxs, self.processingHeaderObj.nHeights) | |
309 |
|
308 | |||
310 | self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs)) |
|
309 | self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs)) | |
311 |
|
310 | |||
312 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
311 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs | |
313 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight |
|
312 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
314 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
313 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
315 |
|
314 | |||
316 | return |
|
315 | return | |
317 |
|
316 | |||
318 | def readFirstHeaderFromServer(self): |
|
317 | def readFirstHeaderFromServer(self): | |
319 |
|
318 | |||
320 | self.getFirstHeader() |
|
319 | self.getFirstHeader() | |
321 |
|
320 | |||
322 | self.firstHeaderSize = self.basicHeaderObj.size |
|
321 | self.firstHeaderSize = self.basicHeaderObj.size | |
323 |
|
322 | |||
324 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
323 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
325 | if datatype == 0: |
|
324 | if datatype == 0: | |
326 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
325 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
327 | elif datatype == 1: |
|
326 | elif datatype == 1: | |
328 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
327 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
329 | elif datatype == 2: |
|
328 | elif datatype == 2: | |
330 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
329 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
331 | elif datatype == 3: |
|
330 | elif datatype == 3: | |
332 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
331 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
333 | elif datatype == 4: |
|
332 | elif datatype == 4: | |
334 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
333 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
335 | elif datatype == 5: |
|
334 | elif datatype == 5: | |
336 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
335 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
337 | else: |
|
336 | else: | |
338 | raise ValueError, 'Data type was not defined' |
|
337 | raise ValueError, 'Data type was not defined' | |
339 |
|
338 | |||
340 | self.dtype = datatype_str |
|
339 | self.dtype = datatype_str | |
341 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
340 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
342 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
341 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
343 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
342 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
344 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
343 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
345 | self.getBlockDimension() |
|
344 | self.getBlockDimension() | |
346 |
|
345 | |||
347 |
|
346 | |||
348 | def getFromServer(self): |
|
347 | def getFromServer(self): | |
349 | self.flagDiscontinuousBlock = 0 |
|
348 | self.flagDiscontinuousBlock = 0 | |
350 | self.profileIndex = 0 |
|
349 | self.profileIndex = 0 | |
351 | self.flagIsNewBlock = 1 |
|
350 | self.flagIsNewBlock = 1 | |
352 | self.dataOut.flagNoData = False |
|
351 | self.dataOut.flagNoData = False | |
353 | self.nTotalBlocks += 1 |
|
352 | self.nTotalBlocks += 1 | |
354 | self.nReadBlocks += 1 |
|
353 | self.nReadBlocks += 1 | |
355 | self.blockPointer = 0 |
|
354 | self.blockPointer = 0 | |
356 |
|
355 | |||
357 | block = self.receiver.recv() |
|
356 | block = self.receiver.recv() | |
358 |
|
357 | |||
359 | self.basicHeaderObj.read(block[self.blockPointer:]) |
|
358 | self.basicHeaderObj.read(block[self.blockPointer:]) | |
360 | self.blockPointer += self.basicHeaderObj.length |
|
359 | self.blockPointer += self.basicHeaderObj.length | |
361 | self.systemHeaderObj.read(block[self.blockPointer:]) |
|
360 | self.systemHeaderObj.read(block[self.blockPointer:]) | |
362 | self.blockPointer += self.systemHeaderObj.length |
|
361 | self.blockPointer += self.systemHeaderObj.length | |
363 | self.radarControllerHeaderObj.read(block[self.blockPointer:]) |
|
362 | self.radarControllerHeaderObj.read(block[self.blockPointer:]) | |
364 | self.blockPointer += self.radarControllerHeaderObj.length |
|
363 | self.blockPointer += self.radarControllerHeaderObj.length | |
365 | self.processingHeaderObj.read(block[self.blockPointer:]) |
|
364 | self.processingHeaderObj.read(block[self.blockPointer:]) | |
366 | self.blockPointer += self.processingHeaderObj.length |
|
365 | self.blockPointer += self.processingHeaderObj.length | |
367 | self.readFirstHeaderFromServer() |
|
366 | self.readFirstHeaderFromServer() | |
368 |
|
367 | |||
369 | timestamp = self.basicHeaderObj.get_datatime() |
|
368 | timestamp = self.basicHeaderObj.get_datatime() | |
370 | print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp) |
|
369 | print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp) | |
371 | current_pointer_location = self.blockPointer |
|
370 | current_pointer_location = self.blockPointer | |
372 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) |
|
371 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) | |
373 |
|
372 | |||
374 | try: |
|
373 | try: | |
375 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
374 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
376 | except: |
|
375 | except: | |
377 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
376 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
378 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
377 | if self.waitDataBlock(pointer_location=current_pointer_location): | |
379 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) |
|
378 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) | |
380 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
379 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
381 | # return 0 |
|
380 | # return 0 | |
382 |
|
381 | |||
383 | #Dimensions : nChannels, nProfiles, nSamples |
|
382 | #Dimensions : nChannels, nProfiles, nSamples | |
384 |
|
383 | |||
385 | junk = numpy.transpose(junk, (2,0,1)) |
|
384 | junk = numpy.transpose(junk, (2,0,1)) | |
386 | self.datablock = junk['real'] + junk['imag'] * 1j |
|
385 | self.datablock = junk['real'] + junk['imag'] * 1j | |
387 | self.profileIndex = 0 |
|
386 | self.profileIndex = 0 | |
388 | if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles |
|
387 | if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles | |
389 | if self.selBlocktime != None: |
|
388 | if self.selBlocktime != None: | |
390 | if self.dataOut.nCohInt is not None: |
|
389 | if self.dataOut.nCohInt is not None: | |
391 | nCohInt = self.dataOut.nCohInt |
|
390 | nCohInt = self.dataOut.nCohInt | |
392 | else: |
|
391 | else: | |
393 | nCohInt = 1 |
|
392 | nCohInt = 1 | |
394 | self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles))) |
|
393 | self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles))) | |
395 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] |
|
394 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] | |
396 | datasize = self.dataOut.data.shape[1] |
|
395 | datasize = self.dataOut.data.shape[1] | |
397 | if datasize < self.selBlocksize: |
|
396 | if datasize < self.selBlocksize: | |
398 | buffer = numpy.zeros((self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype = 'complex') |
|
397 | buffer = numpy.zeros((self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype = 'complex') | |
399 | buffer[:,:datasize,:] = self.dataOut.data |
|
398 | buffer[:,:datasize,:] = self.dataOut.data | |
400 | self.dataOut.data = buffer |
|
399 | self.dataOut.data = buffer | |
401 | self.profileIndex = blockIndex |
|
400 | self.profileIndex = blockIndex | |
402 |
|
401 | |||
403 | self.dataOut.flagDataAsBlock = True |
|
402 | self.dataOut.flagDataAsBlock = True | |
404 | self.flagIsNewBlock = 1 |
|
403 | self.flagIsNewBlock = 1 | |
405 | self.dataOut.realtime = self.online |
|
404 | self.dataOut.realtime = self.online | |
406 |
|
405 | |||
407 | return self.dataOut.data |
|
406 | return self.dataOut.data | |
408 |
|
407 | |||
409 | def getData(self): |
|
408 | def getData(self): | |
410 | """ |
|
409 | """ | |
411 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut |
|
410 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut | |
412 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos |
|
411 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos | |
413 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando |
|
412 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando | |
414 | "readNextBlock" |
|
413 | "readNextBlock" | |
415 |
|
414 | |||
416 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. |
|
415 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. | |
417 |
|
416 | |||
418 | Return: |
|
417 | Return: | |
419 |
|
418 | |||
420 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex |
|
419 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex | |
421 | es igual al total de perfiles leidos desde el archivo. |
|
420 | es igual al total de perfiles leidos desde el archivo. | |
422 |
|
421 | |||
423 | Si self.getByBlock == False: |
|
422 | Si self.getByBlock == False: | |
424 |
|
423 | |||
425 | self.dataOut.data = buffer[:, thisProfile, :] |
|
424 | self.dataOut.data = buffer[:, thisProfile, :] | |
426 |
|
425 | |||
427 | shape = [nChannels, nHeis] |
|
426 | shape = [nChannels, nHeis] | |
428 |
|
427 | |||
429 | Si self.getByBlock == True: |
|
428 | Si self.getByBlock == True: | |
430 |
|
429 | |||
431 | self.dataOut.data = buffer[:, :, :] |
|
430 | self.dataOut.data = buffer[:, :, :] | |
432 |
|
431 | |||
433 | shape = [nChannels, nProfiles, nHeis] |
|
432 | shape = [nChannels, nProfiles, nHeis] | |
434 |
|
433 | |||
435 | Variables afectadas: |
|
434 | Variables afectadas: | |
436 | self.dataOut |
|
435 | self.dataOut | |
437 | self.profileIndex |
|
436 | self.profileIndex | |
438 |
|
437 | |||
439 | Affected: |
|
438 | Affected: | |
440 | self.dataOut |
|
439 | self.dataOut | |
441 | self.profileIndex |
|
440 | self.profileIndex | |
442 | self.flagDiscontinuousBlock |
|
441 | self.flagDiscontinuousBlock | |
443 | self.flagIsNewBlock |
|
442 | self.flagIsNewBlock | |
444 | """ |
|
443 | """ | |
445 | if self.flagNoMoreFiles: |
|
444 | if self.flagNoMoreFiles: | |
446 | self.dataOut.flagNoData = True |
|
445 | self.dataOut.flagNoData = True | |
447 | print 'Process finished' |
|
446 | print 'Process finished' | |
448 | return 0 |
|
447 | return 0 | |
449 | self.flagDiscontinuousBlock = 0 |
|
448 | self.flagDiscontinuousBlock = 0 | |
450 | self.flagIsNewBlock = 0 |
|
449 | self.flagIsNewBlock = 0 | |
451 | if self.__hasNotDataInBuffer(): |
|
450 | if self.__hasNotDataInBuffer(): | |
452 | if not( self.readNextBlock() ): |
|
451 | if not( self.readNextBlock() ): | |
453 | return 0 |
|
452 | return 0 | |
454 |
|
453 | |||
455 | self.getFirstHeader() |
|
454 | self.getFirstHeader() | |
456 |
|
455 | |||
457 | self.reshapeData() |
|
456 | self.reshapeData() | |
458 | if self.datablock is None: |
|
457 | if self.datablock is None: | |
459 | self.dataOut.flagNoData = True |
|
458 | self.dataOut.flagNoData = True | |
460 | return 0 |
|
459 | return 0 | |
461 |
|
460 | |||
462 | if not self.getByBlock: |
|
461 | if not self.getByBlock: | |
463 |
|
462 | |||
464 | """ |
|
463 | """ | |
465 | Return profile by profile |
|
464 | Return profile by profile | |
466 |
|
465 | |||
467 | If nTxs > 1 then one profile is divided by nTxs and number of total |
|
466 | If nTxs > 1 then one profile is divided by nTxs and number of total | |
468 | blocks is increased by nTxs (nProfiles *= nTxs) |
|
467 | blocks is increased by nTxs (nProfiles *= nTxs) | |
469 | """ |
|
468 | """ | |
470 | self.dataOut.flagDataAsBlock = False |
|
469 | self.dataOut.flagDataAsBlock = False | |
471 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
470 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
472 | self.dataOut.profileIndex = self.profileIndex |
|
471 | self.dataOut.profileIndex = self.profileIndex | |
473 |
|
472 | |||
474 | self.profileIndex += 1 |
|
473 | self.profileIndex += 1 | |
475 |
|
474 | |||
476 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: |
|
475 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: | |
477 | # """ |
|
476 | # """ | |
478 | # Return all block |
|
477 | # Return all block | |
479 | # """ |
|
478 | # """ | |
480 | # self.dataOut.flagDataAsBlock = True |
|
479 | # self.dataOut.flagDataAsBlock = True | |
481 | # self.dataOut.data = self.datablock |
|
480 | # self.dataOut.data = self.datablock | |
482 | # self.dataOut.profileIndex = self.dataOut.nProfiles - 1 |
|
481 | # self.dataOut.profileIndex = self.dataOut.nProfiles - 1 | |
483 | # |
|
482 | # | |
484 | # self.profileIndex = self.dataOut.nProfiles |
|
483 | # self.profileIndex = self.dataOut.nProfiles | |
485 |
|
484 | |||
486 | else: |
|
485 | else: | |
487 | """ |
|
486 | """ | |
488 | Return a block |
|
487 | Return a block | |
489 | """ |
|
488 | """ | |
490 | if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles |
|
489 | if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles | |
491 | if self.selBlocktime != None: |
|
490 | if self.selBlocktime != None: | |
492 | if self.dataOut.nCohInt is not None: |
|
491 | if self.dataOut.nCohInt is not None: | |
493 | nCohInt = self.dataOut.nCohInt |
|
492 | nCohInt = self.dataOut.nCohInt | |
494 | else: |
|
493 | else: | |
495 | nCohInt = 1 |
|
494 | nCohInt = 1 | |
496 | self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles))) |
|
495 | self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles))) | |
497 |
|
496 | |||
498 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] |
|
497 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] | |
499 | self.profileIndex += self.selBlocksize |
|
498 | self.profileIndex += self.selBlocksize | |
500 | datasize = self.dataOut.data.shape[1] |
|
499 | datasize = self.dataOut.data.shape[1] | |
501 |
|
500 | |||
502 | if datasize < self.selBlocksize: |
|
501 | if datasize < self.selBlocksize: | |
503 | buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex') |
|
502 | buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex') | |
504 | buffer[:,:datasize,:] = self.dataOut.data |
|
503 | buffer[:,:datasize,:] = self.dataOut.data | |
505 |
|
504 | |||
506 | while datasize < self.selBlocksize: #Not enough profiles to fill the block |
|
505 | while datasize < self.selBlocksize: #Not enough profiles to fill the block | |
507 | if not( self.readNextBlock() ): |
|
506 | if not( self.readNextBlock() ): | |
508 | return 0 |
|
507 | return 0 | |
509 | self.getFirstHeader() |
|
508 | self.getFirstHeader() | |
510 | self.reshapeData() |
|
509 | self.reshapeData() | |
511 | if self.datablock is None: |
|
510 | if self.datablock is None: | |
512 | self.dataOut.flagNoData = True |
|
511 | self.dataOut.flagNoData = True | |
513 | return 0 |
|
512 | return 0 | |
514 | #stack data |
|
513 | #stack data | |
515 | blockIndex = self.selBlocksize - datasize |
|
514 | blockIndex = self.selBlocksize - datasize | |
516 | datablock1 = self.datablock[:,:blockIndex,:] |
|
515 | datablock1 = self.datablock[:,:blockIndex,:] | |
517 |
|
516 | |||
518 | buffer[:,datasize:datasize+datablock1.shape[1],:] = datablock1 |
|
517 | buffer[:,datasize:datasize+datablock1.shape[1],:] = datablock1 | |
519 | datasize += datablock1.shape[1] |
|
518 | datasize += datablock1.shape[1] | |
520 |
|
519 | |||
521 | self.dataOut.data = buffer |
|
520 | self.dataOut.data = buffer | |
522 | self.profileIndex = blockIndex |
|
521 | self.profileIndex = blockIndex | |
523 |
|
522 | |||
524 | self.dataOut.flagDataAsBlock = True |
|
523 | self.dataOut.flagDataAsBlock = True | |
525 | self.dataOut.nProfiles = self.dataOut.data.shape[1] |
|
524 | self.dataOut.nProfiles = self.dataOut.data.shape[1] | |
526 |
|
525 | |||
527 | self.dataOut.flagNoData = False |
|
526 | self.dataOut.flagNoData = False | |
528 |
|
527 | |||
529 | self.getBasicHeader() |
|
528 | self.getBasicHeader() | |
530 |
|
529 | |||
531 | self.dataOut.realtime = self.online |
|
530 | self.dataOut.realtime = self.online | |
532 |
|
531 | |||
533 | return self.dataOut.data |
|
532 | return self.dataOut.data | |
534 |
|
533 | |||
535 | class VoltageWriter(JRODataWriter, Operation): |
|
534 | class VoltageWriter(JRODataWriter, Operation): | |
536 | """ |
|
535 | """ | |
537 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
536 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
538 | de los datos siempre se realiza por bloques. |
|
537 | de los datos siempre se realiza por bloques. | |
539 | """ |
|
538 | """ | |
540 |
|
539 | |||
541 | ext = ".r" |
|
540 | ext = ".r" | |
542 |
|
541 | |||
543 | optchar = "D" |
|
542 | optchar = "D" | |
544 |
|
543 | |||
545 | shapeBuffer = None |
|
544 | shapeBuffer = None | |
546 |
|
545 | |||
547 |
|
546 | |||
548 | def __init__(self, **kwargs): |
|
547 | def __init__(self, **kwargs): | |
549 | """ |
|
548 | """ | |
550 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
549 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
551 |
|
550 | |||
552 | Affected: |
|
551 | Affected: | |
553 | self.dataOut |
|
552 | self.dataOut | |
554 |
|
553 | |||
555 | Return: None |
|
554 | Return: None | |
556 | """ |
|
555 | """ | |
557 | Operation.__init__(self, **kwargs) |
|
556 | Operation.__init__(self, **kwargs) | |
558 |
|
557 | |||
559 | self.nTotalBlocks = 0 |
|
558 | self.nTotalBlocks = 0 | |
560 |
|
559 | |||
561 | self.profileIndex = 0 |
|
560 | self.profileIndex = 0 | |
562 |
|
561 | |||
563 | self.isConfig = False |
|
562 | self.isConfig = False | |
564 |
|
563 | |||
565 | self.fp = None |
|
564 | self.fp = None | |
566 |
|
565 | |||
567 | self.flagIsNewFile = 1 |
|
566 | self.flagIsNewFile = 1 | |
568 |
|
567 | |||
569 | self.blockIndex = 0 |
|
568 | self.blockIndex = 0 | |
570 |
|
569 | |||
571 | self.flagIsNewBlock = 0 |
|
570 | self.flagIsNewBlock = 0 | |
572 |
|
571 | |||
573 | self.setFile = None |
|
572 | self.setFile = None | |
574 |
|
573 | |||
575 | self.dtype = None |
|
574 | self.dtype = None | |
576 |
|
575 | |||
577 | self.path = None |
|
576 | self.path = None | |
578 |
|
577 | |||
579 | self.filename = None |
|
578 | self.filename = None | |
580 |
|
579 | |||
581 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
580 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
582 |
|
581 | |||
583 | self.systemHeaderObj = SystemHeader() |
|
582 | self.systemHeaderObj = SystemHeader() | |
584 |
|
583 | |||
585 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
584 | self.radarControllerHeaderObj = RadarControllerHeader() | |
586 |
|
585 | |||
587 | self.processingHeaderObj = ProcessingHeader() |
|
586 | self.processingHeaderObj = ProcessingHeader() | |
588 |
|
587 | |||
589 | def hasAllDataInBuffer(self): |
|
588 | def hasAllDataInBuffer(self): | |
590 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
589 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
591 | return 1 |
|
590 | return 1 | |
592 | return 0 |
|
591 | return 0 | |
593 |
|
592 | |||
594 |
|
593 | |||
595 | def setBlockDimension(self): |
|
594 | def setBlockDimension(self): | |
596 | """ |
|
595 | """ | |
597 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
596 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
598 |
|
597 | |||
599 | Affected: |
|
598 | Affected: | |
600 | self.shape_spc_Buffer |
|
599 | self.shape_spc_Buffer | |
601 | self.shape_cspc_Buffer |
|
600 | self.shape_cspc_Buffer | |
602 | self.shape_dc_Buffer |
|
601 | self.shape_dc_Buffer | |
603 |
|
602 | |||
604 | Return: None |
|
603 | Return: None | |
605 | """ |
|
604 | """ | |
606 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
605 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
607 | self.processingHeaderObj.nHeights, |
|
606 | self.processingHeaderObj.nHeights, | |
608 | self.systemHeaderObj.nChannels) |
|
607 | self.systemHeaderObj.nChannels) | |
609 |
|
608 | |||
610 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
609 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
611 | self.processingHeaderObj.profilesPerBlock, |
|
610 | self.processingHeaderObj.profilesPerBlock, | |
612 | self.processingHeaderObj.nHeights), |
|
611 | self.processingHeaderObj.nHeights), | |
613 | dtype=numpy.dtype('complex64')) |
|
612 | dtype=numpy.dtype('complex64')) | |
614 |
|
613 | |||
615 | def writeBlock(self): |
|
614 | def writeBlock(self): | |
616 | """ |
|
615 | """ | |
617 | Escribe el buffer en el file designado |
|
616 | Escribe el buffer en el file designado | |
618 |
|
617 | |||
619 | Affected: |
|
618 | Affected: | |
620 | self.profileIndex |
|
619 | self.profileIndex | |
621 | self.flagIsNewFile |
|
620 | self.flagIsNewFile | |
622 | self.flagIsNewBlock |
|
621 | self.flagIsNewBlock | |
623 | self.nTotalBlocks |
|
622 | self.nTotalBlocks | |
624 | self.blockIndex |
|
623 | self.blockIndex | |
625 |
|
624 | |||
626 | Return: None |
|
625 | Return: None | |
627 | """ |
|
626 | """ | |
628 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
627 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
629 |
|
628 | |||
630 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
629 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
631 |
|
630 | |||
632 | data['real'] = junk.real |
|
631 | data['real'] = junk.real | |
633 | data['imag'] = junk.imag |
|
632 | data['imag'] = junk.imag | |
634 |
|
633 | |||
635 | data = data.reshape( (-1) ) |
|
634 | data = data.reshape( (-1) ) | |
636 |
|
635 | |||
637 | data.tofile( self.fp ) |
|
636 | data.tofile( self.fp ) | |
638 |
|
637 | |||
639 | self.datablock.fill(0) |
|
638 | self.datablock.fill(0) | |
640 |
|
639 | |||
641 | self.profileIndex = 0 |
|
640 | self.profileIndex = 0 | |
642 | self.flagIsNewFile = 0 |
|
641 | self.flagIsNewFile = 0 | |
643 | self.flagIsNewBlock = 1 |
|
642 | self.flagIsNewBlock = 1 | |
644 |
|
643 | |||
645 | self.blockIndex += 1 |
|
644 | self.blockIndex += 1 | |
646 | self.nTotalBlocks += 1 |
|
645 | self.nTotalBlocks += 1 | |
647 |
|
646 | |||
648 | # print "[Writing] Block = %04d" %self.blockIndex |
|
647 | # print "[Writing] Block = %04d" %self.blockIndex | |
649 |
|
648 | |||
650 | def putData(self): |
|
649 | def putData(self): | |
651 | """ |
|
650 | """ | |
652 | Setea un bloque de datos y luego los escribe en un file |
|
651 | Setea un bloque de datos y luego los escribe en un file | |
653 |
|
652 | |||
654 | Affected: |
|
653 | Affected: | |
655 | self.flagIsNewBlock |
|
654 | self.flagIsNewBlock | |
656 | self.profileIndex |
|
655 | self.profileIndex | |
657 |
|
656 | |||
658 | Return: |
|
657 | Return: | |
659 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
658 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
660 | 1 : Si se escribio la data de un bloque en un file |
|
659 | 1 : Si se escribio la data de un bloque en un file | |
661 | """ |
|
660 | """ | |
662 | if self.dataOut.flagNoData: |
|
661 | if self.dataOut.flagNoData: | |
663 | return 0 |
|
662 | return 0 | |
664 |
|
663 | |||
665 | self.flagIsNewBlock = 0 |
|
664 | self.flagIsNewBlock = 0 | |
666 |
|
665 | |||
667 | if self.dataOut.flagDiscontinuousBlock: |
|
666 | if self.dataOut.flagDiscontinuousBlock: | |
668 | self.datablock.fill(0) |
|
667 | self.datablock.fill(0) | |
669 | self.profileIndex = 0 |
|
668 | self.profileIndex = 0 | |
670 | self.setNextFile() |
|
669 | self.setNextFile() | |
671 |
|
670 | |||
672 | if self.profileIndex == 0: |
|
671 | if self.profileIndex == 0: | |
673 | self.setBasicHeader() |
|
672 | self.setBasicHeader() | |
674 |
|
673 | |||
675 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
674 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
676 |
|
675 | |||
677 | self.profileIndex += 1 |
|
676 | self.profileIndex += 1 | |
678 |
|
677 | |||
679 | if self.hasAllDataInBuffer(): |
|
678 | if self.hasAllDataInBuffer(): | |
680 | #if self.flagIsNewFile: |
|
679 | #if self.flagIsNewFile: | |
681 | self.writeNextBlock() |
|
680 | self.writeNextBlock() | |
682 | # self.setFirstHeader() |
|
681 | # self.setFirstHeader() | |
683 |
|
682 | |||
684 | return 1 |
|
683 | return 1 | |
685 |
|
684 | |||
686 | def __getBlockSize(self): |
|
685 | def __getBlockSize(self): | |
687 | ''' |
|
686 | ''' | |
688 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
687 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
689 | ''' |
|
688 | ''' | |
690 |
|
689 | |||
691 | dtype_width = self.getDtypeWidth() |
|
690 | dtype_width = self.getDtypeWidth() | |
692 |
|
691 | |||
693 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2) |
|
692 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2) | |
694 |
|
693 | |||
695 | return blocksize |
|
694 | return blocksize | |
696 |
|
695 | |||
697 | def setFirstHeader(self): |
|
696 | def setFirstHeader(self): | |
698 |
|
697 | |||
699 | """ |
|
698 | """ | |
700 | Obtiene una copia del First Header |
|
699 | Obtiene una copia del First Header | |
701 |
|
700 | |||
702 | Affected: |
|
701 | Affected: | |
703 | self.systemHeaderObj |
|
702 | self.systemHeaderObj | |
704 | self.radarControllerHeaderObj |
|
703 | self.radarControllerHeaderObj | |
705 | self.dtype |
|
704 | self.dtype | |
706 |
|
705 | |||
707 | Return: |
|
706 | Return: | |
708 | None |
|
707 | None | |
709 | """ |
|
708 | """ | |
710 |
|
709 | |||
711 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
710 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
712 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
711 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
713 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
712 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
714 |
|
713 | |||
715 | self.processingHeaderObj.dtype = 0 # Voltage |
|
714 | self.processingHeaderObj.dtype = 0 # Voltage | |
716 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
715 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
717 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
716 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
718 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
717 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
719 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
718 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
720 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
719 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
721 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
720 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
722 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
721 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
723 |
|
722 | |||
724 | if self.dataOut.code is not None: |
|
723 | if self.dataOut.code is not None: | |
725 | self.processingHeaderObj.code = self.dataOut.code |
|
724 | self.processingHeaderObj.code = self.dataOut.code | |
726 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
725 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
727 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
726 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
728 |
|
727 | |||
729 | if self.processingHeaderObj.nWindows != 0: |
|
728 | if self.processingHeaderObj.nWindows != 0: | |
730 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
729 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
731 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
730 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
732 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
731 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
733 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
732 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
734 |
|
733 | |||
735 | self.processingHeaderObj.processFlags = self.getProcessFlags() |
|
734 | self.processingHeaderObj.processFlags = self.getProcessFlags() | |
736 |
|
735 | |||
737 | self.setBasicHeader() |
|
736 | self.setBasicHeader() |
@@ -1,69 +1,68 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 16, 2014 |
|
2 | Created on Jul 16, 2014 | |
3 |
|
3 | |||
4 | @author: Miguel Urco |
|
4 | @author: Miguel Urco | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | from setuptools import setup, Extension |
|
7 | from setuptools import setup, Extension | |
8 | from setuptools.command.build_ext import build_ext as _build_ext |
|
8 | from setuptools.command.build_ext import build_ext as _build_ext | |
9 | from schainpy import __version__ |
|
9 | from schainpy import __version__ | |
10 |
|
10 | |||
11 | class build_ext(_build_ext): |
|
11 | class build_ext(_build_ext): | |
12 | def finalize_options(self): |
|
12 | def finalize_options(self): | |
13 | _build_ext.finalize_options(self) |
|
13 | _build_ext.finalize_options(self) | |
14 | # Prevent numpy from thinking it is still in its setup process: |
|
14 | # Prevent numpy from thinking it is still in its setup process: | |
15 | __builtins__.__NUMPY_SETUP__ = False |
|
15 | __builtins__.__NUMPY_SETUP__ = False | |
16 | import numpy |
|
16 | import numpy | |
17 | self.include_dirs.append(numpy.get_include()) |
|
17 | self.include_dirs.append(numpy.get_include()) | |
18 |
|
18 | |||
19 |
|
||||
20 | setup(name="schainpy", |
|
19 | setup(name="schainpy", | |
21 | version=__version__, |
|
20 | version=__version__, | |
22 | description="Python tools to read, write and process Jicamarca data", |
|
21 | description="Python tools to read, write and process Jicamarca data", | |
23 | author="Miguel Urco", |
|
22 | author="Miguel Urco", | |
24 | author_email="miguel.urco@jro.igp.gob.pe", |
|
23 | author_email="miguel.urco@jro.igp.gob.pe", | |
25 | url="http://jro.igp.gob.pe", |
|
24 | url="http://jro.igp.gob.pe", | |
26 | packages = {'schainpy', |
|
25 | packages = {'schainpy', | |
27 | 'schainpy.model', |
|
26 | 'schainpy.model', | |
28 | 'schainpy.model.data', |
|
27 | 'schainpy.model.data', | |
29 | 'schainpy.model.graphics', |
|
28 | 'schainpy.model.graphics', | |
30 | 'schainpy.model.io', |
|
29 | 'schainpy.model.io', | |
31 | 'schainpy.model.proc', |
|
30 | 'schainpy.model.proc', | |
32 | 'schainpy.model.serializer', |
|
31 | 'schainpy.model.serializer', | |
33 | 'schainpy.model.utils', |
|
32 | 'schainpy.model.utils', | |
34 | 'schainpy.gui', |
|
33 | 'schainpy.gui', | |
35 | 'schainpy.gui.figures', |
|
34 | 'schainpy.gui.figures', | |
36 | 'schainpy.gui.viewcontroller', |
|
35 | 'schainpy.gui.viewcontroller', | |
37 | 'schainpy.gui.viewer', |
|
36 | 'schainpy.gui.viewer', | |
38 | 'schainpy.gui.viewer.windows'}, |
|
37 | 'schainpy.gui.viewer.windows'}, | |
39 | ext_package='schainpy', |
|
38 | ext_package='schainpy', | |
40 | py_modules=[''], |
|
39 | py_modules=[''], | |
41 | package_data={'': ['schain.conf.template'], |
|
40 | package_data={'': ['schain.conf.template'], | |
42 | 'schainpy.gui.figures': ['*.png','*.jpg'], |
|
41 | 'schainpy.gui.figures': ['*.png','*.jpg'], | |
43 | }, |
|
42 | }, | |
44 | include_package_data=False, |
|
43 | include_package_data=False, | |
45 | scripts =['schainpy/gui/schainGUI'], |
|
44 | scripts =['schainpy/gui/schainGUI'], | |
46 | ext_modules=[ |
|
45 | ext_modules=[ | |
47 | Extension("cSchain", ["schainpy/model/proc/extensions.c"] |
|
46 | Extension("cSchain", ["schainpy/model/proc/extensions.c"] | |
48 | )], |
|
47 | )], | |
49 | entry_points={ |
|
48 | entry_points={ | |
50 | 'console_scripts': [ |
|
49 | 'console_scripts': [ | |
51 | 'schain = schaincli.cli:main', |
|
50 | 'schain = schaincli.cli:main', | |
52 | ], |
|
51 | ], | |
53 | }, |
|
52 | }, | |
54 | cmdclass={'build_ext':build_ext}, |
|
53 | cmdclass={'build_ext':build_ext}, | |
55 | setup_requires=["numpy >= 1.11.2"], |
|
54 | setup_requires=["numpy >= 1.11.2"], | |
56 | install_requires=[ |
|
55 | install_requires=[ | |
57 | "scipy >= 0.14.0", |
|
56 | "scipy >= 0.14.0", | |
58 | "h5py >= 2.2.1", |
|
57 | "h5py >= 2.2.1", | |
59 | "matplotlib >= 1.4.2", |
|
58 | "matplotlib >= 1.4.2", | |
60 | "pyfits >= 3.4", |
|
59 | "pyfits >= 3.4", | |
61 | "paramiko >= 2.1.2", |
|
60 | "paramiko >= 2.1.2", | |
62 | "paho-mqtt >= 1.2", |
|
61 | "paho-mqtt >= 1.2", | |
63 | "zmq", |
|
62 | "zmq", | |
64 | "fuzzywuzzy", |
|
63 | "fuzzywuzzy", | |
65 | "click", |
|
64 | "click", | |
66 | "colorama", |
|
65 | "colorama", | |
67 | "python-Levenshtein" |
|
66 | "python-Levenshtein" | |
68 | ], |
|
67 | ], | |
69 | ) |
|
68 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now