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