@@ -1,618 +1,679 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 | import numpy |
|
6 | import numpy | |
7 | import copy |
|
7 | import copy | |
8 | import datetime |
|
8 | import datetime | |
9 |
|
9 | |||
|
10 | SPEED_OF_LIGHT = 299792458 | |||
|
11 | SPEED_OF_LIGHT = 3e8 | |||
|
12 | ||||
10 | BASIC_STRUCTURE = numpy.dtype([ |
|
13 | BASIC_STRUCTURE = numpy.dtype([ | |
11 | ('nSize','<u4'), |
|
14 | ('nSize','<u4'), | |
12 | ('nVersion','<u2'), |
|
15 | ('nVersion','<u2'), | |
13 | ('nDataBlockId','<u4'), |
|
16 | ('nDataBlockId','<u4'), | |
14 | ('nUtime','<u4'), |
|
17 | ('nUtime','<u4'), | |
15 | ('nMilsec','<u2'), |
|
18 | ('nMilsec','<u2'), | |
16 | ('nTimezone','<i2'), |
|
19 | ('nTimezone','<i2'), | |
17 | ('nDstflag','<i2'), |
|
20 | ('nDstflag','<i2'), | |
18 | ('nErrorCount','<u4') |
|
21 | ('nErrorCount','<u4') | |
19 | ]) |
|
22 | ]) | |
20 |
|
23 | |||
21 | SYSTEM_STRUCTURE = numpy.dtype([ |
|
24 | SYSTEM_STRUCTURE = numpy.dtype([ | |
22 | ('nSize','<u4'), |
|
25 | ('nSize','<u4'), | |
23 | ('nNumSamples','<u4'), |
|
26 | ('nNumSamples','<u4'), | |
24 | ('nNumProfiles','<u4'), |
|
27 | ('nNumProfiles','<u4'), | |
25 | ('nNumChannels','<u4'), |
|
28 | ('nNumChannels','<u4'), | |
26 | ('nADCResolution','<u4'), |
|
29 | ('nADCResolution','<u4'), | |
27 | ('nPCDIOBusWidth','<u4'), |
|
30 | ('nPCDIOBusWidth','<u4'), | |
28 | ]) |
|
31 | ]) | |
29 |
|
32 | |||
30 | RADAR_STRUCTURE = numpy.dtype([ |
|
33 | RADAR_STRUCTURE = numpy.dtype([ | |
31 | ('nSize','<u4'), |
|
34 | ('nSize','<u4'), | |
32 | ('nExpType','<u4'), |
|
35 | ('nExpType','<u4'), | |
33 | ('nNTx','<u4'), |
|
36 | ('nNTx','<u4'), | |
34 | ('fIpp','<f4'), |
|
37 | ('fIpp','<f4'), | |
35 | ('fTxA','<f4'), |
|
38 | ('fTxA','<f4'), | |
36 | ('fTxB','<f4'), |
|
39 | ('fTxB','<f4'), | |
37 | ('nNumWindows','<u4'), |
|
40 | ('nNumWindows','<u4'), | |
38 | ('nNumTaus','<u4'), |
|
41 | ('nNumTaus','<u4'), | |
39 | ('nCodeType','<u4'), |
|
42 | ('nCodeType','<u4'), | |
40 | ('nLine6Function','<u4'), |
|
43 | ('nLine6Function','<u4'), | |
41 | ('nLine5Function','<u4'), |
|
44 | ('nLine5Function','<u4'), | |
42 | ('fClock','<f4'), |
|
45 | ('fClock','<f4'), | |
43 | ('nPrePulseBefore','<u4'), |
|
46 | ('nPrePulseBefore','<u4'), | |
44 | ('nPrePulseAfter','<u4'), |
|
47 | ('nPrePulseAfter','<u4'), | |
45 | ('sRangeIPP','<a20'), |
|
48 | ('sRangeIPP','<a20'), | |
46 | ('sRangeTxA','<a20'), |
|
49 | ('sRangeTxA','<a20'), | |
47 | ('sRangeTxB','<a20'), |
|
50 | ('sRangeTxB','<a20'), | |
48 | ]) |
|
51 | ]) | |
49 |
|
52 | |||
50 | SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
53 | SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
51 |
|
54 | |||
52 |
|
55 | |||
53 | PROCESSING_STRUCTURE = numpy.dtype([ |
|
56 | PROCESSING_STRUCTURE = numpy.dtype([ | |
54 | ('nSize','<u4'), |
|
57 | ('nSize','<u4'), | |
55 | ('nDataType','<u4'), |
|
58 | ('nDataType','<u4'), | |
56 | ('nSizeOfDataBlock','<u4'), |
|
59 | ('nSizeOfDataBlock','<u4'), | |
57 | ('nProfilesperBlock','<u4'), |
|
60 | ('nProfilesperBlock','<u4'), | |
58 | ('nDataBlocksperFile','<u4'), |
|
61 | ('nDataBlocksperFile','<u4'), | |
59 | ('nNumWindows','<u4'), |
|
62 | ('nNumWindows','<u4'), | |
60 | ('nProcessFlags','<u4'), |
|
63 | ('nProcessFlags','<u4'), | |
61 | ('nCoherentIntegrations','<u4'), |
|
64 | ('nCoherentIntegrations','<u4'), | |
62 | ('nIncoherentIntegrations','<u4'), |
|
65 | ('nIncoherentIntegrations','<u4'), | |
63 | ('nTotalSpectra','<u4') |
|
66 | ('nTotalSpectra','<u4') | |
64 | ]) |
|
67 | ]) | |
65 |
|
68 | |||
66 | class Header(object): |
|
69 | class Header(object): | |
67 |
|
70 | |||
68 | def __init__(self): |
|
71 | def __init__(self): | |
69 | raise |
|
72 | raise | |
70 |
|
73 | |||
71 | def copy(self): |
|
74 | def copy(self): | |
72 | return copy.deepcopy(self) |
|
75 | return copy.deepcopy(self) | |
73 |
|
76 | |||
74 | def read(self): |
|
77 | def read(self): | |
75 |
|
78 | |||
76 | raise ValueError |
|
79 | raise ValueError | |
77 |
|
80 | |||
78 | def write(self): |
|
81 | def write(self): | |
79 |
|
82 | |||
80 | raise ValueError |
|
83 | raise ValueError | |
81 |
|
84 | |||
82 | def printInfo(self): |
|
85 | def printInfo(self): | |
83 |
|
86 | |||
84 | print "#"*100 |
|
87 | print "#"*100 | |
85 | print self.__class__.__name__.upper() |
|
88 | print self.__class__.__name__.upper() | |
86 | print "#"*100 |
|
89 | print "#"*100 | |
87 | for key in self.__dict__.keys(): |
|
90 | for key in self.__dict__.keys(): | |
88 | print "%s = %s" %(key, self.__dict__[key]) |
|
91 | print "%s = %s" %(key, self.__dict__[key]) | |
89 |
|
92 | |||
90 | class BasicHeader(Header): |
|
93 | class BasicHeader(Header): | |
91 |
|
94 | |||
92 | size = None |
|
95 | size = None | |
93 | version = None |
|
96 | version = None | |
94 | dataBlock = None |
|
97 | dataBlock = None | |
95 | utc = None |
|
98 | utc = None | |
96 | ltc = None |
|
99 | ltc = None | |
97 | miliSecond = None |
|
100 | miliSecond = None | |
98 | timeZone = None |
|
101 | timeZone = None | |
99 | dstFlag = None |
|
102 | dstFlag = None | |
100 | errorCount = None |
|
103 | errorCount = None | |
101 | datatime = None |
|
104 | datatime = None | |
102 |
|
105 | |||
103 | __LOCALTIME = None |
|
106 | __LOCALTIME = None | |
104 |
|
107 | |||
105 | def __init__(self, useLocalTime=True): |
|
108 | def __init__(self, useLocalTime=True): | |
106 |
|
109 | |||
107 | self.size = 24 |
|
110 | self.size = 24 | |
108 | self.version = 0 |
|
111 | self.version = 0 | |
109 | self.dataBlock = 0 |
|
112 | self.dataBlock = 0 | |
110 | self.utc = 0 |
|
113 | self.utc = 0 | |
111 | self.miliSecond = 0 |
|
114 | self.miliSecond = 0 | |
112 | self.timeZone = 0 |
|
115 | self.timeZone = 0 | |
113 | self.dstFlag = 0 |
|
116 | self.dstFlag = 0 | |
114 | self.errorCount = 0 |
|
117 | self.errorCount = 0 | |
115 |
|
118 | |||
116 | self.useLocalTime = useLocalTime |
|
119 | self.useLocalTime = useLocalTime | |
117 |
|
120 | |||
118 | def read(self, fp): |
|
121 | def read(self, fp): | |
119 | try: |
|
122 | try: | |
120 |
|
123 | |||
121 | header = numpy.fromfile(fp, BASIC_STRUCTURE,1) |
|
124 | header = numpy.fromfile(fp, BASIC_STRUCTURE,1) | |
122 |
|
125 | |||
123 | self.size = int(header['nSize'][0]) |
|
126 | self.size = int(header['nSize'][0]) | |
124 | self.version = int(header['nVersion'][0]) |
|
127 | self.version = int(header['nVersion'][0]) | |
125 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
128 | self.dataBlock = int(header['nDataBlockId'][0]) | |
126 | self.utc = int(header['nUtime'][0]) |
|
129 | self.utc = int(header['nUtime'][0]) | |
127 | self.miliSecond = int(header['nMilsec'][0]) |
|
130 | self.miliSecond = int(header['nMilsec'][0]) | |
128 | self.timeZone = int(header['nTimezone'][0]) |
|
131 | self.timeZone = int(header['nTimezone'][0]) | |
129 | self.dstFlag = int(header['nDstflag'][0]) |
|
132 | self.dstFlag = int(header['nDstflag'][0]) | |
130 | self.errorCount = int(header['nErrorCount'][0]) |
|
133 | self.errorCount = int(header['nErrorCount'][0]) | |
131 |
|
134 | |||
132 | except Exception, e: |
|
135 | except Exception, e: | |
133 | print "BasicHeader: " |
|
136 | print "BasicHeader: " | |
134 | print e |
|
137 | print e | |
135 | return 0 |
|
138 | return 0 | |
136 |
|
139 | |||
137 | return 1 |
|
140 | return 1 | |
138 |
|
141 | |||
139 | def write(self, fp): |
|
142 | def write(self, fp): | |
140 |
|
143 | |||
141 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
144 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) | |
142 | header = numpy.array(headerTuple, BASIC_STRUCTURE) |
|
145 | header = numpy.array(headerTuple, BASIC_STRUCTURE) | |
143 | header.tofile(fp) |
|
146 | header.tofile(fp) | |
144 |
|
147 | |||
145 | return 1 |
|
148 | return 1 | |
146 |
|
149 | |||
147 | def get_ltc(self): |
|
150 | def get_ltc(self): | |
148 |
|
151 | |||
149 | return self.utc - self.timeZone*60 |
|
152 | return self.utc - self.timeZone*60 | |
150 |
|
153 | |||
151 | def set_ltc(self, value): |
|
154 | def set_ltc(self, value): | |
152 |
|
155 | |||
153 | self.utc = value + self.timeZone*60 |
|
156 | self.utc = value + self.timeZone*60 | |
154 |
|
157 | |||
155 | def get_datatime(self): |
|
158 | def get_datatime(self): | |
156 |
|
159 | |||
157 | return datetime.datetime.utcfromtimestamp(self.ltc) |
|
160 | return datetime.datetime.utcfromtimestamp(self.ltc) | |
158 |
|
161 | |||
159 | ltc = property(get_ltc, set_ltc) |
|
162 | ltc = property(get_ltc, set_ltc) | |
160 | datatime = property(get_datatime) |
|
163 | datatime = property(get_datatime) | |
161 |
|
164 | |||
162 | class SystemHeader(Header): |
|
165 | class SystemHeader(Header): | |
163 |
|
166 | |||
164 | size = None |
|
167 | size = None | |
165 | nSamples = None |
|
168 | nSamples = None | |
166 | nProfiles = None |
|
169 | nProfiles = None | |
167 | nChannels = None |
|
170 | nChannels = None | |
168 | adcResolution = None |
|
171 | adcResolution = None | |
169 | pciDioBusWidth = None |
|
172 | pciDioBusWidth = None | |
170 |
|
173 | |||
171 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0): |
|
174 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0): | |
172 |
|
175 | |||
173 | self.size = 24 |
|
176 | self.size = 24 | |
174 | self.nSamples = nSamples |
|
177 | self.nSamples = nSamples | |
175 | self.nProfiles = nProfiles |
|
178 | self.nProfiles = nProfiles | |
176 | self.nChannels = nChannels |
|
179 | self.nChannels = nChannels | |
177 | self.adcResolution = adcResolution |
|
180 | self.adcResolution = adcResolution | |
178 | self.pciDioBusWidth = pciDioBusWith |
|
181 | self.pciDioBusWidth = pciDioBusWith | |
179 |
|
182 | |||
180 | def read(self, fp): |
|
183 | def read(self, fp): | |
181 |
|
184 | |||
182 | try: |
|
185 | try: | |
183 | header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1) |
|
186 | header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1) | |
184 | self.size = header['nSize'][0] |
|
187 | self.size = header['nSize'][0] | |
185 | self.nSamples = header['nNumSamples'][0] |
|
188 | self.nSamples = header['nNumSamples'][0] | |
186 | self.nProfiles = header['nNumProfiles'][0] |
|
189 | self.nProfiles = header['nNumProfiles'][0] | |
187 | self.nChannels = header['nNumChannels'][0] |
|
190 | self.nChannels = header['nNumChannels'][0] | |
188 | self.adcResolution = header['nADCResolution'][0] |
|
191 | self.adcResolution = header['nADCResolution'][0] | |
189 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
192 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
190 |
|
193 | |||
191 | except Exception, e: |
|
194 | except Exception, e: | |
192 | print "SystemHeader: " + e |
|
195 | print "SystemHeader: " + e | |
193 | return 0 |
|
196 | return 0 | |
194 |
|
197 | |||
195 | return 1 |
|
198 | return 1 | |
196 |
|
199 | |||
197 | def write(self, fp): |
|
200 | def write(self, fp): | |
198 |
|
201 | |||
199 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
202 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) | |
200 | header = numpy.array(headerTuple,SYSTEM_STRUCTURE) |
|
203 | header = numpy.array(headerTuple,SYSTEM_STRUCTURE) | |
201 | header.tofile(fp) |
|
204 | header.tofile(fp) | |
202 |
|
205 | |||
203 | return 1 |
|
206 | return 1 | |
204 |
|
207 | |||
205 | class RadarControllerHeader(Header): |
|
208 | class RadarControllerHeader(Header): | |
206 |
|
209 | |||
207 | size = None |
|
210 | size = None | |
208 | expType = None |
|
211 | expType = None | |
209 | nTx = None |
|
212 | nTx = None | |
210 | ipp = None |
|
213 | ipp = None | |
211 | txA = None |
|
214 | txA = None | |
212 | txB = None |
|
215 | txB = None | |
213 | nWindows = None |
|
216 | nWindows = None | |
214 | numTaus = None |
|
217 | numTaus = None | |
215 | codeType = None |
|
218 | codeType = None | |
216 | line6Function = None |
|
219 | line6Function = None | |
217 | line5Function = None |
|
220 | line5Function = None | |
218 | fClock = None |
|
221 | fClock = None | |
219 | prePulseBefore = None |
|
222 | prePulseBefore = None | |
220 | prePulserAfter = None |
|
223 | prePulserAfter = None | |
221 | rangeIpp = None |
|
224 | rangeIpp = None | |
222 | rangeTxA = None |
|
225 | rangeTxA = None | |
223 | rangeTxB = None |
|
226 | rangeTxB = None | |
224 |
|
227 | |||
225 |
__ |
|
228 | __size = None | |
226 |
|
229 | |||
227 | def __init__(self, expType=2, nTx=1, |
|
230 | def __init__(self, expType=2, nTx=1, | |
228 | ippKm=None, txA=0, txB=0, |
|
231 | ippKm=None, txA=0, txB=0, | |
229 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, |
|
232 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, | |
230 |
numTaus=0, line6Function=0, line5Function=0, fClock= |
|
233 | numTaus=0, line6Function=0, line5Function=0, fClock=None, | |
231 | prePulseBefore=0, prePulseAfter=0, |
|
234 | prePulseBefore=0, prePulseAfter=0, | |
232 | codeType=0, nCode=0, nBaud=0, code=None, |
|
235 | codeType=0, nCode=0, nBaud=0, code=None, | |
233 | flip1=0, flip2=0): |
|
236 | flip1=0, flip2=0): | |
234 |
|
237 | |||
235 | self.size = 116 |
|
238 | self.size = 116 | |
236 | self.expType = expType |
|
239 | self.expType = expType | |
237 | self.nTx = nTx |
|
240 | self.nTx = nTx | |
238 | self.ipp = ippKm |
|
241 | self.ipp = ippKm | |
239 | self.txA = txA |
|
242 | self.txA = txA | |
240 | self.txB = txB |
|
243 | self.txB = txB | |
241 | self.rangeIpp = ippKm |
|
244 | self.rangeIpp = ippKm | |
242 | self.rangeTxA = txA |
|
245 | self.rangeTxA = txA | |
243 | self.rangeTxB = txB |
|
246 | self.rangeTxB = txB | |
244 |
|
247 | |||
245 | self.nWindows = nWindows |
|
248 | self.nWindows = nWindows | |
246 | self.numTaus = numTaus |
|
249 | self.numTaus = numTaus | |
247 | self.codeType = codeType |
|
250 | self.codeType = codeType | |
248 | self.line6Function = line6Function |
|
251 | self.line6Function = line6Function | |
249 | self.line5Function = line5Function |
|
252 | self.line5Function = line5Function | |
250 | self.fClock = fClock |
|
253 | self.fClock = fClock | |
251 | self.prePulseBefore = prePulseBefore |
|
254 | self.prePulseBefore = prePulseBefore | |
252 | self.prePulserAfter = prePulseAfter |
|
255 | self.prePulserAfter = prePulseAfter | |
253 |
|
256 | |||
254 | self.nHeights = nHeights |
|
257 | self.nHeights = nHeights | |
255 | self.firstHeight = firstHeight |
|
258 | self.firstHeight = firstHeight | |
256 | self.deltaHeight = deltaHeight |
|
259 | self.deltaHeight = deltaHeight | |
257 | self.samplesWin = nHeights |
|
260 | self.samplesWin = nHeights | |
258 |
|
261 | |||
259 | self.nCode = nCode |
|
262 | self.nCode = nCode | |
260 | self.nBaud = nBaud |
|
263 | self.nBaud = nBaud | |
261 | self.code = code |
|
264 | self.code = code | |
262 | self.flip1 = flip1 |
|
265 | self.flip1 = flip1 | |
263 | self.flip2 = flip2 |
|
266 | self.flip2 = flip2 | |
264 |
|
267 | |||
265 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 |
|
268 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 | |
266 | # self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
269 | # self.dynamic = numpy.array([],numpy.dtype('byte')) | |
267 |
|
270 | |||
|
271 | if self.fClock is None and self.deltaHeight is not None: | |||
|
272 | self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u) | |||
268 |
|
273 | |||
269 | def read(self, fp): |
|
274 | def read(self, fp): | |
270 |
|
275 | |||
271 | try: |
|
276 | try: | |
272 | startFp = fp.tell() |
|
277 | startFp = fp.tell() | |
273 | header = numpy.fromfile(fp,RADAR_STRUCTURE,1) |
|
278 | header = numpy.fromfile(fp,RADAR_STRUCTURE,1) | |
274 |
|
279 | |||
275 |
|
|
280 | size = int(header['nSize'][0]) | |
276 | self.expType = int(header['nExpType'][0]) |
|
281 | self.expType = int(header['nExpType'][0]) | |
277 | self.nTx = int(header['nNTx'][0]) |
|
282 | self.nTx = int(header['nNTx'][0]) | |
278 | self.ipp = float(header['fIpp'][0]) |
|
283 | self.ipp = float(header['fIpp'][0]) | |
279 | self.txA = float(header['fTxA'][0]) |
|
284 | self.txA = float(header['fTxA'][0]) | |
280 | self.txB = float(header['fTxB'][0]) |
|
285 | self.txB = float(header['fTxB'][0]) | |
281 | self.nWindows = int(header['nNumWindows'][0]) |
|
286 | self.nWindows = int(header['nNumWindows'][0]) | |
282 | self.numTaus = int(header['nNumTaus'][0]) |
|
287 | self.numTaus = int(header['nNumTaus'][0]) | |
283 | self.codeType = int(header['nCodeType'][0]) |
|
288 | self.codeType = int(header['nCodeType'][0]) | |
284 | self.line6Function = int(header['nLine6Function'][0]) |
|
289 | self.line6Function = int(header['nLine6Function'][0]) | |
285 | self.line5Function = int(header['nLine5Function'][0]) |
|
290 | self.line5Function = int(header['nLine5Function'][0]) | |
286 | self.fClock = float(header['fClock'][0]) |
|
291 | self.fClock = float(header['fClock'][0]) | |
287 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
292 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) | |
288 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) |
|
293 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) | |
289 | self.rangeIpp = header['sRangeIPP'][0] |
|
294 | self.rangeIpp = header['sRangeIPP'][0] | |
290 | self.rangeTxA = header['sRangeTxA'][0] |
|
295 | self.rangeTxA = header['sRangeTxA'][0] | |
291 | self.rangeTxB = header['sRangeTxB'][0] |
|
296 | self.rangeTxB = header['sRangeTxB'][0] | |
292 | # jump Dynamic Radar Controller Header |
|
297 | # jump Dynamic Radar Controller Header | |
293 |
# jumpFp = s |
|
298 | # jumpFp = size - 116 | |
294 | # self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
299 | # self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) | |
295 | #pointer backward to dynamic header and read |
|
300 | #pointer backward to dynamic header and read | |
296 | # backFp = fp.tell() - jumpFp |
|
301 | # backFp = fp.tell() - jumpFp | |
297 | # fp.seek(backFp) |
|
302 | # fp.seek(backFp) | |
298 |
|
303 | |||
299 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) |
|
304 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) | |
300 |
|
305 | |||
301 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
306 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
302 | self.firstHeight = samplingWindow['h0'] |
|
307 | self.firstHeight = samplingWindow['h0'] | |
303 | self.deltaHeight = samplingWindow['dh'] |
|
308 | self.deltaHeight = samplingWindow['dh'] | |
304 | self.samplesWin = samplingWindow['nsa'] |
|
309 | self.samplesWin = samplingWindow['nsa'] | |
305 |
|
310 | |||
306 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
311 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) | |
307 |
|
312 | |||
308 | self.code_size = 0 |
|
313 | self.code_size = 0 | |
309 | if self.codeType != 0: |
|
314 | if self.codeType != 0: | |
310 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
315 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
311 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
316 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
312 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='i1') |
|
317 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='i1') | |
313 |
|
318 | |||
314 | for ic in range(self.nCode): |
|
319 | for ic in range(self.nCode): | |
315 | temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.))) |
|
320 | temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.))) | |
316 | for ib in range(self.nBaud-1,-1,-1): |
|
321 | for ib in range(self.nBaud-1,-1,-1): | |
317 | self.code[ic,ib] = temp[ib/32]%2 |
|
322 | self.code[ic,ib] = temp[ib/32]%2 | |
318 | temp[ib/32] = temp[ib/32]/2 |
|
323 | temp[ib/32] = temp[ib/32]/2 | |
319 | self.code = 2.0*self.code - 1.0 |
|
324 | self.code = 2.0*self.code - 1.0 | |
320 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 |
|
325 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 | |
321 |
|
326 | |||
322 | if self.line5Function == RCfunction.FLIP: |
|
327 | # if self.line5Function == RCfunction.FLIP: | |
323 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
328 | # self.flip1 = numpy.fromfile(fp,'<u4',1) | |
324 |
|
329 | # | ||
325 | if self.line6Function == RCfunction.FLIP: |
|
330 | # if self.line6Function == RCfunction.FLIP: | |
326 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
331 | # self.flip2 = numpy.fromfile(fp,'<u4',1) | |
327 |
|
332 | |||
328 |
endFp = |
|
333 | endFp = size + startFp | |
329 | jumpFp = endFp - fp.tell() |
|
334 | jumpFp = endFp - fp.tell() | |
330 | if jumpFp > 0: |
|
335 | if jumpFp > 0: | |
331 | fp.seek(jumpFp) |
|
336 | fp.seek(jumpFp) | |
332 |
|
337 | |||
333 | except Exception, e: |
|
338 | except Exception, e: | |
334 | print "RadarControllerHeader: " + e |
|
339 | print "RadarControllerHeader: " + e | |
335 | return 0 |
|
340 | return 0 | |
336 |
|
341 | |||
337 | return 1 |
|
342 | return 1 | |
338 |
|
343 | |||
339 | def write(self, fp): |
|
344 | def write(self, fp): | |
|
345 | ||||
340 | headerTuple = (self.size, |
|
346 | headerTuple = (self.size, | |
341 | self.expType, |
|
347 | self.expType, | |
342 | self.nTx, |
|
348 | self.nTx, | |
343 | self.ipp, |
|
349 | self.ipp, | |
344 | self.txA, |
|
350 | self.txA, | |
345 | self.txB, |
|
351 | self.txB, | |
346 | self.nWindows, |
|
352 | self.nWindows, | |
347 | self.numTaus, |
|
353 | self.numTaus, | |
348 | self.codeType, |
|
354 | self.codeType, | |
349 | self.line6Function, |
|
355 | self.line6Function, | |
350 | self.line5Function, |
|
356 | self.line5Function, | |
351 | self.fClock, |
|
357 | self.fClock, | |
352 | self.prePulseBefore, |
|
358 | self.prePulseBefore, | |
353 | self.prePulserAfter, |
|
359 | self.prePulserAfter, | |
354 | self.rangeIpp, |
|
360 | self.rangeIpp, | |
355 | self.rangeTxA, |
|
361 | self.rangeTxA, | |
356 | self.rangeTxB) |
|
362 | self.rangeTxB) | |
357 |
|
363 | |||
358 | header = numpy.array(headerTuple,RADAR_STRUCTURE) |
|
364 | header = numpy.array(headerTuple,RADAR_STRUCTURE) | |
359 | header.tofile(fp) |
|
365 | header.tofile(fp) | |
360 |
|
366 | |||
361 | #dynamic = self.dynamic |
|
|||
362 | #dynamic.tofile(fp) |
|
|||
363 |
|
||||
364 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
367 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) | |
365 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
368 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) | |
366 | samplingWindow.tofile(fp) |
|
369 | samplingWindow.tofile(fp) | |
367 |
|
370 | |||
368 | if self.numTaus > 0: |
|
371 | if self.numTaus > 0: | |
369 | self.Taus.tofile(fp) |
|
372 | self.Taus.tofile(fp) | |
370 |
|
373 | |||
371 | if self.codeType !=0: |
|
374 | if self.codeType !=0: | |
372 | nCode = numpy.array(self.nCode, '<u4') |
|
375 | nCode = numpy.array(self.nCode, '<u4') | |
373 | nCode.tofile(fp) |
|
376 | nCode.tofile(fp) | |
374 | nBaud = numpy.array(self.nBaud, '<u4') |
|
377 | nBaud = numpy.array(self.nBaud, '<u4') | |
375 | nBaud.tofile(fp) |
|
378 | nBaud.tofile(fp) | |
376 | code1 = (self.code + 1.0)/2. |
|
379 | code1 = (self.code + 1.0)/2. | |
377 |
|
380 | |||
378 | for ic in range(self.nCode): |
|
381 | for ic in range(self.nCode): | |
379 | tempx = numpy.zeros(numpy.ceil(self.nBaud/32.)) |
|
382 | tempx = numpy.zeros(numpy.ceil(self.nBaud/32.)) | |
380 | start = 0 |
|
383 | start = 0 | |
381 | end = 32 |
|
384 | end = 32 | |
382 | for i in range(len(tempx)): |
|
385 | for i in range(len(tempx)): | |
383 | code_selected = code1[ic,start:end] |
|
386 | code_selected = code1[ic,start:end] | |
384 | for j in range(len(code_selected)-1,-1,-1): |
|
387 | for j in range(len(code_selected)-1,-1,-1): | |
385 | if code_selected[j] == 1: |
|
388 | if code_selected[j] == 1: | |
386 | tempx[i] = tempx[i] + 2**(len(code_selected)-1-j) |
|
389 | tempx[i] = tempx[i] + 2**(len(code_selected)-1-j) | |
387 | start = start + 32 |
|
390 | start = start + 32 | |
388 | end = end + 32 |
|
391 | end = end + 32 | |
389 |
|
392 | |||
390 | tempx = tempx.astype('u4') |
|
393 | tempx = tempx.astype('u4') | |
391 | tempx.tofile(fp) |
|
394 | tempx.tofile(fp) | |
392 |
|
395 | |||
393 | if self.line5Function == RCfunction.FLIP: |
|
396 | # if self.line5Function == RCfunction.FLIP: | |
394 | self.flip1.tofile(fp) |
|
397 | # self.flip1.tofile(fp) | |
395 |
|
398 | # | ||
396 | if self.line6Function == RCfunction.FLIP: |
|
399 | # if self.line6Function == RCfunction.FLIP: | |
397 | self.flip2.tofile(fp) |
|
400 | # self.flip2.tofile(fp) | |
398 |
|
401 | |||
399 | return 1 |
|
402 | return 1 | |
400 |
|
403 | |||
401 | def get_ippSeconds(self): |
|
404 | def get_ippSeconds(self): | |
402 | ''' |
|
405 | ''' | |
403 | ''' |
|
406 | ''' | |
404 |
ippSeconds = 2.0 * 1000 * self.ipp / |
|
407 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT | |
405 |
|
408 | |||
406 | return ippSeconds |
|
409 | return ippSeconds | |
407 |
|
410 | |||
408 | def set_ippSeconds(self, ippSeconds): |
|
411 | def set_ippSeconds(self, ippSeconds): | |
409 | ''' |
|
412 | ''' | |
410 | ''' |
|
413 | ''' | |
411 |
|
414 | |||
412 |
self.ipp = ippSeconds * |
|
415 | self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000) | |
|
416 | ||||
|
417 | return | |||
|
418 | ||||
|
419 | def get_size(self): | |||
|
420 | ||||
|
421 | self.__size = 116 + 12*self.nWindows + 4*self.numTaus | |||
|
422 | ||||
|
423 | if self.codeType != 0: | |||
|
424 | self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) | |||
|
425 | ||||
|
426 | return self.__size | |||
|
427 | ||||
|
428 | def set_size(self, value): | |||
|
429 | ||||
|
430 | self.__size = value | |||
413 |
|
431 | |||
414 | return |
|
432 | return | |
415 |
|
433 | |||
416 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
434 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
|
435 | size = property(get_size, set_size) | |||
417 |
|
436 | |||
418 | class ProcessingHeader(Header): |
|
437 | class ProcessingHeader(Header): | |
419 |
|
438 | |||
420 | size = None |
|
439 | size = None | |
421 | dtype = None |
|
440 | dtype = None | |
422 | blockSize = None |
|
441 | blockSize = None | |
423 | profilesPerBlock = None |
|
442 | profilesPerBlock = None | |
424 | dataBlocksPerFile = None |
|
443 | dataBlocksPerFile = None | |
425 | nWindows = None |
|
444 | nWindows = None | |
426 | processFlags = None |
|
445 | processFlags = None | |
427 | nCohInt = None |
|
446 | nCohInt = None | |
428 | nIncohInt = None |
|
447 | nIncohInt = None | |
429 | totalSpectra = None |
|
448 | totalSpectra = None | |
430 |
|
449 | |||
431 | flag_dc = None |
|
450 | flag_dc = None | |
432 | flag_cspc = None |
|
451 | flag_cspc = None | |
433 |
|
452 | |||
434 | def __init__(self): |
|
453 | def __init__(self): | |
435 |
|
454 | |||
436 | self.size = 0 |
|
455 | self.size = 0 | |
437 | self.dtype = 0 |
|
456 | self.dtype = 0 | |
438 | self.blockSize = 0 |
|
457 | self.blockSize = 0 | |
439 | self.profilesPerBlock = 0 |
|
458 | self.profilesPerBlock = 0 | |
440 | self.dataBlocksPerFile = 0 |
|
459 | self.dataBlocksPerFile = 0 | |
441 | self.nWindows = 0 |
|
460 | self.nWindows = 0 | |
442 | self.processFlags = 0 |
|
461 | self.processFlags = 0 | |
443 | self.nCohInt = 0 |
|
462 | self.nCohInt = 0 | |
444 | self.nIncohInt = 0 |
|
463 | self.nIncohInt = 0 | |
445 | self.totalSpectra = 0 |
|
464 | self.totalSpectra = 0 | |
446 |
|
465 | |||
447 | self.nHeights = 0 |
|
466 | self.nHeights = 0 | |
448 | self.firstHeight = 0 |
|
467 | self.firstHeight = 0 | |
449 | self.deltaHeight = 0 |
|
468 | self.deltaHeight = 0 | |
450 | self.samplesWin = 0 |
|
469 | self.samplesWin = 0 | |
451 | self.spectraComb = 0 |
|
470 | self.spectraComb = 0 | |
452 | # self.nCode = None |
|
471 | # self.nCode = None | |
453 | # self.code = None |
|
472 | # self.code = None | |
454 | # self.nBaud = None |
|
473 | # self.nBaud = None | |
455 | self.shif_fft = False |
|
474 | self.shif_fft = False | |
456 | self.flag_dc = False |
|
475 | self.flag_dc = False | |
457 | self.flag_cspc = False |
|
476 | self.flag_cspc = False | |
458 |
|
477 | |||
459 | def read(self, fp): |
|
478 | def read(self, fp): | |
460 | # try: |
|
479 | # try: | |
461 | header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1) |
|
480 | header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1) | |
462 | self.size = int(header['nSize'][0]) |
|
481 | self.size = int(header['nSize'][0]) | |
463 | self.dtype = int(header['nDataType'][0]) |
|
482 | self.dtype = int(header['nDataType'][0]) | |
464 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
483 | self.blockSize = int(header['nSizeOfDataBlock'][0]) | |
465 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
484 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) | |
466 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
485 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) | |
467 | self.nWindows = int(header['nNumWindows'][0]) |
|
486 | self.nWindows = int(header['nNumWindows'][0]) | |
468 | self.processFlags = header['nProcessFlags'] |
|
487 | self.processFlags = header['nProcessFlags'] | |
469 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
488 | self.nCohInt = int(header['nCoherentIntegrations'][0]) | |
470 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
489 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) | |
471 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
490 | self.totalSpectra = int(header['nTotalSpectra'][0]) | |
472 |
|
491 | |||
473 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) |
|
492 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) | |
474 |
|
493 | |||
475 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
494 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
476 | self.firstHeight = float(samplingWindow['h0'][0]) |
|
495 | self.firstHeight = float(samplingWindow['h0'][0]) | |
477 | self.deltaHeight = float(samplingWindow['dh'][0]) |
|
496 | self.deltaHeight = float(samplingWindow['dh'][0]) | |
478 | self.samplesWin = samplingWindow['nsa'][0] |
|
497 | self.samplesWin = samplingWindow['nsa'][0] | |
479 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
498 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) | |
480 |
|
499 | |||
481 | # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
500 | # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
482 | # self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
501 | # self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
483 | # self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
502 | # self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
484 | # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) |
|
503 | # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) | |
485 |
|
504 | |||
486 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
505 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
487 | self.shif_fft = True |
|
506 | self.shif_fft = True | |
488 | else: |
|
507 | else: | |
489 | self.shif_fft = False |
|
508 | self.shif_fft = False | |
490 |
|
509 | |||
491 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
510 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
492 | self.flag_dc = True |
|
511 | self.flag_dc = True | |
493 |
|
512 | |||
494 | nChannels = 0 |
|
513 | nChannels = 0 | |
495 | nPairs = 0 |
|
514 | nPairs = 0 | |
496 | pairList = [] |
|
515 | pairList = [] | |
497 |
|
516 | |||
498 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
517 | for i in range( 0, self.totalSpectra*2, 2 ): | |
499 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
518 | if self.spectraComb[i] == self.spectraComb[i+1]: | |
500 | nChannels = nChannels + 1 #par de canales iguales |
|
519 | nChannels = nChannels + 1 #par de canales iguales | |
501 | else: |
|
520 | else: | |
502 | nPairs = nPairs + 1 #par de canales diferentes |
|
521 | nPairs = nPairs + 1 #par de canales diferentes | |
503 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
522 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) | |
504 |
|
523 | |||
505 | self.flag_cspc = False |
|
524 | self.flag_cspc = False | |
506 | if nPairs > 0: |
|
525 | if nPairs > 0: | |
507 | self.flag_cspc = True |
|
526 | self.flag_cspc = True | |
508 |
|
527 | |||
509 | # except Exception, e: |
|
528 | # except Exception, e: | |
510 | # print "Error ProcessingHeader: " |
|
529 | # print "Error ProcessingHeader: " | |
511 | # return 0 |
|
530 | # return 0 | |
512 |
|
531 | |||
513 | return 1 |
|
532 | return 1 | |
514 |
|
533 | |||
515 | def write(self, fp): |
|
534 | def write(self, fp): | |
516 |
|
535 | |||
517 | headerTuple = (self.size, |
|
536 | headerTuple = (self.size, | |
518 | self.dtype, |
|
537 | self.dtype, | |
519 | self.blockSize, |
|
538 | self.blockSize, | |
520 | self.profilesPerBlock, |
|
539 | self.profilesPerBlock, | |
521 | self.dataBlocksPerFile, |
|
540 | self.dataBlocksPerFile, | |
522 | self.nWindows, |
|
541 | self.nWindows, | |
523 | self.processFlags, |
|
542 | self.processFlags, | |
524 | self.nCohInt, |
|
543 | self.nCohInt, | |
525 | self.nIncohInt, |
|
544 | self.nIncohInt, | |
526 | self.totalSpectra) |
|
545 | self.totalSpectra) | |
527 |
|
546 | |||
528 | header = numpy.array(headerTuple,PROCESSING_STRUCTURE) |
|
547 | header = numpy.array(headerTuple,PROCESSING_STRUCTURE) | |
529 | header.tofile(fp) |
|
548 | header.tofile(fp) | |
530 |
|
549 | |||
531 | if self.nWindows != 0: |
|
550 | if self.nWindows != 0: | |
532 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
551 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) | |
533 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
552 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) | |
534 | samplingWindow.tofile(fp) |
|
553 | samplingWindow.tofile(fp) | |
535 |
|
554 | |||
536 |
|
555 | |||
537 | if self.totalSpectra != 0: |
|
556 | if self.totalSpectra != 0: | |
538 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
557 | spectraComb = numpy.array([],numpy.dtype('u1')) | |
539 | spectraComb = self.spectraComb |
|
558 | spectraComb = self.spectraComb | |
540 | spectraComb.tofile(fp) |
|
559 | spectraComb.tofile(fp) | |
541 |
|
560 | |||
542 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
561 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
543 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
562 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
544 | # nCode.tofile(fp) |
|
563 | # nCode.tofile(fp) | |
545 | # |
|
564 | # | |
546 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
565 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) | |
547 | # nBaud.tofile(fp) |
|
566 | # nBaud.tofile(fp) | |
548 | # |
|
567 | # | |
549 | # code = self.code.reshape(self.nCode*self.nBaud) |
|
568 | # code = self.code.reshape(self.nCode*self.nBaud) | |
550 | # code = code.astype(numpy.dtype('<f4')) |
|
569 | # code = code.astype(numpy.dtype('<f4')) | |
551 | # code.tofile(fp) |
|
570 | # code.tofile(fp) | |
552 |
|
571 | |||
553 | return 1 |
|
572 | return 1 | |
554 |
|
573 | |||
555 | class RCfunction: |
|
574 | class RCfunction: | |
556 | NONE=0 |
|
575 | NONE=0 | |
557 | FLIP=1 |
|
576 | FLIP=1 | |
558 | CODE=2 |
|
577 | CODE=2 | |
559 | SAMPLING=3 |
|
578 | SAMPLING=3 | |
560 | LIN6DIV256=4 |
|
579 | LIN6DIV256=4 | |
561 | SYNCHRO=5 |
|
580 | SYNCHRO=5 | |
562 |
|
581 | |||
563 | class nCodeType: |
|
582 | class nCodeType: | |
564 | NONE=0 |
|
583 | NONE=0 | |
565 | USERDEFINE=1 |
|
584 | USERDEFINE=1 | |
566 | BARKER2=2 |
|
585 | BARKER2=2 | |
567 | BARKER3=3 |
|
586 | BARKER3=3 | |
568 | BARKER4=4 |
|
587 | BARKER4=4 | |
569 | BARKER5=5 |
|
588 | BARKER5=5 | |
570 | BARKER7=6 |
|
589 | BARKER7=6 | |
571 | BARKER11=7 |
|
590 | BARKER11=7 | |
572 | BARKER13=8 |
|
591 | BARKER13=8 | |
573 | AC128=9 |
|
592 | AC128=9 | |
574 | COMPLEMENTARYCODE2=10 |
|
593 | COMPLEMENTARYCODE2=10 | |
575 | COMPLEMENTARYCODE4=11 |
|
594 | COMPLEMENTARYCODE4=11 | |
576 | COMPLEMENTARYCODE8=12 |
|
595 | COMPLEMENTARYCODE8=12 | |
577 | COMPLEMENTARYCODE16=13 |
|
596 | COMPLEMENTARYCODE16=13 | |
578 | COMPLEMENTARYCODE32=14 |
|
597 | COMPLEMENTARYCODE32=14 | |
579 | COMPLEMENTARYCODE64=15 |
|
598 | COMPLEMENTARYCODE64=15 | |
580 | COMPLEMENTARYCODE128=16 |
|
599 | COMPLEMENTARYCODE128=16 | |
581 | CODE_BINARY28=17 |
|
600 | CODE_BINARY28=17 | |
582 |
|
601 | |||
583 | class PROCFLAG: |
|
602 | class PROCFLAG: | |
|
603 | ||||
584 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
604 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
585 | DECODE_DATA = numpy.uint32(0x00000002) |
|
605 | DECODE_DATA = numpy.uint32(0x00000002) | |
586 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
606 | SPECTRA_CALC = numpy.uint32(0x00000004) | |
587 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
607 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |
588 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
608 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |
589 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
609 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |
590 |
|
610 | |||
591 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
611 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |
592 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
612 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |
593 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
613 | DATATYPE_LONG = numpy.uint32(0x00000100) | |
594 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
614 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |
595 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
615 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |
596 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
616 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |
597 |
|
617 | |||
598 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
618 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |
599 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
619 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |
600 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
620 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |
601 |
|
621 | |||
602 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
622 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |
603 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
623 | DEFLIP_DATA = numpy.uint32(0x00010000) | |
604 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
624 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |
605 |
|
625 | |||
606 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
626 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |
607 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
627 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |
608 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
628 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |
609 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
629 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |
610 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
630 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |
611 |
|
631 | |||
612 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
632 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |
613 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
633 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |
614 |
|
634 | |||
615 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
635 | OPERATION_MASK = numpy.uint32(0x0000003F) | |
616 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
636 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |
617 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
637 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
618 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
|
638 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) | |
|
639 | ||||
|
640 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |||
|
641 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |||
|
642 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |||
|
643 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |||
|
644 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |||
|
645 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |||
|
646 | ||||
|
647 | NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |||
|
648 | ||||
|
649 | PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, | |||
|
650 | PROCFLAG.DATATYPE_SHORT, | |||
|
651 | PROCFLAG.DATATYPE_LONG, | |||
|
652 | PROCFLAG.DATATYPE_INT64, | |||
|
653 | PROCFLAG.DATATYPE_FLOAT, | |||
|
654 | PROCFLAG.DATATYPE_DOUBLE] | |||
|
655 | ||||
|
656 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] | |||
|
657 | ||||
|
658 | def get_dtype_index(numpy_dtype): | |||
|
659 | ||||
|
660 | index = None | |||
|
661 | ||||
|
662 | for i in range(len(NUMPY_DTYPE_LIST)): | |||
|
663 | if numpy_dtype == NUMPY_DTYPE_LIST[i]: | |||
|
664 | index = i | |||
|
665 | break | |||
|
666 | ||||
|
667 | return index | |||
|
668 | ||||
|
669 | def get_numpy_dtype(index): | |||
|
670 | ||||
|
671 | return NUMPY_DTYPE_LIST[index] | |||
|
672 | ||||
|
673 | def get_procflag_dtype(index): | |||
|
674 | ||||
|
675 | return PROCFLAG_DTYPE_LIST[index] | |||
|
676 | ||||
|
677 | def get_dtype_width(index): | |||
|
678 | ||||
|
679 | return DTYPE_WIDTH[index] No newline at end of file |
@@ -1,1465 +1,1526 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 2, 2014 |
|
2 | Created on Jul 2, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import sys |
|
7 | import sys | |
8 | import glob |
|
8 | import glob | |
9 | import time |
|
9 | import time | |
10 | import numpy |
|
10 | import numpy | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import time, datetime |
|
12 | import time, datetime | |
13 | #import h5py |
|
13 | #import h5py | |
14 | import traceback |
|
14 | import traceback | |
15 |
|
15 | |||
16 | try: |
|
16 | try: | |
17 | from gevent import sleep |
|
17 | from gevent import sleep | |
18 | except: |
|
18 | except: | |
19 | from time import sleep |
|
19 | from time import sleep | |
20 |
|
20 | |||
21 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
21 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
22 | from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width | |||
22 |
|
23 | |||
23 | LOCALTIME = True |
|
24 | LOCALTIME = True | |
24 |
|
25 | |||
25 | def isNumber(cad): |
|
26 | def isNumber(cad): | |
26 | """ |
|
27 | """ | |
27 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
28 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
28 |
|
29 | |||
29 | Excepciones: |
|
30 | Excepciones: | |
30 | Si un determinado string no puede ser convertido a numero |
|
31 | Si un determinado string no puede ser convertido a numero | |
31 | Input: |
|
32 | Input: | |
32 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
33 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
33 |
|
34 | |||
34 | Return: |
|
35 | Return: | |
35 | True : si el string es uno numerico |
|
36 | True : si el string es uno numerico | |
36 | False : no es un string numerico |
|
37 | False : no es un string numerico | |
37 | """ |
|
38 | """ | |
38 | try: |
|
39 | try: | |
39 | float( cad ) |
|
40 | float( cad ) | |
40 | return True |
|
41 | return True | |
41 | except: |
|
42 | except: | |
42 | return False |
|
43 | return False | |
43 |
|
44 | |||
44 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
45 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
45 | """ |
|
46 | """ | |
46 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
47 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
47 |
|
48 | |||
48 | Inputs: |
|
49 | Inputs: | |
49 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
50 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
50 |
|
51 | |||
51 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
52 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
52 | segundos contados desde 01/01/1970. |
|
53 | segundos contados desde 01/01/1970. | |
53 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
54 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
54 | segundos contados desde 01/01/1970. |
|
55 | segundos contados desde 01/01/1970. | |
55 |
|
56 | |||
56 | Return: |
|
57 | Return: | |
57 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
58 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
58 | fecha especificado, de lo contrario retorna False. |
|
59 | fecha especificado, de lo contrario retorna False. | |
59 |
|
60 | |||
60 | Excepciones: |
|
61 | Excepciones: | |
61 | Si el archivo no existe o no puede ser abierto |
|
62 | Si el archivo no existe o no puede ser abierto | |
62 | Si la cabecera no puede ser leida. |
|
63 | Si la cabecera no puede ser leida. | |
63 |
|
64 | |||
64 | """ |
|
65 | """ | |
65 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
66 | basicHeaderObj = BasicHeader(LOCALTIME) | |
66 |
|
67 | |||
67 | try: |
|
68 | try: | |
68 | fp = open(filename,'rb') |
|
69 | fp = open(filename,'rb') | |
69 | except IOError: |
|
70 | except IOError: | |
70 | traceback.print_exc() |
|
71 | traceback.print_exc() | |
71 | raise IOError, "The file %s can't be opened" %(filename) |
|
72 | raise IOError, "The file %s can't be opened" %(filename) | |
72 |
|
73 | |||
73 | sts = basicHeaderObj.read(fp) |
|
74 | sts = basicHeaderObj.read(fp) | |
74 | fp.close() |
|
75 | fp.close() | |
75 |
|
76 | |||
76 | if not(sts): |
|
77 | if not(sts): | |
77 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
78 | print "Skipping the file %s because it has not a valid header" %(filename) | |
78 | return 0 |
|
79 | return 0 | |
79 |
|
80 | |||
80 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
81 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
81 | return 0 |
|
82 | return 0 | |
82 |
|
83 | |||
83 | return 1 |
|
84 | return 1 | |
84 |
|
85 | |||
85 | def isFileinThisTime(filename, startTime, endTime): |
|
86 | def isFileinThisTime(filename, startTime, endTime): | |
86 | """ |
|
87 | """ | |
87 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
88 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
88 |
|
89 | |||
89 | Inputs: |
|
90 | Inputs: | |
90 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
91 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
91 |
|
92 | |||
92 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
93 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
93 |
|
94 | |||
94 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
95 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
95 |
|
96 | |||
96 | Return: |
|
97 | Return: | |
97 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
98 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
98 | fecha especificado, de lo contrario retorna False. |
|
99 | fecha especificado, de lo contrario retorna False. | |
99 |
|
100 | |||
100 | Excepciones: |
|
101 | Excepciones: | |
101 | Si el archivo no existe o no puede ser abierto |
|
102 | Si el archivo no existe o no puede ser abierto | |
102 | Si la cabecera no puede ser leida. |
|
103 | Si la cabecera no puede ser leida. | |
103 |
|
104 | |||
104 | """ |
|
105 | """ | |
105 |
|
106 | |||
106 |
|
107 | |||
107 | try: |
|
108 | try: | |
108 | fp = open(filename,'rb') |
|
109 | fp = open(filename,'rb') | |
109 | except IOError: |
|
110 | except IOError: | |
110 | traceback.print_exc() |
|
111 | traceback.print_exc() | |
111 | raise IOError, "The file %s can't be opened" %(filename) |
|
112 | raise IOError, "The file %s can't be opened" %(filename) | |
112 |
|
113 | |||
113 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
114 | basicHeaderObj = BasicHeader(LOCALTIME) | |
114 | sts = basicHeaderObj.read(fp) |
|
115 | sts = basicHeaderObj.read(fp) | |
115 | fp.close() |
|
116 | fp.close() | |
116 |
|
117 | |||
117 | thisDatetime = basicHeaderObj.datatime |
|
118 | thisDatetime = basicHeaderObj.datatime | |
118 | thisTime = thisDatetime.time() |
|
119 | thisTime = thisDatetime.time() | |
119 |
|
120 | |||
120 | if not(sts): |
|
121 | if not(sts): | |
121 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
122 | print "Skipping the file %s because it has not a valid header" %(filename) | |
122 | return None |
|
123 | return None | |
123 |
|
124 | |||
124 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
125 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
125 | return None |
|
126 | return None | |
126 |
|
127 | |||
127 | return thisDatetime |
|
128 | return thisDatetime | |
128 |
|
129 | |||
129 | def getFileFromSet(path, ext, set): |
|
130 | def getFileFromSet(path, ext, set): | |
130 | validFilelist = [] |
|
131 | validFilelist = [] | |
131 | fileList = os.listdir(path) |
|
132 | fileList = os.listdir(path) | |
132 |
|
133 | |||
133 | # 0 1234 567 89A BCDE |
|
134 | # 0 1234 567 89A BCDE | |
134 | # H YYYY DDD SSS .ext |
|
135 | # H YYYY DDD SSS .ext | |
135 |
|
136 | |||
136 | for thisFile in fileList: |
|
137 | for thisFile in fileList: | |
137 | try: |
|
138 | try: | |
138 | year = int(thisFile[1:5]) |
|
139 | year = int(thisFile[1:5]) | |
139 | doy = int(thisFile[5:8]) |
|
140 | doy = int(thisFile[5:8]) | |
140 | except: |
|
141 | except: | |
141 | continue |
|
142 | continue | |
142 |
|
143 | |||
143 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
144 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): | |
144 | continue |
|
145 | continue | |
145 |
|
146 | |||
146 | validFilelist.append(thisFile) |
|
147 | validFilelist.append(thisFile) | |
147 |
|
148 | |||
148 | myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) |
|
149 | myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) | |
149 |
|
150 | |||
150 | if len(myfile)!= 0: |
|
151 | if len(myfile)!= 0: | |
151 | return myfile[0] |
|
152 | return myfile[0] | |
152 | else: |
|
153 | else: | |
153 | filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower()) |
|
154 | filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower()) | |
154 | print 'the filename %s does not exist'%filename |
|
155 | print 'the filename %s does not exist'%filename | |
155 | print '...going to the last file: ' |
|
156 | print '...going to the last file: ' | |
156 |
|
157 | |||
157 | if validFilelist: |
|
158 | if validFilelist: | |
158 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
159 | validFilelist = sorted( validFilelist, key=str.lower ) | |
159 | return validFilelist[-1] |
|
160 | return validFilelist[-1] | |
160 |
|
161 | |||
161 | return None |
|
162 | return None | |
162 |
|
163 | |||
163 | def getlastFileFromPath(path, ext): |
|
164 | def getlastFileFromPath(path, ext): | |
164 | """ |
|
165 | """ | |
165 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
166 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
166 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
167 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
167 |
|
168 | |||
168 | Input: |
|
169 | Input: | |
169 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
170 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
170 | ext : extension de los files contenidos en una carpeta |
|
171 | ext : extension de los files contenidos en una carpeta | |
171 |
|
172 | |||
172 | Return: |
|
173 | Return: | |
173 | El ultimo file de una determinada carpeta, no se considera el path. |
|
174 | El ultimo file de una determinada carpeta, no se considera el path. | |
174 | """ |
|
175 | """ | |
175 | validFilelist = [] |
|
176 | validFilelist = [] | |
176 | fileList = os.listdir(path) |
|
177 | fileList = os.listdir(path) | |
177 |
|
178 | |||
178 | # 0 1234 567 89A BCDE |
|
179 | # 0 1234 567 89A BCDE | |
179 | # H YYYY DDD SSS .ext |
|
180 | # H YYYY DDD SSS .ext | |
180 |
|
181 | |||
181 | for thisFile in fileList: |
|
182 | for thisFile in fileList: | |
182 |
|
183 | |||
183 | year = thisFile[1:5] |
|
184 | year = thisFile[1:5] | |
184 | if not isNumber(year): |
|
185 | if not isNumber(year): | |
185 | continue |
|
186 | continue | |
186 |
|
187 | |||
187 | doy = thisFile[5:8] |
|
188 | doy = thisFile[5:8] | |
188 | if not isNumber(doy): |
|
189 | if not isNumber(doy): | |
189 | continue |
|
190 | continue | |
190 |
|
191 | |||
191 | year = int(year) |
|
192 | year = int(year) | |
192 | doy = int(doy) |
|
193 | doy = int(doy) | |
193 |
|
194 | |||
194 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
195 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): | |
195 | continue |
|
196 | continue | |
196 |
|
197 | |||
197 | validFilelist.append(thisFile) |
|
198 | validFilelist.append(thisFile) | |
198 |
|
199 | |||
199 | if validFilelist: |
|
200 | if validFilelist: | |
200 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
201 | validFilelist = sorted( validFilelist, key=str.lower ) | |
201 | return validFilelist[-1] |
|
202 | return validFilelist[-1] | |
202 |
|
203 | |||
203 | return None |
|
204 | return None | |
204 |
|
205 | |||
205 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
206 | def checkForRealPath(path, foldercounter, year, doy, set, ext): | |
206 | """ |
|
207 | """ | |
207 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
208 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
208 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
209 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
209 | el path exacto de un determinado file. |
|
210 | el path exacto de un determinado file. | |
210 |
|
211 | |||
211 | Example : |
|
212 | Example : | |
212 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
213 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
213 |
|
214 | |||
214 | Entonces la funcion prueba con las siguientes combinaciones |
|
215 | Entonces la funcion prueba con las siguientes combinaciones | |
215 | .../.../y2009307367.ext |
|
216 | .../.../y2009307367.ext | |
216 | .../.../Y2009307367.ext |
|
217 | .../.../Y2009307367.ext | |
217 | .../.../x2009307/y2009307367.ext |
|
218 | .../.../x2009307/y2009307367.ext | |
218 | .../.../x2009307/Y2009307367.ext |
|
219 | .../.../x2009307/Y2009307367.ext | |
219 | .../.../X2009307/y2009307367.ext |
|
220 | .../.../X2009307/y2009307367.ext | |
220 | .../.../X2009307/Y2009307367.ext |
|
221 | .../.../X2009307/Y2009307367.ext | |
221 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
222 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
222 |
|
223 | |||
223 | Return: |
|
224 | Return: | |
224 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
225 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
225 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
226 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
226 | para el filename |
|
227 | para el filename | |
227 | """ |
|
228 | """ | |
228 | fullfilename = None |
|
229 | fullfilename = None | |
229 | find_flag = False |
|
230 | find_flag = False | |
230 | filename = None |
|
231 | filename = None | |
231 |
|
232 | |||
232 | prefixDirList = [None,'d','D'] |
|
233 | prefixDirList = [None,'d','D'] | |
233 | if ext.lower() == ".r": #voltage |
|
234 | if ext.lower() == ".r": #voltage | |
234 | prefixFileList = ['d','D'] |
|
235 | prefixFileList = ['d','D'] | |
235 | elif ext.lower() == ".pdata": #spectra |
|
236 | elif ext.lower() == ".pdata": #spectra | |
236 | prefixFileList = ['p','P'] |
|
237 | prefixFileList = ['p','P'] | |
237 | else: |
|
238 | else: | |
238 | return None, filename |
|
239 | return None, filename | |
239 |
|
240 | |||
240 | #barrido por las combinaciones posibles |
|
241 | #barrido por las combinaciones posibles | |
241 | for prefixDir in prefixDirList: |
|
242 | for prefixDir in prefixDirList: | |
242 | thispath = path |
|
243 | thispath = path | |
243 | if prefixDir != None: |
|
244 | if prefixDir != None: | |
244 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
245 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
245 | if foldercounter == 0: |
|
246 | if foldercounter == 0: | |
246 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) |
|
247 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) | |
247 | else: |
|
248 | else: | |
248 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) |
|
249 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) | |
249 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" |
|
250 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |
250 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
251 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
251 | fullfilename = os.path.join( thispath, filename ) #formo el path completo |
|
252 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |
252 |
|
253 | |||
253 | if os.path.exists( fullfilename ): #verifico que exista |
|
254 | if os.path.exists( fullfilename ): #verifico que exista | |
254 | find_flag = True |
|
255 | find_flag = True | |
255 | break |
|
256 | break | |
256 | if find_flag: |
|
257 | if find_flag: | |
257 | break |
|
258 | break | |
258 |
|
259 | |||
259 | if not(find_flag): |
|
260 | if not(find_flag): | |
260 | return None, filename |
|
261 | return None, filename | |
261 |
|
262 | |||
262 | return fullfilename, filename |
|
263 | return fullfilename, filename | |
263 |
|
264 | |||
264 | def isRadarFolder(folder): |
|
265 | def isRadarFolder(folder): | |
265 | try: |
|
266 | try: | |
266 | year = int(folder[1:5]) |
|
267 | year = int(folder[1:5]) | |
267 | doy = int(folder[5:8]) |
|
268 | doy = int(folder[5:8]) | |
268 | except: |
|
269 | except: | |
269 | return 0 |
|
270 | return 0 | |
270 |
|
271 | |||
271 | return 1 |
|
272 | return 1 | |
272 |
|
273 | |||
273 | def isRadarFile(file): |
|
274 | def isRadarFile(file): | |
274 | try: |
|
275 | try: | |
275 | year = int(file[1:5]) |
|
276 | year = int(file[1:5]) | |
276 | doy = int(file[5:8]) |
|
277 | doy = int(file[5:8]) | |
277 | set = int(file[8:11]) |
|
278 | set = int(file[8:11]) | |
278 | except: |
|
279 | except: | |
279 | return 0 |
|
280 | return 0 | |
280 |
|
281 | |||
281 | return 1 |
|
282 | return 1 | |
282 |
|
283 | |||
283 | def getDateFromRadarFile(file): |
|
284 | def getDateFromRadarFile(file): | |
284 | try: |
|
285 | try: | |
285 | year = int(file[1:5]) |
|
286 | year = int(file[1:5]) | |
286 | doy = int(file[5:8]) |
|
287 | doy = int(file[5:8]) | |
287 | set = int(file[8:11]) |
|
288 | set = int(file[8:11]) | |
288 | except: |
|
289 | except: | |
289 | return None |
|
290 | return None | |
290 |
|
291 | |||
291 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1) |
|
292 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1) | |
292 | return thisDate |
|
293 | return thisDate | |
293 |
|
294 | |||
294 | class JRODataIO: |
|
295 | class JRODataIO: | |
295 |
|
296 | |||
296 | c = 3E8 |
|
297 | c = 3E8 | |
297 |
|
298 | |||
298 | isConfig = False |
|
299 | isConfig = False | |
299 |
|
300 | |||
300 | basicHeaderObj = None |
|
301 | basicHeaderObj = None | |
301 |
|
302 | |||
302 | systemHeaderObj = None |
|
303 | systemHeaderObj = None | |
303 |
|
304 | |||
304 | radarControllerHeaderObj = None |
|
305 | radarControllerHeaderObj = None | |
305 |
|
306 | |||
306 | processingHeaderObj = None |
|
307 | processingHeaderObj = None | |
307 |
|
308 | |||
308 | online = 0 |
|
309 | online = 0 | |
309 |
|
310 | |||
310 | dtype = None |
|
311 | dtype = None | |
311 |
|
312 | |||
312 | pathList = [] |
|
313 | pathList = [] | |
313 |
|
314 | |||
314 | filenameList = [] |
|
315 | filenameList = [] | |
315 |
|
316 | |||
316 | filename = None |
|
317 | filename = None | |
317 |
|
318 | |||
318 | ext = None |
|
319 | ext = None | |
319 |
|
320 | |||
320 | flagIsNewFile = 1 |
|
321 | flagIsNewFile = 1 | |
321 |
|
322 | |||
322 | flagDiscontinuousBlock = 0 |
|
323 | flagDiscontinuousBlock = 0 | |
323 |
|
324 | |||
324 | flagIsNewBlock = 0 |
|
325 | flagIsNewBlock = 0 | |
325 |
|
326 | |||
326 | fp = None |
|
327 | fp = None | |
327 |
|
328 | |||
328 | firstHeaderSize = 0 |
|
329 | firstHeaderSize = 0 | |
329 |
|
330 | |||
330 | basicHeaderSize = 24 |
|
331 | basicHeaderSize = 24 | |
331 |
|
332 | |||
332 | versionFile = 1103 |
|
333 | versionFile = 1103 | |
333 |
|
334 | |||
334 | fileSize = None |
|
335 | fileSize = None | |
335 |
|
336 | |||
336 | # ippSeconds = None |
|
337 | # ippSeconds = None | |
337 |
|
338 | |||
338 | fileSizeByHeader = None |
|
339 | fileSizeByHeader = None | |
339 |
|
340 | |||
340 | fileIndex = None |
|
341 | fileIndex = None | |
341 |
|
342 | |||
342 | profileIndex = None |
|
343 | profileIndex = None | |
343 |
|
344 | |||
344 | blockIndex = None |
|
345 | blockIndex = None | |
345 |
|
346 | |||
346 | nTotalBlocks = None |
|
347 | nTotalBlocks = None | |
347 |
|
348 | |||
348 | maxTimeStep = 30 |
|
349 | maxTimeStep = 30 | |
349 |
|
350 | |||
350 | lastUTTime = None |
|
351 | lastUTTime = None | |
351 |
|
352 | |||
352 | datablock = None |
|
353 | datablock = None | |
353 |
|
354 | |||
354 | dataOut = None |
|
355 | dataOut = None | |
355 |
|
356 | |||
356 | blocksize = None |
|
357 | blocksize = None | |
357 |
|
358 | |||
358 | getByBlock = False |
|
359 | getByBlock = False | |
359 |
|
360 | |||
360 | def __init__(self): |
|
361 | def __init__(self): | |
361 |
|
362 | |||
362 | raise ValueError, "Not implemented" |
|
363 | raise ValueError, "Not implemented" | |
363 |
|
364 | |||
364 | def run(self): |
|
365 | def run(self): | |
365 |
|
366 | |||
366 | raise ValueError, "Not implemented" |
|
367 | raise ValueError, "Not implemented" | |
367 |
|
368 | |||
|
369 | def getDtypeWidth(self): | |||
|
370 | ||||
|
371 | dtype_index = get_dtype_index(self.dtype) | |||
|
372 | dtype_width = get_dtype_width(dtype_index) | |||
|
373 | ||||
|
374 | return dtype_width | |||
|
375 | ||||
368 | class JRODataReader(JRODataIO): |
|
376 | class JRODataReader(JRODataIO): | |
369 |
|
377 | |||
370 | nReadBlocks = 0 |
|
378 | nReadBlocks = 0 | |
371 |
|
379 | |||
372 | delay = 10 #number of seconds waiting a new file |
|
380 | delay = 10 #number of seconds waiting a new file | |
373 |
|
381 | |||
374 | nTries = 3 #quantity tries |
|
382 | nTries = 3 #quantity tries | |
375 |
|
383 | |||
376 | nFiles = 3 #number of files for searching |
|
384 | nFiles = 3 #number of files for searching | |
377 |
|
385 | |||
378 | path = None |
|
386 | path = None | |
379 |
|
387 | |||
380 | foldercounter = 0 |
|
388 | foldercounter = 0 | |
381 |
|
389 | |||
382 | flagNoMoreFiles = 0 |
|
390 | flagNoMoreFiles = 0 | |
383 |
|
391 | |||
384 | datetimeList = [] |
|
392 | datetimeList = [] | |
385 |
|
393 | |||
386 | __isFirstTimeOnline = 1 |
|
394 | __isFirstTimeOnline = 1 | |
387 |
|
395 | |||
388 | __printInfo = True |
|
396 | __printInfo = True | |
389 |
|
397 | |||
390 | profileIndex = None |
|
398 | profileIndex = None | |
391 |
|
399 | |||
392 | nTxs = 1 |
|
400 | nTxs = 1 | |
393 |
|
401 | |||
394 | txIndex = None |
|
402 | txIndex = None | |
395 |
|
403 | |||
396 | def __init__(self): |
|
404 | def __init__(self): | |
397 |
|
405 | |||
398 | """ |
|
406 | """ | |
399 |
|
407 | |||
400 | """ |
|
408 | """ | |
401 |
|
409 | |||
402 | # raise NotImplementedError, "This method has not been implemented" |
|
410 | # raise NotImplementedError, "This method has not been implemented" | |
403 |
|
411 | |||
404 |
|
412 | |||
405 | def createObjByDefault(self): |
|
413 | def createObjByDefault(self): | |
406 | """ |
|
414 | """ | |
407 |
|
415 | |||
408 | """ |
|
416 | """ | |
409 | raise NotImplementedError, "This method has not been implemented" |
|
417 | raise NotImplementedError, "This method has not been implemented" | |
410 |
|
418 | |||
411 | def getBlockDimension(self): |
|
419 | def getBlockDimension(self): | |
412 |
|
420 | |||
413 | raise NotImplementedError, "No implemented" |
|
421 | raise NotImplementedError, "No implemented" | |
414 |
|
422 | |||
415 | def __searchFilesOffLine(self, |
|
423 | def __searchFilesOffLine(self, | |
416 | path, |
|
424 | path, | |
417 | startDate=None, |
|
425 | startDate=None, | |
418 | endDate=None, |
|
426 | endDate=None, | |
419 | startTime=datetime.time(0,0,0), |
|
427 | startTime=datetime.time(0,0,0), | |
420 | endTime=datetime.time(23,59,59), |
|
428 | endTime=datetime.time(23,59,59), | |
421 | set=None, |
|
429 | set=None, | |
422 | expLabel='', |
|
430 | expLabel='', | |
423 | ext='.r', |
|
431 | ext='.r', | |
424 | walk=True): |
|
432 | walk=True): | |
425 |
|
433 | |||
426 | self.filenameList = [] |
|
434 | self.filenameList = [] | |
427 | self.datetimeList = [] |
|
435 | self.datetimeList = [] | |
428 |
|
436 | |||
429 | pathList = [] |
|
437 | pathList = [] | |
430 |
|
438 | |||
431 | if not walk: |
|
439 | if not walk: | |
432 | #pathList.append(path) |
|
440 | #pathList.append(path) | |
433 | multi_path = path.split(',') |
|
441 | multi_path = path.split(',') | |
434 | for single_path in multi_path: |
|
442 | for single_path in multi_path: | |
435 |
|
443 | |||
436 | if not os.path.isdir(single_path): |
|
444 | if not os.path.isdir(single_path): | |
437 | continue |
|
445 | continue | |
438 |
|
446 | |||
439 | pathList.append(single_path) |
|
447 | pathList.append(single_path) | |
440 |
|
448 | |||
441 | else: |
|
449 | else: | |
442 | #dirList = [] |
|
450 | #dirList = [] | |
443 | multi_path = path.split(',') |
|
451 | multi_path = path.split(',') | |
444 | for single_path in multi_path: |
|
452 | for single_path in multi_path: | |
445 |
|
453 | |||
446 | if not os.path.isdir(single_path): |
|
454 | if not os.path.isdir(single_path): | |
447 | continue |
|
455 | continue | |
448 |
|
456 | |||
449 | dirList = [] |
|
457 | dirList = [] | |
450 | for thisPath in os.listdir(single_path): |
|
458 | for thisPath in os.listdir(single_path): | |
451 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
459 | if not os.path.isdir(os.path.join(single_path,thisPath)): | |
452 | continue |
|
460 | continue | |
453 | if not isRadarFolder(thisPath): |
|
461 | if not isRadarFolder(thisPath): | |
454 | continue |
|
462 | continue | |
455 |
|
463 | |||
456 | dirList.append(thisPath) |
|
464 | dirList.append(thisPath) | |
457 |
|
465 | |||
458 | if not(dirList): |
|
466 | if not(dirList): | |
459 | return None, None |
|
467 | return None, None | |
460 |
|
468 | |||
461 | if startDate and endDate: |
|
469 | if startDate and endDate: | |
462 | thisDate = startDate |
|
470 | thisDate = startDate | |
463 |
|
471 | |||
464 | while(thisDate <= endDate): |
|
472 | while(thisDate <= endDate): | |
465 | year = thisDate.timetuple().tm_year |
|
473 | year = thisDate.timetuple().tm_year | |
466 | doy = thisDate.timetuple().tm_yday |
|
474 | doy = thisDate.timetuple().tm_yday | |
467 |
|
475 | |||
468 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
476 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') | |
469 | if len(matchlist) == 0: |
|
477 | if len(matchlist) == 0: | |
470 | thisDate += datetime.timedelta(1) |
|
478 | thisDate += datetime.timedelta(1) | |
471 | continue |
|
479 | continue | |
472 | for match in matchlist: |
|
480 | for match in matchlist: | |
473 | pathList.append(os.path.join(single_path,match,expLabel)) |
|
481 | pathList.append(os.path.join(single_path,match,expLabel)) | |
474 |
|
482 | |||
475 | thisDate += datetime.timedelta(1) |
|
483 | thisDate += datetime.timedelta(1) | |
476 | else: |
|
484 | else: | |
477 | for thiDir in dirList: |
|
485 | for thiDir in dirList: | |
478 | pathList.append(os.path.join(single_path,thiDir,expLabel)) |
|
486 | pathList.append(os.path.join(single_path,thiDir,expLabel)) | |
479 |
|
487 | |||
480 | if pathList == []: |
|
488 | if pathList == []: | |
481 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
489 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
482 | return None, None |
|
490 | return None, None | |
483 |
|
491 | |||
484 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
492 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) | |
485 |
|
493 | |||
486 | filenameList = [] |
|
494 | filenameList = [] | |
487 | datetimeList = [] |
|
495 | datetimeList = [] | |
488 | pathDict = {} |
|
496 | pathDict = {} | |
489 | filenameList_to_sort = [] |
|
497 | filenameList_to_sort = [] | |
490 |
|
498 | |||
491 | for i in range(len(pathList)): |
|
499 | for i in range(len(pathList)): | |
492 |
|
500 | |||
493 | thisPath = pathList[i] |
|
501 | thisPath = pathList[i] | |
494 |
|
502 | |||
495 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
503 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
496 | if len(fileList) < 1: |
|
504 | if len(fileList) < 1: | |
497 | continue |
|
505 | continue | |
498 | fileList.sort() |
|
506 | fileList.sort() | |
499 | pathDict.setdefault(fileList[0]) |
|
507 | pathDict.setdefault(fileList[0]) | |
500 | pathDict[fileList[0]] = i |
|
508 | pathDict[fileList[0]] = i | |
501 | filenameList_to_sort.append(fileList[0]) |
|
509 | filenameList_to_sort.append(fileList[0]) | |
502 |
|
510 | |||
503 | filenameList_to_sort.sort() |
|
511 | filenameList_to_sort.sort() | |
504 |
|
512 | |||
505 | for file in filenameList_to_sort: |
|
513 | for file in filenameList_to_sort: | |
506 | thisPath = pathList[pathDict[file]] |
|
514 | thisPath = pathList[pathDict[file]] | |
507 |
|
515 | |||
508 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
516 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
509 | fileList.sort() |
|
517 | fileList.sort() | |
510 |
|
518 | |||
511 | for file in fileList: |
|
519 | for file in fileList: | |
512 |
|
520 | |||
513 | filename = os.path.join(thisPath,file) |
|
521 | filename = os.path.join(thisPath,file) | |
514 | thisDatetime = isFileinThisTime(filename, startTime, endTime) |
|
522 | thisDatetime = isFileinThisTime(filename, startTime, endTime) | |
515 |
|
523 | |||
516 | if not(thisDatetime): |
|
524 | if not(thisDatetime): | |
517 | continue |
|
525 | continue | |
518 |
|
526 | |||
519 | filenameList.append(filename) |
|
527 | filenameList.append(filename) | |
520 | datetimeList.append(thisDatetime) |
|
528 | datetimeList.append(thisDatetime) | |
521 |
|
529 | |||
522 | if not(filenameList): |
|
530 | if not(filenameList): | |
523 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
531 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
524 | return None, None |
|
532 | return None, None | |
525 |
|
533 | |||
526 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
534 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |
527 |
|
535 | |||
528 |
|
536 | |||
529 | for i in range(len(filenameList)): |
|
537 | for i in range(len(filenameList)): | |
530 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
538 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
531 |
|
539 | |||
532 | self.filenameList = filenameList |
|
540 | self.filenameList = filenameList | |
533 | self.datetimeList = datetimeList |
|
541 | self.datetimeList = datetimeList | |
534 |
|
542 | |||
535 | return pathList, filenameList |
|
543 | return pathList, filenameList | |
536 |
|
544 | |||
537 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None): |
|
545 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None): | |
538 |
|
546 | |||
539 | """ |
|
547 | """ | |
540 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
548 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
541 | devuelve el archivo encontrado ademas de otros datos. |
|
549 | devuelve el archivo encontrado ademas de otros datos. | |
542 |
|
550 | |||
543 | Input: |
|
551 | Input: | |
544 | path : carpeta donde estan contenidos los files que contiene data |
|
552 | path : carpeta donde estan contenidos los files que contiene data | |
545 |
|
553 | |||
546 | expLabel : Nombre del subexperimento (subfolder) |
|
554 | expLabel : Nombre del subexperimento (subfolder) | |
547 |
|
555 | |||
548 | ext : extension de los files |
|
556 | ext : extension de los files | |
549 |
|
557 | |||
550 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
558 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |
551 |
|
559 | |||
552 | Return: |
|
560 | Return: | |
553 | directory : eL directorio donde esta el file encontrado |
|
561 | directory : eL directorio donde esta el file encontrado | |
554 | filename : el ultimo file de una determinada carpeta |
|
562 | filename : el ultimo file de una determinada carpeta | |
555 | year : el anho |
|
563 | year : el anho | |
556 | doy : el numero de dia del anho |
|
564 | doy : el numero de dia del anho | |
557 | set : el set del archivo |
|
565 | set : el set del archivo | |
558 |
|
566 | |||
559 |
|
567 | |||
560 | """ |
|
568 | """ | |
561 | dirList = [] |
|
569 | dirList = [] | |
562 |
|
570 | |||
563 | if not walk: |
|
571 | if not walk: | |
564 | fullpath = path |
|
572 | fullpath = path | |
565 | foldercounter = 0 |
|
573 | foldercounter = 0 | |
566 | else: |
|
574 | else: | |
567 | #Filtra solo los directorios |
|
575 | #Filtra solo los directorios | |
568 | for thisPath in os.listdir(path): |
|
576 | for thisPath in os.listdir(path): | |
569 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
577 | if not os.path.isdir(os.path.join(path,thisPath)): | |
570 | continue |
|
578 | continue | |
571 | if not isRadarFolder(thisPath): |
|
579 | if not isRadarFolder(thisPath): | |
572 | continue |
|
580 | continue | |
573 |
|
581 | |||
574 | dirList.append(thisPath) |
|
582 | dirList.append(thisPath) | |
575 |
|
583 | |||
576 | if not(dirList): |
|
584 | if not(dirList): | |
577 | return None, None, None, None, None, None |
|
585 | return None, None, None, None, None, None | |
578 |
|
586 | |||
579 | dirList = sorted( dirList, key=str.lower ) |
|
587 | dirList = sorted( dirList, key=str.lower ) | |
580 |
|
588 | |||
581 | doypath = dirList[-1] |
|
589 | doypath = dirList[-1] | |
582 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 |
|
590 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 | |
583 | fullpath = os.path.join(path, doypath, expLabel) |
|
591 | fullpath = os.path.join(path, doypath, expLabel) | |
584 |
|
592 | |||
585 |
|
593 | |||
586 | print "%s folder was found: " %(fullpath ) |
|
594 | print "%s folder was found: " %(fullpath ) | |
587 |
|
595 | |||
588 | if set == None: |
|
596 | if set == None: | |
589 | filename = getlastFileFromPath(fullpath, ext) |
|
597 | filename = getlastFileFromPath(fullpath, ext) | |
590 | else: |
|
598 | else: | |
591 | filename = getFileFromSet(fullpath, ext, set) |
|
599 | filename = getFileFromSet(fullpath, ext, set) | |
592 |
|
600 | |||
593 | if not(filename): |
|
601 | if not(filename): | |
594 | return None, None, None, None, None, None |
|
602 | return None, None, None, None, None, None | |
595 |
|
603 | |||
596 | print "%s file was found" %(filename) |
|
604 | print "%s file was found" %(filename) | |
597 |
|
605 | |||
598 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
606 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
599 | return None, None, None, None, None, None |
|
607 | return None, None, None, None, None, None | |
600 |
|
608 | |||
601 | year = int( filename[1:5] ) |
|
609 | year = int( filename[1:5] ) | |
602 | doy = int( filename[5:8] ) |
|
610 | doy = int( filename[5:8] ) | |
603 | set = int( filename[8:11] ) |
|
611 | set = int( filename[8:11] ) | |
604 |
|
612 | |||
605 | return fullpath, foldercounter, filename, year, doy, set |
|
613 | return fullpath, foldercounter, filename, year, doy, set | |
606 |
|
614 | |||
607 | def __setNextFileOffline(self): |
|
615 | def __setNextFileOffline(self): | |
608 |
|
616 | |||
609 | idFile = self.fileIndex |
|
617 | idFile = self.fileIndex | |
610 |
|
618 | |||
611 | while (True): |
|
619 | while (True): | |
612 | idFile += 1 |
|
620 | idFile += 1 | |
613 | if not(idFile < len(self.filenameList)): |
|
621 | if not(idFile < len(self.filenameList)): | |
614 | self.flagNoMoreFiles = 1 |
|
622 | self.flagNoMoreFiles = 1 | |
615 | # print "[Reading] No more Files" |
|
623 | # print "[Reading] No more Files" | |
616 | return 0 |
|
624 | return 0 | |
617 |
|
625 | |||
618 | filename = self.filenameList[idFile] |
|
626 | filename = self.filenameList[idFile] | |
619 |
|
627 | |||
620 | if not(self.__verifyFile(filename)): |
|
628 | if not(self.__verifyFile(filename)): | |
621 | continue |
|
629 | continue | |
622 |
|
630 | |||
623 | fileSize = os.path.getsize(filename) |
|
631 | fileSize = os.path.getsize(filename) | |
624 | fp = open(filename,'rb') |
|
632 | fp = open(filename,'rb') | |
625 | break |
|
633 | break | |
626 |
|
634 | |||
627 | self.flagIsNewFile = 1 |
|
635 | self.flagIsNewFile = 1 | |
628 | self.fileIndex = idFile |
|
636 | self.fileIndex = idFile | |
629 | self.filename = filename |
|
637 | self.filename = filename | |
630 | self.fileSize = fileSize |
|
638 | self.fileSize = fileSize | |
631 | self.fp = fp |
|
639 | self.fp = fp | |
632 |
|
640 | |||
633 | # print "[Reading] Setting the file: %s"%self.filename |
|
641 | # print "[Reading] Setting the file: %s"%self.filename | |
634 |
|
642 | |||
635 | return 1 |
|
643 | return 1 | |
636 |
|
644 | |||
637 | def __setNextFileOnline(self): |
|
645 | def __setNextFileOnline(self): | |
638 | """ |
|
646 | """ | |
639 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
647 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
640 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
648 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
641 | siguientes. |
|
649 | siguientes. | |
642 |
|
650 | |||
643 | Affected: |
|
651 | Affected: | |
644 | self.flagIsNewFile |
|
652 | self.flagIsNewFile | |
645 | self.filename |
|
653 | self.filename | |
646 | self.fileSize |
|
654 | self.fileSize | |
647 | self.fp |
|
655 | self.fp | |
648 | self.set |
|
656 | self.set | |
649 | self.flagNoMoreFiles |
|
657 | self.flagNoMoreFiles | |
650 |
|
658 | |||
651 | Return: |
|
659 | Return: | |
652 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
660 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
653 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
661 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
654 |
|
662 | |||
655 | Excepciones: |
|
663 | Excepciones: | |
656 | Si un determinado file no puede ser abierto |
|
664 | Si un determinado file no puede ser abierto | |
657 | """ |
|
665 | """ | |
658 | nFiles = 0 |
|
666 | nFiles = 0 | |
659 | fileOk_flag = False |
|
667 | fileOk_flag = False | |
660 | firstTime_flag = True |
|
668 | firstTime_flag = True | |
661 |
|
669 | |||
662 | self.set += 1 |
|
670 | self.set += 1 | |
663 |
|
671 | |||
664 | if self.set > 999: |
|
672 | if self.set > 999: | |
665 | self.set = 0 |
|
673 | self.set = 0 | |
666 | self.foldercounter += 1 |
|
674 | self.foldercounter += 1 | |
667 |
|
675 | |||
668 | #busca el 1er file disponible |
|
676 | #busca el 1er file disponible | |
669 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
677 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) | |
670 | if fullfilename: |
|
678 | if fullfilename: | |
671 | if self.__verifyFile(fullfilename, False): |
|
679 | if self.__verifyFile(fullfilename, False): | |
672 | fileOk_flag = True |
|
680 | fileOk_flag = True | |
673 |
|
681 | |||
674 | #si no encuentra un file entonces espera y vuelve a buscar |
|
682 | #si no encuentra un file entonces espera y vuelve a buscar | |
675 | if not(fileOk_flag): |
|
683 | if not(fileOk_flag): | |
676 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
684 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
677 |
|
685 | |||
678 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
686 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
679 | tries = self.nTries |
|
687 | tries = self.nTries | |
680 | else: |
|
688 | else: | |
681 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
689 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
682 |
|
690 | |||
683 | for nTries in range( tries ): |
|
691 | for nTries in range( tries ): | |
684 | if firstTime_flag: |
|
692 | if firstTime_flag: | |
685 | print "\t[Reading] Waiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
693 | print "\t[Reading] Waiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
686 | sleep( self.delay ) |
|
694 | sleep( self.delay ) | |
687 | else: |
|
695 | else: | |
688 | print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
696 | print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
689 |
|
697 | |||
690 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
698 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) | |
691 | if fullfilename: |
|
699 | if fullfilename: | |
692 | if self.__verifyFile(fullfilename): |
|
700 | if self.__verifyFile(fullfilename): | |
693 | fileOk_flag = True |
|
701 | fileOk_flag = True | |
694 | break |
|
702 | break | |
695 |
|
703 | |||
696 | if fileOk_flag: |
|
704 | if fileOk_flag: | |
697 | break |
|
705 | break | |
698 |
|
706 | |||
699 | firstTime_flag = False |
|
707 | firstTime_flag = False | |
700 |
|
708 | |||
701 | print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename |
|
709 | print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename | |
702 | self.set += 1 |
|
710 | self.set += 1 | |
703 |
|
711 | |||
704 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
712 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
705 | self.set = 0 |
|
713 | self.set = 0 | |
706 | self.doy += 1 |
|
714 | self.doy += 1 | |
707 | self.foldercounter = 0 |
|
715 | self.foldercounter = 0 | |
708 |
|
716 | |||
709 | if fileOk_flag: |
|
717 | if fileOk_flag: | |
710 | self.fileSize = os.path.getsize( fullfilename ) |
|
718 | self.fileSize = os.path.getsize( fullfilename ) | |
711 | self.filename = fullfilename |
|
719 | self.filename = fullfilename | |
712 | self.flagIsNewFile = 1 |
|
720 | self.flagIsNewFile = 1 | |
713 | if self.fp != None: self.fp.close() |
|
721 | if self.fp != None: self.fp.close() | |
714 | self.fp = open(fullfilename, 'rb') |
|
722 | self.fp = open(fullfilename, 'rb') | |
715 | self.flagNoMoreFiles = 0 |
|
723 | self.flagNoMoreFiles = 0 | |
716 | # print '[Reading] Setting the file: %s' % fullfilename |
|
724 | # print '[Reading] Setting the file: %s' % fullfilename | |
717 | else: |
|
725 | else: | |
718 | self.fileSize = 0 |
|
726 | self.fileSize = 0 | |
719 | self.filename = None |
|
727 | self.filename = None | |
720 | self.flagIsNewFile = 0 |
|
728 | self.flagIsNewFile = 0 | |
721 | self.fp = None |
|
729 | self.fp = None | |
722 | self.flagNoMoreFiles = 1 |
|
730 | self.flagNoMoreFiles = 1 | |
723 | # print '[Reading] No more files to read' |
|
731 | # print '[Reading] No more files to read' | |
724 |
|
732 | |||
725 | return fileOk_flag |
|
733 | return fileOk_flag | |
726 |
|
734 | |||
727 | def setNextFile(self): |
|
735 | def setNextFile(self): | |
728 | if self.fp != None: |
|
736 | if self.fp != None: | |
729 | self.fp.close() |
|
737 | self.fp.close() | |
730 |
|
738 | |||
731 | if self.online: |
|
739 | if self.online: | |
732 | newFile = self.__setNextFileOnline() |
|
740 | newFile = self.__setNextFileOnline() | |
733 | else: |
|
741 | else: | |
734 | newFile = self.__setNextFileOffline() |
|
742 | newFile = self.__setNextFileOffline() | |
735 |
|
743 | |||
736 | if not(newFile): |
|
744 | if not(newFile): | |
737 | print '[Reading] No more files to read' |
|
745 | print '[Reading] No more files to read' | |
738 | return 0 |
|
746 | return 0 | |
739 |
|
747 | |||
740 | print '[Reading] Setting the file: %s' % self.filename |
|
748 | print '[Reading] Setting the file: %s' % self.filename | |
741 |
|
749 | |||
742 | self.__readFirstHeader() |
|
750 | self.__readFirstHeader() | |
743 | self.nReadBlocks = 0 |
|
751 | self.nReadBlocks = 0 | |
744 | return 1 |
|
752 | return 1 | |
745 |
|
753 | |||
746 | def __waitNewBlock(self): |
|
754 | def __waitNewBlock(self): | |
747 | """ |
|
755 | """ | |
748 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
756 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
749 |
|
757 | |||
750 | Si el modo de lectura es OffLine siempre retorn 0 |
|
758 | Si el modo de lectura es OffLine siempre retorn 0 | |
751 | """ |
|
759 | """ | |
752 | if not self.online: |
|
760 | if not self.online: | |
753 | return 0 |
|
761 | return 0 | |
754 |
|
762 | |||
755 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
763 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |
756 | return 0 |
|
764 | return 0 | |
757 |
|
765 | |||
758 | currentPointer = self.fp.tell() |
|
766 | currentPointer = self.fp.tell() | |
759 |
|
767 | |||
760 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
768 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
761 |
|
769 | |||
762 | for nTries in range( self.nTries ): |
|
770 | for nTries in range( self.nTries ): | |
763 |
|
771 | |||
764 | self.fp.close() |
|
772 | self.fp.close() | |
765 | self.fp = open( self.filename, 'rb' ) |
|
773 | self.fp = open( self.filename, 'rb' ) | |
766 | self.fp.seek( currentPointer ) |
|
774 | self.fp.seek( currentPointer ) | |
767 |
|
775 | |||
768 | self.fileSize = os.path.getsize( self.filename ) |
|
776 | self.fileSize = os.path.getsize( self.filename ) | |
769 | currentSize = self.fileSize - currentPointer |
|
777 | currentSize = self.fileSize - currentPointer | |
770 |
|
778 | |||
771 | if ( currentSize >= neededSize ): |
|
779 | if ( currentSize >= neededSize ): | |
772 | self.basicHeaderObj.read(self.fp) |
|
780 | self.basicHeaderObj.read(self.fp) | |
773 | return 1 |
|
781 | return 1 | |
774 |
|
782 | |||
775 | if self.fileSize == self.fileSizeByHeader: |
|
783 | if self.fileSize == self.fileSizeByHeader: | |
776 | # self.flagEoF = True |
|
784 | # self.flagEoF = True | |
777 | return 0 |
|
785 | return 0 | |
778 |
|
786 | |||
779 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
787 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
780 | sleep( self.delay ) |
|
788 | sleep( self.delay ) | |
781 |
|
789 | |||
782 |
|
790 | |||
783 | return 0 |
|
791 | return 0 | |
784 |
|
792 | |||
785 | def waitDataBlock(self,pointer_location): |
|
793 | def waitDataBlock(self,pointer_location): | |
786 |
|
794 | |||
787 | currentPointer = pointer_location |
|
795 | currentPointer = pointer_location | |
788 |
|
796 | |||
789 | neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize |
|
797 | neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize | |
790 |
|
798 | |||
791 | for nTries in range( self.nTries ): |
|
799 | for nTries in range( self.nTries ): | |
792 | self.fp.close() |
|
800 | self.fp.close() | |
793 | self.fp = open( self.filename, 'rb' ) |
|
801 | self.fp = open( self.filename, 'rb' ) | |
794 | self.fp.seek( currentPointer ) |
|
802 | self.fp.seek( currentPointer ) | |
795 |
|
803 | |||
796 | self.fileSize = os.path.getsize( self.filename ) |
|
804 | self.fileSize = os.path.getsize( self.filename ) | |
797 | currentSize = self.fileSize - currentPointer |
|
805 | currentSize = self.fileSize - currentPointer | |
798 |
|
806 | |||
799 | if ( currentSize >= neededSize ): |
|
807 | if ( currentSize >= neededSize ): | |
800 | return 1 |
|
808 | return 1 | |
801 |
|
809 | |||
802 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
810 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
803 | sleep( self.delay ) |
|
811 | sleep( self.delay ) | |
804 |
|
812 | |||
805 | return 0 |
|
813 | return 0 | |
806 |
|
814 | |||
807 | def __jumpToLastBlock(self): |
|
815 | def __jumpToLastBlock(self): | |
808 |
|
816 | |||
809 | if not(self.__isFirstTimeOnline): |
|
817 | if not(self.__isFirstTimeOnline): | |
810 | return |
|
818 | return | |
811 |
|
819 | |||
812 | csize = self.fileSize - self.fp.tell() |
|
820 | csize = self.fileSize - self.fp.tell() | |
813 | blocksize = self.processingHeaderObj.blockSize |
|
821 | blocksize = self.processingHeaderObj.blockSize | |
814 |
|
822 | |||
815 | #salta el primer bloque de datos |
|
823 | #salta el primer bloque de datos | |
816 | if csize > self.processingHeaderObj.blockSize: |
|
824 | if csize > self.processingHeaderObj.blockSize: | |
817 | self.fp.seek(self.fp.tell() + blocksize) |
|
825 | self.fp.seek(self.fp.tell() + blocksize) | |
818 | else: |
|
826 | else: | |
819 | return |
|
827 | return | |
820 |
|
828 | |||
821 | csize = self.fileSize - self.fp.tell() |
|
829 | csize = self.fileSize - self.fp.tell() | |
822 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
830 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
823 | while True: |
|
831 | while True: | |
824 |
|
832 | |||
825 | if self.fp.tell()<self.fileSize: |
|
833 | if self.fp.tell()<self.fileSize: | |
826 | self.fp.seek(self.fp.tell() + neededsize) |
|
834 | self.fp.seek(self.fp.tell() + neededsize) | |
827 | else: |
|
835 | else: | |
828 | self.fp.seek(self.fp.tell() - neededsize) |
|
836 | self.fp.seek(self.fp.tell() - neededsize) | |
829 | break |
|
837 | break | |
830 |
|
838 | |||
831 | # csize = self.fileSize - self.fp.tell() |
|
839 | # csize = self.fileSize - self.fp.tell() | |
832 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
840 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
833 | # factor = int(csize/neededsize) |
|
841 | # factor = int(csize/neededsize) | |
834 | # if factor > 0: |
|
842 | # if factor > 0: | |
835 | # self.fp.seek(self.fp.tell() + factor*neededsize) |
|
843 | # self.fp.seek(self.fp.tell() + factor*neededsize) | |
836 |
|
844 | |||
837 | self.flagIsNewFile = 0 |
|
845 | self.flagIsNewFile = 0 | |
838 | self.__isFirstTimeOnline = 0 |
|
846 | self.__isFirstTimeOnline = 0 | |
839 |
|
847 | |||
840 | def __setNewBlock(self): |
|
848 | def __setNewBlock(self): | |
841 |
|
849 | |||
842 | if self.fp == None: |
|
850 | if self.fp == None: | |
843 | return 0 |
|
851 | return 0 | |
844 |
|
852 | |||
845 | if self.online: |
|
853 | if self.online: | |
846 | self.__jumpToLastBlock() |
|
854 | self.__jumpToLastBlock() | |
847 |
|
855 | |||
848 | if self.flagIsNewFile: |
|
856 | if self.flagIsNewFile: | |
849 | return 1 |
|
857 | return 1 | |
850 |
|
858 | |||
851 | self.lastUTTime = self.basicHeaderObj.utc |
|
859 | self.lastUTTime = self.basicHeaderObj.utc | |
852 | currentSize = self.fileSize - self.fp.tell() |
|
860 | currentSize = self.fileSize - self.fp.tell() | |
853 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
861 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
854 |
|
862 | |||
855 | if (currentSize >= neededSize): |
|
863 | if (currentSize >= neededSize): | |
856 | self.basicHeaderObj.read(self.fp) |
|
864 | self.basicHeaderObj.read(self.fp) | |
857 | return 1 |
|
865 | return 1 | |
858 |
|
866 | |||
859 | if self.__waitNewBlock(): |
|
867 | if self.__waitNewBlock(): | |
860 | return 1 |
|
868 | return 1 | |
861 |
|
869 | |||
862 | if not(self.setNextFile()): |
|
870 | if not(self.setNextFile()): | |
863 | return 0 |
|
871 | return 0 | |
864 |
|
872 | |||
865 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
873 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
866 |
|
874 | |||
867 | self.flagDiscontinuousBlock = 0 |
|
875 | self.flagDiscontinuousBlock = 0 | |
868 |
|
876 | |||
869 | if deltaTime > self.maxTimeStep: |
|
877 | if deltaTime > self.maxTimeStep: | |
870 | self.flagDiscontinuousBlock = 1 |
|
878 | self.flagDiscontinuousBlock = 1 | |
871 |
|
879 | |||
872 | return 1 |
|
880 | return 1 | |
873 |
|
881 | |||
874 | def readNextBlock(self): |
|
882 | def readNextBlock(self): | |
|
883 | ||||
875 | if not(self.__setNewBlock()): |
|
884 | if not(self.__setNewBlock()): | |
876 | return 0 |
|
885 | return 0 | |
877 |
|
886 | |||
878 | if not(self.readBlock()): |
|
887 | if not(self.readBlock()): | |
879 | return 0 |
|
888 | return 0 | |
880 |
|
889 | |||
|
890 | print "[Reading] Block No. %d/%d -> %s" %(self.basicHeaderObj.dataBlock+1, | |||
|
891 | self.processingHeaderObj.dataBlocksPerFile, | |||
|
892 | self.dataOut.datatime.ctime()) | |||
881 | return 1 |
|
893 | return 1 | |
882 |
|
894 | |||
883 | def __readFirstHeader(self): |
|
895 | def __readFirstHeader(self): | |
884 |
|
896 | |||
885 | self.basicHeaderObj.read(self.fp) |
|
897 | self.basicHeaderObj.read(self.fp) | |
886 | self.systemHeaderObj.read(self.fp) |
|
898 | self.systemHeaderObj.read(self.fp) | |
887 | self.radarControllerHeaderObj.read(self.fp) |
|
899 | self.radarControllerHeaderObj.read(self.fp) | |
888 | self.processingHeaderObj.read(self.fp) |
|
900 | self.processingHeaderObj.read(self.fp) | |
889 |
|
901 | |||
890 | self.firstHeaderSize = self.basicHeaderObj.size |
|
902 | self.firstHeaderSize = self.basicHeaderObj.size | |
891 |
|
903 | |||
892 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
904 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
893 | if datatype == 0: |
|
905 | if datatype == 0: | |
894 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
906 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
895 | elif datatype == 1: |
|
907 | elif datatype == 1: | |
896 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
908 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
897 | elif datatype == 2: |
|
909 | elif datatype == 2: | |
898 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
910 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
899 | elif datatype == 3: |
|
911 | elif datatype == 3: | |
900 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
912 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
901 | elif datatype == 4: |
|
913 | elif datatype == 4: | |
902 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
914 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
903 | elif datatype == 5: |
|
915 | elif datatype == 5: | |
904 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
916 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
905 | else: |
|
917 | else: | |
906 | raise ValueError, 'Data type was not defined' |
|
918 | raise ValueError, 'Data type was not defined' | |
907 |
|
919 | |||
908 | self.dtype = datatype_str |
|
920 | self.dtype = datatype_str | |
909 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
921 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
910 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
922 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
911 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
923 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
912 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
924 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
913 | self.getBlockDimension() |
|
925 | self.getBlockDimension() | |
914 |
|
926 | |||
915 | def __verifyFile(self, filename, msgFlag=True): |
|
927 | def __verifyFile(self, filename, msgFlag=True): | |
916 | msg = None |
|
928 | msg = None | |
917 | try: |
|
929 | try: | |
918 | fp = open(filename, 'rb') |
|
930 | fp = open(filename, 'rb') | |
919 | currentPosition = fp.tell() |
|
931 | currentPosition = fp.tell() | |
920 | except IOError: |
|
932 | except IOError: | |
921 | traceback.print_exc() |
|
933 | traceback.print_exc() | |
922 | if msgFlag: |
|
934 | if msgFlag: | |
923 | print "[Reading] The file %s can't be opened" % (filename) |
|
935 | print "[Reading] The file %s can't be opened" % (filename) | |
924 | return False |
|
936 | return False | |
925 |
|
937 | |||
926 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
938 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
927 |
|
939 | |||
928 | if neededSize == 0: |
|
940 | if neededSize == 0: | |
929 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
941 | basicHeaderObj = BasicHeader(LOCALTIME) | |
930 | systemHeaderObj = SystemHeader() |
|
942 | systemHeaderObj = SystemHeader() | |
931 | radarControllerHeaderObj = RadarControllerHeader() |
|
943 | radarControllerHeaderObj = RadarControllerHeader() | |
932 | processingHeaderObj = ProcessingHeader() |
|
944 | processingHeaderObj = ProcessingHeader() | |
933 |
|
945 | |||
934 | try: |
|
946 | try: | |
935 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
947 | if not( basicHeaderObj.read(fp) ): raise IOError | |
936 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
948 | if not( systemHeaderObj.read(fp) ): raise IOError | |
937 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
949 | if not( radarControllerHeaderObj.read(fp) ): raise IOError | |
938 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
950 | if not( processingHeaderObj.read(fp) ): raise IOError | |
939 | # data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
951 | # data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
940 |
|
952 | |||
941 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
953 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
942 |
|
954 | |||
943 | except IOError: |
|
955 | except IOError: | |
944 | traceback.print_exc() |
|
956 | traceback.print_exc() | |
945 | if msgFlag: |
|
957 | if msgFlag: | |
946 | print "[Reading] The file %s is empty or it hasn't enough data" % filename |
|
958 | print "[Reading] The file %s is empty or it hasn't enough data" % filename | |
947 |
|
959 | |||
948 | fp.close() |
|
960 | fp.close() | |
949 | return False |
|
961 | return False | |
950 | else: |
|
962 | else: | |
951 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename |
|
963 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename | |
952 |
|
964 | |||
953 | fp.close() |
|
965 | fp.close() | |
954 | fileSize = os.path.getsize(filename) |
|
966 | fileSize = os.path.getsize(filename) | |
955 | currentSize = fileSize - currentPosition |
|
967 | currentSize = fileSize - currentPosition | |
956 | if currentSize < neededSize: |
|
968 | if currentSize < neededSize: | |
957 | if msgFlag and (msg != None): |
|
969 | if msgFlag and (msg != None): | |
958 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
970 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
959 | return False |
|
971 | return False | |
960 |
|
972 | |||
961 | return True |
|
973 | return True | |
962 |
|
974 | |||
963 | def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True): |
|
975 | def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True): | |
964 |
|
976 | |||
965 | dateList = [] |
|
977 | dateList = [] | |
966 | pathList = [] |
|
978 | pathList = [] | |
967 |
|
979 | |||
968 | if not walk: |
|
980 | if not walk: | |
969 | #pathList.append(path) |
|
981 | #pathList.append(path) | |
970 | multi_path = path.split(',') |
|
982 | multi_path = path.split(',') | |
971 | for single_path in multi_path: |
|
983 | for single_path in multi_path: | |
972 |
|
984 | |||
973 | if not os.path.isdir(single_path): |
|
985 | if not os.path.isdir(single_path): | |
974 | continue |
|
986 | continue | |
975 |
|
987 | |||
976 | ok = False |
|
988 | ok = False | |
977 | fileList = glob.glob1(single_path, "*"+ext) |
|
989 | fileList = glob.glob1(single_path, "*"+ext) | |
978 |
|
990 | |||
979 | for thisFile in fileList: |
|
991 | for thisFile in fileList: | |
980 |
|
992 | |||
981 | if not os.path.isfile(os.path.join(single_path, thisFile)): |
|
993 | if not os.path.isfile(os.path.join(single_path, thisFile)): | |
982 | continue |
|
994 | continue | |
983 |
|
995 | |||
984 | if not isRadarFile(thisFile): |
|
996 | if not isRadarFile(thisFile): | |
985 | continue |
|
997 | continue | |
986 |
|
998 | |||
987 | ok = True |
|
999 | ok = True | |
988 | thisDate = getDateFromRadarFile(thisFile) |
|
1000 | thisDate = getDateFromRadarFile(thisFile) | |
989 |
|
1001 | |||
990 | if thisDate not in dateList: |
|
1002 | if thisDate not in dateList: | |
991 | dateList.append(thisDate) |
|
1003 | dateList.append(thisDate) | |
992 |
|
1004 | |||
993 | if ok: |
|
1005 | if ok: | |
994 | pathList.append(single_path) |
|
1006 | pathList.append(single_path) | |
995 |
|
1007 | |||
996 | return dateList |
|
1008 | return dateList | |
997 |
|
1009 | |||
998 | multi_path = path.split(',') |
|
1010 | multi_path = path.split(',') | |
999 | for single_path in multi_path: |
|
1011 | for single_path in multi_path: | |
1000 |
|
1012 | |||
1001 | if not os.path.isdir(single_path): |
|
1013 | if not os.path.isdir(single_path): | |
1002 | continue |
|
1014 | continue | |
1003 |
|
1015 | |||
1004 | dirList = [] |
|
1016 | dirList = [] | |
1005 |
|
1017 | |||
1006 | for thisPath in os.listdir(single_path): |
|
1018 | for thisPath in os.listdir(single_path): | |
1007 |
|
1019 | |||
1008 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
1020 | if not os.path.isdir(os.path.join(single_path,thisPath)): | |
1009 | continue |
|
1021 | continue | |
1010 |
|
1022 | |||
1011 | if not isRadarFolder(thisPath): |
|
1023 | if not isRadarFolder(thisPath): | |
1012 | continue |
|
1024 | continue | |
1013 |
|
1025 | |||
1014 | dirList.append(thisPath) |
|
1026 | dirList.append(thisPath) | |
1015 |
|
1027 | |||
1016 | if not dirList: |
|
1028 | if not dirList: | |
1017 | return dateList |
|
1029 | return dateList | |
1018 |
|
1030 | |||
1019 | if startDate and endDate: |
|
1031 | if startDate and endDate: | |
1020 | thisDate = startDate |
|
1032 | thisDate = startDate | |
1021 |
|
1033 | |||
1022 | while(thisDate <= endDate): |
|
1034 | while(thisDate <= endDate): | |
1023 | year = thisDate.timetuple().tm_year |
|
1035 | year = thisDate.timetuple().tm_year | |
1024 | doy = thisDate.timetuple().tm_yday |
|
1036 | doy = thisDate.timetuple().tm_yday | |
1025 |
|
1037 | |||
1026 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
1038 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') | |
1027 | if len(matchlist) == 0: |
|
1039 | if len(matchlist) == 0: | |
1028 | thisDate += datetime.timedelta(1) |
|
1040 | thisDate += datetime.timedelta(1) | |
1029 | continue |
|
1041 | continue | |
1030 |
|
1042 | |||
1031 | for match in matchlist: |
|
1043 | for match in matchlist: | |
1032 | pathList.append(os.path.join(single_path,match,expLabel)) |
|
1044 | pathList.append(os.path.join(single_path,match,expLabel)) | |
1033 | dateList.append(thisDate) |
|
1045 | dateList.append(thisDate) | |
1034 |
|
1046 | |||
1035 | thisDate += datetime.timedelta(1) |
|
1047 | thisDate += datetime.timedelta(1) | |
1036 | else: |
|
1048 | else: | |
1037 | for thisDir in dirList: |
|
1049 | for thisDir in dirList: | |
1038 | year = int(thisDir[1:5]) |
|
1050 | year = int(thisDir[1:5]) | |
1039 | doy = int(thisDir[5:8]) |
|
1051 | doy = int(thisDir[5:8]) | |
1040 | thisDate = datetime.date(year,1,1) + datetime.timedelta(doy-1) |
|
1052 | thisDate = datetime.date(year,1,1) + datetime.timedelta(doy-1) | |
1041 |
|
1053 | |||
1042 | pathList.append(os.path.join(single_path,thisDir,expLabel)) |
|
1054 | pathList.append(os.path.join(single_path,thisDir,expLabel)) | |
1043 | dateList.append(thisDate) |
|
1055 | dateList.append(thisDate) | |
1044 |
|
1056 | |||
1045 | return dateList |
|
1057 | return dateList | |
1046 |
|
1058 | |||
1047 |
|
1059 | |||
1048 | def setup(self, |
|
1060 | def setup(self, | |
1049 | path=None, |
|
1061 | path=None, | |
1050 | startDate=None, |
|
1062 | startDate=None, | |
1051 | endDate=None, |
|
1063 | endDate=None, | |
1052 | startTime=datetime.time(0,0,0), |
|
1064 | startTime=datetime.time(0,0,0), | |
1053 | endTime=datetime.time(23,59,59), |
|
1065 | endTime=datetime.time(23,59,59), | |
1054 | set=None, |
|
1066 | set=None, | |
1055 | expLabel = "", |
|
1067 | expLabel = "", | |
1056 | ext = None, |
|
1068 | ext = None, | |
1057 | online = False, |
|
1069 | online = False, | |
1058 | delay = 60, |
|
1070 | delay = 60, | |
1059 | walk = True, |
|
1071 | walk = True, | |
1060 | getblock = False, |
|
1072 | getblock = False, | |
1061 | nTxs = 1): |
|
1073 | nTxs = 1): | |
1062 |
|
1074 | |||
1063 | if path == None: |
|
1075 | if path == None: | |
1064 | raise ValueError, "[Reading] The path is not valid" |
|
1076 | raise ValueError, "[Reading] The path is not valid" | |
1065 |
|
1077 | |||
1066 | if ext == None: |
|
1078 | if ext == None: | |
1067 | ext = self.ext |
|
1079 | ext = self.ext | |
1068 |
|
1080 | |||
1069 | if online: |
|
1081 | if online: | |
1070 | print "[Reading] Searching files in online mode..." |
|
1082 | print "[Reading] Searching files in online mode..." | |
1071 |
|
1083 | |||
1072 | for nTries in range( self.nTries ): |
|
1084 | for nTries in range( self.nTries ): | |
1073 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) |
|
1085 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) | |
1074 |
|
1086 | |||
1075 | if fullpath: |
|
1087 | if fullpath: | |
1076 | break |
|
1088 | break | |
1077 |
|
1089 | |||
1078 | print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
1090 | print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
1079 | sleep( self.delay ) |
|
1091 | sleep( self.delay ) | |
1080 |
|
1092 | |||
1081 | if not(fullpath): |
|
1093 | if not(fullpath): | |
1082 | print "[Reading] There 'isn't any valid file in %s" % path |
|
1094 | print "[Reading] There 'isn't any valid file in %s" % path | |
1083 | return None |
|
1095 | return None | |
1084 |
|
1096 | |||
1085 | self.year = year |
|
1097 | self.year = year | |
1086 | self.doy = doy |
|
1098 | self.doy = doy | |
1087 | self.set = set - 1 |
|
1099 | self.set = set - 1 | |
1088 | self.path = path |
|
1100 | self.path = path | |
1089 | self.foldercounter = foldercounter |
|
1101 | self.foldercounter = foldercounter | |
1090 | last_set = None |
|
1102 | last_set = None | |
1091 |
|
1103 | |||
1092 | else: |
|
1104 | else: | |
1093 | print "[Reading] Searching files in offline mode ..." |
|
1105 | print "[Reading] Searching files in offline mode ..." | |
1094 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
1106 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
1095 | startTime=startTime, endTime=endTime, |
|
1107 | startTime=startTime, endTime=endTime, | |
1096 | set=set, expLabel=expLabel, ext=ext, |
|
1108 | set=set, expLabel=expLabel, ext=ext, | |
1097 | walk=walk) |
|
1109 | walk=walk) | |
1098 |
|
1110 | |||
1099 | if not(pathList): |
|
1111 | if not(pathList): | |
1100 | print "[Reading] No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
1112 | print "[Reading] No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
1101 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
1113 | datetime.datetime.combine(startDate,startTime).ctime(), | |
1102 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
1114 | datetime.datetime.combine(endDate,endTime).ctime()) | |
1103 |
|
1115 | |||
1104 | sys.exit(-1) |
|
1116 | sys.exit(-1) | |
1105 |
|
1117 | |||
1106 |
|
1118 | |||
1107 | self.fileIndex = -1 |
|
1119 | self.fileIndex = -1 | |
1108 | self.pathList = pathList |
|
1120 | self.pathList = pathList | |
1109 | self.filenameList = filenameList |
|
1121 | self.filenameList = filenameList | |
1110 | file_name = os.path.basename(filenameList[-1]) |
|
1122 | file_name = os.path.basename(filenameList[-1]) | |
1111 | basename, ext = os.path.splitext(file_name) |
|
1123 | basename, ext = os.path.splitext(file_name) | |
1112 | last_set = int(basename[-3:]) |
|
1124 | last_set = int(basename[-3:]) | |
1113 |
|
1125 | |||
1114 | self.online = online |
|
1126 | self.online = online | |
1115 | self.delay = delay |
|
1127 | self.delay = delay | |
1116 | ext = ext.lower() |
|
1128 | ext = ext.lower() | |
1117 | self.ext = ext |
|
1129 | self.ext = ext | |
1118 | self.getByBlock = getblock |
|
1130 | self.getByBlock = getblock | |
1119 | self.nTxs = int(nTxs) |
|
1131 | self.nTxs = int(nTxs) | |
1120 |
|
1132 | |||
1121 | if not(self.setNextFile()): |
|
1133 | if not(self.setNextFile()): | |
1122 | if (startDate!=None) and (endDate!=None): |
|
1134 | if (startDate!=None) and (endDate!=None): | |
1123 | print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
1135 | print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
1124 | elif startDate != None: |
|
1136 | elif startDate != None: | |
1125 | print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
1137 | print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
1126 | else: |
|
1138 | else: | |
1127 | print "[Reading] No files" |
|
1139 | print "[Reading] No files" | |
1128 |
|
1140 | |||
1129 | sys.exit(-1) |
|
1141 | sys.exit(-1) | |
1130 |
|
1142 | |||
1131 |
|
|
1143 | self.getBasicHeader() | |
|
1144 | ||||
1132 | if last_set != None: |
|
1145 | if last_set != None: | |
1133 | self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock |
|
1146 | self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock | |
1134 | return |
|
1147 | return | |
1135 |
|
1148 | |||
1136 | def getBasicHeader(self): |
|
1149 | def getBasicHeader(self): | |
1137 |
|
1150 | |||
1138 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds |
|
1151 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds | |
1139 |
|
1152 | |||
1140 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
1153 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
1141 |
|
1154 | |||
1142 | self.dataOut.timeZone = self.basicHeaderObj.timeZone |
|
1155 | self.dataOut.timeZone = self.basicHeaderObj.timeZone | |
1143 |
|
1156 | |||
1144 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag |
|
1157 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag | |
1145 |
|
1158 | |||
1146 | self.dataOut.errorCount = self.basicHeaderObj.errorCount |
|
1159 | self.dataOut.errorCount = self.basicHeaderObj.errorCount | |
1147 |
|
1160 | |||
1148 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
1161 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime | |
1149 |
|
1162 | |||
1150 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
1163 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
1151 |
|
1164 | |||
1152 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
1165 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs | |
1153 |
|
1166 | |||
1154 |
|
1167 | |||
1155 | def getFirstHeader(self): |
|
1168 | def getFirstHeader(self): | |
1156 |
|
1169 | |||
1157 | raise ValueError, "This method has not been implemented" |
|
1170 | raise ValueError, "This method has not been implemented" | |
1158 |
|
1171 | |||
1159 | def getData(self): |
|
1172 | def getData(self): | |
1160 |
|
1173 | |||
1161 | raise ValueError, "This method has not been implemented" |
|
1174 | raise ValueError, "This method has not been implemented" | |
1162 |
|
1175 | |||
1163 | def hasNotDataInBuffer(self): |
|
1176 | def hasNotDataInBuffer(self): | |
1164 |
|
1177 | |||
1165 | raise ValueError, "This method has not been implemented" |
|
1178 | raise ValueError, "This method has not been implemented" | |
1166 |
|
1179 | |||
1167 | def readBlock(self): |
|
1180 | def readBlock(self): | |
1168 |
|
1181 | |||
1169 | raise ValueError, "This method has not been implemented" |
|
1182 | raise ValueError, "This method has not been implemented" | |
1170 |
|
1183 | |||
1171 | def isEndProcess(self): |
|
1184 | def isEndProcess(self): | |
1172 |
|
1185 | |||
1173 | return self.flagNoMoreFiles |
|
1186 | return self.flagNoMoreFiles | |
1174 |
|
1187 | |||
1175 | def printReadBlocks(self): |
|
1188 | def printReadBlocks(self): | |
1176 |
|
1189 | |||
1177 | print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks |
|
1190 | print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks | |
1178 |
|
1191 | |||
1179 | def printTotalBlocks(self): |
|
1192 | def printTotalBlocks(self): | |
1180 |
|
1193 | |||
1181 | print "[Reading] Number of read blocks %04d" %self.nTotalBlocks |
|
1194 | print "[Reading] Number of read blocks %04d" %self.nTotalBlocks | |
1182 |
|
1195 | |||
1183 | def printNumberOfBlock(self): |
|
1196 | def printNumberOfBlock(self): | |
1184 |
|
1197 | |||
1185 | if self.flagIsNewBlock: |
|
1198 | if self.flagIsNewBlock: | |
1186 |
print "[Reading] Block No. % |
|
1199 | print "[Reading] Block No. %d/%d -> %s" %(self.basicHeaderObj.dataBlock+1, | |
|
1200 | self.processingHeaderObj.dataBlocksPerFile, | |||
|
1201 | self.dataOut.datatime.ctime()) | |||
|
1202 | ||||
1187 | self.dataOut.blocknow = self.basicHeaderObj.dataBlock |
|
1203 | self.dataOut.blocknow = self.basicHeaderObj.dataBlock | |
1188 |
|
1204 | |||
1189 | def printInfo(self): |
|
1205 | def printInfo(self): | |
1190 |
|
1206 | |||
1191 | if self.__printInfo == False: |
|
1207 | if self.__printInfo == False: | |
1192 | return |
|
1208 | return | |
1193 |
|
1209 | |||
1194 | self.basicHeaderObj.printInfo() |
|
1210 | self.basicHeaderObj.printInfo() | |
1195 | self.systemHeaderObj.printInfo() |
|
1211 | self.systemHeaderObj.printInfo() | |
1196 | self.radarControllerHeaderObj.printInfo() |
|
1212 | self.radarControllerHeaderObj.printInfo() | |
1197 | self.processingHeaderObj.printInfo() |
|
1213 | self.processingHeaderObj.printInfo() | |
1198 |
|
1214 | |||
1199 | self.__printInfo = False |
|
1215 | self.__printInfo = False | |
1200 |
|
1216 | |||
1201 |
|
1217 | |||
1202 | def run(self, **kwargs): |
|
1218 | def run(self, **kwargs): | |
1203 |
|
1219 | |||
1204 | if not(self.isConfig): |
|
1220 | if not(self.isConfig): | |
1205 |
|
1221 | |||
1206 | # self.dataOut = dataOut |
|
1222 | # self.dataOut = dataOut | |
1207 | self.setup(**kwargs) |
|
1223 | self.setup(**kwargs) | |
1208 | self.isConfig = True |
|
1224 | self.isConfig = True | |
1209 |
|
1225 | |||
1210 | self.getData() |
|
1226 | self.getData() | |
1211 |
|
1227 | |||
1212 | class JRODataWriter(JRODataIO): |
|
1228 | class JRODataWriter(JRODataIO): | |
1213 |
|
1229 | |||
1214 | """ |
|
1230 | """ | |
1215 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
1231 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
1216 | de los datos siempre se realiza por bloques. |
|
1232 | de los datos siempre se realiza por bloques. | |
1217 | """ |
|
1233 | """ | |
1218 |
|
1234 | |||
1219 | blockIndex = 0 |
|
1235 | blockIndex = 0 | |
1220 |
|
1236 | |||
1221 | path = None |
|
1237 | path = None | |
1222 |
|
1238 | |||
1223 | setFile = None |
|
1239 | setFile = None | |
1224 |
|
1240 | |||
1225 | profilesPerBlock = None |
|
1241 | profilesPerBlock = None | |
1226 |
|
1242 | |||
1227 | blocksPerFile = None |
|
1243 | blocksPerFile = None | |
1228 |
|
1244 | |||
1229 | nWriteBlocks = 0 |
|
1245 | nWriteBlocks = 0 | |
1230 |
|
1246 | |||
1231 | def __init__(self, dataOut=None): |
|
1247 | def __init__(self, dataOut=None): | |
1232 | raise ValueError, "Not implemented" |
|
1248 | raise ValueError, "Not implemented" | |
1233 |
|
1249 | |||
1234 |
|
1250 | |||
1235 | def hasAllDataInBuffer(self): |
|
1251 | def hasAllDataInBuffer(self): | |
1236 | raise ValueError, "Not implemented" |
|
1252 | raise ValueError, "Not implemented" | |
1237 |
|
1253 | |||
1238 |
|
1254 | |||
1239 | def setBlockDimension(self): |
|
1255 | def setBlockDimension(self): | |
1240 | raise ValueError, "Not implemented" |
|
1256 | raise ValueError, "Not implemented" | |
1241 |
|
1257 | |||
1242 |
|
1258 | |||
1243 | def writeBlock(self): |
|
1259 | def writeBlock(self): | |
1244 | raise ValueError, "No implemented" |
|
1260 | raise ValueError, "No implemented" | |
1245 |
|
1261 | |||
1246 |
|
1262 | |||
1247 | def putData(self): |
|
1263 | def putData(self): | |
1248 | raise ValueError, "No implemented" |
|
1264 | raise ValueError, "No implemented" | |
1249 |
|
1265 | |||
1250 |
|
1266 | |||
|
1267 | def getProcessFlags(self): | |||
|
1268 | ||||
|
1269 | processFlags = 0 | |||
|
1270 | ||||
|
1271 | dtype_index = get_dtype_index(self.dtype) | |||
|
1272 | procflag_dtype = get_procflag_dtype(dtype_index) | |||
|
1273 | ||||
|
1274 | processFlags += procflag_dtype | |||
|
1275 | ||||
|
1276 | if self.dataOut.flagDecodeData: | |||
|
1277 | processFlags += PROCFLAG.DECODE_DATA | |||
|
1278 | ||||
|
1279 | if self.dataOut.flagDeflipData: | |||
|
1280 | processFlags += PROCFLAG.DEFLIP_DATA | |||
|
1281 | ||||
|
1282 | if self.dataOut.code is not None: | |||
|
1283 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |||
|
1284 | ||||
|
1285 | if self.dataOut.nCohInt > 1: | |||
|
1286 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |||
|
1287 | ||||
|
1288 | if self.dataOut.type == "Spectra": | |||
|
1289 | if self.dataOut.nIncohInt > 1: | |||
|
1290 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |||
|
1291 | ||||
|
1292 | if self.dataOut.data_dc is not None: | |||
|
1293 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |||
|
1294 | ||||
|
1295 | return processFlags | |||
|
1296 | ||||
1251 | def setBasicHeader(self): |
|
1297 | def setBasicHeader(self): | |
1252 |
|
1298 | |||
1253 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
1299 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
1254 | self.basicHeaderObj.version = self.versionFile |
|
1300 | self.basicHeaderObj.version = self.versionFile | |
1255 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1301 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
1256 |
|
1302 | |||
1257 | utc = numpy.floor(self.dataOut.utctime) |
|
1303 | utc = numpy.floor(self.dataOut.utctime) | |
1258 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
1304 | milisecond = (self.dataOut.utctime - utc)* 1000.0 | |
1259 |
|
1305 | |||
1260 | self.basicHeaderObj.utc = utc |
|
1306 | self.basicHeaderObj.utc = utc | |
1261 | self.basicHeaderObj.miliSecond = milisecond |
|
1307 | self.basicHeaderObj.miliSecond = milisecond | |
1262 | self.basicHeaderObj.timeZone = self.dataOut.timeZone |
|
1308 | self.basicHeaderObj.timeZone = self.dataOut.timeZone | |
1263 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag |
|
1309 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag | |
1264 | self.basicHeaderObj.errorCount = self.dataOut.errorCount |
|
1310 | self.basicHeaderObj.errorCount = self.dataOut.errorCount | |
1265 |
|
1311 | |||
1266 | def setFirstHeader(self): |
|
1312 | def setFirstHeader(self): | |
1267 | """ |
|
1313 | """ | |
1268 | Obtiene una copia del First Header |
|
1314 | Obtiene una copia del First Header | |
1269 |
|
1315 | |||
1270 | Affected: |
|
1316 | Affected: | |
1271 |
|
1317 | |||
1272 | self.basicHeaderObj |
|
1318 | self.basicHeaderObj | |
1273 | self.systemHeaderObj |
|
1319 | self.systemHeaderObj | |
1274 | self.radarControllerHeaderObj |
|
1320 | self.radarControllerHeaderObj | |
1275 | self.processingHeaderObj self. |
|
1321 | self.processingHeaderObj self. | |
1276 |
|
1322 | |||
1277 | Return: |
|
1323 | Return: | |
1278 | None |
|
1324 | None | |
1279 | """ |
|
1325 | """ | |
1280 |
|
1326 | |||
1281 | raise ValueError, "No implemented" |
|
1327 | raise ValueError, "No implemented" | |
1282 |
|
1328 | |||
1283 | def __writeFirstHeader(self): |
|
1329 | def __writeFirstHeader(self): | |
1284 | """ |
|
1330 | """ | |
1285 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
1331 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
1286 |
|
1332 | |||
1287 | Affected: |
|
1333 | Affected: | |
1288 | __dataType |
|
1334 | __dataType | |
1289 |
|
1335 | |||
1290 | Return: |
|
1336 | Return: | |
1291 | None |
|
1337 | None | |
1292 | """ |
|
1338 | """ | |
1293 |
|
1339 | |||
1294 | # CALCULAR PARAMETROS |
|
1340 | # CALCULAR PARAMETROS | |
1295 |
|
1341 | |||
1296 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
1342 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
1297 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1343 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
1298 |
|
1344 | |||
1299 | self.basicHeaderObj.write(self.fp) |
|
1345 | self.basicHeaderObj.write(self.fp) | |
1300 | self.systemHeaderObj.write(self.fp) |
|
1346 | self.systemHeaderObj.write(self.fp) | |
1301 | self.radarControllerHeaderObj.write(self.fp) |
|
1347 | self.radarControllerHeaderObj.write(self.fp) | |
1302 | self.processingHeaderObj.write(self.fp) |
|
1348 | self.processingHeaderObj.write(self.fp) | |
1303 |
|
1349 | |||
1304 | self.dtype = self.dataOut.dtype |
|
1350 | ||
1305 |
|
1351 | |||
1306 | def __setNewBlock(self): |
|
1352 | def __setNewBlock(self): | |
1307 | """ |
|
1353 | """ | |
1308 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
1354 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
1309 |
|
1355 | |||
1310 | Return: |
|
1356 | Return: | |
1311 | 0 : si no pudo escribir nada |
|
1357 | 0 : si no pudo escribir nada | |
1312 | 1 : Si escribio el Basic el First Header |
|
1358 | 1 : Si escribio el Basic el First Header | |
1313 | """ |
|
1359 | """ | |
1314 | if self.fp == None: |
|
1360 | if self.fp == None: | |
1315 | self.setNextFile() |
|
1361 | self.setNextFile() | |
1316 |
|
1362 | |||
1317 | if self.flagIsNewFile: |
|
1363 | if self.flagIsNewFile: | |
1318 | return 1 |
|
1364 | return 1 | |
1319 |
|
1365 | |||
1320 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
1366 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
1321 | self.basicHeaderObj.write(self.fp) |
|
1367 | self.basicHeaderObj.write(self.fp) | |
1322 | return 1 |
|
1368 | return 1 | |
1323 |
|
1369 | |||
1324 | if not( self.setNextFile() ): |
|
1370 | if not( self.setNextFile() ): | |
1325 | return 0 |
|
1371 | return 0 | |
1326 |
|
1372 | |||
1327 | return 1 |
|
1373 | return 1 | |
1328 |
|
1374 | |||
1329 |
|
1375 | |||
1330 | def writeNextBlock(self): |
|
1376 | def writeNextBlock(self): | |
1331 | """ |
|
1377 | """ | |
1332 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1378 | Selecciona el bloque siguiente de datos y los escribe en un file | |
1333 |
|
1379 | |||
1334 | Return: |
|
1380 | Return: | |
1335 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1381 | 0 : Si no hizo pudo escribir el bloque de datos | |
1336 | 1 : Si no pudo escribir el bloque de datos |
|
1382 | 1 : Si no pudo escribir el bloque de datos | |
1337 | """ |
|
1383 | """ | |
1338 | if not( self.__setNewBlock() ): |
|
1384 | if not( self.__setNewBlock() ): | |
1339 | return 0 |
|
1385 | return 0 | |
1340 |
|
1386 | |||
1341 | self.writeBlock() |
|
1387 | self.writeBlock() | |
1342 |
|
1388 | |||
|
1389 | print "[Writing] Block No. %d/%d" %(self.blockIndex, self.processingHeaderObj.dataBlocksPerFile) | |||
|
1390 | ||||
1343 | return 1 |
|
1391 | return 1 | |
1344 |
|
1392 | |||
1345 | def setNextFile(self): |
|
1393 | def setNextFile(self): | |
1346 | """ |
|
1394 | """ | |
1347 | Determina el siguiente file que sera escrito |
|
1395 | Determina el siguiente file que sera escrito | |
1348 |
|
1396 | |||
1349 | Affected: |
|
1397 | Affected: | |
1350 | self.filename |
|
1398 | self.filename | |
1351 | self.subfolder |
|
1399 | self.subfolder | |
1352 | self.fp |
|
1400 | self.fp | |
1353 | self.setFile |
|
1401 | self.setFile | |
1354 | self.flagIsNewFile |
|
1402 | self.flagIsNewFile | |
1355 |
|
1403 | |||
1356 | Return: |
|
1404 | Return: | |
1357 | 0 : Si el archivo no puede ser escrito |
|
1405 | 0 : Si el archivo no puede ser escrito | |
1358 | 1 : Si el archivo esta listo para ser escrito |
|
1406 | 1 : Si el archivo esta listo para ser escrito | |
1359 | """ |
|
1407 | """ | |
1360 | ext = self.ext |
|
1408 | ext = self.ext | |
1361 | path = self.path |
|
1409 | path = self.path | |
1362 |
|
1410 | |||
1363 | if self.fp != None: |
|
1411 | if self.fp != None: | |
1364 | self.fp.close() |
|
1412 | self.fp.close() | |
1365 |
|
1413 | |||
1366 | timeTuple = time.localtime( self.dataOut.utctime) |
|
1414 | timeTuple = time.localtime( self.dataOut.utctime) | |
1367 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1415 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
1368 |
|
1416 | |||
1369 | fullpath = os.path.join( path, subfolder ) |
|
1417 | fullpath = os.path.join( path, subfolder ) | |
1370 | if not( os.path.exists(fullpath) ): |
|
1418 | if not( os.path.exists(fullpath) ): | |
1371 | os.mkdir(fullpath) |
|
1419 | os.mkdir(fullpath) | |
1372 | self.setFile = -1 #inicializo mi contador de seteo |
|
1420 | self.setFile = -1 #inicializo mi contador de seteo | |
1373 | else: |
|
1421 | else: | |
1374 | filesList = os.listdir( fullpath ) |
|
1422 | filesList = os.listdir( fullpath ) | |
1375 | if len( filesList ) > 0: |
|
1423 | if len( filesList ) > 0: | |
1376 | filesList = sorted( filesList, key=str.lower ) |
|
1424 | filesList = sorted( filesList, key=str.lower ) | |
1377 | filen = filesList[-1] |
|
1425 | filen = filesList[-1] | |
1378 | # el filename debera tener el siguiente formato |
|
1426 | # el filename debera tener el siguiente formato | |
1379 | # 0 1234 567 89A BCDE (hex) |
|
1427 | # 0 1234 567 89A BCDE (hex) | |
1380 | # x YYYY DDD SSS .ext |
|
1428 | # x YYYY DDD SSS .ext | |
1381 | if isNumber( filen[8:11] ): |
|
1429 | if isNumber( filen[8:11] ): | |
1382 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1430 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
1383 | else: |
|
1431 | else: | |
1384 | self.setFile = -1 |
|
1432 | self.setFile = -1 | |
1385 | else: |
|
1433 | else: | |
1386 | self.setFile = -1 #inicializo mi contador de seteo |
|
1434 | self.setFile = -1 #inicializo mi contador de seteo | |
1387 |
|
1435 | |||
1388 | setFile = self.setFile |
|
1436 | setFile = self.setFile | |
1389 | setFile += 1 |
|
1437 | setFile += 1 | |
1390 |
|
1438 | |||
1391 | filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
1439 | filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
1392 | timeTuple.tm_year, |
|
1440 | timeTuple.tm_year, | |
1393 | timeTuple.tm_yday, |
|
1441 | timeTuple.tm_yday, | |
1394 | setFile, |
|
1442 | setFile, | |
1395 | ext ) |
|
1443 | ext ) | |
1396 |
|
1444 | |||
1397 | filename = os.path.join( path, subfolder, filen ) |
|
1445 | filename = os.path.join( path, subfolder, filen ) | |
1398 |
|
1446 | |||
1399 | fp = open( filename,'wb' ) |
|
1447 | fp = open( filename,'wb' ) | |
1400 |
|
1448 | |||
1401 | self.blockIndex = 0 |
|
1449 | self.blockIndex = 0 | |
1402 |
|
1450 | |||
1403 | #guardando atributos |
|
1451 | #guardando atributos | |
1404 | self.filename = filename |
|
1452 | self.filename = filename | |
1405 | self.subfolder = subfolder |
|
1453 | self.subfolder = subfolder | |
1406 | self.fp = fp |
|
1454 | self.fp = fp | |
1407 | self.setFile = setFile |
|
1455 | self.setFile = setFile | |
1408 | self.flagIsNewFile = 1 |
|
1456 | self.flagIsNewFile = 1 | |
1409 |
|
1457 | |||
1410 | self.setFirstHeader() |
|
1458 | self.setFirstHeader() | |
1411 |
|
1459 | |||
1412 | print '[Writing] file: %s'%self.filename |
|
1460 | print '[Writing] Opening file: %s'%self.filename | |
1413 |
|
1461 | |||
1414 | self.__writeFirstHeader() |
|
1462 | self.__writeFirstHeader() | |
1415 |
|
1463 | |||
1416 | return 1 |
|
1464 | return 1 | |
1417 |
|
1465 | |||
1418 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None): |
|
1466 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None, datatype=2): | |
1419 | """ |
|
1467 | """ | |
1420 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1468 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1421 |
|
1469 | |||
1422 | Inputs: |
|
1470 | Inputs: | |
1423 | path : el path destino en el cual se escribiran los files a crear |
|
1471 | path : directory where data will be saved | |
1424 | format : formato en el cual sera salvado un file |
|
1472 | profilesPerBlock : number of profiles per block | |
1425 |
set |
|
1473 | set : file set | |
|
1474 | datatype : An integer number that defines data type: | |||
|
1475 | 0 : int8 (1 byte) | |||
|
1476 | 1 : int16 (2 bytes) | |||
|
1477 | 2 : int32 (4 bytes) | |||
|
1478 | 3 : int64 (8 bytes) | |||
|
1479 | 4 : float (4 bytes) | |||
|
1480 | 5 : double (8 bytes) | |||
1426 |
|
1481 | |||
1427 | Return: |
|
1482 | Return: | |
1428 | 0 : Si no realizo un buen seteo |
|
1483 | 0 : Si no realizo un buen seteo | |
1429 | 1 : Si realizo un buen seteo |
|
1484 | 1 : Si realizo un buen seteo | |
1430 | """ |
|
1485 | """ | |
1431 |
|
1486 | |||
1432 | if ext == None: |
|
1487 | if ext == None: | |
1433 | ext = self.ext |
|
1488 | ext = self.ext | |
1434 |
|
1489 | |||
1435 | ext = ext.lower() |
|
1490 | ext = ext.lower() | |
1436 |
|
1491 | |||
1437 | self.ext = ext |
|
1492 | self.ext = ext | |
1438 |
|
1493 | |||
1439 | self.path = path |
|
1494 | self.path = path | |
1440 |
|
1495 | |||
1441 | self.setFile = set - 1 |
|
1496 | self.setFile = set - 1 | |
1442 |
|
1497 | |||
1443 | self.blocksPerFile = blocksPerFile |
|
1498 | self.blocksPerFile = blocksPerFile | |
1444 |
|
1499 | |||
1445 | self.profilesPerBlock = profilesPerBlock |
|
1500 | self.profilesPerBlock = profilesPerBlock | |
1446 |
|
1501 | |||
1447 | self.dataOut = dataOut |
|
1502 | self.dataOut = dataOut | |
1448 |
|
1503 | |||
|
1504 | #By default | |||
|
1505 | self.dtype = self.dataOut.dtype | |||
|
1506 | ||||
|
1507 | if datatype is not None: | |||
|
1508 | self.dtype = get_numpy_dtype(datatype) | |||
|
1509 | ||||
1449 | if not(self.setNextFile()): |
|
1510 | if not(self.setNextFile()): | |
1450 | print "[Writing] There isn't a next file" |
|
1511 | print "[Writing] There isn't a next file" | |
1451 | return 0 |
|
1512 | return 0 | |
1452 |
|
1513 | |||
1453 | self.setBlockDimension() |
|
1514 | self.setBlockDimension() | |
1454 |
|
1515 | |||
1455 | return 1 |
|
1516 | return 1 | |
1456 |
|
1517 | |||
1457 | def run(self, dataOut, **kwargs): |
|
1518 | def run(self, dataOut, **kwargs): | |
1458 |
|
1519 | |||
1459 | if not(self.isConfig): |
|
1520 | if not(self.isConfig): | |
1460 |
|
1521 | |||
1461 | self.setup(dataOut, **kwargs) |
|
1522 | self.setup(dataOut, **kwargs) | |
1462 | self.isConfig = True |
|
1523 | self.isConfig = True | |
1463 |
|
1524 | |||
1464 | self.putData() |
|
1525 | self.putData() | |
1465 |
|
1526 |
@@ -1,764 +1,705 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 2, 2014 |
|
2 | Created on Jul 2, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import numpy |
|
6 | import numpy | |
7 |
|
7 | |||
8 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
8 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter | |
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
10 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
10 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
11 | from schainpy.model.data.jrodata import Spectra |
|
11 | from schainpy.model.data.jrodata import Spectra | |
12 |
|
12 | |||
13 | class SpectraReader(JRODataReader, ProcessingUnit): |
|
13 | class SpectraReader(JRODataReader, ProcessingUnit): | |
14 | """ |
|
14 | """ | |
15 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
15 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
16 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
16 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
17 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
17 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
18 |
|
18 | |||
19 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
19 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
20 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
20 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
21 | canales * alturas (DC Channels) |
|
21 | canales * alturas (DC Channels) | |
22 |
|
22 | |||
23 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
23 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
24 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
24 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
25 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
25 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
26 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
26 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
27 |
|
27 | |||
28 | Example: |
|
28 | Example: | |
29 | dpath = "/home/myuser/data" |
|
29 | dpath = "/home/myuser/data" | |
30 |
|
30 | |||
31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
32 |
|
32 | |||
33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
34 |
|
34 | |||
35 | readerObj = SpectraReader() |
|
35 | readerObj = SpectraReader() | |
36 |
|
36 | |||
37 | readerObj.setup(dpath, startTime, endTime) |
|
37 | readerObj.setup(dpath, startTime, endTime) | |
38 |
|
38 | |||
39 | while(True): |
|
39 | while(True): | |
40 |
|
40 | |||
41 | readerObj.getData() |
|
41 | readerObj.getData() | |
42 |
|
42 | |||
43 | print readerObj.data_spc |
|
43 | print readerObj.data_spc | |
44 |
|
44 | |||
45 | print readerObj.data_cspc |
|
45 | print readerObj.data_cspc | |
46 |
|
46 | |||
47 | print readerObj.data_dc |
|
47 | print readerObj.data_dc | |
48 |
|
48 | |||
49 | if readerObj.flagNoMoreFiles: |
|
49 | if readerObj.flagNoMoreFiles: | |
50 | break |
|
50 | break | |
51 |
|
51 | |||
52 | """ |
|
52 | """ | |
53 |
|
53 | |||
54 | pts2read_SelfSpectra = 0 |
|
54 | pts2read_SelfSpectra = 0 | |
55 |
|
55 | |||
56 | pts2read_CrossSpectra = 0 |
|
56 | pts2read_CrossSpectra = 0 | |
57 |
|
57 | |||
58 | pts2read_DCchannels = 0 |
|
58 | pts2read_DCchannels = 0 | |
59 |
|
59 | |||
60 | ext = ".pdata" |
|
60 | ext = ".pdata" | |
61 |
|
61 | |||
62 | optchar = "P" |
|
62 | optchar = "P" | |
63 |
|
63 | |||
64 | dataOut = None |
|
64 | dataOut = None | |
65 |
|
65 | |||
66 | nRdChannels = None |
|
66 | nRdChannels = None | |
67 |
|
67 | |||
68 | nRdPairs = None |
|
68 | nRdPairs = None | |
69 |
|
69 | |||
70 | rdPairList = [] |
|
70 | rdPairList = [] | |
71 |
|
71 | |||
72 | def __init__(self): |
|
72 | def __init__(self): | |
73 | """ |
|
73 | """ | |
74 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
74 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
75 |
|
75 | |||
76 | Inputs: |
|
76 | Inputs: | |
77 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
77 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
78 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
78 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
79 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
79 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
80 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
80 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
81 | bloque de datos. |
|
81 | bloque de datos. | |
82 | Si este parametro no es pasado se creara uno internamente. |
|
82 | Si este parametro no es pasado se creara uno internamente. | |
83 |
|
83 | |||
84 | Affected: |
|
84 | Affected: | |
85 | self.dataOut |
|
85 | self.dataOut | |
86 |
|
86 | |||
87 | Return : None |
|
87 | Return : None | |
88 | """ |
|
88 | """ | |
89 |
|
89 | |||
90 | #Eliminar de la base la herencia |
|
90 | #Eliminar de la base la herencia | |
91 | ProcessingUnit.__init__(self) |
|
91 | ProcessingUnit.__init__(self) | |
92 |
|
92 | |||
93 | # self.isConfig = False |
|
93 | # self.isConfig = False | |
94 |
|
94 | |||
95 | self.pts2read_SelfSpectra = 0 |
|
95 | self.pts2read_SelfSpectra = 0 | |
96 |
|
96 | |||
97 | self.pts2read_CrossSpectra = 0 |
|
97 | self.pts2read_CrossSpectra = 0 | |
98 |
|
98 | |||
99 | self.pts2read_DCchannels = 0 |
|
99 | self.pts2read_DCchannels = 0 | |
100 |
|
100 | |||
101 | self.datablock = None |
|
101 | self.datablock = None | |
102 |
|
102 | |||
103 | self.utc = None |
|
103 | self.utc = None | |
104 |
|
104 | |||
105 | self.ext = ".pdata" |
|
105 | self.ext = ".pdata" | |
106 |
|
106 | |||
107 | self.optchar = "P" |
|
107 | self.optchar = "P" | |
108 |
|
108 | |||
109 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
109 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
110 |
|
110 | |||
111 | self.systemHeaderObj = SystemHeader() |
|
111 | self.systemHeaderObj = SystemHeader() | |
112 |
|
112 | |||
113 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
113 | self.radarControllerHeaderObj = RadarControllerHeader() | |
114 |
|
114 | |||
115 | self.processingHeaderObj = ProcessingHeader() |
|
115 | self.processingHeaderObj = ProcessingHeader() | |
116 |
|
116 | |||
117 | self.online = 0 |
|
117 | self.online = 0 | |
118 |
|
118 | |||
119 | self.fp = None |
|
119 | self.fp = None | |
120 |
|
120 | |||
121 | self.idFile = None |
|
121 | self.idFile = None | |
122 |
|
122 | |||
123 | self.dtype = None |
|
123 | self.dtype = None | |
124 |
|
124 | |||
125 | self.fileSizeByHeader = None |
|
125 | self.fileSizeByHeader = None | |
126 |
|
126 | |||
127 | self.filenameList = [] |
|
127 | self.filenameList = [] | |
128 |
|
128 | |||
129 | self.filename = None |
|
129 | self.filename = None | |
130 |
|
130 | |||
131 | self.fileSize = None |
|
131 | self.fileSize = None | |
132 |
|
132 | |||
133 | self.firstHeaderSize = 0 |
|
133 | self.firstHeaderSize = 0 | |
134 |
|
134 | |||
135 | self.basicHeaderSize = 24 |
|
135 | self.basicHeaderSize = 24 | |
136 |
|
136 | |||
137 | self.pathList = [] |
|
137 | self.pathList = [] | |
138 |
|
138 | |||
139 | self.lastUTTime = 0 |
|
139 | self.lastUTTime = 0 | |
140 |
|
140 | |||
141 | self.maxTimeStep = 30 |
|
141 | self.maxTimeStep = 30 | |
142 |
|
142 | |||
143 | self.flagNoMoreFiles = 0 |
|
143 | self.flagNoMoreFiles = 0 | |
144 |
|
144 | |||
145 | self.set = 0 |
|
145 | self.set = 0 | |
146 |
|
146 | |||
147 | self.path = None |
|
147 | self.path = None | |
148 |
|
148 | |||
149 | self.delay = 60 #seconds |
|
149 | self.delay = 60 #seconds | |
150 |
|
150 | |||
151 | self.nTries = 3 #quantity tries |
|
151 | self.nTries = 3 #quantity tries | |
152 |
|
152 | |||
153 | self.nFiles = 3 #number of files for searching |
|
153 | self.nFiles = 3 #number of files for searching | |
154 |
|
154 | |||
155 | self.nReadBlocks = 0 |
|
155 | self.nReadBlocks = 0 | |
156 |
|
156 | |||
157 | self.flagIsNewFile = 1 |
|
157 | self.flagIsNewFile = 1 | |
158 |
|
158 | |||
159 | self.__isFirstTimeOnline = 1 |
|
159 | self.__isFirstTimeOnline = 1 | |
160 |
|
160 | |||
161 | # self.ippSeconds = 0 |
|
161 | # self.ippSeconds = 0 | |
162 |
|
162 | |||
163 | self.flagDiscontinuousBlock = 0 |
|
163 | self.flagDiscontinuousBlock = 0 | |
164 |
|
164 | |||
165 | self.flagIsNewBlock = 0 |
|
165 | self.flagIsNewBlock = 0 | |
166 |
|
166 | |||
167 | self.nTotalBlocks = 0 |
|
167 | self.nTotalBlocks = 0 | |
168 |
|
168 | |||
169 | self.blocksize = 0 |
|
169 | self.blocksize = 0 | |
170 |
|
170 | |||
171 | self.dataOut = self.createObjByDefault() |
|
171 | self.dataOut = self.createObjByDefault() | |
172 |
|
172 | |||
173 | self.profileIndex = 1 #Always |
|
173 | self.profileIndex = 1 #Always | |
174 |
|
174 | |||
175 |
|
175 | |||
176 | def createObjByDefault(self): |
|
176 | def createObjByDefault(self): | |
177 |
|
177 | |||
178 | dataObj = Spectra() |
|
178 | dataObj = Spectra() | |
179 |
|
179 | |||
180 | return dataObj |
|
180 | return dataObj | |
181 |
|
181 | |||
182 | def __hasNotDataInBuffer(self): |
|
182 | def __hasNotDataInBuffer(self): | |
183 | return 1 |
|
183 | return 1 | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | def getBlockDimension(self): |
|
186 | def getBlockDimension(self): | |
187 | """ |
|
187 | """ | |
188 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
188 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
189 |
|
189 | |||
190 | Affected: |
|
190 | Affected: | |
191 | self.nRdChannels |
|
191 | self.nRdChannels | |
192 | self.nRdPairs |
|
192 | self.nRdPairs | |
193 | self.pts2read_SelfSpectra |
|
193 | self.pts2read_SelfSpectra | |
194 | self.pts2read_CrossSpectra |
|
194 | self.pts2read_CrossSpectra | |
195 | self.pts2read_DCchannels |
|
195 | self.pts2read_DCchannels | |
196 | self.blocksize |
|
196 | self.blocksize | |
197 | self.dataOut.nChannels |
|
197 | self.dataOut.nChannels | |
198 | self.dataOut.nPairs |
|
198 | self.dataOut.nPairs | |
199 |
|
199 | |||
200 | Return: |
|
200 | Return: | |
201 | None |
|
201 | None | |
202 | """ |
|
202 | """ | |
203 | self.nRdChannels = 0 |
|
203 | self.nRdChannels = 0 | |
204 | self.nRdPairs = 0 |
|
204 | self.nRdPairs = 0 | |
205 | self.rdPairList = [] |
|
205 | self.rdPairList = [] | |
206 |
|
206 | |||
207 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
207 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
208 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
208 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
209 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
209 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
210 | else: |
|
210 | else: | |
211 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
211 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
212 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
212 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
213 |
|
213 | |||
214 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
214 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
215 |
|
215 | |||
216 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
216 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
217 | self.blocksize = self.pts2read_SelfSpectra |
|
217 | self.blocksize = self.pts2read_SelfSpectra | |
218 |
|
218 | |||
219 | if self.processingHeaderObj.flag_cspc: |
|
219 | if self.processingHeaderObj.flag_cspc: | |
220 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
220 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
221 | self.blocksize += self.pts2read_CrossSpectra |
|
221 | self.blocksize += self.pts2read_CrossSpectra | |
222 |
|
222 | |||
223 | if self.processingHeaderObj.flag_dc: |
|
223 | if self.processingHeaderObj.flag_dc: | |
224 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
224 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
225 | self.blocksize += self.pts2read_DCchannels |
|
225 | self.blocksize += self.pts2read_DCchannels | |
226 |
|
226 | |||
227 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
227 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
228 |
|
228 | |||
229 |
|
229 | |||
230 | def readBlock(self): |
|
230 | def readBlock(self): | |
231 | """ |
|
231 | """ | |
232 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
232 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
233 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
233 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
234 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
234 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
235 | es seteado a 0 |
|
235 | es seteado a 0 | |
236 |
|
236 | |||
237 | Return: None |
|
237 | Return: None | |
238 |
|
238 | |||
239 | Variables afectadas: |
|
239 | Variables afectadas: | |
240 |
|
240 | |||
241 | self.flagIsNewFile |
|
241 | self.flagIsNewFile | |
242 | self.flagIsNewBlock |
|
242 | self.flagIsNewBlock | |
243 | self.nTotalBlocks |
|
243 | self.nTotalBlocks | |
244 | self.data_spc |
|
244 | self.data_spc | |
245 | self.data_cspc |
|
245 | self.data_cspc | |
246 | self.data_dc |
|
246 | self.data_dc | |
247 |
|
247 | |||
248 | Exceptions: |
|
248 | Exceptions: | |
249 | Si un bloque leido no es un bloque valido |
|
249 | Si un bloque leido no es un bloque valido | |
250 | """ |
|
250 | """ | |
251 | blockOk_flag = False |
|
251 | blockOk_flag = False | |
252 | fpointer = self.fp.tell() |
|
252 | fpointer = self.fp.tell() | |
253 |
|
253 | |||
254 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
254 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
255 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
255 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
256 |
|
256 | |||
257 | if self.processingHeaderObj.flag_cspc: |
|
257 | if self.processingHeaderObj.flag_cspc: | |
258 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
258 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
259 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
259 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
260 |
|
260 | |||
261 | if self.processingHeaderObj.flag_dc: |
|
261 | if self.processingHeaderObj.flag_dc: | |
262 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
262 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
263 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
263 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
264 |
|
264 | |||
265 |
|
265 | |||
266 | if not(self.processingHeaderObj.shif_fft): |
|
266 | if not(self.processingHeaderObj.shif_fft): | |
267 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
267 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
268 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
268 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
269 | spc = numpy.roll( spc, shift , axis=2 ) |
|
269 | spc = numpy.roll( spc, shift , axis=2 ) | |
270 |
|
270 | |||
271 | if self.processingHeaderObj.flag_cspc: |
|
271 | if self.processingHeaderObj.flag_cspc: | |
272 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
272 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
273 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
273 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
274 |
|
274 | |||
275 | # self.processingHeaderObj.shif_fft = True |
|
275 | # self.processingHeaderObj.shif_fft = True | |
276 |
|
276 | |||
|
277 | #Dimensions : nChannels, nProfiles, nSamples | |||
277 | spc = numpy.transpose( spc, (0,2,1) ) |
|
278 | spc = numpy.transpose( spc, (0,2,1) ) | |
278 | self.data_spc = spc |
|
279 | self.data_spc = spc | |
279 |
|
280 | |||
280 | if self.processingHeaderObj.flag_cspc: |
|
281 | if self.processingHeaderObj.flag_cspc: | |
281 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
282 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
282 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
283 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
283 | else: |
|
284 | else: | |
284 | self.data_cspc = None |
|
285 | self.data_cspc = None | |
285 |
|
286 | |||
286 | if self.processingHeaderObj.flag_dc: |
|
287 | if self.processingHeaderObj.flag_dc: | |
287 | self.data_dc = dc['real'] + dc['imag']*1j |
|
288 | self.data_dc = dc['real'] + dc['imag']*1j | |
288 | else: |
|
289 | else: | |
289 | self.data_dc = None |
|
290 | self.data_dc = None | |
290 |
|
291 | |||
291 | self.flagIsNewFile = 0 |
|
292 | self.flagIsNewFile = 0 | |
292 | self.flagIsNewBlock = 1 |
|
293 | self.flagIsNewBlock = 1 | |
293 |
|
294 | |||
294 | self.nTotalBlocks += 1 |
|
295 | self.nTotalBlocks += 1 | |
295 | self.nReadBlocks += 1 |
|
296 | self.nReadBlocks += 1 | |
296 |
|
297 | |||
297 | return 1 |
|
298 | return 1 | |
298 |
|
299 | |||
299 | def getFirstHeader(self): |
|
300 | def getFirstHeader(self): | |
300 |
|
301 | |||
|
302 | self.getBasicHeader() | |||
|
303 | ||||
301 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
304 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
302 |
|
305 | |||
303 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
306 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
304 |
|
307 | |||
305 | # self.dataOut.ippSeconds = self.ippSeconds |
|
308 | # self.dataOut.ippSeconds = self.ippSeconds | |
306 |
|
309 | |||
307 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock |
|
310 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock | |
308 |
|
311 | |||
309 | self.dataOut.dtype = self.dtype |
|
312 | self.dataOut.dtype = self.dtype | |
310 |
|
313 | |||
311 | # self.dataOut.nPairs = self.nPairs |
|
314 | # self.dataOut.nPairs = self.nPairs | |
312 |
|
315 | |||
313 | self.dataOut.pairsList = self.rdPairList |
|
316 | self.dataOut.pairsList = self.rdPairList | |
314 |
|
317 | |||
315 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
318 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
316 |
|
319 | |||
317 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
320 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
318 |
|
321 | |||
319 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
322 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
320 |
|
323 | |||
321 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
324 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
322 |
|
325 | |||
323 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
326 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
324 |
|
327 | |||
325 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
328 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
326 |
|
329 | |||
327 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
330 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
328 |
|
331 | |||
329 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
332 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
330 |
|
333 | |||
331 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
334 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
332 |
|
335 | |||
333 | self.dataOut.flagDeflipData = False #asumo q la data esta sin flip |
|
336 | self.dataOut.flagDeflipData = False #asumo q la data esta sin flip | |
334 |
|
337 | |||
335 | if self.radarControllerHeaderObj.code is not None: |
|
338 | if self.radarControllerHeaderObj.code is not None: | |
336 |
|
339 | |||
337 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
340 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
338 | # |
|
341 | # | |
339 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
342 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
340 | # |
|
343 | # | |
341 | # self.dataOut.code = self.radarControllerHeaderObj.code |
|
344 | # self.dataOut.code = self.radarControllerHeaderObj.code | |
342 |
|
345 | |||
343 | self.dataOut.flagDecodeData = True |
|
346 | self.dataOut.flagDecodeData = True | |
344 |
|
347 | |||
345 | def getData(self): |
|
348 | def getData(self): | |
346 | """ |
|
349 | """ | |
347 | First method to execute before "RUN" is called. |
|
350 | First method to execute before "RUN" is called. | |
348 |
|
351 | |||
349 | Copia el buffer de lectura a la clase "Spectra", |
|
352 | Copia el buffer de lectura a la clase "Spectra", | |
350 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
353 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
351 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
354 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
352 |
|
355 | |||
353 | Return: |
|
356 | Return: | |
354 | 0 : Si no hay mas archivos disponibles |
|
357 | 0 : Si no hay mas archivos disponibles | |
355 | 1 : Si hizo una buena copia del buffer |
|
358 | 1 : Si hizo una buena copia del buffer | |
356 |
|
359 | |||
357 | Affected: |
|
360 | Affected: | |
358 | self.dataOut |
|
361 | self.dataOut | |
359 |
|
362 | |||
360 | self.flagDiscontinuousBlock |
|
363 | self.flagDiscontinuousBlock | |
361 | self.flagIsNewBlock |
|
364 | self.flagIsNewBlock | |
362 | """ |
|
365 | """ | |
363 |
|
366 | |||
364 | if self.flagNoMoreFiles: |
|
367 | if self.flagNoMoreFiles: | |
365 | self.dataOut.flagNoData = True |
|
368 | self.dataOut.flagNoData = True | |
366 | print 'Process finished' |
|
369 | print 'Process finished' | |
367 | return 0 |
|
370 | return 0 | |
368 |
|
371 | |||
369 | self.flagDiscontinuousBlock = 0 |
|
372 | self.flagDiscontinuousBlock = 0 | |
370 | self.flagIsNewBlock = 0 |
|
373 | self.flagIsNewBlock = 0 | |
371 |
|
374 | |||
372 | if self.__hasNotDataInBuffer(): |
|
375 | if self.__hasNotDataInBuffer(): | |
373 |
|
376 | |||
374 | if not( self.readNextBlock() ): |
|
377 | if not( self.readNextBlock() ): | |
375 | self.dataOut.flagNoData = True |
|
378 | self.dataOut.flagNoData = True | |
376 | return 0 |
|
379 | return 0 | |
377 |
|
380 | |||
378 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
381 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
379 |
|
382 | |||
380 | if self.data_dc is None: |
|
383 | if self.data_dc is None: | |
381 | self.dataOut.flagNoData = True |
|
384 | self.dataOut.flagNoData = True | |
382 | return 0 |
|
385 | return 0 | |
383 |
|
386 | |||
384 | self.getBasicHeader() |
|
387 | self.getBasicHeader() | |
385 |
|
388 | |||
386 | self.getFirstHeader() |
|
389 | self.getFirstHeader() | |
387 |
|
390 | |||
388 | self.dataOut.data_spc = self.data_spc |
|
391 | self.dataOut.data_spc = self.data_spc | |
389 |
|
392 | |||
390 | self.dataOut.data_cspc = self.data_cspc |
|
393 | self.dataOut.data_cspc = self.data_cspc | |
391 |
|
394 | |||
392 | self.dataOut.data_dc = self.data_dc |
|
395 | self.dataOut.data_dc = self.data_dc | |
393 |
|
396 | |||
394 | self.dataOut.flagNoData = False |
|
397 | self.dataOut.flagNoData = False | |
395 |
|
398 | |||
396 | self.dataOut.realtime = self.online |
|
399 | self.dataOut.realtime = self.online | |
397 |
|
400 | |||
398 | return self.dataOut.data_spc |
|
401 | return self.dataOut.data_spc | |
399 |
|
402 | |||
400 | class SpectraWriter(JRODataWriter, Operation): |
|
403 | class SpectraWriter(JRODataWriter, Operation): | |
401 |
|
404 | |||
402 | """ |
|
405 | """ | |
403 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
406 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
404 | de los datos siempre se realiza por bloques. |
|
407 | de los datos siempre se realiza por bloques. | |
405 | """ |
|
408 | """ | |
406 |
|
409 | |||
407 | ext = ".pdata" |
|
410 | ext = ".pdata" | |
408 |
|
411 | |||
409 | optchar = "P" |
|
412 | optchar = "P" | |
410 |
|
413 | |||
411 | shape_spc_Buffer = None |
|
414 | shape_spc_Buffer = None | |
412 |
|
415 | |||
413 | shape_cspc_Buffer = None |
|
416 | shape_cspc_Buffer = None | |
414 |
|
417 | |||
415 | shape_dc_Buffer = None |
|
418 | shape_dc_Buffer = None | |
416 |
|
419 | |||
417 | data_spc = None |
|
420 | data_spc = None | |
418 |
|
421 | |||
419 | data_cspc = None |
|
422 | data_cspc = None | |
420 |
|
423 | |||
421 | data_dc = None |
|
424 | data_dc = None | |
422 |
|
425 | |||
423 | # dataOut = None |
|
426 | # dataOut = None | |
424 |
|
427 | |||
425 | def __init__(self): |
|
428 | def __init__(self): | |
426 | """ |
|
429 | """ | |
427 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
430 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
428 |
|
431 | |||
429 | Affected: |
|
432 | Affected: | |
430 | self.dataOut |
|
433 | self.dataOut | |
431 | self.basicHeaderObj |
|
434 | self.basicHeaderObj | |
432 | self.systemHeaderObj |
|
435 | self.systemHeaderObj | |
433 | self.radarControllerHeaderObj |
|
436 | self.radarControllerHeaderObj | |
434 | self.processingHeaderObj |
|
437 | self.processingHeaderObj | |
435 |
|
438 | |||
436 | Return: None |
|
439 | Return: None | |
437 | """ |
|
440 | """ | |
438 |
|
441 | |||
439 | Operation.__init__(self) |
|
442 | Operation.__init__(self) | |
440 |
|
443 | |||
441 | self.isConfig = False |
|
444 | self.isConfig = False | |
442 |
|
445 | |||
443 | self.nTotalBlocks = 0 |
|
446 | self.nTotalBlocks = 0 | |
444 |
|
447 | |||
445 | self.data_spc = None |
|
448 | self.data_spc = None | |
446 |
|
449 | |||
447 | self.data_cspc = None |
|
450 | self.data_cspc = None | |
448 |
|
451 | |||
449 | self.data_dc = None |
|
452 | self.data_dc = None | |
450 |
|
453 | |||
451 | self.fp = None |
|
454 | self.fp = None | |
452 |
|
455 | |||
453 | self.flagIsNewFile = 1 |
|
456 | self.flagIsNewFile = 1 | |
454 |
|
457 | |||
455 | self.nTotalBlocks = 0 |
|
458 | self.nTotalBlocks = 0 | |
456 |
|
459 | |||
457 | self.flagIsNewBlock = 0 |
|
460 | self.flagIsNewBlock = 0 | |
458 |
|
461 | |||
459 | self.setFile = None |
|
462 | self.setFile = None | |
460 |
|
463 | |||
461 | self.dtype = None |
|
464 | self.dtype = None | |
462 |
|
465 | |||
463 | self.path = None |
|
466 | self.path = None | |
464 |
|
467 | |||
465 | self.noMoreFiles = 0 |
|
468 | self.noMoreFiles = 0 | |
466 |
|
469 | |||
467 | self.filename = None |
|
470 | self.filename = None | |
468 |
|
471 | |||
469 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
472 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
470 |
|
473 | |||
471 | self.systemHeaderObj = SystemHeader() |
|
474 | self.systemHeaderObj = SystemHeader() | |
472 |
|
475 | |||
473 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
476 | self.radarControllerHeaderObj = RadarControllerHeader() | |
474 |
|
477 | |||
475 | self.processingHeaderObj = ProcessingHeader() |
|
478 | self.processingHeaderObj = ProcessingHeader() | |
476 |
|
479 | |||
477 |
|
480 | |||
478 | def hasAllDataInBuffer(self): |
|
481 | def hasAllDataInBuffer(self): | |
479 | return 1 |
|
482 | return 1 | |
480 |
|
483 | |||
481 |
|
484 | |||
482 | def setBlockDimension(self): |
|
485 | def setBlockDimension(self): | |
483 | """ |
|
486 | """ | |
484 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
487 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
485 |
|
488 | |||
486 | Affected: |
|
489 | Affected: | |
487 | self.shape_spc_Buffer |
|
490 | self.shape_spc_Buffer | |
488 | self.shape_cspc_Buffer |
|
491 | self.shape_cspc_Buffer | |
489 | self.shape_dc_Buffer |
|
492 | self.shape_dc_Buffer | |
490 |
|
493 | |||
491 | Return: None |
|
494 | Return: None | |
492 | """ |
|
495 | """ | |
493 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
496 | self.shape_spc_Buffer = (self.dataOut.nChannels, | |
494 | self.processingHeaderObj.nHeights, |
|
497 | self.processingHeaderObj.nHeights, | |
495 | self.processingHeaderObj.profilesPerBlock) |
|
498 | self.processingHeaderObj.profilesPerBlock) | |
496 |
|
499 | |||
497 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
500 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
498 | self.processingHeaderObj.nHeights, |
|
501 | self.processingHeaderObj.nHeights, | |
499 | self.processingHeaderObj.profilesPerBlock) |
|
502 | self.processingHeaderObj.profilesPerBlock) | |
500 |
|
503 | |||
501 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
504 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
502 | self.processingHeaderObj.nHeights) |
|
505 | self.processingHeaderObj.nHeights) | |
503 |
|
506 | |||
504 |
|
507 | |||
505 | def writeBlock(self): |
|
508 | def writeBlock(self): | |
506 | """ |
|
509 | """ | |
507 | Escribe el buffer en el file designado |
|
510 | Escribe el buffer en el file designado | |
508 |
|
511 | |||
509 | Affected: |
|
512 | Affected: | |
510 | self.data_spc |
|
513 | self.data_spc | |
511 | self.data_cspc |
|
514 | self.data_cspc | |
512 | self.data_dc |
|
515 | self.data_dc | |
513 | self.flagIsNewFile |
|
516 | self.flagIsNewFile | |
514 | self.flagIsNewBlock |
|
517 | self.flagIsNewBlock | |
515 | self.nTotalBlocks |
|
518 | self.nTotalBlocks | |
516 | self.nWriteBlocks |
|
519 | self.nWriteBlocks | |
517 |
|
520 | |||
518 | Return: None |
|
521 | Return: None | |
519 | """ |
|
522 | """ | |
520 |
|
523 | |||
521 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
524 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
522 | if not( self.processingHeaderObj.shif_fft ): |
|
525 | if not( self.processingHeaderObj.shif_fft ): | |
523 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
526 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
524 | data = spc.reshape((-1)) |
|
527 | data = spc.reshape((-1)) | |
525 | data = data.astype(self.dtype[0]) |
|
528 | data = data.astype(self.dtype[0]) | |
526 | data.tofile(self.fp) |
|
529 | data.tofile(self.fp) | |
527 |
|
530 | |||
528 | if self.data_cspc is not None: |
|
531 | if self.data_cspc is not None: | |
529 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
532 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
530 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
533 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
531 | if not( self.processingHeaderObj.shif_fft ): |
|
534 | if not( self.processingHeaderObj.shif_fft ): | |
532 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
535 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
533 | data['real'] = cspc.real |
|
536 | data['real'] = cspc.real | |
534 | data['imag'] = cspc.imag |
|
537 | data['imag'] = cspc.imag | |
535 | data = data.reshape((-1)) |
|
538 | data = data.reshape((-1)) | |
536 | data.tofile(self.fp) |
|
539 | data.tofile(self.fp) | |
537 |
|
540 | |||
538 | if self.data_dc is not None: |
|
541 | if self.data_dc is not None: | |
539 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
542 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
540 | dc = self.data_dc |
|
543 | dc = self.data_dc | |
541 | data['real'] = dc.real |
|
544 | data['real'] = dc.real | |
542 | data['imag'] = dc.imag |
|
545 | data['imag'] = dc.imag | |
543 | data = data.reshape((-1)) |
|
546 | data = data.reshape((-1)) | |
544 | data.tofile(self.fp) |
|
547 | data.tofile(self.fp) | |
545 |
|
548 | |||
546 | self.data_spc.fill(0) |
|
549 | self.data_spc.fill(0) | |
547 |
|
550 | |||
548 | if self.data_dc is not None: |
|
551 | if self.data_dc is not None: | |
549 | self.data_dc.fill(0) |
|
552 | self.data_dc.fill(0) | |
550 |
|
553 | |||
551 | if self.data_cspc is not None: |
|
554 | if self.data_cspc is not None: | |
552 | self.data_cspc.fill(0) |
|
555 | self.data_cspc.fill(0) | |
553 |
|
556 | |||
554 | self.flagIsNewFile = 0 |
|
557 | self.flagIsNewFile = 0 | |
555 | self.flagIsNewBlock = 1 |
|
558 | self.flagIsNewBlock = 1 | |
556 | self.nTotalBlocks += 1 |
|
559 | self.nTotalBlocks += 1 | |
557 | self.nWriteBlocks += 1 |
|
560 | self.nWriteBlocks += 1 | |
558 | self.blockIndex += 1 |
|
561 | self.blockIndex += 1 | |
559 |
|
562 | |||
560 | # print "[Writing] Block = %d04" %self.blockIndex |
|
563 | # print "[Writing] Block = %d04" %self.blockIndex | |
561 |
|
564 | |||
562 | def putData(self): |
|
565 | def putData(self): | |
563 | """ |
|
566 | """ | |
564 | Setea un bloque de datos y luego los escribe en un file |
|
567 | Setea un bloque de datos y luego los escribe en un file | |
565 |
|
568 | |||
566 | Affected: |
|
569 | Affected: | |
567 | self.data_spc |
|
570 | self.data_spc | |
568 | self.data_cspc |
|
571 | self.data_cspc | |
569 | self.data_dc |
|
572 | self.data_dc | |
570 |
|
573 | |||
571 | Return: |
|
574 | Return: | |
572 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
575 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
573 | 1 : Si se escribio la data de un bloque en un file |
|
576 | 1 : Si se escribio la data de un bloque en un file | |
574 | """ |
|
577 | """ | |
575 |
|
578 | |||
576 | if self.dataOut.flagNoData: |
|
579 | if self.dataOut.flagNoData: | |
577 | return 0 |
|
580 | return 0 | |
578 |
|
581 | |||
579 | self.flagIsNewBlock = 0 |
|
582 | self.flagIsNewBlock = 0 | |
580 |
|
583 | |||
581 | if self.dataOut.flagDiscontinuousBlock: |
|
584 | if self.dataOut.flagDiscontinuousBlock: | |
582 | self.data_spc.fill(0) |
|
585 | self.data_spc.fill(0) | |
583 | self.data_cspc.fill(0) |
|
586 | self.data_cspc.fill(0) | |
584 | self.data_dc.fill(0) |
|
587 | self.data_dc.fill(0) | |
585 | self.setNextFile() |
|
588 | self.setNextFile() | |
586 |
|
589 | |||
587 | if self.flagIsNewFile == 0: |
|
590 | if self.flagIsNewFile == 0: | |
588 | self.setBasicHeader() |
|
591 | self.setBasicHeader() | |
589 |
|
592 | |||
590 | self.data_spc = self.dataOut.data_spc.copy() |
|
593 | self.data_spc = self.dataOut.data_spc.copy() | |
591 | if self.dataOut.data_cspc is not None: |
|
594 | if self.dataOut.data_cspc is not None: | |
592 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
595 | self.data_cspc = self.dataOut.data_cspc.copy() | |
593 | self.data_dc = self.dataOut.data_dc.copy() |
|
596 | self.data_dc = self.dataOut.data_dc.copy() | |
594 |
|
597 | |||
595 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
598 | # #self.processingHeaderObj.dataBlocksPerFile) | |
596 | if self.hasAllDataInBuffer(): |
|
599 | if self.hasAllDataInBuffer(): | |
597 | # self.setFirstHeader() |
|
600 | # self.setFirstHeader() | |
598 | self.writeNextBlock() |
|
601 | self.writeNextBlock() | |
599 |
|
602 | |||
600 | return 1 |
|
603 | return 1 | |
601 |
|
604 | |||
602 |
|
||||
603 | def __getProcessFlags(self): |
|
|||
604 |
|
||||
605 | processFlags = 0 |
|
|||
606 |
|
||||
607 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
|||
608 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
|||
609 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
|||
610 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
|||
611 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
|||
612 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
|||
613 |
|
||||
614 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
|||
615 |
|
||||
616 |
|
||||
617 |
|
||||
618 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
|||
619 | PROCFLAG.DATATYPE_SHORT, |
|
|||
620 | PROCFLAG.DATATYPE_LONG, |
|
|||
621 | PROCFLAG.DATATYPE_INT64, |
|
|||
622 | PROCFLAG.DATATYPE_FLOAT, |
|
|||
623 | PROCFLAG.DATATYPE_DOUBLE] |
|
|||
624 |
|
||||
625 |
|
||||
626 | for index in range(len(dtypeList)): |
|
|||
627 | if self.dataOut.dtype == dtypeList[index]: |
|
|||
628 | dtypeValue = datatypeValueList[index] |
|
|||
629 | break |
|
|||
630 |
|
||||
631 | processFlags += dtypeValue |
|
|||
632 |
|
||||
633 | if self.dataOut.flagDecodeData: |
|
|||
634 | processFlags += PROCFLAG.DECODE_DATA |
|
|||
635 |
|
||||
636 | if self.dataOut.flagDeflipData: |
|
|||
637 | processFlags += PROCFLAG.DEFLIP_DATA |
|
|||
638 |
|
||||
639 | if self.dataOut.code is not None: |
|
|||
640 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
|||
641 |
|
||||
642 | if self.dataOut.nIncohInt > 1: |
|
|||
643 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
|||
644 |
|
||||
645 | if self.dataOut.data_dc is not None: |
|
|||
646 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
|||
647 |
|
||||
648 | return processFlags |
|
|||
649 |
|
||||
650 |
|
||||
651 | def __getBlockSize(self): |
|
605 | def __getBlockSize(self): | |
652 | ''' |
|
606 | ''' | |
653 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
607 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
654 | ''' |
|
608 | ''' | |
655 |
|
609 | |||
656 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
610 | dtype_width = self.getDtypeWidth() | |
657 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
|||
658 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
|||
659 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
|||
660 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
|||
661 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
|||
662 |
|
||||
663 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
|||
664 | datatypeValueList = [1,2,4,8,4,8] |
|
|||
665 | for index in range(len(dtypeList)): |
|
|||
666 | if self.dataOut.dtype == dtypeList[index]: |
|
|||
667 | datatypeValue = datatypeValueList[index] |
|
|||
668 | break |
|
|||
669 |
|
||||
670 |
|
611 | |||
671 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
612 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
672 |
|
613 | |||
673 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
614 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
674 |
blocksize = (pts2write_SelfSpectra*d |
|
615 | blocksize = (pts2write_SelfSpectra*dtype_width) | |
675 |
|
616 | |||
676 | if self.dataOut.data_cspc is not None: |
|
617 | if self.dataOut.data_cspc is not None: | |
677 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
618 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
678 |
blocksize += (pts2write_CrossSpectra*d |
|
619 | blocksize += (pts2write_CrossSpectra*dtype_width*2) | |
679 |
|
620 | |||
680 | if self.dataOut.data_dc is not None: |
|
621 | if self.dataOut.data_dc is not None: | |
681 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
622 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
682 |
blocksize += (pts2write_DCchannels*d |
|
623 | blocksize += (pts2write_DCchannels*dtype_width*2) | |
683 |
|
624 | |||
684 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
625 | # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
685 |
|
626 | |||
686 | return blocksize |
|
627 | return blocksize | |
687 |
|
628 | |||
688 | def setFirstHeader(self): |
|
629 | def setFirstHeader(self): | |
689 |
|
630 | |||
690 | """ |
|
631 | """ | |
691 | Obtiene una copia del First Header |
|
632 | Obtiene una copia del First Header | |
692 |
|
633 | |||
693 | Affected: |
|
634 | Affected: | |
694 | self.systemHeaderObj |
|
635 | self.systemHeaderObj | |
695 | self.radarControllerHeaderObj |
|
636 | self.radarControllerHeaderObj | |
696 | self.dtype |
|
637 | self.dtype | |
697 |
|
638 | |||
698 | Return: |
|
639 | Return: | |
699 | None |
|
640 | None | |
700 | """ |
|
641 | """ | |
701 |
|
642 | |||
702 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
643 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
703 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
644 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
704 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
645 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
705 | old_code_size = self.dataOut.radarControllerHeaderObj.code_size |
|
646 | old_code_size = self.dataOut.radarControllerHeaderObj.code_size | |
706 | new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4 |
|
647 | new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4 | |
707 | self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size |
|
648 | self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size | |
708 |
|
649 | |||
709 | self.setBasicHeader() |
|
650 | self.setBasicHeader() | |
710 |
|
651 | |||
711 | processingHeaderSize = 40 # bytes |
|
652 | processingHeaderSize = 40 # bytes | |
712 | self.processingHeaderObj.dtype = 1 # Spectra |
|
653 | self.processingHeaderObj.dtype = 1 # Spectra | |
713 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
654 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
714 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
655 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
715 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
656 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
716 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
657 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
717 |
self.processingHeaderObj.processFlags = self. |
|
658 | self.processingHeaderObj.processFlags = self.getProcessFlags() | |
718 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
659 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
719 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
660 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
720 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
661 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
721 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT |
|
662 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT | |
722 |
|
663 | |||
723 | if self.processingHeaderObj.totalSpectra > 0: |
|
664 | if self.processingHeaderObj.totalSpectra > 0: | |
724 | channelList = [] |
|
665 | channelList = [] | |
725 | for channel in range(self.dataOut.nChannels): |
|
666 | for channel in range(self.dataOut.nChannels): | |
726 | channelList.append(channel) |
|
667 | channelList.append(channel) | |
727 | channelList.append(channel) |
|
668 | channelList.append(channel) | |
728 |
|
669 | |||
729 | pairsList = [] |
|
670 | pairsList = [] | |
730 | if self.dataOut.nPairs > 0: |
|
671 | if self.dataOut.nPairs > 0: | |
731 | for pair in self.dataOut.pairsList: |
|
672 | for pair in self.dataOut.pairsList: | |
732 | pairsList.append(pair[0]) |
|
673 | pairsList.append(pair[0]) | |
733 | pairsList.append(pair[1]) |
|
674 | pairsList.append(pair[1]) | |
734 |
|
675 | |||
735 | spectraComb = channelList + pairsList |
|
676 | spectraComb = channelList + pairsList | |
736 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
677 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
737 | self.processingHeaderObj.spectraComb = spectraComb |
|
678 | self.processingHeaderObj.spectraComb = spectraComb | |
738 | sizeOfSpcComb = len(spectraComb) |
|
679 | sizeOfSpcComb = len(spectraComb) | |
739 | processingHeaderSize += sizeOfSpcComb |
|
680 | processingHeaderSize += sizeOfSpcComb | |
740 |
|
681 | |||
741 | # The processing header should not have information about code |
|
682 | # The processing header should not have information about code | |
742 | # if self.dataOut.code is not None: |
|
683 | # if self.dataOut.code is not None: | |
743 | # self.processingHeaderObj.code = self.dataOut.code |
|
684 | # self.processingHeaderObj.code = self.dataOut.code | |
744 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
685 | # self.processingHeaderObj.nCode = self.dataOut.nCode | |
745 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
686 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
746 | # nCodeSize = 4 # bytes |
|
687 | # nCodeSize = 4 # bytes | |
747 | # nBaudSize = 4 # bytes |
|
688 | # nBaudSize = 4 # bytes | |
748 | # codeSize = 4 # bytes |
|
689 | # codeSize = 4 # bytes | |
749 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
690 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) | |
750 | # processingHeaderSize += sizeOfCode |
|
691 | # processingHeaderSize += sizeOfCode | |
751 |
|
692 | |||
752 | if self.processingHeaderObj.nWindows != 0: |
|
693 | if self.processingHeaderObj.nWindows != 0: | |
753 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
694 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
754 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
695 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
755 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
696 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
756 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
697 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
757 | sizeOfFirstHeight = 4 |
|
698 | sizeOfFirstHeight = 4 | |
758 | sizeOfdeltaHeight = 4 |
|
699 | sizeOfdeltaHeight = 4 | |
759 | sizeOfnHeights = 4 |
|
700 | sizeOfnHeights = 4 | |
760 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
701 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
761 | processingHeaderSize += sizeOfWindows |
|
702 | processingHeaderSize += sizeOfWindows | |
762 |
|
703 | |||
763 | self.processingHeaderObj.size = processingHeaderSize |
|
704 | self.processingHeaderObj.size = processingHeaderSize | |
764 |
|
705 |
@@ -1,652 +1,599 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 2, 2014 |
|
2 | Created on Jul 2, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import numpy |
|
7 | import numpy | |
8 |
|
8 | |||
9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter | |
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
12 | from schainpy.model.data.jrodata import Voltage |
|
12 | from schainpy.model.data.jrodata import Voltage | |
13 |
|
13 | |||
14 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
14 | class VoltageReader(JRODataReader, ProcessingUnit): | |
15 | """ |
|
15 | """ | |
16 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
16 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
17 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
17 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
18 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
18 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
19 |
|
19 | |||
20 | perfiles * alturas * canales |
|
20 | perfiles * alturas * canales | |
21 |
|
21 | |||
22 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
22 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
23 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
23 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
24 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
24 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
25 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
25 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
26 |
|
26 | |||
27 | Example: |
|
27 | Example: | |
28 |
|
28 | |||
29 | dpath = "/home/myuser/data" |
|
29 | dpath = "/home/myuser/data" | |
30 |
|
30 | |||
31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
32 |
|
32 | |||
33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
34 |
|
34 | |||
35 | readerObj = VoltageReader() |
|
35 | readerObj = VoltageReader() | |
36 |
|
36 | |||
37 | readerObj.setup(dpath, startTime, endTime) |
|
37 | readerObj.setup(dpath, startTime, endTime) | |
38 |
|
38 | |||
39 | while(True): |
|
39 | while(True): | |
40 |
|
40 | |||
41 | #to get one profile |
|
41 | #to get one profile | |
42 | profile = readerObj.getData() |
|
42 | profile = readerObj.getData() | |
43 |
|
43 | |||
44 | #print the profile |
|
44 | #print the profile | |
45 | print profile |
|
45 | print profile | |
46 |
|
46 | |||
47 | #If you want to see all datablock |
|
47 | #If you want to see all datablock | |
48 | print readerObj.datablock |
|
48 | print readerObj.datablock | |
49 |
|
49 | |||
50 | if readerObj.flagNoMoreFiles: |
|
50 | if readerObj.flagNoMoreFiles: | |
51 | break |
|
51 | break | |
52 |
|
52 | |||
53 | """ |
|
53 | """ | |
54 |
|
54 | |||
55 | ext = ".r" |
|
55 | ext = ".r" | |
56 |
|
56 | |||
57 | optchar = "D" |
|
57 | optchar = "D" | |
58 | dataOut = None |
|
58 | dataOut = None | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def __init__(self): |
|
61 | def __init__(self): | |
62 | """ |
|
62 | """ | |
63 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
63 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
64 |
|
64 | |||
65 | Input: |
|
65 | Input: | |
66 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
66 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
67 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
67 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
68 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
68 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
69 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
69 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
70 | bloque de datos. |
|
70 | bloque de datos. | |
71 | Si este parametro no es pasado se creara uno internamente. |
|
71 | Si este parametro no es pasado se creara uno internamente. | |
72 |
|
72 | |||
73 | Variables afectadas: |
|
73 | Variables afectadas: | |
74 | self.dataOut |
|
74 | self.dataOut | |
75 |
|
75 | |||
76 | Return: |
|
76 | Return: | |
77 | None |
|
77 | None | |
78 | """ |
|
78 | """ | |
79 |
|
79 | |||
80 | ProcessingUnit.__init__(self) |
|
80 | ProcessingUnit.__init__(self) | |
81 |
|
81 | |||
82 | self.isConfig = False |
|
82 | self.isConfig = False | |
83 |
|
83 | |||
84 | self.datablock = None |
|
84 | self.datablock = None | |
85 |
|
85 | |||
86 | self.utc = 0 |
|
86 | self.utc = 0 | |
87 |
|
87 | |||
88 | self.ext = ".r" |
|
88 | self.ext = ".r" | |
89 |
|
89 | |||
90 | self.optchar = "D" |
|
90 | self.optchar = "D" | |
91 |
|
91 | |||
92 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
92 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
93 |
|
93 | |||
94 | self.systemHeaderObj = SystemHeader() |
|
94 | self.systemHeaderObj = SystemHeader() | |
95 |
|
95 | |||
96 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
96 | self.radarControllerHeaderObj = RadarControllerHeader() | |
97 |
|
97 | |||
98 | self.processingHeaderObj = ProcessingHeader() |
|
98 | self.processingHeaderObj = ProcessingHeader() | |
99 |
|
99 | |||
100 | self.online = 0 |
|
100 | self.online = 0 | |
101 |
|
101 | |||
102 | self.fp = None |
|
102 | self.fp = None | |
103 |
|
103 | |||
104 | self.idFile = None |
|
104 | self.idFile = None | |
105 |
|
105 | |||
106 | self.dtype = None |
|
106 | self.dtype = None | |
107 |
|
107 | |||
108 | self.fileSizeByHeader = None |
|
108 | self.fileSizeByHeader = None | |
109 |
|
109 | |||
110 | self.filenameList = [] |
|
110 | self.filenameList = [] | |
111 |
|
111 | |||
112 | self.filename = None |
|
112 | self.filename = None | |
113 |
|
113 | |||
114 | self.fileSize = None |
|
114 | self.fileSize = None | |
115 |
|
115 | |||
116 | self.firstHeaderSize = 0 |
|
116 | self.firstHeaderSize = 0 | |
117 |
|
117 | |||
118 | self.basicHeaderSize = 24 |
|
118 | self.basicHeaderSize = 24 | |
119 |
|
119 | |||
120 | self.pathList = [] |
|
120 | self.pathList = [] | |
121 |
|
121 | |||
122 | self.filenameList = [] |
|
122 | self.filenameList = [] | |
123 |
|
123 | |||
124 | self.lastUTTime = 0 |
|
124 | self.lastUTTime = 0 | |
125 |
|
125 | |||
126 | self.maxTimeStep = 30 |
|
126 | self.maxTimeStep = 30 | |
127 |
|
127 | |||
128 | self.flagNoMoreFiles = 0 |
|
128 | self.flagNoMoreFiles = 0 | |
129 |
|
129 | |||
130 | self.set = 0 |
|
130 | self.set = 0 | |
131 |
|
131 | |||
132 | self.path = None |
|
132 | self.path = None | |
133 |
|
133 | |||
134 | self.profileIndex = 2**32-1 |
|
134 | self.profileIndex = 2**32-1 | |
135 |
|
135 | |||
136 | self.delay = 3 #seconds |
|
136 | self.delay = 3 #seconds | |
137 |
|
137 | |||
138 | self.nTries = 3 #quantity tries |
|
138 | self.nTries = 3 #quantity tries | |
139 |
|
139 | |||
140 | self.nFiles = 3 #number of files for searching |
|
140 | self.nFiles = 3 #number of files for searching | |
141 |
|
141 | |||
142 | self.nReadBlocks = 0 |
|
142 | self.nReadBlocks = 0 | |
143 |
|
143 | |||
144 | self.flagIsNewFile = 1 |
|
144 | self.flagIsNewFile = 1 | |
145 |
|
145 | |||
146 | self.__isFirstTimeOnline = 1 |
|
146 | self.__isFirstTimeOnline = 1 | |
147 |
|
147 | |||
148 | # self.ippSeconds = 0 |
|
148 | # self.ippSeconds = 0 | |
149 |
|
149 | |||
150 | self.flagDiscontinuousBlock = 0 |
|
150 | self.flagDiscontinuousBlock = 0 | |
151 |
|
151 | |||
152 | self.flagIsNewBlock = 0 |
|
152 | self.flagIsNewBlock = 0 | |
153 |
|
153 | |||
154 | self.nTotalBlocks = 0 |
|
154 | self.nTotalBlocks = 0 | |
155 |
|
155 | |||
156 | self.blocksize = 0 |
|
156 | self.blocksize = 0 | |
157 |
|
157 | |||
158 | self.dataOut = self.createObjByDefault() |
|
158 | self.dataOut = self.createObjByDefault() | |
159 |
|
159 | |||
160 | self.nTxs = 1 |
|
160 | self.nTxs = 1 | |
161 |
|
161 | |||
162 | self.txIndex = 0 |
|
162 | self.txIndex = 0 | |
163 |
|
163 | |||
164 | def createObjByDefault(self): |
|
164 | def createObjByDefault(self): | |
165 |
|
165 | |||
166 | dataObj = Voltage() |
|
166 | dataObj = Voltage() | |
167 |
|
167 | |||
168 | return dataObj |
|
168 | return dataObj | |
169 |
|
169 | |||
170 | def __hasNotDataInBuffer(self): |
|
170 | def __hasNotDataInBuffer(self): | |
171 |
|
171 | |||
172 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
172 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
173 | return 1 |
|
173 | return 1 | |
174 |
|
174 | |||
175 | return 0 |
|
175 | return 0 | |
176 |
|
176 | |||
177 |
|
177 | |||
178 | def getBlockDimension(self): |
|
178 | def getBlockDimension(self): | |
179 | """ |
|
179 | """ | |
180 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
180 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
181 |
|
181 | |||
182 | Affected: |
|
182 | Affected: | |
183 | self.blocksize |
|
183 | self.blocksize | |
184 |
|
184 | |||
185 | Return: |
|
185 | Return: | |
186 | None |
|
186 | None | |
187 | """ |
|
187 | """ | |
188 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
188 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
189 | self.blocksize = pts2read |
|
189 | self.blocksize = pts2read | |
190 |
|
190 | |||
191 |
|
191 | |||
192 | def readBlock(self): |
|
192 | def readBlock(self): | |
193 | """ |
|
193 | """ | |
194 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
194 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
195 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
195 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
196 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
196 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
197 | es seteado a 0 |
|
197 | es seteado a 0 | |
198 |
|
198 | |||
199 | Inputs: |
|
199 | Inputs: | |
200 | None |
|
200 | None | |
201 |
|
201 | |||
202 | Return: |
|
202 | Return: | |
203 | None |
|
203 | None | |
204 |
|
204 | |||
205 | Affected: |
|
205 | Affected: | |
206 | self.profileIndex |
|
206 | self.profileIndex | |
207 | self.datablock |
|
207 | self.datablock | |
208 | self.flagIsNewFile |
|
208 | self.flagIsNewFile | |
209 | self.flagIsNewBlock |
|
209 | self.flagIsNewBlock | |
210 | self.nTotalBlocks |
|
210 | self.nTotalBlocks | |
211 |
|
211 | |||
212 | Exceptions: |
|
212 | Exceptions: | |
213 | Si un bloque leido no es un bloque valido |
|
213 | Si un bloque leido no es un bloque valido | |
214 | """ |
|
214 | """ | |
215 | current_pointer_location = self.fp.tell() |
|
215 | current_pointer_location = self.fp.tell() | |
216 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
216 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
217 |
|
217 | |||
218 | try: |
|
218 | try: | |
219 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
219 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
220 | except: |
|
220 | except: | |
221 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
221 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
222 |
|
222 | |||
223 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
223 | if self.waitDataBlock(pointer_location=current_pointer_location): | |
224 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
224 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
225 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
225 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
226 | # return 0 |
|
226 | # return 0 | |
|
227 | ||||
|
228 | #Dimensions : nChannels, nProfiles, nSamples | |||
227 |
|
229 | |||
228 | junk = numpy.transpose(junk, (2,0,1)) |
|
230 | junk = numpy.transpose(junk, (2,0,1)) | |
229 | self.datablock = junk['real'] + junk['imag']*1j |
|
231 | self.datablock = junk['real'] + junk['imag']*1j | |
230 |
|
232 | |||
231 | self.profileIndex = 0 |
|
233 | self.profileIndex = 0 | |
232 |
|
234 | |||
233 | self.flagIsNewFile = 0 |
|
235 | self.flagIsNewFile = 0 | |
234 | self.flagIsNewBlock = 1 |
|
236 | self.flagIsNewBlock = 1 | |
235 |
|
237 | |||
236 | self.nTotalBlocks += 1 |
|
238 | self.nTotalBlocks += 1 | |
237 | self.nReadBlocks += 1 |
|
239 | self.nReadBlocks += 1 | |
238 |
|
240 | |||
239 | return 1 |
|
241 | return 1 | |
240 |
|
242 | |||
241 | def getFirstHeader(self): |
|
243 | def getFirstHeader(self): | |
242 |
|
244 | |||
|
245 | self.getBasicHeader() | |||
|
246 | ||||
243 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
247 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
244 |
|
248 | |||
245 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
249 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
246 |
|
250 | |||
247 | if self.nTxs > 1: |
|
251 | if self.nTxs > 1: | |
248 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
252 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
249 |
|
253 | |||
250 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
|
254 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt | |
251 | # |
|
255 | # | |
252 | # if self.radarControllerHeaderObj.code is not None: |
|
256 | # if self.radarControllerHeaderObj.code is not None: | |
253 | # |
|
257 | # | |
254 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
258 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
255 | # |
|
259 | # | |
256 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
260 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
257 | # |
|
261 | # | |
258 | # self.dataOut.code = self.radarControllerHeaderObj.code |
|
262 | # self.dataOut.code = self.radarControllerHeaderObj.code | |
259 |
|
263 | |||
260 | self.dataOut.dtype = self.dtype |
|
264 | self.dataOut.dtype = self.dtype | |
261 |
|
265 | |||
262 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
266 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs | |
263 |
|
267 | |||
264 | if self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
268 | if self.processingHeaderObj.nHeights % self.nTxs != 0: | |
265 | raise ValueError, "nTxs (%d) should be a multiple of nHeights (%d)" %(self.nTxs, self.processingHeaderObj.nHeights) |
|
269 | raise ValueError, "nTxs (%d) should be a multiple of nHeights (%d)" %(self.nTxs, self.processingHeaderObj.nHeights) | |
266 |
|
270 | |||
267 | xf = self.processingHeaderObj.firstHeight + int(self.processingHeaderObj.nHeights/self.nTxs)*self.processingHeaderObj.deltaHeight |
|
271 | xf = self.processingHeaderObj.firstHeight + int(self.processingHeaderObj.nHeights/self.nTxs)*self.processingHeaderObj.deltaHeight | |
268 |
|
272 | |||
269 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
273 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
270 |
|
274 | |||
271 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
275 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
272 |
|
276 | |||
273 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
277 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
274 |
|
278 | |||
275 | self.dataOut.flagShiftFFT = False |
|
279 | self.dataOut.flagShiftFFT = False | |
276 |
|
280 | |||
277 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
281 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
278 |
|
282 | |||
279 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
283 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip | |
280 |
|
284 | |||
281 | self.dataOut.flagShiftFFT = False |
|
285 | self.dataOut.flagShiftFFT = False | |
282 |
|
286 | |||
283 | def getData(self): |
|
287 | def getData(self): | |
284 | """ |
|
288 | """ | |
285 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut |
|
289 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut | |
286 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos |
|
290 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos | |
287 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando |
|
291 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando | |
288 | "readNextBlock" |
|
292 | "readNextBlock" | |
289 |
|
293 | |||
290 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. |
|
294 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. | |
291 |
|
295 | |||
292 | Return: |
|
296 | Return: | |
293 |
|
297 | |||
294 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex |
|
298 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex | |
295 | es igual al total de perfiles leidos desde el archivo. |
|
299 | es igual al total de perfiles leidos desde el archivo. | |
296 |
|
300 | |||
297 | Si self.getByBlock == False: |
|
301 | Si self.getByBlock == False: | |
298 |
|
302 | |||
299 | self.dataOut.data = buffer[:, thisProfile, :] |
|
303 | self.dataOut.data = buffer[:, thisProfile, :] | |
300 |
|
304 | |||
301 | shape = [nChannels, nHeis] |
|
305 | shape = [nChannels, nHeis] | |
302 |
|
306 | |||
303 | Si self.getByBlock == True: |
|
307 | Si self.getByBlock == True: | |
304 |
|
308 | |||
305 | self.dataOut.data = buffer[:, :, :] |
|
309 | self.dataOut.data = buffer[:, :, :] | |
306 |
|
310 | |||
307 | shape = [nChannels, nProfiles, nHeis] |
|
311 | shape = [nChannels, nProfiles, nHeis] | |
308 |
|
312 | |||
309 | Variables afectadas: |
|
313 | Variables afectadas: | |
310 | self.dataOut |
|
314 | self.dataOut | |
311 | self.profileIndex |
|
315 | self.profileIndex | |
312 |
|
316 | |||
313 | Affected: |
|
317 | Affected: | |
314 | self.dataOut |
|
318 | self.dataOut | |
315 | self.profileIndex |
|
319 | self.profileIndex | |
316 | self.flagDiscontinuousBlock |
|
320 | self.flagDiscontinuousBlock | |
317 | self.flagIsNewBlock |
|
321 | self.flagIsNewBlock | |
318 | """ |
|
322 | """ | |
319 |
|
323 | |||
320 | if self.flagNoMoreFiles: |
|
324 | if self.flagNoMoreFiles: | |
321 | self.dataOut.flagNoData = True |
|
325 | self.dataOut.flagNoData = True | |
322 | print 'Process finished' |
|
326 | print 'Process finished' | |
323 | return 0 |
|
327 | return 0 | |
324 |
|
328 | |||
325 | self.flagDiscontinuousBlock = 0 |
|
329 | self.flagDiscontinuousBlock = 0 | |
326 | self.flagIsNewBlock = 0 |
|
330 | self.flagIsNewBlock = 0 | |
327 |
|
331 | |||
328 | if self.__hasNotDataInBuffer(): |
|
332 | if self.__hasNotDataInBuffer(): | |
329 |
|
333 | |||
330 | if not( self.readNextBlock() ): |
|
334 | if not( self.readNextBlock() ): | |
331 | return 0 |
|
335 | return 0 | |
332 |
|
336 | |||
333 | self.getFirstHeader() |
|
337 | self.getFirstHeader() | |
334 |
|
338 | |||
335 | if self.datablock is None: |
|
339 | if self.datablock is None: | |
336 | self.dataOut.flagNoData = True |
|
340 | self.dataOut.flagNoData = True | |
337 | return 0 |
|
341 | return 0 | |
338 |
|
342 | |||
339 | if not self.getByBlock: |
|
343 | if not self.getByBlock: | |
340 |
|
344 | |||
341 | """ |
|
345 | """ | |
342 | Return profile by profile |
|
346 | Return profile by profile | |
343 |
|
347 | |||
344 | If nTxs > 1 then one profile is divided by nTxs and number of total |
|
348 | If nTxs > 1 then one profile is divided by nTxs and number of total | |
345 | blocks is increased by nTxs (nProfiles *= nTxs) |
|
349 | blocks is increased by nTxs (nProfiles *= nTxs) | |
346 | """ |
|
350 | """ | |
347 | self.dataOut.flagDataAsBlock = False |
|
351 | self.dataOut.flagDataAsBlock = False | |
348 |
|
352 | |||
349 | if self.nTxs == 1: |
|
353 | if self.nTxs == 1: | |
350 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
354 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
351 | self.dataOut.profileIndex = self.profileIndex |
|
355 | self.dataOut.profileIndex = self.profileIndex | |
352 |
|
356 | |||
353 | self.profileIndex += 1 |
|
357 | self.profileIndex += 1 | |
354 |
|
358 | |||
355 | else: |
|
359 | else: | |
356 | iniHei_ForThisTx = (self.txIndex)*int(self.processingHeaderObj.nHeights/self.nTxs) |
|
360 | iniHei_ForThisTx = (self.txIndex)*int(self.processingHeaderObj.nHeights/self.nTxs) | |
357 | endHei_ForThisTx = (self.txIndex+1)*int(self.processingHeaderObj.nHeights/self.nTxs) |
|
361 | endHei_ForThisTx = (self.txIndex+1)*int(self.processingHeaderObj.nHeights/self.nTxs) | |
358 |
|
362 | |||
359 | # print iniHei_ForThisTx, endHei_ForThisTx |
|
363 | # print iniHei_ForThisTx, endHei_ForThisTx | |
360 |
|
364 | |||
361 | self.dataOut.data = self.datablock[:, self.profileIndex, iniHei_ForThisTx:endHei_ForThisTx] |
|
365 | self.dataOut.data = self.datablock[:, self.profileIndex, iniHei_ForThisTx:endHei_ForThisTx] | |
362 | self.dataOut.profileIndex = self.profileIndex*self.nTxs + self.txIndex |
|
366 | self.dataOut.profileIndex = self.profileIndex*self.nTxs + self.txIndex | |
363 |
|
367 | |||
364 | self.txIndex += 1 |
|
368 | self.txIndex += 1 | |
365 |
|
369 | |||
366 | if self.txIndex == self.nTxs: |
|
370 | if self.txIndex == self.nTxs: | |
367 | self.txIndex = 0 |
|
371 | self.txIndex = 0 | |
368 | self.profileIndex += 1 |
|
372 | self.profileIndex += 1 | |
369 |
|
373 | |||
370 | else: |
|
374 | else: | |
371 | """ |
|
375 | """ | |
372 | Return all block |
|
376 | Return all block | |
373 | """ |
|
377 | """ | |
374 | self.dataOut.flagDataAsBlock = True |
|
378 | self.dataOut.flagDataAsBlock = True | |
375 | self.dataOut.data = self.datablock |
|
379 | self.dataOut.data = self.datablock | |
376 | self.dataOut.profileIndex = self.processingHeaderObj.profilesPerBlock |
|
380 | self.dataOut.profileIndex = self.processingHeaderObj.profilesPerBlock | |
377 |
|
381 | |||
378 | self.profileIndex = self.processingHeaderObj.profilesPerBlock |
|
382 | self.profileIndex = self.processingHeaderObj.profilesPerBlock | |
379 |
|
383 | |||
380 | self.dataOut.flagNoData = False |
|
384 | self.dataOut.flagNoData = False | |
381 |
|
385 | |||
382 | self.getBasicHeader() |
|
386 | self.getBasicHeader() | |
383 |
|
387 | |||
384 | self.dataOut.realtime = self.online |
|
388 | self.dataOut.realtime = self.online | |
385 |
|
389 | |||
386 | return self.dataOut.data |
|
390 | return self.dataOut.data | |
387 |
|
391 | |||
388 | class VoltageWriter(JRODataWriter, Operation): |
|
392 | class VoltageWriter(JRODataWriter, Operation): | |
389 | """ |
|
393 | """ | |
390 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
394 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
391 | de los datos siempre se realiza por bloques. |
|
395 | de los datos siempre se realiza por bloques. | |
392 | """ |
|
396 | """ | |
393 |
|
397 | |||
394 | ext = ".r" |
|
398 | ext = ".r" | |
395 |
|
399 | |||
396 | optchar = "D" |
|
400 | optchar = "D" | |
397 |
|
401 | |||
398 | shapeBuffer = None |
|
402 | shapeBuffer = None | |
399 |
|
403 | |||
400 |
|
404 | |||
401 | def __init__(self): |
|
405 | def __init__(self): | |
402 | """ |
|
406 | """ | |
403 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
407 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
404 |
|
408 | |||
405 | Affected: |
|
409 | Affected: | |
406 | self.dataOut |
|
410 | self.dataOut | |
407 |
|
411 | |||
408 | Return: None |
|
412 | Return: None | |
409 | """ |
|
413 | """ | |
410 | Operation.__init__(self) |
|
414 | Operation.__init__(self) | |
411 |
|
415 | |||
412 | self.nTotalBlocks = 0 |
|
416 | self.nTotalBlocks = 0 | |
413 |
|
417 | |||
414 | self.profileIndex = 0 |
|
418 | self.profileIndex = 0 | |
415 |
|
419 | |||
416 | self.isConfig = False |
|
420 | self.isConfig = False | |
417 |
|
421 | |||
418 | self.fp = None |
|
422 | self.fp = None | |
419 |
|
423 | |||
420 | self.flagIsNewFile = 1 |
|
424 | self.flagIsNewFile = 1 | |
421 |
|
425 | |||
422 |
self. |
|
426 | self.blockIndex = 0 | |
423 |
|
427 | |||
424 | self.flagIsNewBlock = 0 |
|
428 | self.flagIsNewBlock = 0 | |
425 |
|
429 | |||
426 | self.setFile = None |
|
430 | self.setFile = None | |
427 |
|
431 | |||
428 | self.dtype = None |
|
432 | self.dtype = None | |
429 |
|
433 | |||
430 | self.path = None |
|
434 | self.path = None | |
431 |
|
435 | |||
432 | self.filename = None |
|
436 | self.filename = None | |
433 |
|
437 | |||
434 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
438 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
435 |
|
439 | |||
436 | self.systemHeaderObj = SystemHeader() |
|
440 | self.systemHeaderObj = SystemHeader() | |
437 |
|
441 | |||
438 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
442 | self.radarControllerHeaderObj = RadarControllerHeader() | |
439 |
|
443 | |||
440 | self.processingHeaderObj = ProcessingHeader() |
|
444 | self.processingHeaderObj = ProcessingHeader() | |
441 |
|
445 | |||
442 | def hasAllDataInBuffer(self): |
|
446 | def hasAllDataInBuffer(self): | |
443 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
447 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
444 | return 1 |
|
448 | return 1 | |
445 | return 0 |
|
449 | return 0 | |
446 |
|
450 | |||
447 |
|
451 | |||
448 | def setBlockDimension(self): |
|
452 | def setBlockDimension(self): | |
449 | """ |
|
453 | """ | |
450 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
454 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
451 |
|
455 | |||
452 | Affected: |
|
456 | Affected: | |
453 | self.shape_spc_Buffer |
|
457 | self.shape_spc_Buffer | |
454 | self.shape_cspc_Buffer |
|
458 | self.shape_cspc_Buffer | |
455 | self.shape_dc_Buffer |
|
459 | self.shape_dc_Buffer | |
456 |
|
460 | |||
457 | Return: None |
|
461 | Return: None | |
458 | """ |
|
462 | """ | |
459 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
463 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
460 | self.processingHeaderObj.nHeights, |
|
464 | self.processingHeaderObj.nHeights, | |
461 | self.systemHeaderObj.nChannels) |
|
465 | self.systemHeaderObj.nChannels) | |
462 |
|
466 | |||
463 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
467 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
464 | self.processingHeaderObj.profilesPerBlock, |
|
468 | self.processingHeaderObj.profilesPerBlock, | |
465 | self.processingHeaderObj.nHeights), |
|
469 | self.processingHeaderObj.nHeights), | |
466 | dtype=numpy.dtype('complex64')) |
|
470 | dtype=numpy.dtype('complex64')) | |
467 |
|
471 | |||
468 | def writeBlock(self): |
|
472 | def writeBlock(self): | |
469 | """ |
|
473 | """ | |
470 | Escribe el buffer en el file designado |
|
474 | Escribe el buffer en el file designado | |
471 |
|
475 | |||
472 | Affected: |
|
476 | Affected: | |
473 | self.profileIndex |
|
477 | self.profileIndex | |
474 | self.flagIsNewFile |
|
478 | self.flagIsNewFile | |
475 | self.flagIsNewBlock |
|
479 | self.flagIsNewBlock | |
476 | self.nTotalBlocks |
|
480 | self.nTotalBlocks | |
477 | self.blockIndex |
|
481 | self.blockIndex | |
478 |
|
482 | |||
479 | Return: None |
|
483 | Return: None | |
480 | """ |
|
484 | """ | |
481 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
485 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
482 |
|
486 | |||
483 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
487 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
484 |
|
488 | |||
485 | data['real'] = junk.real |
|
489 | data['real'] = junk.real | |
486 | data['imag'] = junk.imag |
|
490 | data['imag'] = junk.imag | |
487 |
|
491 | |||
488 | data = data.reshape( (-1) ) |
|
492 | data = data.reshape( (-1) ) | |
489 |
|
493 | |||
490 | data.tofile( self.fp ) |
|
494 | data.tofile( self.fp ) | |
491 |
|
495 | |||
492 | self.datablock.fill(0) |
|
496 | self.datablock.fill(0) | |
493 |
|
497 | |||
494 | self.profileIndex = 0 |
|
498 | self.profileIndex = 0 | |
495 | self.flagIsNewFile = 0 |
|
499 | self.flagIsNewFile = 0 | |
496 | self.flagIsNewBlock = 1 |
|
500 | self.flagIsNewBlock = 1 | |
497 |
|
501 | |||
498 | self.blockIndex += 1 |
|
502 | self.blockIndex += 1 | |
499 | self.nTotalBlocks += 1 |
|
503 | self.nTotalBlocks += 1 | |
500 |
|
504 | |||
501 | # print "[Writing] Block = %04d" %self.blockIndex |
|
505 | # print "[Writing] Block = %04d" %self.blockIndex | |
502 |
|
506 | |||
503 | def putData(self): |
|
507 | def putData(self): | |
504 | """ |
|
508 | """ | |
505 | Setea un bloque de datos y luego los escribe en un file |
|
509 | Setea un bloque de datos y luego los escribe en un file | |
506 |
|
510 | |||
507 | Affected: |
|
511 | Affected: | |
508 | self.flagIsNewBlock |
|
512 | self.flagIsNewBlock | |
509 | self.profileIndex |
|
513 | self.profileIndex | |
510 |
|
514 | |||
511 | Return: |
|
515 | Return: | |
512 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
516 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
513 | 1 : Si se escribio la data de un bloque en un file |
|
517 | 1 : Si se escribio la data de un bloque en un file | |
514 | """ |
|
518 | """ | |
515 | if self.dataOut.flagNoData: |
|
519 | if self.dataOut.flagNoData: | |
516 | return 0 |
|
520 | return 0 | |
517 |
|
521 | |||
518 | self.flagIsNewBlock = 0 |
|
522 | self.flagIsNewBlock = 0 | |
519 |
|
523 | |||
520 | if self.dataOut.flagDiscontinuousBlock: |
|
524 | if self.dataOut.flagDiscontinuousBlock: | |
521 | self.datablock.fill(0) |
|
525 | self.datablock.fill(0) | |
522 | self.profileIndex = 0 |
|
526 | self.profileIndex = 0 | |
523 | self.setNextFile() |
|
527 | self.setNextFile() | |
524 |
|
528 | |||
525 | if self.profileIndex == 0: |
|
529 | if self.profileIndex == 0: | |
526 | self.setBasicHeader() |
|
530 | self.setBasicHeader() | |
527 |
|
531 | |||
528 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
532 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
529 |
|
533 | |||
530 | self.profileIndex += 1 |
|
534 | self.profileIndex += 1 | |
531 |
|
535 | |||
532 | if self.hasAllDataInBuffer(): |
|
536 | if self.hasAllDataInBuffer(): | |
533 | #if self.flagIsNewFile: |
|
537 | #if self.flagIsNewFile: | |
534 | self.writeNextBlock() |
|
538 | self.writeNextBlock() | |
535 | # self.setFirstHeader() |
|
539 | # self.setFirstHeader() | |
536 |
|
540 | |||
537 | return 1 |
|
541 | return 1 | |
538 |
|
542 | |||
539 | def __getProcessFlags(self): |
|
|||
540 |
|
||||
541 | processFlags = 0 |
|
|||
542 |
|
||||
543 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
|||
544 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
|||
545 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
|||
546 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
|||
547 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
|||
548 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
|||
549 |
|
||||
550 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
|||
551 |
|
||||
552 |
|
||||
553 |
|
||||
554 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
|||
555 | PROCFLAG.DATATYPE_SHORT, |
|
|||
556 | PROCFLAG.DATATYPE_LONG, |
|
|||
557 | PROCFLAG.DATATYPE_INT64, |
|
|||
558 | PROCFLAG.DATATYPE_FLOAT, |
|
|||
559 | PROCFLAG.DATATYPE_DOUBLE] |
|
|||
560 |
|
||||
561 |
|
||||
562 | for index in range(len(dtypeList)): |
|
|||
563 | if self.dataOut.dtype == dtypeList[index]: |
|
|||
564 | dtypeValue = datatypeValueList[index] |
|
|||
565 | break |
|
|||
566 |
|
||||
567 | processFlags += dtypeValue |
|
|||
568 |
|
||||
569 | if self.dataOut.flagDecodeData: |
|
|||
570 | processFlags += PROCFLAG.DECODE_DATA |
|
|||
571 |
|
||||
572 | if self.dataOut.flagDeflipData: |
|
|||
573 | processFlags += PROCFLAG.DEFLIP_DATA |
|
|||
574 |
|
||||
575 | if self.dataOut.code is not None: |
|
|||
576 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
|||
577 |
|
||||
578 | if self.dataOut.nCohInt > 1: |
|
|||
579 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
|||
580 |
|
||||
581 | return processFlags |
|
|||
582 |
|
||||
583 |
|
||||
584 | def __getBlockSize(self): |
|
543 | def __getBlockSize(self): | |
585 | ''' |
|
544 | ''' | |
586 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
545 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
587 | ''' |
|
546 | ''' | |
588 |
|
547 | |||
589 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
548 | dtype_width = self.getDtypeWidth() | |
590 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
|||
591 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
|||
592 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
|||
593 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
|||
594 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
|||
595 |
|
||||
596 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
|||
597 | datatypeValueList = [1,2,4,8,4,8] |
|
|||
598 | for index in range(len(dtypeList)): |
|
|||
599 | if self.dataOut.dtype == dtypeList[index]: |
|
|||
600 | datatypeValue = datatypeValueList[index] |
|
|||
601 | break |
|
|||
602 |
|
549 | |||
603 |
blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * d |
|
550 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2) | |
604 |
|
551 | |||
605 | return blocksize |
|
552 | return blocksize | |
606 |
|
553 | |||
607 | def setFirstHeader(self): |
|
554 | def setFirstHeader(self): | |
608 |
|
555 | |||
609 | """ |
|
556 | """ | |
610 | Obtiene una copia del First Header |
|
557 | Obtiene una copia del First Header | |
611 |
|
558 | |||
612 | Affected: |
|
559 | Affected: | |
613 | self.systemHeaderObj |
|
560 | self.systemHeaderObj | |
614 | self.radarControllerHeaderObj |
|
561 | self.radarControllerHeaderObj | |
615 | self.dtype |
|
562 | self.dtype | |
616 |
|
563 | |||
617 | Return: |
|
564 | Return: | |
618 | None |
|
565 | None | |
619 | """ |
|
566 | """ | |
620 |
|
567 | |||
621 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
568 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
622 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
569 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
623 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
570 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
624 |
|
571 | |||
625 | self.setBasicHeader() |
|
572 | self.setBasicHeader() | |
626 |
|
573 | |||
627 | processingHeaderSize = 40 # bytes |
|
574 | processingHeaderSize = 40 # bytes | |
628 | self.processingHeaderObj.dtype = 0 # Voltage |
|
575 | self.processingHeaderObj.dtype = 0 # Voltage | |
629 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
576 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
630 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
577 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
631 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
578 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
632 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
579 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
633 |
self.processingHeaderObj.processFlags = self. |
|
580 | self.processingHeaderObj.processFlags = self.getProcessFlags() | |
634 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
581 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
635 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
582 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
636 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
583 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
637 |
|
584 | |||
638 | # if self.dataOut.code is not None: |
|
585 | # if self.dataOut.code is not None: | |
639 | # self.processingHeaderObj.code = self.dataOut.code |
|
586 | # self.processingHeaderObj.code = self.dataOut.code | |
640 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
587 | # self.processingHeaderObj.nCode = self.dataOut.nCode | |
641 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
588 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
642 | # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
589 | # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) | |
643 | # processingHeaderSize += codesize |
|
590 | # processingHeaderSize += codesize | |
644 |
|
591 | |||
645 | if self.processingHeaderObj.nWindows != 0: |
|
592 | if self.processingHeaderObj.nWindows != 0: | |
646 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
593 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
647 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
594 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
648 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
595 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
649 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
596 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
650 | processingHeaderSize += 12 |
|
597 | processingHeaderSize += 12 | |
651 |
|
598 | |||
652 | self.processingHeaderObj.size = processingHeaderSize No newline at end of file |
|
599 | self.processingHeaderObj.size = processingHeaderSize |
General Comments 0
You need to be logged in to leave comments.
Login now