##// END OF EJS Templates
Changing the Model for the input Objects in Processing package...
Daniel Valdez -
r107:33fbc5472d1b
parent child
Show More
@@ -1,23 +1,13
1 1 [Read0]
2 2 id = 0
3 3 type = VoltageReader
4 setup = str,/Users/jro/Documents/RadarData/EW_Drifts,datetime,2011-11-20-0-0-1,datetime,2011-12-31-0-0-1,int,0,str,,str,None,int,0
4 setup = str,/Users/jro/Documents/RadarData/MST_ISR/MST,datetime,2009-01-01-0-0-1,datetime,2009-12-31-0-0-1,int,0,str,,str,None,int,0
5 5 getData = None,None
6 6
7 7 [Processing0]
8 8 id = 1
9 type = Voltage
10 input = 0
11 setup = None,None
12 init = None,None
13 integrator = int,4,None,None
14 plotData = float,None,float,None,float,None,float,None,str,iq,str,Test Data Voltage 2,int,1
15
16 [Processing1]
17 id = 2
18 9 type = Spectra
19 input = 1
20 setup = int,8,None,None
10 input = 0
11 setup = int,16,None,None
21 12 init = None,None
22 integrator = int,4,int,3
23 plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,2
13 plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,1
@@ -621,7 +621,7 class ColorPlot:
621 621
622 622
623 623
624 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
624 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, title = ''):
625 625 """
626 626 Inputs:
627 627
@@ -647,6 +647,7 class ColorPlot:
647 647
648 648 plplot.plschr(0.0, self.__szchar)
649 649 self.__iniSubpage()
650 self.colorGraphObj.title = title
650 651 self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax)
651 652 self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax)
652 653
@@ -661,7 +662,7 class ColorPlot:
661 662 cmapObj.colorbarPlot(0., 1., zmin, zmax)
662 663
663 664 if self.__showPowerProfile:
664 power = numpy.max(data, axis=0)
665 power = numpy.average(data, axis=0)
665 666
666 667 step = (ymax - ymin)/(nY-1)
667 668 heis = numpy.arange(ymin, ymax + step, step)
@@ -154,7 +154,7 class Spectrum:
154 154 plplot.plsstrm(self.indexPlot)
155 155
156 156 data = 10.*numpy.log10(self.spectraObj.data_spc)
157
157 noise = 10.*numpy.log10(self.spectraObj.noise)
158 158 #data.shape = Channels x Heights x Profiles
159 159 # data = numpy.transpose( data, (0,2,1) )
160 160 #data.shape = Channels x Profiles x Heights
@@ -186,7 +186,8 class Spectrum:
186 186 ymin=ymin,
187 187 ymax=ymax,
188 188 zmin=zmin,
189 zmax=zmax)
189 zmax=zmax,
190 title = "Channel: %d - Noise: %.2f" %(i, noise[i]))
190 191
191 192 plplot.plssub(1,0)
192 193 plplot.pladv(0)
@@ -179,7 +179,7 class JRODataIO:
179 179
180 180 m_ProcessingHeader = ProcessingHeader()
181 181
182 m_DataObj = None
182 dataOutObj = None
183 183
184 184 online = 0
185 185
@@ -256,7 +256,7 class JRODataReader(JRODataIO):
256 256
257 257 nReadBlocks = 0
258 258
259 def __init__(self, m_DataObj=None):
259 def __init__(self, dataOutObj=None):
260 260
261 261 raise ValueError, "This class can't be instanced"
262 262
@@ -280,6 +280,126 class JRODataReader(JRODataIO):
280 280
281 281 raise ValueError, "This method has not been implemented"
282 282
283 def createObjByDefault(self):
284 """
285 Los objetos creados por defecto por cada clase (Voltaje o Espectro) difieren en el tipo
286 raise ValueError, "This method has not been implemented
287 """
288 raise ValueError, "This method has not been implemented"
289
290 def setup(self, dataOutObj=None, path=None, startDateTime=None, endDateTime=None, set=0, expLabel = "", ext = None, online = 0):
291 """
292 setup configura los parametros de lectura de la clase DataReader.
293
294 Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos
295 que coincidan con los parametros especificados; esta lista de archivos son almacenados en
296 self.filenameList.
297
298 Input:
299 path : Directorios donde se ubican los datos a leer. Dentro de este
300 directorio deberia de estar subdirectorios de la forma:
301
302 path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext]
303
304 startDateTime : Fecha inicial. Rechaza todos los archivos donde
305 file end time < startDatetime (obejto datetime.datetime)
306
307 endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde
308 file end time < startDatetime (obejto datetime.datetime)
309
310 set : Set del primer archivo a leer. Por defecto None
311
312 expLabel : Nombre del subdirectorio de datos. Por defecto ""
313
314 ext : Extension de los archivos a leer. Por defecto .r
315
316 online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas
317
318 Return:
319 0 : Si no encuentra files que cumplan con las condiciones dadas
320 1 : Si encuentra files que cumplan con las condiciones dadas
321
322 Affected:
323 self.startUTCSeconds
324 self.endUTCSeconds
325 self.startYear
326 self.endYear
327 self.startDoy
328 self.endDoy
329 self.pathList
330 self.filenameList
331 self.online
332 """
333 if path == None:
334 raise ValueError, "The path is not valid"
335
336 if ext == None:
337 ext = self.ext
338
339 if dataOutObj == None:
340 dataOutObj = self.createObjByDefault()
341
342 self.dataOutObj = dataOutObj
343
344 if online:
345 print "Searching files ..."
346 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
347
348 if not(doypath):
349 for nTries in range( self.nTries ):
350 print '\tWaiting %0.2f sec for valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
351 time.sleep( self.delay )
352 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
353 if doypath:
354 break
355
356 if not(doypath):
357 print "There 'isn't valied files in %s" % path
358 return None
359
360 self.year = year
361 self.doy = doy
362 self.set = set - 1
363 self.path = path
364
365 else: # offline
366 pathList, filenameList = self.__searchFilesOffLine(path, startDateTime, endDateTime, set, expLabel, ext)
367 if not(pathList):
368 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
369 return None
370
371 self.fileIndex = -1
372 self.pathList = pathList
373 self.filenameList = filenameList
374
375 self.online = online
376 self.ext = ext
377
378 ext = ext.lower()
379
380 if not( self.setNextFile() ):
381 if (startDateTime != None) and (endDateTime != None):
382 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
383 elif startDateTime != None:
384 print "No files in : %s" % startDateTime.ctime()
385 else:
386 print "No files"
387 return None
388
389 if startDateTime != None:
390 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
391 self.startYear = startDateTime.timetuple().tm_year
392 self.startDoy = startDateTime.timetuple().tm_yday
393
394 if endDateTime != None:
395 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
396 self.endYear = endDateTime.timetuple().tm_year
397 self.endDoy = endDateTime.timetuple().tm_yday
398 #call fillHeaderValues() - to Data Object
399
400 self.updateDataHeader()
401
402 return self.dataOutObj
283 403
284 404 def __rdSystemHeader(self, fp=None):
285 405
@@ -359,7 +479,9 class JRODataReader(JRODataIO):
359 479 self.ippSeconds = 2 * 1000 * self.m_RadarControllerHeader.ipp / self.c
360 480
361 481 self.fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1)
362
482 self.dataOutObj.channelList = numpy.arange(self.m_SystemHeader.numChannels)
483 self.dataOutObj.channelIndexList = numpy.arange(self.m_SystemHeader.numChannels)
484
363 485 self.getBlockDimension()
364 486
365 487
@@ -833,120 +955,14 class JRODataReader(JRODataIO):
833 955
834 956 def updateDataHeader(self):
835 957
836 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
837 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
838 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
839 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
840
841 self.m_DataObj.dataType = self.dataType
842 self.m_DataObj.updateObjFromHeader()
843
844 def setup(self, path, startDateTime=None, endDateTime=None, set=0, expLabel = "", ext = None, online = 0):
845 """
846 setup configura los parametros de lectura de la clase DataReader.
847
848 Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos
849 que coincidan con los parametros especificados; esta lista de archivos son almacenados en
850 self.filenameList.
851
852 Input:
853 path : Directorios donde se ubican los datos a leer. Dentro de este
854 directorio deberia de estar subdirectorios de la forma:
855
856 path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext]
857
858 startDateTime : Fecha inicial. Rechaza todos los archivos donde
859 file end time < startDatetime (obejto datetime.datetime)
860
861 endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde
862 file end time < startDatetime (obejto datetime.datetime)
863
864 set : Set del primer archivo a leer. Por defecto None
865
866 expLabel : Nombre del subdirectorio de datos. Por defecto ""
867
868 ext : Extension de los archivos a leer. Por defecto .r
869
870 online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas
871
872 Return:
873 0 : Si no encuentra files que cumplan con las condiciones dadas
874 1 : Si encuentra files que cumplan con las condiciones dadas
875
876 Affected:
877 self.startUTCSeconds
878 self.endUTCSeconds
879 self.startYear
880 self.endYear
881 self.startDoy
882 self.endDoy
883 self.pathList
884 self.filenameList
885 self.online
886 """
958 self.dataOutObj.m_BasicHeader = self.m_BasicHeader.copy()
959 self.dataOutObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
960 self.dataOutObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
961 self.dataOutObj.m_SystemHeader = self.m_SystemHeader.copy()
887 962
888 if ext == None:
889 ext = self.ext
890
891 if online:
892 print "Searching files ..."
893 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
963 self.dataOutObj.dataType = self.dataType
964 self.dataOutObj.updateObjFromHeader()
894 965
895 if not(doypath):
896 for nTries in range( self.nTries ):
897 print '\tWaiting %0.2f sec for valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
898 time.sleep( self.delay )
899 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
900 if doypath:
901 break
902
903 if not(doypath):
904 print "There 'isn't valied files in %s" % path
905 return 0
906
907 self.year = year
908 self.doy = doy
909 self.set = set - 1
910 self.path = path
911
912 else: # offline
913 pathList, filenameList = self.__searchFilesOffLine(path, startDateTime, endDateTime, set, expLabel, ext)
914 if not(pathList):
915 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
916 return 0
917
918 self.fileIndex = -1
919 self.pathList = pathList
920 self.filenameList = filenameList
921
922 self.online = online
923 self.ext = ext
924
925 ext = ext.lower()
926
927 if not( self.setNextFile() ):
928 if (startDateTime != None) and (endDateTime != None):
929 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
930 elif startDateTime != None:
931 print "No files in : %s" % startDateTime.ctime()
932 else:
933 print "No files"
934 return 0
935
936 if startDateTime != None:
937 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
938 self.startYear = startDateTime.timetuple().tm_year
939 self.startDoy = startDateTime.timetuple().tm_yday
940
941 if endDateTime != None:
942 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
943 self.endYear = endDateTime.timetuple().tm_year
944 self.endDoy = endDateTime.timetuple().tm_yday
945 #call fillHeaderValues() - to Data Object
946
947 self.updateDataHeader()
948
949 return 1
950 966
951 967 class JRODataWriter(JRODataIO):
952 968
@@ -960,7 +976,7 class JRODataWriter(JRODataIO):
960 976 setFile = None
961 977
962 978
963 def __init__(self, m_DataObj=None):
979 def __init__(self, dataOutObj=None):
964 980 raise ValueError, "Not implemented"
965 981
966 982
@@ -994,7 +1010,7 class JRODataWriter(JRODataIO):
994 1010 self.__wrSystemHeader()
995 1011 self.__wrRadarControllerHeader()
996 1012 self.__wrProcessingHeader()
997 self.dataType = self.m_DataObj.dataType
1013 self.dataType = self.dataOutObj.dataType
998 1014
999 1015
1000 1016 def __writeBasicHeader(self, fp=None):
@@ -1007,7 +1023,7 class JRODataWriter(JRODataIO):
1007 1023 if fp == None:
1008 1024 fp = self.fp
1009 1025
1010 self.m_DataObj.m_BasicHeader.write(fp)
1026 self.dataOutObj.m_BasicHeader.write(fp)
1011 1027
1012 1028
1013 1029 def __wrSystemHeader(self, fp=None):
@@ -1020,7 +1036,7 class JRODataWriter(JRODataIO):
1020 1036 if fp == None:
1021 1037 fp = self.fp
1022 1038
1023 self.m_DataObj.m_SystemHeader.write(fp)
1039 self.dataOutObj.m_SystemHeader.write(fp)
1024 1040
1025 1041
1026 1042 def __wrRadarControllerHeader(self, fp=None):
@@ -1033,7 +1049,7 class JRODataWriter(JRODataIO):
1033 1049 if fp == None:
1034 1050 fp = self.fp
1035 1051
1036 self.m_DataObj.m_RadarControllerHeader.write(fp)
1052 self.dataOutObj.m_RadarControllerHeader.write(fp)
1037 1053
1038 1054
1039 1055 def __wrProcessingHeader(self, fp=None):
@@ -1046,7 +1062,7 class JRODataWriter(JRODataIO):
1046 1062 if fp == None:
1047 1063 fp = self.fp
1048 1064
1049 self.m_DataObj.m_ProcessingHeader.write(fp)
1065 self.dataOutObj.m_ProcessingHeader.write(fp)
1050 1066
1051 1067
1052 1068 def setNextFile(self):
@@ -1070,7 +1086,7 class JRODataWriter(JRODataIO):
1070 1086 if self.fp != None:
1071 1087 self.fp.close()
1072 1088
1073 timeTuple = time.localtime( self.m_DataObj.m_BasicHeader.utc )
1089 timeTuple = time.localtime( self.dataOutObj.m_BasicHeader.utc )
1074 1090 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1075 1091
1076 1092 doypath = os.path.join( path, subfolder )
@@ -1175,14 +1191,14 class JRODataWriter(JRODataIO):
1175 1191 Return:
1176 1192 None
1177 1193 """
1178 self.m_DataObj.updateHeaderFromObj()
1194 self.dataOutObj.updateHeaderFromObj()
1179 1195
1180 self.m_BasicHeader = self.m_DataObj.m_BasicHeader.copy()
1181 self.m_SystemHeader = self.m_DataObj.m_SystemHeader.copy()
1182 self.m_RadarControllerHeader = self.m_DataObj.m_RadarControllerHeader.copy()
1183 self.m_ProcessingHeader = self.m_DataObj.m_ProcessingHeader.copy()
1196 self.m_BasicHeader = self.dataOutObj.m_BasicHeader.copy()
1197 self.m_SystemHeader = self.dataOutObj.m_SystemHeader.copy()
1198 self.m_RadarControllerHeader = self.dataOutObj.m_RadarControllerHeader.copy()
1199 self.m_ProcessingHeader = self.dataOutObj.m_ProcessingHeader.copy()
1184 1200
1185 self.dataType = self.m_DataObj.dataType
1201 self.dataType = self.dataOutObj.dataType
1186 1202
1187 1203
1188 1204 def setup(self, path, set=0, ext=None):
@@ -53,13 +53,13 class SpectraReader(JRODataReader):
53 53
54 54 readerObj.getData()
55 55
56 print readerObj.m_Spectra.data
56 print readerObj.dataOutObj.data
57 57
58 58 if readerObj.flagNoMoreFiles:
59 59 break
60 60
61 61 """
62 m_DataObj = None
62 dataOutObj = None
63 63
64 64 data_spc = None
65 65 data_cspc = None
@@ -70,19 +70,16 class SpectraReader(JRODataReader):
70 70 pts2read_DCchannels = 0
71 71
72 72 nChannels = 0
73
74 73 nPairs = 0
75 74
76 #pairList = None
77
78 channelList = None
75 flag_cspc = False
79 76
80 def __init__(self, m_Spectra=None):
77 def __init__(self, dataOutObj=None):
81 78 """
82 79 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
83 80
84 81 Inputs:
85 m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para
82 dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para
86 83 almacenar un perfil de datos cada vez que se haga un requerimiento
87 84 (getData). El perfil sera obtenido a partir del buffer de datos,
88 85 si el buffer esta vacio se hara un nuevo proceso de lectura de un
@@ -90,17 +87,10 class SpectraReader(JRODataReader):
90 87 Si este parametro no es pasado se creara uno internamente.
91 88
92 89 Affected:
93 self.m_DataObj
90 self.dataOutObj
94 91
95 92 Return : None
96 93 """
97 if m_Spectra == None:
98 m_Spectra = Spectra()
99
100 if not( isinstance(m_Spectra, Spectra) ):
101 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
102
103 self.m_DataObj = m_Spectra
104 94
105 95 self.data_spc = None
106 96 self.data_cspc = None
@@ -174,13 +164,12 class SpectraReader(JRODataReader):
174 164
175 165 self.blocksize = 0
176 166
177 #pairList = None
178
179 channelList = None
167 def createObjByDefault(self):
180 168
181 self.flag_cspc = False
182
183
169 dataObj = Spectra()
170
171 return dataObj
172
184 173 def __hasNotDataInBuffer(self):
185 174 return 1
186 175
@@ -196,8 +185,8 class SpectraReader(JRODataReader):
196 185 self.pts2read_CrossSpectra
197 186 self.pts2read_DCchannels
198 187 self.blocksize
199 self.m_DataObj.nChannels
200 self.m_DataObj.nPairs
188 self.dataOutObj.nChannels
189 self.dataOutObj.nPairs
201 190
202 191 Return:
203 192 None
@@ -212,16 +201,13 class SpectraReader(JRODataReader):
212 201 else:
213 202 self.nPairs = self.nPairs + 1 #par de canales diferentes
214 203 self.pairList.append( (self.m_ProcessingHeader.spectraComb[i], self.m_ProcessingHeader.spectraComb[i+1]) )
215
216 if self.nPairs > 0:
217 self.flag_cspc = True
218 204
219 205 pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock
220 206
221 207 self.pts2read_SelfSpectra = int(self.nChannels * pts2read)
222 208 self.blocksize = self.pts2read_SelfSpectra
223 209
224 if self.flag_cspc:
210 if self.m_ProcessingHeader.flag_cspc:
225 211 self.pts2read_CrossSpectra = int(self.nPairs * pts2read)
226 212 self.blocksize += self.pts2read_CrossSpectra
227 213
@@ -230,8 +216,6 class SpectraReader(JRODataReader):
230 216 self.blocksize += self.pts2read_DCchannels
231 217
232 218 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
233
234 self.channelList = numpy.arange(self.nChannels)
235 219
236 220
237 221 def readBlock(self):
@@ -312,7 +296,7 class SpectraReader(JRODataReader):
312 296 1 : Si hizo una buena copia del buffer
313 297
314 298 Affected:
315 self.m_DataObj
299 self.dataOutObj
316 300 self.datablockIndex
317 301 self.flagResetProcessing
318 302 self.flagIsNewBlock
@@ -337,15 +321,15 class SpectraReader(JRODataReader):
337 321 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
338 322
339 323 if self.data_dc == None:
340 self.m_DataObj.flagNoData = True
324 self.dataOutObj.flagNoData = True
341 325 return 0
342 326
343 self.m_DataObj.flagNoData = False
344 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
327 self.dataOutObj.flagNoData = False
328 self.dataOutObj.flagResetProcessing = self.flagResetProcessing
345 329
346 self.m_DataObj.data_spc = self.data_spc
347 self.m_DataObj.data_cspc = self.data_cspc
348 self.m_DataObj.data_dc = self.data_dc
330 self.dataOutObj.data_spc = self.data_spc
331 self.dataOutObj.data_cspc = self.data_cspc
332 self.dataOutObj.data_dc = self.data_dc
349 333
350 334 return 1
351 335
@@ -357,7 +341,7 class SpectraWriter(JRODataWriter):
357 341 de los datos siempre se realiza por bloques.
358 342 """
359 343
360 m_DataObj = None
344 dataOutObj = None
361 345
362 346 shape_spc_Buffer = None
363 347 shape_cspc_Buffer = None
@@ -368,12 +352,12 class SpectraWriter(JRODataWriter):
368 352 data_dc = None
369 353
370 354
371 def __init__(self, m_Spectra=None):
355 def __init__(self, dataOutObj=None):
372 356 """
373 357 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
374 358
375 359 Affected:
376 self.m_DataObj
360 self.dataOutObj
377 361 self.m_BasicHeader
378 362 self.m_SystemHeader
379 363 self.m_RadarControllerHeader
@@ -381,13 +365,13 class SpectraWriter(JRODataWriter):
381 365
382 366 Return: None
383 367 """
384 if m_Spectra == None:
385 m_Spectra = Spectra()
368 if dataOutObj == None:
369 dataOutObj = Spectra()
386 370
387 if not( isinstance(m_Spectra, Spectra) ):
388 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
371 if not( isinstance(dataOutObj, Spectra) ):
372 raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object"
389 373
390 self.m_DataObj = m_Spectra
374 self.dataOutObj = dataOutObj
391 375
392 376 self.ext = ".pdata"
393 377
@@ -449,11 +433,11 class SpectraWriter(JRODataWriter):
449 433
450 434 Return: None
451 435 """
452 self.shape_spc_Buffer = (self.m_DataObj.nChannels,
436 self.shape_spc_Buffer = (self.dataOutObj.nChannels,
453 437 self.m_ProcessingHeader.numHeights,
454 438 self.m_ProcessingHeader.profilesPerBlock)
455 439
456 self.shape_cspc_Buffer = (self.m_DataObj.nPairs,
440 self.shape_cspc_Buffer = (self.dataOutObj.nPairs,
457 441 self.m_ProcessingHeader.numHeights,
458 442 self.m_ProcessingHeader.profilesPerBlock)
459 443
@@ -526,18 +510,18 class SpectraWriter(JRODataWriter):
526 510 """
527 511 self.flagIsNewBlock = 0
528 512
529 if self.m_DataObj.flagNoData:
513 if self.dataOutObj.flagNoData:
530 514 return 0
531 515
532 if self.m_DataObj.flagResetProcessing:
516 if self.dataOutObj.flagResetProcessing:
533 517 self.data_spc.fill(0)
534 518 self.data_cspc.fill(0)
535 519 self.data_dc.fill(0)
536 520 self.setNextFile()
537 521
538 self.data_spc = self.m_DataObj.data_spc
539 self.data_cspc = self.m_DataObj.data_cspc
540 self.data_dc = self.m_DataObj.data_dc
522 self.data_spc = self.dataOutObj.data_spc
523 self.data_cspc = self.dataOutObj.data_cspc
524 self.data_dc = self.dataOutObj.data_dc
541 525
542 526 # #self.m_ProcessingHeader.dataBlocksPerFile)
543 527 if self.hasAllDataInBuffer():
@@ -61,7 +61,7 class VoltageReader(JRODataReader):
61 61 break
62 62
63 63 """
64 m_DataObj = None
64 dataOutObj = None
65 65
66 66 datablock = None
67 67
@@ -70,12 +70,12 class VoltageReader(JRODataReader):
70 70 optchar = "D"
71 71
72 72
73 def __init__(self, m_Voltage=None):
73 def __init__(self, dataOutObj=None):
74 74 """
75 75 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
76 76
77 77 Input:
78 m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para
78 dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para
79 79 almacenar un perfil de datos cada vez que se haga un requerimiento
80 80 (getData). El perfil sera obtenido a partir del buffer de datos,
81 81 si el buffer esta vacio se hara un nuevo proceso de lectura de un
@@ -83,18 +83,11 class VoltageReader(JRODataReader):
83 83 Si este parametro no es pasado se creara uno internamente.
84 84
85 85 Variables afectadas:
86 self.m_DataObj
86 self.dataOutObj
87 87
88 88 Return:
89 89 None
90 90 """
91 if m_Voltage == None:
92 m_Voltage = Voltage()
93
94 if not(isinstance(m_Voltage, Voltage)):
95 raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object"
96
97 self.m_DataObj = m_Voltage
98 91
99 92 self.datablock = None
100 93
@@ -172,6 +165,12 class VoltageReader(JRODataReader):
172 165
173 166 self.blocksize = 0
174 167
168 def createObjByDefault(self):
169
170 dataObj = Voltage()
171
172 return dataObj
173
175 174 def __hasNotDataInBuffer(self):
176 175 if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock:
177 176 return 1
@@ -251,11 +250,11 class VoltageReader(JRODataReader):
251 250 buffer. Si no hay mas archivos a leer retorna None.
252 251
253 252 Variables afectadas:
254 self.m_DataObj
253 self.dataOutObj
255 254 self.profileIndex
256 255
257 256 Affected:
258 self.m_DataObj
257 self.dataOutObj
259 258 self.profileIndex
260 259 self.flagResetProcessing
261 260 self.flagIsNewBlock
@@ -279,22 +278,22 class VoltageReader(JRODataReader):
279 278 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
280 279
281 280 if self.datablock == None:
282 self.m_DataObj.flagNoData = True
281 self.dataOutObj.flagNoData = True
283 282 return 0
284 283
285 284 time = self.m_BasicHeader.utc + self.profileIndex * self.ippSeconds
286 self.m_DataObj.m_BasicHeader.utc = time
285 self.dataOutObj.m_BasicHeader.utc = time
287 286
288 self.m_DataObj.flagNoData = False
289 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
287 self.dataOutObj.flagNoData = False
288 self.dataOutObj.flagResetProcessing = self.flagResetProcessing
290 289
291 self.m_DataObj.data = self.datablock[:,self.profileIndex,:]
290 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
292 291
293 292 self.profileIndex += 1
294 293
295 294 #call setData - to Data Object
296 295
297 return 1 #self.m_DataObj.data
296 return 1 #self.dataOutObj.data
298 297
299 298
300 299 class VoltageWriter(JRODataWriter):
@@ -304,7 +303,7 class VoltageWriter(JRODataWriter):
304 303 """
305 304 __configHeaderFile = 'wrSetHeadet.txt'
306 305
307 m_DataObj = None
306 dataOutObj = None
308 307
309 308 ext = ".r"
310 309
@@ -317,22 +316,22 class VoltageWriter(JRODataWriter):
317 316 shapeBuffer = None
318 317
319 318
320 def __init__(self, m_Voltage=None):
319 def __init__(self, dataOutObj=None):
321 320 """
322 321 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
323 322
324 323 Affected:
325 self.m_DataObj
324 self.dataOutObj
326 325
327 326 Return: None
328 327 """
329 if m_Voltage == None:
330 m_Voltage = Voltage()
328 if dataOutObj == None:
329 dataOutObj = Voltage()
331 330
332 if not( isinstance(m_Voltage, Voltage) ):
333 raise ValueError, "in VoltageReader, m_Voltage must be an Spectra class object"
331 if not( isinstance(dataOutObj, Voltage) ):
332 raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object"
334 333
335 self.m_DataObj = m_Voltage
334 self.dataOutObj = dataOutObj
336 335
337 336
338 337 def hasAllDataInBuffer(self):
@@ -408,16 +407,16 class VoltageWriter(JRODataWriter):
408 407 """
409 408 self.flagIsNewBlock = 0
410 409
411 if self.m_DataObj.flagNoData:
410 if self.dataOutObj.flagNoData:
412 411 return 0
413 412
414 if self.m_DataObj.flagResetProcessing:
413 if self.dataOutObj.flagResetProcessing:
415 414
416 415 self.datablock.fill(0)
417 416 self.profileIndex = 0
418 417 self.setNextFile()
419 418
420 self.datablock[:,self.profileIndex,:] = self.m_DataObj.data
419 self.datablock[:,self.profileIndex,:] = self.dataOutObj.data
421 420
422 421 self.profileIndex += 1
423 422
@@ -32,16 +32,7 class Data:
32 32
33 33 return copy.deepcopy(self)
34 34
35 class Noise(Data):
36 '''
37 classdocs
38 '''
39 35
40 def __init__(self):
41 '''
42 Constructor
43 '''
44 pass
45 36
46 37 class JROData(Data):
47 38 '''
@@ -56,7 +47,7 class JROData(Data):
56 47
57 48 m_BasicHeader = BasicHeader()
58 49
59 m_NoiseObj = Noise()
50 noise = None
60 51
61 52 type = None
62 53
@@ -72,6 +63,10 class JROData(Data):
72 63
73 64 channelList = None
74 65
66 channelIndexList = None
67
68 pairList = None
69
75 70 flagNoData = False
76 71
77 72 flagResetProcessing = False
@@ -101,6 +96,7 class JROData(Data):
101 96 xf = xi + self.m_ProcessingHeader.numHeights*step
102 97
103 98 self.heightList = numpy.arange(xi, xf, step)
99 self.channelIndexList = numpy.arange(self.m_SystemHeader.numChannels)
104 100 self.channelList = numpy.arange(self.m_SystemHeader.numChannels)
105 101
106 102 self.nHeights = len(self.heightList)
@@ -307,6 +307,8 class ProcessingHeader(Header):
307 307 incoherentInt = None
308 308 totalSpectra = None
309 309 struct = None
310 flag_dc = None
311 flag_cspc = None
310 312
311 313 def __init__(self):
312 314 self.size = 0
@@ -343,6 +345,7 class ProcessingHeader(Header):
343 345 self.numBaud = 0
344 346 self.shif_fft = False
345 347 self.flag_dc = False
348 self.flag_cspc = False
346 349
347 350 def read(self, fp):
348 351 try:
@@ -376,6 +379,22 class ProcessingHeader(Header):
376 379
377 380 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
378 381 self.flag_dc = True
382
383 nChannels = 0
384 nPairs = 0
385 pairList = []
386
387 for i in range( 0, self.totalSpectra*2, 2 ):
388 if self.spectraComb[i] == self.spectraComb[i+1]:
389 nChannels = nChannels + 1 #par de canales iguales
390 else:
391 nPairs = nPairs + 1 #par de canales diferentes
392 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
393
394 self.flag_cspc = False
395 if nPairs > 0:
396 self.flag_cspc = True
397
379 398 except:
380 399 return 0
381 400
@@ -5,7 +5,7 Created on Feb 7, 2012
5 5 @version $Id$
6 6 '''
7 7
8 from JROData import JROData, Noise
8 from JROData import JROData
9 9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10 10
11 11 class Spectra(JROData):
@@ -39,8 +39,6 class Spectra(JROData):
39 39
40 40 self.m_BasicHeader = BasicHeader()
41 41
42 self.m_NoiseObj = Noise()
43
44 42 self.type = "Spectra"
45 43
46 44 self.dataType = None
@@ -5,7 +5,7 Created on Feb 7, 2012
5 5 @version $Id$
6 6 '''
7 7
8 from JROData import JROData, Noise
8 from JROData import JROData
9 9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10 10
11 11 class Voltage(JROData):
@@ -32,8 +32,6 class Voltage(JROData):
32 32
33 33 self.m_BasicHeader = BasicHeader()
34 34
35 self.m_NoiseObj = Noise()
36
37 35 self.type = "Voltage"
38 36
39 37 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
@@ -1,7 +1,7
1 1 import numpy
2 2 from Model.Spectra import Spectra
3 3
4 def hildebrand_sekhon(Data, navg=1):
4 def hildebrand_sekhon(Data, navg):
5 5 """
6 6 This method is for the objective determination of de noise level in Doppler spectra. This
7 7 implementation technique is based on the fact that the standard deviation of the spectral
@@ -15,6 +15,7 def hildebrand_sekhon(Data, navg=1):
15 15 -1 : any error
16 16 anoise : noise's level
17 17 """
18
18 19 divisor = 8
19 20 ratio = 7 / divisor
20 21 data = Data.reshape(-1)
@@ -63,50 +64,150 def hildebrand_sekhon(Data, navg=1):
63 64
64 65 return anoise;
65 66
67 def sorting_bruce(Data, navg):
68 sortdata = numpy.sort(Data)
69 lenOfData = len(Data)
70 nums_min = lenOfData/10
71
72 if (lenOfData/10) > 0:
73 nums_min = lenOfData/10
74 else:
75 nums_min = 0
76
77 rtest = 1.0 + 1.0/navg
78
79 sum = 0.
80
81 sumq = 0.
82
83 j = 0
84
85 cont = 1
86
87 while((cont==1)and(j<lenOfData)):
88
89 sum += sortdata[j]
90
91 sumq += sortdata[j]**2
92
93 j += 1
94
95 if j > nums_min:
96 if ((sumq*j) <= (rtest*sum**2)):
97 lnoise = sum / j
98 else:
99 j = j - 1
100 sum = sum - sordata[j]
101 sumq = sumq - sordata[j]**2
102 cont = 0
103
104 if j == nums_min:
105 lnoise = sum /j
106
107 return lnoise
66 108
67 109 class Noise:
68 110 """
69 111 Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler
70 112 """
71 m_DataObj = None
113 data = None
114 noise = None
115 dim = None
72 116
117 def __init__(self, data=None):
118 """
119 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
73 120
74 def __init__(self, m_Spectra=None):
121 Inputs:
122 data: Numpy array de la forma nChan x nHeis x nProfiles
123
124 Affected:
125 self.noise
126
127 Return:
128 None
129 """
130
131 self.data = data
132 self.dim = None
133 self.nChannels = None
134 self.noise = None
135
136 def setNoise(self, data):
75 137 """
76 138 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
77 139
140 Inputs:
141 data: Numpy array de la forma nChan x nHeis x nProfiles
142
78 143 Affected:
79 self.m_DataObj
144 self.noise
80 145
81 146 Return:
82 147 None
83 148 """
84 if m_Spectra == None:
85 m_Spectra = Spectra()
86 149
87 if not(isinstance(m_Spectra, Spectra)):
88 raise ValueError, "in Noise class, m_Spectra must be an Spectra class object"
150 if data == None:
151 return 0
152
153 shape = data.shape
154 self.dim = len(shape)
155 if self.dim == 3:
156 nChan, nProfiles, nHeis = shape
157 elif self.dim == 2:
158 nChan, nHeis = shape
159 else:
160 raise ValueError, ""
89 161
90 self.m_DataObj = m_Spectra
162 self.nChannels = nChan
163 self.data = data.copy()
164 self.noise = numpy.zeros(nChan)
91 165
166 return 1
167
92 168
93 def getNoiseLevelByHildebrandSekhon(self):
169 def byHildebrand(self, navg=1):
94 170 """
95 171 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
96 172
97 173 Return:
98 noise level
174 noiselevel
99 175 """
100 data = self.m_DataObj.data_spc
176
101 177 daux = None
102 178
103 for channel in range(self.m_DataObj.nChannels):
179 for channel in range(self.nChannels):
180 daux = self.data[channel,:,:]
181 self.noise[channel] = hildebrand_sekhon(daux, navg)
182 return self.noise
183
184 def byWindow(self, heiIndexMin, heiIndexMax, freqIndexMin, freqIndexMax):
185 """
186 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
187 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
188
189 Inputs:
190 heiIndexMin: Limite inferior del eje de alturas
191 heiIndexMax: Limite superior del eje de alturas
192 freqIndexMin: Limite inferior del eje de frecuencia
193 freqIndexMax: Limite supoerior del eje de frecuencia
194 """
195
196 data = self.data[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
197
198 for channel in range(self.nChannels):
104 199 daux = data[channel,:,:]
105 noiselevel = hildebrand_sekhon(daux)
106 print noiselevel
200 self.noise[channel] = numpy.average(daux)
107 201
202 return self.noise
203
204 def bySort(self,navg = 1):
205 daux = None
206
207 for channel in range(self.nChannels):
208 daux = self.data[channel,:,:]
209 self.noise[channel] = sorting_bruce(daux, navg)
210
211 return self.noise
108 212
109 for pair in range(self.m_DataObj.nPairs):
110 daux = data[pair,:,:]
111 noiselevel = hildebrand_sekhon(daux)
112 print noiselevel
213 No newline at end of file
@@ -13,7 +13,7 sys.path.append(path)
13 13 from Model.Spectra import Spectra
14 14 from IO.SpectraIO import SpectraWriter
15 15 from Graphics.SpectraPlot import Spectrum
16
16 from JRONoise import Noise
17 17
18 18 class SpectraProcessor:
19 19 '''
@@ -24,13 +24,7 class SpectraProcessor:
24 24
25 25 dataOutObj = None
26 26
27 integratorObjIndex = None
28
29 decoderObjIndex = None
30
31 writerObjIndex = None
32
33 plotterObjIndex = None
27 noiseObj = None
34 28
35 29 integratorObjList = []
36 30
@@ -40,26 +34,34 class SpectraProcessor:
40 34
41 35 plotterObjList = []
42 36
37 integratorObjIndex = None
38
39 decoderObjIndex = None
40
41 writerObjIndex = None
42
43 plotterObjIndex = None
44
43 45 buffer = None
44 46
45 ptsId = 0
47 profIndex = 0
46 48
47 49 nFFTPoints = None
48 50
51 nChannels = None
52
53 nHeights = None
54
55 nPairs = None
56
49 57 pairList = None
50 58
51 59
52 def __init__(self, dataInObj=None, dataOutObj=None):
60 def __init__(self):
53 61 '''
54 62 Constructor
55 63 '''
56 self.dataInObj = dataInObj
57 64
58 if dataOutObj == None:
59 self.dataOutObj = Spectra()
60 else:
61 self.dataOutObj = dataOutObj
62
63 65 self.integratorObjIndex = None
64 66 self.decoderObjIndex = None
65 67 self.writerObjIndex = None
@@ -70,30 +72,79 class SpectraProcessor:
70 72 self.writerObjList = []
71 73 self.plotterObjList = []
72 74
75 self.noiseObj = Noise()
73 76 self.buffer = None
74 self.ptsId = 0
75
76 def setIO(self,inputObject, outputObject):
77
78 # if not( isinstance(inputObject, Voltage) ):
79 # print 'InputObject must be an instance from Voltage()'
80 # sys.exit(0)
77 self.profIndex = 0
81 78
82 if not( isinstance(outputObject, Spectra) ):
83 print 'OutputObject must be an instance from Spectra()'
84 sys.exit(0)
79 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
85 80
86 self.dataInObj = inputObject
87 self.dataOutObj = outputObject
81 if dataInObj == None:
82 raise ValueError, ""
88 83
89 def setup(self,nFFTPoints=None, pairList=None):
90 84 if nFFTPoints == None:
91 nFFTPoints = self.dataOutObj.nFFTPoints
85 raise ValueError, ""
86
87 self.dataInObj = dataInObj
92 88
89 if dataOutObj == None:
90 dataOutObj = Spectra()
91
92 self.dataOutObj = dataOutObj
93 self.noiseObj = Noise()
94
95 ##########################################
93 96 self.nFFTPoints = nFFTPoints
97 self.nChannels = self.dataInObj.nChannels
98 self.nHeights = self.dataInObj.nHeights
94 99 self.pairList = pairList
100 if pairList != None:
101 self.nPairs = len(pairList)
102 else:
103 self.nPairs = 0
104
105 self.dataOutObj.heightList = self.dataInObj.heightList
106 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
107 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
108 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
109 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
110 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
111
112 self.dataOutObj.dataType = self.dataInObj.dataType
113 self.dataOutObj.nPairs = self.nPairs
114 self.dataOutObj.nChannels = self.nChannels
115 self.dataOutObj.nProfiles = self.nFFTPoints
116 self.dataOutObj.nHeights = self.nHeights
117 self.dataOutObj.nFFTPoints = self.nFFTPoints
118 #self.dataOutObj.data = None
119
120 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
121 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
122
123 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
124 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
125 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
126 self.dataOutObj.m_ProcessingHeader.shif_fft = True
127
128 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
129 k = 0
130 for i in range( 0,self.nChannels*2,2 ):
131 spectraComb[i] = k
132 spectraComb[i+1] = k
133 k += 1
134
135 k *= 2
136
137 if self.pairList != None:
138
139 for pair in self.pairList:
140 spectraComb[k] = pair[0]
141 spectraComb[k+1] = pair[1]
142 k += 2
143
144 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
145
146 return self.dataOutObj
95 147
96 # def init(self, nFFTPoints, pairList=None):
97 148 def init(self):
98 149
99 150 self.integratorObjIndex = 0
@@ -101,18 +152,37 class SpectraProcessor:
101 152 self.writerObjIndex = 0
102 153 self.plotterObjIndex = 0
103 154
104 # if nFFTPoints == None:
105 # nFFTPoints = self.dataOutObj.nFFTPoints
106 #
107 # self.nFFTPoints = nFFTPoints
108 # self.pairList = pairList
109 #
110 if not( isinstance(self.dataInObj, Spectra) ):
111 self.__getFft()
112 else:
155 if self.dataInObj.type == "Voltage":
156
157 if self.buffer == None:
158 self.buffer = numpy.zeros((self.nChannels,
159 self.nFFTPoints,
160 self.nHeights),
161 dtype='complex')
162
163 self.buffer[:,self.profIndex,:] = self.dataInObj.data
164 self.profIndex += 1
165
166 if self.profIndex == self.nFFTPoints:
167 self.__getFft()
168 self.dataOutObj.flagNoData = False
169
170 self.buffer = None
171 self.profIndex = 0
172 return
173
174 self.dataOutObj.flagNoData = True
175
176 return
177
178 #Other kind of data
179 if self.dataInObj.type == "Spectra":
113 180 self.dataOutObj.copy(self.dataInObj)
114
115
181 self.dataOutObj.flagNoData = False
182 return
183
184 raise ValueError, "The datatype is not valid"
185
116 186 def __getFft(self):
117 187 """
118 188 Convierte valores de Voltaje a Spectra
@@ -126,7 +196,7 class SpectraProcessor:
126 196 self.dataOutObj.m_ProcessingHeader
127 197 self.dataOutObj.m_RadarControllerHeader
128 198 self.dataOutObj.m_SystemHeader
129 self.ptsId
199 self.profIndex
130 200 self.buffer
131 201 self.dataOutObj.flagNoData
132 202 self.dataOutObj.dataType
@@ -142,20 +212,6 class SpectraProcessor:
142 212 """
143 213 if self.dataInObj.flagNoData:
144 214 return 0
145
146 blocksize = 0
147 nFFTPoints = self.nFFTPoints
148 nChannels, nheis = self.dataInObj.data.shape
149
150 if self.buffer == None:
151 self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex')
152
153 self.buffer[:,self.ptsId,:] = self.dataInObj.data
154 self.ptsId += 1
155
156 if self.ptsId < self.nFFTPoints:
157 self.dataOutObj.flagNoData = True
158 return
159 215
160 216 fft_volt = numpy.fft.fft(self.buffer,axis=1)
161 217 dc = fft_volt[:,0,:]
@@ -164,69 +220,24 class SpectraProcessor:
164 220 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
165 221 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
166 222
223 blocksize = 0
167 224 blocksize += dc.size
168 225 blocksize += spc.size
169 226
170 227 cspc = None
171 nPair = 0
228 pairIndex = 0
172 229 if self.pairList != None:
173 230 #calculo de cross-spectra
174 nPairs = len(self.pairList)
175 cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex')
231 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
176 232 for pair in self.pairList:
177 cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
178 nPair += 1
233 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
234 pairIndex += 1
179 235 blocksize += cspc.size
180 236
181 237 self.dataOutObj.data_spc = spc
182 238 self.dataOutObj.data_cspc = cspc
183 239 self.dataOutObj.data_dc = dc
184
185 self.ptsId = 0
186 self.buffer = None
187 self.dataOutObj.flagNoData = False
188
189 self.dataOutObj.heightList = self.dataInObj.heightList
190 self.dataOutObj.channelList = self.dataInObj.channelList
191 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
192 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
193 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
194 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
195
196 self.dataOutObj.dataType = self.dataInObj.dataType
197 self.dataOutObj.nPairs = nPair
198 self.dataOutObj.nChannels = nChannels
199 self.dataOutObj.nProfiles = nFFTPoints
200 self.dataOutObj.nHeights = nheis
201 self.dataOutObj.nFFTPoints = nFFTPoints
202 #self.dataOutObj.data = None
203
204 self.dataOutObj.m_SystemHeader.numChannels = nChannels
205 self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints
206
207 240 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
208 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair
209 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints
210 self.dataOutObj.m_ProcessingHeader.numHeights = nheis
211 self.dataOutObj.m_ProcessingHeader.shif_fft = True
212
213 spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1'))
214 k = 0
215 for i in range( 0,nChannels*2,2 ):
216 spectraComb[i] = k
217 spectraComb[i+1] = k
218 k += 1
219
220 k *= 2
221
222 if self.pairList != None:
223
224 for pair in self.pairList:
225 spectraComb[k] = pair[0]
226 spectraComb[k+1] = pair[1]
227 k += 2
228
229 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
230 241
231 242
232 243 def addWriter(self,wrpath):
@@ -289,36 +300,93 class SpectraProcessor:
289 300 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
290 301 self.dataOutObj.flagNoData = False
291 302
303 self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
304 # self.getNoise(type="sort", parm=16)
305
292 306 else:
293 307 self.dataOutObj.flagNoData = True
294 308
295 309 self.integratorObjIndex += 1
296
310
311 """Calcular el ruido"""
312 # self.getNoise(type="hildebrand", parm=1)
313
297 314 def removeDC(self, type):
298 315
299 316 if self.dataOutObj.flagNoData:
300 317 return 0
301 pass
302 318
303 319 def removeInterference(self):
304 320
305 321 if self.dataOutObj.flagNoData:
306 322 return 0
307 pass
308 323
309 324 def removeSatellites(self):
310 325
311 326 if self.dataOutObj.flagNoData:
312 327 return 0
313 pass
314 328
315 def selectChannels(self, channelList, pairList=None):
329 def getNoise(self, type="hildebrand", parm=None):
330
331 self.noiseObj.setNoise(self.dataOutObj.data_spc)
332
333 if type == "hildebrand":
334 noise = self.noiseObj.byHildebrand(parm)
335
336 if type == "window":
337 noise = self.noiseObj.byWindow(parm)
338
339 if type == "sort":
340 noise = self.noiseObj.bySort(parm)
341
342 self.dataOutObj.noise = noise
343 print 10*numpy.log10(noise)
344
345 def selectChannels(self, channelList, pairList=[]):
346
347 channelIndexList = []
348
349 for channel in channelList:
350 if channel in self.dataOutObj.channelList:
351 index = self.dataOutObj.channelList.index(channel)
352 channelIndexList.append(index)
353
354 pairIndexList = []
355
356 for pair in pairList:
357 if pair in self.dataOutObj.pairList:
358 index = self.dataOutObj.pairList.index(pair)
359 pairIndexList.append(index)
360
361 self.selectChannelsByIndex(channelIndexList, pairIndexList)
362
363 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
316 364 """
317 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
365 Selecciona un bloque de datos en base a canales y pares segun el
366 channelIndexList y el pairIndexList
318 367
319 368 Input:
320 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
321 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
369 channelIndexList : lista de indices de los canales a seleccionar por ej.
370
371 Si tenemos los canales
372
373 self.channelList = (2,3,5,7)
374
375 y deseamos escoger los canales (3,7)
376 entonces colocaremos el parametro
377
378 channelndexList = (1,3)
379
380 pairIndexList : tupla de indice depares que se desea selecionar por ej.
381
382 Si tenemos los pares :
383
384 ( (0,1), (0,2), (1,3), (2,5) )
385
386 y deseamos seleccionar los pares ((0,2), (2,5))
387 entonces colocaremos el parametro
388
389 pairIndexList = (1,3)
322 390
323 391 Affected:
324 392 self.dataOutObj.data_spc
@@ -329,6 +397,7 class SpectraProcessor:
329 397 self.dataOutObj.m_ProcessingHeader.spectraComb
330 398 self.dataOutObj.m_SystemHeader.numChannels
331 399
400 self.dataOutObj.noise
332 401 Return:
333 402 None
334 403 """
@@ -336,71 +405,35 class SpectraProcessor:
336 405 if self.dataOutObj.flagNoData:
337 406 return 0
338 407
339 channelIndexList = []
340 for channel in channelList:
341 if channel in self.dataOutObj.channelList:
342 index = self.dataOutObj.channelList.index(channel)
343 channelIndexList.append(index)
344 continue
345
346 raise ValueError, "The value %d in channelList is not valid" %channel
347
348 nProfiles = self.dataOutObj.nProfiles
349 #dataType = self.dataOutObj.dataType
350 nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights
351 blocksize = 0
352
353 #self spectra
408 if pairIndexList == []:
409 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
410
354 411 nChannels = len(channelIndexList)
355 spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] )
356
357 for index, channel in enumerate(channelIndexList):
358 spc[index,:,:] = self.dataOutObj.data_spc[index,:,:]
412 nPairs = len(pairIndexList)
359 413
360 #DC channel
361 dc = numpy.zeros( (nChannels,nHeights), dtype='complex' )
362 for index, channel in enumerate(channelIndexList):
363 dc[index,:] = self.dataOutObj.data_dc[channel,:]
364
365 blocksize += dc.size
414 blocksize = 0
415 #self spectra
416 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
366 417 blocksize += spc.size
367
368 nPairs = 0
369 cspc = None
370 418
371 if pairList == None:
372 pairList = self.pairList
373
374 if (pairList != None) and (self.dataOutObj.data_cspc != None):
375 #cross spectra
376 nPairs = len(pairList)
377 cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' )
378
379 spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb
380 totalSpectra = len(spectraComb)
381 nchan = self.dataOutObj.nChannels
382 pairIndexList = []
383
384 for pair in pairList: #busco el par en la lista de pares del Spectra Combinations
385 for index in range(0,totalSpectra,2):
386 if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]:
387 pairIndexList.append( index/2 - nchan )
388
389 for index, pair in enumerate(pairIndexList):
390 cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:]
419 cspc = None
420 if pairIndexList != []:
421 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
391 422 blocksize += cspc.size
392
393 else:
394 pairList = self.pairList
395 cspc = self.dataOutObj.data_cspc
396 if cspc != None:
397 blocksize += cspc.size
398 423
424 #DC channel
425 dc = None
426 if self.dataOutObj.m_ProcessingHeader.flag_dc:
427 dc = self.dataOutObj.data_dc[channelIndexList,:]
428 blocksize += dc.size
429
430 #Almacenar las combinaciones de canales y cros espectros
431
399 432 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
400 433 i = 0
401 for val in channelList:
402 spectraComb[i] = val
403 spectraComb[i+1] = val
434 for spcChannel in channelIndexList:
435 spectraComb[i] = spcChannel
436 spectraComb[i+1] = spcChannel
404 437 i += 2
405 438
406 439 if pairList != None:
@@ -408,21 +441,28 class SpectraProcessor:
408 441 spectraComb[i] = pair[0]
409 442 spectraComb[i+1] = pair[1]
410 443 i += 2
411
444
445 #######
446
412 447 self.dataOutObj.data_spc = spc
413 448 self.dataOutObj.data_cspc = cspc
414 449 self.dataOutObj.data_dc = dc
415 450 self.dataOutObj.nChannels = nChannels
416 451 self.dataOutObj.nPairs = nPairs
417 452
418 self.dataOutObj.channelList = channelList
453 self.dataOutObj.channelIndexList = channelIndexList
419 454
420 455 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
421 456 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
422 457 self.dataOutObj.m_SystemHeader.numChannels = nChannels
423 458 self.dataOutObj.nChannels = nChannels
424 459 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
425
460
461 if cspc == None:
462 self.dataOutObj.m_ProcessingHeader.flag_dc = False
463 if dc == None:
464 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
465
426 466 def selectHeightsByValue(self, minHei, maxHei):
427 467 """
428 468 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
@@ -22,7 +22,7 class VoltageProcessor:
22 22
23 23 dataInObj = None
24 24 dataOutObj = None
25
25
26 26 integratorObjIndex = None
27 27 decoderObjIndex = None
28 28 profSelectorObjIndex = None
@@ -37,17 +37,10 class VoltageProcessor:
37 37 plotterObjList = []
38 38 m_Voltage= Voltage()
39 39
40 def __init__(self, dataInObj=None, dataOutObj=None):
40 def __init__(self):
41 41 '''
42 42 Constructor
43 43 '''
44
45 self.dataInObj = dataInObj
46
47 if dataOutObj == None:
48 self.dataOutObj = Voltage()
49 else:
50 self.dataOutObj = dataOutObj
51 44
52 45 self.integratorObjIndex = None
53 46 self.decoderObjIndex = None
@@ -60,22 +53,20 class VoltageProcessor:
60 53 self.profileSelectorObjList = []
61 54 self.writerObjList = []
62 55 self.plotterObjList = []
63
64 def setIO(self,inputObject, outputObject):
65 56
66 if not( isinstance(inputObject, Voltage) ):
67 print 'InputObject must be an instance from Voltage()'
68 sys.exit(0)
57 def setup(self, dataInObj=None, dataOutObj=None):
69 58
70 if not( isinstance(outputObject, Voltage) ):
71 print 'OutputObject must be an instance from Voltage()'
72 sys.exit(0)
59 self.dataInObj = dataInObj
60
61 if dataOutObj == None:
62 dataOutObj = Voltage()
73 63
74 self.dataInObj = inputObject
75 self.dataOutObj = outputObject
64 dataOutObj.copy(dataInObj)
65
66 self.dataOutObj = dataOutObj
67
68 return self.dataOutObj
76 69
77 def setup(self):
78 pass
79 70
80 71 def init(self):
81 72
@@ -217,15 +208,18 class VoltageProcessor:
217 208 self.flipIndex *= -1.
218 209
219 210 def selectChannels(self, channelList):
211 pass
212
213 def selectChannelsByIndex(self, channelIndexList):
220 214 """
221 Selecciona un bloque de datos en base a canales segun el channelList
215 Selecciona un bloque de datos en base a canales segun el channelIndexList
222 216
223 217 Input:
224 channelList : lista sencilla de canales a seleccionar por ej. [2,3,7]
218 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
225 219
226 220 Affected:
227 221 self.dataOutObj.data
228 self.dataOutObj.channelList
222 self.dataOutObj.channelIndexList
229 223 self.dataOutObj.nChannels
230 224 self.dataOutObj.m_ProcessingHeader.totalSpectra
231 225 self.dataOutObj.m_SystemHeader.numChannels
@@ -237,19 +231,19 class VoltageProcessor:
237 231 if self.dataOutObj.flagNoData:
238 232 return 0
239 233
240 for channel in channelList:
241 if channel not in self.dataOutObj.channelList:
242 raise ValueError, "The value %d in channelList is not valid" %channel
234 for channel in channelIndexList:
235 if channel not in self.dataOutObj.channelIndexList:
236 raise ValueError, "The value %d in channelIndexList is not valid" %channel
243 237
244 nChannels = len(channelList)
238 nChannels = len(channelIndexList)
245 239
246 data = self.dataOutObj.data[channelList,:]
240 data = self.dataOutObj.data[channelIndexList,:]
247 241
248 242 self.dataOutObj.data = data
249 self.dataOutObj.channelList = channelList
243 self.dataOutObj.channelIndexList = channelIndexList
250 244 self.dataOutObj.nChannels = nChannels
251 245
252 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels
246 self.dataOutObj.m_ProcessingHeader.totalSpectra = 0
253 247 self.dataOutObj.m_SystemHeader.numChannels = nChannels
254 248 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
255 249 return 1
@@ -30,29 +30,47 class TestSChain():
30 30
31 31 self.path = "/home/dsuarez/Projects" #1
32 32 self.path = "/Users/jro/Documents/RadarData/EW_Drifts"
33 # self.path = "/Users/jro/Documents/RadarData/JULIA"
33 self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST"
34 34 # self.startDateTime = datetime.datetime(2007,5,1,15,49,0)
35 35 # self.endDateTime = datetime.datetime(2007,5,1,23,0,0)
36 36
37 self.startDateTime = datetime.datetime(2011,10,1,0,0,0)
38 self.endDateTime = datetime.datetime(2011,12,31,0,20,0)
37 self.startDateTime = datetime.datetime(2009,01,1,0,0,0)
38 self.endDateTime = datetime.datetime(2009,01,31,0,20,0)
39
40 # self.startDateTime = datetime.datetime(2011,11,1,0,0,0)
41 # self.endDateTime = datetime.datetime(2011,12,31,0,20,0)
42
43
39 44 self.N = 4
40 45 self.npts = 8
41 46
42 def createObjects( self ):
47 def createObjects( self ):
43 48
44 self.voltObj1 = Voltage()
45 self.voltObj2 = Voltage()
46 self.specObj1 = Spectra()
47
48 self.readerObj = VoltageReader(self.voltObj1)
49 self.voltProcObj = VoltageProcessor(self.voltObj1, self.voltObj2)
50 self.specProcObj = SpectraProcessor(self.voltObj2, self.specObj1)
49 self.readerObj = VoltageReader()
50 self.voltProcObj = VoltageProcessor()
51 self.specProcObj = SpectraProcessor()
51 52
52 if not(self.readerObj.setup( self.path, self.startDateTime, self.endDateTime, expLabel='', online =0) ):
53 voltObj1 = self.readerObj.setup(
54 path = self.path,
55 startDateTime = self.startDateTime,
56 endDateTime = self.endDateTime,
57 expLabel = '',
58 online = 0)
59
60 if not(voltObj1):
53 61 sys.exit(0)
54 62
55 self.specProcObj.setup(nFFTPoints=8)
63 voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1)
64
65 specObj1 = self.specProcObj.setup(dataInObj = voltObj2,
66 nFFTPoints = 16)
67
68 # voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1,
69 # dataOutObj = voltObj2)
70 #
71 # specObj1 = self.specProcObj.setup(dataInObj = voltObj2,
72 # dataOutObj =specObj1,
73 # nFFTPoints=16)
56 74
57 75
58 76 def testSChain( self ):
@@ -63,18 +81,18 class TestSChain():
63 81
64 82 self.voltProcObj.init()
65 83
66 self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1)
67
68 self.voltProcObj.integrator(4)
69
70 self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2)
84 # self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1)
85 #
86 # self.voltProcObj.integrator(4)
87 #
88 # self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2)
89 #
71 90
72
73 91 self.specProcObj.init()
74 92
75 self.specProcObj.integrator(N=2)
93 self.specProcObj.integrator(N=1)
76 94
77 self.specProcObj.plotData(winTitle='Spectra 1', index=3)
95 self.specProcObj.plotData(winTitle='Spectra 1', index=1)
78 96
79 97
80 98 if self.readerObj.flagNoMoreFiles:
General Comments 0
You need to be logged in to leave comments. Login now