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