##// END OF EJS Templates
data...
Julio Valdez -
r608:3cc55c179318
parent child
Show More
@@ -0,0 +1,188
1 # DIAS 19 Y 20 FEB 2014
2 # Comprobacion de Resultados DBS con SA
3
4 import os, sys
5
6 path = os.path.split(os.getcwd())[0]
7 path = os.path.split(path)[0]
8
9 sys.path.insert(0, path)
10
11 from schainpy.controller import Project
12
13 desc = "JASMET Experiment Test"
14 filename = "JASMETtest.xml"
15
16 controllerObj = Project()
17
18 controllerObj.setup(id = '191', name='test01', description=desc)
19
20 #Experimentos
21
22 #2014051 20 Feb 2014
23 # path = '/home/soporte/Data/JASMET/JASMET_30/2014106'
24 # pathFigure = '/home/soporte/workspace/Graficos/JASMET/prueba1'
25
26 remotefolder = "/home/wmaster/graficos"
27 path = '/media/joscanoa/84A65E64A65E5730/soporte/Data/JASMET/JASMET_30/'
28
29 pathfile1 = os.path.join(os.environ['HOME'],'Pictures/JASMET30/meteor')
30 pathfile2 = os.path.join(os.environ['HOME'],'Pictures/JASMET30/wind')
31 pathfile3 = os.path.join(os.environ['HOME'],'Pictures/JASMET30/phase')
32
33 pathfig = os.path.join(os.environ['HOME'],'Pictures/JASMET30/graph')
34
35 startTime = '00:00:00'
36 endTime = '23:59:59'
37 xmin ='17.0'
38 xmax = '34.0'
39
40 #------------------------------------------------------------------------------------------------
41 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
42 path=path,
43 startDate='2014/04/15',
44 endDate='2014/04/16',
45 startTime=startTime,
46 endTime=endTime,
47 online=0,
48 delay=5,
49 walk=1)
50
51 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
52
53
54 #--------------------------------------------------------------------------------------------------
55
56 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
57
58 opObj00 = procUnitConfObj0.addOperation(name='selectChannels')
59 opObj00.addParameter(name='channelList', value='0, 1, 2, 3, 4', format='intlist')
60
61 opObj01 = procUnitConfObj0.addOperation(name='setRadarFrequency')
62 # opObj01.addParameter(name='frequency', value='30.e6', format='float')
63 opObj01.addParameter(name='frequency', value='50.e6', format='float')
64
65 #opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
66 #--------------------------------------------------------------------------------------------------
67
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj0.getId())
69 procUnitConfObj1.addParameter(name='nSeconds', value='100', format='int')
70
71 opObj10 = procUnitConfObj1.addOperation(name='MeteorDetection')
72 # opObj10.addParameter(name='predefinedPhaseShifts', value='-89.5, 41.5, 0.0, -138.0, -85.5', format='floatlist')
73 opObj10.addParameter(name='predefinedPhaseShifts', value='0, 0, 0, 0, 0', format='floatlist')
74 opObj10.addParameter(name='cohDetection', value='0', format='bool')
75 opObj10.addParameter(name='noise_multiple', value='4', format='int')
76 opObj10.addParameter(name='SNRThresh', value='5', format='float')
77 opObj10.addParameter(name='phaseThresh', value='20', format='float')
78 opObj10.addParameter(name='azimuth', value='45', format='float')
79 opObj10.addParameter(name='hmin', value='68', format='float')
80 opObj10.addParameter(name='hmax', value='112', format='float')
81 opObj10.addParameter(name='saveAll', value='1', format='bool')
82
83 opObj12 = procUnitConfObj1.addOperation(name='HDF5Writer', optype='other')
84 opObj12.addParameter(name='path', value=pathfile1)
85 opObj12.addParameter(name='blocksPerFile', value='1000', format='int')
86 opObj12.addParameter(name='metadataList',value='type,inputUnit,heightList,paramInterval',format='list')
87 opObj12.addParameter(name='dataList',value='data_param',format='list')
88 opObj12.addParameter(name='mode',value='0',format='int')
89 #Tiene que ser de 3 dimensiones, append en lugar de aumentar una dimension
90
91 opObj13 = procUnitConfObj1.addOperation(name='SkyMapPlot', optype='other')
92 opObj13.addParameter(name='id', value='1', format='int')
93 opObj13.addParameter(name='wintitle', value='Sky Map', format='str')
94 opObj13.addParameter(name='save', value='1', format='bool')
95 opObj13.addParameter(name='figpath', value=pathfig, format='str')
96 opObj13.addParameter(name='ftp', value='1', format='int')
97 opObj13.addParameter(name='exp_code', value='15', format='int')
98 opObj13.addParameter(name='sub_exp_code', value='1', format='int')
99
100
101 #--------------------------------------------------------------------------------------------------
102 procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
103
104 opObj22 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other')
105 opObj22.addParameter(name='technique', value='Meteors', format='str')
106 opObj22.addParameter(name='nHours', value='0.25', format='float')
107 opObj22.addParameter(name='SNRThresh', value='12.0', format='float')
108
109 opObj23 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
110 opObj23.addParameter(name='id', value='2', format='int')
111 opObj23.addParameter(name='wintitle', value='Wind Profiler', format='str')
112 opObj23.addParameter(name='save', value='1', format='bool')
113 opObj23.addParameter(name='figpath', value = pathfig, format='str')
114 opObj23.addParameter(name='zmin', value='-120', format='int')
115 opObj23.addParameter(name='zmax', value='120', format='int')
116 # opObj12.addParameter(name='zmin_ver', value='-0.8', format='float')
117 # opObj12.addParameter(name='zmax_ver', value='0.8', format='float')
118 # opObj23.addParameter(name='SNRmin', value='-10', format='int')
119 # opObj23.addParameter(name='SNRmax', value='60', format='int')
120 # opObj23.addParameter(name='SNRthresh', value='0', format='float')
121 opObj23.addParameter(name='xmin', value=xmin, format='float')
122 opObj23.addParameter(name='xmax', value=xmax, format='float')
123 opObj23.addParameter(name='ftp', value='1', format='int')
124 opObj23.addParameter(name='exp_code', value='15', format='int')
125 opObj23.addParameter(name='sub_exp_code', value='1', format='int')
126
127 opObj24 = procUnitConfObj2.addOperation(name='HDF5Writer', optype='other')
128 opObj24.addParameter(name='path', value=pathfile2)
129 opObj24.addParameter(name='blocksPerFile', value='1000', format='int')
130 opObj24.addParameter(name='metadataList',value='type,inputUnit,outputInterval',format='list')
131 opObj24.addParameter(name='dataList',value='data_output,utctime',format='list')
132
133 #--------------------------------------------------------------------------------------------------
134 procUnitConfObj3 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
135
136
137 opObj31 = procUnitConfObj3.addOperation(name='PhaseCalibration', optype='other')
138 opObj31.addParameter(name='nHours', value='0.25', format='float')
139 opObj31.addParameter(name='distances', value='-15, -15, 12, 12', format='intlist')
140 # opObj31.addParameter(name='distances', value='-25, -25, 20, 20', format='intlist')
141 opObj31.addParameter(name='pairs', value='(0,3),(1,2)', format='pairslist')
142 opObj31.addParameter(name='hmin', value='68', format='float')
143 opObj31.addParameter(name='hmax', value='112', format='float')
144
145 opObj32 = procUnitConfObj3.addOperation(name='PhasePlot', optype='other')
146 opObj32.addParameter(name='id', value='201', format='int')
147 opObj32.addParameter(name='wintitle', value='PhaseCalibration', format='str')
148 # opObj32.addParameter(name='timerange', value='300', format='int')
149 opObj32.addParameter(name='xmin', value=xmin, format='float')
150 opObj32.addParameter(name='xmax', value=xmax, format='float')
151 # opObj32.addParameter(name='xmin', value='19', format='float')
152 # opObj32.addParameter(name='xmax', value='20', format='float')
153 opObj32.addParameter(name='ymin', value='-180', format='float')
154 opObj32.addParameter(name='ymax', value='180', format='float')
155 opObj32.addParameter(name='figpath', value=pathfig, format='str')
156 opObj32.addParameter(name='ftp', value='1', format='int')
157 opObj32.addParameter(name='exp_code', value='15', format='int')
158 opObj32.addParameter(name='sub_exp_code', value='1', format='int')
159
160 opObj33 = procUnitConfObj3.addOperation(name='HDF5Writer', optype='other')
161 opObj33.addParameter(name='path', value=pathfile3)
162 opObj33.addParameter(name='blocksPerFile', value='1000', format='int')
163 opObj33.addParameter(name='metadataList',value='type,inputUnit,outputInterval',format='list')
164 opObj33.addParameter(name='dataList',value='data_output,utctime',format='list')
165 # opObj25.addParameter(name='mode',value='1,0,0',format='intlist')
166
167 #--------------------------------------------------------------------------------------------------
168
169 procUnitConfObj4 = controllerObj.addProcUnit(name='SendToServer')
170 procUnitConfObj4.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
171 procUnitConfObj4.addParameter(name='username', value='wmaster', format='str')
172 procUnitConfObj4.addParameter(name='password', value='mst2010vhf', format='str')
173 procUnitConfObj4.addParameter(name='localfolder', value=pathfig, format='str')
174 procUnitConfObj4.addParameter(name='remotefolder', value=remotefolder, format='str')
175 procUnitConfObj4.addParameter(name='ext', value='.png', format='str')
176 procUnitConfObj4.addParameter(name='period', value=20, format='int')
177 procUnitConfObj4.addParameter(name='protocol', value='ftp', format='str')
178
179 #--------------------------------------------------------------------------------------------------
180
181 print "Escribiendo el archivo XML"
182 controllerObj.writeXml(filename)
183 print "Leyendo el archivo XML"
184 controllerObj.readXml(filename)
185
186 controllerObj.createObjects()
187 controllerObj.connectObjects()
188 controllerObj.run() No newline at end of file
@@ -0,0 +1,56
1 """
2 Se debe verficar que el disco de datos se encuentra montado en el sistema
3 """
4 import os, sys
5
6 path = os.path.split(os.getcwd())[0]
7 path = os.path.split(path)[0]
8
9 sys.path.insert(0, path)
10
11 from schainpy.controller import Project
12
13 desc = "Meteor Experiment Test"
14 filename = "meteor20130812.xml"
15
16 controllerObj = Project()
17 controllerObj.setup(id = '191', name='meteor_test01', description=desc)
18
19 path = '/home/dsuarez/.gvfs/data on 10.10.20.13/Jasmet50'
20
21
22 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
23 path=path,
24 startDate='2014/04/16',
25 endDate='2014/04/16',
26 startTime='00:00:00',
27 endTime='23:59:59',
28 online=0,
29 walk=1)
30
31 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
32
33 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
34
35
36 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
37
38
39 opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
40 opObj11.addParameter(name='n', value='2', format='int')
41
42 opObj11 = procUnitConfObj0.addOperation(name='VoltageWriter', optype='other')
43 opObj11.addParameter(name='path', value='/home/jasmet/jasmet30_abril')
44 opObj11.addParameter(name='blocksPerFile', value='100', format='int')
45 opObj11.addParameter(name='profilesPerBlock', value='200', format='int')
46
47
48
49 print "Escribiendo el archivo XML"
50 controllerObj.writeXml(filename)
51 print "Leyendo el archivo XML"
52 controllerObj.readXml(filename)
53
54 controllerObj.createObjects()
55 controllerObj.connectObjects()
56 controllerObj.run()
@@ -1,1115 +1,1124
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
12
13 def getNumpyDtype(dataTypeCode):
13 def getNumpyDtype(dataTypeCode):
14
14
15 if dataTypeCode == 0:
15 if dataTypeCode == 0:
16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
17 elif dataTypeCode == 1:
17 elif dataTypeCode == 1:
18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
19 elif dataTypeCode == 2:
19 elif dataTypeCode == 2:
20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
21 elif dataTypeCode == 3:
21 elif dataTypeCode == 3:
22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
23 elif dataTypeCode == 4:
23 elif dataTypeCode == 4:
24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
25 elif dataTypeCode == 5:
25 elif dataTypeCode == 5:
26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
27 else:
27 else:
28 raise ValueError, 'dataTypeCode was not defined'
28 raise ValueError, 'dataTypeCode was not defined'
29
29
30 return numpyDtype
30 return numpyDtype
31
31
32 def getDataTypeCode(numpyDtype):
32 def getDataTypeCode(numpyDtype):
33
33
34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
35 datatype = 0
35 datatype = 0
36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
37 datatype = 1
37 datatype = 1
38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
39 datatype = 2
39 datatype = 2
40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
41 datatype = 3
41 datatype = 3
42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
43 datatype = 4
43 datatype = 4
44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
45 datatype = 5
45 datatype = 5
46 else:
46 else:
47 datatype = None
47 datatype = None
48
48
49 return datatype
49 return datatype
50
50
51 def hildebrand_sekhon(data, navg):
51 def hildebrand_sekhon(data, navg):
52 """
52 """
53 This method is for the objective determination of the noise level in Doppler spectra. This
53 This method is for the objective determination of the noise level in Doppler spectra. This
54 implementation technique is based on the fact that the standard deviation of the spectral
54 implementation technique is based on the fact that the standard deviation of the spectral
55 densities is equal to the mean spectral density for white Gaussian noise
55 densities is equal to the mean spectral density for white Gaussian noise
56
56
57 Inputs:
57 Inputs:
58 Data : heights
58 Data : heights
59 navg : numbers of averages
59 navg : numbers of averages
60
60
61 Return:
61 Return:
62 -1 : any error
62 -1 : any error
63 anoise : noise's level
63 anoise : noise's level
64 """
64 """
65
65
66 sortdata = numpy.sort(data,axis=None)
66 sortdata = numpy.sort(data,axis=None)
67 lenOfData = len(sortdata)
67 lenOfData = len(sortdata)
68 nums_min = lenOfData/10
68 nums_min = lenOfData/10
69
69
70 if (lenOfData/10) > 2:
70 if (lenOfData/10) > 2:
71 nums_min = lenOfData/10
71 nums_min = lenOfData/10
72 else:
72 else:
73 nums_min = 2
73 nums_min = 2
74
74
75 sump = 0.
75 sump = 0.
76
76
77 sumq = 0.
77 sumq = 0.
78
78
79 j = 0
79 j = 0
80
80
81 cont = 1
81 cont = 1
82
82
83 while((cont==1)and(j<lenOfData)):
83 while((cont==1)and(j<lenOfData)):
84
84
85 sump += sortdata[j]
85 sump += sortdata[j]
86
86
87 sumq += sortdata[j]**2
87 sumq += sortdata[j]**2
88
88
89 if j > nums_min:
89 if j > nums_min:
90 rtest = float(j)/(j-1) + 1.0/navg
90 rtest = float(j)/(j-1) + 1.0/navg
91 if ((sumq*j) > (rtest*sump**2)):
91 if ((sumq*j) > (rtest*sump**2)):
92 j = j - 1
92 j = j - 1
93 sump = sump - sortdata[j]
93 sump = sump - sortdata[j]
94 sumq = sumq - sortdata[j]**2
94 sumq = sumq - sortdata[j]**2
95 cont = 0
95 cont = 0
96
96
97 j += 1
97 j += 1
98
98
99 lnoise = sump /j
99 lnoise = sump /j
100 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
100 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
101 return lnoise
101 return lnoise
102
102
103 class Beam:
103 class Beam:
104 def __init__(self):
104 def __init__(self):
105 self.codeList = []
105 self.codeList = []
106 self.azimuthList = []
106 self.azimuthList = []
107 self.zenithList = []
107 self.zenithList = []
108
108
109 class GenericData(object):
109 class GenericData(object):
110
110
111 flagNoData = True
111 flagNoData = True
112
112
113 def __init__(self):
113 def __init__(self):
114
114
115 raise ValueError, "This class has not been implemented"
115 raise ValueError, "This class has not been implemented"
116
116
117 def copy(self, inputObj=None):
117 def copy(self, inputObj=None):
118
118
119 if inputObj == None:
119 if inputObj == None:
120 return copy.deepcopy(self)
120 return copy.deepcopy(self)
121
121
122 for key in inputObj.__dict__.keys():
122 for key in inputObj.__dict__.keys():
123 self.__dict__[key] = inputObj.__dict__[key]
123 self.__dict__[key] = inputObj.__dict__[key]
124
124
125 def deepcopy(self):
125 def deepcopy(self):
126
126
127 return copy.deepcopy(self)
127 return copy.deepcopy(self)
128
128
129 def isEmpty(self):
129 def isEmpty(self):
130
130
131 return self.flagNoData
131 return self.flagNoData
132
132
133 class JROData(GenericData):
133 class JROData(GenericData):
134
134
135 # m_BasicHeader = BasicHeader()
135 # m_BasicHeader = BasicHeader()
136 # m_ProcessingHeader = ProcessingHeader()
136 # m_ProcessingHeader = ProcessingHeader()
137
137
138 systemHeaderObj = SystemHeader()
138 systemHeaderObj = SystemHeader()
139
139
140 radarControllerHeaderObj = RadarControllerHeader()
140 radarControllerHeaderObj = RadarControllerHeader()
141
141
142 # data = None
142 # data = None
143
143
144 type = None
144 type = None
145
145
146 datatype = None #dtype but in string
146 datatype = None #dtype but in string
147
147
148 # dtype = None
148 # dtype = None
149
149
150 # nChannels = None
150 # nChannels = None
151
151
152 # nHeights = None
152 # nHeights = None
153
153
154 nProfiles = None
154 nProfiles = None
155
155
156 heightList = None
156 heightList = None
157
157
158 channelList = None
158 channelList = None
159
159
160 flagDiscontinuousBlock = False
160 flagDiscontinuousBlock = False
161
161
162 useLocalTime = False
162 useLocalTime = False
163
163
164 utctime = None
164 utctime = None
165
165
166 timeZone = None
166 timeZone = None
167
167
168 dstFlag = None
168 dstFlag = None
169
169
170 errorCount = None
170 errorCount = None
171
171
172 blocksize = None
172 blocksize = None
173
173
174 # nCode = None
174 # nCode = None
175 #
175 #
176 # nBaud = None
176 # nBaud = None
177 #
177 #
178 # code = None
178 # code = None
179
179
180 flagDecodeData = False #asumo q la data no esta decodificada
180 flagDecodeData = False #asumo q la data no esta decodificada
181
181
182 flagDeflipData = False #asumo q la data no esta sin flip
182 flagDeflipData = False #asumo q la data no esta sin flip
183
183
184 flagShiftFFT = False
184 flagShiftFFT = False
185
185
186 # ippSeconds = None
186 # ippSeconds = None
187
187
188 # timeInterval = None
188 # timeInterval = None
189
189
190 nCohInt = None
190 nCohInt = None
191
191
192 # noise = None
192 # noise = None
193
193
194 windowOfFilter = 1
194 windowOfFilter = 1
195
195
196 #Speed of ligth
196 #Speed of ligth
197 C = 3e8
197 C = 3e8
198
198
199 frequency = 49.92e6
199 frequency = 49.92e6
200
200
201 realtime = False
201 realtime = False
202
202
203 beacon_heiIndexList = None
203 beacon_heiIndexList = None
204
204
205 last_block = None
205 last_block = None
206
206
207 blocknow = None
207 blocknow = None
208
208
209 azimuth = None
209 azimuth = None
210
210
211 zenith = None
211 zenith = None
212
212
213 beam = Beam()
213 beam = Beam()
214
214
215 profileIndex = None
215 profileIndex = None
216
216
217 def __init__(self):
217 def __init__(self):
218
218
219 raise ValueError, "This class has not been implemented"
219 raise ValueError, "This class has not been implemented"
220
220
221 def getNoise(self):
221 def getNoise(self):
222
222
223 raise ValueError, "Not implemented"
223 raise ValueError, "Not implemented"
224
224
225 def getNChannels(self):
225 def getNChannels(self):
226
226
227 return len(self.channelList)
227 return len(self.channelList)
228
228
229 def getChannelIndexList(self):
229 def getChannelIndexList(self):
230
230
231 return range(self.nChannels)
231 return range(self.nChannels)
232
232
233 def getNHeights(self):
233 def getNHeights(self):
234
234
235 return len(self.heightList)
235 return len(self.heightList)
236
236
237 def getHeiRange(self, extrapoints=0):
237 def getHeiRange(self, extrapoints=0):
238
238
239 heis = self.heightList
239 heis = self.heightList
240 # deltah = self.heightList[1] - self.heightList[0]
240 # deltah = self.heightList[1] - self.heightList[0]
241 #
241 #
242 # heis.append(self.heightList[-1])
242 # heis.append(self.heightList[-1])
243
243
244 return heis
244 return heis
245
245
246 def getltctime(self):
246 def getltctime(self):
247
247
248 if self.useLocalTime:
248 if self.useLocalTime:
249 return self.utctime - self.timeZone*60
249 return self.utctime - self.timeZone*60
250
250
251 return self.utctime
251 return self.utctime
252
252
253 def getDatatime(self):
253 def getDatatime(self):
254
254
255 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
255 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
256 return datatimeValue
256 return datatimeValue
257
257
258 def getTimeRange(self):
258 def getTimeRange(self):
259
259
260 datatime = []
260 datatime = []
261
261
262 datatime.append(self.ltctime)
262 datatime.append(self.ltctime)
263 datatime.append(self.ltctime + self.timeInterval+60)
263 datatime.append(self.ltctime + self.timeInterval+60)
264
264
265 datatime = numpy.array(datatime)
265 datatime = numpy.array(datatime)
266
266
267 return datatime
267 return datatime
268
268
269 def getFmax(self):
269 def getFmax(self):
270
270
271 PRF = 1./(self.ippSeconds * self.nCohInt)
271 PRF = 1./(self.ippSeconds * self.nCohInt)
272
272
273 fmax = PRF/2.
273 fmax = PRF/2.
274
274
275 return fmax
275 return fmax
276
276
277 def getVmax(self):
277 def getVmax(self):
278
278
279 _lambda = self.C/self.frequency
279 _lambda = self.C/self.frequency
280
280
281 vmax = self.getFmax() * _lambda
281 vmax = self.getFmax() * _lambda
282
282
283 return vmax
283 return vmax
284
284
285 def get_ippSeconds(self):
285 def get_ippSeconds(self):
286 '''
286 '''
287 '''
287 '''
288 return self.radarControllerHeaderObj.ippSeconds
288 return self.radarControllerHeaderObj.ippSeconds
289
289
290 def set_ippSeconds(self, ippSeconds):
290 def set_ippSeconds(self, ippSeconds):
291 '''
291 '''
292 '''
292 '''
293
293
294 self.radarControllerHeaderObj.ippSeconds = ippSeconds
294 self.radarControllerHeaderObj.ippSeconds = ippSeconds
295
295
296 return
296 return
297
297
298 def get_dtype(self):
298 def get_dtype(self):
299 '''
299 '''
300 '''
300 '''
301 return getNumpyDtype(self.datatype)
301 return getNumpyDtype(self.datatype)
302
302
303 def set_dtype(self, numpyDtype):
303 def set_dtype(self, numpyDtype):
304 '''
304 '''
305 '''
305 '''
306
306
307 self.datatype = getDataTypeCode(numpyDtype)
307 self.datatype = getDataTypeCode(numpyDtype)
308
308
309 def get_code(self):
309 def get_code(self):
310 '''
310 '''
311 '''
311 '''
312 return self.radarControllerHeaderObj.code
312 return self.radarControllerHeaderObj.code
313
313
314 def set_code(self, code):
314 def set_code(self, code):
315 '''
315 '''
316 '''
316 '''
317 self.radarControllerHeaderObj.code = code
317 self.radarControllerHeaderObj.code = code
318
318
319 return
319 return
320
320
321 def get_ncode(self):
321 def get_ncode(self):
322 '''
322 '''
323 '''
323 '''
324 return self.radarControllerHeaderObj.nCode
324 return self.radarControllerHeaderObj.nCode
325
325
326 def set_ncode(self, nCode):
326 def set_ncode(self, nCode):
327 '''
327 '''
328 '''
328 '''
329 self.radarControllerHeaderObj.nCode = nCode
329 self.radarControllerHeaderObj.nCode = nCode
330
330
331 return
331 return
332
332
333 def get_nbaud(self):
333 def get_nbaud(self):
334 '''
334 '''
335 '''
335 '''
336 return self.radarControllerHeaderObj.nBaud
336 return self.radarControllerHeaderObj.nBaud
337
337
338 def set_nbaud(self, nBaud):
338 def set_nbaud(self, nBaud):
339 '''
339 '''
340 '''
340 '''
341 self.radarControllerHeaderObj.nBaud = nBaud
341 self.radarControllerHeaderObj.nBaud = nBaud
342
342
343 return
343 return
344 # def getTimeInterval(self):
344 # def getTimeInterval(self):
345 #
345 #
346 # raise IOError, "This method should be implemented inside each Class"
346 # raise IOError, "This method should be implemented inside each Class"
347
347
348 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
348 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
349 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
349 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
350 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
350 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
351 #noise = property(getNoise, "I'm the 'nHeights' property.")
351 #noise = property(getNoise, "I'm the 'nHeights' property.")
352 datatime = property(getDatatime, "I'm the 'datatime' property")
352 datatime = property(getDatatime, "I'm the 'datatime' property")
353 ltctime = property(getltctime, "I'm the 'ltctime' property")
353 ltctime = property(getltctime, "I'm the 'ltctime' property")
354 ippSeconds = property(get_ippSeconds, set_ippSeconds)
354 ippSeconds = property(get_ippSeconds, set_ippSeconds)
355 dtype = property(get_dtype, set_dtype)
355 dtype = property(get_dtype, set_dtype)
356 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
356 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
357 code = property(get_code, set_code)
357 code = property(get_code, set_code)
358 nCode = property(get_ncode, set_ncode)
358 nCode = property(get_ncode, set_ncode)
359 nBaud = property(get_nbaud, set_nbaud)
359 nBaud = property(get_nbaud, set_nbaud)
360
360
361 class Voltage(JROData):
361 class Voltage(JROData):
362
362
363 #data es un numpy array de 2 dmensiones (canales, alturas)
363 #data es un numpy array de 2 dmensiones (canales, alturas)
364 data = None
364 data = None
365
365
366 def __init__(self):
366 def __init__(self):
367 '''
367 '''
368 Constructor
368 Constructor
369 '''
369 '''
370
370
371 self.useLocalTime = True
371 self.useLocalTime = True
372
372
373 self.radarControllerHeaderObj = RadarControllerHeader()
373 self.radarControllerHeaderObj = RadarControllerHeader()
374
374
375 self.systemHeaderObj = SystemHeader()
375 self.systemHeaderObj = SystemHeader()
376
376
377 self.type = "Voltage"
377 self.type = "Voltage"
378
378
379 self.data = None
379 self.data = None
380
380
381 # self.dtype = None
381 # self.dtype = None
382
382
383 # self.nChannels = 0
383 # self.nChannels = 0
384
384
385 # self.nHeights = 0
385 # self.nHeights = 0
386
386
387 self.nProfiles = None
387 self.nProfiles = None
388
388
389 self.heightList = None
389 self.heightList = None
390
390
391 self.channelList = None
391 self.channelList = None
392
392
393 # self.channelIndexList = None
393 # self.channelIndexList = None
394
394
395 self.flagNoData = True
395 self.flagNoData = True
396
396
397 self.flagDiscontinuousBlock = False
397 self.flagDiscontinuousBlock = False
398
398
399 self.utctime = None
399 self.utctime = None
400
400
401 self.timeZone = None
401 self.timeZone = None
402
402
403 self.dstFlag = None
403 self.dstFlag = None
404
404
405 self.errorCount = None
405 self.errorCount = None
406
406
407 self.nCohInt = None
407 self.nCohInt = None
408
408
409 self.blocksize = None
409 self.blocksize = None
410
410
411 self.flagDecodeData = False #asumo q la data no esta decodificada
411 self.flagDecodeData = False #asumo q la data no esta decodificada
412
412
413 self.flagDeflipData = False #asumo q la data no esta sin flip
413 self.flagDeflipData = False #asumo q la data no esta sin flip
414
414
415 self.flagShiftFFT = False
415 self.flagShiftFFT = False
416
416
417 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
417 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
418
418
419 self.profileIndex = 0
419 self.profileIndex = 0
420
420
421 def getNoisebyHildebrand(self, channel = None):
421 def getNoisebyHildebrand(self, channel = None):
422 """
422 """
423 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
423 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
424
424
425 Return:
425 Return:
426 noiselevel
426 noiselevel
427 """
427 """
428
428
429 if channel != None:
429 if channel != None:
430 data = self.data[channel]
430 data = self.data[channel]
431 nChannels = 1
431 nChannels = 1
432 else:
432 else:
433 data = self.data
433 data = self.data
434 nChannels = self.nChannels
434 nChannels = self.nChannels
435
435
436 noise = numpy.zeros(nChannels)
436 noise = numpy.zeros(nChannels)
437 power = data * numpy.conjugate(data)
437 power = data * numpy.conjugate(data)
438
438
439 for thisChannel in range(nChannels):
439 for thisChannel in range(nChannels):
440 if nChannels == 1:
440 if nChannels == 1:
441 daux = power[:].real
441 daux = power[:].real
442 else:
442 else:
443 daux = power[thisChannel,:].real
443 daux = power[thisChannel,:].real
444 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
444 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
445
445
446 return noise
446 return noise
447
447
448 def getNoise(self, type = 1, channel = None):
448 def getNoise(self, type = 1, channel = None):
449
449
450 if type == 1:
450 if type == 1:
451 noise = self.getNoisebyHildebrand(channel)
451 noise = self.getNoisebyHildebrand(channel)
452
452
453 return 10*numpy.log10(noise)
453 return 10*numpy.log10(noise)
454
454
455 def getPower(self, channel = None):
455 def getPower(self, channel = None):
456
456
457 if channel != None:
457 if channel != None:
458 data = self.data[channel]
458 data = self.data[channel]
459 else:
459 else:
460 data = self.data
460 data = self.data
461
461
462 power = data * numpy.conjugate(data)
462 power = data * numpy.conjugate(data)
463
463
464 return 10*numpy.log10(power.real)
464 return 10*numpy.log10(power.real)
465
465
466 def getTimeInterval(self):
466 def getTimeInterval(self):
467
467
468 timeInterval = self.ippSeconds * self.nCohInt
468 timeInterval = self.ippSeconds * self.nCohInt
469
469
470 return timeInterval
470 return timeInterval
471
471
472 noise = property(getNoise, "I'm the 'nHeights' property.")
472 noise = property(getNoise, "I'm the 'nHeights' property.")
473 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
473 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
474
474
475 class Spectra(JROData):
475 class Spectra(JROData):
476
476
477 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
477 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
478 data_spc = None
478 data_spc = None
479
479
480 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
480 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
481 data_cspc = None
481 data_cspc = None
482
482
483 #data es un numpy array de 2 dmensiones (canales, alturas)
483 #data es un numpy array de 2 dmensiones (canales, alturas)
484 data_dc = None
484 data_dc = None
485
485
486 nFFTPoints = None
486 nFFTPoints = None
487
487
488 # nPairs = None
488 # nPairs = None
489
489
490 pairsList = None
490 pairsList = None
491
491
492 nIncohInt = None
492 nIncohInt = None
493
493
494 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
494 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
495
495
496 nCohInt = None #se requiere para determinar el valor de timeInterval
496 nCohInt = None #se requiere para determinar el valor de timeInterval
497
497
498 ippFactor = None
498 ippFactor = None
499
499
500 profileIndex = 0
500 profileIndex = 0
501
501
502 def __init__(self):
502 def __init__(self):
503 '''
503 '''
504 Constructor
504 Constructor
505 '''
505 '''
506
506
507 self.useLocalTime = True
507 self.useLocalTime = True
508
508
509 self.radarControllerHeaderObj = RadarControllerHeader()
509 self.radarControllerHeaderObj = RadarControllerHeader()
510
510
511 self.systemHeaderObj = SystemHeader()
511 self.systemHeaderObj = SystemHeader()
512
512
513 self.type = "Spectra"
513 self.type = "Spectra"
514
514
515 # self.data = None
515 # self.data = None
516
516
517 # self.dtype = None
517 # self.dtype = None
518
518
519 # self.nChannels = 0
519 # self.nChannels = 0
520
520
521 # self.nHeights = 0
521 # self.nHeights = 0
522
522
523 self.nProfiles = None
523 self.nProfiles = None
524
524
525 self.heightList = None
525 self.heightList = None
526
526
527 self.channelList = None
527 self.channelList = None
528
528
529 # self.channelIndexList = None
529 # self.channelIndexList = None
530
530
531 self.pairsList = None
531 self.pairsList = None
532
532
533 self.flagNoData = True
533 self.flagNoData = True
534
534
535 self.flagDiscontinuousBlock = False
535 self.flagDiscontinuousBlock = False
536
536
537 self.utctime = None
537 self.utctime = None
538
538
539 self.nCohInt = None
539 self.nCohInt = None
540
540
541 self.nIncohInt = None
541 self.nIncohInt = None
542
542
543 self.blocksize = None
543 self.blocksize = None
544
544
545 self.nFFTPoints = None
545 self.nFFTPoints = None
546
546
547 self.wavelength = None
547 self.wavelength = None
548
548
549 self.flagDecodeData = False #asumo q la data no esta decodificada
549 self.flagDecodeData = False #asumo q la data no esta decodificada
550
550
551 self.flagDeflipData = False #asumo q la data no esta sin flip
551 self.flagDeflipData = False #asumo q la data no esta sin flip
552
552
553 self.flagShiftFFT = False
553 self.flagShiftFFT = False
554
554
555 self.ippFactor = 1
555 self.ippFactor = 1
556
556
557 #self.noise = None
557 #self.noise = None
558
558
559 self.beacon_heiIndexList = []
559 self.beacon_heiIndexList = []
560
560
561 self.noise_estimation = None
561 self.noise_estimation = None
562
562
563
563
564 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
564 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
565 """
565 """
566 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
566 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
567
567
568 Return:
568 Return:
569 noiselevel
569 noiselevel
570 """
570 """
571
571
572 noise = numpy.zeros(self.nChannels)
572 noise = numpy.zeros(self.nChannels)
573
573
574 for channel in range(self.nChannels):
574 for channel in range(self.nChannels):
575 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
575 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
576 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
576 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
577
577
578 return noise
578 return noise
579
579
580 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
580 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
581
581
582 if self.noise_estimation != None:
582 if self.noise_estimation != None:
583 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
583 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
584 else:
584 else:
585 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
585 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
586 return noise
586 return noise
587
587
588
588
589 def getFreqRange(self, extrapoints=0):
589 def getFreqRange(self, extrapoints=0):
590
590
591 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
591 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
592 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
592 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
593
593
594 return freqrange
594 return freqrange
595
595
596 def getVelRange(self, extrapoints=0):
596 def getVelRange(self, extrapoints=0):
597
597
598 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
598 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
599 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
599 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
600
600
601 return velrange
601 return velrange
602
602
603 def getNPairs(self):
603 def getNPairs(self):
604
604
605 return len(self.pairsList)
605 return len(self.pairsList)
606
606
607 def getPairsIndexList(self):
607 def getPairsIndexList(self):
608
608
609 return range(self.nPairs)
609 return range(self.nPairs)
610
610
611 def getNormFactor(self):
611 def getNormFactor(self):
612 pwcode = 1
612 pwcode = 1
613 if self.flagDecodeData:
613 if self.flagDecodeData:
614 pwcode = numpy.sum(self.code[0]**2)
614 pwcode = numpy.sum(self.code[0]**2)
615 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
615 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
616 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
616 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
617
617
618 return normFactor
618 return normFactor
619
619
620 def getFlagCspc(self):
620 def getFlagCspc(self):
621
621
622 if self.data_cspc == None:
622 if self.data_cspc == None:
623 return True
623 return True
624
624
625 return False
625 return False
626
626
627 def getFlagDc(self):
627 def getFlagDc(self):
628
628
629 if self.data_dc == None:
629 if self.data_dc == None:
630 return True
630 return True
631
631
632 return False
632 return False
633
633
634 def getTimeInterval(self):
634 def getTimeInterval(self):
635
635
636 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
636 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
637
637
638 return timeInterval
638 return timeInterval
639
639
640 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
640 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
641 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
641 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
642 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
642 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
643 flag_cspc = property(getFlagCspc)
643 flag_cspc = property(getFlagCspc)
644 flag_dc = property(getFlagDc)
644 flag_dc = property(getFlagDc)
645 noise = property(getNoise, "I'm the 'nHeights' property.")
645 noise = property(getNoise, "I'm the 'nHeights' property.")
646 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
646 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
647
647
648 class SpectraHeis(Spectra):
648 class SpectraHeis(Spectra):
649
649
650 data_spc = None
650 data_spc = None
651
651
652 data_cspc = None
652 data_cspc = None
653
653
654 data_dc = None
654 data_dc = None
655
655
656 nFFTPoints = None
656 nFFTPoints = None
657
657
658 # nPairs = None
658 # nPairs = None
659
659
660 pairsList = None
660 pairsList = None
661
661
662 nCohInt = None
662 nCohInt = None
663
663
664 nIncohInt = None
664 nIncohInt = None
665
665
666 def __init__(self):
666 def __init__(self):
667
667
668 self.radarControllerHeaderObj = RadarControllerHeader()
668 self.radarControllerHeaderObj = RadarControllerHeader()
669
669
670 self.systemHeaderObj = SystemHeader()
670 self.systemHeaderObj = SystemHeader()
671
671
672 self.type = "SpectraHeis"
672 self.type = "SpectraHeis"
673
673
674 # self.dtype = None
674 # self.dtype = None
675
675
676 # self.nChannels = 0
676 # self.nChannels = 0
677
677
678 # self.nHeights = 0
678 # self.nHeights = 0
679
679
680 self.nProfiles = None
680 self.nProfiles = None
681
681
682 self.heightList = None
682 self.heightList = None
683
683
684 self.channelList = None
684 self.channelList = None
685
685
686 # self.channelIndexList = None
686 # self.channelIndexList = None
687
687
688 self.flagNoData = True
688 self.flagNoData = True
689
689
690 self.flagDiscontinuousBlock = False
690 self.flagDiscontinuousBlock = False
691
691
692 # self.nPairs = 0
692 # self.nPairs = 0
693
693
694 self.utctime = None
694 self.utctime = None
695
695
696 self.blocksize = None
696 self.blocksize = None
697
697
698 self.profileIndex = 0
698 self.profileIndex = 0
699
699
700 self.nCohInt = 1
700 self.nCohInt = 1
701
701
702 self.nIncohInt = 1
702 self.nIncohInt = 1
703
703
704 def getNormFactor(self):
704 def getNormFactor(self):
705 pwcode = 1
705 pwcode = 1
706 if self.flagDecodeData:
706 if self.flagDecodeData:
707 pwcode = numpy.sum(self.code[0]**2)
707 pwcode = numpy.sum(self.code[0]**2)
708
708
709 normFactor = self.nIncohInt*self.nCohInt*pwcode
709 normFactor = self.nIncohInt*self.nCohInt*pwcode
710
710
711 return normFactor
711 return normFactor
712
712
713 def getTimeInterval(self):
713 def getTimeInterval(self):
714
714
715 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
715 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
716
716
717 return timeInterval
717 return timeInterval
718
718
719 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
719 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
720 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
720 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
721
721
722 class Fits(JROData):
722 class Fits(JROData):
723
723
724 heightList = None
724 heightList = None
725
725
726 channelList = None
726 channelList = None
727
727
728 flagNoData = True
728 flagNoData = True
729
729
730 flagDiscontinuousBlock = False
730 flagDiscontinuousBlock = False
731
731
732 useLocalTime = False
732 useLocalTime = False
733
733
734 utctime = None
734 utctime = None
735
735
736 timeZone = None
736 timeZone = None
737
737
738 # ippSeconds = None
738 # ippSeconds = None
739
739
740 # timeInterval = None
740 # timeInterval = None
741
741
742 nCohInt = None
742 nCohInt = None
743
743
744 nIncohInt = None
744 nIncohInt = None
745
745
746 noise = None
746 noise = None
747
747
748 windowOfFilter = 1
748 windowOfFilter = 1
749
749
750 #Speed of ligth
750 #Speed of ligth
751 C = 3e8
751 C = 3e8
752
752
753 frequency = 49.92e6
753 frequency = 49.92e6
754
754
755 realtime = False
755 realtime = False
756
756
757
757
758 def __init__(self):
758 def __init__(self):
759
759
760 self.type = "Fits"
760 self.type = "Fits"
761
761
762 self.nProfiles = None
762 self.nProfiles = None
763
763
764 self.heightList = None
764 self.heightList = None
765
765
766 self.channelList = None
766 self.channelList = None
767
767
768 # self.channelIndexList = None
768 # self.channelIndexList = None
769
769
770 self.flagNoData = True
770 self.flagNoData = True
771
771
772 self.utctime = None
772 self.utctime = None
773
773
774 self.nCohInt = 1
774 self.nCohInt = 1
775
775
776 self.nIncohInt = 1
776 self.nIncohInt = 1
777
777
778 self.useLocalTime = True
778 self.useLocalTime = True
779
779
780 self.profileIndex = 0
780 self.profileIndex = 0
781
781
782 # self.utctime = None
782 # self.utctime = None
783 # self.timeZone = None
783 # self.timeZone = None
784 # self.ltctime = None
784 # self.ltctime = None
785 # self.timeInterval = None
785 # self.timeInterval = None
786 # self.header = None
786 # self.header = None
787 # self.data_header = None
787 # self.data_header = None
788 # self.data = None
788 # self.data = None
789 # self.datatime = None
789 # self.datatime = None
790 # self.flagNoData = False
790 # self.flagNoData = False
791 # self.expName = ''
791 # self.expName = ''
792 # self.nChannels = None
792 # self.nChannels = None
793 # self.nSamples = None
793 # self.nSamples = None
794 # self.dataBlocksPerFile = None
794 # self.dataBlocksPerFile = None
795 # self.comments = ''
795 # self.comments = ''
796 #
796 #
797
797
798
798
799 def getltctime(self):
799 def getltctime(self):
800
800
801 if self.useLocalTime:
801 if self.useLocalTime:
802 return self.utctime - self.timeZone*60
802 return self.utctime - self.timeZone*60
803
803
804 return self.utctime
804 return self.utctime
805
805
806 def getDatatime(self):
806 def getDatatime(self):
807
807
808 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
808 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
809 return datatime
809 return datatime
810
810
811 def getTimeRange(self):
811 def getTimeRange(self):
812
812
813 datatime = []
813 datatime = []
814
814
815 datatime.append(self.ltctime)
815 datatime.append(self.ltctime)
816 datatime.append(self.ltctime + self.timeInterval)
816 datatime.append(self.ltctime + self.timeInterval)
817
817
818 datatime = numpy.array(datatime)
818 datatime = numpy.array(datatime)
819
819
820 return datatime
820 return datatime
821
821
822 def getHeiRange(self):
822 def getHeiRange(self):
823
823
824 heis = self.heightList
824 heis = self.heightList
825
825
826 return heis
826 return heis
827
827
828 def isEmpty(self):
828 def isEmpty(self):
829
829
830 return self.flagNoData
830 return self.flagNoData
831
831
832 def getNHeights(self):
832 def getNHeights(self):
833
833
834 return len(self.heightList)
834 return len(self.heightList)
835
835
836 def getNChannels(self):
836 def getNChannels(self):
837
837
838 return len(self.channelList)
838 return len(self.channelList)
839
839
840 def getChannelIndexList(self):
840 def getChannelIndexList(self):
841
841
842 return range(self.nChannels)
842 return range(self.nChannels)
843
843
844 def getNoise(self, type = 1):
844 def getNoise(self, type = 1):
845
845
846 #noise = numpy.zeros(self.nChannels)
846 #noise = numpy.zeros(self.nChannels)
847
847
848 if type == 1:
848 if type == 1:
849 noise = self.getNoisebyHildebrand()
849 noise = self.getNoisebyHildebrand()
850
850
851 if type == 2:
851 if type == 2:
852 noise = self.getNoisebySort()
852 noise = self.getNoisebySort()
853
853
854 if type == 3:
854 if type == 3:
855 noise = self.getNoisebyWindow()
855 noise = self.getNoisebyWindow()
856
856
857 return noise
857 return noise
858
858
859 def getTimeInterval(self):
859 def getTimeInterval(self):
860
860
861 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
861 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
862
862
863 return timeInterval
863 return timeInterval
864
864
865 datatime = property(getDatatime, "I'm the 'datatime' property")
865 datatime = property(getDatatime, "I'm the 'datatime' property")
866 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
866 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
867 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
867 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
868 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
868 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
869 noise = property(getNoise, "I'm the 'nHeights' property.")
869 noise = property(getNoise, "I'm the 'nHeights' property.")
870 datatime = property(getDatatime, "I'm the 'datatime' property")
870 datatime = property(getDatatime, "I'm the 'datatime' property")
871 ltctime = property(getltctime, "I'm the 'ltctime' property")
871 ltctime = property(getltctime, "I'm the 'ltctime' property")
872 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
872 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
873
873
874 class Correlation(JROData):
874 class Correlation(JROData):
875
875
876 noise = None
876 noise = None
877
877
878 SNR = None
878 SNR = None
879
879
880 pairsAutoCorr = None #Pairs of Autocorrelation
880 pairsAutoCorr = None #Pairs of Autocorrelation
881
881
882 #--------------------------------------------------
882 #--------------------------------------------------
883
883
884 data_corr = None
884 data_corr = None
885
885
886 data_volt = None
886 data_volt = None
887
887
888 lagT = None # each element value is a profileIndex
888 lagT = None # each element value is a profileIndex
889
889
890 lagR = None # each element value is in km
890 lagR = None # each element value is in km
891
891
892 pairsList = None
892 pairsList = None
893
893
894 calculateVelocity = None
894 calculateVelocity = None
895
895
896 nPoints = None
896 nPoints = None
897
897
898 nAvg = None
898 nAvg = None
899
899
900 bufferSize = None
900 bufferSize = None
901
901
902 def __init__(self):
902 def __init__(self):
903 '''
903 '''
904 Constructor
904 Constructor
905 '''
905 '''
906 self.radarControllerHeaderObj = RadarControllerHeader()
906 self.radarControllerHeaderObj = RadarControllerHeader()
907
907
908 self.systemHeaderObj = SystemHeader()
908 self.systemHeaderObj = SystemHeader()
909
909
910 self.type = "Correlation"
910 self.type = "Correlation"
911
911
912 self.data = None
912 self.data = None
913
913
914 self.dtype = None
914 self.dtype = None
915
915
916 self.nProfiles = None
916 self.nProfiles = None
917
917
918 self.heightList = None
918 self.heightList = None
919
919
920 self.channelList = None
920 self.channelList = None
921
921
922 self.flagNoData = True
922 self.flagNoData = True
923
923
924 self.flagDiscontinuousBlock = False
924 self.flagDiscontinuousBlock = False
925
925
926 self.utctime = None
926 self.utctime = None
927
927
928 self.timeZone = None
928 self.timeZone = None
929
929
930 self.dstFlag = None
930 self.dstFlag = None
931
931
932 self.errorCount = None
932 self.errorCount = None
933
933
934 self.blocksize = None
934 self.blocksize = None
935
935
936 self.flagDecodeData = False #asumo q la data no esta decodificada
936 self.flagDecodeData = False #asumo q la data no esta decodificada
937
937
938 self.flagDeflipData = False #asumo q la data no esta sin flip
938 self.flagDeflipData = False #asumo q la data no esta sin flip
939
939
940 self.pairsList = None
940 self.pairsList = None
941
941
942 self.nPoints = None
942 self.nPoints = None
943
943
944 def getLagTRange(self, extrapoints=0):
944 def getLagTRange(self, extrapoints=0):
945
945
946 lagTRange = self.lagT
946 lagTRange = self.lagT
947 diff = lagTRange[1] - lagTRange[0]
947 diff = lagTRange[1] - lagTRange[0]
948 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
948 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
949 lagTRange = numpy.hstack((lagTRange, extra))
949 lagTRange = numpy.hstack((lagTRange, extra))
950
950
951 return lagTRange
951 return lagTRange
952
952
953 def getLagRRange(self, extrapoints=0):
953 def getLagRRange(self, extrapoints=0):
954
954
955 return self.lagR
955 return self.lagR
956
956
957 def getPairsList(self):
957 def getPairsList(self):
958
958
959 return self.pairsList
959 return self.pairsList
960
960
961 def getCalculateVelocity(self):
961 def getCalculateVelocity(self):
962
962
963 return self.calculateVelocity
963 return self.calculateVelocity
964
964
965 def getNPoints(self):
965 def getNPoints(self):
966
966
967 return self.nPoints
967 return self.nPoints
968
968
969 def getNAvg(self):
969 def getNAvg(self):
970
970
971 return self.nAvg
971 return self.nAvg
972
972
973 def getBufferSize(self):
973 def getBufferSize(self):
974
974
975 return self.bufferSize
975 return self.bufferSize
976
976
977 def getPairsAutoCorr(self):
977 def getPairsAutoCorr(self):
978 pairsList = self.pairsList
978 pairsList = self.pairsList
979 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
979 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
980
980
981 for l in range(len(pairsList)):
981 for l in range(len(pairsList)):
982 firstChannel = pairsList[l][0]
982 firstChannel = pairsList[l][0]
983 secondChannel = pairsList[l][1]
983 secondChannel = pairsList[l][1]
984
984
985 #Obteniendo pares de Autocorrelacion
985 #Obteniendo pares de Autocorrelacion
986 if firstChannel == secondChannel:
986 if firstChannel == secondChannel:
987 pairsAutoCorr[firstChannel] = int(l)
987 pairsAutoCorr[firstChannel] = int(l)
988
988
989 pairsAutoCorr = pairsAutoCorr.astype(int)
989 pairsAutoCorr = pairsAutoCorr.astype(int)
990
990
991 return pairsAutoCorr
991 return pairsAutoCorr
992
992
993 def getNoise(self, mode = 2):
993 def getNoise(self, mode = 2):
994
994
995 indR = numpy.where(self.lagR == 0)[0][0]
995 indR = numpy.where(self.lagR == 0)[0][0]
996 indT = numpy.where(self.lagT == 0)[0][0]
996 indT = numpy.where(self.lagT == 0)[0][0]
997
997
998 jspectra0 = self.data_corr[:,:,indR,:]
998 jspectra0 = self.data_corr[:,:,indR,:]
999 jspectra = copy.copy(jspectra0)
999 jspectra = copy.copy(jspectra0)
1000
1000
1001 num_chan = jspectra.shape[0]
1001 num_chan = jspectra.shape[0]
1002 num_hei = jspectra.shape[2]
1002 num_hei = jspectra.shape[2]
1003
1003
1004 freq_dc = jspectra.shape[1]/2
1004 freq_dc = jspectra.shape[1]/2
1005 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1005 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1006
1006
1007 if ind_vel[0]<0:
1007 if ind_vel[0]<0:
1008 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1008 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1009
1009
1010 if mode == 1:
1010 if mode == 1:
1011 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1011 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1012
1012
1013 if mode == 2:
1013 if mode == 2:
1014
1014
1015 vel = numpy.array([-2,-1,1,2])
1015 vel = numpy.array([-2,-1,1,2])
1016 xx = numpy.zeros([4,4])
1016 xx = numpy.zeros([4,4])
1017
1017
1018 for fil in range(4):
1018 for fil in range(4):
1019 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1019 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1020
1020
1021 xx_inv = numpy.linalg.inv(xx)
1021 xx_inv = numpy.linalg.inv(xx)
1022 xx_aux = xx_inv[0,:]
1022 xx_aux = xx_inv[0,:]
1023
1023
1024 for ich in range(num_chan):
1024 for ich in range(num_chan):
1025 yy = jspectra[ich,ind_vel,:]
1025 yy = jspectra[ich,ind_vel,:]
1026 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1026 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1027
1027
1028 junkid = jspectra[ich,freq_dc,:]<=0
1028 junkid = jspectra[ich,freq_dc,:]<=0
1029 cjunkid = sum(junkid)
1029 cjunkid = sum(junkid)
1030
1030
1031 if cjunkid.any():
1031 if cjunkid.any():
1032 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1032 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1033
1033
1034 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1034 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1035
1035
1036 return noise
1036 return noise
1037
1037
1038 def getTimeInterval(self):
1038 def getTimeInterval(self):
1039
1039
1040 timeInterval = self.ippSeconds * self.nCohInt * self.nPoints
1040 timeInterval = self.ippSeconds * self.nCohInt * self.nPoints
1041
1041
1042 return timeInterval
1042 return timeInterval
1043
1043
1044 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1044 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1045 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
1045 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
1046 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
1046 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
1047 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
1047 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
1048 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
1048 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
1049 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
1049 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
1050
1050
1051
1051
1052 class Parameters(JROData):
1052 class Parameters(JROData):
1053
1053
1054 #Information from previous data
1054 #Information from previous data
1055
1055
1056 inputUnit = None #Type of data to be processed
1056 inputUnit = None #Type of data to be processed
1057
1057
1058 operation = None #Type of operation to parametrize
1058 operation = None #Type of operation to parametrize
1059
1059
1060 normFactor = None #Normalization Factor
1060 normFactor = None #Normalization Factor
1061
1061
1062 groupList = None #List of Pairs, Groups, etc
1062 groupList = None #List of Pairs, Groups, etc
1063
1063
1064 #Parameters
1064 #Parameters
1065
1065
1066 data_param = None #Parameters obtained
1066 data_param = None #Parameters obtained
1067
1067
1068 data_pre = None #Data Pre Parametrization
1068 data_pre = None #Data Pre Parametrization
1069
1069
1070 data_SNR = None #Signal to Noise Ratio
1070 data_SNR = None #Signal to Noise Ratio
1071
1071
1072 heightRange = None #Heights
1072 # heightRange = None #Heights
1073
1073
1074 abscissaRange = None #Abscissa, can be velocities, lags or time
1074 abscissaList = None #Abscissa, can be velocities, lags or time
1075
1075
1076 noise = None #Noise Potency
1076 noise = None #Noise Potency
1077
1077
1078 # initUtcTime = None #Initial UTC time
1078 utctimeInit = None #Initial UTC time
1079
1079
1080 paramInterval = None #Time interval to calculate Parameters in seconds
1080 paramInterval = None #Time interval to calculate Parameters in seconds
1081
1081
1082 #Fitting
1082 #Fitting
1083
1083
1084 data_error = None #Error of the estimation
1084 data_error = None #Error of the estimation
1085
1085
1086 constants = None
1086 constants = None
1087
1087
1088 library = None
1088 library = None
1089
1089
1090 #Output signal
1090 #Output signal
1091
1091
1092 outputInterval = None #Time interval to calculate output signal in seconds
1092 outputInterval = None #Time interval to calculate output signal in seconds
1093
1093
1094 data_output = None #Out signal
1094 data_output = None #Out signal
1095
1095
1096
1097
1096 def __init__(self):
1098 def __init__(self):
1097 '''
1099 '''
1098 Constructor
1100 Constructor
1099 '''
1101 '''
1100 self.radarControllerHeaderObj = RadarControllerHeader()
1102 self.radarControllerHeaderObj = RadarControllerHeader()
1101
1103
1102 self.systemHeaderObj = SystemHeader()
1104 self.systemHeaderObj = SystemHeader()
1103
1105
1104 self.type = "Parameters"
1106 self.type = "Parameters"
1105
1107
1106 def getTimeRange1(self):
1108 def getTimeRange1(self):
1107
1109
1108 datatime = []
1110 datatime = []
1109
1111
1110 datatime.append(self.ltctime)
1112 if self.useLocalTime:
1111 datatime.append(self.ltctime + self.outputInterval - 1)
1113 time1 = self.utctimeInit - self.timeZone*60
1114 else:
1115 time1 = utctimeInit
1116
1117 # datatime.append(self.utctimeInit)
1118 # datatime.append(self.utctimeInit + self.outputInterval)
1119 datatime.append(time1)
1120 datatime.append(time1 + self.outputInterval)
1112
1121
1113 datatime = numpy.array(datatime)
1122 datatime = numpy.array(datatime)
1114
1123
1115 return datatime
1124 return datatime
@@ -1,610 +1,610
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6 from schainpy.model.proc.jroproc_base import Operation
6 from schainpy.model.proc.jroproc_base import Operation
7
7
8 def isRealtime(utcdatatime):
8 def isRealtime(utcdatatime):
9 utcnow = time.mktime(time.localtime())
9 utcnow = time.mktime(time.localtime())
10 delta = abs(utcnow - utcdatatime) # abs
10 delta = abs(utcnow - utcdatatime) # abs
11 if delta >= 30.:
11 if delta >= 30.:
12 return False
12 return False
13 return True
13 return True
14
14
15 class Figure(Operation):
15 class Figure(Operation):
16
16
17 __driver = mpldriver
17 __driver = mpldriver
18 __isConfigThread = False
18 __isConfigThread = False
19 fig = None
19 fig = None
20
20
21 id = None
21 id = None
22 wintitle = None
22 wintitle = None
23 width = None
23 width = None
24 height = None
24 height = None
25 nplots = None
25 nplots = None
26 timerange = None
26 timerange = None
27
27
28 axesObjList = []
28 axesObjList = []
29
29
30 WIDTH = None
30 WIDTH = None
31 HEIGHT = None
31 HEIGHT = None
32 PREFIX = 'fig'
32 PREFIX = 'fig'
33
33
34 xmin = None
34 xmin = None
35 xmax = None
35 xmax = None
36
36
37 counter_imagwr = 0
37 counter_imagwr = 0
38
38
39 figfile = None
39 figfile = None
40
40
41 def __init__(self):
41 def __init__(self):
42
42
43 raise ValueError, "This method is not implemented"
43 raise ValueError, "This method is not implemented"
44
44
45 def __del__(self):
45 def __del__(self):
46
46
47 self.__driver.closeFigure()
47 self.__driver.closeFigure()
48
48
49 def getFilename(self, name, ext='.png'):
49 def getFilename(self, name, ext='.png'):
50
50
51 path = '%s%03d' %(self.PREFIX, self.id)
51 path = '%s%03d' %(self.PREFIX, self.id)
52 filename = '%s_%s%s' %(self.PREFIX, name, ext)
52 filename = '%s_%s%s' %(self.PREFIX, name, ext)
53 return os.path.join(path, filename)
53 return os.path.join(path, filename)
54
54
55 def getAxesObjList(self):
55 def getAxesObjList(self):
56
56
57 return self.axesObjList
57 return self.axesObjList
58
58
59 def getSubplots(self):
59 def getSubplots(self):
60
60
61 raise ValueError, "Abstract method: This method should be defined"
61 raise ValueError, "Abstract method: This method should be defined"
62
62
63 def getScreenDim(self, widthplot, heightplot):
63 def getScreenDim(self, widthplot, heightplot):
64
64
65 nrow, ncol = self.getSubplots()
65 nrow, ncol = self.getSubplots()
66
66
67 widthscreen = widthplot*ncol
67 widthscreen = widthplot*ncol
68 heightscreen = heightplot*nrow
68 heightscreen = heightplot*nrow
69
69
70 return widthscreen, heightscreen
70 return widthscreen, heightscreen
71
71
72 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
72 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
73
73
74 if self.xmin != None and self.xmax != None:
74 if self.xmin != None and self.xmax != None:
75 if timerange == None:
75 if timerange == None:
76 timerange = self.xmax - self.xmin
76 timerange = self.xmax - self.xmin
77 xmin = self.xmin + timerange
77 xmin = self.xmin + timerange
78 xmax = self.xmax + timerange
78 xmax = self.xmax + timerange
79
79
80 return xmin, xmax
80 return xmin, xmax
81
81
82 if timerange == None and (xmin==None or xmax==None):
82 if timerange == None and (xmin==None or xmax==None):
83 timerange = 14400 #seconds
83 timerange = 14400 #seconds
84 #raise ValueError, "(timerange) or (xmin & xmax) should be defined"
84 #raise ValueError, "(timerange) or (xmin & xmax) should be defined"
85
85
86 if timerange != None:
86 if timerange != None:
87 txmin = x[0] - x[0] % min(timerange/10, 10*60)
87 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
88 else:
88 else:
89 txmin = x[0] - x[0] % 10*60
89 txmin = x[0] #- x[0] % 10*60
90
90
91 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
91 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
92 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
92 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
93
93
94 if timerange != None:
94 if timerange != None:
95 xmin = (thisdatetime - thisdate).seconds/(60*60.)
95 xmin = (thisdatetime - thisdate).seconds/(60*60.)
96 xmax = xmin + timerange/(60*60.)
96 xmax = xmin + timerange/(60*60.)
97
97
98 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
98 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
99 xmin_sec = time.mktime(mindt.timetuple())
99 xmin_sec = time.mktime(mindt.timetuple())
100
100
101 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
101 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
102 xmax_sec = time.mktime(maxdt.timetuple())
102 xmax_sec = time.mktime(maxdt.timetuple())
103
103
104 return xmin_sec, xmax_sec
104 return xmin_sec, xmax_sec
105
105
106 def init(self, id, nplots, wintitle):
106 def init(self, id, nplots, wintitle):
107
107
108 raise ValueError, "This method has been replaced with createFigure"
108 raise ValueError, "This method has been replaced with createFigure"
109
109
110 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
110 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
111
111
112 """
112 """
113 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
113 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
114 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
114 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
115 y self.HEIGHT y el numero de subplots (nrow, ncol)
115 y self.HEIGHT y el numero de subplots (nrow, ncol)
116
116
117 Input:
117 Input:
118 id : Los parametros necesarios son
118 id : Los parametros necesarios son
119 wintitle :
119 wintitle :
120
120
121 """
121 """
122
122
123 if widthplot == None:
123 if widthplot == None:
124 widthplot = self.WIDTH
124 widthplot = self.WIDTH
125
125
126 if heightplot == None:
126 if heightplot == None:
127 heightplot = self.HEIGHT
127 heightplot = self.HEIGHT
128
128
129 self.id = id
129 self.id = id
130
130
131 self.wintitle = wintitle
131 self.wintitle = wintitle
132
132
133 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
133 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
134
134
135 self.fig = self.__driver.createFigure(id=self.id,
135 self.fig = self.__driver.createFigure(id=self.id,
136 wintitle=self.wintitle,
136 wintitle=self.wintitle,
137 width=self.widthscreen,
137 width=self.widthscreen,
138 height=self.heightscreen,
138 height=self.heightscreen,
139 show=show)
139 show=show)
140
140
141 self.axesObjList = []
141 self.axesObjList = []
142 self.counter_imagwr = 0
142 self.counter_imagwr = 0
143
143
144
144
145 def setDriver(self, driver=mpldriver):
145 def setDriver(self, driver=mpldriver):
146
146
147 self.__driver = driver
147 self.__driver = driver
148
148
149 def setTitle(self, title):
149 def setTitle(self, title):
150
150
151 self.__driver.setTitle(self.fig, title)
151 self.__driver.setTitle(self.fig, title)
152
152
153 def setWinTitle(self, title):
153 def setWinTitle(self, title):
154
154
155 self.__driver.setWinTitle(self.fig, title=title)
155 self.__driver.setWinTitle(self.fig, title=title)
156
156
157 def setTextFromAxes(self, text):
157 def setTextFromAxes(self, text):
158
158
159 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
159 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
160
160
161 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
161 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
162
162
163 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
163 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
164
164
165 def addAxes(self, *args):
165 def addAxes(self, *args):
166 """
166 """
167
167
168 Input:
168 Input:
169 *args : Los parametros necesarios son
169 *args : Los parametros necesarios son
170 nrow, ncol, xpos, ypos, colspan, rowspan
170 nrow, ncol, xpos, ypos, colspan, rowspan
171 """
171 """
172
172
173 axesObj = Axes(self.fig, *args)
173 axesObj = Axes(self.fig, *args)
174 self.axesObjList.append(axesObj)
174 self.axesObjList.append(axesObj)
175
175
176 def saveFigure(self, figpath, figfile, *args):
176 def saveFigure(self, figpath, figfile, *args):
177
177
178 filename = os.path.join(figpath, figfile)
178 filename = os.path.join(figpath, figfile)
179
179
180 fullpath = os.path.split(filename)[0]
180 fullpath = os.path.split(filename)[0]
181
181
182 if not os.path.exists(fullpath):
182 if not os.path.exists(fullpath):
183 subpath = os.path.split(fullpath)[0]
183 subpath = os.path.split(fullpath)[0]
184
184
185 if not os.path.exists(subpath):
185 if not os.path.exists(subpath):
186 os.mkdir(subpath)
186 os.mkdir(subpath)
187
187
188 os.mkdir(fullpath)
188 os.mkdir(fullpath)
189
189
190 self.__driver.saveFigure(self.fig, filename, *args)
190 self.__driver.saveFigure(self.fig, filename, *args)
191
191
192 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
192 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
193
193
194 self.counter_imagwr += 1
194 self.counter_imagwr += 1
195 if self.counter_imagwr < wr_period:
195 if self.counter_imagwr < wr_period:
196 return
196 return
197
197
198 self.counter_imagwr = 0
198 self.counter_imagwr = 0
199
199
200 if save:
200 if save:
201
201
202 if not figfile:
202 if not figfile:
203
203
204 if not thisDatetime:
204 if not thisDatetime:
205 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
205 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
206 return
206 return
207
207
208 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
208 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
209 figfile = self.getFilename(name = str_datetime)
209 figfile = self.getFilename(name = str_datetime)
210
210
211 if self.figfile == None:
211 if self.figfile == None:
212 self.figfile = figfile
212 self.figfile = figfile
213
213
214 if update_figfile:
214 if update_figfile:
215 self.figfile = figfile
215 self.figfile = figfile
216
216
217 # store png plot to local folder
217 # store png plot to local folder
218 self.saveFigure(figpath, self.figfile)
218 self.saveFigure(figpath, self.figfile)
219
219
220
220
221 if not ftp:
221 if not ftp:
222 return
222 return
223
223
224 if not thisDatetime:
224 if not thisDatetime:
225 return
225 return
226
226
227 # store png plot to FTP server according to RT-Web format
227 # store png plot to FTP server according to RT-Web format
228 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
228 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
229 # ftp_filename = os.path.join(figpath, name)
229 # ftp_filename = os.path.join(figpath, name)
230 self.saveFigure(figpath, ftp_filename)
230 self.saveFigure(figpath, ftp_filename)
231
231
232 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
232 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
233 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
233 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
234 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
234 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
235 FTP_WEI = '%2.2d'%FTP_WEI
235 FTP_WEI = '%2.2d'%FTP_WEI
236 EXP_CODE = '%3.3d'%EXP_CODE
236 EXP_CODE = '%3.3d'%EXP_CODE
237 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
237 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
238 PLOT_CODE = '%2.2d'%PLOT_CODE
238 PLOT_CODE = '%2.2d'%PLOT_CODE
239 PLOT_POS = '%2.2d'%PLOT_POS
239 PLOT_POS = '%2.2d'%PLOT_POS
240 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
240 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
241 return name
241 return name
242
242
243 def draw(self):
243 def draw(self):
244
244
245 self.__driver.draw(self.fig)
245 self.__driver.draw(self.fig)
246
246
247 def run(self):
247 def run(self):
248
248
249 raise ValueError, "This method is not implemented"
249 raise ValueError, "This method is not implemented"
250
250
251 def close(self, show=False):
251 def close(self, show=False):
252
252
253 self.__driver.closeFigure(show=show, fig=self.fig)
253 self.__driver.closeFigure(show=show, fig=self.fig)
254
254
255 axesList = property(getAxesObjList)
255 axesList = property(getAxesObjList)
256
256
257
257
258 class Axes:
258 class Axes:
259
259
260 __driver = mpldriver
260 __driver = mpldriver
261 fig = None
261 fig = None
262 ax = None
262 ax = None
263 plot = None
263 plot = None
264 __missing = 1E30
264 __missing = 1E30
265 __firsttime = None
265 __firsttime = None
266
266
267 __showprofile = False
267 __showprofile = False
268
268
269 xmin = None
269 xmin = None
270 xmax = None
270 xmax = None
271 ymin = None
271 ymin = None
272 ymax = None
272 ymax = None
273 zmin = None
273 zmin = None
274 zmax = None
274 zmax = None
275
275
276 x_buffer = None
276 x_buffer = None
277 z_buffer = None
277 z_buffer = None
278
278
279 decimationx = None
279 decimationx = None
280 decimationy = None
280 decimationy = None
281
281
282 __MAXNUMX = 300
282 __MAXNUMX = 300
283 __MAXNUMY = 150
283 __MAXNUMY = 150
284
284
285 def __init__(self, *args):
285 def __init__(self, *args):
286
286
287 """
287 """
288
288
289 Input:
289 Input:
290 *args : Los parametros necesarios son
290 *args : Los parametros necesarios son
291 fig, nrow, ncol, xpos, ypos, colspan, rowspan
291 fig, nrow, ncol, xpos, ypos, colspan, rowspan
292 """
292 """
293
293
294 ax = self.__driver.createAxes(*args)
294 ax = self.__driver.createAxes(*args)
295 self.fig = args[0]
295 self.fig = args[0]
296 self.ax = ax
296 self.ax = ax
297 self.plot = None
297 self.plot = None
298
298
299 self.__firsttime = True
299 self.__firsttime = True
300 self.idlineList = []
300 self.idlineList = []
301
301
302 self.x_buffer = numpy.array([])
302 self.x_buffer = numpy.array([])
303 self.z_buffer = numpy.array([])
303 self.z_buffer = numpy.array([])
304
304
305 def setText(self, text):
305 def setText(self, text):
306
306
307 self.__driver.setAxesText(self.ax, text)
307 self.__driver.setAxesText(self.ax, text)
308
308
309 def setXAxisAsTime(self):
309 def setXAxisAsTime(self):
310 pass
310 pass
311
311
312 def pline(self, x, y,
312 def pline(self, x, y,
313 xmin=None, xmax=None,
313 xmin=None, xmax=None,
314 ymin=None, ymax=None,
314 ymin=None, ymax=None,
315 xlabel='', ylabel='',
315 xlabel='', ylabel='',
316 title='',
316 title='',
317 **kwargs):
317 **kwargs):
318
318
319 """
319 """
320
320
321 Input:
321 Input:
322 x :
322 x :
323 y :
323 y :
324 xmin :
324 xmin :
325 xmax :
325 xmax :
326 ymin :
326 ymin :
327 ymax :
327 ymax :
328 xlabel :
328 xlabel :
329 ylabel :
329 ylabel :
330 title :
330 title :
331 **kwargs : Los parametros aceptados son
331 **kwargs : Los parametros aceptados son
332
332
333 ticksize
333 ticksize
334 ytick_visible
334 ytick_visible
335 """
335 """
336
336
337 if self.__firsttime:
337 if self.__firsttime:
338
338
339 if xmin == None: xmin = numpy.nanmin(x)
339 if xmin == None: xmin = numpy.nanmin(x)
340 if xmax == None: xmax = numpy.nanmax(x)
340 if xmax == None: xmax = numpy.nanmax(x)
341 if ymin == None: ymin = numpy.nanmin(y)
341 if ymin == None: ymin = numpy.nanmin(y)
342 if ymax == None: ymax = numpy.nanmax(y)
342 if ymax == None: ymax = numpy.nanmax(y)
343
343
344 self.plot = self.__driver.createPline(self.ax, x, y,
344 self.plot = self.__driver.createPline(self.ax, x, y,
345 xmin, xmax,
345 xmin, xmax,
346 ymin, ymax,
346 ymin, ymax,
347 xlabel=xlabel,
347 xlabel=xlabel,
348 ylabel=ylabel,
348 ylabel=ylabel,
349 title=title,
349 title=title,
350 **kwargs)
350 **kwargs)
351
351
352 self.idlineList.append(0)
352 self.idlineList.append(0)
353 self.__firsttime = False
353 self.__firsttime = False
354 return
354 return
355
355
356 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
356 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
357 ylabel=ylabel,
357 ylabel=ylabel,
358 title=title)
358 title=title)
359
359
360 def addpline(self, x, y, idline, **kwargs):
360 def addpline(self, x, y, idline, **kwargs):
361 lines = self.ax.lines
361 lines = self.ax.lines
362
362
363 if idline in self.idlineList:
363 if idline in self.idlineList:
364 self.__driver.set_linedata(self.ax, x, y, idline)
364 self.__driver.set_linedata(self.ax, x, y, idline)
365
365
366 if idline not in(self.idlineList):
366 if idline not in(self.idlineList):
367 self.__driver.addpline(self.ax, x, y, **kwargs)
367 self.__driver.addpline(self.ax, x, y, **kwargs)
368 self.idlineList.append(idline)
368 self.idlineList.append(idline)
369
369
370 return
370 return
371
371
372 def pmultiline(self, x, y,
372 def pmultiline(self, x, y,
373 xmin=None, xmax=None,
373 xmin=None, xmax=None,
374 ymin=None, ymax=None,
374 ymin=None, ymax=None,
375 xlabel='', ylabel='',
375 xlabel='', ylabel='',
376 title='',
376 title='',
377 **kwargs):
377 **kwargs):
378
378
379 if self.__firsttime:
379 if self.__firsttime:
380
380
381 if xmin == None: xmin = numpy.nanmin(x)
381 if xmin == None: xmin = numpy.nanmin(x)
382 if xmax == None: xmax = numpy.nanmax(x)
382 if xmax == None: xmax = numpy.nanmax(x)
383 if ymin == None: ymin = numpy.nanmin(y)
383 if ymin == None: ymin = numpy.nanmin(y)
384 if ymax == None: ymax = numpy.nanmax(y)
384 if ymax == None: ymax = numpy.nanmax(y)
385
385
386 self.plot = self.__driver.createPmultiline(self.ax, x, y,
386 self.plot = self.__driver.createPmultiline(self.ax, x, y,
387 xmin, xmax,
387 xmin, xmax,
388 ymin, ymax,
388 ymin, ymax,
389 xlabel=xlabel,
389 xlabel=xlabel,
390 ylabel=ylabel,
390 ylabel=ylabel,
391 title=title,
391 title=title,
392 **kwargs)
392 **kwargs)
393 self.__firsttime = False
393 self.__firsttime = False
394 return
394 return
395
395
396 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
396 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
397 ylabel=ylabel,
397 ylabel=ylabel,
398 title=title)
398 title=title)
399
399
400 def pmultilineyaxis(self, x, y,
400 def pmultilineyaxis(self, x, y,
401 xmin=None, xmax=None,
401 xmin=None, xmax=None,
402 ymin=None, ymax=None,
402 ymin=None, ymax=None,
403 xlabel='', ylabel='',
403 xlabel='', ylabel='',
404 title='',
404 title='',
405 **kwargs):
405 **kwargs):
406
406
407 if self.__firsttime:
407 if self.__firsttime:
408
408
409 if xmin == None: xmin = numpy.nanmin(x)
409 if xmin == None: xmin = numpy.nanmin(x)
410 if xmax == None: xmax = numpy.nanmax(x)
410 if xmax == None: xmax = numpy.nanmax(x)
411 if ymin == None: ymin = numpy.nanmin(y)
411 if ymin == None: ymin = numpy.nanmin(y)
412 if ymax == None: ymax = numpy.nanmax(y)
412 if ymax == None: ymax = numpy.nanmax(y)
413
413
414 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
414 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
415 xmin, xmax,
415 xmin, xmax,
416 ymin, ymax,
416 ymin, ymax,
417 xlabel=xlabel,
417 xlabel=xlabel,
418 ylabel=ylabel,
418 ylabel=ylabel,
419 title=title,
419 title=title,
420 **kwargs)
420 **kwargs)
421 if self.xmin == None: self.xmin = xmin
421 if self.xmin == None: self.xmin = xmin
422 if self.xmax == None: self.xmax = xmax
422 if self.xmax == None: self.xmax = xmax
423 if self.ymin == None: self.ymin = ymin
423 if self.ymin == None: self.ymin = ymin
424 if self.ymax == None: self.ymax = ymax
424 if self.ymax == None: self.ymax = ymax
425
425
426 self.__firsttime = False
426 self.__firsttime = False
427 return
427 return
428
428
429 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
429 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
430 ylabel=ylabel,
430 ylabel=ylabel,
431 title=title)
431 title=title)
432
432
433 def pcolor(self, x, y, z,
433 def pcolor(self, x, y, z,
434 xmin=None, xmax=None,
434 xmin=None, xmax=None,
435 ymin=None, ymax=None,
435 ymin=None, ymax=None,
436 zmin=None, zmax=None,
436 zmin=None, zmax=None,
437 xlabel='', ylabel='',
437 xlabel='', ylabel='',
438 title='', rti = False, colormap='jet',
438 title='', rti = False, colormap='jet',
439 **kwargs):
439 **kwargs):
440
440
441 """
441 """
442 Input:
442 Input:
443 x :
443 x :
444 y :
444 y :
445 x :
445 x :
446 xmin :
446 xmin :
447 xmax :
447 xmax :
448 ymin :
448 ymin :
449 ymax :
449 ymax :
450 zmin :
450 zmin :
451 zmax :
451 zmax :
452 xlabel :
452 xlabel :
453 ylabel :
453 ylabel :
454 title :
454 title :
455 **kwargs : Los parametros aceptados son
455 **kwargs : Los parametros aceptados son
456 ticksize=9,
456 ticksize=9,
457 cblabel=''
457 cblabel=''
458 rti = True or False
458 rti = True or False
459 """
459 """
460
460
461 if self.__firsttime:
461 if self.__firsttime:
462
462
463 if xmin == None: xmin = numpy.nanmin(x)
463 if xmin == None: xmin = numpy.nanmin(x)
464 if xmax == None: xmax = numpy.nanmax(x)
464 if xmax == None: xmax = numpy.nanmax(x)
465 if ymin == None: ymin = numpy.nanmin(y)
465 if ymin == None: ymin = numpy.nanmin(y)
466 if ymax == None: ymax = numpy.nanmax(y)
466 if ymax == None: ymax = numpy.nanmax(y)
467 if zmin == None: zmin = numpy.nanmin(z)
467 if zmin == None: zmin = numpy.nanmin(z)
468 if zmax == None: zmax = numpy.nanmax(z)
468 if zmax == None: zmax = numpy.nanmax(z)
469
469
470
470
471 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
471 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
472 xmin, xmax,
472 xmin, xmax,
473 ymin, ymax,
473 ymin, ymax,
474 zmin, zmax,
474 zmin, zmax,
475 xlabel=xlabel,
475 xlabel=xlabel,
476 ylabel=ylabel,
476 ylabel=ylabel,
477 title=title,
477 title=title,
478 colormap=colormap,
478 colormap=colormap,
479 **kwargs)
479 **kwargs)
480
480
481 if self.xmin == None: self.xmin = xmin
481 if self.xmin == None: self.xmin = xmin
482 if self.xmax == None: self.xmax = xmax
482 if self.xmax == None: self.xmax = xmax
483 if self.ymin == None: self.ymin = ymin
483 if self.ymin == None: self.ymin = ymin
484 if self.ymax == None: self.ymax = ymax
484 if self.ymax == None: self.ymax = ymax
485 if self.zmin == None: self.zmin = zmin
485 if self.zmin == None: self.zmin = zmin
486 if self.zmax == None: self.zmax = zmax
486 if self.zmax == None: self.zmax = zmax
487
487
488 self.__firsttime = False
488 self.__firsttime = False
489 return
489 return
490
490
491 if rti:
491 if rti:
492 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
492 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
493 xlabel=xlabel,
493 xlabel=xlabel,
494 ylabel=ylabel,
494 ylabel=ylabel,
495 title=title,
495 title=title,
496 colormap=colormap)
496 colormap=colormap)
497 return
497 return
498
498
499 self.__driver.pcolor(self.plot, z,
499 self.__driver.pcolor(self.plot, z,
500 xlabel=xlabel,
500 xlabel=xlabel,
501 ylabel=ylabel,
501 ylabel=ylabel,
502 title=title)
502 title=title)
503
503
504 def pcolorbuffer(self, x, y, z,
504 def pcolorbuffer(self, x, y, z,
505 xmin=None, xmax=None,
505 xmin=None, xmax=None,
506 ymin=None, ymax=None,
506 ymin=None, ymax=None,
507 zmin=None, zmax=None,
507 zmin=None, zmax=None,
508 xlabel='', ylabel='',
508 xlabel='', ylabel='',
509 title='', rti = True, colormap='jet',
509 title='', rti = True, colormap='jet',
510 maxNumX = None, maxNumY = None,
510 maxNumX = None, maxNumY = None,
511 **kwargs):
511 **kwargs):
512
512
513 if maxNumX == None:
513 if maxNumX == None:
514 maxNumX = self.__MAXNUMX
514 maxNumX = self.__MAXNUMX
515
515
516 if maxNumY == None:
516 if maxNumY == None:
517 maxNumY = self.__MAXNUMY
517 maxNumY = self.__MAXNUMY
518
518
519 if self.__firsttime:
519 if self.__firsttime:
520 self.z_buffer = z
520 self.z_buffer = z
521 self.x_buffer = numpy.hstack((self.x_buffer, x))
521 self.x_buffer = numpy.hstack((self.x_buffer, x))
522
522
523 if xmin == None: xmin = numpy.nanmin(x)
523 if xmin == None: xmin = numpy.nanmin(x)
524 if xmax == None: xmax = numpy.nanmax(x)
524 if xmax == None: xmax = numpy.nanmax(x)
525 if ymin == None: ymin = numpy.nanmin(y)
525 if ymin == None: ymin = numpy.nanmin(y)
526 if ymax == None: ymax = numpy.nanmax(y)
526 if ymax == None: ymax = numpy.nanmax(y)
527 if zmin == None: zmin = numpy.nanmin(z)
527 if zmin == None: zmin = numpy.nanmin(z)
528 if zmax == None: zmax = numpy.nanmax(z)
528 if zmax == None: zmax = numpy.nanmax(z)
529
529
530
530
531 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
531 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
532 xmin, xmax,
532 xmin, xmax,
533 ymin, ymax,
533 ymin, ymax,
534 zmin, zmax,
534 zmin, zmax,
535 xlabel=xlabel,
535 xlabel=xlabel,
536 ylabel=ylabel,
536 ylabel=ylabel,
537 title=title,
537 title=title,
538 colormap=colormap,
538 colormap=colormap,
539 **kwargs)
539 **kwargs)
540
540
541 if self.xmin == None: self.xmin = xmin
541 if self.xmin == None: self.xmin = xmin
542 if self.xmax == None: self.xmax = xmax
542 if self.xmax == None: self.xmax = xmax
543 if self.ymin == None: self.ymin = ymin
543 if self.ymin == None: self.ymin = ymin
544 if self.ymax == None: self.ymax = ymax
544 if self.ymax == None: self.ymax = ymax
545 if self.zmin == None: self.zmin = zmin
545 if self.zmin == None: self.zmin = zmin
546 if self.zmax == None: self.zmax = zmax
546 if self.zmax == None: self.zmax = zmax
547
547
548 self.__firsttime = False
548 self.__firsttime = False
549 return
549 return
550
550
551 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
551 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
552 self.z_buffer = numpy.hstack((self.z_buffer, z))
552 self.z_buffer = numpy.hstack((self.z_buffer, z))
553
553
554 if self.decimationx == None:
554 if self.decimationx == None:
555 deltax = float(self.xmax - self.xmin)/maxNumX
555 deltax = float(self.xmax - self.xmin)/maxNumX
556 deltay = float(self.ymax - self.ymin)/maxNumY
556 deltay = float(self.ymax - self.ymin)/maxNumY
557
557
558 resolutionx = self.x_buffer[2]-self.x_buffer[0]
558 resolutionx = self.x_buffer[2]-self.x_buffer[0]
559 resolutiony = y[1]-y[0]
559 resolutiony = y[1]-y[0]
560
560
561 self.decimationx = numpy.ceil(deltax / resolutionx)
561 self.decimationx = numpy.ceil(deltax / resolutionx)
562 self.decimationy = numpy.ceil(deltay / resolutiony)
562 self.decimationy = numpy.ceil(deltay / resolutiony)
563
563
564 z_buffer = self.z_buffer.reshape(-1,len(y))
564 z_buffer = self.z_buffer.reshape(-1,len(y))
565
565
566 x_buffer = self.x_buffer[::self.decimationx]
566 x_buffer = self.x_buffer[::self.decimationx]
567 y_buffer = y[::self.decimationy]
567 y_buffer = y[::self.decimationy]
568 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
568 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
569 #===================================================
569 #===================================================
570
570
571 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
571 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
572
572
573 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
573 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
574 xlabel=xlabel,
574 xlabel=xlabel,
575 ylabel=ylabel,
575 ylabel=ylabel,
576 title=title,
576 title=title,
577 colormap=colormap)
577 colormap=colormap)
578
578
579 def polar(self, x, y,
579 def polar(self, x, y,
580 title='', xlabel='',ylabel='',**kwargs):
580 title='', xlabel='',ylabel='',**kwargs):
581
581
582 if self.__firsttime:
582 if self.__firsttime:
583 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
583 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
584 self.__firsttime = False
584 self.__firsttime = False
585 self.x_buffer = x
585 self.x_buffer = x
586 self.y_buffer = y
586 self.y_buffer = y
587 return
587 return
588
588
589 self.x_buffer = numpy.hstack((self.x_buffer,x))
589 self.x_buffer = numpy.hstack((self.x_buffer,x))
590 self.y_buffer = numpy.hstack((self.y_buffer,y))
590 self.y_buffer = numpy.hstack((self.y_buffer,y))
591 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
591 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
592 ylabel=ylabel,
592 ylabel=ylabel,
593 title=title)
593 title=title)
594
594
595 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
595 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
596
596
597 deltas = x_buffer[1:] - x_buffer[0:-1]
597 deltas = x_buffer[1:] - x_buffer[0:-1]
598 x_median = numpy.median(deltas)
598 x_median = numpy.median(deltas)
599
599
600 index = numpy.where(deltas >= 2*x_median)
600 index = numpy.where(deltas >= 2*x_median)
601
601
602 if len(index[0]) != 0:
602 if len(index[0]) != 0:
603 z_buffer[index[0],::] = self.__missing
603 z_buffer[index[0],::] = self.__missing
604 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
604 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
605
605
606 return x_buffer, y_buffer, z_buffer
606 return x_buffer, y_buffer, z_buffer
607
607
608
608
609
609
610 No newline at end of file
610
@@ -1,1164 +1,1362
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4
4
5 from figure import Figure, isRealtime
5 from figure import Figure, isRealtime
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8 class MomentsPlot(Figure):
8 class MomentsPlot(Figure):
9
9
10 isConfig = None
10 isConfig = None
11 __nsubplots = None
11 __nsubplots = None
12
12
13 WIDTHPROF = None
13 WIDTHPROF = None
14 HEIGHTPROF = None
14 HEIGHTPROF = None
15 PREFIX = 'prm'
15 PREFIX = 'prm'
16
16
17 def __init__(self):
17 def __init__(self):
18
18
19 self.isConfig = False
19 self.isConfig = False
20 self.__nsubplots = 1
20 self.__nsubplots = 1
21
21
22 self.WIDTH = 280
22 self.WIDTH = 280
23 self.HEIGHT = 250
23 self.HEIGHT = 250
24 self.WIDTHPROF = 120
24 self.WIDTHPROF = 120
25 self.HEIGHTPROF = 0
25 self.HEIGHTPROF = 0
26 self.counter_imagwr = 0
26 self.counter_imagwr = 0
27
27
28 self.PLOT_CODE = MOMENTS_CODE
28 self.PLOT_CODE = MOMENTS_CODE
29
29
30 self.FTP_WEI = None
30 self.FTP_WEI = None
31 self.EXP_CODE = None
31 self.EXP_CODE = None
32 self.SUB_EXP_CODE = None
32 self.SUB_EXP_CODE = None
33 self.PLOT_POS = None
33 self.PLOT_POS = None
34
34
35 def getSubplots(self):
35 def getSubplots(self):
36
36
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
39
39
40 return nrow, ncol
40 return nrow, ncol
41
41
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43
43
44 self.__showprofile = showprofile
44 self.__showprofile = showprofile
45 self.nplots = nplots
45 self.nplots = nplots
46
46
47 ncolspan = 1
47 ncolspan = 1
48 colspan = 1
48 colspan = 1
49 if showprofile:
49 if showprofile:
50 ncolspan = 3
50 ncolspan = 3
51 colspan = 2
51 colspan = 2
52 self.__nsubplots = 2
52 self.__nsubplots = 2
53
53
54 self.createFigure(id = id,
54 self.createFigure(id = id,
55 wintitle = wintitle,
55 wintitle = wintitle,
56 widthplot = self.WIDTH + self.WIDTHPROF,
56 widthplot = self.WIDTH + self.WIDTHPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 show=show)
58 show=show)
59
59
60 nrow, ncol = self.getSubplots()
60 nrow, ncol = self.getSubplots()
61
61
62 counter = 0
62 counter = 0
63 for y in range(nrow):
63 for y in range(nrow):
64 for x in range(ncol):
64 for x in range(ncol):
65
65
66 if counter >= self.nplots:
66 if counter >= self.nplots:
67 break
67 break
68
68
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70
70
71 if showprofile:
71 if showprofile:
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73
73
74 counter += 1
74 counter += 1
75
75
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 server=None, folder=None, username=None, password=None,
79 server=None, folder=None, username=None, password=None,
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81
81
82 """
82 """
83
83
84 Input:
84 Input:
85 dataOut :
85 dataOut :
86 id :
86 id :
87 wintitle :
87 wintitle :
88 channelList :
88 channelList :
89 showProfile :
89 showProfile :
90 xmin : None,
90 xmin : None,
91 xmax : None,
91 xmax : None,
92 ymin : None,
92 ymin : None,
93 ymax : None,
93 ymax : None,
94 zmin : None,
94 zmin : None,
95 zmax : None
95 zmax : None
96 """
96 """
97
97
98 if dataOut.flagNoData:
98 if dataOut.flagNoData:
99 return None
99 return None
100
100
101 if realtime:
101 if realtime:
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 print 'Skipping this plot function'
103 print 'Skipping this plot function'
104 return
104 return
105
105
106 if channelList == None:
106 if channelList == None:
107 channelIndexList = dataOut.channelIndexList
107 channelIndexList = dataOut.channelIndexList
108 else:
108 else:
109 channelIndexList = []
109 channelIndexList = []
110 for channel in channelList:
110 for channel in channelList:
111 if channel not in dataOut.channelList:
111 if channel not in dataOut.channelList:
112 raise ValueError, "Channel %d is not in dataOut.channelList"
112 raise ValueError, "Channel %d is not in dataOut.channelList"
113 channelIndexList.append(dataOut.channelList.index(channel))
113 channelIndexList.append(dataOut.channelList.index(channel))
114
114
115 factor = dataOut.normFactor
115 factor = dataOut.normFactor
116 x = dataOut.abscissaList
116 x = dataOut.abscissaList
117 y = dataOut.heightList
117 y = dataOut.heightList
118
118
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
121 avg = numpy.average(z, axis=1)
121 avg = numpy.average(z, axis=1)
122 noise = dataOut.noise/factor
122 noise = dataOut.noise/factor
123
123
124 zdB = 10*numpy.log10(z)
124 zdB = 10*numpy.log10(z)
125 avgdB = 10*numpy.log10(avg)
125 avgdB = 10*numpy.log10(avg)
126 noisedB = 10*numpy.log10(noise)
126 noisedB = 10*numpy.log10(noise)
127
127
128 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 title = wintitle + " Parameters"
130 title = wintitle + " Parameters"
131 xlabel = "Velocity (m/s)"
131 xlabel = "Velocity (m/s)"
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 if not self.isConfig:
134 if not self.isConfig:
135
135
136 nplots = len(channelIndexList)
136 nplots = len(channelIndexList)
137
137
138 self.setup(id=id,
138 self.setup(id=id,
139 nplots=nplots,
139 nplots=nplots,
140 wintitle=wintitle,
140 wintitle=wintitle,
141 showprofile=showprofile,
141 showprofile=showprofile,
142 show=show)
142 show=show)
143
143
144 if xmin == None: xmin = numpy.nanmin(x)
144 if xmin == None: xmin = numpy.nanmin(x)
145 if xmax == None: xmax = numpy.nanmax(x)
145 if xmax == None: xmax = numpy.nanmax(x)
146 if ymin == None: ymin = numpy.nanmin(y)
146 if ymin == None: ymin = numpy.nanmin(y)
147 if ymax == None: ymax = numpy.nanmax(y)
147 if ymax == None: ymax = numpy.nanmax(y)
148 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
148 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
149 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
149 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
150
150
151 self.FTP_WEI = ftp_wei
151 self.FTP_WEI = ftp_wei
152 self.EXP_CODE = exp_code
152 self.EXP_CODE = exp_code
153 self.SUB_EXP_CODE = sub_exp_code
153 self.SUB_EXP_CODE = sub_exp_code
154 self.PLOT_POS = plot_pos
154 self.PLOT_POS = plot_pos
155
155
156 self.isConfig = True
156 self.isConfig = True
157
157
158 self.setWinTitle(title)
158 self.setWinTitle(title)
159
159
160 for i in range(self.nplots):
160 for i in range(self.nplots):
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
162 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
163 axes = self.axesList[i*self.__nsubplots]
163 axes = self.axesList[i*self.__nsubplots]
164 axes.pcolor(x, y, zdB[i,:,:],
164 axes.pcolor(x, y, zdB[i,:,:],
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xlabel=xlabel, ylabel=ylabel, title=title,
166 xlabel=xlabel, ylabel=ylabel, title=title,
167 ticksize=9, cblabel='')
167 ticksize=9, cblabel='')
168 #Mean Line
168 #Mean Line
169 mean = dataOut.data_param[i, 1, :]
169 mean = dataOut.data_param[i, 1, :]
170 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
170 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
171
171
172 if self.__showprofile:
172 if self.__showprofile:
173 axes = self.axesList[i*self.__nsubplots +1]
173 axes = self.axesList[i*self.__nsubplots +1]
174 axes.pline(avgdB[i], y,
174 axes.pline(avgdB[i], y,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 xlabel='dB', ylabel='', title='',
176 xlabel='dB', ylabel='', title='',
177 ytick_visible=False,
177 ytick_visible=False,
178 grid='x')
178 grid='x')
179
179
180 noiseline = numpy.repeat(noisedB[i], len(y))
180 noiseline = numpy.repeat(noisedB[i], len(y))
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182
182
183 self.draw()
183 self.draw()
184
184
185 self.save(figpath=figpath,
185 self.save(figpath=figpath,
186 figfile=figfile,
186 figfile=figfile,
187 save=save,
187 save=save,
188 ftp=ftp,
188 ftp=ftp,
189 wr_period=wr_period,
189 wr_period=wr_period,
190 thisDatetime=thisDatetime)
190 thisDatetime=thisDatetime)
191
191
192
192
193
193
194 class SkyMapPlot(Figure):
194 class SkyMapPlot(Figure):
195
195
196 __isConfig = None
196 __isConfig = None
197 __nsubplots = None
197 __nsubplots = None
198
198
199 WIDTHPROF = None
199 WIDTHPROF = None
200 HEIGHTPROF = None
200 HEIGHTPROF = None
201 PREFIX = 'prm'
201 PREFIX = 'mmap'
202
202
203 def __init__(self):
203 def __init__(self):
204
204
205 self.__isConfig = False
205 self.__isConfig = False
206 self.__nsubplots = 1
206 self.__nsubplots = 1
207
207
208 # self.WIDTH = 280
208 # self.WIDTH = 280
209 # self.HEIGHT = 250
209 # self.HEIGHT = 250
210 self.WIDTH = 600
210 self.WIDTH = 600
211 self.HEIGHT = 600
211 self.HEIGHT = 600
212 self.WIDTHPROF = 120
212 self.WIDTHPROF = 120
213 self.HEIGHTPROF = 0
213 self.HEIGHTPROF = 0
214 self.counter_imagwr = 0
214 self.counter_imagwr = 0
215
215
216 self.PLOT_CODE = SKYMAP_CODE
216 self.PLOT_CODE = MSKYMAP_CODE
217
217
218 self.FTP_WEI = None
218 self.FTP_WEI = None
219 self.EXP_CODE = None
219 self.EXP_CODE = None
220 self.SUB_EXP_CODE = None
220 self.SUB_EXP_CODE = None
221 self.PLOT_POS = None
221 self.PLOT_POS = None
222
222
223 def getSubplots(self):
223 def getSubplots(self):
224
224
225 ncol = int(numpy.sqrt(self.nplots)+0.9)
225 ncol = int(numpy.sqrt(self.nplots)+0.9)
226 nrow = int(self.nplots*1./ncol + 0.9)
226 nrow = int(self.nplots*1./ncol + 0.9)
227
227
228 return nrow, ncol
228 return nrow, ncol
229
229
230 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
230 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
231
231
232 self.__showprofile = showprofile
232 self.__showprofile = showprofile
233 self.nplots = nplots
233 self.nplots = nplots
234
234
235 ncolspan = 1
235 ncolspan = 1
236 colspan = 1
236 colspan = 1
237
237
238 self.createFigure(id = id,
238 self.createFigure(id = id,
239 wintitle = wintitle,
239 wintitle = wintitle,
240 widthplot = self.WIDTH, #+ self.WIDTHPROF,
240 widthplot = self.WIDTH, #+ self.WIDTHPROF,
241 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
241 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
242 show=show)
242 show=show)
243
243
244 nrow, ncol = 1,1
244 nrow, ncol = 1,1
245 counter = 0
245 counter = 0
246 x = 0
246 x = 0
247 y = 0
247 y = 0
248 self.addAxes(1, 1, 0, 0, 1, 1, True)
248 self.addAxes(1, 1, 0, 0, 1, 1, True)
249
249
250 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
250 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
251 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
251 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
252 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
252 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
253 server=None, folder=None, username=None, password=None,
253 server=None, folder=None, username=None, password=None,
254 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
254 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
255
255
256 """
256 """
257
257
258 Input:
258 Input:
259 dataOut :
259 dataOut :
260 id :
260 id :
261 wintitle :
261 wintitle :
262 channelList :
262 channelList :
263 showProfile :
263 showProfile :
264 xmin : None,
264 xmin : None,
265 xmax : None,
265 xmax : None,
266 ymin : None,
266 ymin : None,
267 ymax : None,
267 ymax : None,
268 zmin : None,
268 zmin : None,
269 zmax : None
269 zmax : None
270 """
270 """
271
271
272 arrayParameters = dataOut.data_param
272 arrayParameters = dataOut.data_param[0,:]
273 error = arrayParameters[:,-1]
273 error = arrayParameters[:,-1]
274 indValid = numpy.where(error == 0)[0]
274 indValid = numpy.where(error == 0)[0]
275 finalMeteor = arrayParameters[indValid,:]
275 finalMeteor = arrayParameters[indValid,:]
276 finalAzimuth = finalMeteor[:,4]
276 finalAzimuth = finalMeteor[:,4]
277 finalZenith = finalMeteor[:,5]
277 finalZenith = finalMeteor[:,5]
278
278
279 x = finalAzimuth*numpy.pi/180
279 x = finalAzimuth*numpy.pi/180
280 y = finalZenith
280 y = finalZenith
281
281
282
282
283 #thisDatetime = dataOut.datatime
283 #thisDatetime = dataOut.datatime
284 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
284 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
285 title = wintitle + " Parameters"
285 title = wintitle + " Parameters"
286 xlabel = "Zonal Zenith Angle (deg) "
286 xlabel = "Zonal Zenith Angle (deg) "
287 ylabel = "Meridional Zenith Angle (deg)"
287 ylabel = "Meridional Zenith Angle (deg)"
288
288
289 if not self.__isConfig:
289 if not self.__isConfig:
290
290
291 nplots = 1
291 nplots = 1
292
292
293 self.setup(id=id,
293 self.setup(id=id,
294 nplots=nplots,
294 nplots=nplots,
295 wintitle=wintitle,
295 wintitle=wintitle,
296 showprofile=showprofile,
296 showprofile=showprofile,
297 show=show)
297 show=show)
298
298
299 self.FTP_WEI = ftp_wei
299 self.FTP_WEI = ftp_wei
300 self.EXP_CODE = exp_code
300 self.EXP_CODE = exp_code
301 self.SUB_EXP_CODE = sub_exp_code
301 self.SUB_EXP_CODE = sub_exp_code
302 self.PLOT_POS = plot_pos
302 self.PLOT_POS = plot_pos
303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
304 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
304 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
305 self.__isConfig = True
305 self.__isConfig = True
306
306
307 self.setWinTitle(title)
307 self.setWinTitle(title)
308
308
309 i = 0
309 i = 0
310 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
310 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
311
311
312 axes = self.axesList[i*self.__nsubplots]
312 axes = self.axesList[i*self.__nsubplots]
313 nevents = axes.x_buffer.shape[0] + x.shape[0]
313 nevents = axes.x_buffer.shape[0] + x.shape[0]
314 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
314 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
315 axes.polar(x, y,
315 axes.polar(x, y,
316 title=title, xlabel=xlabel, ylabel=ylabel,
316 title=title, xlabel=xlabel, ylabel=ylabel,
317 ticksize=9, cblabel='')
317 ticksize=9, cblabel='')
318
318
319 self.draw()
319 self.draw()
320
320
321 self.save(figpath=figpath,
321 self.save(figpath=figpath,
322 figfile=figfile,
322 figfile=figfile,
323 save=save,
323 save=save,
324 ftp=ftp,
324 ftp=ftp,
325 wr_period=wr_period,
325 wr_period=wr_period,
326 thisDatetime=thisDatetime)
326 thisDatetime=thisDatetime)
327
327
328
328 class WindProfilerPlot(Figure):
329 class WindProfilerPlot(Figure):
329
330
330 __isConfig = None
331 __isConfig = None
331 __nsubplots = None
332 __nsubplots = None
332
333
333 WIDTHPROF = None
334 WIDTHPROF = None
334 HEIGHTPROF = None
335 HEIGHTPROF = None
335 PREFIX = 'wind'
336 PREFIX = 'wind'
336
337
337 def __init__(self):
338 def __init__(self):
338
339
339 self.timerange = 2*60*60
340 self.timerange = None
340 self.__isConfig = False
341 self.__isConfig = False
341 self.__nsubplots = 1
342 self.__nsubplots = 1
342
343
343 self.WIDTH = 800
344 self.WIDTH = 800
344 self.HEIGHT = 150
345 self.HEIGHT = 150
345 self.WIDTHPROF = 120
346 self.WIDTHPROF = 120
346 self.HEIGHTPROF = 0
347 self.HEIGHTPROF = 0
347 self.counter_imagwr = 0
348 self.counter_imagwr = 0
348
349
349 self.PLOT_CODE = WIND_CODE
350 self.PLOT_CODE = WIND_CODE
350
351
351 self.FTP_WEI = None
352 self.FTP_WEI = None
352 self.EXP_CODE = None
353 self.EXP_CODE = None
353 self.SUB_EXP_CODE = None
354 self.SUB_EXP_CODE = None
354 self.PLOT_POS = None
355 self.PLOT_POS = None
355 self.tmin = None
356 self.tmin = None
356 self.tmax = None
357 self.tmax = None
357
358
358 self.xmin = None
359 self.xmin = None
359 self.xmax = None
360 self.xmax = None
360
361
361 self.figfile = None
362 self.figfile = None
362
363
363 def getSubplots(self):
364 def getSubplots(self):
364
365
365 ncol = 1
366 ncol = 1
366 nrow = self.nplots
367 nrow = self.nplots
367
368
368 return nrow, ncol
369 return nrow, ncol
369
370
370 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
371 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
371
372
372 self.__showprofile = showprofile
373 self.__showprofile = showprofile
373 self.nplots = nplots
374 self.nplots = nplots
374
375
375 ncolspan = 1
376 ncolspan = 1
376 colspan = 1
377 colspan = 1
377
378
378 self.createFigure(id = id,
379 self.createFigure(id = id,
379 wintitle = wintitle,
380 wintitle = wintitle,
380 widthplot = self.WIDTH + self.WIDTHPROF,
381 widthplot = self.WIDTH + self.WIDTHPROF,
381 heightplot = self.HEIGHT + self.HEIGHTPROF,
382 heightplot = self.HEIGHT + self.HEIGHTPROF,
382 show=show)
383 show=show)
383
384
384 nrow, ncol = self.getSubplots()
385 nrow, ncol = self.getSubplots()
385
386
386 counter = 0
387 counter = 0
387 for y in range(nrow):
388 for y in range(nrow):
388 if counter >= self.nplots:
389 if counter >= self.nplots:
389 break
390 break
390
391
391 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
392 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
392 counter += 1
393 counter += 1
393
394
394 def run(self, dataOut, id, wintitle="", channelList=None,
395 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
395 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
396 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
396 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
397 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
397 timerange=None, SNRthresh = None,
398 timerange=None, SNRthresh = None,
398 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
399 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
399 server=None, folder=None, username=None, password=None,
400 server=None, folder=None, username=None, password=None,
400 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
401 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
401 """
402 """
402
403
403 Input:
404 Input:
404 dataOut :
405 dataOut :
405 id :
406 id :
406 wintitle :
407 wintitle :
407 channelList :
408 channelList :
408 showProfile :
409 showProfile :
409 xmin : None,
410 xmin : None,
410 xmax : None,
411 xmax : None,
411 ymin : None,
412 ymin : None,
412 ymax : None,
413 ymax : None,
413 zmin : None,
414 zmin : None,
414 zmax : None
415 zmax : None
415 """
416 """
416
417
417 if channelList == None:
418 if channelList == None:
418 channelIndexList = dataOut.channelIndexList
419 channelIndexList = dataOut.channelIndexList
419 else:
420 else:
420 channelIndexList = []
421 channelIndexList = []
421 for channel in channelList:
422 for channel in channelList:
422 if channel not in dataOut.channelList:
423 if channel not in dataOut.channelList:
423 raise ValueError, "Channel %d is not in dataOut.channelList"
424 raise ValueError, "Channel %d is not in dataOut.channelList"
424 channelIndexList.append(dataOut.channelList.index(channel))
425 channelIndexList.append(dataOut.channelList.index(channel))
425
426
426 if timerange != None:
427 # if timerange != None:
427 self.timerange = timerange
428 # self.timerange = timerange
428
429 #
429 tmin = None
430 # tmin = None
430 tmax = None
431 # tmax = None
431
432
432 x = dataOut.getTimeRange1()
433 x = dataOut.getTimeRange1()
433 # y = dataOut.heightList
434 # y = dataOut.heightList
434 y = dataOut.heightList
435 y = dataOut.heightList
435
436
436 z = dataOut.data_output.copy()
437 z = dataOut.data_output.copy()
437 nplots = z.shape[0] #Number of wind dimensions estimated
438 nplots = z.shape[0] #Number of wind dimensions estimated
438 nplotsw = nplots
439 nplotsw = nplots
439
440
440 #If there is a SNR function defined
441 #If there is a SNR function defined
441 if dataOut.data_SNR != None:
442 if dataOut.data_SNR != None:
442 nplots += 1
443 nplots += 1
443 SNR = dataOut.data_SNR
444 SNR = dataOut.data_SNR
444 SNRavg = numpy.average(SNR, axis=0)
445 SNRavg = numpy.average(SNR, axis=0)
445
446
446 SNRdB = 10*numpy.log10(SNR)
447 SNRdB = 10*numpy.log10(SNR)
447 SNRavgdB = 10*numpy.log10(SNRavg)
448 SNRavgdB = 10*numpy.log10(SNRavg)
448
449
449 if SNRthresh == None: SNRthresh = -5.0
450 if SNRthresh == None: SNRthresh = -5.0
450 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
451 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
451
452
452 for i in range(nplotsw):
453 for i in range(nplotsw):
453 z[i,ind] = numpy.nan
454 z[i,ind] = numpy.nan
454
455
455
456
456 showprofile = False
457 # showprofile = False
457 # thisDatetime = dataOut.datatime
458 # thisDatetime = dataOut.datatime
458 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
459 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
459 title = wintitle + "Wind"
460 title = wintitle + "Wind"
460 xlabel = ""
461 xlabel = ""
461 ylabel = "Range (Km)"
462 ylabel = "Range (Km)"
462
463
463 if not self.__isConfig:
464 if not self.__isConfig:
464
465
465 self.setup(id=id,
466 self.setup(id=id,
466 nplots=nplots,
467 nplots=nplots,
467 wintitle=wintitle,
468 wintitle=wintitle,
468 showprofile=showprofile,
469 showprofile=showprofile,
469 show=show)
470 show=show)
470
471
472 if timerange != None:
473 self.timerange = timerange
474
471 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
475 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
472
476
473 if ymin == None: ymin = numpy.nanmin(y)
477 if ymin == None: ymin = numpy.nanmin(y)
474 if ymax == None: ymax = numpy.nanmax(y)
478 if ymax == None: ymax = numpy.nanmax(y)
475
479
476 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
480 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
477 #if numpy.isnan(zmax): zmax = 50
481 #if numpy.isnan(zmax): zmax = 50
478 if zmin == None: zmin = -zmax
482 if zmin == None: zmin = -zmax
479
483
480 if nplotsw == 3:
484 if nplotsw == 3:
481 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
485 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
482 if zmin_ver == None: zmin_ver = -zmax_ver
486 if zmin_ver == None: zmin_ver = -zmax_ver
483
487
484 if dataOut.data_SNR != None:
488 if dataOut.data_SNR != None:
485 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
489 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
486 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
490 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
487
491
492
488 self.FTP_WEI = ftp_wei
493 self.FTP_WEI = ftp_wei
489 self.EXP_CODE = exp_code
494 self.EXP_CODE = exp_code
490 self.SUB_EXP_CODE = sub_exp_code
495 self.SUB_EXP_CODE = sub_exp_code
491 self.PLOT_POS = plot_pos
496 self.PLOT_POS = plot_pos
492
497
493 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
498 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
494 self.__isConfig = True
499 self.__isConfig = True
495
500 self.figfile = figfile
496
501
497 self.setWinTitle(title)
502 self.setWinTitle(title)
498
503
499 if ((self.xmax - x[1]) < (x[1]-x[0])):
504 if ((self.xmax - x[1]) < (x[1]-x[0])):
500 x[1] = self.xmax
505 x[1] = self.xmax
501
506
502 strWind = ['Zonal', 'Meridional', 'Vertical']
507 strWind = ['Zonal', 'Meridional', 'Vertical']
503 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
508 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
504 zmaxVector = [zmax, zmax, zmax_ver]
509 zmaxVector = [zmax, zmax, zmax_ver]
505 zminVector = [zmin, zmin, zmin_ver]
510 zminVector = [zmin, zmin, zmin_ver]
506 windFactor = [1,1,100]
511 windFactor = [1,1,100]
507
512
508 for i in range(nplotsw):
513 for i in range(nplotsw):
509
514
510 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
515 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
511 axes = self.axesList[i*self.__nsubplots]
516 axes = self.axesList[i*self.__nsubplots]
512
517
513 z1 = z[i,:].reshape((1,-1))*windFactor[i]
518 z1 = z[i,:].reshape((1,-1))*windFactor[i]
514
519
515 axes.pcolorbuffer(x, y, z1,
520 axes.pcolorbuffer(x, y, z1,
516 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
521 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
517 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
522 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
518 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
523 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
519
524
520 if dataOut.data_SNR != None:
525 if dataOut.data_SNR != None:
521 i += 1
526 i += 1
522 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
527 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
523 axes = self.axesList[i*self.__nsubplots]
528 axes = self.axesList[i*self.__nsubplots]
524
529
525 SNRavgdB = SNRavgdB.reshape((1,-1))
530 SNRavgdB = SNRavgdB.reshape((1,-1))
526
531
527 axes.pcolorbuffer(x, y, SNRavgdB,
532 axes.pcolorbuffer(x, y, SNRavgdB,
528 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
533 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
529 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
534 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
530 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
535 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
531
536
532 self.draw()
537 self.draw()
533
538
534 if x[1] >= self.axesList[0].xmax:
539 if x[1] >= self.axesList[0].xmax:
535 self.counter_imagwr = wr_period
540 self.counter_imagwr = wr_period
536 self.__isConfig = False
541 self.__isConfig = False
537 self.figfile = None
542 self.figfile = None
538
543
539 self.save(figpath=figpath,
544 self.save(figpath=figpath,
540 figfile=figfile,
545 figfile=figfile,
541 save=save,
546 save=save,
542 ftp=ftp,
547 ftp=ftp,
543 wr_period=wr_period,
548 wr_period=wr_period,
544 thisDatetime=thisDatetime,
549 thisDatetime=thisDatetime,
545 update_figfile=False)
550 update_figfile=False)
546
551
547
552
548 class ParametersPlot(Figure):
553 class ParametersPlot(Figure):
549
554
550 __isConfig = None
555 __isConfig = None
551 __nsubplots = None
556 __nsubplots = None
552
557
553 WIDTHPROF = None
558 WIDTHPROF = None
554 HEIGHTPROF = None
559 HEIGHTPROF = None
555 PREFIX = 'prm'
560 PREFIX = 'prm'
556
561
557 def __init__(self):
562 def __init__(self):
558
563
559 self.timerange = 2*60*60
564 self.timerange = 2*60*60
560 self.__isConfig = False
565 self.__isConfig = False
561 self.__nsubplots = 1
566 self.__nsubplots = 1
562
567
563 self.WIDTH = 800
568 self.WIDTH = 800
564 self.HEIGHT = 150
569 self.HEIGHT = 150
565 self.WIDTHPROF = 120
570 self.WIDTHPROF = 120
566 self.HEIGHTPROF = 0
571 self.HEIGHTPROF = 0
567 self.counter_imagwr = 0
572 self.counter_imagwr = 0
568
573
569 self.PLOT_CODE = PARMS_CODE
574 self.PLOT_CODE = PARMS_CODE
570
575
571 self.FTP_WEI = None
576 self.FTP_WEI = None
572 self.EXP_CODE = None
577 self.EXP_CODE = None
573 self.SUB_EXP_CODE = None
578 self.SUB_EXP_CODE = None
574 self.PLOT_POS = None
579 self.PLOT_POS = None
575 self.tmin = None
580 self.tmin = None
576 self.tmax = None
581 self.tmax = None
577
582
578 self.xmin = None
583 self.xmin = None
579 self.xmax = None
584 self.xmax = None
580
585
581 self.figfile = None
586 self.figfile = None
582
587
583 def getSubplots(self):
588 def getSubplots(self):
584
589
585 ncol = 1
590 ncol = 1
586 nrow = self.nplots
591 nrow = self.nplots
587
592
588 return nrow, ncol
593 return nrow, ncol
589
594
590 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
595 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
591
596
592 self.__showprofile = showprofile
597 self.__showprofile = showprofile
593 self.nplots = nplots
598 self.nplots = nplots
594
599
595 ncolspan = 1
600 ncolspan = 1
596 colspan = 1
601 colspan = 1
597
602
598 self.createFigure(id = id,
603 self.createFigure(id = id,
599 wintitle = wintitle,
604 wintitle = wintitle,
600 widthplot = self.WIDTH + self.WIDTHPROF,
605 widthplot = self.WIDTH + self.WIDTHPROF,
601 heightplot = self.HEIGHT + self.HEIGHTPROF,
606 heightplot = self.HEIGHT + self.HEIGHTPROF,
602 show=show)
607 show=show)
603
608
604 nrow, ncol = self.getSubplots()
609 nrow, ncol = self.getSubplots()
605
610
606 counter = 0
611 counter = 0
607 for y in range(nrow):
612 for y in range(nrow):
608 for x in range(ncol):
613 for x in range(ncol):
609
614
610 if counter >= self.nplots:
615 if counter >= self.nplots:
611 break
616 break
612
617
613 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
618 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
614
619
615 if showprofile:
620 if showprofile:
616 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
621 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
617
622
618 counter += 1
623 counter += 1
619
624
620 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
625 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
621 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
626 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
622 parameterIndex = None, onlyPositive = False,
627 parameterIndex = None, onlyPositive = False,
623 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None,
628 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
624 DOP = True,
629 DOP = True,
625 zlabel = "", parameterName = "", parameterObject = "data_param",
630 zlabel = "", parameterName = "", parameterObject = "data_param",
626 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
631 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
627 server=None, folder=None, username=None, password=None,
632 server=None, folder=None, username=None, password=None,
628 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
633 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
629
634
630 """
635 """
631
636
632 Input:
637 Input:
633 dataOut :
638 dataOut :
634 id :
639 id :
635 wintitle :
640 wintitle :
636 channelList :
641 channelList :
637 showProfile :
642 showProfile :
638 xmin : None,
643 xmin : None,
639 xmax : None,
644 xmax : None,
640 ymin : None,
645 ymin : None,
641 ymax : None,
646 ymax : None,
642 zmin : None,
647 zmin : None,
643 zmax : None
648 zmax : None
644 """
649 """
645
650
646 data_param = getattr(dataOut, parameterObject)
651 data_param = getattr(dataOut, parameterObject)
647
652
648 if channelList == None:
653 if channelList == None:
649 channelIndexList = numpy.arange(data_param.shape[0])
654 channelIndexList = numpy.arange(data_param.shape[0])
650 else:
655 else:
651 channelIndexList = numpy.array(channelList)
656 channelIndexList = numpy.array(channelList)
652
657
653 nchan = len(channelIndexList) #Number of channels being plotted
658 nchan = len(channelIndexList) #Number of channels being plotted
654
659
655 if nchan < 1:
660 if nchan < 1:
656 return
661 return
657
662
658 nGraphsByChannel = 0
663 nGraphsByChannel = 0
659
664
660 if SNR:
665 if SNR:
661 nGraphsByChannel += 1
666 nGraphsByChannel += 1
662 if DOP:
667 if DOP:
663 nGraphsByChannel += 1
668 nGraphsByChannel += 1
664
669
665 if nGraphsByChannel < 1:
670 if nGraphsByChannel < 1:
666 return
671 return
667
672
668 nplots = nGraphsByChannel*nchan
673 nplots = nGraphsByChannel*nchan
669
674
670 if timerange != None:
675 if timerange != None:
671 self.timerange = timerange
676 self.timerange = timerange
672
677
673 #tmin = None
678 #tmin = None
674 #tmax = None
679 #tmax = None
675 if parameterIndex == None:
680 if parameterIndex == None:
676 parameterIndex = 1
681 parameterIndex = 1
677
682
678 x = dataOut.getTimeRange1()
683 x = dataOut.getTimeRange1()
679 y = dataOut.heightList
684 y = dataOut.heightList
680 z = data_param[channelIndexList,parameterIndex,:].copy()
685 z = data_param[channelIndexList,parameterIndex,:].copy()
681
686
682 zRange = dataOut.abscissaList
687 zRange = dataOut.abscissaList
683 # nChannels = z.shape[0] #Number of wind dimensions estimated
688 # nChannels = z.shape[0] #Number of wind dimensions estimated
684 # thisDatetime = dataOut.datatime
689 # thisDatetime = dataOut.datatime
685
690
686 if dataOut.data_SNR != None:
691 if dataOut.data_SNR != None:
687 SNRarray = dataOut.data_SNR[channelIndexList,:]
692 SNRarray = dataOut.data_SNR[channelIndexList,:]
688 SNRdB = 10*numpy.log10(SNRarray)
693 SNRdB = 10*numpy.log10(SNRarray)
689 # SNRavgdB = 10*numpy.log10(SNRavg)
694 # SNRavgdB = 10*numpy.log10(SNRavg)
690 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
695 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
691 z[ind] = numpy.nan
696 z[ind] = numpy.nan
692
697
693 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
698 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
694 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
699 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
695 xlabel = ""
700 xlabel = ""
696 ylabel = "Range (Km)"
701 ylabel = "Range (Km)"
697
702
703 if (SNR and not onlySNR): nplots = 2*nplots
704
698 if onlyPositive:
705 if onlyPositive:
699 colormap = "jet"
706 colormap = "jet"
700 zmin = 0
707 zmin = 0
701 else: colormap = "RdBu_r"
708 else: colormap = "RdBu_r"
702
709
703 if not self.__isConfig:
710 if not self.__isConfig:
704
711
705 self.setup(id=id,
712 self.setup(id=id,
706 nplots=nplots,
713 nplots=nplots,
707 wintitle=wintitle,
714 wintitle=wintitle,
708 showprofile=showprofile,
715 showprofile=showprofile,
709 show=show)
716 show=show)
710
717
711 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
718 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
712
719
713 if ymin == None: ymin = numpy.nanmin(y)
720 if ymin == None: ymin = numpy.nanmin(y)
714 if ymax == None: ymax = numpy.nanmax(y)
721 if ymax == None: ymax = numpy.nanmax(y)
715 if zmin == None: zmin = numpy.nanmin(zRange)
722 if zmin == None: zmin = numpy.nanmin(zRange)
716 if zmax == None: zmax = numpy.nanmax(zRange)
723 if zmax == None: zmax = numpy.nanmax(zRange)
717
724
718 if SNR:
725 if SNR:
719 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
726 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
720 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
727 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
721
728
722 self.FTP_WEI = ftp_wei
729 self.FTP_WEI = ftp_wei
723 self.EXP_CODE = exp_code
730 self.EXP_CODE = exp_code
724 self.SUB_EXP_CODE = sub_exp_code
731 self.SUB_EXP_CODE = sub_exp_code
725 self.PLOT_POS = plot_pos
732 self.PLOT_POS = plot_pos
726
733
727 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
734 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
728 self.__isConfig = True
735 self.__isConfig = True
729 self.figfile = figfile
736 self.figfile = figfile
730
737
731 self.setWinTitle(title)
738 self.setWinTitle(title)
732
739
733 if ((self.xmax - x[1]) < (x[1]-x[0])):
740 if ((self.xmax - x[1]) < (x[1]-x[0])):
734 x[1] = self.xmax
741 x[1] = self.xmax
735
742
736 for i in range(nchan):
743 for i in range(nchan):
737
744
745 if (SNR and not onlySNR): j = 2*i
746 else: j = i
747
738 j = nGraphsByChannel*i
748 j = nGraphsByChannel*i
739
749
750 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
751 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
752
753 if not onlySNR:
754 axes = self.axesList[j*self.__nsubplots]
755 z1 = z[i,:].reshape((1,-1))
756 axes.pcolorbuffer(x, y, z1,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
759 ticksize=9, cblabel=zlabel, cbsize="1%")
760
740 if DOP:
761 if DOP:
741 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
762 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
742
763
743 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
764 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
744 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
765 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
745 axes = self.axesList[j]
766 axes = self.axesList[j]
746 z1 = z[i,:].reshape((1,-1))
767 z1 = z[i,:].reshape((1,-1))
747 axes.pcolorbuffer(x, y, z1,
768 axes.pcolorbuffer(x, y, z1,
748 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
769 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
749 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
770 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
750 ticksize=9, cblabel=zlabel, cbsize="1%")
771 ticksize=9, cblabel=zlabel, cbsize="1%")
751
772
752 if SNR:
773 if SNR:
753 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
774 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
775 axes = self.axesList[(j)*self.__nsubplots]
776 if not onlySNR:
777 axes = self.axesList[(j + 1)*self.__nsubplots]
778
754 axes = self.axesList[(j + nGraphsByChannel-1)]
779 axes = self.axesList[(j + nGraphsByChannel-1)]
780
755 z1 = SNRdB[i,:].reshape((1,-1))
781 z1 = SNRdB[i,:].reshape((1,-1))
756 axes.pcolorbuffer(x, y, z1,
782 axes.pcolorbuffer(x, y, z1,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
783 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
784 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
759 ticksize=9, cblabel=zlabel, cbsize="1%")
785 ticksize=9, cblabel=zlabel, cbsize="1%")
760
786
761
787
762
788
763 self.draw()
789 self.draw()
764
790
765 if x[1] >= self.axesList[0].xmax:
791 if x[1] >= self.axesList[0].xmax:
766 self.counter_imagwr = wr_period
792 self.counter_imagwr = wr_period
767 self.__isConfig = False
793 self.__isConfig = False
768 self.figfile = None
794 self.figfile = None
769
795
770 self.save(figpath=figpath,
796 self.save(figpath=figpath,
771 figfile=figfile,
797 figfile=figfile,
772 save=save,
798 save=save,
773 ftp=ftp,
799 ftp=ftp,
774 wr_period=wr_period,
800 wr_period=wr_period,
775 thisDatetime=thisDatetime,
801 thisDatetime=thisDatetime,
776 update_figfile=False)
802 update_figfile=False)
777
803
778 class SpectralFittingPlot(Figure):
804 class SpectralFittingPlot(Figure):
779
805
780 __isConfig = None
806 __isConfig = None
781 __nsubplots = None
807 __nsubplots = None
782
808
783 WIDTHPROF = None
809 WIDTHPROF = None
784 HEIGHTPROF = None
810 HEIGHTPROF = None
785 PREFIX = 'prm'
811 PREFIX = 'prm'
786
812
787
813
788 N = None
814 N = None
789 ippSeconds = None
815 ippSeconds = None
790
816
791 def __init__(self):
817 def __init__(self):
792 self.__isConfig = False
818 self.__isConfig = False
793 self.__nsubplots = 1
819 self.__nsubplots = 1
794
820
795 self.PLOT_CODE = SPECFIT_CODE
821 self.PLOT_CODE = SPECFIT_CODE
796
822
797 self.WIDTH = 450
823 self.WIDTH = 450
798 self.HEIGHT = 250
824 self.HEIGHT = 250
799 self.WIDTHPROF = 0
825 self.WIDTHPROF = 0
800 self.HEIGHTPROF = 0
826 self.HEIGHTPROF = 0
801
827
802 def getSubplots(self):
828 def getSubplots(self):
803
829
804 ncol = int(numpy.sqrt(self.nplots)+0.9)
830 ncol = int(numpy.sqrt(self.nplots)+0.9)
805 nrow = int(self.nplots*1./ncol + 0.9)
831 nrow = int(self.nplots*1./ncol + 0.9)
806
832
807 return nrow, ncol
833 return nrow, ncol
808
834
809 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
835 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
810
836
811 showprofile = False
837 showprofile = False
812 self.__showprofile = showprofile
838 self.__showprofile = showprofile
813 self.nplots = nplots
839 self.nplots = nplots
814
840
815 ncolspan = 5
841 ncolspan = 5
816 colspan = 4
842 colspan = 4
817 if showprofile:
843 if showprofile:
818 ncolspan = 5
844 ncolspan = 5
819 colspan = 4
845 colspan = 4
820 self.__nsubplots = 2
846 self.__nsubplots = 2
821
847
822 self.createFigure(id = id,
848 self.createFigure(id = id,
823 wintitle = wintitle,
849 wintitle = wintitle,
824 widthplot = self.WIDTH + self.WIDTHPROF,
850 widthplot = self.WIDTH + self.WIDTHPROF,
825 heightplot = self.HEIGHT + self.HEIGHTPROF,
851 heightplot = self.HEIGHT + self.HEIGHTPROF,
826 show=show)
852 show=show)
827
853
828 nrow, ncol = self.getSubplots()
854 nrow, ncol = self.getSubplots()
829
855
830 counter = 0
856 counter = 0
831 for y in range(nrow):
857 for y in range(nrow):
832 for x in range(ncol):
858 for x in range(ncol):
833
859
834 if counter >= self.nplots:
860 if counter >= self.nplots:
835 break
861 break
836
862
837 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
838
864
839 if showprofile:
865 if showprofile:
840 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
866 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
841
867
842 counter += 1
868 counter += 1
843
869
844 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
870 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
845 xmin=None, xmax=None, ymin=None, ymax=None,
871 xmin=None, xmax=None, ymin=None, ymax=None,
846 save=False, figpath='./', figfile=None, show=True):
872 save=False, figpath='./', figfile=None, show=True):
847
873
848 """
874 """
849
875
850 Input:
876 Input:
851 dataOut :
877 dataOut :
852 id :
878 id :
853 wintitle :
879 wintitle :
854 channelList :
880 channelList :
855 showProfile :
881 showProfile :
856 xmin : None,
882 xmin : None,
857 xmax : None,
883 xmax : None,
858 zmin : None,
884 zmin : None,
859 zmax : None
885 zmax : None
860 """
886 """
861
887
862 if cutHeight==None:
888 if cutHeight==None:
863 h=270
889 h=270
864 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
890 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
865 cutHeight = dataOut.heightList[heightindex]
891 cutHeight = dataOut.heightList[heightindex]
866
892
867 factor = dataOut.normFactor
893 factor = dataOut.normFactor
868 x = dataOut.abscissaList[:-1]
894 x = dataOut.abscissaList[:-1]
869 #y = dataOut.getHeiRange()
895 #y = dataOut.getHeiRange()
870
896
871 z = dataOut.data_pre[:,:,heightindex]/factor
897 z = dataOut.data_pre[:,:,heightindex]/factor
872 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
898 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
873 avg = numpy.average(z, axis=1)
899 avg = numpy.average(z, axis=1)
874 listChannels = z.shape[0]
900 listChannels = z.shape[0]
875
901
876 #Reconstruct Function
902 #Reconstruct Function
877 if fit==True:
903 if fit==True:
878 groupArray = dataOut.groupList
904 groupArray = dataOut.groupList
879 listChannels = groupArray.reshape((groupArray.size))
905 listChannels = groupArray.reshape((groupArray.size))
880 listChannels.sort()
906 listChannels.sort()
881 spcFitLine = numpy.zeros(z.shape)
907 spcFitLine = numpy.zeros(z.shape)
882 constants = dataOut.constants
908 constants = dataOut.constants
883
909
884 nGroups = groupArray.shape[0]
910 nGroups = groupArray.shape[0]
885 nChannels = groupArray.shape[1]
911 nChannels = groupArray.shape[1]
886 nProfiles = z.shape[1]
912 nProfiles = z.shape[1]
887
913
888 for f in range(nGroups):
914 for f in range(nGroups):
889 groupChann = groupArray[f,:]
915 groupChann = groupArray[f,:]
890 p = dataOut.data_param[f,:,heightindex]
916 p = dataOut.data_param[f,:,heightindex]
891 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
917 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
892 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
918 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
893 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
919 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
894 spcFitLine[groupChann,:] = fitLineAux
920 spcFitLine[groupChann,:] = fitLineAux
895 # spcFitLine = spcFitLine/factor
921 # spcFitLine = spcFitLine/factor
896
922
897 z = z[listChannels,:]
923 z = z[listChannels,:]
898 spcFitLine = spcFitLine[listChannels,:]
924 spcFitLine = spcFitLine[listChannels,:]
899 spcFitLinedB = 10*numpy.log10(spcFitLine)
925 spcFitLinedB = 10*numpy.log10(spcFitLine)
900
926
901 zdB = 10*numpy.log10(z)
927 zdB = 10*numpy.log10(z)
902 #thisDatetime = dataOut.datatime
928 #thisDatetime = dataOut.datatime
903 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
929 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
904 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
930 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
905 xlabel = "Velocity (m/s)"
931 xlabel = "Velocity (m/s)"
906 ylabel = "Spectrum"
932 ylabel = "Spectrum"
907
933
908 if not self.__isConfig:
934 if not self.__isConfig:
909
935
910 nplots = listChannels.size
936 nplots = listChannels.size
911
937
912 self.setup(id=id,
938 self.setup(id=id,
913 nplots=nplots,
939 nplots=nplots,
914 wintitle=wintitle,
940 wintitle=wintitle,
915 showprofile=showprofile,
941 showprofile=showprofile,
916 show=show)
942 show=show)
917
943
918 if xmin == None: xmin = numpy.nanmin(x)
944 if xmin == None: xmin = numpy.nanmin(x)
919 if xmax == None: xmax = numpy.nanmax(x)
945 if xmax == None: xmax = numpy.nanmax(x)
920 if ymin == None: ymin = numpy.nanmin(zdB)
946 if ymin == None: ymin = numpy.nanmin(zdB)
921 if ymax == None: ymax = numpy.nanmax(zdB)+2
947 if ymax == None: ymax = numpy.nanmax(zdB)+2
922
948
923 self.__isConfig = True
949 self.__isConfig = True
924
950
925 self.setWinTitle(title)
951 self.setWinTitle(title)
926 for i in range(self.nplots):
952 for i in range(self.nplots):
927 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
953 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
928 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
954 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
929 axes = self.axesList[i*self.__nsubplots]
955 axes = self.axesList[i*self.__nsubplots]
930 if fit == False:
956 if fit == False:
931 axes.pline(x, zdB[i,:],
957 axes.pline(x, zdB[i,:],
932 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
958 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
933 xlabel=xlabel, ylabel=ylabel, title=title
959 xlabel=xlabel, ylabel=ylabel, title=title
934 )
960 )
935 if fit == True:
961 if fit == True:
936 fitline=spcFitLinedB[i,:]
962 fitline=spcFitLinedB[i,:]
937 y=numpy.vstack([zdB[i,:],fitline] )
963 y=numpy.vstack([zdB[i,:],fitline] )
938 legendlabels=['Data','Fitting']
964 legendlabels=['Data','Fitting']
939 axes.pmultilineyaxis(x, y,
965 axes.pmultilineyaxis(x, y,
940 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
966 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
941 xlabel=xlabel, ylabel=ylabel, title=title,
967 xlabel=xlabel, ylabel=ylabel, title=title,
942 legendlabels=legendlabels, marker=None,
968 legendlabels=legendlabels, marker=None,
943 linestyle='solid', grid='both')
969 linestyle='solid', grid='both')
944
970
945 self.draw()
971 self.draw()
946
972
947 self.save(figpath=figpath,
973 self.save(figpath=figpath,
948 figfile=figfile,
974 figfile=figfile,
949 save=save,
975 save=save,
950 ftp=ftp,
976 ftp=ftp,
951 wr_period=wr_period,
977 wr_period=wr_period,
952 thisDatetime=thisDatetime)
978 thisDatetime=thisDatetime)
953
979
954
980
955 class EWDriftsPlot(Figure):
981 class EWDriftsPlot(Figure):
956
982
957 __isConfig = None
983 __isConfig = None
958 __nsubplots = None
984 __nsubplots = None
959
985
960 WIDTHPROF = None
986 WIDTHPROF = None
961 HEIGHTPROF = None
987 HEIGHTPROF = None
962 PREFIX = 'drift'
988 PREFIX = 'drift'
963
989
964 def __init__(self):
990 def __init__(self):
965
991
966 self.timerange = 2*60*60
992 self.timerange = 2*60*60
967 self.isConfig = False
993 self.isConfig = False
968 self.__nsubplots = 1
994 self.__nsubplots = 1
969
995
970 self.WIDTH = 800
996 self.WIDTH = 800
971 self.HEIGHT = 150
997 self.HEIGHT = 150
972 self.WIDTHPROF = 120
998 self.WIDTHPROF = 120
973 self.HEIGHTPROF = 0
999 self.HEIGHTPROF = 0
974 self.counter_imagwr = 0
1000 self.counter_imagwr = 0
975
1001
976 self.PLOT_CODE = EWDRIFT_CODE
1002 self.PLOT_CODE = EWDRIFT_CODE
977
1003
978 self.FTP_WEI = None
1004 self.FTP_WEI = None
979 self.EXP_CODE = None
1005 self.EXP_CODE = None
980 self.SUB_EXP_CODE = None
1006 self.SUB_EXP_CODE = None
981 self.PLOT_POS = None
1007 self.PLOT_POS = None
982 self.tmin = None
1008 self.tmin = None
983 self.tmax = None
1009 self.tmax = None
984
1010
985 self.xmin = None
1011 self.xmin = None
986 self.xmax = None
1012 self.xmax = None
987
1013
988 self.figfile = None
1014 self.figfile = None
989
1015
990 def getSubplots(self):
1016 def getSubplots(self):
991
1017
992 ncol = 1
1018 ncol = 1
993 nrow = self.nplots
1019 nrow = self.nplots
994
1020
995 return nrow, ncol
1021 return nrow, ncol
996
1022
997 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1023 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
998
1024
999 self.__showprofile = showprofile
1025 self.__showprofile = showprofile
1000 self.nplots = nplots
1026 self.nplots = nplots
1001
1027
1002 ncolspan = 1
1028 ncolspan = 1
1003 colspan = 1
1029 colspan = 1
1004
1030
1005 self.createFigure(id = id,
1031 self.createFigure(id = id,
1006 wintitle = wintitle,
1032 wintitle = wintitle,
1007 widthplot = self.WIDTH + self.WIDTHPROF,
1033 widthplot = self.WIDTH + self.WIDTHPROF,
1008 heightplot = self.HEIGHT + self.HEIGHTPROF,
1034 heightplot = self.HEIGHT + self.HEIGHTPROF,
1009 show=show)
1035 show=show)
1010
1036
1011 nrow, ncol = self.getSubplots()
1037 nrow, ncol = self.getSubplots()
1012
1038
1013 counter = 0
1039 counter = 0
1014 for y in range(nrow):
1040 for y in range(nrow):
1015 if counter >= self.nplots:
1041 if counter >= self.nplots:
1016 break
1042 break
1017
1043
1018 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1044 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1019 counter += 1
1045 counter += 1
1020
1046
1021 def run(self, dataOut, id, wintitle="", channelList=None,
1047 def run(self, dataOut, id, wintitle="", channelList=None,
1022 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1048 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1023 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1049 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1024 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1050 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1025 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1051 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1026 server=None, folder=None, username=None, password=None,
1052 server=None, folder=None, username=None, password=None,
1027 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1053 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1028 """
1054 """
1029
1055
1030 Input:
1056 Input:
1031 dataOut :
1057 dataOut :
1032 id :
1058 id :
1033 wintitle :
1059 wintitle :
1034 channelList :
1060 channelList :
1035 showProfile :
1061 showProfile :
1036 xmin : None,
1062 xmin : None,
1037 xmax : None,
1063 xmax : None,
1038 ymin : None,
1064 ymin : None,
1039 ymax : None,
1065 ymax : None,
1040 zmin : None,
1066 zmin : None,
1041 zmax : None
1067 zmax : None
1042 """
1068 """
1043
1069
1044 if timerange != None:
1070 if timerange != None:
1045 self.timerange = timerange
1071 self.timerange = timerange
1046
1072
1047 tmin = None
1073 tmin = None
1048 tmax = None
1074 tmax = None
1049
1075
1050 x = dataOut.getTimeRange1()
1076 x = dataOut.getTimeRange1()
1051 # y = dataOut.heightList
1077 # y = dataOut.heightList
1052 y = dataOut.heightList
1078 y = dataOut.heightList
1053
1079
1054 z = dataOut.data_output
1080 z = dataOut.data_output
1055 nplots = z.shape[0] #Number of wind dimensions estimated
1081 nplots = z.shape[0] #Number of wind dimensions estimated
1056 nplotsw = nplots
1082 nplotsw = nplots
1057
1083
1058 #If there is a SNR function defined
1084 #If there is a SNR function defined
1059 if dataOut.data_SNR != None:
1085 if dataOut.data_SNR != None:
1060 nplots += 1
1086 nplots += 1
1061 SNR = dataOut.data_SNR
1087 SNR = dataOut.data_SNR
1062
1088
1063 if SNR_1:
1089 if SNR_1:
1064 SNR += 1
1090 SNR += 1
1065
1091
1066 SNRavg = numpy.average(SNR, axis=0)
1092 SNRavg = numpy.average(SNR, axis=0)
1067
1093
1068 SNRdB = 10*numpy.log10(SNR)
1094 SNRdB = 10*numpy.log10(SNR)
1069 SNRavgdB = 10*numpy.log10(SNRavg)
1095 SNRavgdB = 10*numpy.log10(SNRavg)
1070
1096
1071 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1097 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1072
1098
1073 for i in range(nplotsw):
1099 for i in range(nplotsw):
1074 z[i,ind] = numpy.nan
1100 z[i,ind] = numpy.nan
1075
1101
1076
1102
1077 showprofile = False
1103 showprofile = False
1078 # thisDatetime = dataOut.datatime
1104 # thisDatetime = dataOut.datatime
1079 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1105 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1080 title = wintitle + " EW Drifts"
1106 title = wintitle + " EW Drifts"
1081 xlabel = ""
1107 xlabel = ""
1082 ylabel = "Height (Km)"
1108 ylabel = "Height (Km)"
1083
1109
1084 if not self.__isConfig:
1110 if not self.__isConfig:
1085
1111
1086 self.setup(id=id,
1112 self.setup(id=id,
1087 nplots=nplots,
1113 nplots=nplots,
1088 wintitle=wintitle,
1114 wintitle=wintitle,
1089 showprofile=showprofile,
1115 showprofile=showprofile,
1090 show=show)
1116 show=show)
1091
1117
1092 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1118 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1093
1119
1094 if ymin == None: ymin = numpy.nanmin(y)
1120 if ymin == None: ymin = numpy.nanmin(y)
1095 if ymax == None: ymax = numpy.nanmax(y)
1121 if ymax == None: ymax = numpy.nanmax(y)
1096
1122
1097 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1123 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1098 if zminZonal == None: zminZonal = -zmaxZonal
1124 if zminZonal == None: zminZonal = -zmaxZonal
1099 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1125 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1100 if zminVertical == None: zminVertical = -zmaxVertical
1126 if zminVertical == None: zminVertical = -zmaxVertical
1101
1127
1102 if dataOut.data_SNR != None:
1128 if dataOut.data_SNR != None:
1103 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1129 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1104 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1130 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1105
1131
1106 self.FTP_WEI = ftp_wei
1132 self.FTP_WEI = ftp_wei
1107 self.EXP_CODE = exp_code
1133 self.EXP_CODE = exp_code
1108 self.SUB_EXP_CODE = sub_exp_code
1134 self.SUB_EXP_CODE = sub_exp_code
1109 self.PLOT_POS = plot_pos
1135 self.PLOT_POS = plot_pos
1110
1136
1111 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1137 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1112 self.__isConfig = True
1138 self.__isConfig = True
1113
1139
1114
1140
1115 self.setWinTitle(title)
1141 self.setWinTitle(title)
1116
1142
1117 if ((self.xmax - x[1]) < (x[1]-x[0])):
1143 if ((self.xmax - x[1]) < (x[1]-x[0])):
1118 x[1] = self.xmax
1144 x[1] = self.xmax
1119
1145
1120 strWind = ['Zonal','Vertical']
1146 strWind = ['Zonal','Vertical']
1121 strCb = 'Velocity (m/s)'
1147 strCb = 'Velocity (m/s)'
1122 zmaxVector = [zmaxZonal, zmaxVertical]
1148 zmaxVector = [zmaxZonal, zmaxVertical]
1123 zminVector = [zminZonal, zminVertical]
1149 zminVector = [zminZonal, zminVertical]
1124
1150
1125 for i in range(nplotsw):
1151 for i in range(nplotsw):
1126
1152
1127 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1153 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1128 axes = self.axesList[i*self.__nsubplots]
1154 axes = self.axesList[i*self.__nsubplots]
1129
1155
1130 z1 = z[i,:].reshape((1,-1))
1156 z1 = z[i,:].reshape((1,-1))
1131
1157
1132 axes.pcolorbuffer(x, y, z1,
1158 axes.pcolorbuffer(x, y, z1,
1133 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1159 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1134 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1160 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1135 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1161 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1136
1162
1137 if dataOut.data_SNR != None:
1163 if dataOut.data_SNR != None:
1138 i += 1
1164 i += 1
1139 if SNR_1:
1165 if SNR_1:
1140 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1166 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1141 else:
1167 else:
1142 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1168 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1143 axes = self.axesList[i*self.__nsubplots]
1169 axes = self.axesList[i*self.__nsubplots]
1144 SNRavgdB = SNRavgdB.reshape((1,-1))
1170 SNRavgdB = SNRavgdB.reshape((1,-1))
1145
1171
1146 axes.pcolorbuffer(x, y, SNRavgdB,
1172 axes.pcolorbuffer(x, y, SNRavgdB,
1147 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1173 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1148 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1174 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1149 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1175 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1150
1176
1151 self.draw()
1177 self.draw()
1152
1178
1153 if x[1] >= self.axesList[0].xmax:
1179 if x[1] >= self.axesList[0].xmax:
1154 self.counter_imagwr = wr_period
1180 self.counter_imagwr = wr_period
1155 self.__isConfig = False
1181 self.__isConfig = False
1156 self.figfile = None
1182 self.figfile = None
1157
1183
1184
1185
1186
1187 class PhasePlot(Figure):
1188
1189 __isConfig = None
1190 __nsubplots = None
1191
1192 PREFIX = 'mphase'
1193
1194 def __init__(self):
1195
1196 self.timerange = 24*60*60
1197 self.__isConfig = False
1198 self.__nsubplots = 1
1199 self.counter_imagwr = 0
1200 self.WIDTH = 600
1201 self.HEIGHT = 300
1202 self.WIDTHPROF = 120
1203 self.HEIGHTPROF = 0
1204 self.xdata = None
1205 self.ydata = None
1206
1207 self.PLOT_CODE = MPHASE_CODE
1208
1209 self.FTP_WEI = None
1210 self.EXP_CODE = None
1211 self.SUB_EXP_CODE = None
1212 self.PLOT_POS = None
1213
1214
1215 self.filename_phase = None
1216
1217 self.figfile = None
1218
1219 def getSubplots(self):
1220
1221 ncol = 1
1222 nrow = 1
1223
1224 return nrow, ncol
1225
1226 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1227
1228 self.__showprofile = showprofile
1229 self.nplots = nplots
1230
1231 ncolspan = 7
1232 colspan = 6
1233 self.__nsubplots = 2
1234
1235 self.createFigure(id = id,
1236 wintitle = wintitle,
1237 widthplot = self.WIDTH+self.WIDTHPROF,
1238 heightplot = self.HEIGHT+self.HEIGHTPROF,
1239 show=show)
1240
1241 nrow, ncol = self.getSubplots()
1242
1243 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1244
1245
1246 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1247 xmin=None, xmax=None, ymin=None, ymax=None,
1248 timerange=None,
1249 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1250 server=None, folder=None, username=None, password=None,
1251 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1252
1253
1254 if timerange != None:
1255 self.timerange = timerange
1256
1257 tmin = None
1258 tmax = None
1259 x = dataOut.getTimeRange1()
1260 y = dataOut.getHeiRange()
1261
1262
1263 #thisDatetime = dataOut.datatime
1264 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1265 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1266 xlabel = "Local Time"
1267 ylabel = "Phase"
1268
1269
1270 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1271 phase_beacon = dataOut.data_output
1272
1273
1274 if not self.__isConfig:
1275
1276 self.nplots = phase_beacon.size
1277
1278 self.setup(id=id,
1279 nplots=self.nplots,
1280 wintitle=wintitle,
1281 showprofile=showprofile,
1282 show=show)
1283
1284 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1285 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1286 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1287
1288 self.FTP_WEI = ftp_wei
1289 self.EXP_CODE = exp_code
1290 self.SUB_EXP_CODE = sub_exp_code
1291 self.PLOT_POS = plot_pos
1292
1293 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1294 self.__isConfig = True
1295 self.figfile = figfile
1296 self.xdata = numpy.array([])
1297 self.ydata = numpy.array([])
1298
1299 #open file beacon phase
1300 path = '%s%03d' %(self.PREFIX, self.id)
1301 beacon_file = os.path.join(path,'%s.txt'%self.name)
1302 self.filename_phase = os.path.join(figpath,beacon_file)
1303 #self.save_phase(self.filename_phase)
1304
1305
1306 #store data beacon phase
1307 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1308
1309 self.setWinTitle(title)
1310
1311
1312 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1313
1314 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1315
1316 axes = self.axesList[0]
1317
1318 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1319
1320 if len(self.ydata)==0:
1321 self.ydata = phase_beacon.reshape(-1,1)
1322 else:
1323 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1324
1325
1326 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1327 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1328 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1329 XAxisAsTime=True, grid='both'
1330 )
1331
1332 self.draw()
1333
1334 if x[1] >= self.axesList[0].xmax:
1335 self.counter_imagwr = wr_period
1336 del self.xdata
1337 del self.ydata
1338 self.__isConfig = False
1339
1340 if self.figfile == None:
1341 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1342 self.figfile = self.getFilename(name = str_datetime)
1343
1344 if figpath != '':
1345 self.counter_imagwr += 1
1346 if (self.counter_imagwr>=wr_period):
1347 # store png plot to local folder
1348 self.saveFigure(figpath, self.figfile)
1349 # store png plot to FTP server according to RT-Web format
1350 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1351 ftp_filename = os.path.join(figpath, name)
1352 self.saveFigure(figpath, ftp_filename)
1353 self.counter_imagwr = 0
1354 self.figfile = None
1355
1158 self.save(figpath=figpath,
1356 self.save(figpath=figpath,
1159 figfile=figfile,
1357 figfile=figfile,
1160 save=save,
1358 save=save,
1161 ftp=ftp,
1359 ftp=ftp,
1162 wr_period=wr_period,
1360 wr_period=wr_period,
1163 thisDatetime=thisDatetime,
1361 thisDatetime=thisDatetime,
1164 update_figfile=False)
1362 update_figfile=False)
@@ -1,435 +1,437
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import sys
3 import sys
4 import matplotlib
4 import matplotlib
5
5
6 if 'linux' in sys.platform:
6 if 'linux' in sys.platform:
7 matplotlib.use("TKAgg")
7 matplotlib.use("TKAgg")
8
8
9 if 'darwin' in sys.platform:
9 if 'darwin' in sys.platform:
10 matplotlib.use("WXAgg")
10 matplotlib.use("WXAgg")
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 import matplotlib.pyplot
12 import matplotlib.pyplot
13
13
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 from matplotlib.ticker import *
15 from matplotlib.ticker import *
16
16
17 ###########################################
17 ###########################################
18 #Actualizacion de las funciones del driver
18 #Actualizacion de las funciones del driver
19 ###########################################
19 ###########################################
20
20
21 def createFigure(id, wintitle, width, height, facecolor="w", show=True):
21 def createFigure(id, wintitle, width, height, facecolor="w", show=True):
22
22
23 matplotlib.pyplot.ioff()
23 matplotlib.pyplot.ioff()
24 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor)
24 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor)
25 fig.canvas.manager.set_window_title(wintitle)
25 fig.canvas.manager.set_window_title(wintitle)
26 fig.canvas.manager.resize(width, height)
26 fig.canvas.manager.resize(width, height)
27 matplotlib.pyplot.ion()
27 matplotlib.pyplot.ion()
28 if show:
28 if show:
29 matplotlib.pyplot.show()
29 matplotlib.pyplot.show()
30
30
31 return fig
31 return fig
32
32
33 def closeFigure(show=False, fig=None):
33 def closeFigure(show=False, fig=None):
34
34
35 matplotlib.pyplot.ioff()
35 matplotlib.pyplot.ioff()
36 matplotlib.pyplot.pause(0.1)
36 matplotlib.pyplot.pause(0.1)
37
37
38 if show:
38 if show:
39 matplotlib.pyplot.show()
39 matplotlib.pyplot.show()
40
40
41 if fig != None:
41 if fig != None:
42 matplotlib.pyplot.close(fig)
42 matplotlib.pyplot.close(fig)
43 matplotlib.pyplot.pause(0.1)
43 matplotlib.pyplot.pause(0.1)
44 matplotlib.pyplot.ion()
44 matplotlib.pyplot.ion()
45 return
45 return
46
46
47 matplotlib.pyplot.close("all")
47 matplotlib.pyplot.close("all")
48 matplotlib.pyplot.pause(0.1)
48 matplotlib.pyplot.pause(0.1)
49 matplotlib.pyplot.ion()
49 matplotlib.pyplot.ion()
50 return
50 return
51
51
52 def saveFigure(fig, filename):
52 def saveFigure(fig, filename):
53
53
54 matplotlib.pyplot.ioff()
54 matplotlib.pyplot.ioff()
55 fig.savefig(filename)
55 fig.savefig(filename)
56 matplotlib.pyplot.ion()
56 matplotlib.pyplot.ion()
57
57
58 def setWinTitle(fig, title):
58 def setWinTitle(fig, title):
59
59
60 fig.canvas.manager.set_window_title(title)
60 fig.canvas.manager.set_window_title(title)
61
61
62 def setTitle(fig, title):
62 def setTitle(fig, title):
63
63
64 fig.suptitle(title)
64 fig.suptitle(title)
65
65
66 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
66 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
67
67
68 matplotlib.pyplot.ioff()
68 matplotlib.pyplot.ioff()
69 matplotlib.pyplot.figure(fig.number)
69 matplotlib.pyplot.figure(fig.number)
70 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
70 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
71 (xpos, ypos),
71 (xpos, ypos),
72 colspan=colspan,
72 colspan=colspan,
73 rowspan=rowspan,
73 rowspan=rowspan,
74 polar=polar)
74 polar=polar)
75
75
76 matplotlib.pyplot.ion()
76 matplotlib.pyplot.ion()
77 return axes
77 return axes
78
78
79 def setAxesText(ax, text):
79 def setAxesText(ax, text):
80
80
81 ax.annotate(text,
81 ax.annotate(text,
82 xy = (.1, .99),
82 xy = (.1, .99),
83 xycoords = 'figure fraction',
83 xycoords = 'figure fraction',
84 horizontalalignment = 'left',
84 horizontalalignment = 'left',
85 verticalalignment = 'top',
85 verticalalignment = 'top',
86 fontsize = 10)
86 fontsize = 10)
87
87
88 def printLabels(ax, xlabel, ylabel, title):
88 def printLabels(ax, xlabel, ylabel, title):
89
89
90 ax.set_xlabel(xlabel, size=11)
90 ax.set_xlabel(xlabel, size=11)
91 ax.set_ylabel(ylabel, size=11)
91 ax.set_ylabel(ylabel, size=11)
92 ax.set_title(title, size=8)
92 ax.set_title(title, size=8)
93
93
94 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
94 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
95 ticksize=9, xtick_visible=True, ytick_visible=True,
95 ticksize=9, xtick_visible=True, ytick_visible=True,
96 nxticks=4, nyticks=10,
96 nxticks=4, nyticks=10,
97 grid=None,color='blue'):
97 grid=None,color='blue'):
98
98
99 """
99 """
100
100
101 Input:
101 Input:
102 grid : None, 'both', 'x', 'y'
102 grid : None, 'both', 'x', 'y'
103 """
103 """
104
104
105 matplotlib.pyplot.ioff()
105 matplotlib.pyplot.ioff()
106
106
107 ax.set_xlim([xmin,xmax])
107 ax.set_xlim([xmin,xmax])
108 ax.set_ylim([ymin,ymax])
108 ax.set_ylim([ymin,ymax])
109
109
110 printLabels(ax, xlabel, ylabel, title)
110 printLabels(ax, xlabel, ylabel, title)
111
111
112 ######################################################
112 ######################################################
113 if (xmax-xmin)<=1:
113 if (xmax-xmin)<=1:
114 xtickspos = numpy.linspace(xmin,xmax,nxticks)
114 xtickspos = numpy.linspace(xmin,xmax,nxticks)
115 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
115 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
116 ax.set_xticks(xtickspos)
116 ax.set_xticks(xtickspos)
117 else:
117 else:
118 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
118 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
119 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
119 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
120 ax.set_xticks(xtickspos)
120 ax.set_xticks(xtickspos)
121
121
122 for tick in ax.get_xticklabels():
122 for tick in ax.get_xticklabels():
123 tick.set_visible(xtick_visible)
123 tick.set_visible(xtick_visible)
124
124
125 for tick in ax.xaxis.get_major_ticks():
125 for tick in ax.xaxis.get_major_ticks():
126 tick.label.set_fontsize(ticksize)
126 tick.label.set_fontsize(ticksize)
127
127
128 ######################################################
128 ######################################################
129 for tick in ax.get_yticklabels():
129 for tick in ax.get_yticklabels():
130 tick.set_visible(ytick_visible)
130 tick.set_visible(ytick_visible)
131
131
132 for tick in ax.yaxis.get_major_ticks():
132 for tick in ax.yaxis.get_major_ticks():
133 tick.label.set_fontsize(ticksize)
133 tick.label.set_fontsize(ticksize)
134
134
135 ax.plot(x, y, color=color)
135 ax.plot(x, y, color=color)
136 iplot = ax.lines[-1]
136 iplot = ax.lines[-1]
137
137
138 ######################################################
138 ######################################################
139 if '0.' in matplotlib.__version__[0:2]:
139 if '0.' in matplotlib.__version__[0:2]:
140 print "The matplotlib version has to be updated to 1.1 or newer"
140 print "The matplotlib version has to be updated to 1.1 or newer"
141 return iplot
141 return iplot
142
142
143 if '1.0.' in matplotlib.__version__[0:4]:
143 if '1.0.' in matplotlib.__version__[0:4]:
144 print "The matplotlib version has to be updated to 1.1 or newer"
144 print "The matplotlib version has to be updated to 1.1 or newer"
145 return iplot
145 return iplot
146
146
147 if grid != None:
147 if grid != None:
148 ax.grid(b=True, which='major', axis=grid)
148 ax.grid(b=True, which='major', axis=grid)
149
149
150 matplotlib.pyplot.tight_layout()
150 matplotlib.pyplot.tight_layout()
151
151
152 matplotlib.pyplot.ion()
152 matplotlib.pyplot.ion()
153
153
154 return iplot
154 return iplot
155
155
156 def set_linedata(ax, x, y, idline):
156 def set_linedata(ax, x, y, idline):
157
157
158 ax.lines[idline].set_data(x,y)
158 ax.lines[idline].set_data(x,y)
159
159
160 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
160 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
161
161
162 ax = iplot.get_axes()
162 ax = iplot.get_axes()
163
163
164 printLabels(ax, xlabel, ylabel, title)
164 printLabels(ax, xlabel, ylabel, title)
165
165
166 set_linedata(ax, x, y, idline=0)
166 set_linedata(ax, x, y, idline=0)
167
167
168 def addpline(ax, x, y, color, linestyle, lw):
168 def addpline(ax, x, y, color, linestyle, lw):
169
169
170 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
170 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
171
171
172
172
173 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
173 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
174 xlabel='', ylabel='', title='', ticksize = 9,
174 xlabel='', ylabel='', title='', ticksize = 9,
175 colormap='jet',cblabel='', cbsize="5%",
175 colormap='jet',cblabel='', cbsize="5%",
176 XAxisAsTime=False):
176 XAxisAsTime=False):
177
177
178 matplotlib.pyplot.ioff()
178 matplotlib.pyplot.ioff()
179
179
180 divider = make_axes_locatable(ax)
180 divider = make_axes_locatable(ax)
181 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
181 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
182 fig = ax.get_figure()
182 fig = ax.get_figure()
183 fig.add_axes(ax_cb)
183 fig.add_axes(ax_cb)
184
184
185 ax.set_xlim([xmin,xmax])
185 ax.set_xlim([xmin,xmax])
186 ax.set_ylim([ymin,ymax])
186 ax.set_ylim([ymin,ymax])
187
187
188 printLabels(ax, xlabel, ylabel, title)
188 printLabels(ax, xlabel, ylabel, title)
189
189
190 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
190 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
191 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
191 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
192 cb.set_label(cblabel)
192 cb.set_label(cblabel)
193
193
194 # for tl in ax_cb.get_yticklabels():
194 # for tl in ax_cb.get_yticklabels():
195 # tl.set_visible(True)
195 # tl.set_visible(True)
196
196
197 for tick in ax.yaxis.get_major_ticks():
197 for tick in ax.yaxis.get_major_ticks():
198 tick.label.set_fontsize(ticksize)
198 tick.label.set_fontsize(ticksize)
199
199
200 for tick in ax.xaxis.get_major_ticks():
200 for tick in ax.xaxis.get_major_ticks():
201 tick.label.set_fontsize(ticksize)
201 tick.label.set_fontsize(ticksize)
202
202
203 for tick in cb.ax.get_yticklabels():
203 for tick in cb.ax.get_yticklabels():
204 tick.set_fontsize(ticksize)
204 tick.set_fontsize(ticksize)
205
205
206 ax_cb.yaxis.tick_right()
206 ax_cb.yaxis.tick_right()
207
207
208 if '0.' in matplotlib.__version__[0:2]:
208 if '0.' in matplotlib.__version__[0:2]:
209 print "The matplotlib version has to be updated to 1.1 or newer"
209 print "The matplotlib version has to be updated to 1.1 or newer"
210 return imesh
210 return imesh
211
211
212 if '1.0.' in matplotlib.__version__[0:4]:
212 if '1.0.' in matplotlib.__version__[0:4]:
213 print "The matplotlib version has to be updated to 1.1 or newer"
213 print "The matplotlib version has to be updated to 1.1 or newer"
214 return imesh
214 return imesh
215
215
216 matplotlib.pyplot.tight_layout()
216 matplotlib.pyplot.tight_layout()
217
217
218 if XAxisAsTime:
218 if XAxisAsTime:
219
219
220 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
220 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
221 ax.xaxis.set_major_formatter(FuncFormatter(func))
221 ax.xaxis.set_major_formatter(FuncFormatter(func))
222 ax.xaxis.set_major_locator(LinearLocator(7))
222 ax.xaxis.set_major_locator(LinearLocator(7))
223
223
224 matplotlib.pyplot.ion()
224 matplotlib.pyplot.ion()
225 return imesh
225 return imesh
226
226
227 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
227 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
228
228
229 z = z.T
229 z = z.T
230 ax = imesh.get_axes()
230 ax = imesh.get_axes()
231 printLabels(ax, xlabel, ylabel, title)
231 printLabels(ax, xlabel, ylabel, title)
232 imesh.set_array(z.ravel())
232 imesh.set_array(z.ravel())
233
233
234 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
234 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
235
235
236 printLabels(ax, xlabel, ylabel, title)
236 printLabels(ax, xlabel, ylabel, title)
237
237
238 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
238 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
239
239
240 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
240 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
241
241
242 printLabels(ax, xlabel, ylabel, title)
242 printLabels(ax, xlabel, ylabel, title)
243
243
244 ax.collections.remove(ax.collections[0])
244 ax.collections.remove(ax.collections[0])
245
245
246 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
246 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
247
247
248 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
248 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
249 ticksize=9, xtick_visible=True, ytick_visible=True,
249 ticksize=9, xtick_visible=True, ytick_visible=True,
250 nxticks=4, nyticks=10,
250 nxticks=4, nyticks=10,
251 grid=None):
251 grid=None):
252
252
253 """
253 """
254
254
255 Input:
255 Input:
256 grid : None, 'both', 'x', 'y'
256 grid : None, 'both', 'x', 'y'
257 """
257 """
258
258
259 matplotlib.pyplot.ioff()
259 matplotlib.pyplot.ioff()
260
260
261 lines = ax.plot(x.T, y)
261 lines = ax.plot(x.T, y)
262 leg = ax.legend(lines, legendlabels, loc='upper right')
262 leg = ax.legend(lines, legendlabels, loc='upper right')
263 leg.get_frame().set_alpha(0.5)
263 leg.get_frame().set_alpha(0.5)
264 ax.set_xlim([xmin,xmax])
264 ax.set_xlim([xmin,xmax])
265 ax.set_ylim([ymin,ymax])
265 ax.set_ylim([ymin,ymax])
266 printLabels(ax, xlabel, ylabel, title)
266 printLabels(ax, xlabel, ylabel, title)
267
267
268 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
268 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
269 ax.set_xticks(xtickspos)
269 ax.set_xticks(xtickspos)
270
270
271 for tick in ax.get_xticklabels():
271 for tick in ax.get_xticklabels():
272 tick.set_visible(xtick_visible)
272 tick.set_visible(xtick_visible)
273
273
274 for tick in ax.xaxis.get_major_ticks():
274 for tick in ax.xaxis.get_major_ticks():
275 tick.label.set_fontsize(ticksize)
275 tick.label.set_fontsize(ticksize)
276
276
277 for tick in ax.get_yticklabels():
277 for tick in ax.get_yticklabels():
278 tick.set_visible(ytick_visible)
278 tick.set_visible(ytick_visible)
279
279
280 for tick in ax.yaxis.get_major_ticks():
280 for tick in ax.yaxis.get_major_ticks():
281 tick.label.set_fontsize(ticksize)
281 tick.label.set_fontsize(ticksize)
282
282
283 iplot = ax.lines[-1]
283 iplot = ax.lines[-1]
284
284
285 if '0.' in matplotlib.__version__[0:2]:
285 if '0.' in matplotlib.__version__[0:2]:
286 print "The matplotlib version has to be updated to 1.1 or newer"
286 print "The matplotlib version has to be updated to 1.1 or newer"
287 return iplot
287 return iplot
288
288
289 if '1.0.' in matplotlib.__version__[0:4]:
289 if '1.0.' in matplotlib.__version__[0:4]:
290 print "The matplotlib version has to be updated to 1.1 or newer"
290 print "The matplotlib version has to be updated to 1.1 or newer"
291 return iplot
291 return iplot
292
292
293 if grid != None:
293 if grid != None:
294 ax.grid(b=True, which='major', axis=grid)
294 ax.grid(b=True, which='major', axis=grid)
295
295
296 matplotlib.pyplot.tight_layout()
296 matplotlib.pyplot.tight_layout()
297
297
298 matplotlib.pyplot.ion()
298 matplotlib.pyplot.ion()
299
299
300 return iplot
300 return iplot
301
301
302
302
303 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
303 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
304
304
305 ax = iplot.get_axes()
305 ax = iplot.get_axes()
306
306
307 printLabels(ax, xlabel, ylabel, title)
307 printLabels(ax, xlabel, ylabel, title)
308
308
309 for i in range(len(ax.lines)):
309 for i in range(len(ax.lines)):
310 line = ax.lines[i]
310 line = ax.lines[i]
311 line.set_data(x[i,:],y)
311 line.set_data(x[i,:],y)
312
312
313 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
313 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
314 ticksize=9, xtick_visible=True, ytick_visible=True,
314 ticksize=9, xtick_visible=True, ytick_visible=True,
315 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
315 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
316 grid=None, XAxisAsTime=False):
316 grid=None, XAxisAsTime=False):
317
317
318 """
318 """
319
319
320 Input:
320 Input:
321 grid : None, 'both', 'x', 'y'
321 grid : None, 'both', 'x', 'y'
322 """
322 """
323
323
324 matplotlib.pyplot.ioff()
324 matplotlib.pyplot.ioff()
325
325
326 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
326 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
327 lines = ax.plot(x, y.T, linestyle=linestyle, marker=marker, markersize=markersize)
327 lines = ax.plot(x, y.T, linestyle=linestyle, marker=marker, markersize=markersize)
328 leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
328 leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
329 handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
329 handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
330
330
331 for label in leg.get_texts(): label.set_fontsize(9)
331 for label in leg.get_texts(): label.set_fontsize(9)
332
332
333 ax.set_xlim([xmin,xmax])
333 ax.set_xlim([xmin,xmax])
334 ax.set_ylim([ymin,ymax])
334 ax.set_ylim([ymin,ymax])
335 printLabels(ax, xlabel, ylabel, title)
335 printLabels(ax, xlabel, ylabel, title)
336
336
337 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
337 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
338 # ax.set_xticks(xtickspos)
338 # ax.set_xticks(xtickspos)
339
339
340 for tick in ax.get_xticklabels():
340 for tick in ax.get_xticklabels():
341 tick.set_visible(xtick_visible)
341 tick.set_visible(xtick_visible)
342
342
343 for tick in ax.xaxis.get_major_ticks():
343 for tick in ax.xaxis.get_major_ticks():
344 tick.label.set_fontsize(ticksize)
344 tick.label.set_fontsize(ticksize)
345
345
346 for tick in ax.get_yticklabels():
346 for tick in ax.get_yticklabels():
347 tick.set_visible(ytick_visible)
347 tick.set_visible(ytick_visible)
348
348
349 for tick in ax.yaxis.get_major_ticks():
349 for tick in ax.yaxis.get_major_ticks():
350 tick.label.set_fontsize(ticksize)
350 tick.label.set_fontsize(ticksize)
351
351
352 iplot = ax.lines[-1]
352 iplot = ax.lines[-1]
353
353
354 if '0.' in matplotlib.__version__[0:2]:
354 if '0.' in matplotlib.__version__[0:2]:
355 print "The matplotlib version has to be updated to 1.1 or newer"
355 print "The matplotlib version has to be updated to 1.1 or newer"
356 return iplot
356 return iplot
357
357
358 if '1.0.' in matplotlib.__version__[0:4]:
358 if '1.0.' in matplotlib.__version__[0:4]:
359 print "The matplotlib version has to be updated to 1.1 or newer"
359 print "The matplotlib version has to be updated to 1.1 or newer"
360 return iplot
360 return iplot
361
361
362 if grid != None:
362 if grid != None:
363 ax.grid(b=True, which='major', axis=grid)
363 ax.grid(b=True, which='major', axis=grid)
364
364
365 matplotlib.pyplot.tight_layout()
365 matplotlib.pyplot.tight_layout()
366
366
367 if XAxisAsTime:
367 if XAxisAsTime:
368
368
369 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
369 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
370 ax.xaxis.set_major_formatter(FuncFormatter(func))
370 ax.xaxis.set_major_formatter(FuncFormatter(func))
371 ax.xaxis.set_major_locator(LinearLocator(7))
371 ax.xaxis.set_major_locator(LinearLocator(7))
372
372
373 matplotlib.pyplot.ion()
373 matplotlib.pyplot.ion()
374
374
375 return iplot
375 return iplot
376
376
377 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
377 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
378
378
379 ax = iplot.get_axes()
379 ax = iplot.get_axes()
380
380
381 printLabels(ax, xlabel, ylabel, title)
381 printLabels(ax, xlabel, ylabel, title)
382
382
383 for i in range(len(ax.lines)):
383 for i in range(len(ax.lines)):
384 line = ax.lines[i]
384 line = ax.lines[i]
385 line.set_data(x,y[i,:])
385 line.set_data(x,y[i,:])
386
386
387 def createPolar(ax, x, y,
387 def createPolar(ax, x, y,
388 xlabel='', ylabel='', title='', ticksize = 9,
388 xlabel='', ylabel='', title='', ticksize = 9,
389 colormap='jet',cblabel='', cbsize="5%",
389 colormap='jet',cblabel='', cbsize="5%",
390 XAxisAsTime=False):
390 XAxisAsTime=False):
391
391
392 matplotlib.pyplot.ioff()
392 matplotlib.pyplot.ioff()
393
393
394 ax.plot(x,y,'bo', markersize=5)
394 ax.plot(x,y,'bo', markersize=5)
395 # ax.set_rmax(90)
395 # ax.set_rmax(90)
396 ax.set_ylim(0,90)
396 ax.set_ylim(0,90)
397 ax.set_yticks(numpy.arange(0,90,20))
397 ax.set_yticks(numpy.arange(0,90,20))
398 ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
398 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
399 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
399 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
400 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
400 printLabels(ax, xlabel, '', title)
401 ax.yaxis.labelpad = 230
402 printLabels(ax, xlabel, ylabel, title)
401 iplot = ax.lines[-1]
403 iplot = ax.lines[-1]
402
404
403 if '0.' in matplotlib.__version__[0:2]:
405 if '0.' in matplotlib.__version__[0:2]:
404 print "The matplotlib version has to be updated to 1.1 or newer"
406 print "The matplotlib version has to be updated to 1.1 or newer"
405 return iplot
407 return iplot
406
408
407 if '1.0.' in matplotlib.__version__[0:4]:
409 if '1.0.' in matplotlib.__version__[0:4]:
408 print "The matplotlib version has to be updated to 1.1 or newer"
410 print "The matplotlib version has to be updated to 1.1 or newer"
409 return iplot
411 return iplot
410
412
411 # if grid != None:
413 # if grid != None:
412 # ax.grid(b=True, which='major', axis=grid)
414 # ax.grid(b=True, which='major', axis=grid)
413
415
414 matplotlib.pyplot.tight_layout()
416 matplotlib.pyplot.tight_layout()
415
417
416 matplotlib.pyplot.ion()
418 matplotlib.pyplot.ion()
417
419
418
420
419 return iplot
421 return iplot
420
422
421 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
423 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
422
424
423 ax = iplot.get_axes()
425 ax = iplot.get_axes()
424
426
425 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
427 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
426 printLabels(ax, xlabel, '', title)
428 printLabels(ax, xlabel, ylabel, title)
427
429
428 set_linedata(ax, x, y, idline=0)
430 set_linedata(ax, x, y, idline=0)
429
431
430 def draw(fig):
432 def draw(fig):
431
433
432 if type(fig) == 'int':
434 if type(fig) == 'int':
433 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
435 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
434
436
435 fig.canvas.draw()
437 fig.canvas.draw()
@@ -1,27 +1,28
1 '''
1 '''
2 @author: roj-idl71
2 @author: roj-idl71
3 '''
3 '''
4 #USED IN jroplot_spectra.py
4 #USED IN jroplot_spectra.py
5 RTI_CODE = 0 #Range time intensity (RTI).
5 RTI_CODE = 0 #Range time intensity (RTI).
6 SPEC_CODE = 1 #Spectra (and Cross-spectra) information.
6 SPEC_CODE = 1 #Spectra (and Cross-spectra) information.
7 CROSS_CODE = 2 #Cross-Correlation information.
7 CROSS_CODE = 2 #Cross-Correlation information.
8 COH_CODE = 3 #Coherence map.
8 COH_CODE = 3 #Coherence map.
9 BASE_CODE = 4 #Base lines graphic.
9 BASE_CODE = 4 #Base lines graphic.
10 ROW_CODE = 5 #Row Spectra.
10 ROW_CODE = 5 #Row Spectra.
11 TOTAL_CODE = 6 #Total Power.
11 TOTAL_CODE = 6 #Total Power.
12 DRIFT_CODE = 7 #Drifts graphics.
12 DRIFT_CODE = 7 #Drifts graphics.
13 HEIGHT_CODE = 8 #Height profile.
13 HEIGHT_CODE = 8 #Height profile.
14 PHASE_CODE = 9 #Signal Phase.
14 PHASE_CODE = 9 #Signal Phase.
15
15
16 POWER_CODE = 16
16 POWER_CODE = 16
17 NOISE_CODE = 17
17 NOISE_CODE = 17
18 BEACON_CODE = 18
18 BEACON_CODE = 18
19
19
20 #USED IN jroplot_parameters.py
20 #USED IN jroplot_parameters.py
21
22 MOMENTS_CODE = 20
23 SKYMAP_CODE = 21
24 WIND_CODE = 22
21 WIND_CODE = 22
25 PARMS_CODE = 23
22 MSKYMAP_CODE = 23
26 SPECFIT_CODE = 24
23 MPHASE_CODE = 24
27 EWDRIFT_CODE = 25
24
25 MOMENTS_CODE = 25
26 PARMS_CODE = 26
27 SPECFIT_CODE = 27
28 EWDRIFT_CODE = 28
@@ -1,903 +1,1005
1 import numpy
1 import numpy
2 import time
2 import time
3 import os
3 import os
4 import h5py
4 import h5py
5 import re
5 import re
6 import tables
6
7
7 from schainpy.model.data.jrodata import *
8 from schainpy.model.data.jrodata import *
8 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.io.jroIO_base import *
10 from schainpy.model.io.jroIO_base import *
10
11
11
12
12 class HDF5Reader(ProcessingUnit):
13 class HDF5Reader(ProcessingUnit):
13
14
14 ext = ".hdf5"
15 ext = ".hdf5"
15
16
16 optchar = "D"
17 optchar = "D"
17
18
18 timezone = None
19 timezone = None
19
20
20 secStart = None
21 secStart = None
21
22
22 secEnd = None
23 secEnd = None
23
24
24 fileIndex = None
25 fileIndex = None
25
26
26 blockIndex = None
27 blockIndex = None
27
28
28 blocksPerFile = None
29 blocksPerFile = None
29
30
30 path = None
31 path = None
31
32
32 #List of Files
33 #List of Files
33
34
34 filenameList = None
35 filenameList = None
35
36
36 datetimeList = None
37 datetimeList = None
37
38
38 #Hdf5 File
39 #Hdf5 File
39
40
40 fpMetadata = None
41 fpMetadata = None
41
42
42 pathMeta = None
43 pathMeta = None
43
44
44 listMetaname = None
45 listMetaname = None
45
46
46 listMeta = None
47 listMeta = None
47
48
48 listDataname = None
49 listDataname = None
49
50
50 listData = None
51 listData = None
51
52
52 listShapes = None
53 listShapes = None
53
54
54 fp = None
55 fp = None
55
56
56 #dataOut reconstruction
57 #dataOut reconstruction
57
58
58 dataOut = None
59 dataOut = None
59
60
60 nRecords = None
61 nRecords = None
61
62
62
63
63 def __init__(self):
64 def __init__(self):
64 self.dataOut = self.__createObjByDefault()
65 self.dataOut = self.__createObjByDefault()
65 return
66 return
66
67
67 def __createObjByDefault(self):
68 def __createObjByDefault(self):
68
69
69 dataObj = Parameters()
70 dataObj = Parameters()
70
71
71 return dataObj
72 return dataObj
72
73
73 def setup(self,path=None,
74 def setup(self,path=None,
74 startDate=None,
75 startDate=None,
75 endDate=None,
76 endDate=None,
76 startTime=datetime.time(0,0,0),
77 startTime=datetime.time(0,0,0),
77 endTime=datetime.time(23,59,59),
78 endTime=datetime.time(23,59,59),
78 walk=True,
79 walk=True,
79 timezone='ut',
80 timezone='ut',
80 all=0,
81 all=0,
81 online=False,
82 online=False,
82 ext=None):
83 ext=None):
83
84
84 if ext==None:
85 if ext==None:
85 ext = self.ext
86 ext = self.ext
86 self.timezone = timezone
87 self.timezone = timezone
87 # self.all = all
88 # self.all = all
88 # self.online = online
89 # self.online = online
89 self.path = path
90 self.path = path
90
91
91 startDateTime = datetime.datetime.combine(startDate,startTime)
92 startDateTime = datetime.datetime.combine(startDate,startTime)
92 endDateTime = datetime.datetime.combine(endDate,endTime)
93 endDateTime = datetime.datetime.combine(endDate,endTime)
93 secStart = (startDateTime-datetime.datetime(1970,1,1)).total_seconds()
94 secStart = (startDateTime-datetime.datetime(1970,1,1)).total_seconds()
94 secEnd = (endDateTime-datetime.datetime(1970,1,1)).total_seconds()
95 secEnd = (endDateTime-datetime.datetime(1970,1,1)).total_seconds()
95
96
96 self.secStart = secStart
97 self.secStart = secStart
97 self.secEnd = secEnd
98 self.secEnd = secEnd
98
99
99 if not(online):
100 if not(online):
100 #Busqueda de archivos offline
101 #Busqueda de archivos offline
101 self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, secStart, secEnd, walk)
102 self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, secStart, secEnd, walk)
102 else:
103 else:
103 self.__searchFilesOnline(path, walk)
104 self.__searchFilesOnline(path, walk)
104
105
105 if not(self.filenameList):
106 if not(self.filenameList):
106 print "There is no files into the folder: %s"%(path)
107 print "There is no files into the folder: %s"%(path)
107 sys.exit(-1)
108 sys.exit(-1)
108
109
109 # self.__getExpParameters()
110 # self.__getExpParameters()
110
111
111 self.fileIndex = -1
112 self.fileIndex = -1
112
113
113 self.__setNextFileOffline()
114 self.__setNextFileOffline()
114
115
115 self.__readMetadata()
116 self.__readMetadata()
116
117
117 self.blockIndex = 0
118 self.blockIndex = 0
118
119
119 return
120 return
120
121
121 def __searchFilesOffline(self,
122 def __searchFilesOffline(self,
122 path,
123 path,
123 startDate,
124 startDate,
124 endDate,
125 endDate,
125 ext,
126 ext,
126 startTime=datetime.time(0,0,0),
127 startTime=datetime.time(0,0,0),
127 endTime=datetime.time(23,59,59),
128 endTime=datetime.time(23,59,59),
128 secStart = 0,
129 secStart = 0,
129 secEnd = numpy.inf,
130 secEnd = numpy.inf,
130 walk=True):
131 walk=True):
131
132
132 # self.__setParameters(path, startDate, endDate, startTime, endTime, walk)
133 # self.__setParameters(path, startDate, endDate, startTime, endTime, walk)
133 #
134 #
134 # self.__checkPath()
135 # self.__checkPath()
135 #
136 #
136 # self.__findDataForDates()
137 # self.__findDataForDates()
137 #
138 #
138 # self.__selectDataForTimes()
139 # self.__selectDataForTimes()
139 #
140 #
140 # for i in range(len(self.filenameList)):
141 # for i in range(len(self.filenameList)):
141 # print "%s" %(self.filenameList[i])
142 # print "%s" %(self.filenameList[i])
142
143
143 pathList = []
144 pathList = []
144
145
145 if not walk:
146 if not walk:
146 #pathList.append(path)
147 #pathList.append(path)
147 multi_path = path.split(',')
148 multi_path = path.split(',')
148 for single_path in multi_path:
149 for single_path in multi_path:
149 pathList.append(single_path)
150 pathList.append(single_path)
150
151
151 else:
152 else:
152 #dirList = []
153 #dirList = []
153 multi_path = path.split(',')
154 multi_path = path.split(',')
154 for single_path in multi_path:
155 for single_path in multi_path:
155 dirList = []
156 dirList = []
156 for thisPath in os.listdir(single_path):
157 for thisPath in os.listdir(single_path):
157 if not os.path.isdir(os.path.join(single_path,thisPath)):
158 if not os.path.isdir(os.path.join(single_path,thisPath)):
158 continue
159 continue
159 if not isRadarFolder(thisPath):
160 if not isDoyFolder(thisPath):
160 continue
161 continue
161
162
162 dirList.append(thisPath)
163 dirList.append(thisPath)
163
164
164 if not(dirList):
165 if not(dirList):
165 return None, None
166 return None, None
166
167
167 thisDate = startDate
168 thisDate = startDate
168
169
169 while(thisDate <= endDate):
170 while(thisDate <= endDate):
170 year = thisDate.timetuple().tm_year
171 year = thisDate.timetuple().tm_year
171 doy = thisDate.timetuple().tm_yday
172 doy = thisDate.timetuple().tm_yday
172
173
173 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
174 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
174 if len(matchlist) == 0:
175 if len(matchlist) == 0:
175 thisDate += datetime.timedelta(1)
176 thisDate += datetime.timedelta(1)
176 continue
177 continue
177 for match in matchlist:
178 for match in matchlist:
178 pathList.append(os.path.join(single_path,match))
179 pathList.append(os.path.join(single_path,match))
179
180
180 thisDate += datetime.timedelta(1)
181 thisDate += datetime.timedelta(1)
181
182
182 if pathList == []:
183 if pathList == []:
183 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
184 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
184 return None, None
185 return None, None
185
186
186 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
187 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
187
188
188 filenameList = []
189 filenameList = []
189 datetimeList = []
190 datetimeList = []
190 pathDict = {}
191 pathDict = {}
191 filenameList_to_sort = []
192 filenameList_to_sort = []
192
193
193 for i in range(len(pathList)):
194 for i in range(len(pathList)):
194
195
195 thisPath = pathList[i]
196 thisPath = pathList[i]
196
197
197 fileList = glob.glob1(thisPath, "*%s" %ext)
198 fileList = glob.glob1(thisPath, "*%s" %ext)
198 fileList.sort()
199 fileList.sort()
199 pathDict.setdefault(fileList[0])
200 pathDict.setdefault(fileList[0])
200 pathDict[fileList[0]] = i
201 pathDict[fileList[0]] = i
201 filenameList_to_sort.append(fileList[0])
202 filenameList_to_sort.append(fileList[0])
202
203
203 filenameList_to_sort.sort()
204 filenameList_to_sort.sort()
204
205
205 for file in filenameList_to_sort:
206 for file in filenameList_to_sort:
206 thisPath = pathList[pathDict[file]]
207 thisPath = pathList[pathDict[file]]
207
208
208 fileList = glob.glob1(thisPath, "*%s" %ext)
209 fileList = glob.glob1(thisPath, "*%s" %ext)
209 fileList.sort()
210 fileList.sort()
210
211
211 for file in fileList:
212 for file in fileList:
212
213
213 filename = os.path.join(thisPath,file)
214 filename = os.path.join(thisPath,file)
214 thisDatetime = self.__isFileinThisTime(filename, secStart, secEnd)
215 thisDatetime = self.__isFileinThisTime(filename, secStart, secEnd)
215
216
216 if not(thisDatetime):
217 if not(thisDatetime):
217 continue
218 continue
218
219
219 filenameList.append(filename)
220 filenameList.append(filename)
220 datetimeList.append(thisDatetime)
221 datetimeList.append(thisDatetime)
221
222
222 if not(filenameList):
223 if not(filenameList):
223 print "Any file was found for the time range %s - %s" %(startTime, endTime)
224 print "Any file was found for the time range %s - %s" %(startTime, endTime)
224 return None, None
225 return None, None
225
226
226 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
227 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
227 print
228 print
228
229
229 for i in range(len(filenameList)):
230 for i in range(len(filenameList)):
230 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
231 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
231
232
232 self.filenameList = filenameList
233 self.filenameList = filenameList
233 self.datetimeList = datetimeList
234 self.datetimeList = datetimeList
234
235
235 return pathList, filenameList
236 return pathList, filenameList
236
237
237 def __isFileinThisTime(self, filename, startSeconds, endSeconds):
238 def __isFileinThisTime(self, filename, startSeconds, endSeconds):
238 """
239 """
239 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
240 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
240
241
241 Inputs:
242 Inputs:
242 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
243 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
243
244
244 startTime : tiempo inicial del rango seleccionado en formato datetime.time
245 startTime : tiempo inicial del rango seleccionado en formato datetime.time
245
246
246 endTime : tiempo final del rango seleccionado en formato datetime.time
247 endTime : tiempo final del rango seleccionado en formato datetime.time
247
248
248 Return:
249 Return:
249 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
250 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
250 fecha especificado, de lo contrario retorna False.
251 fecha especificado, de lo contrario retorna False.
251
252
252 Excepciones:
253 Excepciones:
253 Si el archivo no existe o no puede ser abierto
254 Si el archivo no existe o no puede ser abierto
254 Si la cabecera no puede ser leida.
255 Si la cabecera no puede ser leida.
255
256
256 """
257 """
257
258
258 try:
259 try:
259 fp = fp = h5py.File(filename,'r')
260 fp = fp = h5py.File(filename,'r')
260 except IOError:
261 except IOError:
261 traceback.print_exc()
262 traceback.print_exc()
262 raise IOError, "The file %s can't be opened" %(filename)
263 raise IOError, "The file %s can't be opened" %(filename)
263
264
264 grp = fp['Data']
265 grp = fp['Data']
265 timeAux = grp['time']
266 timeAux = grp['time']
266 time0 = timeAux[:][0].astype(numpy.float) #Time Vector
267 time0 = timeAux[:][0].astype(numpy.float) #Time Vector
267
268
268 fp.close()
269 fp.close()
269
270
270 if self.timezone == 'lt':
271 if self.timezone == 'lt':
271 time0 -= 5*3600
272 time0 -= 5*3600
272
273
273 boolTimer = numpy.logical_and(time0 >= startSeconds,time0 < endSeconds)
274 boolTimer = numpy.logical_and(time0 >= startSeconds,time0 < endSeconds)
274
275
275 if not (numpy.any(boolTimer)):
276 if not (numpy.any(boolTimer)):
276 return None
277 return None
277
278
278 thisDatetime = datetime.datetime.utcfromtimestamp(time0[0])
279 thisDatetime = datetime.datetime.utcfromtimestamp(time0[0])
279 return thisDatetime
280 return thisDatetime
280
281
281 def __checkPath(self):
282 def __checkPath(self):
282 if os.path.exists(self.path):
283 if os.path.exists(self.path):
283 self.status = 1
284 self.status = 1
284 else:
285 else:
285 self.status = 0
286 self.status = 0
286 print 'Path:%s does not exists'%self.path
287 print 'Path:%s does not exists'%self.path
287
288
288 return
289 return
289
290
290 def __setNextFileOffline(self):
291 def __setNextFileOffline(self):
291 idFile = self.fileIndex
292 idFile = self.fileIndex
292 idFile += 1
293 idFile += 1
293
294
294 if not(idFile < len(self.filenameList)):
295 if not(idFile < len(self.filenameList)):
295 print "No more Files"
296 print "No more Files"
296 return 0
297 return 0
297
298
298 filename = self.filenameList[idFile]
299 filename = self.filenameList[idFile]
299
300
300 filePointer = h5py.File(filename,'r')
301 filePointer = h5py.File(filename,'r')
301
302
302 self.flagIsNewFile = 1
303 self.flagIsNewFile = 1
303 self.fileIndex = idFile
304 self.fileIndex = idFile
304 self.filename = filename
305 self.filename = filename
305
306
306 self.fp = filePointer
307 self.fp = filePointer
307
308
308 print "Setting the file: %s"%self.filename
309 print "Setting the file: %s"%self.filename
309
310
310 self.__readMetadata()
311 self.__readMetadata()
311 self.__setBlockList()
312 self.__setBlockList()
312 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
313 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
313 self.nRecords = self.fp['Data'].attrs['nRecords']
314 self.nRecords = self.fp['Data'].attrs['nRecords']
314 self.blockIndex = 0
315 self.blockIndex = 0
315 return 1
316 return 1
316
317
317 def __setBlockList(self):
318 def __setBlockList(self):
318 '''
319 '''
319 self.fp
320 self.fp
320 self.startDateTime
321 self.startDateTime
321 self.endDateTime
322 self.endDateTime
322
323
323 self.blockList
324 self.blockList
324 self.blocksPerFile
325 self.blocksPerFile
325
326
326 '''
327 '''
327 filePointer = self.fp
328 filePointer = self.fp
328 secStart = self.secStart
329 secStart = self.secStart
329 secEnd = self.secEnd
330 secEnd = self.secEnd
330
331
331 grp = filePointer['Data']
332 grp = filePointer['Data']
332 timeVector = grp['time'].value.astype(numpy.float)[0]
333 timeVector = grp['time'].value.astype(numpy.float)[0]
333
334
334 if self.timezone == 'lt':
335 if self.timezone == 'lt':
335 timeVector -= 5*3600
336 timeVector -= 5*3600
336
337
337 ind = numpy.where(numpy.logical_and(timeVector >= secStart , timeVector < secEnd))[0]
338 ind = numpy.where(numpy.logical_and(timeVector >= secStart , timeVector < secEnd))[0]
338
339
339 self.blockList = ind
340 self.blockList = ind
340 self.blocksPerFile = len(ind)
341 self.blocksPerFile = len(ind)
341
342
342 return
343 return
343
344
344 def __readMetadata(self):
345 def __readMetadata(self):
345 '''
346 '''
346 self.pathMeta
347 self.pathMeta
347
348
348 self.listShapes
349 self.listShapes
349 self.listMetaname
350 self.listMetaname
350 self.listMeta
351 self.listMeta
351
352
352 '''
353 '''
353
354
354 grp = self.fp['Data']
355 grp = self.fp['Data']
355 pathMeta = os.path.join(self.path, grp.attrs['metadata'])
356 pathMeta = os.path.join(self.path, grp.attrs['metadata'])
356
357
357 if pathMeta == self.pathMeta:
358 if pathMeta == self.pathMeta:
358 return
359 return
359 else:
360 else:
360 self.pathMeta = pathMeta
361 self.pathMeta = pathMeta
361
362
362 filePointer = h5py.File(self.pathMeta,'r')
363 filePointer = h5py.File(self.pathMeta,'r')
363 groupPointer = filePointer['Metadata']
364 groupPointer = filePointer['Metadata']
364
365
365 listMetaname = []
366 listMetaname = []
366 listMetadata = []
367 listMetadata = []
367 for item in groupPointer.items():
368 for item in groupPointer.items():
368 name = item[0]
369 name = item[0]
369
370
370 if name=='array dimensions':
371 if name=='array dimensions':
371 table = groupPointer[name][:]
372 table = groupPointer[name][:]
372 listShapes = {}
373 listShapes = {}
373 for shapes in table:
374 for shapes in table:
374 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4]])
375 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4]])
375 else:
376 else:
376 data = groupPointer[name].value
377 data = groupPointer[name].value
377 listMetaname.append(name)
378 listMetaname.append(name)
378 listMetadata.append(data)
379 listMetadata.append(data)
379
380
380 if name=='type':
381 if name=='type':
381 self.__initDataOut(data)
382 self.__initDataOut(data)
382
383
383 filePointer.close()
384 filePointer.close()
384
385
385 self.listShapes = listShapes
386 self.listShapes = listShapes
386 self.listMetaname = listMetaname
387 self.listMetaname = listMetaname
387 self.listMeta = listMetadata
388 self.listMeta = listMetadata
388
389
389 return
390 return
390
391
391 def __readData(self):
392 def __readData(self):
392 grp = self.fp['Data']
393 grp = self.fp['Data']
393 listdataname = []
394 listdataname = []
394 listdata = []
395 listdata = []
395
396
396 for item in grp.items():
397 for item in grp.items():
397 name = item[0]
398 name = item[0]
398
399
399 if name == 'time':
400 if name == 'time':
400 listdataname.append('utctime')
401 listdataname.append('utctime')
401 timeAux = grp[name].value.astype(numpy.float)[0]
402 timeAux = grp[name].value.astype(numpy.float)[0]
402 listdata.append(timeAux)
403 listdata.append(timeAux)
403 continue
404 continue
404
405
405 listdataname.append(name)
406 listdataname.append(name)
406 array = self.__setDataArray(self.nRecords, grp[name],self.listShapes[name])
407 array = self.__setDataArray(self.nRecords, grp[name],self.listShapes[name])
407 listdata.append(array)
408 listdata.append(array)
408
409
409 self.listDataname = listdataname
410 self.listDataname = listdataname
410 self.listData = listdata
411 self.listData = listdata
411 return
412 return
412
413
413 def __setDataArray(self, nRecords, dataset, shapes):
414 def __setDataArray(self, nRecords, dataset, shapes):
414
415
415 nChannels = shapes[0] #Dimension 0
416 nChannels = shapes[0] #Dimension 0
416
417
417 nPoints = shapes[1] #Dimension 1, number of Points or Parameters
418 nPoints = shapes[1] #Dimension 1, number of Points or Parameters
418
419
419 nSamples = shapes[2] #Dimension 2, number of samples or ranges
420 nSamples = shapes[2] #Dimension 2, number of samples or ranges
420
421
421 mode = shapes[3]
422 mode = shapes[3]
422
423
423 # if nPoints>1:
424 # if nPoints>1:
424 # arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples))
425 # arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples))
425 # else:
426 # else:
426 # arrayData = numpy.zeros((nRecords,nChannels,nSamples))
427 # arrayData = numpy.zeros((nRecords,nChannels,nSamples))
427 #
428 #
428 # chn = 'channel'
429 # chn = 'channel'
429 #
430 #
430 # for i in range(nChannels):
431 # for i in range(nChannels):
431 #
432 #
432 # data = dataset[chn + str(i)].value
433 # data = dataset[chn + str(i)].value
433 #
434 #
434 # if nPoints>1:
435 # if nPoints>1:
435 # data = numpy.rollaxis(data,2)
436 # data = numpy.rollaxis(data,2)
436 #
437 #
437 # arrayData[:,i,:] = data
438 # arrayData[:,i,:] = data
438
439
439 arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples))
440 arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples))
440 doSqueeze = False
441 doSqueeze = False
441 if mode == 0:
442 if mode == 0:
442 strds = 'channel'
443 strds = 'channel'
443 nDatas = nChannels
444 nDatas = nChannels
444 newShapes = (nRecords,nPoints,nSamples)
445 newShapes = (nRecords,nPoints,nSamples)
445 if nPoints == 1:
446 if nPoints == 1:
446 doSqueeze = True
447 doSqueeze = True
447 axisSqueeze = 2
448 axisSqueeze = 2
448 else:
449 else:
449 strds = 'param'
450 strds = 'param'
450 nDatas = nPoints
451 nDatas = nPoints
451 newShapes = (nRecords,nChannels,nSamples)
452 newShapes = (nRecords,nChannels,nSamples)
452 if nChannels == 1:
453 if nChannels == 1:
453 doSqueeze = True
454 doSqueeze = True
454 axisSqueeze = 1
455 axisSqueeze = 1
455
456
456 for i in range(nDatas):
457 for i in range(nDatas):
457
458
458 data = dataset[strds + str(i)].value
459 data = dataset[strds + str(i)].value
459 data = data.reshape(newShapes)
460 data = data.reshape(newShapes)
460
461
461 if mode == 0:
462 if mode == 0:
462 arrayData[:,i,:,:] = data
463 arrayData[:,i,:,:] = data
463 else:
464 else:
464 arrayData[:,:,i,:] = data
465 arrayData[:,:,i,:] = data
465
466
466 if doSqueeze:
467 if doSqueeze:
467 arrayData = numpy.squeeze(arrayData, axis=axisSqueeze)
468 arrayData = numpy.squeeze(arrayData, axis=axisSqueeze)
468
469
469 return arrayData
470 return arrayData
470
471
471 def __initDataOut(self, type):
472 def __initDataOut(self, type):
472
473
473 # if type =='Parameters':
474 # if type =='Parameters':
474 # self.dataOut = Parameters()
475 # self.dataOut = Parameters()
475 # elif type =='Spectra':
476 # elif type =='Spectra':
476 # self.dataOut = Spectra()
477 # self.dataOut = Spectra()
477 # elif type =='Voltage':
478 # elif type =='Voltage':
478 # self.dataOut = Voltage()
479 # self.dataOut = Voltage()
479 # elif type =='Correlation':
480 # elif type =='Correlation':
480 # self.dataOut = Correlation()
481 # self.dataOut = Correlation()
481
482
482 return
483 return
483
484
484 def __setDataOut(self):
485 def __setDataOut(self):
485 listMeta = self.listMeta
486 listMeta = self.listMeta
486 listMetaname = self.listMetaname
487 listMetaname = self.listMetaname
487 listDataname = self.listDataname
488 listDataname = self.listDataname
488 listData = self.listData
489 listData = self.listData
489
490
490 blockIndex = self.blockIndex
491 blockIndex = self.blockIndex
491 blockList = self.blockList
492 blockList = self.blockList
492
493
493 for i in range(len(listMeta)):
494 for i in range(len(listMeta)):
494 setattr(self.dataOut,listMetaname[i],listMeta[i])
495 setattr(self.dataOut,listMetaname[i],listMeta[i])
495
496
496 for j in range(len(listData)):
497 for j in range(len(listData)):
497 if listDataname[j]=='utctime':
498 if listDataname[j]=='utctime':
498 # setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex]])
499 # setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex]])
499 setattr(self.dataOut,'utctimeInit',listData[j][blockList[blockIndex]])
500 setattr(self.dataOut,'utctimeInit',listData[j][blockList[blockIndex]])
500 continue
501 continue
501
502
502 setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex],:])
503 setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex],:])
503
504
504 return self.dataOut.data_param
505 return self.dataOut.data_param
505
506
506 def getData(self):
507 def getData(self):
507
508
508 # if self.flagNoMoreFiles:
509 # if self.flagNoMoreFiles:
509 # self.dataOut.flagNoData = True
510 # self.dataOut.flagNoData = True
510 # print 'Process finished'
511 # print 'Process finished'
511 # return 0
512 # return 0
512 #
513 #
513 if self.blockIndex==self.blocksPerFile:
514 if self.blockIndex==self.blocksPerFile:
514 if not( self.__setNextFileOffline() ):
515 if not( self.__setNextFileOffline() ):
515 self.dataOut.flagNoData = True
516 self.dataOut.flagNoData = True
516 return 0
517 return 0
517
518
518 #
519 #
519 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
520 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
520 # self.dataOut.flagNoData = True
521 # self.dataOut.flagNoData = True
521 # return 0
522 # return 0
522
523
523 self.__readData()
524 self.__readData()
524 self.__setDataOut()
525 self.__setDataOut()
525 self.dataOut.flagNoData = False
526 self.dataOut.flagNoData = False
526
527
527 self.blockIndex += 1
528 self.blockIndex += 1
528
529
529 return
530 return
530
531
531 def run(self, **kwargs):
532 def run(self, **kwargs):
532
533
533 if not(self.isConfig):
534 if not(self.isConfig):
534 self.setup(**kwargs)
535 self.setup(**kwargs)
535 # self.setObjProperties()
536 # self.setObjProperties()
536 self.isConfig = True
537 self.isConfig = True
537
538
538 self.getData()
539 self.getData()
539
540
540 return
541 return
541
542
542 class HDF5Writer(Operation):
543 class HDF5Writer(Operation):
543
544
544 ext = ".hdf5"
545 ext = ".hdf5"
545
546
546 optchar = "D"
547 optchar = "D"
547
548
548 metaoptchar = "M"
549 metaoptchar = "M"
549
550
550 metaFile = None
551 metaFile = None
551
552
553 filename = None
554
552 path = None
555 path = None
553
556
554 setFile = None
557 setFile = None
555
558
556 fp = None
559 fp = None
557
560
558 grp = None
561 grp = None
559
562
560 ds = None
563 ds = None
561
564
562 firsttime = True
565 firsttime = True
563
566
564 #Configurations
567 #Configurations
565
568
566 blocksPerFile = None
569 blocksPerFile = None
567
570
568 blockIndex = None
571 blockIndex = None
569
572
570 dataOut = None
573 dataOut = None
571
574
572 #Data Arrays
575 #Data Arrays
573
576
574 dataList = None
577 dataList = None
575
578
576 metadataList = None
579 metadataList = None
577
580
578 arrayDim = None
581 arrayDim = None
579
582
580 tableDim = None
583 tableDim = None
581
584
582 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
585 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
583
586
584 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
587 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
585
588
586 mode = None
589 mode = None
587
590
588 nDatas = None #Number of datasets to be stored per array
591 nDatas = None #Number of datasets to be stored per array
589
592
590 nDims = None #Number Dimensions in each dataset
593 nDims = None #Number Dimensions in each dataset
591
594
595 nDimsForDs = None
596
592 def __init__(self):
597 def __init__(self):
593
598
594 Operation.__init__(self)
599 Operation.__init__(self)
595 self.isConfig = False
600 self.isConfig = False
596 return
601 return
597
602
598
603
599 def setup(self, dataOut, **kwargs):
604 def setup(self, dataOut, **kwargs):
600
605
601 self.path = kwargs['path']
606 self.path = kwargs['path']
602
607
603 if kwargs.has_key('ext'):
608 if kwargs.has_key('ext'):
604 self.ext = kwargs['ext']
609 self.ext = kwargs['ext']
605
610
606 if kwargs.has_key('blocksPerFile'):
611 if kwargs.has_key('blocksPerFile'):
607 self.blocksPerFile = kwargs['blocksPerFile']
612 self.blocksPerFile = kwargs['blocksPerFile']
608 else:
613 else:
609 self.blocksPerFile = 10
614 self.blocksPerFile = 10
610
615
611 self.metadataList = kwargs['metadataList']
616 self.metadataList = kwargs['metadataList']
612
617
613 self.dataList = kwargs['dataList']
618 self.dataList = kwargs['dataList']
614
619
615 self.dataOut = dataOut
620 self.dataOut = dataOut
616
621
617 if kwargs.has_key('mode'):
622 if kwargs.has_key('mode'):
618 mode = kwargs['mode']
623 mode = kwargs['mode']
619
624
620 if type(mode) == int:
625 if type(mode) == int:
621 mode = numpy.zeros(len(self.dataList)) + mode
626 mode = numpy.zeros(len(self.dataList)) + mode
622 else:
627 else:
623 mode = numpy.zeros(len(self.dataList))
628 mode = numpy.zeros(len(self.dataList))
624
629
625 self.mode = mode
630 self.mode = mode
626
631
627 arrayDim = numpy.zeros((len(self.dataList),5))
632 arrayDim = numpy.zeros((len(self.dataList),5))
628
633
629 #Table dimensions
634 #Table dimensions
630
635
631 dtype0 = self.dtype
636 dtype0 = self.dtype
632
637
633 tableList = []
638 tableList = []
634
639
635 for i in range(len(self.dataList)):
640 for i in range(len(self.dataList)):
636
641
637 dataAux = getattr(self.dataOut, self.dataList[i])
642 dataAux = getattr(self.dataOut, self.dataList[i])
638
643
639 if type(dataAux)==float or type(dataAux)==int:
644 if type(dataAux)==float or type(dataAux)==int:
640 arrayDim[i,0] = 1
645 arrayDim[i,0] = 1
641 else:
646 else:
642 arrayDim0 = dataAux.shape
647 arrayDim0 = dataAux.shape
643 arrayDim[i,0] = len(arrayDim0)
648 arrayDim[i,0] = len(arrayDim0)
644 arrayDim[i,4] = mode[i]
649 arrayDim[i,4] = mode[i]
645
650
646 if len(arrayDim0) == 3:
651 if len(arrayDim0) == 3:
647 arrayDim[i,1:-1] = numpy.array(arrayDim0)
652 arrayDim[i,1:-1] = numpy.array(arrayDim0)
648 elif len(arrayDim0) == 2:
653 elif len(arrayDim0) == 2:
649 arrayDim[i,2:-1] = numpy.array(arrayDim0) #nHeights
654 arrayDim[i,2:-1] = numpy.array(arrayDim0) #nHeights
650 elif len(arrayDim0) == 1:
655 elif len(arrayDim0) == 1:
651 arrayDim[i,3] = arrayDim0
656 arrayDim[i,3] = arrayDim0
652 elif len(arrayDim0) == 0:
657 elif len(arrayDim0) == 0:
653 arrayDim[i,0] = 1
658 arrayDim[i,0] = 1
654 arrayDim[i,3] = 1
659 arrayDim[i,3] = 1
655
660
656 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
661 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
657 tableList.append(table)
662 tableList.append(table)
658
663
659 self.arrayDim = arrayDim
664 self.arrayDim = arrayDim
660 self.tableDim = numpy.array(tableList, dtype = dtype0)
665 self.tableDim = numpy.array(tableList, dtype = dtype0)
661 self.blockIndex = 0
666 self.blockIndex = 0
662
667
663 return
668 return
664
669
665 def putMetadata(self):
670 def putMetadata(self):
666
671
667 fp = self.createMetadataFile()
672 fp = self.createMetadataFile()
668 self.writeMetadata(fp)
673 self.writeMetadata(fp)
669 fp.close()
674 fp.close()
670 return
675 return
671
676
672 def createMetadataFile(self):
677 def createMetadataFile(self):
673 ext = self.ext
678 ext = self.ext
674 path = self.path
679 path = self.path
675 setFile = self.setFile
680 setFile = self.setFile
676
681
677 timeTuple = time.localtime(self.dataOut.utctime)
682 timeTuple = time.localtime(self.dataOut.utctime)
683
678 subfolder = ''
684 subfolder = ''
685 fullpath = os.path.join( path, subfolder )
679
686
687 if not( os.path.exists(fullpath) ):
688 os.mkdir(fullpath)
689 setFile = -1 #inicializo mi contador de seteo
690
691 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
680 fullpath = os.path.join( path, subfolder )
692 fullpath = os.path.join( path, subfolder )
693
681 if not( os.path.exists(fullpath) ):
694 if not( os.path.exists(fullpath) ):
682 os.mkdir(fullpath)
695 os.mkdir(fullpath)
683 setFile = -1 #inicializo mi contador de seteo
696 setFile = -1 #inicializo mi contador de seteo
697
684 else:
698 else:
685 filesList = os.listdir( fullpath )
699 filesList = os.listdir( fullpath )
686 if len( filesList ) > 0:
687 filesList = sorted( filesList, key=str.lower )
700 filesList = sorted( filesList, key=str.lower )
701 if len( filesList ) > 0:
702 filesList = [k for k in filesList if 'M' in k]
688 filen = filesList[-1]
703 filen = filesList[-1]
689 # el filename debera tener el siguiente formato
704 # el filename debera tener el siguiente formato
690 # 0 1234 567 89A BCDE (hex)
705 # 0 1234 567 89A BCDE (hex)
691 # x YYYY DDD SSS .ext
706 # x YYYY DDD SSS .ext
692 if isNumber( filen[8:11] ):
707 if isNumber( filen[8:11] ):
693 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
708 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
694 else:
709 else:
695 setFile = -1
710 setFile = -1
696 else:
711 else:
697 setFile = -1 #inicializo mi contador de seteo
712 setFile = -1 #inicializo mi contador de seteo
698
713
699 setFile += 1
714 setFile += 1
700
715
701 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
716 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
702 timeTuple.tm_year,
717 timeTuple.tm_year,
703 timeTuple.tm_yday,
718 timeTuple.tm_yday,
704 setFile,
719 setFile,
705 ext )
720 ext )
706
721
707 filename = os.path.join( path, subfolder, file )
722 filename = os.path.join( path, subfolder, file )
708 self.metaFile = file
723 self.metaFile = file
709 #Setting HDF5 File
724 #Setting HDF5 File
710 fp = h5py.File(filename,'w')
725 fp = h5py.File(filename,'w')
711
726
712 return fp
727 return fp
713
728
714 def writeMetadata(self, fp):
729 def writeMetadata(self, fp):
715
730
716 grp = fp.create_group("Metadata")
731 grp = fp.create_group("Metadata")
717 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
732 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
718
733
719 for i in range(len(self.metadataList)):
734 for i in range(len(self.metadataList)):
720 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
735 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
721 return
736 return
722
737
723 def setNextFile(self):
738 def setNextFile(self):
724
739
725 ext = self.ext
740 ext = self.ext
726 path = self.path
741 path = self.path
727 setFile = self.setFile
742 setFile = self.setFile
728 mode = self.mode
743 mode = self.mode
729
744
730 if self.fp != None:
731 self.fp.close()
732
733 timeTuple = time.localtime(self.dataOut.utctime)
745 timeTuple = time.localtime(self.dataOut.utctime)
734 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
746 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
735
747
736 fullpath = os.path.join( path, subfolder )
748 fullpath = os.path.join( path, subfolder )
737 if not( os.path.exists(fullpath) ):
749
738 os.mkdir(fullpath)
750 if os.path.exists(fullpath):
739 setFile = -1 #inicializo mi contador de seteo
740 else:
741 filesList = os.listdir( fullpath )
751 filesList = os.listdir( fullpath )
752 filesList = [k for k in filesList if 'D' in k]
742 if len( filesList ) > 0:
753 if len( filesList ) > 0:
743 filesList = sorted( filesList, key=str.lower )
754 filesList = sorted( filesList, key=str.lower )
744 filen = filesList[-1]
755 filen = filesList[-1]
745 # el filename debera tener el siguiente formato
756 # el filename debera tener el siguiente formato
746 # 0 1234 567 89A BCDE (hex)
757 # 0 1234 567 89A BCDE (hex)
747 # x YYYY DDD SSS .ext
758 # x YYYY DDD SSS .ext
748 if isNumber( filen[8:11] ):
759 if isNumber( filen[8:11] ):
749 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
760 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
750 else:
761 else:
751 setFile = -1
762 setFile = -1
752 else:
763 else:
753 setFile = -1 #inicializo mi contador de seteo
764 setFile = -1 #inicializo mi contador de seteo
754
765
755 setFile += 1
766 setFile += 1
756
767
757 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
768 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
758 timeTuple.tm_year,
769 timeTuple.tm_year,
759 timeTuple.tm_yday,
770 timeTuple.tm_yday,
760 setFile,
771 setFile,
761 ext )
772 ext )
762
773
763 filename = os.path.join( path, subfolder, file )
774 filename = os.path.join( path, subfolder, file )
764
775
765 #Setting HDF5 File
776 #Setting HDF5 File
766 fp = h5py.File(filename,'w')
777 fp = h5py.File(filename,'w')
767 grp = fp.create_group("Data")
778 grp = fp.create_group("Data")
768 grp.attrs['metadata'] = self.metaFile
779 grp.attrs['metadata'] = self.metaFile
769
780
770 # grp.attrs['blocksPerFile'] = 0
781 # grp.attrs['blocksPerFile'] = 0
771
782
772 ds = []
783 ds = []
773 data = []
784 data = []
785 nDimsForDs = []
774
786
775 nDatas = numpy.zeros(len(self.dataList))
787 nDatas = numpy.zeros(len(self.dataList))
776 nDims = self.arrayDim[:,0]
788 nDims = self.arrayDim[:,0]
777
789
790 nDim1 = self.arrayDim[:,2]
791 nDim0 = self.arrayDim[:,3]
792
778 for i in range(len(self.dataList)):
793 for i in range(len(self.dataList)):
779
794
780 if nDims[i]==1:
795 if nDims[i]==1:
781 ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,None) , chunks = True, dtype='S20')
796 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
797 ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
782 ds.append(ds0)
798 ds.append(ds0)
783 data.append([])
799 data.append([])
784
800 nDimsForDs.append(nDims[i])
785 else:
801 else:
786
802
787 if mode[i]==0:
803 if mode[i]==0:
788 strMode = "channel"
804 strMode = "channel"
789 nDatas[i] = self.arrayDim[i,1]
805 nDatas[i] = self.arrayDim[i,1]
790 else:
806 else:
791 strMode = "param"
807 strMode = "param"
792 nDatas[i] = self.arrayDim[i,2]
808 nDatas[i] = self.arrayDim[i,2]
793
809
794 if nDims[i]==2:
810 if nDims[i]==2:
795 nDatas[i] = self.arrayDim[i,2]
811 nDatas[i] = self.arrayDim[i,2]
796
812
797 grp0 = grp.create_group(self.dataList[i])
813 grp0 = grp.create_group(self.dataList[i])
798
814
799 for j in range(int(nDatas[i])):
815 for j in range(int(nDatas[i])):
800 tableName = strMode + str(j)
816 tableName = strMode + str(j)
801
817
802 if nDims[i] == 3:
818 if nDims[i] == 3:
803 ds0 = grp0.create_dataset(tableName, (1,1,1) , maxshape=(None,None,None), chunks=True)
819 ds0 = grp0.create_dataset(tableName, (nDim1[i],nDim0[i],1) , data = numpy.zeros((nDim1[i],nDim0[i],1)) ,maxshape=(None,nDim0[i],None), chunks=True)
804 else:
820 else:
805 ds0 = grp0.create_dataset(tableName, (1,1) , maxshape=(None,None), chunks=True)
821 ds0 = grp0.create_dataset(tableName, (1,nDim0[i]), data = numpy.zeros((1,nDim0[i])) , maxshape=(None,nDim0[i]), chunks=True)
806
822
807 ds.append(ds0)
823 ds.append(ds0)
808 data.append([])
824 data.append([])
809
825 nDimsForDs.append(nDims[i])
810 self.nDatas = nDatas
826 self.nDatas = nDatas
811 self.nDims = nDims
827 self.nDims = nDims
812
828 self.nDimsForDs = nDimsForDs
813 #Saving variables
829 #Saving variables
814 print 'Writing the file: %s'%filename
830 print 'Writing the file: %s'%filename
831 self.filename = filename
815 self.fp = fp
832 self.fp = fp
816 self.grp = grp
833 self.grp = grp
834 self.grp.attrs.modify('nRecords', 1)
817 self.ds = ds
835 self.ds = ds
818 self.data = data
836 self.data = data
819
837
820 self.setFile = setFile
838 self.setFile = setFile
821 self.firsttime = True
839 self.firsttime = True
822 self.blockIndex = 0
840 self.blockIndex = 0
823 return
841 return
824
842
825 def putData(self):
843 def putData(self):
826 self.setBlock()
844
827 self.writeBlock()
845 if not self.firsttime:
846 self.fp.flush()
847 self.fp.close()
848 self.readBlock()
828
849
829 if self.blockIndex == self.blocksPerFile:
850 if self.blockIndex == self.blocksPerFile:
851
830 self.setNextFile()
852 self.setNextFile()
853
854 self.setBlock()
855 self.writeBlock()
856
857
831 return
858 return
832
859
860 def readBlock(self):
861
862 '''
863 data Array configured
864
865
866 self.data
867 '''
868 ds = self.ds
869 #Setting HDF5 File
870 fp = h5py.File(self.filename,'r+')
871 grp = fp["Data"]
872 ind = 0
873
874 # grp.attrs['blocksPerFile'] = 0
875 for i in range(len(self.dataList)):
876
877 if self.nDims[i]==1:
878 ds0 = grp[self.dataList[i]]
879 ds[ind] = ds0
880 ind += 1
881 else:
882 if self.mode[i]==0:
883 strMode = "channel"
884 else:
885 strMode = "param"
886
887 grp0 = grp[self.dataList[i]]
888
889 for j in range(int(self.nDatas[i])):
890 tableName = strMode + str(j)
891 ds0 = grp0[tableName]
892 ds[ind] = ds0
893 ind += 1
894
895
896 self.fp = fp
897 self.grp = grp
898 self.ds = ds
899
900 return
901
902
833 def setBlock(self):
903 def setBlock(self):
834 '''
904 '''
835 data Array configured
905 data Array configured
836
906
837
907
838 self.data
908 self.data
839 '''
909 '''
840 #Creating Arrays
910 #Creating Arrays
841 data = self.data
911 data = self.data
842 nDatas = self.nDatas
912 nDatas = self.nDatas
843 nDims = self.nDims
913 nDims = self.nDims
844 mode = self.mode
914 mode = self.mode
845 ind = 0
915 ind = 0
846
916
847 for i in range(len(self.dataList)):
917 for i in range(len(self.dataList)):
848 dataAux = getattr(self.dataOut,self.dataList[i])
918 dataAux = getattr(self.dataOut,self.dataList[i])
849
919
850 if nDims[i] == 1:
920 if nDims[i] == 1:
851 data[ind] = numpy.array([str(dataAux)]).reshape((1,1))
921 # data[ind] = numpy.array([str(dataAux)]).reshape((1,1))
852 if not self.firsttime:
922 data[ind] = dataAux
853 data[ind] = numpy.hstack((self.ds[ind][:], self.data[ind]))
923 # if not self.firsttime:
924 # data[ind] = numpy.hstack((self.ds[ind][:], self.data[ind]))
854 ind += 1
925 ind += 1
855
856 else:
926 else:
857 for j in range(int(nDatas[i])):
927 for j in range(int(nDatas[i])):
858 if (mode[i] == 0) or (nDims[i] == 2): #In case division per channel or Dimensions is only 1
928 if (mode[i] == 0) or (nDims[i] == 2): #In case division per channel or Dimensions is only 1
859 data[ind] = dataAux[j,:]
929 data[ind] = dataAux[j,:]
860 else:
930 else:
861 data[ind] = dataAux[:,j,:]
931 data[ind] = dataAux[:,j,:]
862
932
863 if nDims[i] == 3:
933 # if nDims[i] == 3:
864 data[ind] = data[ind].reshape((data[ind].shape[0],data[ind].shape[1],1))
934 # data[ind] = data[ind].reshape((data[ind].shape[0],data[ind].shape[1],1))
865
935
866 if not self.firsttime:
936 # if not self.firsttime:
867 data[ind] = numpy.dstack((self.ds[ind][:], data[ind]))
937 # data[ind] = numpy.dstack((self.ds[ind][:], data[ind]))
868
938
869 else:
939 # else:
870 data[ind] = data[ind].reshape((1,data[ind].shape[0]))
940 # data[ind] = data[ind].reshape((1,data[ind].shape[0]))
871
941
872 if not self.firsttime:
942 # if not self.firsttime:
873 data[ind] = numpy.vstack((self.ds[ind][:], data[ind]))
943 # data[ind] = numpy.vstack((self.ds[ind][:], data[ind]))
874 ind += 1
944 ind += 1
875
945
876 self.data = data
946 self.data = data
877 return
947 return
878
948
879 def writeBlock(self):
949 def writeBlock(self):
880 '''
950 '''
881 Saves the block in the HDF5 file
951 Saves the block in the HDF5 file
882 '''
952 '''
883 for i in range(len(self.ds)):
953 for i in range(len(self.ds)):
954 if self.firsttime:
955 # self.ds[i].resize(self.data[i].shape)
956 # self.ds[i][self.blockIndex,:] = self.data[i]
957 if type(self.data[i]) == numpy.ndarray:
958 nDims1 = len(self.ds[i].shape)
959
960 if nDims1 == 3:
961 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
962
884 self.ds[i].resize(self.data[i].shape)
963 self.ds[i].resize(self.data[i].shape)
885 self.ds[i][:] = self.data[i]
964 self.ds[i][:] = self.data[i]
965 else:
966 if self.nDimsForDs[i] == 1:
967 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
968 self.ds[i][0,-1] = self.data[i]
969 elif self.nDimsForDs[i] == 2:
970 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
971 self.ds[i][self.blockIndex,:] = self.data[i]
972 elif self.nDimsForDs[i] == 3:
973
974 dataShape = self.data[i].shape
975 dsShape = self.ds[i].shape
976
977 if dataShape[0]==dsShape[0]:
978 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
979 self.ds[i][:,:,-1] = self.data[i]
980 else:
981 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1],self.ds[i].shape[2]))
982 self.ds[i][dsShape[0]:,:,0] = self.data[i]
983 # self.ds[i].append(self.data[i])
984 # self.fp.flush()
985 # if not self.firsttime:
986 # self.fp.root.Data._v_attrs.nRecords = self.blockIndex
886
987
887 self.blockIndex += 1
988 # if self.firsttime:
888
989 # self.fp.close()
889 self.grp.attrs.modify('nRecords', self.blockIndex)
990 # self.readBlock2()
890
991
992 self.blockIndex += 1
891 self.firsttime = False
993 self.firsttime = False
892 return
994 return
893
995
894 def run(self, dataOut, **kwargs):
996 def run(self, dataOut, **kwargs):
895 if not(self.isConfig):
997 if not(self.isConfig):
896 self.setup(dataOut, **kwargs)
998 self.setup(dataOut, **kwargs)
897 self.isConfig = True
999 self.isConfig = True
898 self.putMetadata()
1000 self.putMetadata()
899 self.setNextFile()
1001 self.setNextFile()
900
1002
901 self.putData()
1003 self.putData()
902 return
1004 return
903
1005
@@ -1,1786 +1,2144
1 import numpy
1 import numpy
2 import math
2 import math
3 from scipy import optimize
3 from scipy import optimize
4 from scipy import interpolate
4 from scipy import interpolate
5 from scipy import signal
5 from scipy import signal
6 from scipy import stats
6 from scipy import stats
7 import re
7 import re
8 import datetime
8 import datetime
9 import copy
9 import copy
10 import sys
10 import sys
11 import importlib
11 import importlib
12 import itertools
12 import itertools
13
13
14 from jroproc_base import ProcessingUnit, Operation
14 from jroproc_base import ProcessingUnit, Operation
15 from schainpy.model.data.jrodata import Parameters
15 from schainpy.model.data.jrodata import Parameters
16
16
17
17
18 class ParametersProc(ProcessingUnit):
18 class ParametersProc(ProcessingUnit):
19
19
20 nSeconds = None
20 nSeconds = None
21
21
22 def __init__(self):
22 def __init__(self):
23 ProcessingUnit.__init__(self)
23 ProcessingUnit.__init__(self)
24
24
25 # self.objectDict = {}
25 # self.objectDict = {}
26 self.buffer = None
26 self.buffer = None
27 self.firstdatatime = None
27 self.firstdatatime = None
28 self.profIndex = 0
28 self.profIndex = 0
29 self.dataOut = Parameters()
29 self.dataOut = Parameters()
30
30
31 def __updateObjFromInput(self):
31 def __updateObjFromInput(self):
32
32
33 self.dataOut.inputUnit = self.dataIn.type
33 self.dataOut.inputUnit = self.dataIn.type
34
34
35 self.dataOut.timeZone = self.dataIn.timeZone
35 self.dataOut.timeZone = self.dataIn.timeZone
36 self.dataOut.dstFlag = self.dataIn.dstFlag
36 self.dataOut.dstFlag = self.dataIn.dstFlag
37 self.dataOut.errorCount = self.dataIn.errorCount
37 self.dataOut.errorCount = self.dataIn.errorCount
38 self.dataOut.useLocalTime = self.dataIn.useLocalTime
38 self.dataOut.useLocalTime = self.dataIn.useLocalTime
39
39
40 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
40 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
41 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
41 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
42 self.dataOut.channelList = self.dataIn.channelList
42 self.dataOut.channelList = self.dataIn.channelList
43 self.dataOut.heightList = self.dataIn.heightList
43 self.dataOut.heightList = self.dataIn.heightList
44 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
44 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
45 # self.dataOut.nHeights = self.dataIn.nHeights
45 # self.dataOut.nHeights = self.dataIn.nHeights
46 # self.dataOut.nChannels = self.dataIn.nChannels
46 # self.dataOut.nChannels = self.dataIn.nChannels
47 self.dataOut.nBaud = self.dataIn.nBaud
47 self.dataOut.nBaud = self.dataIn.nBaud
48 self.dataOut.nCode = self.dataIn.nCode
48 self.dataOut.nCode = self.dataIn.nCode
49 self.dataOut.code = self.dataIn.code
49 self.dataOut.code = self.dataIn.code
50 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
50 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
51 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
51 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
52 self.dataOut.utctime = self.firstdatatime
52 self.dataOut.utctime = self.firstdatatime
53 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
53 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
54 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
54 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
55 # self.dataOut.nCohInt = self.dataIn.nCohInt
55 # self.dataOut.nCohInt = self.dataIn.nCohInt
56 # self.dataOut.nIncohInt = 1
56 # self.dataOut.nIncohInt = 1
57 self.dataOut.ippSeconds = self.dataIn.ippSeconds
57 self.dataOut.ippSeconds = self.dataIn.ippSeconds
58 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
58 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
59 self.dataOut.timeInterval = self.dataIn.timeInterval
59 self.dataOut.timeInterval = self.dataIn.timeInterval
60 self.dataOut.heightList = self.dataIn.getHeiRange()
60 self.dataOut.heightList = self.dataIn.getHeiRange()
61 self.dataOut.frequency = self.dataIn.frequency
61 self.dataOut.frequency = self.dataIn.frequency
62
62
63 def run(self, nSeconds = None, nProfiles = None):
63 def run(self, nSeconds = None, nProfiles = None):
64
64
65
65
66
66
67 if self.firstdatatime == None:
67 if self.firstdatatime == None:
68 self.firstdatatime = self.dataIn.utctime
68 self.firstdatatime = self.dataIn.utctime
69
69
70 #---------------------- Voltage Data ---------------------------
70 #---------------------- Voltage Data ---------------------------
71
71
72 if self.dataIn.type == "Voltage":
72 if self.dataIn.type == "Voltage":
73 self.dataOut.flagNoData = True
73 self.dataOut.flagNoData = True
74 if nSeconds != None:
74 if nSeconds != None:
75 self.nSeconds = nSeconds
75 self.nSeconds = nSeconds
76 self.nProfiles= int(numpy.floor(nSeconds/(self.dataIn.ippSeconds*self.dataIn.nCohInt)))
76 self.nProfiles= int(numpy.floor(nSeconds/(self.dataIn.ippSeconds*self.dataIn.nCohInt)))
77
77
78 if self.buffer == None:
78 if self.buffer == None:
79 self.buffer = numpy.zeros((self.dataIn.nChannels,
79 self.buffer = numpy.zeros((self.dataIn.nChannels,
80 self.nProfiles,
80 self.nProfiles,
81 self.dataIn.nHeights),
81 self.dataIn.nHeights),
82 dtype='complex')
82 dtype='complex')
83
83
84 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
84 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
85 self.profIndex += 1
85 self.profIndex += 1
86
86
87 if self.profIndex == self.nProfiles:
87 if self.profIndex == self.nProfiles:
88
88
89 self.__updateObjFromInput()
89 self.__updateObjFromInput()
90 self.dataOut.data_pre = self.buffer.copy()
90 self.dataOut.data_pre = self.buffer.copy()
91 self.dataOut.paramInterval = nSeconds
91 self.dataOut.paramInterval = nSeconds
92 self.dataOut.flagNoData = False
92 self.dataOut.flagNoData = False
93
93
94 self.buffer = None
94 self.buffer = None
95 self.firstdatatime = None
95 self.firstdatatime = None
96 self.profIndex = 0
96 self.profIndex = 0
97 return
97 return
98
98
99 #---------------------- Spectra Data ---------------------------
99 #---------------------- Spectra Data ---------------------------
100
100
101 if self.dataIn.type == "Spectra":
101 if self.dataIn.type == "Spectra":
102 self.dataOut.data_pre = self.dataIn.data_spc.copy()
102 self.dataOut.data_pre = self.dataIn.data_spc.copy()
103 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
103 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
104 self.dataOut.noise = self.dataIn.getNoise()
104 self.dataOut.noise = self.dataIn.getNoise()
105 self.dataOut.normFactor = self.dataIn.normFactor
105 self.dataOut.normFactor = self.dataIn.normFactor
106 self.dataOut.groupList = self.dataIn.pairsList
106 self.dataOut.groupList = self.dataIn.pairsList
107 self.dataOut.flagNoData = False
107 self.dataOut.flagNoData = False
108
108
109 #---------------------- Correlation Data ---------------------------
109 #---------------------- Correlation Data ---------------------------
110
110
111 if self.dataIn.type == "Correlation":
111 if self.dataIn.type == "Correlation":
112 lagRRange = self.dataIn.lagR
112 lagRRange = self.dataIn.lagR
113 indR = numpy.where(lagRRange == 0)[0][0]
113 indR = numpy.where(lagRRange == 0)[0][0]
114
114
115 self.dataOut.data_pre = self.dataIn.data_corr.copy()[:,:,indR,:]
115 self.dataOut.data_pre = self.dataIn.data_corr.copy()[:,:,indR,:]
116 self.dataOut.abscissaList = self.dataIn.getLagTRange(1)
116 self.dataOut.abscissaList = self.dataIn.getLagTRange(1)
117 self.dataOut.noise = self.dataIn.noise
117 self.dataOut.noise = self.dataIn.noise
118 self.dataOut.normFactor = self.dataIn.normFactor
118 self.dataOut.normFactor = self.dataIn.normFactor
119 self.dataOut.data_SNR = self.dataIn.SNR
119 self.dataOut.data_SNR = self.dataIn.SNR
120 self.dataOut.groupList = self.dataIn.pairsList
120 self.dataOut.groupList = self.dataIn.pairsList
121 self.dataOut.flagNoData = False
121 self.dataOut.flagNoData = False
122
122
123 #---------------------- Correlation Data ---------------------------
123 #---------------------- Correlation Data ---------------------------
124
124
125 if self.dataIn.type == "Parameters":
125 if self.dataIn.type == "Parameters":
126 self.dataOut.copy(self.dataIn)
126 self.dataOut.copy(self.dataIn)
127 self.dataOut.flagNoData = False
127 self.dataOut.flagNoData = False
128
128
129 return True
129 return True
130
130
131 self.__updateObjFromInput()
131 self.__updateObjFromInput()
132 self.firstdatatime = None
132 self.firstdatatime = None
133 self.dataOut.utctimeInit = self.dataIn.utctime
133 self.dataOut.utctimeInit = self.dataIn.utctime
134 self.dataOut.outputInterval = self.dataIn.timeInterval
134 self.dataOut.outputInterval = self.dataIn.timeInterval
135
135
136 #------------------- Get Moments ----------------------------------
136 #------------------- Get Moments ----------------------------------
137 def GetMoments(self, channelList = None):
137 def GetMoments(self, channelList = None):
138 '''
138 '''
139 Function GetMoments()
139 Function GetMoments()
140
140
141 Input:
141 Input:
142 channelList : simple channel list to select e.g. [2,3,7]
142 channelList : simple channel list to select e.g. [2,3,7]
143 self.dataOut.data_pre
143 self.dataOut.data_pre
144 self.dataOut.abscissaList
144 self.dataOut.abscissaList
145 self.dataOut.noise
145 self.dataOut.noise
146
146
147 Affected:
147 Affected:
148 self.dataOut.data_param
148 self.dataOut.data_param
149 self.dataOut.data_SNR
149 self.dataOut.data_SNR
150
150
151 '''
151 '''
152 data = self.dataOut.data_pre
152 data = self.dataOut.data_pre
153 absc = self.dataOut.abscissaList[:-1]
153 absc = self.dataOut.abscissaList[:-1]
154 noise = self.dataOut.noise
154 noise = self.dataOut.noise
155
155
156 data_param = numpy.zeros((data.shape[0], 4, data.shape[2]))
156 data_param = numpy.zeros((data.shape[0], 4, data.shape[2]))
157
157
158 if channelList== None:
158 if channelList== None:
159 channelList = self.dataIn.channelList
159 channelList = self.dataIn.channelList
160 self.dataOut.channelList = channelList
160 self.dataOut.channelList = channelList
161
161
162 for ind in channelList:
162 for ind in channelList:
163 data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind])
163 data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind])
164
164
165 self.dataOut.data_param = data_param[:,1:,:]
165 self.dataOut.data_param = data_param[:,1:,:]
166 self.dataOut.data_SNR = data_param[:,0]
166 self.dataOut.data_SNR = data_param[:,0]
167 return
167 return
168
168
169 def __calculateMoments(self, oldspec, oldfreq, n0, nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
169 def __calculateMoments(self, oldspec, oldfreq, n0, nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
170
170
171 if (nicoh == None): nicoh = 1
171 if (nicoh == None): nicoh = 1
172 if (graph == None): graph = 0
172 if (graph == None): graph = 0
173 if (smooth == None): smooth = 0
173 if (smooth == None): smooth = 0
174 elif (self.smooth < 3): smooth = 0
174 elif (self.smooth < 3): smooth = 0
175
175
176 if (type1 == None): type1 = 0
176 if (type1 == None): type1 = 0
177 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
177 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
178 if (snrth == None): snrth = -3
178 if (snrth == None): snrth = -3
179 if (dc == None): dc = 0
179 if (dc == None): dc = 0
180 if (aliasing == None): aliasing = 0
180 if (aliasing == None): aliasing = 0
181 if (oldfd == None): oldfd = 0
181 if (oldfd == None): oldfd = 0
182 if (wwauto == None): wwauto = 0
182 if (wwauto == None): wwauto = 0
183
183
184 if (n0 < 1.e-20): n0 = 1.e-20
184 if (n0 < 1.e-20): n0 = 1.e-20
185
185
186 freq = oldfreq
186 freq = oldfreq
187 vec_power = numpy.zeros(oldspec.shape[1])
187 vec_power = numpy.zeros(oldspec.shape[1])
188 vec_fd = numpy.zeros(oldspec.shape[1])
188 vec_fd = numpy.zeros(oldspec.shape[1])
189 vec_w = numpy.zeros(oldspec.shape[1])
189 vec_w = numpy.zeros(oldspec.shape[1])
190 vec_snr = numpy.zeros(oldspec.shape[1])
190 vec_snr = numpy.zeros(oldspec.shape[1])
191
191
192 for ind in range(oldspec.shape[1]):
192 for ind in range(oldspec.shape[1]):
193
193
194 spec = oldspec[:,ind]
194 spec = oldspec[:,ind]
195 aux = spec*fwindow
195 aux = spec*fwindow
196 max_spec = aux.max()
196 max_spec = aux.max()
197 m = list(aux).index(max_spec)
197 m = list(aux).index(max_spec)
198
198
199 #Smooth
199 #Smooth
200 if (smooth == 0): spec2 = spec
200 if (smooth == 0): spec2 = spec
201 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
201 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
202
202
203 # Calculo de Momentos
203 # Calculo de Momentos
204 bb = spec2[range(m,spec2.size)]
204 bb = spec2[range(m,spec2.size)]
205 bb = (bb<n0).nonzero()
205 bb = (bb<n0).nonzero()
206 bb = bb[0]
206 bb = bb[0]
207
207
208 ss = spec2[range(0,m + 1)]
208 ss = spec2[range(0,m + 1)]
209 ss = (ss<n0).nonzero()
209 ss = (ss<n0).nonzero()
210 ss = ss[0]
210 ss = ss[0]
211
211
212 if (bb.size == 0):
212 if (bb.size == 0):
213 bb0 = spec.size - 1 - m
213 bb0 = spec.size - 1 - m
214 else:
214 else:
215 bb0 = bb[0] - 1
215 bb0 = bb[0] - 1
216 if (bb0 < 0):
216 if (bb0 < 0):
217 bb0 = 0
217 bb0 = 0
218
218
219 if (ss.size == 0): ss1 = 1
219 if (ss.size == 0): ss1 = 1
220 else: ss1 = max(ss) + 1
220 else: ss1 = max(ss) + 1
221
221
222 if (ss1 > m): ss1 = m
222 if (ss1 > m): ss1 = m
223
223
224 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
224 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
225 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
225 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
226 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
226 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
227 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
227 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
228 snr = (spec2.mean()-n0)/n0
228 snr = (spec2.mean()-n0)/n0
229
229
230 if (snr < 1.e-20) :
230 if (snr < 1.e-20) :
231 snr = 1.e-20
231 snr = 1.e-20
232
232
233 vec_power[ind] = power
233 vec_power[ind] = power
234 vec_fd[ind] = fd
234 vec_fd[ind] = fd
235 vec_w[ind] = w
235 vec_w[ind] = w
236 vec_snr[ind] = snr
236 vec_snr[ind] = snr
237
237
238 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
238 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
239 return moments
239 return moments
240
240
241 #------------------ Get SA Parameters --------------------------
241 #------------------ Get SA Parameters --------------------------
242
242 def GetSAParameters(self):
243 def GetSAParameters(self):
243 data = self.dataOut.data_pre
244 pairslist = self.dataOut.groupList
244 crossdata = self.dataIn.data_cspc
245 num_pairs = len(pairslist)
245 a = 1
246
247 vel = self.dataOut.abscissaList
248 spectra = self.dataOut.data_pre
249 cspectra = self.dataIn.data_cspc
250 delta_v = vel[1] - vel[0]
251
252 #Calculating the power spectrum
253 spc_pow = numpy.sum(spectra, 3)*delta_v
254 #Normalizing Spectra
255 norm_spectra = spectra/spc_pow
256 #Calculating the norm_spectra at peak
257 max_spectra = numpy.max(norm_spectra, 3)
246
258
259 #Normalizing Cross Spectra
260 norm_cspectra = numpy.zeros(cspectra.shape)
247
261
262 for i in range(num_chan):
263 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
248
264
265 max_cspectra = numpy.max(norm_cspectra,2)
266 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
267
268 for i in range(num_pairs):
269 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
249 #------------------- Get Lags ----------------------------------
270 #------------------- Get Lags ----------------------------------
250
271
251 def GetLags(self):
272 def GetLags(self):
252 '''
273 '''
253 Function GetMoments()
274 Function GetMoments()
254
275
255 Input:
276 Input:
256 self.dataOut.data_pre
277 self.dataOut.data_pre
257 self.dataOut.abscissaList
278 self.dataOut.abscissaList
258 self.dataOut.noise
279 self.dataOut.noise
259 self.dataOut.normFactor
280 self.dataOut.normFactor
260 self.dataOut.data_SNR
281 self.dataOut.data_SNR
261 self.dataOut.groupList
282 self.dataOut.groupList
262 self.dataOut.nChannels
283 self.dataOut.nChannels
263
284
264 Affected:
285 Affected:
265 self.dataOut.data_param
286 self.dataOut.data_param
266
287
267 '''
288 '''
268
289
269 data = self.dataOut.data_pre
290 data = self.dataOut.data_pre
270 normFactor = self.dataOut.normFactor
291 normFactor = self.dataOut.normFactor
271 nHeights = self.dataOut.nHeights
292 nHeights = self.dataOut.nHeights
272 absc = self.dataOut.abscissaList[:-1]
293 absc = self.dataOut.abscissaList[:-1]
273 noise = self.dataOut.noise
294 noise = self.dataOut.noise
274 SNR = self.dataOut.data_SNR
295 SNR = self.dataOut.data_SNR
275 pairsList = self.dataOut.groupList
296 pairsList = self.dataOut.groupList
276 nChannels = self.dataOut.nChannels
297 nChannels = self.dataOut.nChannels
277 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
298 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
278 self.dataOut.data_param = numpy.zeros((len(pairsCrossCorr)*2 + 1, nHeights))
299 self.dataOut.data_param = numpy.zeros((len(pairsCrossCorr)*2 + 1, nHeights))
279
300
280 dataNorm = numpy.abs(data)
301 dataNorm = numpy.abs(data)
281 for l in range(len(pairsList)):
302 for l in range(len(pairsList)):
282 dataNorm[l,:,:] = dataNorm[l,:,:]/normFactor[l,:]
303 dataNorm[l,:,:] = dataNorm[l,:,:]/normFactor[l,:]
283
304
284 self.dataOut.data_param[:-1,:] = self.__calculateTaus(dataNorm, pairsCrossCorr, pairsAutoCorr, absc)
305 self.dataOut.data_param[:-1,:] = self.__calculateTaus(dataNorm, pairsCrossCorr, pairsAutoCorr, absc)
285 self.dataOut.data_param[-1,:] = self.__calculateLag1Phase(data, pairsAutoCorr, absc)
306 self.dataOut.data_param[-1,:] = self.__calculateLag1Phase(data, pairsAutoCorr, absc)
286 return
307 return
287
308
288 def __getPairsAutoCorr(self, pairsList, nChannels):
309 def __getPairsAutoCorr(self, pairsList, nChannels):
289
310
290 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
311 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
291
312
292 for l in range(len(pairsList)):
313 for l in range(len(pairsList)):
293 firstChannel = pairsList[l][0]
314 firstChannel = pairsList[l][0]
294 secondChannel = pairsList[l][1]
315 secondChannel = pairsList[l][1]
295
316
296 #Obteniendo pares de Autocorrelacion
317 #Obteniendo pares de Autocorrelacion
297 if firstChannel == secondChannel:
318 if firstChannel == secondChannel:
298 pairsAutoCorr[firstChannel] = int(l)
319 pairsAutoCorr[firstChannel] = int(l)
299
320
300 pairsAutoCorr = pairsAutoCorr.astype(int)
321 pairsAutoCorr = pairsAutoCorr.astype(int)
301
322
302 pairsCrossCorr = range(len(pairsList))
323 pairsCrossCorr = range(len(pairsList))
303 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
324 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
304
325
305 return pairsAutoCorr, pairsCrossCorr
326 return pairsAutoCorr, pairsCrossCorr
306
327
307 def __calculateTaus(self, data, pairsCrossCorr, pairsAutoCorr, lagTRange):
328 def __calculateTaus(self, data, pairsCrossCorr, pairsAutoCorr, lagTRange):
308
329
309 Pt0 = data.shape[1]/2
330 Pt0 = data.shape[1]/2
310 #Funcion de Autocorrelacion
331 #Funcion de Autocorrelacion
311 dataAutoCorr = stats.nanmean(data[pairsAutoCorr,:,:], axis = 0)
332 dataAutoCorr = stats.nanmean(data[pairsAutoCorr,:,:], axis = 0)
312
333
313 #Obtencion Indice de TauCross
334 #Obtencion Indice de TauCross
314 indCross = data[pairsCrossCorr,:,:].argmax(axis = 1)
335 indCross = data[pairsCrossCorr,:,:].argmax(axis = 1)
315 #Obtencion Indice de TauAuto
336 #Obtencion Indice de TauAuto
316 indAuto = numpy.zeros(indCross.shape,dtype = 'int')
337 indAuto = numpy.zeros(indCross.shape,dtype = 'int')
317 CCValue = data[pairsCrossCorr,Pt0,:]
338 CCValue = data[pairsCrossCorr,Pt0,:]
318 for i in range(pairsCrossCorr.size):
339 for i in range(pairsCrossCorr.size):
319 indAuto[i,:] = numpy.abs(dataAutoCorr - CCValue[i,:]).argmin(axis = 0)
340 indAuto[i,:] = numpy.abs(dataAutoCorr - CCValue[i,:]).argmin(axis = 0)
320
341
321 #Obtencion de TauCross y TauAuto
342 #Obtencion de TauCross y TauAuto
322 tauCross = lagTRange[indCross]
343 tauCross = lagTRange[indCross]
323 tauAuto = lagTRange[indAuto]
344 tauAuto = lagTRange[indAuto]
324
345
325 Nan1, Nan2 = numpy.where(tauCross == lagTRange[0])
346 Nan1, Nan2 = numpy.where(tauCross == lagTRange[0])
326
347
327 tauCross[Nan1,Nan2] = numpy.nan
348 tauCross[Nan1,Nan2] = numpy.nan
328 tauAuto[Nan1,Nan2] = numpy.nan
349 tauAuto[Nan1,Nan2] = numpy.nan
329 tau = numpy.vstack((tauCross,tauAuto))
350 tau = numpy.vstack((tauCross,tauAuto))
330
351
331 return tau
352 return tau
332
353
333 def __calculateLag1Phase(self, data, pairs, lagTRange):
354 def __calculateLag1Phase(self, data, pairs, lagTRange):
334 data1 = stats.nanmean(data[pairs,:,:], axis = 0)
355 data1 = stats.nanmean(data[pairs,:,:], axis = 0)
335 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
356 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
336
357
337 phase = numpy.angle(data1[lag1,:])
358 phase = numpy.angle(data1[lag1,:])
338
359
339 return phase
360 return phase
340 #------------------- Detect Meteors ------------------------------
361 #------------------- Detect Meteors ------------------------------
341
362
342 def DetectMeteors(self, hei_ref = None, tauindex = 0,
363 def MeteorDetection(self, hei_ref = None, tauindex = 0,
343 predefinedPhaseShifts = None, centerReceiverIndex = 2,
364 predefinedPhaseShifts = None, centerReceiverIndex = 2, saveAll = False,
344 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
365 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
345 noise_timeStep = 4, noise_multiple = 4,
366 noise_timeStep = 4, noise_multiple = 4,
346 multDet_timeLimit = 1, multDet_rangeLimit = 3,
367 multDet_timeLimit = 1, multDet_rangeLimit = 3,
347 phaseThresh = 20, SNRThresh = 8,
368 phaseThresh = 20, SNRThresh = 8,
348 hmin = 70, hmax=110, azimuth = 0) :
369 hmin = 70, hmax=110, azimuth = 0) :
349
370
350 '''
371 '''
351 Function DetectMeteors()
372 Function DetectMeteors()
352 Project developed with paper:
373 Project developed with paper:
353 HOLDSWORTH ET AL. 2004
374 HOLDSWORTH ET AL. 2004
354
375
355 Input:
376 Input:
356 self.dataOut.data_pre
377 self.dataOut.data_pre
357
378
358 centerReceiverIndex: From the channels, which is the center receiver
379 centerReceiverIndex: From the channels, which is the center receiver
359
380
360 hei_ref: Height reference for the Beacon signal extraction
381 hei_ref: Height reference for the Beacon signal extraction
361 tauindex:
382 tauindex:
362 predefinedPhaseShifts: Predefined phase offset for the voltge signals
383 predefinedPhaseShifts: Predefined phase offset for the voltge signals
363
384
364 cohDetection: Whether to user Coherent detection or not
385 cohDetection: Whether to user Coherent detection or not
365 cohDet_timeStep: Coherent Detection calculation time step
386 cohDet_timeStep: Coherent Detection calculation time step
366 cohDet_thresh: Coherent Detection phase threshold to correct phases
387 cohDet_thresh: Coherent Detection phase threshold to correct phases
367
388
368 noise_timeStep: Noise calculation time step
389 noise_timeStep: Noise calculation time step
369 noise_multiple: Noise multiple to define signal threshold
390 noise_multiple: Noise multiple to define signal threshold
370
391
371 multDet_timeLimit: Multiple Detection Removal time limit in seconds
392 multDet_timeLimit: Multiple Detection Removal time limit in seconds
372 multDet_rangeLimit: Multiple Detection Removal range limit in km
393 multDet_rangeLimit: Multiple Detection Removal range limit in km
373
394
374 phaseThresh: Maximum phase difference between receiver to be consider a meteor
395 phaseThresh: Maximum phase difference between receiver to be consider a meteor
375 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
396 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
376
397
377 hmin: Minimum Height of the meteor to use it in the further wind estimations
398 hmin: Minimum Height of the meteor to use it in the further wind estimations
378 hmax: Maximum Height of the meteor to use it in the further wind estimations
399 hmax: Maximum Height of the meteor to use it in the further wind estimations
379 azimuth: Azimuth angle correction
400 azimuth: Azimuth angle correction
380
401
381 Affected:
402 Affected:
382 self.dataOut.data_param
403 self.dataOut.data_param
383
404
384 Rejection Criteria (Errors):
405 Rejection Criteria (Errors):
385 0: No error; analysis OK
406 0: No error; analysis OK
386 1: SNR < SNR threshold
407 1: SNR < SNR threshold
387 2: angle of arrival (AOA) ambiguously determined
408 2: angle of arrival (AOA) ambiguously determined
388 3: AOA estimate not feasible
409 3: AOA estimate not feasible
389 4: Large difference in AOAs obtained from different antenna baselines
410 4: Large difference in AOAs obtained from different antenna baselines
390 5: echo at start or end of time series
411 5: echo at start or end of time series
391 6: echo less than 5 examples long; too short for analysis
412 6: echo less than 5 examples long; too short for analysis
392 7: echo rise exceeds 0.3s
413 7: echo rise exceeds 0.3s
393 8: echo decay time less than twice rise time
414 8: echo decay time less than twice rise time
394 9: large power level before echo
415 9: large power level before echo
395 10: large power level after echo
416 10: large power level after echo
396 11: poor fit to amplitude for estimation of decay time
417 11: poor fit to amplitude for estimation of decay time
397 12: poor fit to CCF phase variation for estimation of radial drift velocity
418 12: poor fit to CCF phase variation for estimation of radial drift velocity
398 13: height unresolvable echo: not valid height within 70 to 110 km
419 13: height unresolvable echo: not valid height within 70 to 110 km
399 14: height ambiguous echo: more then one possible height within 70 to 110 km
420 14: height ambiguous echo: more then one possible height within 70 to 110 km
400 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
421 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
401 16: oscilatory echo, indicating event most likely not an underdense echo
422 16: oscilatory echo, indicating event most likely not an underdense echo
402
423
403 17: phase difference in meteor Reestimation
424 17: phase difference in meteor Reestimation
404
425
405 Data Storage:
426 Data Storage:
406 Meteors for Wind Estimation (8):
427 Meteors for Wind Estimation (8):
407 Day Hour | Range Height
428 Day Hour | Range Height
408 Azimuth Zenith errorCosDir
429 Azimuth Zenith errorCosDir
409 VelRad errorVelRad
430 VelRad errorVelRad
410 TypeError
431 TypeError
411
432
412 '''
433 '''
413 #Get Beacon signal
434 #Get Beacon signal
414 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
435 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
415
436
416 if hei_ref != None:
437 if hei_ref != None:
417 newheis = numpy.where(self.dataOut.heightList>hei_ref)
438 newheis = numpy.where(self.dataOut.heightList>hei_ref)
418
439
419 heiRang = self.dataOut.getHeiRange()
440 heiRang = self.dataOut.getHeiRange()
420 #Pairs List
441 #Pairs List
421 pairslist = []
442 pairslist = []
422 nChannel = self.dataOut.nChannels
443 nChannel = self.dataOut.nChannels
423 for i in range(nChannel):
444 for i in range(nChannel):
424 if i != centerReceiverIndex:
445 if i != centerReceiverIndex:
425 pairslist.append((centerReceiverIndex,i))
446 pairslist.append((centerReceiverIndex,i))
426
447
427 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
448 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
428 # see if the user put in pre defined phase shifts
449 # see if the user put in pre defined phase shifts
429 voltsPShift = self.dataOut.data_pre.copy()
450 voltsPShift = self.dataOut.data_pre.copy()
430
451
431 if predefinedPhaseShifts != None:
452 if predefinedPhaseShifts != None:
432 hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
453 hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
433 else:
454
455 elif beaconPhaseShifts:
434 #get hardware phase shifts using beacon signal
456 #get hardware phase shifts using beacon signal
435 hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
457 hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
436 hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
458 hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
437
459
460 else:
461 hardwarePhaseShifts = numpy.zeros(5)
462
463
438 voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
464 voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
439 for i in range(self.dataOut.data_pre.shape[0]):
465 for i in range(self.dataOut.data_pre.shape[0]):
440 voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
466 voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
467
468
441 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
469 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
442
470
443 #Remove DC
471 #Remove DC
444 voltsDC = numpy.mean(voltsPShift,1)
472 voltsDC = numpy.mean(voltsPShift,1)
445 voltsDC = numpy.mean(voltsDC,1)
473 voltsDC = numpy.mean(voltsDC,1)
446 for i in range(voltsDC.shape[0]):
474 for i in range(voltsDC.shape[0]):
447 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
475 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
448
476
449 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
477 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
450 voltsPShift = voltsPShift[:,:,:newheis[0][0]]
478 voltsPShift = voltsPShift[:,:,:newheis[0][0]]
451
479
452 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
480 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
453 #Coherent Detection
481 #Coherent Detection
454 if cohDetection:
482 if cohDetection:
455 #use coherent detection to get the net power
483 #use coherent detection to get the net power
456 cohDet_thresh = cohDet_thresh*numpy.pi/180
484 cohDet_thresh = cohDet_thresh*numpy.pi/180
457 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, self.dataOut.timeInterval, pairslist, cohDet_thresh)
485 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, self.dataOut.timeInterval, pairslist, cohDet_thresh)
458
486
459 #Non-coherent detection!
487 #Non-coherent detection!
460 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
488 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
461 #********** END OF COH/NON-COH POWER CALCULATION**********************
489 #********** END OF COH/NON-COH POWER CALCULATION**********************
462
490
463 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
491 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
464 #Get noise
492 #Get noise
465 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, self.dataOut.timeInterval)
493 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, self.dataOut.timeInterval)
466 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
494 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
467 #Get signal threshold
495 #Get signal threshold
468 signalThresh = noise_multiple*noise
496 signalThresh = noise_multiple*noise
469 #Meteor echoes detection
497 #Meteor echoes detection
470 listMeteors = self.__findMeteors(powerNet, signalThresh)
498 listMeteors = self.__findMeteors(powerNet, signalThresh)
471 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
499 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
472
500
473 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
501 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
474 #Parameters
502 #Parameters
475 heiRange = self.dataOut.getHeiRange()
503 heiRange = self.dataOut.getHeiRange()
476 rangeInterval = heiRange[1] - heiRange[0]
504 rangeInterval = heiRange[1] - heiRange[0]
477 rangeLimit = multDet_rangeLimit/rangeInterval
505 rangeLimit = multDet_rangeLimit/rangeInterval
478 timeLimit = multDet_timeLimit/self.dataOut.timeInterval
506 timeLimit = multDet_timeLimit/self.dataOut.timeInterval
479 #Multiple detection removals
507 #Multiple detection removals
480 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
508 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
481 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
509 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
482
510
483 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
511 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
484 #Parameters
512 #Parameters
485 phaseThresh = phaseThresh*numpy.pi/180
513 phaseThresh = phaseThresh*numpy.pi/180
486 thresh = [phaseThresh, noise_multiple, SNRThresh]
514 thresh = [phaseThresh, noise_multiple, SNRThresh]
487 #Meteor reestimation (Errors N 1, 6, 12, 17)
515 #Meteor reestimation (Errors N 1, 6, 12, 17)
488 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist, thresh, noise, self.dataOut.timeInterval, self.dataOut.frequency)
516 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist, thresh, noise, self.dataOut.timeInterval, self.dataOut.frequency)
489 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
517 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
490 #Estimation of decay times (Errors N 7, 8, 11)
518 #Estimation of decay times (Errors N 7, 8, 11)
491 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, self.dataOut.timeInterval, self.dataOut.frequency)
519 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, self.dataOut.timeInterval, self.dataOut.frequency)
492 #******************* END OF METEOR REESTIMATION *******************
520 #******************* END OF METEOR REESTIMATION *******************
493
521
494 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
522 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
495 #Calculating Radial Velocity (Error N 15)
523 #Calculating Radial Velocity (Error N 15)
496 radialStdThresh = 10
524 radialStdThresh = 10
497 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist, self.dataOut.timeInterval)
525 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist, self.dataOut.timeInterval)
498
526
499 if len(listMeteors4) > 0:
527 if len(listMeteors4) > 0:
500 #Setting New Array
501 date = repr(self.dataOut.datatime)
502 arrayMeteors4, arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
503
528
504 #Calculate AOA (Error N 3, 4)
505 #JONES ET AL. 1998
506 AOAthresh = numpy.pi/8
507 error = arrayParameters[:,-1]
508 phases = -arrayMeteors4[:,9:13]
509 pairsList = []
529 pairsList = []
510 pairsList.append((0,3))
530 pairx = (0,3)
511 pairsList.append((1,2))
531 pairy = (1,2)
512 arrayParameters[:,4:7], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, error, AOAthresh, azimuth)
532 pairsList.append(pairx)
533 pairsList.append(pairy)
513
534
514 #Calculate Heights (Error N 13 and 14)
535 #Setting New Array
515 error = arrayParameters[:,-1]
536 date = repr(self.dataOut.datatime)
516 Ranges = arrayParameters[:,2]
537 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
517 zenith = arrayParameters[:,5]
538
518 arrayParameters[:,3], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
539 meteorOps = MeteorOperations()
540 jph = numpy.array([0,0,0,0])
541 h = (hmin,hmax)
542 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, jph)
543
544 # #Calculate AOA (Error N 3, 4)
545 # #JONES ET AL. 1998
546 # error = arrayParameters[:,-1]
547 # AOAthresh = numpy.pi/8
548 # phases = -arrayParameters[:,9:13]
549 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
550 #
551 # #Calculate Heights (Error N 13 and 14)
552 # error = arrayParameters[:,-1]
553 # Ranges = arrayParameters[:,2]
554 # zenith = arrayParameters[:,5]
555 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
556 # error = arrayParameters[:,-1]
519 #********************* END OF PARAMETERS CALCULATION **************************
557 #********************* END OF PARAMETERS CALCULATION **************************
520
558
521 #***************************+ SAVE DATA IN HDF5 FORMAT **********************
559 #***************************+ PASS DATA TO NEXT STEP **********************
522 self.dataOut.data_param = arrayParameters
560 arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
561 self.dataOut.data_param = arrayFinal
523
562
524 return
563 return
525
564
526 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
565 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
527
566
528 minIndex = min(newheis[0])
567 minIndex = min(newheis[0])
529 maxIndex = max(newheis[0])
568 maxIndex = max(newheis[0])
530
569
531 voltage = voltage0[:,:,minIndex:maxIndex+1]
570 voltage = voltage0[:,:,minIndex:maxIndex+1]
532 nLength = voltage.shape[1]/n
571 nLength = voltage.shape[1]/n
533 nMin = 0
572 nMin = 0
534 nMax = 0
573 nMax = 0
535 phaseOffset = numpy.zeros((len(pairslist),n))
574 phaseOffset = numpy.zeros((len(pairslist),n))
536
575
537 for i in range(n):
576 for i in range(n):
538 nMax += nLength
577 nMax += nLength
539 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
578 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
540 phaseCCF = numpy.mean(phaseCCF, axis = 2)
579 phaseCCF = numpy.mean(phaseCCF, axis = 2)
541 phaseOffset[:,i] = phaseCCF.transpose()
580 phaseOffset[:,i] = phaseCCF.transpose()
542 nMin = nMax
581 nMin = nMax
543 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
582 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
544
583
545 #Remove Outliers
584 #Remove Outliers
546 factor = 2
585 factor = 2
547 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
586 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
548 dw = numpy.std(wt,axis = 1)
587 dw = numpy.std(wt,axis = 1)
549 dw = dw.reshape((dw.size,1))
588 dw = dw.reshape((dw.size,1))
550 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
589 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
551 phaseOffset[ind] = numpy.nan
590 phaseOffset[ind] = numpy.nan
552 phaseOffset = stats.nanmean(phaseOffset, axis=1)
591 phaseOffset = stats.nanmean(phaseOffset, axis=1)
553
592
554 return phaseOffset
593 return phaseOffset
555
594
556 def __shiftPhase(self, data, phaseShift):
595 def __shiftPhase(self, data, phaseShift):
557 #this will shift the phase of a complex number
596 #this will shift the phase of a complex number
558 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
597 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
559 return dataShifted
598 return dataShifted
560
599
561 def __estimatePhaseDifference(self, array, pairslist):
600 def __estimatePhaseDifference(self, array, pairslist):
562 nChannel = array.shape[0]
601 nChannel = array.shape[0]
563 nHeights = array.shape[2]
602 nHeights = array.shape[2]
564 numPairs = len(pairslist)
603 numPairs = len(pairslist)
565 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
604 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
566 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
605 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
567
606
568 #Correct phases
607 #Correct phases
569 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
608 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
570 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
609 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
571
610
572 if indDer[0].shape[0] > 0:
611 if indDer[0].shape[0] > 0:
573 for i in range(indDer[0].shape[0]):
612 for i in range(indDer[0].shape[0]):
574 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
613 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
575 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
614 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
576
615
577 # for j in range(numSides):
616 # for j in range(numSides):
578 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
617 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
579 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
618 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
580 #
619 #
581 #Linear
620 #Linear
582 phaseInt = numpy.zeros((numPairs,1))
621 phaseInt = numpy.zeros((numPairs,1))
583 angAllCCF = phaseCCF[:,[0,1,3,4],0]
622 angAllCCF = phaseCCF[:,[0,1,3,4],0]
584 for j in range(numPairs):
623 for j in range(numPairs):
585 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
624 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
586 phaseInt[j] = fit[1]
625 phaseInt[j] = fit[1]
587 #Phase Differences
626 #Phase Differences
588 phaseDiff = phaseInt - phaseCCF[:,2,:]
627 phaseDiff = phaseInt - phaseCCF[:,2,:]
589 phaseArrival = phaseInt.reshape(phaseInt.size)
628 phaseArrival = phaseInt.reshape(phaseInt.size)
590
629
591 #Dealias
630 #Dealias
592 indAlias = numpy.where(phaseArrival > numpy.pi)
631 indAlias = numpy.where(phaseArrival > numpy.pi)
593 phaseArrival[indAlias] -= 2*numpy.pi
632 phaseArrival[indAlias] -= 2*numpy.pi
594 indAlias = numpy.where(phaseArrival < -numpy.pi)
633 indAlias = numpy.where(phaseArrival < -numpy.pi)
595 phaseArrival[indAlias] += 2*numpy.pi
634 phaseArrival[indAlias] += 2*numpy.pi
596
635
597 return phaseDiff, phaseArrival
636 return phaseDiff, phaseArrival
598
637
599 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
638 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
600 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
639 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
601 #find the phase shifts of each channel over 1 second intervals
640 #find the phase shifts of each channel over 1 second intervals
602 #only look at ranges below the beacon signal
641 #only look at ranges below the beacon signal
603 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
642 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
604 numBlocks = int(volts.shape[1]/numProfPerBlock)
643 numBlocks = int(volts.shape[1]/numProfPerBlock)
605 numHeights = volts.shape[2]
644 numHeights = volts.shape[2]
606 nChannel = volts.shape[0]
645 nChannel = volts.shape[0]
607 voltsCohDet = volts.copy()
646 voltsCohDet = volts.copy()
608
647
609 pairsarray = numpy.array(pairslist)
648 pairsarray = numpy.array(pairslist)
610 indSides = pairsarray[:,1]
649 indSides = pairsarray[:,1]
611 # indSides = numpy.array(range(nChannel))
650 # indSides = numpy.array(range(nChannel))
612 # indSides = numpy.delete(indSides, indCenter)
651 # indSides = numpy.delete(indSides, indCenter)
613 #
652 #
614 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
653 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
615 listBlocks = numpy.array_split(volts, numBlocks, 1)
654 listBlocks = numpy.array_split(volts, numBlocks, 1)
616
655
617 startInd = 0
656 startInd = 0
618 endInd = 0
657 endInd = 0
619
658
620 for i in range(numBlocks):
659 for i in range(numBlocks):
621 startInd = endInd
660 startInd = endInd
622 endInd = endInd + listBlocks[i].shape[1]
661 endInd = endInd + listBlocks[i].shape[1]
623
662
624 arrayBlock = listBlocks[i]
663 arrayBlock = listBlocks[i]
625 # arrayBlockCenter = listCenter[i]
664 # arrayBlockCenter = listCenter[i]
626
665
627 #Estimate the Phase Difference
666 #Estimate the Phase Difference
628 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
667 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
629 #Phase Difference RMS
668 #Phase Difference RMS
630 arrayPhaseRMS = numpy.abs(phaseDiff)
669 arrayPhaseRMS = numpy.abs(phaseDiff)
631 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
670 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
632 indPhase = numpy.where(phaseRMSaux==4)
671 indPhase = numpy.where(phaseRMSaux==4)
633 #Shifting
672 #Shifting
634 if indPhase[0].shape[0] > 0:
673 if indPhase[0].shape[0] > 0:
635 for j in range(indSides.size):
674 for j in range(indSides.size):
636 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
675 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
637 voltsCohDet[:,startInd:endInd,:] = arrayBlock
676 voltsCohDet[:,startInd:endInd,:] = arrayBlock
638
677
639 return voltsCohDet
678 return voltsCohDet
640
679
641 def __calculateCCF(self, volts, pairslist ,laglist):
680 def __calculateCCF(self, volts, pairslist ,laglist):
642
681
643 nHeights = volts.shape[2]
682 nHeights = volts.shape[2]
644 nPoints = volts.shape[1]
683 nPoints = volts.shape[1]
645 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
684 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
646
685
647 for i in range(len(pairslist)):
686 for i in range(len(pairslist)):
648 volts1 = volts[pairslist[i][0]]
687 volts1 = volts[pairslist[i][0]]
649 volts2 = volts[pairslist[i][1]]
688 volts2 = volts[pairslist[i][1]]
650
689
651 for t in range(len(laglist)):
690 for t in range(len(laglist)):
652 idxT = laglist[t]
691 idxT = laglist[t]
653 if idxT >= 0:
692 if idxT >= 0:
654 vStacked = numpy.vstack((volts2[idxT:,:],
693 vStacked = numpy.vstack((volts2[idxT:,:],
655 numpy.zeros((idxT, nHeights),dtype='complex')))
694 numpy.zeros((idxT, nHeights),dtype='complex')))
656 else:
695 else:
657 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
696 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
658 volts2[:(nPoints + idxT),:]))
697 volts2[:(nPoints + idxT),:]))
659 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
698 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
660
699
661 vStacked = None
700 vStacked = None
662 return voltsCCF
701 return voltsCCF
663
702
664 def __getNoise(self, power, timeSegment, timeInterval):
703 def __getNoise(self, power, timeSegment, timeInterval):
665 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
704 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
666 numBlocks = int(power.shape[0]/numProfPerBlock)
705 numBlocks = int(power.shape[0]/numProfPerBlock)
667 numHeights = power.shape[1]
706 numHeights = power.shape[1]
668
707
669 listPower = numpy.array_split(power, numBlocks, 0)
708 listPower = numpy.array_split(power, numBlocks, 0)
670 noise = numpy.zeros((power.shape[0], power.shape[1]))
709 noise = numpy.zeros((power.shape[0], power.shape[1]))
671 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
710 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
672
711
673 startInd = 0
712 startInd = 0
674 endInd = 0
713 endInd = 0
675
714
676 for i in range(numBlocks): #split por canal
715 for i in range(numBlocks): #split por canal
677 startInd = endInd
716 startInd = endInd
678 endInd = endInd + listPower[i].shape[0]
717 endInd = endInd + listPower[i].shape[0]
679
718
680 arrayBlock = listPower[i]
719 arrayBlock = listPower[i]
681 noiseAux = numpy.mean(arrayBlock, 0)
720 noiseAux = numpy.mean(arrayBlock, 0)
682 # noiseAux = numpy.median(noiseAux)
721 # noiseAux = numpy.median(noiseAux)
683 # noiseAux = numpy.mean(arrayBlock)
722 # noiseAux = numpy.mean(arrayBlock)
684 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
723 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
685
724
686 noiseAux1 = numpy.mean(arrayBlock)
725 noiseAux1 = numpy.mean(arrayBlock)
687 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
726 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
688
727
689 return noise, noise1
728 return noise, noise1
690
729
691 def __findMeteors(self, power, thresh):
730 def __findMeteors(self, power, thresh):
692 nProf = power.shape[0]
731 nProf = power.shape[0]
693 nHeights = power.shape[1]
732 nHeights = power.shape[1]
694 listMeteors = []
733 listMeteors = []
695
734
696 for i in range(nHeights):
735 for i in range(nHeights):
697 powerAux = power[:,i]
736 powerAux = power[:,i]
698 threshAux = thresh[:,i]
737 threshAux = thresh[:,i]
699
738
700 indUPthresh = numpy.where(powerAux > threshAux)[0]
739 indUPthresh = numpy.where(powerAux > threshAux)[0]
701 indDNthresh = numpy.where(powerAux <= threshAux)[0]
740 indDNthresh = numpy.where(powerAux <= threshAux)[0]
702
741
703 j = 0
742 j = 0
704
743
705 while (j < indUPthresh.size - 2):
744 while (j < indUPthresh.size - 2):
706 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
745 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
707 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
746 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
708 indDNthresh = indDNthresh[indDNAux]
747 indDNthresh = indDNthresh[indDNAux]
709
748
710 if (indDNthresh.size > 0):
749 if (indDNthresh.size > 0):
711 indEnd = indDNthresh[0] - 1
750 indEnd = indDNthresh[0] - 1
712 indInit = indUPthresh[j]
751 indInit = indUPthresh[j]
713
752
714 meteor = powerAux[indInit:indEnd + 1]
753 meteor = powerAux[indInit:indEnd + 1]
715 indPeak = meteor.argmax() + indInit
754 indPeak = meteor.argmax() + indInit
716 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
755 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
717
756
718 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
757 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
719 j = numpy.where(indUPthresh == indEnd)[0] + 1
758 j = numpy.where(indUPthresh == indEnd)[0] + 1
720 else: j+=1
759 else: j+=1
721 else: j+=1
760 else: j+=1
722
761
723 return listMeteors
762 return listMeteors
724
763
725 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
764 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
726
765
727 arrayMeteors = numpy.asarray(listMeteors)
766 arrayMeteors = numpy.asarray(listMeteors)
728 listMeteors1 = []
767 listMeteors1 = []
729
768
730 while arrayMeteors.shape[0] > 0:
769 while arrayMeteors.shape[0] > 0:
731 FLAs = arrayMeteors[:,4]
770 FLAs = arrayMeteors[:,4]
732 maxFLA = FLAs.argmax()
771 maxFLA = FLAs.argmax()
733 listMeteors1.append(arrayMeteors[maxFLA,:])
772 listMeteors1.append(arrayMeteors[maxFLA,:])
734
773
735 MeteorInitTime = arrayMeteors[maxFLA,1]
774 MeteorInitTime = arrayMeteors[maxFLA,1]
736 MeteorEndTime = arrayMeteors[maxFLA,3]
775 MeteorEndTime = arrayMeteors[maxFLA,3]
737 MeteorHeight = arrayMeteors[maxFLA,0]
776 MeteorHeight = arrayMeteors[maxFLA,0]
738
777
739 #Check neighborhood
778 #Check neighborhood
740 maxHeightIndex = MeteorHeight + rangeLimit
779 maxHeightIndex = MeteorHeight + rangeLimit
741 minHeightIndex = MeteorHeight - rangeLimit
780 minHeightIndex = MeteorHeight - rangeLimit
742 minTimeIndex = MeteorInitTime - timeLimit
781 minTimeIndex = MeteorInitTime - timeLimit
743 maxTimeIndex = MeteorEndTime + timeLimit
782 maxTimeIndex = MeteorEndTime + timeLimit
744
783
745 #Check Heights
784 #Check Heights
746 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
785 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
747 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
786 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
748 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
787 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
749
788
750 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
789 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
751
790
752 return listMeteors1
791 return listMeteors1
753
792
754 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
793 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
755 numHeights = volts.shape[2]
794 numHeights = volts.shape[2]
756 nChannel = volts.shape[0]
795 nChannel = volts.shape[0]
757
796
758 thresholdPhase = thresh[0]
797 thresholdPhase = thresh[0]
759 thresholdNoise = thresh[1]
798 thresholdNoise = thresh[1]
760 thresholdDB = float(thresh[2])
799 thresholdDB = float(thresh[2])
761
800
762 thresholdDB1 = 10**(thresholdDB/10)
801 thresholdDB1 = 10**(thresholdDB/10)
763 pairsarray = numpy.array(pairslist)
802 pairsarray = numpy.array(pairslist)
764 indSides = pairsarray[:,1]
803 indSides = pairsarray[:,1]
765
804
766 pairslist1 = list(pairslist)
805 pairslist1 = list(pairslist)
767 pairslist1.append((0,1))
806 pairslist1.append((0,1))
768 pairslist1.append((3,4))
807 pairslist1.append((3,4))
769
808
770 listMeteors1 = []
809 listMeteors1 = []
771 listPowerSeries = []
810 listPowerSeries = []
772 listVoltageSeries = []
811 listVoltageSeries = []
773 #volts has the war data
812 #volts has the war data
774
813
775 if frequency == 30e6:
814 if frequency == 30e6:
776 timeLag = 45*10**-3
815 timeLag = 45*10**-3
777 else:
816 else:
778 timeLag = 15*10**-3
817 timeLag = 15*10**-3
779 lag = numpy.ceil(timeLag/timeInterval)
818 lag = numpy.ceil(timeLag/timeInterval)
780
819
781 for i in range(len(listMeteors)):
820 for i in range(len(listMeteors)):
782
821
783 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
822 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
784 meteorAux = numpy.zeros(16)
823 meteorAux = numpy.zeros(16)
785
824
786 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
825 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
787 mHeight = listMeteors[i][0]
826 mHeight = listMeteors[i][0]
788 mStart = listMeteors[i][1]
827 mStart = listMeteors[i][1]
789 mPeak = listMeteors[i][2]
828 mPeak = listMeteors[i][2]
790 mEnd = listMeteors[i][3]
829 mEnd = listMeteors[i][3]
791
830
792 #get the volt data between the start and end times of the meteor
831 #get the volt data between the start and end times of the meteor
793 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
832 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
794 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
833 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
795
834
796 #3.6. Phase Difference estimation
835 #3.6. Phase Difference estimation
797 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
836 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
798
837
799 #3.7. Phase difference removal & meteor start, peak and end times reestimated
838 #3.7. Phase difference removal & meteor start, peak and end times reestimated
800 #meteorVolts0.- all Channels, all Profiles
839 #meteorVolts0.- all Channels, all Profiles
801 meteorVolts0 = volts[:,:,mHeight]
840 meteorVolts0 = volts[:,:,mHeight]
802 meteorThresh = noise[:,mHeight]*thresholdNoise
841 meteorThresh = noise[:,mHeight]*thresholdNoise
803 meteorNoise = noise[:,mHeight]
842 meteorNoise = noise[:,mHeight]
804 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
843 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
805 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
844 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
806
845
807 #Times reestimation
846 #Times reestimation
808 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
847 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
809 if mStart1.size > 0:
848 if mStart1.size > 0:
810 mStart1 = mStart1[-1] + 1
849 mStart1 = mStart1[-1] + 1
811
850
812 else:
851 else:
813 mStart1 = mPeak
852 mStart1 = mPeak
814
853
815 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
854 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
816 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
855 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
817 if mEndDecayTime1.size == 0:
856 if mEndDecayTime1.size == 0:
818 mEndDecayTime1 = powerNet0.size
857 mEndDecayTime1 = powerNet0.size
819 else:
858 else:
820 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
859 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
821 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
860 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
822
861
823 #meteorVolts1.- all Channels, from start to end
862 #meteorVolts1.- all Channels, from start to end
824 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
863 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
825 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
864 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
826 if meteorVolts2.shape[1] == 0:
865 if meteorVolts2.shape[1] == 0:
827 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
866 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
828 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
867 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
829 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
868 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
830 ##################### END PARAMETERS REESTIMATION #########################
869 ##################### END PARAMETERS REESTIMATION #########################
831
870
832 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
871 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
833 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
872 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
834 if meteorVolts2.shape[1] > 0:
873 if meteorVolts2.shape[1] > 0:
835 #Phase Difference re-estimation
874 #Phase Difference re-estimation
836 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
875 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
837 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
876 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
838 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
877 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
839 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
878 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
840 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
879 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
841
880
842 #Phase Difference RMS
881 #Phase Difference RMS
843 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
882 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
844 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
883 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
845 #Data from Meteor
884 #Data from Meteor
846 mPeak1 = powerNet1.argmax() + mStart1
885 mPeak1 = powerNet1.argmax() + mStart1
847 mPeakPower1 = powerNet1.max()
886 mPeakPower1 = powerNet1.max()
848 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
887 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
849 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
888 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
850 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
889 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
851 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
890 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
852 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
891 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
853 #Vectorize
892 #Vectorize
854 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
893 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
855 meteorAux[7:11] = phaseDiffint[0:4]
894 meteorAux[7:11] = phaseDiffint[0:4]
856
895
857 #Rejection Criterions
896 #Rejection Criterions
858 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
897 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
859 meteorAux[-1] = 17
898 meteorAux[-1] = 17
860 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
899 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
861 meteorAux[-1] = 1
900 meteorAux[-1] = 1
862
901
863
902
864 else:
903 else:
865 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
904 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
866 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
905 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
867 PowerSeries = 0
906 PowerSeries = 0
868
907
869 listMeteors1.append(meteorAux)
908 listMeteors1.append(meteorAux)
870 listPowerSeries.append(PowerSeries)
909 listPowerSeries.append(PowerSeries)
871 listVoltageSeries.append(meteorVolts1)
910 listVoltageSeries.append(meteorVolts1)
872
911
873 return listMeteors1, listPowerSeries, listVoltageSeries
912 return listMeteors1, listPowerSeries, listVoltageSeries
874
913
875 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
914 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
876
915
877 threshError = 10
916 threshError = 10
878 #Depending if it is 30 or 50 MHz
917 #Depending if it is 30 or 50 MHz
879 if frequency == 30e6:
918 if frequency == 30e6:
880 timeLag = 45*10**-3
919 timeLag = 45*10**-3
881 else:
920 else:
882 timeLag = 15*10**-3
921 timeLag = 15*10**-3
883 lag = numpy.ceil(timeLag/timeInterval)
922 lag = numpy.ceil(timeLag/timeInterval)
884
923
885 listMeteors1 = []
924 listMeteors1 = []
886
925
887 for i in range(len(listMeteors)):
926 for i in range(len(listMeteors)):
888 meteorPower = listPower[i]
927 meteorPower = listPower[i]
889 meteorAux = listMeteors[i]
928 meteorAux = listMeteors[i]
890
929
891 if meteorAux[-1] == 0:
930 if meteorAux[-1] == 0:
892
931
893 try:
932 try:
894 indmax = meteorPower.argmax()
933 indmax = meteorPower.argmax()
895 indlag = indmax + lag
934 indlag = indmax + lag
896
935
897 y = meteorPower[indlag:]
936 y = meteorPower[indlag:]
898 x = numpy.arange(0, y.size)*timeLag
937 x = numpy.arange(0, y.size)*timeLag
899
938
900 #first guess
939 #first guess
901 a = y[0]
940 a = y[0]
902 tau = timeLag
941 tau = timeLag
903 #exponential fit
942 #exponential fit
904 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
943 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
905 y1 = self.__exponential_function(x, *popt)
944 y1 = self.__exponential_function(x, *popt)
906 #error estimation
945 #error estimation
907 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
946 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
908
947
909 decayTime = popt[1]
948 decayTime = popt[1]
910 riseTime = indmax*timeInterval
949 riseTime = indmax*timeInterval
911 meteorAux[11:13] = [decayTime, error]
950 meteorAux[11:13] = [decayTime, error]
912
951
913 #Table items 7, 8 and 11
952 #Table items 7, 8 and 11
914 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
953 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
915 meteorAux[-1] = 7
954 meteorAux[-1] = 7
916 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
955 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
917 meteorAux[-1] = 8
956 meteorAux[-1] = 8
918 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
957 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
919 meteorAux[-1] = 11
958 meteorAux[-1] = 11
920
959
921
960
922 except:
961 except:
923 meteorAux[-1] = 11
962 meteorAux[-1] = 11
924
963
925
964
926 listMeteors1.append(meteorAux)
965 listMeteors1.append(meteorAux)
927
966
928 return listMeteors1
967 return listMeteors1
929
968
930 #Exponential Function
969 #Exponential Function
931
970
932 def __exponential_function(self, x, a, tau):
971 def __exponential_function(self, x, a, tau):
933 y = a*numpy.exp(-x/tau)
972 y = a*numpy.exp(-x/tau)
934 return y
973 return y
935
974
936 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
975 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
937
976
938 pairslist1 = list(pairslist)
977 pairslist1 = list(pairslist)
939 pairslist1.append((0,1))
978 pairslist1.append((0,1))
940 pairslist1.append((3,4))
979 pairslist1.append((3,4))
941 numPairs = len(pairslist1)
980 numPairs = len(pairslist1)
942 #Time Lag
981 #Time Lag
943 timeLag = 45*10**-3
982 timeLag = 45*10**-3
944 c = 3e8
983 c = 3e8
945 lag = numpy.ceil(timeLag/timeInterval)
984 lag = numpy.ceil(timeLag/timeInterval)
946 freq = 30e6
985 freq = 30e6
947
986
948 listMeteors1 = []
987 listMeteors1 = []
949
988
950 for i in range(len(listMeteors)):
989 for i in range(len(listMeteors)):
951 meteor = listMeteors[i]
990 meteorAux = listMeteors[i]
952 meteorAux = numpy.hstack((meteor[:-1], 0, 0, meteor[-1]))
991 if meteorAux[-1] == 0:
953 if meteor[-1] == 0:
954 mStart = listMeteors[i][1]
992 mStart = listMeteors[i][1]
955 mPeak = listMeteors[i][2]
993 mPeak = listMeteors[i][2]
956 mLag = mPeak - mStart + lag
994 mLag = mPeak - mStart + lag
957
995
958 #get the volt data between the start and end times of the meteor
996 #get the volt data between the start and end times of the meteor
959 meteorVolts = listVolts[i]
997 meteorVolts = listVolts[i]
960 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
998 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
961
999
962 #Get CCF
1000 #Get CCF
963 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
1001 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
964
1002
965 #Method 2
1003 #Method 2
966 slopes = numpy.zeros(numPairs)
1004 slopes = numpy.zeros(numPairs)
967 time = numpy.array([-2,-1,1,2])*timeInterval
1005 time = numpy.array([-2,-1,1,2])*timeInterval
968 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
1006 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
969
1007
970 #Correct phases
1008 #Correct phases
971 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
1009 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
972 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
1010 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
973
1011
974 if indDer[0].shape[0] > 0:
1012 if indDer[0].shape[0] > 0:
975 for i in range(indDer[0].shape[0]):
1013 for i in range(indDer[0].shape[0]):
976 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
1014 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
977 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
1015 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
978
1016
979 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
1017 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
980 for j in range(numPairs):
1018 for j in range(numPairs):
981 fit = stats.linregress(time, angAllCCF[j,:])
1019 fit = stats.linregress(time, angAllCCF[j,:])
982 slopes[j] = fit[0]
1020 slopes[j] = fit[0]
983
1021
984 #Remove Outlier
1022 #Remove Outlier
985 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
1023 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
986 # slopes = numpy.delete(slopes,indOut)
1024 # slopes = numpy.delete(slopes,indOut)
987 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
1025 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
988 # slopes = numpy.delete(slopes,indOut)
1026 # slopes = numpy.delete(slopes,indOut)
989
1027
990 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
1028 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
991 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
1029 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
992 meteorAux[-2] = radialError
1030 meteorAux[-2] = radialError
993 meteorAux[-3] = radialVelocity
1031 meteorAux[-3] = radialVelocity
994
1032
995 #Setting Error
1033 #Setting Error
996 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
1034 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
997 if numpy.abs(radialVelocity) > 200:
1035 if numpy.abs(radialVelocity) > 200:
998 meteorAux[-1] = 15
1036 meteorAux[-1] = 15
999 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
1037 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
1000 elif radialError > radialStdThresh:
1038 elif radialError > radialStdThresh:
1001 meteorAux[-1] = 12
1039 meteorAux[-1] = 12
1002
1040
1003 listMeteors1.append(meteorAux)
1041 listMeteors1.append(meteorAux)
1004 return listMeteors1
1042 return listMeteors1
1005
1043
1006 def __setNewArrays(self, listMeteors, date, heiRang):
1044 def __setNewArrays(self, listMeteors, date, heiRang):
1007
1045
1008 #New arrays
1046 #New arrays
1009 arrayMeteors = numpy.array(listMeteors)
1047 arrayMeteors = numpy.array(listMeteors)
1010 arrayParameters = numpy.zeros((len(listMeteors),10))
1048 arrayParameters = numpy.zeros((len(listMeteors), 14))
1011
1049
1012 #Date inclusion
1050 #Date inclusion
1013 date = re.findall(r'\((.*?)\)', date)
1051 date = re.findall(r'\((.*?)\)', date)
1014 date = date[0].split(',')
1052 date = date[0].split(',')
1015 date = map(int, date)
1053 date = map(int, date)
1016 date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
1054 date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
1017 arrayDate = numpy.tile(date, (len(listMeteors), 1))
1055 arrayDate = numpy.tile(date, (len(listMeteors), 1))
1018
1056
1019 #Meteor array
1057 #Meteor array
1020 arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
1058 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
1021 arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
1059 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
1022
1060
1023 #Parameters Array
1061 #Parameters Array
1024 arrayParameters[:,0:3] = arrayMeteors[:,0:3]
1062 arrayParameters[:,:2] = arrayDate #Date
1025 arrayParameters[:,-3:] = arrayMeteors[:,-3:]
1063 arrayParameters[:,2] = heiRang[arrayMeteors[:,0].astype(int)] #Range
1064 arrayParameters[:,7:9] = arrayMeteors[:,-3:-1] #Radial velocity and its error
1065 arrayParameters[:,9:13] = arrayMeteors[:,7:11] #Phases
1066 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
1067
1026
1068
1027 return arrayMeteors, arrayParameters
1069 return arrayParameters
1028
1070
1029 def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
1071 def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
1030
1072
1031 arrayAOA = numpy.zeros((phases.shape[0],3))
1073 arrayAOA = numpy.zeros((phases.shape[0],3))
1032 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
1074 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
1033
1075
1034 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
1076 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
1035 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
1077 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
1036 arrayAOA[:,2] = cosDirError
1078 arrayAOA[:,2] = cosDirError
1037
1079
1038 azimuthAngle = arrayAOA[:,0]
1080 azimuthAngle = arrayAOA[:,0]
1039 zenithAngle = arrayAOA[:,1]
1081 zenithAngle = arrayAOA[:,1]
1040
1082
1041 #Setting Error
1083 #Setting Error
1042 #Number 3: AOA not fesible
1084 #Number 3: AOA not fesible
1043 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
1085 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
1044 error[indInvalid] = 3
1086 error[indInvalid] = 3
1045 #Number 4: Large difference in AOAs obtained from different antenna baselines
1087 #Number 4: Large difference in AOAs obtained from different antenna baselines
1046 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
1088 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
1047 error[indInvalid] = 4
1089 error[indInvalid] = 4
1048 return arrayAOA, error
1090 return arrayAOA, error
1049
1091
1050 def __getDirectionCosines(self, arrayPhase, pairsList):
1092 def __getDirectionCosines(self, arrayPhase, pairsList):
1051
1093
1052 #Initializing some variables
1094 #Initializing some variables
1053 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
1095 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
1054 ang_aux = ang_aux.reshape(1,ang_aux.size)
1096 ang_aux = ang_aux.reshape(1,ang_aux.size)
1055
1097
1056 cosdir = numpy.zeros((arrayPhase.shape[0],2))
1098 cosdir = numpy.zeros((arrayPhase.shape[0],2))
1057 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
1099 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
1058
1100
1059
1101
1060 for i in range(2):
1102 for i in range(2):
1061 #First Estimation
1103 #First Estimation
1062 phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
1104 phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
1063 #Dealias
1105 #Dealias
1064 indcsi = numpy.where(phi0_aux > numpy.pi)
1106 indcsi = numpy.where(phi0_aux > numpy.pi)
1065 phi0_aux[indcsi] -= 2*numpy.pi
1107 phi0_aux[indcsi] -= 2*numpy.pi
1066 indcsi = numpy.where(phi0_aux < -numpy.pi)
1108 indcsi = numpy.where(phi0_aux < -numpy.pi)
1067 phi0_aux[indcsi] += 2*numpy.pi
1109 phi0_aux[indcsi] += 2*numpy.pi
1068 #Direction Cosine 0
1110 #Direction Cosine 0
1069 cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
1111 cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
1070
1112
1071 #Most-Accurate Second Estimation
1113 #Most-Accurate Second Estimation
1072 phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
1114 phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
1073 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
1115 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
1074 #Direction Cosine 1
1116 #Direction Cosine 1
1075 cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
1117 cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
1076
1118
1077 #Searching the correct Direction Cosine
1119 #Searching the correct Direction Cosine
1078 cosdir0_aux = cosdir0[:,i]
1120 cosdir0_aux = cosdir0[:,i]
1079 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
1121 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
1080 #Minimum Distance
1122 #Minimum Distance
1081 cosDiff = (cosdir1 - cosdir0_aux)**2
1123 cosDiff = (cosdir1 - cosdir0_aux)**2
1082 indcos = cosDiff.argmin(axis = 1)
1124 indcos = cosDiff.argmin(axis = 1)
1083 #Saving Value obtained
1125 #Saving Value obtained
1084 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
1126 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
1085
1127
1086 return cosdir0, cosdir
1128 return cosdir0, cosdir
1087
1129
1088 def __calculateAOA(self, cosdir, azimuth):
1130 def __calculateAOA(self, cosdir, azimuth):
1089 cosdirX = cosdir[:,0]
1131 cosdirX = cosdir[:,0]
1090 cosdirY = cosdir[:,1]
1132 cosdirY = cosdir[:,1]
1091
1133
1092 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
1134 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
1093 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
1135 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
1094 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
1136 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
1095
1137
1096 return angles
1138 return angles
1097
1139
1098 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
1140 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
1099
1141
1100 Ramb = 375 #Ramb = c/(2*PRF)
1142 Ramb = 375 #Ramb = c/(2*PRF)
1101 Re = 6371 #Earth Radius
1143 Re = 6371 #Earth Radius
1102 heights = numpy.zeros(Ranges.shape)
1144 heights = numpy.zeros(Ranges.shape)
1103
1145
1104 R_aux = numpy.array([0,1,2])*Ramb
1146 R_aux = numpy.array([0,1,2])*Ramb
1105 R_aux = R_aux.reshape(1,R_aux.size)
1147 R_aux = R_aux.reshape(1,R_aux.size)
1106
1148
1107 Ranges = Ranges.reshape(Ranges.size,1)
1149 Ranges = Ranges.reshape(Ranges.size,1)
1108
1150
1109 Ri = Ranges + R_aux
1151 Ri = Ranges + R_aux
1110 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
1152 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
1111
1153
1112 #Check if there is a height between 70 and 110 km
1154 #Check if there is a height between 70 and 110 km
1113 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
1155 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
1114 ind_h = numpy.where(h_bool == 1)[0]
1156 ind_h = numpy.where(h_bool == 1)[0]
1115
1157
1116 hCorr = hi[ind_h, :]
1158 hCorr = hi[ind_h, :]
1117 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
1159 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
1118
1160
1119 hCorr = hi[ind_hCorr]
1161 hCorr = hi[ind_hCorr]
1120 heights[ind_h] = hCorr
1162 heights[ind_h] = hCorr
1121
1163
1122 #Setting Error
1164 #Setting Error
1123 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
1165 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
1124 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
1166 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
1125
1167
1126 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
1168 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
1127 error[indInvalid2] = 14
1169 error[indInvalid2] = 14
1128 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
1170 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
1129 error[indInvalid1] = 13
1171 error[indInvalid1] = 13
1130
1172
1131 return heights, error
1173 return heights, error
1132
1174
1133 def SpectralFitting(self, getSNR = True, path=None, file=None, groupList=None):
1175 def SpectralFitting(self, getSNR = True, path=None, file=None, groupList=None):
1134
1176
1135 '''
1177 '''
1136 Function GetMoments()
1178 Function GetMoments()
1137
1179
1138 Input:
1180 Input:
1139 Output:
1181 Output:
1140 Variables modified:
1182 Variables modified:
1141 '''
1183 '''
1142 if path != None:
1184 if path != None:
1143 sys.path.append(path)
1185 sys.path.append(path)
1144 self.dataOut.library = importlib.import_module(file)
1186 self.dataOut.library = importlib.import_module(file)
1145
1187
1146 #To be inserted as a parameter
1188 #To be inserted as a parameter
1147 groupArray = numpy.array(groupList)
1189 groupArray = numpy.array(groupList)
1148 # groupArray = numpy.array([[0,1],[2,3]])
1190 # groupArray = numpy.array([[0,1],[2,3]])
1149 self.dataOut.groupList = groupArray
1191 self.dataOut.groupList = groupArray
1150
1192
1151 nGroups = groupArray.shape[0]
1193 nGroups = groupArray.shape[0]
1152 nChannels = self.dataIn.nChannels
1194 nChannels = self.dataIn.nChannels
1153 nHeights=self.dataIn.heightList.size
1195 nHeights=self.dataIn.heightList.size
1154
1196
1155 #Parameters Array
1197 #Parameters Array
1156 self.dataOut.data_param = None
1198 self.dataOut.data_param = None
1157
1199
1158 #Set constants
1200 #Set constants
1159 constants = self.dataOut.library.setConstants(self.dataIn)
1201 constants = self.dataOut.library.setConstants(self.dataIn)
1160 self.dataOut.constants = constants
1202 self.dataOut.constants = constants
1161 M = self.dataIn.normFactor
1203 M = self.dataIn.normFactor
1162 N = self.dataIn.nFFTPoints
1204 N = self.dataIn.nFFTPoints
1163 ippSeconds = self.dataIn.ippSeconds
1205 ippSeconds = self.dataIn.ippSeconds
1164 K = self.dataIn.nIncohInt
1206 K = self.dataIn.nIncohInt
1165 pairsArray = numpy.array(self.dataIn.pairsList)
1207 pairsArray = numpy.array(self.dataIn.pairsList)
1166
1208
1167 #List of possible combinations
1209 #List of possible combinations
1168 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1210 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1169 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1211 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1170
1212
1171 if getSNR:
1213 if getSNR:
1172 listChannels = groupArray.reshape((groupArray.size))
1214 listChannels = groupArray.reshape((groupArray.size))
1173 listChannels.sort()
1215 listChannels.sort()
1174 noise = self.dataIn.getNoise()
1216 noise = self.dataIn.getNoise()
1175 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1217 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1176
1218
1177 for i in range(nGroups):
1219 for i in range(nGroups):
1178 coord = groupArray[i,:]
1220 coord = groupArray[i,:]
1179
1221
1180 #Input data array
1222 #Input data array
1181 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1223 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1182 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1224 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1183
1225
1184 #Cross Spectra data array for Covariance Matrixes
1226 #Cross Spectra data array for Covariance Matrixes
1185 ind = 0
1227 ind = 0
1186 for pairs in listComb:
1228 for pairs in listComb:
1187 pairsSel = numpy.array([coord[x],coord[y]])
1229 pairsSel = numpy.array([coord[x],coord[y]])
1188 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1230 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1189 ind += 1
1231 ind += 1
1190 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1232 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1191 dataCross = dataCross**2/K
1233 dataCross = dataCross**2/K
1192
1234
1193 for h in range(nHeights):
1235 for h in range(nHeights):
1194 # print self.dataOut.heightList[h]
1236 # print self.dataOut.heightList[h]
1195
1237
1196 #Input
1238 #Input
1197 d = data[:,h]
1239 d = data[:,h]
1198
1240
1199 #Covariance Matrix
1241 #Covariance Matrix
1200 D = numpy.diag(d**2/K)
1242 D = numpy.diag(d**2/K)
1201 ind = 0
1243 ind = 0
1202 for pairs in listComb:
1244 for pairs in listComb:
1203 #Coordinates in Covariance Matrix
1245 #Coordinates in Covariance Matrix
1204 x = pairs[0]
1246 x = pairs[0]
1205 y = pairs[1]
1247 y = pairs[1]
1206 #Channel Index
1248 #Channel Index
1207 S12 = dataCross[ind,:,h]
1249 S12 = dataCross[ind,:,h]
1208 D12 = numpy.diag(S12)
1250 D12 = numpy.diag(S12)
1209 #Completing Covariance Matrix with Cross Spectras
1251 #Completing Covariance Matrix with Cross Spectras
1210 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1252 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1211 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1253 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1212 ind += 1
1254 ind += 1
1213 Dinv=numpy.linalg.inv(D)
1255 Dinv=numpy.linalg.inv(D)
1214 L=numpy.linalg.cholesky(Dinv)
1256 L=numpy.linalg.cholesky(Dinv)
1215 LT=L.T
1257 LT=L.T
1216
1258
1217 dp = numpy.dot(LT,d)
1259 dp = numpy.dot(LT,d)
1218
1260
1219 #Initial values
1261 #Initial values
1220 data_spc = self.dataIn.data_spc[coord,:,h]
1262 data_spc = self.dataIn.data_spc[coord,:,h]
1221
1263
1222 if (h>0)and(error1[3]<5):
1264 if (h>0)and(error1[3]<5):
1223 p0 = self.dataOut.data_param[i,:,h-1]
1265 p0 = self.dataOut.data_param[i,:,h-1]
1224 else:
1266 else:
1225 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1267 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1226
1268
1227 try:
1269 try:
1228 #Least Squares
1270 #Least Squares
1229 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1271 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1230 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1272 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1231 #Chi square error
1273 #Chi square error
1232 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1274 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1233 #Error with Jacobian
1275 #Error with Jacobian
1234 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1276 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1235 except:
1277 except:
1236 minp = p0*numpy.nan
1278 minp = p0*numpy.nan
1237 error0 = numpy.nan
1279 error0 = numpy.nan
1238 error1 = p0*numpy.nan
1280 error1 = p0*numpy.nan
1239
1281
1240 #Save
1282 #Save
1241 if self.dataOut.data_param == None:
1283 if self.dataOut.data_param == None:
1242 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1284 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1243 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1285 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1244
1286
1245 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1287 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1246 self.dataOut.data_param[i,:,h] = minp
1288 self.dataOut.data_param[i,:,h] = minp
1247 return
1289 return
1248
1290
1249
1250 def __residFunction(self, p, dp, LT, constants):
1291 def __residFunction(self, p, dp, LT, constants):
1251
1292
1252 fm = self.dataOut.library.modelFunction(p, constants)
1293 fm = self.dataOut.library.modelFunction(p, constants)
1253 fmp=numpy.dot(LT,fm)
1294 fmp=numpy.dot(LT,fm)
1254
1295
1255 return dp-fmp
1296 return dp-fmp
1256
1297
1257 def __getSNR(self, z, noise):
1298 def __getSNR(self, z, noise):
1258
1299
1259 avg = numpy.average(z, axis=1)
1300 avg = numpy.average(z, axis=1)
1260 SNR = (avg.T-noise)/noise
1301 SNR = (avg.T-noise)/noise
1261 SNR = SNR.T
1302 SNR = SNR.T
1262 return SNR
1303 return SNR
1263
1304
1264 def __chisq(p,chindex,hindex):
1305 def __chisq(p,chindex,hindex):
1265 #similar to Resid but calculates CHI**2
1306 #similar to Resid but calculates CHI**2
1266 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1307 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1267 dp=numpy.dot(LT,d)
1308 dp=numpy.dot(LT,d)
1268 fmp=numpy.dot(LT,fm)
1309 fmp=numpy.dot(LT,fm)
1269 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1310 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1270 return chisq
1311 return chisq
1271
1312
1272
1313
1273
1314
1274 class WindProfiler(Operation):
1315 class WindProfiler(Operation):
1275
1316
1276 __isConfig = False
1317 __isConfig = False
1277
1318
1278 __initime = None
1319 __initime = None
1279 __lastdatatime = None
1320 __lastdatatime = None
1280 __integrationtime = None
1321 __integrationtime = None
1281
1322
1282 __buffer = None
1323 __buffer = None
1283
1324
1284 __dataReady = False
1325 __dataReady = False
1285
1326
1286 __firstdata = None
1327 __firstdata = None
1287
1328
1288 n = None
1329 n = None
1289
1330
1290 def __init__(self):
1331 def __init__(self):
1291 Operation.__init__(self)
1332 Operation.__init__(self)
1292
1333
1293 def __calculateCosDir(self, elev, azim):
1334 def __calculateCosDir(self, elev, azim):
1294 zen = (90 - elev)*numpy.pi/180
1335 zen = (90 - elev)*numpy.pi/180
1295 azim = azim*numpy.pi/180
1336 azim = azim*numpy.pi/180
1296 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1337 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1297 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1338 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1298
1339
1299 signX = numpy.sign(numpy.cos(azim))
1340 signX = numpy.sign(numpy.cos(azim))
1300 signY = numpy.sign(numpy.sin(azim))
1341 signY = numpy.sign(numpy.sin(azim))
1301
1342
1302 cosDirX = numpy.copysign(cosDirX, signX)
1343 cosDirX = numpy.copysign(cosDirX, signX)
1303 cosDirY = numpy.copysign(cosDirY, signY)
1344 cosDirY = numpy.copysign(cosDirY, signY)
1304 return cosDirX, cosDirY
1345 return cosDirX, cosDirY
1305
1346
1306 def __calculateAngles(self, theta_x, theta_y, azimuth):
1347 def __calculateAngles(self, theta_x, theta_y, azimuth):
1307
1348
1308 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1349 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1309 zenith_arr = numpy.arccos(dir_cosw)
1350 zenith_arr = numpy.arccos(dir_cosw)
1310 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1351 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1311
1352
1312 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1353 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1313 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1354 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1314
1355
1315 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1356 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1316
1357
1317 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1358 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1318
1359
1319 #
1360 #
1320 if horOnly:
1361 if horOnly:
1321 A = numpy.c_[dir_cosu,dir_cosv]
1362 A = numpy.c_[dir_cosu,dir_cosv]
1322 else:
1363 else:
1323 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1364 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1324 A = numpy.asmatrix(A)
1365 A = numpy.asmatrix(A)
1325 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1366 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1326
1367
1327 return A1
1368 return A1
1328
1369
1329 def __correctValues(self, heiRang, phi, velRadial, SNR):
1370 def __correctValues(self, heiRang, phi, velRadial, SNR):
1330
1331 listPhi = phi.tolist()
1371 listPhi = phi.tolist()
1332 maxid = listPhi.index(max(listPhi))
1372 maxid = listPhi.index(max(listPhi))
1333 minid = listPhi.index(min(listPhi))
1373 minid = listPhi.index(min(listPhi))
1334
1374
1335 rango = range(len(phi))
1375 rango = range(len(phi))
1336 # rango = numpy.delete(rango,maxid)
1376 # rango = numpy.delete(rango,maxid)
1337
1377
1338 heiRang1 = heiRang*math.cos(phi[maxid])
1378 heiRang1 = heiRang*math.cos(phi[maxid])
1339 heiRangAux = heiRang*math.cos(phi[minid])
1379 heiRangAux = heiRang*math.cos(phi[minid])
1340 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1380 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1341 heiRang1 = numpy.delete(heiRang1,indOut)
1381 heiRang1 = numpy.delete(heiRang1,indOut)
1342
1382
1343 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1383 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1344 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1384 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1345
1385
1346 for i in rango:
1386 for i in rango:
1347 x = heiRang*math.cos(phi[i])
1387 x = heiRang*math.cos(phi[i])
1348 y1 = velRadial[i,:]
1388 y1 = velRadial[i,:]
1349 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1389 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1350
1390
1351 x1 = heiRang1
1391 x1 = heiRang1
1352 y11 = f1(x1)
1392 y11 = f1(x1)
1353
1393
1354 y2 = SNR[i,:]
1394 y2 = SNR[i,:]
1355 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1395 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1356 y21 = f2(x1)
1396 y21 = f2(x1)
1357
1397
1358 velRadial1[i,:] = y11
1398 velRadial1[i,:] = y11
1359 SNR1[i,:] = y21
1399 SNR1[i,:] = y21
1360
1400
1361 return heiRang1, velRadial1, SNR1
1401 return heiRang1, velRadial1, SNR1
1362
1402
1363 def __calculateVelUVW(self, A, velRadial):
1403 def __calculateVelUVW(self, A, velRadial):
1364
1404
1365 #Operacion Matricial
1405 #Operacion Matricial
1366 # velUVW = numpy.zeros((velRadial.shape[1],3))
1406 # velUVW = numpy.zeros((velRadial.shape[1],3))
1367 # for ind in range(velRadial.shape[1]):
1407 # for ind in range(velRadial.shape[1]):
1368 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1408 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1369 # velUVW = velUVW.transpose()
1409 # velUVW = velUVW.transpose()
1370 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1410 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1371 velUVW[:,:] = numpy.dot(A,velRadial)
1411 velUVW[:,:] = numpy.dot(A,velRadial)
1372
1412
1373
1413
1374 return velUVW
1414 return velUVW
1375
1415
1376 def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1416 def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1377 """
1417 """
1378 Function that implements Doppler Beam Swinging (DBS) technique.
1418 Function that implements Doppler Beam Swinging (DBS) technique.
1379
1419
1380 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1420 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1381 Direction correction (if necessary), Ranges and SNR
1421 Direction correction (if necessary), Ranges and SNR
1382
1422
1383 Output: Winds estimation (Zonal, Meridional and Vertical)
1423 Output: Winds estimation (Zonal, Meridional and Vertical)
1384
1424
1385 Parameters affected: Winds, height range, SNR
1425 Parameters affected: Winds, height range, SNR
1386 """
1426 """
1387 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(dirCosx, disrCosy, azimuth)
1427 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(dirCosx, disrCosy, azimuth)
1388 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correct*velRadial0, SNR0)
1428 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correct*velRadial0, SNR0)
1389 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1429 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1390
1430
1391 #Calculo de Componentes de la velocidad con DBS
1431 #Calculo de Componentes de la velocidad con DBS
1392 winds = self.__calculateVelUVW(A,velRadial1)
1432 winds = self.__calculateVelUVW(A,velRadial1)
1393
1433
1394 return winds, heiRang1, SNR1
1434 return winds, heiRang1, SNR1
1395
1435
1396 def __calculateDistance(self, posx, posy, pairsCrossCorr, pairsList, pairs, azimuth = None):
1436 def __calculateDistance(self, posx, posy, pairsCrossCorr, pairsList, pairs, azimuth = None):
1397
1437
1398 posx = numpy.asarray(posx)
1438 posx = numpy.asarray(posx)
1399 posy = numpy.asarray(posy)
1439 posy = numpy.asarray(posy)
1400
1440
1401 #Rotacion Inversa para alinear con el azimuth
1441 #Rotacion Inversa para alinear con el azimuth
1402 if azimuth!= None:
1442 if azimuth!= None:
1403 azimuth = azimuth*math.pi/180
1443 azimuth = azimuth*math.pi/180
1404 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1444 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1405 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1445 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1406 else:
1446 else:
1407 posx1 = posx
1447 posx1 = posx
1408 posy1 = posy
1448 posy1 = posy
1409
1449
1410 #Calculo de Distancias
1450 #Calculo de Distancias
1411 distx = numpy.zeros(pairsCrossCorr.size)
1451 distx = numpy.zeros(pairsCrossCorr.size)
1412 disty = numpy.zeros(pairsCrossCorr.size)
1452 disty = numpy.zeros(pairsCrossCorr.size)
1413 dist = numpy.zeros(pairsCrossCorr.size)
1453 dist = numpy.zeros(pairsCrossCorr.size)
1414 ang = numpy.zeros(pairsCrossCorr.size)
1454 ang = numpy.zeros(pairsCrossCorr.size)
1415
1455
1416 for i in range(pairsCrossCorr.size):
1456 for i in range(pairsCrossCorr.size):
1417 distx[i] = posx1[pairsList[pairsCrossCorr[i]][1]] - posx1[pairsList[pairsCrossCorr[i]][0]]
1457 distx[i] = posx1[pairsList[pairsCrossCorr[i]][1]] - posx1[pairsList[pairsCrossCorr[i]][0]]
1418 disty[i] = posy1[pairsList[pairsCrossCorr[i]][1]] - posy1[pairsList[pairsCrossCorr[i]][0]]
1458 disty[i] = posy1[pairsList[pairsCrossCorr[i]][1]] - posy1[pairsList[pairsCrossCorr[i]][0]]
1419 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1459 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1420 ang[i] = numpy.arctan2(disty[i],distx[i])
1460 ang[i] = numpy.arctan2(disty[i],distx[i])
1421 #Calculo de Matrices
1461 #Calculo de Matrices
1422 nPairs = len(pairs)
1462 nPairs = len(pairs)
1423 ang1 = numpy.zeros((nPairs, 2, 1))
1463 ang1 = numpy.zeros((nPairs, 2, 1))
1424 dist1 = numpy.zeros((nPairs, 2, 1))
1464 dist1 = numpy.zeros((nPairs, 2, 1))
1425
1465
1426 for j in range(nPairs):
1466 for j in range(nPairs):
1427 dist1[j,0,0] = dist[pairs[j][0]]
1467 dist1[j,0,0] = dist[pairs[j][0]]
1428 dist1[j,1,0] = dist[pairs[j][1]]
1468 dist1[j,1,0] = dist[pairs[j][1]]
1429 ang1[j,0,0] = ang[pairs[j][0]]
1469 ang1[j,0,0] = ang[pairs[j][0]]
1430 ang1[j,1,0] = ang[pairs[j][1]]
1470 ang1[j,1,0] = ang[pairs[j][1]]
1431
1471
1432 return distx,disty, dist1,ang1
1472 return distx,disty, dist1,ang1
1433
1473
1434 def __calculateVelVer(self, phase, lagTRange, _lambda):
1474 def __calculateVelVer(self, phase, lagTRange, _lambda):
1435
1475
1436 Ts = lagTRange[1] - lagTRange[0]
1476 Ts = lagTRange[1] - lagTRange[0]
1437 velW = -_lambda*phase/(4*math.pi*Ts)
1477 velW = -_lambda*phase/(4*math.pi*Ts)
1438
1478
1439 return velW
1479 return velW
1440
1480
1441 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1481 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1442 nPairs = tau1.shape[0]
1482 nPairs = tau1.shape[0]
1443 vel = numpy.zeros((nPairs,3,tau1.shape[2]))
1483 vel = numpy.zeros((nPairs,3,tau1.shape[2]))
1444
1484
1445 angCos = numpy.cos(ang)
1485 angCos = numpy.cos(ang)
1446 angSin = numpy.sin(ang)
1486 angSin = numpy.sin(ang)
1447
1487
1448 vel0 = dist*tau1/(2*tau2**2)
1488 vel0 = dist*tau1/(2*tau2**2)
1449 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1489 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1450 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1490 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1451
1491
1452 ind = numpy.where(numpy.isinf(vel))
1492 ind = numpy.where(numpy.isinf(vel))
1453 vel[ind] = numpy.nan
1493 vel[ind] = numpy.nan
1454
1494
1455 return vel
1495 return vel
1456
1496
1457 def __getPairsAutoCorr(self, pairsList, nChannels):
1497 def __getPairsAutoCorr(self, pairsList, nChannels):
1458
1498
1459 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1499 pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1460
1500
1461 for l in range(len(pairsList)):
1501 for l in range(len(pairsList)):
1462 firstChannel = pairsList[l][0]
1502 firstChannel = pairsList[l][0]
1463 secondChannel = pairsList[l][1]
1503 secondChannel = pairsList[l][1]
1464
1504
1465 #Obteniendo pares de Autocorrelacion
1505 #Obteniendo pares de Autocorrelacion
1466 if firstChannel == secondChannel:
1506 if firstChannel == secondChannel:
1467 pairsAutoCorr[firstChannel] = int(l)
1507 pairsAutoCorr[firstChannel] = int(l)
1468
1508
1469 pairsAutoCorr = pairsAutoCorr.astype(int)
1509 pairsAutoCorr = pairsAutoCorr.astype(int)
1470
1510
1471 pairsCrossCorr = range(len(pairsList))
1511 pairsCrossCorr = range(len(pairsList))
1472 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1512 pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1473
1513
1474 return pairsAutoCorr, pairsCrossCorr
1514 return pairsAutoCorr, pairsCrossCorr
1475
1515
1476 def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1516 def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1477 """
1517 """
1478 Function that implements Spaced Antenna (SA) technique.
1518 Function that implements Spaced Antenna (SA) technique.
1479
1519
1480 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1520 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1481 Direction correction (if necessary), Ranges and SNR
1521 Direction correction (if necessary), Ranges and SNR
1482
1522
1483 Output: Winds estimation (Zonal, Meridional and Vertical)
1523 Output: Winds estimation (Zonal, Meridional and Vertical)
1484
1524
1485 Parameters affected: Winds
1525 Parameters affected: Winds
1486 """
1526 """
1487 #Cross Correlation pairs obtained
1527 #Cross Correlation pairs obtained
1488 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1528 pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1489 pairsArray = numpy.array(pairsList)[pairsCrossCorr]
1529 pairsArray = numpy.array(pairsList)[pairsCrossCorr]
1490 pairsSelArray = numpy.array(pairsSelected)
1530 pairsSelArray = numpy.array(pairsSelected)
1491 pairs = []
1531 pairs = []
1492
1532
1493 #Wind estimation pairs obtained
1533 #Wind estimation pairs obtained
1494 for i in range(pairsSelArray.shape[0]/2):
1534 for i in range(pairsSelArray.shape[0]/2):
1495 ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
1535 ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
1496 ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
1536 ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
1497 pairs.append((ind1,ind2))
1537 pairs.append((ind1,ind2))
1498
1538
1499 indtau = tau.shape[0]/2
1539 indtau = tau.shape[0]/2
1500 tau1 = tau[:indtau,:]
1540 tau1 = tau[:indtau,:]
1501 tau2 = tau[indtau:-1,:]
1541 tau2 = tau[indtau:-1,:]
1502 tau1 = tau1[pairs,:]
1542 tau1 = tau1[pairs,:]
1503 tau2 = tau2[pairs,:]
1543 tau2 = tau2[pairs,:]
1504 phase1 = tau[-1,:]
1544 phase1 = tau[-1,:]
1505
1545
1506 #---------------------------------------------------------------------
1546 #---------------------------------------------------------------------
1507 #Metodo Directo
1547 #Metodo Directo
1508 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairsCrossCorr, pairsList, pairs,azimuth)
1548 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairsCrossCorr, pairsList, pairs,azimuth)
1509 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
1549 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
1510 winds = stats.nanmean(winds, axis=0)
1550 winds = stats.nanmean(winds, axis=0)
1511 #---------------------------------------------------------------------
1551 #---------------------------------------------------------------------
1512 #Metodo General
1552 #Metodo General
1513 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
1553 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
1514 # #Calculo Coeficientes de Funcion de Correlacion
1554 # #Calculo Coeficientes de Funcion de Correlacion
1515 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
1555 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
1516 # #Calculo de Velocidades
1556 # #Calculo de Velocidades
1517 # winds = self.calculateVelUV(F,G,A,B,H)
1557 # winds = self.calculateVelUV(F,G,A,B,H)
1518
1558
1519 #---------------------------------------------------------------------
1559 #---------------------------------------------------------------------
1520 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
1560 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
1521 winds = correctFactor*winds
1561 winds = correctFactor*winds
1522 return winds
1562 return winds
1523
1563
1524 def __checkTime(self, currentTime, paramInterval, outputInterval):
1564 def __checkTime(self, currentTime, paramInterval, outputInterval):
1525
1565
1526 dataTime = currentTime + paramInterval
1566 dataTime = currentTime + paramInterval
1527 deltaTime = dataTime - self.__initime
1567 deltaTime = dataTime - self.__initime
1528
1568
1529 if deltaTime >= outputInterval or deltaTime < 0:
1569 if deltaTime >= outputInterval or deltaTime < 0:
1530 self.__dataReady = True
1570 self.__dataReady = True
1531 return
1571 return
1532
1572
1533 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
1573 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
1534 '''
1574 '''
1535 Function that implements winds estimation technique with detected meteors.
1575 Function that implements winds estimation technique with detected meteors.
1536
1576
1537 Input: Detected meteors, Minimum meteor quantity to wind estimation
1577 Input: Detected meteors, Minimum meteor quantity to wind estimation
1538
1578
1539 Output: Winds estimation (Zonal and Meridional)
1579 Output: Winds estimation (Zonal and Meridional)
1540
1580
1541 Parameters affected: Winds
1581 Parameters affected: Winds
1542 '''
1582 '''
1583 print arrayMeteor.shape
1543 #Settings
1584 #Settings
1544 nInt = (heightMax - heightMin)/2
1585 nInt = (heightMax - heightMin)/2
1545 winds = numpy.zeros((2,nInt))*numpy.nan
1586 winds = numpy.zeros((2,nInt))*numpy.nan
1546
1587
1547 #Filter errors
1588 #Filter errors
1548 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
1589 error = numpy.where(arrayMeteor[0,:,-1] == 0)[0]
1549 finalMeteor = arrayMeteor[error,:]
1590 finalMeteor = arrayMeteor[0,error,:]
1550
1591
1551 #Meteor Histogram
1592 #Meteor Histogram
1552 finalHeights = finalMeteor[:,3]
1593 finalHeights = finalMeteor[:,3]
1553 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
1594 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
1554 nMeteorsPerI = hist[0]
1595 nMeteorsPerI = hist[0]
1555 heightPerI = hist[1]
1596 heightPerI = hist[1]
1556
1597
1557 #Sort of meteors
1598 #Sort of meteors
1558 indSort = finalHeights.argsort()
1599 indSort = finalHeights.argsort()
1559 finalMeteor2 = finalMeteor[indSort,:]
1600 finalMeteor2 = finalMeteor[indSort,:]
1560
1601
1561 # Calculating winds
1602 # Calculating winds
1562 ind1 = 0
1603 ind1 = 0
1563 ind2 = 0
1604 ind2 = 0
1564
1605
1565 for i in range(nInt):
1606 for i in range(nInt):
1566 nMet = nMeteorsPerI[i]
1607 nMet = nMeteorsPerI[i]
1567 ind1 = ind2
1608 ind1 = ind2
1568 ind2 = ind1 + nMet
1609 ind2 = ind1 + nMet
1569
1610
1570 meteorAux = finalMeteor2[ind1:ind2,:]
1611 meteorAux = finalMeteor2[ind1:ind2,:]
1571
1612
1572 if meteorAux.shape[0] >= meteorThresh:
1613 if meteorAux.shape[0] >= meteorThresh:
1573 vel = meteorAux[:, 7]
1614 vel = meteorAux[:, 7]
1574 zen = meteorAux[:, 5]*numpy.pi/180
1615 zen = meteorAux[:, 5]*numpy.pi/180
1575 azim = meteorAux[:, 4]*numpy.pi/180
1616 azim = meteorAux[:, 4]*numpy.pi/180
1576
1617
1577 n = numpy.cos(zen)
1618 n = numpy.cos(zen)
1578 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
1619 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
1579 # l = m*numpy.tan(azim)
1620 # l = m*numpy.tan(azim)
1580 l = numpy.sin(zen)*numpy.sin(azim)
1621 l = numpy.sin(zen)*numpy.sin(azim)
1581 m = numpy.sin(zen)*numpy.cos(azim)
1622 m = numpy.sin(zen)*numpy.cos(azim)
1582
1623
1583 A = numpy.vstack((l, m)).transpose()
1624 A = numpy.vstack((l, m)).transpose()
1584 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
1625 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
1585 windsAux = numpy.dot(A1, vel)
1626 windsAux = numpy.dot(A1, vel)
1586
1627
1587 winds[0,i] = windsAux[0]
1628 winds[0,i] = windsAux[0]
1588 winds[1,i] = windsAux[1]
1629 winds[1,i] = windsAux[1]
1589
1630
1590 return winds, heightPerI[:-1]
1631 return winds, heightPerI[:-1]
1591
1632
1592 def run(self, dataOut, technique, **kwargs):
1633 def run(self, dataOut, technique, **kwargs):
1593
1634
1594 param = dataOut.data_param
1635 param = dataOut.data_param
1595 if dataOut.abscissaList != None:
1636 # if dataOut.abscissaList != None:
1596 absc = dataOut.abscissaList[:-1]
1637 # absc = dataOut.abscissaList[:-1]
1597 noise = dataOut.noise
1638 noise = dataOut.noise
1598 heightList = dataOut.getHeiRange()
1639 heightList = dataOut.heightList
1599 SNR = dataOut.data_SNR
1640 SNR = dataOut.data_SNR
1600
1641
1601 if technique == 'DBS':
1642 if technique == 'DBS':
1602
1643
1603 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1644 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1604 theta_x = numpy.array(kwargs['dirCosx'])
1645 theta_x = numpy.array(kwargs['dirCosx'])
1605 theta_y = numpy.array(kwargs['dirCosy'])
1646 theta_y = numpy.array(kwargs['dirCosy'])
1606 else:
1647 else:
1607 elev = numpy.array(kwargs['elevation'])
1648 elev = numpy.array(kwargs['elevation'])
1608 azim = numpy.array(kwargs['azimuth'])
1649 azim = numpy.array(kwargs['azimuth'])
1609 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1650 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1610 azimuth = kwargs['correctAzimuth']
1651 azimuth = kwargs['correctAzimuth']
1611 if kwargs.has_key('horizontalOnly'):
1652 if kwargs.has_key('horizontalOnly'):
1612 horizontalOnly = kwargs['horizontalOnly']
1653 horizontalOnly = kwargs['horizontalOnly']
1613 else: horizontalOnly = False
1654 else: horizontalOnly = False
1614 if kwargs.has_key('correctFactor'):
1655 if kwargs.has_key('correctFactor'):
1615 correctFactor = kwargs['correctFactor']
1656 correctFactor = kwargs['correctFactor']
1616 else: correctFactor = 1
1657 else: correctFactor = 1
1617 if kwargs.has_key('channelList'):
1658 if kwargs.has_key('channelList'):
1618 channelList = kwargs['channelList']
1659 channelList = kwargs['channelList']
1660 if len(channelList) == 2:
1661 horizontalOnly = True
1619 arrayChannel = numpy.array(channelList)
1662 arrayChannel = numpy.array(channelList)
1620 param = param[arrayChannel,:,:]
1663 param = param[arrayChannel,:,:]
1621 theta_x = theta_x[arrayChannel]
1664 theta_x = theta_x[arrayChannel]
1622 theta_y = theta_y[arrayChannel]
1665 theta_y = theta_y[arrayChannel]
1623
1666
1624 velRadial0 = param[:,1,:] #Radial velocity
1667 velRadial0 = param[:,1,:] #Radial velocity
1625
1626 if velRadial0.shape[0] != theta_x.shape[0] or velRadial0.shape[0] != theta_y.shape[0]:
1627 raise ValueError, "The max number of channels is %d, and the length of cosine director is %d. Please check: dirCosX, dirCosY, elevation or azimuth arguments" %(velRadial0.shape[0], theta_x.shape[0])
1628
1629 if theta_x.shape[0] == 2:
1630 horizontalOnly = True
1631
1632 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(velRadial0, theta_x, theta_y, azimuth, correctFactor, horizontalOnly, heightList, SNR) #DBS Function
1668 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(velRadial0, theta_x, theta_y, azimuth, correctFactor, horizontalOnly, heightList, SNR) #DBS Function
1633 dataOut.utctimeInit = dataOut.utctime
1669 dataOut.utctimeInit = dataOut.utctime
1634 dataOut.outputInterval = dataOut.timeInterval
1670 dataOut.outputInterval = dataOut.timeInterval
1635
1671
1636 elif technique == 'SA':
1672 elif technique == 'SA':
1637
1673
1638 #Parameters
1674 #Parameters
1639 position_x = kwargs['positionX']
1675 position_x = kwargs['positionX']
1640 position_y = kwargs['positionY']
1676 position_y = kwargs['positionY']
1641 azimuth = kwargs['azimuth']
1677 azimuth = kwargs['azimuth']
1642
1678
1643 if kwargs.has_key('crosspairsList'):
1679 if kwargs.has_key('crosspairsList'):
1644 pairs = kwargs['crosspairsList']
1680 pairs = kwargs['crosspairsList']
1645 else:
1681 else:
1646 pairs = None
1682 pairs = None
1647
1683
1648 if kwargs.has_key('correctFactor'):
1684 if kwargs.has_key('correctFactor'):
1649 correctFactor = kwargs['correctFactor']
1685 correctFactor = kwargs['correctFactor']
1650 else:
1686 else:
1651 correctFactor = 1
1687 correctFactor = 1
1652
1688
1653 tau = dataOut.data_param
1689 tau = dataOut.data_param
1654 _lambda = dataOut.C/dataOut.frequency
1690 _lambda = dataOut.C/dataOut.frequency
1655 pairsList = dataOut.groupList
1691 pairsList = dataOut.groupList
1656 nChannels = dataOut.nChannels
1692 nChannels = dataOut.nChannels
1657
1693
1658 dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
1694 dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
1659 dataOut.utctimeInit = dataOut.utctime
1695 dataOut.utctimeInit = dataOut.utctime
1660 dataOut.outputInterval = dataOut.timeInterval
1696 dataOut.outputInterval = dataOut.timeInterval
1661
1697
1662 elif technique == 'Meteors':
1698 elif technique == 'Meteors':
1663 dataOut.flagNoData = True
1699 dataOut.flagNoData = True
1664 self.__dataReady = False
1700 self.__dataReady = False
1665
1701
1666 if kwargs.has_key('nHours'):
1702 if kwargs.has_key('nHours'):
1667 nHours = kwargs['nHours']
1703 nHours = kwargs['nHours']
1668 else:
1704 else:
1669 nHours = 1
1705 nHours = 1
1670
1706
1671 if kwargs.has_key('meteorsPerBin'):
1707 if kwargs.has_key('meteorsPerBin'):
1672 meteorThresh = kwargs['meteorsPerBin']
1708 meteorThresh = kwargs['meteorsPerBin']
1673 else:
1709 else:
1674 meteorThresh = 6
1710 meteorThresh = 6
1675
1711
1676 if kwargs.has_key('hmin'):
1712 if kwargs.has_key('hmin'):
1677 hmin = kwargs['hmin']
1713 hmin = kwargs['hmin']
1678 else: hmin = 70
1714 else: hmin = 70
1679 if kwargs.has_key('hmax'):
1715 if kwargs.has_key('hmax'):
1680 hmax = kwargs['hmax']
1716 hmax = kwargs['hmax']
1681 else: hmax = 110
1717 else: hmax = 110
1682
1718
1683 dataOut.outputInterval = nHours*3600
1719 dataOut.outputInterval = nHours*3600
1684
1720
1685 if self.__isConfig == False:
1721 if self.__isConfig == False:
1686 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1722 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1687 #Get Initial LTC time
1723 #Get Initial LTC time
1688 self.__initime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
1724 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
1689 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1725 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1690
1726
1691 self.__isConfig = True
1727 self.__isConfig = True
1692
1728
1693 if self.__buffer == None:
1729 if self.__buffer == None:
1694 self.__buffer = dataOut.data_param
1730 self.__buffer = dataOut.data_param
1695 self.__firstdata = copy.copy(dataOut)
1731 self.__firstdata = copy.copy(dataOut)
1696
1732
1697 else:
1733 else:
1698 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1734 self.__buffer = numpy.hstack((self.__buffer, dataOut.data_param))
1699
1735
1700 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1736 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1701
1737
1702 if self.__dataReady:
1738 if self.__dataReady:
1703 dataOut.utctimeInit = self.__initime
1739 dataOut.utctimeInit = self.__initime
1704
1740
1705 self.__initime += dataOut.outputInterval #to erase time offset
1741 self.__initime += dataOut.outputInterval #to erase time offset
1706
1742
1707 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
1743 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
1708 dataOut.flagNoData = False
1744 dataOut.flagNoData = False
1709 self.__buffer = None
1745 self.__buffer = None
1710
1746
1711 return
1747 return
1712
1748
1713 class EWDriftsEstimation(Operation):
1749 class EWDriftsEstimation(Operation):
1714
1750
1715
1751
1716 def __init__(self):
1752 def __init__(self):
1717 Operation.__init__(self)
1753 Operation.__init__(self)
1718
1754
1719 def __correctValues(self, heiRang, phi, velRadial, SNR):
1755 def __correctValues(self, heiRang, phi, velRadial, SNR):
1720 listPhi = phi.tolist()
1756 listPhi = phi.tolist()
1721 maxid = listPhi.index(max(listPhi))
1757 maxid = listPhi.index(max(listPhi))
1722 minid = listPhi.index(min(listPhi))
1758 minid = listPhi.index(min(listPhi))
1723
1759
1724 rango = range(len(phi))
1760 rango = range(len(phi))
1725 # rango = numpy.delete(rango,maxid)
1761 # rango = numpy.delete(rango,maxid)
1726
1762
1727 heiRang1 = heiRang*math.cos(phi[maxid])
1763 heiRang1 = heiRang*math.cos(phi[maxid])
1728 heiRangAux = heiRang*math.cos(phi[minid])
1764 heiRangAux = heiRang*math.cos(phi[minid])
1729 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1765 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1730 heiRang1 = numpy.delete(heiRang1,indOut)
1766 heiRang1 = numpy.delete(heiRang1,indOut)
1731
1767
1732 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1768 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1733 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1769 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1734
1770
1735 for i in rango:
1771 for i in rango:
1736 x = heiRang*math.cos(phi[i])
1772 x = heiRang*math.cos(phi[i])
1737 y1 = velRadial[i,:]
1773 y1 = velRadial[i,:]
1738 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1774 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1739
1775
1740 x1 = heiRang1
1776 x1 = heiRang1
1741 y11 = f1(x1)
1777 y11 = f1(x1)
1742
1778
1743 y2 = SNR[i,:]
1779 y2 = SNR[i,:]
1744 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1780 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1745 y21 = f2(x1)
1781 y21 = f2(x1)
1746
1782
1747 velRadial1[i,:] = y11
1783 velRadial1[i,:] = y11
1748 SNR1[i,:] = y21
1784 SNR1[i,:] = y21
1749
1785
1750 return heiRang1, velRadial1, SNR1
1786 return heiRang1, velRadial1, SNR1
1751
1787
1752 def run(self, dataOut, zenith, zenithCorrection):
1788 def run(self, dataOut, zenith, zenithCorrection):
1753 heiRang = dataOut.heightList
1789 heiRang = dataOut.heightList
1754 velRadial = dataOut.data_param[:,3,:]
1790 velRadial = dataOut.data_param[:,3,:]
1755 SNR = dataOut.data_SNR
1791 SNR = dataOut.data_SNR
1756
1792
1757 zenith = numpy.array(zenith)
1793 zenith = numpy.array(zenith)
1758 zenith -= zenithCorrection
1794 zenith -= zenithCorrection
1759 zenith *= numpy.pi/180
1795 zenith *= numpy.pi/180
1760
1796
1761 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
1797 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
1762
1798
1763 alp = zenith[0]
1799 alp = zenith[0]
1764 bet = zenith[1]
1800 bet = zenith[1]
1765
1801
1766 w_w = velRadial1[0,:]
1802 w_w = velRadial1[0,:]
1767 w_e = velRadial1[1,:]
1803 w_e = velRadial1[1,:]
1768
1804
1769 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
1805 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
1770 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
1806 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
1771
1807
1772 winds = numpy.vstack((u,w))
1808 winds = numpy.vstack((u,w))
1773
1809
1774 dataOut.heightList = heiRang1
1810 dataOut.heightList = heiRang1
1775 dataOut.data_output = winds
1811 dataOut.data_output = winds
1776 dataOut.data_SNR = SNR1
1812 dataOut.data_SNR = SNR1
1777
1813
1778 dataOut.utctimeInit = dataOut.utctime
1814 dataOut.utctimeInit = dataOut.utctime
1779 dataOut.outputInterval = dataOut.timeInterval
1815 dataOut.outputInterval = dataOut.timeInterval
1780 return
1816 return
1781
1817
1818 class PhaseCalibration(Operation):
1819
1820 __buffer = None
1821
1822 __initime = None
1823
1824 __dataReady = False
1825
1826 __isConfig = False
1827
1828 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
1829
1830 dataTime = currentTime + paramInterval
1831 deltaTime = dataTime - initTime
1832
1833 if deltaTime >= outputInterval or deltaTime < 0:
1834 return True
1835
1836 return False
1837
1838 def __getGammas(self, pairs, k, d, phases):
1839 gammas = numpy.zeros(2)
1840
1841 for i in range(len(pairs)):
1842
1843 pairi = pairs[i]
1844
1845 #Calculating gamma
1846 jdcos = phases[:,pairi[1]]/(k*d[pairi[1]])
1847 jgamma = numpy.angle(numpy.exp(1j*(k*d[pairi[0]]*jdcos - phases[:,pairi[0]])))
1848
1849 #Revised distribution
1850 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
1851
1852 #Histogram
1853 nBins = 64.0
1854 rmin = -0.5*numpy.pi
1855 rmax = 0.5*numpy.pi
1856 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
1857
1858 meteorsY = phaseHisto[0]
1859 phasesX = phaseHisto[1][:-1]
1860 width = phasesX[1] - phasesX[0]
1861 phasesX += width/2
1862
1863 #Gaussian aproximation
1864 bpeak = meteorsY.argmax()
1865 peak = meteorsY.max()
1866 jmin = bpeak - 5
1867 jmax = bpeak + 5 + 1
1868
1869 if jmin<0:
1870 jmin = 0
1871 jmax = 6
1872 elif jmax > meteorsY.size:
1873 jmin = meteorsY.size - 6
1874 jmax = meteorsY.size
1875
1876 x0 = numpy.array([peak,bpeak,50])
1877 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
1878
1879 #Gammas
1880 gammas[i] = coeff[0][1]
1881 # gammas[i] = bpeak
1882
1883 return gammas
1884
1885 def __residualFunction(self, coeffs, y, t):
1886
1887 return y - self.__gauss_function(t, coeffs)
1888
1889 def __gauss_function(self, t, coeffs):
1890
1891 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
1892
1893 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
1894 meteorOps = MeteorOperations()
1895 nchan = 4
1896 pairx = pairsList[0]
1897 pairy = pairsList[1]
1898 center_xangle = 0
1899 center_yangle = 0
1900 range_angle = numpy.array([8*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
1901 ntimes = len(range_angle)
1902
1903 nstepsx = 20.0
1904 nstepsy = 20.0
1905
1906 for iz in range(ntimes):
1907 min_xangle = -range_angle[iz]/2 + center_xangle
1908 max_xangle = range_angle[iz]/2 + center_xangle
1909 min_yangle = -range_angle[iz]/2 + center_yangle
1910 max_yangle = range_angle[iz]/2 + center_yangle
1911
1912 inc_x = (max_xangle-min_xangle)/nstepsx
1913 inc_y = (max_yangle-min_yangle)/nstepsy
1914
1915 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
1916 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
1917 penalty = numpy.zeros((nstepsx,nstepsy))
1918 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
1919 jph = numpy.zeros(nchan)
1920
1921 # Iterations looking for the offset
1922 for iy in range(int(nstepsy)):
1923 for ix in range(int(nstepsx)):
1924 jph[pairy[1]] = alpha_y[iy]
1925 jph[pairy[0]] = -gammas[1] + alpha_y[iy]*d[pairy[0]]/d[pairy[1]]
1926
1927 jph[pairx[1]] = alpha_x[ix]
1928 jph[pairx[0]] = -gammas[0] + alpha_x[ix]*d[pairx[0]]/d[pairx[1]]
1929
1930 jph_array[:,ix,iy] = jph
1931
1932 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, jph)
1933 error = meteorsArray1[:,-1]
1934 ind1 = numpy.where(error==0)[0]
1935 penalty[ix,iy] = ind1.size
1936
1937 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
1938 phOffset = jph_array[:,i,j]
1939
1940 center_xangle = phOffset[pairx[1]]
1941 center_yangle = phOffset[pairy[1]]
1942
1943 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
1944 phOffset = phOffset*180/numpy.pi
1945 return phOffset
1946
1947
1948 def run(self, dataOut, pairs, distances, hmin, hmax, nHours = None):
1949
1950 dataOut.flagNoData = True
1951 self.__dataReady = False
1952
1953 if nHours == None:
1954 nHours = 1
1955
1956 dataOut.outputInterval = nHours*3600
1957
1958 if self.__isConfig == False:
1959 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1960 #Get Initial LTC time
1961 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
1962 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1963
1964 self.__isConfig = True
1965
1966 if self.__buffer == None:
1967 self.__buffer = dataOut.data_param.copy()
1968
1969 else:
1970 self.__buffer = numpy.hstack((self.__buffer, dataOut.data_param))
1971
1972 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1973
1974 if self.__dataReady:
1975 dataOut.utctimeInit = self.__initime
1976 self.__initime += dataOut.outputInterval #to erase time offset
1977
1978 freq = dataOut.frequency
1979 c = dataOut.C #m/s
1980 lamb = c/freq
1981 k = 2*numpy.pi/lamb
1982 azimuth = 0
1983 h = (hmin, hmax)
1984 pairsList = ((0,3),(1,2))
1985
1986 meteorsArray = self.__buffer[0,:,:]
1987 error = meteorsArray[:,-1]
1988 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
1989 ind1 = numpy.where(boolError)[0]
1990 meteorsArray = meteorsArray[ind1,:]
1991 meteorsArray[:,-1] = 0
1992 phases = meteorsArray[:,9:13]
1993
1994 #Calculate Gammas
1995 gammas = self.__getGammas(pairs, k, distances, phases)
1996 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
1997 #Calculate Phases
1998 phasesOff = self.__getPhases(azimuth, h, pairsList, distances, gammas, meteorsArray)
1999 phasesOff = phasesOff.reshape((1,phasesOff.size))
2000 dataOut.data_output = -phasesOff
2001 dataOut.flagNoData = False
2002 self.__buffer = None
2003
2004
2005 return
2006
2007 class MeteorOperations():
2008
2009 def __init__(self):
2010
2011 return
2012
2013 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, jph):
1782
2014
2015 arrayParameters = arrayParameters0.copy()
2016 hmin = h[0]
2017 hmax = h[1]
1783
2018
2019 #Calculate AOA (Error N 3, 4)
2020 #JONES ET AL. 1998
2021 AOAthresh = numpy.pi/8
2022 error = arrayParameters[:,-1]
2023 phases = -arrayParameters[:,9:13] + jph
2024 arrayParameters[:,4:7], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, error, AOAthresh, azimuth)
2025
2026 #Calculate Heights (Error N 13 and 14)
2027 error = arrayParameters[:,-1]
2028 Ranges = arrayParameters[:,2]
2029 zenith = arrayParameters[:,5]
2030 arrayParameters[:,3], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
2031
2032 #----------------------- Get Final data ------------------------------------
2033 # error = arrayParameters[:,-1]
2034 # ind1 = numpy.where(error==0)[0]
2035 # arrayParameters = arrayParameters[ind1,:]
2036
2037 return arrayParameters
2038
2039 def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
2040
2041 arrayAOA = numpy.zeros((phases.shape[0],3))
2042 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
2043
2044 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
2045 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
2046 arrayAOA[:,2] = cosDirError
2047
2048 azimuthAngle = arrayAOA[:,0]
2049 zenithAngle = arrayAOA[:,1]
2050
2051 #Setting Error
2052 #Number 3: AOA not fesible
2053 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
2054 error[indInvalid] = 3
2055 #Number 4: Large difference in AOAs obtained from different antenna baselines
2056 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
2057 error[indInvalid] = 4
2058 return arrayAOA, error
2059
2060 def __getDirectionCosines(self, arrayPhase, pairsList):
2061
2062 #Initializing some variables
2063 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
2064 ang_aux = ang_aux.reshape(1,ang_aux.size)
2065
2066 cosdir = numpy.zeros((arrayPhase.shape[0],2))
2067 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
2068
2069
2070 for i in range(2):
2071 #First Estimation
2072 phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
2073 #Dealias
2074 indcsi = numpy.where(phi0_aux > numpy.pi)
2075 phi0_aux[indcsi] -= 2*numpy.pi
2076 indcsi = numpy.where(phi0_aux < -numpy.pi)
2077 phi0_aux[indcsi] += 2*numpy.pi
2078 #Direction Cosine 0
2079 cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
2080
2081 #Most-Accurate Second Estimation
2082 phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
2083 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
2084 #Direction Cosine 1
2085 cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
2086
2087 #Searching the correct Direction Cosine
2088 cosdir0_aux = cosdir0[:,i]
2089 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
2090 #Minimum Distance
2091 cosDiff = (cosdir1 - cosdir0_aux)**2
2092 indcos = cosDiff.argmin(axis = 1)
2093 #Saving Value obtained
2094 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
2095
2096 return cosdir0, cosdir
2097
2098 def __calculateAOA(self, cosdir, azimuth):
2099 cosdirX = cosdir[:,0]
2100 cosdirY = cosdir[:,1]
2101
2102 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
2103 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
2104 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
2105
2106 return angles
2107
2108 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
2109
2110 Ramb = 375 #Ramb = c/(2*PRF)
2111 Re = 6371 #Earth Radius
2112 heights = numpy.zeros(Ranges.shape)
2113
2114 R_aux = numpy.array([0,1,2])*Ramb
2115 R_aux = R_aux.reshape(1,R_aux.size)
2116
2117 Ranges = Ranges.reshape(Ranges.size,1)
2118
2119 Ri = Ranges + R_aux
2120 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
2121
2122 #Check if there is a height between 70 and 110 km
2123 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
2124 ind_h = numpy.where(h_bool == 1)[0]
2125
2126 hCorr = hi[ind_h, :]
2127 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
2128
2129 hCorr = hi[ind_hCorr]
2130 heights[ind_h] = hCorr
2131
2132 #Setting Error
2133 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
2134 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
2135
2136 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
2137 error[indInvalid2] = 14
2138 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
2139 error[indInvalid1] = 13
2140
2141 return heights, error
1784
2142
1785
2143
1786 No newline at end of file
2144
General Comments 0
You need to be logged in to leave comments. Login now