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