@@ -1,90 +1,90 | |||||
1 | basic = '''from schainpy.controller import Project |
|
1 | basic = '''from schainpy.controller import Project | |
2 |
|
2 | |||
3 | desc = "{desc}" |
|
3 | desc = "{desc}" | |
4 | project = Project() |
|
4 | project = Project() | |
5 | project.setup(id='200', name="{name}", description=desc) |
|
5 | project.setup(id='200', name="{name}", description=desc) | |
6 |
|
6 | |||
7 | voltage_reader = project.addReadUnit(datatype='VoltageReader', |
|
7 | voltage_reader = project.addReadUnit(datatype='VoltageReader', | |
8 | path="{path}", |
|
8 | path="{path}", | |
9 | startDate="{startDate}", |
|
9 | startDate="{startDate}", | |
10 | endDate="{endDate}", |
|
10 | endDate="{endDate}", | |
11 | startTime="{startHour}", |
|
11 | startTime="{startHour}", | |
12 | endTime="{endHour}", |
|
12 | endTime="{endHour}", | |
13 | online=0, |
|
13 | online=0, | |
14 | verbose=1, |
|
14 | verbose=1, | |
15 | walk=1, |
|
15 | walk=1, | |
16 | ) |
|
16 | ) | |
17 |
|
17 | |||
18 | voltage_proc = project.addProcUnit(datatype='VoltageProc', inputId=voltage_reader.getId()) |
|
18 | voltage_proc = project.addProcUnit(datatype='VoltageProc', inputId=voltage_reader.getId()) | |
19 |
|
19 | |||
20 | profile = voltage_proc.addOperation(name='ProfileSelector', optype='other') |
|
20 | profile = voltage_proc.addOperation(name='ProfileSelector', optype='other') | |
21 | profile.addParameter(name='profileRangeList', value='120,183', format='intlist') |
|
21 | profile.addParameter(name='profileRangeList', value='120,183', format='intlist') | |
22 |
|
22 | |||
23 | rti = voltage_proc.addOperation(name='RTIPlot', optype='other') |
|
23 | rti = voltage_proc.addOperation(name='RTIPlot', optype='other') | |
24 | rti.addParameter(name='wintitle', value='Jicamarca Radio Observatory', format='str') |
|
24 | rti.addParameter(name='wintitle', value='Jicamarca Radio Observatory', format='str') | |
25 | rti.addParameter(name='showprofile', value='0', format='int') |
|
25 | rti.addParameter(name='showprofile', value='0', format='int') | |
26 | rti.addParameter(name='xmin', value='0', format='int') |
|
26 | rti.addParameter(name='xmin', value='0', format='int') | |
27 | rti.addParameter(name='xmax', value='24', format='int') |
|
27 | rti.addParameter(name='xmax', value='24', format='int') | |
28 | rti.addParameter(name='figpath', value="{figpath}", format='str') |
|
28 | rti.addParameter(name='figpath', value="{figpath}", format='str') | |
29 | rti.addParameter(name='wr_period', value='5', format='int') |
|
29 | rti.addParameter(name='wr_period', value='5', format='int') | |
30 | rti.addParameter(name='exp_code', value='22', format='int') |
|
30 | rti.addParameter(name='exp_code', value='22', format='int') | |
31 |
|
31 | |||
32 |
|
32 | |||
33 |
|
|
33 | project.start() | |
34 | ''' |
|
34 | ''' | |
35 |
|
35 | |||
36 | multiprocess = '''from schainpy.controller import Project, MPProject |
|
36 | multiprocess = '''from schainpy.controller import Project, MPProject | |
37 | from time import sleep |
|
37 | from time import sleep | |
38 | desc = "{desc}" |
|
38 | desc = "{desc}" | |
39 |
|
39 | |||
40 | #################### |
|
40 | #################### | |
41 | # PLOTTER RECEIVER # |
|
41 | # PLOTTER RECEIVER # | |
42 | #################### |
|
42 | #################### | |
43 | plotter = Project() |
|
43 | plotter = Project() | |
44 | plotter.setup(id='100', name='receiver', description=desc) |
|
44 | plotter.setup(id='100', name='receiver', description=desc) | |
45 |
|
45 | |||
46 | receiver_plot = plotter.addProcUnit(name='PlotterReceiver') |
|
46 | receiver_plot = plotter.addProcUnit(name='PlotterReceiver') | |
47 | receiver_plot.addParameter(name='throttle', value=20, format='int') |
|
47 | receiver_plot.addParameter(name='throttle', value=20, format='int') | |
48 | receiver_plot.addParameter(name='plottypes', value='rti', format='str') |
|
48 | receiver_plot.addParameter(name='plottypes', value='rti', format='str') | |
49 |
|
49 | |||
50 | rti = receiver_plot.addOperation(name='PlotRTIData', optype='other') |
|
50 | rti = receiver_plot.addOperation(name='PlotRTIData', optype='other') | |
51 | rti.addParameter(name='zmin', value='-40.0', format='float') |
|
51 | rti.addParameter(name='zmin', value='-40.0', format='float') | |
52 | rti.addParameter(name='zmax', value='100.0', format='float') |
|
52 | rti.addParameter(name='zmax', value='100.0', format='float') | |
53 | rti.addParameter(name='decimation', value='200', format='int') |
|
53 | rti.addParameter(name='decimation', value='200', format='int') | |
54 | rti.addParameter(name='xmin', value='0.0', format='int') |
|
54 | rti.addParameter(name='xmin', value='0.0', format='int') | |
55 | rti.addParameter(name='colormap', value='jet', format='str') |
|
55 | rti.addParameter(name='colormap', value='jet', format='str') | |
56 |
|
56 | |||
57 | plotter.start() |
|
57 | plotter.start() | |
58 |
|
58 | |||
59 | sleep(2) |
|
59 | sleep(2) | |
60 |
|
60 | |||
61 | ################ |
|
61 | ################ | |
62 | # DATA EMITTER # |
|
62 | # DATA EMITTER # | |
63 | ################ |
|
63 | ################ | |
64 | project = Project() |
|
64 | project = Project() | |
65 | project.setup(id='200', name="{name}", description=desc) |
|
65 | project.setup(id='200', name="{name}", description=desc) | |
66 |
|
66 | |||
67 | spectra_reader = project.addReadUnit(datatype='SpectraReader', |
|
67 | spectra_reader = project.addReadUnit(datatype='SpectraReader', | |
68 | path="{path}", |
|
68 | path="{path}", | |
69 | startDate={startDate}, |
|
69 | startDate={startDate}, | |
70 | endDate={endDate}, |
|
70 | endDate={endDate}, | |
71 | startTime="{startHour}", |
|
71 | startTime="{startHour}", | |
72 | endTime="{endHour}", |
|
72 | endTime="{endHour}", | |
73 | online=0, |
|
73 | online=0, | |
74 | verbose=1, |
|
74 | verbose=1, | |
75 | walk=1, |
|
75 | walk=1, | |
76 | ) |
|
76 | ) | |
77 |
|
77 | |||
78 | spectra_proc = project.addProcUnit(datatype='Spectra', inputId=spectra_reader.getId()) |
|
78 | spectra_proc = project.addProcUnit(datatype='Spectra', inputId=spectra_reader.getId()) | |
79 |
|
79 | |||
80 | parameters_proc = project.addProcUnit(datatype='ParametersProc', inputId=spectra_proc.getId()) |
|
80 | parameters_proc = project.addProcUnit(datatype='ParametersProc', inputId=spectra_proc.getId()) | |
81 | moments = parameters_proc.addOperation(name='SpectralMoments', optype='other') |
|
81 | moments = parameters_proc.addOperation(name='SpectralMoments', optype='other') | |
82 |
|
82 | |||
83 | publish = parameters_proc.addOperation(name='PublishData', optype='other') |
|
83 | publish = parameters_proc.addOperation(name='PublishData', optype='other') | |
84 | publish.addParameter(name='zeromq', value=1, format='int') |
|
84 | publish.addParameter(name='zeromq', value=1, format='int') | |
85 | publish.addParameter(name='verbose', value=0, format='bool') |
|
85 | publish.addParameter(name='verbose', value=0, format='bool') | |
86 |
|
86 | |||
87 | MPProject(project, 16) |
|
87 | MPProject(project, 16) | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | ''' |
|
90 | ''' |
@@ -1,1227 +1,1251 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import copy |
|
7 | import copy | |
8 | import numpy |
|
8 | import numpy | |
9 | import datetime |
|
9 | import datetime | |
10 |
|
10 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
11 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 | from schainpy import cSchain |
|
12 | from schainpy import cSchain | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | def getNumpyDtype(dataTypeCode): |
|
15 | def getNumpyDtype(dataTypeCode): | |
16 |
|
16 | |||
17 | if dataTypeCode == 0: |
|
17 | if dataTypeCode == 0: | |
18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
18 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
19 | elif dataTypeCode == 1: |
|
19 | elif dataTypeCode == 1: | |
20 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
20 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
21 | elif dataTypeCode == 2: |
|
21 | elif dataTypeCode == 2: | |
22 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
22 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
23 | elif dataTypeCode == 3: |
|
23 | elif dataTypeCode == 3: | |
24 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
24 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
25 | elif dataTypeCode == 4: |
|
25 | elif dataTypeCode == 4: | |
26 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
26 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
27 | elif dataTypeCode == 5: |
|
27 | elif dataTypeCode == 5: | |
28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
28 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
29 | else: |
|
29 | else: | |
30 | raise ValueError, 'dataTypeCode was not defined' |
|
30 | raise ValueError, 'dataTypeCode was not defined' | |
31 |
|
31 | |||
32 | return numpyDtype |
|
32 | return numpyDtype | |
33 |
|
33 | |||
|
34 | ||||
34 | def getDataTypeCode(numpyDtype): |
|
35 | def getDataTypeCode(numpyDtype): | |
35 |
|
36 | |||
36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
37 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): | |
37 | datatype = 0 |
|
38 | datatype = 0 | |
38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
39 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): | |
39 | datatype = 1 |
|
40 | datatype = 1 | |
40 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): |
|
41 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): | |
41 | datatype = 2 |
|
42 | datatype = 2 | |
42 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): |
|
43 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): | |
43 | datatype = 3 |
|
44 | datatype = 3 | |
44 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): |
|
45 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): | |
45 | datatype = 4 |
|
46 | datatype = 4 | |
46 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): |
|
47 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): | |
47 | datatype = 5 |
|
48 | datatype = 5 | |
48 | else: |
|
49 | else: | |
49 | datatype = None |
|
50 | datatype = None | |
50 |
|
51 | |||
51 | return datatype |
|
52 | return datatype | |
52 |
|
53 | |||
|
54 | ||||
53 | def hildebrand_sekhon(data, navg): |
|
55 | def hildebrand_sekhon(data, navg): | |
54 | """ |
|
56 | """ | |
55 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
57 | This method is for the objective determination of the noise level in Doppler spectra. This | |
56 | implementation technique is based on the fact that the standard deviation of the spectral |
|
58 | implementation technique is based on the fact that the standard deviation of the spectral | |
57 | densities is equal to the mean spectral density for white Gaussian noise |
|
59 | densities is equal to the mean spectral density for white Gaussian noise | |
58 |
|
60 | |||
59 | Inputs: |
|
61 | Inputs: | |
60 | Data : heights |
|
62 | Data : heights | |
61 | navg : numbers of averages |
|
63 | navg : numbers of averages | |
62 |
|
64 | |||
63 | Return: |
|
65 | Return: | |
64 | -1 : any error |
|
66 | -1 : any error | |
65 | anoise : noise's level |
|
67 | anoise : noise's level | |
66 | """ |
|
68 | """ | |
67 |
|
69 | |||
68 | sortdata = numpy.sort(data, axis=None) |
|
70 | sortdata = numpy.sort(data, axis=None) | |
69 | # lenOfData = len(sortdata) |
|
71 | # lenOfData = len(sortdata) | |
70 | # nums_min = lenOfData*0.2 |
|
72 | # nums_min = lenOfData*0.2 | |
71 | # |
|
73 | # | |
72 | # if nums_min <= 5: |
|
74 | # if nums_min <= 5: | |
73 | # nums_min = 5 |
|
75 | # nums_min = 5 | |
74 | # |
|
76 | # | |
75 | # sump = 0. |
|
77 | # sump = 0. | |
76 | # |
|
78 | # | |
77 | # sumq = 0. |
|
79 | # sumq = 0. | |
78 | # |
|
80 | # | |
79 | # j = 0 |
|
81 | # j = 0 | |
80 | # |
|
82 | # | |
81 | # cont = 1 |
|
83 | # cont = 1 | |
82 | # |
|
84 | # | |
83 | # while((cont==1)and(j<lenOfData)): |
|
85 | # while((cont==1)and(j<lenOfData)): | |
84 | # |
|
86 | # | |
85 | # sump += sortdata[j] |
|
87 | # sump += sortdata[j] | |
86 | # |
|
88 | # | |
87 | # sumq += sortdata[j]**2 |
|
89 | # sumq += sortdata[j]**2 | |
88 | # |
|
90 | # | |
89 | # if j > nums_min: |
|
91 | # if j > nums_min: | |
90 | # rtest = float(j)/(j-1) + 1.0/navg |
|
92 | # rtest = float(j)/(j-1) + 1.0/navg | |
91 | # if ((sumq*j) > (rtest*sump**2)): |
|
93 | # if ((sumq*j) > (rtest*sump**2)): | |
92 | # j = j - 1 |
|
94 | # j = j - 1 | |
93 | # sump = sump - sortdata[j] |
|
95 | # sump = sump - sortdata[j] | |
94 | # sumq = sumq - sortdata[j]**2 |
|
96 | # sumq = sumq - sortdata[j]**2 | |
95 | # cont = 0 |
|
97 | # cont = 0 | |
96 | # |
|
98 | # | |
97 | # j += 1 |
|
99 | # j += 1 | |
98 | # |
|
100 | # | |
99 | # lnoise = sump /j |
|
101 | # lnoise = sump /j | |
100 | # |
|
102 | # | |
101 | # return lnoise |
|
103 | # return lnoise | |
102 |
|
104 | |||
103 | return cSchain.hildebrand_sekhon(sortdata, navg) |
|
105 | return cSchain.hildebrand_sekhon(sortdata, navg) | |
104 |
|
106 | |||
105 |
|
107 | |||
106 | class Beam: |
|
108 | class Beam: | |
107 |
|
109 | |||
108 | def __init__(self): |
|
110 | def __init__(self): | |
109 | self.codeList = [] |
|
111 | self.codeList = [] | |
110 | self.azimuthList = [] |
|
112 | self.azimuthList = [] | |
111 | self.zenithList = [] |
|
113 | self.zenithList = [] | |
112 |
|
114 | |||
|
115 | ||||
113 | class GenericData(object): |
|
116 | class GenericData(object): | |
114 |
|
117 | |||
115 | flagNoData = True |
|
118 | flagNoData = True | |
116 |
|
119 | |||
117 | def copy(self, inputObj=None): |
|
120 | def copy(self, inputObj=None): | |
118 |
|
121 | |||
119 | if inputObj == None: |
|
122 | if inputObj == None: | |
120 | return copy.deepcopy(self) |
|
123 | return copy.deepcopy(self) | |
121 |
|
124 | |||
122 | for key in inputObj.__dict__.keys(): |
|
125 | for key in inputObj.__dict__.keys(): | |
123 |
|
126 | |||
124 | attribute = inputObj.__dict__[key] |
|
127 | attribute = inputObj.__dict__[key] | |
125 |
|
128 | |||
126 | #If this attribute is a tuple or list |
|
129 | # If this attribute is a tuple or list | |
127 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
130 | if type(inputObj.__dict__[key]) in (tuple, list): | |
128 | self.__dict__[key] = attribute[:] |
|
131 | self.__dict__[key] = attribute[:] | |
129 | continue |
|
132 | continue | |
130 |
|
133 | |||
131 | #If this attribute is another object or instance |
|
134 | # If this attribute is another object or instance | |
132 | if hasattr(attribute, '__dict__'): |
|
135 | if hasattr(attribute, '__dict__'): | |
133 | self.__dict__[key] = attribute.copy() |
|
136 | self.__dict__[key] = attribute.copy() | |
134 | continue |
|
137 | continue | |
135 |
|
138 | |||
136 | self.__dict__[key] = inputObj.__dict__[key] |
|
139 | self.__dict__[key] = inputObj.__dict__[key] | |
137 |
|
140 | |||
138 | def deepcopy(self): |
|
141 | def deepcopy(self): | |
139 |
|
142 | |||
140 | return copy.deepcopy(self) |
|
143 | return copy.deepcopy(self) | |
141 |
|
144 | |||
142 | def isEmpty(self): |
|
145 | def isEmpty(self): | |
143 |
|
146 | |||
144 | return self.flagNoData |
|
147 | return self.flagNoData | |
145 |
|
148 | |||
|
149 | ||||
146 | class JROData(GenericData): |
|
150 | class JROData(GenericData): | |
147 |
|
151 | |||
148 | # m_BasicHeader = BasicHeader() |
|
152 | # m_BasicHeader = BasicHeader() | |
149 | # m_ProcessingHeader = ProcessingHeader() |
|
153 | # m_ProcessingHeader = ProcessingHeader() | |
150 |
|
154 | |||
151 | systemHeaderObj = SystemHeader() |
|
155 | systemHeaderObj = SystemHeader() | |
152 |
|
156 | |||
153 | radarControllerHeaderObj = RadarControllerHeader() |
|
157 | radarControllerHeaderObj = RadarControllerHeader() | |
154 |
|
158 | |||
155 | # data = None |
|
159 | # data = None | |
156 |
|
160 | |||
157 | type = None |
|
161 | type = None | |
158 |
|
162 | |||
159 | datatype = None #dtype but in string |
|
163 | datatype = None # dtype but in string | |
160 |
|
164 | |||
161 | # dtype = None |
|
165 | # dtype = None | |
162 |
|
166 | |||
163 | # nChannels = None |
|
167 | # nChannels = None | |
164 |
|
168 | |||
165 | # nHeights = None |
|
169 | # nHeights = None | |
166 |
|
170 | |||
167 | nProfiles = None |
|
171 | nProfiles = None | |
168 |
|
172 | |||
169 | heightList = None |
|
173 | heightList = None | |
170 |
|
174 | |||
171 | channelList = None |
|
175 | channelList = None | |
172 |
|
176 | |||
173 | flagDiscontinuousBlock = False |
|
177 | flagDiscontinuousBlock = False | |
174 |
|
178 | |||
175 | useLocalTime = False |
|
179 | useLocalTime = False | |
176 |
|
180 | |||
177 | utctime = None |
|
181 | utctime = None | |
178 |
|
182 | |||
179 | timeZone = None |
|
183 | timeZone = None | |
180 |
|
184 | |||
181 | dstFlag = None |
|
185 | dstFlag = None | |
182 |
|
186 | |||
183 | errorCount = None |
|
187 | errorCount = None | |
184 |
|
188 | |||
185 | blocksize = None |
|
189 | blocksize = None | |
186 |
|
190 | |||
187 | # nCode = None |
|
191 | # nCode = None | |
188 | # |
|
192 | # | |
189 | # nBaud = None |
|
193 | # nBaud = None | |
190 | # |
|
194 | # | |
191 | # code = None |
|
195 | # code = None | |
192 |
|
196 | |||
193 | flagDecodeData = False #asumo q la data no esta decodificada |
|
197 | flagDecodeData = False # asumo q la data no esta decodificada | |
194 |
|
198 | |||
195 | flagDeflipData = False #asumo q la data no esta sin flip |
|
199 | flagDeflipData = False # asumo q la data no esta sin flip | |
196 |
|
200 | |||
197 | flagShiftFFT = False |
|
201 | flagShiftFFT = False | |
198 |
|
202 | |||
199 | # ippSeconds = None |
|
203 | # ippSeconds = None | |
200 |
|
204 | |||
201 | # timeInterval = None |
|
205 | # timeInterval = None | |
202 |
|
206 | |||
203 | nCohInt = None |
|
207 | nCohInt = None | |
204 |
|
208 | |||
205 | # noise = None |
|
209 | # noise = None | |
206 |
|
210 | |||
207 | windowOfFilter = 1 |
|
211 | windowOfFilter = 1 | |
208 |
|
212 | |||
209 | #Speed of ligth |
|
213 | # Speed of ligth | |
210 | C = 3e8 |
|
214 | C = 3e8 | |
211 |
|
215 | |||
212 | frequency = 49.92e6 |
|
216 | frequency = 49.92e6 | |
213 |
|
217 | |||
214 | realtime = False |
|
218 | realtime = False | |
215 |
|
219 | |||
216 | beacon_heiIndexList = None |
|
220 | beacon_heiIndexList = None | |
217 |
|
221 | |||
218 | last_block = None |
|
222 | last_block = None | |
219 |
|
223 | |||
220 | blocknow = None |
|
224 | blocknow = None | |
221 |
|
225 | |||
222 | azimuth = None |
|
226 | azimuth = None | |
223 |
|
227 | |||
224 | zenith = None |
|
228 | zenith = None | |
225 |
|
229 | |||
226 | beam = Beam() |
|
230 | beam = Beam() | |
227 |
|
231 | |||
228 | profileIndex = None |
|
232 | profileIndex = None | |
229 |
|
233 | |||
230 | def getNoise(self): |
|
234 | def getNoise(self): | |
231 |
|
235 | |||
232 | raise NotImplementedError |
|
236 | raise NotImplementedError | |
233 |
|
237 | |||
234 | def getNChannels(self): |
|
238 | def getNChannels(self): | |
235 |
|
239 | |||
236 | return len(self.channelList) |
|
240 | return len(self.channelList) | |
237 |
|
241 | |||
238 | def getChannelIndexList(self): |
|
242 | def getChannelIndexList(self): | |
239 |
|
243 | |||
240 | return range(self.nChannels) |
|
244 | return range(self.nChannels) | |
241 |
|
245 | |||
242 | def getNHeights(self): |
|
246 | def getNHeights(self): | |
243 |
|
247 | |||
244 | return len(self.heightList) |
|
248 | return len(self.heightList) | |
245 |
|
249 | |||
246 | def getHeiRange(self, extrapoints=0): |
|
250 | def getHeiRange(self, extrapoints=0): | |
247 |
|
251 | |||
248 | heis = self.heightList |
|
252 | heis = self.heightList | |
249 | # deltah = self.heightList[1] - self.heightList[0] |
|
253 | # deltah = self.heightList[1] - self.heightList[0] | |
250 | # |
|
254 | # | |
251 | # heis.append(self.heightList[-1]) |
|
255 | # heis.append(self.heightList[-1]) | |
252 |
|
256 | |||
253 | return heis |
|
257 | return heis | |
254 |
|
258 | |||
255 | def getDeltaH(self): |
|
259 | def getDeltaH(self): | |
256 |
|
260 | |||
257 | delta = self.heightList[1] - self.heightList[0] |
|
261 | delta = self.heightList[1] - self.heightList[0] | |
258 |
|
262 | |||
259 | return delta |
|
263 | return delta | |
260 |
|
264 | |||
261 | def getltctime(self): |
|
265 | def getltctime(self): | |
262 |
|
266 | |||
263 | if self.useLocalTime: |
|
267 | if self.useLocalTime: | |
264 | return self.utctime - self.timeZone*60 |
|
268 | return self.utctime - self.timeZone * 60 | |
265 |
|
269 | |||
266 | return self.utctime |
|
270 | return self.utctime | |
267 |
|
271 | |||
268 | def getDatatime(self): |
|
272 | def getDatatime(self): | |
269 |
|
273 | |||
270 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
274 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
271 | return datatimeValue |
|
275 | return datatimeValue | |
272 |
|
276 | |||
273 | def getTimeRange(self): |
|
277 | def getTimeRange(self): | |
274 |
|
278 | |||
275 | datatime = [] |
|
279 | datatime = [] | |
276 |
|
280 | |||
277 | datatime.append(self.ltctime) |
|
281 | datatime.append(self.ltctime) | |
278 | datatime.append(self.ltctime + self.timeInterval+1) |
|
282 | datatime.append(self.ltctime + self.timeInterval + 1) | |
279 |
|
283 | |||
280 | datatime = numpy.array(datatime) |
|
284 | datatime = numpy.array(datatime) | |
281 |
|
285 | |||
282 | return datatime |
|
286 | return datatime | |
283 |
|
287 | |||
284 | def getFmaxTimeResponse(self): |
|
288 | def getFmaxTimeResponse(self): | |
285 |
|
289 | |||
286 | period = (10**-6)*self.getDeltaH()/(0.15) |
|
290 | period = (10**-6) * self.getDeltaH() / (0.15) | |
287 |
|
291 | |||
288 | PRF = 1./(period * self.nCohInt) |
|
292 | PRF = 1. / (period * self.nCohInt) | |
289 |
|
293 | |||
290 | fmax = PRF |
|
294 | fmax = PRF | |
291 |
|
295 | |||
292 | return fmax |
|
296 | return fmax | |
293 |
|
297 | |||
294 | def getFmax(self): |
|
298 | def getFmax(self): | |
295 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
299 | PRF = 1. / (self.ippSeconds * self.nCohInt) | |
296 |
|
300 | |||
297 | fmax = PRF |
|
301 | fmax = PRF | |
298 | return fmax |
|
302 | return fmax | |
299 |
|
303 | |||
300 | def getVmax(self): |
|
304 | def getVmax(self): | |
301 |
|
305 | |||
302 | _lambda = self.C/self.frequency |
|
306 | _lambda = self.C / self.frequency | |
303 |
|
307 | |||
304 | vmax = self.getFmax() * _lambda/2 |
|
308 | vmax = self.getFmax() * _lambda / 2 | |
305 |
|
309 | |||
306 | return vmax |
|
310 | return vmax | |
307 |
|
311 | |||
308 | def get_ippSeconds(self): |
|
312 | def get_ippSeconds(self): | |
309 | ''' |
|
313 | ''' | |
310 | ''' |
|
314 | ''' | |
311 | return self.radarControllerHeaderObj.ippSeconds |
|
315 | return self.radarControllerHeaderObj.ippSeconds | |
312 |
|
316 | |||
313 | def set_ippSeconds(self, ippSeconds): |
|
317 | def set_ippSeconds(self, ippSeconds): | |
314 | ''' |
|
318 | ''' | |
315 | ''' |
|
319 | ''' | |
316 |
|
320 | |||
317 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
321 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
318 |
|
322 | |||
319 | return |
|
323 | return | |
320 |
|
324 | |||
321 | def get_dtype(self): |
|
325 | def get_dtype(self): | |
322 | ''' |
|
326 | ''' | |
323 | ''' |
|
327 | ''' | |
324 | return getNumpyDtype(self.datatype) |
|
328 | return getNumpyDtype(self.datatype) | |
325 |
|
329 | |||
326 | def set_dtype(self, numpyDtype): |
|
330 | def set_dtype(self, numpyDtype): | |
327 | ''' |
|
331 | ''' | |
328 | ''' |
|
332 | ''' | |
329 |
|
333 | |||
330 | self.datatype = getDataTypeCode(numpyDtype) |
|
334 | self.datatype = getDataTypeCode(numpyDtype) | |
331 |
|
335 | |||
332 | def get_code(self): |
|
336 | def get_code(self): | |
333 | ''' |
|
337 | ''' | |
334 | ''' |
|
338 | ''' | |
335 | return self.radarControllerHeaderObj.code |
|
339 | return self.radarControllerHeaderObj.code | |
336 |
|
340 | |||
337 | def set_code(self, code): |
|
341 | def set_code(self, code): | |
338 | ''' |
|
342 | ''' | |
339 | ''' |
|
343 | ''' | |
340 | self.radarControllerHeaderObj.code = code |
|
344 | self.radarControllerHeaderObj.code = code | |
341 |
|
345 | |||
342 | return |
|
346 | return | |
343 |
|
347 | |||
344 | def get_ncode(self): |
|
348 | def get_ncode(self): | |
345 | ''' |
|
349 | ''' | |
346 | ''' |
|
350 | ''' | |
347 | return self.radarControllerHeaderObj.nCode |
|
351 | return self.radarControllerHeaderObj.nCode | |
348 |
|
352 | |||
349 | def set_ncode(self, nCode): |
|
353 | def set_ncode(self, nCode): | |
350 | ''' |
|
354 | ''' | |
351 | ''' |
|
355 | ''' | |
352 | self.radarControllerHeaderObj.nCode = nCode |
|
356 | self.radarControllerHeaderObj.nCode = nCode | |
353 |
|
357 | |||
354 | return |
|
358 | return | |
355 |
|
359 | |||
356 | def get_nbaud(self): |
|
360 | def get_nbaud(self): | |
357 | ''' |
|
361 | ''' | |
358 | ''' |
|
362 | ''' | |
359 | return self.radarControllerHeaderObj.nBaud |
|
363 | return self.radarControllerHeaderObj.nBaud | |
360 |
|
364 | |||
361 | def set_nbaud(self, nBaud): |
|
365 | def set_nbaud(self, nBaud): | |
362 | ''' |
|
366 | ''' | |
363 | ''' |
|
367 | ''' | |
364 | self.radarControllerHeaderObj.nBaud = nBaud |
|
368 | self.radarControllerHeaderObj.nBaud = nBaud | |
365 |
|
369 | |||
366 | return |
|
370 | return | |
367 |
|
371 | |||
368 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
372 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
369 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
373 | channelIndexList = property( | |
|
374 | getChannelIndexList, "I'm the 'channelIndexList' property.") | |||
370 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
375 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
371 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
376 | #noise = property(getNoise, "I'm the 'nHeights' property.") | |
372 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
377 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
373 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
378 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
374 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
379 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
375 | dtype = property(get_dtype, set_dtype) |
|
380 | dtype = property(get_dtype, set_dtype) | |
376 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
381 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
377 | code = property(get_code, set_code) |
|
382 | code = property(get_code, set_code) | |
378 | nCode = property(get_ncode, set_ncode) |
|
383 | nCode = property(get_ncode, set_ncode) | |
379 | nBaud = property(get_nbaud, set_nbaud) |
|
384 | nBaud = property(get_nbaud, set_nbaud) | |
380 |
|
385 | |||
|
386 | ||||
381 | class Voltage(JROData): |
|
387 | class Voltage(JROData): | |
382 |
|
388 | |||
383 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
389 | # data es un numpy array de 2 dmensiones (canales, alturas) | |
384 | data = None |
|
390 | data = None | |
385 |
|
391 | |||
386 | def __init__(self): |
|
392 | def __init__(self): | |
387 | ''' |
|
393 | ''' | |
388 | Constructor |
|
394 | Constructor | |
389 | ''' |
|
395 | ''' | |
390 |
|
396 | |||
391 | self.useLocalTime = True |
|
397 | self.useLocalTime = True | |
392 |
|
398 | |||
393 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
399 | self.radarControllerHeaderObj = RadarControllerHeader() | |
394 |
|
400 | |||
395 | self.systemHeaderObj = SystemHeader() |
|
401 | self.systemHeaderObj = SystemHeader() | |
396 |
|
402 | |||
397 | self.type = "Voltage" |
|
403 | self.type = "Voltage" | |
398 |
|
404 | |||
399 | self.data = None |
|
405 | self.data = None | |
400 |
|
406 | |||
401 | # self.dtype = None |
|
407 | # self.dtype = None | |
402 |
|
408 | |||
403 | # self.nChannels = 0 |
|
409 | # self.nChannels = 0 | |
404 |
|
410 | |||
405 | # self.nHeights = 0 |
|
411 | # self.nHeights = 0 | |
406 |
|
412 | |||
407 | self.nProfiles = None |
|
413 | self.nProfiles = None | |
408 |
|
414 | |||
409 | self.heightList = None |
|
415 | self.heightList = None | |
410 |
|
416 | |||
411 | self.channelList = None |
|
417 | self.channelList = None | |
412 |
|
418 | |||
413 | # self.channelIndexList = None |
|
419 | # self.channelIndexList = None | |
414 |
|
420 | |||
415 | self.flagNoData = True |
|
421 | self.flagNoData = True | |
416 |
|
422 | |||
417 | self.flagDiscontinuousBlock = False |
|
423 | self.flagDiscontinuousBlock = False | |
418 |
|
424 | |||
419 | self.utctime = None |
|
425 | self.utctime = None | |
420 |
|
426 | |||
421 | self.timeZone = None |
|
427 | self.timeZone = None | |
422 |
|
428 | |||
423 | self.dstFlag = None |
|
429 | self.dstFlag = None | |
424 |
|
430 | |||
425 | self.errorCount = None |
|
431 | self.errorCount = None | |
426 |
|
432 | |||
427 | self.nCohInt = None |
|
433 | self.nCohInt = None | |
428 |
|
434 | |||
429 | self.blocksize = None |
|
435 | self.blocksize = None | |
430 |
|
436 | |||
431 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
437 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
432 |
|
438 | |||
433 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
439 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
434 |
|
440 | |||
435 | self.flagShiftFFT = False |
|
441 | self.flagShiftFFT = False | |
436 |
|
442 | |||
437 |
self.flagDataAsBlock = False |
|
443 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil | |
438 |
|
444 | |||
439 | self.profileIndex = 0 |
|
445 | self.profileIndex = 0 | |
440 |
|
446 | |||
441 |
def getNoisebyHildebrand(self, channel |
|
447 | def getNoisebyHildebrand(self, channel=None): | |
442 | """ |
|
448 | """ | |
443 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
449 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
444 |
|
450 | |||
445 | Return: |
|
451 | Return: | |
446 | noiselevel |
|
452 | noiselevel | |
447 | """ |
|
453 | """ | |
448 |
|
454 | |||
449 | if channel != None: |
|
455 | if channel != None: | |
450 | data = self.data[channel] |
|
456 | data = self.data[channel] | |
451 | nChannels = 1 |
|
457 | nChannels = 1 | |
452 | else: |
|
458 | else: | |
453 | data = self.data |
|
459 | data = self.data | |
454 | nChannels = self.nChannels |
|
460 | nChannels = self.nChannels | |
455 |
|
461 | |||
456 | noise = numpy.zeros(nChannels) |
|
462 | noise = numpy.zeros(nChannels) | |
457 | power = data * numpy.conjugate(data) |
|
463 | power = data * numpy.conjugate(data) | |
458 |
|
464 | |||
459 | for thisChannel in range(nChannels): |
|
465 | for thisChannel in range(nChannels): | |
460 | if nChannels == 1: |
|
466 | if nChannels == 1: | |
461 | daux = power[:].real |
|
467 | daux = power[:].real | |
462 | else: |
|
468 | else: | |
463 | daux = power[thisChannel,:].real |
|
469 | daux = power[thisChannel, :].real | |
464 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
470 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
465 |
|
471 | |||
466 | return noise |
|
472 | return noise | |
467 |
|
473 | |||
468 |
def getNoise(self, type |
|
474 | def getNoise(self, type=1, channel=None): | |
469 |
|
475 | |||
470 | if type == 1: |
|
476 | if type == 1: | |
471 | noise = self.getNoisebyHildebrand(channel) |
|
477 | noise = self.getNoisebyHildebrand(channel) | |
472 |
|
478 | |||
473 | return noise |
|
479 | return noise | |
474 |
|
480 | |||
475 |
def getPower(self, channel |
|
481 | def getPower(self, channel=None): | |
476 |
|
482 | |||
477 | if channel != None: |
|
483 | if channel != None: | |
478 | data = self.data[channel] |
|
484 | data = self.data[channel] | |
479 | else: |
|
485 | else: | |
480 | data = self.data |
|
486 | data = self.data | |
481 |
|
487 | |||
482 | power = data * numpy.conjugate(data) |
|
488 | power = data * numpy.conjugate(data) | |
483 | powerdB = 10*numpy.log10(power.real) |
|
489 | powerdB = 10 * numpy.log10(power.real) | |
484 | powerdB = numpy.squeeze(powerdB) |
|
490 | powerdB = numpy.squeeze(powerdB) | |
485 |
|
491 | |||
486 | return powerdB |
|
492 | return powerdB | |
487 |
|
493 | |||
488 | def getTimeInterval(self): |
|
494 | def getTimeInterval(self): | |
489 |
|
495 | |||
490 | timeInterval = self.ippSeconds * self.nCohInt |
|
496 | timeInterval = self.ippSeconds * self.nCohInt | |
491 |
|
497 | |||
492 | return timeInterval |
|
498 | return timeInterval | |
493 |
|
499 | |||
494 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
500 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
495 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
501 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
496 |
|
502 | |||
|
503 | ||||
497 | class Spectra(JROData): |
|
504 | class Spectra(JROData): | |
498 |
|
505 | |||
499 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
506 | # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
500 | data_spc = None |
|
507 | data_spc = None | |
501 |
|
508 | |||
502 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
509 | # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) | |
503 | data_cspc = None |
|
510 | data_cspc = None | |
504 |
|
511 | |||
505 | #data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
512 | # data dc es un numpy array de 2 dmensiones (canales, alturas) | |
506 | data_dc = None |
|
513 | data_dc = None | |
507 |
|
514 | |||
508 | #data power |
|
515 | # data power | |
509 | data_pwr = None |
|
516 | data_pwr = None | |
510 |
|
517 | |||
511 | nFFTPoints = None |
|
518 | nFFTPoints = None | |
512 |
|
519 | |||
513 | # nPairs = None |
|
520 | # nPairs = None | |
514 |
|
521 | |||
515 | pairsList = None |
|
522 | pairsList = None | |
516 |
|
523 | |||
517 | nIncohInt = None |
|
524 | nIncohInt = None | |
518 |
|
525 | |||
519 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
526 | wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia | |
520 |
|
527 | |||
521 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
528 | nCohInt = None # se requiere para determinar el valor de timeInterval | |
522 |
|
529 | |||
523 | ippFactor = None |
|
530 | ippFactor = None | |
524 |
|
531 | |||
525 | profileIndex = 0 |
|
532 | profileIndex = 0 | |
526 |
|
533 | |||
527 | plotting = "spectra" |
|
534 | plotting = "spectra" | |
528 |
|
535 | |||
529 | def __init__(self): |
|
536 | def __init__(self): | |
530 | ''' |
|
537 | ''' | |
531 | Constructor |
|
538 | Constructor | |
532 | ''' |
|
539 | ''' | |
533 |
|
540 | |||
534 | self.useLocalTime = True |
|
541 | self.useLocalTime = True | |
535 |
|
542 | |||
536 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
543 | self.radarControllerHeaderObj = RadarControllerHeader() | |
537 |
|
544 | |||
538 | self.systemHeaderObj = SystemHeader() |
|
545 | self.systemHeaderObj = SystemHeader() | |
539 |
|
546 | |||
540 | self.type = "Spectra" |
|
547 | self.type = "Spectra" | |
541 |
|
548 | |||
542 | # self.data = None |
|
549 | # self.data = None | |
543 |
|
550 | |||
544 | # self.dtype = None |
|
551 | # self.dtype = None | |
545 |
|
552 | |||
546 | # self.nChannels = 0 |
|
553 | # self.nChannels = 0 | |
547 |
|
554 | |||
548 | # self.nHeights = 0 |
|
555 | # self.nHeights = 0 | |
549 |
|
556 | |||
550 | self.nProfiles = None |
|
557 | self.nProfiles = None | |
551 |
|
558 | |||
552 | self.heightList = None |
|
559 | self.heightList = None | |
553 |
|
560 | |||
554 | self.channelList = None |
|
561 | self.channelList = None | |
555 |
|
562 | |||
556 | # self.channelIndexList = None |
|
563 | # self.channelIndexList = None | |
557 |
|
564 | |||
558 | self.pairsList = None |
|
565 | self.pairsList = None | |
559 |
|
566 | |||
560 | self.flagNoData = True |
|
567 | self.flagNoData = True | |
561 |
|
568 | |||
562 | self.flagDiscontinuousBlock = False |
|
569 | self.flagDiscontinuousBlock = False | |
563 |
|
570 | |||
564 | self.utctime = None |
|
571 | self.utctime = None | |
565 |
|
572 | |||
566 | self.nCohInt = None |
|
573 | self.nCohInt = None | |
567 |
|
574 | |||
568 | self.nIncohInt = None |
|
575 | self.nIncohInt = None | |
569 |
|
576 | |||
570 | self.blocksize = None |
|
577 | self.blocksize = None | |
571 |
|
578 | |||
572 | self.nFFTPoints = None |
|
579 | self.nFFTPoints = None | |
573 |
|
580 | |||
574 | self.wavelength = None |
|
581 | self.wavelength = None | |
575 |
|
582 | |||
576 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
583 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
577 |
|
584 | |||
578 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
585 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
579 |
|
586 | |||
580 | self.flagShiftFFT = False |
|
587 | self.flagShiftFFT = False | |
581 |
|
588 | |||
582 | self.ippFactor = 1 |
|
589 | self.ippFactor = 1 | |
583 |
|
590 | |||
584 | #self.noise = None |
|
591 | #self.noise = None | |
585 |
|
592 | |||
586 | self.beacon_heiIndexList = [] |
|
593 | self.beacon_heiIndexList = [] | |
587 |
|
594 | |||
588 | self.noise_estimation = None |
|
595 | self.noise_estimation = None | |
589 |
|
596 | |||
590 |
|
||||
591 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
597 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
592 | """ |
|
598 | """ | |
593 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
599 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
594 |
|
600 | |||
595 | Return: |
|
601 | Return: | |
596 | noiselevel |
|
602 | noiselevel | |
597 | """ |
|
603 | """ | |
598 |
|
604 | |||
599 | noise = numpy.zeros(self.nChannels) |
|
605 | noise = numpy.zeros(self.nChannels) | |
600 |
|
606 | |||
601 | for channel in range(self.nChannels): |
|
607 | for channel in range(self.nChannels): | |
602 |
daux = self.data_spc[channel, |
|
608 | daux = self.data_spc[channel, | |
|
609 | xmin_index:xmax_index, ymin_index:ymax_index] | |||
603 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
610 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
604 |
|
611 | |||
605 | return noise |
|
612 | return noise | |
606 |
|
613 | |||
607 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
614 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
608 |
|
615 | |||
609 | if self.noise_estimation is not None: |
|
616 | if self.noise_estimation is not None: | |
610 |
|
|
617 | # this was estimated by getNoise Operation defined in jroproc_spectra.py | |
|
618 | return self.noise_estimation | |||
611 | else: |
|
619 | else: | |
612 |
noise = self.getNoisebyHildebrand( |
|
620 | noise = self.getNoisebyHildebrand( | |
|
621 | xmin_index, xmax_index, ymin_index, ymax_index) | |||
613 | return noise |
|
622 | return noise | |
614 |
|
623 | |||
615 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
624 | def getFreqRangeTimeResponse(self, extrapoints=0): | |
616 |
|
625 | |||
617 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) |
|
626 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) | |
618 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
627 | freqrange = deltafreq * \ | |
|
628 | (numpy.arange(self.nFFTPoints + extrapoints) - | |||
|
629 | self.nFFTPoints / 2.) - deltafreq / 2 | |||
619 |
|
630 | |||
620 | return freqrange |
|
631 | return freqrange | |
621 |
|
632 | |||
622 | def getAcfRange(self, extrapoints=0): |
|
633 | def getAcfRange(self, extrapoints=0): | |
623 |
|
634 | |||
624 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) |
|
635 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) | |
625 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
636 | freqrange = deltafreq * \ | |
|
637 | (numpy.arange(self.nFFTPoints + extrapoints) - | |||
|
638 | self.nFFTPoints / 2.) - deltafreq / 2 | |||
626 |
|
639 | |||
627 | return freqrange |
|
640 | return freqrange | |
628 |
|
641 | |||
629 | def getFreqRange(self, extrapoints=0): |
|
642 | def getFreqRange(self, extrapoints=0): | |
630 |
|
643 | |||
631 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
644 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) | |
632 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
645 | freqrange = deltafreq * \ | |
|
646 | (numpy.arange(self.nFFTPoints + extrapoints) - | |||
|
647 | self.nFFTPoints / 2.) - deltafreq / 2 | |||
633 |
|
648 | |||
634 | return freqrange |
|
649 | return freqrange | |
635 |
|
650 | |||
636 | def getVelRange(self, extrapoints=0): |
|
651 | def getVelRange(self, extrapoints=0): | |
637 |
|
652 | |||
638 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
653 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) | |
639 |
velrange = deltav*(numpy.arange(self.nFFTPoints+ |
|
654 | velrange = deltav * (numpy.arange(self.nFFTPoints + | |
|
655 | extrapoints) - self.nFFTPoints / 2.) # - deltav/2 | |||
640 |
|
656 | |||
641 | return velrange |
|
657 | return velrange | |
642 |
|
658 | |||
643 | def getNPairs(self): |
|
659 | def getNPairs(self): | |
644 |
|
660 | |||
645 | return len(self.pairsList) |
|
661 | return len(self.pairsList) | |
646 |
|
662 | |||
647 | def getPairsIndexList(self): |
|
663 | def getPairsIndexList(self): | |
648 |
|
664 | |||
649 | return range(self.nPairs) |
|
665 | return range(self.nPairs) | |
650 |
|
666 | |||
651 | def getNormFactor(self): |
|
667 | def getNormFactor(self): | |
652 |
|
668 | |||
653 | pwcode = 1 |
|
669 | pwcode = 1 | |
654 |
|
670 | |||
655 | if self.flagDecodeData: |
|
671 | if self.flagDecodeData: | |
656 | pwcode = numpy.sum(self.code[0]**2) |
|
672 | pwcode = numpy.sum(self.code[0]**2) | |
657 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
673 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
658 |
normFactor = self.nProfiles*self.nIncohInt* |
|
674 | normFactor = self.nProfiles * self.nIncohInt * \ | |
|
675 | self.nCohInt * pwcode * self.windowOfFilter | |||
659 |
|
676 | |||
660 | return normFactor |
|
677 | return normFactor | |
661 |
|
678 | |||
662 | def getFlagCspc(self): |
|
679 | def getFlagCspc(self): | |
663 |
|
680 | |||
664 | if self.data_cspc is None: |
|
681 | if self.data_cspc is None: | |
665 | return True |
|
682 | return True | |
666 |
|
683 | |||
667 | return False |
|
684 | return False | |
668 |
|
685 | |||
669 | def getFlagDc(self): |
|
686 | def getFlagDc(self): | |
670 |
|
687 | |||
671 | if self.data_dc is None: |
|
688 | if self.data_dc is None: | |
672 | return True |
|
689 | return True | |
673 |
|
690 | |||
674 | return False |
|
691 | return False | |
675 |
|
692 | |||
676 | def getTimeInterval(self): |
|
693 | def getTimeInterval(self): | |
677 |
|
694 | |||
678 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles |
|
695 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles | |
679 |
|
696 | |||
680 | return timeInterval |
|
697 | return timeInterval | |
681 |
|
698 | |||
682 | def getPower(self): |
|
699 | def getPower(self): | |
683 |
|
700 | |||
684 | factor = self.normFactor |
|
701 | factor = self.normFactor | |
685 | z = self.data_spc/factor |
|
702 | z = self.data_spc / factor | |
686 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
703 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
687 | avg = numpy.average(z, axis=1) |
|
704 | avg = numpy.average(z, axis=1) | |
688 |
|
705 | |||
689 | return 10*numpy.log10(avg) |
|
706 | return 10 * numpy.log10(avg) | |
690 |
|
707 | |||
691 | def getCoherence(self, pairsList=None, phase=False): |
|
708 | def getCoherence(self, pairsList=None, phase=False): | |
692 |
|
709 | |||
693 | z = [] |
|
710 | z = [] | |
694 | if pairsList is None: |
|
711 | if pairsList is None: | |
695 | pairsIndexList = self.pairsIndexList |
|
712 | pairsIndexList = self.pairsIndexList | |
696 | else: |
|
713 | else: | |
697 | pairsIndexList = [] |
|
714 | pairsIndexList = [] | |
698 | for pair in pairsList: |
|
715 | for pair in pairsList: | |
699 | if pair not in self.pairsList: |
|
716 | if pair not in self.pairsList: | |
700 |
raise ValueError, "Pair %s is not in dataOut.pairsList" %( |
|
717 | raise ValueError, "Pair %s is not in dataOut.pairsList" % ( | |
701 | pairsIndexList.append(self.pairsList.index(pair)) |
|
718 | pair) | |
|
719 | pairsIndexList.append(self.pairsList.index(pair)) | |||
702 | for i in range(len(pairsIndexList)): |
|
720 | for i in range(len(pairsIndexList)): | |
703 | pair = self.pairsList[pairsIndexList[i]] |
|
721 | pair = self.pairsList[pairsIndexList[i]] | |
704 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
722 | ccf = numpy.average( | |
|
723 | self.data_cspc[pairsIndexList[i], :, :], axis=0) | |||
705 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
724 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) | |
706 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
725 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) | |
707 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
726 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) | |
708 | if phase: |
|
727 | if phase: | |
709 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
728 | data = numpy.arctan2(avgcoherenceComplex.imag, | |
710 | avgcoherenceComplex.real)*180/numpy.pi |
|
729 | avgcoherenceComplex.real) * 180 / numpy.pi | |
711 | else: |
|
730 | else: | |
712 | data = numpy.abs(avgcoherenceComplex) |
|
731 | data = numpy.abs(avgcoherenceComplex) | |
713 |
|
732 | |||
714 | z.append(data) |
|
733 | z.append(data) | |
715 |
|
734 | |||
716 | return numpy.array(z) |
|
735 | return numpy.array(z) | |
717 |
|
736 | |||
718 | def setValue(self, value): |
|
737 | def setValue(self, value): | |
719 |
|
738 | |||
720 | print "This property should not be initialized" |
|
739 | print "This property should not be initialized" | |
721 |
|
740 | |||
722 | return |
|
741 | return | |
723 |
|
742 | |||
724 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
743 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") | |
725 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
744 | pairsIndexList = property( | |
726 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") |
|
745 | getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") | |
|
746 | normFactor = property(getNormFactor, setValue, | |||
|
747 | "I'm the 'getNormFactor' property.") | |||
727 | flag_cspc = property(getFlagCspc, setValue) |
|
748 | flag_cspc = property(getFlagCspc, setValue) | |
728 | flag_dc = property(getFlagDc, setValue) |
|
749 | flag_dc = property(getFlagDc, setValue) | |
729 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
750 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") | |
730 |
timeInterval = property(getTimeInterval, setValue, |
|
751 | timeInterval = property(getTimeInterval, setValue, | |
|
752 | "I'm the 'timeInterval' property") | |||
|
753 | ||||
731 |
|
754 | |||
732 | class SpectraHeis(Spectra): |
|
755 | class SpectraHeis(Spectra): | |
733 |
|
756 | |||
734 | data_spc = None |
|
757 | data_spc = None | |
735 |
|
758 | |||
736 | data_cspc = None |
|
759 | data_cspc = None | |
737 |
|
760 | |||
738 | data_dc = None |
|
761 | data_dc = None | |
739 |
|
762 | |||
740 | nFFTPoints = None |
|
763 | nFFTPoints = None | |
741 |
|
764 | |||
742 | # nPairs = None |
|
765 | # nPairs = None | |
743 |
|
766 | |||
744 | pairsList = None |
|
767 | pairsList = None | |
745 |
|
768 | |||
746 | nCohInt = None |
|
769 | nCohInt = None | |
747 |
|
770 | |||
748 | nIncohInt = None |
|
771 | nIncohInt = None | |
749 |
|
772 | |||
750 | def __init__(self): |
|
773 | def __init__(self): | |
751 |
|
774 | |||
752 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
775 | self.radarControllerHeaderObj = RadarControllerHeader() | |
753 |
|
776 | |||
754 | self.systemHeaderObj = SystemHeader() |
|
777 | self.systemHeaderObj = SystemHeader() | |
755 |
|
778 | |||
756 | self.type = "SpectraHeis" |
|
779 | self.type = "SpectraHeis" | |
757 |
|
780 | |||
758 | # self.dtype = None |
|
781 | # self.dtype = None | |
759 |
|
782 | |||
760 | # self.nChannels = 0 |
|
783 | # self.nChannels = 0 | |
761 |
|
784 | |||
762 | # self.nHeights = 0 |
|
785 | # self.nHeights = 0 | |
763 |
|
786 | |||
764 | self.nProfiles = None |
|
787 | self.nProfiles = None | |
765 |
|
788 | |||
766 | self.heightList = None |
|
789 | self.heightList = None | |
767 |
|
790 | |||
768 | self.channelList = None |
|
791 | self.channelList = None | |
769 |
|
792 | |||
770 | # self.channelIndexList = None |
|
793 | # self.channelIndexList = None | |
771 |
|
794 | |||
772 | self.flagNoData = True |
|
795 | self.flagNoData = True | |
773 |
|
796 | |||
774 | self.flagDiscontinuousBlock = False |
|
797 | self.flagDiscontinuousBlock = False | |
775 |
|
798 | |||
776 | # self.nPairs = 0 |
|
799 | # self.nPairs = 0 | |
777 |
|
800 | |||
778 | self.utctime = None |
|
801 | self.utctime = None | |
779 |
|
802 | |||
780 | self.blocksize = None |
|
803 | self.blocksize = None | |
781 |
|
804 | |||
782 | self.profileIndex = 0 |
|
805 | self.profileIndex = 0 | |
783 |
|
806 | |||
784 | self.nCohInt = 1 |
|
807 | self.nCohInt = 1 | |
785 |
|
808 | |||
786 | self.nIncohInt = 1 |
|
809 | self.nIncohInt = 1 | |
787 |
|
810 | |||
788 | def getNormFactor(self): |
|
811 | def getNormFactor(self): | |
789 | pwcode = 1 |
|
812 | pwcode = 1 | |
790 | if self.flagDecodeData: |
|
813 | if self.flagDecodeData: | |
791 | pwcode = numpy.sum(self.code[0]**2) |
|
814 | pwcode = numpy.sum(self.code[0]**2) | |
792 |
|
815 | |||
793 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
816 | normFactor = self.nIncohInt * self.nCohInt * pwcode | |
794 |
|
817 | |||
795 | return normFactor |
|
818 | return normFactor | |
796 |
|
819 | |||
797 | def getTimeInterval(self): |
|
820 | def getTimeInterval(self): | |
798 |
|
821 | |||
799 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
822 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
800 |
|
823 | |||
801 | return timeInterval |
|
824 | return timeInterval | |
802 |
|
825 | |||
803 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
826 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
804 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
827 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
805 |
|
828 | |||
|
829 | ||||
806 | class Fits(JROData): |
|
830 | class Fits(JROData): | |
807 |
|
831 | |||
808 | heightList = None |
|
832 | heightList = None | |
809 |
|
833 | |||
810 | channelList = None |
|
834 | channelList = None | |
811 |
|
835 | |||
812 | flagNoData = True |
|
836 | flagNoData = True | |
813 |
|
837 | |||
814 | flagDiscontinuousBlock = False |
|
838 | flagDiscontinuousBlock = False | |
815 |
|
839 | |||
816 | useLocalTime = False |
|
840 | useLocalTime = False | |
817 |
|
841 | |||
818 | utctime = None |
|
842 | utctime = None | |
819 |
|
843 | |||
820 | timeZone = None |
|
844 | timeZone = None | |
821 |
|
845 | |||
822 | # ippSeconds = None |
|
846 | # ippSeconds = None | |
823 |
|
847 | |||
824 | # timeInterval = None |
|
848 | # timeInterval = None | |
825 |
|
849 | |||
826 | nCohInt = None |
|
850 | nCohInt = None | |
827 |
|
851 | |||
828 | nIncohInt = None |
|
852 | nIncohInt = None | |
829 |
|
853 | |||
830 | noise = None |
|
854 | noise = None | |
831 |
|
855 | |||
832 | windowOfFilter = 1 |
|
856 | windowOfFilter = 1 | |
833 |
|
857 | |||
834 | #Speed of ligth |
|
858 | # Speed of ligth | |
835 | C = 3e8 |
|
859 | C = 3e8 | |
836 |
|
860 | |||
837 | frequency = 49.92e6 |
|
861 | frequency = 49.92e6 | |
838 |
|
862 | |||
839 | realtime = False |
|
863 | realtime = False | |
840 |
|
864 | |||
841 |
|
||||
842 | def __init__(self): |
|
865 | def __init__(self): | |
843 |
|
866 | |||
844 | self.type = "Fits" |
|
867 | self.type = "Fits" | |
845 |
|
868 | |||
846 | self.nProfiles = None |
|
869 | self.nProfiles = None | |
847 |
|
870 | |||
848 | self.heightList = None |
|
871 | self.heightList = None | |
849 |
|
872 | |||
850 | self.channelList = None |
|
873 | self.channelList = None | |
851 |
|
874 | |||
852 | # self.channelIndexList = None |
|
875 | # self.channelIndexList = None | |
853 |
|
876 | |||
854 | self.flagNoData = True |
|
877 | self.flagNoData = True | |
855 |
|
878 | |||
856 | self.utctime = None |
|
879 | self.utctime = None | |
857 |
|
880 | |||
858 | self.nCohInt = 1 |
|
881 | self.nCohInt = 1 | |
859 |
|
882 | |||
860 | self.nIncohInt = 1 |
|
883 | self.nIncohInt = 1 | |
861 |
|
884 | |||
862 | self.useLocalTime = True |
|
885 | self.useLocalTime = True | |
863 |
|
886 | |||
864 | self.profileIndex = 0 |
|
887 | self.profileIndex = 0 | |
865 |
|
888 | |||
866 | # self.utctime = None |
|
889 | # self.utctime = None | |
867 | # self.timeZone = None |
|
890 | # self.timeZone = None | |
868 | # self.ltctime = None |
|
891 | # self.ltctime = None | |
869 | # self.timeInterval = None |
|
892 | # self.timeInterval = None | |
870 | # self.header = None |
|
893 | # self.header = None | |
871 | # self.data_header = None |
|
894 | # self.data_header = None | |
872 | # self.data = None |
|
895 | # self.data = None | |
873 | # self.datatime = None |
|
896 | # self.datatime = None | |
874 | # self.flagNoData = False |
|
897 | # self.flagNoData = False | |
875 | # self.expName = '' |
|
898 | # self.expName = '' | |
876 | # self.nChannels = None |
|
899 | # self.nChannels = None | |
877 | # self.nSamples = None |
|
900 | # self.nSamples = None | |
878 | # self.dataBlocksPerFile = None |
|
901 | # self.dataBlocksPerFile = None | |
879 | # self.comments = '' |
|
902 | # self.comments = '' | |
880 | # |
|
903 | # | |
881 |
|
904 | |||
882 |
|
||||
883 | def getltctime(self): |
|
905 | def getltctime(self): | |
884 |
|
906 | |||
885 | if self.useLocalTime: |
|
907 | if self.useLocalTime: | |
886 | return self.utctime - self.timeZone*60 |
|
908 | return self.utctime - self.timeZone * 60 | |
887 |
|
909 | |||
888 | return self.utctime |
|
910 | return self.utctime | |
889 |
|
911 | |||
890 | def getDatatime(self): |
|
912 | def getDatatime(self): | |
891 |
|
913 | |||
892 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
914 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
893 | return datatime |
|
915 | return datatime | |
894 |
|
916 | |||
895 | def getTimeRange(self): |
|
917 | def getTimeRange(self): | |
896 |
|
918 | |||
897 | datatime = [] |
|
919 | datatime = [] | |
898 |
|
920 | |||
899 | datatime.append(self.ltctime) |
|
921 | datatime.append(self.ltctime) | |
900 | datatime.append(self.ltctime + self.timeInterval) |
|
922 | datatime.append(self.ltctime + self.timeInterval) | |
901 |
|
923 | |||
902 | datatime = numpy.array(datatime) |
|
924 | datatime = numpy.array(datatime) | |
903 |
|
925 | |||
904 | return datatime |
|
926 | return datatime | |
905 |
|
927 | |||
906 | def getHeiRange(self): |
|
928 | def getHeiRange(self): | |
907 |
|
929 | |||
908 | heis = self.heightList |
|
930 | heis = self.heightList | |
909 |
|
931 | |||
910 | return heis |
|
932 | return heis | |
911 |
|
933 | |||
912 | def getNHeights(self): |
|
934 | def getNHeights(self): | |
913 |
|
935 | |||
914 | return len(self.heightList) |
|
936 | return len(self.heightList) | |
915 |
|
937 | |||
916 | def getNChannels(self): |
|
938 | def getNChannels(self): | |
917 |
|
939 | |||
918 | return len(self.channelList) |
|
940 | return len(self.channelList) | |
919 |
|
941 | |||
920 | def getChannelIndexList(self): |
|
942 | def getChannelIndexList(self): | |
921 |
|
943 | |||
922 | return range(self.nChannels) |
|
944 | return range(self.nChannels) | |
923 |
|
945 | |||
924 |
def getNoise(self, type |
|
946 | def getNoise(self, type=1): | |
925 |
|
947 | |||
926 | #noise = numpy.zeros(self.nChannels) |
|
948 | #noise = numpy.zeros(self.nChannels) | |
927 |
|
949 | |||
928 | if type == 1: |
|
950 | if type == 1: | |
929 | noise = self.getNoisebyHildebrand() |
|
951 | noise = self.getNoisebyHildebrand() | |
930 |
|
952 | |||
931 | if type == 2: |
|
953 | if type == 2: | |
932 | noise = self.getNoisebySort() |
|
954 | noise = self.getNoisebySort() | |
933 |
|
955 | |||
934 | if type == 3: |
|
956 | if type == 3: | |
935 | noise = self.getNoisebyWindow() |
|
957 | noise = self.getNoisebyWindow() | |
936 |
|
958 | |||
937 | return noise |
|
959 | return noise | |
938 |
|
960 | |||
939 | def getTimeInterval(self): |
|
961 | def getTimeInterval(self): | |
940 |
|
962 | |||
941 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
963 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
942 |
|
964 | |||
943 | return timeInterval |
|
965 | return timeInterval | |
944 |
|
966 | |||
945 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
967 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
946 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
968 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
947 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
969 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
948 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
970 | channelIndexList = property( | |
|
971 | getChannelIndexList, "I'm the 'channelIndexList' property.") | |||
949 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
972 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
950 |
|
973 | |||
951 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
974 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
952 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
975 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
953 |
|
976 | |||
954 |
|
977 | |||
955 | class Correlation(JROData): |
|
978 | class Correlation(JROData): | |
956 |
|
979 | |||
957 | noise = None |
|
980 | noise = None | |
958 |
|
981 | |||
959 | SNR = None |
|
982 | SNR = None | |
960 |
|
983 | |||
961 | #-------------------------------------------------- |
|
984 | #-------------------------------------------------- | |
962 |
|
985 | |||
963 | mode = None |
|
986 | mode = None | |
964 |
|
987 | |||
965 | split = False |
|
988 | split = False | |
966 |
|
989 | |||
967 | data_cf = None |
|
990 | data_cf = None | |
968 |
|
991 | |||
969 | lags = None |
|
992 | lags = None | |
970 |
|
993 | |||
971 | lagRange = None |
|
994 | lagRange = None | |
972 |
|
995 | |||
973 | pairsList = None |
|
996 | pairsList = None | |
974 |
|
997 | |||
975 | normFactor = None |
|
998 | normFactor = None | |
976 |
|
999 | |||
977 | #-------------------------------------------------- |
|
1000 | #-------------------------------------------------- | |
978 |
|
1001 | |||
979 | # calculateVelocity = None |
|
1002 | # calculateVelocity = None | |
980 |
|
1003 | |||
981 | nLags = None |
|
1004 | nLags = None | |
982 |
|
1005 | |||
983 | nPairs = None |
|
1006 | nPairs = None | |
984 |
|
1007 | |||
985 | nAvg = None |
|
1008 | nAvg = None | |
986 |
|
1009 | |||
987 |
|
||||
988 | def __init__(self): |
|
1010 | def __init__(self): | |
989 | ''' |
|
1011 | ''' | |
990 | Constructor |
|
1012 | Constructor | |
991 | ''' |
|
1013 | ''' | |
992 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1014 | self.radarControllerHeaderObj = RadarControllerHeader() | |
993 |
|
1015 | |||
994 | self.systemHeaderObj = SystemHeader() |
|
1016 | self.systemHeaderObj = SystemHeader() | |
995 |
|
1017 | |||
996 | self.type = "Correlation" |
|
1018 | self.type = "Correlation" | |
997 |
|
1019 | |||
998 | self.data = None |
|
1020 | self.data = None | |
999 |
|
1021 | |||
1000 | self.dtype = None |
|
1022 | self.dtype = None | |
1001 |
|
1023 | |||
1002 | self.nProfiles = None |
|
1024 | self.nProfiles = None | |
1003 |
|
1025 | |||
1004 | self.heightList = None |
|
1026 | self.heightList = None | |
1005 |
|
1027 | |||
1006 | self.channelList = None |
|
1028 | self.channelList = None | |
1007 |
|
1029 | |||
1008 | self.flagNoData = True |
|
1030 | self.flagNoData = True | |
1009 |
|
1031 | |||
1010 | self.flagDiscontinuousBlock = False |
|
1032 | self.flagDiscontinuousBlock = False | |
1011 |
|
1033 | |||
1012 | self.utctime = None |
|
1034 | self.utctime = None | |
1013 |
|
1035 | |||
1014 | self.timeZone = None |
|
1036 | self.timeZone = None | |
1015 |
|
1037 | |||
1016 | self.dstFlag = None |
|
1038 | self.dstFlag = None | |
1017 |
|
1039 | |||
1018 | self.errorCount = None |
|
1040 | self.errorCount = None | |
1019 |
|
1041 | |||
1020 | self.blocksize = None |
|
1042 | self.blocksize = None | |
1021 |
|
1043 | |||
1022 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
1044 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
1023 |
|
1045 | |||
1024 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
1046 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
1025 |
|
1047 | |||
1026 | self.pairsList = None |
|
1048 | self.pairsList = None | |
1027 |
|
1049 | |||
1028 | self.nPoints = None |
|
1050 | self.nPoints = None | |
1029 |
|
1051 | |||
1030 | def getPairsList(self): |
|
1052 | def getPairsList(self): | |
1031 |
|
1053 | |||
1032 | return self.pairsList |
|
1054 | return self.pairsList | |
1033 |
|
1055 | |||
1034 |
def getNoise(self, mode |
|
1056 | def getNoise(self, mode=2): | |
1035 |
|
1057 | |||
1036 | indR = numpy.where(self.lagR == 0)[0][0] |
|
1058 | indR = numpy.where(self.lagR == 0)[0][0] | |
1037 | indT = numpy.where(self.lagT == 0)[0][0] |
|
1059 | indT = numpy.where(self.lagT == 0)[0][0] | |
1038 |
|
1060 | |||
1039 | jspectra0 = self.data_corr[:,:,indR,:] |
|
1061 | jspectra0 = self.data_corr[:, :, indR, :] | |
1040 | jspectra = copy.copy(jspectra0) |
|
1062 | jspectra = copy.copy(jspectra0) | |
1041 |
|
1063 | |||
1042 | num_chan = jspectra.shape[0] |
|
1064 | num_chan = jspectra.shape[0] | |
1043 | num_hei = jspectra.shape[2] |
|
1065 | num_hei = jspectra.shape[2] | |
1044 |
|
1066 | |||
1045 | freq_dc = jspectra.shape[1]/2 |
|
1067 | freq_dc = jspectra.shape[1] / 2 | |
1046 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1068 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
1047 |
|
1069 | |||
1048 | if ind_vel[0]<0: |
|
1070 | if ind_vel[0] < 0: | |
1049 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1071 | ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof | |
1050 |
|
1072 | |||
1051 | if mode == 1: |
|
1073 | if mode == 1: | |
1052 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1074 | jspectra[:, freq_dc, :] = ( | |
|
1075 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |||
1053 |
|
1076 | |||
1054 | if mode == 2: |
|
1077 | if mode == 2: | |
1055 |
|
1078 | |||
1056 | vel = numpy.array([-2,-1,1,2]) |
|
1079 | vel = numpy.array([-2, -1, 1, 2]) | |
1057 | xx = numpy.zeros([4,4]) |
|
1080 | xx = numpy.zeros([4, 4]) | |
1058 |
|
1081 | |||
1059 | for fil in range(4): |
|
1082 | for fil in range(4): | |
1060 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1083 | xx[fil, :] = vel[fil]**numpy.asarray(range(4)) | |
1061 |
|
1084 | |||
1062 | xx_inv = numpy.linalg.inv(xx) |
|
1085 | xx_inv = numpy.linalg.inv(xx) | |
1063 | xx_aux = xx_inv[0,:] |
|
1086 | xx_aux = xx_inv[0, :] | |
1064 |
|
1087 | |||
1065 | for ich in range(num_chan): |
|
1088 | for ich in range(num_chan): | |
1066 | yy = jspectra[ich,ind_vel,:] |
|
1089 | yy = jspectra[ich, ind_vel, :] | |
1067 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1090 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) | |
1068 |
|
1091 | |||
1069 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1092 | junkid = jspectra[ich, freq_dc, :] <= 0 | |
1070 | cjunkid = sum(junkid) |
|
1093 | cjunkid = sum(junkid) | |
1071 |
|
1094 | |||
1072 | if cjunkid.any(): |
|
1095 | if cjunkid.any(): | |
1073 |
jspectra[ich,freq_dc,junkid.nonzero()] = ( |
|
1096 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
|
1097 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |||
1074 |
|
1098 | |||
1075 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
1099 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] | |
1076 |
|
1100 | |||
1077 | return noise |
|
1101 | return noise | |
1078 |
|
1102 | |||
1079 | def getTimeInterval(self): |
|
1103 | def getTimeInterval(self): | |
1080 |
|
1104 | |||
1081 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
1105 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles | |
1082 |
|
1106 | |||
1083 | return timeInterval |
|
1107 | return timeInterval | |
1084 |
|
1108 | |||
1085 | def splitFunctions(self): |
|
1109 | def splitFunctions(self): | |
1086 |
|
1110 | |||
1087 | pairsList = self.pairsList |
|
1111 | pairsList = self.pairsList | |
1088 | ccf_pairs = [] |
|
1112 | ccf_pairs = [] | |
1089 | acf_pairs = [] |
|
1113 | acf_pairs = [] | |
1090 | ccf_ind = [] |
|
1114 | ccf_ind = [] | |
1091 | acf_ind = [] |
|
1115 | acf_ind = [] | |
1092 | for l in range(len(pairsList)): |
|
1116 | for l in range(len(pairsList)): | |
1093 | chan0 = pairsList[l][0] |
|
1117 | chan0 = pairsList[l][0] | |
1094 | chan1 = pairsList[l][1] |
|
1118 | chan1 = pairsList[l][1] | |
1095 |
|
1119 | |||
1096 | #Obteniendo pares de Autocorrelacion |
|
1120 | # Obteniendo pares de Autocorrelacion | |
1097 | if chan0 == chan1: |
|
1121 | if chan0 == chan1: | |
1098 | acf_pairs.append(chan0) |
|
1122 | acf_pairs.append(chan0) | |
1099 | acf_ind.append(l) |
|
1123 | acf_ind.append(l) | |
1100 | else: |
|
1124 | else: | |
1101 | ccf_pairs.append(pairsList[l]) |
|
1125 | ccf_pairs.append(pairsList[l]) | |
1102 | ccf_ind.append(l) |
|
1126 | ccf_ind.append(l) | |
1103 |
|
1127 | |||
1104 | data_acf = self.data_cf[acf_ind] |
|
1128 | data_acf = self.data_cf[acf_ind] | |
1105 | data_ccf = self.data_cf[ccf_ind] |
|
1129 | data_ccf = self.data_cf[ccf_ind] | |
1106 |
|
1130 | |||
1107 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1131 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf | |
1108 |
|
1132 | |||
1109 | def getNormFactor(self): |
|
1133 | def getNormFactor(self): | |
1110 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1134 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() | |
1111 | acf_pairs = numpy.array(acf_pairs) |
|
1135 | acf_pairs = numpy.array(acf_pairs) | |
1112 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) |
|
1136 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) | |
1113 |
|
1137 | |||
1114 | for p in range(self.nPairs): |
|
1138 | for p in range(self.nPairs): | |
1115 | pair = self.pairsList[p] |
|
1139 | pair = self.pairsList[p] | |
1116 |
|
1140 | |||
1117 | ch0 = pair[0] |
|
1141 | ch0 = pair[0] | |
1118 | ch1 = pair[1] |
|
1142 | ch1 = pair[1] | |
1119 |
|
1143 | |||
1120 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) |
|
1144 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) | |
1121 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) |
|
1145 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) | |
1122 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) |
|
1146 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) | |
1123 |
|
1147 | |||
1124 | return normFactor |
|
1148 | return normFactor | |
1125 |
|
1149 | |||
1126 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1150 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
1127 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1151 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") | |
1128 |
|
1152 | |||
|
1153 | ||||
1129 | class Parameters(Spectra): |
|
1154 | class Parameters(Spectra): | |
1130 |
|
1155 | |||
1131 |
experimentInfo = None |
|
1156 | experimentInfo = None # Information about the experiment | |
1132 |
|
1157 | |||
1133 | #Information from previous data |
|
1158 | # Information from previous data | |
1134 |
|
1159 | |||
1135 |
inputUnit = None |
|
1160 | inputUnit = None # Type of data to be processed | |
1136 |
|
1161 | |||
1137 |
operation = None |
|
1162 | operation = None # Type of operation to parametrize | |
1138 |
|
1163 | |||
1139 | #normFactor = None #Normalization Factor |
|
1164 | # normFactor = None #Normalization Factor | |
1140 |
|
1165 | |||
1141 |
groupList = None |
|
1166 | groupList = None # List of Pairs, Groups, etc | |
1142 |
|
1167 | |||
1143 | #Parameters |
|
1168 | # Parameters | |
1144 |
|
1169 | |||
1145 |
data_param = None |
|
1170 | data_param = None # Parameters obtained | |
1146 |
|
1171 | |||
1147 |
data_pre = None |
|
1172 | data_pre = None # Data Pre Parametrization | |
1148 |
|
1173 | |||
1149 |
data_SNR = None |
|
1174 | data_SNR = None # Signal to Noise Ratio | |
1150 |
|
1175 | |||
1151 | # heightRange = None #Heights |
|
1176 | # heightRange = None #Heights | |
1152 |
|
1177 | |||
1153 |
abscissaList = None |
|
1178 | abscissaList = None # Abscissa, can be velocities, lags or time | |
1154 |
|
1179 | |||
1155 | # noise = None #Noise Potency |
|
1180 | # noise = None #Noise Potency | |
1156 |
|
1181 | |||
1157 |
utctimeInit = None |
|
1182 | utctimeInit = None # Initial UTC time | |
1158 |
|
1183 | |||
1159 |
paramInterval = None |
|
1184 | paramInterval = None # Time interval to calculate Parameters in seconds | |
1160 |
|
1185 | |||
1161 | useLocalTime = True |
|
1186 | useLocalTime = True | |
1162 |
|
1187 | |||
1163 | #Fitting |
|
1188 | # Fitting | |
1164 |
|
1189 | |||
1165 |
data_error = None |
|
1190 | data_error = None # Error of the estimation | |
1166 |
|
1191 | |||
1167 | constants = None |
|
1192 | constants = None | |
1168 |
|
1193 | |||
1169 | library = None |
|
1194 | library = None | |
1170 |
|
1195 | |||
1171 | #Output signal |
|
1196 | # Output signal | |
1172 |
|
1197 | |||
1173 |
outputInterval = None |
|
1198 | outputInterval = None # Time interval to calculate output signal in seconds | |
1174 |
|
1199 | |||
1175 |
data_output = None |
|
1200 | data_output = None # Out signal | |
1176 |
|
1201 | |||
1177 | nAvg = None |
|
1202 | nAvg = None | |
1178 |
|
1203 | |||
1179 | noise_estimation = None |
|
1204 | noise_estimation = None | |
1180 |
|
||||
1181 | GauSPC = None #Fit gaussian SPC |
|
|||
1182 |
|
1205 | |||
|
1206 | GauSPC = None # Fit gaussian SPC | |||
1183 |
|
1207 | |||
1184 | def __init__(self): |
|
1208 | def __init__(self): | |
1185 | ''' |
|
1209 | ''' | |
1186 | Constructor |
|
1210 | Constructor | |
1187 | ''' |
|
1211 | ''' | |
1188 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1212 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1189 |
|
1213 | |||
1190 | self.systemHeaderObj = SystemHeader() |
|
1214 | self.systemHeaderObj = SystemHeader() | |
1191 |
|
1215 | |||
1192 | self.type = "Parameters" |
|
1216 | self.type = "Parameters" | |
1193 |
|
1217 | |||
1194 | def getTimeRange1(self, interval): |
|
1218 | def getTimeRange1(self, interval): | |
1195 |
|
1219 | |||
1196 | datatime = [] |
|
1220 | datatime = [] | |
1197 |
|
1221 | |||
1198 | if self.useLocalTime: |
|
1222 | if self.useLocalTime: | |
1199 | time1 = self.utctimeInit - self.timeZone*60 |
|
1223 | time1 = self.utctimeInit - self.timeZone * 60 | |
1200 | else: |
|
1224 | else: | |
1201 | time1 = self.utctimeInit |
|
1225 | time1 = self.utctimeInit | |
1202 |
|
1226 | |||
1203 | datatime.append(time1) |
|
1227 | datatime.append(time1) | |
1204 | datatime.append(time1 + interval) |
|
1228 | datatime.append(time1 + interval) | |
1205 | datatime = numpy.array(datatime) |
|
1229 | datatime = numpy.array(datatime) | |
1206 |
|
1230 | |||
1207 | return datatime |
|
1231 | return datatime | |
1208 |
|
1232 | |||
1209 | def getTimeInterval(self): |
|
1233 | def getTimeInterval(self): | |
1210 |
|
1234 | |||
1211 | if hasattr(self, 'timeInterval1'): |
|
1235 | if hasattr(self, 'timeInterval1'): | |
1212 | return self.timeInterval1 |
|
1236 | return self.timeInterval1 | |
1213 | else: |
|
1237 | else: | |
1214 | return self.paramInterval |
|
1238 | return self.paramInterval | |
1215 |
|
1239 | |||
1216 | def setValue(self, value): |
|
1240 | def setValue(self, value): | |
1217 |
|
1241 | |||
1218 | print "This property should not be initialized" |
|
1242 | print "This property should not be initialized" | |
1219 |
|
1243 | |||
1220 | return |
|
1244 | return | |
1221 |
|
1245 | |||
1222 | def getNoise(self): |
|
1246 | def getNoise(self): | |
1223 |
|
1247 | |||
1224 | return self.spc_noise |
|
1248 | return self.spc_noise | |
1225 |
|
1249 | |||
1226 | timeInterval = property(getTimeInterval) |
|
1250 | timeInterval = property(getTimeInterval) | |
1227 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") |
|
1251 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") |
@@ -1,751 +1,790 | |||||
1 |
|
1 | |||
2 | ''' |
|
2 | ''' | |
3 | Created on Jul 3, 2014 |
|
3 | Created on Jul 3, 2014 | |
4 |
|
4 | |||
5 | @author: roj-idl71 |
|
5 | @author: roj-idl71 | |
6 | ''' |
|
6 | ''' | |
7 | # SUBCHANNELS EN VEZ DE CHANNELS |
|
7 | # SUBCHANNELS EN VEZ DE CHANNELS | |
8 | # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO |
|
8 | # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO | |
9 | # ACTUALIZACION DE VERSION |
|
9 | # ACTUALIZACION DE VERSION | |
10 | # HEADERS |
|
10 | # HEADERS | |
11 | # MODULO DE ESCRITURA |
|
11 | # MODULO DE ESCRITURA | |
12 | # METADATA |
|
12 | # METADATA | |
13 |
|
13 | |||
14 | import os |
|
14 | import os | |
15 | import datetime |
|
15 | import datetime | |
16 | import numpy |
|
16 | import numpy | |
17 | import timeit |
|
17 | import timeit | |
18 | from profilehooks import coverage, profile |
|
|||
19 | from fractions import Fraction |
|
18 | from fractions import Fraction | |
20 |
|
19 | |||
21 | try: |
|
20 | try: | |
22 | from gevent import sleep |
|
21 | from gevent import sleep | |
23 | except: |
|
22 | except: | |
24 | from time import sleep |
|
23 | from time import sleep | |
25 |
|
24 | |||
26 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader |
|
25 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
27 | from schainpy.model.data.jrodata import Voltage |
|
26 | from schainpy.model.data.jrodata import Voltage | |
28 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
27 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
29 | from time import time |
|
28 | from time import time | |
30 |
|
29 | |||
31 | import cPickle |
|
30 | import cPickle | |
32 | try: |
|
31 | try: | |
33 | import digital_rf |
|
32 | import digital_rf | |
34 | except: |
|
33 | except: | |
35 | print 'You should install "digital_rf" module if you want to read Digital RF data' |
|
34 | print 'You should install "digital_rf" module if you want to read Digital RF data' | |
36 |
|
35 | |||
|
36 | ||||
37 | class DigitalRFReader(ProcessingUnit): |
|
37 | class DigitalRFReader(ProcessingUnit): | |
38 | ''' |
|
38 | ''' | |
39 | classdocs |
|
39 | classdocs | |
40 | ''' |
|
40 | ''' | |
41 |
|
41 | |||
42 | def __init__(self, **kwargs): |
|
42 | def __init__(self, **kwargs): | |
43 | ''' |
|
43 | ''' | |
44 | Constructor |
|
44 | Constructor | |
45 | ''' |
|
45 | ''' | |
46 |
|
46 | |||
47 | ProcessingUnit.__init__(self, **kwargs) |
|
47 | ProcessingUnit.__init__(self, **kwargs) | |
48 |
|
48 | |||
49 | self.dataOut = Voltage() |
|
49 | self.dataOut = Voltage() | |
50 | self.__printInfo = True |
|
50 | self.__printInfo = True | |
51 | self.__flagDiscontinuousBlock = False |
|
51 | self.__flagDiscontinuousBlock = False | |
52 | self.__bufferIndex = 9999999 |
|
52 | self.__bufferIndex = 9999999 | |
53 | self.__ippKm = None |
|
53 | self.__ippKm = None | |
54 | self.__codeType = 0 |
|
54 | self.__codeType = 0 | |
55 | self.__nCode = None |
|
55 | self.__nCode = None | |
56 | self.__nBaud = None |
|
56 | self.__nBaud = None | |
57 | self.__code = None |
|
57 | self.__code = None | |
58 | self.dtype = None |
|
58 | self.dtype = None | |
59 |
|
59 | |||
60 | def close(self): |
|
60 | def close(self): | |
61 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 |
|
61 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 | |
62 | return |
|
62 | return | |
63 |
|
63 | |||
64 | def __getCurrentSecond(self): |
|
64 | def __getCurrentSecond(self): | |
65 |
|
65 | |||
66 | return self.__thisUnixSample/self.__sample_rate |
|
66 | return self.__thisUnixSample / self.__sample_rate | |
67 |
|
67 | |||
68 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") |
|
68 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") | |
69 |
|
69 | |||
70 | def __setFileHeader(self): |
|
70 | def __setFileHeader(self): | |
71 | ''' |
|
71 | ''' | |
72 | In this method will be initialized every parameter of dataOut object (header, no data) |
|
72 | In this method will be initialized every parameter of dataOut object (header, no data) | |
73 | ''' |
|
73 | ''' | |
74 | ippSeconds = 1.0*self.__nSamples/self.__sample_rate |
|
74 | ippSeconds = 1.0 * self.__nSamples / self.__sample_rate | |
|
75 | ||||
|
76 | nProfiles = 1.0 / ippSeconds # Number of profiles in one second | |||
75 |
|
77 | |||
76 | nProfiles = 1.0/ippSeconds # Number of profiles in one second |
|
|||
77 |
|
||||
78 | try: |
|
78 | try: | |
79 |
self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
79 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
|
80 | self.__radarControllerHeader) | |||
80 | except: |
|
81 | except: | |
81 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
82 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
82 | txA=0, |
|
83 | txA=0, | |
83 | txB=0, |
|
84 | txB=0, | |
84 | nWindows=1, |
|
85 | nWindows=1, | |
85 | nHeights=self.__nSamples, |
|
86 | nHeights=self.__nSamples, | |
86 |
|
|
87 | firstHeight=self.__firstHeigth, | |
87 |
|
|
88 | deltaHeight=self.__deltaHeigth, | |
88 | codeType=self.__codeType, |
|
89 | codeType=self.__codeType, | |
89 |
|
|
90 | nCode=self.__nCode, nBaud=self.__nBaud, | |
90 | code = self.__code) |
|
91 | code=self.__code) | |
91 |
|
92 | |||
92 | try: |
|
93 | try: | |
93 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) |
|
94 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) | |
94 | except: |
|
95 | except: | |
95 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, |
|
96 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, | |
96 | nProfiles=nProfiles, |
|
97 | nProfiles=nProfiles, | |
97 |
nChannels=len( |
|
98 | nChannels=len( | |
|
99 | self.__channelList), | |||
98 | adcResolution=14) |
|
100 | adcResolution=14) | |
99 | self.dataOut.type = "Voltage" |
|
101 | self.dataOut.type = "Voltage" | |
100 |
|
102 | |||
101 | self.dataOut.data = None |
|
103 | self.dataOut.data = None | |
102 |
|
104 | |||
103 | self.dataOut.dtype = self.dtype |
|
105 | self.dataOut.dtype = self.dtype | |
104 |
|
106 | |||
105 | # self.dataOut.nChannels = 0 |
|
107 | # self.dataOut.nChannels = 0 | |
106 |
|
108 | |||
107 | # self.dataOut.nHeights = 0 |
|
109 | # self.dataOut.nHeights = 0 | |
108 |
|
110 | |||
109 | self.dataOut.nProfiles = int(nProfiles) |
|
111 | self.dataOut.nProfiles = int(nProfiles) | |
110 |
|
112 | |||
111 |
self.dataOut.heightList = self.__firstHeigth + |
|
113 | self.dataOut.heightList = self.__firstHeigth + \ | |
|
114 | numpy.arange(self.__nSamples, dtype=numpy.float) * \ | |||
|
115 | self.__deltaHeigth | |||
112 |
|
116 | |||
113 | self.dataOut.channelList = range(self.__num_subchannels) |
|
117 | self.dataOut.channelList = range(self.__num_subchannels) | |
114 |
|
118 | |||
115 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() |
|
119 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
116 |
|
120 | |||
117 | # self.dataOut.channelIndexList = None |
|
121 | # self.dataOut.channelIndexList = None | |
118 |
|
122 | |||
119 | self.dataOut.flagNoData = True |
|
123 | self.dataOut.flagNoData = True | |
120 |
|
124 | |||
121 | self.dataOut.flagDataAsBlock = False |
|
125 | self.dataOut.flagDataAsBlock = False | |
122 | # Set to TRUE if the data is discontinuous |
|
126 | # Set to TRUE if the data is discontinuous | |
123 | self.dataOut.flagDiscontinuousBlock = False |
|
127 | self.dataOut.flagDiscontinuousBlock = False | |
124 |
|
128 | |||
125 | self.dataOut.utctime = None |
|
129 | self.dataOut.utctime = None | |
126 |
|
130 | |||
127 |
|
|
131 | # timezone like jroheader, difference in minutes between UTC and localtime | |
|
132 | self.dataOut.timeZone = self.__timezone / 60 | |||
128 |
|
133 | |||
129 | self.dataOut.dstFlag = 0 |
|
134 | self.dataOut.dstFlag = 0 | |
130 |
|
135 | |||
131 | self.dataOut.errorCount = 0 |
|
136 | self.dataOut.errorCount = 0 | |
132 |
|
137 | |||
133 | try: |
|
138 | try: | |
134 |
self.dataOut.nCohInt = self.fixed_metadata_dict.get( |
|
139 | self.dataOut.nCohInt = self.fixed_metadata_dict.get( | |
|
140 | 'nCohInt', self.nCohInt) | |||
135 |
|
141 | |||
136 | self.dataOut.flagDecodeData = self.fixed_metadata_dict['flagDecodeData'] # asumo que la data esta decodificada |
|
142 | # asumo que la data esta decodificada | |
|
143 | self.dataOut.flagDecodeData = self.fixed_metadata_dict.get( | |||
|
144 | 'flagDecodeData', self.flagDecodeData) | |||
137 |
|
145 | |||
138 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] # asumo que la data esta sin flip |
|
146 | # asumo que la data esta sin flip | |
|
147 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] | |||
139 |
|
148 | |||
140 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] |
|
149 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] | |
141 |
|
150 | |||
142 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] |
|
151 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] | |
143 | except: |
|
152 | except: | |
144 | pass |
|
153 | pass | |
145 |
|
||||
146 |
|
154 | |||
147 | self.dataOut.ippSeconds = ippSeconds |
|
155 | self.dataOut.ippSeconds = ippSeconds | |
148 |
|
156 | |||
149 | # Time interval between profiles |
|
157 | # Time interval between profiles | |
150 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
158 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
151 |
|
159 | |||
152 | self.dataOut.frequency = self.__frequency |
|
160 | self.dataOut.frequency = self.__frequency | |
153 |
|
161 | |||
154 | self.dataOut.realtime = self.__online |
|
162 | self.dataOut.realtime = self.__online | |
155 |
|
163 | |||
156 | def findDatafiles(self, path, startDate=None, endDate=None): |
|
164 | def findDatafiles(self, path, startDate=None, endDate=None): | |
157 |
|
165 | |||
158 | if not os.path.isdir(path): |
|
166 | if not os.path.isdir(path): | |
159 | return [] |
|
167 | return [] | |
160 |
|
168 | |||
161 | try: |
|
169 | try: | |
162 |
digitalReadObj = digital_rf.DigitalRFReader( |
|
170 | digitalReadObj = digital_rf.DigitalRFReader( | |
|
171 | path, load_all_metadata=True) | |||
163 | except: |
|
172 | except: | |
164 | digitalReadObj = digital_rf.DigitalRFReader(path) |
|
173 | digitalReadObj = digital_rf.DigitalRFReader(path) | |
165 |
|
174 | |||
166 | channelNameList = digitalReadObj.get_channels() |
|
175 | channelNameList = digitalReadObj.get_channels() | |
167 |
|
176 | |||
168 | if not channelNameList: |
|
177 | if not channelNameList: | |
169 | return [] |
|
178 | return [] | |
170 |
|
179 | |||
171 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) |
|
180 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) | |
172 |
|
181 | |||
173 | sample_rate = metadata_dict['sample_rate'][0] |
|
182 | sample_rate = metadata_dict['sample_rate'][0] | |
174 |
|
183 | |||
175 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) |
|
184 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) | |
176 |
|
185 | |||
177 | try: |
|
186 | try: | |
178 | timezone = this_metadata_file['timezone'].value |
|
187 | timezone = this_metadata_file['timezone'].value | |
179 | except: |
|
188 | except: | |
180 | timezone = 0 |
|
189 | timezone = 0 | |
181 |
|
190 | |||
182 |
startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( |
|
191 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( | |
|
192 | channelNameList[0]) / sample_rate - timezone | |||
183 |
|
193 | |||
184 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) |
|
194 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) | |
185 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) |
|
195 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) | |
186 |
|
196 | |||
187 | if not startDate: |
|
197 | if not startDate: | |
188 | startDate = startDatetime.date() |
|
198 | startDate = startDatetime.date() | |
189 |
|
199 | |||
190 | if not endDate: |
|
200 | if not endDate: | |
191 | endDate = endDatatime.date() |
|
201 | endDate = endDatatime.date() | |
192 |
|
202 | |||
193 | dateList = [] |
|
203 | dateList = [] | |
194 |
|
204 | |||
195 | thisDatetime = startDatetime |
|
205 | thisDatetime = startDatetime | |
196 |
|
206 | |||
197 | while(thisDatetime<=endDatatime): |
|
207 | while(thisDatetime <= endDatatime): | |
198 |
|
208 | |||
199 | thisDate = thisDatetime.date() |
|
209 | thisDate = thisDatetime.date() | |
200 |
|
210 | |||
201 | if thisDate < startDate: |
|
211 | if thisDate < startDate: | |
202 | continue |
|
212 | continue | |
203 |
|
213 | |||
204 | if thisDate > endDate: |
|
214 | if thisDate > endDate: | |
205 | break |
|
215 | break | |
206 |
|
216 | |||
207 | dateList.append(thisDate) |
|
217 | dateList.append(thisDate) | |
208 | thisDatetime += datetime.timedelta(1) |
|
218 | thisDatetime += datetime.timedelta(1) | |
209 |
|
219 | |||
210 | return dateList |
|
220 | return dateList | |
211 |
|
221 | |||
212 |
def setup(self, path |
|
222 | def setup(self, path=None, | |
213 |
|
|
223 | startDate=None, | |
214 |
|
|
224 | endDate=None, | |
215 |
|
|
225 | startTime=datetime.time(0, 0, 0), | |
216 |
|
|
226 | endTime=datetime.time(23, 59, 59), | |
217 |
|
|
227 | channelList=None, | |
218 |
|
|
228 | nSamples=None, | |
219 |
|
|
229 | online=False, | |
220 |
|
|
230 | delay=60, | |
221 |
|
|
231 | buffer_size=1024, | |
222 |
|
|
232 | ippKm=None, | |
223 | **kwargs): |
|
233 | nCohInt=1, | |
|
234 | nCode=1, | |||
|
235 | nBaud=1, | |||
|
236 | flagDecodeData=False, | |||
|
237 | code=numpy.ones((1, 1), dtype=numpy.int), | |||
|
238 | **kwargs): | |||
224 | ''' |
|
239 | ''' | |
225 | In this method we should set all initial parameters. |
|
240 | In this method we should set all initial parameters. | |
226 |
|
241 | |||
227 | Inputs: |
|
242 | Inputs: | |
228 | path |
|
243 | path | |
229 | startDate |
|
244 | startDate | |
230 | endDate |
|
245 | endDate | |
231 | startTime |
|
246 | startTime | |
232 | endTime |
|
247 | endTime | |
233 | set |
|
248 | set | |
234 | expLabel |
|
249 | expLabel | |
235 | ext |
|
250 | ext | |
236 | online |
|
251 | online | |
237 | delay |
|
252 | delay | |
238 | ''' |
|
253 | ''' | |
|
254 | self.nCohInt = nCohInt | |||
|
255 | self.flagDecodeData = flagDecodeData | |||
239 | self.i = 0 |
|
256 | self.i = 0 | |
240 | if not os.path.isdir(path): |
|
257 | if not os.path.isdir(path): | |
241 | raise ValueError, "[Reading] Directory %s does not exist" %path |
|
258 | raise ValueError, "[Reading] Directory %s does not exist" % path | |
242 |
|
259 | |||
243 | try: |
|
260 | try: | |
244 |
self.digitalReadObj = digital_rf.DigitalRFReader( |
|
261 | self.digitalReadObj = digital_rf.DigitalRFReader( | |
|
262 | path, load_all_metadata=True) | |||
245 | except: |
|
263 | except: | |
246 | self.digitalReadObj = digital_rf.DigitalRFReader(path) |
|
264 | self.digitalReadObj = digital_rf.DigitalRFReader(path) | |
247 |
|
265 | |||
248 | channelNameList = self.digitalReadObj.get_channels() |
|
266 | channelNameList = self.digitalReadObj.get_channels() | |
249 |
|
267 | |||
250 | if not channelNameList: |
|
268 | if not channelNameList: | |
251 | raise ValueError, "[Reading] Directory %s does not have any files" %path |
|
269 | raise ValueError, "[Reading] Directory %s does not have any files" % path | |
252 |
|
270 | |||
253 | if not channelList: |
|
271 | if not channelList: | |
254 | channelList = range(len(channelNameList)) |
|
272 | channelList = range(len(channelNameList)) | |
255 |
|
273 | |||
256 |
|
||||
257 | ########## Reading metadata ###################### |
|
274 | ########## Reading metadata ###################### | |
258 |
|
275 | |||
259 |
top_properties = self.digitalReadObj.get_properties( |
|
276 | top_properties = self.digitalReadObj.get_properties( | |
260 |
|
277 | channelNameList[channelList[0]]) | ||
261 |
|
278 | |||
262 | self.__num_subchannels = top_properties['num_subchannels'] |
|
279 | self.__num_subchannels = top_properties['num_subchannels'] | |
263 | self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator'] |
|
280 | self.__sample_rate = 1.0 * \ | |
|
281 | top_properties['sample_rate_numerator'] / \ | |||
|
282 | top_properties['sample_rate_denominator'] | |||
264 | # self.__samples_per_file = top_properties['samples_per_file'][0] |
|
283 | # self.__samples_per_file = top_properties['samples_per_file'][0] | |
265 |
self.__deltaHeigth = 1e6*0.15/self.__sample_rate |
|
284 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? | |
266 |
|
285 | |||
267 |
this_metadata_file = self.digitalReadObj.get_digital_metadata( |
|
286 | this_metadata_file = self.digitalReadObj.get_digital_metadata( | |
|
287 | channelNameList[channelList[0]]) | |||
268 | metadata_bounds = this_metadata_file.get_bounds() |
|
288 | metadata_bounds = this_metadata_file.get_bounds() | |
269 |
self.fixed_metadata_dict = this_metadata_file.read( |
|
289 | self.fixed_metadata_dict = this_metadata_file.read( | |
|
290 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER | |||
270 |
|
291 | |||
271 | try: |
|
292 | try: | |
272 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] |
|
293 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] | |
273 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] |
|
294 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] | |
274 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] |
|
295 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] | |
275 | self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype']) |
|
296 | self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype']) | |
276 | except: |
|
297 | except: | |
277 | pass |
|
298 | pass | |
278 |
|
||||
279 |
|
299 | |||
280 | self.__frequency = None |
|
300 | self.__frequency = None | |
281 |
|
301 | |||
282 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) |
|
302 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) | |
283 |
|
303 | |||
284 | self.__timezone = self.fixed_metadata_dict.get('timezone', 300) |
|
304 | self.__timezone = self.fixed_metadata_dict.get('timezone', 300) | |
285 |
|
305 | |||
286 |
|
||||
287 | try: |
|
306 | try: | |
288 | nSamples = self.fixed_metadata_dict['nSamples'] |
|
307 | nSamples = self.fixed_metadata_dict['nSamples'] | |
289 | except: |
|
308 | except: | |
290 | nSamples = None |
|
309 | nSamples = None | |
291 |
|
310 | |||
292 | self.__firstHeigth = 0 |
|
311 | self.__firstHeigth = 0 | |
293 |
|
312 | |||
294 | try: |
|
313 | try: | |
295 | codeType = self.__radarControllerHeader['codeType'] |
|
314 | codeType = self.__radarControllerHeader['codeType'] | |
296 | except: |
|
315 | except: | |
297 | codeType = 0 |
|
316 | codeType = 0 | |
298 |
|
317 | |||
299 | nCode = 1 |
|
|||
300 | nBaud = 1 |
|
|||
301 | code = numpy.ones((nCode, nBaud), dtype=numpy.int) |
|
|||
302 |
|
||||
303 | try: |
|
318 | try: | |
304 | if codeType: |
|
319 | if codeType: | |
305 | nCode = self.__radarControllerHeader['nCode'] |
|
320 | nCode = self.__radarControllerHeader['nCode'] | |
306 | nBaud = self.__radarControllerHeader['nBaud'] |
|
321 | nBaud = self.__radarControllerHeader['nBaud'] | |
307 | code = self.__radarControllerHeader['code'] |
|
322 | code = self.__radarControllerHeader['code'] | |
308 | except: |
|
323 | except: | |
309 | pass |
|
324 | pass | |
310 |
|
325 | |||
311 |
|
||||
312 | if not ippKm: |
|
326 | if not ippKm: | |
313 | try: |
|
327 | try: | |
314 | # seconds to km |
|
328 | # seconds to km | |
315 | ippKm = self.__radarControllerHeader['ipp'] |
|
329 | ippKm = self.__radarControllerHeader['ipp'] | |
316 | except: |
|
330 | except: | |
317 | ippKm = None |
|
331 | ippKm = None | |
318 | #################################################### |
|
332 | #################################################### | |
319 | self.__ippKm = ippKm |
|
333 | self.__ippKm = ippKm | |
320 | startUTCSecond = None |
|
334 | startUTCSecond = None | |
321 | endUTCSecond = None |
|
335 | endUTCSecond = None | |
322 |
|
336 | |||
323 | if startDate: |
|
337 | if startDate: | |
324 | startDatetime = datetime.datetime.combine(startDate, startTime) |
|
338 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
325 | startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone |
|
339 | startUTCSecond = ( | |
|
340 | startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone | |||
326 |
|
341 | |||
327 | if endDate: |
|
342 | if endDate: | |
328 | endDatetime = datetime.datetime.combine(endDate, endTime) |
|
343 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
329 |
endUTCSecond = (endDatetime-datetime.datetime(1970, |
|
344 | endUTCSecond = (endDatetime - datetime.datetime(1970, | |
|
345 | 1, 1)).total_seconds() + self.__timezone | |||
330 |
|
346 | |||
331 |
start_index, end_index = self.digitalReadObj.get_bounds( |
|
347 | start_index, end_index = self.digitalReadObj.get_bounds( | |
|
348 | channelNameList[channelList[0]]) | |||
332 |
|
349 | |||
333 | if not startUTCSecond: |
|
350 | if not startUTCSecond: | |
334 |
startUTCSecond = start_index/self.__sample_rate |
|
351 | startUTCSecond = start_index / self.__sample_rate | |
335 |
|
352 | |||
336 | if start_index > startUTCSecond*self.__sample_rate: |
|
353 | if start_index > startUTCSecond * self.__sample_rate: | |
337 | startUTCSecond = start_index/self.__sample_rate |
|
354 | startUTCSecond = start_index / self.__sample_rate | |
338 |
|
355 | |||
339 | if not endUTCSecond: |
|
356 | if not endUTCSecond: | |
340 | endUTCSecond = end_index/self.__sample_rate |
|
357 | endUTCSecond = end_index / self.__sample_rate | |
341 |
|
358 | |||
342 | if end_index < endUTCSecond*self.__sample_rate: |
|
359 | if end_index < endUTCSecond * self.__sample_rate: | |
343 | endUTCSecond = end_index/self.__sample_rate |
|
360 | endUTCSecond = end_index / self.__sample_rate | |
344 | if not nSamples: |
|
361 | if not nSamples: | |
345 | if not ippKm: |
|
362 | if not ippKm: | |
346 | raise ValueError, "[Reading] nSamples or ippKm should be defined" |
|
363 | raise ValueError, "[Reading] nSamples or ippKm should be defined" | |
347 | nSamples = int(ippKm / (1e6*0.15/self.__sample_rate)) |
|
364 | nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate)) | |
348 | channelBoundList = [] |
|
365 | channelBoundList = [] | |
349 | channelNameListFiltered = [] |
|
366 | channelNameListFiltered = [] | |
350 |
|
367 | |||
351 | for thisIndexChannel in channelList: |
|
368 | for thisIndexChannel in channelList: | |
352 |
thisChannelName = |
|
369 | thisChannelName = channelNameList[thisIndexChannel] | |
353 |
start_index, end_index = self.digitalReadObj.get_bounds( |
|
370 | start_index, end_index = self.digitalReadObj.get_bounds( | |
|
371 | thisChannelName) | |||
354 | channelBoundList.append((start_index, end_index)) |
|
372 | channelBoundList.append((start_index, end_index)) | |
355 | channelNameListFiltered.append(thisChannelName) |
|
373 | channelNameListFiltered.append(thisChannelName) | |
356 |
|
374 | |||
357 | self.profileIndex = 0 |
|
375 | self.profileIndex = 0 | |
358 | self.i= 0 |
|
376 | self.i = 0 | |
359 | self.__delay = delay |
|
377 | self.__delay = delay | |
360 |
|
378 | |||
361 | self.__codeType = codeType |
|
379 | self.__codeType = codeType | |
362 | self.__nCode = nCode |
|
380 | self.__nCode = nCode | |
363 | self.__nBaud = nBaud |
|
381 | self.__nBaud = nBaud | |
364 | self.__code = code |
|
382 | self.__code = code | |
365 |
|
383 | |||
366 | self.__datapath = path |
|
384 | self.__datapath = path | |
367 | self.__online = online |
|
385 | self.__online = online | |
368 | self.__channelList = channelList |
|
386 | self.__channelList = channelList | |
369 | self.__channelNameList = channelNameListFiltered |
|
387 | self.__channelNameList = channelNameListFiltered | |
370 | self.__channelBoundList = channelBoundList |
|
388 | self.__channelBoundList = channelBoundList | |
371 | self.__nSamples = nSamples |
|
389 | self.__nSamples = nSamples | |
372 | self.__samples_to_read = long(nSamples) # FIJO: AHORA 40 |
|
390 | self.__samples_to_read = long(nSamples) # FIJO: AHORA 40 | |
373 | self.__nChannels = len(self.__channelList) |
|
391 | self.__nChannels = len(self.__channelList) | |
374 |
|
392 | |||
375 | self.__startUTCSecond = startUTCSecond |
|
393 | self.__startUTCSecond = startUTCSecond | |
376 | self.__endUTCSecond = endUTCSecond |
|
394 | self.__endUTCSecond = endUTCSecond | |
377 |
|
395 | |||
378 |
self.__timeInterval = 1.0 * self.__samples_to_read/ |
|
396 | self.__timeInterval = 1.0 * self.__samples_to_read / \ | |
|
397 | self.__sample_rate # Time interval | |||
379 |
|
398 | |||
380 | if online: |
|
399 | if online: | |
381 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) |
|
400 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) | |
382 | startUTCSecond = numpy.floor(endUTCSecond) |
|
401 | startUTCSecond = numpy.floor(endUTCSecond) | |
383 |
|
402 | |||
384 |
|
|
403 | # por que en el otro metodo lo primero q se hace es sumar samplestoread | |
|
404 | self.__thisUnixSample = long( | |||
|
405 | startUTCSecond * self.__sample_rate) - self.__samples_to_read | |||
385 |
|
406 | |||
386 | self.__data_buffer = numpy.zeros((self.__num_subchannels, self.__samples_to_read), dtype = numpy.complex) |
|
407 | self.__data_buffer = numpy.zeros( | |
|
408 | (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex) | |||
387 |
|
409 | |||
388 | self.__setFileHeader() |
|
410 | self.__setFileHeader() | |
389 | self.isConfig = True |
|
411 | self.isConfig = True | |
390 |
|
412 | |||
391 | print "[Reading] Digital RF Data was found from %s to %s " %( |
|
413 | print "[Reading] Digital RF Data was found from %s to %s " % ( | |
392 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
414 | datetime.datetime.utcfromtimestamp( | |
393 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
415 | self.__startUTCSecond - self.__timezone), | |
394 | ) |
|
416 | datetime.datetime.utcfromtimestamp( | |
395 |
|
417 | self.__endUTCSecond - self.__timezone) | ||
396 | print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), |
|
418 | ) | |
397 | datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone) |
|
419 | ||
398 | ) |
|
420 | print "[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), | |
|
421 | datetime.datetime.utcfromtimestamp( | |||
|
422 | endUTCSecond - self.__timezone) | |||
|
423 | ) | |||
399 | self.oldAverage = None |
|
424 | self.oldAverage = None | |
400 | self.count = 0 |
|
425 | self.count = 0 | |
401 | self.executionTime = 0 |
|
426 | self.executionTime = 0 | |
|
427 | ||||
402 | def __reload(self): |
|
428 | def __reload(self): | |
403 |
|
429 | |||
404 | # print "%s not in range [%s, %s]" %( |
|
430 | # print "%s not in range [%s, %s]" %( | |
405 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
431 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
406 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
432 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
407 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
433 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
408 | # ) |
|
434 | # ) | |
409 | print "[Reading] reloading metadata ..." |
|
435 | print "[Reading] reloading metadata ..." | |
410 |
|
436 | |||
411 | try: |
|
437 | try: | |
412 | self.digitalReadObj.reload(complete_update=True) |
|
438 | self.digitalReadObj.reload(complete_update=True) | |
413 | except: |
|
439 | except: | |
414 | self.digitalReadObj.reload() |
|
440 | self.digitalReadObj.reload() | |
415 |
|
441 | |||
416 |
start_index, end_index = self.digitalReadObj.get_bounds( |
|
442 | start_index, end_index = self.digitalReadObj.get_bounds( | |
|
443 | self.__channelNameList[self.__channelList[0]]) | |||
417 |
|
444 | |||
418 | if start_index > self.__startUTCSecond*self.__sample_rate: |
|
445 | if start_index > self.__startUTCSecond * self.__sample_rate: | |
419 | self.__startUTCSecond = 1.0*start_index/self.__sample_rate |
|
446 | self.__startUTCSecond = 1.0 * start_index / self.__sample_rate | |
420 |
|
447 | |||
421 | if end_index > self.__endUTCSecond*self.__sample_rate: |
|
448 | if end_index > self.__endUTCSecond * self.__sample_rate: | |
422 | self.__endUTCSecond = 1.0*end_index/self.__sample_rate |
|
449 | self.__endUTCSecond = 1.0 * end_index / self.__sample_rate | |
423 |
|
450 | |||
424 | print "[Reading] New timerange found [%s, %s] " %( |
|
451 | print "[Reading] New timerange found [%s, %s] " % ( | |
425 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
452 | datetime.datetime.utcfromtimestamp( | |
426 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
453 | self.__startUTCSecond - self.__timezone), | |
427 | ) |
|
454 | datetime.datetime.utcfromtimestamp( | |
|
455 | self.__endUTCSecond - self.__timezone) | |||
|
456 | ) | |||
428 |
|
457 | |||
429 | return True |
|
458 | return True | |
430 |
|
459 | |||
431 | return False |
|
460 | return False | |
432 |
|
461 | |||
433 | def timeit(self, toExecute): |
|
462 | def timeit(self, toExecute): | |
434 | t0 = time() |
|
463 | t0 = time() | |
435 | toExecute() |
|
464 | toExecute() | |
436 | self.executionTime = time() - t0 |
|
465 | self.executionTime = time() - t0 | |
437 |
if self.oldAverage is None: |
|
466 | if self.oldAverage is None: | |
438 |
self.oldAverage = |
|
467 | self.oldAverage = self.executionTime | |
|
468 | self.oldAverage = (self.executionTime + self.count * | |||
|
469 | self.oldAverage) / (self.count + 1.0) | |||
439 | self.count = self.count + 1.0 |
|
470 | self.count = self.count + 1.0 | |
440 | return |
|
471 | return | |
441 |
|
472 | |||
442 |
def __readNextBlock(self, seconds=30, volt_scale |
|
473 | def __readNextBlock(self, seconds=30, volt_scale=1): | |
443 | ''' |
|
474 | ''' | |
444 | ''' |
|
475 | ''' | |
445 |
|
476 | |||
446 | # Set the next data |
|
477 | # Set the next data | |
447 | self.__flagDiscontinuousBlock = False |
|
478 | self.__flagDiscontinuousBlock = False | |
448 | self.__thisUnixSample += self.__samples_to_read |
|
479 | self.__thisUnixSample += self.__samples_to_read | |
449 |
|
480 | |||
450 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: |
|
481 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: | |
451 | print "[Reading] There are no more data into selected time-range" |
|
482 | print "[Reading] There are no more data into selected time-range" | |
452 | if self.__online: |
|
483 | if self.__online: | |
453 | self.__reload() |
|
484 | self.__reload() | |
454 | else: |
|
485 | else: | |
455 | return False |
|
486 | return False | |
456 |
|
487 | |||
457 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: |
|
488 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: | |
458 | return False |
|
489 | return False | |
459 |
self.__thisUnixSample -= |
|
490 | self.__thisUnixSample -= self.__samples_to_read | |
460 |
|
491 | |||
461 | indexChannel = 0 |
|
492 | indexChannel = 0 | |
462 |
|
493 | |||
463 | dataOk = False |
|
494 | dataOk = False | |
464 |
for thisChannelName in self.__channelNameList: |
|
495 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? | |
465 | for indexSubchannel in range(self.__num_subchannels): |
|
496 | for indexSubchannel in range(self.__num_subchannels): | |
466 | try: |
|
497 | try: | |
467 | t0 = time() |
|
498 | t0 = time() | |
468 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, |
|
499 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
469 | self.__samples_to_read, |
|
500 | self.__samples_to_read, | |
470 | thisChannelName, sub_channel=indexSubchannel) |
|
501 | thisChannelName, sub_channel=indexSubchannel) | |
471 | self.executionTime = time() - t0 |
|
502 | self.executionTime = time() - t0 | |
472 |
if self.oldAverage is None: |
|
503 | if self.oldAverage is None: | |
473 |
self.oldAverage = |
|
504 | self.oldAverage = self.executionTime | |
|
505 | self.oldAverage = ( | |||
|
506 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) | |||
474 | self.count = self.count + 1.0 |
|
507 | self.count = self.count + 1.0 | |
475 |
|
508 | |||
476 | except IOError, e: |
|
509 | except IOError, e: | |
477 | #read next profile |
|
510 | # read next profile | |
478 | self.__flagDiscontinuousBlock = True |
|
511 | self.__flagDiscontinuousBlock = True | |
479 | print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e |
|
512 | print "[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e | |
480 | break |
|
513 | break | |
481 |
|
514 | |||
482 | if result.shape[0] != self.__samples_to_read: |
|
515 | if result.shape[0] != self.__samples_to_read: | |
483 | self.__flagDiscontinuousBlock = True |
|
516 | self.__flagDiscontinuousBlock = True | |
484 | print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
517 | print "[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
485 | result.shape[0], |
|
518 | result.shape[0], | |
486 | self.__samples_to_read) |
|
519 | self.__samples_to_read) | |
487 | break |
|
520 | break | |
488 |
|
521 | |||
489 | self.__data_buffer[indexSubchannel,:] = result*volt_scale |
|
522 | self.__data_buffer[indexSubchannel, :] = result * volt_scale | |
490 |
|
523 | |||
491 | indexChannel += 1 |
|
524 | indexChannel += 1 | |
492 |
|
525 | |||
493 | dataOk = True |
|
526 | dataOk = True | |
494 |
|
527 | |||
495 | self.__utctime = self.__thisUnixSample/self.__sample_rate |
|
528 | self.__utctime = self.__thisUnixSample / self.__sample_rate | |
496 |
|
529 | |||
497 | if not dataOk: |
|
530 | if not dataOk: | |
498 | return False |
|
531 | return False | |
499 |
|
532 | |||
500 | print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
533 | print "[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
501 | self.__samples_to_read, |
|
534 | self.__samples_to_read, | |
502 | self.__timeInterval) |
|
535 | self.__timeInterval) | |
503 |
|
536 | |||
504 | self.__bufferIndex = 0 |
|
537 | self.__bufferIndex = 0 | |
505 |
|
538 | |||
506 | return True |
|
539 | return True | |
507 |
|
540 | |||
508 | def __isBufferEmpty(self): |
|
541 | def __isBufferEmpty(self): | |
509 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40 |
|
542 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40 | |
510 |
|
543 | |||
511 | def getData(self, seconds=30, nTries=5): |
|
544 | def getData(self, seconds=30, nTries=5): | |
512 |
|
||||
513 | ''' |
|
545 | ''' | |
514 | This method gets the data from files and put the data into the dataOut object |
|
546 | This method gets the data from files and put the data into the dataOut object | |
515 |
|
547 | |||
516 | In addition, increase el the buffer counter in one. |
|
548 | In addition, increase el the buffer counter in one. | |
517 |
|
549 | |||
518 | Return: |
|
550 | Return: | |
519 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
551 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
520 | buffer. Si no hay mas archivos a leer retorna None. |
|
552 | buffer. Si no hay mas archivos a leer retorna None. | |
521 |
|
553 | |||
522 | Affected: |
|
554 | Affected: | |
523 | self.dataOut |
|
555 | self.dataOut | |
524 | self.profileIndex |
|
556 | self.profileIndex | |
525 | self.flagDiscontinuousBlock |
|
557 | self.flagDiscontinuousBlock | |
526 | self.flagIsNewBlock |
|
558 | self.flagIsNewBlock | |
527 | ''' |
|
559 | ''' | |
528 |
|
560 | |||
529 | err_counter = 0 |
|
561 | err_counter = 0 | |
530 | self.dataOut.flagNoData = True |
|
562 | self.dataOut.flagNoData = True | |
531 |
|
563 | |||
532 | if self.__isBufferEmpty(): |
|
564 | if self.__isBufferEmpty(): | |
533 | self.__flagDiscontinuousBlock = False |
|
565 | self.__flagDiscontinuousBlock = False | |
534 |
|
566 | |||
535 | while True: |
|
567 | while True: | |
536 | if self.__readNextBlock(): |
|
568 | if self.__readNextBlock(): | |
537 | break |
|
569 | break | |
538 | if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate: |
|
570 | if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate: | |
539 | return False |
|
571 | return False | |
540 |
|
572 | |||
541 | if self.__flagDiscontinuousBlock: |
|
573 | if self.__flagDiscontinuousBlock: | |
542 | print '[Reading] discontinuous block found ... continue with the next block' |
|
574 | print '[Reading] discontinuous block found ... continue with the next block' | |
543 | continue |
|
575 | continue | |
544 |
|
576 | |||
545 | if not self.__online: |
|
577 | if not self.__online: | |
546 | return False |
|
578 | return False | |
547 |
|
579 | |||
548 | err_counter += 1 |
|
580 | err_counter += 1 | |
549 | if err_counter > nTries: |
|
581 | if err_counter > nTries: | |
550 | return False |
|
582 | return False | |
551 |
|
583 | |||
552 | print '[Reading] waiting %d seconds to read a new block' %seconds |
|
584 | print '[Reading] waiting %d seconds to read a new block' % seconds | |
553 | sleep(seconds) |
|
585 | sleep(seconds) | |
554 |
|
586 | |||
555 |
self.dataOut.data = self.__data_buffer[:, |
|
587 | self.dataOut.data = self.__data_buffer[:, | |
556 | self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate |
|
588 | self.__bufferIndex:self.__bufferIndex + self.__nSamples] | |
|
589 | self.dataOut.utctime = ( | |||
|
590 | self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate | |||
557 | self.dataOut.flagNoData = False |
|
591 | self.dataOut.flagNoData = False | |
558 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock |
|
592 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
559 | self.dataOut.profileIndex = self.profileIndex |
|
593 | self.dataOut.profileIndex = self.profileIndex | |
560 |
|
594 | |||
561 | self.__bufferIndex += self.__nSamples |
|
595 | self.__bufferIndex += self.__nSamples | |
562 | self.profileIndex += 1 |
|
596 | self.profileIndex += 1 | |
563 |
|
597 | |||
564 | if self.profileIndex == self.dataOut.nProfiles: |
|
598 | if self.profileIndex == self.dataOut.nProfiles: | |
565 | self.profileIndex = 0 |
|
599 | self.profileIndex = 0 | |
566 |
|
600 | |||
567 | return True |
|
601 | return True | |
568 |
|
602 | |||
569 | def printInfo(self): |
|
603 | def printInfo(self): | |
570 | ''' |
|
604 | ''' | |
571 | ''' |
|
605 | ''' | |
572 | if self.__printInfo == False: |
|
606 | if self.__printInfo == False: | |
573 | return |
|
607 | return | |
574 |
|
608 | |||
575 | # self.systemHeaderObj.printInfo() |
|
609 | # self.systemHeaderObj.printInfo() | |
576 | # self.radarControllerHeaderObj.printInfo() |
|
610 | # self.radarControllerHeaderObj.printInfo() | |
577 |
|
611 | |||
578 | self.__printInfo = False |
|
612 | self.__printInfo = False | |
579 |
|
613 | |||
580 | def printNumberOfBlock(self): |
|
614 | def printNumberOfBlock(self): | |
581 | ''' |
|
615 | ''' | |
582 | ''' |
|
616 | ''' | |
583 | return |
|
617 | return | |
584 | # print self.profileIndex |
|
618 | # print self.profileIndex | |
585 |
|
619 | |||
586 |
|
||||
587 | def run(self, **kwargs): |
|
620 | def run(self, **kwargs): | |
588 | ''' |
|
621 | ''' | |
589 | This method will be called many times so here you should put all your code |
|
622 | This method will be called many times so here you should put all your code | |
590 | ''' |
|
623 | ''' | |
591 |
|
624 | |||
592 | if not self.isConfig: |
|
625 | if not self.isConfig: | |
593 | self.setup(**kwargs) |
|
626 | self.setup(**kwargs) | |
594 | #self.i = self.i+1 |
|
627 | #self.i = self.i+1 | |
595 | self.getData(seconds=self.__delay) |
|
628 | self.getData(seconds=self.__delay) | |
596 |
|
629 | |||
597 | return |
|
630 | return | |
598 |
|
631 | |||
|
632 | ||||
599 | class DigitalRFWriter(Operation): |
|
633 | class DigitalRFWriter(Operation): | |
600 | ''' |
|
634 | ''' | |
601 | classdocs |
|
635 | classdocs | |
602 | ''' |
|
636 | ''' | |
603 |
|
637 | |||
604 | def __init__(self, **kwargs): |
|
638 | def __init__(self, **kwargs): | |
605 | ''' |
|
639 | ''' | |
606 | Constructor |
|
640 | Constructor | |
607 | ''' |
|
641 | ''' | |
608 | Operation.__init__(self, **kwargs) |
|
642 | Operation.__init__(self, **kwargs) | |
609 | self.metadata_dict = {} |
|
643 | self.metadata_dict = {} | |
610 |
self.dataOut = None |
|
644 | self.dataOut = None | |
611 | self.dtype = None |
|
645 | self.dtype = None | |
612 |
|
646 | |||
613 | def setHeader(self): |
|
647 | def setHeader(self): | |
614 |
|
648 | |||
615 | self.metadata_dict['frequency'] = self.dataOut.frequency |
|
649 | self.metadata_dict['frequency'] = self.dataOut.frequency | |
616 | self.metadata_dict['timezone'] = self.dataOut.timeZone |
|
650 | self.metadata_dict['timezone'] = self.dataOut.timeZone | |
617 | self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype) |
|
651 | self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype) | |
618 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles |
|
652 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles | |
619 | self.metadata_dict['heightList'] = self.dataOut.heightList |
|
653 | self.metadata_dict['heightList'] = self.dataOut.heightList | |
620 | self.metadata_dict['channelList'] = self.dataOut.channelList |
|
654 | self.metadata_dict['channelList'] = self.dataOut.channelList | |
621 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData |
|
655 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData | |
622 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData |
|
656 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData | |
623 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT |
|
657 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT | |
624 | self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock |
|
658 | self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock | |
625 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime |
|
659 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime | |
626 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt |
|
660 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt | |
627 |
|
661 | |||
628 | return |
|
662 | return | |
629 |
|
663 | |||
630 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): |
|
664 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): | |
631 | ''' |
|
665 | ''' | |
632 | In this method we should set all initial parameters. |
|
666 | In this method we should set all initial parameters. | |
633 | Input: |
|
667 | Input: | |
634 | dataOut: Input data will also be outputa data |
|
668 | dataOut: Input data will also be outputa data | |
635 | ''' |
|
669 | ''' | |
636 | self.setHeader() |
|
670 | self.setHeader() | |
637 | self.__ippSeconds = dataOut.ippSeconds |
|
671 | self.__ippSeconds = dataOut.ippSeconds | |
638 | self.__deltaH = dataOut.getDeltaH() |
|
672 | self.__deltaH = dataOut.getDeltaH() | |
639 | self.__sample_rate = 1e6*0.15/self.__deltaH |
|
673 | self.__sample_rate = 1e6 * 0.15 / self.__deltaH | |
640 | self.__dtype = dataOut.dtype |
|
674 | self.__dtype = dataOut.dtype | |
641 | if len(dataOut.dtype) == 2: |
|
675 | if len(dataOut.dtype) == 2: | |
642 | self.__dtype = dataOut.dtype[0] |
|
676 | self.__dtype = dataOut.dtype[0] | |
643 | self.__nSamples = dataOut.systemHeaderObj.nSamples |
|
677 | self.__nSamples = dataOut.systemHeaderObj.nSamples | |
644 | self.__nProfiles = dataOut.nProfiles |
|
678 | self.__nProfiles = dataOut.nProfiles | |
645 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile |
|
679 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile | |
646 |
|
680 | |||
647 |
self.arr_data = arr_data = numpy.ones((self.__nSamples, len( |
|
681 | self.arr_data = arr_data = numpy.ones((self.__nSamples, len( | |
|
682 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |||
648 |
|
683 | |||
649 | file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000 |
|
684 | file_cadence_millisecs = long( | |
|
685 | 1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000 | |||
650 | sub_cadence_secs = file_cadence_millisecs / 500 |
|
686 | sub_cadence_secs = file_cadence_millisecs / 500 | |
651 |
|
687 | |||
652 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() |
|
688 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() | |
653 | sample_rate_numerator = long(sample_rate_fraction.numerator) |
|
689 | sample_rate_numerator = long(sample_rate_fraction.numerator) | |
654 | sample_rate_denominator = long(sample_rate_fraction.denominator) |
|
690 | sample_rate_denominator = long(sample_rate_fraction.denominator) | |
655 | start_global_index = dataOut.utctime * self.__sample_rate |
|
691 | start_global_index = dataOut.utctime * self.__sample_rate | |
656 |
|
692 | |||
657 | uuid = 'prueba' |
|
693 | uuid = 'prueba' | |
658 | compression_level = 1 |
|
694 | compression_level = 1 | |
659 | checksum = False |
|
695 | checksum = False | |
660 | is_complex = True |
|
696 | is_complex = True | |
661 | num_subchannels = len(dataOut.channelList) |
|
697 | num_subchannels = len(dataOut.channelList) | |
662 | is_continuous = True |
|
698 | is_continuous = True | |
663 | marching_periods = False |
|
699 | marching_periods = False | |
664 |
|
700 | |||
665 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, |
|
701 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, | |
666 | fileCadence, start_global_index, |
|
702 | fileCadence, start_global_index, | |
667 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, |
|
703 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, | |
668 | is_complex, num_subchannels, is_continuous, marching_periods) |
|
704 | is_complex, num_subchannels, is_continuous, marching_periods) | |
669 |
|
705 | |||
670 | metadata_dir = os.path.join(path, 'metadata') |
|
706 | metadata_dir = os.path.join(path, 'metadata') | |
671 | os.system('mkdir %s' % (metadata_dir)) |
|
707 | os.system('mkdir %s' % (metadata_dir)) | |
672 |
|
||||
673 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, ##236, file_cadence_millisecs / 1000 |
|
|||
674 | sample_rate_numerator, sample_rate_denominator, |
|
|||
675 | metadataFile) |
|
|||
676 |
|
708 | |||
|
709 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 | |||
|
710 | sample_rate_numerator, sample_rate_denominator, | |||
|
711 | metadataFile) | |||
677 |
|
712 | |||
678 | self.isConfig = True |
|
713 | self.isConfig = True | |
679 | self.currentSample = 0 |
|
714 | self.currentSample = 0 | |
680 | self.oldAverage = 0 |
|
715 | self.oldAverage = 0 | |
681 | self.count = 0 |
|
716 | self.count = 0 | |
682 | return |
|
717 | return | |
683 |
|
718 | |||
684 | def writeMetadata(self): |
|
719 | def writeMetadata(self): | |
685 | print '[Writing] - Writing metadata' |
|
720 | print '[Writing] - Writing metadata' | |
686 | start_idx = self.__sample_rate * self.dataOut.utctime |
|
721 | start_idx = self.__sample_rate * self.dataOut.utctime | |
687 |
|
722 | |||
688 |
self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( |
|
723 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( | |
689 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict() |
|
724 | ) | |
690 |
self.metadata_dict[' |
|
725 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( | |
|
726 | ) | |||
|
727 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( | |||
|
728 | ) | |||
691 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) |
|
729 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) | |
692 | return |
|
730 | return | |
693 |
|
731 | |||
694 |
|
||||
695 | def timeit(self, toExecute): |
|
732 | def timeit(self, toExecute): | |
696 | t0 = time() |
|
733 | t0 = time() | |
697 | toExecute() |
|
734 | toExecute() | |
698 | self.executionTime = time() - t0 |
|
735 | self.executionTime = time() - t0 | |
699 |
if self.oldAverage is None: |
|
736 | if self.oldAverage is None: | |
700 |
self.oldAverage = |
|
737 | self.oldAverage = self.executionTime | |
|
738 | self.oldAverage = (self.executionTime + self.count * | |||
|
739 | self.oldAverage) / (self.count + 1.0) | |||
701 | self.count = self.count + 1.0 |
|
740 | self.count = self.count + 1.0 | |
702 | return |
|
741 | return | |
703 |
|
742 | |||
704 |
|
||||
705 | def writeData(self): |
|
743 | def writeData(self): | |
706 | for i in range(self.dataOut.systemHeaderObj.nSamples): |
|
744 | for i in range(self.dataOut.systemHeaderObj.nSamples): | |
707 | for channel in self.dataOut.channelList: |
|
745 | for channel in self.dataOut.channelList: | |
708 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real |
|
746 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real | |
709 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag |
|
747 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag | |
710 |
|
748 | |||
711 | def f(): return self.digitalWriteObj.rf_write(self.arr_data) |
|
749 | def f(): return self.digitalWriteObj.rf_write(self.arr_data) | |
712 | self.timeit(f) |
|
750 | self.timeit(f) | |
713 |
|
751 | |||
714 | return |
|
752 | return | |
715 |
|
753 | |||
716 | def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=100, dirCadence=25, metadataCadence=1, **kwargs): |
|
754 | def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=100, dirCadence=25, metadataCadence=1, **kwargs): | |
717 | ''' |
|
755 | ''' | |
718 | This method will be called many times so here you should put all your code |
|
756 | This method will be called many times so here you should put all your code | |
719 | Inputs: |
|
757 | Inputs: | |
720 | dataOut: object with the data |
|
758 | dataOut: object with the data | |
721 | ''' |
|
759 | ''' | |
722 | # print dataOut.__dict__ |
|
760 | # print dataOut.__dict__ | |
723 | self.dataOut = dataOut |
|
761 | self.dataOut = dataOut | |
724 | if not self.isConfig: |
|
762 | if not self.isConfig: | |
725 |
self.setup(dataOut, path, frequency, fileCadence, |
|
763 | self.setup(dataOut, path, frequency, fileCadence, | |
|
764 | dirCadence, metadataCadence, **kwargs) | |||
726 | self.writeMetadata() |
|
765 | self.writeMetadata() | |
727 |
|
766 | |||
728 | self.writeData() |
|
767 | self.writeData() | |
729 |
|
768 | |||
730 | ## self.currentSample += 1 |
|
769 | ## self.currentSample += 1 | |
731 |
|
|
770 | # if self.dataOut.flagDataAsBlock or self.currentSample == 1: | |
732 |
|
|
771 | # self.writeMetadata() | |
733 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 |
|
772 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 | |
734 |
|
773 | |||
735 | def close(self): |
|
774 | def close(self): | |
736 | print '[Writing] - Closing files ' |
|
775 | print '[Writing] - Closing files ' | |
737 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 |
|
776 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 | |
738 | try: |
|
777 | try: | |
739 | self.digitalWriteObj.close() |
|
778 | self.digitalWriteObj.close() | |
740 | except: |
|
779 | except: | |
741 | pass |
|
780 | pass | |
742 |
|
781 | |||
743 | # raise |
|
782 | # raise | |
744 | if __name__ == '__main__': |
|
783 | if __name__ == '__main__': | |
745 |
|
784 | |||
746 | readObj = DigitalRFReader() |
|
785 | readObj = DigitalRFReader() | |
747 |
|
786 | |||
748 | while True: |
|
787 | while True: | |
749 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') |
|
788 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') | |
750 | # readObj.printInfo() |
|
789 | # readObj.printInfo() | |
751 |
# readObj.printNumberOfBlock() |
|
790 | # readObj.printNumberOfBlock() |
@@ -1,1283 +1,1281 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy |
|
2 | import numpy | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy import cSchain |
|
4 | from schainpy import cSchain | |
5 | from jroproc_base import ProcessingUnit, Operation |
|
5 | from jroproc_base import ProcessingUnit, Operation | |
6 | from schainpy.model.data.jrodata import Voltage |
|
6 | from schainpy.model.data.jrodata import Voltage | |
7 | from time import time |
|
7 | from time import time | |
8 |
|
8 | |||
9 | class VoltageProc(ProcessingUnit): |
|
9 | class VoltageProc(ProcessingUnit): | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def __init__(self, **kwargs): |
|
12 | def __init__(self, **kwargs): | |
13 |
|
13 | |||
14 | ProcessingUnit.__init__(self, **kwargs) |
|
14 | ProcessingUnit.__init__(self, **kwargs) | |
15 |
|
15 | |||
16 | # self.objectDict = {} |
|
16 | # self.objectDict = {} | |
17 | self.dataOut = Voltage() |
|
17 | self.dataOut = Voltage() | |
18 | self.flip = 1 |
|
18 | self.flip = 1 | |
19 |
|
19 | |||
20 | def run(self): |
|
20 | def run(self): | |
21 | if self.dataIn.type == 'AMISR': |
|
21 | if self.dataIn.type == 'AMISR': | |
22 | self.__updateObjFromAmisrInput() |
|
22 | self.__updateObjFromAmisrInput() | |
23 |
|
23 | |||
24 | if self.dataIn.type == 'Voltage': |
|
24 | if self.dataIn.type == 'Voltage': | |
25 | self.dataOut.copy(self.dataIn) |
|
25 | self.dataOut.copy(self.dataIn) | |
26 |
|
26 | |||
27 | # self.dataOut.copy(self.dataIn) |
|
27 | # self.dataOut.copy(self.dataIn) | |
28 |
|
28 | |||
29 | def __updateObjFromAmisrInput(self): |
|
29 | def __updateObjFromAmisrInput(self): | |
30 |
|
30 | |||
31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
31 | self.dataOut.timeZone = self.dataIn.timeZone | |
32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
32 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
33 | self.dataOut.errorCount = self.dataIn.errorCount | |
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
35 |
|
35 | |||
36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
36 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
37 | self.dataOut.data = self.dataIn.data |
|
37 | self.dataOut.data = self.dataIn.data | |
38 | self.dataOut.utctime = self.dataIn.utctime |
|
38 | self.dataOut.utctime = self.dataIn.utctime | |
39 | self.dataOut.channelList = self.dataIn.channelList |
|
39 | self.dataOut.channelList = self.dataIn.channelList | |
40 | # self.dataOut.timeInterval = self.dataIn.timeInterval |
|
40 | # self.dataOut.timeInterval = self.dataIn.timeInterval | |
41 | self.dataOut.heightList = self.dataIn.heightList |
|
41 | self.dataOut.heightList = self.dataIn.heightList | |
42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
42 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
43 |
|
43 | |||
44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
44 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
46 | self.dataOut.frequency = self.dataIn.frequency |
|
46 | self.dataOut.frequency = self.dataIn.frequency | |
47 |
|
47 | |||
48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
48 | self.dataOut.azimuth = self.dataIn.azimuth | |
49 | self.dataOut.zenith = self.dataIn.zenith |
|
49 | self.dataOut.zenith = self.dataIn.zenith | |
50 |
|
50 | |||
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
54 | # |
|
54 | # | |
55 | # pass# |
|
55 | # pass# | |
56 | # |
|
56 | # | |
57 | # def init(self): |
|
57 | # def init(self): | |
58 | # |
|
58 | # | |
59 | # |
|
59 | # | |
60 | # if self.dataIn.type == 'AMISR': |
|
60 | # if self.dataIn.type == 'AMISR': | |
61 | # self.__updateObjFromAmisrInput() |
|
61 | # self.__updateObjFromAmisrInput() | |
62 | # |
|
62 | # | |
63 | # if self.dataIn.type == 'Voltage': |
|
63 | # if self.dataIn.type == 'Voltage': | |
64 | # self.dataOut.copy(self.dataIn) |
|
64 | # self.dataOut.copy(self.dataIn) | |
65 | # # No necesita copiar en cada init() los atributos de dataIn |
|
65 | # # No necesita copiar en cada init() los atributos de dataIn | |
66 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
66 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
67 |
|
67 | |||
68 | def selectChannels(self, channelList): |
|
68 | def selectChannels(self, channelList): | |
69 |
|
69 | |||
70 | channelIndexList = [] |
|
70 | channelIndexList = [] | |
71 |
|
71 | |||
72 | for channel in channelList: |
|
72 | for channel in channelList: | |
73 | if channel not in self.dataOut.channelList: |
|
73 | if channel not in self.dataOut.channelList: | |
74 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) |
|
74 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) | |
75 |
|
75 | |||
76 | index = self.dataOut.channelList.index(channel) |
|
76 | index = self.dataOut.channelList.index(channel) | |
77 | channelIndexList.append(index) |
|
77 | channelIndexList.append(index) | |
78 |
|
78 | |||
79 | self.selectChannelsByIndex(channelIndexList) |
|
79 | self.selectChannelsByIndex(channelIndexList) | |
80 |
|
80 | |||
81 | def selectChannelsByIndex(self, channelIndexList): |
|
81 | def selectChannelsByIndex(self, channelIndexList): | |
82 | """ |
|
82 | """ | |
83 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
83 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
86 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
87 |
|
87 | |||
88 | Affected: |
|
88 | Affected: | |
89 | self.dataOut.data |
|
89 | self.dataOut.data | |
90 | self.dataOut.channelIndexList |
|
90 | self.dataOut.channelIndexList | |
91 | self.dataOut.nChannels |
|
91 | self.dataOut.nChannels | |
92 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
92 | self.dataOut.m_ProcessingHeader.totalSpectra | |
93 | self.dataOut.systemHeaderObj.numChannels |
|
93 | self.dataOut.systemHeaderObj.numChannels | |
94 | self.dataOut.m_ProcessingHeader.blockSize |
|
94 | self.dataOut.m_ProcessingHeader.blockSize | |
95 |
|
95 | |||
96 | Return: |
|
96 | Return: | |
97 | None |
|
97 | None | |
98 | """ |
|
98 | """ | |
99 |
|
99 | |||
100 | for channelIndex in channelIndexList: |
|
100 | for channelIndex in channelIndexList: | |
101 | if channelIndex not in self.dataOut.channelIndexList: |
|
101 | if channelIndex not in self.dataOut.channelIndexList: | |
102 | print channelIndexList |
|
102 | print channelIndexList | |
103 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
103 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
104 |
|
104 | |||
105 | if self.dataOut.flagDataAsBlock: |
|
105 | if self.dataOut.flagDataAsBlock: | |
106 | """ |
|
106 | """ | |
107 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
107 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
108 | """ |
|
108 | """ | |
109 | data = self.dataOut.data[channelIndexList,:,:] |
|
109 | data = self.dataOut.data[channelIndexList,:,:] | |
110 | else: |
|
110 | else: | |
111 | data = self.dataOut.data[channelIndexList,:] |
|
111 | data = self.dataOut.data[channelIndexList,:] | |
112 |
|
112 | |||
113 | self.dataOut.data = data |
|
113 | self.dataOut.data = data | |
114 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
114 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
115 | # self.dataOut.nChannels = nChannels |
|
115 | # self.dataOut.nChannels = nChannels | |
116 |
|
116 | |||
117 | return 1 |
|
117 | return 1 | |
118 |
|
118 | |||
119 | def selectHeights(self, minHei=None, maxHei=None): |
|
119 | def selectHeights(self, minHei=None, maxHei=None): | |
120 | """ |
|
120 | """ | |
121 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
121 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
122 | minHei <= height <= maxHei |
|
122 | minHei <= height <= maxHei | |
123 |
|
123 | |||
124 | Input: |
|
124 | Input: | |
125 | minHei : valor minimo de altura a considerar |
|
125 | minHei : valor minimo de altura a considerar | |
126 | maxHei : valor maximo de altura a considerar |
|
126 | maxHei : valor maximo de altura a considerar | |
127 |
|
127 | |||
128 | Affected: |
|
128 | Affected: | |
129 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
129 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
130 |
|
130 | |||
131 | Return: |
|
131 | Return: | |
132 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
132 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
133 | """ |
|
133 | """ | |
134 |
|
134 | |||
135 | if minHei == None: |
|
135 | if minHei == None: | |
136 | minHei = self.dataOut.heightList[0] |
|
136 | minHei = self.dataOut.heightList[0] | |
137 |
|
137 | |||
138 | if maxHei == None: |
|
138 | if maxHei == None: | |
139 | maxHei = self.dataOut.heightList[-1] |
|
139 | maxHei = self.dataOut.heightList[-1] | |
140 |
|
140 | |||
141 | if (minHei < self.dataOut.heightList[0]): |
|
141 | if (minHei < self.dataOut.heightList[0]): | |
142 | minHei = self.dataOut.heightList[0] |
|
142 | minHei = self.dataOut.heightList[0] | |
143 |
|
143 | |||
144 | if (maxHei > self.dataOut.heightList[-1]): |
|
144 | if (maxHei > self.dataOut.heightList[-1]): | |
145 | maxHei = self.dataOut.heightList[-1] |
|
145 | maxHei = self.dataOut.heightList[-1] | |
146 |
|
146 | |||
147 | minIndex = 0 |
|
147 | minIndex = 0 | |
148 | maxIndex = 0 |
|
148 | maxIndex = 0 | |
149 | heights = self.dataOut.heightList |
|
149 | heights = self.dataOut.heightList | |
150 |
|
150 | |||
151 | inda = numpy.where(heights >= minHei) |
|
151 | inda = numpy.where(heights >= minHei) | |
152 | indb = numpy.where(heights <= maxHei) |
|
152 | indb = numpy.where(heights <= maxHei) | |
153 |
|
153 | |||
154 | try: |
|
154 | try: | |
155 | minIndex = inda[0][0] |
|
155 | minIndex = inda[0][0] | |
156 | except: |
|
156 | except: | |
157 | minIndex = 0 |
|
157 | minIndex = 0 | |
158 |
|
158 | |||
159 | try: |
|
159 | try: | |
160 | maxIndex = indb[0][-1] |
|
160 | maxIndex = indb[0][-1] | |
161 | except: |
|
161 | except: | |
162 | maxIndex = len(heights) |
|
162 | maxIndex = len(heights) | |
163 |
|
163 | |||
164 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
164 | self.selectHeightsByIndex(minIndex, maxIndex) | |
165 |
|
165 | |||
166 | return 1 |
|
166 | return 1 | |
167 |
|
167 | |||
168 |
|
168 | |||
169 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
169 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
170 | """ |
|
170 | """ | |
171 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
171 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
172 | minIndex <= index <= maxIndex |
|
172 | minIndex <= index <= maxIndex | |
173 |
|
173 | |||
174 | Input: |
|
174 | Input: | |
175 | minIndex : valor de indice minimo de altura a considerar |
|
175 | minIndex : valor de indice minimo de altura a considerar | |
176 | maxIndex : valor de indice maximo de altura a considerar |
|
176 | maxIndex : valor de indice maximo de altura a considerar | |
177 |
|
177 | |||
178 | Affected: |
|
178 | Affected: | |
179 | self.dataOut.data |
|
179 | self.dataOut.data | |
180 | self.dataOut.heightList |
|
180 | self.dataOut.heightList | |
181 |
|
181 | |||
182 | Return: |
|
182 | Return: | |
183 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
183 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
184 | """ |
|
184 | """ | |
185 |
|
185 | |||
186 | if (minIndex < 0) or (minIndex > maxIndex): |
|
186 | if (minIndex < 0) or (minIndex > maxIndex): | |
187 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
187 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) | |
188 |
|
188 | |||
189 | if (maxIndex >= self.dataOut.nHeights): |
|
189 | if (maxIndex >= self.dataOut.nHeights): | |
190 | maxIndex = self.dataOut.nHeights |
|
190 | maxIndex = self.dataOut.nHeights | |
191 |
|
191 | |||
192 | #voltage |
|
192 | #voltage | |
193 | if self.dataOut.flagDataAsBlock: |
|
193 | if self.dataOut.flagDataAsBlock: | |
194 | """ |
|
194 | """ | |
195 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
195 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
196 | """ |
|
196 | """ | |
197 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
197 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
198 | else: |
|
198 | else: | |
199 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
199 | data = self.dataOut.data[:, minIndex:maxIndex] | |
200 |
|
200 | |||
201 | # firstHeight = self.dataOut.heightList[minIndex] |
|
201 | # firstHeight = self.dataOut.heightList[minIndex] | |
202 |
|
202 | |||
203 | self.dataOut.data = data |
|
203 | self.dataOut.data = data | |
204 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
204 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
205 |
|
205 | |||
206 | if self.dataOut.nHeights <= 1: |
|
206 | if self.dataOut.nHeights <= 1: | |
207 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) |
|
207 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) | |
208 |
|
208 | |||
209 | return 1 |
|
209 | return 1 | |
210 |
|
210 | |||
211 |
|
211 | |||
212 | def filterByHeights(self, window): |
|
212 | def filterByHeights(self, window): | |
213 |
|
213 | |||
214 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
214 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
215 |
|
215 | |||
216 | if window == None: |
|
216 | if window == None: | |
217 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
217 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
218 |
|
218 | |||
219 | newdelta = deltaHeight * window |
|
219 | newdelta = deltaHeight * window | |
220 | r = self.dataOut.nHeights % window |
|
220 | r = self.dataOut.nHeights % window | |
221 | newheights = (self.dataOut.nHeights-r)/window |
|
221 | newheights = (self.dataOut.nHeights-r)/window | |
222 |
|
222 | |||
223 | if newheights <= 1: |
|
223 | if newheights <= 1: | |
224 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) |
|
224 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) | |
225 |
|
225 | |||
226 | if self.dataOut.flagDataAsBlock: |
|
226 | if self.dataOut.flagDataAsBlock: | |
227 | """ |
|
227 | """ | |
228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
229 | """ |
|
229 | """ | |
230 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] |
|
230 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] | |
231 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) |
|
231 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) | |
232 | buffer = numpy.sum(buffer,3) |
|
232 | buffer = numpy.sum(buffer,3) | |
233 |
|
233 | |||
234 | else: |
|
234 | else: | |
235 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] |
|
235 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] | |
236 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) |
|
236 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) | |
237 | buffer = numpy.sum(buffer,2) |
|
237 | buffer = numpy.sum(buffer,2) | |
238 |
|
238 | |||
239 | self.dataOut.data = buffer |
|
239 | self.dataOut.data = buffer | |
240 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
240 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
241 | self.dataOut.windowOfFilter = window |
|
241 | self.dataOut.windowOfFilter = window | |
242 |
|
242 | |||
243 | def setH0(self, h0, deltaHeight = None): |
|
243 | def setH0(self, h0, deltaHeight = None): | |
244 |
|
244 | |||
245 | if not deltaHeight: |
|
245 | if not deltaHeight: | |
246 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
246 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
247 |
|
247 | |||
248 | nHeights = self.dataOut.nHeights |
|
248 | nHeights = self.dataOut.nHeights | |
249 |
|
249 | |||
250 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
250 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
251 |
|
251 | |||
252 | self.dataOut.heightList = newHeiRange |
|
252 | self.dataOut.heightList = newHeiRange | |
253 |
|
253 | |||
254 | def deFlip(self, channelList = []): |
|
254 | def deFlip(self, channelList = []): | |
255 |
|
255 | |||
256 | data = self.dataOut.data.copy() |
|
256 | data = self.dataOut.data.copy() | |
257 |
|
257 | |||
258 | if self.dataOut.flagDataAsBlock: |
|
258 | if self.dataOut.flagDataAsBlock: | |
259 | flip = self.flip |
|
259 | flip = self.flip | |
260 | profileList = range(self.dataOut.nProfiles) |
|
260 | profileList = range(self.dataOut.nProfiles) | |
261 |
|
261 | |||
262 | if not channelList: |
|
262 | if not channelList: | |
263 | for thisProfile in profileList: |
|
263 | for thisProfile in profileList: | |
264 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
264 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
265 | flip *= -1.0 |
|
265 | flip *= -1.0 | |
266 | else: |
|
266 | else: | |
267 | for thisChannel in channelList: |
|
267 | for thisChannel in channelList: | |
268 | if thisChannel not in self.dataOut.channelList: |
|
268 | if thisChannel not in self.dataOut.channelList: | |
269 | continue |
|
269 | continue | |
270 |
|
270 | |||
271 | for thisProfile in profileList: |
|
271 | for thisProfile in profileList: | |
272 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
272 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
273 | flip *= -1.0 |
|
273 | flip *= -1.0 | |
274 |
|
274 | |||
275 | self.flip = flip |
|
275 | self.flip = flip | |
276 |
|
276 | |||
277 | else: |
|
277 | else: | |
278 | if not channelList: |
|
278 | if not channelList: | |
279 | data[:,:] = data[:,:]*self.flip |
|
279 | data[:,:] = data[:,:]*self.flip | |
280 | else: |
|
280 | else: | |
281 | for thisChannel in channelList: |
|
281 | for thisChannel in channelList: | |
282 | if thisChannel not in self.dataOut.channelList: |
|
282 | if thisChannel not in self.dataOut.channelList: | |
283 | continue |
|
283 | continue | |
284 |
|
284 | |||
285 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
285 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
286 |
|
286 | |||
287 | self.flip *= -1. |
|
287 | self.flip *= -1. | |
288 |
|
288 | |||
289 | self.dataOut.data = data |
|
289 | self.dataOut.data = data | |
290 |
|
290 | |||
291 | def setRadarFrequency(self, frequency=None): |
|
291 | def setRadarFrequency(self, frequency=None): | |
292 |
|
292 | |||
293 | if frequency != None: |
|
293 | if frequency != None: | |
294 | self.dataOut.frequency = frequency |
|
294 | self.dataOut.frequency = frequency | |
295 |
|
295 | |||
296 | return 1 |
|
296 | return 1 | |
297 |
|
297 | |||
298 | def interpolateHeights(self, topLim, botLim): |
|
298 | def interpolateHeights(self, topLim, botLim): | |
299 | #69 al 72 para julia |
|
299 | #69 al 72 para julia | |
300 | #82-84 para meteoros |
|
300 | #82-84 para meteoros | |
301 | if len(numpy.shape(self.dataOut.data))==2: |
|
301 | if len(numpy.shape(self.dataOut.data))==2: | |
302 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 |
|
302 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 | |
303 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
303 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
304 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp |
|
304 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp | |
305 | self.dataOut.data[:,botLim:topLim+1] = sampInterp |
|
305 | self.dataOut.data[:,botLim:topLim+1] = sampInterp | |
306 | else: |
|
306 | else: | |
307 | nHeights = self.dataOut.data.shape[2] |
|
307 | nHeights = self.dataOut.data.shape[2] | |
308 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
308 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
309 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] |
|
309 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] | |
310 | f = interpolate.interp1d(x, y, axis = 2) |
|
310 | f = interpolate.interp1d(x, y, axis = 2) | |
311 | xnew = numpy.arange(botLim,topLim+1) |
|
311 | xnew = numpy.arange(botLim,topLim+1) | |
312 | ynew = f(xnew) |
|
312 | ynew = f(xnew) | |
313 |
|
313 | |||
314 | self.dataOut.data[:,:,botLim:topLim+1] = ynew |
|
314 | self.dataOut.data[:,:,botLim:topLim+1] = ynew | |
315 |
|
315 | |||
316 | # import collections |
|
316 | # import collections | |
317 |
|
317 | |||
318 | class CohInt(Operation): |
|
318 | class CohInt(Operation): | |
319 |
|
319 | |||
320 | isConfig = False |
|
320 | isConfig = False | |
321 |
|
321 | |||
322 | __profIndex = 0 |
|
322 | __profIndex = 0 | |
323 | __withOverapping = False |
|
323 | __withOverapping = False | |
324 |
|
324 | |||
325 | __byTime = False |
|
325 | __byTime = False | |
326 | __initime = None |
|
326 | __initime = None | |
327 | __lastdatatime = None |
|
327 | __lastdatatime = None | |
328 | __integrationtime = None |
|
328 | __integrationtime = None | |
329 |
|
329 | |||
330 | __buffer = None |
|
330 | __buffer = None | |
331 |
|
331 | |||
332 | __dataReady = False |
|
332 | __dataReady = False | |
333 |
|
333 | |||
334 | n = None |
|
334 | n = None | |
335 |
|
335 | |||
336 | def __init__(self, **kwargs): |
|
336 | def __init__(self, **kwargs): | |
337 |
|
337 | |||
338 | Operation.__init__(self, **kwargs) |
|
338 | Operation.__init__(self, **kwargs) | |
339 |
|
339 | |||
340 | # self.isConfig = False |
|
340 | # self.isConfig = False | |
341 |
|
341 | |||
342 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): |
|
342 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): | |
343 | """ |
|
343 | """ | |
344 | Set the parameters of the integration class. |
|
344 | Set the parameters of the integration class. | |
345 |
|
345 | |||
346 | Inputs: |
|
346 | Inputs: | |
347 |
|
347 | |||
348 | n : Number of coherent integrations |
|
348 | n : Number of coherent integrations | |
349 | 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 | |
350 | overlapping : |
|
350 | overlapping : | |
351 | """ |
|
351 | """ | |
352 |
|
352 | |||
353 | self.__initime = None |
|
353 | self.__initime = None | |
354 | self.__lastdatatime = 0 |
|
354 | self.__lastdatatime = 0 | |
355 | self.__buffer = None |
|
355 | self.__buffer = None | |
356 | self.__dataReady = False |
|
356 | self.__dataReady = False | |
357 | self.byblock = byblock |
|
357 | self.byblock = byblock | |
358 |
|
358 | |||
359 | if n == None and timeInterval == None: |
|
359 | if n == None and timeInterval == None: | |
360 | raise ValueError, "n or timeInterval should be specified ..." |
|
360 | raise ValueError, "n or timeInterval should be specified ..." | |
361 |
|
361 | |||
362 | if n != None: |
|
362 | if n != None: | |
363 | self.n = n |
|
363 | self.n = n | |
364 | self.__byTime = False |
|
364 | self.__byTime = False | |
365 | else: |
|
365 | else: | |
366 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
366 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
367 | self.n = 9999 |
|
367 | self.n = 9999 | |
368 | self.__byTime = True |
|
368 | self.__byTime = True | |
369 |
|
369 | |||
370 | if overlapping: |
|
370 | if overlapping: | |
371 | self.__withOverapping = True |
|
371 | self.__withOverapping = True | |
372 | self.__buffer = None |
|
372 | self.__buffer = None | |
373 | else: |
|
373 | else: | |
374 | self.__withOverapping = False |
|
374 | self.__withOverapping = False | |
375 | self.__buffer = 0 |
|
375 | self.__buffer = 0 | |
376 |
|
376 | |||
377 | self.__profIndex = 0 |
|
377 | self.__profIndex = 0 | |
378 |
|
378 | |||
379 | def putData(self, data): |
|
379 | def putData(self, data): | |
380 |
|
380 | |||
381 | """ |
|
381 | """ | |
382 | Add a profile to the __buffer and increase in one the __profileIndex |
|
382 | Add a profile to the __buffer and increase in one the __profileIndex | |
383 |
|
383 | |||
384 | """ |
|
384 | """ | |
385 |
|
385 | |||
386 | if not self.__withOverapping: |
|
386 | if not self.__withOverapping: | |
387 | self.__buffer += data.copy() |
|
387 | self.__buffer += data.copy() | |
388 | self.__profIndex += 1 |
|
388 | self.__profIndex += 1 | |
389 | return |
|
389 | return | |
390 |
|
390 | |||
391 | #Overlapping data |
|
391 | #Overlapping data | |
392 | nChannels, nHeis = data.shape |
|
392 | nChannels, nHeis = data.shape | |
393 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
393 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
394 |
|
394 | |||
395 | #If the buffer is empty then it takes the data value |
|
395 | #If the buffer is empty then it takes the data value | |
396 | if self.__buffer is None: |
|
396 | if self.__buffer is None: | |
397 | self.__buffer = data |
|
397 | self.__buffer = data | |
398 | self.__profIndex += 1 |
|
398 | self.__profIndex += 1 | |
399 | return |
|
399 | return | |
400 |
|
400 | |||
401 | #If the buffer length is lower than n then stakcing the data value |
|
401 | #If the buffer length is lower than n then stakcing the data value | |
402 | if self.__profIndex < self.n: |
|
402 | if self.__profIndex < self.n: | |
403 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
403 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
404 | self.__profIndex += 1 |
|
404 | self.__profIndex += 1 | |
405 | return |
|
405 | return | |
406 |
|
406 | |||
407 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
407 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
408 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
408 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
409 | self.__buffer[self.n-1] = data |
|
409 | self.__buffer[self.n-1] = data | |
410 | self.__profIndex = self.n |
|
410 | self.__profIndex = self.n | |
411 | return |
|
411 | return | |
412 |
|
412 | |||
413 |
|
413 | |||
414 | def pushData(self): |
|
414 | def pushData(self): | |
415 | """ |
|
415 | """ | |
416 | Return the sum of the last profiles and the profiles used in the sum. |
|
416 | Return the sum of the last profiles and the profiles used in the sum. | |
417 |
|
417 | |||
418 | Affected: |
|
418 | Affected: | |
419 |
|
419 | |||
420 | self.__profileIndex |
|
420 | self.__profileIndex | |
421 |
|
421 | |||
422 | """ |
|
422 | """ | |
423 |
|
423 | |||
424 | if not self.__withOverapping: |
|
424 | if not self.__withOverapping: | |
425 | data = self.__buffer |
|
425 | data = self.__buffer | |
426 | n = self.__profIndex |
|
426 | n = self.__profIndex | |
427 |
|
427 | |||
428 | self.__buffer = 0 |
|
428 | self.__buffer = 0 | |
429 | self.__profIndex = 0 |
|
429 | self.__profIndex = 0 | |
430 |
|
430 | |||
431 | return data, n |
|
431 | return data, n | |
432 |
|
432 | |||
433 | #Integration with Overlapping |
|
433 | #Integration with Overlapping | |
434 | data = numpy.sum(self.__buffer, axis=0) |
|
434 | data = numpy.sum(self.__buffer, axis=0) | |
435 | n = self.__profIndex |
|
435 | n = self.__profIndex | |
436 |
|
436 | |||
437 | return data, n |
|
437 | return data, n | |
438 |
|
438 | |||
439 | def byProfiles(self, data): |
|
439 | def byProfiles(self, data): | |
440 |
|
440 | |||
441 | self.__dataReady = False |
|
441 | self.__dataReady = False | |
442 | avgdata = None |
|
442 | avgdata = None | |
443 | # n = None |
|
443 | # n = None | |
444 |
|
444 | |||
445 | self.putData(data) |
|
445 | self.putData(data) | |
446 |
|
446 | |||
447 | if self.__profIndex == self.n: |
|
447 | if self.__profIndex == self.n: | |
448 |
|
448 | |||
449 | avgdata, n = self.pushData() |
|
449 | avgdata, n = self.pushData() | |
450 | self.__dataReady = True |
|
450 | self.__dataReady = True | |
451 |
|
451 | |||
452 | return avgdata |
|
452 | return avgdata | |
453 |
|
453 | |||
454 | def byTime(self, data, datatime): |
|
454 | def byTime(self, data, datatime): | |
455 |
|
455 | |||
456 | self.__dataReady = False |
|
456 | self.__dataReady = False | |
457 | avgdata = None |
|
457 | avgdata = None | |
458 | n = None |
|
458 | n = None | |
459 |
|
459 | |||
460 | self.putData(data) |
|
460 | self.putData(data) | |
461 |
|
461 | |||
462 | if (datatime - self.__initime) >= self.__integrationtime: |
|
462 | if (datatime - self.__initime) >= self.__integrationtime: | |
463 | avgdata, n = self.pushData() |
|
463 | avgdata, n = self.pushData() | |
464 | self.n = n |
|
464 | self.n = n | |
465 | self.__dataReady = True |
|
465 | self.__dataReady = True | |
466 |
|
466 | |||
467 | return avgdata |
|
467 | return avgdata | |
468 |
|
468 | |||
469 | def integrate(self, data, datatime=None): |
|
469 | def integrate(self, data, datatime=None): | |
470 |
|
470 | |||
471 | if self.__initime == None: |
|
471 | if self.__initime == None: | |
472 | self.__initime = datatime |
|
472 | self.__initime = datatime | |
473 |
|
473 | |||
474 | if self.__byTime: |
|
474 | if self.__byTime: | |
475 | avgdata = self.byTime(data, datatime) |
|
475 | avgdata = self.byTime(data, datatime) | |
476 | else: |
|
476 | else: | |
477 | avgdata = self.byProfiles(data) |
|
477 | avgdata = self.byProfiles(data) | |
478 |
|
478 | |||
479 |
|
479 | |||
480 | self.__lastdatatime = datatime |
|
480 | self.__lastdatatime = datatime | |
481 |
|
481 | |||
482 | if avgdata is None: |
|
482 | if avgdata is None: | |
483 | return None, None |
|
483 | return None, None | |
484 |
|
484 | |||
485 | avgdatatime = self.__initime |
|
485 | avgdatatime = self.__initime | |
486 |
|
486 | |||
487 | deltatime = datatime -self.__lastdatatime |
|
487 | deltatime = datatime -self.__lastdatatime | |
488 |
|
488 | |||
489 | if not self.__withOverapping: |
|
489 | if not self.__withOverapping: | |
490 | self.__initime = datatime |
|
490 | self.__initime = datatime | |
491 | else: |
|
491 | else: | |
492 | self.__initime += deltatime |
|
492 | self.__initime += deltatime | |
493 |
|
493 | |||
494 | return avgdata, avgdatatime |
|
494 | return avgdata, avgdatatime | |
495 |
|
495 | |||
496 | def integrateByBlock(self, dataOut): |
|
496 | def integrateByBlock(self, dataOut): | |
497 |
|
497 | |||
498 | times = int(dataOut.data.shape[1]/self.n) |
|
498 | times = int(dataOut.data.shape[1]/self.n) | |
499 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
499 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
500 |
|
500 | |||
501 | id_min = 0 |
|
501 | id_min = 0 | |
502 | id_max = self.n |
|
502 | id_max = self.n | |
503 |
|
503 | |||
504 | for i in range(times): |
|
504 | for i in range(times): | |
505 | junk = dataOut.data[:,id_min:id_max,:] |
|
505 | junk = dataOut.data[:,id_min:id_max,:] | |
506 | avgdata[:,i,:] = junk.sum(axis=1) |
|
506 | avgdata[:,i,:] = junk.sum(axis=1) | |
507 | id_min += self.n |
|
507 | id_min += self.n | |
508 | id_max += self.n |
|
508 | id_max += self.n | |
509 |
|
509 | |||
510 | timeInterval = dataOut.ippSeconds*self.n |
|
510 | timeInterval = dataOut.ippSeconds*self.n | |
511 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
511 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
512 | self.__dataReady = True |
|
512 | self.__dataReady = True | |
513 | return avgdata, avgdatatime |
|
513 | return avgdata, avgdatatime | |
514 |
|
514 | |||
515 |
|
515 | |||
516 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs): |
|
516 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs): | |
517 | if not self.isConfig: |
|
517 | if not self.isConfig: | |
518 | self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
518 | self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
519 | self.isConfig = True |
|
519 | self.isConfig = True | |
520 |
|
520 | |||
521 | if dataOut.flagDataAsBlock: |
|
521 | if dataOut.flagDataAsBlock: | |
522 | """ |
|
522 | """ | |
523 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
523 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
524 | """ |
|
524 | """ | |
525 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
525 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
526 | dataOut.nProfiles /= self.n |
|
526 | dataOut.nProfiles /= self.n | |
527 | else: |
|
527 | else: | |
528 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
528 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
529 |
|
529 | |||
530 | # dataOut.timeInterval *= n |
|
530 | # dataOut.timeInterval *= n | |
531 | dataOut.flagNoData = True |
|
531 | dataOut.flagNoData = True | |
532 |
|
532 | |||
533 | if self.__dataReady: |
|
533 | if self.__dataReady: | |
534 | dataOut.data = avgdata |
|
534 | dataOut.data = avgdata | |
535 | dataOut.nCohInt *= self.n |
|
535 | dataOut.nCohInt *= self.n | |
536 | dataOut.utctime = avgdatatime |
|
536 | dataOut.utctime = avgdatatime | |
537 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
537 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
538 | dataOut.flagNoData = False |
|
538 | dataOut.flagNoData = False | |
539 |
|
539 | |||
540 | class Decoder(Operation): |
|
540 | class Decoder(Operation): | |
541 |
|
541 | |||
542 | isConfig = False |
|
542 | isConfig = False | |
543 | __profIndex = 0 |
|
543 | __profIndex = 0 | |
544 |
|
544 | |||
545 | code = None |
|
545 | code = None | |
546 |
|
546 | |||
547 | nCode = None |
|
547 | nCode = None | |
548 | nBaud = None |
|
548 | nBaud = None | |
549 |
|
549 | |||
550 | def __init__(self, **kwargs): |
|
550 | def __init__(self, **kwargs): | |
551 |
|
551 | |||
552 | Operation.__init__(self, **kwargs) |
|
552 | Operation.__init__(self, **kwargs) | |
553 |
|
553 | |||
554 | self.times = None |
|
554 | self.times = None | |
555 | self.osamp = None |
|
555 | self.osamp = None | |
556 | # self.__setValues = False |
|
556 | # self.__setValues = False | |
557 | self.isConfig = False |
|
557 | self.isConfig = False | |
558 |
|
558 | |||
559 | def setup(self, code, osamp, dataOut): |
|
559 | def setup(self, code, osamp, dataOut): | |
560 |
|
560 | |||
561 | self.__profIndex = 0 |
|
561 | self.__profIndex = 0 | |
562 |
|
562 | |||
563 | self.code = code |
|
563 | self.code = code | |
564 |
|
564 | |||
565 | self.nCode = len(code) |
|
565 | self.nCode = len(code) | |
566 | self.nBaud = len(code[0]) |
|
566 | self.nBaud = len(code[0]) | |
567 |
|
567 | |||
568 | if (osamp != None) and (osamp >1): |
|
568 | if (osamp != None) and (osamp >1): | |
569 | self.osamp = osamp |
|
569 | self.osamp = osamp | |
570 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
570 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
571 | self.nBaud = self.nBaud*self.osamp |
|
571 | self.nBaud = self.nBaud*self.osamp | |
572 |
|
572 | |||
573 | self.__nChannels = dataOut.nChannels |
|
573 | self.__nChannels = dataOut.nChannels | |
574 | self.__nProfiles = dataOut.nProfiles |
|
574 | self.__nProfiles = dataOut.nProfiles | |
575 | self.__nHeis = dataOut.nHeights |
|
575 | self.__nHeis = dataOut.nHeights | |
576 |
|
576 | |||
577 | if self.__nHeis < self.nBaud: |
|
577 | if self.__nHeis < self.nBaud: | |
578 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) |
|
578 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) | |
579 |
|
579 | |||
580 | #Frequency |
|
580 | #Frequency | |
581 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
581 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
582 |
|
582 | |||
583 | __codeBuffer[:,0:self.nBaud] = self.code |
|
583 | __codeBuffer[:,0:self.nBaud] = self.code | |
584 |
|
584 | |||
585 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
585 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
586 |
|
586 | |||
587 | if dataOut.flagDataAsBlock: |
|
587 | if dataOut.flagDataAsBlock: | |
588 |
|
588 | |||
589 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
589 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
590 |
|
590 | |||
591 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
591 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
592 |
|
592 | |||
593 | else: |
|
593 | else: | |
594 |
|
594 | |||
595 | #Time |
|
595 | #Time | |
596 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
596 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
597 |
|
597 | |||
598 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
598 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
599 |
|
599 | |||
600 | def __convolutionInFreq(self, data): |
|
600 | def __convolutionInFreq(self, data): | |
601 |
|
601 | |||
602 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
602 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
603 |
|
603 | |||
604 | fft_data = numpy.fft.fft(data, axis=1) |
|
604 | fft_data = numpy.fft.fft(data, axis=1) | |
605 |
|
605 | |||
606 | conv = fft_data*fft_code |
|
606 | conv = fft_data*fft_code | |
607 |
|
607 | |||
608 | data = numpy.fft.ifft(conv,axis=1) |
|
608 | data = numpy.fft.ifft(conv,axis=1) | |
609 |
|
609 | |||
610 | return data |
|
610 | return data | |
611 |
|
611 | |||
612 | def __convolutionInFreqOpt(self, data): |
|
612 | def __convolutionInFreqOpt(self, data): | |
613 |
|
613 | |||
614 | raise NotImplementedError |
|
614 | raise NotImplementedError | |
615 |
|
615 | |||
616 | def __convolutionInTime(self, data): |
|
616 | def __convolutionInTime(self, data): | |
617 |
|
617 | |||
618 | code = self.code[self.__profIndex] |
|
618 | code = self.code[self.__profIndex] | |
619 |
|
||||
620 | for i in range(self.__nChannels): |
|
619 | for i in range(self.__nChannels): | |
621 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
620 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
622 |
|
621 | |||
623 | return self.datadecTime |
|
622 | return self.datadecTime | |
624 |
|
623 | |||
625 | def __convolutionByBlockInTime(self, data): |
|
624 | def __convolutionByBlockInTime(self, data): | |
626 |
|
625 | |||
627 | repetitions = self.__nProfiles / self.nCode |
|
626 | repetitions = self.__nProfiles / self.nCode | |
628 |
|
627 | |||
629 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
628 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
630 | junk = junk.flatten() |
|
629 | junk = junk.flatten() | |
631 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
630 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
632 | profilesList = xrange(self.__nProfiles) |
|
631 | profilesList = xrange(self.__nProfiles) | |
633 |
|
632 | |||
634 | for i in range(self.__nChannels): |
|
633 | for i in range(self.__nChannels): | |
635 | for j in profilesList: |
|
634 | for j in profilesList: | |
636 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
635 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
637 | return self.datadecTime |
|
636 | return self.datadecTime | |
638 |
|
637 | |||
639 | def __convolutionByBlockInFreq(self, data): |
|
638 | def __convolutionByBlockInFreq(self, data): | |
640 |
|
639 | |||
641 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" |
|
640 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" | |
642 |
|
641 | |||
643 |
|
642 | |||
644 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
643 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
645 |
|
644 | |||
646 | fft_data = numpy.fft.fft(data, axis=2) |
|
645 | fft_data = numpy.fft.fft(data, axis=2) | |
647 |
|
646 | |||
648 | conv = fft_data*fft_code |
|
647 | conv = fft_data*fft_code | |
649 |
|
648 | |||
650 | data = numpy.fft.ifft(conv,axis=2) |
|
649 | data = numpy.fft.ifft(conv,axis=2) | |
651 |
|
650 | |||
652 | return data |
|
651 | return data | |
653 |
|
652 | |||
654 |
|
653 | |||
655 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
654 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
656 |
|
655 | |||
657 | if dataOut.flagDecodeData: |
|
656 | if dataOut.flagDecodeData: | |
658 | print "This data is already decoded, recoding again ..." |
|
657 | print "This data is already decoded, recoding again ..." | |
659 |
|
658 | |||
660 | if not self.isConfig: |
|
659 | if not self.isConfig: | |
661 |
|
660 | |||
662 | if code is None: |
|
661 | if code is None: | |
663 | if dataOut.code is None: |
|
662 | if dataOut.code is None: | |
664 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type |
|
663 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type | |
665 |
|
664 | |||
666 | code = dataOut.code |
|
665 | code = dataOut.code | |
667 | else: |
|
666 | else: | |
668 | code = numpy.array(code).reshape(nCode,nBaud) |
|
667 | code = numpy.array(code).reshape(nCode,nBaud) | |
669 |
|
||||
670 | self.setup(code, osamp, dataOut) |
|
668 | self.setup(code, osamp, dataOut) | |
671 |
|
669 | |||
672 | self.isConfig = True |
|
670 | self.isConfig = True | |
673 |
|
671 | |||
674 | if mode == 3: |
|
672 | if mode == 3: | |
675 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
673 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
676 |
|
674 | |||
677 | if times != None: |
|
675 | if times != None: | |
678 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
676 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
679 |
|
677 | |||
680 | if self.code is None: |
|
678 | if self.code is None: | |
681 | print "Fail decoding: Code is not defined." |
|
679 | print "Fail decoding: Code is not defined." | |
682 | return |
|
680 | return | |
683 |
|
681 | |||
684 | self.__nProfiles = dataOut.nProfiles |
|
682 | self.__nProfiles = dataOut.nProfiles | |
685 | datadec = None |
|
683 | datadec = None | |
686 |
|
684 | |||
687 | if mode == 3: |
|
685 | if mode == 3: | |
688 | mode = 0 |
|
686 | mode = 0 | |
689 |
|
687 | |||
690 | if dataOut.flagDataAsBlock: |
|
688 | if dataOut.flagDataAsBlock: | |
691 | """ |
|
689 | """ | |
692 | Decoding when data have been read as block, |
|
690 | Decoding when data have been read as block, | |
693 | """ |
|
691 | """ | |
694 |
|
692 | |||
695 | if mode == 0: |
|
693 | if mode == 0: | |
696 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
694 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
697 | if mode == 1: |
|
695 | if mode == 1: | |
698 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
696 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
699 | else: |
|
697 | else: | |
700 | """ |
|
698 | """ | |
701 | Decoding when data have been read profile by profile |
|
699 | Decoding when data have been read profile by profile | |
702 | """ |
|
700 | """ | |
703 | if mode == 0: |
|
701 | if mode == 0: | |
704 | datadec = self.__convolutionInTime(dataOut.data) |
|
702 | datadec = self.__convolutionInTime(dataOut.data) | |
705 |
|
703 | |||
706 | if mode == 1: |
|
704 | if mode == 1: | |
707 | datadec = self.__convolutionInFreq(dataOut.data) |
|
705 | datadec = self.__convolutionInFreq(dataOut.data) | |
708 |
|
706 | |||
709 | if mode == 2: |
|
707 | if mode == 2: | |
710 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
708 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
711 |
|
709 | |||
712 | if datadec is None: |
|
710 | if datadec is None: | |
713 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode |
|
711 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode | |
714 |
|
712 | |||
715 | dataOut.code = self.code |
|
713 | dataOut.code = self.code | |
716 | dataOut.nCode = self.nCode |
|
714 | dataOut.nCode = self.nCode | |
717 | dataOut.nBaud = self.nBaud |
|
715 | dataOut.nBaud = self.nBaud | |
718 |
|
716 | |||
719 | dataOut.data = datadec |
|
717 | dataOut.data = datadec | |
720 |
|
718 | |||
721 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
719 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
722 |
|
720 | |||
723 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
721 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
724 |
|
722 | |||
725 | if self.__profIndex == self.nCode-1: |
|
723 | if self.__profIndex == self.nCode-1: | |
726 | self.__profIndex = 0 |
|
724 | self.__profIndex = 0 | |
727 | return 1 |
|
725 | return 1 | |
728 |
|
726 | |||
729 | self.__profIndex += 1 |
|
727 | self.__profIndex += 1 | |
730 |
|
728 | |||
731 | return 1 |
|
729 | return 1 | |
732 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
730 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
733 |
|
731 | |||
734 |
|
732 | |||
735 | class ProfileConcat(Operation): |
|
733 | class ProfileConcat(Operation): | |
736 |
|
734 | |||
737 | isConfig = False |
|
735 | isConfig = False | |
738 | buffer = None |
|
736 | buffer = None | |
739 |
|
737 | |||
740 | def __init__(self, **kwargs): |
|
738 | def __init__(self, **kwargs): | |
741 |
|
739 | |||
742 | Operation.__init__(self, **kwargs) |
|
740 | Operation.__init__(self, **kwargs) | |
743 | self.profileIndex = 0 |
|
741 | self.profileIndex = 0 | |
744 |
|
742 | |||
745 | def reset(self): |
|
743 | def reset(self): | |
746 | self.buffer = numpy.zeros_like(self.buffer) |
|
744 | self.buffer = numpy.zeros_like(self.buffer) | |
747 | self.start_index = 0 |
|
745 | self.start_index = 0 | |
748 | self.times = 1 |
|
746 | self.times = 1 | |
749 |
|
747 | |||
750 | def setup(self, data, m, n=1): |
|
748 | def setup(self, data, m, n=1): | |
751 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
749 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
752 | self.nHeights = data.shape[1]#.nHeights |
|
750 | self.nHeights = data.shape[1]#.nHeights | |
753 | self.start_index = 0 |
|
751 | self.start_index = 0 | |
754 | self.times = 1 |
|
752 | self.times = 1 | |
755 |
|
753 | |||
756 | def concat(self, data): |
|
754 | def concat(self, data): | |
757 |
|
755 | |||
758 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
756 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
759 | self.start_index = self.start_index + self.nHeights |
|
757 | self.start_index = self.start_index + self.nHeights | |
760 |
|
758 | |||
761 | def run(self, dataOut, m): |
|
759 | def run(self, dataOut, m): | |
762 |
|
760 | |||
763 | dataOut.flagNoData = True |
|
761 | dataOut.flagNoData = True | |
764 |
|
762 | |||
765 | if not self.isConfig: |
|
763 | if not self.isConfig: | |
766 | self.setup(dataOut.data, m, 1) |
|
764 | self.setup(dataOut.data, m, 1) | |
767 | self.isConfig = True |
|
765 | self.isConfig = True | |
768 |
|
766 | |||
769 | if dataOut.flagDataAsBlock: |
|
767 | if dataOut.flagDataAsBlock: | |
770 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" |
|
768 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" | |
771 |
|
769 | |||
772 | else: |
|
770 | else: | |
773 | self.concat(dataOut.data) |
|
771 | self.concat(dataOut.data) | |
774 | self.times += 1 |
|
772 | self.times += 1 | |
775 | if self.times > m: |
|
773 | if self.times > m: | |
776 | dataOut.data = self.buffer |
|
774 | dataOut.data = self.buffer | |
777 | self.reset() |
|
775 | self.reset() | |
778 | dataOut.flagNoData = False |
|
776 | dataOut.flagNoData = False | |
779 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
777 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
780 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
778 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
781 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
779 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
782 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
780 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
783 | dataOut.ippSeconds *= m |
|
781 | dataOut.ippSeconds *= m | |
784 |
|
782 | |||
785 | class ProfileSelector(Operation): |
|
783 | class ProfileSelector(Operation): | |
786 |
|
784 | |||
787 | profileIndex = None |
|
785 | profileIndex = None | |
788 | # Tamanho total de los perfiles |
|
786 | # Tamanho total de los perfiles | |
789 | nProfiles = None |
|
787 | nProfiles = None | |
790 |
|
788 | |||
791 | def __init__(self, **kwargs): |
|
789 | def __init__(self, **kwargs): | |
792 |
|
790 | |||
793 | Operation.__init__(self, **kwargs) |
|
791 | Operation.__init__(self, **kwargs) | |
794 | self.profileIndex = 0 |
|
792 | self.profileIndex = 0 | |
795 |
|
793 | |||
796 | def incProfileIndex(self): |
|
794 | def incProfileIndex(self): | |
797 |
|
795 | |||
798 | self.profileIndex += 1 |
|
796 | self.profileIndex += 1 | |
799 |
|
797 | |||
800 | if self.profileIndex >= self.nProfiles: |
|
798 | if self.profileIndex >= self.nProfiles: | |
801 | self.profileIndex = 0 |
|
799 | self.profileIndex = 0 | |
802 |
|
800 | |||
803 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
801 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
804 |
|
802 | |||
805 | if profileIndex < minIndex: |
|
803 | if profileIndex < minIndex: | |
806 | return False |
|
804 | return False | |
807 |
|
805 | |||
808 | if profileIndex > maxIndex: |
|
806 | if profileIndex > maxIndex: | |
809 | return False |
|
807 | return False | |
810 |
|
808 | |||
811 | return True |
|
809 | return True | |
812 |
|
810 | |||
813 | def isThisProfileInList(self, profileIndex, profileList): |
|
811 | def isThisProfileInList(self, profileIndex, profileList): | |
814 |
|
812 | |||
815 | if profileIndex not in profileList: |
|
813 | if profileIndex not in profileList: | |
816 | return False |
|
814 | return False | |
817 |
|
815 | |||
818 | return True |
|
816 | return True | |
819 |
|
817 | |||
820 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
818 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
821 |
|
819 | |||
822 | """ |
|
820 | """ | |
823 | ProfileSelector: |
|
821 | ProfileSelector: | |
824 |
|
822 | |||
825 | Inputs: |
|
823 | Inputs: | |
826 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
824 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
827 |
|
825 | |||
828 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
826 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
829 |
|
827 | |||
830 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
828 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
831 |
|
829 | |||
832 | """ |
|
830 | """ | |
833 |
|
831 | |||
834 | if rangeList is not None: |
|
832 | if rangeList is not None: | |
835 | if type(rangeList[0]) not in (tuple, list): |
|
833 | if type(rangeList[0]) not in (tuple, list): | |
836 | rangeList = [rangeList] |
|
834 | rangeList = [rangeList] | |
837 |
|
835 | |||
838 | dataOut.flagNoData = True |
|
836 | dataOut.flagNoData = True | |
839 |
|
837 | |||
840 | if dataOut.flagDataAsBlock: |
|
838 | if dataOut.flagDataAsBlock: | |
841 | """ |
|
839 | """ | |
842 | data dimension = [nChannels, nProfiles, nHeis] |
|
840 | data dimension = [nChannels, nProfiles, nHeis] | |
843 | """ |
|
841 | """ | |
844 | if profileList != None: |
|
842 | if profileList != None: | |
845 | dataOut.data = dataOut.data[:,profileList,:] |
|
843 | dataOut.data = dataOut.data[:,profileList,:] | |
846 |
|
844 | |||
847 | if profileRangeList != None: |
|
845 | if profileRangeList != None: | |
848 | minIndex = profileRangeList[0] |
|
846 | minIndex = profileRangeList[0] | |
849 | maxIndex = profileRangeList[1] |
|
847 | maxIndex = profileRangeList[1] | |
850 | profileList = range(minIndex, maxIndex+1) |
|
848 | profileList = range(minIndex, maxIndex+1) | |
851 |
|
849 | |||
852 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
850 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
853 |
|
851 | |||
854 | if rangeList != None: |
|
852 | if rangeList != None: | |
855 |
|
853 | |||
856 | profileList = [] |
|
854 | profileList = [] | |
857 |
|
855 | |||
858 | for thisRange in rangeList: |
|
856 | for thisRange in rangeList: | |
859 | minIndex = thisRange[0] |
|
857 | minIndex = thisRange[0] | |
860 | maxIndex = thisRange[1] |
|
858 | maxIndex = thisRange[1] | |
861 |
|
859 | |||
862 | profileList.extend(range(minIndex, maxIndex+1)) |
|
860 | profileList.extend(range(minIndex, maxIndex+1)) | |
863 |
|
861 | |||
864 | dataOut.data = dataOut.data[:,profileList,:] |
|
862 | dataOut.data = dataOut.data[:,profileList,:] | |
865 |
|
863 | |||
866 | dataOut.nProfiles = len(profileList) |
|
864 | dataOut.nProfiles = len(profileList) | |
867 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
865 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
868 | dataOut.flagNoData = False |
|
866 | dataOut.flagNoData = False | |
869 |
|
867 | |||
870 | return True |
|
868 | return True | |
871 |
|
869 | |||
872 | """ |
|
870 | """ | |
873 | data dimension = [nChannels, nHeis] |
|
871 | data dimension = [nChannels, nHeis] | |
874 | """ |
|
872 | """ | |
875 |
|
873 | |||
876 | if profileList != None: |
|
874 | if profileList != None: | |
877 |
|
875 | |||
878 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
876 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
879 |
|
877 | |||
880 | self.nProfiles = len(profileList) |
|
878 | self.nProfiles = len(profileList) | |
881 | dataOut.nProfiles = self.nProfiles |
|
879 | dataOut.nProfiles = self.nProfiles | |
882 | dataOut.profileIndex = self.profileIndex |
|
880 | dataOut.profileIndex = self.profileIndex | |
883 | dataOut.flagNoData = False |
|
881 | dataOut.flagNoData = False | |
884 |
|
882 | |||
885 | self.incProfileIndex() |
|
883 | self.incProfileIndex() | |
886 | return True |
|
884 | return True | |
887 |
|
885 | |||
888 | if profileRangeList != None: |
|
886 | if profileRangeList != None: | |
889 |
|
887 | |||
890 | minIndex = profileRangeList[0] |
|
888 | minIndex = profileRangeList[0] | |
891 | maxIndex = profileRangeList[1] |
|
889 | maxIndex = profileRangeList[1] | |
892 |
|
890 | |||
893 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
891 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
894 |
|
892 | |||
895 | self.nProfiles = maxIndex - minIndex + 1 |
|
893 | self.nProfiles = maxIndex - minIndex + 1 | |
896 | dataOut.nProfiles = self.nProfiles |
|
894 | dataOut.nProfiles = self.nProfiles | |
897 | dataOut.profileIndex = self.profileIndex |
|
895 | dataOut.profileIndex = self.profileIndex | |
898 | dataOut.flagNoData = False |
|
896 | dataOut.flagNoData = False | |
899 |
|
897 | |||
900 | self.incProfileIndex() |
|
898 | self.incProfileIndex() | |
901 | return True |
|
899 | return True | |
902 |
|
900 | |||
903 | if rangeList != None: |
|
901 | if rangeList != None: | |
904 |
|
902 | |||
905 | nProfiles = 0 |
|
903 | nProfiles = 0 | |
906 |
|
904 | |||
907 | for thisRange in rangeList: |
|
905 | for thisRange in rangeList: | |
908 | minIndex = thisRange[0] |
|
906 | minIndex = thisRange[0] | |
909 | maxIndex = thisRange[1] |
|
907 | maxIndex = thisRange[1] | |
910 |
|
908 | |||
911 | nProfiles += maxIndex - minIndex + 1 |
|
909 | nProfiles += maxIndex - minIndex + 1 | |
912 |
|
910 | |||
913 | for thisRange in rangeList: |
|
911 | for thisRange in rangeList: | |
914 |
|
912 | |||
915 | minIndex = thisRange[0] |
|
913 | minIndex = thisRange[0] | |
916 | maxIndex = thisRange[1] |
|
914 | maxIndex = thisRange[1] | |
917 |
|
915 | |||
918 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
916 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
919 |
|
917 | |||
920 | self.nProfiles = nProfiles |
|
918 | self.nProfiles = nProfiles | |
921 | dataOut.nProfiles = self.nProfiles |
|
919 | dataOut.nProfiles = self.nProfiles | |
922 | dataOut.profileIndex = self.profileIndex |
|
920 | dataOut.profileIndex = self.profileIndex | |
923 | dataOut.flagNoData = False |
|
921 | dataOut.flagNoData = False | |
924 |
|
922 | |||
925 | self.incProfileIndex() |
|
923 | self.incProfileIndex() | |
926 |
|
924 | |||
927 | break |
|
925 | break | |
928 |
|
926 | |||
929 | return True |
|
927 | return True | |
930 |
|
928 | |||
931 |
|
929 | |||
932 | if beam != None: #beam is only for AMISR data |
|
930 | if beam != None: #beam is only for AMISR data | |
933 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
931 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
934 | dataOut.flagNoData = False |
|
932 | dataOut.flagNoData = False | |
935 | dataOut.profileIndex = self.profileIndex |
|
933 | dataOut.profileIndex = self.profileIndex | |
936 |
|
934 | |||
937 | self.incProfileIndex() |
|
935 | self.incProfileIndex() | |
938 |
|
936 | |||
939 | return True |
|
937 | return True | |
940 |
|
938 | |||
941 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" |
|
939 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" | |
942 |
|
940 | |||
943 | return False |
|
941 | return False | |
944 |
|
942 | |||
945 | class Reshaper(Operation): |
|
943 | class Reshaper(Operation): | |
946 |
|
944 | |||
947 | def __init__(self, **kwargs): |
|
945 | def __init__(self, **kwargs): | |
948 |
|
946 | |||
949 | Operation.__init__(self, **kwargs) |
|
947 | Operation.__init__(self, **kwargs) | |
950 |
|
948 | |||
951 | self.__buffer = None |
|
949 | self.__buffer = None | |
952 | self.__nitems = 0 |
|
950 | self.__nitems = 0 | |
953 |
|
951 | |||
954 | def __appendProfile(self, dataOut, nTxs): |
|
952 | def __appendProfile(self, dataOut, nTxs): | |
955 |
|
953 | |||
956 | if self.__buffer is None: |
|
954 | if self.__buffer is None: | |
957 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
955 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
958 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
956 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
959 |
|
957 | |||
960 | ini = dataOut.nHeights * self.__nitems |
|
958 | ini = dataOut.nHeights * self.__nitems | |
961 | end = ini + dataOut.nHeights |
|
959 | end = ini + dataOut.nHeights | |
962 |
|
960 | |||
963 | self.__buffer[:, ini:end] = dataOut.data |
|
961 | self.__buffer[:, ini:end] = dataOut.data | |
964 |
|
962 | |||
965 | self.__nitems += 1 |
|
963 | self.__nitems += 1 | |
966 |
|
964 | |||
967 | return int(self.__nitems*nTxs) |
|
965 | return int(self.__nitems*nTxs) | |
968 |
|
966 | |||
969 | def __getBuffer(self): |
|
967 | def __getBuffer(self): | |
970 |
|
968 | |||
971 | if self.__nitems == int(1./self.__nTxs): |
|
969 | if self.__nitems == int(1./self.__nTxs): | |
972 |
|
970 | |||
973 | self.__nitems = 0 |
|
971 | self.__nitems = 0 | |
974 |
|
972 | |||
975 | return self.__buffer.copy() |
|
973 | return self.__buffer.copy() | |
976 |
|
974 | |||
977 | return None |
|
975 | return None | |
978 |
|
976 | |||
979 | def __checkInputs(self, dataOut, shape, nTxs): |
|
977 | def __checkInputs(self, dataOut, shape, nTxs): | |
980 |
|
978 | |||
981 | if shape is None and nTxs is None: |
|
979 | if shape is None and nTxs is None: | |
982 | raise ValueError, "Reshaper: shape of factor should be defined" |
|
980 | raise ValueError, "Reshaper: shape of factor should be defined" | |
983 |
|
981 | |||
984 | if nTxs: |
|
982 | if nTxs: | |
985 | if nTxs < 0: |
|
983 | if nTxs < 0: | |
986 | raise ValueError, "nTxs should be greater than 0" |
|
984 | raise ValueError, "nTxs should be greater than 0" | |
987 |
|
985 | |||
988 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
986 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
989 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) |
|
987 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) | |
990 |
|
988 | |||
991 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
989 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
992 |
|
990 | |||
993 | return shape, nTxs |
|
991 | return shape, nTxs | |
994 |
|
992 | |||
995 | if len(shape) != 2 and len(shape) != 3: |
|
993 | if len(shape) != 2 and len(shape) != 3: | |
996 | 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) |
|
994 | 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) | |
997 |
|
995 | |||
998 | if len(shape) == 2: |
|
996 | if len(shape) == 2: | |
999 | shape_tuple = [dataOut.nChannels] |
|
997 | shape_tuple = [dataOut.nChannels] | |
1000 | shape_tuple.extend(shape) |
|
998 | shape_tuple.extend(shape) | |
1001 | else: |
|
999 | else: | |
1002 | shape_tuple = list(shape) |
|
1000 | shape_tuple = list(shape) | |
1003 |
|
1001 | |||
1004 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1002 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1005 |
|
1003 | |||
1006 | return shape_tuple, nTxs |
|
1004 | return shape_tuple, nTxs | |
1007 |
|
1005 | |||
1008 | def run(self, dataOut, shape=None, nTxs=None): |
|
1006 | def run(self, dataOut, shape=None, nTxs=None): | |
1009 |
|
1007 | |||
1010 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1008 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1011 |
|
1009 | |||
1012 | dataOut.flagNoData = True |
|
1010 | dataOut.flagNoData = True | |
1013 | profileIndex = None |
|
1011 | profileIndex = None | |
1014 |
|
1012 | |||
1015 | if dataOut.flagDataAsBlock: |
|
1013 | if dataOut.flagDataAsBlock: | |
1016 |
|
1014 | |||
1017 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1015 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1018 | dataOut.flagNoData = False |
|
1016 | dataOut.flagNoData = False | |
1019 |
|
1017 | |||
1020 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1018 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1021 |
|
1019 | |||
1022 | else: |
|
1020 | else: | |
1023 |
|
1021 | |||
1024 | if self.__nTxs < 1: |
|
1022 | if self.__nTxs < 1: | |
1025 |
|
1023 | |||
1026 | self.__appendProfile(dataOut, self.__nTxs) |
|
1024 | self.__appendProfile(dataOut, self.__nTxs) | |
1027 | new_data = self.__getBuffer() |
|
1025 | new_data = self.__getBuffer() | |
1028 |
|
1026 | |||
1029 | if new_data is not None: |
|
1027 | if new_data is not None: | |
1030 | dataOut.data = new_data |
|
1028 | dataOut.data = new_data | |
1031 | dataOut.flagNoData = False |
|
1029 | dataOut.flagNoData = False | |
1032 |
|
1030 | |||
1033 | profileIndex = dataOut.profileIndex*nTxs |
|
1031 | profileIndex = dataOut.profileIndex*nTxs | |
1034 |
|
1032 | |||
1035 | else: |
|
1033 | else: | |
1036 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" |
|
1034 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" | |
1037 |
|
1035 | |||
1038 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1036 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1039 |
|
1037 | |||
1040 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1038 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1041 |
|
1039 | |||
1042 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1040 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1043 |
|
1041 | |||
1044 | dataOut.profileIndex = profileIndex |
|
1042 | dataOut.profileIndex = profileIndex | |
1045 |
|
1043 | |||
1046 | dataOut.ippSeconds /= self.__nTxs |
|
1044 | dataOut.ippSeconds /= self.__nTxs | |
1047 |
|
1045 | |||
1048 | class SplitProfiles(Operation): |
|
1046 | class SplitProfiles(Operation): | |
1049 |
|
1047 | |||
1050 | def __init__(self, **kwargs): |
|
1048 | def __init__(self, **kwargs): | |
1051 |
|
1049 | |||
1052 | Operation.__init__(self, **kwargs) |
|
1050 | Operation.__init__(self, **kwargs) | |
1053 |
|
1051 | |||
1054 | def run(self, dataOut, n): |
|
1052 | def run(self, dataOut, n): | |
1055 |
|
1053 | |||
1056 | dataOut.flagNoData = True |
|
1054 | dataOut.flagNoData = True | |
1057 | profileIndex = None |
|
1055 | profileIndex = None | |
1058 |
|
1056 | |||
1059 | if dataOut.flagDataAsBlock: |
|
1057 | if dataOut.flagDataAsBlock: | |
1060 |
|
1058 | |||
1061 | #nchannels, nprofiles, nsamples |
|
1059 | #nchannels, nprofiles, nsamples | |
1062 | shape = dataOut.data.shape |
|
1060 | shape = dataOut.data.shape | |
1063 |
|
1061 | |||
1064 | if shape[2] % n != 0: |
|
1062 | if shape[2] % n != 0: | |
1065 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) |
|
1063 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) | |
1066 |
|
1064 | |||
1067 | new_shape = shape[0], shape[1]*n, shape[2]/n |
|
1065 | new_shape = shape[0], shape[1]*n, shape[2]/n | |
1068 |
|
1066 | |||
1069 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1067 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1070 | dataOut.flagNoData = False |
|
1068 | dataOut.flagNoData = False | |
1071 |
|
1069 | |||
1072 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1070 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1073 |
|
1071 | |||
1074 | else: |
|
1072 | else: | |
1075 |
|
1073 | |||
1076 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" |
|
1074 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" | |
1077 |
|
1075 | |||
1078 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1076 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1079 |
|
1077 | |||
1080 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1078 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1081 |
|
1079 | |||
1082 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1080 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1083 |
|
1081 | |||
1084 | dataOut.profileIndex = profileIndex |
|
1082 | dataOut.profileIndex = profileIndex | |
1085 |
|
1083 | |||
1086 | dataOut.ippSeconds /= n |
|
1084 | dataOut.ippSeconds /= n | |
1087 |
|
1085 | |||
1088 | class CombineProfiles(Operation): |
|
1086 | class CombineProfiles(Operation): | |
1089 | def __init__(self, **kwargs): |
|
1087 | def __init__(self, **kwargs): | |
1090 |
|
1088 | |||
1091 | Operation.__init__(self, **kwargs) |
|
1089 | Operation.__init__(self, **kwargs) | |
1092 |
|
1090 | |||
1093 | self.__remData = None |
|
1091 | self.__remData = None | |
1094 | self.__profileIndex = 0 |
|
1092 | self.__profileIndex = 0 | |
1095 |
|
1093 | |||
1096 | def run(self, dataOut, n): |
|
1094 | def run(self, dataOut, n): | |
1097 |
|
1095 | |||
1098 | dataOut.flagNoData = True |
|
1096 | dataOut.flagNoData = True | |
1099 | profileIndex = None |
|
1097 | profileIndex = None | |
1100 |
|
1098 | |||
1101 | if dataOut.flagDataAsBlock: |
|
1099 | if dataOut.flagDataAsBlock: | |
1102 |
|
1100 | |||
1103 | #nchannels, nprofiles, nsamples |
|
1101 | #nchannels, nprofiles, nsamples | |
1104 | shape = dataOut.data.shape |
|
1102 | shape = dataOut.data.shape | |
1105 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1103 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1106 |
|
1104 | |||
1107 | if shape[1] % n != 0: |
|
1105 | if shape[1] % n != 0: | |
1108 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) |
|
1106 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) | |
1109 |
|
1107 | |||
1110 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1108 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1111 | dataOut.flagNoData = False |
|
1109 | dataOut.flagNoData = False | |
1112 |
|
1110 | |||
1113 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1111 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1114 |
|
1112 | |||
1115 | else: |
|
1113 | else: | |
1116 |
|
1114 | |||
1117 | #nchannels, nsamples |
|
1115 | #nchannels, nsamples | |
1118 | if self.__remData is None: |
|
1116 | if self.__remData is None: | |
1119 | newData = dataOut.data |
|
1117 | newData = dataOut.data | |
1120 | else: |
|
1118 | else: | |
1121 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1119 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1122 |
|
1120 | |||
1123 | self.__profileIndex += 1 |
|
1121 | self.__profileIndex += 1 | |
1124 |
|
1122 | |||
1125 | if self.__profileIndex < n: |
|
1123 | if self.__profileIndex < n: | |
1126 | self.__remData = newData |
|
1124 | self.__remData = newData | |
1127 | #continue |
|
1125 | #continue | |
1128 | return |
|
1126 | return | |
1129 |
|
1127 | |||
1130 | self.__profileIndex = 0 |
|
1128 | self.__profileIndex = 0 | |
1131 | self.__remData = None |
|
1129 | self.__remData = None | |
1132 |
|
1130 | |||
1133 | dataOut.data = newData |
|
1131 | dataOut.data = newData | |
1134 | dataOut.flagNoData = False |
|
1132 | dataOut.flagNoData = False | |
1135 |
|
1133 | |||
1136 | profileIndex = dataOut.profileIndex/n |
|
1134 | profileIndex = dataOut.profileIndex/n | |
1137 |
|
1135 | |||
1138 |
|
1136 | |||
1139 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1137 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1140 |
|
1138 | |||
1141 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1139 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1142 |
|
1140 | |||
1143 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1141 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1144 |
|
1142 | |||
1145 | dataOut.profileIndex = profileIndex |
|
1143 | dataOut.profileIndex = profileIndex | |
1146 |
|
1144 | |||
1147 | dataOut.ippSeconds *= n |
|
1145 | dataOut.ippSeconds *= n | |
1148 |
|
1146 | |||
1149 | # import collections |
|
1147 | # import collections | |
1150 | # from scipy.stats import mode |
|
1148 | # from scipy.stats import mode | |
1151 | # |
|
1149 | # | |
1152 | # class Synchronize(Operation): |
|
1150 | # class Synchronize(Operation): | |
1153 | # |
|
1151 | # | |
1154 | # isConfig = False |
|
1152 | # isConfig = False | |
1155 | # __profIndex = 0 |
|
1153 | # __profIndex = 0 | |
1156 | # |
|
1154 | # | |
1157 | # def __init__(self, **kwargs): |
|
1155 | # def __init__(self, **kwargs): | |
1158 | # |
|
1156 | # | |
1159 | # Operation.__init__(self, **kwargs) |
|
1157 | # Operation.__init__(self, **kwargs) | |
1160 | # # self.isConfig = False |
|
1158 | # # self.isConfig = False | |
1161 | # self.__powBuffer = None |
|
1159 | # self.__powBuffer = None | |
1162 | # self.__startIndex = 0 |
|
1160 | # self.__startIndex = 0 | |
1163 | # self.__pulseFound = False |
|
1161 | # self.__pulseFound = False | |
1164 | # |
|
1162 | # | |
1165 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1163 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1166 | # |
|
1164 | # | |
1167 | # #Read data |
|
1165 | # #Read data | |
1168 | # |
|
1166 | # | |
1169 | # powerdB = dataOut.getPower(channel = channel) |
|
1167 | # powerdB = dataOut.getPower(channel = channel) | |
1170 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1168 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1171 | # |
|
1169 | # | |
1172 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1170 | # self.__powBuffer.extend(powerdB.flatten()) | |
1173 | # |
|
1171 | # | |
1174 | # dataArray = numpy.array(self.__powBuffer) |
|
1172 | # dataArray = numpy.array(self.__powBuffer) | |
1175 | # |
|
1173 | # | |
1176 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1174 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1177 | # |
|
1175 | # | |
1178 | # maxValue = numpy.nanmax(filteredPower) |
|
1176 | # maxValue = numpy.nanmax(filteredPower) | |
1179 | # |
|
1177 | # | |
1180 | # if maxValue < noisedB + 10: |
|
1178 | # if maxValue < noisedB + 10: | |
1181 | # #No se encuentra ningun pulso de transmision |
|
1179 | # #No se encuentra ningun pulso de transmision | |
1182 | # return None |
|
1180 | # return None | |
1183 | # |
|
1181 | # | |
1184 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1182 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1185 | # |
|
1183 | # | |
1186 | # if len(maxValuesIndex) < 2: |
|
1184 | # if len(maxValuesIndex) < 2: | |
1187 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1185 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1188 | # return None |
|
1186 | # return None | |
1189 | # |
|
1187 | # | |
1190 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1188 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1191 | # |
|
1189 | # | |
1192 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1190 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1193 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1191 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1194 | # |
|
1192 | # | |
1195 | # if len(pulseIndex) < 2: |
|
1193 | # if len(pulseIndex) < 2: | |
1196 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1194 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1197 | # return None |
|
1195 | # return None | |
1198 | # |
|
1196 | # | |
1199 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1197 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1200 | # |
|
1198 | # | |
1201 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1199 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1202 | # #(No deberian existir IPP menor a 10 unidades) |
|
1200 | # #(No deberian existir IPP menor a 10 unidades) | |
1203 | # |
|
1201 | # | |
1204 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1202 | # realIndex = numpy.where(spacing > 10 )[0] | |
1205 | # |
|
1203 | # | |
1206 | # if len(realIndex) < 2: |
|
1204 | # if len(realIndex) < 2: | |
1207 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1205 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1208 | # return None |
|
1206 | # return None | |
1209 | # |
|
1207 | # | |
1210 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1208 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1211 | # realPulseIndex = pulseIndex[realIndex] |
|
1209 | # realPulseIndex = pulseIndex[realIndex] | |
1212 | # |
|
1210 | # | |
1213 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1211 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1214 | # |
|
1212 | # | |
1215 | # print "IPP = %d samples" %period |
|
1213 | # print "IPP = %d samples" %period | |
1216 | # |
|
1214 | # | |
1217 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1215 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1218 | # self.__startIndex = int(realPulseIndex[0]) |
|
1216 | # self.__startIndex = int(realPulseIndex[0]) | |
1219 | # |
|
1217 | # | |
1220 | # return 1 |
|
1218 | # return 1 | |
1221 | # |
|
1219 | # | |
1222 | # |
|
1220 | # | |
1223 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1221 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1224 | # |
|
1222 | # | |
1225 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1223 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1226 | # maxlen = buffer_size*nSamples) |
|
1224 | # maxlen = buffer_size*nSamples) | |
1227 | # |
|
1225 | # | |
1228 | # bufferList = [] |
|
1226 | # bufferList = [] | |
1229 | # |
|
1227 | # | |
1230 | # for i in range(nChannels): |
|
1228 | # for i in range(nChannels): | |
1231 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1229 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1232 | # maxlen = buffer_size*nSamples) |
|
1230 | # maxlen = buffer_size*nSamples) | |
1233 | # |
|
1231 | # | |
1234 | # bufferList.append(bufferByChannel) |
|
1232 | # bufferList.append(bufferByChannel) | |
1235 | # |
|
1233 | # | |
1236 | # self.__nSamples = nSamples |
|
1234 | # self.__nSamples = nSamples | |
1237 | # self.__nChannels = nChannels |
|
1235 | # self.__nChannels = nChannels | |
1238 | # self.__bufferList = bufferList |
|
1236 | # self.__bufferList = bufferList | |
1239 | # |
|
1237 | # | |
1240 | # def run(self, dataOut, channel = 0): |
|
1238 | # def run(self, dataOut, channel = 0): | |
1241 | # |
|
1239 | # | |
1242 | # if not self.isConfig: |
|
1240 | # if not self.isConfig: | |
1243 | # nSamples = dataOut.nHeights |
|
1241 | # nSamples = dataOut.nHeights | |
1244 | # nChannels = dataOut.nChannels |
|
1242 | # nChannels = dataOut.nChannels | |
1245 | # self.setup(nSamples, nChannels) |
|
1243 | # self.setup(nSamples, nChannels) | |
1246 | # self.isConfig = True |
|
1244 | # self.isConfig = True | |
1247 | # |
|
1245 | # | |
1248 | # #Append new data to internal buffer |
|
1246 | # #Append new data to internal buffer | |
1249 | # for thisChannel in range(self.__nChannels): |
|
1247 | # for thisChannel in range(self.__nChannels): | |
1250 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1248 | # bufferByChannel = self.__bufferList[thisChannel] | |
1251 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1249 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1252 | # |
|
1250 | # | |
1253 | # if self.__pulseFound: |
|
1251 | # if self.__pulseFound: | |
1254 | # self.__startIndex -= self.__nSamples |
|
1252 | # self.__startIndex -= self.__nSamples | |
1255 | # |
|
1253 | # | |
1256 | # #Finding Tx Pulse |
|
1254 | # #Finding Tx Pulse | |
1257 | # if not self.__pulseFound: |
|
1255 | # if not self.__pulseFound: | |
1258 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1256 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1259 | # |
|
1257 | # | |
1260 | # if indexFound == None: |
|
1258 | # if indexFound == None: | |
1261 | # dataOut.flagNoData = True |
|
1259 | # dataOut.flagNoData = True | |
1262 | # return |
|
1260 | # return | |
1263 | # |
|
1261 | # | |
1264 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1262 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1265 | # self.__pulseFound = True |
|
1263 | # self.__pulseFound = True | |
1266 | # self.__startIndex = indexFound |
|
1264 | # self.__startIndex = indexFound | |
1267 | # |
|
1265 | # | |
1268 | # #If pulse was found ... |
|
1266 | # #If pulse was found ... | |
1269 | # for thisChannel in range(self.__nChannels): |
|
1267 | # for thisChannel in range(self.__nChannels): | |
1270 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1268 | # bufferByChannel = self.__bufferList[thisChannel] | |
1271 | # #print self.__startIndex |
|
1269 | # #print self.__startIndex | |
1272 | # x = numpy.array(bufferByChannel) |
|
1270 | # x = numpy.array(bufferByChannel) | |
1273 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1271 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1274 | # |
|
1272 | # | |
1275 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1273 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1276 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1274 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1277 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1275 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1278 | # |
|
1276 | # | |
1279 | # dataOut.data = self.__arrayBuffer |
|
1277 | # dataOut.data = self.__arrayBuffer | |
1280 | # |
|
1278 | # | |
1281 | # self.__startIndex += self.__newNSamples |
|
1279 | # self.__startIndex += self.__newNSamples | |
1282 | # |
|
1280 | # | |
1283 | # return |
|
1281 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now