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