##// END OF EJS Templates
Modulo de lectura de espectros corregido y testeado....
Miguel Valdez -
r25:7eaaf56ff468
parent child
Show More
@@ -9,6 +9,141 Created on Feb 7, 2012
9 9 import numpy
10 10 import plplot
11 11
12 def cmap1_init(colormap="gray"):
13
14 ncolor = None
15 rgb_lvl = None
16
17 # Routine for defining a specific color map 1 in HLS space.
18 # if gray is true, use basic grayscale variation from half-dark to light.
19 # otherwise use false color variation from blue (240 deg) to red (360 deg).
20
21 # Independent variable of control points.
22 i = numpy.array((0., 1.))
23 if colormap=="gray":
24 ncolor = 256
25 # Hue for control points. Doesn't matter since saturation is zero.
26 h = numpy.array((0., 0.))
27 # Lightness ranging from half-dark (for interest) to light.
28 l = numpy.array((0.5, 1.))
29 # Gray scale has zero saturation
30 s = numpy.array((0., 0.))
31
32 # number of cmap1 colours is 256 in this case.
33 plplot.plscmap1n(ncolor)
34 # Interpolate between control points to set up cmap1.
35 plplot.plscmap1l(0, i, h, l, s)
36
37 return None
38
39 if colormap=="br_green":
40 ncolor = 256
41 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
42 h = numpy.array((240., 0.))
43 # Lightness and saturation are constant (values taken from C example).
44 l = numpy.array((0.6, 0.6))
45 s = numpy.array((0.8, 0.8))
46
47 # number of cmap1 colours is 256 in this case.
48 plplot.plscmap1n(ncolor)
49 # Interpolate between control points to set up cmap1.
50 plplot.plscmap1l(0, i, h, l, s)
51
52 return None
53
54 if colormap=="tricolor":
55 ncolor = 3
56 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
57 h = numpy.array((240., 0.))
58 # Lightness and saturation are constant (values taken from C example).
59 l = numpy.array((0.6, 0.6))
60 s = numpy.array((0.8, 0.8))
61
62 # number of cmap1 colours is 256 in this case.
63 plplot.plscmap1n(ncolor)
64 # Interpolate between control points to set up cmap1.
65 plplot.plscmap1l(0, i, h, l, s)
66
67 return None
68
69 if colormap == 'rgb' or colormap == 'rgb666':
70
71 color_sz = 6
72 ncolor = color_sz*color_sz*color_sz
73 pos = numpy.zeros((ncolor))
74 r = numpy.zeros((ncolor))
75 g = numpy.zeros((ncolor))
76 b = numpy.zeros((ncolor))
77 ind = 0
78 for ri in range(color_sz):
79 for gi in range(color_sz):
80 for bi in range(color_sz):
81 r[ind] = ri/(color_sz-1.0)
82 g[ind] = gi/(color_sz-1.0)
83 b[ind] = bi/(color_sz-1.0)
84 pos[ind] = ind/(ncolor-1.0)
85 ind += 1
86 rgb_lvl = [6,6,6] #Levels for RGB colors
87
88 if colormap == 'rgb676':
89 ncolor = 6*7*6
90 pos = numpy.zeros((ncolor))
91 r = numpy.zeros((ncolor))
92 g = numpy.zeros((ncolor))
93 b = numpy.zeros((ncolor))
94 ind = 0
95 for ri in range(8):
96 for gi in range(8):
97 for bi in range(4):
98 r[ind] = ri/(6-1.0)
99 g[ind] = gi/(7-1.0)
100 b[ind] = bi/(6-1.0)
101 pos[ind] = ind/(ncolor-1.0)
102 ind += 1
103 rgb_lvl = [6,7,6] #Levels for RGB colors
104
105 if colormap == 'rgb685':
106 ncolor = 6*8*5
107 pos = numpy.zeros((ncolor))
108 r = numpy.zeros((ncolor))
109 g = numpy.zeros((ncolor))
110 b = numpy.zeros((ncolor))
111 ind = 0
112 for ri in range(8):
113 for gi in range(8):
114 for bi in range(4):
115 r[ind] = ri/(6-1.0)
116 g[ind] = gi/(8-1.0)
117 b[ind] = bi/(5-1.0)
118 pos[ind] = ind/(ncolor-1.0)
119 ind += 1
120 rgb_lvl = [6,8,5] #Levels for RGB colors
121
122 if colormap == 'rgb884':
123 ncolor = 8*8*4
124 pos = numpy.zeros((ncolor))
125 r = numpy.zeros((ncolor))
126 g = numpy.zeros((ncolor))
127 b = numpy.zeros((ncolor))
128 ind = 0
129 for ri in range(8):
130 for gi in range(8):
131 for bi in range(4):
132 r[ind] = ri/(8-1.0)
133 g[ind] = gi/(8-1.0)
134 b[ind] = bi/(4-1.0)
135 pos[ind] = ind/(ncolor-1.0)
136 ind += 1
137 rgb_lvl = [8,8,4] #Levels for RGB colors
138
139 if ncolor == None:
140 raise ValueError, "The colormap selected is not valid"
141
142 plplot.plscmap1n(ncolor)
143 plplot.plscmap1l(1, pos, r, g, b)
144
145 return rgb_lvl
146
12 147 class BaseGraph:
13 148 """
14 149
@@ -97,7 +232,6 class BaseGraph:
97 232 data = numpy.arange(256)
98 233 data = numpy.reshape(data, (1,-1))
99 234
100 self.plotBox(xmin, xmax, ymin, ymax)
101 235 plplot.plimage(data,
102 236 float(xmin),
103 237 float(xmax),
@@ -198,6 +332,8 class LinearPlot():
198 332 self.m_BaseGraph = BaseGraph()
199 333 self.m_BaseGraph.setName(key)
200 334
335 self.__subpage = 0
336
201 337 def setColormap(self, colormap="br_green"):
202 338
203 339 if colormap == None:
@@ -308,6 +444,177 class LinearPlot():
308 444
309 445 class ColorPlot():
310 446
447 def __init__(self):
448
449 self.graphObjDict = {}
450
451 self.__subpage = 0
452 self.__showColorbar = False
453 self.__showPowerProfile = True
454
455 self.__szchar = 0.7
456 self.__xrange = None
457 self.__yrange = None
458 self.__zrange = None
459
460 key = "colorplot"
461 self.m_BaseGraph = BaseGraph()
462 self.m_BaseGraph.setName(key)
463
464 def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
465 """
466 """
467
468 self.m_BaseGraph.setOpt("bcnts","bcntsv")
469 self.m_BaseGraph.setup(title,
470 xlabel,
471 ylabel
472 )
473
474 self.__subpage = subpage
475 self.__colormap = colormap
476 self.__showColorbar = showColorbar
477 self.__showPowerProfile = showPowerProfile
478
479 if showColorbar:
480 key = "colorbar"
481
482 cmapObj = BaseGraph()
483 cmapObj.setName(key)
484 cmapObj.setOpt("bc","bcmt")
485 cmapObj.setup(title="dBs",
486 xlabel="",
487 ylabel="",
488 colormap=colormap)
489
490 self.graphObjDict[key] = cmapObj
491
492
493 if showPowerProfile:
494 key = "powerprof"
495
496 powObj = BaseGraph()
497 powObj.setName(key)
498 powObj.setOpt("bcntg","bc")
499 powObj.setup(title="Power Profile",
500 xlabel="dBs",
501 ylabel="")
502
503 self.graphObjDict[key] = powObj
504
505 self.setScreenPos(width='small')
506
507 if XAxisAsTime:
508 self.m_BaseGraph.setXAxisAsTime()
509
510
511
512 def setColormap(self, colormap="br_green"):
513
514 if colormap == None:
515 colormap = self.__colormap
516
517 cmap1_init(colormap)
518
519 def iniSubpage(self):
520
521 if plplot.plgdev() == '':
522 raise ValueError, "Plot device has not been initialize"
523
524 plplot.pladv(self.__subpage)
525 plplot.plschr(0.0, self.__szchar)
526
527 self.setColormap()
528
529 def setScreenPos(self, width='small'):
530
531 if width == 'small':
532 xi = 0.12; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.05; xpoww = 0.26; deltaxcmap = 0.02; deltaxpow = 0.06
533
534 if width == 'medium':
535 xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.05; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06
536
537 if self.__showColorbar:
538 xw -= xcmapw + deltaxcmap
539
540 if self.__showPowerProfile:
541 xw -= xpoww + deltaxpow
542
543 xf = xi + xw
544 yf = yi + yw
545 xcmapf = xf
546
547 self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf])
548
549 if self.__showColorbar:
550 xcmapi = xf + deltaxcmap
551 xcmapf = xcmapi + xcmapw
552
553 key = "colorbar"
554 cmapObj = self.graphObjDict[key]
555 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
556
557 if self.__showPowerProfile:
558
559 xpowi = xcmapf + deltaxpow
560 xpowf = xpowi + xpoww
561
562 key = "powerprof"
563 powObj = self.graphObjDict[key]
564 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
565
566
567
568 def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
569 """
570 Inputs:
571
572 x : Numpy array of dimension 1
573 y : Numpy array of dimension 1
574
575 """
576
577 try:
578 nX, nY = numpy.shape(data)
579 except:
580 raise ValueError, "data is not a numpy array"
581
582 if x == None: x = numpy.arange(nX)
583 if y == None: y = numpy.arange(nY)
584
585 if xmin == None: xmin = x[0]
586 if xmax == None: xmax = x[-1]
587 if ymin == None: ymin = y[0]
588 if ymax == None: ymax = y[-1]
589 if zmin == None: zmin = numpy.nanmin(data)
590 if zmax == None: zmax = numpy.nanmax(data)
591
592 self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax)
593 self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax)
594
595 if self.__showColorbar:
596 key = "colorbar"
597 cmapObj = self.graphObjDict[key]
598 cmapObj.plotBox(0., 1., zmin, zmax)
599 cmapObj.colorbarPlot(0., 1., zmin, zmax)
600
601 if self.__showPowerProfile:
602 power = numpy.average(data, axis=0)
603
604 step = (ymax - ymin)/(nY-1)
605 heis = numpy.arange(ymin, ymax + step, step)
606
607 key = "powerprof"
608 powObj = self.graphObjDict[key]
609
610 plplot.pllsty(2)
611 powObj.plotBox(zmin, zmax, ymin, ymax)
612 plplot.pllsty(1)
613 powObj.basicXYPlot(power, heis)
614
615
616 class ColorPlotX():
617
311 618
312 619 graphObjDict = {}
313 620 showColorbar = False
@@ -325,8 +632,27 class ColorPlot():
325 632 key = "colorplot"
326 633 self.m_BaseGraph.setName(key)
327 634
635 self.__subpage = 0
636
328 637 self.graphObjDict[key] = self.m_BaseGraph
329 638
639 def setColormap(self, colormap="br_green"):
640
641 if colormap == None:
642 colormap = self.__colormap
643
644 cmap1_init(colormap)
645
646 def iniSubpage(self):
647
648 if plplot.plgdev() == '':
649 raise ValueError, "Plot device has not been initialize"
650
651 plplot.pladv(self.__subpage)
652 plplot.plschr(0.0, self.__szchar)
653
654 self.setColormap()
655
330 656 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
331 657 """
332 658 """
@@ -467,137 +793,52 class ColorPlot():
467 793 powObj = self.graphObjDict[key]
468 794 powObj.basicXYPlot(power, heis)
469 795
470 def cmap1_init(colormap="gray"):
471
472 ncolor = None
473 rgb_lvl = None
474
475 # Routine for defining a specific color map 1 in HLS space.
476 # if gray is true, use basic grayscale variation from half-dark to light.
477 # otherwise use false color variation from blue (240 deg) to red (360 deg).
796 if __name__ == '__main__':
478 797
479 # Independent variable of control points.
480 i = numpy.array((0., 1.))
481 if colormap=="gray":
482 ncolor = 256
483 # Hue for control points. Doesn't matter since saturation is zero.
484 h = numpy.array((0., 0.))
485 # Lightness ranging from half-dark (for interest) to light.
486 l = numpy.array((0.5, 1.))
487 # Gray scale has zero saturation
488 s = numpy.array((0., 0.))
489
490 # number of cmap1 colours is 256 in this case.
491 plplot.plscmap1n(ncolor)
492 # Interpolate between control points to set up cmap1.
493 plplot.plscmap1l(0, i, h, l, s)
494
495 return None
798 import numpy
799 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
800 plplot.plsdev("xwin")
801 plplot.plscolbg(255,255,255)
802 plplot.plscol0(1,0,0,0)
803 plplot.plspause(False)
804 plplot.plinit()
805 plplot.plssub(2, 2)
496 806
497 if colormap=="br_green":
498 ncolor = 256
499 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
500 h = numpy.array((240., 0.))
501 # Lightness and saturation are constant (values taken from C example).
502 l = numpy.array((0.6, 0.6))
503 s = numpy.array((0.8, 0.8))
807 nx = 64
808 ny = 100
504 809
505 # number of cmap1 colours is 256 in this case.
506 plplot.plscmap1n(ncolor)
507 # Interpolate between control points to set up cmap1.
508 plplot.plscmap1l(0, i, h, l, s)
810 data = numpy.random.uniform(-50,50,(nx,ny))
509 811
510 return None
812 baseObj = ColorPlot()
813 specObj = ColorPlot()
814 baseObj1 = ColorPlot()
815 specObj1 = ColorPlot()
511 816
512 if colormap=="tricolor":
513 ncolor = 3
514 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
515 h = numpy.array((240., 0.))
516 # Lightness and saturation are constant (values taken from C example).
517 l = numpy.array((0.6, 0.6))
518 s = numpy.array((0.8, 0.8))
817 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True)
818 specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True)
519 819
520 # number of cmap1 colours is 256 in this case.
521 plplot.plscmap1n(ncolor)
522 # Interpolate between control points to set up cmap1.
523 plplot.plscmap1l(0, i, h, l, s)
820 baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True)
821 specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True)
524 822
525 return None
823 data = numpy.random.uniform(-50,50,(nx,ny))
526 824
527 if colormap == 'rgb' or colormap == 'rgb666':
825 plplot.plbop()
826 baseObj.iniSubpage()
827 baseObj.plotData(data)
528 828
529 color_sz = 6
530 ncolor = color_sz*color_sz*color_sz
531 pos = numpy.zeros((ncolor))
532 r = numpy.zeros((ncolor))
533 g = numpy.zeros((ncolor))
534 b = numpy.zeros((ncolor))
535 ind = 0
536 for ri in range(color_sz):
537 for gi in range(color_sz):
538 for bi in range(color_sz):
539 r[ind] = ri/(color_sz-1.0)
540 g[ind] = gi/(color_sz-1.0)
541 b[ind] = bi/(color_sz-1.0)
542 pos[ind] = ind/(ncolor-1.0)
543 ind += 1
544 rgb_lvl = [6,6,6] #Levels for RGB colors
829 specObj.iniSubpage()
830 specObj.plotData(data)
545 831
546 if colormap == 'rgb676':
547 ncolor = 6*7*6
548 pos = numpy.zeros((ncolor))
549 r = numpy.zeros((ncolor))
550 g = numpy.zeros((ncolor))
551 b = numpy.zeros((ncolor))
552 ind = 0
553 for ri in range(8):
554 for gi in range(8):
555 for bi in range(4):
556 r[ind] = ri/(6-1.0)
557 g[ind] = gi/(7-1.0)
558 b[ind] = bi/(6-1.0)
559 pos[ind] = ind/(ncolor-1.0)
560 ind += 1
561 rgb_lvl = [6,7,6] #Levels for RGB colors
832 baseObj1.iniSubpage()
833 baseObj1.plotData(data)
562 834
563 if colormap == 'rgb685':
564 ncolor = 6*8*5
565 pos = numpy.zeros((ncolor))
566 r = numpy.zeros((ncolor))
567 g = numpy.zeros((ncolor))
568 b = numpy.zeros((ncolor))
569 ind = 0
570 for ri in range(8):
571 for gi in range(8):
572 for bi in range(4):
573 r[ind] = ri/(6-1.0)
574 g[ind] = gi/(8-1.0)
575 b[ind] = bi/(5-1.0)
576 pos[ind] = ind/(ncolor-1.0)
577 ind += 1
578 rgb_lvl = [6,8,5] #Levels for RGB colors
835 specObj1.iniSubpage()
836 specObj1.plotData(data)
579 837
580 if colormap == 'rgb884':
581 ncolor = 8*8*4
582 pos = numpy.zeros((ncolor))
583 r = numpy.zeros((ncolor))
584 g = numpy.zeros((ncolor))
585 b = numpy.zeros((ncolor))
586 ind = 0
587 for ri in range(8):
588 for gi in range(8):
589 for bi in range(4):
590 r[ind] = ri/(8-1.0)
591 g[ind] = gi/(8-1.0)
592 b[ind] = bi/(4-1.0)
593 pos[ind] = ind/(ncolor-1.0)
594 ind += 1
595 rgb_lvl = [8,8,4] #Levels for RGB colors
838 plplot.plflush()
596 839
597 if ncolor == None:
598 raise ValueError, "The colormap selected is not valid"
840 plplot.plspause(1)
841 plplot.plend()
842 exit(0)
599 843
600 plplot.plscmap1n(ncolor)
601 plplot.plscmap1l(1, pos, r, g, b)
602 844
603 return rgb_lvl No newline at end of file
@@ -5,230 +5,145 Created on Feb 7, 2012
5 5 @version $Id$
6 6 '''
7 7
8 import os, sys
8 9 import numpy
9 10 import plplot
10 11
11 from BaseGraph import *
12 path = os.path.split(os.getcwd())[0]
13 sys.path.append(path)
12 14
13 class Spectrum:
15 from Graphics.BaseGraph import *
16 from Model.Spectra import Spectra
14 17
15 graphObjDict = {}
16 showColorbar = False
17 showPowerProfile = True
18 class Spectrum():
18 19
19 __szchar = 0.7
20 __xrange = None
21 __yrange = None
22 __zrange = None
23 baseObj = BaseGraph()
20 def __init__(self, Spectra):
24 21
25
26 def __init__(self):
27
28 key = "spec"
29
30 baseObj = BaseGraph()
31 baseObj.setName(key)
32
33 self.graphObjDict[key] = baseObj
34
35
36 def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False):
37 22 """
38 """
39
40 xi = 0.12; xw = 0.78; xf = xi + xw
41 yi = 0.14; yw = 0.80; yf = yi + yw
42
43 xcmapi = xcmapf = 0.; xpowi = xpowf = 0.
44 23
45 key = "spec"
46 baseObj = self.graphObjDict[key]
47 baseObj.setSubpage(subpage)
48 baseObj.setSzchar(self.__szchar)
49 baseObj.setOpt("bcnts","bcnts")
50 baseObj.setup(title,
51 xlabel,
52 ylabel,
53 colormap)
24 Inputs:
54 25
55 if showColorbar:
56 key = "colorbar"
57
58 cmapObj = BaseGraph()
59 cmapObj.setName(key)
60 cmapObj.setSubpage(subpage)
61 cmapObj.setSzchar(self.__szchar)
62 cmapObj.setOpt("bc","bcmt")
63 cmapObj.setup(title="dBs",
64 xlabel="",
65 ylabel="",
66 colormap=colormap)
67
68 self.graphObjDict[key] = cmapObj
69
70 xcmapi = 0.
71 xcmapw = 0.05
72 xw -= xcmapw
73
74 if showPowerProfile:
75 key = "powerprof"
76
77 powObj = BaseGraph()
78 powObj.setName(key)
79 powObj.setSubpage(subpage)
80 powObj.setSzchar(self.__szchar)
81 plplot.pllsty(2)
82 powObj.setOpt("bcntg","bc")
83 plplot.pllsty(1)
84 powObj.setup(title="Power Profile",
85 xlabel="dBs",
86 ylabel="")
26 type: "power" ->> Potencia
27 "iq" ->> Real + Imaginario
28 """
87 29
88 self.graphObjDict[key] = powObj
30 self.__isPlotConfig = False
89 31
90 xpowi = 0.
91 xpoww = 0.24
92 xw -= xpoww
32 self.__isPlotIni = False
93 33
94 xf = xi + xw
95 yf = yi + yw
96 xcmapf = xf
34 self.__xrange = None
97 35
98 baseObj.setScreenPos([xi, xf], [yi, yf])
36 self.__yrange = None
99 37
100 if showColorbar:
101 xcmapi = xf + 0.02
102 xcmapf = xcmapi + xcmapw
103 cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf])
38 self.nGraphs = 0
104 39
105 if showPowerProfile:
106 xpowi = xcmapf + 0.06
107 xpowf = xpowi + xpoww
108 powObj.setScreenPos([xpowi, xpowf], [yi, yf])
40 self.graphObjList = []
109 41
42 self.m_Spectra = Spectra
110 43
111 # baseObj.initSubpage()
112 #
113 # if showColorbar:
114 # cmapObj.initPlot()
115 #
116 # if showPowerProfile:
117 # powObj.initPlot()
118 44
119 self.showColorbar = showColorbar
120 self.showPowerProfile = showPowerProfile
45 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
121 46
122 def setRanges(self, xrange, yrange, zrange):
47 graphObj = ColorPlot()
48 graphObj.setup(subpage,
49 title,
50 xlabel,
51 ylabel,
52 showColorbar=showColorbar,
53 showPowerProfile=showPowerProfile,
54 XAxisAsTime=XAxisAsTime)
123 55
124 key = "spec"
125 baseObj = self.graphObjDict[key]
126 baseObj.setRanges(xrange, yrange, zrange)
56 self.graphObjList.append(graphObj)
127 57
128 keyList = self.graphObjDict.keys()
129 58
130 key = "colorbar"
131 if key in keyList:
132 cmapObj = self.graphObjDict[key]
133 cmapObj.setRanges([0., 1.], zrange)
59 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
134 60
135 key = "powerprof"
136 if key in keyList:
137 powObj = self.graphObjDict[key]
138 powObj.setRanges(zrange, yrange)
61 nChan = int(self.m_Spectra.m_SystemHeader.numChannels)
139 62
140 def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
63 myTitle = ""
64 myXlabel = ""
65 myYlabel = ""
141 66
142 key = "spec"
143 baseObj = self.graphObjDict[key]
144 baseObj.initSubpage()
67 for i in range(nChan):
68 if titleList != None:
69 myTitle = titleList[i]
70 myXlabel = xlabelList[i]
71 myYlabel = ylabelList[i]
145 72
146 if xmin == None:
147 xmin = 0.
73 self.__addGraph(i+1,
74 title=myTitle,
75 xlabel=myXlabel,
76 ylabel=myYlabel,
77 showColorbar=showColorbar,
78 showPowerProfile=showPowerProfile,
79 XAxisAsTime=XAxisAsTime)
148 80
149 if xmax == None:
150 xmax = 1.
81 self.nGraphs = nChan
82 self.__isPlotConfig = True
151 83
152 if ymin == None:
153 ymin = 0.
84 def iniPlot(self):
154 85
155 if ymax == None:
156 ymax = 1.
86 nx = int(numpy.sqrt(self.nGraphs)+1)
87 #ny = int(self.nGraphs/nx)
157 88
158 if zmin == None:
159 zmin = numpy.nanmin(data)
89 plplot.plsetopt("geometry", "%dx%d" %(400*nx, 300*nx))
90 plplot.plsdev("xcairo")
91 plplot.plscolbg(255,255,255)
92 plplot.plscol0(1,0,0,0)
93 plplot.plinit()
94 plplot.plspause(False)
95 plplot.pladv(0)
96 plplot.plssub(nx, nx)
160 97
161 if zmax == None:
162 zmax = numpy.nanmax(data)
98 self.__isPlotIni = True
163 99
164 if not(baseObj.hasRange):
165 self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax])
100 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
166 101
167 baseObj.basicPcolorPlot(data, xmin, xmax, ymin, ymax, baseObj.zrange[0], baseObj.zrange[1])
102 if not(self.__isPlotConfig):
103 self.setup(titleList,
104 xlabelList,
105 ylabelList,
106 showColorbar,
107 showPowerProfile,
108 XAxisAsTime)
168 109
169 if self.showColorbar:
170 key = "colorbar"
171 cmapObj = self.graphObjDict[key]
172 cmapObj.colorbarPlot()
110 if not(self.__isPlotIni):
111 self.iniPlot()
173 112
174 if self.showPowerProfile:
175 power = numpy.average(data, axis=1)
113 data = numpy.log10(self.m_Spectra.data_spc)
176 114
177 step = (ymax - ymin)/(power.shape[0]-1)
178 heis = numpy.arange(ymin, ymax + step, step)
115 nX, nY, nChan = numpy.shape(data)
179 116
180 key = "powerprof"
181 powObj = self.graphObjDict[key]
182 powObj.basicXYPlot(power, heis)
117 x = numpy.arange(nX)
118 y = self.m_Spectra.heights
183 119
184 class CrossSpectrum:
185 graphObjDict = {}
186 showColorbar = False
187 showPowerProfile = True
120 if xmin == None: xmin = x[0]
121 if xmax == None: xmax = x[-1]
122 if ymin == None: ymin = y[0]
123 if ymax == None: ymax = y[-1]
124 if zmin == None: zmin = numpy.nanmin(abs(data))
125 if zmax == None: zmax = numpy.nanmax(abs(data))
188 126
189 __szchar = 0.7
190 __showPhase = False
191 __xrange = None
192 __yrange = None
193 __zrange = None
194 m_BaseGraph= BaseGraph()
127 plplot.plbop()
128 for i in range(self.nGraphs):
129 self.graphObjList[i].iniSubpage()
130 self.graphObjList[i].plotData(data[:,:,i],
131 x,
132 y,
133 xmin=xmin,
134 xmax=xmax,
135 ymin=ymin,
136 ymax=ymax,
137 zmin=zmin,
138 zmax=zmax)
195 139
196 def __init__(self):
197 pass
198 140
199 def setup(self, subpage, title, xlabel, ylabel, colormap, showColorbar, showPowerProfile):
200 pass
141 plplot.plflush()
142 plplot.pleop()
201 143
202 def setRanges(self, xrange, yrange, zrange):
203 pass
144 def end(self):
145 plplot.plend()
204 146
205 def plotData(self, data, xmin, xmax, ymin, ymax, zmin, zmax):
206 pass
207 147
208 148 if __name__ == '__main__':
209
210 import numpy
211 plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2))
212 plplot.plsdev("xcairo")
213 plplot.plscolbg(255,255,255)
214 plplot.plscol0(1,0,0,0)
215 plplot.plinit()
216 plplot.plssub(2, 2)
217
218 nx = 64
219 ny = 100
220
221 data = numpy.random.uniform(-50,50,(nx,ny))
222
223 baseObj = ColorPlot()
224 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False)
225 baseObj.plotData(data)
226
227 data = numpy.random.uniform(-50,50,(nx,ny))
228
229 spec2Obj = ColorPlot()
230 spec2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True)
231 spec2Obj.plotData(data)
232
233 plplot.plend()
234 exit(0) No newline at end of file
149 pass No newline at end of file
@@ -383,11 +383,11 class SpectraReader(DataReader):
383 383
384 384 spc = numpy.fromfile(self.__fp, self.__dataType[0], int(pts2read*Npair_SelfSpectra))
385 385 cspc = numpy.fromfile(self.__fp, self.__dataType, int(pts2read*Npair_CrossSpectra))
386 dc = numpy.fromfile(self.__fp, self.__dataType, int(pts2read*self.m_SystemHeader.numChannels) )
386 dc = numpy.fromfile(self.__fp, self.__dataType, int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
387 387
388 388 spc = spc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_SelfSpectra))
389 389 cspc = cspc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, Npair_CrossSpectra))
390 dc = dc.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels))
390 dc = dc.reshape((self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels))
391 391
392 392 data_spc = spc
393 393 data_cspc = cspc['real'] + cspc['imag']*1j
@@ -84,9 +84,14 class VoltageReader(DataReader):
84 84
85 85 while(True):
86 86
87 readerObj.getData()
87 #to get one profile
88 profile = readerObj.getData()
88 89
89 print readerObj.m_Voltage.data
90 #print the profile
91 print profile
92
93 #If you want to see all datablock
94 print readerObj.datablock
90 95
91 96 if readerObj.noMoreFiles:
92 97 break
@@ -180,9 +185,9 class VoltageReader(DataReader):
180 185
181 186 self.idProfile = 0
182 187
183 self.__buffer = None
188 self.datablock = None
184 189
185 self.__buffer_id = 9999
190 self.datablock_id = 9999
186 191
187 192 def __rdSystemHeader(self,fp=None):
188 193 if fp == None:
@@ -349,9 +354,9 class VoltageReader(DataReader):
349 354
350 355 Variables afectadas:
351 356
352 self.__buffer_id
357 self.datablock_id
353 358
354 self.__buffer
359 self.datablock
355 360
356 361 self.__flagIsNewFile
357 362
@@ -371,9 +376,9 class VoltageReader(DataReader):
371 376
372 377 data = junk['real'] + junk['imag']*1j
373 378
374 self.__buffer_id = 0
379 self.datablock_id = 0
375 380
376 self.__buffer = data
381 self.datablock = data
377 382
378 383 self.__flagIsNewFile = 0
379 384
@@ -384,7 +389,7 class VoltageReader(DataReader):
384 389 self.nReadBlocks += 1
385 390
386 391 def __hasNotDataInBuffer(self):
387 if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock:
392 if self.datablock_id >= self.m_ProcessingHeader.profilesPerBlock:
388 393 return 1
389 394
390 395 return 0
@@ -577,7 +582,7 class VoltageReader(DataReader):
577 582
578 583 Variables afectadas:
579 584 self.m_Voltage
580 self.__buffer_id
585 self.datablock_id
581 586 self.idProfile
582 587
583 588 Excepciones:
@@ -603,21 +608,21 class VoltageReader(DataReader):
603 608
604 609 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
605 610
606 time = self.m_BasicHeader.utc + self.__buffer_id*self.__ippSeconds
611 time = self.m_BasicHeader.utc + self.datablock_id*self.__ippSeconds
607 612 self.m_Voltage.m_BasicHeader.utc = time
608 self.m_Voltage.data = self.__buffer[self.__buffer_id,:,:]
613 self.m_Voltage.data = self.datablock[self.datablock_id,:,:]
609 614 self.m_Voltage.flagNoData = False
610 615 self.m_Voltage.flagResetProcessing = self.flagResetProcessing
611 616
612 617 self.m_Voltage.idProfile = self.idProfile
613 618
614 619
615 self.__buffer_id += 1
620 self.datablock_id += 1
616 621 self.idProfile += 1
617 622
618 623 #call setData - to Data Object
619 624
620 return 1
625 return self.m_Voltage.data
621 626
622 627 class VoltageWriter(DataWriter):
623 628 __configHeaderFile = 'wrSetHeadet.txt'
@@ -641,9 +646,9 class VoltageWriter(DataWriter):
641 646
642 647 self.__flagIsNewFile = 1
643 648
644 self.__buffer = None
649 self.datablock = None
645 650
646 self.__buffer_id = 0
651 self.datablock_id = 0
647 652
648 653 self.__dataType = None
649 654
@@ -757,16 +762,16 class VoltageWriter(DataWriter):
757 762
758 763 data = numpy.zeros(self.__shapeBuffer, self.__dataType)
759 764
760 data['real'] = self.__buffer.real
761 data['imag'] = self.__buffer.imag
765 data['real'] = self.datablock.real
766 data['imag'] = self.datablock.imag
762 767
763 768 data = data.reshape((-1))
764 769
765 770 data.tofile(self.__fp)
766 771
767 self.__buffer.fill(0)
772 self.datablock.fill(0)
768 773
769 self.__buffer_id = 0
774 self.datablock_id = 0
770 775
771 776 self.__flagIsNewFile = 0
772 777
@@ -787,7 +792,7 class VoltageWriter(DataWriter):
787 792 return 1
788 793
789 794 def __hasAllDataInBuffer(self):
790 if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock:
795 if self.datablock_id >= self.m_ProcessingHeader.profilesPerBlock:
791 796 return 1
792 797
793 798 return 0
@@ -801,14 +806,14 class VoltageWriter(DataWriter):
801 806
802 807 if self.m_Voltage.flagResetProcessing:
803 808
804 self.__buffer.fill(0)
809 self.datablock.fill(0)
805 810
806 self.__buffer_id = 0
811 self.datablock_id = 0
807 812 self.__setNextFile()
808 813
809 self.__buffer[self.__buffer_id,:,:] = self.m_Voltage.data
814 self.datablock[self.datablock_id,:,:] = self.m_Voltage.data
810 815
811 self.__buffer_id += 1
816 self.datablock_id += 1
812 817
813 818 if self.__hasAllDataInBuffer():
814 819
@@ -933,7 +938,7 class VoltageWriter(DataWriter):
933 938 self.m_ProcessingHeader.numHeights,
934 939 self.m_SystemHeader.numChannels )
935 940
936 self.__buffer = numpy.zeros(self.__shapeBuffer, numpy.dtype('complex'))
941 self.datablock = numpy.zeros(self.__shapeBuffer, numpy.dtype('complex'))
937 942
938 943 # if not(self.__setNextFile()):
939 944 # return 0
@@ -11,6 +11,10 from Model.Voltage import Voltage
11 11 from IO.VoltageIO import *
12 12 from Graphics.VoltagePlot import Osciloscope
13 13
14 from Model.Spectra import Spectra
15 from IO.SpectraIO import *
16 from Graphics.SpectraPlot import Spectrum
17
14 18 class TestSChain():
15 19
16 20
@@ -25,32 +29,32 class TestSChain():
25 29 self.path = '/home/roj-idl71/Data/RAWDATA/DP_Faraday/'
26 30 self.path = '/Users/danielangelsuarezmunoz/Documents/Projects/testWR'
27 31 self.path = '/home/roj-idl71/Data/RAWDATA/IMAGING'
28 self.path = '/home/roj-idl71/tmp/data'
32 # self.path = '/home/roj-idl71/tmp/data'
29 33 #self.path = '/remote/puma/2004_11/DVD/'
30 34
31 35 self.ppath = "/home/roj-idl71/tmp/data"
32 self.startDateTime = datetime.datetime(2004,5,1,17,49,0)
33 self.endDateTime = datetime.datetime(2012,5,1,18,10,0)
36 self.startDateTime = datetime.datetime(2011,1,1,17,49,0)
37 self.endDateTime = datetime.datetime(2011,1,30,18,10,0)
34 38
35 39 def createObjects(self):
36 40
37 self.voltageObj = Voltage()
38 self.readerObj = VoltageReader(self.voltageObj)
39 self.plotObj = Osciloscope(self.voltageObj)
40 self.writerObj = VoltageWriter(self.voltageObj)
41 self.Obj = Spectra()
42 self.readerObj = SpectraReader(self.Obj)
43 self.plotObj = Spectrum(self.Obj)
44 # self.writerObj = SpectraWriter(self.Obj)
41 45
42 if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime)):
46 if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, expLabel='')):
43 47 sys.exit(0)
44 48
45 if not(self.writerObj.setup(self.ppath)):
46 sys.exit(0)
49 # if not(self.writerObj.setup(self.ppath)):
50 # sys.exit(0)
47 51
48 52 def testSChain(self):
49 53
50 54 ini = time.time()
51 55 while(True):
52 56 self.readerObj.getData()
53 self.plotObj.plotData(idProfile = 1, type='iq', ymin = -100, ymax = 100)
57 self.plotObj.plotData(showColorbar=False, showPowerProfile=True)
54 58
55 59 # self.writerObj.putData()
56 60
@@ -64,10 +68,7 class TestSChain():
64 68 print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini)
65 69 ini = time.time()
66 70
67
68
69
70
71 #time.sleep(0.5)
71 72 self.plotObj.end()
72 73
73 74 if __name__ == '__main__':
General Comments 0
You need to be logged in to leave comments. Login now