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