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