@@ -2,6 +2,8 import mpldriver | |||
|
2 | 2 | |
|
3 | 3 | class Figure: |
|
4 | 4 | axesList = None |
|
5 | width = None | |
|
6 | height = None | |
|
5 | 7 | def __init__(self): |
|
6 | 8 | pass |
|
7 | 9 | |
@@ -36,10 +38,12 class Figure: | |||
|
36 | 38 | class Axes: |
|
37 | 39 | firsttime = None |
|
38 | 40 | ax = None |
|
41 | mesh = None | |
|
39 | 42 | |
|
40 | 43 | def __init__(self, ax): |
|
41 | 44 | self.firsttime = True |
|
42 | 45 | self.ax = ax |
|
46 | self.mesh = None | |
|
43 | 47 | |
|
44 | 48 | def pline(self, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title): |
|
45 | 49 | |
@@ -57,5 +61,21 class Axes: | |||
|
57 | 61 | |
|
58 | 62 | self.firsttime = False |
|
59 | 63 | |
|
60 | def pcolor(self): | |
|
61 | pass | |
|
64 | def pcolor(self, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title): | |
|
65 | meshfromaxes=mpldriver.pcolor(ax=self.ax, | |
|
66 | x=x, | |
|
67 | y=y, | |
|
68 | z=z, | |
|
69 | xmin=xmin, | |
|
70 | xmax=xmax, | |
|
71 | ymin=ymin, | |
|
72 | ymax=ymax, | |
|
73 | zmin=zmin, | |
|
74 | zmax=zmax, | |
|
75 | xlabel=xlabel, | |
|
76 | ylabel=ylabel, | |
|
77 | title=title, | |
|
78 | firsttime=self.firsttime, | |
|
79 | mesh=self.mesh) | |
|
80 | self.mesh = meshfromaxes | |
|
81 | self.firsttime = False |
@@ -2,6 +2,7 import matplotlib | |||
|
2 | 2 | matplotlib.use("TKAgg") |
|
3 | 3 | import matplotlib.pyplot |
|
4 | 4 | import scitools.numpyutils |
|
5 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
|
5 | 6 | |
|
6 | 7 | def init(idfigure, wintitle, width, height): |
|
7 | 8 | matplotlib.pyplot.ioff() |
@@ -42,8 +43,32 def draw(idfigure): | |||
|
42 | 43 | fig = matplotlib.pyplot.figure(idfigure) |
|
43 | 44 | fig.canvas.draw() |
|
44 | 45 | |
|
45 | def pcolor(): | |
|
46 | pass | |
|
46 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |
|
47 | if firsttime: | |
|
48 | divider = make_axes_locatable(ax) | |
|
49 | ax_cb = divider.new_horizontal(size="5%", pad=0.05) | |
|
50 | fig1 = ax.get_figure() | |
|
51 | fig1.add_axes(ax_cb) | |
|
52 | ||
|
53 | ax.set_xlim([xmin,xmax]) | |
|
54 | ax.set_ylim([ymin,ymax]) | |
|
55 | ax.set_xlabel(xlabel) | |
|
56 | ax.set_ylabel(ylabel) | |
|
57 | ax.set_title(title) | |
|
58 | ||
|
59 | imesh=ax.pcolormesh(x,y,z,vmin=zmin,vmax=zmax) | |
|
60 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
|
61 | ax_cb.yaxis.tick_right() | |
|
62 | for tl in ax_cb.get_yticklabels(): | |
|
63 | tl.set_visible(True) | |
|
64 | ax_cb.yaxis.tick_right() | |
|
65 | matplotlib.pyplot.tight_layout() | |
|
66 | return imesh | |
|
67 | else: | |
|
68 | tmp = z[0:-1,0:-1] | |
|
69 | mesh.set_array(tmp.ravel()) | |
|
70 | ||
|
71 | return mesh | |
|
47 | 72 | |
|
48 | 73 | |
|
49 | 74 |
@@ -232,7 +232,7 class JRODataIO: | |||
|
232 | 232 | |
|
233 | 233 | raise ValueError, "Not implemented" |
|
234 | 234 | |
|
235 | def getOuput(self): | |
|
235 | def getOutput(self): | |
|
236 | 236 | |
|
237 | 237 | return self.dataOut |
|
238 | 238 |
@@ -2,10 +2,107 import numpy | |||
|
2 | 2 | import datetime |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | class SpectraPlot(Figure): | |
|
6 | __isConfig = None | |
|
7 | ||
|
8 | def __init__(self): | |
|
9 | self.__isConfig = False | |
|
10 | self.width = 850 | |
|
11 | self.height = 800 | |
|
12 | ||
|
13 | def getSubplots(self): | |
|
14 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
|
15 | nrow = int(self.nplots*1./ncol + 0.9) | |
|
16 | return nrow, ncol | |
|
17 | ||
|
18 | ||
|
19 | def setAxesWithOutProfiles(self, nrow, ncol): | |
|
20 | colspan = 1 | |
|
21 | rowspan = 1 | |
|
22 | counter = 0 | |
|
23 | ||
|
24 | for y in range(nrow): | |
|
25 | for x in range(ncol): | |
|
26 | if counter < self.nplots: | |
|
27 | # plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) | |
|
28 | self.makeAxes(nrow, ncol, y, x, colspan, rowspan) | |
|
29 | counter += 1 | |
|
30 | ||
|
31 | def setAxesWithProfiles(self, nrow, ncol): | |
|
32 | colspan = 1 | |
|
33 | rowspan = 1 | |
|
34 | factor = 2 | |
|
35 | ncol = ncol*factor | |
|
36 | counter = 0 | |
|
37 | ||
|
38 | for y in range(nrow): | |
|
39 | for x in range(ncol): | |
|
40 | if counter < self.nplots*factor: | |
|
41 | # plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) | |
|
42 | self.makeAxes(nrow, ncol, y, x, colspan, rowspan) | |
|
43 | counter += 1 | |
|
44 | ||
|
45 | def setup(self, idfigure, wintitle, width, height, nplots, profile): | |
|
46 | self.init(idfigure, wintitle, width, height, nplots) | |
|
47 | ||
|
48 | nrow,ncol = self.getSubplots() | |
|
49 | ||
|
50 | if profile: | |
|
51 | self.setAxesWithProfiles(nrow, ncol) | |
|
52 | else: | |
|
53 | self.setAxesWithOutProfiles(nrow, ncol) | |
|
54 | ||
|
55 | def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, profile=False): | |
|
56 | if dataOut.isEmpty(): | |
|
57 | return None | |
|
58 | ||
|
59 | if channelList == None: | |
|
60 | channelList = dataOut.channelList | |
|
61 | ||
|
62 | nplots = len(channelList) | |
|
63 | ||
|
64 | z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:]) | |
|
65 | ||
|
66 | y = dataOut.heightList | |
|
67 | ||
|
68 | x = numpy.arange(dataOut.nFFTPoints) | |
|
69 | ||
|
70 | if not self.__isConfig: | |
|
71 | self.setup(idfigure=idfigure, | |
|
72 | wintitle=wintitle, | |
|
73 | width=self.width, | |
|
74 | height=self.height, | |
|
75 | nplots=nplots, | |
|
76 | profile=profile) | |
|
77 | ||
|
78 | if xmin == None: self.xmin = numpy.min(x) | |
|
79 | if xmax == None: self.xmax = numpy.max(x) | |
|
80 | if ymin == None: self.ymin = numpy.min(y) | |
|
81 | if ymax == None: self.ymax = numpy.max(y) | |
|
82 | if zmin == None: self.zmin = 0 | |
|
83 | if zmax == None: self.zmax = 90 | |
|
84 | ||
|
85 | self.__isConfig = True | |
|
86 | ||
|
87 | ylabel = "Range[Km]" | |
|
88 | ||
|
89 | xlabel = "m/s" | |
|
90 | ||
|
91 | for i in range(len(self.axesList)): | |
|
92 | title = "Channel %d"%i | |
|
93 | axes = self.axesList[i] | |
|
94 | z2 = z[i,:,:] | |
|
95 | axes.pcolor(x, y, z, self.xmin, self.xmax, self.ymin, self.ymax, self.zmin, self.zmax, xlabel, ylabel, title) | |
|
96 | ||
|
97 | ||
|
98 | self.draw() | |
|
99 | ||
|
100 | ||
|
101 | ||
|
102 | ||
|
103 | ||
|
5 | 104 | class Scope(Figure): |
|
6 | 105 | __isConfig = None |
|
7 | width = None | |
|
8 | height = None | |
|
9 | 106 | |
|
10 | 107 | def __init__(self): |
|
11 | 108 | self.__isConfig = False |
@@ -46,7 +143,7 class Scope(Figure): | |||
|
46 | 143 | |
|
47 | 144 | if not self.__isConfig: |
|
48 | 145 | self.setup(idfigure=idfigure, |
|
49 |
wintitle= |
|
|
146 | wintitle=wintitle, | |
|
50 | 147 | width=self.width, |
|
51 | 148 | height=self.height, |
|
52 | 149 | nplots=nplots) |
@@ -432,4 +432,144 class CohInt(Operation): | |||
|
432 | 432 | dataOut.timeInterval *= self.nCohInt |
|
433 | 433 | dataOut.nCohInt *= self.nCohInt |
|
434 | 434 | dataOut.utctime = avgdatatime |
|
435 | dataOut.flagNoData = False No newline at end of file | |
|
435 | dataOut.flagNoData = False | |
|
436 | ||
|
437 | ||
|
438 | class SpectraProc(ProcessingUnit): | |
|
439 | ||
|
440 | def __init__(self): | |
|
441 | self.objectDict = {} | |
|
442 | self.buffer = None | |
|
443 | self.firstdatatime = None | |
|
444 | self.profIndex = 0 | |
|
445 | self.dataOut = Spectra() | |
|
446 | ||
|
447 | def init(self, nFFTPoints=None, pairsList=None): | |
|
448 | if self.dataIn.type == "Spectra": | |
|
449 | self.dataOut.copy(self.dataIn) | |
|
450 | return | |
|
451 | ||
|
452 | if self.dataIn.type == "Voltage": | |
|
453 | ||
|
454 | if nFFTPoints == None: | |
|
455 | raise ValueError, "This SpectraProc.setup() need nFFTPoints input variable" | |
|
456 | ||
|
457 | if pairsList == None: | |
|
458 | nPairs = 0 | |
|
459 | else: | |
|
460 | nPairs = len(pairsList) | |
|
461 | ||
|
462 | self.dataOut.nFFTPoints = nFFTPoints | |
|
463 | self.dataOut.pairsList = pairsList | |
|
464 | self.dataOut.nPairs = nPairs | |
|
465 | ||
|
466 | if self.buffer == None: | |
|
467 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
|
468 | self.dataOut.nFFTPoints, | |
|
469 | self.dataIn.nHeights), | |
|
470 | dtype='complex') | |
|
471 | ||
|
472 | ||
|
473 | self.buffer[:,self.profIndex,:] = self.dataIn.data | |
|
474 | self.profIndex += 1 | |
|
475 | ||
|
476 | if self.firstdatatime == None: | |
|
477 | self.firstdatatime = self.dataIn.utctime | |
|
478 | ||
|
479 | if self.profIndex == self.dataOut.nFFTPoints: | |
|
480 | self.__updateObjFromInput() | |
|
481 | self.__getFft() | |
|
482 | ||
|
483 | self.dataOut.flagNoData = False | |
|
484 | ||
|
485 | self.buffer = None | |
|
486 | self.firstdatatime = None | |
|
487 | self.profIndex = 0 | |
|
488 | ||
|
489 | return | |
|
490 | ||
|
491 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) | |
|
492 | ||
|
493 | def __updateObjFromInput(self): | |
|
494 | ||
|
495 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
|
496 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
|
497 | self.dataOut.channelList = self.dataIn.channelList | |
|
498 | self.dataOut.heightList = self.dataIn.heightList | |
|
499 | self.dataOut.dtype = self.dataIn.dtype | |
|
500 | self.dataOut.nHeights = self.dataIn.nHeights | |
|
501 | self.dataOut.nChannels = self.dataIn.nChannels | |
|
502 | self.dataOut.nBaud = self.dataIn.nBaud | |
|
503 | self.dataOut.nCode = self.dataIn.nCode | |
|
504 | self.dataOut.code = self.dataIn.code | |
|
505 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
|
506 | self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
|
507 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
|
508 | self.dataOut.utctime = self.firstdatatime | |
|
509 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
|
510 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
|
511 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
|
512 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
|
513 | self.dataOut.nIncohInt = 1 | |
|
514 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
|
515 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints | |
|
516 | ||
|
517 | def __getFft(self): | |
|
518 | """ | |
|
519 | Convierte valores de Voltaje a Spectra | |
|
520 | ||
|
521 | Affected: | |
|
522 | self.dataOut.data_spc | |
|
523 | self.dataOut.data_cspc | |
|
524 | self.dataOut.data_dc | |
|
525 | self.dataOut.heightList | |
|
526 | self.dataOut.m_BasicHeader | |
|
527 | self.dataOut.m_ProcessingHeader | |
|
528 | self.dataOut.radarControllerHeaderObj | |
|
529 | self.dataOut.systemHeaderObj | |
|
530 | self.profIndex | |
|
531 | self.buffer | |
|
532 | self.dataOut.flagNoData | |
|
533 | self.dataOut.dtype | |
|
534 | self.dataOut.nPairs | |
|
535 | self.dataOut.nChannels | |
|
536 | self.dataOut.nProfiles | |
|
537 | self.dataOut.systemHeaderObj.numChannels | |
|
538 | self.dataOut.m_ProcessingHeader.totalSpectra | |
|
539 | self.dataOut.m_ProcessingHeader.profilesPerBlock | |
|
540 | self.dataOut.m_ProcessingHeader.numHeights | |
|
541 | self.dataOut.m_ProcessingHeader.spectraComb | |
|
542 | self.dataOut.m_ProcessingHeader.shif_fft | |
|
543 | """ | |
|
544 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
|
545 | dc = fft_volt[:,0,:] | |
|
546 | ||
|
547 | #calculo de self-spectra | |
|
548 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
|
549 | spc = fft_volt * numpy.conjugate(fft_volt) | |
|
550 | spc = spc.real | |
|
551 | ||
|
552 | blocksize = 0 | |
|
553 | blocksize += dc.size | |
|
554 | blocksize += spc.size | |
|
555 | ||
|
556 | cspc = None | |
|
557 | pairIndex = 0 | |
|
558 | if self.dataOut.pairsList != None: | |
|
559 | #calculo de cross-spectra | |
|
560 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
|
561 | for pair in self.dataOut.pairsList: | |
|
562 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
|
563 | pairIndex += 1 | |
|
564 | blocksize += cspc.size | |
|
565 | ||
|
566 | self.dataOut.data_spc = spc | |
|
567 | self.dataOut.data_cspc = cspc | |
|
568 | self.dataOut.data_dc = dc | |
|
569 | self.dataOut.blockSize = blocksize | |
|
570 | ||
|
571 | ||
|
572 | class IncohInt(Operation): | |
|
573 | ||
|
574 | def __init__(self): | |
|
575 | pass No newline at end of file |
@@ -25,6 +25,14 class Test(): | |||
|
25 | 25 | opConf2 = self.upConfig.addOperation(name="Scope", priority=2, type="other") |
|
26 | 26 | opConf2.addParameter(name="idfigure", value=1) |
|
27 | 27 | |
|
28 | ||
|
29 | self.upConfigSpc = controller.UPConf(id=2, name="spectraproc", type="spectra") | |
|
30 | opConf = self.upConfigSpc.addOperation(name="init", priority=0) | |
|
31 | opConf.addParameter(name="nFFTPoints", value=8) | |
|
32 | ||
|
33 | opConf3 = self.upConfigSpc.addOperation(name="SpectraPlot", priority=1, type="other") | |
|
34 | opConf3.addParameter(name="idfigure", value=2) | |
|
35 | ||
|
28 | 36 | # opConf = self.upConfig.addOperation(name="selectChannels", priority=3) |
|
29 | 37 | # opConf.addParameter(name="channelList", value=[0,1]) |
|
30 | 38 | |
@@ -32,6 +40,7 class Test(): | |||
|
32 | 40 | ######################################### |
|
33 | 41 | self.objR = jrodataIO.VoltageReader() |
|
34 | 42 | self.objP = jroprocessing.VoltageProc() |
|
43 | self.objSpc = jroprocessing.SpectraProc() | |
|
35 | 44 | |
|
36 | 45 | self.objInt = jroprocessing.CohInt() |
|
37 | 46 | |
@@ -41,10 +50,16 class Test(): | |||
|
41 | 50 | |
|
42 | 51 | self.objP.addOperation(self.objScope, opConf2.id) |
|
43 | 52 | |
|
53 | self.objSpcPlot = jroplot.SpectraPlot() | |
|
54 | ||
|
55 | self.objSpc.addOperation(self.objSpcPlot, opConf3.id) | |
|
56 | ||
|
44 | 57 | self.connect(self.objR, self.objP) |
|
45 | 58 | |
|
59 | self.connect(self.objP, self.objSpc) | |
|
60 | ||
|
46 | 61 | def connect(self, obj1, obj2): |
|
47 |
obj2. |
|
|
62 | obj2.setInput(obj1.getOutput()) | |
|
48 | 63 | |
|
49 | 64 | def run(self): |
|
50 | 65 | |
@@ -65,6 +80,14 class Test(): | |||
|
65 | 80 | kwargs[parm.name]=parm.value |
|
66 | 81 | |
|
67 | 82 | self.objP.call(opConf,**kwargs) |
|
83 | ||
|
84 | ############################ | |
|
85 | for opConfSpc in self.upConfigSpc.getOperationObjList(): | |
|
86 | kwargs={} | |
|
87 | for parm in opConfSpc.getParameterObjList(): | |
|
88 | kwargs[parm.name]=parm.value | |
|
89 | ||
|
90 | self.objSpc.call(opConfSpc,**kwargs) | |
|
68 | 91 | |
|
69 | 92 | if self.objR.flagNoMoreFiles: |
|
70 | 93 | break |
General Comments 0
You need to be logged in to leave comments.
Login now