##// END OF EJS Templates
Se agregan las clases para Procesamiento en Alturas: SpectraHeis, sus graficos tambien son agregados en jroplot.py....
Daniel Valdez -
r334:39d6a3ac95d1
parent child
Show More
@@ -0,0 +1,66
1 import os, sys
2
3 path = os.path.split(os.getcwd())[0]
4 sys.path.append(path)
5
6 from controller import *
7
8 desc = "EWDrifts Experiment Test"
9 filename = "ewdrifts.xml"
10
11 controllerObj = Project()
12
13 controllerObj.setup(id = '191', name='test01', description=desc)
14
15 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
16 path='/Volumes/data_e/PaseDelSol/Raw/100KHZ',
17 startDate='2013/02/06',
18 endDate='2013/12/31',
19 startTime='17:30:00',
20 endTime='17:40:59',
21 online=0,
22 walk=1)
23
24 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
25
26 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraHeis', inputId=procUnitConfObj0.getId())
27
28 opObj11 = procUnitConfObj1.addOperation(name='IncohInt4SpectraHeis', optype='other')
29 opObj11.addParameter(name='timeInterval', value='5', format='float')
30
31 opObj11 = procUnitConfObj1.addOperation(name='SpectraHeisScope', optype='other')
32 opObj11.addParameter(name='idfigure', value='10', format='int')
33 opObj11.addParameter(name='wintitle', value='SpectraHeisPlot', format='str')
34 opObj11.addParameter(name='ymin', value='125', format='int')
35 opObj11.addParameter(name='ymax', value='140', format='int')
36 #opObj11.addParameter(name='channelList', value='0,1,2', format='intlist')
37 #opObj11.addParameter(name='showprofile', value='1', format='int')
38 opObj11.addParameter(name='save', value='1', format='bool')
39 opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/sun_pics', format='str')
40
41
42 #opObj11 = procUnitConfObj1.addOperation(name='RTIfromSpectraHeis', optype='other')
43 #opObj11.addParameter(name='idfigure', value='6', format='int')
44 #opObj11.addParameter(name='wintitle', value='RTIPLot', format='str')
45 ##opObj11.addParameter(name='zmin', value='10', format='int')
46 ##opObj11.addParameter(name='zmax', value='40', format='int')
47 #opObj11.addParameter(name='ymin', value='60', format='int')
48 #opObj11.addParameter(name='ymax', value='130', format='int')
49 ##opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
50 #opObj11.addParameter(name='timerange', value='600', format='int')
51 ##opObj11.addParameter(name='showprofile', value='0', format='int')
52 #opObj11.addParameter(name='save', value='1', format='bool')
53 #opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/sun_pics', format='str')
54
55
56
57 print "Escribiendo el archivo XML"
58 controllerObj.writeXml(filename)
59 print "Leyendo el archivo XML"
60 controllerObj.readXml(filename)
61
62 controllerObj.createObjects()
63 controllerObj.connectObjects()
64 controllerObj.run()
65
66 No newline at end of file
@@ -1001,4 +1001,308 class RTIfromNoise(Figure):
1001 1001 self.__isConfig = False
1002 1002 del self.xdata
1003 1003 del self.ydata
1004
1005
1006 class SpectraHeisScope(Figure):
1007
1008
1009 __isConfig = None
1010 __nsubplots = None
1011
1012 WIDTHPROF = None
1013 HEIGHTPROF = None
1014 PREFIX = 'spc'
1015
1016 def __init__(self):
1017
1018 self.__isConfig = False
1019 self.__nsubplots = 1
1020
1021 self.WIDTH = 230
1022 self.HEIGHT = 250
1023 self.WIDTHPROF = 120
1024 self.HEIGHTPROF = 0
1025
1026 def getSubplots(self):
1027
1028 ncol = int(numpy.sqrt(self.nplots)+0.9)
1029 nrow = int(self.nplots*1./ncol + 0.9)
1030
1031 return nrow, ncol
1032
1033 def setup(self, idfigure, nplots, wintitle):
1034
1035 showprofile = False
1036 self.__showprofile = showprofile
1037 self.nplots = nplots
1038
1039 ncolspan = 1
1040 colspan = 1
1041 if showprofile:
1042 ncolspan = 3
1043 colspan = 2
1044 self.__nsubplots = 2
1045
1046 self.createFigure(idfigure = idfigure,
1047 wintitle = wintitle,
1048 widthplot = self.WIDTH + self.WIDTHPROF,
1049 heightplot = self.HEIGHT + self.HEIGHTPROF)
1050
1051 nrow, ncol = self.getSubplots()
1052
1053 counter = 0
1054 for y in range(nrow):
1055 for x in range(ncol):
1056
1057 if counter >= self.nplots:
1058 break
1059
1060 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1061
1062 if showprofile:
1063 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1064
1065 counter += 1
1066
1067 # __isConfig = None
1068 # def __init__(self):
1069 #
1070 # self.__isConfig = False
1071 # self.WIDTH = 600
1072 # self.HEIGHT = 200
1073 #
1074 # def getSubplots(self):
1075 #
1076 # nrow = self.nplots
1077 # ncol = 3
1078 # return nrow, ncol
1079 #
1080 # def setup(self, idfigure, nplots, wintitle):
1081 #
1082 # self.nplots = nplots
1083 #
1084 # self.createFigure(idfigure, wintitle)
1085 #
1086 # nrow,ncol = self.getSubplots()
1087 # colspan = 3
1088 # rowspan = 1
1089 #
1090 # for i in range(nplots):
1091 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1092
1093 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1094 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1095 figpath='./', figfile=None):
1096
1097 """
1098
1099 Input:
1100 dataOut :
1101 idfigure :
1102 wintitle :
1103 channelList :
1104 xmin : None,
1105 xmax : None,
1106 ymin : None,
1107 ymax : None,
1108 """
1109
1110 if channelList == None:
1111 channelIndexList = dataOut.channelIndexList
1112 else:
1113 channelIndexList = []
1114 for channel in channelList:
1115 if channel not in dataOut.channelList:
1116 raise ValueError, "Channel %d is not in dataOut.channelList"
1117 channelIndexList.append(dataOut.channelList.index(channel))
1118
1119 # x = dataOut.heightList
1120 c = 3E8
1121 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1122 #deberia cambiar para el caso de 1Mhz y 100KHz
1123 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1124 x= x/(10000.0)
1125 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1126 # y = y.real
1127 datadB = 10.*numpy.log10(dataOut.data_spc)
1128 y = datadB
1129
1130 thisDatetime = dataOut.datatime
1131 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1132 xlabel = "Frequency"
1133 ylabel = "Intensity (dB)"
1134
1135 if not self.__isConfig:
1136 nplots = len(channelIndexList)
1137
1138 self.setup(idfigure=idfigure,
1139 nplots=nplots,
1140 wintitle=wintitle)
1141
1142 if xmin == None: xmin = numpy.nanmin(x)
1143 if xmax == None: xmax = numpy.nanmax(x)
1144 if ymin == None: ymin = numpy.nanmin(y)
1145 if ymax == None: ymax = numpy.nanmax(y)
1146
1147 self.__isConfig = True
1148
1149 self.setWinTitle(title)
1150
1151 for i in range(len(self.axesList)):
1152 title = "Channel %d" %(i)
1153 axes = self.axesList[i]
1154 ychannel = y[i,:]
1155 axes.pline(x, ychannel,
1156 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1157 xlabel=xlabel, ylabel=ylabel, title=title)
1158
1159 self.draw()
1160
1161 if save:
1162 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1163 if figfile == None:
1164 figfile = self.getFilename(name = date)
1165
1166 self.saveFigure(figpath, figfile)
1167
1168
1169 class RTIfromSpectraHeis(Figure):
1170
1171 __isConfig = None
1172 __nsubplots = None
1173
1174 PREFIX = 'rtinoise'
1175
1176 def __init__(self):
1177
1178 self.timerange = 24*60*60
1179 self.__isConfig = False
1180 self.__nsubplots = 1
1181
1182 self.WIDTH = 820
1183 self.HEIGHT = 200
1184 self.WIDTHPROF = 120
1185 self.HEIGHTPROF = 0
1186 self.xdata = None
1187 self.ydata = None
1188
1189 def getSubplots(self):
1190
1191 ncol = 1
1192 nrow = 1
1193
1194 return nrow, ncol
1195
1196 def setup(self, idfigure, nplots, wintitle, showprofile=True):
1197
1198 self.__showprofile = showprofile
1199 self.nplots = nplots
1200
1201 ncolspan = 7
1202 colspan = 6
1203 self.__nsubplots = 2
1204
1205 self.createFigure(idfigure = idfigure,
1206 wintitle = wintitle,
1207 widthplot = self.WIDTH+self.WIDTHPROF,
1208 heightplot = self.HEIGHT+self.HEIGHTPROF)
1209
1210 nrow, ncol = self.getSubplots()
1211
1212 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1213
1214
1215 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1216 xmin=None, xmax=None, ymin=None, ymax=None,
1217 timerange=None,
1218 save=False, figpath='./', figfile=None):
1219
1220 if channelList == None:
1221 channelIndexList = dataOut.channelIndexList
1222 channelList = dataOut.channelList
1223 else:
1224 channelIndexList = []
1225 for channel in channelList:
1226 if channel not in dataOut.channelList:
1227 raise ValueError, "Channel %d is not in dataOut.channelList"
1228 channelIndexList.append(dataOut.channelList.index(channel))
1229
1230 if timerange != None:
1231 self.timerange = timerange
1232
1233 tmin = None
1234 tmax = None
1235 x = dataOut.getTimeRange()
1236 y = dataOut.getHeiRange()
1237
1238 factor = 1
1239 data = dataOut.data_spc/factor
1240 data = numpy.average(data,axis=1)
1241 datadB = 10*numpy.log10(data)
1242
1243 # factor = dataOut.normFactor
1244 # noise = dataOut.getNoise()/factor
1245 # noisedB = 10*numpy.log10(noise)
1246
1247 thisDatetime = dataOut.datatime
1248 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1249 xlabel = "Local Time"
1250 ylabel = "Intensity (dB)"
1251
1252 if not self.__isConfig:
1253
1254 nplots = 1
1255
1256 self.setup(idfigure=idfigure,
1257 nplots=nplots,
1258 wintitle=wintitle,
1259 showprofile=showprofile)
1260
1261 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1262 if ymin == None: ymin = numpy.nanmin(datadB)
1263 if ymax == None: ymax = numpy.nanmax(datadB)
1264
1265 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1266 self.__isConfig = True
1267
1268 self.xdata = numpy.array([])
1269 self.ydata = numpy.array([])
1270
1271 self.setWinTitle(title)
1272
1273
1274 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
1275
1276 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1277 axes = self.axesList[0]
1278
1279 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1280
1281 if len(self.ydata)==0:
1282 self.ydata = datadB[channelIndexList].reshape(-1,1)
1283 else:
1284 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1285
1286
1287 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1288 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1289 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1290 XAxisAsTime=True
1291 )
1292
1293 self.draw()
1294
1295 if save:
1296
1297 if figfile == None:
1298 figfile = self.getFilename(name = self.name)
1299
1300 self.saveFigure(figpath, figfile)
1301
1302 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1303 self.__isConfig = False
1304 del self.xdata
1305 del self.ydata
1306
1307
1004 1308 No newline at end of file
@@ -1308,3 +1308,309 class ProfileSelector(Operation):
1308 1308
1309 1309 return 0
1310 1310
1311 class SpectraHeisProc(ProcessingUnit):
1312 def __init__(self):
1313 self.objectDict = {}
1314 # self.buffer = None
1315 # self.firstdatatime = None
1316 # self.profIndex = 0
1317 self.dataOut = SpectraHeis()
1318
1319 def __updateObjFromInput(self):
1320 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1321 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1322 self.dataOut.channelList = self.dataIn.channelList
1323 self.dataOut.heightList = self.dataIn.heightList
1324 # self.dataOut.dtype = self.dataIn.dtype
1325 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1326 # self.dataOut.nHeights = self.dataIn.nHeights
1327 # self.dataOut.nChannels = self.dataIn.nChannels
1328 self.dataOut.nBaud = self.dataIn.nBaud
1329 self.dataOut.nCode = self.dataIn.nCode
1330 self.dataOut.code = self.dataIn.code
1331 # self.dataOut.nProfiles = 1
1332 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1333 self.dataOut.nFFTPoints = self.dataIn.nHeights
1334 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1335 # self.dataOut.flagNoData = self.dataIn.flagNoData
1336 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1337 self.dataOut.utctime = self.dataIn.utctime
1338 # self.dataOut.utctime = self.firstdatatime
1339 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1340 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1341 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1342 self.dataOut.nCohInt = self.dataIn.nCohInt
1343 self.dataOut.nIncohInt = 1
1344 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1345 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1346
1347 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1348 # self.dataOut.set=self.dataIn.set
1349 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1350
1351
1352 def __getFft(self):
1353
1354 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1355 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1356 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1357 self.dataOut.data_spc = spc
1358
1359 def init(self):
1360
1361 self.dataOut.flagNoData = True
1362
1363 if self.dataIn.type == "SpectraHeis":
1364 self.dataOut.copy(self.dataIn)
1365 return
1366
1367 if self.dataIn.type == "Voltage":
1368 self.__updateObjFromInput()
1369 self.__getFft()
1370 self.dataOut.flagNoData = False
1371
1372 return
1373
1374 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1375
1376
1377 def selectChannels(self, channelList):
1378
1379 channelIndexList = []
1380
1381 for channel in channelList:
1382 index = self.dataOut.channelList.index(channel)
1383 channelIndexList.append(index)
1384
1385 self.selectChannelsByIndex(channelIndexList)
1386
1387 def selectChannelsByIndex(self, channelIndexList):
1388 """
1389 Selecciona un bloque de datos en base a canales segun el channelIndexList
1390
1391 Input:
1392 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1393
1394 Affected:
1395 self.dataOut.data
1396 self.dataOut.channelIndexList
1397 self.dataOut.nChannels
1398 self.dataOut.m_ProcessingHeader.totalSpectra
1399 self.dataOut.systemHeaderObj.numChannels
1400 self.dataOut.m_ProcessingHeader.blockSize
1401
1402 Return:
1403 None
1404 """
1405
1406 for channelIndex in channelIndexList:
1407 if channelIndex not in self.dataOut.channelIndexList:
1408 print channelIndexList
1409 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1410
1411 nChannels = len(channelIndexList)
1412
1413 data_spc = self.dataOut.data_spc[channelIndexList,:]
1414
1415 self.dataOut.data_spc = data_spc
1416 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1417
1418 return 1
1419
1420 class IncohInt4SpectraHeis(Operation):
1421
1422 __isConfig = False
1423
1424 __profIndex = 0
1425 __withOverapping = False
1426
1427 __byTime = False
1428 __initime = None
1429 __lastdatatime = None
1430 __integrationtime = None
1431
1432 __buffer = None
1433
1434 __dataReady = False
1435
1436 n = None
1437
1438
1439 def __init__(self):
1440
1441 self.__isConfig = False
1442
1443 def setup(self, n=None, timeInterval=None, overlapping=False):
1444 """
1445 Set the parameters of the integration class.
1446
1447 Inputs:
1448
1449 n : Number of coherent integrations
1450 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1451 overlapping :
1452
1453 """
1454
1455 self.__initime = None
1456 self.__lastdatatime = 0
1457 self.__buffer = None
1458 self.__dataReady = False
1459
1460
1461 if n == None and timeInterval == None:
1462 raise ValueError, "n or timeInterval should be specified ..."
1463
1464 if n != None:
1465 self.n = n
1466 self.__byTime = False
1467 else:
1468 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1469 self.n = 9999
1470 self.__byTime = True
1471
1472 if overlapping:
1473 self.__withOverapping = True
1474 self.__buffer = None
1475 else:
1476 self.__withOverapping = False
1477 self.__buffer = 0
1478
1479 self.__profIndex = 0
1480
1481 def putData(self, data):
1482
1483 """
1484 Add a profile to the __buffer and increase in one the __profileIndex
1485
1486 """
1487
1488 if not self.__withOverapping:
1489 self.__buffer += data.copy()
1490 self.__profIndex += 1
1491 return
1492
1493 #Overlapping data
1494 nChannels, nHeis = data.shape
1495 data = numpy.reshape(data, (1, nChannels, nHeis))
1496
1497 #If the buffer is empty then it takes the data value
1498 if self.__buffer == None:
1499 self.__buffer = data
1500 self.__profIndex += 1
1501 return
1502
1503 #If the buffer length is lower than n then stakcing the data value
1504 if self.__profIndex < self.n:
1505 self.__buffer = numpy.vstack((self.__buffer, data))
1506 self.__profIndex += 1
1507 return
1508
1509 #If the buffer length is equal to n then replacing the last buffer value with the data value
1510 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1511 self.__buffer[self.n-1] = data
1512 self.__profIndex = self.n
1513 return
1514
1515
1516 def pushData(self):
1517 """
1518 Return the sum of the last profiles and the profiles used in the sum.
1519
1520 Affected:
1521
1522 self.__profileIndex
1523
1524 """
1525
1526 if not self.__withOverapping:
1527 data = self.__buffer
1528 n = self.__profIndex
1529
1530 self.__buffer = 0
1531 self.__profIndex = 0
1532
1533 return data, n
1534
1535 #Integration with Overlapping
1536 data = numpy.sum(self.__buffer, axis=0)
1537 n = self.__profIndex
1538
1539 return data, n
1540
1541 def byProfiles(self, data):
1542
1543 self.__dataReady = False
1544 avgdata = None
1545 n = None
1546
1547 self.putData(data)
1548
1549 if self.__profIndex == self.n:
1550
1551 avgdata, n = self.pushData()
1552 self.__dataReady = True
1553
1554 return avgdata
1555
1556 def byTime(self, data, datatime):
1557
1558 self.__dataReady = False
1559 avgdata = None
1560 n = None
1561
1562 self.putData(data)
1563
1564 if (datatime - self.__initime) >= self.__integrationtime:
1565 avgdata, n = self.pushData()
1566 self.n = n
1567 self.__dataReady = True
1568
1569 return avgdata
1570
1571 def integrate(self, data, datatime=None):
1572
1573 if self.__initime == None:
1574 self.__initime = datatime
1575
1576 if self.__byTime:
1577 avgdata = self.byTime(data, datatime)
1578 else:
1579 avgdata = self.byProfiles(data)
1580
1581
1582 self.__lastdatatime = datatime
1583
1584 if avgdata == None:
1585 return None, None
1586
1587 avgdatatime = self.__initime
1588
1589 deltatime = datatime -self.__lastdatatime
1590
1591 if not self.__withOverapping:
1592 self.__initime = datatime
1593 else:
1594 self.__initime += deltatime
1595
1596 return avgdata, avgdatatime
1597
1598 def run(self, dataOut, **kwargs):
1599
1600 if not self.__isConfig:
1601 self.setup(**kwargs)
1602 self.__isConfig = True
1603
1604 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1605
1606 # dataOut.timeInterval *= n
1607 dataOut.flagNoData = True
1608
1609 if self.__dataReady:
1610 dataOut.data_spc = avgdata
1611 dataOut.nIncohInt *= self.n
1612 # dataOut.nCohInt *= self.n
1613 dataOut.utctime = avgdatatime
1614 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1615 # dataOut.timeInterval = self.__timeInterval*self.n
1616 dataOut.flagNoData = False No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now