##// END OF EJS Templates
cometando linea doce libreria scipy
sebastianVP -
r1744:7a5d7fe4c2a6
parent child
Show More
@@ -1,800 +1,800
1 1 import os
2 2 import sys
3 3 import glob
4 4 import fnmatch
5 5 import datetime
6 6 import time
7 7 import re
8 8 import h5py
9 9 import numpy
10 10
11 11 from scipy.optimize import curve_fit
12 from scipy import asarray as ar, exp
12 #from scipy import asarray as ar, exp
13 13 from scipy import stats
14 14
15 15 from numpy.ma.core import getdata
16 16
17 17 SPEED_OF_LIGHT = 299792458
18 18 SPEED_OF_LIGHT = 3e8
19 19
20 20 try:
21 21 from gevent import sleep
22 22 except:
23 23 from time import sleep
24 24
25 25 from schainpy.model.data.jrodata import Spectra
26 26 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
27 27 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 28 #from schainpy.model.io.jroIO_bltr import BLTRReader
29 29 from numpy import imag, shape, NaN, empty
30 30
31 31
32 32 class Header(object):
33 33
34 34 def __init__(self):
35 35 raise NotImplementedError
36 36
37 37 def read(self):
38 38
39 39 raise NotImplementedError
40 40
41 41 def write(self):
42 42
43 43 raise NotImplementedError
44 44
45 45 def printInfo(self):
46 46
47 47 message = "#" * 50 + "\n"
48 48 message += self.__class__.__name__.upper() + "\n"
49 49 message += "#" * 50 + "\n"
50 50
51 51 keyList = list(self.__dict__.keys())
52 52 keyList.sort()
53 53
54 54 for key in keyList:
55 55 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
56 56
57 57 if "size" not in keyList:
58 58 attr = getattr(self, "size")
59 59
60 60 if attr:
61 61 message += "%s = %s" % ("size", attr) + "\n"
62 62
63 63 # print message
64 64
65 65
66 66 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
67 67 ('Hname', 'a32'), # Original file name
68 68 # Date and time when the file was created
69 69 ('Htime', numpy.str_, 32),
70 70 # Name of operator who created the file
71 71 ('Hoper', numpy.str_, 64),
72 72 # Place where the measurements was carried out
73 73 ('Hplace', numpy.str_, 128),
74 74 # Description of measurements
75 75 ('Hdescr', numpy.str_, 256),
76 76 ('Hdummy', numpy.str_, 512), # Reserved space
77 77 # Main chunk 8bytes
78 78 # Main chunk signature FZKF or NUIG
79 79 ('Msign', numpy.str_, 4),
80 80 ('MsizeData', '<i4'), # Size of data block main chunk
81 81 # Processing DSP parameters 36bytes
82 82 ('PPARsign', numpy.str_, 4), # PPAR signature
83 83 ('PPARsize', '<i4'), # PPAR size of block
84 84 ('PPARprf', '<i4'), # Pulse repetition frequency
85 85 ('PPARpdr', '<i4'), # Pulse duration
86 86 ('PPARsft', '<i4'), # FFT length
87 87 # Number of spectral (in-coherent) averages
88 88 ('PPARavc', '<i4'),
89 89 # Number of lowest range gate for moment estimation
90 90 ('PPARihp', '<i4'),
91 91 # Count for gates for moment estimation
92 92 ('PPARchg', '<i4'),
93 93 # switch on/off polarimetric measurements. Should be 1.
94 94 ('PPARpol', '<i4'),
95 95 # Service DSP parameters 112bytes
96 96 # STC attenuation on the lowest ranges on/off
97 97 ('SPARatt', '<i4'),
98 98 ('SPARtx', '<i4'), # OBSOLETE
99 99 ('SPARaddGain0', '<f4'), # OBSOLETE
100 100 ('SPARaddGain1', '<f4'), # OBSOLETE
101 101 # Debug only. It normal mode it is 0.
102 102 ('SPARwnd', '<i4'),
103 103 # Delay between sync pulse and tx pulse for phase corr, ns
104 104 ('SPARpos', '<i4'),
105 105 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
106 106 ('SPARadd', '<i4'),
107 107 # Time for measuring txn pulse phase. OBSOLETE
108 108 ('SPARlen', '<i4'),
109 109 ('SPARcal', '<i4'), # OBSOLETE
110 110 ('SPARnos', '<i4'), # OBSOLETE
111 111 ('SPARof0', '<i4'), # detection threshold
112 112 ('SPARof1', '<i4'), # OBSOLETE
113 113 ('SPARswt', '<i4'), # 2nd moment estimation threshold
114 114 ('SPARsum', '<i4'), # OBSOLETE
115 115 ('SPARosc', '<i4'), # flag Oscillosgram mode
116 116 ('SPARtst', '<i4'), # OBSOLETE
117 117 ('SPARcor', '<i4'), # OBSOLETE
118 118 ('SPARofs', '<i4'), # OBSOLETE
119 119 # Hildebrand div noise detection on noise gate
120 120 ('SPARhsn', '<i4'),
121 121 # Hildebrand div noise detection on all gates
122 122 ('SPARhsa', '<f4'),
123 123 ('SPARcalibPow_M', '<f4'), # OBSOLETE
124 124 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
125 125 ('SPARcalibPow_S', '<f4'), # OBSOLETE
126 126 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
127 127 # Lowest range gate for spectra saving Raw_Gate1 >=5
128 128 ('SPARrawGate1', '<i4'),
129 129 # Number of range gates with atmospheric signal
130 130 ('SPARrawGate2', '<i4'),
131 131 # flag - IQ or spectra saving on/off
132 132 ('SPARraw', '<i4'),
133 133 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
134 134
135 135
136 136 class FileHeaderMIRA35c(Header):
137 137
138 138 def __init__(self):
139 139
140 140 self.Hname = None
141 141 self.Htime = None
142 142 self.Hoper = None
143 143 self.Hplace = None
144 144 self.Hdescr = None
145 145 self.Hdummy = None
146 146
147 147 self.Msign = None
148 148 self.MsizeData = None
149 149
150 150 self.PPARsign = None
151 151 self.PPARsize = None
152 152 self.PPARprf = None
153 153 self.PPARpdr = None
154 154 self.PPARsft = None
155 155 self.PPARavc = None
156 156 self.PPARihp = None
157 157 self.PPARchg = None
158 158 self.PPARpol = None
159 159 # Service DSP parameters
160 160 self.SPARatt = None
161 161 self.SPARtx = None
162 162 self.SPARaddGain0 = None
163 163 self.SPARaddGain1 = None
164 164 self.SPARwnd = None
165 165 self.SPARpos = None
166 166 self.SPARadd = None
167 167 self.SPARlen = None
168 168 self.SPARcal = None
169 169 self.SPARnos = None
170 170 self.SPARof0 = None
171 171 self.SPARof1 = None
172 172 self.SPARswt = None
173 173 self.SPARsum = None
174 174 self.SPARosc = None
175 175 self.SPARtst = None
176 176 self.SPARcor = None
177 177 self.SPARofs = None
178 178 self.SPARhsn = None
179 179 self.SPARhsa = None
180 180 self.SPARcalibPow_M = None
181 181 self.SPARcalibSNR_M = None
182 182 self.SPARcalibPow_S = None
183 183 self.SPARcalibSNR_S = None
184 184 self.SPARrawGate1 = None
185 185 self.SPARrawGate2 = None
186 186 self.SPARraw = None
187 187 self.SPARprc = None
188 188
189 189 self.FHsize = 1180
190 190
191 191 def FHread(self, fp):
192 192
193 193 header = numpy.fromfile(fp, FILE_HEADER, 1)
194 194 ''' numpy.fromfile(file, dtype, count, sep='')
195 195 file : file or str
196 196 Open file object or filename.
197 197
198 198 dtype : data-type
199 199 Data type of the returned array. For binary files, it is used to determine
200 200 the size and byte-order of the items in the file.
201 201
202 202 count : int
203 203 Number of items to read. -1 means all items (i.e., the complete file).
204 204
205 205 sep : str
206 206 Separator between items if file is a text file. Empty ("") separator means
207 207 the file should be treated as binary. Spaces (" ") in the separator match zero
208 208 or more whitespace characters. A separator consisting only of spaces must match
209 209 at least one whitespace.
210 210
211 211 '''
212 212
213 213 self.Hname = str(header['Hname'][0])
214 214 self.Htime = str(header['Htime'][0])
215 215 self.Hoper = str(header['Hoper'][0])
216 216 self.Hplace = str(header['Hplace'][0])
217 217 self.Hdescr = str(header['Hdescr'][0])
218 218 self.Hdummy = str(header['Hdummy'][0])
219 219 # 1024
220 220
221 221 self.Msign = str(header['Msign'][0])
222 222 self.MsizeData = header['MsizeData'][0]
223 223 # 8
224 224
225 225 self.PPARsign = str(header['PPARsign'][0])
226 226 self.PPARsize = header['PPARsize'][0]
227 227 self.PPARprf = header['PPARprf'][0]
228 228 self.PPARpdr = header['PPARpdr'][0]
229 229 self.PPARsft = header['PPARsft'][0]
230 230 self.PPARavc = header['PPARavc'][0]
231 231 self.PPARihp = header['PPARihp'][0]
232 232 self.PPARchg = header['PPARchg'][0]
233 233 self.PPARpol = header['PPARpol'][0]
234 234 # Service DSP parameters
235 235 # 36
236 236
237 237 self.SPARatt = header['SPARatt'][0]
238 238 self.SPARtx = header['SPARtx'][0]
239 239 self.SPARaddGain0 = header['SPARaddGain0'][0]
240 240 self.SPARaddGain1 = header['SPARaddGain1'][0]
241 241 self.SPARwnd = header['SPARwnd'][0]
242 242 self.SPARpos = header['SPARpos'][0]
243 243 self.SPARadd = header['SPARadd'][0]
244 244 self.SPARlen = header['SPARlen'][0]
245 245 self.SPARcal = header['SPARcal'][0]
246 246 self.SPARnos = header['SPARnos'][0]
247 247 self.SPARof0 = header['SPARof0'][0]
248 248 self.SPARof1 = header['SPARof1'][0]
249 249 self.SPARswt = header['SPARswt'][0]
250 250 self.SPARsum = header['SPARsum'][0]
251 251 self.SPARosc = header['SPARosc'][0]
252 252 self.SPARtst = header['SPARtst'][0]
253 253 self.SPARcor = header['SPARcor'][0]
254 254 self.SPARofs = header['SPARofs'][0]
255 255 self.SPARhsn = header['SPARhsn'][0]
256 256 self.SPARhsa = header['SPARhsa'][0]
257 257 self.SPARcalibPow_M = header['SPARcalibPow_M'][0]
258 258 self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
259 259 self.SPARcalibPow_S = header['SPARcalibPow_S'][0]
260 260 self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
261 261 self.SPARrawGate1 = header['SPARrawGate1'][0]
262 262 self.SPARrawGate2 = header['SPARrawGate2'][0]
263 263 self.SPARraw = header['SPARraw'][0]
264 264 self.SPARprc = header['SPARprc'][0]
265 265 # 112
266 266 # 1180
267 267 # print 'Pointer fp header', fp.tell()
268 268 # print ' '
269 269 # print 'SPARrawGate'
270 270 # print self.SPARrawGate2 - self.SPARrawGate1
271 271
272 272 # print ' '
273 273 # print 'Hname'
274 274 # print self.Hname
275 275
276 276 # print ' '
277 277 # print 'Msign'
278 278 # print self.Msign
279 279
280 280 def write(self, fp):
281 281
282 282 headerTuple = (self.Hname,
283 283 self.Htime,
284 284 self.Hoper,
285 285 self.Hplace,
286 286 self.Hdescr,
287 287 self.Hdummy)
288 288
289 289 header = numpy.array(headerTuple, FILE_HEADER)
290 290 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
291 291 header.tofile(fp)
292 292 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
293 293
294 294 fid : file or str
295 295 An open file object, or a string containing a filename.
296 296
297 297 sep : str
298 298 Separator between array items for text output. If "" (empty), a binary file is written,
299 299 equivalent to file.write(a.tobytes()).
300 300
301 301 format : str
302 302 Format string for text file output. Each entry in the array is formatted to text by
303 303 first converting it to the closest Python type, and then using "format" % item.
304 304
305 305 '''
306 306
307 307 return 1
308 308
309 309
310 310 SRVI_HEADER = numpy.dtype([
311 311 ('SignatureSRVI1', numpy.str_, 4),
312 312 ('SizeOfDataBlock1', '<i4'),
313 313 ('DataBlockTitleSRVI1', numpy.str_, 4),
314 314 ('SizeOfSRVI1', '<i4'), ])
315 315
316 316
317 317 class SRVIHeader(Header):
318 318 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
319 319
320 320 self.SignatureSRVI1 = SignatureSRVI1
321 321 self.SizeOfDataBlock1 = SizeOfDataBlock1
322 322 self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1
323 323 self.SizeOfSRVI1 = SizeOfSRVI1
324 324
325 325 self.SRVIHsize = 16
326 326
327 327 def SRVIread(self, fp):
328 328
329 329 header = numpy.fromfile(fp, SRVI_HEADER, 1)
330 330
331 331 self.SignatureSRVI1 = str(header['SignatureSRVI1'][0])
332 332 self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0]
333 333 self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0])
334 334 self.SizeOfSRVI1 = header['SizeOfSRVI1'][0]
335 335 # 16
336 336 print('Pointer fp SRVIheader', fp.tell())
337 337
338 338
339 339 SRVI_STRUCTURE = numpy.dtype([
340 340 ('frame_cnt', '<u4'),
341 341 ('time_t', '<u4'), #
342 342 ('tpow', '<f4'), #
343 343 ('npw1', '<f4'), #
344 344 ('npw2', '<f4'), #
345 345 ('cpw1', '<f4'), #
346 346 ('pcw2', '<f4'), #
347 347 ('ps_err', '<u4'), #
348 348 ('te_err', '<u4'), #
349 349 ('rc_err', '<u4'), #
350 350 ('grs1', '<u4'), #
351 351 ('grs2', '<u4'), #
352 352 ('azipos', '<f4'), #
353 353 ('azivel', '<f4'), #
354 354 ('elvpos', '<f4'), #
355 355 ('elvvel', '<f4'), #
356 356 ('northAngle', '<f4'),
357 357 ('microsec', '<u4'), #
358 358 ('azisetvel', '<f4'), #
359 359 ('elvsetpos', '<f4'), #
360 360 ('RadarConst', '<f4'), ]) #
361 361
362 362
363 363 class RecordHeader(Header):
364 364
365 365 def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0,
366 366 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
367 367 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
368 368 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0):
369 369
370 370 self.frame_cnt = frame_cnt
371 371 self.dwell = time_t
372 372 self.tpow = tpow
373 373 self.npw1 = npw1
374 374 self.npw2 = npw2
375 375 self.cpw1 = cpw1
376 376 self.pcw2 = pcw2
377 377 self.ps_err = ps_err
378 378 self.te_err = te_err
379 379 self.rc_err = rc_err
380 380 self.grs1 = grs1
381 381 self.grs2 = grs2
382 382 self.azipos = azipos
383 383 self.azivel = azivel
384 384 self.elvpos = elvpos
385 385 self.elvvel = elvvel
386 386 self.northAngle = northangle
387 387 self.microsec = microsec
388 388 self.azisetvel = azisetvel
389 389 self.elvsetpos = elvsetpos
390 390 self.RadarConst = RadarConst
391 391 self.RHsize = 84
392 392 self.RecCounter = RecCounter
393 393 self.Off2StartNxtRec = Off2StartNxtRec
394 394
395 395 def RHread(self, fp):
396 396
397 397 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
398 398
399 399 #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec)
400 400 #startFp.seek(OffRHeader, os.SEEK_SET)
401 401
402 402 # print 'Posicion del bloque: ',OffRHeader
403 403
404 404 header = numpy.fromfile(fp, SRVI_STRUCTURE, 1)
405 405
406 406 self.frame_cnt = header['frame_cnt'][0]
407 407 self.time_t = header['time_t'][0] #
408 408 self.tpow = header['tpow'][0] #
409 409 self.npw1 = header['npw1'][0] #
410 410 self.npw2 = header['npw2'][0] #
411 411 self.cpw1 = header['cpw1'][0] #
412 412 self.pcw2 = header['pcw2'][0] #
413 413 self.ps_err = header['ps_err'][0] #
414 414 self.te_err = header['te_err'][0] #
415 415 self.rc_err = header['rc_err'][0] #
416 416 self.grs1 = header['grs1'][0] #
417 417 self.grs2 = header['grs2'][0] #
418 418 self.azipos = header['azipos'][0] #
419 419 self.azivel = header['azivel'][0] #
420 420 self.elvpos = header['elvpos'][0] #
421 421 self.elvvel = header['elvvel'][0] #
422 422 self.northAngle = header['northAngle'][0] #
423 423 self.microsec = header['microsec'][0] #
424 424 self.azisetvel = header['azisetvel'][0] #
425 425 self.elvsetpos = header['elvsetpos'][0] #
426 426 self.RadarConst = header['RadarConst'][0] #
427 427 # 84
428 428
429 429 # print 'Pointer fp RECheader', fp.tell()
430 430
431 431 #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
432 432
433 433 #self.RHsize = 180+20*self.nChannels
434 434 #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
435 435 # print 'Datasize',self.Datasize
436 436 #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
437 437
438 438 print('==============================================')
439 439
440 440 print('==============================================')
441 441
442 442 return 1
443 443
444 444
445 445 class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader):
446 446
447 447 path = None
448 448 startDate = None
449 449 endDate = None
450 450 startTime = None
451 451 endTime = None
452 452 walk = None
453 453 isConfig = False
454 454
455 455 fileList = None
456 456
457 457 # metadata
458 458 TimeZone = None
459 459 Interval = None
460 460 heightList = None
461 461
462 462 # data
463 463 data = None
464 464 utctime = None
465 465
466 466 def __init__(self, **kwargs):
467 467
468 468 # Eliminar de la base la herencia
469 469 ProcessingUnit.__init__(self, **kwargs)
470 470 self.PointerReader = 0
471 471 self.FileHeaderFlag = False
472 472 self.utc = None
473 473 self.ext = ".zspca"
474 474 self.optchar = "P"
475 475 self.fpFile = None
476 476 self.fp = None
477 477 self.BlockCounter = 0
478 478 self.dtype = None
479 479 self.fileSizeByHeader = None
480 480 self.filenameList = []
481 481 self.fileSelector = 0
482 482 self.Off2StartNxtRec = 0
483 483 self.RecCounter = 0
484 484 self.flagNoMoreFiles = 0
485 485 self.data_spc = None
486 486 # self.data_cspc=None
487 487 self.data_output = None
488 488 self.path = None
489 489 self.OffsetStartHeader = 0
490 490 self.Off2StartData = 0
491 491 self.ipp = 0
492 492 self.nFDTdataRecors = 0
493 493 self.blocksize = 0
494 494 self.dataOut = Spectra()
495 495 self.profileIndex = 1 # Always
496 496 self.dataOut.flagNoData = False
497 497 self.dataOut.nRdPairs = 0
498 498 self.dataOut.data_spc = None
499 499 self.nextfileflag = True
500 500 self.dataOut.RadarConst = 0
501 501 self.dataOut.HSDV = []
502 502 self.dataOut.NPW = []
503 503 self.dataOut.COFA = []
504 504 # self.dataOut.noise = 0
505 505
506 506 def Files2Read(self, fp):
507 507 '''
508 508 Function that indicates the number of .fdt files that exist in the folder to be read.
509 509 It also creates an organized list with the names of the files to read.
510 510 '''
511 511 # self.__checkPath()
512 512
513 513 # Gets the list of files within the fp address
514 514 ListaData = os.listdir(fp)
515 515 # Sort the list of files from least to largest by names
516 516 ListaData = sorted(ListaData)
517 517 nFiles = 0 # File Counter
518 518 FileList = [] # A list is created that will contain the .fdt files
519 519 for IndexFile in ListaData:
520 520 if '.zspca' in IndexFile and '.gz' not in IndexFile:
521 521 FileList.append(IndexFile)
522 522 nFiles += 1
523 523
524 524 # print 'Files2Read'
525 525 # print 'Existen '+str(nFiles)+' archivos .fdt'
526 526
527 527 self.filenameList = FileList # List of files from least to largest by names
528 528
529 529 def run(self, **kwargs):
530 530 '''
531 531 This method will be the one that will initiate the data entry, will be called constantly.
532 532 You should first verify that your Setup () is set up and then continue to acquire
533 533 the data to be processed with getData ().
534 534 '''
535 535 if not self.isConfig:
536 536 self.setup(**kwargs)
537 537 self.isConfig = True
538 538
539 539 self.getData()
540 540
541 541 def setup(self, path=None,
542 542 startDate=None,
543 543 endDate=None,
544 544 startTime=None,
545 545 endTime=None,
546 546 walk=True,
547 547 timezone='utc',
548 548 code=None,
549 549 online=False,
550 550 ReadMode=None, **kwargs):
551 551
552 552 self.isConfig = True
553 553
554 554 self.path = path
555 555 self.startDate = startDate
556 556 self.endDate = endDate
557 557 self.startTime = startTime
558 558 self.endTime = endTime
559 559 self.walk = walk
560 560 # self.ReadMode=int(ReadMode)
561 561
562 562 pass
563 563
564 564 def getData(self):
565 565 '''
566 566 Before starting this function, you should check that there is still an unread file,
567 567 If there are still blocks to read or if the data block is empty.
568 568
569 569 You should call the file "read".
570 570
571 571 '''
572 572
573 573 if self.flagNoMoreFiles:
574 574 self.dataOut.flagNoData = True
575 575 print('NoData se vuelve true')
576 576 return 0
577 577
578 578 self.fp = self.path
579 579 self.Files2Read(self.fp)
580 580 self.readFile(self.fp)
581 581
582 582 self.dataOut.data_spc = self.dataOut_spc # self.data_spc.copy()
583 583 self.dataOut.RadarConst = self.RadarConst
584 584 self.dataOut.data_output = self.data_output
585 585 self.dataOut.noise = self.dataOut.getNoise()
586 586 # print 'ACAAAAAA', self.dataOut.noise
587 587 self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise
588 588 self.dataOut.normFactor = 1
589 589 # print 'self.dataOut.noise',self.dataOut.noise
590 590
591 591 return self.dataOut.data_spc
592 592
593 593 def readFile(self, fp):
594 594 '''
595 595 You must indicate if you are reading in Online or Offline mode and load the
596 596 The parameters for this file reading mode.
597 597
598 598 Then you must do 2 actions:
599 599
600 600 1. Get the BLTR FileHeader.
601 601 2. Start reading the first block.
602 602 '''
603 603
604 604 # The address of the folder is generated the name of the .fdt file that will be read
605 605 print("File: ", self.fileSelector + 1)
606 606
607 607 if self.fileSelector < len(self.filenameList):
608 608
609 609 self.fpFile = str(fp) + '/' + \
610 610 str(self.filenameList[self.fileSelector])
611 611
612 612 if self.nextfileflag == True:
613 613 self.fp = open(self.fpFile, "rb")
614 614 self.nextfileflag == False
615 615
616 616 '''HERE STARTING THE FILE READING'''
617 617
618 618 self.fheader = FileHeaderMIRA35c()
619 619 self.fheader.FHread(self.fp) # Bltr FileHeader Reading
620 620
621 621 self.SPARrawGate1 = self.fheader.SPARrawGate1
622 622 self.SPARrawGate2 = self.fheader.SPARrawGate2
623 623 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
624 624 self.Num_Bins = self.fheader.PPARsft
625 625 self.dataOut.nFFTPoints = self.fheader.PPARsft
626 626
627 627 self.Num_inCoh = self.fheader.PPARavc
628 628 self.dataOut.PRF = self.fheader.PPARprf
629 629 self.dataOut.frequency = 34.85 * 10**9
630 630 self.Lambda = SPEED_OF_LIGHT / self.dataOut.frequency
631 631 self.dataOut.ippSeconds = 1. / float(self.dataOut.PRF)
632 632
633 633 pulse_width = self.fheader.PPARpdr * 10**-9
634 634 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
635 635
636 636 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2))
637 637 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
638 638
639 639 self.Ze = numpy.zeros(self.Num_Hei)
640 640 self.ETA = numpy.zeros(([2, self.Num_Hei]))
641 641
642 642 self.readBlock() # Block reading
643 643
644 644 else:
645 645 print('readFile FlagNoData becomes true')
646 646 self.flagNoMoreFiles = True
647 647 self.dataOut.flagNoData = True
648 648 self.FileHeaderFlag == True
649 649 return 0
650 650
651 651 def readBlock(self):
652 652 '''
653 653 It should be checked if the block has data, if it is not passed to the next file.
654 654
655 655 Then the following is done:
656 656
657 657 1. Read the RecordHeader
658 658 2. Fill the buffer with the current block number.
659 659
660 660 '''
661 661
662 662 if self.PointerReader > 1180:
663 663 self.fp.seek(self.PointerReader, os.SEEK_SET)
664 664 self.FirstPoint = self.PointerReader
665 665
666 666 else:
667 667 self.FirstPoint = 1180
668 668
669 669 self.srviHeader = SRVIHeader()
670 670
671 671 self.srviHeader.SRVIread(self.fp) # Se obtiene la cabecera del SRVI
672 672
673 673 self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque
674 674
675 675 if self.blocksize == 148:
676 676 print('blocksize == 148 bug')
677 677 jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1)
678 678
679 679 # Se obtiene la cabecera del SRVI
680 680 self.srviHeader.SRVIread(self.fp)
681 681
682 682 if not self.srviHeader.SizeOfSRVI1:
683 683 self.fileSelector += 1
684 684 self.nextfileflag == True
685 685 self.FileHeaderFlag == True
686 686
687 687 self.recordheader = RecordHeader()
688 688 self.recordheader.RHread(self.fp)
689 689 self.RadarConst = self.recordheader.RadarConst
690 690 dwell = self.recordheader.time_t
691 691 npw1 = self.recordheader.npw1
692 692 npw2 = self.recordheader.npw2
693 693
694 694 self.dataOut.channelList = list(range(1))
695 695 self.dataOut.nIncohInt = self.Num_inCoh
696 696 self.dataOut.nProfiles = self.Num_Bins
697 697 self.dataOut.nCohInt = 1
698 698 self.dataOut.windowOfFilter = 1
699 699 self.dataOut.utctime = dwell
700 700 self.dataOut.timeZone = 0
701 701
702 702 self.dataOut.outputInterval = self.dataOut.timeInterval
703 703 self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \
704 704 numpy.array(list(range(self.Num_Hei))) * self.__deltaHeigth
705 705
706 706 self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1)
707 707 self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1)
708 708 self.HSDV_Co = numpy.fromfile(
709 709 self.fp, [('HSDV_Co', '<f4')], self.Num_Hei)
710 710 self.HSDV_Cx = numpy.fromfile(
711 711 self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei)
712 712
713 713 self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1)
714 714 self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1)
715 715 self.COFA_Co = numpy.fromfile(
716 716 self.fp, [('COFA_Co', '<f4')], self.Num_Hei)
717 717 self.COFA_Cx = numpy.fromfile(
718 718 self.fp, [('COFA_Cx', '<f4')], self.Num_Hei)
719 719
720 720 self.ZSPCsign = numpy.fromfile(
721 721 self.fp, [('ZSPCsign', numpy.str_, 4)], 1)
722 722 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1)
723 723
724 724 self.dataOut.HSDV[0] = self.HSDV_Co[:][0]
725 725 self.dataOut.HSDV[1] = self.HSDV_Cx[:][0]
726 726
727 727 for irg in range(self.Num_Hei):
728 728 # Number of spectral sub pieces containing significant power
729 729 nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0]
730 730
731 731 for k in range(nspc):
732 732 # Index of the spectral bin where the piece is beginning
733 733 binIndex = numpy.fromfile(
734 734 self.fp, [('binIndex', 'int16')], 1)[0][0]
735 735 nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[
736 736 0][0] # Number of bins of the piece
737 737
738 738 # Co_Channel
739 739 jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[
740 740 0][0] # Spectrum piece to be normaliced
741 741 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[
742 742 0][0] # Maximun piece to be normaliced
743 743
744 744 self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg,
745 745 binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax
746 746
747 747 # Cx_Channel
748 748 jbin = numpy.fromfile(
749 749 self.fp, [('jbin', 'uint16')], nbins)[0][0]
750 750 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0]
751 751
752 752 self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg,
753 753 binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax
754 754
755 755 for bin in range(self.Num_Bins):
756 756
757 757 self.data_spc[:, bin, 0] = self.data_spc[:,
758 758 bin, 0] - self.dataOut.HSDV[:, 0]
759 759
760 760 self.data_spc[:, bin, 1] = self.data_spc[:,
761 761 bin, 1] - self.dataOut.HSDV[:, 1]
762 762
763 763 numpy.set_printoptions(threshold='nan')
764 764
765 765 self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
766 766
767 767 self.dataOut.COFA = numpy.array([self.COFA_Co, self.COFA_Cx])
768 768
769 769 print(' ')
770 770 print('SPC', numpy.shape(self.dataOut.data_spc))
771 771 # print 'SPC',self.dataOut.data_spc
772 772
773 773 noinor1 = 713031680
774 774 noinor2 = 30
775 775
776 776 npw1 = 1 # 0**(npw1/10) * noinor1 * noinor2
777 777 npw2 = 1 # 0**(npw2/10) * noinor1 * noinor2
778 778 self.dataOut.NPW = numpy.array([npw1, npw2])
779 779
780 780 print(' ')
781 781
782 782 self.data_spc = numpy.transpose(self.data_spc, (2, 1, 0))
783 783 self.data_spc = numpy.fft.fftshift(self.data_spc, axes=1)
784 784
785 785 self.data_spc = numpy.fliplr(self.data_spc)
786 786
787 787 self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
788 788 self.dataOut_spc = numpy.ones([1, self.Num_Bins, self.Num_Hei])
789 789 self.dataOut_spc[0, :, :] = self.data_spc[0, :, :]
790 790 # print 'SHAPE', self.dataOut_spc.shape
791 791 # For nyquist correction:
792 792 # fix = 20 # ~3m/s
793 793 #shift = self.Num_Bins/2 + fix
794 794 #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]])
795 795
796 796 '''Block Reading, the Block Data is received and Reshape is used to give it
797 797 shape.
798 798 '''
799 799
800 800 self.PointerReader = self.fp.tell()
General Comments 0
You need to be logged in to leave comments. Login now