@@ -0,0 +1,485 | |||||
|
1 | import numpy,math,random,time | |||
|
2 | import zmq | |||
|
3 | import tempfile | |||
|
4 | from io import StringIO | |||
|
5 | ########## 1 Heredamos JRODatareader | |||
|
6 | from schainpy.model.io.jroIO_base import * | |||
|
7 | ########## 2 Heredamos las propiedades de ProcessingUnit | |||
|
8 | from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator | |||
|
9 | ########## 3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader | |||
|
10 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader | |||
|
11 | ########## 4 Importaremos el objeto Voltge | |||
|
12 | from schainpy.model.data.jrodata import Voltage | |||
|
13 | ||||
|
14 | @MPDecorator | |||
|
15 | class SimulatorReader(JRODataReader, ProcessingUnit): | |||
|
16 | incIntFactor = 1 | |||
|
17 | nFFTPoints = 0 | |||
|
18 | FixPP_IncInt = 1 | |||
|
19 | FixRCP_IPP = 1000 | |||
|
20 | FixPP_CohInt = 1 | |||
|
21 | Tau_0 = 250 | |||
|
22 | AcqH0_0 = 70 | |||
|
23 | H0 = AcqH0_0 | |||
|
24 | AcqDH_0 = 1.25 | |||
|
25 | DH0 = AcqDH_0 | |||
|
26 | Bauds = 32 | |||
|
27 | BaudWidth = None | |||
|
28 | FixRCP_TXA = 40 | |||
|
29 | FixRCP_TXB = 70 | |||
|
30 | fAngle = 2.0*math.pi*(1/16) | |||
|
31 | DC_level = 500 | |||
|
32 | stdev = 8 | |||
|
33 | Num_Codes = 2 | |||
|
34 | #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1]) | |||
|
35 | #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0]) | |||
|
36 | #Dyn_snCode = numpy.array([Num_Codes,Bauds]) | |||
|
37 | Dyn_snCode = None | |||
|
38 | Samples = 200 | |||
|
39 | channels = 5 | |||
|
40 | pulses = None | |||
|
41 | Reference = None | |||
|
42 | pulse_size = None | |||
|
43 | prof_gen = None | |||
|
44 | Fdoppler = 100 | |||
|
45 | Hdoppler = 36 | |||
|
46 | def __init__(self): | |||
|
47 | """ | |||
|
48 | Inicializador de la clases SimulatorReader para | |||
|
49 | generar datos de voltage simulados. | |||
|
50 | Input: | |||
|
51 | dataOut: Objeto de la clase Voltage. | |||
|
52 | Este Objeto sera utilizado apra almacenar | |||
|
53 | un perfil de datos cada vez qe se haga psiversho | |||
|
54 | un requerimiento (getData) | |||
|
55 | """ | |||
|
56 | ProcessingUnit.__init__(self) | |||
|
57 | print(" [ START ] init - Metodo Simulator Reader") | |||
|
58 | ||||
|
59 | self.isConfig = False | |||
|
60 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |||
|
61 | self.systemHeaderObj = SystemHeader() | |||
|
62 | self.radarControllerHeaderObj = RadarControllerHeader() | |||
|
63 | self.processingHeaderObj = ProcessingHeader() | |||
|
64 | self.profileIndex = 2**32-1 | |||
|
65 | self.dataOut = Voltage() | |||
|
66 | #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1]) | |||
|
67 | code0 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1]) | |||
|
68 | #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0]) | |||
|
69 | code1 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1,-1,-1,1,-1]) | |||
|
70 | #self.Dyn_snCode = numpy.array([code0,code1]) | |||
|
71 | self.Dyn_snCode = None | |||
|
72 | print(" [ END ] init - Metodo simulator Reader" ) | |||
|
73 | ||||
|
74 | ||||
|
75 | def __hasNotDataInBuffer(self): | |||
|
76 | ||||
|
77 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs: | |||
|
78 | if self.nReadBlocks>0: | |||
|
79 | tmp = self.dataOut.utctime | |||
|
80 | tmp_utc = int(self.dataOut.utctime) | |||
|
81 | tmp_milisecond = int((tmp-tmp_utc)*1000) | |||
|
82 | self.basicHeaderObj.utc = tmp_utc | |||
|
83 | self.basicHeaderObj.miliSecond= tmp_milisecond | |||
|
84 | return 1 | |||
|
85 | return 0 | |||
|
86 | ||||
|
87 | ||||
|
88 | def setNextFile(self): | |||
|
89 | """Set the next file to be readed open it and parse de file header""" | |||
|
90 | ||||
|
91 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |||
|
92 | print('------------------- [Opening file] ------------------------------') | |||
|
93 | self.nReadBlocks = 0 | |||
|
94 | ||||
|
95 | def __setNewBlock(self): | |||
|
96 | ||||
|
97 | self.setNextFile() | |||
|
98 | if self.flagIsNewFile: | |||
|
99 | return 1 | |||
|
100 | ||||
|
101 | def readNextBlock(self): | |||
|
102 | while True: | |||
|
103 | self.__setNewBlock() | |||
|
104 | if not(self.readBlock()): | |||
|
105 | return 0 | |||
|
106 | self.getBasicHeader() | |||
|
107 | break | |||
|
108 | if self.verbose: | |||
|
109 | print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, | |||
|
110 | self.processingHeaderObj.dataBlocksPerFile, | |||
|
111 | self.dataOut.datatime.ctime()) ) | |||
|
112 | return 1 | |||
|
113 | ||||
|
114 | def getFirstHeader(self): | |||
|
115 | self.getBasicHeader() | |||
|
116 | self.dataOut.processingHeaderObj = self.processingHeaderObj.copy() | |||
|
117 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |||
|
118 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |||
|
119 | #ADD NEW | |||
|
120 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |||
|
121 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |||
|
122 | self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels)) | |||
|
123 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |||
|
124 | # asumo q la data no esta decodificada | |||
|
125 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode | |||
|
126 | # asumo q la data no esta sin flip | |||
|
127 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip | |||
|
128 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |||
|
129 | ||||
|
130 | def getBasicHeader(self): | |||
|
131 | ||||
|
132 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ | |||
|
133 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds | |||
|
134 | ||||
|
135 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |||
|
136 | ||||
|
137 | self.dataOut.timeZone = self.basicHeaderObj.timeZone | |||
|
138 | ||||
|
139 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag | |||
|
140 | ||||
|
141 | self.dataOut.errorCount = self.basicHeaderObj.errorCount | |||
|
142 | ||||
|
143 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime | |||
|
144 | ||||
|
145 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |||
|
146 | ||||
|
147 | def reshapeData(self): | |||
|
148 | if self.nTxs==1: | |||
|
149 | return | |||
|
150 | ||||
|
151 | def readBlock(self): | |||
|
152 | ||||
|
153 | self.jro_GenerateBlockOfData(Samples= self.samples,DC_level=self.DC_level, | |||
|
154 | stdev=self.stdev,Reference= self.Reference, | |||
|
155 | pulses = self.pulses,Num_Codes=self.Num_Codes, | |||
|
156 | pulse_size=self.pulse_size,prof_gen=self.profiles, | |||
|
157 | H0=self.H0,DH0=self.DH0) | |||
|
158 | ||||
|
159 | self.profileIndex = 0 | |||
|
160 | self.flagIsNewFile = 0 | |||
|
161 | self.flagIsNewBlock = 1 | |||
|
162 | self.nTotalBlocks += 1 | |||
|
163 | self.nReadBlocks += 1 | |||
|
164 | ||||
|
165 | return 1 | |||
|
166 | ||||
|
167 | ||||
|
168 | def getData(self): ### metodo propio de VoltageReader | |||
|
169 | ||||
|
170 | if self.flagNoMoreFiles: | |||
|
171 | self.dataOut.flagNodata = True | |||
|
172 | self.flagDiscontinuousBlock = 0 | |||
|
173 | self.flagIsNewBlock = 0 | |||
|
174 | if self.__hasNotDataInBuffer(): # aqui es verdad | |||
|
175 | if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header | |||
|
176 | return 0 | |||
|
177 | self.getFirstHeader() # atributo | |||
|
178 | self.reshapeData() # nTxx1 =1 return , n | |||
|
179 | ||||
|
180 | if not self.getByBlock: | |||
|
181 | self.dataOut.flagDataAsBlock = False | |||
|
182 | self.dataOut.data = self.datablock[:, self.profileIndex, :] | |||
|
183 | self.dataOut.profileIndex = self.profileIndex | |||
|
184 | self.profileIndex += 1 | |||
|
185 | else: | |||
|
186 | pass | |||
|
187 | self.dataOut.flagNoData = False | |||
|
188 | self.getBasicHeader() | |||
|
189 | self.dataOut.realtime = self.online | |||
|
190 | return self.dataOut.data | |||
|
191 | ||||
|
192 | def set_kwargs(self, **kwargs): | |||
|
193 | for key, value in kwargs.items(): | |||
|
194 | setattr(self, key, value) | |||
|
195 | ||||
|
196 | def set_RCH(self, expType=2, nTx=1,ipp=None, txA=0, txB=0, | |||
|
197 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, | |||
|
198 | numTaus=0, line6Function=0, line5Function=0, fClock=None, | |||
|
199 | prePulseBefore=0, prePulseAfter=0, | |||
|
200 | codeType=0, nCode=0, nBaud=0, code=None, | |||
|
201 | flip1=0, flip2=0): | |||
|
202 | ||||
|
203 | self.radarControllerHeaderObj.expType = expType | |||
|
204 | self.radarControllerHeaderObj.nTx = nTx | |||
|
205 | self.radarControllerHeaderObj.ipp = float(ipp) | |||
|
206 | self.radarControllerHeaderObj.txA = float(txA) | |||
|
207 | self.radarControllerHeaderObj.txB = float(txB) | |||
|
208 | self.radarControllerHeaderObj.rangeIPP = ipp | |||
|
209 | self.radarControllerHeaderObj.rangeTxA = txA | |||
|
210 | self.radarControllerHeaderObj.rangeTxB = txB | |||
|
211 | ||||
|
212 | self.radarControllerHeaderObj.nHeights = int(nHeights) | |||
|
213 | self.radarControllerHeaderObj.firstHeight = numpy.array([firstHeight]) | |||
|
214 | self.radarControllerHeaderObj.deltaHeight = numpy.array([deltaHeight]) | |||
|
215 | self.radarControllerHeaderObj.samplesWin = numpy.array([nHeights]) | |||
|
216 | ||||
|
217 | ||||
|
218 | self.radarControllerHeaderObj.nWindows = nWindows | |||
|
219 | self.radarControllerHeaderObj.numTaus = numTaus | |||
|
220 | self.radarControllerHeaderObj.codeType = codeType | |||
|
221 | self.radarControllerHeaderObj.line6Function = line6Function | |||
|
222 | self.radarControllerHeaderObj.line5Function = line5Function | |||
|
223 | self.radarControllerHeaderObj.fclock = fClock | |||
|
224 | self.radarControllerHeaderObj.prePulseBefore= prePulseBefore | |||
|
225 | self.radarControllerHeaderObj.prePulseAfter = prePulseAfter | |||
|
226 | ||||
|
227 | self.radarControllerHeaderObj.nCode = nCode | |||
|
228 | self.radarControllerHeaderObj.nBaud = nBaud | |||
|
229 | self.radarControllerHeaderObj.code = code | |||
|
230 | self.radarControllerHeaderObj.flip1 = flip1 | |||
|
231 | self.radarControllerHeaderObj.flip2 = flip2 | |||
|
232 | ||||
|
233 | self.radarControllerHeaderObj.code_size = int(numpy.ceil(nBaud / 32.)) * nCode * 4 | |||
|
234 | ||||
|
235 | if fClock is None and deltaHeight is not None: | |||
|
236 | self.fClock = 0.15 / (deltaHeight * 1e-6) | |||
|
237 | ||||
|
238 | def set_PH(self, dtype=0, blockSize=0, profilesPerBlock=0, | |||
|
239 | dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0, | |||
|
240 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, | |||
|
241 | deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, | |||
|
242 | code=0, nBaud=None, shif_fft=False, flag_dc=False, | |||
|
243 | flag_cspc=False, flag_decode=False, flag_deflip=False): | |||
|
244 | ||||
|
245 | self.processingHeaderObj.profilesPerBlock = profilesPerBlock | |||
|
246 | self.processingHeaderObj.dataBlocksPerFile = dataBlocksPerFile | |||
|
247 | self.processingHeaderObj.nWindows = nWindows | |||
|
248 | self.processingHeaderObj.nCohInt = nCohInt | |||
|
249 | self.processingHeaderObj.nIncohInt = nIncohInt | |||
|
250 | self.processingHeaderObj.totalSpectra = totalSpectra | |||
|
251 | self.processingHeaderObj.nHeights = int(nHeights) | |||
|
252 | self.processingHeaderObj.firstHeight = firstHeight | |||
|
253 | self.processingHeaderObj.deltaHeight = deltaHeight | |||
|
254 | self.processingHeaderObj.samplesWin = nHeights | |||
|
255 | ||||
|
256 | def set_BH(self, utc = 0, miliSecond = 0, timeZone = 0): | |||
|
257 | self.basicHeaderObj.utc = utc | |||
|
258 | self.basicHeaderObj.miliSecond = miliSecond | |||
|
259 | self.basicHeaderObj.timeZone = timeZone | |||
|
260 | ||||
|
261 | def set_SH(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0): | |||
|
262 | self.systemHeaderObj.nSamples = nSamples | |||
|
263 | self.systemHeaderObj.nProfiles = nProfiles | |||
|
264 | self.systemHeaderObj.nChannels = nChannels | |||
|
265 | self.systemHeaderObj.adcResolution = adcResolution | |||
|
266 | self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth | |||
|
267 | ||||
|
268 | def setup(self,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000, | |||
|
269 | FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32, | |||
|
270 | FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 500, | |||
|
271 | stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200,channels=1,Fdoppler=20,Hdoppler=36, | |||
|
272 | **kwargs): | |||
|
273 | ||||
|
274 | self.set_kwargs(**kwargs) | |||
|
275 | self.nReadBlocks = 0 | |||
|
276 | tmp = time.time() | |||
|
277 | tmp_utc = int(tmp) | |||
|
278 | tmp_milisecond = int((tmp-tmp_utc)*1000) | |||
|
279 | print(" SETUP -basicHeaderObj.utc",datetime.datetime.utcfromtimestamp(tmp)) | |||
|
280 | if Dyn_snCode is None: | |||
|
281 | Num_Codes=1 | |||
|
282 | Bauds =1 | |||
|
283 | ||||
|
284 | ||||
|
285 | ||||
|
286 | self.set_BH(utc= tmp_utc,miliSecond= tmp_milisecond,timeZone=300 ) | |||
|
287 | ||||
|
288 | self.set_RCH( expType=0, nTx=150,ipp=FixRCP_IPP, txA=FixRCP_TXA, txB= FixRCP_TXB, | |||
|
289 | nWindows=1 , nHeights=samples, firstHeight=AcqH0_0, deltaHeight=AcqDH_0, | |||
|
290 | numTaus=1, line6Function=0, line5Function=0, fClock=None, | |||
|
291 | prePulseBefore=0, prePulseAfter=0, | |||
|
292 | codeType=14, nCode=Num_Codes, nBaud=32, code=Dyn_snCode, | |||
|
293 | flip1=0, flip2=0) | |||
|
294 | ||||
|
295 | self.set_PH(dtype=0, blockSize=0, profilesPerBlock=300, | |||
|
296 | dataBlocksPerFile=120, nWindows=1, processFlags=0, nCohInt=1, | |||
|
297 | nIncohInt=1, totalSpectra=0, nHeights=samples, firstHeight=AcqH0_0, | |||
|
298 | deltaHeight=AcqDH_0, samplesWin=samples, spectraComb=0, nCode=0, | |||
|
299 | code=0, nBaud=None, shif_fft=False, flag_dc=False, | |||
|
300 | flag_cspc=False, flag_decode=False, flag_deflip=False) | |||
|
301 | ||||
|
302 | self.set_SH(nSamples=samples, nProfiles=300, nChannels=channels) | |||
|
303 | ||||
|
304 | self.incIntFactor = incIntFactor | |||
|
305 | self.nFFTPoints = nFFTPoints | |||
|
306 | self.FixPP_IncInt = FixPP_IncInt | |||
|
307 | self.FixRCP_IPP = FixRCP_IPP | |||
|
308 | self.FixPP_CohInt = FixPP_CohInt | |||
|
309 | self.Tau_0 = Tau_0 | |||
|
310 | self.AcqH0_0 = AcqH0_0 | |||
|
311 | self.H0 = AcqH0_0 | |||
|
312 | self.AcqDH_0 = AcqDH_0 | |||
|
313 | self.DH0 = AcqDH_0 | |||
|
314 | self.Bauds = Bauds | |||
|
315 | self.FixRCP_TXA = FixRCP_TXA | |||
|
316 | self.FixRCP_TXB = FixRCP_TXB | |||
|
317 | self.fAngle = fAngle | |||
|
318 | self.DC_level = DC_level | |||
|
319 | self.stdev = stdev | |||
|
320 | self.Num_Codes = Num_Codes | |||
|
321 | self.Dyn_snCode = Dyn_snCode | |||
|
322 | self.samples = samples | |||
|
323 | self.channels = channels | |||
|
324 | self.profiles = None | |||
|
325 | self.m_nReference = None | |||
|
326 | self.Baudwidth = None | |||
|
327 | self.Fdoppler = Fdoppler | |||
|
328 | self.Hdoppler = Hdoppler | |||
|
329 | ||||
|
330 | print("IPP ", self.FixRCP_IPP) | |||
|
331 | print("Tau_0 ",self.Tau_0) | |||
|
332 | print("AcqH0_0",self.AcqH0_0) | |||
|
333 | print("samples,window ",self.samples) | |||
|
334 | print("AcqDH_0",AcqDH_0) | |||
|
335 | print("FixRCP_TXA",self.FixRCP_TXA) | |||
|
336 | print("FixRCP_TXB",self.FixRCP_TXB) | |||
|
337 | print("Dyn_snCode",Dyn_snCode) | |||
|
338 | print("Fdoppler", Fdoppler) | |||
|
339 | print("Hdoppler",Hdoppler) | |||
|
340 | ||||
|
341 | self.init_acquisition() | |||
|
342 | self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode) | |||
|
343 | print(" [ END ] - SETUP metodo") | |||
|
344 | return | |||
|
345 | ||||
|
346 | def run(self,**kwargs): # metodo propio | |||
|
347 | if not(self.isConfig): | |||
|
348 | self.setup(**kwargs) | |||
|
349 | self.isConfig = True | |||
|
350 | self.getData() | |||
|
351 | ||||
|
352 | ################################################################## | |||
|
353 | ###### Aqui ingresamos las clases y metodos propios del simulador | |||
|
354 | ################################################################## | |||
|
355 | ||||
|
356 | ############################################# | |||
|
357 | ############## INIT_ACQUISITION############## | |||
|
358 | ############################################# | |||
|
359 | def init_acquisition(self): | |||
|
360 | ||||
|
361 | if self.nFFTPoints != 0: | |||
|
362 | self.incIntFactor = m_nProfilesperBlock/self.nFFTPoints | |||
|
363 | if (self.FixPP_IncInt > self.incIntFactor): | |||
|
364 | self.incIntFactor = self.FixPP_IncInt/ self.incIntFactor | |||
|
365 | elif(self.FixPP_IncInt< self.incIntFactor): | |||
|
366 | print("False alert...") | |||
|
367 | ||||
|
368 | ProfilesperBlock = self.processingHeaderObj.profilesPerBlock | |||
|
369 | ||||
|
370 | self.timeperblock =int(((self.FixRCP_IPP | |||
|
371 | *ProfilesperBlock | |||
|
372 | *self.FixPP_CohInt | |||
|
373 | *self.incIntFactor) | |||
|
374 | /150.0) | |||
|
375 | *0.9 | |||
|
376 | +0.5) | |||
|
377 | # para cada canal | |||
|
378 | self.profiles = ProfilesperBlock*self.FixPP_CohInt | |||
|
379 | self.profiles = ProfilesperBlock | |||
|
380 | self.Reference = int((self.Tau_0-self.AcqH0_0)/(self.AcqDH_0)+0.5) | |||
|
381 | self.BaudWidth = int((self.FixRCP_TXA/self.AcqDH_0)/self.Bauds + 0.5 ) | |||
|
382 | ||||
|
383 | if (self.BaudWidth==0): | |||
|
384 | self.BaudWidth=1 | |||
|
385 | ################################################################# | |||
|
386 | ####################### init_pulse ############################## | |||
|
387 | ################################################################ | |||
|
388 | ||||
|
389 | def init_pulse(self,Num_Codes=Num_Codes,Bauds=Bauds,BaudWidth=BaudWidth,Dyn_snCode=Dyn_snCode): | |||
|
390 | ||||
|
391 | Num_Codes = Num_Codes | |||
|
392 | Bauds = Bauds | |||
|
393 | BaudWidth = BaudWidth | |||
|
394 | Dyn_snCode = Dyn_snCode | |||
|
395 | ||||
|
396 | if Dyn_snCode: | |||
|
397 | print("EXISTE") | |||
|
398 | else: | |||
|
399 | print("No existe") | |||
|
400 | ||||
|
401 | if Dyn_snCode: # if Bauds: | |||
|
402 | pulses = list(range(0,Num_Codes)) | |||
|
403 | num_codes = Num_Codes | |||
|
404 | for i in range(num_codes): | |||
|
405 | pulse_size = Bauds*BaudWidth | |||
|
406 | pulses[i] = numpy.zeros(pulse_size) | |||
|
407 | for j in range(Bauds): | |||
|
408 | for k in range(BaudWidth): | |||
|
409 | pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600) | |||
|
410 | else: | |||
|
411 | print("sin code") | |||
|
412 | pulses = list(range(1)) | |||
|
413 | pulse_size = int(self.FixRCP_TXB/0.15+0.5) | |||
|
414 | pulses[0] = numpy.ones(pulse_size) | |||
|
415 | pulses = 600*pulses[0] | |||
|
416 | ||||
|
417 | return pulses,pulse_size | |||
|
418 | ||||
|
419 | ################################################################# | |||
|
420 | ##################### Generate block data | |||
|
421 | ################################################################ | |||
|
422 | ||||
|
423 | def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev, | |||
|
424 | Reference= Reference,pulses= pulses, | |||
|
425 | Num_Codes= Num_Codes,pulse_size=pulse_size, | |||
|
426 | prof_gen= prof_gen,H0 = H0,DH0=DH0,Fdoppler= Fdoppler,Hdoppler=Hdoppler): | |||
|
427 | Samples = Samples | |||
|
428 | DC_level = DC_level | |||
|
429 | stdev = stdev | |||
|
430 | m_nR = Reference | |||
|
431 | pulses = pulses | |||
|
432 | num_codes = Num_Codes | |||
|
433 | ps = pulse_size | |||
|
434 | prof_gen = prof_gen | |||
|
435 | channels = self.channels | |||
|
436 | H0 = H0 | |||
|
437 | DH0 = DH0 | |||
|
438 | ippSec = self.radarControllerHeaderObj.ippSeconds | |||
|
439 | Fdoppler = self.Fdoppler | |||
|
440 | Hdoppler = self.Hdoppler | |||
|
441 | ||||
|
442 | self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64) | |||
|
443 | for i in range(channels): | |||
|
444 | for k in range(prof_gen): | |||
|
445 | #·······················NOISE··············· | |||
|
446 | Noise_r = numpy.random.normal(DC_level,stdev,Samples) | |||
|
447 | Noise_i = numpy.random.normal(DC_level,stdev,Samples) | |||
|
448 | Noise = numpy.zeros(Samples,dtype=complex) | |||
|
449 | Noise.real = Noise_r | |||
|
450 | Noise.imag = Noise_i | |||
|
451 | #·······················PULSOS·············· | |||
|
452 | Pulso = numpy.zeros(pulse_size,dtype=complex) | |||
|
453 | Pulso.real = pulses[k%num_codes] | |||
|
454 | Pulso.imag = pulses[k%num_codes] | |||
|
455 | #····················· PULSES+NOISE·········· | |||
|
456 | InBuffer = numpy.zeros(Samples,dtype=complex) | |||
|
457 | InBuffer[m_nR:m_nR+ps] = Pulso | |||
|
458 | InBuffer = Noise+ InBuffer | |||
|
459 | #····················· ANGLE ······························· | |||
|
460 | ||||
|
461 | ||||
|
462 | ||||
|
463 | ||||
|
464 | InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5) | |||
|
465 | InBuffer=InBuffer | |||
|
466 | self.datablock[i][k]= InBuffer | |||
|
467 | #plot_cts(InBuffer,H0=H0,DH0=DH0 | |||
|
468 | ||||
|
469 | ||||
|
470 | #wave_fft(x=InBuffer,plot_show=True) | |||
|
471 | #time.sleep(1) | |||
|
472 | #················DOPPLER SIGNAL............................................... | |||
|
473 | time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen | |||
|
474 | fd = Fdoppler #+(600.0/120)*self.nReadBlocks | |||
|
475 | d_signal = 650*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64) | |||
|
476 | #·················· DATABLOCK + DOPPLER············........................... | |||
|
477 | HD=int(Hdoppler/self.AcqDH_0) | |||
|
478 | self.datablock[0,:,HD]=self.datablock[0,:,HD]+ d_signal # RESULT | |||
|
479 | ''' | |||
|
480 | a= numpy.zeros(10) | |||
|
481 | for i in range(10): | |||
|
482 | a[i]=i+self.nReadBlocks+20 | |||
|
483 | for i in a: | |||
|
484 | self.datablock[0,:,int(i)]=self.datablock[0,:,int(i)]+ d_signal # RESULT | |||
|
485 | ''' |
@@ -0,0 +1,336 | |||||
|
1 | import numpy,math | |||
|
2 | import zmq | |||
|
3 | import tempfile | |||
|
4 | from io import StringIO | |||
|
5 | ########## 1 Heredamos JRODatareader | |||
|
6 | from schainpy.model.io.jroIO_base import * | |||
|
7 | ########## 2 Heredamos las propiedades de ProcessingUnit | |||
|
8 | from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator | |||
|
9 | ########## 3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader | |||
|
10 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader | |||
|
11 | ########## 4 Importaremos el objeto Voltge | |||
|
12 | from schainpy.model.data.jrodata import Voltage | |||
|
13 | ||||
|
14 | @MPDecorator | |||
|
15 | class SimulatorReader(JRODataReader, ProcessingUnit): | |||
|
16 | incIntFactor = 1 | |||
|
17 | nFFTPoints = 0 | |||
|
18 | FixPP_IncInt = 1 | |||
|
19 | FixRCP_IPP = 1000 | |||
|
20 | FixPP_CohInt = 1 | |||
|
21 | Tau_0 = 250 | |||
|
22 | AcqH0_0 = 70 | |||
|
23 | H0 = AcqH0_0 | |||
|
24 | AcqDH_0 = 1.25 | |||
|
25 | DH0 = AcqDH_0 | |||
|
26 | Bauds = 32 | |||
|
27 | FixRCP_TXA = 40 | |||
|
28 | ||||
|
29 | fAngle = 2.0*math.pi*(1/16) | |||
|
30 | DC_level = 500 | |||
|
31 | stdev = 8 | |||
|
32 | Num_codes = 2 | |||
|
33 | code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1]) | |||
|
34 | code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0]) | |||
|
35 | Dyn_sncode = numpy.array([Num_codes,Bauds]) | |||
|
36 | samples = 200 | |||
|
37 | channels = 1 | |||
|
38 | ||||
|
39 | ||||
|
40 | def __init__(self): | |||
|
41 | """ | |||
|
42 | Inicializador de la clases SimulatorReader para | |||
|
43 | generar datos de voltage simulados. | |||
|
44 | Input: | |||
|
45 | dataOut: Objeto de la clase Voltage. | |||
|
46 | Este Objeto sera utilizado apra almacenar | |||
|
47 | un perfil de datos cada vez qe se haga psiversho | |||
|
48 | un requerimiento (getData) | |||
|
49 | """ | |||
|
50 | ProcessingUnit.__init__(self) | |||
|
51 | print(" [ START ] init - Metodo Simulator Reader") | |||
|
52 | self.isConfig = False | |||
|
53 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |||
|
54 | self.systemHeaderObj = SystemHeader() | |||
|
55 | self.radarControlHeaderObj = RadarControllerHeader() | |||
|
56 | self.processingHeaderObj = ProcessingHeader() | |||
|
57 | self.profileIndex = 2**32-1 | |||
|
58 | self.dataOut = Voltage() | |||
|
59 | #self.server = "simulate" | |||
|
60 | print(" [ END ] init - Metodo simulator Reader" ) | |||
|
61 | ||||
|
62 | ||||
|
63 | def __hasNotDataInBuffer(self): | |||
|
64 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs: | |||
|
65 | return 1 | |||
|
66 | return 0 | |||
|
67 | ||||
|
68 | def __setNewBlock(self): | |||
|
69 | if self.flagIsNewFile: | |||
|
70 | #self.lastUTTime = self.basicHeaderObj.utc | |||
|
71 | return 1 | |||
|
72 | ||||
|
73 | def readNextBlock(self): | |||
|
74 | while True: | |||
|
75 | self.__setNewBlock() | |||
|
76 | print (" [ START ] readNexBlock") | |||
|
77 | if not(self.readBlock()): | |||
|
78 | return 0 | |||
|
79 | self.getBasicHeader() | |||
|
80 | break | |||
|
81 | if self.verbose: | |||
|
82 | print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlock, | |||
|
83 | self.processingHeaderObj.dataBlocksPerfile, | |||
|
84 | self.dataOut.datatime.ctime()) ) | |||
|
85 | return 1 | |||
|
86 | ||||
|
87 | def getFirstHeader(self): | |||
|
88 | self.getBasicHeader() | |||
|
89 | self.dataOut.processingHeaderObj= self.processingHeaderObj.copy() | |||
|
90 | ||||
|
91 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |||
|
92 | ||||
|
93 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |||
|
94 | ||||
|
95 | def getBasicHeader(self): | |||
|
96 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ | |||
|
97 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds | |||
|
98 | ||||
|
99 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |||
|
100 | ||||
|
101 | self.dataOut.timeZone = self.basicHeaderObj.timeZone | |||
|
102 | ||||
|
103 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag | |||
|
104 | ||||
|
105 | self.dataOut.errorCount = self.basicHeaderObj.errorCount | |||
|
106 | ||||
|
107 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime | |||
|
108 | ||||
|
109 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |||
|
110 | ||||
|
111 | def reshapeData(self): | |||
|
112 | if self.nTxs==1: | |||
|
113 | return | |||
|
114 | ||||
|
115 | def readBlock(self): | |||
|
116 | self.init_acquisition() | |||
|
117 | pulses, num_codes, pulse_size = self.init_pulse() | |||
|
118 | self.jro_GenerateBlockOfData() | |||
|
119 | self.profileIndex = 0 | |||
|
120 | ||||
|
121 | self.flagIsNewFile = 0 | |||
|
122 | self.flagIsNewBlock = 1 | |||
|
123 | ||||
|
124 | self.nTotalBlocks += 1 | |||
|
125 | self.nReadBlocks += 1 | |||
|
126 | ||||
|
127 | return 1 | |||
|
128 | ||||
|
129 | ||||
|
130 | def getData(self): ### metodo propio de VoltageReader | |||
|
131 | ||||
|
132 | if self.flagNoMoreFiles: | |||
|
133 | self.dataOut.flagNodata= True | |||
|
134 | self.flagDiscontinuousBlock=0 | |||
|
135 | self.flagIsNewBlock = 0 | |||
|
136 | if self.__hasNotDataInBuffer(): # aqui es verdad | |||
|
137 | if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header | |||
|
138 | return 0 | |||
|
139 | self.getFirstHeader() # atributo | |||
|
140 | self.reshapeData() # nTxx1 =1 return , n | |||
|
141 | ||||
|
142 | if not self.getByBlock: | |||
|
143 | self.dataOut.flagDataAsBlock = False | |||
|
144 | self.dataOut.data = self.datablock[:, self.profileIndex, :] | |||
|
145 | self.dataOut.profileIndex = self.profileIndex | |||
|
146 | ||||
|
147 | self.profileIndex += 1 | |||
|
148 | else: | |||
|
149 | pass | |||
|
150 | self.getBasicHeader() | |||
|
151 | self.dataOut.realtime = self.searchFilesOnline | |||
|
152 | ||||
|
153 | return self.dataOut.data | |||
|
154 | ||||
|
155 | ||||
|
156 | def set_kwargs(self, **kwargs): | |||
|
157 | ||||
|
158 | for key, value in kwargs.items(): | |||
|
159 | print(" set_kwargs ",key,value) | |||
|
160 | setattr(self, key, value) | |||
|
161 | ||||
|
162 | ||||
|
163 | def setup(self,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=100, | |||
|
164 | FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32, | |||
|
165 | FixRCP_TXA = 40, fAngle = 2.0*math.pi*(1/16),DC_level= 500, stdev= 8, | |||
|
166 | Num_codes = None , Dyn_snCode = None, samples=200,channels=1, | |||
|
167 | **kwargs): | |||
|
168 | print(" [ START ] - SETUP metodo") | |||
|
169 | self.set_kwargs(**kwargs) | |||
|
170 | self.processingHeaderObj.profilesPerBlock = 100 | |||
|
171 | self.incIntFactor = incIntFactor | |||
|
172 | self.nFFTPoints = nFFTPoints | |||
|
173 | self.FixPP_IncInt = FixPP_IncInt | |||
|
174 | self.FixRCP_IPP = FixRCP_IPP | |||
|
175 | self.FixPP_CohInt = FixPP_CohInt | |||
|
176 | self.Tau_0 = Tau_0 | |||
|
177 | self.AcqH0_0 = AcqH0_0 | |||
|
178 | self.H0 = AcqH0_0 | |||
|
179 | self.AcqDH_0 = AcqDH_0 | |||
|
180 | self.DH0 = AcqDH_0 | |||
|
181 | self.Bauds = Bauds | |||
|
182 | self.FixRCP_TXA = FixRCP_TXA | |||
|
183 | ||||
|
184 | self.fAngle = fAngle | |||
|
185 | self.DC_level = DC_level | |||
|
186 | self.stdev = stdev | |||
|
187 | self.Num_codes = Num_codes | |||
|
188 | #self.code0 = code0 | |||
|
189 | #self.code1 = code1 | |||
|
190 | self.Dyn_snCode = Dyn_snCode | |||
|
191 | self.samples = samples | |||
|
192 | self.channels = channels | |||
|
193 | ||||
|
194 | print(" [ END ] - SETUP metodo") | |||
|
195 | return | |||
|
196 | ||||
|
197 | def run(self,**kwargs): # metodo propio | |||
|
198 | ||||
|
199 | print(" [ START ] Metodo RUN: ", self.server) | |||
|
200 | if not(self.isConfig): | |||
|
201 | self.setup(**kwargs) | |||
|
202 | self.isConfig = True | |||
|
203 | import time | |||
|
204 | time.sleep(3) | |||
|
205 | #if self.server is None: | |||
|
206 | self.getData() | |||
|
207 | #else: | |||
|
208 | # self.getFromServer() | |||
|
209 | ################################################################## | |||
|
210 | ###### Aqui ingresamos las clases y metodos propios del simulador | |||
|
211 | ################################################################## | |||
|
212 | ||||
|
213 | ############################################# | |||
|
214 | ############## INIT_ACQUISITION############## | |||
|
215 | ############################################# | |||
|
216 | def init_acquisition(self): | |||
|
217 | ||||
|
218 | if self.nFFTPoints != 0: | |||
|
219 | self.incIntfactor = m_nProfilesperBlock/self.nFFTPoints | |||
|
220 | if (self.FixPP_IncInt > self.incIntfactor): | |||
|
221 | self.incIntfactor = self.FixPP_IncInt/ self.incIntfactor | |||
|
222 | elif(self.FixPP_IncInt< self.incIntfactor): | |||
|
223 | print("False alert...") | |||
|
224 | ||||
|
225 | ProfilesperBLock = self.processingHeaderObj.profilesPerBlock | |||
|
226 | ||||
|
227 | self.timeperblock =int(((self.FixRCP_m_fIPP | |||
|
228 | *m_nProfilesperBlock | |||
|
229 | *self.FixPP_CohInt | |||
|
230 | *self.incIntfactor) | |||
|
231 | /150.0) | |||
|
232 | *0.9 | |||
|
233 | +0.5) | |||
|
234 | # para cada canal | |||
|
235 | prof_gen = m_nProfilesperBlock*FixPP_m_n_CoherentIntegrations | |||
|
236 | prof_gen = m_nProfilesperBlock | |||
|
237 | ||||
|
238 | ||||
|
239 | m_nReference = int((Dyn_sfTau_0-Dyn_sfAcqH0_0)/(Dyn_sfAcqDH_0)+0.5) | |||
|
240 | print(m_nReference) | |||
|
241 | BaudWidth = int((FixRCP_m_fTXA/Dyn_sfAcqDH_0)/m_nBauds + 0.5 ) | |||
|
242 | print(BaudWidth) | |||
|
243 | if (BaudWidth==0): | |||
|
244 | BaudWidth=1 | |||
|
245 | ||||
|
246 | ||||
|
247 | ################################################################# | |||
|
248 | ##################### init_pulse | |||
|
249 | ################################################################ | |||
|
250 | ||||
|
251 | def init_pulse(m_nNum_Codes,m_nBauds,BaudWidth,Dyn_snCode): | |||
|
252 | fAngle = 2.0*math.pi*(1/16) | |||
|
253 | DC_level = 500 | |||
|
254 | stdev = 8 | |||
|
255 | m_nNum_Codes= m_nNum_Codes | |||
|
256 | m_nBauds = m_nBauds | |||
|
257 | BaudWidth = BaudWidth | |||
|
258 | Dyn_snCode = Dyn_snCode | |||
|
259 | ||||
|
260 | if m_nBauds: | |||
|
261 | pulses = list(range(0,m_nNum_Codes)) | |||
|
262 | num_codes = m_nNum_Codes | |||
|
263 | for i in range(num_codes): | |||
|
264 | pulse_size = m_nBauds*BaudWidth | |||
|
265 | pulses[i] = numpy.zeros(pulse_size) | |||
|
266 | for j in range(m_nBauds): | |||
|
267 | for k in range(BaudWidth): | |||
|
268 | pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600) | |||
|
269 | else: | |||
|
270 | pulses = list(range(1)) | |||
|
271 | pulse_size = int(FixRCP_m_fTXB/0.15+0.5) | |||
|
272 | pulses[0] = numpy.ones(pulse_size) | |||
|
273 | pulses = 600*pulses[0] | |||
|
274 | return pulses,num_codes,pulse_size | |||
|
275 | ||||
|
276 | ################################################################# | |||
|
277 | ##################### Generate block data | |||
|
278 | ################################################################ | |||
|
279 | # m_nChannels | |||
|
280 | # prof_gen | |||
|
281 | # fAngle = 2.0*math.pi*(1/16) | |||
|
282 | # DC_level = 500 | |||
|
283 | # stdev | |||
|
284 | # num_codes | |||
|
285 | #fAngle = 2.0*math.pi*(1/16) | |||
|
286 | #num_codes = 8 | |||
|
287 | ||||
|
288 | ||||
|
289 | def jro_GenerateBlockOfData(m_nSamples,DC_level,stdev,m_nReference,pulses,num_codes,pulse_size,prof_gen,H0,DH0): | |||
|
290 | m_nSamples = m_nSamples | |||
|
291 | DC_level = DC_level | |||
|
292 | stdev = stdev | |||
|
293 | m_nR = m_nReference | |||
|
294 | pulses = pulses | |||
|
295 | num_codes = num_codes | |||
|
296 | ps = pulse_size | |||
|
297 | prof_gen = prof_gen | |||
|
298 | H0 = H0 | |||
|
299 | DH0 = DH0 | |||
|
300 | fAngle = 2.0*math.pi*(1/16) | |||
|
301 | ||||
|
302 | # NOISE | |||
|
303 | Seed_r=random.seed(2) | |||
|
304 | Noise_r = numpy.random.normal(DC_level,stdev,m_nSamples) | |||
|
305 | Seed_i=random.seed(3) | |||
|
306 | Noise_i = numpy.random.normal(DC_level,stdev,m_nSamples) | |||
|
307 | Noise = numpy.zeros(m_nSamples,dtype=complex) | |||
|
308 | Noise.real = Noise_r | |||
|
309 | Noise.imag = Noise_i | |||
|
310 | Pulso = numpy.zeros(pulse_size,dtype=complex) | |||
|
311 | ||||
|
312 | #DOPPLER | |||
|
313 | x = m_nSamples | |||
|
314 | time_space = (DH0*numpy.linspace(0, x-1,num=x) +H0) | |||
|
315 | time_vec = time_space*(1.0e-3/150.0) | |||
|
316 | fd = 10 | |||
|
317 | d_signal = numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64) | |||
|
318 | ||||
|
319 | ||||
|
320 | ||||
|
321 | for i in range(m_nChannels): | |||
|
322 | for k in range(prof_gen): | |||
|
323 | Pulso.real = pulses[k%num_codes] | |||
|
324 | Pulso.imag = pulses[k%num_codes] | |||
|
325 | InBuffer = numpy.zeros(m_nSamples,dtype=complex) | |||
|
326 | InBuffer[m_nR:m_nR+ps] = Pulso | |||
|
327 | InBuffer = Noise+ InBuffer | |||
|
328 | InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( fAngle)*5) | |||
|
329 | InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( fAngle)*5) | |||
|
330 | InBuffer=InBuffer | |||
|
331 | #print(InBuffer[:10]) | |||
|
332 | #print(InBuffer.shape) | |||
|
333 | plot_cts(InBuffer,H0=H0,DH0=DH0) | |||
|
334 | #wave_fft(x=InBuffer,plot_show=True) | |||
|
335 | #time.sleep(1) | |||
|
336 |
@@ -57,7 +57,7 def MPProject(project, n=cpu_count()): | |||||
57 | nFiles = len(files) |
|
57 | nFiles = len(files) | |
58 | if nFiles == 0: |
|
58 | if nFiles == 0: | |
59 | continue |
|
59 | continue | |
60 |
skip = int(math.ceil(nFiles / n)) |
|
60 | skip = int(math.ceil(nFiles / n)) | |
61 | while nFiles > cursor * skip: |
|
61 | while nFiles > cursor * skip: | |
62 | rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor, |
|
62 | rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor, | |
63 | skip=skip) |
|
63 | skip=skip) | |
@@ -81,11 +81,11 def MPProject(project, n=cpu_count()): | |||||
81 | time.sleep(3) |
|
81 | time.sleep(3) | |
82 |
|
82 | |||
83 | def wait(context): |
|
83 | def wait(context): | |
84 |
|
84 | |||
85 | time.sleep(1) |
|
85 | time.sleep(1) | |
86 | c = zmq.Context() |
|
86 | c = zmq.Context() | |
87 | receiver = c.socket(zmq.SUB) |
|
87 | receiver = c.socket(zmq.SUB) | |
88 |
receiver.connect('ipc:///tmp/schain_{}_pub'.format(self.id)) |
|
88 | receiver.connect('ipc:///tmp/schain_{}_pub'.format(self.id)) | |
89 | receiver.setsockopt(zmq.SUBSCRIBE, self.id.encode()) |
|
89 | receiver.setsockopt(zmq.SUBSCRIBE, self.id.encode()) | |
90 | msg = receiver.recv_multipart()[1] |
|
90 | msg = receiver.recv_multipart()[1] | |
91 | context.terminate() |
|
91 | context.terminate() | |
@@ -262,7 +262,7 class ParameterConf(): | |||||
262 | parmElement.set('name', self.name) |
|
262 | parmElement.set('name', self.name) | |
263 | parmElement.set('value', self.value) |
|
263 | parmElement.set('value', self.value) | |
264 | parmElement.set('format', self.format) |
|
264 | parmElement.set('format', self.format) | |
265 |
|
265 | |||
266 | def readXml(self, parmElement): |
|
266 | def readXml(self, parmElement): | |
267 |
|
267 | |||
268 | self.id = parmElement.get('id') |
|
268 | self.id = parmElement.get('id') | |
@@ -417,7 +417,7 class OperationConf(): | |||||
417 | self.name = opElement.get('name') |
|
417 | self.name = opElement.get('name') | |
418 | self.type = opElement.get('type') |
|
418 | self.type = opElement.get('type') | |
419 | self.priority = opElement.get('priority') |
|
419 | self.priority = opElement.get('priority') | |
420 |
self.project_id = str(project_id) |
|
420 | self.project_id = str(project_id) | |
421 |
|
421 | |||
422 | # Compatible with old signal chain version |
|
422 | # Compatible with old signal chain version | |
423 | # Use of 'run' method instead 'init' |
|
423 | # Use of 'run' method instead 'init' | |
@@ -476,7 +476,7 class ProcUnitConf(): | |||||
476 | self.id = None |
|
476 | self.id = None | |
477 | self.datatype = None |
|
477 | self.datatype = None | |
478 | self.name = None |
|
478 | self.name = None | |
479 |
self.inputId = None |
|
479 | self.inputId = None | |
480 | self.opConfObjList = [] |
|
480 | self.opConfObjList = [] | |
481 | self.procUnitObj = None |
|
481 | self.procUnitObj = None | |
482 | self.opObjDict = {} |
|
482 | self.opObjDict = {} | |
@@ -497,7 +497,7 class ProcUnitConf(): | |||||
497 |
|
497 | |||
498 | return self.id |
|
498 | return self.id | |
499 |
|
499 | |||
500 |
def updateId(self, new_id): |
|
500 | def updateId(self, new_id): | |
501 | ''' |
|
501 | ''' | |
502 | new_id = int(parentId) * 10 + (int(self.id) % 10) |
|
502 | new_id = int(parentId) * 10 + (int(self.id) % 10) | |
503 | new_inputId = int(parentId) * 10 + (int(self.inputId) % 10) |
|
503 | new_inputId = int(parentId) * 10 + (int(self.inputId) % 10) | |
@@ -556,7 +556,7 class ProcUnitConf(): | |||||
556 | id sera el topico a publicar |
|
556 | id sera el topico a publicar | |
557 | inputId sera el topico a subscribirse |
|
557 | inputId sera el topico a subscribirse | |
558 | ''' |
|
558 | ''' | |
559 |
|
559 | |||
560 | # Compatible with old signal chain version |
|
560 | # Compatible with old signal chain version | |
561 | if datatype == None and name == None: |
|
561 | if datatype == None and name == None: | |
562 | raise ValueError('datatype or name should be defined') |
|
562 | raise ValueError('datatype or name should be defined') | |
@@ -581,7 +581,7 class ProcUnitConf(): | |||||
581 | self.lock = lock |
|
581 | self.lock = lock | |
582 | self.opConfObjList = [] |
|
582 | self.opConfObjList = [] | |
583 |
|
583 | |||
584 |
self.addOperation(name='run', optype='self') |
|
584 | self.addOperation(name='run', optype='self') | |
585 |
|
585 | |||
586 | def removeOperations(self): |
|
586 | def removeOperations(self): | |
587 |
|
587 | |||
@@ -677,30 +677,32 class ProcUnitConf(): | |||||
677 | ''' |
|
677 | ''' | |
678 | Instancia de unidades de procesamiento. |
|
678 | Instancia de unidades de procesamiento. | |
679 | ''' |
|
679 | ''' | |
680 |
|
680 | #print(" [ CREATE OBJ ] :",self.name) | ||
681 | className = eval(self.name) |
|
681 | className = eval(self.name) | |
|
682 | ||||
682 | kwargs = self.getKwargs() |
|
683 | kwargs = self.getKwargs() | |
|
684 | #print (" [ kwargs ] : ", kwargs) | |||
683 | procUnitObj = className(self.id, self.inputId, self.project_id, self.err_queue, self.lock, 'ProcUnit', **kwargs) |
|
685 | procUnitObj = className(self.id, self.inputId, self.project_id, self.err_queue, self.lock, 'ProcUnit', **kwargs) | |
684 | log.success('creating process...', self.name) |
|
686 | log.success('creating process...', self.name) | |
685 |
|
687 | |||
686 | for opConfObj in self.opConfObjList: |
|
688 | for opConfObj in self.opConfObjList: | |
687 |
|
689 | |||
688 | if opConfObj.type == 'self' and opConfObj.name == 'run': |
|
690 | if opConfObj.type == 'self' and opConfObj.name == 'run': | |
689 | continue |
|
691 | continue | |
690 | elif opConfObj.type == 'self': |
|
692 | elif opConfObj.type == 'self': | |
691 | opObj = getattr(procUnitObj, opConfObj.name) |
|
693 | opObj = getattr(procUnitObj, opConfObj.name) | |
692 | else: |
|
694 | else: | |
693 | opObj = opConfObj.createObject() |
|
695 | opObj = opConfObj.createObject() | |
694 |
|
696 | |||
695 | log.success('adding operation: {}, type:{}'.format( |
|
697 | log.success('adding operation: {}, type:{}'.format( | |
696 | opConfObj.name, |
|
698 | opConfObj.name, | |
697 | opConfObj.type), self.name) |
|
699 | opConfObj.type), self.name) | |
698 |
|
700 | |||
699 | procUnitObj.addOperation(opConfObj, opObj) |
|
701 | procUnitObj.addOperation(opConfObj, opObj) | |
700 |
|
702 | |||
701 | procUnitObj.start() |
|
703 | procUnitObj.start() | |
702 | self.procUnitObj = procUnitObj |
|
704 | self.procUnitObj = procUnitObj | |
703 |
|
705 | |||
704 | def close(self): |
|
706 | def close(self): | |
705 |
|
707 | |||
706 | for opConfObj in self.opConfObjList: |
|
708 | for opConfObj in self.opConfObjList: | |
@@ -732,8 +734,8 class ReadUnitConf(ProcUnitConf): | |||||
732 |
|
734 | |||
733 | def getElementName(self): |
|
735 | def getElementName(self): | |
734 |
|
736 | |||
735 |
return self.ELEMENTNAME |
|
737 | return self.ELEMENTNAME | |
736 |
|
738 | |||
737 | def setup(self, project_id, id, name, datatype, err_queue, path='', startDate='', endDate='', |
|
739 | def setup(self, project_id, id, name, datatype, err_queue, path='', startDate='', endDate='', | |
738 | startTime='', endTime='', server=None, **kwargs): |
|
740 | startTime='', endTime='', server=None, **kwargs): | |
739 |
|
741 | |||
@@ -745,8 +747,9 class ReadUnitConf(ProcUnitConf): | |||||
745 | kwargs deben ser trasmitidos en la instanciacion |
|
747 | kwargs deben ser trasmitidos en la instanciacion | |
746 |
|
748 | |||
747 | ''' |
|
749 | ''' | |
748 |
|
750 | |||
749 | # Compatible with old signal chain version |
|
751 | # Compatible with old signal chain version | |
|
752 | #print (" [INSIDE] : setup ReadUnit", kwargs) | |||
750 | if datatype == None and name == None: |
|
753 | if datatype == None and name == None: | |
751 | raise ValueError('datatype or name should be defined') |
|
754 | raise ValueError('datatype or name should be defined') | |
752 | if name == None: |
|
755 | if name == None: | |
@@ -773,7 +776,7 class ReadUnitConf(ProcUnitConf): | |||||
773 | self.startTime = startTime |
|
776 | self.startTime = startTime | |
774 | self.endTime = endTime |
|
777 | self.endTime = endTime | |
775 | self.server = server |
|
778 | self.server = server | |
776 |
self.err_queue = err_queue |
|
779 | self.err_queue = err_queue | |
777 | self.addRunOperation(**kwargs) |
|
780 | self.addRunOperation(**kwargs) | |
778 |
|
781 | |||
779 | def update(self, **kwargs): |
|
782 | def update(self, **kwargs): | |
@@ -804,7 +807,7 class ReadUnitConf(ProcUnitConf): | |||||
804 |
|
807 | |||
805 | def addRunOperation(self, **kwargs): |
|
808 | def addRunOperation(self, **kwargs): | |
806 |
|
809 | |||
807 |
opObj = self.addOperation(name='run', optype='self') |
|
810 | opObj = self.addOperation(name='run', optype='self') | |
808 |
|
811 | |||
809 | if self.server is None: |
|
812 | if self.server is None: | |
810 | opObj.addParameter( |
|
813 | opObj.addParameter( | |
@@ -822,6 +825,13 class ReadUnitConf(ProcUnitConf): | |||||
822 | for key, value in list(kwargs.items()): |
|
825 | for key, value in list(kwargs.items()): | |
823 | opObj.addParameter(name=key, value=value, |
|
826 | opObj.addParameter(name=key, value=value, | |
824 | format=type(value).__name__) |
|
827 | format=type(value).__name__) | |
|
828 | elif self.server== "simulate": | |||
|
829 | #print(" [ INSIDE ] : AROperation simulate -True simulate") | |||
|
830 | opObj.addParameter( | |||
|
831 | name='datatype', value=self.datatype, format='str') | |||
|
832 | for key, value in list(kwargs.items()): | |||
|
833 | opObj.addParameter(name=key, value=value, | |||
|
834 | format=type(value).__name__) | |||
825 | else: |
|
835 | else: | |
826 | opObj.addParameter(name='server', value=self.server, format='str') |
|
836 | opObj.addParameter(name='server', value=self.server, format='str') | |
827 |
|
837 | |||
@@ -942,7 +952,7 class Project(Process): | |||||
942 | print('*' * 19) |
|
952 | print('*' * 19) | |
943 | print(' ') |
|
953 | print(' ') | |
944 | self.id = str(id) |
|
954 | self.id = str(id) | |
945 |
self.description = description |
|
955 | self.description = description | |
946 | self.email = email |
|
956 | self.email = email | |
947 | self.alarm = alarm |
|
957 | self.alarm = alarm | |
948 | if name: |
|
958 | if name: | |
@@ -977,7 +987,7 class Project(Process): | |||||
977 | readUnitConfObj = ReadUnitConf() |
|
987 | readUnitConfObj = ReadUnitConf() | |
978 | readUnitConfObj.setup(self.id, idReadUnit, name, datatype, self.err_queue, **kwargs) |
|
988 | readUnitConfObj.setup(self.id, idReadUnit, name, datatype, self.err_queue, **kwargs) | |
979 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
989 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
980 |
|
990 | |||
981 | return readUnitConfObj |
|
991 | return readUnitConfObj | |
982 |
|
992 | |||
983 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
993 | def addProcUnit(self, inputId='0', datatype=None, name=None): | |
@@ -994,7 +1004,7 class Project(Process): | |||||
994 |
|
1004 | |||
995 | idProcUnit = self.__getNewId() |
|
1005 | idProcUnit = self.__getNewId() | |
996 | procUnitConfObj = ProcUnitConf() |
|
1006 | procUnitConfObj = ProcUnitConf() | |
997 |
input_proc = self.procUnitConfObjDict[inputId] |
|
1007 | input_proc = self.procUnitConfObjDict[inputId] | |
998 | procUnitConfObj.setup(self.id, idProcUnit, name, datatype, inputId, self.err_queue, input_proc.lock) |
|
1008 | procUnitConfObj.setup(self.id, idProcUnit, name, datatype, inputId, self.err_queue, input_proc.lock) | |
999 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1009 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1000 |
|
1010 | |||
@@ -1152,14 +1162,14 class Project(Process): | |||||
1152 |
|
1162 | |||
1153 | t = Thread(target=self.__monitor, args=(self.err_queue, self.ctx)) |
|
1163 | t = Thread(target=self.__monitor, args=(self.err_queue, self.ctx)) | |
1154 | t.start() |
|
1164 | t.start() | |
1155 |
|
1165 | |||
1156 | def __monitor(self, queue, ctx): |
|
1166 | def __monitor(self, queue, ctx): | |
1157 |
|
1167 | |||
1158 | import socket |
|
1168 | import socket | |
1159 |
|
1169 | |||
1160 | procs = 0 |
|
1170 | procs = 0 | |
1161 | err_msg = '' |
|
1171 | err_msg = '' | |
1162 |
|
1172 | |||
1163 | while True: |
|
1173 | while True: | |
1164 | msg = queue.get() |
|
1174 | msg = queue.get() | |
1165 | if '#_start_#' in msg: |
|
1175 | if '#_start_#' in msg: | |
@@ -1168,11 +1178,11 class Project(Process): | |||||
1168 | procs -=1 |
|
1178 | procs -=1 | |
1169 | else: |
|
1179 | else: | |
1170 | err_msg = msg |
|
1180 | err_msg = msg | |
1171 |
|
1181 | |||
1172 |
if procs == 0 or 'Traceback' in err_msg: |
|
1182 | if procs == 0 or 'Traceback' in err_msg: | |
1173 | break |
|
1183 | break | |
1174 | time.sleep(0.1) |
|
1184 | time.sleep(0.1) | |
1175 |
|
1185 | |||
1176 | if '|' in err_msg: |
|
1186 | if '|' in err_msg: | |
1177 | name, err = err_msg.split('|') |
|
1187 | name, err = err_msg.split('|') | |
1178 | if 'SchainWarning' in err: |
|
1188 | if 'SchainWarning' in err: | |
@@ -1181,9 +1191,9 class Project(Process): | |||||
1181 | log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), name) |
|
1191 | log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), name) | |
1182 | else: |
|
1192 | else: | |
1183 | log.error(err, name) |
|
1193 | log.error(err, name) | |
1184 |
else: |
|
1194 | else: | |
1185 | name, err = self.name, err_msg |
|
1195 | name, err = self.name, err_msg | |
1186 |
|
1196 | |||
1187 | time.sleep(2) |
|
1197 | time.sleep(2) | |
1188 |
|
1198 | |||
1189 | for conf in self.procUnitConfObjDict.values(): |
|
1199 | for conf in self.procUnitConfObjDict.values(): | |
@@ -1191,7 +1201,7 class Project(Process): | |||||
1191 | if confop.type == 'external': |
|
1201 | if confop.type == 'external': | |
1192 | confop.opObj.terminate() |
|
1202 | confop.opObj.terminate() | |
1193 | conf.procUnitObj.terminate() |
|
1203 | conf.procUnitObj.terminate() | |
1194 |
|
1204 | |||
1195 | ctx.term() |
|
1205 | ctx.term() | |
1196 |
|
1206 | |||
1197 | message = ''.join(err) |
|
1207 | message = ''.join(err) | |
@@ -1217,7 +1227,7 class Project(Process): | |||||
1217 | subtitle += '[End time = %s]\n' % readUnitConfObj.endTime |
|
1227 | subtitle += '[End time = %s]\n' % readUnitConfObj.endTime | |
1218 |
|
1228 | |||
1219 | a = Alarm( |
|
1229 | a = Alarm( | |
1220 |
modes=self.alarm, |
|
1230 | modes=self.alarm, | |
1221 | email=self.email, |
|
1231 | email=self.email, | |
1222 | message=message, |
|
1232 | message=message, | |
1223 | subject=subject, |
|
1233 | subject=subject, | |
@@ -1266,7 +1276,7 class Project(Process): | |||||
1266 |
|
1276 | |||
1267 | if not os.path.exists('/tmp/schain'): |
|
1277 | if not os.path.exists('/tmp/schain'): | |
1268 | os.mkdir('/tmp/schain') |
|
1278 | os.mkdir('/tmp/schain') | |
1269 |
|
1279 | |||
1270 | self.ctx = zmq.Context() |
|
1280 | self.ctx = zmq.Context() | |
1271 | xpub = self.ctx.socket(zmq.XPUB) |
|
1281 | xpub = self.ctx.socket(zmq.XPUB) | |
1272 | xpub.bind('ipc:///tmp/schain/{}_pub'.format(self.id)) |
|
1282 | xpub.bind('ipc:///tmp/schain/{}_pub'.format(self.id)) | |
@@ -1282,9 +1292,9 class Project(Process): | |||||
1282 | def run(self): |
|
1292 | def run(self): | |
1283 |
|
1293 | |||
1284 | log.success('Starting {}: {}'.format(self.name, self.id), tag='') |
|
1294 | log.success('Starting {}: {}'.format(self.name, self.id), tag='') | |
1285 |
self.start_time = time.time() |
|
1295 | self.start_time = time.time() | |
1286 |
self.createObjects() |
|
1296 | self.createObjects() | |
1287 |
self.setProxy() |
|
1297 | self.setProxy() | |
1288 | log.success('{} Done (Time: {}s)'.format( |
|
1298 | log.success('{} Done (Time: {}s)'.format( | |
1289 | self.name, |
|
1299 | self.name, | |
1290 | time.time()-self.start_time), '') |
|
1300 | time.time()-self.start_time), '') |
@@ -177,9 +177,10 class Scope_(Figure): | |||||
177 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
177 | channelIndexList.append(dataOut.channelList.index(channel)) | |
178 |
|
178 | |||
179 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
179 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
180 |
# |
|
180 | #print("***************** PLOTEO **************************") | |
181 |
# |
|
181 | #print(dataOut.nProfiles) | |
182 |
# |
|
182 | #print(dataOut.heightList.shape) | |
|
183 | #print(dataOut.data.shape) | |||
183 | if dataOut.flagDataAsBlock: |
|
184 | if dataOut.flagDataAsBlock: | |
184 |
|
185 | |||
185 | for i in range(dataOut.nProfiles): |
|
186 | for i in range(dataOut.nProfiles): |
@@ -20,4 +20,6 from .bltrIO_spectra import * | |||||
20 | from .jroIO_mira35c import * |
|
20 | from .jroIO_mira35c import * | |
21 | from .julIO_param import * |
|
21 | from .julIO_param import * | |
22 |
|
22 | |||
23 | from .pxIO_param import * No newline at end of file |
|
23 | from .pxIO_param import * | |
|
24 | ||||
|
25 | from .jroIO_simulator import * |
@@ -383,7 +383,7 def isRadarFolder(folder): | |||||
383 |
|
383 | |||
384 |
|
384 | |||
385 | def isRadarFile(file): |
|
385 | def isRadarFile(file): | |
386 |
try: |
|
386 | try: | |
387 | year = int(file[1:5]) |
|
387 | year = int(file[1:5]) | |
388 | doy = int(file[5:8]) |
|
388 | doy = int(file[5:8]) | |
389 | set = int(file[8:11]) |
|
389 | set = int(file[8:11]) | |
@@ -394,10 +394,10 def isRadarFile(file): | |||||
394 |
|
394 | |||
395 |
|
395 | |||
396 | def getDateFromRadarFile(file): |
|
396 | def getDateFromRadarFile(file): | |
397 |
try: |
|
397 | try: | |
398 | year = int(file[1:5]) |
|
398 | year = int(file[1:5]) | |
399 | doy = int(file[5:8]) |
|
399 | doy = int(file[5:8]) | |
400 |
set = int(file[8:11]) |
|
400 | set = int(file[8:11]) | |
401 | except: |
|
401 | except: | |
402 | return None |
|
402 | return None | |
403 |
|
403 | |||
@@ -416,7 +416,7 def getDateFromRadarFolder(folder): | |||||
416 | return thisDate |
|
416 | return thisDate | |
417 |
|
417 | |||
418 | def parse_format(s, fmt): |
|
418 | def parse_format(s, fmt): | |
419 |
|
419 | |||
420 | for i in range(fmt.count('%')): |
|
420 | for i in range(fmt.count('%')): | |
421 | x = fmt.index('%') |
|
421 | x = fmt.index('%') | |
422 | d = DT_DIRECTIVES[fmt[x:x+2]] |
|
422 | d = DT_DIRECTIVES[fmt[x:x+2]] | |
@@ -483,7 +483,7 class Reader(object): | |||||
483 |
|
483 | |||
484 | def run(self): |
|
484 | def run(self): | |
485 |
|
485 | |||
486 |
raise NotImplementedError |
|
486 | raise NotImplementedError | |
487 |
|
487 | |||
488 | def getAllowedArgs(self): |
|
488 | def getAllowedArgs(self): | |
489 | if hasattr(self, '__attrs__'): |
|
489 | if hasattr(self, '__attrs__'): | |
@@ -495,19 +495,19 class Reader(object): | |||||
495 |
|
495 | |||
496 | for key, value in kwargs.items(): |
|
496 | for key, value in kwargs.items(): | |
497 | setattr(self, key, value) |
|
497 | setattr(self, key, value) | |
498 |
|
498 | |||
499 | def find_folders(self, path, startDate, endDate, folderfmt, last=False): |
|
499 | def find_folders(self, path, startDate, endDate, folderfmt, last=False): | |
500 |
|
500 | |||
501 |
folders = [x for f in path.split(',') |
|
501 | folders = [x for f in path.split(',') | |
502 | for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))] |
|
502 | for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))] | |
503 | folders.sort() |
|
503 | folders.sort() | |
504 |
|
504 | |||
505 | if last: |
|
505 | if last: | |
506 | folders = [folders[-1]] |
|
506 | folders = [folders[-1]] | |
507 |
|
507 | |||
508 |
for folder in folders: |
|
508 | for folder in folders: | |
509 |
try: |
|
509 | try: | |
510 |
dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date() |
|
510 | dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date() | |
511 | if dt >= startDate and dt <= endDate: |
|
511 | if dt >= startDate and dt <= endDate: | |
512 | yield os.path.join(path, folder) |
|
512 | yield os.path.join(path, folder) | |
513 | else: |
|
513 | else: | |
@@ -516,38 +516,38 class Reader(object): | |||||
516 | log.log('Skiping folder {}'.format(folder), self.name) |
|
516 | log.log('Skiping folder {}'.format(folder), self.name) | |
517 | continue |
|
517 | continue | |
518 | return |
|
518 | return | |
519 |
|
519 | |||
520 |
def find_files(self, folders, ext, filefmt, startDate=None, endDate=None, |
|
520 | def find_files(self, folders, ext, filefmt, startDate=None, endDate=None, | |
521 | expLabel='', last=False): |
|
521 | expLabel='', last=False): | |
522 |
|
522 | |||
523 |
for path in folders: |
|
523 | for path in folders: | |
524 | files = glob.glob1(path, '*{}'.format(ext)) |
|
524 | files = glob.glob1(path, '*{}'.format(ext)) | |
525 | files.sort() |
|
525 | files.sort() | |
526 | if last: |
|
526 | if last: | |
527 |
if files: |
|
527 | if files: | |
528 | fo = files[-1] |
|
528 | fo = files[-1] | |
529 |
try: |
|
529 | try: | |
530 |
dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date() |
|
530 | dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date() | |
531 |
yield os.path.join(path, expLabel, fo) |
|
531 | yield os.path.join(path, expLabel, fo) | |
532 |
except Exception as e: |
|
532 | except Exception as e: | |
533 | pass |
|
533 | pass | |
534 | return |
|
534 | return | |
535 | else: |
|
535 | else: | |
536 | return |
|
536 | return | |
537 |
|
537 | |||
538 | for fo in files: |
|
538 | for fo in files: | |
539 |
try: |
|
539 | try: | |
540 |
dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date() |
|
540 | dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date() | |
541 | if dt >= startDate and dt <= endDate: |
|
541 | if dt >= startDate and dt <= endDate: | |
542 | yield os.path.join(path, expLabel, fo) |
|
542 | yield os.path.join(path, expLabel, fo) | |
543 | else: |
|
543 | else: | |
544 | log.log('Skiping file {}'.format(fo), self.name) |
|
544 | log.log('Skiping file {}'.format(fo), self.name) | |
545 | except Exception as e: |
|
545 | except Exception as e: | |
546 | log.log('Skiping file {}'.format(fo), self.name) |
|
546 | log.log('Skiping file {}'.format(fo), self.name) | |
547 |
continue |
|
547 | continue | |
548 |
|
548 | |||
549 | def searchFilesOffLine(self, path, startDate, endDate, |
|
549 | def searchFilesOffLine(self, path, startDate, endDate, | |
550 |
expLabel, ext, walk, |
|
550 | expLabel, ext, walk, | |
551 | filefmt, folderfmt): |
|
551 | filefmt, folderfmt): | |
552 | """Search files in offline mode for the given arguments |
|
552 | """Search files in offline mode for the given arguments | |
553 |
|
553 | |||
@@ -560,12 +560,12 class Reader(object): | |||||
560 | path, startDate, endDate, folderfmt) |
|
560 | path, startDate, endDate, folderfmt) | |
561 | else: |
|
561 | else: | |
562 | folders = path.split(',') |
|
562 | folders = path.split(',') | |
563 |
|
563 | |||
564 | return self.find_files( |
|
564 | return self.find_files( | |
565 |
folders, ext, filefmt, startDate, endDate, expLabel) |
|
565 | folders, ext, filefmt, startDate, endDate, expLabel) | |
566 |
|
566 | |||
567 | def searchFilesOnLine(self, path, startDate, endDate, |
|
567 | def searchFilesOnLine(self, path, startDate, endDate, | |
568 |
expLabel, ext, walk, |
|
568 | expLabel, ext, walk, | |
569 | filefmt, folderfmt): |
|
569 | filefmt, folderfmt): | |
570 | """Search for the last file of the last folder |
|
570 | """Search for the last file of the last folder | |
571 |
|
571 | |||
@@ -578,13 +578,13 class Reader(object): | |||||
578 | Return: |
|
578 | Return: | |
579 | generator with the full path of last filename |
|
579 | generator with the full path of last filename | |
580 | """ |
|
580 | """ | |
581 |
|
581 | |||
582 | if walk: |
|
582 | if walk: | |
583 | folders = self.find_folders( |
|
583 | folders = self.find_folders( | |
584 | path, startDate, endDate, folderfmt, last=True) |
|
584 | path, startDate, endDate, folderfmt, last=True) | |
585 | else: |
|
585 | else: | |
586 | folders = path.split(',') |
|
586 | folders = path.split(',') | |
587 |
|
587 | |||
588 | return self.find_files( |
|
588 | return self.find_files( | |
589 | folders, ext, filefmt, startDate, endDate, expLabel, last=True) |
|
589 | folders, ext, filefmt, startDate, endDate, expLabel, last=True) | |
590 |
|
590 | |||
@@ -593,13 +593,13 class Reader(object): | |||||
593 |
|
593 | |||
594 | while True: |
|
594 | while True: | |
595 | if self.fp != None: |
|
595 | if self.fp != None: | |
596 |
self.fp.close() |
|
596 | self.fp.close() | |
597 |
|
597 | |||
598 | if self.online: |
|
598 | if self.online: | |
599 | newFile = self.setNextFileOnline() |
|
599 | newFile = self.setNextFileOnline() | |
600 | else: |
|
600 | else: | |
601 | newFile = self.setNextFileOffline() |
|
601 | newFile = self.setNextFileOffline() | |
602 |
|
602 | |||
603 | if not(newFile): |
|
603 | if not(newFile): | |
604 | if self.online: |
|
604 | if self.online: | |
605 | raise schainpy.admin.SchainError('Time to wait for new files reach') |
|
605 | raise schainpy.admin.SchainError('Time to wait for new files reach') | |
@@ -608,10 +608,10 class Reader(object): | |||||
608 | raise schainpy.admin.SchainWarning('No files found in the given path') |
|
608 | raise schainpy.admin.SchainWarning('No files found in the given path') | |
609 | else: |
|
609 | else: | |
610 | raise schainpy.admin.SchainWarning('No more files to read') |
|
610 | raise schainpy.admin.SchainWarning('No more files to read') | |
611 |
|
611 | |||
612 | if self.verifyFile(self.filename): |
|
612 | if self.verifyFile(self.filename): | |
613 | break |
|
613 | break | |
614 |
|
614 | |||
615 | log.log('Opening file: %s' % self.filename, self.name) |
|
615 | log.log('Opening file: %s' % self.filename, self.name) | |
616 |
|
616 | |||
617 | self.readFirstHeader() |
|
617 | self.readFirstHeader() | |
@@ -624,7 +624,7 class Reader(object): | |||||
624 | self.filename |
|
624 | self.filename | |
625 | self.fp |
|
625 | self.fp | |
626 | self.filesize |
|
626 | self.filesize | |
627 |
|
627 | |||
628 | Return: |
|
628 | Return: | |
629 | boolean |
|
629 | boolean | |
630 |
|
630 | |||
@@ -632,7 +632,7 class Reader(object): | |||||
632 | nextFile = True |
|
632 | nextFile = True | |
633 | nextDay = False |
|
633 | nextDay = False | |
634 |
|
634 | |||
635 |
for nFiles in range(self.nFiles+1): |
|
635 | for nFiles in range(self.nFiles+1): | |
636 | for nTries in range(self.nTries): |
|
636 | for nTries in range(self.nTries): | |
637 | fullfilename, filename = self.checkForRealPath(nextFile, nextDay) |
|
637 | fullfilename, filename = self.checkForRealPath(nextFile, nextDay) | |
638 | if fullfilename is not None: |
|
638 | if fullfilename is not None: | |
@@ -642,18 +642,18 class Reader(object): | |||||
642 | self.name) |
|
642 | self.name) | |
643 | time.sleep(self.delay) |
|
643 | time.sleep(self.delay) | |
644 | nextFile = False |
|
644 | nextFile = False | |
645 |
continue |
|
645 | continue | |
646 |
|
646 | |||
647 | if fullfilename is not None: |
|
647 | if fullfilename is not None: | |
648 | break |
|
648 | break | |
649 |
|
649 | |||
650 | self.nTries = 1 |
|
650 | self.nTries = 1 | |
651 |
nextFile = True |
|
651 | nextFile = True | |
652 |
|
652 | |||
653 | if nFiles == (self.nFiles - 1): |
|
653 | if nFiles == (self.nFiles - 1): | |
654 | log.log('Trying with next day...', self.name) |
|
654 | log.log('Trying with next day...', self.name) | |
655 | nextDay = True |
|
655 | nextDay = True | |
656 |
self.nTries = 3 |
|
656 | self.nTries = 3 | |
657 |
|
657 | |||
658 | if fullfilename: |
|
658 | if fullfilename: | |
659 | self.fileSize = os.path.getsize(fullfilename) |
|
659 | self.fileSize = os.path.getsize(fullfilename) | |
@@ -665,18 +665,18 class Reader(object): | |||||
665 | self.flagNoMoreFiles = 0 |
|
665 | self.flagNoMoreFiles = 0 | |
666 | self.fileIndex += 1 |
|
666 | self.fileIndex += 1 | |
667 | return 1 |
|
667 | return 1 | |
668 |
else: |
|
668 | else: | |
669 | return 0 |
|
669 | return 0 | |
670 |
|
670 | |||
671 | def setNextFileOffline(self): |
|
671 | def setNextFileOffline(self): | |
672 | """Open the next file to be readed in offline mode""" |
|
672 | """Open the next file to be readed in offline mode""" | |
673 |
|
673 | |||
674 | try: |
|
674 | try: | |
675 | filename = next(self.filenameList) |
|
675 | filename = next(self.filenameList) | |
676 | self.fileIndex +=1 |
|
676 | self.fileIndex +=1 | |
677 | except StopIteration: |
|
677 | except StopIteration: | |
678 | self.flagNoMoreFiles = 1 |
|
678 | self.flagNoMoreFiles = 1 | |
679 |
return 0 |
|
679 | return 0 | |
680 |
|
680 | |||
681 | self.filename = filename |
|
681 | self.filename = filename | |
682 | self.fileSize = os.path.getsize(filename) |
|
682 | self.fileSize = os.path.getsize(filename) | |
@@ -684,22 +684,22 class Reader(object): | |||||
684 | self.flagIsNewFile = 1 |
|
684 | self.flagIsNewFile = 1 | |
685 |
|
685 | |||
686 | return 1 |
|
686 | return 1 | |
687 |
|
687 | |||
688 | @staticmethod |
|
688 | @staticmethod | |
689 | def isDateTimeInRange(dt, startDate, endDate, startTime, endTime): |
|
689 | def isDateTimeInRange(dt, startDate, endDate, startTime, endTime): | |
690 | """Check if the given datetime is in range""" |
|
690 | """Check if the given datetime is in range""" | |
691 |
|
691 | |||
692 | if startDate <= dt.date() <= endDate: |
|
692 | if startDate <= dt.date() <= endDate: | |
693 | if startTime <= dt.time() <= endTime: |
|
693 | if startTime <= dt.time() <= endTime: | |
694 | return True |
|
694 | return True | |
695 | return False |
|
695 | return False | |
696 |
|
696 | |||
697 | def verifyFile(self, filename): |
|
697 | def verifyFile(self, filename): | |
698 | """Check for a valid file |
|
698 | """Check for a valid file | |
699 |
|
699 | |||
700 | Arguments: |
|
700 | Arguments: | |
701 | filename -- full path filename |
|
701 | filename -- full path filename | |
702 |
|
702 | |||
703 | Return: |
|
703 | Return: | |
704 | boolean |
|
704 | boolean | |
705 | """ |
|
705 | """ | |
@@ -710,7 +710,7 class Reader(object): | |||||
710 | """Check if the next file to be readed exists""" |
|
710 | """Check if the next file to be readed exists""" | |
711 |
|
711 | |||
712 | raise NotImplementedError |
|
712 | raise NotImplementedError | |
713 |
|
713 | |||
714 | def readFirstHeader(self): |
|
714 | def readFirstHeader(self): | |
715 | """Parse the file header""" |
|
715 | """Parse the file header""" | |
716 |
|
716 | |||
@@ -753,8 +753,9 class JRODataReader(Reader): | |||||
753 | Return: |
|
753 | Return: | |
754 | str -- fullpath of the file |
|
754 | str -- fullpath of the file | |
755 | """ |
|
755 | """ | |
756 |
|
756 | |||
757 |
|
757 | |||
|
758 | ||||
758 | if nextFile: |
|
759 | if nextFile: | |
759 | self.set += 1 |
|
760 | self.set += 1 | |
760 | if nextDay: |
|
761 | if nextDay: | |
@@ -766,7 +767,7 class JRODataReader(Reader): | |||||
766 | prefixFileList = ['d', 'D'] |
|
767 | prefixFileList = ['d', 'D'] | |
767 | elif self.ext.lower() == ".pdata": # spectra |
|
768 | elif self.ext.lower() == ".pdata": # spectra | |
768 | prefixFileList = ['p', 'P'] |
|
769 | prefixFileList = ['p', 'P'] | |
769 |
|
770 | |||
770 | # barrido por las combinaciones posibles |
|
771 | # barrido por las combinaciones posibles | |
771 | for prefixDir in prefixDirList: |
|
772 | for prefixDir in prefixDirList: | |
772 | thispath = self.path |
|
773 | thispath = self.path | |
@@ -786,9 +787,9 class JRODataReader(Reader): | |||||
786 |
|
787 | |||
787 | if os.path.exists(fullfilename): |
|
788 | if os.path.exists(fullfilename): | |
788 | return fullfilename, filename |
|
789 | return fullfilename, filename | |
789 |
|
790 | |||
790 |
return None, filename |
|
791 | return None, filename | |
791 |
|
792 | |||
792 | def __waitNewBlock(self): |
|
793 | def __waitNewBlock(self): | |
793 | """ |
|
794 | """ | |
794 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
795 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
@@ -857,9 +858,11 class JRODataReader(Reader): | |||||
857 | def __setNewBlock(self): |
|
858 | def __setNewBlock(self): | |
858 |
|
859 | |||
859 | if self.fp == None: |
|
860 | if self.fp == None: | |
860 |
return 0 |
|
861 | return 0 | |
861 |
|
862 | |||
862 | if self.flagIsNewFile: |
|
863 | #print("DIME COMO ARRANCA",self.flagIsNewFile) | |
|
864 | #print("DIME COMO VA",self.nReadBlocks) | |||
|
865 | if self.flagIsNewFile: | |||
863 | self.lastUTTime = self.basicHeaderObj.utc |
|
866 | self.lastUTTime = self.basicHeaderObj.utc | |
864 | return 1 |
|
867 | return 1 | |
865 |
|
868 | |||
@@ -872,12 +875,12 class JRODataReader(Reader): | |||||
872 |
|
875 | |||
873 | currentSize = self.fileSize - self.fp.tell() |
|
876 | currentSize = self.fileSize - self.fp.tell() | |
874 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
877 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
875 |
|
878 | |||
876 | if (currentSize >= neededSize): |
|
879 | if (currentSize >= neededSize): | |
877 | self.basicHeaderObj.read(self.fp) |
|
880 | self.basicHeaderObj.read(self.fp) | |
878 | self.lastUTTime = self.basicHeaderObj.utc |
|
881 | self.lastUTTime = self.basicHeaderObj.utc | |
879 | return 1 |
|
882 | return 1 | |
880 |
|
883 | |||
881 | if self.__waitNewBlock(): |
|
884 | if self.__waitNewBlock(): | |
882 | self.lastUTTime = self.basicHeaderObj.utc |
|
885 | self.lastUTTime = self.basicHeaderObj.utc | |
883 | return 1 |
|
886 | return 1 | |
@@ -896,6 +899,7 class JRODataReader(Reader): | |||||
896 | return 1 |
|
899 | return 1 | |
897 |
|
900 | |||
898 | def readNextBlock(self): |
|
901 | def readNextBlock(self): | |
|
902 | #print("nReadBlocks",self.nReadBlocks) | |||
899 |
|
903 | |||
900 | while True: |
|
904 | while True: | |
901 | self.__setNewBlock() |
|
905 | self.__setNewBlock() | |
@@ -917,6 +921,7 class JRODataReader(Reader): | |||||
917 | print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks, |
|
921 | print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks, | |
918 | self.processingHeaderObj.dataBlocksPerFile, |
|
922 | self.processingHeaderObj.dataBlocksPerFile, | |
919 | self.dataOut.datatime.ctime())) |
|
923 | self.dataOut.datatime.ctime())) | |
|
924 | ||||
920 | return 1 |
|
925 | return 1 | |
921 |
|
926 | |||
922 | def readFirstHeader(self): |
|
927 | def readFirstHeader(self): | |
@@ -965,7 +970,7 class JRODataReader(Reader): | |||||
965 | print("[Reading] File %s can't be opened" % (filename)) |
|
970 | print("[Reading] File %s can't be opened" % (filename)) | |
966 |
|
971 | |||
967 | return False |
|
972 | return False | |
968 |
|
973 | |||
969 | if self.waitDataBlock(0): |
|
974 | if self.waitDataBlock(0): | |
970 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
975 | basicHeaderObj = BasicHeader(LOCALTIME) | |
971 | systemHeaderObj = SystemHeader() |
|
976 | systemHeaderObj = SystemHeader() | |
@@ -986,10 +991,10 class JRODataReader(Reader): | |||||
986 |
|
991 | |||
987 | if not(processingHeaderObj.read(fp)): |
|
992 | if not(processingHeaderObj.read(fp)): | |
988 | fp.close() |
|
993 | fp.close() | |
989 |
return False |
|
994 | return False | |
990 |
|
995 | |||
991 | if not self.online: |
|
996 | if not self.online: | |
992 |
dt1 = basicHeaderObj.datatime |
|
997 | dt1 = basicHeaderObj.datatime | |
993 | fp.seek(self.fileSize-processingHeaderObj.blockSize-24) |
|
998 | fp.seek(self.fileSize-processingHeaderObj.blockSize-24) | |
994 | if not(basicHeaderObj.read(fp)): |
|
999 | if not(basicHeaderObj.read(fp)): | |
995 | fp.close() |
|
1000 | fp.close() | |
@@ -997,10 +1002,10 class JRODataReader(Reader): | |||||
997 | dt2 = basicHeaderObj.datatime |
|
1002 | dt2 = basicHeaderObj.datatime | |
998 | if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \ |
|
1003 | if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \ | |
999 | self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime): |
|
1004 | self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime): | |
1000 |
return False |
|
1005 | return False | |
1001 |
|
1006 | |||
1002 | fp.close() |
|
1007 | fp.close() | |
1003 |
|
1008 | |||
1004 | return True |
|
1009 | return True | |
1005 |
|
1010 | |||
1006 | def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False): |
|
1011 | def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False): | |
@@ -1107,11 +1112,11 class JRODataReader(Reader): | |||||
1107 | return dateList |
|
1112 | return dateList | |
1108 |
|
1113 | |||
1109 | def setup(self, **kwargs): |
|
1114 | def setup(self, **kwargs): | |
1110 |
|
1115 | |||
1111 | self.set_kwargs(**kwargs) |
|
1116 | self.set_kwargs(**kwargs) | |
1112 | if not self.ext.startswith('.'): |
|
1117 | if not self.ext.startswith('.'): | |
1113 | self.ext = '.{}'.format(self.ext) |
|
1118 | self.ext = '.{}'.format(self.ext) | |
1114 |
|
1119 | |||
1115 | if self.server is not None: |
|
1120 | if self.server is not None: | |
1116 | if 'tcp://' in self.server: |
|
1121 | if 'tcp://' in self.server: | |
1117 | address = server |
|
1122 | address = server | |
@@ -1133,44 +1138,51 class JRODataReader(Reader): | |||||
1133 |
|
1138 | |||
1134 | for nTries in range(self.nTries): |
|
1139 | for nTries in range(self.nTries): | |
1135 | fullpath = self.searchFilesOnLine(self.path, self.startDate, |
|
1140 | fullpath = self.searchFilesOnLine(self.path, self.startDate, | |
1136 |
self.endDate, self.expLabel, self.ext, self.walk, |
|
1141 | self.endDate, self.expLabel, self.ext, self.walk, | |
1137 | self.filefmt, self.folderfmt) |
|
1142 | self.filefmt, self.folderfmt) | |
1138 |
|
1143 | |||
1139 | try: |
|
1144 | try: | |
1140 | fullpath = next(fullpath) |
|
1145 | fullpath = next(fullpath) | |
1141 | except: |
|
1146 | except: | |
1142 | fullpath = None |
|
1147 | fullpath = None | |
1143 |
|
1148 | |||
1144 | if fullpath: |
|
1149 | if fullpath: | |
1145 | break |
|
1150 | break | |
1146 |
|
1151 | |||
1147 | log.warning( |
|
1152 | log.warning( | |
1148 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( |
|
1153 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( | |
1149 |
self.delay, self.path, nTries + 1), |
|
1154 | self.delay, self.path, nTries + 1), | |
1150 | self.name) |
|
1155 | self.name) | |
1151 | time.sleep(self.delay) |
|
1156 | time.sleep(self.delay) | |
1152 |
|
1157 | |||
1153 | if not(fullpath): |
|
1158 | if not(fullpath): | |
1154 | raise schainpy.admin.SchainError( |
|
1159 | raise schainpy.admin.SchainError( | |
1155 |
'There isn\'t any valid file in {}'.format(self.path)) |
|
1160 | 'There isn\'t any valid file in {}'.format(self.path)) | |
1156 |
|
1161 | |||
1157 | pathname, filename = os.path.split(fullpath) |
|
1162 | pathname, filename = os.path.split(fullpath) | |
1158 | self.year = int(filename[1:5]) |
|
1163 | self.year = int(filename[1:5]) | |
1159 | self.doy = int(filename[5:8]) |
|
1164 | self.doy = int(filename[5:8]) | |
1160 |
self.set = int(filename[8:11]) - 1 |
|
1165 | self.set = int(filename[8:11]) - 1 | |
1161 | else: |
|
1166 | else: | |
1162 | log.log("Searching files in {}".format(self.path), self.name) |
|
1167 | log.log("Searching files in {}".format(self.path), self.name) | |
1163 |
self.filenameList = self.searchFilesOffLine(self.path, self.startDate, |
|
1168 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, | |
1164 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) |
|
1169 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) | |
1165 |
|
1170 | |||
1166 | self.setNextFile() |
|
1171 | self.setNextFile() | |
1167 |
|
1172 | |||
1168 | return |
|
1173 | return | |
1169 |
|
1174 | |||
1170 | def getBasicHeader(self): |
|
1175 | def getBasicHeader(self): | |
1171 |
|
1176 | ''' | ||
|
1177 | print("1",self.radarControllerHeaderObj.ippSeconds) | |||
|
1178 | print("2",self.profileIndex) | |||
|
1179 | print("3",self.basicHeaderObj.miliSecond) | |||
|
1180 | print("4",self.basicHeaderObj.utc) | |||
|
1181 | print("5",self.nTxs) | |||
|
1182 | ''' | |||
1172 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ |
|
1183 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ | |
1173 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds |
|
1184 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds | |
|
1185 | #print(self.profileIndex,self.dataOut.utctime) | |||
1174 |
|
1186 | |||
1175 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
1187 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
1176 |
|
1188 | |||
@@ -1238,8 +1250,8 class JRODataReader(Reader): | |||||
1238 | """ |
|
1250 | """ | |
1239 |
|
1251 | |||
1240 | Arguments: |
|
1252 | Arguments: | |
1241 |
path : |
|
1253 | path : | |
1242 |
startDate : |
|
1254 | startDate : | |
1243 | endDate : |
|
1255 | endDate : | |
1244 | startTime : |
|
1256 | startTime : | |
1245 | endTime : |
|
1257 | endTime : | |
@@ -1308,7 +1320,7 class JRODataWriter(Reader): | |||||
1308 | dtype_width = get_dtype_width(dtype_index) |
|
1320 | dtype_width = get_dtype_width(dtype_index) | |
1309 |
|
1321 | |||
1310 | return dtype_width |
|
1322 | return dtype_width | |
1311 |
|
1323 | |||
1312 | def getProcessFlags(self): |
|
1324 | def getProcessFlags(self): | |
1313 |
|
1325 | |||
1314 | processFlags = 0 |
|
1326 | processFlags = 0 | |
@@ -1346,9 +1358,9 class JRODataWriter(Reader): | |||||
1346 |
|
1358 | |||
1347 | self.basicHeaderObj.size = self.basicHeaderSize # bytes |
|
1359 | self.basicHeaderObj.size = self.basicHeaderSize # bytes | |
1348 | self.basicHeaderObj.version = self.versionFile |
|
1360 | self.basicHeaderObj.version = self.versionFile | |
1349 |
self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1361 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
1350 | utc = numpy.floor(self.dataOut.utctime) |
|
1362 | utc = numpy.floor(self.dataOut.utctime) | |
1351 |
milisecond = (self.dataOut.utctime - utc) * 1000.0 |
|
1363 | milisecond = (self.dataOut.utctime - utc) * 1000.0 | |
1352 | self.basicHeaderObj.utc = utc |
|
1364 | self.basicHeaderObj.utc = utc | |
1353 | self.basicHeaderObj.miliSecond = milisecond |
|
1365 | self.basicHeaderObj.miliSecond = milisecond | |
1354 | self.basicHeaderObj.timeZone = self.dataOut.timeZone |
|
1366 | self.basicHeaderObj.timeZone = self.dataOut.timeZone | |
@@ -1435,7 +1447,7 class JRODataWriter(Reader): | |||||
1435 |
|
1447 | |||
1436 | return 1 |
|
1448 | return 1 | |
1437 |
|
1449 | |||
1438 | def setNextFile(self): |
|
1450 | def setNewxtFile(self): | |
1439 | """Determina el siguiente file que sera escrito |
|
1451 | """Determina el siguiente file que sera escrito | |
1440 |
|
1452 | |||
1441 | Affected: |
|
1453 | Affected: | |
@@ -1489,9 +1501,9 class JRODataWriter(Reader): | |||||
1489 | if self.dataOut.datatime.date() > self.fileDate: |
|
1501 | if self.dataOut.datatime.date() > self.fileDate: | |
1490 | setFile = 0 |
|
1502 | setFile = 0 | |
1491 | self.nTotalBlocks = 0 |
|
1503 | self.nTotalBlocks = 0 | |
1492 |
|
1504 | |||
1493 | filen = '{}{:04d}{:03d}{:03d}{}'.format( |
|
1505 | filen = '{}{:04d}{:03d}{:03d}{}'.format( | |
1494 |
self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext) |
|
1506 | self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext) | |
1495 |
|
1507 | |||
1496 | filename = os.path.join(path, subfolder, filen) |
|
1508 | filename = os.path.join(path, subfolder, filen) | |
1497 |
|
1509 | |||
@@ -1539,11 +1551,11 class JRODataWriter(Reader): | |||||
1539 | self.ext = ext.lower() |
|
1551 | self.ext = ext.lower() | |
1540 |
|
1552 | |||
1541 | self.path = path |
|
1553 | self.path = path | |
1542 |
|
1554 | |||
1543 | if set is None: |
|
1555 | if set is None: | |
1544 | self.setFile = -1 |
|
1556 | self.setFile = -1 | |
1545 | else: |
|
1557 | else: | |
1546 |
self.setFile = set - 1 |
|
1558 | self.setFile = set - 1 | |
1547 |
|
1559 | |||
1548 | self.blocksPerFile = blocksPerFile |
|
1560 | self.blocksPerFile = blocksPerFile | |
1549 | self.profilesPerBlock = profilesPerBlock |
|
1561 | self.profilesPerBlock = profilesPerBlock |
@@ -65,7 +65,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
65 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
65 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
66 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
66 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
67 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
67 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
68 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
68 | si el buffer esta vacio se hara un nuevo proceso de lectura de unX | |
69 | bloque de datos. |
|
69 | bloque de datos. | |
70 | Si este parametro no es pasado se creara uno internamente. |
|
70 | Si este parametro no es pasado se creara uno internamente. | |
71 |
|
71 | |||
@@ -285,7 +285,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
285 | self.flagDiscontinuousBlock = 0 |
|
285 | self.flagDiscontinuousBlock = 0 | |
286 | self.profileIndex = 0 |
|
286 | self.profileIndex = 0 | |
287 | self.flagIsNewBlock = 1 |
|
287 | self.flagIsNewBlock = 1 | |
288 |
self.dataOut.flagNo |
|
288 | self.dataOut.flagNoata = False | |
289 | self.nTotalBlocks += 1 |
|
289 | self.nTotalBlocks += 1 | |
290 | self.nReadBlocks += 1 |
|
290 | self.nReadBlocks += 1 | |
291 | self.blockPointer = 0 |
|
291 | self.blockPointer = 0 | |
@@ -677,4 +677,4 class VoltageWriter(JRODataWriter, Operation): | |||||
677 | self.processingHeaderObj.processFlags = self.getProcessFlags() |
|
677 | self.processingHeaderObj.processFlags = self.getProcessFlags() | |
678 |
|
678 | |||
679 | self.setBasicHeader() |
|
679 | self.setBasicHeader() | |
680 | No newline at end of file |
|
680 |
General Comments 0
You need to be logged in to leave comments.
Login now