@@ -1,905 +1,905 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 | import sys |
|
6 | import sys | |
7 | import numpy |
|
7 | import numpy | |
8 | import copy |
|
8 | import copy | |
9 | import datetime |
|
9 | import datetime | |
10 | import inspect |
|
10 | import inspect | |
11 |
|
11 | |||
12 | SPEED_OF_LIGHT = 299792458 |
|
12 | SPEED_OF_LIGHT = 299792458 | |
13 | SPEED_OF_LIGHT = 3e8 |
|
13 | SPEED_OF_LIGHT = 3e8 | |
14 |
|
14 | |||
15 | BASIC_STRUCTURE = numpy.dtype([ |
|
15 | BASIC_STRUCTURE = numpy.dtype([ | |
16 | ('nSize', '<u4'), |
|
16 | ('nSize', '<u4'), | |
17 | ('nVersion', '<u2'), |
|
17 | ('nVersion', '<u2'), | |
18 | ('nDataBlockId', '<u4'), |
|
18 | ('nDataBlockId', '<u4'), | |
19 | ('nUtime', '<u4'), |
|
19 | ('nUtime', '<u4'), | |
20 | ('nMilsec', '<u2'), |
|
20 | ('nMilsec', '<u2'), | |
21 | ('nTimezone', '<i2'), |
|
21 | ('nTimezone', '<i2'), | |
22 | ('nDstflag', '<i2'), |
|
22 | ('nDstflag', '<i2'), | |
23 | ('nErrorCount', '<u4') |
|
23 | ('nErrorCount', '<u4') | |
24 | ]) |
|
24 | ]) | |
25 |
|
25 | |||
26 | SYSTEM_STRUCTURE = numpy.dtype([ |
|
26 | SYSTEM_STRUCTURE = numpy.dtype([ | |
27 | ('nSize', '<u4'), |
|
27 | ('nSize', '<u4'), | |
28 | ('nNumSamples', '<u4'), |
|
28 | ('nNumSamples', '<u4'), | |
29 | ('nNumProfiles', '<u4'), |
|
29 | ('nNumProfiles', '<u4'), | |
30 | ('nNumChannels', '<u4'), |
|
30 | ('nNumChannels', '<u4'), | |
31 | ('nADCResolution', '<u4'), |
|
31 | ('nADCResolution', '<u4'), | |
32 | ('nPCDIOBusWidth', '<u4'), |
|
32 | ('nPCDIOBusWidth', '<u4'), | |
33 | ]) |
|
33 | ]) | |
34 |
|
34 | |||
35 | RADAR_STRUCTURE = numpy.dtype([ |
|
35 | RADAR_STRUCTURE = numpy.dtype([ | |
36 | ('nSize', '<u4'), |
|
36 | ('nSize', '<u4'), | |
37 | ('nExpType', '<u4'), |
|
37 | ('nExpType', '<u4'), | |
38 | ('nNTx', '<u4'), |
|
38 | ('nNTx', '<u4'), | |
39 | ('fIpp', '<f4'), |
|
39 | ('fIpp', '<f4'), | |
40 | ('fTxA', '<f4'), |
|
40 | ('fTxA', '<f4'), | |
41 | ('fTxB', '<f4'), |
|
41 | ('fTxB', '<f4'), | |
42 | ('nNumWindows', '<u4'), |
|
42 | ('nNumWindows', '<u4'), | |
43 | ('nNumTaus', '<u4'), |
|
43 | ('nNumTaus', '<u4'), | |
44 | ('nCodeType', '<u4'), |
|
44 | ('nCodeType', '<u4'), | |
45 | ('nLine6Function', '<u4'), |
|
45 | ('nLine6Function', '<u4'), | |
46 | ('nLine5Function', '<u4'), |
|
46 | ('nLine5Function', '<u4'), | |
47 | ('fClock', '<f4'), |
|
47 | ('fClock', '<f4'), | |
48 | ('nPrePulseBefore', '<u4'), |
|
48 | ('nPrePulseBefore', '<u4'), | |
49 | ('nPrePulseAfter', '<u4'), |
|
49 | ('nPrePulseAfter', '<u4'), | |
50 | ('sRangeIPP', '<a20'), |
|
50 | ('sRangeIPP', '<a20'), | |
51 | ('sRangeTxA', '<a20'), |
|
51 | ('sRangeTxA', '<a20'), | |
52 | ('sRangeTxB', '<a20'), |
|
52 | ('sRangeTxB', '<a20'), | |
53 | ]) |
|
53 | ]) | |
54 |
|
54 | |||
55 | SAMPLING_STRUCTURE = numpy.dtype( |
|
55 | SAMPLING_STRUCTURE = numpy.dtype( | |
56 | [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')]) |
|
56 | [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')]) | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | PROCESSING_STRUCTURE = numpy.dtype([ |
|
59 | PROCESSING_STRUCTURE = numpy.dtype([ | |
60 | ('nSize', '<u4'), |
|
60 | ('nSize', '<u4'), | |
61 | ('nDataType', '<u4'), |
|
61 | ('nDataType', '<u4'), | |
62 | ('nSizeOfDataBlock', '<u4'), |
|
62 | ('nSizeOfDataBlock', '<u4'), | |
63 | ('nProfilesperBlock', '<u4'), |
|
63 | ('nProfilesperBlock', '<u4'), | |
64 | ('nDataBlocksperFile', '<u4'), |
|
64 | ('nDataBlocksperFile', '<u4'), | |
65 | ('nNumWindows', '<u4'), |
|
65 | ('nNumWindows', '<u4'), | |
66 | ('nProcessFlags', '<u4'), |
|
66 | ('nProcessFlags', '<u4'), | |
67 | ('nCoherentIntegrations', '<u4'), |
|
67 | ('nCoherentIntegrations', '<u4'), | |
68 | ('nIncoherentIntegrations', '<u4'), |
|
68 | ('nIncoherentIntegrations', '<u4'), | |
69 | ('nTotalSpectra', '<u4') |
|
69 | ('nTotalSpectra', '<u4') | |
70 | ]) |
|
70 | ]) | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | class Header(object): |
|
73 | class Header(object): | |
74 |
|
74 | |||
75 | def __init__(self): |
|
75 | def __init__(self): | |
76 | raise NotImplementedError |
|
76 | raise NotImplementedError | |
77 |
|
77 | |||
78 | def copy(self): |
|
78 | def copy(self): | |
79 | return copy.deepcopy(self) |
|
79 | return copy.deepcopy(self) | |
80 |
|
80 | |||
81 | def read(self): |
|
81 | def read(self): | |
82 |
|
82 | |||
83 | raise NotImplementedError |
|
83 | raise NotImplementedError | |
84 |
|
84 | |||
85 | def write(self): |
|
85 | def write(self): | |
86 |
|
86 | |||
87 | raise NotImplementedError |
|
87 | raise NotImplementedError | |
88 |
|
88 | |||
89 | def getAllowedArgs(self): |
|
89 | def getAllowedArgs(self): | |
90 | args = inspect.getargspec(self.__init__).args |
|
90 | args = inspect.getargspec(self.__init__).args | |
91 | try: |
|
91 | try: | |
92 | args.remove('self') |
|
92 | args.remove('self') | |
93 | except: |
|
93 | except: | |
94 | pass |
|
94 | pass | |
95 | return args |
|
95 | return args | |
96 |
|
96 | |||
97 | def getAsDict(self): |
|
97 | def getAsDict(self): | |
98 | args = self.getAllowedArgs() |
|
98 | args = self.getAllowedArgs() | |
99 | asDict = {} |
|
99 | asDict = {} | |
100 | for x in args: |
|
100 | for x in args: | |
101 | asDict[x] = self[x] |
|
101 | asDict[x] = self[x] | |
102 | return asDict |
|
102 | return asDict | |
103 |
|
103 | |||
104 | def __getitem__(self, name): |
|
104 | def __getitem__(self, name): | |
105 | return getattr(self, name) |
|
105 | return getattr(self, name) | |
106 |
|
106 | |||
107 | def printInfo(self): |
|
107 | def printInfo(self): | |
108 |
|
108 | |||
109 | message = "#" * 50 + "\n" |
|
109 | message = "#" * 50 + "\n" | |
110 | message += self.__class__.__name__.upper() + "\n" |
|
110 | message += self.__class__.__name__.upper() + "\n" | |
111 | message += "#" * 50 + "\n" |
|
111 | message += "#" * 50 + "\n" | |
112 |
|
112 | |||
113 | keyList = self.__dict__.keys() |
|
113 | keyList = self.__dict__.keys() | |
114 | keyList.sort() |
|
114 | keyList.sort() | |
115 |
|
115 | |||
116 | for key in keyList: |
|
116 | for key in keyList: | |
117 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" |
|
117 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" | |
118 |
|
118 | |||
119 | if "size" not in keyList: |
|
119 | if "size" not in keyList: | |
120 | attr = getattr(self, "size") |
|
120 | attr = getattr(self, "size") | |
121 |
|
121 | |||
122 | if attr: |
|
122 | if attr: | |
123 | message += "%s = %s" % ("size", attr) + "\n" |
|
123 | message += "%s = %s" % ("size", attr) + "\n" | |
124 |
|
124 | |||
125 | print message |
|
125 | print message | |
126 |
|
126 | |||
127 |
|
127 | |||
128 | class BasicHeader(Header): |
|
128 | class BasicHeader(Header): | |
129 |
|
129 | |||
130 | size = None |
|
130 | size = None | |
131 | version = None |
|
131 | version = None | |
132 | dataBlock = None |
|
132 | dataBlock = None | |
133 | utc = None |
|
133 | utc = None | |
134 | ltc = None |
|
134 | ltc = None | |
135 | miliSecond = None |
|
135 | miliSecond = None | |
136 | timeZone = None |
|
136 | timeZone = None | |
137 | dstFlag = None |
|
137 | dstFlag = None | |
138 | errorCount = None |
|
138 | errorCount = None | |
139 | datatime = None |
|
139 | datatime = None | |
140 | structure = BASIC_STRUCTURE |
|
140 | structure = BASIC_STRUCTURE | |
141 | __LOCALTIME = None |
|
141 | __LOCALTIME = None | |
142 |
|
142 | |||
143 | def __init__(self, useLocalTime=True): |
|
143 | def __init__(self, useLocalTime=True): | |
144 |
|
144 | |||
145 | self.size = 24 |
|
145 | self.size = 24 | |
146 | self.version = 0 |
|
146 | self.version = 0 | |
147 | self.dataBlock = 0 |
|
147 | self.dataBlock = 0 | |
148 | self.utc = 0 |
|
148 | self.utc = 0 | |
149 | self.miliSecond = 0 |
|
149 | self.miliSecond = 0 | |
150 | self.timeZone = 0 |
|
150 | self.timeZone = 0 | |
151 | self.dstFlag = 0 |
|
151 | self.dstFlag = 0 | |
152 | self.errorCount = 0 |
|
152 | self.errorCount = 0 | |
153 |
|
153 | |||
154 | self.useLocalTime = useLocalTime |
|
154 | self.useLocalTime = useLocalTime | |
155 |
|
155 | |||
156 | def read(self, fp): |
|
156 | def read(self, fp): | |
157 |
|
157 | |||
158 | self.length = 0 |
|
158 | self.length = 0 | |
159 | try: |
|
159 | try: | |
160 | if hasattr(fp, 'read'): |
|
160 | if hasattr(fp, 'read'): | |
161 | header = numpy.fromfile(fp, BASIC_STRUCTURE, 1) |
|
161 | header = numpy.fromfile(fp, BASIC_STRUCTURE, 1) | |
162 | else: |
|
162 | else: | |
163 | header = numpy.fromstring(fp, BASIC_STRUCTURE, 1) |
|
163 | header = numpy.fromstring(fp, BASIC_STRUCTURE, 1) | |
164 | except Exception, e: |
|
164 | except Exception, e: | |
165 | print "BasicHeader: " |
|
165 | print "BasicHeader: " | |
166 | print e |
|
166 | print e | |
167 | return 0 |
|
167 | return 0 | |
168 |
|
168 | |||
169 | self.size = int(header['nSize'][0]) |
|
169 | self.size = int(header['nSize'][0]) | |
170 | self.version = int(header['nVersion'][0]) |
|
170 | self.version = int(header['nVersion'][0]) | |
171 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
171 | self.dataBlock = int(header['nDataBlockId'][0]) | |
172 | self.utc = int(header['nUtime'][0]) |
|
172 | self.utc = int(header['nUtime'][0]) | |
173 | self.miliSecond = int(header['nMilsec'][0]) |
|
173 | self.miliSecond = int(header['nMilsec'][0]) | |
174 | self.timeZone = int(header['nTimezone'][0]) |
|
174 | self.timeZone = int(header['nTimezone'][0]) | |
175 | self.dstFlag = int(header['nDstflag'][0]) |
|
175 | self.dstFlag = int(header['nDstflag'][0]) | |
176 | self.errorCount = int(header['nErrorCount'][0]) |
|
176 | self.errorCount = int(header['nErrorCount'][0]) | |
177 |
|
177 | |||
178 | if self.size < 24: |
|
178 | if self.size < 24: | |
179 | return 0 |
|
179 | return 0 | |
180 |
|
180 | |||
181 | self.length = header.nbytes |
|
181 | self.length = header.nbytes | |
182 | return 1 |
|
182 | return 1 | |
183 |
|
183 | |||
184 | def write(self, fp): |
|
184 | def write(self, fp): | |
185 |
|
185 | |||
186 | headerTuple = (self.size, self.version, self.dataBlock, self.utc, |
|
186 | headerTuple = (self.size, self.version, self.dataBlock, self.utc, | |
187 | self.miliSecond, self.timeZone, self.dstFlag, self.errorCount) |
|
187 | self.miliSecond, self.timeZone, self.dstFlag, self.errorCount) | |
188 | header = numpy.array(headerTuple, BASIC_STRUCTURE) |
|
188 | header = numpy.array(headerTuple, BASIC_STRUCTURE) | |
189 | header.tofile(fp) |
|
189 | header.tofile(fp) | |
190 |
|
190 | |||
191 | return 1 |
|
191 | return 1 | |
192 |
|
192 | |||
193 | def get_ltc(self): |
|
193 | def get_ltc(self): | |
194 |
|
194 | |||
195 | return self.utc - self.timeZone * 60 |
|
195 | return self.utc - self.timeZone * 60 | |
196 |
|
196 | |||
197 | def set_ltc(self, value): |
|
197 | def set_ltc(self, value): | |
198 |
|
198 | |||
199 | self.utc = value + self.timeZone * 60 |
|
199 | self.utc = value + self.timeZone * 60 | |
200 |
|
200 | |||
201 | def get_datatime(self): |
|
201 | def get_datatime(self): | |
202 |
|
202 | |||
203 | return datetime.datetime.utcfromtimestamp(self.ltc) |
|
203 | return datetime.datetime.utcfromtimestamp(self.ltc) | |
204 |
|
204 | |||
205 | ltc = property(get_ltc, set_ltc) |
|
205 | ltc = property(get_ltc, set_ltc) | |
206 | datatime = property(get_datatime) |
|
206 | datatime = property(get_datatime) | |
207 |
|
207 | |||
208 |
|
208 | |||
209 | class SystemHeader(Header): |
|
209 | class SystemHeader(Header): | |
210 |
|
210 | |||
211 | size = None |
|
211 | size = None | |
212 | nSamples = None |
|
212 | nSamples = None | |
213 | nProfiles = None |
|
213 | nProfiles = None | |
214 | nChannels = None |
|
214 | nChannels = None | |
215 | adcResolution = None |
|
215 | adcResolution = None | |
216 | pciDioBusWidth = None |
|
216 | pciDioBusWidth = None | |
217 | structure = SYSTEM_STRUCTURE |
|
217 | structure = SYSTEM_STRUCTURE | |
218 |
|
218 | |||
219 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0): |
|
219 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0): | |
220 |
|
220 | |||
221 | self.size = 24 |
|
221 | self.size = 24 | |
222 | self.nSamples = nSamples |
|
222 | self.nSamples = nSamples | |
223 | self.nProfiles = nProfiles |
|
223 | self.nProfiles = nProfiles | |
224 | self.nChannels = nChannels |
|
224 | self.nChannels = nChannels | |
225 | self.adcResolution = adcResolution |
|
225 | self.adcResolution = adcResolution | |
226 | self.pciDioBusWidth = pciDioBusWidth |
|
226 | self.pciDioBusWidth = pciDioBusWidth | |
227 |
|
227 | |||
228 | def read(self, fp): |
|
228 | def read(self, fp): | |
229 | self.length = 0 |
|
229 | self.length = 0 | |
230 | try: |
|
230 | try: | |
231 | startFp = fp.tell() |
|
231 | startFp = fp.tell() | |
232 | except Exception, e: |
|
232 | except Exception, e: | |
233 | startFp = None |
|
233 | startFp = None | |
234 | pass |
|
234 | pass | |
235 |
|
235 | |||
236 | try: |
|
236 | try: | |
237 | if hasattr(fp, 'read'): |
|
237 | if hasattr(fp, 'read'): | |
238 | header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1) |
|
238 | header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1) | |
239 | else: |
|
239 | else: | |
240 | header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1) |
|
240 | header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1) | |
241 | except Exception, e: |
|
241 | except Exception, e: | |
242 | print "System Header: " + str(e) |
|
242 | print "System Header: " + str(e) | |
243 | return 0 |
|
243 | return 0 | |
244 |
|
244 | |||
245 | self.size = header['nSize'][0] |
|
245 | self.size = header['nSize'][0] | |
246 | self.nSamples = header['nNumSamples'][0] |
|
246 | self.nSamples = header['nNumSamples'][0] | |
247 | self.nProfiles = header['nNumProfiles'][0] |
|
247 | self.nProfiles = header['nNumProfiles'][0] | |
248 | self.nChannels = header['nNumChannels'][0] |
|
248 | self.nChannels = header['nNumChannels'][0] | |
249 | self.adcResolution = header['nADCResolution'][0] |
|
249 | self.adcResolution = header['nADCResolution'][0] | |
250 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
250 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
251 |
|
251 | |||
252 | if startFp is not None: |
|
252 | if startFp is not None: | |
253 | endFp = self.size + startFp |
|
253 | endFp = self.size + startFp | |
254 |
|
254 | |||
255 | if fp.tell() > endFp: |
|
255 | if fp.tell() > endFp: | |
256 | sys.stderr.write( |
|
256 | sys.stderr.write( | |
257 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name) |
|
257 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name) | |
258 | return 0 |
|
258 | return 0 | |
259 |
|
259 | |||
260 | if fp.tell() < endFp: |
|
260 | if fp.tell() < endFp: | |
261 | sys.stderr.write( |
|
261 | sys.stderr.write( | |
262 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name) |
|
262 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name) | |
263 | return 0 |
|
263 | return 0 | |
264 |
|
264 | |||
265 | self.length = header.nbytes |
|
265 | self.length = header.nbytes | |
266 | return 1 |
|
266 | return 1 | |
267 |
|
267 | |||
268 | def write(self, fp): |
|
268 | def write(self, fp): | |
269 |
|
269 | |||
270 | headerTuple = (self.size, self.nSamples, self.nProfiles, |
|
270 | headerTuple = (self.size, self.nSamples, self.nProfiles, | |
271 | self.nChannels, self.adcResolution, self.pciDioBusWidth) |
|
271 | self.nChannels, self.adcResolution, self.pciDioBusWidth) | |
272 | header = numpy.array(headerTuple, SYSTEM_STRUCTURE) |
|
272 | header = numpy.array(headerTuple, SYSTEM_STRUCTURE) | |
273 | header.tofile(fp) |
|
273 | header.tofile(fp) | |
274 |
|
274 | |||
275 | return 1 |
|
275 | return 1 | |
276 |
|
276 | |||
277 |
|
277 | |||
278 | class RadarControllerHeader(Header): |
|
278 | class RadarControllerHeader(Header): | |
279 |
|
279 | |||
280 | expType = None |
|
280 | expType = None | |
281 | nTx = None |
|
281 | nTx = None | |
282 | ipp = None |
|
282 | ipp = None | |
283 | txA = None |
|
283 | txA = None | |
284 | txB = None |
|
284 | txB = None | |
285 | nWindows = None |
|
285 | nWindows = None | |
286 | numTaus = None |
|
286 | numTaus = None | |
287 | codeType = None |
|
287 | codeType = None | |
288 | line6Function = None |
|
288 | line6Function = None | |
289 | line5Function = None |
|
289 | line5Function = None | |
290 | fClock = None |
|
290 | fClock = None | |
291 | prePulseBefore = None |
|
291 | prePulseBefore = None | |
292 | prePulseAfter = None |
|
292 | prePulseAfter = None | |
293 | rangeIpp = None |
|
293 | rangeIpp = None | |
294 | rangeTxA = None |
|
294 | rangeTxA = None | |
295 | rangeTxB = None |
|
295 | rangeTxB = None | |
296 | structure = RADAR_STRUCTURE |
|
296 | structure = RADAR_STRUCTURE | |
297 | __size = None |
|
297 | __size = None | |
298 |
|
298 | |||
299 | def __init__(self, expType=2, nTx=1, |
|
299 | def __init__(self, expType=2, nTx=1, | |
300 | ipp=None, txA=0, txB=0, |
|
300 | ipp=None, txA=0, txB=0, | |
301 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, |
|
301 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, | |
302 | numTaus=0, line6Function=0, line5Function=0, fClock=None, |
|
302 | numTaus=0, line6Function=0, line5Function=0, fClock=None, | |
303 | prePulseBefore=0, prePulseAfter=0, |
|
303 | prePulseBefore=0, prePulseAfter=0, | |
304 | codeType=0, nCode=0, nBaud=0, code=None, |
|
304 | codeType=0, nCode=0, nBaud=0, code=None, | |
305 | flip1=0, flip2=0): |
|
305 | flip1=0, flip2=0): | |
306 |
|
306 | |||
307 | # self.size = 116 |
|
307 | # self.size = 116 | |
308 | self.expType = expType |
|
308 | self.expType = expType | |
309 | self.nTx = nTx |
|
309 | self.nTx = nTx | |
310 | self.ipp = ipp |
|
310 | self.ipp = ipp | |
311 | self.txA = txA |
|
311 | self.txA = txA | |
312 | self.txB = txB |
|
312 | self.txB = txB | |
313 | self.rangeIpp = ipp |
|
313 | self.rangeIpp = ipp | |
314 | self.rangeTxA = txA |
|
314 | self.rangeTxA = txA | |
315 | self.rangeTxB = txB |
|
315 | self.rangeTxB = txB | |
316 |
|
316 | |||
317 | self.nWindows = nWindows |
|
317 | self.nWindows = nWindows | |
318 | self.numTaus = numTaus |
|
318 | self.numTaus = numTaus | |
319 | self.codeType = codeType |
|
319 | self.codeType = codeType | |
320 | self.line6Function = line6Function |
|
320 | self.line6Function = line6Function | |
321 | self.line5Function = line5Function |
|
321 | self.line5Function = line5Function | |
322 | self.fClock = fClock |
|
322 | self.fClock = fClock | |
323 | self.prePulseBefore = prePulseBefore |
|
323 | self.prePulseBefore = prePulseBefore | |
324 | self.prePulseAfter = prePulseAfter |
|
324 | self.prePulseAfter = prePulseAfter | |
325 |
|
325 | |||
326 | self.nHeights = nHeights |
|
326 | self.nHeights = nHeights | |
327 | self.firstHeight = firstHeight |
|
327 | self.firstHeight = firstHeight | |
328 | self.deltaHeight = deltaHeight |
|
328 | self.deltaHeight = deltaHeight | |
329 | self.samplesWin = nHeights |
|
329 | self.samplesWin = nHeights | |
330 |
|
330 | |||
331 | self.nCode = nCode |
|
331 | self.nCode = nCode | |
332 | self.nBaud = nBaud |
|
332 | self.nBaud = nBaud | |
333 | self.code = code |
|
333 | self.code = code | |
334 | self.flip1 = flip1 |
|
334 | self.flip1 = flip1 | |
335 | self.flip2 = flip2 |
|
335 | self.flip2 = flip2 | |
336 |
|
336 | |||
337 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 |
|
337 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 | |
338 | # self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
338 | # self.dynamic = numpy.array([],numpy.dtype('byte')) | |
339 |
|
339 | |||
340 | if self.fClock is None and self.deltaHeight is not None: |
|
340 | if self.fClock is None and self.deltaHeight is not None: | |
341 | self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u) |
|
341 | self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u) | |
342 |
|
342 | |||
343 | def read(self, fp): |
|
343 | def read(self, fp): | |
344 | self.length = 0 |
|
344 | self.length = 0 | |
345 | try: |
|
345 | try: | |
346 | startFp = fp.tell() |
|
346 | startFp = fp.tell() | |
347 | except Exception, e: |
|
347 | except Exception, e: | |
348 | startFp = None |
|
348 | startFp = None | |
349 | pass |
|
349 | pass | |
350 |
|
350 | |||
351 | try: |
|
351 | try: | |
352 | if hasattr(fp, 'read'): |
|
352 | if hasattr(fp, 'read'): | |
353 | header = numpy.fromfile(fp, RADAR_STRUCTURE, 1) |
|
353 | header = numpy.fromfile(fp, RADAR_STRUCTURE, 1) | |
354 | else: |
|
354 | else: | |
355 | header = numpy.fromstring(fp, RADAR_STRUCTURE, 1) |
|
355 | header = numpy.fromstring(fp, RADAR_STRUCTURE, 1) | |
356 | self.length += header.nbytes |
|
356 | self.length += header.nbytes | |
357 | except Exception, e: |
|
357 | except Exception, e: | |
358 | print "RadarControllerHeader: " + str(e) |
|
358 | print "RadarControllerHeader: " + str(e) | |
359 | return 0 |
|
359 | return 0 | |
360 |
|
360 | |||
361 | size = int(header['nSize'][0]) |
|
361 | size = int(header['nSize'][0]) | |
362 | self.expType = int(header['nExpType'][0]) |
|
362 | self.expType = int(header['nExpType'][0]) | |
363 | self.nTx = int(header['nNTx'][0]) |
|
363 | self.nTx = int(header['nNTx'][0]) | |
364 | self.ipp = float(header['fIpp'][0]) |
|
364 | self.ipp = float(header['fIpp'][0]) | |
365 | self.txA = float(header['fTxA'][0]) |
|
365 | self.txA = float(header['fTxA'][0]) | |
366 | self.txB = float(header['fTxB'][0]) |
|
366 | self.txB = float(header['fTxB'][0]) | |
367 | self.nWindows = int(header['nNumWindows'][0]) |
|
367 | self.nWindows = int(header['nNumWindows'][0]) | |
368 | self.numTaus = int(header['nNumTaus'][0]) |
|
368 | self.numTaus = int(header['nNumTaus'][0]) | |
369 | self.codeType = int(header['nCodeType'][0]) |
|
369 | self.codeType = int(header['nCodeType'][0]) | |
370 | self.line6Function = int(header['nLine6Function'][0]) |
|
370 | self.line6Function = int(header['nLine6Function'][0]) | |
371 | self.line5Function = int(header['nLine5Function'][0]) |
|
371 | self.line5Function = int(header['nLine5Function'][0]) | |
372 | self.fClock = float(header['fClock'][0]) |
|
372 | self.fClock = float(header['fClock'][0]) | |
373 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
373 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) | |
374 | self.prePulseAfter = int(header['nPrePulseAfter'][0]) |
|
374 | self.prePulseAfter = int(header['nPrePulseAfter'][0]) | |
375 | self.rangeIpp = header['sRangeIPP'][0] |
|
375 | self.rangeIpp = header['sRangeIPP'][0] | |
376 | self.rangeTxA = header['sRangeTxA'][0] |
|
376 | self.rangeTxA = header['sRangeTxA'][0] | |
377 | self.rangeTxB = header['sRangeTxB'][0] |
|
377 | self.rangeTxB = header['sRangeTxB'][0] | |
378 |
|
378 | |||
379 | try: |
|
379 | try: | |
380 | if hasattr(fp, 'read'): |
|
380 | if hasattr(fp, 'read'): | |
381 | samplingWindow = numpy.fromfile( |
|
381 | samplingWindow = numpy.fromfile( | |
382 | fp, SAMPLING_STRUCTURE, self.nWindows) |
|
382 | fp, SAMPLING_STRUCTURE, self.nWindows) | |
383 | else: |
|
383 | else: | |
384 | samplingWindow = numpy.fromstring( |
|
384 | samplingWindow = numpy.fromstring( | |
385 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) |
|
385 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) | |
386 | self.length += samplingWindow.nbytes |
|
386 | self.length += samplingWindow.nbytes | |
387 | except Exception, e: |
|
387 | except Exception, e: | |
388 | print "RadarControllerHeader: " + str(e) |
|
388 | print "RadarControllerHeader: " + str(e) | |
389 | return 0 |
|
389 | return 0 | |
390 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
390 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
391 | self.firstHeight = samplingWindow['h0'] |
|
391 | self.firstHeight = samplingWindow['h0'] | |
392 | self.deltaHeight = samplingWindow['dh'] |
|
392 | self.deltaHeight = samplingWindow['dh'] | |
393 | self.samplesWin = samplingWindow['nsa'] |
|
393 | self.samplesWin = samplingWindow['nsa'] | |
394 |
|
394 | |||
395 | try: |
|
395 | try: | |
396 | if hasattr(fp, 'read'): |
|
396 | if hasattr(fp, 'read'): | |
397 | self.Taus = numpy.fromfile(fp, '<f4', self.numTaus) |
|
397 | self.Taus = numpy.fromfile(fp, '<f4', self.numTaus) | |
398 | else: |
|
398 | else: | |
399 | self.Taus = numpy.fromstring( |
|
399 | self.Taus = numpy.fromstring( | |
400 | fp[self.length:], '<f4', self.numTaus) |
|
400 | fp[self.length:], '<f4', self.numTaus) | |
401 | self.length += self.Taus.nbytes |
|
401 | self.length += self.Taus.nbytes | |
402 | except Exception, e: |
|
402 | except Exception, e: | |
403 | print "RadarControllerHeader: " + str(e) |
|
403 | print "RadarControllerHeader: " + str(e) | |
404 | return 0 |
|
404 | return 0 | |
405 |
|
405 | |||
406 | self.code_size = 0 |
|
406 | self.code_size = 0 | |
407 | if self.codeType != 0: |
|
407 | if self.codeType != 0: | |
408 |
|
408 | |||
409 | try: |
|
409 | try: | |
410 | if hasattr(fp, 'read'): |
|
410 | if hasattr(fp, 'read'): | |
411 | self.nCode = numpy.fromfile(fp, '<u4', 1)[0] |
|
411 | self.nCode = numpy.fromfile(fp, '<u4', 1)[0] | |
412 | self.length += self.nCode.nbytes |
|
412 | self.length += self.nCode.nbytes | |
413 | self.nBaud = numpy.fromfile(fp, '<u4', 1)[0] |
|
413 | self.nBaud = numpy.fromfile(fp, '<u4', 1)[0] | |
414 | self.length += self.nBaud.nbytes |
|
414 | self.length += self.nBaud.nbytes | |
415 | else: |
|
415 | else: | |
416 | self.nCode = numpy.fromstring( |
|
416 | self.nCode = numpy.fromstring( | |
417 | fp[self.length:], '<u4', 1)[0] |
|
417 | fp[self.length:], '<u4', 1)[0] | |
418 | self.length += self.nCode.nbytes |
|
418 | self.length += self.nCode.nbytes | |
419 | self.nBaud = numpy.fromstring( |
|
419 | self.nBaud = numpy.fromstring( | |
420 | fp[self.length:], '<u4', 1)[0] |
|
420 | fp[self.length:], '<u4', 1)[0] | |
421 | self.length += self.nBaud.nbytes |
|
421 | self.length += self.nBaud.nbytes | |
422 | except Exception, e: |
|
422 | except Exception, e: | |
423 | print "RadarControllerHeader: " + str(e) |
|
423 | print "RadarControllerHeader: " + str(e) | |
424 | return 0 |
|
424 | return 0 | |
425 | code = numpy.empty([self.nCode, self.nBaud], dtype='i1') |
|
425 | code = numpy.empty([self.nCode, self.nBaud], dtype='i1') | |
426 |
|
426 | |||
427 | for ic in range(self.nCode): |
|
427 | for ic in range(self.nCode): | |
428 | try: |
|
428 | try: | |
429 | if hasattr(fp, 'read'): |
|
429 | if hasattr(fp, 'read'): | |
430 | temp = numpy.fromfile(fp, 'u4', int( |
|
430 | temp = numpy.fromfile(fp, 'u4', int( | |
431 | numpy.ceil(self.nBaud / 32.))) |
|
431 | numpy.ceil(self.nBaud / 32.))) | |
432 | else: |
|
432 | else: | |
433 | temp = numpy.fromstring( |
|
433 | temp = numpy.fromstring( | |
434 | fp, 'u4', int(numpy.ceil(self.nBaud / 32.))) |
|
434 | fp, 'u4', int(numpy.ceil(self.nBaud / 32.))) | |
435 | self.length += temp.nbytes |
|
435 | self.length += temp.nbytes | |
436 | except Exception, e: |
|
436 | except Exception, e: | |
437 | print "RadarControllerHeader: " + str(e) |
|
437 | print "RadarControllerHeader: " + str(e) | |
438 | return 0 |
|
438 | return 0 | |
439 |
|
439 | |||
440 | for ib in range(self.nBaud - 1, -1, -1): |
|
440 | for ib in range(self.nBaud - 1, -1, -1): | |
441 | code[ic, ib] = temp[ib / 32] % 2 |
|
441 | code[ic, ib] = temp[ib / 32] % 2 | |
442 | temp[ib / 32] = temp[ib / 32] / 2 |
|
442 | temp[ib / 32] = temp[ib / 32] / 2 | |
443 |
|
443 | |||
444 | self.code = 2.0 * code - 1.0 |
|
444 | self.code = 2.0 * code - 1.0 | |
445 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 |
|
445 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 | |
446 |
|
446 | |||
447 | # if self.line5Function == RCfunction.FLIP: |
|
447 | # if self.line5Function == RCfunction.FLIP: | |
448 | # self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
448 | # self.flip1 = numpy.fromfile(fp,'<u4',1) | |
449 | # |
|
449 | # | |
450 | # if self.line6Function == RCfunction.FLIP: |
|
450 | # if self.line6Function == RCfunction.FLIP: | |
451 | # self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
451 | # self.flip2 = numpy.fromfile(fp,'<u4',1) | |
452 | if startFp is not None: |
|
452 | if startFp is not None: | |
453 | endFp = size + startFp |
|
453 | endFp = size + startFp | |
454 |
|
454 | |||
455 | if fp.tell() != endFp: |
|
455 | if fp.tell() != endFp: | |
456 | # fp.seek(endFp) |
|
456 | # fp.seek(endFp) | |
457 | print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size) |
|
457 | print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size) | |
458 | # return 0 |
|
458 | # return 0 | |
459 |
|
459 | |||
460 | if fp.tell() > endFp: |
|
460 | if fp.tell() > endFp: | |
461 | sys.stderr.write( |
|
461 | sys.stderr.write( | |
462 | "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name) |
|
462 | "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name) | |
463 | # return 0 |
|
463 | # return 0 | |
464 |
|
464 | |||
465 | if fp.tell() < endFp: |
|
465 | if fp.tell() < endFp: | |
466 | sys.stderr.write( |
|
466 | sys.stderr.write( | |
467 | "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name) |
|
467 | "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name) | |
468 |
|
468 | |||
469 | return 1 |
|
469 | return 1 | |
470 |
|
470 | |||
471 | def write(self, fp): |
|
471 | def write(self, fp): | |
472 |
|
472 | |||
473 | headerTuple = (self.size, |
|
473 | headerTuple = (self.size, | |
474 | self.expType, |
|
474 | self.expType, | |
475 | self.nTx, |
|
475 | self.nTx, | |
476 | self.ipp, |
|
476 | self.ipp, | |
477 | self.txA, |
|
477 | self.txA, | |
478 | self.txB, |
|
478 | self.txB, | |
479 | self.nWindows, |
|
479 | self.nWindows, | |
480 | self.numTaus, |
|
480 | self.numTaus, | |
481 | self.codeType, |
|
481 | self.codeType, | |
482 | self.line6Function, |
|
482 | self.line6Function, | |
483 | self.line5Function, |
|
483 | self.line5Function, | |
484 | self.fClock, |
|
484 | self.fClock, | |
485 | self.prePulseBefore, |
|
485 | self.prePulseBefore, | |
486 | self.prePulseAfter, |
|
486 | self.prePulseAfter, | |
487 | self.rangeIpp, |
|
487 | self.rangeIpp, | |
488 | self.rangeTxA, |
|
488 | self.rangeTxA, | |
489 | self.rangeTxB) |
|
489 | self.rangeTxB) | |
490 |
|
490 | |||
491 | header = numpy.array(headerTuple, RADAR_STRUCTURE) |
|
491 | header = numpy.array(headerTuple, RADAR_STRUCTURE) | |
492 | header.tofile(fp) |
|
492 | header.tofile(fp) | |
493 |
|
493 | |||
494 | sampleWindowTuple = ( |
|
494 | sampleWindowTuple = ( | |
495 | self.firstHeight, self.deltaHeight, self.samplesWin) |
|
495 | self.firstHeight, self.deltaHeight, self.samplesWin) | |
496 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) |
|
496 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) | |
497 | samplingWindow.tofile(fp) |
|
497 | samplingWindow.tofile(fp) | |
498 |
|
498 | |||
499 | if self.numTaus > 0: |
|
499 | if self.numTaus > 0: | |
500 | self.Taus.tofile(fp) |
|
500 | self.Taus.tofile(fp) | |
501 |
|
501 | |||
502 | if self.codeType != 0: |
|
502 | if self.codeType != 0: | |
503 | nCode = numpy.array(self.nCode, '<u4') |
|
503 | nCode = numpy.array(self.nCode, '<u4') | |
504 | nCode.tofile(fp) |
|
504 | nCode.tofile(fp) | |
505 | nBaud = numpy.array(self.nBaud, '<u4') |
|
505 | nBaud = numpy.array(self.nBaud, '<u4') | |
506 | nBaud.tofile(fp) |
|
506 | nBaud.tofile(fp) | |
507 | code1 = (self.code + 1.0) / 2. |
|
507 | code1 = (self.code + 1.0) / 2. | |
508 |
|
508 | |||
509 | for ic in range(self.nCode): |
|
509 | for ic in range(self.nCode): | |
510 |
tempx = numpy.zeros( |
|
510 | tempx = numpy.zeros(int(self.nBaud / 32.)) | |
511 | start = 0 |
|
511 | start = 0 | |
512 | end = 32 |
|
512 | end = 32 | |
513 | for i in range(len(tempx)): |
|
513 | for i in range(len(tempx)): | |
514 | code_selected = code1[ic, start:end] |
|
514 | code_selected = code1[ic, start:end] | |
515 | for j in range(len(code_selected) - 1, -1, -1): |
|
515 | for j in range(len(code_selected) - 1, -1, -1): | |
516 | if code_selected[j] == 1: |
|
516 | if code_selected[j] == 1: | |
517 | tempx[i] = tempx[i] + \ |
|
517 | tempx[i] = tempx[i] + \ | |
518 | 2**(len(code_selected) - 1 - j) |
|
518 | 2**(len(code_selected) - 1 - j) | |
519 | start = start + 32 |
|
519 | start = start + 32 | |
520 | end = end + 32 |
|
520 | end = end + 32 | |
521 |
|
521 | |||
522 | tempx = tempx.astype('u4') |
|
522 | tempx = tempx.astype('u4') | |
523 | tempx.tofile(fp) |
|
523 | tempx.tofile(fp) | |
524 |
|
524 | |||
525 | # if self.line5Function == RCfunction.FLIP: |
|
525 | # if self.line5Function == RCfunction.FLIP: | |
526 | # self.flip1.tofile(fp) |
|
526 | # self.flip1.tofile(fp) | |
527 | # |
|
527 | # | |
528 | # if self.line6Function == RCfunction.FLIP: |
|
528 | # if self.line6Function == RCfunction.FLIP: | |
529 | # self.flip2.tofile(fp) |
|
529 | # self.flip2.tofile(fp) | |
530 |
|
530 | |||
531 | return 1 |
|
531 | return 1 | |
532 |
|
532 | |||
533 | def get_ippSeconds(self): |
|
533 | def get_ippSeconds(self): | |
534 | ''' |
|
534 | ''' | |
535 | ''' |
|
535 | ''' | |
536 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT |
|
536 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT | |
537 |
|
537 | |||
538 | return ippSeconds |
|
538 | return ippSeconds | |
539 |
|
539 | |||
540 | def set_ippSeconds(self, ippSeconds): |
|
540 | def set_ippSeconds(self, ippSeconds): | |
541 | ''' |
|
541 | ''' | |
542 | ''' |
|
542 | ''' | |
543 |
|
543 | |||
544 | self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000) |
|
544 | self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000) | |
545 |
|
545 | |||
546 | return |
|
546 | return | |
547 |
|
547 | |||
548 | def get_size(self): |
|
548 | def get_size(self): | |
549 |
|
549 | |||
550 | self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus |
|
550 | self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus | |
551 |
|
551 | |||
552 | if self.codeType != 0: |
|
552 | if self.codeType != 0: | |
553 | self.__size += 4 + 4 + 4 * self.nCode * \ |
|
553 | self.__size += 4 + 4 + 4 * self.nCode * \ | |
554 | numpy.ceil(self.nBaud / 32.) |
|
554 | numpy.ceil(self.nBaud / 32.) | |
555 |
|
555 | |||
556 | return self.__size |
|
556 | return self.__size | |
557 |
|
557 | |||
558 | def set_size(self, value): |
|
558 | def set_size(self, value): | |
559 |
|
559 | |||
560 | raise IOError, "size is a property and it cannot be set, just read" |
|
560 | raise IOError, "size is a property and it cannot be set, just read" | |
561 |
|
561 | |||
562 | return |
|
562 | return | |
563 |
|
563 | |||
564 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
564 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
565 | size = property(get_size, set_size) |
|
565 | size = property(get_size, set_size) | |
566 |
|
566 | |||
567 |
|
567 | |||
568 | class ProcessingHeader(Header): |
|
568 | class ProcessingHeader(Header): | |
569 |
|
569 | |||
570 | # size = None |
|
570 | # size = None | |
571 | dtype = None |
|
571 | dtype = None | |
572 | blockSize = None |
|
572 | blockSize = None | |
573 | profilesPerBlock = None |
|
573 | profilesPerBlock = None | |
574 | dataBlocksPerFile = None |
|
574 | dataBlocksPerFile = None | |
575 | nWindows = None |
|
575 | nWindows = None | |
576 | processFlags = None |
|
576 | processFlags = None | |
577 | nCohInt = None |
|
577 | nCohInt = None | |
578 | nIncohInt = None |
|
578 | nIncohInt = None | |
579 | totalSpectra = None |
|
579 | totalSpectra = None | |
580 | structure = PROCESSING_STRUCTURE |
|
580 | structure = PROCESSING_STRUCTURE | |
581 | flag_dc = None |
|
581 | flag_dc = None | |
582 | flag_cspc = None |
|
582 | flag_cspc = None | |
583 |
|
583 | |||
584 | def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0, |
|
584 | def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0, | |
585 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, |
|
585 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, | |
586 | code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False |
|
586 | code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False | |
587 | ): |
|
587 | ): | |
588 |
|
588 | |||
589 | # self.size = 0 |
|
589 | # self.size = 0 | |
590 | self.dtype = dtype |
|
590 | self.dtype = dtype | |
591 | self.blockSize = blockSize |
|
591 | self.blockSize = blockSize | |
592 | self.profilesPerBlock = 0 |
|
592 | self.profilesPerBlock = 0 | |
593 | self.dataBlocksPerFile = 0 |
|
593 | self.dataBlocksPerFile = 0 | |
594 | self.nWindows = 0 |
|
594 | self.nWindows = 0 | |
595 | self.processFlags = 0 |
|
595 | self.processFlags = 0 | |
596 | self.nCohInt = 0 |
|
596 | self.nCohInt = 0 | |
597 | self.nIncohInt = 0 |
|
597 | self.nIncohInt = 0 | |
598 | self.totalSpectra = 0 |
|
598 | self.totalSpectra = 0 | |
599 |
|
599 | |||
600 | self.nHeights = 0 |
|
600 | self.nHeights = 0 | |
601 | self.firstHeight = 0 |
|
601 | self.firstHeight = 0 | |
602 | self.deltaHeight = 0 |
|
602 | self.deltaHeight = 0 | |
603 | self.samplesWin = 0 |
|
603 | self.samplesWin = 0 | |
604 | self.spectraComb = 0 |
|
604 | self.spectraComb = 0 | |
605 | self.nCode = None |
|
605 | self.nCode = None | |
606 | self.code = None |
|
606 | self.code = None | |
607 | self.nBaud = None |
|
607 | self.nBaud = None | |
608 |
|
608 | |||
609 | self.shif_fft = False |
|
609 | self.shif_fft = False | |
610 | self.flag_dc = False |
|
610 | self.flag_dc = False | |
611 | self.flag_cspc = False |
|
611 | self.flag_cspc = False | |
612 | self.flag_decode = False |
|
612 | self.flag_decode = False | |
613 | self.flag_deflip = False |
|
613 | self.flag_deflip = False | |
614 | self.length = 0 |
|
614 | self.length = 0 | |
615 |
|
615 | |||
616 | def read(self, fp): |
|
616 | def read(self, fp): | |
617 | self.length = 0 |
|
617 | self.length = 0 | |
618 | try: |
|
618 | try: | |
619 | startFp = fp.tell() |
|
619 | startFp = fp.tell() | |
620 | except Exception, e: |
|
620 | except Exception, e: | |
621 | startFp = None |
|
621 | startFp = None | |
622 | pass |
|
622 | pass | |
623 |
|
623 | |||
624 | try: |
|
624 | try: | |
625 | if hasattr(fp, 'read'): |
|
625 | if hasattr(fp, 'read'): | |
626 | header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1) |
|
626 | header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1) | |
627 | else: |
|
627 | else: | |
628 | header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1) |
|
628 | header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1) | |
629 | self.length += header.nbytes |
|
629 | self.length += header.nbytes | |
630 | except Exception, e: |
|
630 | except Exception, e: | |
631 | print "ProcessingHeader: " + str(e) |
|
631 | print "ProcessingHeader: " + str(e) | |
632 | return 0 |
|
632 | return 0 | |
633 |
|
633 | |||
634 | size = int(header['nSize'][0]) |
|
634 | size = int(header['nSize'][0]) | |
635 | self.dtype = int(header['nDataType'][0]) |
|
635 | self.dtype = int(header['nDataType'][0]) | |
636 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
636 | self.blockSize = int(header['nSizeOfDataBlock'][0]) | |
637 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
637 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) | |
638 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
638 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) | |
639 | self.nWindows = int(header['nNumWindows'][0]) |
|
639 | self.nWindows = int(header['nNumWindows'][0]) | |
640 | self.processFlags = header['nProcessFlags'] |
|
640 | self.processFlags = header['nProcessFlags'] | |
641 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
641 | self.nCohInt = int(header['nCoherentIntegrations'][0]) | |
642 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
642 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) | |
643 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
643 | self.totalSpectra = int(header['nTotalSpectra'][0]) | |
644 |
|
644 | |||
645 | try: |
|
645 | try: | |
646 | if hasattr(fp, 'read'): |
|
646 | if hasattr(fp, 'read'): | |
647 | samplingWindow = numpy.fromfile( |
|
647 | samplingWindow = numpy.fromfile( | |
648 | fp, SAMPLING_STRUCTURE, self.nWindows) |
|
648 | fp, SAMPLING_STRUCTURE, self.nWindows) | |
649 | else: |
|
649 | else: | |
650 | samplingWindow = numpy.fromstring( |
|
650 | samplingWindow = numpy.fromstring( | |
651 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) |
|
651 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) | |
652 | self.length += samplingWindow.nbytes |
|
652 | self.length += samplingWindow.nbytes | |
653 | except Exception, e: |
|
653 | except Exception, e: | |
654 | print "ProcessingHeader: " + str(e) |
|
654 | print "ProcessingHeader: " + str(e) | |
655 | return 0 |
|
655 | return 0 | |
656 |
|
656 | |||
657 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
657 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
658 | self.firstHeight = float(samplingWindow['h0'][0]) |
|
658 | self.firstHeight = float(samplingWindow['h0'][0]) | |
659 | self.deltaHeight = float(samplingWindow['dh'][0]) |
|
659 | self.deltaHeight = float(samplingWindow['dh'][0]) | |
660 | self.samplesWin = samplingWindow['nsa'][0] |
|
660 | self.samplesWin = samplingWindow['nsa'][0] | |
661 |
|
661 | |||
662 | try: |
|
662 | try: | |
663 | if hasattr(fp, 'read'): |
|
663 | if hasattr(fp, 'read'): | |
664 | self.spectraComb = numpy.fromfile( |
|
664 | self.spectraComb = numpy.fromfile( | |
665 | fp, 'u1', 2 * self.totalSpectra) |
|
665 | fp, 'u1', 2 * self.totalSpectra) | |
666 | else: |
|
666 | else: | |
667 | self.spectraComb = numpy.fromstring( |
|
667 | self.spectraComb = numpy.fromstring( | |
668 | fp[self.length:], 'u1', 2 * self.totalSpectra) |
|
668 | fp[self.length:], 'u1', 2 * self.totalSpectra) | |
669 | self.length += self.spectraComb.nbytes |
|
669 | self.length += self.spectraComb.nbytes | |
670 | except Exception, e: |
|
670 | except Exception, e: | |
671 | print "ProcessingHeader: " + str(e) |
|
671 | print "ProcessingHeader: " + str(e) | |
672 | return 0 |
|
672 | return 0 | |
673 |
|
673 | |||
674 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
674 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
675 | self.nCode = int(numpy.fromfile(fp, '<u4', 1)) |
|
675 | self.nCode = int(numpy.fromfile(fp, '<u4', 1)) | |
676 | self.nBaud = int(numpy.fromfile(fp, '<u4', 1)) |
|
676 | self.nBaud = int(numpy.fromfile(fp, '<u4', 1)) | |
677 | self.code = numpy.fromfile( |
|
677 | self.code = numpy.fromfile( | |
678 | fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud) |
|
678 | fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud) | |
679 |
|
679 | |||
680 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): |
|
680 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): | |
681 | exp_name_len = int(numpy.fromfile(fp, '<u4', 1)) |
|
681 | exp_name_len = int(numpy.fromfile(fp, '<u4', 1)) | |
682 | exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1) |
|
682 | exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1) | |
683 |
|
683 | |||
684 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
684 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
685 | self.shif_fft = True |
|
685 | self.shif_fft = True | |
686 | else: |
|
686 | else: | |
687 | self.shif_fft = False |
|
687 | self.shif_fft = False | |
688 |
|
688 | |||
689 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
689 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
690 | self.flag_dc = True |
|
690 | self.flag_dc = True | |
691 | else: |
|
691 | else: | |
692 | self.flag_dc = False |
|
692 | self.flag_dc = False | |
693 |
|
693 | |||
694 | if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA): |
|
694 | if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA): | |
695 | self.flag_decode = True |
|
695 | self.flag_decode = True | |
696 | else: |
|
696 | else: | |
697 | self.flag_decode = False |
|
697 | self.flag_decode = False | |
698 |
|
698 | |||
699 | if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA): |
|
699 | if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA): | |
700 | self.flag_deflip = True |
|
700 | self.flag_deflip = True | |
701 | else: |
|
701 | else: | |
702 | self.flag_deflip = False |
|
702 | self.flag_deflip = False | |
703 |
|
703 | |||
704 | nChannels = 0 |
|
704 | nChannels = 0 | |
705 | nPairs = 0 |
|
705 | nPairs = 0 | |
706 | pairList = [] |
|
706 | pairList = [] | |
707 |
|
707 | |||
708 | for i in range(0, self.totalSpectra * 2, 2): |
|
708 | for i in range(0, self.totalSpectra * 2, 2): | |
709 | if self.spectraComb[i] == self.spectraComb[i + 1]: |
|
709 | if self.spectraComb[i] == self.spectraComb[i + 1]: | |
710 | nChannels = nChannels + 1 # par de canales iguales |
|
710 | nChannels = nChannels + 1 # par de canales iguales | |
711 | else: |
|
711 | else: | |
712 | nPairs = nPairs + 1 # par de canales diferentes |
|
712 | nPairs = nPairs + 1 # par de canales diferentes | |
713 | pairList.append((self.spectraComb[i], self.spectraComb[i + 1])) |
|
713 | pairList.append((self.spectraComb[i], self.spectraComb[i + 1])) | |
714 |
|
714 | |||
715 | self.flag_cspc = False |
|
715 | self.flag_cspc = False | |
716 | if nPairs > 0: |
|
716 | if nPairs > 0: | |
717 | self.flag_cspc = True |
|
717 | self.flag_cspc = True | |
718 |
|
718 | |||
719 | if startFp is not None: |
|
719 | if startFp is not None: | |
720 | endFp = size + startFp |
|
720 | endFp = size + startFp | |
721 | if fp.tell() > endFp: |
|
721 | if fp.tell() > endFp: | |
722 | sys.stderr.write( |
|
722 | sys.stderr.write( | |
723 | "Warning: Processing header size is lower than it has to be") |
|
723 | "Warning: Processing header size is lower than it has to be") | |
724 | return 0 |
|
724 | return 0 | |
725 |
|
725 | |||
726 | if fp.tell() < endFp: |
|
726 | if fp.tell() < endFp: | |
727 | sys.stderr.write( |
|
727 | sys.stderr.write( | |
728 | "Warning: Processing header size is greater than it is considered") |
|
728 | "Warning: Processing header size is greater than it is considered") | |
729 |
|
729 | |||
730 | return 1 |
|
730 | return 1 | |
731 |
|
731 | |||
732 | def write(self, fp): |
|
732 | def write(self, fp): | |
733 | # Clear DEFINE_PROCESS_CODE |
|
733 | # Clear DEFINE_PROCESS_CODE | |
734 | self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE) |
|
734 | self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE) | |
735 |
|
735 | |||
736 | headerTuple = (self.size, |
|
736 | headerTuple = (self.size, | |
737 | self.dtype, |
|
737 | self.dtype, | |
738 | self.blockSize, |
|
738 | self.blockSize, | |
739 | self.profilesPerBlock, |
|
739 | self.profilesPerBlock, | |
740 | self.dataBlocksPerFile, |
|
740 | self.dataBlocksPerFile, | |
741 | self.nWindows, |
|
741 | self.nWindows, | |
742 | self.processFlags, |
|
742 | self.processFlags, | |
743 | self.nCohInt, |
|
743 | self.nCohInt, | |
744 | self.nIncohInt, |
|
744 | self.nIncohInt, | |
745 | self.totalSpectra) |
|
745 | self.totalSpectra) | |
746 |
|
746 | |||
747 | header = numpy.array(headerTuple, PROCESSING_STRUCTURE) |
|
747 | header = numpy.array(headerTuple, PROCESSING_STRUCTURE) | |
748 | header.tofile(fp) |
|
748 | header.tofile(fp) | |
749 |
|
749 | |||
750 | if self.nWindows != 0: |
|
750 | if self.nWindows != 0: | |
751 | sampleWindowTuple = ( |
|
751 | sampleWindowTuple = ( | |
752 | self.firstHeight, self.deltaHeight, self.samplesWin) |
|
752 | self.firstHeight, self.deltaHeight, self.samplesWin) | |
753 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) |
|
753 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) | |
754 | samplingWindow.tofile(fp) |
|
754 | samplingWindow.tofile(fp) | |
755 |
|
755 | |||
756 | if self.totalSpectra != 0: |
|
756 | if self.totalSpectra != 0: | |
757 | # spectraComb = numpy.array([],numpy.dtype('u1')) |
|
757 | # spectraComb = numpy.array([],numpy.dtype('u1')) | |
758 | spectraComb = self.spectraComb |
|
758 | spectraComb = self.spectraComb | |
759 | spectraComb.tofile(fp) |
|
759 | spectraComb.tofile(fp) | |
760 |
|
760 | |||
761 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
761 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
762 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
762 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
763 | # nCode.tofile(fp) |
|
763 | # nCode.tofile(fp) | |
764 | # |
|
764 | # | |
765 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
765 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) | |
766 | # nBaud.tofile(fp) |
|
766 | # nBaud.tofile(fp) | |
767 | # |
|
767 | # | |
768 | # code = self.code.reshape(self.nCode*self.nBaud) |
|
768 | # code = self.code.reshape(self.nCode*self.nBaud) | |
769 | # code = code.astype(numpy.dtype('<f4')) |
|
769 | # code = code.astype(numpy.dtype('<f4')) | |
770 | # code.tofile(fp) |
|
770 | # code.tofile(fp) | |
771 |
|
771 | |||
772 | return 1 |
|
772 | return 1 | |
773 |
|
773 | |||
774 | def get_size(self): |
|
774 | def get_size(self): | |
775 |
|
775 | |||
776 | self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra |
|
776 | self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra | |
777 |
|
777 | |||
778 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
778 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
779 | # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) |
|
779 | # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) | |
780 | # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud |
|
780 | # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud | |
781 |
|
781 | |||
782 | return self.__size |
|
782 | return self.__size | |
783 |
|
783 | |||
784 | def set_size(self, value): |
|
784 | def set_size(self, value): | |
785 |
|
785 | |||
786 | raise IOError, "size is a property and it cannot be set, just read" |
|
786 | raise IOError, "size is a property and it cannot be set, just read" | |
787 |
|
787 | |||
788 | return |
|
788 | return | |
789 |
|
789 | |||
790 | size = property(get_size, set_size) |
|
790 | size = property(get_size, set_size) | |
791 |
|
791 | |||
792 |
|
792 | |||
793 | class RCfunction: |
|
793 | class RCfunction: | |
794 | NONE = 0 |
|
794 | NONE = 0 | |
795 | FLIP = 1 |
|
795 | FLIP = 1 | |
796 | CODE = 2 |
|
796 | CODE = 2 | |
797 | SAMPLING = 3 |
|
797 | SAMPLING = 3 | |
798 | LIN6DIV256 = 4 |
|
798 | LIN6DIV256 = 4 | |
799 | SYNCHRO = 5 |
|
799 | SYNCHRO = 5 | |
800 |
|
800 | |||
801 |
|
801 | |||
802 | class nCodeType: |
|
802 | class nCodeType: | |
803 | NONE = 0 |
|
803 | NONE = 0 | |
804 | USERDEFINE = 1 |
|
804 | USERDEFINE = 1 | |
805 | BARKER2 = 2 |
|
805 | BARKER2 = 2 | |
806 | BARKER3 = 3 |
|
806 | BARKER3 = 3 | |
807 | BARKER4 = 4 |
|
807 | BARKER4 = 4 | |
808 | BARKER5 = 5 |
|
808 | BARKER5 = 5 | |
809 | BARKER7 = 6 |
|
809 | BARKER7 = 6 | |
810 | BARKER11 = 7 |
|
810 | BARKER11 = 7 | |
811 | BARKER13 = 8 |
|
811 | BARKER13 = 8 | |
812 | AC128 = 9 |
|
812 | AC128 = 9 | |
813 | COMPLEMENTARYCODE2 = 10 |
|
813 | COMPLEMENTARYCODE2 = 10 | |
814 | COMPLEMENTARYCODE4 = 11 |
|
814 | COMPLEMENTARYCODE4 = 11 | |
815 | COMPLEMENTARYCODE8 = 12 |
|
815 | COMPLEMENTARYCODE8 = 12 | |
816 | COMPLEMENTARYCODE16 = 13 |
|
816 | COMPLEMENTARYCODE16 = 13 | |
817 | COMPLEMENTARYCODE32 = 14 |
|
817 | COMPLEMENTARYCODE32 = 14 | |
818 | COMPLEMENTARYCODE64 = 15 |
|
818 | COMPLEMENTARYCODE64 = 15 | |
819 | COMPLEMENTARYCODE128 = 16 |
|
819 | COMPLEMENTARYCODE128 = 16 | |
820 | CODE_BINARY28 = 17 |
|
820 | CODE_BINARY28 = 17 | |
821 |
|
821 | |||
822 |
|
822 | |||
823 | class PROCFLAG: |
|
823 | class PROCFLAG: | |
824 |
|
824 | |||
825 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
825 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
826 | DECODE_DATA = numpy.uint32(0x00000002) |
|
826 | DECODE_DATA = numpy.uint32(0x00000002) | |
827 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
827 | SPECTRA_CALC = numpy.uint32(0x00000004) | |
828 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
828 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |
829 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
829 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |
830 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
830 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |
831 |
|
831 | |||
832 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
832 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |
833 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
833 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |
834 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
834 | DATATYPE_LONG = numpy.uint32(0x00000100) | |
835 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
835 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |
836 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
836 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |
837 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
837 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |
838 |
|
838 | |||
839 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
839 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |
840 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
840 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |
841 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
841 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |
842 |
|
842 | |||
843 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
843 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |
844 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
844 | DEFLIP_DATA = numpy.uint32(0x00010000) | |
845 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
845 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |
846 |
|
846 | |||
847 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
847 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |
848 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
848 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |
849 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
849 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |
850 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
850 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |
851 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
851 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |
852 |
|
852 | |||
853 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
853 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |
854 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
854 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |
855 |
|
855 | |||
856 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
856 | OPERATION_MASK = numpy.uint32(0x0000003F) | |
857 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
857 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |
858 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
858 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
859 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
859 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) | |
860 |
|
860 | |||
861 |
|
861 | |||
862 | dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
862 | dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
863 | dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
863 | dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
864 | dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
864 | dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
865 | dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
865 | dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
866 | dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
866 | dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
867 | dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
867 | dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
868 |
|
868 | |||
869 | NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
869 | NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
870 |
|
870 | |||
871 | PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, |
|
871 | PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, | |
872 | PROCFLAG.DATATYPE_SHORT, |
|
872 | PROCFLAG.DATATYPE_SHORT, | |
873 | PROCFLAG.DATATYPE_LONG, |
|
873 | PROCFLAG.DATATYPE_LONG, | |
874 | PROCFLAG.DATATYPE_INT64, |
|
874 | PROCFLAG.DATATYPE_INT64, | |
875 | PROCFLAG.DATATYPE_FLOAT, |
|
875 | PROCFLAG.DATATYPE_FLOAT, | |
876 | PROCFLAG.DATATYPE_DOUBLE] |
|
876 | PROCFLAG.DATATYPE_DOUBLE] | |
877 |
|
877 | |||
878 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] |
|
878 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] | |
879 |
|
879 | |||
880 |
|
880 | |||
881 | def get_dtype_index(numpy_dtype): |
|
881 | def get_dtype_index(numpy_dtype): | |
882 |
|
882 | |||
883 | index = None |
|
883 | index = None | |
884 |
|
884 | |||
885 | for i in range(len(NUMPY_DTYPE_LIST)): |
|
885 | for i in range(len(NUMPY_DTYPE_LIST)): | |
886 | if numpy_dtype == NUMPY_DTYPE_LIST[i]: |
|
886 | if numpy_dtype == NUMPY_DTYPE_LIST[i]: | |
887 | index = i |
|
887 | index = i | |
888 | break |
|
888 | break | |
889 |
|
889 | |||
890 | return index |
|
890 | return index | |
891 |
|
891 | |||
892 |
|
892 | |||
893 | def get_numpy_dtype(index): |
|
893 | def get_numpy_dtype(index): | |
894 |
|
894 | |||
895 | return NUMPY_DTYPE_LIST[index] |
|
895 | return NUMPY_DTYPE_LIST[index] | |
896 |
|
896 | |||
897 |
|
897 | |||
898 | def get_procflag_dtype(index): |
|
898 | def get_procflag_dtype(index): | |
899 |
|
899 | |||
900 | return PROCFLAG_DTYPE_LIST[index] |
|
900 | return PROCFLAG_DTYPE_LIST[index] | |
901 |
|
901 | |||
902 |
|
902 | |||
903 | def get_dtype_width(index): |
|
903 | def get_dtype_width(index): | |
904 |
|
904 | |||
905 | return DTYPE_WIDTH[index] |
|
905 | return DTYPE_WIDTH[index] |
@@ -1,1319 +1,1319 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy |
|
2 | import numpy | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy import cSchain |
|
4 | from schainpy import cSchain | |
5 | from jroproc_base import ProcessingUnit, Operation |
|
5 | from jroproc_base import ProcessingUnit, Operation | |
6 | from schainpy.model.data.jrodata import Voltage |
|
6 | from schainpy.model.data.jrodata import Voltage | |
7 | from time import time |
|
7 | from time import time | |
8 |
|
8 | |||
9 | class VoltageProc(ProcessingUnit): |
|
9 | class VoltageProc(ProcessingUnit): | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def __init__(self, **kwargs): |
|
12 | def __init__(self, **kwargs): | |
13 |
|
13 | |||
14 | ProcessingUnit.__init__(self, **kwargs) |
|
14 | ProcessingUnit.__init__(self, **kwargs) | |
15 |
|
15 | |||
16 | # self.objectDict = {} |
|
16 | # self.objectDict = {} | |
17 | self.dataOut = Voltage() |
|
17 | self.dataOut = Voltage() | |
18 | self.flip = 1 |
|
18 | self.flip = 1 | |
19 |
|
19 | |||
20 | def run(self): |
|
20 | def run(self): | |
21 | if self.dataIn.type == 'AMISR': |
|
21 | if self.dataIn.type == 'AMISR': | |
22 | self.__updateObjFromAmisrInput() |
|
22 | self.__updateObjFromAmisrInput() | |
23 |
|
23 | |||
24 | if self.dataIn.type == 'Voltage': |
|
24 | if self.dataIn.type == 'Voltage': | |
25 | self.dataOut.copy(self.dataIn) |
|
25 | self.dataOut.copy(self.dataIn) | |
26 |
|
26 | |||
27 | # self.dataOut.copy(self.dataIn) |
|
27 | # self.dataOut.copy(self.dataIn) | |
28 |
|
28 | |||
29 | def __updateObjFromAmisrInput(self): |
|
29 | def __updateObjFromAmisrInput(self): | |
30 |
|
30 | |||
31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
31 | self.dataOut.timeZone = self.dataIn.timeZone | |
32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
32 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
33 | self.dataOut.errorCount = self.dataIn.errorCount | |
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
35 |
|
35 | |||
36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
36 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
37 | self.dataOut.data = self.dataIn.data |
|
37 | self.dataOut.data = self.dataIn.data | |
38 | self.dataOut.utctime = self.dataIn.utctime |
|
38 | self.dataOut.utctime = self.dataIn.utctime | |
39 | self.dataOut.channelList = self.dataIn.channelList |
|
39 | self.dataOut.channelList = self.dataIn.channelList | |
40 | # self.dataOut.timeInterval = self.dataIn.timeInterval |
|
40 | # self.dataOut.timeInterval = self.dataIn.timeInterval | |
41 | self.dataOut.heightList = self.dataIn.heightList |
|
41 | self.dataOut.heightList = self.dataIn.heightList | |
42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
42 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
43 |
|
43 | |||
44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
44 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
46 | self.dataOut.frequency = self.dataIn.frequency |
|
46 | self.dataOut.frequency = self.dataIn.frequency | |
47 |
|
47 | |||
48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
48 | self.dataOut.azimuth = self.dataIn.azimuth | |
49 | self.dataOut.zenith = self.dataIn.zenith |
|
49 | self.dataOut.zenith = self.dataIn.zenith | |
50 |
|
50 | |||
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
54 | # |
|
54 | # | |
55 | # pass# |
|
55 | # pass# | |
56 | # |
|
56 | # | |
57 | # def init(self): |
|
57 | # def init(self): | |
58 | # |
|
58 | # | |
59 | # |
|
59 | # | |
60 | # if self.dataIn.type == 'AMISR': |
|
60 | # if self.dataIn.type == 'AMISR': | |
61 | # self.__updateObjFromAmisrInput() |
|
61 | # self.__updateObjFromAmisrInput() | |
62 | # |
|
62 | # | |
63 | # if self.dataIn.type == 'Voltage': |
|
63 | # if self.dataIn.type == 'Voltage': | |
64 | # self.dataOut.copy(self.dataIn) |
|
64 | # self.dataOut.copy(self.dataIn) | |
65 | # # No necesita copiar en cada init() los atributos de dataIn |
|
65 | # # No necesita copiar en cada init() los atributos de dataIn | |
66 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
66 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
67 |
|
67 | |||
68 | def selectChannels(self, channelList): |
|
68 | def selectChannels(self, channelList): | |
69 |
|
69 | |||
70 | channelIndexList = [] |
|
70 | channelIndexList = [] | |
71 |
|
71 | |||
72 | for channel in channelList: |
|
72 | for channel in channelList: | |
73 | if channel not in self.dataOut.channelList: |
|
73 | if channel not in self.dataOut.channelList: | |
74 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) |
|
74 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) | |
75 |
|
75 | |||
76 | index = self.dataOut.channelList.index(channel) |
|
76 | index = self.dataOut.channelList.index(channel) | |
77 | channelIndexList.append(index) |
|
77 | channelIndexList.append(index) | |
78 |
|
78 | |||
79 | self.selectChannelsByIndex(channelIndexList) |
|
79 | self.selectChannelsByIndex(channelIndexList) | |
80 |
|
80 | |||
81 | def selectChannelsByIndex(self, channelIndexList): |
|
81 | def selectChannelsByIndex(self, channelIndexList): | |
82 | """ |
|
82 | """ | |
83 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
83 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
86 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
87 |
|
87 | |||
88 | Affected: |
|
88 | Affected: | |
89 | self.dataOut.data |
|
89 | self.dataOut.data | |
90 | self.dataOut.channelIndexList |
|
90 | self.dataOut.channelIndexList | |
91 | self.dataOut.nChannels |
|
91 | self.dataOut.nChannels | |
92 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
92 | self.dataOut.m_ProcessingHeader.totalSpectra | |
93 | self.dataOut.systemHeaderObj.numChannels |
|
93 | self.dataOut.systemHeaderObj.numChannels | |
94 | self.dataOut.m_ProcessingHeader.blockSize |
|
94 | self.dataOut.m_ProcessingHeader.blockSize | |
95 |
|
95 | |||
96 | Return: |
|
96 | Return: | |
97 | None |
|
97 | None | |
98 | """ |
|
98 | """ | |
99 |
|
99 | |||
100 | for channelIndex in channelIndexList: |
|
100 | for channelIndex in channelIndexList: | |
101 | if channelIndex not in self.dataOut.channelIndexList: |
|
101 | if channelIndex not in self.dataOut.channelIndexList: | |
102 | print channelIndexList |
|
102 | print channelIndexList | |
103 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
103 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
104 |
|
104 | |||
105 | if self.dataOut.flagDataAsBlock: |
|
105 | if self.dataOut.flagDataAsBlock: | |
106 | """ |
|
106 | """ | |
107 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
107 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
108 | """ |
|
108 | """ | |
109 | data = self.dataOut.data[channelIndexList,:,:] |
|
109 | data = self.dataOut.data[channelIndexList,:,:] | |
110 | else: |
|
110 | else: | |
111 | data = self.dataOut.data[channelIndexList,:] |
|
111 | data = self.dataOut.data[channelIndexList,:] | |
112 |
|
112 | |||
113 | self.dataOut.data = data |
|
113 | self.dataOut.data = data | |
114 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
114 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
115 | # self.dataOut.nChannels = nChannels |
|
115 | # self.dataOut.nChannels = nChannels | |
116 |
|
116 | |||
117 | return 1 |
|
117 | return 1 | |
118 |
|
118 | |||
119 | def selectHeights(self, minHei=None, maxHei=None): |
|
119 | def selectHeights(self, minHei=None, maxHei=None): | |
120 | """ |
|
120 | """ | |
121 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
121 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
122 | minHei <= height <= maxHei |
|
122 | minHei <= height <= maxHei | |
123 |
|
123 | |||
124 | Input: |
|
124 | Input: | |
125 | minHei : valor minimo de altura a considerar |
|
125 | minHei : valor minimo de altura a considerar | |
126 | maxHei : valor maximo de altura a considerar |
|
126 | maxHei : valor maximo de altura a considerar | |
127 |
|
127 | |||
128 | Affected: |
|
128 | Affected: | |
129 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
129 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
130 |
|
130 | |||
131 | Return: |
|
131 | Return: | |
132 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
132 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
133 | """ |
|
133 | """ | |
134 |
|
134 | |||
135 | if minHei == None: |
|
135 | if minHei == None: | |
136 | minHei = self.dataOut.heightList[0] |
|
136 | minHei = self.dataOut.heightList[0] | |
137 |
|
137 | |||
138 | if maxHei == None: |
|
138 | if maxHei == None: | |
139 | maxHei = self.dataOut.heightList[-1] |
|
139 | maxHei = self.dataOut.heightList[-1] | |
140 |
|
140 | |||
141 | if (minHei < self.dataOut.heightList[0]): |
|
141 | if (minHei < self.dataOut.heightList[0]): | |
142 | minHei = self.dataOut.heightList[0] |
|
142 | minHei = self.dataOut.heightList[0] | |
143 |
|
143 | |||
144 | if (maxHei > self.dataOut.heightList[-1]): |
|
144 | if (maxHei > self.dataOut.heightList[-1]): | |
145 | maxHei = self.dataOut.heightList[-1] |
|
145 | maxHei = self.dataOut.heightList[-1] | |
146 |
|
146 | |||
147 | minIndex = 0 |
|
147 | minIndex = 0 | |
148 | maxIndex = 0 |
|
148 | maxIndex = 0 | |
149 | heights = self.dataOut.heightList |
|
149 | heights = self.dataOut.heightList | |
150 |
|
150 | |||
151 | inda = numpy.where(heights >= minHei) |
|
151 | inda = numpy.where(heights >= minHei) | |
152 | indb = numpy.where(heights <= maxHei) |
|
152 | indb = numpy.where(heights <= maxHei) | |
153 |
|
153 | |||
154 | try: |
|
154 | try: | |
155 | minIndex = inda[0][0] |
|
155 | minIndex = inda[0][0] | |
156 | except: |
|
156 | except: | |
157 | minIndex = 0 |
|
157 | minIndex = 0 | |
158 |
|
158 | |||
159 | try: |
|
159 | try: | |
160 | maxIndex = indb[0][-1] |
|
160 | maxIndex = indb[0][-1] | |
161 | except: |
|
161 | except: | |
162 | maxIndex = len(heights) |
|
162 | maxIndex = len(heights) | |
163 |
|
163 | |||
164 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
164 | self.selectHeightsByIndex(minIndex, maxIndex) | |
165 |
|
165 | |||
166 | return 1 |
|
166 | return 1 | |
167 |
|
167 | |||
168 |
|
168 | |||
169 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
169 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
170 | """ |
|
170 | """ | |
171 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
171 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
172 | minIndex <= index <= maxIndex |
|
172 | minIndex <= index <= maxIndex | |
173 |
|
173 | |||
174 | Input: |
|
174 | Input: | |
175 | minIndex : valor de indice minimo de altura a considerar |
|
175 | minIndex : valor de indice minimo de altura a considerar | |
176 | maxIndex : valor de indice maximo de altura a considerar |
|
176 | maxIndex : valor de indice maximo de altura a considerar | |
177 |
|
177 | |||
178 | Affected: |
|
178 | Affected: | |
179 | self.dataOut.data |
|
179 | self.dataOut.data | |
180 | self.dataOut.heightList |
|
180 | self.dataOut.heightList | |
181 |
|
181 | |||
182 | Return: |
|
182 | Return: | |
183 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
183 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
184 | """ |
|
184 | """ | |
185 |
|
185 | |||
186 | if (minIndex < 0) or (minIndex > maxIndex): |
|
186 | if (minIndex < 0) or (minIndex > maxIndex): | |
187 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
187 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) | |
188 |
|
188 | |||
189 | if (maxIndex >= self.dataOut.nHeights): |
|
189 | if (maxIndex >= self.dataOut.nHeights): | |
190 | maxIndex = self.dataOut.nHeights |
|
190 | maxIndex = self.dataOut.nHeights | |
191 |
|
191 | |||
192 | #voltage |
|
192 | #voltage | |
193 | if self.dataOut.flagDataAsBlock: |
|
193 | if self.dataOut.flagDataAsBlock: | |
194 | """ |
|
194 | """ | |
195 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
195 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
196 | """ |
|
196 | """ | |
197 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
197 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
198 | else: |
|
198 | else: | |
199 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
199 | data = self.dataOut.data[:, minIndex:maxIndex] | |
200 |
|
200 | |||
201 | # firstHeight = self.dataOut.heightList[minIndex] |
|
201 | # firstHeight = self.dataOut.heightList[minIndex] | |
202 |
|
202 | |||
203 | self.dataOut.data = data |
|
203 | self.dataOut.data = data | |
204 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
204 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
205 |
|
205 | |||
206 | if self.dataOut.nHeights <= 1: |
|
206 | if self.dataOut.nHeights <= 1: | |
207 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) |
|
207 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) | |
208 |
|
208 | |||
209 | return 1 |
|
209 | return 1 | |
210 |
|
210 | |||
211 |
|
211 | |||
212 | def filterByHeights(self, window): |
|
212 | def filterByHeights(self, window): | |
213 |
|
213 | |||
214 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
214 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
215 |
|
215 | |||
216 | if window == None: |
|
216 | if window == None: | |
217 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
217 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
218 |
|
218 | |||
219 | newdelta = deltaHeight * window |
|
219 | newdelta = deltaHeight * window | |
220 | r = self.dataOut.nHeights % window |
|
220 | r = self.dataOut.nHeights % window | |
221 | newheights = (self.dataOut.nHeights-r)/window |
|
221 | newheights = (self.dataOut.nHeights-r)/window | |
222 |
|
222 | |||
223 | if newheights <= 1: |
|
223 | if newheights <= 1: | |
224 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) |
|
224 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) | |
225 |
|
225 | |||
226 | if self.dataOut.flagDataAsBlock: |
|
226 | if self.dataOut.flagDataAsBlock: | |
227 | """ |
|
227 | """ | |
228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
229 | """ |
|
229 | """ | |
230 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] |
|
230 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] | |
231 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) |
|
231 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) | |
232 | buffer = numpy.sum(buffer,3) |
|
232 | buffer = numpy.sum(buffer,3) | |
233 |
|
233 | |||
234 | else: |
|
234 | else: | |
235 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] |
|
235 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] | |
236 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) |
|
236 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) | |
237 | buffer = numpy.sum(buffer,2) |
|
237 | buffer = numpy.sum(buffer,2) | |
238 |
|
238 | |||
239 | self.dataOut.data = buffer |
|
239 | self.dataOut.data = buffer | |
240 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
240 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
241 | self.dataOut.windowOfFilter = window |
|
241 | self.dataOut.windowOfFilter = window | |
242 |
|
242 | |||
243 | def setH0(self, h0, deltaHeight = None): |
|
243 | def setH0(self, h0, deltaHeight = None): | |
244 |
|
244 | |||
245 | if not deltaHeight: |
|
245 | if not deltaHeight: | |
246 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
246 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
247 |
|
247 | |||
248 | nHeights = self.dataOut.nHeights |
|
248 | nHeights = self.dataOut.nHeights | |
249 |
|
249 | |||
250 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
250 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
251 |
|
251 | |||
252 | self.dataOut.heightList = newHeiRange |
|
252 | self.dataOut.heightList = newHeiRange | |
253 |
|
253 | |||
254 | def deFlip(self, channelList = []): |
|
254 | def deFlip(self, channelList = []): | |
255 |
|
255 | |||
256 | data = self.dataOut.data.copy() |
|
256 | data = self.dataOut.data.copy() | |
257 |
|
257 | |||
258 | if self.dataOut.flagDataAsBlock: |
|
258 | if self.dataOut.flagDataAsBlock: | |
259 | flip = self.flip |
|
259 | flip = self.flip | |
260 | profileList = range(self.dataOut.nProfiles) |
|
260 | profileList = range(self.dataOut.nProfiles) | |
261 |
|
261 | |||
262 | if not channelList: |
|
262 | if not channelList: | |
263 | for thisProfile in profileList: |
|
263 | for thisProfile in profileList: | |
264 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
264 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
265 | flip *= -1.0 |
|
265 | flip *= -1.0 | |
266 | else: |
|
266 | else: | |
267 | for thisChannel in channelList: |
|
267 | for thisChannel in channelList: | |
268 | if thisChannel not in self.dataOut.channelList: |
|
268 | if thisChannel not in self.dataOut.channelList: | |
269 | continue |
|
269 | continue | |
270 |
|
270 | |||
271 | for thisProfile in profileList: |
|
271 | for thisProfile in profileList: | |
272 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
272 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
273 | flip *= -1.0 |
|
273 | flip *= -1.0 | |
274 |
|
274 | |||
275 | self.flip = flip |
|
275 | self.flip = flip | |
276 |
|
276 | |||
277 | else: |
|
277 | else: | |
278 | if not channelList: |
|
278 | if not channelList: | |
279 | data[:,:] = data[:,:]*self.flip |
|
279 | data[:,:] = data[:,:]*self.flip | |
280 | else: |
|
280 | else: | |
281 | for thisChannel in channelList: |
|
281 | for thisChannel in channelList: | |
282 | if thisChannel not in self.dataOut.channelList: |
|
282 | if thisChannel not in self.dataOut.channelList: | |
283 | continue |
|
283 | continue | |
284 |
|
284 | |||
285 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
285 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
286 |
|
286 | |||
287 | self.flip *= -1. |
|
287 | self.flip *= -1. | |
288 |
|
288 | |||
289 | self.dataOut.data = data |
|
289 | self.dataOut.data = data | |
290 |
|
290 | |||
291 | def setRadarFrequency(self, frequency=None): |
|
291 | def setRadarFrequency(self, frequency=None): | |
292 |
|
292 | |||
293 | if frequency != None: |
|
293 | if frequency != None: | |
294 | self.dataOut.frequency = frequency |
|
294 | self.dataOut.frequency = frequency | |
295 |
|
295 | |||
296 | return 1 |
|
296 | return 1 | |
297 |
|
297 | |||
298 | def interpolateHeights(self, topLim, botLim): |
|
298 | def interpolateHeights(self, topLim, botLim): | |
299 | #69 al 72 para julia |
|
299 | #69 al 72 para julia | |
300 | #82-84 para meteoros |
|
300 | #82-84 para meteoros | |
301 | if len(numpy.shape(self.dataOut.data))==2: |
|
301 | if len(numpy.shape(self.dataOut.data))==2: | |
302 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 |
|
302 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 | |
303 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
303 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
304 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp |
|
304 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp | |
305 | self.dataOut.data[:,botLim:topLim+1] = sampInterp |
|
305 | self.dataOut.data[:,botLim:topLim+1] = sampInterp | |
306 | else: |
|
306 | else: | |
307 | nHeights = self.dataOut.data.shape[2] |
|
307 | nHeights = self.dataOut.data.shape[2] | |
308 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
308 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
309 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] |
|
309 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] | |
310 | f = interpolate.interp1d(x, y, axis = 2) |
|
310 | f = interpolate.interp1d(x, y, axis = 2) | |
311 | xnew = numpy.arange(botLim,topLim+1) |
|
311 | xnew = numpy.arange(botLim,topLim+1) | |
312 | ynew = f(xnew) |
|
312 | ynew = f(xnew) | |
313 |
|
313 | |||
314 | self.dataOut.data[:,:,botLim:topLim+1] = ynew |
|
314 | self.dataOut.data[:,:,botLim:topLim+1] = ynew | |
315 |
|
315 | |||
316 | # import collections |
|
316 | # import collections | |
317 |
|
317 | |||
318 | class CohInt(Operation): |
|
318 | class CohInt(Operation): | |
319 |
|
319 | |||
320 | isConfig = False |
|
320 | isConfig = False | |
321 | __profIndex = 0 |
|
321 | __profIndex = 0 | |
322 | __byTime = False |
|
322 | __byTime = False | |
323 | __initime = None |
|
323 | __initime = None | |
324 | __lastdatatime = None |
|
324 | __lastdatatime = None | |
325 | __integrationtime = None |
|
325 | __integrationtime = None | |
326 | __buffer = None |
|
326 | __buffer = None | |
327 | __bufferStride = [] |
|
327 | __bufferStride = [] | |
328 | __dataReady = False |
|
328 | __dataReady = False | |
329 | __profIndexStride = 0 |
|
329 | __profIndexStride = 0 | |
330 | __dataToPutStride = False |
|
330 | __dataToPutStride = False | |
331 | n = None |
|
331 | n = None | |
332 |
|
332 | |||
333 | def __init__(self, **kwargs): |
|
333 | def __init__(self, **kwargs): | |
334 |
|
334 | |||
335 | Operation.__init__(self, **kwargs) |
|
335 | Operation.__init__(self, **kwargs) | |
336 |
|
336 | |||
337 | # self.isConfig = False |
|
337 | # self.isConfig = False | |
338 |
|
338 | |||
339 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
339 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
340 | """ |
|
340 | """ | |
341 | Set the parameters of the integration class. |
|
341 | Set the parameters of the integration class. | |
342 |
|
342 | |||
343 | Inputs: |
|
343 | Inputs: | |
344 |
|
344 | |||
345 | n : Number of coherent integrations |
|
345 | n : Number of coherent integrations | |
346 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
346 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
347 | overlapping : |
|
347 | overlapping : | |
348 | """ |
|
348 | """ | |
349 |
|
349 | |||
350 | self.__initime = None |
|
350 | self.__initime = None | |
351 | self.__lastdatatime = 0 |
|
351 | self.__lastdatatime = 0 | |
352 | self.__buffer = None |
|
352 | self.__buffer = None | |
353 | self.__dataReady = False |
|
353 | self.__dataReady = False | |
354 | self.byblock = byblock |
|
354 | self.byblock = byblock | |
355 | self.stride = stride |
|
355 | self.stride = stride | |
356 |
|
356 | |||
357 | if n == None and timeInterval == None: |
|
357 | if n == None and timeInterval == None: | |
358 | raise ValueError, "n or timeInterval should be specified ..." |
|
358 | raise ValueError, "n or timeInterval should be specified ..." | |
359 |
|
359 | |||
360 | if n != None: |
|
360 | if n != None: | |
361 | self.n = n |
|
361 | self.n = n | |
362 | self.__byTime = False |
|
362 | self.__byTime = False | |
363 | else: |
|
363 | else: | |
364 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
364 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
365 | self.n = 9999 |
|
365 | self.n = 9999 | |
366 | self.__byTime = True |
|
366 | self.__byTime = True | |
367 |
|
367 | |||
368 | if overlapping: |
|
368 | if overlapping: | |
369 | self.__withOverlapping = True |
|
369 | self.__withOverlapping = True | |
370 | self.__buffer = None |
|
370 | self.__buffer = None | |
371 | else: |
|
371 | else: | |
372 | self.__withOverlapping = False |
|
372 | self.__withOverlapping = False | |
373 | self.__buffer = 0 |
|
373 | self.__buffer = 0 | |
374 |
|
374 | |||
375 | self.__profIndex = 0 |
|
375 | self.__profIndex = 0 | |
376 |
|
376 | |||
377 | def putData(self, data): |
|
377 | def putData(self, data): | |
378 |
|
378 | |||
379 | """ |
|
379 | """ | |
380 | Add a profile to the __buffer and increase in one the __profileIndex |
|
380 | Add a profile to the __buffer and increase in one the __profileIndex | |
381 |
|
381 | |||
382 | """ |
|
382 | """ | |
383 |
|
383 | |||
384 | if not self.__withOverlapping: |
|
384 | if not self.__withOverlapping: | |
385 | self.__buffer += data.copy() |
|
385 | self.__buffer += data.copy() | |
386 | self.__profIndex += 1 |
|
386 | self.__profIndex += 1 | |
387 | return |
|
387 | return | |
388 |
|
388 | |||
389 | #Overlapping data |
|
389 | #Overlapping data | |
390 | nChannels, nHeis = data.shape |
|
390 | nChannels, nHeis = data.shape | |
391 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
391 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
392 |
|
392 | |||
393 | #If the buffer is empty then it takes the data value |
|
393 | #If the buffer is empty then it takes the data value | |
394 | if self.__buffer is None: |
|
394 | if self.__buffer is None: | |
395 | self.__buffer = data |
|
395 | self.__buffer = data | |
396 | self.__profIndex += 1 |
|
396 | self.__profIndex += 1 | |
397 | return |
|
397 | return | |
398 |
|
398 | |||
399 | #If the buffer length is lower than n then stakcing the data value |
|
399 | #If the buffer length is lower than n then stakcing the data value | |
400 | if self.__profIndex < self.n: |
|
400 | if self.__profIndex < self.n: | |
401 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
401 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
402 | self.__profIndex += 1 |
|
402 | self.__profIndex += 1 | |
403 | return |
|
403 | return | |
404 |
|
404 | |||
405 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
405 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
406 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
406 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
407 | self.__buffer[self.n-1] = data |
|
407 | self.__buffer[self.n-1] = data | |
408 | self.__profIndex = self.n |
|
408 | self.__profIndex = self.n | |
409 | return |
|
409 | return | |
410 |
|
410 | |||
411 |
|
411 | |||
412 | def pushData(self): |
|
412 | def pushData(self): | |
413 | """ |
|
413 | """ | |
414 | Return the sum of the last profiles and the profiles used in the sum. |
|
414 | Return the sum of the last profiles and the profiles used in the sum. | |
415 |
|
415 | |||
416 | Affected: |
|
416 | Affected: | |
417 |
|
417 | |||
418 | self.__profileIndex |
|
418 | self.__profileIndex | |
419 |
|
419 | |||
420 | """ |
|
420 | """ | |
421 |
|
421 | |||
422 | if not self.__withOverlapping: |
|
422 | if not self.__withOverlapping: | |
423 | data = self.__buffer |
|
423 | data = self.__buffer | |
424 | n = self.__profIndex |
|
424 | n = self.__profIndex | |
425 |
|
425 | |||
426 | self.__buffer = 0 |
|
426 | self.__buffer = 0 | |
427 | self.__profIndex = 0 |
|
427 | self.__profIndex = 0 | |
428 |
|
428 | |||
429 | return data, n |
|
429 | return data, n | |
430 |
|
430 | |||
431 | #Integration with Overlapping |
|
431 | #Integration with Overlapping | |
432 | data = numpy.sum(self.__buffer, axis=0) |
|
432 | data = numpy.sum(self.__buffer, axis=0) | |
433 | # print data |
|
433 | # print data | |
434 | # raise |
|
434 | # raise | |
435 | n = self.__profIndex |
|
435 | n = self.__profIndex | |
436 |
|
436 | |||
437 | return data, n |
|
437 | return data, n | |
438 |
|
438 | |||
439 | def byProfiles(self, data): |
|
439 | def byProfiles(self, data): | |
440 |
|
440 | |||
441 | self.__dataReady = False |
|
441 | self.__dataReady = False | |
442 | avgdata = None |
|
442 | avgdata = None | |
443 | # n = None |
|
443 | # n = None | |
444 | # print data |
|
444 | # print data | |
445 | # raise |
|
445 | # raise | |
446 | self.putData(data) |
|
446 | self.putData(data) | |
447 |
|
447 | |||
448 | if self.__profIndex == self.n: |
|
448 | if self.__profIndex == self.n: | |
449 | avgdata, n = self.pushData() |
|
449 | avgdata, n = self.pushData() | |
450 | self.__dataReady = True |
|
450 | self.__dataReady = True | |
451 |
|
451 | |||
452 | return avgdata |
|
452 | return avgdata | |
453 |
|
453 | |||
454 | def byTime(self, data, datatime): |
|
454 | def byTime(self, data, datatime): | |
455 |
|
455 | |||
456 | self.__dataReady = False |
|
456 | self.__dataReady = False | |
457 | avgdata = None |
|
457 | avgdata = None | |
458 | n = None |
|
458 | n = None | |
459 |
|
459 | |||
460 | self.putData(data) |
|
460 | self.putData(data) | |
461 |
|
461 | |||
462 | if (datatime - self.__initime) >= self.__integrationtime: |
|
462 | if (datatime - self.__initime) >= self.__integrationtime: | |
463 | avgdata, n = self.pushData() |
|
463 | avgdata, n = self.pushData() | |
464 | self.n = n |
|
464 | self.n = n | |
465 | self.__dataReady = True |
|
465 | self.__dataReady = True | |
466 |
|
466 | |||
467 | return avgdata |
|
467 | return avgdata | |
468 |
|
468 | |||
469 | def integrateByStride(self, data, datatime): |
|
469 | def integrateByStride(self, data, datatime): | |
470 | # print data |
|
470 | # print data | |
471 | if self.__profIndex == 0: |
|
471 | if self.__profIndex == 0: | |
472 | self.__buffer = [[data.copy(), datatime]] |
|
472 | self.__buffer = [[data.copy(), datatime]] | |
473 | else: |
|
473 | else: | |
474 | self.__buffer.append([data.copy(),datatime]) |
|
474 | self.__buffer.append([data.copy(),datatime]) | |
475 | self.__profIndex += 1 |
|
475 | self.__profIndex += 1 | |
476 | self.__dataReady = False |
|
476 | self.__dataReady = False | |
477 |
|
477 | |||
478 | if self.__profIndex == self.n * self.stride : |
|
478 | if self.__profIndex == self.n * self.stride : | |
479 | self.__dataToPutStride = True |
|
479 | self.__dataToPutStride = True | |
480 | self.__profIndexStride = 0 |
|
480 | self.__profIndexStride = 0 | |
481 | self.__profIndex = 0 |
|
481 | self.__profIndex = 0 | |
482 | self.__bufferStride = [] |
|
482 | self.__bufferStride = [] | |
483 | for i in range(self.stride): |
|
483 | for i in range(self.stride): | |
484 | current = self.__buffer[i::self.stride] |
|
484 | current = self.__buffer[i::self.stride] | |
485 | data = numpy.sum([t[0] for t in current], axis=0) |
|
485 | data = numpy.sum([t[0] for t in current], axis=0) | |
486 | avgdatatime = numpy.average([t[1] for t in current]) |
|
486 | avgdatatime = numpy.average([t[1] for t in current]) | |
487 | # print data |
|
487 | # print data | |
488 | self.__bufferStride.append((data, avgdatatime)) |
|
488 | self.__bufferStride.append((data, avgdatatime)) | |
489 |
|
489 | |||
490 | if self.__dataToPutStride: |
|
490 | if self.__dataToPutStride: | |
491 | self.__dataReady = True |
|
491 | self.__dataReady = True | |
492 | self.__profIndexStride += 1 |
|
492 | self.__profIndexStride += 1 | |
493 | if self.__profIndexStride == self.stride: |
|
493 | if self.__profIndexStride == self.stride: | |
494 | self.__dataToPutStride = False |
|
494 | self.__dataToPutStride = False | |
495 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
495 | # print self.__bufferStride[self.__profIndexStride - 1] | |
496 | # raise |
|
496 | # raise | |
497 | return self.__bufferStride[self.__profIndexStride - 1] |
|
497 | return self.__bufferStride[self.__profIndexStride - 1] | |
498 |
|
498 | |||
499 |
|
499 | |||
500 | return None, None |
|
500 | return None, None | |
501 |
|
501 | |||
502 | def integrate(self, data, datatime=None): |
|
502 | def integrate(self, data, datatime=None): | |
503 |
|
503 | |||
504 | if self.__initime == None: |
|
504 | if self.__initime == None: | |
505 | self.__initime = datatime |
|
505 | self.__initime = datatime | |
506 |
|
506 | |||
507 | if self.__byTime: |
|
507 | if self.__byTime: | |
508 | avgdata = self.byTime(data, datatime) |
|
508 | avgdata = self.byTime(data, datatime) | |
509 | else: |
|
509 | else: | |
510 | avgdata = self.byProfiles(data) |
|
510 | avgdata = self.byProfiles(data) | |
511 |
|
511 | |||
512 |
|
512 | |||
513 | self.__lastdatatime = datatime |
|
513 | self.__lastdatatime = datatime | |
514 |
|
514 | |||
515 | if avgdata is None: |
|
515 | if avgdata is None: | |
516 | return None, None |
|
516 | return None, None | |
517 |
|
517 | |||
518 | avgdatatime = self.__initime |
|
518 | avgdatatime = self.__initime | |
519 |
|
519 | |||
520 | deltatime = datatime - self.__lastdatatime |
|
520 | deltatime = datatime - self.__lastdatatime | |
521 |
|
521 | |||
522 | if not self.__withOverlapping: |
|
522 | if not self.__withOverlapping: | |
523 | self.__initime = datatime |
|
523 | self.__initime = datatime | |
524 | else: |
|
524 | else: | |
525 | self.__initime += deltatime |
|
525 | self.__initime += deltatime | |
526 |
|
526 | |||
527 | return avgdata, avgdatatime |
|
527 | return avgdata, avgdatatime | |
528 |
|
528 | |||
529 | def integrateByBlock(self, dataOut): |
|
529 | def integrateByBlock(self, dataOut): | |
530 |
|
530 | |||
531 | times = int(dataOut.data.shape[1]/self.n) |
|
531 | times = int(dataOut.data.shape[1]/self.n) | |
532 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
532 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
533 |
|
533 | |||
534 | id_min = 0 |
|
534 | id_min = 0 | |
535 | id_max = self.n |
|
535 | id_max = self.n | |
536 |
|
536 | |||
537 | for i in range(times): |
|
537 | for i in range(times): | |
538 | junk = dataOut.data[:,id_min:id_max,:] |
|
538 | junk = dataOut.data[:,id_min:id_max,:] | |
539 | avgdata[:,i,:] = junk.sum(axis=1) |
|
539 | avgdata[:,i,:] = junk.sum(axis=1) | |
540 | id_min += self.n |
|
540 | id_min += self.n | |
541 | id_max += self.n |
|
541 | id_max += self.n | |
542 |
|
542 | |||
543 | timeInterval = dataOut.ippSeconds*self.n |
|
543 | timeInterval = dataOut.ippSeconds*self.n | |
544 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
544 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
545 | self.__dataReady = True |
|
545 | self.__dataReady = True | |
546 | return avgdata, avgdatatime |
|
546 | return avgdata, avgdatatime | |
547 |
|
547 | |||
548 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
548 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
549 | if not self.isConfig: |
|
549 | if not self.isConfig: | |
550 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
550 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
551 | self.isConfig = True |
|
551 | self.isConfig = True | |
552 |
|
552 | |||
553 | if dataOut.flagDataAsBlock: |
|
553 | if dataOut.flagDataAsBlock: | |
554 | """ |
|
554 | """ | |
555 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
555 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
556 | """ |
|
556 | """ | |
557 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
557 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
558 | dataOut.nProfiles /= self.n |
|
558 | dataOut.nProfiles /= self.n | |
559 | else: |
|
559 | else: | |
560 | if stride is None: |
|
560 | if stride is None: | |
561 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
561 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
562 | else: |
|
562 | else: | |
563 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
563 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
564 |
|
564 | |||
565 |
|
565 | |||
566 | # dataOut.timeInterval *= n |
|
566 | # dataOut.timeInterval *= n | |
567 | dataOut.flagNoData = True |
|
567 | dataOut.flagNoData = True | |
568 |
|
568 | |||
569 | if self.__dataReady: |
|
569 | if self.__dataReady: | |
570 | dataOut.data = avgdata |
|
570 | dataOut.data = avgdata | |
571 | dataOut.nCohInt *= self.n |
|
571 | dataOut.nCohInt *= self.n | |
572 | dataOut.utctime = avgdatatime |
|
572 | dataOut.utctime = avgdatatime | |
573 | # print avgdata, avgdatatime |
|
573 | # print avgdata, avgdatatime | |
574 | # raise |
|
574 | # raise | |
575 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
575 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
576 | dataOut.flagNoData = False |
|
576 | dataOut.flagNoData = False | |
577 |
|
577 | |||
578 | class Decoder(Operation): |
|
578 | class Decoder(Operation): | |
579 |
|
579 | |||
580 | isConfig = False |
|
580 | isConfig = False | |
581 | __profIndex = 0 |
|
581 | __profIndex = 0 | |
582 |
|
582 | |||
583 | code = None |
|
583 | code = None | |
584 |
|
584 | |||
585 | nCode = None |
|
585 | nCode = None | |
586 | nBaud = None |
|
586 | nBaud = None | |
587 |
|
587 | |||
588 | def __init__(self, **kwargs): |
|
588 | def __init__(self, **kwargs): | |
589 |
|
589 | |||
590 | Operation.__init__(self, **kwargs) |
|
590 | Operation.__init__(self, **kwargs) | |
591 |
|
591 | |||
592 | self.times = None |
|
592 | self.times = None | |
593 | self.osamp = None |
|
593 | self.osamp = None | |
594 | # self.__setValues = False |
|
594 | # self.__setValues = False | |
595 | self.isConfig = False |
|
595 | self.isConfig = False | |
596 |
|
596 | |||
597 | def setup(self, code, osamp, dataOut): |
|
597 | def setup(self, code, osamp, dataOut): | |
598 |
|
598 | |||
599 | self.__profIndex = 0 |
|
599 | self.__profIndex = 0 | |
600 |
|
600 | |||
601 | self.code = code |
|
601 | self.code = code | |
602 |
|
602 | |||
603 | self.nCode = len(code) |
|
603 | self.nCode = len(code) | |
604 | self.nBaud = len(code[0]) |
|
604 | self.nBaud = len(code[0]) | |
605 |
|
605 | |||
606 | if (osamp != None) and (osamp >1): |
|
606 | if (osamp != None) and (osamp >1): | |
607 | self.osamp = osamp |
|
607 | self.osamp = osamp | |
608 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
608 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
609 | self.nBaud = self.nBaud*self.osamp |
|
609 | self.nBaud = self.nBaud*self.osamp | |
610 |
|
610 | |||
611 | self.__nChannels = dataOut.nChannels |
|
611 | self.__nChannels = dataOut.nChannels | |
612 | self.__nProfiles = dataOut.nProfiles |
|
612 | self.__nProfiles = dataOut.nProfiles | |
613 | self.__nHeis = dataOut.nHeights |
|
613 | self.__nHeis = dataOut.nHeights | |
614 |
|
614 | |||
615 | if self.__nHeis < self.nBaud: |
|
615 | if self.__nHeis < self.nBaud: | |
616 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) |
|
616 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) | |
617 |
|
617 | |||
618 | #Frequency |
|
618 | #Frequency | |
619 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
619 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
620 |
|
620 | |||
621 | __codeBuffer[:,0:self.nBaud] = self.code |
|
621 | __codeBuffer[:,0:self.nBaud] = self.code | |
622 |
|
622 | |||
623 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
623 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
624 |
|
624 | |||
625 | if dataOut.flagDataAsBlock: |
|
625 | if dataOut.flagDataAsBlock: | |
626 |
|
626 | |||
627 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
627 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
628 |
|
628 | |||
629 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
629 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
630 |
|
630 | |||
631 | else: |
|
631 | else: | |
632 |
|
632 | |||
633 | #Time |
|
633 | #Time | |
634 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
634 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
635 |
|
635 | |||
636 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
636 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
637 |
|
637 | |||
638 | def __convolutionInFreq(self, data): |
|
638 | def __convolutionInFreq(self, data): | |
639 |
|
639 | |||
640 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
640 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
641 |
|
641 | |||
642 | fft_data = numpy.fft.fft(data, axis=1) |
|
642 | fft_data = numpy.fft.fft(data, axis=1) | |
643 |
|
643 | |||
644 | conv = fft_data*fft_code |
|
644 | conv = fft_data*fft_code | |
645 |
|
645 | |||
646 | data = numpy.fft.ifft(conv,axis=1) |
|
646 | data = numpy.fft.ifft(conv,axis=1) | |
647 |
|
647 | |||
648 | return data |
|
648 | return data | |
649 |
|
649 | |||
650 | def __convolutionInFreqOpt(self, data): |
|
650 | def __convolutionInFreqOpt(self, data): | |
651 |
|
651 | |||
652 | raise NotImplementedError |
|
652 | raise NotImplementedError | |
653 |
|
653 | |||
654 | def __convolutionInTime(self, data): |
|
654 | def __convolutionInTime(self, data): | |
655 |
|
655 | |||
656 | code = self.code[self.__profIndex] |
|
656 | code = self.code[self.__profIndex] | |
657 | for i in range(self.__nChannels): |
|
657 | for i in range(self.__nChannels): | |
658 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
658 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
659 |
|
659 | |||
660 | return self.datadecTime |
|
660 | return self.datadecTime | |
661 |
|
661 | |||
662 | def __convolutionByBlockInTime(self, data): |
|
662 | def __convolutionByBlockInTime(self, data): | |
663 |
|
663 | |||
664 | repetitions = self.__nProfiles / self.nCode |
|
664 | repetitions = self.__nProfiles / self.nCode | |
665 |
|
665 | |||
666 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
666 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
667 | junk = junk.flatten() |
|
667 | junk = junk.flatten() | |
668 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
668 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
669 | profilesList = xrange(self.__nProfiles) |
|
669 | profilesList = xrange(self.__nProfiles) | |
670 |
|
670 | |||
671 | for i in range(self.__nChannels): |
|
671 | for i in range(self.__nChannels): | |
672 | for j in profilesList: |
|
672 | for j in profilesList: | |
673 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
673 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
674 | return self.datadecTime |
|
674 | return self.datadecTime | |
675 |
|
675 | |||
676 | def __convolutionByBlockInFreq(self, data): |
|
676 | def __convolutionByBlockInFreq(self, data): | |
677 |
|
677 | |||
678 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" |
|
678 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" | |
679 |
|
679 | |||
680 |
|
680 | |||
681 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
681 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
682 |
|
682 | |||
683 | fft_data = numpy.fft.fft(data, axis=2) |
|
683 | fft_data = numpy.fft.fft(data, axis=2) | |
684 |
|
684 | |||
685 | conv = fft_data*fft_code |
|
685 | conv = fft_data*fft_code | |
686 |
|
686 | |||
687 | data = numpy.fft.ifft(conv,axis=2) |
|
687 | data = numpy.fft.ifft(conv,axis=2) | |
688 |
|
688 | |||
689 | return data |
|
689 | return data | |
690 |
|
690 | |||
691 |
|
691 | |||
692 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
692 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
693 |
|
693 | |||
694 | if dataOut.flagDecodeData: |
|
694 | if dataOut.flagDecodeData: | |
695 | print "This data is already decoded, recoding again ..." |
|
695 | print "This data is already decoded, recoding again ..." | |
696 |
|
696 | |||
697 | if not self.isConfig: |
|
697 | if not self.isConfig: | |
698 |
|
698 | |||
699 | if code is None: |
|
699 | if code is None: | |
700 | if dataOut.code is None: |
|
700 | if dataOut.code is None: | |
701 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type |
|
701 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type | |
702 |
|
702 | |||
703 | code = dataOut.code |
|
703 | code = dataOut.code | |
704 | else: |
|
704 | else: | |
705 | code = numpy.array(code).reshape(nCode,nBaud) |
|
705 | code = numpy.array(code).reshape(nCode,nBaud) | |
706 | self.setup(code, osamp, dataOut) |
|
706 | self.setup(code, osamp, dataOut) | |
707 |
|
707 | |||
708 | self.isConfig = True |
|
708 | self.isConfig = True | |
709 |
|
709 | |||
710 | if mode == 3: |
|
710 | if mode == 3: | |
711 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
711 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
712 |
|
712 | |||
713 | if times != None: |
|
713 | if times != None: | |
714 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
714 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
715 |
|
715 | |||
716 | if self.code is None: |
|
716 | if self.code is None: | |
717 | print "Fail decoding: Code is not defined." |
|
717 | print "Fail decoding: Code is not defined." | |
718 | return |
|
718 | return | |
719 |
|
719 | |||
720 | self.__nProfiles = dataOut.nProfiles |
|
720 | self.__nProfiles = dataOut.nProfiles | |
721 | datadec = None |
|
721 | datadec = None | |
722 |
|
722 | |||
723 | if mode == 3: |
|
723 | if mode == 3: | |
724 | mode = 0 |
|
724 | mode = 0 | |
725 |
|
725 | |||
726 | if dataOut.flagDataAsBlock: |
|
726 | if dataOut.flagDataAsBlock: | |
727 | """ |
|
727 | """ | |
728 | Decoding when data have been read as block, |
|
728 | Decoding when data have been read as block, | |
729 | """ |
|
729 | """ | |
730 |
|
730 | |||
731 | if mode == 0: |
|
731 | if mode == 0: | |
732 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
732 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
733 | if mode == 1: |
|
733 | if mode == 1: | |
734 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
734 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
735 | else: |
|
735 | else: | |
736 | """ |
|
736 | """ | |
737 | Decoding when data have been read profile by profile |
|
737 | Decoding when data have been read profile by profile | |
738 | """ |
|
738 | """ | |
739 | if mode == 0: |
|
739 | if mode == 0: | |
740 | datadec = self.__convolutionInTime(dataOut.data) |
|
740 | datadec = self.__convolutionInTime(dataOut.data) | |
741 |
|
741 | |||
742 | if mode == 1: |
|
742 | if mode == 1: | |
743 | datadec = self.__convolutionInFreq(dataOut.data) |
|
743 | datadec = self.__convolutionInFreq(dataOut.data) | |
744 |
|
744 | |||
745 | if mode == 2: |
|
745 | if mode == 2: | |
746 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
746 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
747 |
|
747 | |||
748 | if datadec is None: |
|
748 | if datadec is None: | |
749 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode |
|
749 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode | |
750 |
|
750 | |||
751 | dataOut.code = self.code |
|
751 | dataOut.code = self.code | |
752 | dataOut.nCode = self.nCode |
|
752 | dataOut.nCode = self.nCode | |
753 | dataOut.nBaud = self.nBaud |
|
753 | dataOut.nBaud = self.nBaud | |
754 |
|
754 | |||
755 | dataOut.data = datadec |
|
755 | dataOut.data = datadec | |
756 |
|
756 | |||
757 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
757 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
758 |
|
758 | |||
759 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
759 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
760 |
|
760 | |||
761 | if self.__profIndex == self.nCode-1: |
|
761 | if self.__profIndex == self.nCode-1: | |
762 | self.__profIndex = 0 |
|
762 | self.__profIndex = 0 | |
763 | return 1 |
|
763 | return 1 | |
764 |
|
764 | |||
765 | self.__profIndex += 1 |
|
765 | self.__profIndex += 1 | |
766 |
|
766 | |||
767 | return 1 |
|
767 | return 1 | |
768 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
768 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
769 |
|
769 | |||
770 |
|
770 | |||
771 | class ProfileConcat(Operation): |
|
771 | class ProfileConcat(Operation): | |
772 |
|
772 | |||
773 | isConfig = False |
|
773 | isConfig = False | |
774 | buffer = None |
|
774 | buffer = None | |
775 |
|
775 | |||
776 | def __init__(self, **kwargs): |
|
776 | def __init__(self, **kwargs): | |
777 |
|
777 | |||
778 | Operation.__init__(self, **kwargs) |
|
778 | Operation.__init__(self, **kwargs) | |
779 | self.profileIndex = 0 |
|
779 | self.profileIndex = 0 | |
780 |
|
780 | |||
781 | def reset(self): |
|
781 | def reset(self): | |
782 | self.buffer = numpy.zeros_like(self.buffer) |
|
782 | self.buffer = numpy.zeros_like(self.buffer) | |
783 | self.start_index = 0 |
|
783 | self.start_index = 0 | |
784 | self.times = 1 |
|
784 | self.times = 1 | |
785 |
|
785 | |||
786 | def setup(self, data, m, n=1): |
|
786 | def setup(self, data, m, n=1): | |
787 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
787 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
788 | self.nHeights = data.shape[1]#.nHeights |
|
788 | self.nHeights = data.shape[1]#.nHeights | |
789 | self.start_index = 0 |
|
789 | self.start_index = 0 | |
790 | self.times = 1 |
|
790 | self.times = 1 | |
791 |
|
791 | |||
792 | def concat(self, data): |
|
792 | def concat(self, data): | |
793 |
|
793 | |||
794 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
794 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
795 | self.start_index = self.start_index + self.nHeights |
|
795 | self.start_index = self.start_index + self.nHeights | |
796 |
|
796 | |||
797 | def run(self, dataOut, m): |
|
797 | def run(self, dataOut, m): | |
798 |
|
798 | |||
799 | dataOut.flagNoData = True |
|
799 | dataOut.flagNoData = True | |
800 |
|
800 | |||
801 | if not self.isConfig: |
|
801 | if not self.isConfig: | |
802 | self.setup(dataOut.data, m, 1) |
|
802 | self.setup(dataOut.data, m, 1) | |
803 | self.isConfig = True |
|
803 | self.isConfig = True | |
804 |
|
804 | |||
805 | if dataOut.flagDataAsBlock: |
|
805 | if dataOut.flagDataAsBlock: | |
806 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" |
|
806 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" | |
807 |
|
807 | |||
808 | else: |
|
808 | else: | |
809 | self.concat(dataOut.data) |
|
809 | self.concat(dataOut.data) | |
810 | self.times += 1 |
|
810 | self.times += 1 | |
811 | if self.times > m: |
|
811 | if self.times > m: | |
812 | dataOut.data = self.buffer |
|
812 | dataOut.data = self.buffer | |
813 | self.reset() |
|
813 | self.reset() | |
814 | dataOut.flagNoData = False |
|
814 | dataOut.flagNoData = False | |
815 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
815 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
816 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
816 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
817 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
817 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
818 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
818 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
819 | dataOut.ippSeconds *= m |
|
819 | dataOut.ippSeconds *= m | |
820 |
|
820 | |||
821 | class ProfileSelector(Operation): |
|
821 | class ProfileSelector(Operation): | |
822 |
|
822 | |||
823 | profileIndex = None |
|
823 | profileIndex = None | |
824 | # Tamanho total de los perfiles |
|
824 | # Tamanho total de los perfiles | |
825 | nProfiles = None |
|
825 | nProfiles = None | |
826 |
|
826 | |||
827 | def __init__(self, **kwargs): |
|
827 | def __init__(self, **kwargs): | |
828 |
|
828 | |||
829 | Operation.__init__(self, **kwargs) |
|
829 | Operation.__init__(self, **kwargs) | |
830 | self.profileIndex = 0 |
|
830 | self.profileIndex = 0 | |
831 |
|
831 | |||
832 | def incProfileIndex(self): |
|
832 | def incProfileIndex(self): | |
833 |
|
833 | |||
834 | self.profileIndex += 1 |
|
834 | self.profileIndex += 1 | |
835 |
|
835 | |||
836 | if self.profileIndex >= self.nProfiles: |
|
836 | if self.profileIndex >= self.nProfiles: | |
837 | self.profileIndex = 0 |
|
837 | self.profileIndex = 0 | |
838 |
|
838 | |||
839 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
839 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
840 |
|
840 | |||
841 | if profileIndex < minIndex: |
|
841 | if profileIndex < minIndex: | |
842 | return False |
|
842 | return False | |
843 |
|
843 | |||
844 | if profileIndex > maxIndex: |
|
844 | if profileIndex > maxIndex: | |
845 | return False |
|
845 | return False | |
846 |
|
846 | |||
847 | return True |
|
847 | return True | |
848 |
|
848 | |||
849 | def isThisProfileInList(self, profileIndex, profileList): |
|
849 | def isThisProfileInList(self, profileIndex, profileList): | |
850 |
|
850 | |||
851 | if profileIndex not in profileList: |
|
851 | if profileIndex not in profileList: | |
852 | return False |
|
852 | return False | |
853 |
|
853 | |||
854 | return True |
|
854 | return True | |
855 |
|
855 | |||
856 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
856 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
857 |
|
857 | |||
858 | """ |
|
858 | """ | |
859 | ProfileSelector: |
|
859 | ProfileSelector: | |
860 |
|
860 | |||
861 | Inputs: |
|
861 | Inputs: | |
862 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
862 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
863 |
|
863 | |||
864 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
864 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
865 |
|
865 | |||
866 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
866 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
867 |
|
867 | |||
868 | """ |
|
868 | """ | |
869 |
|
869 | |||
870 | if rangeList is not None: |
|
870 | if rangeList is not None: | |
871 | if type(rangeList[0]) not in (tuple, list): |
|
871 | if type(rangeList[0]) not in (tuple, list): | |
872 | rangeList = [rangeList] |
|
872 | rangeList = [rangeList] | |
873 |
|
873 | |||
874 | dataOut.flagNoData = True |
|
874 | dataOut.flagNoData = True | |
875 |
|
875 | |||
876 | if dataOut.flagDataAsBlock: |
|
876 | if dataOut.flagDataAsBlock: | |
877 | """ |
|
877 | """ | |
878 | data dimension = [nChannels, nProfiles, nHeis] |
|
878 | data dimension = [nChannels, nProfiles, nHeis] | |
879 | """ |
|
879 | """ | |
880 | if profileList != None: |
|
880 | if profileList != None: | |
881 | dataOut.data = dataOut.data[:,profileList,:] |
|
881 | dataOut.data = dataOut.data[:,profileList,:] | |
882 |
|
882 | |||
883 | if profileRangeList != None: |
|
883 | if profileRangeList != None: | |
884 | minIndex = profileRangeList[0] |
|
884 | minIndex = profileRangeList[0] | |
885 | maxIndex = profileRangeList[1] |
|
885 | maxIndex = profileRangeList[1] | |
886 | profileList = range(minIndex, maxIndex+1) |
|
886 | profileList = range(minIndex, maxIndex+1) | |
887 |
|
887 | |||
888 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
888 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
889 |
|
889 | |||
890 | if rangeList != None: |
|
890 | if rangeList != None: | |
891 |
|
891 | |||
892 | profileList = [] |
|
892 | profileList = [] | |
893 |
|
893 | |||
894 | for thisRange in rangeList: |
|
894 | for thisRange in rangeList: | |
895 | minIndex = thisRange[0] |
|
895 | minIndex = thisRange[0] | |
896 | maxIndex = thisRange[1] |
|
896 | maxIndex = thisRange[1] | |
897 |
|
897 | |||
898 | profileList.extend(range(minIndex, maxIndex+1)) |
|
898 | profileList.extend(range(minIndex, maxIndex+1)) | |
899 |
|
899 | |||
900 | dataOut.data = dataOut.data[:,profileList,:] |
|
900 | dataOut.data = dataOut.data[:,profileList,:] | |
901 |
|
901 | |||
902 | dataOut.nProfiles = len(profileList) |
|
902 | dataOut.nProfiles = len(profileList) | |
903 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
903 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
904 | dataOut.flagNoData = False |
|
904 | dataOut.flagNoData = False | |
905 |
|
905 | |||
906 | return True |
|
906 | return True | |
907 |
|
907 | |||
908 | """ |
|
908 | """ | |
909 | data dimension = [nChannels, nHeis] |
|
909 | data dimension = [nChannels, nHeis] | |
910 | """ |
|
910 | """ | |
911 |
|
911 | |||
912 | if profileList != None: |
|
912 | if profileList != None: | |
913 |
|
913 | |||
914 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
914 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
915 |
|
915 | |||
916 | self.nProfiles = len(profileList) |
|
916 | self.nProfiles = len(profileList) | |
917 | dataOut.nProfiles = self.nProfiles |
|
917 | dataOut.nProfiles = self.nProfiles | |
918 | dataOut.profileIndex = self.profileIndex |
|
918 | dataOut.profileIndex = self.profileIndex | |
919 | dataOut.flagNoData = False |
|
919 | dataOut.flagNoData = False | |
920 |
|
920 | |||
921 | self.incProfileIndex() |
|
921 | self.incProfileIndex() | |
922 | return True |
|
922 | return True | |
923 |
|
923 | |||
924 | if profileRangeList != None: |
|
924 | if profileRangeList != None: | |
925 |
|
925 | |||
926 | minIndex = profileRangeList[0] |
|
926 | minIndex = profileRangeList[0] | |
927 | maxIndex = profileRangeList[1] |
|
927 | maxIndex = profileRangeList[1] | |
928 |
|
928 | |||
929 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
929 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
930 |
|
930 | |||
931 | self.nProfiles = maxIndex - minIndex + 1 |
|
931 | self.nProfiles = maxIndex - minIndex + 1 | |
932 | dataOut.nProfiles = self.nProfiles |
|
932 | dataOut.nProfiles = self.nProfiles | |
933 | dataOut.profileIndex = self.profileIndex |
|
933 | dataOut.profileIndex = self.profileIndex | |
934 | dataOut.flagNoData = False |
|
934 | dataOut.flagNoData = False | |
935 |
|
935 | |||
936 | self.incProfileIndex() |
|
936 | self.incProfileIndex() | |
937 | return True |
|
937 | return True | |
938 |
|
938 | |||
939 | if rangeList != None: |
|
939 | if rangeList != None: | |
940 |
|
940 | |||
941 | nProfiles = 0 |
|
941 | nProfiles = 0 | |
942 |
|
942 | |||
943 | for thisRange in rangeList: |
|
943 | for thisRange in rangeList: | |
944 | minIndex = thisRange[0] |
|
944 | minIndex = thisRange[0] | |
945 | maxIndex = thisRange[1] |
|
945 | maxIndex = thisRange[1] | |
946 |
|
946 | |||
947 | nProfiles += maxIndex - minIndex + 1 |
|
947 | nProfiles += maxIndex - minIndex + 1 | |
948 |
|
948 | |||
949 | for thisRange in rangeList: |
|
949 | for thisRange in rangeList: | |
950 |
|
950 | |||
951 | minIndex = thisRange[0] |
|
951 | minIndex = thisRange[0] | |
952 | maxIndex = thisRange[1] |
|
952 | maxIndex = thisRange[1] | |
953 |
|
953 | |||
954 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
954 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
955 |
|
955 | |||
956 | self.nProfiles = nProfiles |
|
956 | self.nProfiles = nProfiles | |
957 | dataOut.nProfiles = self.nProfiles |
|
957 | dataOut.nProfiles = self.nProfiles | |
958 | dataOut.profileIndex = self.profileIndex |
|
958 | dataOut.profileIndex = self.profileIndex | |
959 | dataOut.flagNoData = False |
|
959 | dataOut.flagNoData = False | |
960 |
|
960 | |||
961 | self.incProfileIndex() |
|
961 | self.incProfileIndex() | |
962 |
|
962 | |||
963 | break |
|
963 | break | |
964 |
|
964 | |||
965 | return True |
|
965 | return True | |
966 |
|
966 | |||
967 |
|
967 | |||
968 | if beam != None: #beam is only for AMISR data |
|
968 | if beam != None: #beam is only for AMISR data | |
969 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
969 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
970 | dataOut.flagNoData = False |
|
970 | dataOut.flagNoData = False | |
971 | dataOut.profileIndex = self.profileIndex |
|
971 | dataOut.profileIndex = self.profileIndex | |
972 |
|
972 | |||
973 | self.incProfileIndex() |
|
973 | self.incProfileIndex() | |
974 |
|
974 | |||
975 | return True |
|
975 | return True | |
976 |
|
976 | |||
977 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" |
|
977 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" | |
978 |
|
978 | |||
979 | return False |
|
979 | return False | |
980 |
|
980 | |||
981 | class Reshaper(Operation): |
|
981 | class Reshaper(Operation): | |
982 |
|
982 | |||
983 | def __init__(self, **kwargs): |
|
983 | def __init__(self, **kwargs): | |
984 |
|
984 | |||
985 | Operation.__init__(self, **kwargs) |
|
985 | Operation.__init__(self, **kwargs) | |
986 |
|
986 | |||
987 | self.__buffer = None |
|
987 | self.__buffer = None | |
988 | self.__nitems = 0 |
|
988 | self.__nitems = 0 | |
989 |
|
989 | |||
990 | def __appendProfile(self, dataOut, nTxs): |
|
990 | def __appendProfile(self, dataOut, nTxs): | |
991 |
|
991 | |||
992 | if self.__buffer is None: |
|
992 | if self.__buffer is None: | |
993 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
993 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
994 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
994 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
995 |
|
995 | |||
996 | ini = dataOut.nHeights * self.__nitems |
|
996 | ini = dataOut.nHeights * self.__nitems | |
997 | end = ini + dataOut.nHeights |
|
997 | end = ini + dataOut.nHeights | |
998 |
|
998 | |||
999 | self.__buffer[:, ini:end] = dataOut.data |
|
999 | self.__buffer[:, ini:end] = dataOut.data | |
1000 |
|
1000 | |||
1001 | self.__nitems += 1 |
|
1001 | self.__nitems += 1 | |
1002 |
|
1002 | |||
1003 | return int(self.__nitems*nTxs) |
|
1003 | return int(self.__nitems*nTxs) | |
1004 |
|
1004 | |||
1005 | def __getBuffer(self): |
|
1005 | def __getBuffer(self): | |
1006 |
|
1006 | |||
1007 | if self.__nitems == int(1./self.__nTxs): |
|
1007 | if self.__nitems == int(1./self.__nTxs): | |
1008 |
|
1008 | |||
1009 | self.__nitems = 0 |
|
1009 | self.__nitems = 0 | |
1010 |
|
1010 | |||
1011 | return self.__buffer.copy() |
|
1011 | return self.__buffer.copy() | |
1012 |
|
1012 | |||
1013 | return None |
|
1013 | return None | |
1014 |
|
1014 | |||
1015 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1015 | def __checkInputs(self, dataOut, shape, nTxs): | |
1016 |
|
1016 | |||
1017 | if shape is None and nTxs is None: |
|
1017 | if shape is None and nTxs is None: | |
1018 | raise ValueError, "Reshaper: shape of factor should be defined" |
|
1018 | raise ValueError, "Reshaper: shape of factor should be defined" | |
1019 |
|
1019 | |||
1020 | if nTxs: |
|
1020 | if nTxs: | |
1021 | if nTxs < 0: |
|
1021 | if nTxs < 0: | |
1022 | raise ValueError, "nTxs should be greater than 0" |
|
1022 | raise ValueError, "nTxs should be greater than 0" | |
1023 |
|
1023 | |||
1024 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1024 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1025 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) |
|
1025 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) | |
1026 |
|
1026 | |||
1027 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1027 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1028 |
|
1028 | |||
1029 | return shape, nTxs |
|
1029 | return shape, nTxs | |
1030 |
|
1030 | |||
1031 | if len(shape) != 2 and len(shape) != 3: |
|
1031 | if len(shape) != 2 and len(shape) != 3: | |
1032 | raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights) |
|
1032 | raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights) | |
1033 |
|
1033 | |||
1034 | if len(shape) == 2: |
|
1034 | if len(shape) == 2: | |
1035 | shape_tuple = [dataOut.nChannels] |
|
1035 | shape_tuple = [dataOut.nChannels] | |
1036 | shape_tuple.extend(shape) |
|
1036 | shape_tuple.extend(shape) | |
1037 | else: |
|
1037 | else: | |
1038 | shape_tuple = list(shape) |
|
1038 | shape_tuple = list(shape) | |
1039 |
|
1039 | |||
1040 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1040 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1041 |
|
1041 | |||
1042 | return shape_tuple, nTxs |
|
1042 | return shape_tuple, nTxs | |
1043 |
|
1043 | |||
1044 | def run(self, dataOut, shape=None, nTxs=None): |
|
1044 | def run(self, dataOut, shape=None, nTxs=None): | |
1045 |
|
1045 | |||
1046 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1046 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1047 |
|
1047 | |||
1048 | dataOut.flagNoData = True |
|
1048 | dataOut.flagNoData = True | |
1049 | profileIndex = None |
|
1049 | profileIndex = None | |
1050 |
|
1050 | |||
1051 | if dataOut.flagDataAsBlock: |
|
1051 | if dataOut.flagDataAsBlock: | |
1052 |
|
1052 | |||
1053 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1053 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1054 | dataOut.flagNoData = False |
|
1054 | dataOut.flagNoData = False | |
1055 |
|
1055 | |||
1056 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1056 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1057 |
|
1057 | |||
1058 | else: |
|
1058 | else: | |
1059 |
|
1059 | |||
1060 | if self.__nTxs < 1: |
|
1060 | if self.__nTxs < 1: | |
1061 |
|
1061 | |||
1062 | self.__appendProfile(dataOut, self.__nTxs) |
|
1062 | self.__appendProfile(dataOut, self.__nTxs) | |
1063 | new_data = self.__getBuffer() |
|
1063 | new_data = self.__getBuffer() | |
1064 |
|
1064 | |||
1065 | if new_data is not None: |
|
1065 | if new_data is not None: | |
1066 | dataOut.data = new_data |
|
1066 | dataOut.data = new_data | |
1067 | dataOut.flagNoData = False |
|
1067 | dataOut.flagNoData = False | |
1068 |
|
1068 | |||
1069 | profileIndex = dataOut.profileIndex*nTxs |
|
1069 | profileIndex = dataOut.profileIndex*nTxs | |
1070 |
|
1070 | |||
1071 | else: |
|
1071 | else: | |
1072 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" |
|
1072 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" | |
1073 |
|
1073 | |||
1074 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1074 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1075 |
|
1075 | |||
1076 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1076 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1077 |
|
1077 | |||
1078 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1078 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1079 |
|
1079 | |||
1080 | dataOut.profileIndex = profileIndex |
|
1080 | dataOut.profileIndex = profileIndex | |
1081 |
|
1081 | |||
1082 | dataOut.ippSeconds /= self.__nTxs |
|
1082 | dataOut.ippSeconds /= self.__nTxs | |
1083 |
|
1083 | |||
1084 | class SplitProfiles(Operation): |
|
1084 | class SplitProfiles(Operation): | |
1085 |
|
1085 | |||
1086 | def __init__(self, **kwargs): |
|
1086 | def __init__(self, **kwargs): | |
1087 |
|
1087 | |||
1088 | Operation.__init__(self, **kwargs) |
|
1088 | Operation.__init__(self, **kwargs) | |
1089 |
|
1089 | |||
1090 | def run(self, dataOut, n): |
|
1090 | def run(self, dataOut, n): | |
1091 |
|
1091 | |||
1092 | dataOut.flagNoData = True |
|
1092 | dataOut.flagNoData = True | |
1093 | profileIndex = None |
|
1093 | profileIndex = None | |
1094 |
|
1094 | |||
1095 | if dataOut.flagDataAsBlock: |
|
1095 | if dataOut.flagDataAsBlock: | |
1096 |
|
1096 | |||
1097 | #nchannels, nprofiles, nsamples |
|
1097 | #nchannels, nprofiles, nsamples | |
1098 | shape = dataOut.data.shape |
|
1098 | shape = dataOut.data.shape | |
1099 |
|
1099 | |||
1100 | if shape[2] % n != 0: |
|
1100 | if shape[2] % n != 0: | |
1101 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) |
|
1101 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) | |
1102 |
|
1102 | |||
1103 | new_shape = shape[0], shape[1]*n, shape[2]/n |
|
1103 | new_shape = shape[0], shape[1]*n, shape[2]/n | |
1104 |
|
1104 | |||
1105 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1105 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1106 | dataOut.flagNoData = False |
|
1106 | dataOut.flagNoData = False | |
1107 |
|
1107 | |||
1108 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1108 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1109 |
|
1109 | |||
1110 | else: |
|
1110 | else: | |
1111 |
|
1111 | |||
1112 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" |
|
1112 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" | |
1113 |
|
1113 | |||
1114 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1114 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1115 |
|
1115 | |||
1116 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1116 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1117 |
|
1117 | |||
1118 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1118 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1119 |
|
1119 | |||
1120 | dataOut.profileIndex = profileIndex |
|
1120 | dataOut.profileIndex = profileIndex | |
1121 |
|
1121 | |||
1122 | dataOut.ippSeconds /= n |
|
1122 | dataOut.ippSeconds /= n | |
1123 |
|
1123 | |||
1124 | class CombineProfiles(Operation): |
|
1124 | class CombineProfiles(Operation): | |
1125 | def __init__(self, **kwargs): |
|
1125 | def __init__(self, **kwargs): | |
1126 |
|
1126 | |||
1127 | Operation.__init__(self, **kwargs) |
|
1127 | Operation.__init__(self, **kwargs) | |
1128 |
|
1128 | |||
1129 | self.__remData = None |
|
1129 | self.__remData = None | |
1130 | self.__profileIndex = 0 |
|
1130 | self.__profileIndex = 0 | |
1131 |
|
1131 | |||
1132 | def run(self, dataOut, n): |
|
1132 | def run(self, dataOut, n): | |
1133 |
|
1133 | |||
1134 | dataOut.flagNoData = True |
|
1134 | dataOut.flagNoData = True | |
1135 | profileIndex = None |
|
1135 | profileIndex = None | |
1136 |
|
1136 | |||
1137 | if dataOut.flagDataAsBlock: |
|
1137 | if dataOut.flagDataAsBlock: | |
1138 |
|
1138 | |||
1139 | #nchannels, nprofiles, nsamples |
|
1139 | #nchannels, nprofiles, nsamples | |
1140 | shape = dataOut.data.shape |
|
1140 | shape = dataOut.data.shape | |
1141 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1141 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1142 |
|
1142 | |||
1143 | if shape[1] % n != 0: |
|
1143 | if shape[1] % n != 0: | |
1144 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) |
|
1144 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) | |
1145 |
|
1145 | |||
1146 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1146 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1147 | dataOut.flagNoData = False |
|
1147 | dataOut.flagNoData = False | |
1148 |
|
1148 | |||
1149 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1149 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1150 |
|
1150 | |||
1151 | else: |
|
1151 | else: | |
1152 |
|
1152 | |||
1153 | #nchannels, nsamples |
|
1153 | #nchannels, nsamples | |
1154 | if self.__remData is None: |
|
1154 | if self.__remData is None: | |
1155 | newData = dataOut.data |
|
1155 | newData = dataOut.data | |
1156 | else: |
|
1156 | else: | |
1157 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1157 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1158 |
|
1158 | |||
1159 | self.__profileIndex += 1 |
|
1159 | self.__profileIndex += 1 | |
1160 |
|
1160 | |||
1161 | if self.__profileIndex < n: |
|
1161 | if self.__profileIndex < n: | |
1162 | self.__remData = newData |
|
1162 | self.__remData = newData | |
1163 | #continue |
|
1163 | #continue | |
1164 | return |
|
1164 | return | |
1165 |
|
1165 | |||
1166 | self.__profileIndex = 0 |
|
1166 | self.__profileIndex = 0 | |
1167 | self.__remData = None |
|
1167 | self.__remData = None | |
1168 |
|
1168 | |||
1169 | dataOut.data = newData |
|
1169 | dataOut.data = newData | |
1170 | dataOut.flagNoData = False |
|
1170 | dataOut.flagNoData = False | |
1171 |
|
1171 | |||
1172 | profileIndex = dataOut.profileIndex/n |
|
1172 | profileIndex = dataOut.profileIndex/n | |
1173 |
|
1173 | |||
1174 |
|
1174 | |||
1175 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1175 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1176 |
|
1176 | |||
1177 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1177 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1178 |
|
1178 | |||
1179 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1179 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1180 |
|
1180 | |||
1181 | dataOut.profileIndex = profileIndex |
|
1181 | dataOut.profileIndex = profileIndex | |
1182 |
|
1182 | |||
1183 | dataOut.ippSeconds *= n |
|
1183 | dataOut.ippSeconds *= n | |
1184 |
|
1184 | |||
1185 | # import collections |
|
1185 | # import collections | |
1186 | # from scipy.stats import mode |
|
1186 | # from scipy.stats import mode | |
1187 | # |
|
1187 | # | |
1188 | # class Synchronize(Operation): |
|
1188 | # class Synchronize(Operation): | |
1189 | # |
|
1189 | # | |
1190 | # isConfig = False |
|
1190 | # isConfig = False | |
1191 | # __profIndex = 0 |
|
1191 | # __profIndex = 0 | |
1192 | # |
|
1192 | # | |
1193 | # def __init__(self, **kwargs): |
|
1193 | # def __init__(self, **kwargs): | |
1194 | # |
|
1194 | # | |
1195 | # Operation.__init__(self, **kwargs) |
|
1195 | # Operation.__init__(self, **kwargs) | |
1196 | # # self.isConfig = False |
|
1196 | # # self.isConfig = False | |
1197 | # self.__powBuffer = None |
|
1197 | # self.__powBuffer = None | |
1198 | # self.__startIndex = 0 |
|
1198 | # self.__startIndex = 0 | |
1199 | # self.__pulseFound = False |
|
1199 | # self.__pulseFound = False | |
1200 | # |
|
1200 | # | |
1201 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1201 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1202 | # |
|
1202 | # | |
1203 | # #Read data |
|
1203 | # #Read data | |
1204 | # |
|
1204 | # | |
1205 | # powerdB = dataOut.getPower(channel = channel) |
|
1205 | # powerdB = dataOut.getPower(channel = channel) | |
1206 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1206 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1207 | # |
|
1207 | # | |
1208 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1208 | # self.__powBuffer.extend(powerdB.flatten()) | |
1209 | # |
|
1209 | # | |
1210 | # dataArray = numpy.array(self.__powBuffer) |
|
1210 | # dataArray = numpy.array(self.__powBuffer) | |
1211 | # |
|
1211 | # | |
1212 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1212 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1213 | # |
|
1213 | # | |
1214 | # maxValue = numpy.nanmax(filteredPower) |
|
1214 | # maxValue = numpy.nanmax(filteredPower) | |
1215 | # |
|
1215 | # | |
1216 | # if maxValue < noisedB + 10: |
|
1216 | # if maxValue < noisedB + 10: | |
1217 | # #No se encuentra ningun pulso de transmision |
|
1217 | # #No se encuentra ningun pulso de transmision | |
1218 | # return None |
|
1218 | # return None | |
1219 | # |
|
1219 | # | |
1220 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1220 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1221 | # |
|
1221 | # | |
1222 | # if len(maxValuesIndex) < 2: |
|
1222 | # if len(maxValuesIndex) < 2: | |
1223 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1223 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1224 | # return None |
|
1224 | # return None | |
1225 | # |
|
1225 | # | |
1226 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1226 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1227 | # |
|
1227 | # | |
1228 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1228 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1229 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1229 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1230 | # |
|
1230 | # | |
1231 | # if len(pulseIndex) < 2: |
|
1231 | # if len(pulseIndex) < 2: | |
1232 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1232 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1233 | # return None |
|
1233 | # return None | |
1234 | # |
|
1234 | # | |
1235 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1235 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1236 | # |
|
1236 | # | |
1237 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1237 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1238 | # #(No deberian existir IPP menor a 10 unidades) |
|
1238 | # #(No deberian existir IPP menor a 10 unidades) | |
1239 | # |
|
1239 | # | |
1240 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1240 | # realIndex = numpy.where(spacing > 10 )[0] | |
1241 | # |
|
1241 | # | |
1242 | # if len(realIndex) < 2: |
|
1242 | # if len(realIndex) < 2: | |
1243 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1243 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1244 | # return None |
|
1244 | # return None | |
1245 | # |
|
1245 | # | |
1246 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1246 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1247 | # realPulseIndex = pulseIndex[realIndex] |
|
1247 | # realPulseIndex = pulseIndex[realIndex] | |
1248 | # |
|
1248 | # | |
1249 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1249 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1250 | # |
|
1250 | # | |
1251 | # print "IPP = %d samples" %period |
|
1251 | # print "IPP = %d samples" %period | |
1252 | # |
|
1252 | # | |
1253 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1253 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1254 | # self.__startIndex = int(realPulseIndex[0]) |
|
1254 | # self.__startIndex = int(realPulseIndex[0]) | |
1255 | # |
|
1255 | # | |
1256 | # return 1 |
|
1256 | # return 1 | |
1257 | # |
|
1257 | # | |
1258 | # |
|
1258 | # | |
1259 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1259 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1260 | # |
|
1260 | # | |
1261 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1261 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1262 | # maxlen = buffer_size*nSamples) |
|
1262 | # maxlen = buffer_size*nSamples) | |
1263 | # |
|
1263 | # | |
1264 | # bufferList = [] |
|
1264 | # bufferList = [] | |
1265 | # |
|
1265 | # | |
1266 | # for i in range(nChannels): |
|
1266 | # for i in range(nChannels): | |
1267 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1267 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1268 | # maxlen = buffer_size*nSamples) |
|
1268 | # maxlen = buffer_size*nSamples) | |
1269 | # |
|
1269 | # | |
1270 | # bufferList.append(bufferByChannel) |
|
1270 | # bufferList.append(bufferByChannel) | |
1271 | # |
|
1271 | # | |
1272 | # self.__nSamples = nSamples |
|
1272 | # self.__nSamples = nSamples | |
1273 | # self.__nChannels = nChannels |
|
1273 | # self.__nChannels = nChannels | |
1274 | # self.__bufferList = bufferList |
|
1274 | # self.__bufferList = bufferList | |
1275 | # |
|
1275 | # | |
1276 | # def run(self, dataOut, channel = 0): |
|
1276 | # def run(self, dataOut, channel = 0): | |
1277 | # |
|
1277 | # | |
1278 | # if not self.isConfig: |
|
1278 | # if not self.isConfig: | |
1279 | # nSamples = dataOut.nHeights |
|
1279 | # nSamples = dataOut.nHeights | |
1280 | # nChannels = dataOut.nChannels |
|
1280 | # nChannels = dataOut.nChannels | |
1281 | # self.setup(nSamples, nChannels) |
|
1281 | # self.setup(nSamples, nChannels) | |
1282 | # self.isConfig = True |
|
1282 | # self.isConfig = True | |
1283 | # |
|
1283 | # | |
1284 | # #Append new data to internal buffer |
|
1284 | # #Append new data to internal buffer | |
1285 | # for thisChannel in range(self.__nChannels): |
|
1285 | # for thisChannel in range(self.__nChannels): | |
1286 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1286 | # bufferByChannel = self.__bufferList[thisChannel] | |
1287 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1287 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1288 | # |
|
1288 | # | |
1289 | # if self.__pulseFound: |
|
1289 | # if self.__pulseFound: | |
1290 | # self.__startIndex -= self.__nSamples |
|
1290 | # self.__startIndex -= self.__nSamples | |
1291 | # |
|
1291 | # | |
1292 | # #Finding Tx Pulse |
|
1292 | # #Finding Tx Pulse | |
1293 | # if not self.__pulseFound: |
|
1293 | # if not self.__pulseFound: | |
1294 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1294 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1295 | # |
|
1295 | # | |
1296 | # if indexFound == None: |
|
1296 | # if indexFound == None: | |
1297 | # dataOut.flagNoData = True |
|
1297 | # dataOut.flagNoData = True | |
1298 | # return |
|
1298 | # return | |
1299 | # |
|
1299 | # | |
1300 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1300 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1301 | # self.__pulseFound = True |
|
1301 | # self.__pulseFound = True | |
1302 | # self.__startIndex = indexFound |
|
1302 | # self.__startIndex = indexFound | |
1303 | # |
|
1303 | # | |
1304 | # #If pulse was found ... |
|
1304 | # #If pulse was found ... | |
1305 | # for thisChannel in range(self.__nChannels): |
|
1305 | # for thisChannel in range(self.__nChannels): | |
1306 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1306 | # bufferByChannel = self.__bufferList[thisChannel] | |
1307 | # #print self.__startIndex |
|
1307 | # #print self.__startIndex | |
1308 | # x = numpy.array(bufferByChannel) |
|
1308 | # x = numpy.array(bufferByChannel) | |
1309 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1309 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1310 | # |
|
1310 | # | |
1311 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1311 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1312 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1312 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1313 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1313 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1314 | # |
|
1314 | # | |
1315 | # dataOut.data = self.__arrayBuffer |
|
1315 | # dataOut.data = self.__arrayBuffer | |
1316 | # |
|
1316 | # | |
1317 | # self.__startIndex += self.__newNSamples |
|
1317 | # self.__startIndex += self.__newNSamples | |
1318 | # |
|
1318 | # | |
1319 | # return |
|
1319 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now