@@ -0,0 +1,49 | |||
|
1 | ''' | |
|
2 | Created on 23/01/2012 | |
|
3 | ||
|
4 | @author: danielangelsuarezmunoz | |
|
5 | ''' | |
|
6 | import os | |
|
7 | import sys | |
|
8 | import datetime | |
|
9 | import time | |
|
10 | ||
|
11 | class TestIO(): | |
|
12 | ||
|
13 | def __init__(self): | |
|
14 | self.setValues() | |
|
15 | self.createVoltageObjects() | |
|
16 | self.testReadVoltage() | |
|
17 | pass | |
|
18 | ||
|
19 | def setValues(self): | |
|
20 | ||
|
21 | ||
|
22 | self.path = '/Users/danielangelsuarezmunoz/Documents/Projects' | |
|
23 | self.startDateTime = datetime.datetime(2007,5,1,17,49,0) | |
|
24 | self.endDateTime = datetime.datetime(2007,5,1,18,10,0) | |
|
25 | ||
|
26 | def createVoltageObjects(self): | |
|
27 | path = os.path.split(os.getcwd())[0] | |
|
28 | sys.path.append(path) | |
|
29 | ||
|
30 | from IO.Voltage import VoltageReader | |
|
31 | from Model.Voltage import Voltage | |
|
32 | ||
|
33 | self.voltageModelObj = Voltage() | |
|
34 | self.voltageReaderObj = VoltageReader(self.voltageModelObj) | |
|
35 | self.voltageReaderObj.setup(self.path, self.startDateTime, self.endDateTime) | |
|
36 | ||
|
37 | def testReadVoltage(self): | |
|
38 | while(not(self.voltageReaderObj.noMoreFiles)): | |
|
39 | ||
|
40 | self.voltageReaderObj.getData() | |
|
41 | if self.voltageReaderObj.flagResetProcessing: | |
|
42 | print 'jump' | |
|
43 | ||
|
44 | if self.voltageReaderObj.flagIsNewBlock: | |
|
45 | print 'Block No %04d, Time: %s'%(self.voltageReaderObj.nReadBlocks, | |
|
46 | datetime.datetime.fromtimestamp(self.voltageReaderObj.m_BasicHeader.utc)) | |
|
47 | ||
|
48 | if __name__ == '__main__': | |
|
49 | TestIO() No newline at end of file |
@@ -1,269 +1,312 | |||
|
1 | 1 | import numpy |
|
2 | 2 | |
|
3 | 3 | class PROCFLAG: |
|
4 | 4 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
5 | 5 | DECODE_DATA = numpy.uint32(0x00000002) |
|
6 | 6 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
7 | 7 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
8 | 8 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
9 | 9 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
10 | 10 | |
|
11 | 11 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
12 | 12 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
13 | 13 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
14 | 14 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
15 | 15 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
16 | 16 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
17 | 17 | |
|
18 | 18 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
19 | 19 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
20 | 20 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
21 | 21 | |
|
22 | 22 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
23 | 23 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
24 | 24 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
25 | 25 | |
|
26 | 26 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
27 | 27 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
28 | 28 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
29 | 29 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
30 | 30 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
31 | 31 | |
|
32 | 32 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
33 | 33 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
34 | 34 | |
|
35 | 35 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
36 | 36 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
37 | 37 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
38 | 38 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
39 | 39 | |
|
40 | 40 | class BasicHeader: |
|
41 | 41 | |
|
42 | 42 | size = 0 |
|
43 | 43 | version = 0 |
|
44 | 44 | dataBlock = 0 |
|
45 | 45 | utc = 0 |
|
46 | 46 | miliSecond = 0 |
|
47 | 47 | timeZone = 0 |
|
48 | 48 | dstFlag = 0 |
|
49 | 49 | errorCount = 0 |
|
50 | 50 | struct = numpy.dtype([ |
|
51 | 51 | ('nSize','<u4'), |
|
52 | 52 | ('nVersion','<u2'), |
|
53 | 53 | ('nDataBlockId','<u4'), |
|
54 | 54 | ('nUtime','<u4'), |
|
55 | 55 | ('nMilsec','<u2'), |
|
56 | 56 | ('nTimezone','<i2'), |
|
57 | 57 | ('nDstflag','<i2'), |
|
58 | 58 | ('nErrorCount','<u4') |
|
59 | 59 | ]) |
|
60 | 60 | |
|
61 | 61 | def __init__(self): |
|
62 | 62 | pass |
|
63 | 63 | |
|
64 | 64 | def read(self, fp): |
|
65 | 65 | |
|
66 | 66 | header = numpy.fromfile(fp, self.struct,1) |
|
67 | 67 | self.size = header['nSize'][0] |
|
68 | 68 | self.version = header['nVersion'][0] |
|
69 | 69 | self.dataBlock = header['nDataBlockId'][0] |
|
70 | 70 | self.utc = header['nUtime'][0] |
|
71 | 71 | self.miliSecond = header['nMilsec'][0] |
|
72 | 72 | self.timeZone = header['nTimezone'][0] |
|
73 | 73 | self.dstFlag = header['nDstflag'][0] |
|
74 | 74 | self.errorCount = header['nErrorCount'][0] |
|
75 | 75 | |
|
76 | 76 | return 1 |
|
77 | 77 | |
|
78 | 78 | def copy(self): |
|
79 | 79 | |
|
80 | 80 | obj = BasicHeader() |
|
81 | 81 | obj.size = self.size |
|
82 | ||
|
82 | obj.version = self.version | |
|
83 | obj.dataBlock = self.dataBlock | |
|
84 | obj.utc = self.utc | |
|
85 | obj.miliSecond = self.miliSecond | |
|
86 | obj.timeZone = self.timeZone | |
|
87 | obj.dstFlag = self.dstFlag | |
|
88 | obj.errorCount = self.errorCount | |
|
83 | 89 | |
|
84 | 90 | return obj |
|
85 | 91 | |
|
86 | 92 | class SystemHeader: |
|
87 | 93 | size = 0 |
|
88 | 94 | numSamples = 0 |
|
89 | 95 | numProfiles = 0 |
|
90 | 96 | numChannels = 0 |
|
91 | 97 | adcResolution = 0 |
|
92 | 98 | pciDioBusWidth = 0 |
|
93 | 99 | struct = numpy.dtype([ |
|
94 | 100 | ('nSize','<u4'), |
|
95 | 101 | ('nNumSamples','<u4'), |
|
96 | 102 | ('nNumProfiles','<u4'), |
|
97 | 103 | ('nNumChannels','<u4'), |
|
98 | 104 | ('nADCResolution','<u4'), |
|
99 | 105 | ('nPCDIOBusWidth','<u4'), |
|
100 | 106 | ]) |
|
101 | 107 | |
|
102 | 108 | def __init__(self): |
|
103 | 109 | pass |
|
104 | 110 | |
|
105 | 111 | def read(self, fp): |
|
106 | 112 | header = numpy.fromfile(fp,self.struct,1) |
|
107 | 113 | self.size = header['nSize'][0] |
|
108 | 114 | self.numSamples = header['nNumSamples'][0] |
|
109 | 115 | self.numProfiles = header['nNumProfiles'][0] |
|
110 | 116 | self.numChannels = header['nNumChannels'][0] |
|
111 | 117 | self.adcResolution = header['nADCResolution'][0] |
|
112 | 118 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
113 | 119 | |
|
114 | 120 | |
|
115 | 121 | return 1 |
|
116 | 122 | |
|
117 | 123 | def copy(self): |
|
118 | 124 | |
|
119 | 125 | obj = SystemHeader() |
|
120 | 126 | obj.size = self.size |
|
127 | obj.numSamples = self.numSamples | |
|
128 | obj.numProfiles = self.numProfiles | |
|
129 | obj.numChannels = self.numChannels | |
|
130 | obj.adcResolution = self.adcResolution | |
|
131 | self.pciDioBusWidth = self.pciDioBusWidth | |
|
121 | 132 | |
|
122 | 133 | |
|
123 | 134 | return obj |
|
124 | 135 | |
|
125 | 136 | class RadarControllerHeader: |
|
126 | 137 | size = 0 |
|
127 | 138 | expType = 0 |
|
128 | 139 | nTx = 0 |
|
129 | 140 | ipp = 0 |
|
130 | 141 | txA = 0 |
|
131 | 142 | txB = 0 |
|
132 | 143 | numWindows = 0 |
|
133 | 144 | numTaus = 0 |
|
134 | 145 | codeType = 0 |
|
135 | 146 | line6Function = 0 |
|
136 | 147 | line5Fuction = 0 |
|
137 | 148 | fClock = 0 |
|
138 | 149 | prePulseBefore = 0 |
|
139 | 150 | prePulserAfter = 0 |
|
140 | 151 | rangeIpp = 0 |
|
141 | 152 | rangeTxA = 0 |
|
142 | 153 | rangeTxB = 0 |
|
143 | 154 | struct = numpy.dtype([ |
|
144 | 155 | ('nSize','<u4'), |
|
145 | 156 | ('nExpType','<u4'), |
|
146 | 157 | ('nNTx','<u4'), |
|
147 | 158 | ('fIpp','<f4'), |
|
148 | 159 | ('fTxA','<f4'), |
|
149 | 160 | ('fTxB','<f4'), |
|
150 | 161 | ('nNumWindows','<u4'), |
|
151 | 162 | ('nNumTaus','<u4'), |
|
152 | 163 | ('nCodeType','<u4'), |
|
153 | 164 | ('nLine6Function','<u4'), |
|
154 | 165 | ('nLine5Function','<u4'), |
|
155 | 166 | ('fClock','<f4'), |
|
156 | 167 | ('nPrePulseBefore','<u4'), |
|
157 | 168 | ('nPrePulseAfter','<u4'), |
|
158 | 169 | ('sRangeIPP','<a20'), |
|
159 | 170 | ('sRangeTxA','<a20'), |
|
160 | 171 | ('sRangeTxB','<a20'), |
|
161 | 172 | ]) |
|
162 | 173 | |
|
163 | 174 | |
|
164 | 175 | def __init__(self): |
|
165 | 176 | pass |
|
166 | 177 | |
|
167 | 178 | def read(self, fp): |
|
168 | 179 | header = numpy.fromfile(fp,self.struct,1) |
|
169 | 180 | self.size = header['nSize'][0] |
|
170 | 181 | self.expType = header['nExpType'][0] |
|
171 | 182 | self.nTx = header['nNTx'][0] |
|
172 | 183 | self.ipp = header['fIpp'][0] |
|
173 | 184 | self.txA = header['fTxA'][0] |
|
174 | 185 | self.txB = header['fTxB'][0] |
|
175 | 186 | self.numWindows = header['nNumWindows'][0] |
|
176 | 187 | self.numTaus = header['nNumTaus'][0] |
|
177 | 188 | self.codeType = header['nCodeType'][0] |
|
178 | 189 | self.line6Function = header['nLine6Function'][0] |
|
179 | 190 | self.line5Fuction = header['nLine5Function'][0] |
|
180 | 191 | self.fClock = header['fClock'][0] |
|
181 | 192 | self.prePulseBefore = header['nPrePulseBefore'][0] |
|
182 | 193 | self.prePulserAfter = header['nPrePulseAfter'][0] |
|
183 | 194 | self.rangeIpp = header['sRangeIPP'][0] |
|
184 | 195 | self.rangeTxA = header['sRangeTxA'][0] |
|
185 | 196 | self.rangeTxB = header['sRangeTxB'][0] |
|
186 | 197 | # jump Dynamic Radar Controller Header |
|
187 | 198 | jumpHeader = self.size - 116 |
|
188 | 199 | fp.seek(fp.tell() + jumpHeader) |
|
189 | 200 | |
|
190 | 201 | return 1 |
|
191 | 202 | |
|
192 | 203 | def copy(self): |
|
193 | 204 | |
|
194 | 205 | obj = RadarControllerHeader() |
|
195 | 206 | obj.size = self.size |
|
196 | ||
|
207 | obj.expType = self.expType | |
|
208 | obj.nTx = self.nTx | |
|
209 | obj.ipp = self.ipp | |
|
210 | obj.txA = self.txA | |
|
211 | obj.txB = self.txB | |
|
212 | obj.numWindows = self.numWindows | |
|
213 | obj.numTaus = self.numTaus | |
|
214 | obj.codeType = self.codeType | |
|
215 | obj.line6Function = self.line6Function | |
|
216 | obj.line5Fuction = self.line5Fuction | |
|
217 | obj.fClock = self.fClock | |
|
218 | obj.prePulseBefore = self.prePulseBefore | |
|
219 | obj.prePulserAfter = self.prePulserAfter | |
|
220 | obj.rangeIpp = self.rangeIpp | |
|
221 | obj.rangeTxA = self.rangeTxA | |
|
222 | obj.rangeTxB = self.rangeTxB | |
|
197 | 223 | |
|
198 | 224 | return obj |
|
199 | 225 | |
|
200 | 226 | class ProcessingHeader: |
|
201 | 227 | size = 0 |
|
202 | 228 | dataType = 0 |
|
203 | 229 | blockSize = 0 |
|
204 | 230 | profilesPerBlock = 0 |
|
205 | 231 | dataBlocksPerFile = 0 |
|
206 | 232 | numWindows = 0 |
|
207 | 233 | processFlags = 0 |
|
208 | 234 | coherentInt = 0 |
|
209 | 235 | incoherentInt = 0 |
|
210 | 236 | totalSpectra = 0 |
|
211 | 237 | struct = numpy.dtype([ |
|
212 | 238 | ('nSize','<u4'), |
|
213 | 239 | ('nDataType','<u4'), |
|
214 | 240 | ('nSizeOfDataBlock','<u4'), |
|
215 | 241 | ('nProfilesperBlock','<u4'), |
|
216 | 242 | ('nDataBlocksperFile','<u4'), |
|
217 | 243 | ('nNumWindows','<u4'), |
|
218 | 244 | ('nProcessFlags','<u4'), |
|
219 | 245 | ('nCoherentIntegrations','<u4'), |
|
220 | 246 | ('nIncoherentIntegrations','<u4'), |
|
221 | 247 | ('nTotalSpectra','<u4') |
|
222 | 248 | ]) |
|
223 | 249 | samplingWindow = 0 |
|
224 | 250 | structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
225 | 251 | numHeights = 0 |
|
226 | 252 | firstHeight = 0 |
|
227 | 253 | deltaHeight = 0 |
|
228 | 254 | samplesWin = 0 |
|
229 | 255 | spectraComb = 0 |
|
230 | 256 | numCode = 0 |
|
231 | 257 | codes = 0 |
|
232 | 258 | numBaud = 0 |
|
233 | 259 | |
|
234 | 260 | def __init__(self): |
|
235 | 261 | pass |
|
236 | 262 | |
|
237 | 263 | def read(self, fp): |
|
238 | 264 | header = numpy.fromfile(fp,self.struct,1) |
|
239 | 265 | self.size = header['nSize'][0] |
|
240 | 266 | self.dataType = header['nDataType'][0] |
|
241 | 267 | self.blockSize = header['nSizeOfDataBlock'][0] |
|
242 | 268 | self.profilesPerBlock = header['nProfilesperBlock'][0] |
|
243 | 269 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] |
|
244 | 270 | self.numWindows = header['nNumWindows'][0] |
|
245 | 271 | self.processFlags = header['nProcessFlags'] |
|
246 | 272 | self.coherentInt = header['nCoherentIntegrations'][0] |
|
247 | 273 | self.incoherentInt = header['nIncoherentIntegrations'][0] |
|
248 | 274 | self.totalSpectra = header['nTotalSpectra'][0] |
|
249 | 275 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows) |
|
250 | 276 | self.numHeights = numpy.sum(self.samplingWindow['nsa']) |
|
251 | 277 | self.firstHeight = self.samplingWindow['h0'] |
|
252 | 278 | self.deltaHeight = self.samplingWindow['dh'] |
|
253 | 279 | self.samplesWin = self.samplingWindow['nsa'] |
|
254 | 280 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
255 | 281 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
256 | 282 | self.numCode = numpy.fromfile(fp,'<u4',1) |
|
257 | 283 | self.numBaud = numpy.fromfile(fp,'<u4',1) |
|
258 | 284 | self.codes = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode) |
|
259 | 285 | |
|
260 | 286 | |
|
261 | 287 | return 1 |
|
262 | 288 | |
|
263 | 289 | def copy(self): |
|
264 | 290 | |
|
265 | 291 | obj = ProcessingHeader() |
|
266 | 292 | obj.size = self.size |
|
267 | ||
|
293 | obj.dataType = self.dataType | |
|
294 | obj.blockSize = self.blockSize | |
|
295 | obj.profilesPerBlock = self.profilesPerBlock | |
|
296 | obj.dataBlocksPerFile = self.dataBlocksPerFile | |
|
297 | obj.numWindows = self.numWindows | |
|
298 | obj.processFlags = self.processFlags | |
|
299 | obj.coherentInt = self.coherentInt | |
|
300 | obj.incoherentInt = self.incoherentInt | |
|
301 | obj.totalSpectra = self.totalSpectra | |
|
302 | obj.samplingWindow = self.samplingWindow | |
|
303 | obj.numHeights = self.numHeights | |
|
304 | obj.firstHeight = self.firstHeight | |
|
305 | obj.deltaHeight = self.deltaHeight | |
|
306 | obj.samplesWin = self.samplesWin | |
|
307 | obj.spectraComb = self.spectraComb | |
|
308 | obj.numCode = self.numCode | |
|
309 | obj.numBaud = self.numBaud | |
|
310 | obj.codes = self.codes | |
|
268 | 311 | |
|
269 | 312 | return obj No newline at end of file |
@@ -1,454 +1,459 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 23/01/2012 |
|
3 | 3 | |
|
4 | 4 | @author: danielangelsuarezmunoz |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | import os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | import glob |
|
11 | 11 | import fnmatch |
|
12 | 12 | import time |
|
13 | 13 | import datetime |
|
14 | 14 | |
|
15 | from Header import * | |
|
16 | from Data import DataReader | |
|
17 | from Data import DataWriter | |
|
15 | from IO.Header import * | |
|
16 | from IO.Data import DataReader | |
|
17 | from IO.Data import DataWriter | |
|
18 | 18 | |
|
19 | 19 | path = os.path.split(os.getcwd())[0] |
|
20 | 20 | sys.path.append(path) |
|
21 | 21 | |
|
22 | 22 | from Model.Voltage import Voltage |
|
23 | 23 | |
|
24 | 24 | class VoltageReader(DataReader): |
|
25 | 25 | |
|
26 | 26 | __idFile = None |
|
27 | 27 | |
|
28 | 28 | __fp = None |
|
29 | 29 | |
|
30 | 30 | __startDateTime = None |
|
31 | 31 | |
|
32 | 32 | __endDateTime = None |
|
33 | 33 | |
|
34 | 34 | __dataType = None |
|
35 | 35 | |
|
36 | 36 | __fileSizeByHeader = 0 |
|
37 | 37 | |
|
38 | 38 | __pathList = [] |
|
39 | 39 | |
|
40 | 40 | filenameList = [] |
|
41 | 41 | |
|
42 | 42 | __lastUTTime = 0 |
|
43 | 43 | |
|
44 | 44 | __maxTimeStep = 5 |
|
45 | 45 | |
|
46 | 46 | __flagIsNewFile = 0 |
|
47 | 47 | |
|
48 | __ippSeconds = 0 | |
|
49 | ||
|
48 | 50 | flagResetProcessing = 0 |
|
49 | 51 | |
|
50 | 52 | flagIsNewBlock = 0 |
|
51 | 53 | |
|
52 | 54 | noMoreFiles = 0 |
|
53 | 55 | |
|
54 | 56 | nReadBlocks = 0 |
|
55 | 57 | |
|
56 | 58 | online = 0 |
|
57 | 59 | |
|
58 | 60 | filename = None |
|
59 | 61 | |
|
60 | 62 | fileSize = None |
|
61 | 63 | |
|
62 | 64 | firstHeaderSize = 0 |
|
63 | 65 | |
|
64 | 66 | basicHeaderSize = 24 |
|
65 | 67 | |
|
66 | 68 | m_BasicHeader = BasicHeader() |
|
67 | 69 | |
|
68 | 70 | m_SystemHeader = SystemHeader() |
|
69 | 71 | |
|
70 | 72 | m_RadarControllerHeader = RadarControllerHeader() |
|
71 | 73 | |
|
72 | 74 | m_ProcessingHeader = ProcessingHeader() |
|
73 | 75 | |
|
74 | 76 | m_Voltage = None |
|
75 | 77 | |
|
76 | 78 | __buffer = 0 |
|
77 | 79 | |
|
78 | 80 | __buffer_id = 9999 |
|
79 | 81 | |
|
80 | 82 | def __init__(self, m_Voltage = None): |
|
81 | 83 | |
|
82 | 84 | if m_Voltage == None: |
|
83 | 85 | m_Voltage = Voltage() |
|
84 | 86 | |
|
85 | 87 | self.m_Voltage = m_Voltage |
|
86 | 88 | |
|
87 | 89 | def __rdSystemHeader(self,fp=None): |
|
88 | 90 | if fp == None: |
|
89 | 91 | fp = self.__fp |
|
90 | 92 | |
|
91 | 93 | self.m_SystemHeader.read(fp) |
|
92 | 94 | |
|
93 | 95 | def __rdRadarControllerHeader(self,fp=None): |
|
94 | 96 | if fp == None: |
|
95 | 97 | fp = self.__fp |
|
96 | 98 | |
|
97 | 99 | self.m_RadarControllerHeader.read(fp) |
|
98 | 100 | |
|
99 | 101 | def __rdProcessingHeader(self,fp=None): |
|
100 | 102 | if fp == None: |
|
101 | 103 | fp = self.__fp |
|
102 | 104 | |
|
103 | 105 | self.m_ProcessingHeader.read(fp) |
|
104 | 106 | |
|
105 | 107 | def __searchFiles(self,path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"): |
|
106 | 108 | |
|
107 | 109 | print "Searching files ..." |
|
108 | 110 | |
|
109 | 111 | startUtSeconds = time.mktime(startDateTime.timetuple()) |
|
110 | 112 | endUtSeconds = time.mktime(endDateTime.timetuple()) |
|
111 | 113 | |
|
112 | 114 | # startYear = startDateTime.timetuple().tm_year |
|
113 | 115 | # endYear = endDateTime.timetuple().tm_year |
|
114 | 116 | # |
|
115 | 117 | # startDoy = startDateTime.timetuple().tm_yday |
|
116 | 118 | # endDoy = endDateTime.timetuple().tm_yday |
|
117 | 119 | # |
|
118 | 120 | # yearRange = range(startYear,endYear+1) |
|
119 | 121 | # |
|
120 | 122 | # doyDoubleList = [] |
|
121 | 123 | # if startYear == endYear: |
|
122 | 124 | # doyList = range(startDoy,endDoy+1) |
|
123 | 125 | # else: |
|
124 | 126 | # for year in yearRange: |
|
125 | 127 | # if (year == startYear): |
|
126 | 128 | # doyDoubleList.append(range(startDoy,365+1)) |
|
127 | 129 | # elif (year == endYear): |
|
128 | 130 | # doyDoubleList.append(range(1,endDoy+1)) |
|
129 | 131 | # else: |
|
130 | 132 | # doyDoubleList.append(range(1,365+1)) |
|
131 | 133 | # doyList = [] |
|
132 | 134 | # for list in doyDoubleList: |
|
133 | 135 | # doyList = doyList + list |
|
134 | 136 | # |
|
135 | 137 | # dirList = [] |
|
136 | 138 | # for thisPath in os.listdir(path): |
|
137 | 139 | # if os.path.isdir(os.path.join(path,thisPath)): |
|
138 | 140 | # #dirList.append(os.path.join(path,thisPath)) |
|
139 | 141 | # dirList.append(thisPath) |
|
140 | 142 | # |
|
141 | 143 | # pathList = [] |
|
142 | 144 | # pathDict = {} |
|
143 | 145 | # for year in yearRange: |
|
144 | 146 | # for doy in doyList: |
|
145 | 147 | # match = fnmatch.filter(dirList, 'D' + '%4.4d%3.3d' % (year,doy)) |
|
146 | 148 | # if len(match) == 0: |
|
147 | 149 | # match = fnmatch.filter(dirList, 'd' + '%4.4d%3.3d' % (year,doy)) |
|
148 | 150 | # if len(match) == 0: continue |
|
149 | 151 | # if expLabel == '': |
|
150 | 152 | # pathList.append(os.path.join(path,match[0])) |
|
151 | 153 | # pathDict.setdefault(os.path.join(path,match[0])) |
|
152 | 154 | # pathDict[os.path.join(path,match[0])] = [] |
|
153 | 155 | # else: |
|
154 | 156 | # pathList.append(os.path.join(path,os.path.join(match[0],expLabel))) |
|
155 | 157 | # pathDict.setdefault(os.path.join(path,os.path.join(match[0],expLabel))) |
|
156 | 158 | # pathDict[os.path.join(path,os.path.join(match[0],expLabel))] = [] |
|
157 | 159 | |
|
158 | 160 | |
|
159 | 161 | dirList = [] |
|
160 | 162 | for thisPath in os.listdir(path): |
|
161 | 163 | if os.path.isdir(os.path.join(path,thisPath)): |
|
162 | 164 | dirList.append(thisPath) |
|
163 | 165 | |
|
164 | 166 | pathList = [] |
|
165 | 167 | |
|
166 | 168 | thisDateTime = startDateTime |
|
167 | 169 | |
|
168 | 170 | while(thisDateTime <= endDateTime): |
|
169 | 171 | year = thisDateTime.timetuple().tm_year |
|
170 | 172 | doy = thisDateTime.timetuple().tm_yday |
|
171 | 173 | |
|
172 | 174 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
173 | 175 | if len(match) == 0: |
|
174 | 176 | thisDateTime += datetime.timedelta(1) |
|
175 | 177 | continue |
|
176 | 178 | |
|
177 | 179 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
178 | 180 | thisDateTime += datetime.timedelta(1) |
|
179 | 181 | |
|
180 | 182 | filenameList = [] |
|
181 | 183 | for thisPath in pathList: |
|
182 | 184 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
183 | 185 | #pathDict[thisPath].append(fileList) |
|
184 | 186 | fileList.sort() |
|
185 | 187 | for file in fileList: |
|
186 | 188 | filename = os.path.join(thisPath,file) |
|
187 | 189 | if self.isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
188 | 190 | filenameList.append(filename) |
|
189 | 191 | |
|
190 | 192 | self.filenameList = filenameList |
|
191 | 193 | |
|
192 | 194 | return pathList, filenameList |
|
193 | 195 | |
|
194 | 196 | def isThisFileinRange(self, filename, startUTSeconds=None, endUTSeconds=None): |
|
195 | 197 | |
|
196 | 198 | try: |
|
197 | 199 | fp = open(filename,'rb') |
|
198 | 200 | except: |
|
199 | 201 | raise IOError, "The file %s can't be opened" %(filename) |
|
200 | 202 | |
|
201 | 203 | if startUTSeconds==None: |
|
202 | 204 | startUTSeconds = self.startUTCSeconds |
|
203 | 205 | |
|
204 | 206 | if endUTSeconds==None: |
|
205 | 207 | endUTSeconds = self.endUTCSeconds |
|
206 | 208 | |
|
207 | 209 | m_BasicHeader = BasicHeader() |
|
208 | 210 | |
|
209 | 211 | if not(m_BasicHeader.read(fp)): |
|
210 | 212 | return 0 |
|
211 | 213 | |
|
212 | 214 | fp.close() |
|
213 | 215 | |
|
214 | 216 | if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): |
|
215 | 217 | return 0 |
|
216 | 218 | |
|
217 | 219 | return 1 |
|
218 | 220 | |
|
219 | 221 | def __readBasicHeader(self, fp=None): |
|
220 | 222 | |
|
221 | 223 | if fp == None: |
|
222 | 224 | fp = self.__fp |
|
223 | 225 | |
|
224 | 226 | self.m_BasicHeader.read(fp) |
|
225 | 227 | |
|
226 | 228 | def __readFirstHeader(self): |
|
227 | 229 | |
|
228 | 230 | self.__readBasicHeader() |
|
229 | 231 | self.__rdSystemHeader() |
|
230 | 232 | self.__rdRadarControllerHeader() |
|
231 | 233 | self.__rdProcessingHeader() |
|
232 | 234 | self.firstHeaderSize = self.m_BasicHeader.size |
|
233 | 235 | |
|
234 | 236 | data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
235 | 237 | if data_type == 0: |
|
236 | 238 | tmp=numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
237 | 239 | elif data_type == 1: |
|
238 | 240 | tmp=numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
239 | 241 | elif data_type == 2: |
|
240 | 242 | tmp=numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
241 | 243 | elif data_type == 3: |
|
242 | 244 | tmp=numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
243 | 245 | elif data_type == 4: |
|
244 | 246 | tmp=numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
245 | 247 | elif data_type == 5: |
|
246 | 248 | tmp=numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
247 | 249 | else: |
|
248 | 250 | raise ValueError, 'Data type was not defined' |
|
249 | 251 | |
|
250 | 252 | self.__dataType = tmp |
|
251 | 253 | self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) |
|
254 | c=3E8 | |
|
255 | self.__ippSeconds = 2*1000*self.m_RadarControllerHeader.ipp/c | |
|
252 | 256 | |
|
253 | 257 | def __setNextFileOnline(self): |
|
254 | 258 | return 0 |
|
255 | 259 | |
|
256 | 260 | def __setNextFileOffline(self): |
|
257 | 261 | |
|
258 | 262 | idFile = self.__idFile |
|
259 | 263 | while(True): |
|
260 | 264 | |
|
261 | 265 | idFile += 1 |
|
262 | 266 | |
|
263 | 267 | if not(idFile < len(self.filenameList)): |
|
264 | 268 | self.noMoreFiles = 1 |
|
265 | 269 | return 0 |
|
266 | 270 | |
|
267 | 271 | filename = self.filenameList[idFile] |
|
268 | 272 | fileSize = os.path.getsize(filename) |
|
269 | 273 | fp = open(filename,'rb') |
|
270 | 274 | |
|
271 | 275 | currentSize = fileSize - fp.tell() |
|
272 | 276 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize |
|
273 | 277 | |
|
274 | 278 | if (currentSize < neededSize): |
|
275 | 279 | continue |
|
276 | 280 | |
|
277 | 281 | break |
|
278 | 282 | |
|
279 | 283 | self.__flagIsNewFile = 1 |
|
280 | 284 | self.__idFile = idFile |
|
281 | 285 | self.filename = filename |
|
282 | 286 | self.fileSize = fileSize |
|
283 | 287 | self.__fp = fp |
|
284 | 288 | |
|
285 | 289 | print 'Setting the file: %s'%self.filename |
|
286 | 290 | |
|
287 | 291 | return 1 |
|
288 | 292 | |
|
289 | 293 | def __setNextFile(self): |
|
290 | 294 | |
|
291 | 295 | if self.online: |
|
292 | 296 | return self.__setNextFileOnline() |
|
293 | 297 | else: |
|
294 | 298 | return self.__setNextFileOffline() |
|
295 | 299 | |
|
296 | 300 | def __setNewBlock(self): |
|
297 | 301 | |
|
298 | 302 | if self.__fp == None: |
|
299 | 303 | return 0 |
|
300 | 304 | |
|
301 | 305 | if self.__flagIsNewFile: |
|
302 | 306 | return 1 |
|
303 | 307 | |
|
304 | 308 | currentSize = self.fileSize - self.__fp.tell() |
|
305 | 309 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize |
|
306 | 310 | |
|
307 | 311 | # Bloque Completo |
|
308 | 312 | if (currentSize >= neededSize): |
|
309 | 313 | self.__readBasicHeader() |
|
310 | 314 | return 1 |
|
311 | 315 | |
|
312 | 316 | if not(self.__setNextFile()): |
|
313 | 317 | return 0 |
|
314 | 318 | |
|
315 | 319 | self.__readFirstHeader() |
|
316 | 320 | |
|
317 | 321 | deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this |
|
318 | 322 | |
|
319 | 323 | self.flagResetProcessing = 0 |
|
320 | 324 | if deltaTime > self.__maxTimeStep: |
|
321 | 325 | self.flagResetProcessing = 1 |
|
322 | 326 | self.nReadBlocks = 0 |
|
323 | 327 | |
|
324 | 328 | return 1 |
|
325 | 329 | |
|
326 | 330 | def __readBlock(self): |
|
327 | 331 | """Lee el bloque de datos desde la posicion actual del puntero del archivo y |
|
328 | 332 | actualiza todos los parametros relacionados al bloque de datos (data, time, |
|
329 | 333 | etc). La data leida es almacenada en el buffer y el contador de datos leidos es |
|
330 | 334 | seteado a 0 |
|
331 | 335 | """ |
|
332 | 336 | |
|
333 | 337 | pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels |
|
334 | 338 | |
|
335 | 339 | data = numpy.fromfile(self.__fp,self.__dataType,pts2read) |
|
336 | 340 | |
|
337 | 341 | data = data.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) |
|
338 | 342 | |
|
339 | 343 | self.__flagIsNewFile = 0 |
|
340 | 344 | |
|
341 | 345 | self.flagIsNewBlock = 1 |
|
342 | 346 | |
|
343 | 347 | self.nReadBlocks += 1 |
|
344 | 348 | |
|
345 | 349 | self.__buffer = data |
|
346 | 350 | |
|
347 | 351 | self.__buffer_id = 0 |
|
348 | 352 | |
|
349 | 353 | def readNextBlock(self): |
|
350 | 354 | |
|
351 | 355 | if not(self.__setNewBlock()): |
|
352 | 356 | return 0 |
|
353 | 357 | |
|
354 | 358 | self.__readBlock() |
|
355 | 359 | |
|
356 | 360 | self.__lastUTTime = self.m_BasicHeader.utc |
|
357 | 361 | |
|
358 | 362 | return 1 |
|
359 | 363 | |
|
360 | 364 | def __hasNotDataInBuffer(self): |
|
361 | 365 | if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock: |
|
362 | 366 | return 1 |
|
363 | 367 | |
|
364 | 368 | return 0 |
|
365 | 369 | |
|
366 | 370 | def getData(self): |
|
367 | 371 | """Obtiene un unidad de datos del buffer de lectura y es copiada a la clase "Voltage" |
|
368 | 372 | con todos los parametros asociados a este. cuando no hay datos en el buffer de |
|
369 | 373 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
370 | 374 | """ |
|
371 | 375 | self.flagResetProcessing = 0 |
|
372 | 376 | self.flagIsNewBlock = 0 |
|
373 | 377 | |
|
374 | 378 | if self.__hasNotDataInBuffer(): |
|
375 | 379 | self.readNextBlock() |
|
376 | 380 | |
|
377 | 381 | if self.noMoreFiles == 1: |
|
378 | 382 | print 'Process finished' |
|
379 | 383 | return None |
|
380 | 384 | |
|
381 | 385 | data = self.__buffer[self.__buffer_id,:,:] |
|
382 |
|
|
|
383 | ||
|
384 | # self.m_Voltage.data = data | |
|
385 | # self.m_Voltage.timeProfile = time | |
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 | # self.m_Voltage.m_SystemHeader = self.m_systemHeader.copy() | |
|
386 | ||
|
387 | time = self.m_BasicHeader.utc + self.__buffer_id*self.__ippSeconds | |
|
388 | ||
|
389 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() | |
|
390 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() | |
|
391 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() | |
|
392 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() | |
|
393 | self.m_Voltage.m_BasicHeader.utc = time | |
|
394 | self.m_Voltage.data = data | |
|
390 | 395 | |
|
391 | 396 | self.__buffer_id += 1 |
|
392 | 397 | |
|
393 | 398 | #call setData - to Data Object |
|
394 | 399 | |
|
395 | 400 | return data |
|
396 | 401 | |
|
397 | 402 | |
|
398 | 403 | def setup(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r", online = 0): |
|
399 | 404 | |
|
400 | 405 | if online == 0: |
|
401 | 406 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) |
|
402 | 407 | |
|
403 | 408 | if len(filenameList) == 0: |
|
404 | 409 | self.__fp = None |
|
405 | 410 | self.noMoreFiles = 1 |
|
406 | 411 | print 'Do not exist files in range: %s - %s'%(startDateTime.ctime(), endDateTime.ctime()) |
|
407 | 412 | return 0 |
|
408 | 413 | |
|
409 | 414 | # for thisFile in filenameList: |
|
410 | 415 | # print thisFile |
|
411 | 416 | |
|
412 | 417 | self.__idFile = -1 |
|
413 | 418 | |
|
414 | 419 | if not(self.__setNextFile()): |
|
415 | 420 | print "No more files" |
|
416 | 421 | return 0 |
|
417 | 422 | |
|
418 | 423 | self.__readFirstHeader() |
|
419 | 424 | |
|
420 | 425 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) |
|
421 | 426 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) |
|
422 | 427 | |
|
423 | 428 | self.startYear = startDateTime.timetuple().tm_year |
|
424 | 429 | self.endYear = endDateTime.timetuple().tm_year |
|
425 | 430 | |
|
426 | 431 | self.startDoy = startDateTime.timetuple().tm_yday |
|
427 | 432 | self.endDoy = endDateTime.timetuple().tm_yday |
|
428 | 433 | #call fillHeaderValues() - to Data Object |
|
429 | 434 | |
|
430 | 435 | self.__pathList = pathList |
|
431 | 436 | self.filenameList = filenameList |
|
432 | 437 | self.online = online |
|
433 | 438 | |
|
434 | 439 | class VoltageWriter(DataWriter): |
|
435 | 440 | |
|
436 | 441 | m_BasicHeader= BasicHeader() |
|
437 | 442 | |
|
438 | 443 | |
|
439 | 444 | m_SystemHeader = SystemHeader() |
|
440 | 445 | |
|
441 | 446 | |
|
442 | 447 | m_RadarControllerHeader = RadarControllerHeader() |
|
443 | 448 | |
|
444 | 449 | |
|
445 | 450 | m_ProcessingHeader = ProcessingHeader() |
|
446 | 451 | |
|
447 | 452 | m_Voltage = None |
|
448 | 453 | |
|
449 | 454 | def __init__(self, m_Voltage): |
|
450 | 455 | |
|
451 | 456 | self.m_Voltage = m_Voltage |
|
452 | 457 | |
|
453 | 458 | |
|
454 | 459 | No newline at end of file |
@@ -1,37 +1,47 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os, sys |
|
7 | 7 | |
|
8 | 8 | path = os.path.split(os.getcwd())[0] |
|
9 | 9 | sys.path.append(path) |
|
10 | 10 | |
|
11 | 11 | from Model.Data import Data |
|
12 | 12 | from IO.Header import * |
|
13 | 13 | |
|
14 | 14 | class Voltage(Data): |
|
15 | 15 | ''' |
|
16 | 16 | classdocs |
|
17 | 17 | ''' |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | m_RadarControllerHeader= RadarControllerHeader() |
|
21 | 21 | |
|
22 | 22 | m_ProcessingHeader= ProcessingHeader() |
|
23 | 23 | |
|
24 | 24 | m_SystemHeader= SystemHeader() |
|
25 | 25 | |
|
26 | 26 | m_BasicHeader= BasicHeader() |
|
27 | 27 | |
|
28 | data = None | |
|
29 | ||
|
30 | noData = True | |
|
31 | ||
|
28 | 32 | |
|
29 | 33 | def __init__(self): |
|
30 | 34 | ''' |
|
31 | 35 | Constructor |
|
32 | 36 | ''' |
|
33 | 37 | pass |
|
34 | 38 | |
|
35 | 39 | def copy(self): |
|
36 | pass | |
|
40 | obj = Voltage() | |
|
41 | obj.m_BasicHeader = self.m_BasicHeader.copy() | |
|
42 | obj.m_SystemHeader = self.m_SystemHeader.copy() | |
|
43 | obj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() | |
|
44 | obj.m_ProcessingHeader = self.m_ProcessingHeader.copy() | |
|
45 | ||
|
46 | return obj | |
|
37 | 47 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now