@@ -10,58 +10,61 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 | |||
|
14 | import tempfile | |||
|
15 | from StringIO import StringIO | |||
13 | # from _sha import blocksize |
|
16 | # from _sha import blocksize | |
14 |
|
17 | |||
15 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
18 | class VoltageReader(JRODataReader, ProcessingUnit): | |
16 | """ |
|
19 | """ | |
17 | 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 | |
18 |
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: | |
19 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
22 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
20 |
|
||||
21 | perfiles * alturas * canales |
|
|||
22 |
|
23 | |||
23 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
24 | perfiles * alturas * canales | |
|
25 | ||||
|
26 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |||
24 | 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 | |
25 | 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 | |
26 | 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". | |
27 |
|
30 | |||
28 | Example: |
|
31 | Example: | |
29 |
|
32 | |||
30 | dpath = "/home/myuser/data" |
|
33 | dpath = "/home/myuser/data" | |
31 |
|
34 | |||
32 | 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) | |
33 |
|
36 | |||
34 | 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) | |
35 |
|
38 | |||
36 | readerObj = VoltageReader() |
|
39 | readerObj = VoltageReader() | |
37 |
|
40 | |||
38 | readerObj.setup(dpath, startTime, endTime) |
|
41 | readerObj.setup(dpath, startTime, endTime) | |
39 |
|
42 | |||
40 | while(True): |
|
43 | while(True): | |
41 |
|
44 | |||
42 |
#to get one profile |
|
45 | #to get one profile | |
43 | profile = readerObj.getData() |
|
46 | profile = readerObj.getData() | |
44 |
|
47 | |||
45 | #print the profile |
|
48 | #print the profile | |
46 | print profile |
|
49 | print profile | |
47 |
|
50 | |||
48 | #If you want to see all datablock |
|
51 | #If you want to see all datablock | |
49 | print readerObj.datablock |
|
52 | print readerObj.datablock | |
50 |
|
53 | |||
51 | if readerObj.flagNoMoreFiles: |
|
54 | if readerObj.flagNoMoreFiles: | |
52 | break |
|
55 | break | |
53 |
|
56 | |||
54 | """ |
|
57 | """ | |
55 |
|
58 | |||
56 | ext = ".r" |
|
59 | ext = ".r" | |
57 |
|
60 | |||
58 | optchar = "D" |
|
61 | optchar = "D" | |
59 | dataOut = None |
|
62 | dataOut = None | |
60 |
|
63 | |||
61 | def __init__(self): |
|
64 | def __init__(self, **kwargs): | |
62 | """ |
|
65 | """ | |
63 | 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. | |
64 |
|
67 | |||
65 | Input: |
|
68 | Input: | |
66 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
69 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
67 | 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 | |
@@ -69,109 +72,109 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
69 | 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 | |
70 | bloque de datos. |
|
73 | bloque de datos. | |
71 | Si este parametro no es pasado se creara uno internamente. |
|
74 | Si este parametro no es pasado se creara uno internamente. | |
72 |
|
75 | |||
73 | Variables afectadas: |
|
76 | Variables afectadas: | |
74 | self.dataOut |
|
77 | self.dataOut | |
75 |
|
78 | |||
76 | Return: |
|
79 | Return: | |
77 | None |
|
80 | None | |
78 | """ |
|
81 | """ | |
79 |
|
82 | |||
80 | ProcessingUnit.__init__(self) |
|
83 | ProcessingUnit.__init__(self, **kwargs) | |
81 |
|
84 | |||
82 | self.isConfig = False |
|
85 | self.isConfig = False | |
83 |
|
86 | |||
84 | self.datablock = None |
|
87 | self.datablock = None | |
85 |
|
88 | |||
86 | self.utc = 0 |
|
89 | self.utc = 0 | |
87 |
|
90 | |||
88 | self.ext = ".r" |
|
91 | self.ext = ".r" | |
89 |
|
92 | |||
90 | self.optchar = "D" |
|
93 | self.optchar = "D" | |
91 |
|
94 | |||
92 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
95 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
93 |
|
96 | |||
94 | self.systemHeaderObj = SystemHeader() |
|
97 | self.systemHeaderObj = SystemHeader() | |
95 |
|
98 | |||
96 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
99 | self.radarControllerHeaderObj = RadarControllerHeader() | |
97 |
|
100 | |||
98 | self.processingHeaderObj = ProcessingHeader() |
|
101 | self.processingHeaderObj = ProcessingHeader() | |
99 |
|
102 | |||
100 | self.online = 0 |
|
103 | self.online = 0 | |
101 |
|
104 | |||
102 | self.fp = None |
|
105 | self.fp = None | |
103 |
|
106 | |||
104 | self.idFile = None |
|
107 | self.idFile = None | |
105 |
|
108 | |||
106 | self.dtype = None |
|
109 | self.dtype = None | |
107 |
|
110 | |||
108 | self.fileSizeByHeader = None |
|
111 | self.fileSizeByHeader = None | |
109 |
|
112 | |||
110 | self.filenameList = [] |
|
113 | self.filenameList = [] | |
111 |
|
114 | |||
112 | self.filename = None |
|
115 | self.filename = None | |
113 |
|
116 | |||
114 | self.fileSize = None |
|
117 | self.fileSize = None | |
115 |
|
118 | |||
116 | self.firstHeaderSize = 0 |
|
119 | self.firstHeaderSize = 0 | |
117 |
|
120 | |||
118 | self.basicHeaderSize = 24 |
|
121 | self.basicHeaderSize = 24 | |
119 |
|
122 | |||
120 | self.pathList = [] |
|
123 | self.pathList = [] | |
121 |
|
124 | |||
122 | self.filenameList = [] |
|
125 | self.filenameList = [] | |
123 |
|
126 | |||
124 | self.lastUTTime = 0 |
|
127 | self.lastUTTime = 0 | |
125 |
|
128 | |||
126 | self.maxTimeStep = 30 |
|
129 | self.maxTimeStep = 30 | |
127 |
|
130 | |||
128 | self.flagNoMoreFiles = 0 |
|
131 | self.flagNoMoreFiles = 0 | |
129 |
|
132 | |||
130 | self.set = 0 |
|
133 | self.set = 0 | |
131 |
|
134 | |||
132 | self.path = None |
|
135 | self.path = None | |
133 |
|
136 | |||
134 | self.profileIndex = 2**32-1 |
|
137 | self.profileIndex = 2**32-1 | |
135 |
|
138 | |||
136 | self.delay = 3 #seconds |
|
139 | self.delay = 3 #seconds | |
137 |
|
140 | |||
138 | self.nTries = 3 #quantity tries |
|
141 | self.nTries = 3 #quantity tries | |
139 |
|
142 | |||
140 | self.nFiles = 3 #number of files for searching |
|
143 | self.nFiles = 3 #number of files for searching | |
141 |
|
144 | |||
142 | self.nReadBlocks = 0 |
|
145 | self.nReadBlocks = 0 | |
143 |
|
146 | |||
144 | self.flagIsNewFile = 1 |
|
147 | self.flagIsNewFile = 1 | |
145 |
|
148 | |||
146 | self.__isFirstTimeOnline = 1 |
|
149 | self.__isFirstTimeOnline = 1 | |
147 |
|
150 | |||
148 | # self.ippSeconds = 0 |
|
151 | # self.ippSeconds = 0 | |
149 |
|
152 | |||
150 |
self.flagDiscontinuousBlock = 0 |
|
153 | self.flagDiscontinuousBlock = 0 | |
151 |
|
154 | |||
152 | self.flagIsNewBlock = 0 |
|
155 | self.flagIsNewBlock = 0 | |
153 |
|
156 | |||
154 | self.nTotalBlocks = 0 |
|
157 | self.nTotalBlocks = 0 | |
155 |
|
158 | |||
156 | self.blocksize = 0 |
|
159 | self.blocksize = 0 | |
157 |
|
160 | |||
158 | self.dataOut = self.createObjByDefault() |
|
161 | self.dataOut = self.createObjByDefault() | |
159 |
|
162 | |||
160 | self.nTxs = 1 |
|
163 | self.nTxs = 1 | |
161 |
|
164 | |||
162 | self.txIndex = 0 |
|
165 | self.txIndex = 0 | |
163 |
|
166 | |||
164 | def createObjByDefault(self): |
|
167 | def createObjByDefault(self): | |
165 |
|
168 | |||
166 | dataObj = Voltage() |
|
169 | dataObj = Voltage() | |
167 |
|
170 | |||
168 | return dataObj |
|
171 | return dataObj | |
169 |
|
172 | |||
170 | def __hasNotDataInBuffer(self): |
|
173 | def __hasNotDataInBuffer(self): | |
171 |
|
174 | |||
172 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs: |
|
175 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs: | |
173 | return 1 |
|
176 | return 1 | |
174 |
|
177 | |||
175 | return 0 |
|
178 | return 0 | |
176 |
|
179 | |||
177 |
|
180 | |||
@@ -188,7 +191,8 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
188 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
191 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
189 | self.blocksize = pts2read |
|
192 | self.blocksize = pts2read | |
190 |
|
193 | |||
191 |
|
194 | |||
|
195 | ||||
192 | def readBlock(self): |
|
196 | def readBlock(self): | |
193 | """ |
|
197 | """ | |
194 | 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 | |
@@ -224,40 +228,40 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
224 | # else: |
|
228 | # else: | |
225 | current_pointer_location = self.fp.tell() |
|
229 | current_pointer_location = self.fp.tell() | |
226 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
230 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
227 |
|
231 | |||
228 | try: |
|
232 | try: | |
229 | 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) ) | |
230 | except: |
|
234 | except: | |
231 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
235 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
232 |
|
236 | |||
233 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
237 | if self.waitDataBlock(pointer_location=current_pointer_location): | |
234 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
238 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
235 | 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) ) | |
236 | # return 0 |
|
240 | # return 0 | |
237 |
|
241 | |||
238 | #Dimensions : nChannels, nProfiles, nSamples |
|
242 | #Dimensions : nChannels, nProfiles, nSamples | |
239 |
|
243 | |||
240 | junk = numpy.transpose(junk, (2,0,1)) |
|
244 | junk = numpy.transpose(junk, (2,0,1)) | |
241 | self.datablock = junk['real'] + junk['imag']*1j |
|
245 | self.datablock = junk['real'] + junk['imag']*1j | |
242 |
|
246 | |||
243 | self.profileIndex = 0 |
|
247 | self.profileIndex = 0 | |
244 |
|
248 | |||
245 | self.flagIsNewFile = 0 |
|
249 | self.flagIsNewFile = 0 | |
246 | self.flagIsNewBlock = 1 |
|
250 | self.flagIsNewBlock = 1 | |
247 |
|
251 | |||
248 | self.nTotalBlocks += 1 |
|
252 | self.nTotalBlocks += 1 | |
249 | self.nReadBlocks += 1 |
|
253 | self.nReadBlocks += 1 | |
250 |
|
254 | |||
251 | return 1 |
|
255 | return 1 | |
252 |
|
256 | |||
253 | def getFirstHeader(self): |
|
257 | def getFirstHeader(self): | |
254 |
|
258 | |||
255 | self.getBasicHeader() |
|
259 | self.getBasicHeader() | |
256 |
|
260 | |||
257 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
261 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
258 |
|
262 | |||
259 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
263 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
260 |
|
264 | |||
261 | if self.nTxs > 1: |
|
265 | if self.nTxs > 1: | |
262 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
266 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
263 |
|
267 | |||
@@ -274,39 +278,39 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
274 | # self.dataOut.code = self.radarControllerHeaderObj.code |
|
278 | # self.dataOut.code = self.radarControllerHeaderObj.code | |
275 |
|
279 | |||
276 | self.dataOut.dtype = self.dtype |
|
280 | self.dataOut.dtype = self.dtype | |
277 |
|
281 | |||
278 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
282 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
279 |
|
283 | |||
280 |
self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight |
|
284 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
281 |
|
285 | |||
282 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
286 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
283 |
|
287 | |||
284 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
288 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
285 |
|
289 | |||
286 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada |
|
290 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada | |
287 |
|
291 | |||
288 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip |
|
292 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip | |
289 |
|
293 | |||
290 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
294 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
291 |
|
295 | |||
292 | def reshapeData(self): |
|
296 | def reshapeData(self): | |
293 |
|
297 | |||
294 | if self.nTxs < 0: |
|
298 | if self.nTxs < 0: | |
295 | return |
|
299 | return | |
296 |
|
300 | |||
297 | if self.nTxs == 1: |
|
301 | if self.nTxs == 1: | |
298 | return |
|
302 | return | |
299 |
|
303 | |||
300 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0: |
|
304 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0: | |
301 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %(1./self.nTxs, self.processingHeaderObj.profilesPerBlock) |
|
305 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %(1./self.nTxs, self.processingHeaderObj.profilesPerBlock) | |
302 |
|
306 | |||
303 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
307 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: | |
304 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %(self.nTxs, self.processingHeaderObj.nHeights) |
|
308 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %(self.nTxs, self.processingHeaderObj.nHeights) | |
305 |
|
309 | |||
306 | self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs)) |
|
310 | self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs)) | |
307 |
|
311 | |||
308 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
312 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs | |
309 |
self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight |
|
313 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
310 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
314 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
311 |
|
315 | |||
312 | return |
|
316 | return | |
@@ -438,28 +442,23 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
438 | self.flagDiscontinuousBlock |
|
442 | self.flagDiscontinuousBlock | |
439 | self.flagIsNewBlock |
|
443 | self.flagIsNewBlock | |
440 | """ |
|
444 | """ | |
441 |
|
||||
442 | if self.flagNoMoreFiles: |
|
445 | if self.flagNoMoreFiles: | |
443 | self.dataOut.flagNoData = True |
|
446 | self.dataOut.flagNoData = True | |
444 | print 'Process finished' |
|
447 | print 'Process finished' | |
445 | return 0 |
|
448 | return 0 | |
446 |
|
||||
447 | self.flagDiscontinuousBlock = 0 |
|
449 | self.flagDiscontinuousBlock = 0 | |
448 | self.flagIsNewBlock = 0 |
|
450 | self.flagIsNewBlock = 0 | |
449 |
|
||||
450 | if self.__hasNotDataInBuffer(): |
|
451 | if self.__hasNotDataInBuffer(): | |
451 |
|
||||
452 | if not( self.readNextBlock() ): |
|
452 | if not( self.readNextBlock() ): | |
453 | return 0 |
|
453 | return 0 | |
454 |
|
454 | |||
455 | self.getFirstHeader() |
|
455 | self.getFirstHeader() | |
456 |
|
456 | |||
457 | self.reshapeData() |
|
457 | self.reshapeData() | |
458 |
|
||||
459 | if self.datablock is None: |
|
458 | if self.datablock is None: | |
460 | self.dataOut.flagNoData = True |
|
459 | self.dataOut.flagNoData = True | |
461 | return 0 |
|
460 | return 0 | |
462 |
|
461 | |||
463 | if not self.getByBlock: |
|
462 | if not self.getByBlock: | |
464 |
|
463 | |||
465 | """ |
|
464 | """ | |
@@ -471,7 +470,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
471 | self.dataOut.flagDataAsBlock = False |
|
470 | self.dataOut.flagDataAsBlock = False | |
472 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
471 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
473 | self.dataOut.profileIndex = self.profileIndex |
|
472 | self.dataOut.profileIndex = self.profileIndex | |
474 |
|
473 | |||
475 | self.profileIndex += 1 |
|
474 | self.profileIndex += 1 | |
476 |
|
475 | |||
477 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: |
|
476 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: | |
@@ -493,20 +492,20 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
493 | if self.dataOut.nCohInt is not None: |
|
492 | if self.dataOut.nCohInt is not None: | |
494 | nCohInt = self.dataOut.nCohInt |
|
493 | nCohInt = self.dataOut.nCohInt | |
495 | else: |
|
494 | else: | |
496 |
nCohInt = 1 |
|
495 | nCohInt = 1 | |
497 | self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles))) |
|
496 | self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles))) | |
498 |
|
497 | |||
499 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] |
|
498 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] | |
500 | self.profileIndex += self.selBlocksize |
|
499 | self.profileIndex += self.selBlocksize | |
501 | datasize = self.dataOut.data.shape[1] |
|
500 | datasize = self.dataOut.data.shape[1] | |
502 |
|
501 | |||
503 |
if datasize < self.selBlocksize: |
|
502 | if datasize < self.selBlocksize: | |
504 | buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex') |
|
503 | buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex') | |
505 | buffer[:,:datasize,:] = self.dataOut.data |
|
504 | buffer[:,:datasize,:] = self.dataOut.data | |
506 |
|
505 | |||
507 | while datasize < self.selBlocksize: #Not enough profiles to fill the block |
|
506 | while datasize < self.selBlocksize: #Not enough profiles to fill the block | |
508 | if not( self.readNextBlock() ): |
|
507 | if not( self.readNextBlock() ): | |
509 |
return 0 |
|
508 | return 0 | |
510 | self.getFirstHeader() |
|
509 | self.getFirstHeader() | |
511 | self.reshapeData() |
|
510 | self.reshapeData() | |
512 | if self.datablock is None: |
|
511 | if self.datablock is None: | |
@@ -515,76 +514,76 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
515 | #stack data |
|
514 | #stack data | |
516 | blockIndex = self.selBlocksize - datasize |
|
515 | blockIndex = self.selBlocksize - datasize | |
517 | datablock1 = self.datablock[:,:blockIndex,:] |
|
516 | datablock1 = self.datablock[:,:blockIndex,:] | |
518 |
|
517 | |||
519 | buffer[:,datasize:datasize+datablock1.shape[1],:] = datablock1 |
|
518 | buffer[:,datasize:datasize+datablock1.shape[1],:] = datablock1 | |
520 | datasize += datablock1.shape[1] |
|
519 | datasize += datablock1.shape[1] | |
521 |
|
520 | |||
522 | self.dataOut.data = buffer |
|
521 | self.dataOut.data = buffer | |
523 | self.profileIndex = blockIndex |
|
522 | self.profileIndex = blockIndex | |
524 |
|
523 | |||
525 | self.dataOut.flagDataAsBlock = True |
|
524 | self.dataOut.flagDataAsBlock = True | |
526 | self.dataOut.nProfiles = self.dataOut.data.shape[1] |
|
525 | self.dataOut.nProfiles = self.dataOut.data.shape[1] | |
527 |
|
526 | |||
528 | self.dataOut.flagNoData = False |
|
527 | self.dataOut.flagNoData = False | |
529 |
|
528 | |||
530 | self.getBasicHeader() |
|
529 | self.getBasicHeader() | |
531 |
|
530 | |||
532 | self.dataOut.realtime = self.online |
|
531 | self.dataOut.realtime = self.online | |
533 |
|
532 | |||
534 | return self.dataOut.data |
|
533 | return self.dataOut.data | |
535 |
|
534 | |||
536 | class VoltageWriter(JRODataWriter, Operation): |
|
535 | class VoltageWriter(JRODataWriter, Operation): | |
537 |
""" |
|
536 | """ | |
538 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
537 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
539 |
de los datos siempre se realiza por bloques. |
|
538 | de los datos siempre se realiza por bloques. | |
540 | """ |
|
539 | """ | |
541 |
|
540 | |||
542 | ext = ".r" |
|
541 | ext = ".r" | |
543 |
|
542 | |||
544 | optchar = "D" |
|
543 | optchar = "D" | |
545 |
|
544 | |||
546 | shapeBuffer = None |
|
545 | shapeBuffer = None | |
547 |
|
||||
548 |
|
546 | |||
549 | def __init__(self): |
|
547 | ||
550 | """ |
|
548 | def __init__(self, **kwargs): | |
|
549 | """ | |||
551 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
550 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
552 |
|
551 | |||
553 |
Affected: |
|
552 | Affected: | |
554 | self.dataOut |
|
553 | self.dataOut | |
555 |
|
554 | |||
556 | Return: None |
|
555 | Return: None | |
557 | """ |
|
556 | """ | |
558 | Operation.__init__(self) |
|
557 | Operation.__init__(self, **kwargs) | |
559 |
|
558 | |||
560 | self.nTotalBlocks = 0 |
|
559 | self.nTotalBlocks = 0 | |
561 |
|
560 | |||
562 | self.profileIndex = 0 |
|
561 | self.profileIndex = 0 | |
563 |
|
562 | |||
564 | self.isConfig = False |
|
563 | self.isConfig = False | |
565 |
|
564 | |||
566 | self.fp = None |
|
565 | self.fp = None | |
567 |
|
566 | |||
568 | self.flagIsNewFile = 1 |
|
567 | self.flagIsNewFile = 1 | |
569 |
|
568 | |||
570 |
self.blockIndex = 0 |
|
569 | self.blockIndex = 0 | |
571 |
|
570 | |||
572 | self.flagIsNewBlock = 0 |
|
571 | self.flagIsNewBlock = 0 | |
573 |
|
572 | |||
574 | self.setFile = None |
|
573 | self.setFile = None | |
575 |
|
574 | |||
576 | self.dtype = None |
|
575 | self.dtype = None | |
577 |
|
576 | |||
578 | self.path = None |
|
577 | self.path = None | |
579 |
|
578 | |||
580 | self.filename = None |
|
579 | self.filename = None | |
581 |
|
580 | |||
582 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
581 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
583 |
|
582 | |||
584 | self.systemHeaderObj = SystemHeader() |
|
583 | self.systemHeaderObj = SystemHeader() | |
585 |
|
584 | |||
586 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
585 | self.radarControllerHeaderObj = RadarControllerHeader() | |
587 |
|
586 | |||
588 | self.processingHeaderObj = ProcessingHeader() |
|
587 | self.processingHeaderObj = ProcessingHeader() | |
589 |
|
588 | |||
590 | def hasAllDataInBuffer(self): |
|
589 | def hasAllDataInBuffer(self): | |
@@ -607,112 +606,112 class VoltageWriter(JRODataWriter, Operation): | |||||
607 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
606 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
608 | self.processingHeaderObj.nHeights, |
|
607 | self.processingHeaderObj.nHeights, | |
609 | self.systemHeaderObj.nChannels) |
|
608 | self.systemHeaderObj.nChannels) | |
610 |
|
609 | |||
611 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
610 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
612 | self.processingHeaderObj.profilesPerBlock, |
|
611 | self.processingHeaderObj.profilesPerBlock, | |
613 | self.processingHeaderObj.nHeights), |
|
612 | self.processingHeaderObj.nHeights), | |
614 | dtype=numpy.dtype('complex64')) |
|
613 | dtype=numpy.dtype('complex64')) | |
615 |
|
614 | |||
616 | def writeBlock(self): |
|
615 | def writeBlock(self): | |
617 | """ |
|
616 | """ | |
618 | Escribe el buffer en el file designado |
|
617 | Escribe el buffer en el file designado | |
619 |
|
618 | |||
620 | Affected: |
|
619 | Affected: | |
621 |
self.profileIndex |
|
620 | self.profileIndex | |
622 | self.flagIsNewFile |
|
621 | self.flagIsNewFile | |
623 | self.flagIsNewBlock |
|
622 | self.flagIsNewBlock | |
624 | self.nTotalBlocks |
|
623 | self.nTotalBlocks | |
625 |
self.blockIndex |
|
624 | self.blockIndex | |
626 |
|
625 | |||
627 | Return: None |
|
626 | Return: None | |
628 | """ |
|
627 | """ | |
629 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
628 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
630 |
|
629 | |||
631 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
630 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
632 |
|
631 | |||
633 | data['real'] = junk.real |
|
632 | data['real'] = junk.real | |
634 | data['imag'] = junk.imag |
|
633 | data['imag'] = junk.imag | |
635 |
|
634 | |||
636 | data = data.reshape( (-1) ) |
|
635 | data = data.reshape( (-1) ) | |
637 |
|
636 | |||
638 | data.tofile( self.fp ) |
|
637 | data.tofile( self.fp ) | |
639 |
|
638 | |||
640 | self.datablock.fill(0) |
|
639 | self.datablock.fill(0) | |
641 |
|
640 | |||
642 |
self.profileIndex = 0 |
|
641 | self.profileIndex = 0 | |
643 | self.flagIsNewFile = 0 |
|
642 | self.flagIsNewFile = 0 | |
644 | self.flagIsNewBlock = 1 |
|
643 | self.flagIsNewBlock = 1 | |
645 |
|
644 | |||
646 | self.blockIndex += 1 |
|
645 | self.blockIndex += 1 | |
647 | self.nTotalBlocks += 1 |
|
646 | self.nTotalBlocks += 1 | |
648 |
|
647 | |||
649 | # print "[Writing] Block = %04d" %self.blockIndex |
|
648 | # print "[Writing] Block = %04d" %self.blockIndex | |
650 |
|
649 | |||
651 | def putData(self): |
|
650 | def putData(self): | |
652 | """ |
|
651 | """ | |
653 |
Setea un bloque de datos y luego los escribe en un file |
|
652 | Setea un bloque de datos y luego los escribe en un file | |
654 |
|
653 | |||
655 | Affected: |
|
654 | Affected: | |
656 | self.flagIsNewBlock |
|
655 | self.flagIsNewBlock | |
657 | self.profileIndex |
|
656 | self.profileIndex | |
658 |
|
657 | |||
659 |
Return: |
|
658 | Return: | |
660 |
0 : Si no hay data o no hay mas files que puedan escribirse |
|
659 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
661 | 1 : Si se escribio la data de un bloque en un file |
|
660 | 1 : Si se escribio la data de un bloque en un file | |
662 | """ |
|
661 | """ | |
663 | if self.dataOut.flagNoData: |
|
662 | if self.dataOut.flagNoData: | |
664 | return 0 |
|
663 | return 0 | |
665 |
|
664 | |||
666 | self.flagIsNewBlock = 0 |
|
665 | self.flagIsNewBlock = 0 | |
667 |
|
666 | |||
668 | if self.dataOut.flagDiscontinuousBlock: |
|
667 | if self.dataOut.flagDiscontinuousBlock: | |
669 | self.datablock.fill(0) |
|
668 | self.datablock.fill(0) | |
670 | self.profileIndex = 0 |
|
669 | self.profileIndex = 0 | |
671 | self.setNextFile() |
|
670 | self.setNextFile() | |
672 |
|
671 | |||
673 | if self.profileIndex == 0: |
|
672 | if self.profileIndex == 0: | |
674 | self.setBasicHeader() |
|
673 | self.setBasicHeader() | |
675 |
|
674 | |||
676 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
675 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
677 |
|
676 | |||
678 | self.profileIndex += 1 |
|
677 | self.profileIndex += 1 | |
679 |
|
678 | |||
680 | if self.hasAllDataInBuffer(): |
|
679 | if self.hasAllDataInBuffer(): | |
681 |
#if self.flagIsNewFile: |
|
680 | #if self.flagIsNewFile: | |
682 | self.writeNextBlock() |
|
681 | self.writeNextBlock() | |
683 | # self.setFirstHeader() |
|
682 | # self.setFirstHeader() | |
684 |
|
683 | |||
685 | return 1 |
|
684 | return 1 | |
686 |
|
685 | |||
687 | def __getBlockSize(self): |
|
686 | def __getBlockSize(self): | |
688 | ''' |
|
687 | ''' | |
689 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
688 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
690 | ''' |
|
689 | ''' | |
691 |
|
690 | |||
692 | dtype_width = self.getDtypeWidth() |
|
691 | dtype_width = self.getDtypeWidth() | |
693 |
|
692 | |||
694 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2) |
|
693 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2) | |
695 |
|
694 | |||
696 | return blocksize |
|
695 | return blocksize | |
697 |
|
696 | |||
698 | def setFirstHeader(self): |
|
697 | def setFirstHeader(self): | |
699 |
|
698 | |||
700 | """ |
|
699 | """ | |
701 | Obtiene una copia del First Header |
|
700 | Obtiene una copia del First Header | |
702 |
|
701 | |||
703 | Affected: |
|
702 | Affected: | |
704 | self.systemHeaderObj |
|
703 | self.systemHeaderObj | |
705 | self.radarControllerHeaderObj |
|
704 | self.radarControllerHeaderObj | |
706 | self.dtype |
|
705 | self.dtype | |
707 |
|
706 | |||
708 |
Return: |
|
707 | Return: | |
709 | None |
|
708 | None | |
710 | """ |
|
709 | """ | |
711 |
|
710 | |||
712 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
711 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
713 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
712 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
714 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
713 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
715 |
|
714 | |||
716 | self.processingHeaderObj.dtype = 0 # Voltage |
|
715 | self.processingHeaderObj.dtype = 0 # Voltage | |
717 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
716 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
718 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
717 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
@@ -721,18 +720,18 class VoltageWriter(JRODataWriter, Operation): | |||||
721 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
720 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
722 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
721 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
723 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
722 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
724 |
|
723 | |||
725 | if self.dataOut.code is not None: |
|
724 | if self.dataOut.code is not None: | |
726 | self.processingHeaderObj.code = self.dataOut.code |
|
725 | self.processingHeaderObj.code = self.dataOut.code | |
727 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
726 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
728 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
727 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
729 |
|
728 | |||
730 | if self.processingHeaderObj.nWindows != 0: |
|
729 | if self.processingHeaderObj.nWindows != 0: | |
731 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
730 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
732 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
731 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
733 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
732 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
734 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
733 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
735 |
|
734 | |||
736 | self.processingHeaderObj.processFlags = self.getProcessFlags() |
|
735 | self.processingHeaderObj.processFlags = self.getProcessFlags() | |
737 |
|
736 | |||
738 | self.setBasicHeader() No newline at end of file |
|
737 | self.setBasicHeader() |
General Comments 0
You need to be logged in to leave comments.
Login now