##// END OF EJS Templates
LAST CHANGE WR
avaldez -
r1393:ccbe99dfcead
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -0,0 +1,217
1 # Ing. AVP
2 # 06/10/2021
3 # ARCHIVO DE LECTURA
4 import os, sys
5 import datetime
6 import time
7 from schainpy.controller import Project
8 #### NOTA###########################################
9 # INPUT :
10 # VELOCIDAD PARAMETRO : V = 2Β°/seg
11 # MODO PULSE PAIR O MOMENTOS: 0 : Pulse Pair ,1 : Momentos
12 ######################################################
13 ##### PROCESAMIENTO ##################################
14 ##### OJO TENER EN CUENTA EL n= para el Pulse Pair ##
15 ##### O EL n= nFFTPoints ###
16 ######################################################
17 ######## BUSCAMOS EL numero de IPP equivalente 1Β°#####
18 ######## Sea V la velocidad del Pedestal en Β°/seg#####
19 ######## 1Β° sera Recorrido en un tiempo de 1/V ######
20 ######## IPP del Radar 400 useg --> 60 Km ############
21 ######## n = 1/(V(Β°/seg)*IPP(Km)) , NUMERO DE IPP ##
22 ######## n = 1/(V*IPP) #############################
23 ######## VELOCIDAD DEL PEDESTAL ######################
24 print("SETUP- RADAR METEOROLOGICO")
25 V = 10
26 mode = 1
27 #path = '/DATA_RM/23/6v'
28 #path = '/DATA_RM/TEST_INTEGRACION_2M'
29 path = '/DATA_RM/WR_20_OCT'
30
31 #path_ped='/DATA_RM/TEST_PEDESTAL/P20211012-082745'
32 path_ped='/DATA_RM/TEST_PEDESTAL/P20211020-131248'
33
34 figpath_pp = "/home/soporte/Pictures/TEST_PP"
35 figpath_mom = "/home/soporte/Pictures/TEST_MOM"
36 plot = 0
37 integration = 1
38 save = 0
39 if save == 1:
40 if mode==0:
41 path_save = '/DATA_RM/TEST_HDF5_PP_23/6v'
42 path_save = '/DATA_RM/TEST_HDF5_PP'
43 path_save = '/DATA_RM/TEST_HDF5_PP_100'
44 else:
45 path_save = '/DATA_RM/TEST_HDF5_SPEC_23_V2/6v'
46
47 print("* PATH data ADQ :", path)
48 print("* Velocidad Pedestal :",V,"Β°/seg")
49 ############################ NRO Perfiles PROCESAMIENTO ###################
50 V=V
51 IPP=400*1e-6
52 n= int(1/(V*IPP))
53 print("* n - NRO Perfiles Proc:", n )
54 ################################## MODE ###################################
55 print("* Modo de Operacion :",mode)
56 if mode ==0:
57 print("* Met. Seleccionado : Pulse Pair")
58 else:
59 print("* Met. Momentos : Momentos")
60
61 ################################## MODE ###################################
62 print("* Grabado de datos :",save)
63 if save ==1:
64 if mode==0:
65 ope= "Pulse Pair"
66 else:
67 ope= "Momentos"
68 print("* Path-Save Data -", ope , path_save)
69
70 print("* Integracion de datos :",integration)
71
72 time.sleep(15)
73 #remotefolder = "/home/wmaster/graficos"
74 #######################################################################
75 ################# RANGO DE PLOTEO######################################
76 dBmin = '1'
77 dBmax = '85'
78 xmin = '15'
79 xmax = '15.25'
80 ymin = '0'
81 ymax = '600'
82 #######################################################################
83 ########################FECHA##########################################
84 str = datetime.date.today()
85 today = str.strftime("%Y/%m/%d")
86 str2 = str - datetime.timedelta(days=1)
87 yesterday = str2.strftime("%Y/%m/%d")
88 #######################################################################
89 ########################SIGNAL CHAIN ##################################
90 #######################################################################
91 desc = "USRP_test"
92 filename = "USRP_processing.xml"
93 controllerObj = Project()
94 controllerObj.setup(id = '191', name='Test_USRP', description=desc)
95 #######################################################################
96 ######################## UNIDAD DE LECTURA#############################
97 #######################################################################
98 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader',
99 path=path,
100 startDate="2021/01/01",#today,
101 endDate="2021/12/30",#today,
102 startTime='00:00:00',
103 endTime='23:59:59',
104 delay=0,
105 #set=0,
106 online=0,
107 walk=1,
108 ippKm = 60)
109
110 opObj11 = readUnitConfObj.addOperation(name='printInfo')
111
112 procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
113
114 if mode ==0:
115 ####################### METODO PULSE PAIR ######################################################################
116 opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other')
117 opObj11.addParameter(name='n', value=int(n), format='int')#10 VOY A USAR 250 DADO QUE LA VELOCIDAD ES 10 GRADOS
118 #opObj11.addParameter(name='removeDC', value=1, format='int')
119 ####################### METODO Parametros ######################################################################
120 procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId())
121 if plot==1:
122 opObj11 = procUnitConfObjB.addOperation(name='GenericRTIPlot',optype='external')
123 opObj11.addParameter(name='attr_data', value='dataPP_POW')
124 opObj11.addParameter(name='colormap', value='jet')
125 opObj11.addParameter(name='xmin', value=xmin)
126 opObj11.addParameter(name='xmax', value=xmax)
127 opObj11.addParameter(name='zmin', value=dBmin)
128 opObj11.addParameter(name='zmax', value=dBmax)
129 opObj11.addParameter(name='save', value=figpath_pp)
130 opObj11.addParameter(name='showprofile', value=0)
131 opObj11.addParameter(name='save_period', value=50)
132
133 ####################### METODO ESCRITURA #######################################################################
134 if save==1:
135 opObj10 = procUnitConfObjB.addOperation(name='HDFWriter')
136 opObj10.addParameter(name='path',value=path_save)
137 #opObj10.addParameter(name='mode',value=0)
138 opObj10.addParameter(name='blocksPerFile',value='100',format='int')
139 opObj10.addParameter(name='metadataList',value='utctimeInit,timeZone,paramInterval,profileIndex,channelList,heightList,flagDataAsBlock',format='list')
140 opObj10.addParameter(name='dataList',value='dataPP_POW,dataPP_DOP,utctime',format='list')#,format='list'
141 if integration==1:
142 V=10
143 blocksPerfile=360
144 print("* Velocidad del Pedestal:",V)
145 tmp_blocksPerfile = 100
146 f_a_p= int(tmp_blocksPerfile/V)
147
148 opObj11 = procUnitConfObjB.addOperation(name='PedestalInformation')
149 opObj11.addParameter(name='path_ped', value=path_ped)
150 #opObj11.addParameter(name='path_adq', value=path_adq)
151 opObj11.addParameter(name='t_Interval_p', value='0.01', format='float')
152 opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int')
153 opObj11.addParameter(name='n_Muestras_p', value='100', format='float')
154 opObj11.addParameter(name='f_a_p', value=f_a_p, format='int')
155 opObj11.addParameter(name='online', value='0', format='int')
156
157 opObj11 = procUnitConfObjB.addOperation(name='Block360')
158 opObj11.addParameter(name='n', value='10', format='int')
159 opObj11.addParameter(name='mode', value=mode, format='int')
160
161 # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180
162
163 opObj11= procUnitConfObjB.addOperation(name='WeatherPlot',optype='other')
164
165
166 else:
167 ####################### METODO SPECTROS ######################################################################
168 procUnitConfObjB = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjA.getId())
169 procUnitConfObjB.addParameter(name='nFFTPoints', value=n, format='int')
170 procUnitConfObjB.addParameter(name='nProfiles' , value=n, format='int')
171
172 procUnitConfObjC = controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjB.getId())
173 procUnitConfObjC.addOperation(name='SpectralMoments')
174 if plot==1:
175 dBmin = '1'
176 dBmax = '65'
177 opObj11 = procUnitConfObjC.addOperation(name='PowerPlot',optype='external')
178 opObj11.addParameter(name='xmin', value=xmin)
179 opObj11.addParameter(name='xmax', value=xmax)
180 opObj11.addParameter(name='zmin', value=dBmin)
181 opObj11.addParameter(name='zmax', value=dBmax)
182 opObj11.addParameter(name='save', value=figpath_mom)
183 opObj11.addParameter(name='showprofile', value=0)
184 opObj11.addParameter(name='save_period', value=100)
185
186 if save==1:
187 opObj10 = procUnitConfObjC.addOperation(name='HDFWriter')
188 opObj10.addParameter(name='path',value=path_save)
189 #opObj10.addParameter(name='mode',value=0)
190 opObj10.addParameter(name='blocksPerFile',value='360',format='int')
191 #opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
192 opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
193 opObj10.addParameter(name='dataList',value='data_pow,data_dop,utctime',format='list')#,format='list'
194
195 if integration==1:
196 V=10
197 blocksPerfile=360
198 print("* Velocidad del Pedestal:",V)
199 tmp_blocksPerfile = 100
200 f_a_p= int(tmp_blocksPerfile/V)
201
202 opObj11 = procUnitConfObjC.addOperation(name='PedestalInformation')
203 opObj11.addParameter(name='path_ped', value=path_ped)
204 #opObj11.addParameter(name='path_adq', value=path_adq)
205 opObj11.addParameter(name='t_Interval_p', value='0.01', format='float')
206 opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int')
207 opObj11.addParameter(name='n_Muestras_p', value='100', format='float')
208 opObj11.addParameter(name='f_a_p', value=f_a_p, format='int')
209 opObj11.addParameter(name='online', value='0', format='int')
210
211 opObj11 = procUnitConfObjC.addOperation(name='Block360')
212 opObj11.addParameter(name='n', value='30', format='int')
213 opObj11.addParameter(name='mode', value=mode, format='int')
214
215 # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180
216 opObj11= procUnitConfObjC.addOperation(name='WeatherPlot',optype='other')
217 controllerObj.start()
@@ -0,0 +1,13
1
2 PULSE PAIR
3 help [[1.364 1.376 1.28 ... 1.352 1.372 1.332]
4 [2.912 3.012 3.06 ... 3.056 2.6 2.936]]
5 help [[1.256 1.304 1.212 ... 1.228 1.328 1.528]
6 [2.744 2.604 2.492 ... 2.544 2.916 2.644]]
7 help [[1.176 1.248 1.48 ... 1.388 1.396 1.216]
8 [2.564 2.524 2.756 ... 2.772 2.7 2.684]]
9
10 help [[1.312 1.328 1.28 ... 1.28 1.444 1.532]
11 [3. 2.964 3.092 ... 3.104 3.016 2.984]]
12
13 MOMENTOS
@@ -0,0 +1,69
1 # Ing. AVP
2 # 06/10/2021
3 # ARCHIVO DE LECTURA
4 import os, sys
5 import datetime
6 import time
7 from schainpy.controller import Project
8
9 print("SETUP- RADAR METEOROLOGICO")
10 V = 10
11 #######################################################################
12 ################# RANGO DE PLOTEO######################################
13 dBmin = '1'
14 dBmax = '65'
15 xmin = '13.2'
16 xmax = '13.5'
17 ymin = '0'
18 ymax = '60'
19
20 path = '/DATA_RM/WR_20_OCT'
21 figpath_pp = "/home/soporte/Pictures/TEST_PP"
22
23
24 IPP=400*1e-6
25 n= int(1/(V*IPP))
26 #n=250
27 print("* n - NRO Perfiles Proc:", n )
28
29 desc = "USRP_test"
30 filename = "USRP_processing.xml"
31 controllerObj = Project()
32 controllerObj.setup(id = '191', name='Test_USRP', description=desc)
33 #######################################################################
34 ######################## UNIDAD DE LECTURA#############################
35 #######################################################################
36 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader',
37 path=path,
38 startDate="2021/01/01",#today,
39 endDate="2021/12/30",#today,
40 startTime='00:00:00',
41 endTime='23:59:59',
42 delay=0,
43 #set=0,
44 online=0,
45 walk=1,
46 ippKm = 60)
47
48 opObj11 = readUnitConfObj.addOperation(name='printInfo')
49
50 procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
51
52 opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other')
53 opObj11.addParameter(name='n', value=int(n), format='int')#10 VOY A USAR 250 DADO QUE LA VELOCIDAD ES 10 GRADOS
54 #opObj11.addParameter(name='removeDC', value=1, format='int')
55
56 procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId())
57
58 opObj11 = procUnitConfObjB.addOperation(name='GenericRTIPlot',optype='external')
59 opObj11.addParameter(name='attr_data', value='dataPP_POWER')
60 opObj11.addParameter(name='colormap', value='jet')
61 opObj11.addParameter(name='xmin', value=xmin)
62 opObj11.addParameter(name='xmax', value=xmax)
63 opObj11.addParameter(name='zmin', value=dBmin)
64 opObj11.addParameter(name='zmax', value=dBmax)
65 opObj11.addParameter(name='save', value=figpath_pp)
66 opObj11.addParameter(name='showprofile', value=0)
67 #opObj11.addParameter(name='save_period', value=10)
68
69 controllerObj.start()
@@ -0,0 +1,80
1 # Ing. AVP
2 # 06/10/2021
3 # ARCHIVO DE LECTURA
4 import os, sys
5 import datetime
6 import time
7 from schainpy.controller import Project
8
9 print("SETUP- RADAR METEOROLOGICO")
10 V = 10
11 #######################################################################
12 ################# RANGO DE PLOTEO######################################
13 dBmin = '1'
14 dBmax = '65'
15 xmin = '13.2'
16 xmax = '13.5'
17 ymin = '0'
18 ymax = '60'
19
20 path = '/DATA_RM/WR_20_OCT'
21 figpath_spec = "/home/soporte/Pictures/TEST_MOM"
22
23
24 IPP=400*1e-6
25 n= int(1/(V*IPP))
26 print("* n - NRO Perfiles Proc:", n )
27 time.sleep(5)
28 desc = "USRP_test"
29 filename = "USRP_processing.xml"
30 controllerObj = Project()
31 controllerObj.setup(id = '191', name='Test_USRP', description=desc)
32 #######################################################################
33 ######################## UNIDAD DE LECTURA#############################
34 #######################################################################
35 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader',
36 path=path,
37 startDate="2021/01/01",#today,
38 endDate="2021/12/30",#today,
39 startTime='00:00:00',
40 endTime='23:59:59',
41 delay=0,
42 #set=0,
43 online=0,
44 walk=1,
45 ippKm = 60)
46
47 opObj11 = readUnitConfObj.addOperation(name='printInfo')
48
49 procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
50
51 procUnitConfObjB = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjA.getId())
52 procUnitConfObjB.addParameter(name='nFFTPoints', value=n, format='int')
53 procUnitConfObjB.addParameter(name='nProfiles' , value=n, format='int')
54 '''
55 opObj11 = procUnitConfObjB.addOperation(name='RTIPlot', optype='external')
56 #.addParameter(name='id', value='2', format='int')
57 opObj11.addParameter(name='wintitle', value='RTIPlot', format='str')
58 opObj11.addParameter(name='xmin', value=xmin)
59 opObj11.addParameter(name='xmax', value=xmax)
60 opObj11.addParameter(name='zmin', value=dBmin, format='int')
61 opObj11.addParameter(name='zmax', value=dBmax, format='int')
62 '''
63 #opObj13 = procUnitConfObjB.addOperation(name='removeDC')
64 #opObj13.addParameter(name='mode', value='2', format='int')
65
66 procUnitConfObjC = controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjB.getId())
67 procUnitConfObjC.addOperation(name='SpectralMoments')
68
69 dBmin = '1'
70 dBmax = '65'
71 opObj11 = procUnitConfObjC.addOperation(name='PowerPlot',optype='external')
72 opObj11.addParameter(name='xmin', value=xmin)
73 opObj11.addParameter(name='xmax', value=xmax)
74 opObj11.addParameter(name='zmin', value=dBmin)
75 opObj11.addParameter(name='zmax', value=dBmax)
76 opObj11.addParameter(name='save', value=figpath_spec)
77 opObj11.addParameter(name='showprofile', value=0)
78 #opObj11.addParameter(name='save_period', value=10)
79
80 controllerObj.start()
@@ -1,1069 +1,1068
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Definition of diferent Data objects for different types of data
5 """Definition of diferent Data objects for different types of data
6
6
7 Here you will find the diferent data objects for the different types
7 Here you will find the diferent data objects for the different types
8 of data, this data objects must be used as dataIn or dataOut objects in
8 of data, this data objects must be used as dataIn or dataOut objects in
9 processing units and operations. Currently the supported data objects are:
9 processing units and operations. Currently the supported data objects are:
10 Voltage, Spectra, SpectraHeis, Fits, Correlation and Parameters
10 Voltage, Spectra, SpectraHeis, Fits, Correlation and Parameters
11 """
11 """
12
12
13 import copy
13 import copy
14 import numpy
14 import numpy
15 import datetime
15 import datetime
16 import json
16 import json
17
17
18 import schainpy.admin
18 import schainpy.admin
19 from schainpy.utils import log
19 from schainpy.utils import log
20 from .jroheaderIO import SystemHeader, RadarControllerHeader
20 from .jroheaderIO import SystemHeader, RadarControllerHeader
21 from schainpy.model.data import _noise
21 from schainpy.model.data import _noise
22
22
23
23
24 def getNumpyDtype(dataTypeCode):
24 def getNumpyDtype(dataTypeCode):
25
25
26 if dataTypeCode == 0:
26 if dataTypeCode == 0:
27 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
27 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
28 elif dataTypeCode == 1:
28 elif dataTypeCode == 1:
29 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
29 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
30 elif dataTypeCode == 2:
30 elif dataTypeCode == 2:
31 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
31 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
32 elif dataTypeCode == 3:
32 elif dataTypeCode == 3:
33 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
33 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
34 elif dataTypeCode == 4:
34 elif dataTypeCode == 4:
35 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
35 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
36 elif dataTypeCode == 5:
36 elif dataTypeCode == 5:
37 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
37 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
38 else:
38 else:
39 raise ValueError('dataTypeCode was not defined')
39 raise ValueError('dataTypeCode was not defined')
40
40
41 return numpyDtype
41 return numpyDtype
42
42
43
43
44 def getDataTypeCode(numpyDtype):
44 def getDataTypeCode(numpyDtype):
45
45
46 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
46 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
47 datatype = 0
47 datatype = 0
48 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
48 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
49 datatype = 1
49 datatype = 1
50 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
50 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
51 datatype = 2
51 datatype = 2
52 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
52 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
53 datatype = 3
53 datatype = 3
54 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
54 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
55 datatype = 4
55 datatype = 4
56 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
56 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
57 datatype = 5
57 datatype = 5
58 else:
58 else:
59 datatype = None
59 datatype = None
60
60
61 return datatype
61 return datatype
62
62
63
63
64 def hildebrand_sekhon(data, navg):
64 def hildebrand_sekhon(data, navg):
65 """
65 """
66 This method is for the objective determination of the noise level in Doppler spectra. This
66 This method is for the objective determination of the noise level in Doppler spectra. This
67 implementation technique is based on the fact that the standard deviation of the spectral
67 implementation technique is based on the fact that the standard deviation of the spectral
68 densities is equal to the mean spectral density for white Gaussian noise
68 densities is equal to the mean spectral density for white Gaussian noise
69
69
70 Inputs:
70 Inputs:
71 Data : heights
71 Data : heights
72 navg : numbers of averages
72 navg : numbers of averages
73
73
74 Return:
74 Return:
75 mean : noise's level
75 mean : noise's level
76 """
76 """
77
77
78 sortdata = numpy.sort(data, axis=None)
78 sortdata = numpy.sort(data, axis=None)
79 '''
79 '''
80 lenOfData = len(sortdata)
80 lenOfData = len(sortdata)
81 nums_min = lenOfData*0.2
81 nums_min = lenOfData*0.2
82
82
83 if nums_min <= 5:
83 if nums_min <= 5:
84
84
85 nums_min = 5
85 nums_min = 5
86
86
87 sump = 0.
87 sump = 0.
88 sumq = 0.
88 sumq = 0.
89
89
90 j = 0
90 j = 0
91 cont = 1
91 cont = 1
92
92
93 while((cont == 1)and(j < lenOfData)):
93 while((cont == 1)and(j < lenOfData)):
94
94
95 sump += sortdata[j]
95 sump += sortdata[j]
96 sumq += sortdata[j]**2
96 sumq += sortdata[j]**2
97
97
98 if j > nums_min:
98 if j > nums_min:
99 rtest = float(j)/(j-1) + 1.0/navg
99 rtest = float(j)/(j-1) + 1.0/navg
100 if ((sumq*j) > (rtest*sump**2)):
100 if ((sumq*j) > (rtest*sump**2)):
101 j = j - 1
101 j = j - 1
102 sump = sump - sortdata[j]
102 sump = sump - sortdata[j]
103 sumq = sumq - sortdata[j]**2
103 sumq = sumq - sortdata[j]**2
104 cont = 0
104 cont = 0
105
105
106 j += 1
106 j += 1
107
107
108 lnoise = sump / j
108 lnoise = sump / j
109 '''
109 '''
110 return _noise.hildebrand_sekhon(sortdata, navg)
110 return _noise.hildebrand_sekhon(sortdata, navg)
111
111
112
112
113 class Beam:
113 class Beam:
114
114
115 def __init__(self):
115 def __init__(self):
116 self.codeList = []
116 self.codeList = []
117 self.azimuthList = []
117 self.azimuthList = []
118 self.zenithList = []
118 self.zenithList = []
119
119
120
120
121 class GenericData(object):
121 class GenericData(object):
122
122
123 flagNoData = True
123 flagNoData = True
124
124
125 def copy(self, inputObj=None):
125 def copy(self, inputObj=None):
126
126
127 if inputObj == None:
127 if inputObj == None:
128 return copy.deepcopy(self)
128 return copy.deepcopy(self)
129
129
130 for key in list(inputObj.__dict__.keys()):
130 for key in list(inputObj.__dict__.keys()):
131
131
132 attribute = inputObj.__dict__[key]
132 attribute = inputObj.__dict__[key]
133
133
134 # If this attribute is a tuple or list
134 # If this attribute is a tuple or list
135 if type(inputObj.__dict__[key]) in (tuple, list):
135 if type(inputObj.__dict__[key]) in (tuple, list):
136 self.__dict__[key] = attribute[:]
136 self.__dict__[key] = attribute[:]
137 continue
137 continue
138
138
139 # If this attribute is another object or instance
139 # If this attribute is another object or instance
140 if hasattr(attribute, '__dict__'):
140 if hasattr(attribute, '__dict__'):
141 self.__dict__[key] = attribute.copy()
141 self.__dict__[key] = attribute.copy()
142 continue
142 continue
143
143
144 self.__dict__[key] = inputObj.__dict__[key]
144 self.__dict__[key] = inputObj.__dict__[key]
145
145
146 def deepcopy(self):
146 def deepcopy(self):
147
147
148 return copy.deepcopy(self)
148 return copy.deepcopy(self)
149
149
150 def isEmpty(self):
150 def isEmpty(self):
151
151
152 return self.flagNoData
152 return self.flagNoData
153
153
154 def isReady(self):
154 def isReady(self):
155
155
156 return not self.flagNoData
156 return not self.flagNoData
157
157
158
158
159 class JROData(GenericData):
159 class JROData(GenericData):
160
160
161 systemHeaderObj = SystemHeader()
161 systemHeaderObj = SystemHeader()
162 radarControllerHeaderObj = RadarControllerHeader()
162 radarControllerHeaderObj = RadarControllerHeader()
163 type = None
163 type = None
164 datatype = None # dtype but in string
164 datatype = None # dtype but in string
165 nProfiles = None
165 nProfiles = None
166 heightList = None
166 heightList = None
167 channelList = None
167 channelList = None
168 flagDiscontinuousBlock = False
168 flagDiscontinuousBlock = False
169 useLocalTime = False
169 useLocalTime = False
170 utctime = None
170 utctime = None
171 timeZone = None
171 timeZone = None
172 dstFlag = None
172 dstFlag = None
173 errorCount = None
173 errorCount = None
174 blocksize = None
174 blocksize = None
175 flagDecodeData = False # asumo q la data no esta decodificada
175 flagDecodeData = False # asumo q la data no esta decodificada
176 flagDeflipData = False # asumo q la data no esta sin flip
176 flagDeflipData = False # asumo q la data no esta sin flip
177 flagShiftFFT = False
177 flagShiftFFT = False
178 nCohInt = None
178 nCohInt = None
179 windowOfFilter = 1
179 windowOfFilter = 1
180 C = 3e8
180 C = 3e8
181 frequency = 49.92e6
181 frequency = 49.92e6
182 realtime = False
182 realtime = False
183 beacon_heiIndexList = None
183 beacon_heiIndexList = None
184 last_block = None
184 last_block = None
185 blocknow = None
185 blocknow = None
186 azimuth = None
186 azimuth = None
187 zenith = None
187 zenith = None
188 beam = Beam()
188 beam = Beam()
189 profileIndex = None
189 profileIndex = None
190 error = None
190 error = None
191 data = None
191 data = None
192 nmodes = None
192 nmodes = None
193 metadata_list = ['heightList', 'timeZone', 'type']
193 metadata_list = ['heightList', 'timeZone', 'type']
194
194
195 def __str__(self):
195 def __str__(self):
196
196
197 return '{} - {}'.format(self.type, self.datatime())
197 return '{} - {}'.format(self.type, self.datatime())
198
198
199 def getNoise(self):
199 def getNoise(self):
200
200
201 raise NotImplementedError
201 raise NotImplementedError
202
202
203 @property
203 @property
204 def nChannels(self):
204 def nChannels(self):
205
205
206 return len(self.channelList)
206 return len(self.channelList)
207
207
208 @property
208 @property
209 def channelIndexList(self):
209 def channelIndexList(self):
210
210
211 return list(range(self.nChannels))
211 return list(range(self.nChannels))
212
212
213 @property
213 @property
214 def nHeights(self):
214 def nHeights(self):
215
215
216 return len(self.heightList)
216 return len(self.heightList)
217
217
218 def getDeltaH(self):
218 def getDeltaH(self):
219
219
220 return self.heightList[1] - self.heightList[0]
220 return self.heightList[1] - self.heightList[0]
221
221
222 @property
222 @property
223 def ltctime(self):
223 def ltctime(self):
224
224
225 if self.useLocalTime:
225 if self.useLocalTime:
226 return self.utctime - self.timeZone * 60
226 return self.utctime - self.timeZone * 60
227
227
228 return self.utctime
228 return self.utctime
229
229
230 @property
230 @property
231 def datatime(self):
231 def datatime(self):
232
232
233 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
233 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
234 return datatimeValue
234 return datatimeValue
235
235
236 def getTimeRange(self):
236 def getTimeRange(self):
237
237
238 datatime = []
238 datatime = []
239
239
240 datatime.append(self.ltctime)
240 datatime.append(self.ltctime)
241 datatime.append(self.ltctime + self.timeInterval + 1)
241 datatime.append(self.ltctime + self.timeInterval + 1)
242
242
243 datatime = numpy.array(datatime)
243 datatime = numpy.array(datatime)
244
244
245 return datatime
245 return datatime
246
246
247 def getFmaxTimeResponse(self):
247 def getFmaxTimeResponse(self):
248
248
249 period = (10**-6) * self.getDeltaH() / (0.15)
249 period = (10**-6) * self.getDeltaH() / (0.15)
250
250
251 PRF = 1. / (period * self.nCohInt)
251 PRF = 1. / (period * self.nCohInt)
252
252
253 fmax = PRF
253 fmax = PRF
254
254
255 return fmax
255 return fmax
256
256
257 def getFmax(self):
257 def getFmax(self):
258 PRF = 1. / (self.ippSeconds * self.nCohInt)
258 PRF = 1. / (self.ippSeconds * self.nCohInt)
259
259
260 fmax = PRF
260 fmax = PRF
261 return fmax
261 return fmax
262
262
263 def getVmax(self):
263 def getVmax(self):
264
264
265 _lambda = self.C / self.frequency
265 _lambda = self.C / self.frequency
266
266
267 vmax = self.getFmax() * _lambda / 2
267 vmax = self.getFmax() * _lambda / 2
268
268
269 return vmax
269 return vmax
270
270
271 @property
271 @property
272 def ippSeconds(self):
272 def ippSeconds(self):
273 '''
273 '''
274 '''
274 '''
275 return self.radarControllerHeaderObj.ippSeconds
275 return self.radarControllerHeaderObj.ippSeconds
276
276
277 @ippSeconds.setter
277 @ippSeconds.setter
278 def ippSeconds(self, ippSeconds):
278 def ippSeconds(self, ippSeconds):
279 '''
279 '''
280 '''
280 '''
281 self.radarControllerHeaderObj.ippSeconds = ippSeconds
281 self.radarControllerHeaderObj.ippSeconds = ippSeconds
282
282
283 @property
283 @property
284 def code(self):
284 def code(self):
285 '''
285 '''
286 '''
286 '''
287 return self.radarControllerHeaderObj.code
287 return self.radarControllerHeaderObj.code
288
288
289 @code.setter
289 @code.setter
290 def code(self, code):
290 def code(self, code):
291 '''
291 '''
292 '''
292 '''
293 self.radarControllerHeaderObj.code = code
293 self.radarControllerHeaderObj.code = code
294
294
295 @property
295 @property
296 def nCode(self):
296 def nCode(self):
297 '''
297 '''
298 '''
298 '''
299 return self.radarControllerHeaderObj.nCode
299 return self.radarControllerHeaderObj.nCode
300
300
301 @nCode.setter
301 @nCode.setter
302 def nCode(self, ncode):
302 def nCode(self, ncode):
303 '''
303 '''
304 '''
304 '''
305 self.radarControllerHeaderObj.nCode = ncode
305 self.radarControllerHeaderObj.nCode = ncode
306
306
307 @property
307 @property
308 def nBaud(self):
308 def nBaud(self):
309 '''
309 '''
310 '''
310 '''
311 return self.radarControllerHeaderObj.nBaud
311 return self.radarControllerHeaderObj.nBaud
312
312
313 @nBaud.setter
313 @nBaud.setter
314 def nBaud(self, nbaud):
314 def nBaud(self, nbaud):
315 '''
315 '''
316 '''
316 '''
317 self.radarControllerHeaderObj.nBaud = nbaud
317 self.radarControllerHeaderObj.nBaud = nbaud
318
318
319 @property
319 @property
320 def ipp(self):
320 def ipp(self):
321 '''
321 '''
322 '''
322 '''
323 return self.radarControllerHeaderObj.ipp
323 return self.radarControllerHeaderObj.ipp
324
324
325 @ipp.setter
325 @ipp.setter
326 def ipp(self, ipp):
326 def ipp(self, ipp):
327 '''
327 '''
328 '''
328 '''
329 self.radarControllerHeaderObj.ipp = ipp
329 self.radarControllerHeaderObj.ipp = ipp
330
330
331 @property
331 @property
332 def metadata(self):
332 def metadata(self):
333 '''
333 '''
334 '''
334 '''
335
335
336 return {attr: getattr(self, attr) for attr in self.metadata_list}
336 return {attr: getattr(self, attr) for attr in self.metadata_list}
337
337
338
338
339 class Voltage(JROData):
339 class Voltage(JROData):
340
340
341 dataPP_POW = None
341 dataPP_POW = None
342 dataPP_DOP = None
342 dataPP_DOP = None
343 dataPP_WIDTH = None
343 dataPP_WIDTH = None
344 dataPP_SNR = None
344 dataPP_SNR = None
345
345
346 def __init__(self):
346 def __init__(self):
347 '''
347 '''
348 Constructor
348 Constructor
349 '''
349 '''
350
350
351 self.useLocalTime = True
351 self.useLocalTime = True
352 self.radarControllerHeaderObj = RadarControllerHeader()
352 self.radarControllerHeaderObj = RadarControllerHeader()
353 self.systemHeaderObj = SystemHeader()
353 self.systemHeaderObj = SystemHeader()
354 self.type = "Voltage"
354 self.type = "Voltage"
355 self.data = None
355 self.data = None
356 self.nProfiles = None
356 self.nProfiles = None
357 self.heightList = None
357 self.heightList = None
358 self.channelList = None
358 self.channelList = None
359 self.flagNoData = True
359 self.flagNoData = True
360 self.flagDiscontinuousBlock = False
360 self.flagDiscontinuousBlock = False
361 self.utctime = None
361 self.utctime = None
362 self.timeZone = 0
362 self.timeZone = 0
363 self.dstFlag = None
363 self.dstFlag = None
364 self.errorCount = None
364 self.errorCount = None
365 self.nCohInt = None
365 self.nCohInt = None
366 self.blocksize = None
366 self.blocksize = None
367 self.flagCohInt = False
367 self.flagCohInt = False
368 self.flagDecodeData = False # asumo q la data no esta decodificada
368 self.flagDecodeData = False # asumo q la data no esta decodificada
369 self.flagDeflipData = False # asumo q la data no esta sin flip
369 self.flagDeflipData = False # asumo q la data no esta sin flip
370 self.flagShiftFFT = False
370 self.flagShiftFFT = False
371 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
371 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
372 self.profileIndex = 0
372 self.profileIndex = 0
373 self.metadata_list = ['type', 'heightList', 'timeZone', 'nProfiles', 'channelList', 'nCohInt',
373 self.metadata_list = ['type', 'heightList', 'timeZone', 'nProfiles', 'channelList', 'nCohInt',
374 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp']
374 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp']
375
375
376 def getNoisebyHildebrand(self, channel=None):
376 def getNoisebyHildebrand(self, channel=None):
377 """
377 """
378 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
378 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
379
379
380 Return:
380 Return:
381 noiselevel
381 noiselevel
382 """
382 """
383
383
384 if channel != None:
384 if channel != None:
385 data = self.data[channel]
385 data = self.data[channel]
386 nChannels = 1
386 nChannels = 1
387 else:
387 else:
388 data = self.data
388 data = self.data
389 nChannels = self.nChannels
389 nChannels = self.nChannels
390
390
391 noise = numpy.zeros(nChannels)
391 noise = numpy.zeros(nChannels)
392 power = data * numpy.conjugate(data)
392 power = data * numpy.conjugate(data)
393
393
394 for thisChannel in range(nChannels):
394 for thisChannel in range(nChannels):
395 if nChannels == 1:
395 if nChannels == 1:
396 daux = power[:].real
396 daux = power[:].real
397 else:
397 else:
398 daux = power[thisChannel, :].real
398 daux = power[thisChannel, :].real
399 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
399 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
400
400
401 return noise
401 return noise
402
402
403 def getNoise(self, type=1, channel=None):
403 def getNoise(self, type=1, channel=None):
404
404
405 if type == 1:
405 if type == 1:
406 noise = self.getNoisebyHildebrand(channel)
406 noise = self.getNoisebyHildebrand(channel)
407
407
408 return noise
408 return noise
409
409
410 def getPower(self, channel=None):
410 def getPower(self, channel=None):
411
411
412 if channel != None:
412 if channel != None:
413 data = self.data[channel]
413 data = self.data[channel]
414 else:
414 else:
415 data = self.data
415 data = self.data
416
416
417 power = data * numpy.conjugate(data)
417 power = data * numpy.conjugate(data)
418 powerdB = 10 * numpy.log10(power.real)
418 powerdB = 10 * numpy.log10(power.real)
419 powerdB = numpy.squeeze(powerdB)
419 powerdB = numpy.squeeze(powerdB)
420
420
421 return powerdB
421 return powerdB
422
422
423 @property
423 @property
424 def timeInterval(self):
424 def timeInterval(self):
425
425
426 return self.ippSeconds * self.nCohInt
426 return self.ippSeconds * self.nCohInt
427
427
428 noise = property(getNoise, "I'm the 'nHeights' property.")
428 noise = property(getNoise, "I'm the 'nHeights' property.")
429
429
430
430
431 class Spectra(JROData):
431 class Spectra(JROData):
432
432
433 def __init__(self):
433 def __init__(self):
434 '''
434 '''
435 Constructor
435 Constructor
436 '''
436 '''
437
437
438 self.data_dc = None
438 self.data_dc = None
439 self.data_spc = None
439 self.data_spc = None
440 self.data_cspc = None
440 self.data_cspc = None
441 self.useLocalTime = True
441 self.useLocalTime = True
442 self.radarControllerHeaderObj = RadarControllerHeader()
442 self.radarControllerHeaderObj = RadarControllerHeader()
443 self.systemHeaderObj = SystemHeader()
443 self.systemHeaderObj = SystemHeader()
444 self.type = "Spectra"
444 self.type = "Spectra"
445 self.timeZone = 0
445 self.timeZone = 0
446 self.nProfiles = None
446 self.nProfiles = None
447 self.heightList = None
447 self.heightList = None
448 self.channelList = None
448 self.channelList = None
449 self.pairsList = None
449 self.pairsList = None
450 self.flagNoData = True
450 self.flagNoData = True
451 self.flagDiscontinuousBlock = False
451 self.flagDiscontinuousBlock = False
452 self.utctime = None
452 self.utctime = None
453 self.nCohInt = None
453 self.nCohInt = None
454 self.nIncohInt = None
454 self.nIncohInt = None
455 self.blocksize = None
455 self.blocksize = None
456 self.nFFTPoints = None
456 self.nFFTPoints = None
457 self.wavelength = None
457 self.wavelength = None
458 self.flagDecodeData = False # asumo q la data no esta decodificada
458 self.flagDecodeData = False # asumo q la data no esta decodificada
459 self.flagDeflipData = False # asumo q la data no esta sin flip
459 self.flagDeflipData = False # asumo q la data no esta sin flip
460 self.flagShiftFFT = False
460 self.flagShiftFFT = False
461 self.ippFactor = 1
461 self.ippFactor = 1
462 self.beacon_heiIndexList = []
462 self.beacon_heiIndexList = []
463 self.noise_estimation = None
463 self.noise_estimation = None
464 self.metadata_list = ['type', 'heightList', 'timeZone', 'pairsList', 'channelList', 'nCohInt',
464 self.metadata_list = ['type', 'heightList', 'timeZone', 'pairsList', 'channelList', 'nCohInt',
465 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp','nIncohInt', 'nFFTPoints', 'nProfiles']
465 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp','nIncohInt', 'nFFTPoints', 'nProfiles']
466
466
467 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
467 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
468 """
468 """
469 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
469 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
470
470
471 Return:
471 Return:
472 noiselevel
472 noiselevel
473 """
473 """
474
474
475 noise = numpy.zeros(self.nChannels)
475 noise = numpy.zeros(self.nChannels)
476
476
477 for channel in range(self.nChannels):
477 for channel in range(self.nChannels):
478 daux = self.data_spc[channel,
478 daux = self.data_spc[channel,
479 xmin_index:xmax_index, ymin_index:ymax_index]
479 xmin_index:xmax_index, ymin_index:ymax_index]
480 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
480 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
481
481
482 return noise
482 return noise
483
483
484 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
484 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
485
485
486 if self.noise_estimation is not None:
486 if self.noise_estimation is not None:
487 # this was estimated by getNoise Operation defined in jroproc_spectra.py
487 # this was estimated by getNoise Operation defined in jroproc_spectra.py
488 return self.noise_estimation
488 return self.noise_estimation
489 else:
489 else:
490 noise = self.getNoisebyHildebrand(
490 noise = self.getNoisebyHildebrand(
491 xmin_index, xmax_index, ymin_index, ymax_index)
491 xmin_index, xmax_index, ymin_index, ymax_index)
492 return noise
492 return noise
493
493
494 def getFreqRangeTimeResponse(self, extrapoints=0):
494 def getFreqRangeTimeResponse(self, extrapoints=0):
495
495
496 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
496 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
497 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2
497 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2
498
498
499 return freqrange
499 return freqrange
500
500
501 def getAcfRange(self, extrapoints=0):
501 def getAcfRange(self, extrapoints=0):
502
502
503 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
503 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
504 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
504 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
505
505
506 return freqrange
506 return freqrange
507
507
508 def getFreqRange(self, extrapoints=0):
508 def getFreqRange(self, extrapoints=0):
509
509
510 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
510 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
511 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
511 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
512
512
513 return freqrange
513 return freqrange
514
514
515 def getVelRange(self, extrapoints=0):
515 def getVelRange(self, extrapoints=0):
516
516
517 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
517 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
518 velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.)
518 velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.)
519
519
520 if self.nmodes:
520 if self.nmodes:
521 return velrange/self.nmodes
521 return velrange/self.nmodes
522 else:
522 else:
523 return velrange
523 return velrange
524
524
525 @property
525 @property
526 def nPairs(self):
526 def nPairs(self):
527
527
528 return len(self.pairsList)
528 return len(self.pairsList)
529
529
530 @property
530 @property
531 def pairsIndexList(self):
531 def pairsIndexList(self):
532
532
533 return list(range(self.nPairs))
533 return list(range(self.nPairs))
534
534
535 @property
535 @property
536 def normFactor(self):
536 def normFactor(self):
537
537
538 pwcode = 1
538 pwcode = 1
539
539
540 if self.flagDecodeData:
540 if self.flagDecodeData:
541 pwcode = numpy.sum(self.code[0]**2)
541 pwcode = numpy.sum(self.code[0]**2)
542 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
542 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
543 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
543 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
544
544
545 return normFactor
545 return normFactor
546
546
547 @property
547 @property
548 def flag_cspc(self):
548 def flag_cspc(self):
549
549
550 if self.data_cspc is None:
550 if self.data_cspc is None:
551 return True
551 return True
552
552
553 return False
553 return False
554
554
555 @property
555 @property
556 def flag_dc(self):
556 def flag_dc(self):
557
557
558 if self.data_dc is None:
558 if self.data_dc is None:
559 return True
559 return True
560
560
561 return False
561 return False
562
562
563 @property
563 @property
564 def timeInterval(self):
564 def timeInterval(self):
565
565
566 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
566 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
567 if self.nmodes:
567 if self.nmodes:
568 return self.nmodes*timeInterval
568 return self.nmodes*timeInterval
569 else:
569 else:
570 return timeInterval
570 return timeInterval
571
571
572 def getPower(self):
572 def getPower(self):
573
573
574 factor = self.normFactor
574 factor = self.normFactor
575 z = self.data_spc / factor
575 z = self.data_spc / factor
576 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
576 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
577 avg = numpy.average(z, axis=1)
577 avg = numpy.average(z, axis=1)
578
579 return 10 * numpy.log10(avg)
578 return 10 * numpy.log10(avg)
580
579
581 def getCoherence(self, pairsList=None, phase=False):
580 def getCoherence(self, pairsList=None, phase=False):
582
581
583 z = []
582 z = []
584 if pairsList is None:
583 if pairsList is None:
585 pairsIndexList = self.pairsIndexList
584 pairsIndexList = self.pairsIndexList
586 else:
585 else:
587 pairsIndexList = []
586 pairsIndexList = []
588 for pair in pairsList:
587 for pair in pairsList:
589 if pair not in self.pairsList:
588 if pair not in self.pairsList:
590 raise ValueError("Pair %s is not in dataOut.pairsList" % (
589 raise ValueError("Pair %s is not in dataOut.pairsList" % (
591 pair))
590 pair))
592 pairsIndexList.append(self.pairsList.index(pair))
591 pairsIndexList.append(self.pairsList.index(pair))
593 for i in range(len(pairsIndexList)):
592 for i in range(len(pairsIndexList)):
594 pair = self.pairsList[pairsIndexList[i]]
593 pair = self.pairsList[pairsIndexList[i]]
595 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
594 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
596 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
595 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
597 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
596 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
598 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
597 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
599 if phase:
598 if phase:
600 data = numpy.arctan2(avgcoherenceComplex.imag,
599 data = numpy.arctan2(avgcoherenceComplex.imag,
601 avgcoherenceComplex.real) * 180 / numpy.pi
600 avgcoherenceComplex.real) * 180 / numpy.pi
602 else:
601 else:
603 data = numpy.abs(avgcoherenceComplex)
602 data = numpy.abs(avgcoherenceComplex)
604
603
605 z.append(data)
604 z.append(data)
606
605
607 return numpy.array(z)
606 return numpy.array(z)
608
607
609 def setValue(self, value):
608 def setValue(self, value):
610
609
611 print("This property should not be initialized")
610 print("This property should not be initialized")
612
611
613 return
612 return
614
613
615 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
614 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
616
615
617
616
618 class SpectraHeis(Spectra):
617 class SpectraHeis(Spectra):
619
618
620 def __init__(self):
619 def __init__(self):
621
620
622 self.radarControllerHeaderObj = RadarControllerHeader()
621 self.radarControllerHeaderObj = RadarControllerHeader()
623 self.systemHeaderObj = SystemHeader()
622 self.systemHeaderObj = SystemHeader()
624 self.type = "SpectraHeis"
623 self.type = "SpectraHeis"
625 self.nProfiles = None
624 self.nProfiles = None
626 self.heightList = None
625 self.heightList = None
627 self.channelList = None
626 self.channelList = None
628 self.flagNoData = True
627 self.flagNoData = True
629 self.flagDiscontinuousBlock = False
628 self.flagDiscontinuousBlock = False
630 self.utctime = None
629 self.utctime = None
631 self.blocksize = None
630 self.blocksize = None
632 self.profileIndex = 0
631 self.profileIndex = 0
633 self.nCohInt = 1
632 self.nCohInt = 1
634 self.nIncohInt = 1
633 self.nIncohInt = 1
635
634
636 @property
635 @property
637 def normFactor(self):
636 def normFactor(self):
638 pwcode = 1
637 pwcode = 1
639 if self.flagDecodeData:
638 if self.flagDecodeData:
640 pwcode = numpy.sum(self.code[0]**2)
639 pwcode = numpy.sum(self.code[0]**2)
641
640
642 normFactor = self.nIncohInt * self.nCohInt * pwcode
641 normFactor = self.nIncohInt * self.nCohInt * pwcode
643
642
644 return normFactor
643 return normFactor
645
644
646 @property
645 @property
647 def timeInterval(self):
646 def timeInterval(self):
648
647
649 return self.ippSeconds * self.nCohInt * self.nIncohInt
648 return self.ippSeconds * self.nCohInt * self.nIncohInt
650
649
651
650
652 class Fits(JROData):
651 class Fits(JROData):
653
652
654 def __init__(self):
653 def __init__(self):
655
654
656 self.type = "Fits"
655 self.type = "Fits"
657 self.nProfiles = None
656 self.nProfiles = None
658 self.heightList = None
657 self.heightList = None
659 self.channelList = None
658 self.channelList = None
660 self.flagNoData = True
659 self.flagNoData = True
661 self.utctime = None
660 self.utctime = None
662 self.nCohInt = 1
661 self.nCohInt = 1
663 self.nIncohInt = 1
662 self.nIncohInt = 1
664 self.useLocalTime = True
663 self.useLocalTime = True
665 self.profileIndex = 0
664 self.profileIndex = 0
666 self.timeZone = 0
665 self.timeZone = 0
667
666
668 def getTimeRange(self):
667 def getTimeRange(self):
669
668
670 datatime = []
669 datatime = []
671
670
672 datatime.append(self.ltctime)
671 datatime.append(self.ltctime)
673 datatime.append(self.ltctime + self.timeInterval)
672 datatime.append(self.ltctime + self.timeInterval)
674
673
675 datatime = numpy.array(datatime)
674 datatime = numpy.array(datatime)
676
675
677 return datatime
676 return datatime
678
677
679 def getChannelIndexList(self):
678 def getChannelIndexList(self):
680
679
681 return list(range(self.nChannels))
680 return list(range(self.nChannels))
682
681
683 def getNoise(self, type=1):
682 def getNoise(self, type=1):
684
683
685
684
686 if type == 1:
685 if type == 1:
687 noise = self.getNoisebyHildebrand()
686 noise = self.getNoisebyHildebrand()
688
687
689 if type == 2:
688 if type == 2:
690 noise = self.getNoisebySort()
689 noise = self.getNoisebySort()
691
690
692 if type == 3:
691 if type == 3:
693 noise = self.getNoisebyWindow()
692 noise = self.getNoisebyWindow()
694
693
695 return noise
694 return noise
696
695
697 @property
696 @property
698 def timeInterval(self):
697 def timeInterval(self):
699
698
700 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
699 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
701
700
702 return timeInterval
701 return timeInterval
703
702
704 @property
703 @property
705 def ippSeconds(self):
704 def ippSeconds(self):
706 '''
705 '''
707 '''
706 '''
708 return self.ipp_sec
707 return self.ipp_sec
709
708
710 noise = property(getNoise, "I'm the 'nHeights' property.")
709 noise = property(getNoise, "I'm the 'nHeights' property.")
711
710
712
711
713 class Correlation(JROData):
712 class Correlation(JROData):
714
713
715 def __init__(self):
714 def __init__(self):
716 '''
715 '''
717 Constructor
716 Constructor
718 '''
717 '''
719 self.radarControllerHeaderObj = RadarControllerHeader()
718 self.radarControllerHeaderObj = RadarControllerHeader()
720 self.systemHeaderObj = SystemHeader()
719 self.systemHeaderObj = SystemHeader()
721 self.type = "Correlation"
720 self.type = "Correlation"
722 self.data = None
721 self.data = None
723 self.dtype = None
722 self.dtype = None
724 self.nProfiles = None
723 self.nProfiles = None
725 self.heightList = None
724 self.heightList = None
726 self.channelList = None
725 self.channelList = None
727 self.flagNoData = True
726 self.flagNoData = True
728 self.flagDiscontinuousBlock = False
727 self.flagDiscontinuousBlock = False
729 self.utctime = None
728 self.utctime = None
730 self.timeZone = 0
729 self.timeZone = 0
731 self.dstFlag = None
730 self.dstFlag = None
732 self.errorCount = None
731 self.errorCount = None
733 self.blocksize = None
732 self.blocksize = None
734 self.flagDecodeData = False # asumo q la data no esta decodificada
733 self.flagDecodeData = False # asumo q la data no esta decodificada
735 self.flagDeflipData = False # asumo q la data no esta sin flip
734 self.flagDeflipData = False # asumo q la data no esta sin flip
736 self.pairsList = None
735 self.pairsList = None
737 self.nPoints = None
736 self.nPoints = None
738
737
739 def getPairsList(self):
738 def getPairsList(self):
740
739
741 return self.pairsList
740 return self.pairsList
742
741
743 def getNoise(self, mode=2):
742 def getNoise(self, mode=2):
744
743
745 indR = numpy.where(self.lagR == 0)[0][0]
744 indR = numpy.where(self.lagR == 0)[0][0]
746 indT = numpy.where(self.lagT == 0)[0][0]
745 indT = numpy.where(self.lagT == 0)[0][0]
747
746
748 jspectra0 = self.data_corr[:, :, indR, :]
747 jspectra0 = self.data_corr[:, :, indR, :]
749 jspectra = copy.copy(jspectra0)
748 jspectra = copy.copy(jspectra0)
750
749
751 num_chan = jspectra.shape[0]
750 num_chan = jspectra.shape[0]
752 num_hei = jspectra.shape[2]
751 num_hei = jspectra.shape[2]
753
752
754 freq_dc = jspectra.shape[1] / 2
753 freq_dc = jspectra.shape[1] / 2
755 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
754 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
756
755
757 if ind_vel[0] < 0:
756 if ind_vel[0] < 0:
758 ind_vel[list(range(0, 1))] = ind_vel[list(
757 ind_vel[list(range(0, 1))] = ind_vel[list(
759 range(0, 1))] + self.num_prof
758 range(0, 1))] + self.num_prof
760
759
761 if mode == 1:
760 if mode == 1:
762 jspectra[:, freq_dc, :] = (
761 jspectra[:, freq_dc, :] = (
763 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
762 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
764
763
765 if mode == 2:
764 if mode == 2:
766
765
767 vel = numpy.array([-2, -1, 1, 2])
766 vel = numpy.array([-2, -1, 1, 2])
768 xx = numpy.zeros([4, 4])
767 xx = numpy.zeros([4, 4])
769
768
770 for fil in range(4):
769 for fil in range(4):
771 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
770 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
772
771
773 xx_inv = numpy.linalg.inv(xx)
772 xx_inv = numpy.linalg.inv(xx)
774 xx_aux = xx_inv[0, :]
773 xx_aux = xx_inv[0, :]
775
774
776 for ich in range(num_chan):
775 for ich in range(num_chan):
777 yy = jspectra[ich, ind_vel, :]
776 yy = jspectra[ich, ind_vel, :]
778 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
777 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
779
778
780 junkid = jspectra[ich, freq_dc, :] <= 0
779 junkid = jspectra[ich, freq_dc, :] <= 0
781 cjunkid = sum(junkid)
780 cjunkid = sum(junkid)
782
781
783 if cjunkid.any():
782 if cjunkid.any():
784 jspectra[ich, freq_dc, junkid.nonzero()] = (
783 jspectra[ich, freq_dc, junkid.nonzero()] = (
785 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
784 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
786
785
787 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
786 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
788
787
789 return noise
788 return noise
790
789
791 @property
790 @property
792 def timeInterval(self):
791 def timeInterval(self):
793
792
794 return self.ippSeconds * self.nCohInt * self.nProfiles
793 return self.ippSeconds * self.nCohInt * self.nProfiles
795
794
796 def splitFunctions(self):
795 def splitFunctions(self):
797
796
798 pairsList = self.pairsList
797 pairsList = self.pairsList
799 ccf_pairs = []
798 ccf_pairs = []
800 acf_pairs = []
799 acf_pairs = []
801 ccf_ind = []
800 ccf_ind = []
802 acf_ind = []
801 acf_ind = []
803 for l in range(len(pairsList)):
802 for l in range(len(pairsList)):
804 chan0 = pairsList[l][0]
803 chan0 = pairsList[l][0]
805 chan1 = pairsList[l][1]
804 chan1 = pairsList[l][1]
806
805
807 # Obteniendo pares de Autocorrelacion
806 # Obteniendo pares de Autocorrelacion
808 if chan0 == chan1:
807 if chan0 == chan1:
809 acf_pairs.append(chan0)
808 acf_pairs.append(chan0)
810 acf_ind.append(l)
809 acf_ind.append(l)
811 else:
810 else:
812 ccf_pairs.append(pairsList[l])
811 ccf_pairs.append(pairsList[l])
813 ccf_ind.append(l)
812 ccf_ind.append(l)
814
813
815 data_acf = self.data_cf[acf_ind]
814 data_acf = self.data_cf[acf_ind]
816 data_ccf = self.data_cf[ccf_ind]
815 data_ccf = self.data_cf[ccf_ind]
817
816
818 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
817 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
819
818
820 @property
819 @property
821 def normFactor(self):
820 def normFactor(self):
822 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
821 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
823 acf_pairs = numpy.array(acf_pairs)
822 acf_pairs = numpy.array(acf_pairs)
824 normFactor = numpy.zeros((self.nPairs, self.nHeights))
823 normFactor = numpy.zeros((self.nPairs, self.nHeights))
825
824
826 for p in range(self.nPairs):
825 for p in range(self.nPairs):
827 pair = self.pairsList[p]
826 pair = self.pairsList[p]
828
827
829 ch0 = pair[0]
828 ch0 = pair[0]
830 ch1 = pair[1]
829 ch1 = pair[1]
831
830
832 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
831 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
833 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
832 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
834 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
833 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
835
834
836 return normFactor
835 return normFactor
837
836
838
837
839 class Parameters(Spectra):
838 class Parameters(Spectra):
840
839
841 groupList = None # List of Pairs, Groups, etc
840 groupList = None # List of Pairs, Groups, etc
842 data_param = None # Parameters obtained
841 data_param = None # Parameters obtained
843 data_pre = None # Data Pre Parametrization
842 data_pre = None # Data Pre Parametrization
844 data_SNR = None # Signal to Noise Ratio
843 data_SNR = None # Signal to Noise Ratio
845 abscissaList = None # Abscissa, can be velocities, lags or time
844 abscissaList = None # Abscissa, can be velocities, lags or time
846 utctimeInit = None # Initial UTC time
845 utctimeInit = None # Initial UTC time
847 paramInterval = None # Time interval to calculate Parameters in seconds
846 paramInterval = None # Time interval to calculate Parameters in seconds
848 useLocalTime = True
847 useLocalTime = True
849 # Fitting
848 # Fitting
850 data_error = None # Error of the estimation
849 data_error = None # Error of the estimation
851 constants = None
850 constants = None
852 library = None
851 library = None
853 # Output signal
852 # Output signal
854 outputInterval = None # Time interval to calculate output signal in seconds
853 outputInterval = None # Time interval to calculate output signal in seconds
855 data_output = None # Out signal
854 data_output = None # Out signal
856 nAvg = None
855 nAvg = None
857 noise_estimation = None
856 noise_estimation = None
858 GauSPC = None # Fit gaussian SPC
857 GauSPC = None # Fit gaussian SPC
859
858
860 def __init__(self):
859 def __init__(self):
861 '''
860 '''
862 Constructor
861 Constructor
863 '''
862 '''
864 self.radarControllerHeaderObj = RadarControllerHeader()
863 self.radarControllerHeaderObj = RadarControllerHeader()
865 self.systemHeaderObj = SystemHeader()
864 self.systemHeaderObj = SystemHeader()
866 self.type = "Parameters"
865 self.type = "Parameters"
867 self.timeZone = 0
866 self.timeZone = 0
868
867
869 def getTimeRange1(self, interval):
868 def getTimeRange1(self, interval):
870
869
871 datatime = []
870 datatime = []
872
871
873 if self.useLocalTime:
872 if self.useLocalTime:
874 time1 = self.utctimeInit - self.timeZone * 60
873 time1 = self.utctimeInit - self.timeZone * 60
875 else:
874 else:
876 time1 = self.utctimeInit
875 time1 = self.utctimeInit
877
876
878 datatime.append(time1)
877 datatime.append(time1)
879 datatime.append(time1 + interval)
878 datatime.append(time1 + interval)
880 datatime = numpy.array(datatime)
879 datatime = numpy.array(datatime)
881
880
882 return datatime
881 return datatime
883
882
884 @property
883 @property
885 def timeInterval(self):
884 def timeInterval(self):
886
885
887 if hasattr(self, 'timeInterval1'):
886 if hasattr(self, 'timeInterval1'):
888 return self.timeInterval1
887 return self.timeInterval1
889 else:
888 else:
890 return self.paramInterval
889 return self.paramInterval
891
890
892 def setValue(self, value):
891 def setValue(self, value):
893
892
894 print("This property should not be initialized")
893 print("This property should not be initialized")
895
894
896 return
895 return
897
896
898 def getNoise(self):
897 def getNoise(self):
899
898
900 return self.spc_noise
899 return self.spc_noise
901
900
902 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
901 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
903
902
904
903
905 class PlotterData(object):
904 class PlotterData(object):
906 '''
905 '''
907 Object to hold data to be plotted
906 Object to hold data to be plotted
908 '''
907 '''
909
908
910 MAXNUMX = 200
909 MAXNUMX = 200
911 MAXNUMY = 200
910 MAXNUMY = 200
912
911
913 def __init__(self, code, exp_code, localtime=True):
912 def __init__(self, code, exp_code, localtime=True):
914
913
915 self.key = code
914 self.key = code
916 self.exp_code = exp_code
915 self.exp_code = exp_code
917 self.ready = False
916 self.ready = False
918 self.flagNoData = False
917 self.flagNoData = False
919 self.localtime = localtime
918 self.localtime = localtime
920 self.data = {}
919 self.data = {}
921 self.meta = {}
920 self.meta = {}
922 self.__heights = []
921 self.__heights = []
923
922
924 def __str__(self):
923 def __str__(self):
925 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
924 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
926 return 'Data[{}][{}]'.format(';'.join(dum), len(self.times))
925 return 'Data[{}][{}]'.format(';'.join(dum), len(self.times))
927
926
928 def __len__(self):
927 def __len__(self):
929 return len(self.data)
928 return len(self.data)
930
929
931 def __getitem__(self, key):
930 def __getitem__(self, key):
932 if isinstance(key, int):
931 if isinstance(key, int):
933 return self.data[self.times[key]]
932 return self.data[self.times[key]]
934 elif isinstance(key, str):
933 elif isinstance(key, str):
935 ret = numpy.array([self.data[x][key] for x in self.times])
934 ret = numpy.array([self.data[x][key] for x in self.times])
936 if ret.ndim > 1:
935 if ret.ndim > 1:
937 ret = numpy.swapaxes(ret, 0, 1)
936 ret = numpy.swapaxes(ret, 0, 1)
938 return ret
937 return ret
939
938
940 def __contains__(self, key):
939 def __contains__(self, key):
941 return key in self.data[self.min_time]
940 return key in self.data[self.min_time]
942
941
943 def setup(self):
942 def setup(self):
944 '''
943 '''
945 Configure object
944 Configure object
946 '''
945 '''
947 self.type = ''
946 self.type = ''
948 self.ready = False
947 self.ready = False
949 del self.data
948 del self.data
950 self.data = {}
949 self.data = {}
951 self.__heights = []
950 self.__heights = []
952 self.__all_heights = set()
951 self.__all_heights = set()
953
952
954 def shape(self, key):
953 def shape(self, key):
955 '''
954 '''
956 Get the shape of the one-element data for the given key
955 Get the shape of the one-element data for the given key
957 '''
956 '''
958
957
959 if len(self.data[self.min_time][key]):
958 if len(self.data[self.min_time][key]):
960 return self.data[self.min_time][key].shape
959 return self.data[self.min_time][key].shape
961 return (0,)
960 return (0,)
962
961
963 def update(self, data, tm, meta={}):
962 def update(self, data, tm, meta={}):
964 '''
963 '''
965 Update data object with new dataOut
964 Update data object with new dataOut
966 '''
965 '''
967
966
968 self.data[tm] = data
967 self.data[tm] = data
969
968
970 for key, value in meta.items():
969 for key, value in meta.items():
971 setattr(self, key, value)
970 setattr(self, key, value)
972
971
973 def normalize_heights(self):
972 def normalize_heights(self):
974 '''
973 '''
975 Ensure same-dimension of the data for different heighList
974 Ensure same-dimension of the data for different heighList
976 '''
975 '''
977
976
978 H = numpy.array(list(self.__all_heights))
977 H = numpy.array(list(self.__all_heights))
979 H.sort()
978 H.sort()
980 for key in self.data:
979 for key in self.data:
981 shape = self.shape(key)[:-1] + H.shape
980 shape = self.shape(key)[:-1] + H.shape
982 for tm, obj in list(self.data[key].items()):
981 for tm, obj in list(self.data[key].items()):
983 h = self.__heights[self.times.tolist().index(tm)]
982 h = self.__heights[self.times.tolist().index(tm)]
984 if H.size == h.size:
983 if H.size == h.size:
985 continue
984 continue
986 index = numpy.where(numpy.in1d(H, h))[0]
985 index = numpy.where(numpy.in1d(H, h))[0]
987 dummy = numpy.zeros(shape) + numpy.nan
986 dummy = numpy.zeros(shape) + numpy.nan
988 if len(shape) == 2:
987 if len(shape) == 2:
989 dummy[:, index] = obj
988 dummy[:, index] = obj
990 else:
989 else:
991 dummy[index] = obj
990 dummy[index] = obj
992 self.data[key][tm] = dummy
991 self.data[key][tm] = dummy
993
992
994 self.__heights = [H for tm in self.times]
993 self.__heights = [H for tm in self.times]
995
994
996 def jsonify(self, tm, plot_name, plot_type, decimate=False):
995 def jsonify(self, tm, plot_name, plot_type, decimate=False):
997 '''
996 '''
998 Convert data to json
997 Convert data to json
999 '''
998 '''
1000
999
1001 meta = {}
1000 meta = {}
1002 meta['xrange'] = []
1001 meta['xrange'] = []
1003 dy = int(len(self.yrange)/self.MAXNUMY) + 1
1002 dy = int(len(self.yrange)/self.MAXNUMY) + 1
1004 tmp = self.data[tm][self.key]
1003 tmp = self.data[tm][self.key]
1005 shape = tmp.shape
1004 shape = tmp.shape
1006 if len(shape) == 2:
1005 if len(shape) == 2:
1007 data = self.roundFloats(self.data[tm][self.key][::, ::dy].tolist())
1006 data = self.roundFloats(self.data[tm][self.key][::, ::dy].tolist())
1008 elif len(shape) == 3:
1007 elif len(shape) == 3:
1009 dx = int(self.data[tm][self.key].shape[1]/self.MAXNUMX) + 1
1008 dx = int(self.data[tm][self.key].shape[1]/self.MAXNUMX) + 1
1010 data = self.roundFloats(
1009 data = self.roundFloats(
1011 self.data[tm][self.key][::, ::dx, ::dy].tolist())
1010 self.data[tm][self.key][::, ::dx, ::dy].tolist())
1012 meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1011 meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1013 else:
1012 else:
1014 data = self.roundFloats(self.data[tm][self.key].tolist())
1013 data = self.roundFloats(self.data[tm][self.key].tolist())
1015
1014
1016 ret = {
1015 ret = {
1017 'plot': plot_name,
1016 'plot': plot_name,
1018 'code': self.exp_code,
1017 'code': self.exp_code,
1019 'time': float(tm),
1018 'time': float(tm),
1020 'data': data,
1019 'data': data,
1021 }
1020 }
1022 meta['type'] = plot_type
1021 meta['type'] = plot_type
1023 meta['interval'] = float(self.interval)
1022 meta['interval'] = float(self.interval)
1024 meta['localtime'] = self.localtime
1023 meta['localtime'] = self.localtime
1025 meta['yrange'] = self.roundFloats(self.yrange[::dy].tolist())
1024 meta['yrange'] = self.roundFloats(self.yrange[::dy].tolist())
1026 meta.update(self.meta)
1025 meta.update(self.meta)
1027 ret['metadata'] = meta
1026 ret['metadata'] = meta
1028 return json.dumps(ret)
1027 return json.dumps(ret)
1029
1028
1030 @property
1029 @property
1031 def times(self):
1030 def times(self):
1032 '''
1031 '''
1033 Return the list of times of the current data
1032 Return the list of times of the current data
1034 '''
1033 '''
1035
1034
1036 ret = [t for t in self.data]
1035 ret = [t for t in self.data]
1037 ret.sort()
1036 ret.sort()
1038 return numpy.array(ret)
1037 return numpy.array(ret)
1039
1038
1040 @property
1039 @property
1041 def min_time(self):
1040 def min_time(self):
1042 '''
1041 '''
1043 Return the minimun time value
1042 Return the minimun time value
1044 '''
1043 '''
1045
1044
1046 return self.times[0]
1045 return self.times[0]
1047
1046
1048 @property
1047 @property
1049 def max_time(self):
1048 def max_time(self):
1050 '''
1049 '''
1051 Return the maximun time value
1050 Return the maximun time value
1052 '''
1051 '''
1053
1052
1054 return self.times[-1]
1053 return self.times[-1]
1055
1054
1056 # @property
1055 # @property
1057 # def heights(self):
1056 # def heights(self):
1058 # '''
1057 # '''
1059 # Return the list of heights of the current data
1058 # Return the list of heights of the current data
1060 # '''
1059 # '''
1061
1060
1062 # return numpy.array(self.__heights[-1])
1061 # return numpy.array(self.__heights[-1])
1063
1062
1064 @staticmethod
1063 @staticmethod
1065 def roundFloats(obj):
1064 def roundFloats(obj):
1066 if isinstance(obj, list):
1065 if isinstance(obj, list):
1067 return list(map(PlotterData.roundFloats, obj))
1066 return list(map(PlotterData.roundFloats, obj))
1068 elif isinstance(obj, float):
1067 elif isinstance(obj, float):
1069 return round(obj, 2)
1068 return round(obj, 2)
@@ -1,519 +1,509
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4
4
5 from schainpy.model.graphics.jroplot_base import Plot, plt
5 from schainpy.model.graphics.jroplot_base import Plot, plt
6 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
6 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot
7 from schainpy.utils import log
7 from schainpy.utils import log
8 # libreria wradlib
8 # libreria wradlib
9 import wradlib as wrl
9 import wradlib as wrl
10
10
11 EARTH_RADIUS = 6.3710e3
11 EARTH_RADIUS = 6.3710e3
12
12
13
13
14 def ll2xy(lat1, lon1, lat2, lon2):
14 def ll2xy(lat1, lon1, lat2, lon2):
15
15
16 p = 0.017453292519943295
16 p = 0.017453292519943295
17 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
17 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
18 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
18 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
19 r = 12742 * numpy.arcsin(numpy.sqrt(a))
19 r = 12742 * numpy.arcsin(numpy.sqrt(a))
20 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
20 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
21 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
21 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
22 theta = -theta + numpy.pi/2
22 theta = -theta + numpy.pi/2
23 return r*numpy.cos(theta), r*numpy.sin(theta)
23 return r*numpy.cos(theta), r*numpy.sin(theta)
24
24
25
25
26 def km2deg(km):
26 def km2deg(km):
27 '''
27 '''
28 Convert distance in km to degrees
28 Convert distance in km to degrees
29 '''
29 '''
30
30
31 return numpy.rad2deg(km/EARTH_RADIUS)
31 return numpy.rad2deg(km/EARTH_RADIUS)
32
32
33
33
34
34
35 class SpectralMomentsPlot(SpectraPlot):
35 class SpectralMomentsPlot(SpectraPlot):
36 '''
36 '''
37 Plot for Spectral Moments
37 Plot for Spectral Moments
38 '''
38 '''
39 CODE = 'spc_moments'
39 CODE = 'spc_moments'
40 # colormap = 'jet'
40 # colormap = 'jet'
41 # plot_type = 'pcolor'
41 # plot_type = 'pcolor'
42
42
43 class DobleGaussianPlot(SpectraPlot):
43 class DobleGaussianPlot(SpectraPlot):
44 '''
44 '''
45 Plot for Double Gaussian Plot
45 Plot for Double Gaussian Plot
46 '''
46 '''
47 CODE = 'gaussian_fit'
47 CODE = 'gaussian_fit'
48 # colormap = 'jet'
48 # colormap = 'jet'
49 # plot_type = 'pcolor'
49 # plot_type = 'pcolor'
50
50
51 class DoubleGaussianSpectraCutPlot(SpectraCutPlot):
51 class DoubleGaussianSpectraCutPlot(SpectraCutPlot):
52 '''
52 '''
53 Plot SpectraCut with Double Gaussian Fit
53 Plot SpectraCut with Double Gaussian Fit
54 '''
54 '''
55 CODE = 'cut_gaussian_fit'
55 CODE = 'cut_gaussian_fit'
56
56
57 class SnrPlot(RTIPlot):
57 class SnrPlot(RTIPlot):
58 '''
58 '''
59 Plot for SNR Data
59 Plot for SNR Data
60 '''
60 '''
61
61
62 CODE = 'snr'
62 CODE = 'snr'
63 colormap = 'jet'
63 colormap = 'jet'
64
64
65 def update(self, dataOut):
65 def update(self, dataOut):
66
66
67 data = {
67 data = {
68 'snr': 10*numpy.log10(dataOut.data_snr)
68 'snr': 10*numpy.log10(dataOut.data_snr)
69 }
69 }
70
70
71 return data, {}
71 return data, {}
72
72
73 class DopplerPlot(RTIPlot):
73 class DopplerPlot(RTIPlot):
74 '''
74 '''
75 Plot for DOPPLER Data (1st moment)
75 Plot for DOPPLER Data (1st moment)
76 '''
76 '''
77
77
78 CODE = 'dop'
78 CODE = 'dop'
79 colormap = 'jet'
79 colormap = 'jet'
80
80
81 def update(self, dataOut):
81 def update(self, dataOut):
82
82
83 data = {
83 data = {
84 'dop': 10*numpy.log10(dataOut.data_dop)
84 'dop': 10*numpy.log10(dataOut.data_dop)
85 }
85 }
86
86
87 return data, {}
87 return data, {}
88
88
89 class PowerPlot(RTIPlot):
89 class PowerPlot(RTIPlot):
90 '''
90 '''
91 Plot for Power Data (0 moment)
91 Plot for Power Data (0 moment)
92 '''
92 '''
93
93
94 CODE = 'pow'
94 CODE = 'pow'
95 colormap = 'jet'
95 colormap = 'jet'
96
96
97 def update(self, dataOut):
97 def update(self, dataOut):
98
99 data = {
98 data = {
100 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor)
99 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor)
101 }
100 }
102
103 return data, {}
101 return data, {}
104
102
105 class SpectralWidthPlot(RTIPlot):
103 class SpectralWidthPlot(RTIPlot):
106 '''
104 '''
107 Plot for Spectral Width Data (2nd moment)
105 Plot for Spectral Width Data (2nd moment)
108 '''
106 '''
109
107
110 CODE = 'width'
108 CODE = 'width'
111 colormap = 'jet'
109 colormap = 'jet'
112
110
113 def update(self, dataOut):
111 def update(self, dataOut):
114
112
115 data = {
113 data = {
116 'width': dataOut.data_width
114 'width': dataOut.data_width
117 }
115 }
118
116
119 return data, {}
117 return data, {}
120
118
121 class SkyMapPlot(Plot):
119 class SkyMapPlot(Plot):
122 '''
120 '''
123 Plot for meteors detection data
121 Plot for meteors detection data
124 '''
122 '''
125
123
126 CODE = 'param'
124 CODE = 'param'
127
125
128 def setup(self):
126 def setup(self):
129
127
130 self.ncols = 1
128 self.ncols = 1
131 self.nrows = 1
129 self.nrows = 1
132 self.width = 7.2
130 self.width = 7.2
133 self.height = 7.2
131 self.height = 7.2
134 self.nplots = 1
132 self.nplots = 1
135 self.xlabel = 'Zonal Zenith Angle (deg)'
133 self.xlabel = 'Zonal Zenith Angle (deg)'
136 self.ylabel = 'Meridional Zenith Angle (deg)'
134 self.ylabel = 'Meridional Zenith Angle (deg)'
137 self.polar = True
135 self.polar = True
138 self.ymin = -180
136 self.ymin = -180
139 self.ymax = 180
137 self.ymax = 180
140 self.colorbar = False
138 self.colorbar = False
141
139
142 def plot(self):
140 def plot(self):
143
141
144 arrayParameters = numpy.concatenate(self.data['param'])
142 arrayParameters = numpy.concatenate(self.data['param'])
145 error = arrayParameters[:, -1]
143 error = arrayParameters[:, -1]
146 indValid = numpy.where(error == 0)[0]
144 indValid = numpy.where(error == 0)[0]
147 finalMeteor = arrayParameters[indValid, :]
145 finalMeteor = arrayParameters[indValid, :]
148 finalAzimuth = finalMeteor[:, 3]
146 finalAzimuth = finalMeteor[:, 3]
149 finalZenith = finalMeteor[:, 4]
147 finalZenith = finalMeteor[:, 4]
150
148
151 x = finalAzimuth * numpy.pi / 180
149 x = finalAzimuth * numpy.pi / 180
152 y = finalZenith
150 y = finalZenith
153
151
154 ax = self.axes[0]
152 ax = self.axes[0]
155
153
156 if ax.firsttime:
154 if ax.firsttime:
157 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
155 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
158 else:
156 else:
159 ax.plot.set_data(x, y)
157 ax.plot.set_data(x, y)
160
158
161 dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S')
159 dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S')
162 dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S')
160 dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S')
163 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
161 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
164 dt2,
162 dt2,
165 len(x))
163 len(x))
166 self.titles[0] = title
164 self.titles[0] = title
167
165
168
166
169 class GenericRTIPlot(Plot):
167 class GenericRTIPlot(Plot):
170 '''
168 '''
171 Plot for data_xxxx object
169 Plot for data_xxxx object
172 '''
170 '''
173
171
174 CODE = 'param'
172 CODE = 'param'
175 colormap = 'viridis'
173 colormap = 'viridis'
176 plot_type = 'pcolorbuffer'
174 plot_type = 'pcolorbuffer'
177
175
178 def setup(self):
176 def setup(self):
179 self.xaxis = 'time'
177 self.xaxis = 'time'
180 self.ncols = 1
178 self.ncols = 1
181 self.nrows = self.data.shape('param')[0]
179 self.nrows = self.data.shape('param')[0]
182 self.nplots = self.nrows
180 self.nplots = self.nrows
183 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
181 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
184
182
185 if not self.xlabel:
183 if not self.xlabel:
186 self.xlabel = 'Time'
184 self.xlabel = 'Time'
187
185
188 self.ylabel = 'Range [km]'
186 self.ylabel = 'Range [km]'
189 if not self.titles:
187 if not self.titles:
190 self.titles = ['Param {}'.format(x) for x in range(self.nrows)]
188 self.titles = ['Param {}'.format(x) for x in range(self.nrows)]
191
189
192 def update(self, dataOut):
190 def update(self, dataOut):
193
191
194 data = {
192 data = {
195 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0)
193 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0)
196 }
194 }
197
195
198 meta = {}
196 meta = {}
199
197
200 return data, meta
198 return data, meta
201
199
202 def plot(self):
200 def plot(self):
203 # self.data.normalize_heights()
201 # self.data.normalize_heights()
204 self.x = self.data.times
202 self.x = self.data.times
205 self.y = self.data.yrange
203 self.y = self.data.yrange
206 self.z = self.data['param']
204 self.z = self.data['param']
207
208 self.z = 10*numpy.log10(self.z)
205 self.z = 10*numpy.log10(self.z)
209
210 self.z = numpy.ma.masked_invalid(self.z)
206 self.z = numpy.ma.masked_invalid(self.z)
211
207
212 if self.decimation is None:
208 if self.decimation is None:
213 x, y, z = self.fill_gaps(self.x, self.y, self.z)
209 x, y, z = self.fill_gaps(self.x, self.y, self.z)
214 else:
210 else:
215 x, y, z = self.fill_gaps(*self.decimate())
211 x, y, z = self.fill_gaps(*self.decimate())
216
212
217 for n, ax in enumerate(self.axes):
213 for n, ax in enumerate(self.axes):
218
214
219 self.zmax = self.zmax if self.zmax is not None else numpy.max(
215 self.zmax = self.zmax if self.zmax is not None else numpy.max(
220 self.z[n])
216 self.z[n])
221 self.zmin = self.zmin if self.zmin is not None else numpy.min(
217 self.zmin = self.zmin if self.zmin is not None else numpy.min(
222 self.z[n])
218 self.z[n])
223
219
224 if ax.firsttime:
220 if ax.firsttime:
225 if self.zlimits is not None:
221 if self.zlimits is not None:
226 self.zmin, self.zmax = self.zlimits[n]
222 self.zmin, self.zmax = self.zlimits[n]
227
223
228 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
224 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
229 vmin=self.zmin,
225 vmin=self.zmin,
230 vmax=self.zmax,
226 vmax=self.zmax,
231 cmap=self.cmaps[n]
227 cmap=self.cmaps[n]
232 )
228 )
233 else:
229 else:
234 if self.zlimits is not None:
230 if self.zlimits is not None:
235 self.zmin, self.zmax = self.zlimits[n]
231 self.zmin, self.zmax = self.zlimits[n]
236 ax.collections.remove(ax.collections[0])
232 ax.collections.remove(ax.collections[0])
237 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
233 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
238 vmin=self.zmin,
234 vmin=self.zmin,
239 vmax=self.zmax,
235 vmax=self.zmax,
240 cmap=self.cmaps[n]
236 cmap=self.cmaps[n]
241 )
237 )
242
238
243
239
244 class PolarMapPlot(Plot):
240 class PolarMapPlot(Plot):
245 '''
241 '''
246 Plot for weather radar
242 Plot for weather radar
247 '''
243 '''
248
244
249 CODE = 'param'
245 CODE = 'param'
250 colormap = 'seismic'
246 colormap = 'seismic'
251
247
252 def setup(self):
248 def setup(self):
253 self.ncols = 1
249 self.ncols = 1
254 self.nrows = 1
250 self.nrows = 1
255 self.width = 9
251 self.width = 9
256 self.height = 8
252 self.height = 8
257 self.mode = self.data.meta['mode']
253 self.mode = self.data.meta['mode']
258 if self.channels is not None:
254 if self.channels is not None:
259 self.nplots = len(self.channels)
255 self.nplots = len(self.channels)
260 self.nrows = len(self.channels)
256 self.nrows = len(self.channels)
261 else:
257 else:
262 self.nplots = self.data.shape(self.CODE)[0]
258 self.nplots = self.data.shape(self.CODE)[0]
263 self.nrows = self.nplots
259 self.nrows = self.nplots
264 self.channels = list(range(self.nplots))
260 self.channels = list(range(self.nplots))
265 if self.mode == 'E':
261 if self.mode == 'E':
266 self.xlabel = 'Longitude'
262 self.xlabel = 'Longitude'
267 self.ylabel = 'Latitude'
263 self.ylabel = 'Latitude'
268 else:
264 else:
269 self.xlabel = 'Range (km)'
265 self.xlabel = 'Range (km)'
270 self.ylabel = 'Height (km)'
266 self.ylabel = 'Height (km)'
271 self.bgcolor = 'white'
267 self.bgcolor = 'white'
272 self.cb_labels = self.data.meta['units']
268 self.cb_labels = self.data.meta['units']
273 self.lat = self.data.meta['latitude']
269 self.lat = self.data.meta['latitude']
274 self.lon = self.data.meta['longitude']
270 self.lon = self.data.meta['longitude']
275 self.xmin, self.xmax = float(
271 self.xmin, self.xmax = float(
276 km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
272 km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
277 self.ymin, self.ymax = float(
273 self.ymin, self.ymax = float(
278 km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
274 km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
279 # self.polar = True
275 # self.polar = True
280
276
281 def plot(self):
277 def plot(self):
282
278
283 for n, ax in enumerate(self.axes):
279 for n, ax in enumerate(self.axes):
284 data = self.data['param'][self.channels[n]]
280 data = self.data['param'][self.channels[n]]
285
281
286 zeniths = numpy.linspace(
282 zeniths = numpy.linspace(
287 0, self.data.meta['max_range'], data.shape[1])
283 0, self.data.meta['max_range'], data.shape[1])
288 if self.mode == 'E':
284 if self.mode == 'E':
289 azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2
285 azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2
290 r, theta = numpy.meshgrid(zeniths, azimuths)
286 r, theta = numpy.meshgrid(zeniths, azimuths)
291 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(
287 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(
292 theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
288 theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
293 x = km2deg(x) + self.lon
289 x = km2deg(x) + self.lon
294 y = km2deg(y) + self.lat
290 y = km2deg(y) + self.lat
295 else:
291 else:
296 azimuths = numpy.radians(self.data.yrange)
292 azimuths = numpy.radians(self.data.yrange)
297 r, theta = numpy.meshgrid(zeniths, azimuths)
293 r, theta = numpy.meshgrid(zeniths, azimuths)
298 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
294 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
299 self.y = zeniths
295 self.y = zeniths
300
296
301 if ax.firsttime:
297 if ax.firsttime:
302 if self.zlimits is not None:
298 if self.zlimits is not None:
303 self.zmin, self.zmax = self.zlimits[n]
299 self.zmin, self.zmax = self.zlimits[n]
304 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
300 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
305 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
301 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
306 vmin=self.zmin,
302 vmin=self.zmin,
307 vmax=self.zmax,
303 vmax=self.zmax,
308 cmap=self.cmaps[n])
304 cmap=self.cmaps[n])
309 else:
305 else:
310 if self.zlimits is not None:
306 if self.zlimits is not None:
311 self.zmin, self.zmax = self.zlimits[n]
307 self.zmin, self.zmax = self.zlimits[n]
312 ax.collections.remove(ax.collections[0])
308 ax.collections.remove(ax.collections[0])
313 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
309 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
314 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
310 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
315 vmin=self.zmin,
311 vmin=self.zmin,
316 vmax=self.zmax,
312 vmax=self.zmax,
317 cmap=self.cmaps[n])
313 cmap=self.cmaps[n])
318
314
319 if self.mode == 'A':
315 if self.mode == 'A':
320 continue
316 continue
321
317
322 # plot district names
318 # plot district names
323 f = open('/data/workspace/schain_scripts/distrito.csv')
319 f = open('/data/workspace/schain_scripts/distrito.csv')
324 for line in f:
320 for line in f:
325 label, lon, lat = [s.strip() for s in line.split(',') if s]
321 label, lon, lat = [s.strip() for s in line.split(',') if s]
326 lat = float(lat)
322 lat = float(lat)
327 lon = float(lon)
323 lon = float(lon)
328 # ax.plot(lon, lat, '.b', ms=2)
324 # ax.plot(lon, lat, '.b', ms=2)
329 ax.text(lon, lat, label.decode('utf8'), ha='center',
325 ax.text(lon, lat, label.decode('utf8'), ha='center',
330 va='bottom', size='8', color='black')
326 va='bottom', size='8', color='black')
331
327
332 # plot limites
328 # plot limites
333 limites = []
329 limites = []
334 tmp = []
330 tmp = []
335 for line in open('/data/workspace/schain_scripts/lima.csv'):
331 for line in open('/data/workspace/schain_scripts/lima.csv'):
336 if '#' in line:
332 if '#' in line:
337 if tmp:
333 if tmp:
338 limites.append(tmp)
334 limites.append(tmp)
339 tmp = []
335 tmp = []
340 continue
336 continue
341 values = line.strip().split(',')
337 values = line.strip().split(',')
342 tmp.append((float(values[0]), float(values[1])))
338 tmp.append((float(values[0]), float(values[1])))
343 for points in limites:
339 for points in limites:
344 ax.add_patch(
340 ax.add_patch(
345 Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
341 Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
346
342
347 # plot Cuencas
343 # plot Cuencas
348 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
344 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
349 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
345 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
350 values = [line.strip().split(',') for line in f]
346 values = [line.strip().split(',') for line in f]
351 points = [(float(s[0]), float(s[1])) for s in values]
347 points = [(float(s[0]), float(s[1])) for s in values]
352 ax.add_patch(Polygon(points, ec='b', fc='none'))
348 ax.add_patch(Polygon(points, ec='b', fc='none'))
353
349
354 # plot grid
350 # plot grid
355 for r in (15, 30, 45, 60):
351 for r in (15, 30, 45, 60):
356 ax.add_artist(plt.Circle((self.lon, self.lat),
352 ax.add_artist(plt.Circle((self.lon, self.lat),
357 km2deg(r), color='0.6', fill=False, lw=0.2))
353 km2deg(r), color='0.6', fill=False, lw=0.2))
358 ax.text(
354 ax.text(
359 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
355 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
360 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
356 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
361 '{}km'.format(r),
357 '{}km'.format(r),
362 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
358 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
363
359
364 if self.mode == 'E':
360 if self.mode == 'E':
365 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
361 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
366 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
362 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
367 else:
363 else:
368 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
364 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
369 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
365 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
370
366
371 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
367 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
372 self.titles = ['{} {}'.format(
368 self.titles = ['{} {}'.format(
373 self.data.parameters[x], title) for x in self.channels]
369 self.data.parameters[x], title) for x in self.channels]
374
370
375 class WeatherPlot(Plot):
371 class WeatherPlot(Plot):
376 CODE = 'weather'
372 CODE = 'weather'
377 plot_name = 'weather'
373 plot_name = 'weather'
378 plot_type = 'ppistyle'
374 plot_type = 'ppistyle'
379 buffering = False
375 buffering = False
380
376
381 def setup(self):
377 def setup(self):
382 self.ncols = 1
378 self.ncols = 1
383 self.nrows = 1
379 self.nrows = 1
384 self.nplots= 1
380 self.nplots= 1
385 self.ylabel= 'Range [Km]'
381 self.ylabel= 'Range [Km]'
386 self.titles= ['Weather']
382 self.titles= ['Weather']
387 self.colorbar=False
383 self.colorbar=False
388 self.width =8
384 self.width =8
389 self.height =8
385 self.height =8
390 self.ini =0
386 self.ini =0
391 self.len_azi =0
387 self.len_azi =0
392 self.buffer_ini = None
388 self.buffer_ini = None
393 self.buffer_azi = None
389 self.buffer_azi = None
394 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
390 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
395 self.flag =0
391 self.flag =0
396 self.indicador= 0
392 self.indicador= 0
397
393
398 def update(self, dataOut):
394 def update(self, dataOut):
399
395
400 data = {}
396 data = {}
401 meta = {}
397 meta = {}
402 print("aprox",dataOut.data_360[0])
403 data['weather'] = 10*numpy.log10(dataOut.data_360[0]/(250.0))
398 data['weather'] = 10*numpy.log10(dataOut.data_360[0]/(250.0))
404 #print(data['weather'])
405 data['azi'] = dataOut.data_azi
399 data['azi'] = dataOut.data_azi
406 print("UPDATE",data['azi'])
407 return data, meta
400 return data, meta
408
401
409 def const_ploteo(self,data_weather,data_azi,step,res):
402 def const_ploteo(self,data_weather,data_azi,step,res):
410 #print("data_weather",data_weather)
411 print("data_azi",data_azi)
412 print("step",step)
413 if self.ini==0:
403 if self.ini==0:
414 #------- AZIMUTH
404 #------- AZIMUTH
415 n = (360/res)-len(data_azi)
405 n = (360/res)-len(data_azi)
416 start = data_azi[-1] + res
406 start = data_azi[-1] + res
417 end = data_azi[0] - res
407 end = data_azi[0] - res
418 if start>end:
408 if start>end:
419 end = end + 360
409 end = end + 360
420 azi_vacia = numpy.linspace(start,end,int(n))
410 azi_vacia = numpy.linspace(start,end,int(n))
421 azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia)
411 azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia)
422 data_azi = numpy.hstack((data_azi,azi_vacia))
412 data_azi = numpy.hstack((data_azi,azi_vacia))
423 # RADAR
413 # RADAR
424 val_mean = numpy.mean(data_weather[:,0])
414 val_mean = numpy.mean(data_weather[:,0])
425 data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean
415 data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean
426 data_weather = numpy.vstack((data_weather,data_weather_cmp))
416 data_weather = numpy.vstack((data_weather,data_weather_cmp))
427 else:
417 else:
428 # azimuth
418 # azimuth
429 flag=0
419 flag=0
430 start_azi = self.res_azi[0]
420 start_azi = self.res_azi[0]
431 start = data_azi[0]
421 start = data_azi[0]
432 end = data_azi[-1]
422 end = data_azi[-1]
433 print("start",start)
423 print("start",start)
434 print("end",end)
424 print("end",end)
435 if start< start_azi:
425 if start< start_azi:
436 start = start +360
426 start = start +360
437 if end <start_azi:
427 if end <start_azi:
438 end = end +360
428 end = end +360
439
429
440 print("start",start)
430 print("start",start)
441 print("end",end)
431 print("end",end)
442 #### AQUI SERA LA MAGIA
432 #### AQUI SERA LA MAGIA
443 pos_ini = int((start-start_azi)/res)
433 pos_ini = int((start-start_azi)/res)
444 len_azi = len(data_azi)
434 len_azi = len(data_azi)
445 if (360-pos_ini)<len_azi:
435 if (360-pos_ini)<len_azi:
446 if pos_ini+1==360:
436 if pos_ini+1==360:
447 pos_ini=0
437 pos_ini=0
448 else:
438 else:
449 flag=1
439 flag=1
450 dif= 360-pos_ini
440 dif= 360-pos_ini
451 comp= len_azi-dif
441 comp= len_azi-dif
452
442
453 print(pos_ini)
443 print(pos_ini)
454 print(len_azi)
444 print(len_azi)
455 print("shape",self.res_azi.shape)
445 print("shape",self.res_azi.shape)
456 if flag==0:
446 if flag==0:
457 # AZIMUTH
447 # AZIMUTH
458 self.res_azi[pos_ini:pos_ini+len_azi] = data_azi
448 self.res_azi[pos_ini:pos_ini+len_azi] = data_azi
459 # RADAR
449 # RADAR
460 self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather
450 self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather
461 else:
451 else:
462 # AZIMUTH
452 # AZIMUTH
463 self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif]
453 self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif]
464 self.res_azi[0:comp] = data_azi[dif:]
454 self.res_azi[0:comp] = data_azi[dif:]
465 # RADAR
455 # RADAR
466 self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:]
456 self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:]
467 self.res_weather[0:comp,:] = data_weather[dif:,:]
457 self.res_weather[0:comp,:] = data_weather[dif:,:]
468 flag=0
458 flag=0
469 data_azi = self.res_azi
459 data_azi = self.res_azi
470 data_weather = self.res_weather
460 data_weather = self.res_weather
471
461
472 return data_weather,data_azi
462 return data_weather,data_azi
473
463
474 def plot(self):
464 def plot(self):
475 print("--------------------------------------",self.ini,"-----------------------------------")
465 print("--------------------------------------",self.ini,"-----------------------------------")
476 #numpy.set_printoptions(suppress=True)
466 #numpy.set_printoptions(suppress=True)
477 #print(self.data.times)
467 #print(self.data.times)
478 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1])
468 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1])
479 data = self.data[-1]
469 data = self.data[-1]
480 # ALTURA altura_tmp_h
470 # ALTURA altura_tmp_h
481 altura_h = (data['weather'].shape[1])/10.0
471 altura_h = (data['weather'].shape[1])/10.0
482 stoprange = float(altura_h*1.5)#stoprange = float(33*1.5) por ahora 400
472 stoprange = float(altura_h*1.5)#stoprange = float(33*1.5) por ahora 400
483 rangestep = float(0.15)
473 rangestep = float(0.15)
484 r = numpy.arange(0, stoprange, rangestep)
474 r = numpy.arange(0, stoprange, rangestep)
485 self.y = 2*r
475 self.y = 2*r
486 # RADAR
476 # RADAR
487 #data_weather = data['weather']
477 #data_weather = data['weather']
488 # PEDESTAL
478 # PEDESTAL
489 #data_azi = data['azi']
479 #data_azi = data['azi']
490 res = 1
480 res = 1
491 # STEP
481 # STEP
492 step = (360/(res*data['weather'].shape[0]))
482 step = (360/(res*data['weather'].shape[0]))
493 #print("shape wr_data", wr_data.shape)
483 #print("shape wr_data", wr_data.shape)
494 #print("shape wr_azi",wr_azi.shape)
484 #print("shape wr_azi",wr_azi.shape)
495 #print("step",step)
485 #print("step",step)
496 print("Time---->",self.data.times[-1],thisDatetime)
486 print("Time---->",self.data.times[-1],thisDatetime)
497 #print("alturas", len(self.y))
487 #print("alturas", len(self.y))
498 self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'],data_azi=data['azi'],step=step,res=res)
488 self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'],data_azi=data['azi'],step=step,res=res)
499 #numpy.set_printoptions(suppress=True)
489 #numpy.set_printoptions(suppress=True)
500 #print("resultado",self.res_azi)
490 #print("resultado",self.res_azi)
501 ##########################################################
491 ##########################################################
502 ################# PLOTEO ###################
492 ################# PLOTEO ###################
503 ##########################################################
493 ##########################################################
504
494
505 for i,ax in enumerate(self.axes):
495 for i,ax in enumerate(self.axes):
506 if ax.firsttime:
496 if ax.firsttime:
507 plt.clf()
497 plt.clf()
508 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=1, vmax=60)
498 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=1, vmax=60)
509 else:
499 else:
510 plt.clf()
500 plt.clf()
511 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=0, vmax=60)
501 cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=0, vmax=60)
512 caax = cgax.parasites[0]
502 caax = cgax.parasites[0]
513 paax = cgax.parasites[1]
503 paax = cgax.parasites[1]
514 cbar = plt.gcf().colorbar(pm, pad=0.075)
504 cbar = plt.gcf().colorbar(pm, pad=0.075)
515 caax.set_xlabel('x_range [km]')
505 caax.set_xlabel('x_range [km]')
516 caax.set_ylabel('y_range [km]')
506 caax.set_ylabel('y_range [km]')
517 plt.text(1.0, 1.05, 'azimuth '+str(thisDatetime)+"step"+str(self.ini), transform=caax.transAxes, va='bottom',ha='right')
507 plt.text(1.0, 1.05, 'azimuth '+str(thisDatetime)+"step"+str(self.ini), transform=caax.transAxes, va='bottom',ha='right')
518
508
519 self.ini= self.ini+1
509 self.ini= self.ini+1
@@ -1,745 +1,743
1 # Copyright (c) 2012-2021 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2021 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Classes to plot Spectra data
5 """Classes to plot Spectra data
6
6
7 """
7 """
8
8
9 import os
9 import os
10 import numpy
10 import numpy
11
11
12 from schainpy.model.graphics.jroplot_base import Plot, plt, log
12 from schainpy.model.graphics.jroplot_base import Plot, plt, log
13
13
14
14
15 class SpectraPlot(Plot):
15 class SpectraPlot(Plot):
16 '''
16 '''
17 Plot for Spectra data
17 Plot for Spectra data
18 '''
18 '''
19
19
20 CODE = 'spc'
20 CODE = 'spc'
21 colormap = 'jet'
21 colormap = 'jet'
22 plot_type = 'pcolor'
22 plot_type = 'pcolor'
23 buffering = False
23 buffering = False
24
24
25 def setup(self):
25 def setup(self):
26 self.nplots = len(self.data.channels)
26 self.nplots = len(self.data.channels)
27 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
27 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
28 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
28 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
29 self.height = 2.6 * self.nrows
29 self.height = 2.6 * self.nrows
30 self.cb_label = 'dB'
30 self.cb_label = 'dB'
31 if self.showprofile:
31 if self.showprofile:
32 self.width = 4 * self.ncols
32 self.width = 4 * self.ncols
33 else:
33 else:
34 self.width = 3.5 * self.ncols
34 self.width = 3.5 * self.ncols
35 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
35 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
36 self.ylabel = 'Range [km]'
36 self.ylabel = 'Range [km]'
37
37
38 def update(self, dataOut):
38 def update(self, dataOut):
39
39
40 data = {}
40 data = {}
41 meta = {}
41 meta = {}
42 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
42 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
43 data['spc'] = spc
43 data['spc'] = spc
44 data['rti'] = dataOut.getPower()
44 data['rti'] = dataOut.getPower()
45 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
45 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
46 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
46 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
47
47
48 if self.CODE == 'spc_moments':
48 if self.CODE == 'spc_moments':
49 data['moments'] = dataOut.moments
49 data['moments'] = dataOut.moments
50 # data['spc'] = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
50 # data['spc'] = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
51 if self.CODE == 'gaussian_fit':
51 if self.CODE == 'gaussian_fit':
52 # data['moments'] = dataOut.moments
52 # data['moments'] = dataOut.moments
53 data['gaussfit'] = dataOut.DGauFitParams
53 data['gaussfit'] = dataOut.DGauFitParams
54 # data['spc'] = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
54 # data['spc'] = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
55
55
56 return data, meta
56 return data, meta
57
57
58 def plot(self):
58 def plot(self):
59 if self.xaxis == "frequency":
59 if self.xaxis == "frequency":
60 x = self.data.xrange[0]
60 x = self.data.xrange[0]
61 self.xlabel = "Frequency (kHz)"
61 self.xlabel = "Frequency (kHz)"
62 elif self.xaxis == "time":
62 elif self.xaxis == "time":
63 x = self.data.xrange[1]
63 x = self.data.xrange[1]
64 self.xlabel = "Time (ms)"
64 self.xlabel = "Time (ms)"
65 else:
65 else:
66 x = self.data.xrange[2]
66 x = self.data.xrange[2]
67 self.xlabel = "Velocity (m/s)"
67 self.xlabel = "Velocity (m/s)"
68
68
69 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
69 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
70 x = self.data.xrange[2]
70 x = self.data.xrange[2]
71 self.xlabel = "Velocity (m/s)"
71 self.xlabel = "Velocity (m/s)"
72
72
73 self.titles = []
73 self.titles = []
74
74
75 y = self.data.yrange
75 y = self.data.yrange
76 self.y = y
76 self.y = y
77
77
78 data = self.data[-1]
78 data = self.data[-1]
79 z = data['spc']
79 z = data['spc']
80
80
81 for n, ax in enumerate(self.axes):
81 for n, ax in enumerate(self.axes):
82 noise = data['noise'][n]
82 noise = data['noise'][n]
83 if self.CODE == 'spc_moments':
83 if self.CODE == 'spc_moments':
84 mean = data['moments'][n, 1]
84 mean = data['moments'][n, 1]
85 if self.CODE == 'gaussian_fit':
85 if self.CODE == 'gaussian_fit':
86 # mean = data['moments'][n, 1]
86 # mean = data['moments'][n, 1]
87 gau0 = data['gaussfit'][n][2,:,0]
87 gau0 = data['gaussfit'][n][2,:,0]
88 gau1 = data['gaussfit'][n][2,:,1]
88 gau1 = data['gaussfit'][n][2,:,1]
89 if ax.firsttime:
89 if ax.firsttime:
90 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
90 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
91 self.xmin = self.xmin if self.xmin else -self.xmax
91 self.xmin = self.xmin if self.xmin else -self.xmax
92 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
92 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
93 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
93 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
94 ax.plt = ax.pcolormesh(x, y, z[n].T,
94 ax.plt = ax.pcolormesh(x, y, z[n].T,
95 vmin=self.zmin,
95 vmin=self.zmin,
96 vmax=self.zmax,
96 vmax=self.zmax,
97 cmap=plt.get_cmap(self.colormap)
97 cmap=plt.get_cmap(self.colormap)
98 )
98 )
99
99
100 if self.showprofile:
100 if self.showprofile:
101 ax.plt_profile = self.pf_axes[n].plot(
101 ax.plt_profile = self.pf_axes[n].plot(
102 data['rti'][n], y)[0]
102 data['rti'][n], y)[0]
103 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
103 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
104 color="k", linestyle="dashed", lw=1)[0]
104 color="k", linestyle="dashed", lw=1)[0]
105 if self.CODE == 'spc_moments':
105 if self.CODE == 'spc_moments':
106 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
106 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
107 if self.CODE == 'gaussian_fit':
107 if self.CODE == 'gaussian_fit':
108 # ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
108 # ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
109 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
109 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
110 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
110 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
111 else:
111 else:
112 ax.plt.set_array(z[n].T.ravel())
112 ax.plt.set_array(z[n].T.ravel())
113 if self.showprofile:
113 if self.showprofile:
114 ax.plt_profile.set_data(data['rti'][n], y)
114 ax.plt_profile.set_data(data['rti'][n], y)
115 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
115 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
116 if self.CODE == 'spc_moments':
116 if self.CODE == 'spc_moments':
117 ax.plt_mean.set_data(mean, y)
117 ax.plt_mean.set_data(mean, y)
118 if self.CODE == 'gaussian_fit':
118 if self.CODE == 'gaussian_fit':
119 # ax.plt_mean.set_data(mean, y)
119 # ax.plt_mean.set_data(mean, y)
120 ax.plt_gau0.set_data(gau0, y)
120 ax.plt_gau0.set_data(gau0, y)
121 ax.plt_gau1.set_data(gau1, y)
121 ax.plt_gau1.set_data(gau1, y)
122 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
122 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
123
123
124
124
125 class CrossSpectraPlot(Plot):
125 class CrossSpectraPlot(Plot):
126
126
127 CODE = 'cspc'
127 CODE = 'cspc'
128 colormap = 'jet'
128 colormap = 'jet'
129 plot_type = 'pcolor'
129 plot_type = 'pcolor'
130 zmin_coh = None
130 zmin_coh = None
131 zmax_coh = None
131 zmax_coh = None
132 zmin_phase = None
132 zmin_phase = None
133 zmax_phase = None
133 zmax_phase = None
134
134
135 def setup(self):
135 def setup(self):
136
136
137 self.ncols = 4
137 self.ncols = 4
138 self.nplots = len(self.data.pairs) * 2
138 self.nplots = len(self.data.pairs) * 2
139 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
139 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
140 self.width = 3.1 * self.ncols
140 self.width = 3.1 * self.ncols
141 self.height = 2.6 * self.nrows
141 self.height = 2.6 * self.nrows
142 self.ylabel = 'Range [km]'
142 self.ylabel = 'Range [km]'
143 self.showprofile = False
143 self.showprofile = False
144 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
144 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
145
145
146 def update(self, dataOut):
146 def update(self, dataOut):
147
147
148 data = {}
148 data = {}
149 meta = {}
149 meta = {}
150
150
151 spc = dataOut.data_spc
151 spc = dataOut.data_spc
152 cspc = dataOut.data_cspc
152 cspc = dataOut.data_cspc
153 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
153 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
154 meta['pairs'] = dataOut.pairsList
154 meta['pairs'] = dataOut.pairsList
155
155
156 tmp = []
156 tmp = []
157
157
158 for n, pair in enumerate(meta['pairs']):
158 for n, pair in enumerate(meta['pairs']):
159 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
159 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
160 coh = numpy.abs(out)
160 coh = numpy.abs(out)
161 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
161 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
162 tmp.append(coh)
162 tmp.append(coh)
163 tmp.append(phase)
163 tmp.append(phase)
164
164
165 data['cspc'] = numpy.array(tmp)
165 data['cspc'] = numpy.array(tmp)
166
166
167 return data, meta
167 return data, meta
168
168
169 def plot(self):
169 def plot(self):
170
170
171 if self.xaxis == "frequency":
171 if self.xaxis == "frequency":
172 x = self.data.xrange[0]
172 x = self.data.xrange[0]
173 self.xlabel = "Frequency (kHz)"
173 self.xlabel = "Frequency (kHz)"
174 elif self.xaxis == "time":
174 elif self.xaxis == "time":
175 x = self.data.xrange[1]
175 x = self.data.xrange[1]
176 self.xlabel = "Time (ms)"
176 self.xlabel = "Time (ms)"
177 else:
177 else:
178 x = self.data.xrange[2]
178 x = self.data.xrange[2]
179 self.xlabel = "Velocity (m/s)"
179 self.xlabel = "Velocity (m/s)"
180
180
181 self.titles = []
181 self.titles = []
182
182
183 y = self.data.yrange
183 y = self.data.yrange
184 self.y = y
184 self.y = y
185
185
186 data = self.data[-1]
186 data = self.data[-1]
187 cspc = data['cspc']
187 cspc = data['cspc']
188
188
189 for n in range(len(self.data.pairs)):
189 for n in range(len(self.data.pairs)):
190 pair = self.data.pairs[n]
190 pair = self.data.pairs[n]
191 coh = cspc[n*2]
191 coh = cspc[n*2]
192 phase = cspc[n*2+1]
192 phase = cspc[n*2+1]
193 ax = self.axes[2 * n]
193 ax = self.axes[2 * n]
194 if ax.firsttime:
194 if ax.firsttime:
195 ax.plt = ax.pcolormesh(x, y, coh.T,
195 ax.plt = ax.pcolormesh(x, y, coh.T,
196 vmin=0,
196 vmin=0,
197 vmax=1,
197 vmax=1,
198 cmap=plt.get_cmap(self.colormap_coh)
198 cmap=plt.get_cmap(self.colormap_coh)
199 )
199 )
200 else:
200 else:
201 ax.plt.set_array(coh.T.ravel())
201 ax.plt.set_array(coh.T.ravel())
202 self.titles.append(
202 self.titles.append(
203 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
203 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
204
204
205 ax = self.axes[2 * n + 1]
205 ax = self.axes[2 * n + 1]
206 if ax.firsttime:
206 if ax.firsttime:
207 ax.plt = ax.pcolormesh(x, y, phase.T,
207 ax.plt = ax.pcolormesh(x, y, phase.T,
208 vmin=-180,
208 vmin=-180,
209 vmax=180,
209 vmax=180,
210 cmap=plt.get_cmap(self.colormap_phase)
210 cmap=plt.get_cmap(self.colormap_phase)
211 )
211 )
212 else:
212 else:
213 ax.plt.set_array(phase.T.ravel())
213 ax.plt.set_array(phase.T.ravel())
214 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
214 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
215
215
216
216
217 class RTIPlot(Plot):
217 class RTIPlot(Plot):
218 '''
218 '''
219 Plot for RTI data
219 Plot for RTI data
220 '''
220 '''
221
221
222 CODE = 'rti'
222 CODE = 'rti'
223 colormap = 'jet'
223 colormap = 'jet'
224 plot_type = 'pcolorbuffer'
224 plot_type = 'pcolorbuffer'
225
225
226 def setup(self):
226 def setup(self):
227 self.xaxis = 'time'
227 self.xaxis = 'time'
228 self.ncols = 1
228 self.ncols = 1
229 print("ch",self.data.channels)
230 self.nrows = len(self.data.channels)
229 self.nrows = len(self.data.channels)
231 self.nplots = len(self.data.channels)
230 self.nplots = len(self.data.channels)
232 self.ylabel = 'Range [km]'
231 self.ylabel = 'Range [km]'
233 self.xlabel = 'Time'
232 self.xlabel = 'Time'
234 self.cb_label = 'dB'
233 self.cb_label = 'dB'
235 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95})
234 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95})
236 self.titles = ['{} Channel {}'.format(
235 self.titles = ['{} Channel {}'.format(
237 self.CODE.upper(), x) for x in range(self.nrows)]
236 self.CODE.upper(), x) for x in range(self.nrows)]
238
237
239 def update(self, dataOut):
238 def update(self, dataOut):
240
239
241 data = {}
240 data = {}
242 meta = {}
241 meta = {}
243 data['rti'] = dataOut.getPower()
242 data['rti'] = dataOut.getPower()
244 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
243 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
245
244
246 return data, meta
245 return data, meta
247
246
248 def plot(self):
247 def plot(self):
249 self.x = self.data.times
248 self.x = self.data.times
250 self.y = self.data.yrange
249 self.y = self.data.yrange
251 self.z = self.data[self.CODE]
250 self.z = self.data[self.CODE]
252 self.z = numpy.ma.masked_invalid(self.z)
251 self.z = numpy.ma.masked_invalid(self.z)
253
252
254 if self.decimation is None:
253 if self.decimation is None:
255 x, y, z = self.fill_gaps(self.x, self.y, self.z)
254 x, y, z = self.fill_gaps(self.x, self.y, self.z)
256 else:
255 else:
257 x, y, z = self.fill_gaps(*self.decimate())
256 x, y, z = self.fill_gaps(*self.decimate())
258
257
259 for n, ax in enumerate(self.axes):
258 for n, ax in enumerate(self.axes):
260 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
259 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
261 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
260 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
262 data = self.data[-1]
261 data = self.data[-1]
263 if ax.firsttime:
262 if ax.firsttime:
264 ax.plt = ax.pcolormesh(x, y, z[n].T,
263 ax.plt = ax.pcolormesh(x, y, z[n].T,
265 vmin=self.zmin,
264 vmin=self.zmin,
266 vmax=self.zmax,
265 vmax=self.zmax,
267 cmap=plt.get_cmap(self.colormap)
266 cmap=plt.get_cmap(self.colormap)
268 )
267 )
269 if self.showprofile:
268 if self.showprofile:
270 print("test-------------------------------------1")
271 ax.plot_profile = self.pf_axes[n].plot(
269 ax.plot_profile = self.pf_axes[n].plot(
272 data['rti'][n], self.y)[0]
270 data['rti'][n], self.y)[0]
273 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
271 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
274 color="k", linestyle="dashed", lw=1)[0]
272 color="k", linestyle="dashed", lw=1)[0]
275 else:
273 else:
276 ax.collections.remove(ax.collections[0])
274 ax.collections.remove(ax.collections[0])
277 ax.plt = ax.pcolormesh(x, y, z[n].T,
275 ax.plt = ax.pcolormesh(x, y, z[n].T,
278 vmin=self.zmin,
276 vmin=self.zmin,
279 vmax=self.zmax,
277 vmax=self.zmax,
280 cmap=plt.get_cmap(self.colormap)
278 cmap=plt.get_cmap(self.colormap)
281 )
279 )
282 if self.showprofile:
280 if self.showprofile:
283 ax.plot_profile.set_data(data['rti'][n], self.y)
281 ax.plot_profile.set_data(data['rti'][n], self.y)
284 ax.plot_noise.set_data(numpy.repeat(
282 ax.plot_noise.set_data(numpy.repeat(
285 data['noise'][n], len(self.y)), self.y)
283 data['noise'][n], len(self.y)), self.y)
286
284
287
285
288 class CoherencePlot(RTIPlot):
286 class CoherencePlot(RTIPlot):
289 '''
287 '''
290 Plot for Coherence data
288 Plot for Coherence data
291 '''
289 '''
292
290
293 CODE = 'coh'
291 CODE = 'coh'
294
292
295 def setup(self):
293 def setup(self):
296 self.xaxis = 'time'
294 self.xaxis = 'time'
297 self.ncols = 1
295 self.ncols = 1
298 self.nrows = len(self.data.pairs)
296 self.nrows = len(self.data.pairs)
299 self.nplots = len(self.data.pairs)
297 self.nplots = len(self.data.pairs)
300 self.ylabel = 'Range [km]'
298 self.ylabel = 'Range [km]'
301 self.xlabel = 'Time'
299 self.xlabel = 'Time'
302 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
300 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
303 if self.CODE == 'coh':
301 if self.CODE == 'coh':
304 self.cb_label = ''
302 self.cb_label = ''
305 self.titles = [
303 self.titles = [
306 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
304 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
307 else:
305 else:
308 self.cb_label = 'Degrees'
306 self.cb_label = 'Degrees'
309 self.titles = [
307 self.titles = [
310 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
308 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
311
309
312 def update(self, dataOut):
310 def update(self, dataOut):
313
311
314 data = {}
312 data = {}
315 meta = {}
313 meta = {}
316 data['coh'] = dataOut.getCoherence()
314 data['coh'] = dataOut.getCoherence()
317 meta['pairs'] = dataOut.pairsList
315 meta['pairs'] = dataOut.pairsList
318
316
319 return data, meta
317 return data, meta
320
318
321 class PhasePlot(CoherencePlot):
319 class PhasePlot(CoherencePlot):
322 '''
320 '''
323 Plot for Phase map data
321 Plot for Phase map data
324 '''
322 '''
325
323
326 CODE = 'phase'
324 CODE = 'phase'
327 colormap = 'seismic'
325 colormap = 'seismic'
328
326
329 def update(self, dataOut):
327 def update(self, dataOut):
330
328
331 data = {}
329 data = {}
332 meta = {}
330 meta = {}
333 data['phase'] = dataOut.getCoherence(phase=True)
331 data['phase'] = dataOut.getCoherence(phase=True)
334 meta['pairs'] = dataOut.pairsList
332 meta['pairs'] = dataOut.pairsList
335
333
336 return data, meta
334 return data, meta
337
335
338 class NoisePlot(Plot):
336 class NoisePlot(Plot):
339 '''
337 '''
340 Plot for noise
338 Plot for noise
341 '''
339 '''
342
340
343 CODE = 'noise'
341 CODE = 'noise'
344 plot_type = 'scatterbuffer'
342 plot_type = 'scatterbuffer'
345
343
346 def setup(self):
344 def setup(self):
347 self.xaxis = 'time'
345 self.xaxis = 'time'
348 self.ncols = 1
346 self.ncols = 1
349 self.nrows = 1
347 self.nrows = 1
350 self.nplots = 1
348 self.nplots = 1
351 self.ylabel = 'Intensity [dB]'
349 self.ylabel = 'Intensity [dB]'
352 self.xlabel = 'Time'
350 self.xlabel = 'Time'
353 self.titles = ['Noise']
351 self.titles = ['Noise']
354 self.colorbar = False
352 self.colorbar = False
355 self.plots_adjust.update({'right': 0.85 })
353 self.plots_adjust.update({'right': 0.85 })
356
354
357 def update(self, dataOut):
355 def update(self, dataOut):
358
356
359 data = {}
357 data = {}
360 meta = {}
358 meta = {}
361 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1)
359 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1)
362 meta['yrange'] = numpy.array([])
360 meta['yrange'] = numpy.array([])
363
361
364 return data, meta
362 return data, meta
365
363
366 def plot(self):
364 def plot(self):
367
365
368 x = self.data.times
366 x = self.data.times
369 xmin = self.data.min_time
367 xmin = self.data.min_time
370 xmax = xmin + self.xrange * 60 * 60
368 xmax = xmin + self.xrange * 60 * 60
371 Y = self.data['noise']
369 Y = self.data['noise']
372
370
373 if self.axes[0].firsttime:
371 if self.axes[0].firsttime:
374 self.ymin = numpy.nanmin(Y) - 5
372 self.ymin = numpy.nanmin(Y) - 5
375 self.ymax = numpy.nanmax(Y) + 5
373 self.ymax = numpy.nanmax(Y) + 5
376 for ch in self.data.channels:
374 for ch in self.data.channels:
377 y = Y[ch]
375 y = Y[ch]
378 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
376 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
379 plt.legend(bbox_to_anchor=(1.18, 1.0))
377 plt.legend(bbox_to_anchor=(1.18, 1.0))
380 else:
378 else:
381 for ch in self.data.channels:
379 for ch in self.data.channels:
382 y = Y[ch]
380 y = Y[ch]
383 self.axes[0].lines[ch].set_data(x, y)
381 self.axes[0].lines[ch].set_data(x, y)
384
382
385
383
386 class PowerProfilePlot(Plot):
384 class PowerProfilePlot(Plot):
387
385
388 CODE = 'pow_profile'
386 CODE = 'pow_profile'
389 plot_type = 'scatter'
387 plot_type = 'scatter'
390
388
391 def setup(self):
389 def setup(self):
392
390
393 self.ncols = 1
391 self.ncols = 1
394 self.nrows = 1
392 self.nrows = 1
395 self.nplots = 1
393 self.nplots = 1
396 self.height = 4
394 self.height = 4
397 self.width = 3
395 self.width = 3
398 self.ylabel = 'Range [km]'
396 self.ylabel = 'Range [km]'
399 self.xlabel = 'Intensity [dB]'
397 self.xlabel = 'Intensity [dB]'
400 self.titles = ['Power Profile']
398 self.titles = ['Power Profile']
401 self.colorbar = False
399 self.colorbar = False
402
400
403 def update(self, dataOut):
401 def update(self, dataOut):
404
402
405 data = {}
403 data = {}
406 meta = {}
404 meta = {}
407 data[self.CODE] = dataOut.getPower()
405 data[self.CODE] = dataOut.getPower()
408
406
409 return data, meta
407 return data, meta
410
408
411 def plot(self):
409 def plot(self):
412
410
413 y = self.data.yrange
411 y = self.data.yrange
414 self.y = y
412 self.y = y
415
413
416 x = self.data[-1][self.CODE]
414 x = self.data[-1][self.CODE]
417
415
418 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
416 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
419 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
417 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
420
418
421 if self.axes[0].firsttime:
419 if self.axes[0].firsttime:
422 for ch in self.data.channels:
420 for ch in self.data.channels:
423 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
421 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
424 plt.legend()
422 plt.legend()
425 else:
423 else:
426 for ch in self.data.channels:
424 for ch in self.data.channels:
427 self.axes[0].lines[ch].set_data(x[ch], y)
425 self.axes[0].lines[ch].set_data(x[ch], y)
428
426
429
427
430 class SpectraCutPlot(Plot):
428 class SpectraCutPlot(Plot):
431
429
432 CODE = 'spc_cut'
430 CODE = 'spc_cut'
433 plot_type = 'scatter'
431 plot_type = 'scatter'
434 buffering = False
432 buffering = False
435
433
436 def setup(self):
434 def setup(self):
437
435
438 self.nplots = len(self.data.channels)
436 self.nplots = len(self.data.channels)
439 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
437 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
440 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
438 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
441 self.width = 3.4 * self.ncols + 1.5
439 self.width = 3.4 * self.ncols + 1.5
442 self.height = 3 * self.nrows
440 self.height = 3 * self.nrows
443 self.ylabel = 'Power [dB]'
441 self.ylabel = 'Power [dB]'
444 self.colorbar = False
442 self.colorbar = False
445 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
443 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
446
444
447 def update(self, dataOut):
445 def update(self, dataOut):
448
446
449 data = {}
447 data = {}
450 meta = {}
448 meta = {}
451 spc = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
449 spc = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
452 data['spc'] = spc
450 data['spc'] = spc
453 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
451 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
454 if self.CODE == 'cut_gaussian_fit':
452 if self.CODE == 'cut_gaussian_fit':
455 data['gauss_fit0'] = 10*numpy.log10(dataOut.GaussFit0/dataOut.normFactor)
453 data['gauss_fit0'] = 10*numpy.log10(dataOut.GaussFit0/dataOut.normFactor)
456 data['gauss_fit1'] = 10*numpy.log10(dataOut.GaussFit1/dataOut.normFactor)
454 data['gauss_fit1'] = 10*numpy.log10(dataOut.GaussFit1/dataOut.normFactor)
457 return data, meta
455 return data, meta
458
456
459 def plot(self):
457 def plot(self):
460 if self.xaxis == "frequency":
458 if self.xaxis == "frequency":
461 x = self.data.xrange[0][1:]
459 x = self.data.xrange[0][1:]
462 self.xlabel = "Frequency (kHz)"
460 self.xlabel = "Frequency (kHz)"
463 elif self.xaxis == "time":
461 elif self.xaxis == "time":
464 x = self.data.xrange[1]
462 x = self.data.xrange[1]
465 self.xlabel = "Time (ms)"
463 self.xlabel = "Time (ms)"
466 else:
464 else:
467 x = self.data.xrange[2][:-1]
465 x = self.data.xrange[2][:-1]
468 self.xlabel = "Velocity (m/s)"
466 self.xlabel = "Velocity (m/s)"
469
467
470 if self.CODE == 'cut_gaussian_fit':
468 if self.CODE == 'cut_gaussian_fit':
471 x = self.data.xrange[2][:-1]
469 x = self.data.xrange[2][:-1]
472 self.xlabel = "Velocity (m/s)"
470 self.xlabel = "Velocity (m/s)"
473
471
474 self.titles = []
472 self.titles = []
475
473
476 y = self.data.yrange
474 y = self.data.yrange
477 data = self.data[-1]
475 data = self.data[-1]
478 z = data['spc']
476 z = data['spc']
479
477
480 if self.height_index:
478 if self.height_index:
481 index = numpy.array(self.height_index)
479 index = numpy.array(self.height_index)
482 else:
480 else:
483 index = numpy.arange(0, len(y), int((len(y))/9))
481 index = numpy.arange(0, len(y), int((len(y))/9))
484
482
485 for n, ax in enumerate(self.axes):
483 for n, ax in enumerate(self.axes):
486 if self.CODE == 'cut_gaussian_fit':
484 if self.CODE == 'cut_gaussian_fit':
487 gau0 = data['gauss_fit0']
485 gau0 = data['gauss_fit0']
488 gau1 = data['gauss_fit1']
486 gau1 = data['gauss_fit1']
489 if ax.firsttime:
487 if ax.firsttime:
490 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
488 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
491 self.xmin = self.xmin if self.xmin else -self.xmax
489 self.xmin = self.xmin if self.xmin else -self.xmax
492 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
490 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
493 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
491 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
494 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
492 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
495 if self.CODE == 'cut_gaussian_fit':
493 if self.CODE == 'cut_gaussian_fit':
496 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
494 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
497 for i, line in enumerate(ax.plt_gau0):
495 for i, line in enumerate(ax.plt_gau0):
498 line.set_color(ax.plt[i].get_color())
496 line.set_color(ax.plt[i].get_color())
499 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
497 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
500 for i, line in enumerate(ax.plt_gau1):
498 for i, line in enumerate(ax.plt_gau1):
501 line.set_color(ax.plt[i].get_color())
499 line.set_color(ax.plt[i].get_color())
502 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
500 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
503 self.figures[0].legend(ax.plt, labels, loc='center right')
501 self.figures[0].legend(ax.plt, labels, loc='center right')
504 else:
502 else:
505 for i, line in enumerate(ax.plt):
503 for i, line in enumerate(ax.plt):
506 line.set_data(x, z[n, :, index[i]].T)
504 line.set_data(x, z[n, :, index[i]].T)
507 for i, line in enumerate(ax.plt_gau0):
505 for i, line in enumerate(ax.plt_gau0):
508 line.set_data(x, gau0[n, :, index[i]].T)
506 line.set_data(x, gau0[n, :, index[i]].T)
509 line.set_color(ax.plt[i].get_color())
507 line.set_color(ax.plt[i].get_color())
510 for i, line in enumerate(ax.plt_gau1):
508 for i, line in enumerate(ax.plt_gau1):
511 line.set_data(x, gau1[n, :, index[i]].T)
509 line.set_data(x, gau1[n, :, index[i]].T)
512 line.set_color(ax.plt[i].get_color())
510 line.set_color(ax.plt[i].get_color())
513 self.titles.append('CH {}'.format(n))
511 self.titles.append('CH {}'.format(n))
514
512
515
513
516 class BeaconPhase(Plot):
514 class BeaconPhase(Plot):
517
515
518 __isConfig = None
516 __isConfig = None
519 __nsubplots = None
517 __nsubplots = None
520
518
521 PREFIX = 'beacon_phase'
519 PREFIX = 'beacon_phase'
522
520
523 def __init__(self):
521 def __init__(self):
524 Plot.__init__(self)
522 Plot.__init__(self)
525 self.timerange = 24*60*60
523 self.timerange = 24*60*60
526 self.isConfig = False
524 self.isConfig = False
527 self.__nsubplots = 1
525 self.__nsubplots = 1
528 self.counter_imagwr = 0
526 self.counter_imagwr = 0
529 self.WIDTH = 800
527 self.WIDTH = 800
530 self.HEIGHT = 400
528 self.HEIGHT = 400
531 self.WIDTHPROF = 120
529 self.WIDTHPROF = 120
532 self.HEIGHTPROF = 0
530 self.HEIGHTPROF = 0
533 self.xdata = None
531 self.xdata = None
534 self.ydata = None
532 self.ydata = None
535
533
536 self.PLOT_CODE = BEACON_CODE
534 self.PLOT_CODE = BEACON_CODE
537
535
538 self.FTP_WEI = None
536 self.FTP_WEI = None
539 self.EXP_CODE = None
537 self.EXP_CODE = None
540 self.SUB_EXP_CODE = None
538 self.SUB_EXP_CODE = None
541 self.PLOT_POS = None
539 self.PLOT_POS = None
542
540
543 self.filename_phase = None
541 self.filename_phase = None
544
542
545 self.figfile = None
543 self.figfile = None
546
544
547 self.xmin = None
545 self.xmin = None
548 self.xmax = None
546 self.xmax = None
549
547
550 def getSubplots(self):
548 def getSubplots(self):
551
549
552 ncol = 1
550 ncol = 1
553 nrow = 1
551 nrow = 1
554
552
555 return nrow, ncol
553 return nrow, ncol
556
554
557 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
555 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
558
556
559 self.__showprofile = showprofile
557 self.__showprofile = showprofile
560 self.nplots = nplots
558 self.nplots = nplots
561
559
562 ncolspan = 7
560 ncolspan = 7
563 colspan = 6
561 colspan = 6
564 self.__nsubplots = 2
562 self.__nsubplots = 2
565
563
566 self.createFigure(id = id,
564 self.createFigure(id = id,
567 wintitle = wintitle,
565 wintitle = wintitle,
568 widthplot = self.WIDTH+self.WIDTHPROF,
566 widthplot = self.WIDTH+self.WIDTHPROF,
569 heightplot = self.HEIGHT+self.HEIGHTPROF,
567 heightplot = self.HEIGHT+self.HEIGHTPROF,
570 show=show)
568 show=show)
571
569
572 nrow, ncol = self.getSubplots()
570 nrow, ncol = self.getSubplots()
573
571
574 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
572 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
575
573
576 def save_phase(self, filename_phase):
574 def save_phase(self, filename_phase):
577 f = open(filename_phase,'w+')
575 f = open(filename_phase,'w+')
578 f.write('\n\n')
576 f.write('\n\n')
579 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
577 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
580 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
578 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
581 f.close()
579 f.close()
582
580
583 def save_data(self, filename_phase, data, data_datetime):
581 def save_data(self, filename_phase, data, data_datetime):
584 f=open(filename_phase,'a')
582 f=open(filename_phase,'a')
585 timetuple_data = data_datetime.timetuple()
583 timetuple_data = data_datetime.timetuple()
586 day = str(timetuple_data.tm_mday)
584 day = str(timetuple_data.tm_mday)
587 month = str(timetuple_data.tm_mon)
585 month = str(timetuple_data.tm_mon)
588 year = str(timetuple_data.tm_year)
586 year = str(timetuple_data.tm_year)
589 hour = str(timetuple_data.tm_hour)
587 hour = str(timetuple_data.tm_hour)
590 minute = str(timetuple_data.tm_min)
588 minute = str(timetuple_data.tm_min)
591 second = str(timetuple_data.tm_sec)
589 second = str(timetuple_data.tm_sec)
592 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
590 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
593 f.close()
591 f.close()
594
592
595 def plot(self):
593 def plot(self):
596 log.warning('TODO: Not yet implemented...')
594 log.warning('TODO: Not yet implemented...')
597
595
598 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
596 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
599 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
597 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
600 timerange=None,
598 timerange=None,
601 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
599 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
602 server=None, folder=None, username=None, password=None,
600 server=None, folder=None, username=None, password=None,
603 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
601 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
604
602
605 if dataOut.flagNoData:
603 if dataOut.flagNoData:
606 return dataOut
604 return dataOut
607
605
608 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
606 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
609 return
607 return
610
608
611 if pairsList == None:
609 if pairsList == None:
612 pairsIndexList = dataOut.pairsIndexList[:10]
610 pairsIndexList = dataOut.pairsIndexList[:10]
613 else:
611 else:
614 pairsIndexList = []
612 pairsIndexList = []
615 for pair in pairsList:
613 for pair in pairsList:
616 if pair not in dataOut.pairsList:
614 if pair not in dataOut.pairsList:
617 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
615 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
618 pairsIndexList.append(dataOut.pairsList.index(pair))
616 pairsIndexList.append(dataOut.pairsList.index(pair))
619
617
620 if pairsIndexList == []:
618 if pairsIndexList == []:
621 return
619 return
622
620
623 # if len(pairsIndexList) > 4:
621 # if len(pairsIndexList) > 4:
624 # pairsIndexList = pairsIndexList[0:4]
622 # pairsIndexList = pairsIndexList[0:4]
625
623
626 hmin_index = None
624 hmin_index = None
627 hmax_index = None
625 hmax_index = None
628
626
629 if hmin != None and hmax != None:
627 if hmin != None and hmax != None:
630 indexes = numpy.arange(dataOut.nHeights)
628 indexes = numpy.arange(dataOut.nHeights)
631 hmin_list = indexes[dataOut.heightList >= hmin]
629 hmin_list = indexes[dataOut.heightList >= hmin]
632 hmax_list = indexes[dataOut.heightList <= hmax]
630 hmax_list = indexes[dataOut.heightList <= hmax]
633
631
634 if hmin_list.any():
632 if hmin_list.any():
635 hmin_index = hmin_list[0]
633 hmin_index = hmin_list[0]
636
634
637 if hmax_list.any():
635 if hmax_list.any():
638 hmax_index = hmax_list[-1]+1
636 hmax_index = hmax_list[-1]+1
639
637
640 x = dataOut.getTimeRange()
638 x = dataOut.getTimeRange()
641
639
642 thisDatetime = dataOut.datatime
640 thisDatetime = dataOut.datatime
643
641
644 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
642 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
645 xlabel = "Local Time"
643 xlabel = "Local Time"
646 ylabel = "Phase (degrees)"
644 ylabel = "Phase (degrees)"
647
645
648 update_figfile = False
646 update_figfile = False
649
647
650 nplots = len(pairsIndexList)
648 nplots = len(pairsIndexList)
651 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
649 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
652 phase_beacon = numpy.zeros(len(pairsIndexList))
650 phase_beacon = numpy.zeros(len(pairsIndexList))
653 for i in range(nplots):
651 for i in range(nplots):
654 pair = dataOut.pairsList[pairsIndexList[i]]
652 pair = dataOut.pairsList[pairsIndexList[i]]
655 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
653 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
656 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
654 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
657 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
655 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
658 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
656 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
659 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
657 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
660
658
661 if dataOut.beacon_heiIndexList:
659 if dataOut.beacon_heiIndexList:
662 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
660 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
663 else:
661 else:
664 phase_beacon[i] = numpy.average(phase)
662 phase_beacon[i] = numpy.average(phase)
665
663
666 if not self.isConfig:
664 if not self.isConfig:
667
665
668 nplots = len(pairsIndexList)
666 nplots = len(pairsIndexList)
669
667
670 self.setup(id=id,
668 self.setup(id=id,
671 nplots=nplots,
669 nplots=nplots,
672 wintitle=wintitle,
670 wintitle=wintitle,
673 showprofile=showprofile,
671 showprofile=showprofile,
674 show=show)
672 show=show)
675
673
676 if timerange != None:
674 if timerange != None:
677 self.timerange = timerange
675 self.timerange = timerange
678
676
679 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
677 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
680
678
681 if ymin == None: ymin = 0
679 if ymin == None: ymin = 0
682 if ymax == None: ymax = 360
680 if ymax == None: ymax = 360
683
681
684 self.FTP_WEI = ftp_wei
682 self.FTP_WEI = ftp_wei
685 self.EXP_CODE = exp_code
683 self.EXP_CODE = exp_code
686 self.SUB_EXP_CODE = sub_exp_code
684 self.SUB_EXP_CODE = sub_exp_code
687 self.PLOT_POS = plot_pos
685 self.PLOT_POS = plot_pos
688
686
689 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
687 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
690 self.isConfig = True
688 self.isConfig = True
691 self.figfile = figfile
689 self.figfile = figfile
692 self.xdata = numpy.array([])
690 self.xdata = numpy.array([])
693 self.ydata = numpy.array([])
691 self.ydata = numpy.array([])
694
692
695 update_figfile = True
693 update_figfile = True
696
694
697 #open file beacon phase
695 #open file beacon phase
698 path = '%s%03d' %(self.PREFIX, self.id)
696 path = '%s%03d' %(self.PREFIX, self.id)
699 beacon_file = os.path.join(path,'%s.txt'%self.name)
697 beacon_file = os.path.join(path,'%s.txt'%self.name)
700 self.filename_phase = os.path.join(figpath,beacon_file)
698 self.filename_phase = os.path.join(figpath,beacon_file)
701 #self.save_phase(self.filename_phase)
699 #self.save_phase(self.filename_phase)
702
700
703
701
704 #store data beacon phase
702 #store data beacon phase
705 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
703 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
706
704
707 self.setWinTitle(title)
705 self.setWinTitle(title)
708
706
709
707
710 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
708 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
711
709
712 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
710 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
713
711
714 axes = self.axesList[0]
712 axes = self.axesList[0]
715
713
716 self.xdata = numpy.hstack((self.xdata, x[0:1]))
714 self.xdata = numpy.hstack((self.xdata, x[0:1]))
717
715
718 if len(self.ydata)==0:
716 if len(self.ydata)==0:
719 self.ydata = phase_beacon.reshape(-1,1)
717 self.ydata = phase_beacon.reshape(-1,1)
720 else:
718 else:
721 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
719 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
722
720
723
721
724 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
722 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
725 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
723 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
726 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
724 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
727 XAxisAsTime=True, grid='both'
725 XAxisAsTime=True, grid='both'
728 )
726 )
729
727
730 self.draw()
728 self.draw()
731
729
732 if dataOut.ltctime >= self.xmax:
730 if dataOut.ltctime >= self.xmax:
733 self.counter_imagwr = wr_period
731 self.counter_imagwr = wr_period
734 self.isConfig = False
732 self.isConfig = False
735 update_figfile = True
733 update_figfile = True
736
734
737 self.save(figpath=figpath,
735 self.save(figpath=figpath,
738 figfile=figfile,
736 figfile=figfile,
739 save=save,
737 save=save,
740 ftp=ftp,
738 ftp=ftp,
741 wr_period=wr_period,
739 wr_period=wr_period,
742 thisDatetime=thisDatetime,
740 thisDatetime=thisDatetime,
743 update_figfile=update_figfile)
741 update_figfile=update_figfile)
744
742
745 return dataOut
743 return dataOut
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,1627 +1,1628
1 import sys
1 import sys
2 import numpy,math
2 import numpy,math
3 from scipy import interpolate
3 from scipy import interpolate
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
6 from schainpy.utils import log
6 from schainpy.utils import log
7 from time import time
7 from time import time
8
8
9
9
10
10
11 class VoltageProc(ProcessingUnit):
11 class VoltageProc(ProcessingUnit):
12
12
13 def __init__(self):
13 def __init__(self):
14
14
15 ProcessingUnit.__init__(self)
15 ProcessingUnit.__init__(self)
16
16
17 self.dataOut = Voltage()
17 self.dataOut = Voltage()
18 self.flip = 1
18 self.flip = 1
19 self.setupReq = False
19 self.setupReq = False
20
20
21 def run(self):
21 def run(self):
22
22
23 if self.dataIn.type == 'AMISR':
23 if self.dataIn.type == 'AMISR':
24 self.__updateObjFromAmisrInput()
24 self.__updateObjFromAmisrInput()
25
25
26 if self.dataIn.type == 'Voltage':
26 if self.dataIn.type == 'Voltage':
27 self.dataOut.copy(self.dataIn)
27 self.dataOut.copy(self.dataIn)
28
28
29 def __updateObjFromAmisrInput(self):
29 def __updateObjFromAmisrInput(self):
30
30
31 self.dataOut.timeZone = self.dataIn.timeZone
31 self.dataOut.timeZone = self.dataIn.timeZone
32 self.dataOut.dstFlag = self.dataIn.dstFlag
32 self.dataOut.dstFlag = self.dataIn.dstFlag
33 self.dataOut.errorCount = self.dataIn.errorCount
33 self.dataOut.errorCount = self.dataIn.errorCount
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35
35
36 self.dataOut.flagNoData = self.dataIn.flagNoData
36 self.dataOut.flagNoData = self.dataIn.flagNoData
37 self.dataOut.data = self.dataIn.data
37 self.dataOut.data = self.dataIn.data
38 self.dataOut.utctime = self.dataIn.utctime
38 self.dataOut.utctime = self.dataIn.utctime
39 self.dataOut.channelList = self.dataIn.channelList
39 self.dataOut.channelList = self.dataIn.channelList
40 #self.dataOut.timeInterval = self.dataIn.timeInterval
40 #self.dataOut.timeInterval = self.dataIn.timeInterval
41 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.nProfiles = self.dataIn.nProfiles
42 self.dataOut.nProfiles = self.dataIn.nProfiles
43
43
44 self.dataOut.nCohInt = self.dataIn.nCohInt
44 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 self.dataOut.frequency = self.dataIn.frequency
46 self.dataOut.frequency = self.dataIn.frequency
47
47
48 self.dataOut.azimuth = self.dataIn.azimuth
48 self.dataOut.azimuth = self.dataIn.azimuth
49 self.dataOut.zenith = self.dataIn.zenith
49 self.dataOut.zenith = self.dataIn.zenith
50
50
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54
54
55
55
56 class selectChannels(Operation):
56 class selectChannels(Operation):
57
57
58 def run(self, dataOut, channelList):
58 def run(self, dataOut, channelList):
59
59
60 channelIndexList = []
60 channelIndexList = []
61 self.dataOut = dataOut
61 self.dataOut = dataOut
62 for channel in channelList:
62 for channel in channelList:
63 if channel not in self.dataOut.channelList:
63 if channel not in self.dataOut.channelList:
64 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
64 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
65
65
66 index = self.dataOut.channelList.index(channel)
66 index = self.dataOut.channelList.index(channel)
67 channelIndexList.append(index)
67 channelIndexList.append(index)
68 self.selectChannelsByIndex(channelIndexList)
68 self.selectChannelsByIndex(channelIndexList)
69 return self.dataOut
69 return self.dataOut
70
70
71 def selectChannelsByIndex(self, channelIndexList):
71 def selectChannelsByIndex(self, channelIndexList):
72 """
72 """
73 Selecciona un bloque de datos en base a canales segun el channelIndexList
73 Selecciona un bloque de datos en base a canales segun el channelIndexList
74
74
75 Input:
75 Input:
76 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
76 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
77
77
78 Affected:
78 Affected:
79 self.dataOut.data
79 self.dataOut.data
80 self.dataOut.channelIndexList
80 self.dataOut.channelIndexList
81 self.dataOut.nChannels
81 self.dataOut.nChannels
82 self.dataOut.m_ProcessingHeader.totalSpectra
82 self.dataOut.m_ProcessingHeader.totalSpectra
83 self.dataOut.systemHeaderObj.numChannels
83 self.dataOut.systemHeaderObj.numChannels
84 self.dataOut.m_ProcessingHeader.blockSize
84 self.dataOut.m_ProcessingHeader.blockSize
85
85
86 Return:
86 Return:
87 None
87 None
88 """
88 """
89
89
90 for channelIndex in channelIndexList:
90 for channelIndex in channelIndexList:
91 if channelIndex not in self.dataOut.channelIndexList:
91 if channelIndex not in self.dataOut.channelIndexList:
92 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
92 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
93
93
94 if self.dataOut.type == 'Voltage':
94 if self.dataOut.type == 'Voltage':
95 if self.dataOut.flagDataAsBlock:
95 if self.dataOut.flagDataAsBlock:
96 """
96 """
97 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
97 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
98 """
98 """
99 data = self.dataOut.data[channelIndexList,:,:]
99 data = self.dataOut.data[channelIndexList,:,:]
100 else:
100 else:
101 data = self.dataOut.data[channelIndexList,:]
101 data = self.dataOut.data[channelIndexList,:]
102
102
103 self.dataOut.data = data
103 self.dataOut.data = data
104 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
104 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
105 self.dataOut.channelList = range(len(channelIndexList))
105 self.dataOut.channelList = range(len(channelIndexList))
106
106
107 elif self.dataOut.type == 'Spectra':
107 elif self.dataOut.type == 'Spectra':
108 data_spc = self.dataOut.data_spc[channelIndexList, :]
108 data_spc = self.dataOut.data_spc[channelIndexList, :]
109 data_dc = self.dataOut.data_dc[channelIndexList, :]
109 data_dc = self.dataOut.data_dc[channelIndexList, :]
110
110
111 self.dataOut.data_spc = data_spc
111 self.dataOut.data_spc = data_spc
112 self.dataOut.data_dc = data_dc
112 self.dataOut.data_dc = data_dc
113
113
114 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
114 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 self.dataOut.channelList = range(len(channelIndexList))
115 self.dataOut.channelList = range(len(channelIndexList))
116 self.__selectPairsByChannel(channelIndexList)
116 self.__selectPairsByChannel(channelIndexList)
117
117
118 return 1
118 return 1
119
119
120 def __selectPairsByChannel(self, channelList=None):
120 def __selectPairsByChannel(self, channelList=None):
121
121
122 if channelList == None:
122 if channelList == None:
123 return
123 return
124
124
125 pairsIndexListSelected = []
125 pairsIndexListSelected = []
126 for pairIndex in self.dataOut.pairsIndexList:
126 for pairIndex in self.dataOut.pairsIndexList:
127 # First pair
127 # First pair
128 if self.dataOut.pairsList[pairIndex][0] not in channelList:
128 if self.dataOut.pairsList[pairIndex][0] not in channelList:
129 continue
129 continue
130 # Second pair
130 # Second pair
131 if self.dataOut.pairsList[pairIndex][1] not in channelList:
131 if self.dataOut.pairsList[pairIndex][1] not in channelList:
132 continue
132 continue
133
133
134 pairsIndexListSelected.append(pairIndex)
134 pairsIndexListSelected.append(pairIndex)
135
135
136 if not pairsIndexListSelected:
136 if not pairsIndexListSelected:
137 self.dataOut.data_cspc = None
137 self.dataOut.data_cspc = None
138 self.dataOut.pairsList = []
138 self.dataOut.pairsList = []
139 return
139 return
140
140
141 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
141 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
142 self.dataOut.pairsList = [self.dataOut.pairsList[i]
142 self.dataOut.pairsList = [self.dataOut.pairsList[i]
143 for i in pairsIndexListSelected]
143 for i in pairsIndexListSelected]
144
144
145 return
145 return
146
146
147 class selectHeights(Operation):
147 class selectHeights(Operation):
148
148
149 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
149 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
150 """
150 """
151 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
151 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
152 minHei <= height <= maxHei
152 minHei <= height <= maxHei
153
153
154 Input:
154 Input:
155 minHei : valor minimo de altura a considerar
155 minHei : valor minimo de altura a considerar
156 maxHei : valor maximo de altura a considerar
156 maxHei : valor maximo de altura a considerar
157
157
158 Affected:
158 Affected:
159 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
159 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
160
160
161 Return:
161 Return:
162 1 si el metodo se ejecuto con exito caso contrario devuelve 0
162 1 si el metodo se ejecuto con exito caso contrario devuelve 0
163 """
163 """
164
164
165 self.dataOut = dataOut
165 self.dataOut = dataOut
166
166
167 if minHei and maxHei:
167 if minHei and maxHei:
168
168
169 if (minHei < self.dataOut.heightList[0]):
169 if (minHei < self.dataOut.heightList[0]):
170 minHei = self.dataOut.heightList[0]
170 minHei = self.dataOut.heightList[0]
171
171
172 if (maxHei > self.dataOut.heightList[-1]):
172 if (maxHei > self.dataOut.heightList[-1]):
173 maxHei = self.dataOut.heightList[-1]
173 maxHei = self.dataOut.heightList[-1]
174
174
175 minIndex = 0
175 minIndex = 0
176 maxIndex = 0
176 maxIndex = 0
177 heights = self.dataOut.heightList
177 heights = self.dataOut.heightList
178
178
179 inda = numpy.where(heights >= minHei)
179 inda = numpy.where(heights >= minHei)
180 indb = numpy.where(heights <= maxHei)
180 indb = numpy.where(heights <= maxHei)
181
181
182 try:
182 try:
183 minIndex = inda[0][0]
183 minIndex = inda[0][0]
184 except:
184 except:
185 minIndex = 0
185 minIndex = 0
186
186
187 try:
187 try:
188 maxIndex = indb[0][-1]
188 maxIndex = indb[0][-1]
189 except:
189 except:
190 maxIndex = len(heights)
190 maxIndex = len(heights)
191
191
192 self.selectHeightsByIndex(minIndex, maxIndex)
192 self.selectHeightsByIndex(minIndex, maxIndex)
193
193
194 return self.dataOut
194 return self.dataOut
195
195
196 def selectHeightsByIndex(self, minIndex, maxIndex):
196 def selectHeightsByIndex(self, minIndex, maxIndex):
197 """
197 """
198 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
198 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
199 minIndex <= index <= maxIndex
199 minIndex <= index <= maxIndex
200
200
201 Input:
201 Input:
202 minIndex : valor de indice minimo de altura a considerar
202 minIndex : valor de indice minimo de altura a considerar
203 maxIndex : valor de indice maximo de altura a considerar
203 maxIndex : valor de indice maximo de altura a considerar
204
204
205 Affected:
205 Affected:
206 self.dataOut.data
206 self.dataOut.data
207 self.dataOut.heightList
207 self.dataOut.heightList
208
208
209 Return:
209 Return:
210 1 si el metodo se ejecuto con exito caso contrario devuelve 0
210 1 si el metodo se ejecuto con exito caso contrario devuelve 0
211 """
211 """
212
212
213 if self.dataOut.type == 'Voltage':
213 if self.dataOut.type == 'Voltage':
214 if (minIndex < 0) or (minIndex > maxIndex):
214 if (minIndex < 0) or (minIndex > maxIndex):
215 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
215 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
216
216
217 if (maxIndex >= self.dataOut.nHeights):
217 if (maxIndex >= self.dataOut.nHeights):
218 maxIndex = self.dataOut.nHeights
218 maxIndex = self.dataOut.nHeights
219
219
220 #voltage
220 #voltage
221 if self.dataOut.flagDataAsBlock:
221 if self.dataOut.flagDataAsBlock:
222 """
222 """
223 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
223 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
224 """
224 """
225 data = self.dataOut.data[:,:, minIndex:maxIndex]
225 data = self.dataOut.data[:,:, minIndex:maxIndex]
226 else:
226 else:
227 data = self.dataOut.data[:, minIndex:maxIndex]
227 data = self.dataOut.data[:, minIndex:maxIndex]
228
228
229 # firstHeight = self.dataOut.heightList[minIndex]
229 # firstHeight = self.dataOut.heightList[minIndex]
230
230
231 self.dataOut.data = data
231 self.dataOut.data = data
232 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
232 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
233
233
234 if self.dataOut.nHeights <= 1:
234 if self.dataOut.nHeights <= 1:
235 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
235 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
236 elif self.dataOut.type == 'Spectra':
236 elif self.dataOut.type == 'Spectra':
237 if (minIndex < 0) or (minIndex > maxIndex):
237 if (minIndex < 0) or (minIndex > maxIndex):
238 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
238 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
239 minIndex, maxIndex))
239 minIndex, maxIndex))
240
240
241 if (maxIndex >= self.dataOut.nHeights):
241 if (maxIndex >= self.dataOut.nHeights):
242 maxIndex = self.dataOut.nHeights - 1
242 maxIndex = self.dataOut.nHeights - 1
243
243
244 # Spectra
244 # Spectra
245 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
245 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
246
246
247 data_cspc = None
247 data_cspc = None
248 if self.dataOut.data_cspc is not None:
248 if self.dataOut.data_cspc is not None:
249 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
249 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
250
250
251 data_dc = None
251 data_dc = None
252 if self.dataOut.data_dc is not None:
252 if self.dataOut.data_dc is not None:
253 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
253 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
254
254
255 self.dataOut.data_spc = data_spc
255 self.dataOut.data_spc = data_spc
256 self.dataOut.data_cspc = data_cspc
256 self.dataOut.data_cspc = data_cspc
257 self.dataOut.data_dc = data_dc
257 self.dataOut.data_dc = data_dc
258
258
259 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
259 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
260
260
261 return 1
261 return 1
262
262
263
263
264 class filterByHeights(Operation):
264 class filterByHeights(Operation):
265
265
266 def run(self, dataOut, window):
266 def run(self, dataOut, window):
267
267
268 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
268 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
269
269
270 if window == None:
270 if window == None:
271 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
271 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
272
272
273 newdelta = deltaHeight * window
273 newdelta = deltaHeight * window
274 r = dataOut.nHeights % window
274 r = dataOut.nHeights % window
275 newheights = (dataOut.nHeights-r)/window
275 newheights = (dataOut.nHeights-r)/window
276
276
277 if newheights <= 1:
277 if newheights <= 1:
278 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
278 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
279
279
280 if dataOut.flagDataAsBlock:
280 if dataOut.flagDataAsBlock:
281 """
281 """
282 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
282 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
283 """
283 """
284 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
284 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
285 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
285 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
286 buffer = numpy.sum(buffer,3)
286 buffer = numpy.sum(buffer,3)
287
287
288 else:
288 else:
289 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
289 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
290 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
290 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
291 buffer = numpy.sum(buffer,2)
291 buffer = numpy.sum(buffer,2)
292
292
293 dataOut.data = buffer
293 dataOut.data = buffer
294 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
294 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
295 dataOut.windowOfFilter = window
295 dataOut.windowOfFilter = window
296
296
297 return dataOut
297 return dataOut
298
298
299
299
300 class setH0(Operation):
300 class setH0(Operation):
301
301
302 def run(self, dataOut, h0, deltaHeight = None):
302 def run(self, dataOut, h0, deltaHeight = None):
303
303
304 if not deltaHeight:
304 if not deltaHeight:
305 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
305 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
306
306
307 nHeights = dataOut.nHeights
307 nHeights = dataOut.nHeights
308
308
309 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
309 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
310
310
311 dataOut.heightList = newHeiRange
311 dataOut.heightList = newHeiRange
312
312
313 return dataOut
313 return dataOut
314
314
315
315
316 class deFlip(Operation):
316 class deFlip(Operation):
317
317
318 def run(self, dataOut, channelList = []):
318 def run(self, dataOut, channelList = []):
319
319
320 data = dataOut.data.copy()
320 data = dataOut.data.copy()
321
321
322 if dataOut.flagDataAsBlock:
322 if dataOut.flagDataAsBlock:
323 flip = self.flip
323 flip = self.flip
324 profileList = list(range(dataOut.nProfiles))
324 profileList = list(range(dataOut.nProfiles))
325
325
326 if not channelList:
326 if not channelList:
327 for thisProfile in profileList:
327 for thisProfile in profileList:
328 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
328 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
329 flip *= -1.0
329 flip *= -1.0
330 else:
330 else:
331 for thisChannel in channelList:
331 for thisChannel in channelList:
332 if thisChannel not in dataOut.channelList:
332 if thisChannel not in dataOut.channelList:
333 continue
333 continue
334
334
335 for thisProfile in profileList:
335 for thisProfile in profileList:
336 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
336 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
337 flip *= -1.0
337 flip *= -1.0
338
338
339 self.flip = flip
339 self.flip = flip
340
340
341 else:
341 else:
342 if not channelList:
342 if not channelList:
343 data[:,:] = data[:,:]*self.flip
343 data[:,:] = data[:,:]*self.flip
344 else:
344 else:
345 for thisChannel in channelList:
345 for thisChannel in channelList:
346 if thisChannel not in dataOut.channelList:
346 if thisChannel not in dataOut.channelList:
347 continue
347 continue
348
348
349 data[thisChannel,:] = data[thisChannel,:]*self.flip
349 data[thisChannel,:] = data[thisChannel,:]*self.flip
350
350
351 self.flip *= -1.
351 self.flip *= -1.
352
352
353 dataOut.data = data
353 dataOut.data = data
354
354
355 return dataOut
355 return dataOut
356
356
357
357
358 class setAttribute(Operation):
358 class setAttribute(Operation):
359 '''
359 '''
360 Set an arbitrary attribute(s) to dataOut
360 Set an arbitrary attribute(s) to dataOut
361 '''
361 '''
362
362
363 def __init__(self):
363 def __init__(self):
364
364
365 Operation.__init__(self)
365 Operation.__init__(self)
366 self._ready = False
366 self._ready = False
367
367
368 def run(self, dataOut, **kwargs):
368 def run(self, dataOut, **kwargs):
369
369
370 for key, value in kwargs.items():
370 for key, value in kwargs.items():
371 setattr(dataOut, key, value)
371 setattr(dataOut, key, value)
372
372
373 return dataOut
373 return dataOut
374
374
375
375
376 @MPDecorator
376 @MPDecorator
377 class printAttribute(Operation):
377 class printAttribute(Operation):
378 '''
378 '''
379 Print an arbitrary attribute of dataOut
379 Print an arbitrary attribute of dataOut
380 '''
380 '''
381
381
382 def __init__(self):
382 def __init__(self):
383
383
384 Operation.__init__(self)
384 Operation.__init__(self)
385
385
386 def run(self, dataOut, attributes):
386 def run(self, dataOut, attributes):
387
387
388 if isinstance(attributes, str):
388 if isinstance(attributes, str):
389 attributes = [attributes]
389 attributes = [attributes]
390 for attr in attributes:
390 for attr in attributes:
391 if hasattr(dataOut, attr):
391 if hasattr(dataOut, attr):
392 log.log(getattr(dataOut, attr), attr)
392 log.log(getattr(dataOut, attr), attr)
393
393
394
394
395 class interpolateHeights(Operation):
395 class interpolateHeights(Operation):
396
396
397 def run(self, dataOut, topLim, botLim):
397 def run(self, dataOut, topLim, botLim):
398 #69 al 72 para julia
398 #69 al 72 para julia
399 #82-84 para meteoros
399 #82-84 para meteoros
400 if len(numpy.shape(dataOut.data))==2:
400 if len(numpy.shape(dataOut.data))==2:
401 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
401 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
402 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
402 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
403 #dataOut.data[:,botLim:limSup+1] = sampInterp
403 #dataOut.data[:,botLim:limSup+1] = sampInterp
404 dataOut.data[:,botLim:topLim+1] = sampInterp
404 dataOut.data[:,botLim:topLim+1] = sampInterp
405 else:
405 else:
406 nHeights = dataOut.data.shape[2]
406 nHeights = dataOut.data.shape[2]
407 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
407 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
408 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
408 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
409 f = interpolate.interp1d(x, y, axis = 2)
409 f = interpolate.interp1d(x, y, axis = 2)
410 xnew = numpy.arange(botLim,topLim+1)
410 xnew = numpy.arange(botLim,topLim+1)
411 ynew = f(xnew)
411 ynew = f(xnew)
412 dataOut.data[:,:,botLim:topLim+1] = ynew
412 dataOut.data[:,:,botLim:topLim+1] = ynew
413
413
414 return dataOut
414 return dataOut
415
415
416
416
417 class CohInt(Operation):
417 class CohInt(Operation):
418
418
419 isConfig = False
419 isConfig = False
420 __profIndex = 0
420 __profIndex = 0
421 __byTime = False
421 __byTime = False
422 __initime = None
422 __initime = None
423 __lastdatatime = None
423 __lastdatatime = None
424 __integrationtime = None
424 __integrationtime = None
425 __buffer = None
425 __buffer = None
426 __bufferStride = []
426 __bufferStride = []
427 __dataReady = False
427 __dataReady = False
428 __profIndexStride = 0
428 __profIndexStride = 0
429 __dataToPutStride = False
429 __dataToPutStride = False
430 n = None
430 n = None
431
431
432 def __init__(self, **kwargs):
432 def __init__(self, **kwargs):
433
433
434 Operation.__init__(self, **kwargs)
434 Operation.__init__(self, **kwargs)
435
435
436 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
436 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
437 """
437 """
438 Set the parameters of the integration class.
438 Set the parameters of the integration class.
439
439
440 Inputs:
440 Inputs:
441
441
442 n : Number of coherent integrations
442 n : Number of coherent integrations
443 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
443 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
444 overlapping :
444 overlapping :
445 """
445 """
446
446
447 self.__initime = None
447 self.__initime = None
448 self.__lastdatatime = 0
448 self.__lastdatatime = 0
449 self.__buffer = None
449 self.__buffer = None
450 self.__dataReady = False
450 self.__dataReady = False
451 self.byblock = byblock
451 self.byblock = byblock
452 self.stride = stride
452 self.stride = stride
453
453
454 if n == None and timeInterval == None:
454 if n == None and timeInterval == None:
455 raise ValueError("n or timeInterval should be specified ...")
455 raise ValueError("n or timeInterval should be specified ...")
456
456
457 if n != None:
457 if n != None:
458 self.n = n
458 self.n = n
459 self.__byTime = False
459 self.__byTime = False
460 else:
460 else:
461 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
461 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
462 self.n = 9999
462 self.n = 9999
463 self.__byTime = True
463 self.__byTime = True
464
464
465 if overlapping:
465 if overlapping:
466 self.__withOverlapping = True
466 self.__withOverlapping = True
467 self.__buffer = None
467 self.__buffer = None
468 else:
468 else:
469 self.__withOverlapping = False
469 self.__withOverlapping = False
470 self.__buffer = 0
470 self.__buffer = 0
471
471
472 self.__profIndex = 0
472 self.__profIndex = 0
473
473
474 def putData(self, data):
474 def putData(self, data):
475
475
476 """
476 """
477 Add a profile to the __buffer and increase in one the __profileIndex
477 Add a profile to the __buffer and increase in one the __profileIndex
478
478
479 """
479 """
480
480
481 if not self.__withOverlapping:
481 if not self.__withOverlapping:
482 self.__buffer += data.copy()
482 self.__buffer += data.copy()
483 self.__profIndex += 1
483 self.__profIndex += 1
484 return
484 return
485
485
486 #Overlapping data
486 #Overlapping data
487 nChannels, nHeis = data.shape
487 nChannels, nHeis = data.shape
488 data = numpy.reshape(data, (1, nChannels, nHeis))
488 data = numpy.reshape(data, (1, nChannels, nHeis))
489
489
490 #If the buffer is empty then it takes the data value
490 #If the buffer is empty then it takes the data value
491 if self.__buffer is None:
491 if self.__buffer is None:
492 self.__buffer = data
492 self.__buffer = data
493 self.__profIndex += 1
493 self.__profIndex += 1
494 return
494 return
495
495
496 #If the buffer length is lower than n then stakcing the data value
496 #If the buffer length is lower than n then stakcing the data value
497 if self.__profIndex < self.n:
497 if self.__profIndex < self.n:
498 self.__buffer = numpy.vstack((self.__buffer, data))
498 self.__buffer = numpy.vstack((self.__buffer, data))
499 self.__profIndex += 1
499 self.__profIndex += 1
500 return
500 return
501
501
502 #If the buffer length is equal to n then replacing the last buffer value with the data value
502 #If the buffer length is equal to n then replacing the last buffer value with the data value
503 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
503 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
504 self.__buffer[self.n-1] = data
504 self.__buffer[self.n-1] = data
505 self.__profIndex = self.n
505 self.__profIndex = self.n
506 return
506 return
507
507
508
508
509 def pushData(self):
509 def pushData(self):
510 """
510 """
511 Return the sum of the last profiles and the profiles used in the sum.
511 Return the sum of the last profiles and the profiles used in the sum.
512
512
513 Affected:
513 Affected:
514
514
515 self.__profileIndex
515 self.__profileIndex
516
516
517 """
517 """
518
518
519 if not self.__withOverlapping:
519 if not self.__withOverlapping:
520 data = self.__buffer
520 data = self.__buffer
521 n = self.__profIndex
521 n = self.__profIndex
522
522
523 self.__buffer = 0
523 self.__buffer = 0
524 self.__profIndex = 0
524 self.__profIndex = 0
525
525
526 return data, n
526 return data, n
527
527
528 #Integration with Overlapping
528 #Integration with Overlapping
529 data = numpy.sum(self.__buffer, axis=0)
529 data = numpy.sum(self.__buffer, axis=0)
530 # print data
530 # print data
531 # raise
531 # raise
532 n = self.__profIndex
532 n = self.__profIndex
533
533
534 return data, n
534 return data, n
535
535
536 def byProfiles(self, data):
536 def byProfiles(self, data):
537
537
538 self.__dataReady = False
538 self.__dataReady = False
539 avgdata = None
539 avgdata = None
540 # n = None
540 # n = None
541 # print data
541 # print data
542 # raise
542 # raise
543 self.putData(data)
543 self.putData(data)
544
544
545 if self.__profIndex == self.n:
545 if self.__profIndex == self.n:
546 avgdata, n = self.pushData()
546 avgdata, n = self.pushData()
547 self.__dataReady = True
547 self.__dataReady = True
548
548
549 return avgdata
549 return avgdata
550
550
551 def byTime(self, data, datatime):
551 def byTime(self, data, datatime):
552
552
553 self.__dataReady = False
553 self.__dataReady = False
554 avgdata = None
554 avgdata = None
555 n = None
555 n = None
556
556
557 self.putData(data)
557 self.putData(data)
558
558
559 if (datatime - self.__initime) >= self.__integrationtime:
559 if (datatime - self.__initime) >= self.__integrationtime:
560 avgdata, n = self.pushData()
560 avgdata, n = self.pushData()
561 self.n = n
561 self.n = n
562 self.__dataReady = True
562 self.__dataReady = True
563
563
564 return avgdata
564 return avgdata
565
565
566 def integrateByStride(self, data, datatime):
566 def integrateByStride(self, data, datatime):
567 # print data
567 # print data
568 if self.__profIndex == 0:
568 if self.__profIndex == 0:
569 self.__buffer = [[data.copy(), datatime]]
569 self.__buffer = [[data.copy(), datatime]]
570 else:
570 else:
571 self.__buffer.append([data.copy(),datatime])
571 self.__buffer.append([data.copy(),datatime])
572 self.__profIndex += 1
572 self.__profIndex += 1
573 self.__dataReady = False
573 self.__dataReady = False
574
574
575 if self.__profIndex == self.n * self.stride :
575 if self.__profIndex == self.n * self.stride :
576 self.__dataToPutStride = True
576 self.__dataToPutStride = True
577 self.__profIndexStride = 0
577 self.__profIndexStride = 0
578 self.__profIndex = 0
578 self.__profIndex = 0
579 self.__bufferStride = []
579 self.__bufferStride = []
580 for i in range(self.stride):
580 for i in range(self.stride):
581 current = self.__buffer[i::self.stride]
581 current = self.__buffer[i::self.stride]
582 data = numpy.sum([t[0] for t in current], axis=0)
582 data = numpy.sum([t[0] for t in current], axis=0)
583 avgdatatime = numpy.average([t[1] for t in current])
583 avgdatatime = numpy.average([t[1] for t in current])
584 # print data
584 # print data
585 self.__bufferStride.append((data, avgdatatime))
585 self.__bufferStride.append((data, avgdatatime))
586
586
587 if self.__dataToPutStride:
587 if self.__dataToPutStride:
588 self.__dataReady = True
588 self.__dataReady = True
589 self.__profIndexStride += 1
589 self.__profIndexStride += 1
590 if self.__profIndexStride == self.stride:
590 if self.__profIndexStride == self.stride:
591 self.__dataToPutStride = False
591 self.__dataToPutStride = False
592 # print self.__bufferStride[self.__profIndexStride - 1]
592 # print self.__bufferStride[self.__profIndexStride - 1]
593 # raise
593 # raise
594 return self.__bufferStride[self.__profIndexStride - 1]
594 return self.__bufferStride[self.__profIndexStride - 1]
595
595
596
596
597 return None, None
597 return None, None
598
598
599 def integrate(self, data, datatime=None):
599 def integrate(self, data, datatime=None):
600
600
601 if self.__initime == None:
601 if self.__initime == None:
602 self.__initime = datatime
602 self.__initime = datatime
603
603
604 if self.__byTime:
604 if self.__byTime:
605 avgdata = self.byTime(data, datatime)
605 avgdata = self.byTime(data, datatime)
606 else:
606 else:
607 avgdata = self.byProfiles(data)
607 avgdata = self.byProfiles(data)
608
608
609
609
610 self.__lastdatatime = datatime
610 self.__lastdatatime = datatime
611
611
612 if avgdata is None:
612 if avgdata is None:
613 return None, None
613 return None, None
614
614
615 avgdatatime = self.__initime
615 avgdatatime = self.__initime
616
616
617 deltatime = datatime - self.__lastdatatime
617 deltatime = datatime - self.__lastdatatime
618
618
619 if not self.__withOverlapping:
619 if not self.__withOverlapping:
620 self.__initime = datatime
620 self.__initime = datatime
621 else:
621 else:
622 self.__initime += deltatime
622 self.__initime += deltatime
623
623
624 return avgdata, avgdatatime
624 return avgdata, avgdatatime
625
625
626 def integrateByBlock(self, dataOut):
626 def integrateByBlock(self, dataOut):
627
627
628 times = int(dataOut.data.shape[1]/self.n)
628 times = int(dataOut.data.shape[1]/self.n)
629 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
629 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
630
630
631 id_min = 0
631 id_min = 0
632 id_max = self.n
632 id_max = self.n
633
633
634 for i in range(times):
634 for i in range(times):
635 junk = dataOut.data[:,id_min:id_max,:]
635 junk = dataOut.data[:,id_min:id_max,:]
636 avgdata[:,i,:] = junk.sum(axis=1)
636 avgdata[:,i,:] = junk.sum(axis=1)
637 id_min += self.n
637 id_min += self.n
638 id_max += self.n
638 id_max += self.n
639
639
640 timeInterval = dataOut.ippSeconds*self.n
640 timeInterval = dataOut.ippSeconds*self.n
641 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
641 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
642 self.__dataReady = True
642 self.__dataReady = True
643 return avgdata, avgdatatime
643 return avgdata, avgdatatime
644
644
645 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
645 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
646
646
647 if not self.isConfig:
647 if not self.isConfig:
648 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
648 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
649 self.isConfig = True
649 self.isConfig = True
650
650
651 if dataOut.flagDataAsBlock:
651 if dataOut.flagDataAsBlock:
652 """
652 """
653 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
653 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
654 """
654 """
655 avgdata, avgdatatime = self.integrateByBlock(dataOut)
655 avgdata, avgdatatime = self.integrateByBlock(dataOut)
656 dataOut.nProfiles /= self.n
656 dataOut.nProfiles /= self.n
657 else:
657 else:
658 if stride is None:
658 if stride is None:
659 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
659 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
660 else:
660 else:
661 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
661 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
662
662
663
663
664 # dataOut.timeInterval *= n
664 # dataOut.timeInterval *= n
665 dataOut.flagNoData = True
665 dataOut.flagNoData = True
666
666
667 if self.__dataReady:
667 if self.__dataReady:
668 dataOut.data = avgdata
668 dataOut.data = avgdata
669 if not dataOut.flagCohInt:
669 if not dataOut.flagCohInt:
670 dataOut.nCohInt *= self.n
670 dataOut.nCohInt *= self.n
671 dataOut.flagCohInt = True
671 dataOut.flagCohInt = True
672 dataOut.utctime = avgdatatime
672 dataOut.utctime = avgdatatime
673 # print avgdata, avgdatatime
673 # print avgdata, avgdatatime
674 # raise
674 # raise
675 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
675 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
676 dataOut.flagNoData = False
676 dataOut.flagNoData = False
677 return dataOut
677 return dataOut
678
678
679 class Decoder(Operation):
679 class Decoder(Operation):
680
680
681 isConfig = False
681 isConfig = False
682 __profIndex = 0
682 __profIndex = 0
683
683
684 code = None
684 code = None
685
685
686 nCode = None
686 nCode = None
687 nBaud = None
687 nBaud = None
688
688
689 def __init__(self, **kwargs):
689 def __init__(self, **kwargs):
690
690
691 Operation.__init__(self, **kwargs)
691 Operation.__init__(self, **kwargs)
692
692
693 self.times = None
693 self.times = None
694 self.osamp = None
694 self.osamp = None
695 # self.__setValues = False
695 # self.__setValues = False
696 self.isConfig = False
696 self.isConfig = False
697 self.setupReq = False
697 self.setupReq = False
698 def setup(self, code, osamp, dataOut):
698 def setup(self, code, osamp, dataOut):
699
699
700 self.__profIndex = 0
700 self.__profIndex = 0
701
701
702 self.code = code
702 self.code = code
703
703
704 self.nCode = len(code)
704 self.nCode = len(code)
705 self.nBaud = len(code[0])
705 self.nBaud = len(code[0])
706
706
707 if (osamp != None) and (osamp >1):
707 if (osamp != None) and (osamp >1):
708 self.osamp = osamp
708 self.osamp = osamp
709 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
709 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
710 self.nBaud = self.nBaud*self.osamp
710 self.nBaud = self.nBaud*self.osamp
711
711
712 self.__nChannels = dataOut.nChannels
712 self.__nChannels = dataOut.nChannels
713 self.__nProfiles = dataOut.nProfiles
713 self.__nProfiles = dataOut.nProfiles
714 self.__nHeis = dataOut.nHeights
714 self.__nHeis = dataOut.nHeights
715
715
716 if self.__nHeis < self.nBaud:
716 if self.__nHeis < self.nBaud:
717 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
717 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
718
718
719 #Frequency
719 #Frequency
720 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
720 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
721
721
722 __codeBuffer[:,0:self.nBaud] = self.code
722 __codeBuffer[:,0:self.nBaud] = self.code
723
723
724 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
724 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
725
725
726 if dataOut.flagDataAsBlock:
726 if dataOut.flagDataAsBlock:
727
727
728 self.ndatadec = self.__nHeis #- self.nBaud + 1
728 self.ndatadec = self.__nHeis #- self.nBaud + 1
729
729
730 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
730 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
731
731
732 else:
732 else:
733
733
734 #Time
734 #Time
735 self.ndatadec = self.__nHeis #- self.nBaud + 1
735 self.ndatadec = self.__nHeis #- self.nBaud + 1
736
736
737 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
737 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
738
738
739 def __convolutionInFreq(self, data):
739 def __convolutionInFreq(self, data):
740
740
741 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
741 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
742
742
743 fft_data = numpy.fft.fft(data, axis=1)
743 fft_data = numpy.fft.fft(data, axis=1)
744
744
745 conv = fft_data*fft_code
745 conv = fft_data*fft_code
746
746
747 data = numpy.fft.ifft(conv,axis=1)
747 data = numpy.fft.ifft(conv,axis=1)
748
748
749 return data
749 return data
750
750
751 def __convolutionInFreqOpt(self, data):
751 def __convolutionInFreqOpt(self, data):
752
752
753 raise NotImplementedError
753 raise NotImplementedError
754
754
755 def __convolutionInTime(self, data):
755 def __convolutionInTime(self, data):
756
756
757 code = self.code[self.__profIndex]
757 code = self.code[self.__profIndex]
758 for i in range(self.__nChannels):
758 for i in range(self.__nChannels):
759 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
759 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
760
760
761 return self.datadecTime
761 return self.datadecTime
762
762
763 def __convolutionByBlockInTime(self, data):
763 def __convolutionByBlockInTime(self, data):
764
764
765 repetitions = int(self.__nProfiles / self.nCode)
765 repetitions = int(self.__nProfiles / self.nCode)
766 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
766 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
767 junk = junk.flatten()
767 junk = junk.flatten()
768 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
768 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
769 profilesList = range(self.__nProfiles)
769 profilesList = range(self.__nProfiles)
770
770
771 for i in range(self.__nChannels):
771 for i in range(self.__nChannels):
772 for j in profilesList:
772 for j in profilesList:
773 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
773 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
774 return self.datadecTime
774 return self.datadecTime
775
775
776 def __convolutionByBlockInFreq(self, data):
776 def __convolutionByBlockInFreq(self, data):
777
777
778 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
778 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
779
779
780
780
781 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
781 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
782
782
783 fft_data = numpy.fft.fft(data, axis=2)
783 fft_data = numpy.fft.fft(data, axis=2)
784
784
785 conv = fft_data*fft_code
785 conv = fft_data*fft_code
786
786
787 data = numpy.fft.ifft(conv,axis=2)
787 data = numpy.fft.ifft(conv,axis=2)
788
788
789 return data
789 return data
790
790
791
791
792 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
792 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
793
793
794 if dataOut.flagDecodeData:
794 if dataOut.flagDecodeData:
795 print("This data is already decoded, recoding again ...")
795 print("This data is already decoded, recoding again ...")
796
796
797 if not self.isConfig:
797 if not self.isConfig:
798
798
799 if code is None:
799 if code is None:
800 if dataOut.code is None:
800 if dataOut.code is None:
801 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
801 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
802
802
803 code = dataOut.code
803 code = dataOut.code
804 else:
804 else:
805 code = numpy.array(code).reshape(nCode,nBaud)
805 code = numpy.array(code).reshape(nCode,nBaud)
806 self.setup(code, osamp, dataOut)
806 self.setup(code, osamp, dataOut)
807
807
808 self.isConfig = True
808 self.isConfig = True
809
809
810 if mode == 3:
810 if mode == 3:
811 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
811 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
812
812
813 if times != None:
813 if times != None:
814 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
814 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
815
815
816 if self.code is None:
816 if self.code is None:
817 print("Fail decoding: Code is not defined.")
817 print("Fail decoding: Code is not defined.")
818 return
818 return
819
819
820 self.__nProfiles = dataOut.nProfiles
820 self.__nProfiles = dataOut.nProfiles
821 datadec = None
821 datadec = None
822
822
823 if mode == 3:
823 if mode == 3:
824 mode = 0
824 mode = 0
825
825
826 if dataOut.flagDataAsBlock:
826 if dataOut.flagDataAsBlock:
827 """
827 """
828 Decoding when data have been read as block,
828 Decoding when data have been read as block,
829 """
829 """
830
830
831 if mode == 0:
831 if mode == 0:
832 datadec = self.__convolutionByBlockInTime(dataOut.data)
832 datadec = self.__convolutionByBlockInTime(dataOut.data)
833 if mode == 1:
833 if mode == 1:
834 datadec = self.__convolutionByBlockInFreq(dataOut.data)
834 datadec = self.__convolutionByBlockInFreq(dataOut.data)
835 else:
835 else:
836 """
836 """
837 Decoding when data have been read profile by profile
837 Decoding when data have been read profile by profile
838 """
838 """
839 if mode == 0:
839 if mode == 0:
840 datadec = self.__convolutionInTime(dataOut.data)
840 datadec = self.__convolutionInTime(dataOut.data)
841
841
842 if mode == 1:
842 if mode == 1:
843 datadec = self.__convolutionInFreq(dataOut.data)
843 datadec = self.__convolutionInFreq(dataOut.data)
844
844
845 if mode == 2:
845 if mode == 2:
846 datadec = self.__convolutionInFreqOpt(dataOut.data)
846 datadec = self.__convolutionInFreqOpt(dataOut.data)
847
847
848 if datadec is None:
848 if datadec is None:
849 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
849 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
850
850
851 dataOut.code = self.code
851 dataOut.code = self.code
852 dataOut.nCode = self.nCode
852 dataOut.nCode = self.nCode
853 dataOut.nBaud = self.nBaud
853 dataOut.nBaud = self.nBaud
854
854
855 dataOut.data = datadec
855 dataOut.data = datadec
856
856
857 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
857 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
858
858
859 dataOut.flagDecodeData = True #asumo q la data esta decodificada
859 dataOut.flagDecodeData = True #asumo q la data esta decodificada
860
860
861 if self.__profIndex == self.nCode-1:
861 if self.__profIndex == self.nCode-1:
862 self.__profIndex = 0
862 self.__profIndex = 0
863 return dataOut
863 return dataOut
864
864
865 self.__profIndex += 1
865 self.__profIndex += 1
866
866
867 return dataOut
867 return dataOut
868 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
868 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
869
869
870
870
871 class ProfileConcat(Operation):
871 class ProfileConcat(Operation):
872
872
873 isConfig = False
873 isConfig = False
874 buffer = None
874 buffer = None
875
875
876 def __init__(self, **kwargs):
876 def __init__(self, **kwargs):
877
877
878 Operation.__init__(self, **kwargs)
878 Operation.__init__(self, **kwargs)
879 self.profileIndex = 0
879 self.profileIndex = 0
880
880
881 def reset(self):
881 def reset(self):
882 self.buffer = numpy.zeros_like(self.buffer)
882 self.buffer = numpy.zeros_like(self.buffer)
883 self.start_index = 0
883 self.start_index = 0
884 self.times = 1
884 self.times = 1
885
885
886 def setup(self, data, m, n=1):
886 def setup(self, data, m, n=1):
887 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
887 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
888 self.nHeights = data.shape[1]#.nHeights
888 self.nHeights = data.shape[1]#.nHeights
889 self.start_index = 0
889 self.start_index = 0
890 self.times = 1
890 self.times = 1
891
891
892 def concat(self, data):
892 def concat(self, data):
893
893
894 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
894 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
895 self.start_index = self.start_index + self.nHeights
895 self.start_index = self.start_index + self.nHeights
896
896
897 def run(self, dataOut, m):
897 def run(self, dataOut, m):
898 dataOut.flagNoData = True
898 dataOut.flagNoData = True
899
899
900 if not self.isConfig:
900 if not self.isConfig:
901 self.setup(dataOut.data, m, 1)
901 self.setup(dataOut.data, m, 1)
902 self.isConfig = True
902 self.isConfig = True
903
903
904 if dataOut.flagDataAsBlock:
904 if dataOut.flagDataAsBlock:
905 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
905 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
906
906
907 else:
907 else:
908 self.concat(dataOut.data)
908 self.concat(dataOut.data)
909 self.times += 1
909 self.times += 1
910 if self.times > m:
910 if self.times > m:
911 dataOut.data = self.buffer
911 dataOut.data = self.buffer
912 self.reset()
912 self.reset()
913 dataOut.flagNoData = False
913 dataOut.flagNoData = False
914 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
914 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
915 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
915 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
916 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
916 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
917 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
917 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
918 dataOut.ippSeconds *= m
918 dataOut.ippSeconds *= m
919 return dataOut
919 return dataOut
920
920
921 class ProfileSelector(Operation):
921 class ProfileSelector(Operation):
922
922
923 profileIndex = None
923 profileIndex = None
924 # Tamanho total de los perfiles
924 # Tamanho total de los perfiles
925 nProfiles = None
925 nProfiles = None
926
926
927 def __init__(self, **kwargs):
927 def __init__(self, **kwargs):
928
928
929 Operation.__init__(self, **kwargs)
929 Operation.__init__(self, **kwargs)
930 self.profileIndex = 0
930 self.profileIndex = 0
931
931
932 def incProfileIndex(self):
932 def incProfileIndex(self):
933
933
934 self.profileIndex += 1
934 self.profileIndex += 1
935
935
936 if self.profileIndex >= self.nProfiles:
936 if self.profileIndex >= self.nProfiles:
937 self.profileIndex = 0
937 self.profileIndex = 0
938
938
939 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
939 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
940
940
941 if profileIndex < minIndex:
941 if profileIndex < minIndex:
942 return False
942 return False
943
943
944 if profileIndex > maxIndex:
944 if profileIndex > maxIndex:
945 return False
945 return False
946
946
947 return True
947 return True
948
948
949 def isThisProfileInList(self, profileIndex, profileList):
949 def isThisProfileInList(self, profileIndex, profileList):
950
950
951 if profileIndex not in profileList:
951 if profileIndex not in profileList:
952 return False
952 return False
953
953
954 return True
954 return True
955
955
956 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
956 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
957
957
958 """
958 """
959 ProfileSelector:
959 ProfileSelector:
960
960
961 Inputs:
961 Inputs:
962 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
962 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
963
963
964 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
964 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
965
965
966 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
966 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
967
967
968 """
968 """
969
969
970 if rangeList is not None:
970 if rangeList is not None:
971 if type(rangeList[0]) not in (tuple, list):
971 if type(rangeList[0]) not in (tuple, list):
972 rangeList = [rangeList]
972 rangeList = [rangeList]
973
973
974 dataOut.flagNoData = True
974 dataOut.flagNoData = True
975
975
976 if dataOut.flagDataAsBlock:
976 if dataOut.flagDataAsBlock:
977 """
977 """
978 data dimension = [nChannels, nProfiles, nHeis]
978 data dimension = [nChannels, nProfiles, nHeis]
979 """
979 """
980 if profileList != None:
980 if profileList != None:
981 dataOut.data = dataOut.data[:,profileList,:]
981 dataOut.data = dataOut.data[:,profileList,:]
982
982
983 if profileRangeList != None:
983 if profileRangeList != None:
984 minIndex = profileRangeList[0]
984 minIndex = profileRangeList[0]
985 maxIndex = profileRangeList[1]
985 maxIndex = profileRangeList[1]
986 profileList = list(range(minIndex, maxIndex+1))
986 profileList = list(range(minIndex, maxIndex+1))
987
987
988 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
988 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
989
989
990 if rangeList != None:
990 if rangeList != None:
991
991
992 profileList = []
992 profileList = []
993
993
994 for thisRange in rangeList:
994 for thisRange in rangeList:
995 minIndex = thisRange[0]
995 minIndex = thisRange[0]
996 maxIndex = thisRange[1]
996 maxIndex = thisRange[1]
997
997
998 profileList.extend(list(range(minIndex, maxIndex+1)))
998 profileList.extend(list(range(minIndex, maxIndex+1)))
999
999
1000 dataOut.data = dataOut.data[:,profileList,:]
1000 dataOut.data = dataOut.data[:,profileList,:]
1001
1001
1002 dataOut.nProfiles = len(profileList)
1002 dataOut.nProfiles = len(profileList)
1003 dataOut.profileIndex = dataOut.nProfiles - 1
1003 dataOut.profileIndex = dataOut.nProfiles - 1
1004 dataOut.flagNoData = False
1004 dataOut.flagNoData = False
1005
1005
1006 return dataOut
1006 return dataOut
1007
1007
1008 """
1008 """
1009 data dimension = [nChannels, nHeis]
1009 data dimension = [nChannels, nHeis]
1010 """
1010 """
1011
1011
1012 if profileList != None:
1012 if profileList != None:
1013
1013
1014 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1014 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1015
1015
1016 self.nProfiles = len(profileList)
1016 self.nProfiles = len(profileList)
1017 dataOut.nProfiles = self.nProfiles
1017 dataOut.nProfiles = self.nProfiles
1018 dataOut.profileIndex = self.profileIndex
1018 dataOut.profileIndex = self.profileIndex
1019 dataOut.flagNoData = False
1019 dataOut.flagNoData = False
1020
1020
1021 self.incProfileIndex()
1021 self.incProfileIndex()
1022 return dataOut
1022 return dataOut
1023
1023
1024 if profileRangeList != None:
1024 if profileRangeList != None:
1025
1025
1026 minIndex = profileRangeList[0]
1026 minIndex = profileRangeList[0]
1027 maxIndex = profileRangeList[1]
1027 maxIndex = profileRangeList[1]
1028
1028
1029 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1029 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1030
1030
1031 self.nProfiles = maxIndex - minIndex + 1
1031 self.nProfiles = maxIndex - minIndex + 1
1032 dataOut.nProfiles = self.nProfiles
1032 dataOut.nProfiles = self.nProfiles
1033 dataOut.profileIndex = self.profileIndex
1033 dataOut.profileIndex = self.profileIndex
1034 dataOut.flagNoData = False
1034 dataOut.flagNoData = False
1035
1035
1036 self.incProfileIndex()
1036 self.incProfileIndex()
1037 return dataOut
1037 return dataOut
1038
1038
1039 if rangeList != None:
1039 if rangeList != None:
1040
1040
1041 nProfiles = 0
1041 nProfiles = 0
1042
1042
1043 for thisRange in rangeList:
1043 for thisRange in rangeList:
1044 minIndex = thisRange[0]
1044 minIndex = thisRange[0]
1045 maxIndex = thisRange[1]
1045 maxIndex = thisRange[1]
1046
1046
1047 nProfiles += maxIndex - minIndex + 1
1047 nProfiles += maxIndex - minIndex + 1
1048
1048
1049 for thisRange in rangeList:
1049 for thisRange in rangeList:
1050
1050
1051 minIndex = thisRange[0]
1051 minIndex = thisRange[0]
1052 maxIndex = thisRange[1]
1052 maxIndex = thisRange[1]
1053
1053
1054 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1054 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1055
1055
1056 self.nProfiles = nProfiles
1056 self.nProfiles = nProfiles
1057 dataOut.nProfiles = self.nProfiles
1057 dataOut.nProfiles = self.nProfiles
1058 dataOut.profileIndex = self.profileIndex
1058 dataOut.profileIndex = self.profileIndex
1059 dataOut.flagNoData = False
1059 dataOut.flagNoData = False
1060
1060
1061 self.incProfileIndex()
1061 self.incProfileIndex()
1062
1062
1063 break
1063 break
1064
1064
1065 return dataOut
1065 return dataOut
1066
1066
1067
1067
1068 if beam != None: #beam is only for AMISR data
1068 if beam != None: #beam is only for AMISR data
1069 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1069 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1070 dataOut.flagNoData = False
1070 dataOut.flagNoData = False
1071 dataOut.profileIndex = self.profileIndex
1071 dataOut.profileIndex = self.profileIndex
1072
1072
1073 self.incProfileIndex()
1073 self.incProfileIndex()
1074
1074
1075 return dataOut
1075 return dataOut
1076
1076
1077 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1077 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1078
1078
1079
1079
1080 class Reshaper(Operation):
1080 class Reshaper(Operation):
1081
1081
1082 def __init__(self, **kwargs):
1082 def __init__(self, **kwargs):
1083
1083
1084 Operation.__init__(self, **kwargs)
1084 Operation.__init__(self, **kwargs)
1085
1085
1086 self.__buffer = None
1086 self.__buffer = None
1087 self.__nitems = 0
1087 self.__nitems = 0
1088
1088
1089 def __appendProfile(self, dataOut, nTxs):
1089 def __appendProfile(self, dataOut, nTxs):
1090
1090
1091 if self.__buffer is None:
1091 if self.__buffer is None:
1092 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1092 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1093 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1093 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1094
1094
1095 ini = dataOut.nHeights * self.__nitems
1095 ini = dataOut.nHeights * self.__nitems
1096 end = ini + dataOut.nHeights
1096 end = ini + dataOut.nHeights
1097
1097
1098 self.__buffer[:, ini:end] = dataOut.data
1098 self.__buffer[:, ini:end] = dataOut.data
1099
1099
1100 self.__nitems += 1
1100 self.__nitems += 1
1101
1101
1102 return int(self.__nitems*nTxs)
1102 return int(self.__nitems*nTxs)
1103
1103
1104 def __getBuffer(self):
1104 def __getBuffer(self):
1105
1105
1106 if self.__nitems == int(1./self.__nTxs):
1106 if self.__nitems == int(1./self.__nTxs):
1107
1107
1108 self.__nitems = 0
1108 self.__nitems = 0
1109
1109
1110 return self.__buffer.copy()
1110 return self.__buffer.copy()
1111
1111
1112 return None
1112 return None
1113
1113
1114 def __checkInputs(self, dataOut, shape, nTxs):
1114 def __checkInputs(self, dataOut, shape, nTxs):
1115
1115
1116 if shape is None and nTxs is None:
1116 if shape is None and nTxs is None:
1117 raise ValueError("Reshaper: shape of factor should be defined")
1117 raise ValueError("Reshaper: shape of factor should be defined")
1118
1118
1119 if nTxs:
1119 if nTxs:
1120 if nTxs < 0:
1120 if nTxs < 0:
1121 raise ValueError("nTxs should be greater than 0")
1121 raise ValueError("nTxs should be greater than 0")
1122
1122
1123 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1123 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1124 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1124 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1125
1125
1126 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1126 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1127
1127
1128 return shape, nTxs
1128 return shape, nTxs
1129
1129
1130 if len(shape) != 2 and len(shape) != 3:
1130 if len(shape) != 2 and len(shape) != 3:
1131 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1131 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1132
1132
1133 if len(shape) == 2:
1133 if len(shape) == 2:
1134 shape_tuple = [dataOut.nChannels]
1134 shape_tuple = [dataOut.nChannels]
1135 shape_tuple.extend(shape)
1135 shape_tuple.extend(shape)
1136 else:
1136 else:
1137 shape_tuple = list(shape)
1137 shape_tuple = list(shape)
1138
1138
1139 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1139 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1140
1140
1141 return shape_tuple, nTxs
1141 return shape_tuple, nTxs
1142
1142
1143 def run(self, dataOut, shape=None, nTxs=None):
1143 def run(self, dataOut, shape=None, nTxs=None):
1144
1144
1145 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1145 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1146
1146
1147 dataOut.flagNoData = True
1147 dataOut.flagNoData = True
1148 profileIndex = None
1148 profileIndex = None
1149
1149
1150 if dataOut.flagDataAsBlock:
1150 if dataOut.flagDataAsBlock:
1151
1151
1152 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1152 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1153 dataOut.flagNoData = False
1153 dataOut.flagNoData = False
1154
1154
1155 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1155 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1156
1156
1157 else:
1157 else:
1158
1158
1159 if self.__nTxs < 1:
1159 if self.__nTxs < 1:
1160
1160
1161 self.__appendProfile(dataOut, self.__nTxs)
1161 self.__appendProfile(dataOut, self.__nTxs)
1162 new_data = self.__getBuffer()
1162 new_data = self.__getBuffer()
1163
1163
1164 if new_data is not None:
1164 if new_data is not None:
1165 dataOut.data = new_data
1165 dataOut.data = new_data
1166 dataOut.flagNoData = False
1166 dataOut.flagNoData = False
1167
1167
1168 profileIndex = dataOut.profileIndex*nTxs
1168 profileIndex = dataOut.profileIndex*nTxs
1169
1169
1170 else:
1170 else:
1171 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1171 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1172
1172
1173 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1173 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1174
1174
1175 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1175 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1176
1176
1177 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1177 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1178
1178
1179 dataOut.profileIndex = profileIndex
1179 dataOut.profileIndex = profileIndex
1180
1180
1181 dataOut.ippSeconds /= self.__nTxs
1181 dataOut.ippSeconds /= self.__nTxs
1182
1182
1183 return dataOut
1183 return dataOut
1184
1184
1185 class SplitProfiles(Operation):
1185 class SplitProfiles(Operation):
1186
1186
1187 def __init__(self, **kwargs):
1187 def __init__(self, **kwargs):
1188
1188
1189 Operation.__init__(self, **kwargs)
1189 Operation.__init__(self, **kwargs)
1190
1190
1191 def run(self, dataOut, n):
1191 def run(self, dataOut, n):
1192
1192
1193 dataOut.flagNoData = True
1193 dataOut.flagNoData = True
1194 profileIndex = None
1194 profileIndex = None
1195
1195
1196 if dataOut.flagDataAsBlock:
1196 if dataOut.flagDataAsBlock:
1197
1197
1198 #nchannels, nprofiles, nsamples
1198 #nchannels, nprofiles, nsamples
1199 shape = dataOut.data.shape
1199 shape = dataOut.data.shape
1200
1200
1201 if shape[2] % n != 0:
1201 if shape[2] % n != 0:
1202 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1202 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1203
1203
1204 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1204 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1205
1205
1206 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1206 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1207 dataOut.flagNoData = False
1207 dataOut.flagNoData = False
1208
1208
1209 profileIndex = int(dataOut.nProfiles/n) - 1
1209 profileIndex = int(dataOut.nProfiles/n) - 1
1210
1210
1211 else:
1211 else:
1212
1212
1213 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1213 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1214
1214
1215 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1215 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1216
1216
1217 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1217 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1218
1218
1219 dataOut.nProfiles = int(dataOut.nProfiles*n)
1219 dataOut.nProfiles = int(dataOut.nProfiles*n)
1220
1220
1221 dataOut.profileIndex = profileIndex
1221 dataOut.profileIndex = profileIndex
1222
1222
1223 dataOut.ippSeconds /= n
1223 dataOut.ippSeconds /= n
1224
1224
1225 return dataOut
1225 return dataOut
1226
1226
1227 class CombineProfiles(Operation):
1227 class CombineProfiles(Operation):
1228 def __init__(self, **kwargs):
1228 def __init__(self, **kwargs):
1229
1229
1230 Operation.__init__(self, **kwargs)
1230 Operation.__init__(self, **kwargs)
1231
1231
1232 self.__remData = None
1232 self.__remData = None
1233 self.__profileIndex = 0
1233 self.__profileIndex = 0
1234
1234
1235 def run(self, dataOut, n):
1235 def run(self, dataOut, n):
1236
1236
1237 dataOut.flagNoData = True
1237 dataOut.flagNoData = True
1238 profileIndex = None
1238 profileIndex = None
1239
1239
1240 if dataOut.flagDataAsBlock:
1240 if dataOut.flagDataAsBlock:
1241
1241
1242 #nchannels, nprofiles, nsamples
1242 #nchannels, nprofiles, nsamples
1243 shape = dataOut.data.shape
1243 shape = dataOut.data.shape
1244 new_shape = shape[0], shape[1]/n, shape[2]*n
1244 new_shape = shape[0], shape[1]/n, shape[2]*n
1245
1245
1246 if shape[1] % n != 0:
1246 if shape[1] % n != 0:
1247 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1247 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1248
1248
1249 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1249 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1250 dataOut.flagNoData = False
1250 dataOut.flagNoData = False
1251
1251
1252 profileIndex = int(dataOut.nProfiles*n) - 1
1252 profileIndex = int(dataOut.nProfiles*n) - 1
1253
1253
1254 else:
1254 else:
1255
1255
1256 #nchannels, nsamples
1256 #nchannels, nsamples
1257 if self.__remData is None:
1257 if self.__remData is None:
1258 newData = dataOut.data
1258 newData = dataOut.data
1259 else:
1259 else:
1260 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1260 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1261
1261
1262 self.__profileIndex += 1
1262 self.__profileIndex += 1
1263
1263
1264 if self.__profileIndex < n:
1264 if self.__profileIndex < n:
1265 self.__remData = newData
1265 self.__remData = newData
1266 #continue
1266 #continue
1267 return
1267 return
1268
1268
1269 self.__profileIndex = 0
1269 self.__profileIndex = 0
1270 self.__remData = None
1270 self.__remData = None
1271
1271
1272 dataOut.data = newData
1272 dataOut.data = newData
1273 dataOut.flagNoData = False
1273 dataOut.flagNoData = False
1274
1274
1275 profileIndex = dataOut.profileIndex/n
1275 profileIndex = dataOut.profileIndex/n
1276
1276
1277
1277
1278 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1278 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1279
1279
1280 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1280 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1281
1281
1282 dataOut.nProfiles = int(dataOut.nProfiles/n)
1282 dataOut.nProfiles = int(dataOut.nProfiles/n)
1283
1283
1284 dataOut.profileIndex = profileIndex
1284 dataOut.profileIndex = profileIndex
1285
1285
1286 dataOut.ippSeconds *= n
1286 dataOut.ippSeconds *= n
1287
1287
1288 return dataOut
1288 return dataOut
1289
1289
1290 class PulsePair(Operation):
1290 class PulsePair(Operation):
1291 '''
1291 '''
1292 Function PulsePair(Signal Power, Velocity)
1292 Function PulsePair(Signal Power, Velocity)
1293 The real component of Lag[0] provides Intensity Information
1293 The real component of Lag[0] provides Intensity Information
1294 The imag component of Lag[1] Phase provides Velocity Information
1294 The imag component of Lag[1] Phase provides Velocity Information
1295
1295
1296 Configuration Parameters:
1296 Configuration Parameters:
1297 nPRF = Number of Several PRF
1297 nPRF = Number of Several PRF
1298 theta = Degree Azimuth angel Boundaries
1298 theta = Degree Azimuth angel Boundaries
1299
1299
1300 Input:
1300 Input:
1301 self.dataOut
1301 self.dataOut
1302 lag[N]
1302 lag[N]
1303 Affected:
1303 Affected:
1304 self.dataOut.spc
1304 self.dataOut.spc
1305 '''
1305 '''
1306 isConfig = False
1306 isConfig = False
1307 __profIndex = 0
1307 __profIndex = 0
1308 __initime = None
1308 __initime = None
1309 __lastdatatime = None
1309 __lastdatatime = None
1310 __buffer = None
1310 __buffer = None
1311 noise = None
1311 noise = None
1312 __dataReady = False
1312 __dataReady = False
1313 n = None
1313 n = None
1314 __nch = 0
1314 __nch = 0
1315 __nHeis = 0
1315 __nHeis = 0
1316 removeDC = False
1316 removeDC = False
1317 ipp = None
1317 ipp = None
1318 lambda_ = 0
1318 lambda_ = 0
1319
1319
1320 def __init__(self,**kwargs):
1320 def __init__(self,**kwargs):
1321 Operation.__init__(self,**kwargs)
1321 Operation.__init__(self,**kwargs)
1322
1322
1323 def setup(self, dataOut, n = None, removeDC=False):
1323 def setup(self, dataOut, n = None, removeDC=False):
1324 '''
1324 '''
1325 n= Numero de PRF's de entrada
1325 n= Numero de PRF's de entrada
1326 '''
1326 '''
1327 print("[INICIO]-setup del METODO PULSE PAIR")
1327 print("[INICIO]-setup del METODO PULSE PAIR")
1328 self.__initime = None
1328 self.__initime = None
1329 self.__lastdatatime = 0
1329 self.__lastdatatime = 0
1330 self.__dataReady = False
1330 self.__dataReady = False
1331 self.__buffer = 0
1331 self.__buffer = 0
1332 self.__profIndex = 0
1332 self.__profIndex = 0
1333 self.noise = None
1333 self.noise = None
1334 self.__nch = dataOut.nChannels
1334 self.__nch = dataOut.nChannels
1335 self.__nHeis = dataOut.nHeights
1335 self.__nHeis = dataOut.nHeights
1336 self.removeDC = removeDC
1336 self.removeDC = removeDC
1337 self.lambda_ = 3.0e8/(9345.0e6)
1337 self.lambda_ = 3.0e8/(9345.0e6)
1338 self.ippSec = dataOut.ippSeconds
1338 self.ippSec = dataOut.ippSeconds
1339 self.nCohInt = dataOut.nCohInt
1339 self.nCohInt = dataOut.nCohInt
1340 print("IPPseconds",dataOut.ippSeconds)
1340 print("IPPseconds",dataOut.ippSeconds)
1341
1341
1342 print("ELVALOR DE n es:", n)
1342 print("ELVALOR DE n es:", n)
1343 if n == None:
1343 if n == None:
1344 raise ValueError("n should be specified.")
1344 raise ValueError("n should be specified.")
1345
1345
1346 if n != None:
1346 if n != None:
1347 if n<2:
1347 if n<2:
1348 raise ValueError("n should be greater than 2")
1348 raise ValueError("n should be greater than 2")
1349
1349
1350 self.n = n
1350 self.n = n
1351 self.__nProf = n
1351 self.__nProf = n
1352
1352
1353 self.__buffer = numpy.zeros((dataOut.nChannels,
1353 self.__buffer = numpy.zeros((dataOut.nChannels,
1354 n,
1354 n,
1355 dataOut.nHeights),
1355 dataOut.nHeights),
1356 dtype='complex')
1356 dtype='complex')
1357
1357
1358 def putData(self,data):
1358 def putData(self,data):
1359 '''
1359 '''
1360 Add a profile to he __buffer and increase in one the __profiel Index
1360 Add a profile to he __buffer and increase in one the __profiel Index
1361 '''
1361 '''
1362 self.__buffer[:,self.__profIndex,:]= data
1362 self.__buffer[:,self.__profIndex,:]= data
1363 self.__profIndex += 1
1363 self.__profIndex += 1
1364 return
1364 return
1365
1365
1366 def pushData(self,dataOut):
1366 def pushData(self,dataOut):
1367 '''
1367 '''
1368 Return the PULSEPAIR and the profiles used in the operation
1368 Return the PULSEPAIR and the profiles used in the operation
1369 Affected : self.__profileIndex
1369 Affected : self.__profileIndex
1370 '''
1370 '''
1371 #----------------- Remove DC-----------------------------------
1371 #----------------- Remove DC-----------------------------------
1372 if self.removeDC==True:
1372 if self.removeDC==True:
1373 mean = numpy.mean(self.__buffer,1)
1373 mean = numpy.mean(self.__buffer,1)
1374 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1374 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1375 dc= numpy.tile(tmp,[1,self.__nProf,1])
1375 dc= numpy.tile(tmp,[1,self.__nProf,1])
1376 self.__buffer = self.__buffer - dc
1376 self.__buffer = self.__buffer - dc
1377 #------------------Calculo de Potencia ------------------------
1377 #------------------Calculo de Potencia ------------------------
1378 pair0 = self.__buffer*numpy.conj(self.__buffer)
1378 pair0 = self.__buffer*numpy.conj(self.__buffer)
1379 pair0 = pair0.real
1379 pair0 = pair0.real
1380 lag_0 = numpy.sum(pair0,1)
1380 lag_0 = numpy.sum(pair0,1)
1381 #------------------Calculo de Ruido x canal--------------------
1381 #------------------Calculo de Ruido x canal--------------------
1382 self.noise = numpy.zeros(self.__nch)
1382 self.noise = numpy.zeros(self.__nch)
1383 for i in range(self.__nch):
1383 for i in range(self.__nch):
1384 daux = numpy.sort(pair0[i,:,:],axis= None)
1384 daux = numpy.sort(pair0[i,:,:],axis= None)
1385 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1385 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1386
1386
1387 self.noise = self.noise.reshape(self.__nch,1)
1387 self.noise = self.noise.reshape(self.__nch,1)
1388 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1388 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1389 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1389 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1390 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1390 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1391 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1391 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1392 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1392 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1393 #-------------------- Power --------------------------------------------------
1393 #-------------------- Power --------------------------------------------------
1394 data_power = lag_0/(self.n*self.nCohInt)
1394 data_power = lag_0/(self.n*self.nCohInt)
1395 #------------------ Senal ---------------------------------------------------
1395 #------------------ Senal ---------------------------------------------------
1396 data_intensity = pair0 - noise_buffer
1396 data_intensity = pair0 - noise_buffer
1397 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1397 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1398 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1398 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1399 for i in range(self.__nch):
1399 for i in range(self.__nch):
1400 for j in range(self.__nHeis):
1400 for j in range(self.__nHeis):
1401 if data_intensity[i][j] < 0:
1401 if data_intensity[i][j] < 0:
1402 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1402 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1403
1403
1404 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1404 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1405 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1405 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1406 lag_1 = numpy.sum(pair1,1)
1406 lag_1 = numpy.sum(pair1,1)
1407 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1407 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1408 data_velocity = (self.lambda_/2.0)*data_freq
1408 data_velocity = (self.lambda_/2.0)*data_freq
1409
1409
1410 #---------------- Potencia promedio estimada de la Senal-----------
1410 #---------------- Potencia promedio estimada de la Senal-----------
1411 lag_0 = lag_0/self.n
1411 lag_0 = lag_0/self.n
1412 S = lag_0-self.noise
1412 S = lag_0-self.noise
1413
1413
1414 #---------------- Frecuencia Doppler promedio ---------------------
1414 #---------------- Frecuencia Doppler promedio ---------------------
1415 lag_1 = lag_1/(self.n-1)
1415 lag_1 = lag_1/(self.n-1)
1416 R1 = numpy.abs(lag_1)
1416 R1 = numpy.abs(lag_1)
1417
1417
1418 #---------------- Calculo del SNR----------------------------------
1418 #---------------- Calculo del SNR----------------------------------
1419 data_snrPP = S/self.noise
1419 data_snrPP = S/self.noise
1420 for i in range(self.__nch):
1420 for i in range(self.__nch):
1421 for j in range(self.__nHeis):
1421 for j in range(self.__nHeis):
1422 if data_snrPP[i][j] < 1.e-20:
1422 if data_snrPP[i][j] < 1.e-20:
1423 data_snrPP[i][j] = 1.e-20
1423 data_snrPP[i][j] = 1.e-20
1424
1424
1425 #----------------- Calculo del ancho espectral ----------------------
1425 #----------------- Calculo del ancho espectral ----------------------
1426 L = S/R1
1426 L = S/R1
1427 L = numpy.where(L<0,1,L)
1427 L = numpy.where(L<0,1,L)
1428 L = numpy.log(L)
1428 L = numpy.log(L)
1429 tmp = numpy.sqrt(numpy.absolute(L))
1429 tmp = numpy.sqrt(numpy.absolute(L))
1430 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1430 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1431 n = self.__profIndex
1431 n = self.__profIndex
1432
1432
1433 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1433 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1434 self.__profIndex = 0
1434 self.__profIndex = 0
1435 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
1435 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
1436
1436
1437
1437
1438 def pulsePairbyProfiles(self,dataOut):
1438 def pulsePairbyProfiles(self,dataOut):
1439
1439
1440 self.__dataReady = False
1440 self.__dataReady = False
1441 data_power = None
1441 data_power = None
1442 data_intensity = None
1442 data_intensity = None
1443 data_velocity = None
1443 data_velocity = None
1444 data_specwidth = None
1444 data_specwidth = None
1445 data_snrPP = None
1445 data_snrPP = None
1446 self.putData(data=dataOut.data)
1446 self.putData(data=dataOut.data)
1447 if self.__profIndex == self.n:
1447 if self.__profIndex == self.n:
1448 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
1448 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
1449 self.__dataReady = True
1449 self.__dataReady = True
1450
1450
1451 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
1451 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
1452
1452
1453
1453
1454 def pulsePairOp(self, dataOut, datatime= None):
1454 def pulsePairOp(self, dataOut, datatime= None):
1455
1455
1456 if self.__initime == None:
1456 if self.__initime == None:
1457 self.__initime = datatime
1457 self.__initime = datatime
1458 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
1458 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
1459 self.__lastdatatime = datatime
1459 self.__lastdatatime = datatime
1460
1460
1461 if data_power is None:
1461 if data_power is None:
1462 return None, None, None,None,None,None
1462 return None, None, None,None,None,None
1463
1463
1464 avgdatatime = self.__initime
1464 avgdatatime = self.__initime
1465 deltatime = datatime - self.__lastdatatime
1465 deltatime = datatime - self.__lastdatatime
1466 self.__initime = datatime
1466 self.__initime = datatime
1467
1467
1468 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1468 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1469
1469
1470 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1470 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1471
1471
1472 if not self.isConfig:
1472 if not self.isConfig:
1473 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1473 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1474 self.isConfig = True
1474 self.isConfig = True
1475 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1475 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1476 dataOut.flagNoData = True
1476 dataOut.flagNoData = True
1477
1477
1478 if self.__dataReady:
1478 if self.__dataReady:
1479 dataOut.nCohInt *= self.n
1479 dataOut.nCohInt *= self.n
1480 dataOut.dataPP_POW = data_intensity # S
1480 dataOut.dataPP_POW = data_intensity # S
1481 print("help",data_power)
1481 dataOut.dataPP_POWER = data_power # P
1482 dataOut.dataPP_POWER = data_power # P
1482 dataOut.dataPP_DOP = data_velocity
1483 dataOut.dataPP_DOP = data_velocity
1483 dataOut.dataPP_SNR = data_snrPP
1484 dataOut.dataPP_SNR = data_snrPP
1484 dataOut.dataPP_WIDTH = data_specwidth
1485 dataOut.dataPP_WIDTH = data_specwidth
1485 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1486 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1486 dataOut.nProfiles = int(dataOut.nProfiles/n)
1487 dataOut.nProfiles = int(dataOut.nProfiles/n)
1487 dataOut.utctime = avgdatatime
1488 dataOut.utctime = avgdatatime
1488 dataOut.flagNoData = False
1489 dataOut.flagNoData = False
1489 return dataOut
1490 return dataOut
1490
1491
1491
1492
1492
1493
1493 # import collections
1494 # import collections
1494 # from scipy.stats import mode
1495 # from scipy.stats import mode
1495 #
1496 #
1496 # class Synchronize(Operation):
1497 # class Synchronize(Operation):
1497 #
1498 #
1498 # isConfig = False
1499 # isConfig = False
1499 # __profIndex = 0
1500 # __profIndex = 0
1500 #
1501 #
1501 # def __init__(self, **kwargs):
1502 # def __init__(self, **kwargs):
1502 #
1503 #
1503 # Operation.__init__(self, **kwargs)
1504 # Operation.__init__(self, **kwargs)
1504 # # self.isConfig = False
1505 # # self.isConfig = False
1505 # self.__powBuffer = None
1506 # self.__powBuffer = None
1506 # self.__startIndex = 0
1507 # self.__startIndex = 0
1507 # self.__pulseFound = False
1508 # self.__pulseFound = False
1508 #
1509 #
1509 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1510 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1510 #
1511 #
1511 # #Read data
1512 # #Read data
1512 #
1513 #
1513 # powerdB = dataOut.getPower(channel = channel)
1514 # powerdB = dataOut.getPower(channel = channel)
1514 # noisedB = dataOut.getNoise(channel = channel)[0]
1515 # noisedB = dataOut.getNoise(channel = channel)[0]
1515 #
1516 #
1516 # self.__powBuffer.extend(powerdB.flatten())
1517 # self.__powBuffer.extend(powerdB.flatten())
1517 #
1518 #
1518 # dataArray = numpy.array(self.__powBuffer)
1519 # dataArray = numpy.array(self.__powBuffer)
1519 #
1520 #
1520 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1521 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1521 #
1522 #
1522 # maxValue = numpy.nanmax(filteredPower)
1523 # maxValue = numpy.nanmax(filteredPower)
1523 #
1524 #
1524 # if maxValue < noisedB + 10:
1525 # if maxValue < noisedB + 10:
1525 # #No se encuentra ningun pulso de transmision
1526 # #No se encuentra ningun pulso de transmision
1526 # return None
1527 # return None
1527 #
1528 #
1528 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1529 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1529 #
1530 #
1530 # if len(maxValuesIndex) < 2:
1531 # if len(maxValuesIndex) < 2:
1531 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1532 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1532 # return None
1533 # return None
1533 #
1534 #
1534 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1535 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1535 #
1536 #
1536 # #Seleccionar solo valores con un espaciamiento de nSamples
1537 # #Seleccionar solo valores con un espaciamiento de nSamples
1537 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1538 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1538 #
1539 #
1539 # if len(pulseIndex) < 2:
1540 # if len(pulseIndex) < 2:
1540 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1541 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1541 # return None
1542 # return None
1542 #
1543 #
1543 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1544 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1544 #
1545 #
1545 # #remover senales que se distancien menos de 10 unidades o muestras
1546 # #remover senales que se distancien menos de 10 unidades o muestras
1546 # #(No deberian existir IPP menor a 10 unidades)
1547 # #(No deberian existir IPP menor a 10 unidades)
1547 #
1548 #
1548 # realIndex = numpy.where(spacing > 10 )[0]
1549 # realIndex = numpy.where(spacing > 10 )[0]
1549 #
1550 #
1550 # if len(realIndex) < 2:
1551 # if len(realIndex) < 2:
1551 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1552 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1552 # return None
1553 # return None
1553 #
1554 #
1554 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1555 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1555 # realPulseIndex = pulseIndex[realIndex]
1556 # realPulseIndex = pulseIndex[realIndex]
1556 #
1557 #
1557 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1558 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1558 #
1559 #
1559 # print "IPP = %d samples" %period
1560 # print "IPP = %d samples" %period
1560 #
1561 #
1561 # self.__newNSamples = dataOut.nHeights #int(period)
1562 # self.__newNSamples = dataOut.nHeights #int(period)
1562 # self.__startIndex = int(realPulseIndex[0])
1563 # self.__startIndex = int(realPulseIndex[0])
1563 #
1564 #
1564 # return 1
1565 # return 1
1565 #
1566 #
1566 #
1567 #
1567 # def setup(self, nSamples, nChannels, buffer_size = 4):
1568 # def setup(self, nSamples, nChannels, buffer_size = 4):
1568 #
1569 #
1569 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1570 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1570 # maxlen = buffer_size*nSamples)
1571 # maxlen = buffer_size*nSamples)
1571 #
1572 #
1572 # bufferList = []
1573 # bufferList = []
1573 #
1574 #
1574 # for i in range(nChannels):
1575 # for i in range(nChannels):
1575 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1576 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1576 # maxlen = buffer_size*nSamples)
1577 # maxlen = buffer_size*nSamples)
1577 #
1578 #
1578 # bufferList.append(bufferByChannel)
1579 # bufferList.append(bufferByChannel)
1579 #
1580 #
1580 # self.__nSamples = nSamples
1581 # self.__nSamples = nSamples
1581 # self.__nChannels = nChannels
1582 # self.__nChannels = nChannels
1582 # self.__bufferList = bufferList
1583 # self.__bufferList = bufferList
1583 #
1584 #
1584 # def run(self, dataOut, channel = 0):
1585 # def run(self, dataOut, channel = 0):
1585 #
1586 #
1586 # if not self.isConfig:
1587 # if not self.isConfig:
1587 # nSamples = dataOut.nHeights
1588 # nSamples = dataOut.nHeights
1588 # nChannels = dataOut.nChannels
1589 # nChannels = dataOut.nChannels
1589 # self.setup(nSamples, nChannels)
1590 # self.setup(nSamples, nChannels)
1590 # self.isConfig = True
1591 # self.isConfig = True
1591 #
1592 #
1592 # #Append new data to internal buffer
1593 # #Append new data to internal buffer
1593 # for thisChannel in range(self.__nChannels):
1594 # for thisChannel in range(self.__nChannels):
1594 # bufferByChannel = self.__bufferList[thisChannel]
1595 # bufferByChannel = self.__bufferList[thisChannel]
1595 # bufferByChannel.extend(dataOut.data[thisChannel])
1596 # bufferByChannel.extend(dataOut.data[thisChannel])
1596 #
1597 #
1597 # if self.__pulseFound:
1598 # if self.__pulseFound:
1598 # self.__startIndex -= self.__nSamples
1599 # self.__startIndex -= self.__nSamples
1599 #
1600 #
1600 # #Finding Tx Pulse
1601 # #Finding Tx Pulse
1601 # if not self.__pulseFound:
1602 # if not self.__pulseFound:
1602 # indexFound = self.__findTxPulse(dataOut, channel)
1603 # indexFound = self.__findTxPulse(dataOut, channel)
1603 #
1604 #
1604 # if indexFound == None:
1605 # if indexFound == None:
1605 # dataOut.flagNoData = True
1606 # dataOut.flagNoData = True
1606 # return
1607 # return
1607 #
1608 #
1608 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1609 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1609 # self.__pulseFound = True
1610 # self.__pulseFound = True
1610 # self.__startIndex = indexFound
1611 # self.__startIndex = indexFound
1611 #
1612 #
1612 # #If pulse was found ...
1613 # #If pulse was found ...
1613 # for thisChannel in range(self.__nChannels):
1614 # for thisChannel in range(self.__nChannels):
1614 # bufferByChannel = self.__bufferList[thisChannel]
1615 # bufferByChannel = self.__bufferList[thisChannel]
1615 # #print self.__startIndex
1616 # #print self.__startIndex
1616 # x = numpy.array(bufferByChannel)
1617 # x = numpy.array(bufferByChannel)
1617 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1618 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1618 #
1619 #
1619 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1620 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1620 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1621 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1621 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1622 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1622 #
1623 #
1623 # dataOut.data = self.__arrayBuffer
1624 # dataOut.data = self.__arrayBuffer
1624 #
1625 #
1625 # self.__startIndex += self.__newNSamples
1626 # self.__startIndex += self.__newNSamples
1626 #
1627 #
1627 # return
1628 # return
@@ -1,157 +1,159
1 #!python
1 #!python
2 '''
2 '''
3 '''
3 '''
4
4
5 import os, sys
5 import os, sys
6 import datetime
6 import datetime
7 import time
7 import time
8
8
9 #path = os.path.dirname(os.getcwd())
9 #path = os.path.dirname(os.getcwd())
10 #path = os.path.dirname(path)
10 #path = os.path.dirname(path)
11 #sys.path.insert(0, path)
11 #sys.path.insert(0, path)
12
12
13 from schainpy.controller import Project
13 from schainpy.controller import Project
14
14
15 desc = "USRP_test"
15 desc = "USRP_test"
16 filename = "USRP_processing.xml"
16 filename = "USRP_processing.xml"
17 controllerObj = Project()
17 controllerObj = Project()
18 controllerObj.setup(id = '191', name='Test_USRP', description=desc)
18 controllerObj.setup(id = '191', name='Test_USRP', description=desc)
19
19
20 ############## USED TO PLOT IQ VOLTAGE, POWER AND SPECTRA #############
20 ############## USED TO PLOT IQ VOLTAGE, POWER AND SPECTRA #############
21
21
22 #######################################################################
22 #######################################################################
23 ######PATH DE LECTURA, ESCRITURA, GRAFICOS Y ENVIO WEB#################
23 ######PATH DE LECTURA, ESCRITURA, GRAFICOS Y ENVIO WEB#################
24 #######################################################################
24 #######################################################################
25 #path = '/media/data/data/vientos/57.2063km/echoes/NCO_Woodman'
25 #path = '/media/data/data/vientos/57.2063km/echoes/NCO_Woodman'
26 #path = '/DATA_RM/TEST_INTEGRACION'
26 #path = '/DATA_RM/TEST_INTEGRACION'
27 #path = '/DATA_RM/TEST_ONLINE'
27 #path = '/DATA_RM/TEST_ONLINE'
28 #path_pp = '/DATA_RM/TEST_HDF5'
28 #path_pp = '/DATA_RM/TEST_HDF5'
29
29
30 #figpath = '/home/soporte/Pictures/TEST_INTEGRACION_IMG'
30 #figpath = '/home/soporte/Pictures/TEST_INTEGRACION_IMG'
31 ###path = '/DATA_RM/TEST_INTEGRACION/ADQ_OFFLINE/'
31 ###path = '/DATA_RM/TEST_INTEGRACION/ADQ_OFFLINE/'
32 ###path_pp = '/DATA_RM/TEST_HDF5_SPEC'
32 ###path_pp = '/DATA_RM/TEST_HDF5_SPEC'
33
33
34 #path = '/DATA_RM/USRP_22'
34 #path = '/DATA_RM/USRP_22'
35 path = '/DATA_RM/23/6v'
35 ###path = '/DATA_RM/23/6v'
36 path = '/DATA_RM/TEST_19OCTUBRE/10MHZ'
36 #path_pp = '/DATA_RM/TEST_HDF5'
37 #path_pp = '/DATA_RM/TEST_HDF5'
38 path_pp = '/DATA_RM/TEST_HDF5_19OCT'
37 # UTIMO TEST 22 DE SEPTIEMBRE
39 # UTIMO TEST 22 DE SEPTIEMBRE
38 #path_pp = '/DATA_RM/TEST_HDF5_SPEC_22'
40 #path_pp = '/DATA_RM/TEST_HDF5_SPEC_22'
39 #path_pp = '/DATA_RM/TEST_HDF5_SPEC_3v'
41 #path_pp = '/DATA_RM/TEST_HDF5_SPEC_3v'
40 path_pp = '/DATA_RM/TEST_HDF5_SPEC_23/6v'
42 ###path_pp = '/DATA_RM/TEST_HDF5_SPEC_23/6v'
41
43
42
44
43 #remotefolder = "/home/wmaster/graficos"
45 #remotefolder = "/home/wmaster/graficos"
44 #######################################################################
46 #######################################################################
45 ################# RANGO DE PLOTEO######################################
47 ################# RANGO DE PLOTEO######################################
46 #######################################################################
48 #######################################################################
47 dBmin = '-5'
49 dBmin = '-5'
48 dBmax = '20'
50 dBmax = '20'
49 xmin = '0'
51 xmin = '0'
50 xmax ='24'
52 xmax ='24'
51 ymin = '0'
53 ymin = '0'
52 ymax = '600'
54 ymax = '600'
53 #######################################################################
55 #######################################################################
54 ########################FECHA##########################################
56 ########################FECHA##########################################
55 #######################################################################
57 #######################################################################
56 str = datetime.date.today()
58 str = datetime.date.today()
57 today = str.strftime("%Y/%m/%d")
59 today = str.strftime("%Y/%m/%d")
58 str2 = str - datetime.timedelta(days=1)
60 str2 = str - datetime.timedelta(days=1)
59 yesterday = str2.strftime("%Y/%m/%d")
61 yesterday = str2.strftime("%Y/%m/%d")
60 #######################################################################
62 #######################################################################
61 ######################## UNIDAD DE LECTURA#############################
63 ######################## UNIDAD DE LECTURA#############################
62 #######################################################################
64 #######################################################################
63 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader',
65 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader',
64 path=path,
66 path=path,
65 startDate="2021/01/01",#today,
67 startDate="2021/01/01",#today,
66 endDate="2021/12/30",#today,
68 endDate="2021/12/30",#today,
67 startTime='00:00:00',
69 startTime='00:00:00',
68 endTime='23:59:59',
70 endTime='23:59:59',
69 delay=0,
71 delay=0,
70 #set=0,
72 #set=0,
71 online=0,
73 online=0,
72 walk=1,
74 walk=1,
73 ippKm = 60)
75 ippKm = 60)
74
76
75 opObj11 = readUnitConfObj.addOperation(name='printInfo')
77 opObj11 = readUnitConfObj.addOperation(name='printInfo')
76 #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
78 #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
77 #######################################################################
79 #######################################################################
78 ################ OPERACIONES DOMINIO DEL TIEMPO########################
80 ################ OPERACIONES DOMINIO DEL TIEMPO########################
79 #######################################################################
81 #######################################################################
80
82
81
83
82 V=6
84 V=10
83 IPP=400*1e-6
85 IPP=400*1e-6
84 n= int(1/(V*IPP))
86 n= int(1/(V*IPP))
85 print("n numero de Perfiles a procesar con nFFTPoints ", n)
87 print("n numero de Perfiles a procesar con nFFTPoints ", n)
86
88
87 procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
89 procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
88
90
89 procUnitConfObjB = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjA.getId())
91 procUnitConfObjB = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjA.getId())
90 procUnitConfObjB.addParameter(name='nFFTPoints', value=n, format='int')
92 procUnitConfObjB.addParameter(name='nFFTPoints', value=n, format='int')
91 procUnitConfObjB.addParameter(name='nProfiles' , value=n, format='int')
93 procUnitConfObjB.addParameter(name='nProfiles' , value=n, format='int')
92
94
93
95
94
96
95 #
97 #
96 # codigo64='1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0,'+\
98 # codigo64='1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0,'+\
97 # '1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1,0,0,0,1,0,0,1,0,0,0,0,1,1,1,0,1,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1'
99 # '1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1,0,0,0,1,0,0,1,0,0,0,0,1,1,1,0,1,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1'
98
100
99 #opObj11 = procUnitConfObjA.addOperation(name='setRadarFrequency')
101 #opObj11 = procUnitConfObjA.addOperation(name='setRadarFrequency')
100 #opObj11.addParameter(name='frequency', value='70312500')
102 #opObj11.addParameter(name='frequency', value='70312500')
101 #opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other')
103 #opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other')
102 #opObj11.addParameter(name='n', value='625', format='int')#10
104 #opObj11.addParameter(name='n', value='625', format='int')#10
103 #opObj11.addParameter(name='removeDC', value=1, format='int')
105 #opObj11.addParameter(name='removeDC', value=1, format='int')
104
106
105 # Ploteo TEST
107 # Ploteo TEST
106 '''
108 '''
107 opObj11 = procUnitConfObjA.addOperation(name='PulsepairPowerPlot', optype='other')
109 opObj11 = procUnitConfObjA.addOperation(name='PulsepairPowerPlot', optype='other')
108 opObj11 = procUnitConfObjA.addOperation(name='PulsepairSignalPlot', optype='other')
110 opObj11 = procUnitConfObjA.addOperation(name='PulsepairSignalPlot', optype='other')
109 opObj11 = procUnitConfObjA.addOperation(name='PulsepairVelocityPlot', optype='other')
111 opObj11 = procUnitConfObjA.addOperation(name='PulsepairVelocityPlot', optype='other')
110 #opObj11.addParameter(name='xmax', value=8)
112 #opObj11.addParameter(name='xmax', value=8)
111 opObj11 = procUnitConfObjA.addOperation(name='PulsepairSpecwidthPlot', optype='other')
113 opObj11 = procUnitConfObjA.addOperation(name='PulsepairSpecwidthPlot', optype='other')
112 '''
114 '''
113 # OJO SCOPE
115 # OJO SCOPE
114 #opObj10 = procUnitConfObjA.addOperation(name='ScopePlot', optype='external')
116 #opObj10 = procUnitConfObjA.addOperation(name='ScopePlot', optype='external')
115 #opObj10.addParameter(name='buffer_sizeid', value='10', format='int')
117 #opObj10.addParameter(name='buffer_sizeid', value='10', format='int')
116 ##opObj10.addParameter(name='xmin', value='0', format='int')
118 ##opObj10.addParameter(name='xmin', value='0', format='int')
117 ##opObj10.addParameter(name='xmax', value='50', format='int')
119 ##opObj10.addParameter(name='xmax', value='50', format='int')
118 #opObj10.addParameter(name='type', value='iq')
120 #opObj10.addParameter(name='type', value='iq')
119 ##opObj10.addParameter(name='ymin', value='-5000', format='int')
121 ##opObj10.addParameter(name='ymin', value='-5000', format='int')
120 ##opObj10.addParameter(name='ymax', value='8500', format='int')
122 ##opObj10.addParameter(name='ymax', value='8500', format='int')
121 #opObj11.addParameter(name='save', value=figpath, format='str')
123 #opObj11.addParameter(name='save', value=figpath, format='str')
122 #opObj11.addParameter(name='save_period', value=10, format='int')
124 #opObj11.addParameter(name='save_period', value=10, format='int')
123
125
124 #opObj10 = procUnitConfObjA.addOperation(name='setH0')
126 #opObj10 = procUnitConfObjA.addOperation(name='setH0')
125 #opObj10.addParameter(name='h0', value='-5000', format='float')
127 #opObj10.addParameter(name='h0', value='-5000', format='float')
126
128
127 #opObj11 = procUnitConfObjA.addOperation(name='filterByHeights')
129 #opObj11 = procUnitConfObjA.addOperation(name='filterByHeights')
128 #opObj11.addParameter(name='window', value='1', format='int')
130 #opObj11.addParameter(name='window', value='1', format='int')
129
131
130 #codigo='1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1,-1,-1'
132 #codigo='1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1,-1,-1'
131 #opObj11 = procUnitConfObjSousy.addOperation(name='Decoder', optype='other')
133 #opObj11 = procUnitConfObjSousy.addOperation(name='Decoder', optype='other')
132 #opObj11.addParameter(name='code', value=codigo, formatyesterday='floatlist')
134 #opObj11.addParameter(name='code', value=codigo, formatyesterday='floatlist')
133 #opObj11.addParameter(name='nCode', value='1', format='int')
135 #opObj11.addParameter(name='nCode', value='1', format='int')
134 #opObj11.addParameter(name='nBaud', value='28', format='int')
136 #opObj11.addParameter(name='nBaud', value='28', format='int')
135
137
136 #opObj11 = procUnitConfObjA.addOperation(name='CohInt', optype='other')
138 #opObj11 = procUnitConfObjA.addOperation(name='CohInt', optype='other')
137 #opObj11.addParameter(name='n', value='100', format='int')
139 #opObj11.addParameter(name='n', value='100', format='int')
138
140
139 #######################################################################
141 #######################################################################
140 ########## OPERACIONES ParametersProc########################
142 ########## OPERACIONES ParametersProc########################
141 #######################################################################
143 #######################################################################
142
144
143 procUnitConfObjC= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjB.getId())
145 procUnitConfObjC= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjB.getId())
144
146
145 procUnitConfObjC.addOperation(name='SpectralMoments')
147 procUnitConfObjC.addOperation(name='SpectralMoments')
146
148
147
149
148 opObj10 = procUnitConfObjC.addOperation(name='HDFWriter')
150 opObj10 = procUnitConfObjC.addOperation(name='HDFWriter')
149 opObj10.addParameter(name='path',value=path_pp)
151 opObj10.addParameter(name='path',value=path_pp)
150 #opObj10.addParameter(name='mode',value=0)
152 #opObj10.addParameter(name='mode',value=0)
151 opObj10.addParameter(name='blocksPerFile',value='100',format='int')
153 opObj10.addParameter(name='blocksPerFile',value='100',format='int')
152 #opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
154 #opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
153 opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
155 opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
154
156
155 opObj10.addParameter(name='dataList',value='data_pow,data_dop,utctime',format='list')#,format='list'
157 opObj10.addParameter(name='dataList',value='data_pow,data_dop,utctime',format='list')#,format='list'
156
158
157 controllerObj.start()
159 controllerObj.start()
@@ -1,213 +1,216
1 # Ing. AVP
1 # Ing. AVP
2 # 06/10/2021
2 # 06/10/2021
3 # ARCHIVO DE LECTURA
3 # ARCHIVO DE LECTURA
4 import os, sys
4 import os, sys
5 import datetime
5 import datetime
6 import time
6 import time
7 from schainpy.controller import Project
7 from schainpy.controller import Project
8 #### NOTA###########################################
8 #### NOTA###########################################
9 # INPUT :
9 # INPUT :
10 # VELOCIDAD PARAMETRO : V = 2Β°/seg
10 # VELOCIDAD PARAMETRO : V = 2Β°/seg
11 # MODO PULSE PAIR O MOMENTOS: 0 : Pulse Pair ,1 : Momentos
11 # MODO PULSE PAIR O MOMENTOS: 0 : Pulse Pair ,1 : Momentos
12 ######################################################
12 ######################################################
13 ##### PROCESAMIENTO ##################################
13 ##### PROCESAMIENTO ##################################
14 ##### OJO TENER EN CUENTA EL n= para el Pulse Pair ##
14 ##### OJO TENER EN CUENTA EL n= para el Pulse Pair ##
15 ##### O EL n= nFFTPoints ###
15 ##### O EL n= nFFTPoints ###
16 ######################################################
16 ######################################################
17 ######## BUSCAMOS EL numero de IPP equivalente 1Β°#####
17 ######## BUSCAMOS EL numero de IPP equivalente 1Β°#####
18 ######## Sea V la velocidad del Pedestal en Β°/seg#####
18 ######## Sea V la velocidad del Pedestal en Β°/seg#####
19 ######## 1Β° sera Recorrido en un tiempo de 1/V ######
19 ######## 1Β° sera Recorrido en un tiempo de 1/V ######
20 ######## IPP del Radar 400 useg --> 60 Km ############
20 ######## IPP del Radar 400 useg --> 60 Km ############
21 ######## n = 1/(V(Β°/seg)*IPP(Km)) , NUMERO DE IPP ##
21 ######## n = 1/(V(Β°/seg)*IPP(Km)) , NUMERO DE IPP ##
22 ######## n = 1/(V*IPP) #############################
22 ######## n = 1/(V*IPP) #############################
23 ######## VELOCIDAD DEL PEDESTAL ######################
23 ######## VELOCIDAD DEL PEDESTAL ######################
24 print("SETUP- RADAR METEOROLOGICO")
24 print("SETUP- RADAR METEOROLOGICO")
25 V = 10
25 V = 10
26 mode = 1
26 mode = 1
27 #path = '/DATA_RM/23/6v'
27 #path = '/DATA_RM/23/6v'
28 path = '/DATA_RM/TEST_INTEGRACION_2M'
28 ####path = '/DATA_RM/TEST_INTEGRACION_2M'
29 path_ped='/DATA_RM/TEST_PEDESTAL/P20211012-082745'
29 #path = '/DATA_RM/TEST_19OCTUBRE/10MHZ'
30 path = '/DATA_RM/WR_20_OCT'
31 #### path_ped='/DATA_RM/TEST_PEDESTAL/P20211012-082745'
32 #### path_ped='/DATA_RM/TEST_PEDESTAL/P20211019-192244'
30 figpath_pp = "/home/soporte/Pictures/TEST_PP"
33 figpath_pp = "/home/soporte/Pictures/TEST_PP"
31 figpath_mom = "/home/soporte/Pictures/TEST_MOM"
34 figpath_spec = "/home/soporte/Pictures/TEST_MOM"
32 plot = 0
35 plot = 1
33 integration = 1
36 integration = 0
34 save = 0
37 save = 0
35 if save == 1:
38 if save == 1:
36 if mode==0:
39 if mode==0:
37 path_save = '/DATA_RM/TEST_HDF5_PP_23/6v'
40 path_save = '/DATA_RM/TEST_HDF5_PP_23/6v'
38 path_save = '/DATA_RM/TEST_HDF5_PP'
41 path_save = '/DATA_RM/TEST_HDF5_PP'
39 path_save = '/DATA_RM/TEST_HDF5_PP_100'
42 path_save = '/DATA_RM/TEST_HDF5_PP_100'
40 else:
43 else:
41 path_save = '/DATA_RM/TEST_HDF5_SPEC_23_V2/6v'
44 path_save = '/DATA_RM/TEST_HDF5_SPEC_23_V2/6v'
42
45
43 print("* PATH data ADQ :", path)
46 print("* PATH data ADQ :", path)
44 print("* Velocidad Pedestal :",V,"Β°/seg")
47 print("* Velocidad Pedestal :",V,"Β°/seg")
45 ############################ NRO Perfiles PROCESAMIENTO ###################
48 ############################ NRO Perfiles PROCESAMIENTO ###################
46 V=V
49 V=V
47 IPP=400*1e-6
50 IPP=400*1e-6
48 n= int(1/(V*IPP))
51 n= int(1/(V*IPP))
49 print("* n - NRO Perfiles Proc:", n )
52 print("* n - NRO Perfiles Proc:", n )
50 ################################## MODE ###################################
53 ################################## MODE ###################################
51 print("* Modo de Operacion :",mode)
54 print("* Modo de Operacion :",mode)
52 if mode ==0:
55 if mode ==0:
53 print("* Met. Seleccionado : Pulse Pair")
56 print("* Met. Seleccionado : Pulse Pair")
54 else:
57 else:
55 print("* Met. Momentos : Momentos")
58 print("* Met. Momentos : Momentos")
56
59
57 ################################## MODE ###################################
60 ################################## MODE ###################################
58 print("* Grabado de datos :",save)
61 print("* Grabado de datos :",save)
59 if save ==1:
62 if save ==1:
60 if mode==0:
63 if mode==0:
61 ope= "Pulse Pair"
64 ope= "Pulse Pair"
62 else:
65 else:
63 ope= "Momentos"
66 ope= "Momentos"
64 print("* Path-Save Data -", ope , path_save)
67 print("* Path-Save Data -", ope , path_save)
65
68
66 print("* Integracion de datos :",integration)
69 print("* Integracion de datos :",integration)
67
70
68 time.sleep(15)
71 time.sleep(15)
69 #remotefolder = "/home/wmaster/graficos"
72 #remotefolder = "/home/wmaster/graficos"
70 #######################################################################
73 #######################################################################
71 ################# RANGO DE PLOTEO######################################
74 ################# RANGO DE PLOTEO######################################
72 dBmin = '1'
75 dBmin = '1'
73 dBmax = '85'
76 dBmax = '65'
74 xmin = '15'
77 xmin = '13.2'
75 xmax = '15.25'
78 xmax = '13.5'
76 ymin = '0'
79 ymin = '0'
77 ymax = '600'
80 ymax = '60'
78 #######################################################################
81 #######################################################################
79 ########################FECHA##########################################
82 ########################FECHA##########################################
80 str = datetime.date.today()
83 str = datetime.date.today()
81 today = str.strftime("%Y/%m/%d")
84 today = str.strftime("%Y/%m/%d")
82 str2 = str - datetime.timedelta(days=1)
85 str2 = str - datetime.timedelta(days=1)
83 yesterday = str2.strftime("%Y/%m/%d")
86 yesterday = str2.strftime("%Y/%m/%d")
84 #######################################################################
87 #######################################################################
85 ########################SIGNAL CHAIN ##################################
88 ########################SIGNAL CHAIN ##################################
86 #######################################################################
89 #######################################################################
87 desc = "USRP_test"
90 desc = "USRP_test"
88 filename = "USRP_processing.xml"
91 filename = "USRP_processing.xml"
89 controllerObj = Project()
92 controllerObj = Project()
90 controllerObj.setup(id = '191', name='Test_USRP', description=desc)
93 controllerObj.setup(id = '191', name='Test_USRP', description=desc)
91 #######################################################################
94 #######################################################################
92 ######################## UNIDAD DE LECTURA#############################
95 ######################## UNIDAD DE LECTURA#############################
93 #######################################################################
96 #######################################################################
94 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader',
97 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader',
95 path=path,
98 path=path,
96 startDate="2021/01/01",#today,
99 startDate="2021/01/01",#today,
97 endDate="2021/12/30",#today,
100 endDate="2021/12/30",#today,
98 startTime='00:00:00',
101 startTime='00:00:00',
99 endTime='23:59:59',
102 endTime='23:59:59',
100 delay=0,
103 delay=0,
101 #set=0,
104 #set=0,
102 online=0,
105 online=0,
103 walk=1,
106 walk=1,
104 ippKm = 60)
107 ippKm = 60)
105
108
106 opObj11 = readUnitConfObj.addOperation(name='printInfo')
109 opObj11 = readUnitConfObj.addOperation(name='printInfo')
107
110
108 procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
111 procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
109
112
110 if mode ==0:
113 if mode ==0:
111 ####################### METODO PULSE PAIR ######################################################################
114 ####################### METODO PULSE PAIR ######################################################################
112 opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other')
115 opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other')
113 opObj11.addParameter(name='n', value=int(n), format='int')#10 VOY A USAR 250 DADO QUE LA VELOCIDAD ES 10 GRADOS
116 opObj11.addParameter(name='n', value=int(n), format='int')#10 VOY A USAR 250 DADO QUE LA VELOCIDAD ES 10 GRADOS
114 #opObj11.addParameter(name='removeDC', value=1, format='int')
117 #opObj11.addParameter(name='removeDC', value=1, format='int')
115 ####################### METODO Parametros ######################################################################
118 ####################### METODO Parametros ######################################################################
116 procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId())
119 procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId())
117 if plot==1:
120 if plot==1:
118 opObj11 = procUnitConfObjB.addOperation(name='GenericRTIPlot',optype='external')
121 opObj11 = procUnitConfObjB.addOperation(name='GenericRTIPlot',optype='external')
119 opObj11.addParameter(name='attr_data', value='dataPP_POW')
122 opObj11.addParameter(name='attr_data', value='dataPP_POWER')
120 opObj11.addParameter(name='colormap', value='jet')
123 opObj11.addParameter(name='colormap', value='jet')
121 opObj11.addParameter(name='xmin', value=xmin)
124 opObj11.addParameter(name='xmin', value=xmin)
122 opObj11.addParameter(name='xmax', value=xmax)
125 opObj11.addParameter(name='xmax', value=xmax)
123 opObj11.addParameter(name='zmin', value=dBmin)
126 opObj11.addParameter(name='zmin', value=dBmin)
124 opObj11.addParameter(name='zmax', value=dBmax)
127 opObj11.addParameter(name='zmax', value=dBmax)
125 opObj11.addParameter(name='save', value=figpath_pp)
128 opObj11.addParameter(name='save', value=figpath_pp)
126 opObj11.addParameter(name='showprofile', value=0)
129 opObj11.addParameter(name='showprofile', value=0)
127 opObj11.addParameter(name='save_period', value=50)
130 opObj11.addParameter(name='save_period', value=10)
128
131
129 ####################### METODO ESCRITURA #######################################################################
132 ####################### METODO ESCRITURA #######################################################################
130 if save==1:
133 if save==1:
131 opObj10 = procUnitConfObjB.addOperation(name='HDFWriter')
134 opObj10 = procUnitConfObjB.addOperation(name='HDFWriter')
132 opObj10.addParameter(name='path',value=path_save)
135 opObj10.addParameter(name='path',value=path_save)
133 #opObj10.addParameter(name='mode',value=0)
136 #opObj10.addParameter(name='mode',value=0)
134 opObj10.addParameter(name='blocksPerFile',value='100',format='int')
137 opObj10.addParameter(name='blocksPerFile',value='100',format='int')
135 opObj10.addParameter(name='metadataList',value='utctimeInit,timeZone,paramInterval,profileIndex,channelList,heightList,flagDataAsBlock',format='list')
138 opObj10.addParameter(name='metadataList',value='utctimeInit,timeZone,paramInterval,profileIndex,channelList,heightList,flagDataAsBlock',format='list')
136 opObj10.addParameter(name='dataList',value='dataPP_POW,dataPP_DOP,utctime',format='list')#,format='list'
139 opObj10.addParameter(name='dataList',value='dataPP_POWER,dataPP_DOP,utctime',format='list')#,format='list'
137 if integration==1:
140 if integration==1:
138 V=10
141 V=10
139 blocksPerfile=360
142 blocksPerfile=360
140 print("* Velocidad del Pedestal:",V)
143 print("* Velocidad del Pedestal:",V)
141 tmp_blocksPerfile = 100
144 tmp_blocksPerfile = 100
142 f_a_p= int(tmp_blocksPerfile/V)
145 f_a_p= int(tmp_blocksPerfile/V)
143
146
144 opObj11 = procUnitConfObjB.addOperation(name='PedestalInformation')
147 opObj11 = procUnitConfObjB.addOperation(name='PedestalInformation')
145 opObj11.addParameter(name='path_ped', value=path_ped)
148 opObj11.addParameter(name='path_ped', value=path_ped)
146 #opObj11.addParameter(name='path_adq', value=path_adq)
149 #opObj11.addParameter(name='path_adq', value=path_adq)
147 opObj11.addParameter(name='t_Interval_p', value='0.01', format='float')
150 opObj11.addParameter(name='t_Interval_p', value='0.01', format='float')
148 opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int')
151 opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int')
149 opObj11.addParameter(name='n_Muestras_p', value='100', format='float')
152 opObj11.addParameter(name='n_Muestras_p', value='100', format='float')
150 opObj11.addParameter(name='f_a_p', value=f_a_p, format='int')
153 opObj11.addParameter(name='f_a_p', value=f_a_p, format='int')
151 opObj11.addParameter(name='online', value='0', format='int')
154 opObj11.addParameter(name='online', value='0', format='int')
152
155
153 opObj11 = procUnitConfObjB.addOperation(name='Block360')
156 opObj11 = procUnitConfObjB.addOperation(name='Block360')
154 opObj11.addParameter(name='n', value='10', format='int')
157 opObj11.addParameter(name='n', value='10', format='int')
155 opObj11.addParameter(name='mode', value=mode, format='int')
158 opObj11.addParameter(name='mode', value=mode, format='int')
156
159
157 # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180
160 # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180
158
161
159 opObj11= procUnitConfObjB.addOperation(name='WeatherPlot',optype='other')
162 opObj11= procUnitConfObjB.addOperation(name='WeatherPlot',optype='other')
160
163
161
164
162 else:
165 else:
163 ####################### METODO SPECTROS ######################################################################
166 ####################### METODO SPECTROS ######################################################################
164 procUnitConfObjB = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjA.getId())
167 procUnitConfObjB = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjA.getId())
165 procUnitConfObjB.addParameter(name='nFFTPoints', value=n, format='int')
168 procUnitConfObjB.addParameter(name='nFFTPoints', value=n, format='int')
166 procUnitConfObjB.addParameter(name='nProfiles' , value=n, format='int')
169 procUnitConfObjB.addParameter(name='nProfiles' , value=n, format='int')
167
170
168 procUnitConfObjC = controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjB.getId())
171 procUnitConfObjC = controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjB.getId())
169 procUnitConfObjC.addOperation(name='SpectralMoments')
172 procUnitConfObjC.addOperation(name='SpectralMoments')
170 if plot==1:
173 if plot==1:
171 dBmin = '1'
174 dBmin = '1'
172 dBmax = '65'
175 dBmax = '65'
173 opObj11 = procUnitConfObjC.addOperation(name='PowerPlot',optype='external')
176 opObj11 = procUnitConfObjC.addOperation(name='PowerPlot',optype='external')
174 opObj11.addParameter(name='xmin', value=xmin)
177 opObj11.addParameter(name='xmin', value=xmin)
175 opObj11.addParameter(name='xmax', value=xmax)
178 opObj11.addParameter(name='xmax', value=xmax)
176 opObj11.addParameter(name='zmin', value=dBmin)
179 opObj11.addParameter(name='zmin', value=dBmin)
177 opObj11.addParameter(name='zmax', value=dBmax)
180 opObj11.addParameter(name='zmax', value=dBmax)
178 opObj11.addParameter(name='save', value=figpath_mom)
181 opObj11.addParameter(name='save', value=figpath_spec)
179 opObj11.addParameter(name='showprofile', value=0)
182 opObj11.addParameter(name='showprofile', value=0)
180 opObj11.addParameter(name='save_period', value=100)
183 opObj11.addParameter(name='save_period', value=10)
181
184
182 if save==1:
185 if save==1:
183 opObj10 = procUnitConfObjC.addOperation(name='HDFWriter')
186 opObj10 = procUnitConfObjC.addOperation(name='HDFWriter')
184 opObj10.addParameter(name='path',value=path_save)
187 opObj10.addParameter(name='path',value=path_save)
185 #opObj10.addParameter(name='mode',value=0)
188 #opObj10.addParameter(name='mode',value=0)
186 opObj10.addParameter(name='blocksPerFile',value='360',format='int')
189 opObj10.addParameter(name='blocksPerFile',value='360',format='int')
187 #opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
190 #opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
188 opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
191 opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex
189 opObj10.addParameter(name='dataList',value='data_pow,data_dop,utctime',format='list')#,format='list'
192 opObj10.addParameter(name='dataList',value='data_pow,data_dop,utctime',format='list')#,format='list'
190
193
191 if integration==1:
194 if integration==1:
192 V=10
195 V=10
193 blocksPerfile=360
196 blocksPerfile=360
194 print("* Velocidad del Pedestal:",V)
197 print("* Velocidad del Pedestal:",V)
195 tmp_blocksPerfile = 100
198 tmp_blocksPerfile = 100
196 f_a_p= int(tmp_blocksPerfile/V)
199 f_a_p= int(tmp_blocksPerfile/V)
197
200
198 opObj11 = procUnitConfObjC.addOperation(name='PedestalInformation')
201 opObj11 = procUnitConfObjC.addOperation(name='PedestalInformation')
199 opObj11.addParameter(name='path_ped', value=path_ped)
202 opObj11.addParameter(name='path_ped', value=path_ped)
200 #opObj11.addParameter(name='path_adq', value=path_adq)
203 #opObj11.addParameter(name='path_adq', value=path_adq)
201 opObj11.addParameter(name='t_Interval_p', value='0.01', format='float')
204 opObj11.addParameter(name='t_Interval_p', value='0.01', format='float')
202 opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int')
205 opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int')
203 opObj11.addParameter(name='n_Muestras_p', value='100', format='float')
206 opObj11.addParameter(name='n_Muestras_p', value='100', format='float')
204 opObj11.addParameter(name='f_a_p', value=f_a_p, format='int')
207 opObj11.addParameter(name='f_a_p', value=f_a_p, format='int')
205 opObj11.addParameter(name='online', value='0', format='int')
208 opObj11.addParameter(name='online', value='0', format='int')
206
209
207 opObj11 = procUnitConfObjC.addOperation(name='Block360')
210 opObj11 = procUnitConfObjC.addOperation(name='Block360')
208 opObj11.addParameter(name='n', value='10', format='int')
211 opObj11.addParameter(name='n', value='10', format='int')
209 opObj11.addParameter(name='mode', value=mode, format='int')
212 opObj11.addParameter(name='mode', value=mode, format='int')
210
213
211 # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180
214 # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180
212 opObj11= procUnitConfObjC.addOperation(name='WeatherPlot',optype='other')
215 opObj11= procUnitConfObjC.addOperation(name='WeatherPlot',optype='other')
213 controllerObj.start()
216 controllerObj.start()
@@ -1,112 +1,119
1 # Ing-AlexanderValdez
1 # Ing-AlexanderValdez
2 # Monitoreo de Pedestal
2 # Monitoreo de Pedestal
3
3
4 ############## IMPORTA LIBRERIAS ###################
4 ############## IMPORTA LIBRERIAS ###################
5 import os,numpy,h5py
5 import os,numpy,h5py
6 import sys,time
6 import sys,time
7 import matplotlib.pyplot as plt
7 import matplotlib.pyplot as plt
8 ####################################################
8 ####################################################
9 path_ped = '/DATA_RM/TEST_PEDESTAL/P20211012-082745'
9 #################################################################
10 # LA FECHA 21-10-20 CORRESPONDE A LAS PRUEBAS DEL DIA MIERCOLES
11 # 1:15:51 pm hasta 3:49:32 pm
12 #################################################################
13
14 #path_ped = '/DATA_RM/TEST_PEDESTAL/P20211012-082745'
15 path_ped = '/DATA_RM/TEST_PEDESTAL/P20211020-131248'
10 # Metodo para verificar numero
16 # Metodo para verificar numero
11 def isNumber(str):
17 def isNumber(str):
12 try:
18 try:
13 float(str)
19 float(str)
14 return True
20 return True
15 except:
21 except:
16 return False
22 return False
17 # Metodo para extraer el arreglo
23 # Metodo para extraer el arreglo
18 def getDatavaluefromDirFilename(path,file,value):
24 def getDatavaluefromDirFilename(path,file,value):
19 dir_file= path+"/"+file
25 dir_file= path+"/"+file
20 fp = h5py.File(dir_file,'r')
26 fp = h5py.File(dir_file,'r')
21 array = fp['Data'].get(value)[()]
27 array = fp['Data'].get(value)[()]
22 fp.close()
28 fp.close()
23 return array
29 return array
24
30
25 # LISTA COMPLETA DE ARCHIVOS HDF5 Pedestal
31 # LISTA COMPLETA DE ARCHIVOS HDF5 Pedestal
26 LIST= sorted(os.listdir(path_ped))
32 LIST= sorted(os.listdir(path_ped))
27 m=len(LIST)
33 m=len(LIST)
28 print("TOTAL DE ARCHIVOS DE PEDESTAL:",m)
34 print("TOTAL DE ARCHIVOS DE PEDESTAL:",m)
29 # Contadores temporales
35 # Contadores temporales
30 k= 0
36 k= 0
31 l= 0
37 l= 0
32 t= 0
38 t= 0
33 # Marca de tiempo temporal
39 # Marca de tiempo temporal
34 time_ = numpy.zeros([m])
40 time_ = numpy.zeros([m])
35 # creacion de
41 # creacion de
36 for i in range(m):
42 for i in range(m):
43 print("order:",i)
37 tmp_azi_pos = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="azi_pos")
44 tmp_azi_pos = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="azi_pos")
38 tmp_ele_pos = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="ele_pos")
45 tmp_ele_pos = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="ele_pos")
39 tmp_azi_vel = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="azi_vel")
46 tmp_azi_vel = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="azi_vel")
40 tmp_ele_vel = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="azi_vel")# nuevo :D
47 tmp_ele_vel = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="azi_vel")# nuevo :D
41
48
42 time_[i] = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="utc")
49 time_[i] = getDatavaluefromDirFilename(path=path_ped,file=LIST[i],value="utc")
43
50
44 k=k +tmp_azi_pos.shape[0]
51 k=k +tmp_azi_pos.shape[0]
45 l=l +tmp_ele_pos.shape[0]
52 l=l +tmp_ele_pos.shape[0]
46 t=t +tmp_azi_vel.shape[0]
53 t=t +tmp_azi_vel.shape[0]
47
54
48 print("TOTAL DE MUESTRAS, ARCHIVOS X100:",k)
55 print("TOTAL DE MUESTRAS, ARCHIVOS X100:",k)
49 time.sleep(5)
56 time.sleep(5)
50 ######CREACION DE ARREGLOS CANTIDAD DE VALORES POR MUESTRA#################
57 ######CREACION DE ARREGLOS CANTIDAD DE VALORES POR MUESTRA#################
51 azi_pos = numpy.zeros([k])
58 azi_pos = numpy.zeros([k])
52 ele_pos = numpy.zeros([l])
59 ele_pos = numpy.zeros([l])
53 time_azi_pos= numpy.zeros([k])
60 time_azi_pos= numpy.zeros([k])
54 # Contadores temporales
61 # Contadores temporales
55 p=0
62 p=0
56 r=0
63 r=0
57 z=0
64 z=0
58 # VARIABLES TMP para almacenar azimuth, elevacion y tiempo
65 # VARIABLES TMP para almacenar azimuth, elevacion y tiempo
59
66
60 #for filename in sorted(os.listdir(path_ped)):
67 #for filename in sorted(os.listdir(path_ped)):
61 # CONDICION POR LEER EN TIEMPO REAL NO OFFLINE
68 # CONDICION POR LEER EN TIEMPO REAL NO OFFLINE
62
69
63 for filename in LIST:
70 for filename in LIST:
64 tmp_azi_pos = getDatavaluefromDirFilename(path=path_ped,file=filename,value="azi_pos")
71 tmp_azi_pos = getDatavaluefromDirFilename(path=path_ped,file=filename,value="azi_pos")
65 tmp_ele_pos = getDatavaluefromDirFilename(path=path_ped,file=filename,value="ele_pos")
72 tmp_ele_pos = getDatavaluefromDirFilename(path=path_ped,file=filename,value="ele_pos")
66 # CONDICION POR LEER EN TIEMPO REAL NO OFFLINE
73 # CONDICION POR LEER EN TIEMPO REAL NO OFFLINE
67
74
68 if z==(m-1):
75 if z==(m-1):
69 tmp_azi_time=numpy.arange(time_[z],time_[z]+1,1/(tmp_azi_pos.shape[0]))
76 tmp_azi_time=numpy.arange(time_[z],time_[z]+1,1/(tmp_azi_pos.shape[0]))
70 else:
77 else:
71 tmp_azi_time=numpy.arange(time_[z],time_[z+1],(time_[z+1]-time_[z])/(tmp_azi_pos.shape[0]))
78 tmp_azi_time=numpy.arange(time_[z],time_[z+1],(time_[z+1]-time_[z])/(tmp_azi_pos.shape[0]))
72
79
73 print(filename,time_[z])
80 print(filename,time_[z])
74 print(z,tmp_azi_pos.shape[0])
81 print(z,tmp_azi_pos.shape[0])
75
82
76 i=0
83 i=0
77 for i in range(tmp_azi_pos.shape[0]):
84 for i in range(tmp_azi_pos.shape[0]):
78 index=p+i
85 index=p+i
79 azi_pos[index]=tmp_azi_pos[i]
86 azi_pos[index]=tmp_azi_pos[i]
80 time_azi_pos[index]=tmp_azi_time[i]
87 time_azi_pos[index]=tmp_azi_time[i]
81 p=p+tmp_azi_pos.shape[0]
88 p=p+tmp_azi_pos.shape[0]
82 i=0
89 i=0
83 for i in range(tmp_ele_pos.shape[0]):
90 for i in range(tmp_ele_pos.shape[0]):
84 index=r+i
91 index=r+i
85 ele_pos[index]=tmp_ele_pos[i]
92 ele_pos[index]=tmp_ele_pos[i]
86 r=r+tmp_ele_pos.shape[0]
93 r=r+tmp_ele_pos.shape[0]
87
94
88
95
89 z+=1
96 z+=1
90
97
91
98
92 ######## GRAFIQUEMOS Y VEAMOS LOS DATOS DEL Pedestal
99 ######## GRAFIQUEMOS Y VEAMOS LOS DATOS DEL Pedestal
93 fig, ax = plt.subplots(figsize=(16,8))
100 fig, ax = plt.subplots(figsize=(16,8))
94 print(time_azi_pos.shape)
101 print(time_azi_pos.shape)
95 print(azi_pos.shape)
102 print(azi_pos.shape)
96 t=numpy.arange(time_azi_pos.shape[0])*0.01/(60.0)
103 t=numpy.arange(time_azi_pos.shape[0])*0.01/(60.0)
97 plt.plot(t,azi_pos,label='AZIMUTH_POS',color='blue')
104 plt.plot(t,azi_pos,label='AZIMUTH_POS',color='blue')
98
105
99 # AQUI ESTOY ADICIONANDO LA POSICION EN elevaciont=numpy.arange(len(ele_pos))*0.01/60.0
106 # AQUI ESTOY ADICIONANDO LA POSICION EN elevaciont=numpy.arange(len(ele_pos))*0.01/60.0
100 t=numpy.arange(len(ele_pos))*0.01/60.0
107 t=numpy.arange(len(ele_pos))*0.01/60.0
101 plt.plot(t,ele_pos,label='ELEVATION_POS',color='red')#*10
108 plt.plot(t,ele_pos,label='ELEVATION_POS',color='red')#*10
102
109
103 #ax.set_xlim(0, 9)
110 #ax.set_xlim(0, 9)
104 ax.set_ylim(-5, 400)
111 ax.set_ylim(-5, 400)
105 plt.ylabel("Azimuth Position")
112 plt.ylabel("Azimuth Position")
106 plt.xlabel("Muestra")
113 plt.xlabel("Muestra")
107 plt.title('Azimuth Position vs Muestra ', fontsize=20)
114 plt.title('Azimuth Position vs Muestra ', fontsize=20)
108 axes = plt.gca()
115 axes = plt.gca()
109 axes.yaxis.grid()
116 axes.yaxis.grid()
110 plt.xticks(fontsize=16)
117 plt.xticks(fontsize=16)
111 plt.yticks(fontsize=16)
118 plt.yticks(fontsize=16)
112 plt.show()
119 plt.show()
@@ -1,78 +1,79
1 import os,sys,json
1 import os,sys,json
2 import datetime
2 import datetime
3 import time
3 import time
4 from schainpy.controller import Project
4 from schainpy.controller import Project
5 '''
5 '''
6 NOTA:
6 NOTA:
7 Este script de prueba.
7 Este script de prueba.
8 - Unidad del lectura 'HDFReader'.
8 - Unidad del lectura 'HDFReader'.
9 - Unidad de procesamiento ParametersProc
9 - Unidad de procesamiento ParametersProc
10 - Operacion SpectralMomentsPlot
10 - Operacion SpectralMomentsPlot
11
11
12 '''
12 '''
13
13
14 #######################################################################
14 #######################################################################
15 ################# RANGO DE PLOTEO######################################
15 ################# RANGO DE PLOTEO######################################
16 #######################################################################
16 #######################################################################
17 dBmin = '1'
17 dBmin = '1'
18 dBmax = '65'
18 dBmax = '65'
19 xmin = '0'
19 xmin = '0'
20 xmax ='24'
20 xmax ='24'
21 #tmmin = 16.2
21 #tmmin = 16.2
22 #tmmax = 16.25
22 #tmmax = 16.25
23 tmmin =15
23 tmmin =15
24 tmmax =15.5
24 tmmax =15.5
25 ymin = '0'
25 ymin = '0'
26 ymax = '600'
26 ymax = '600'
27 #######################################################################
27 #######################################################################
28 #######################################################################
28 #######################################################################
29 #######################################################################
29 #######################################################################
30 #path = '/DATA_RM/TEST_HDF5_SPEC'
30 #path = '/DATA_RM/TEST_HDF5_SPEC'
31 path = '/DATA_RM/TEST_HDF5_SPEC_23/6v/'
31 #path = '/DATA_RM/TEST_HDF5_SPEC_23/6v/'
32 path = '/DATA_RM/TEST_HDF5_19OCT'
32 figpath = '/home/soporte/Downloads/23/6v'
33 figpath = '/home/soporte/Downloads/23/6v'
33 desc = "Simulator Test"
34 desc = "Simulator Test"
34 desc_data = {
35 desc_data = {
35 'Data': {
36 'Data': {
36 'data_pow': ['Data/data_pow/channel00','Data/data_pow/channel01'],
37 'data_pow': ['Data/data_pow/channel00','Data/data_pow/channel01'],
37 'data_dop': ['Data/data_dop/channel00','Data/data_dop/channel01'],
38 'data_dop': ['Data/data_dop/channel00','Data/data_dop/channel01'],
38 'utctime':'Data/utctime'
39 'utctime':'Data/utctime'
39 },
40 },
40 'Metadata': {
41 'Metadata': {
41 'heightList':'Metadata/heightList',
42 'heightList':'Metadata/heightList',
42 'nIncohInt' :'Metadata/nIncohInt',
43 'nIncohInt' :'Metadata/nIncohInt',
43 'nCohInt' :'Metadata/nCohInt',
44 'nCohInt' :'Metadata/nCohInt',
44 'nProfiles' :'Metadata/nProfiles',
45 'nProfiles' :'Metadata/nProfiles',
45 'channelList' :'Metadata/channelList',
46 'channelList' :'Metadata/channelList',
46 'utctimeInit' :'Metadata/utctimeInit'
47 'utctimeInit' :'Metadata/utctimeInit'
47
48
48 }
49 }
49 }
50 }
50
51
51 controllerObj = Project()
52 controllerObj = Project()
52
53
53 controllerObj.setup(id='10',name='Test Simulator',description=desc)
54 controllerObj.setup(id='10',name='Test Simulator',description=desc)
54
55
55 readUnitConfObj = controllerObj.addReadUnit(datatype='HDFReader',
56 readUnitConfObj = controllerObj.addReadUnit(datatype='HDFReader',
56 path=path,
57 path=path,
57 startDate="2021/01/01", #"2020/01/01",#today,
58 startDate="2021/01/01", #"2020/01/01",#today,
58 endDate= "2021/12/01", #"2020/12/30",#today,
59 endDate= "2021/12/01", #"2020/12/30",#today,
59 startTime='00:00:00',
60 startTime='00:00:00',
60 endTime='23:59:59',
61 endTime='23:59:59',
61 delay=0,
62 delay=0,
62 #set=0,
63 #set=0,
63 online=0,
64 online=0,
64 walk=1,
65 walk=1,
65 description= json.dumps(desc_data))#1
66 description= json.dumps(desc_data))#1
66
67
67 procUnitConfObjA = controllerObj.addProcUnit(datatype='ParametersProc',inputId=readUnitConfObj.getId())
68 procUnitConfObjA = controllerObj.addProcUnit(datatype='ParametersProc',inputId=readUnitConfObj.getId())
68
69
69 opObj11 = procUnitConfObjA.addOperation(name='PowerPlot',optype='external')
70 opObj11 = procUnitConfObjA.addOperation(name='PowerPlot',optype='external')
70 opObj11.addParameter(name='xmin', value=tmmin)
71 opObj11.addParameter(name='xmin', value=tmmin)
71 opObj11.addParameter(name='xmax', value=tmmax)
72 opObj11.addParameter(name='xmax', value=tmmax)
72 opObj11.addParameter(name='zmin', value=dBmin)
73 opObj11.addParameter(name='zmin', value=dBmin)
73 opObj11.addParameter(name='zmax', value=dBmax)
74 opObj11.addParameter(name='zmax', value=dBmax)
74 opObj11.addParameter(name='save', value=figpath)
75 opObj11.addParameter(name='save', value=figpath)
75 opObj11.addParameter(name='showprofile', value=0)
76 opObj11.addParameter(name='showprofile', value=0)
76 opObj11.addParameter(name='save_period', value=10)
77 opObj11.addParameter(name='save_period', value=10)
77
78
78 controllerObj.start()
79 controllerObj.start()
General Comments 0
You need to be logged in to leave comments. Login now