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