@@ -1,178 +1,178 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | import datetime |
|
11 | 11 | import plplot |
|
12 | 12 | |
|
13 | 13 | path = os.path.split(os.getcwd())[0] |
|
14 | 14 | sys.path.append(path) |
|
15 | 15 | |
|
16 | 16 | from Graphics.BaseGraph import * |
|
17 | 17 | from Model.Spectra import Spectra |
|
18 | 18 | |
|
19 | 19 | class Spectrum(): |
|
20 | 20 | |
|
21 | 21 | def __init__(self, Spectra, index=0): |
|
22 | 22 | |
|
23 | 23 | """ |
|
24 | 24 | |
|
25 | 25 | Inputs: |
|
26 | 26 | |
|
27 | 27 | type: "power" ->> Potencia |
|
28 | 28 | "iq" ->> Real + Imaginario |
|
29 | 29 | """ |
|
30 | 30 | |
|
31 | 31 | self.__isPlotConfig = False |
|
32 | 32 | |
|
33 | 33 | self.__isPlotIni = False |
|
34 | 34 | |
|
35 | 35 | self.__xrange = None |
|
36 | 36 | |
|
37 | 37 | self.__yrange = None |
|
38 | 38 | |
|
39 | 39 | self.nGraphs = 0 |
|
40 | 40 | |
|
41 | 41 | self.indexPlot = index |
|
42 | 42 | |
|
43 | 43 | self.graphObjList = [] |
|
44 | 44 | |
|
45 | 45 | self.m_Spectra = Spectra |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): |
|
49 | 49 | |
|
50 | 50 | graphObj = ColorPlot() |
|
51 | 51 | graphObj.setup(subpage, |
|
52 | 52 | title, |
|
53 | 53 | xlabel, |
|
54 | 54 | ylabel, |
|
55 | 55 | showColorbar=showColorbar, |
|
56 | 56 | showPowerProfile=showPowerProfile, |
|
57 | 57 | XAxisAsTime=XAxisAsTime) |
|
58 | 58 | |
|
59 | 59 | self.graphObjList.append(graphObj) |
|
60 | 60 | |
|
61 | 61 | |
|
62 | 62 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): |
|
63 | 63 | |
|
64 | 64 | nChan = int(self.m_Spectra.m_SystemHeader.numChannels) |
|
65 | 65 | channels = range(nChan) |
|
66 | 66 | |
|
67 | 67 | myXlabel = "Radial Velocity (m/s)" |
|
68 | 68 | myYlabel = "Range (km)" |
|
69 | 69 | |
|
70 | 70 | for i in channels: |
|
71 | 71 | if titleList != None: |
|
72 | 72 | myTitle = titleList[i] |
|
73 | 73 | myXlabel = xlabelList[i] |
|
74 | 74 | myYlabel = ylabelList[i] |
|
75 | 75 | |
|
76 | 76 | # if self.m_Spectra.m_NoiseObj != None: |
|
77 | 77 | # noise = '%4.2fdB' %(self.m_Spectra.m_NoiseObj[i]) |
|
78 | 78 | # else: |
|
79 | 79 | noise = '--' |
|
80 | 80 | |
|
81 | 81 | myTitle = "Channel: %d - Noise: %s" %(i, noise) |
|
82 | 82 | |
|
83 | 83 | self.__addGraph(i+1, |
|
84 | 84 | title=myTitle, |
|
85 | 85 | xlabel=myXlabel, |
|
86 | 86 | ylabel=myYlabel, |
|
87 | 87 | showColorbar=showColorbar, |
|
88 | 88 | showPowerProfile=showPowerProfile, |
|
89 | 89 | XAxisAsTime=XAxisAsTime) |
|
90 | 90 | |
|
91 | 91 | self.nGraphs = nChan |
|
92 | 92 | self.__isPlotConfig = True |
|
93 | 93 | |
|
94 | 94 | def iniPlot(self, winTitle=""): |
|
95 | 95 | |
|
96 | 96 | nx = int(numpy.sqrt(self.nGraphs)+1) |
|
97 | 97 | #ny = int(self.nGraphs/nx) |
|
98 | 98 | |
|
99 | 99 | plplot.plsstrm(self.indexPlot) |
|
100 | 100 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) |
|
101 | 101 | plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx)) |
|
102 | 102 | plplot.plsdev("xwin") |
|
103 | 103 | plplot.plscolbg(255,255,255) |
|
104 | 104 | plplot.plscol0(1,0,0,0) |
|
105 | 105 | plplot.plinit() |
|
106 | 106 | plplot.plspause(False) |
|
107 | 107 | plplot.pladv(0) |
|
108 | 108 | plplot.plssub(nx, nx) |
|
109 | 109 | |
|
110 | 110 | self.__nx = nx |
|
111 | 111 | self.__ny = nx |
|
112 | 112 | self.__isPlotIni = True |
|
113 | 113 | |
|
114 | 114 | |
|
115 | 115 | 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, winTitle="Spectra"): |
|
116 | 116 | |
|
117 | 117 | if not(self.__isPlotConfig): |
|
118 | 118 | self.setup(titleList, |
|
119 | 119 | xlabelList, |
|
120 | 120 | ylabelList, |
|
121 | 121 | showColorbar, |
|
122 | 122 | showPowerProfile, |
|
123 | 123 | XAxisAsTime) |
|
124 | 124 | |
|
125 | 125 | if not(self.__isPlotIni): |
|
126 | 126 | self.iniPlot(winTitle) |
|
127 | 127 | |
|
128 | 128 | plplot.plsstrm(self.indexPlot) |
|
129 | 129 | |
|
130 | 130 | data = 10.*numpy.log10(self.m_Spectra.data_spc) |
|
131 | 131 | |
|
132 | 132 | #data.shape = Channels x Heights x Profiles |
|
133 | data = numpy.transpose( data, (0,2,1) ) | |
|
133 | # data = numpy.transpose( data, (0,2,1) ) | |
|
134 | 134 | #data.shape = Channels x Profiles x Heights |
|
135 | 135 | |
|
136 | 136 | nChan, nX, nY = numpy.shape(data) |
|
137 | 137 | |
|
138 | 138 | x = numpy.arange(nX) |
|
139 | 139 | y = self.m_Spectra.heights |
|
140 | 140 | |
|
141 | 141 | thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc) |
|
142 | 142 | txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
143 | 143 | |
|
144 | 144 | if xmin == None: xmin = x[0] |
|
145 | 145 | if xmax == None: xmax = x[-1] |
|
146 | 146 | if ymin == None: ymin = y[0] |
|
147 | 147 | if ymax == None: ymax = y[-1] |
|
148 | 148 | if zmin == None: zmin = numpy.nanmin(abs(data)) |
|
149 | 149 | if zmax == None: zmax = numpy.nanmax(abs(data)) |
|
150 | 150 | |
|
151 | 151 | plplot.plbop() |
|
152 | 152 | |
|
153 | 153 | plplot.plssub(self.__nx, self.__ny) |
|
154 | 154 | for i in range(self.nGraphs): |
|
155 | 155 | self.graphObjList[i].iniSubpage() |
|
156 | 156 | self.graphObjList[i].plotData(data[i,:,:], |
|
157 | 157 | x, |
|
158 | 158 | y, |
|
159 | 159 | xmin=xmin, |
|
160 | 160 | xmax=xmax, |
|
161 | 161 | ymin=ymin, |
|
162 | 162 | ymax=ymax, |
|
163 | 163 | zmin=zmin, |
|
164 | 164 | zmax=zmax) |
|
165 | 165 | |
|
166 | 166 | plplot.plssub(1,0) |
|
167 | 167 | plplot.pladv(0) |
|
168 | 168 | plplot.plvpor(0., 1., 0., 1.) |
|
169 | 169 | plplot.plmtex("t",-1., 0.5, 0.5, txtDate) |
|
170 | 170 | plplot.plflush() |
|
171 | 171 | plplot.pleop() |
|
172 | 172 | |
|
173 | 173 | def end(self): |
|
174 | 174 | plplot.plend() |
|
175 | 175 | |
|
176 | 176 | |
|
177 | 177 | if __name__ == '__main__': |
|
178 | 178 | pass No newline at end of file |
@@ -1,182 +1,182 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | import numpy |
|
9 | 9 | import plplot |
|
10 | 10 | |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Graphics.BaseGraph import * |
|
15 | 15 | from Model.Voltage import Voltage |
|
16 | 16 | |
|
17 | 17 | class Osciloscope(): |
|
18 | 18 | |
|
19 | 19 | def __init__(self, Voltage, index=0): |
|
20 | 20 | |
|
21 | 21 | """ |
|
22 | 22 | |
|
23 | 23 | Inputs: |
|
24 | 24 | |
|
25 | 25 | type: "power" ->> Potencia |
|
26 | 26 | "iq" ->> Real + Imaginario |
|
27 | 27 | """ |
|
28 | 28 | |
|
29 | 29 | self.__isPlotConfig = False |
|
30 | 30 | |
|
31 | 31 | self.__isPlotIni = False |
|
32 | 32 | |
|
33 | 33 | self.__xrange = None |
|
34 | 34 | |
|
35 | 35 | self.__yrange = None |
|
36 | 36 | |
|
37 | 37 | self.m_Voltage = None |
|
38 | 38 | |
|
39 | 39 | self.nGraphs = 0 |
|
40 | 40 | |
|
41 | 41 | self.indexPlot = index |
|
42 | 42 | |
|
43 | 43 | self.graphObjList = [] |
|
44 | 44 | |
|
45 | 45 | self.m_Voltage = Voltage |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): |
|
49 | 49 | |
|
50 | 50 | graphObj = LinearPlot() |
|
51 | 51 | graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) |
|
52 | 52 | #graphObj.setScreenPos() |
|
53 | 53 | |
|
54 | 54 | self.graphObjList.append(graphObj) |
|
55 | 55 | |
|
56 | 56 | del graphObj |
|
57 | 57 | |
|
58 | 58 | # def setXRange(self, xmin, xmax): |
|
59 | 59 | # self.__xrange = (xmin, xmax) |
|
60 | 60 | # |
|
61 | 61 | # def setYRange(self, ymin, ymax): |
|
62 | 62 | # self.__yrange = (ymin, ymax) |
|
63 | 63 | |
|
64 | 64 | |
|
65 | 65 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): |
|
66 | 66 | |
|
67 | 67 | nChan = int(self.m_Voltage.m_SystemHeader.numChannels) |
|
68 | 68 | |
|
69 | 69 | myTitle = "" |
|
70 | 70 | myXlabel = "" |
|
71 | 71 | myYlabel = "" |
|
72 | 72 | |
|
73 |
for |
|
|
73 | for chan in range(nChan): | |
|
74 | 74 | if titleList != None: |
|
75 |
myTitle = titleList[ |
|
|
76 |
myXlabel = xlabelList[ |
|
|
77 |
myYlabel = ylabelList[ |
|
|
75 | myTitle = titleList[chan] | |
|
76 | myXlabel = xlabelList[chan] | |
|
77 | myYlabel = ylabelList[chan] | |
|
78 | 78 | |
|
79 |
self.__addGraph( |
|
|
79 | self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) | |
|
80 | 80 | |
|
81 | 81 | self.nGraphs = nChan |
|
82 | 82 | self.__isPlotConfig = True |
|
83 | 83 | |
|
84 | 84 | def iniPlot(self, winTitle=""): |
|
85 | 85 | |
|
86 | 86 | plplot.plsstrm(self.indexPlot) |
|
87 | 87 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) |
|
88 | 88 | plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) |
|
89 | 89 | plplot.plsdev("xwin") |
|
90 | 90 | plplot.plscolbg(255,255,255) |
|
91 | 91 | plplot.plscol0(1,0,0,0) |
|
92 | 92 | plplot.plinit() |
|
93 | 93 | plplot.plspause(False) |
|
94 | 94 | plplot.plssub(1, self.nGraphs) |
|
95 | 95 | |
|
96 | 96 | self.__isPlotIni = True |
|
97 | 97 | |
|
98 | 98 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): |
|
99 | 99 | |
|
100 | 100 | if idProfile != None and idProfile != self.m_Voltage.idProfile: |
|
101 | 101 | return |
|
102 | 102 | |
|
103 | 103 | if not(self.__isPlotConfig): |
|
104 | 104 | self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) |
|
105 | 105 | |
|
106 | 106 | if not(self.__isPlotIni): |
|
107 | 107 | self.iniPlot(winTitle) |
|
108 | 108 | |
|
109 | 109 | plplot.plsstrm(self.indexPlot) |
|
110 | 110 | |
|
111 | 111 | data = self.m_Voltage.data |
|
112 | 112 | |
|
113 | 113 | x = self.m_Voltage.heights |
|
114 | 114 | |
|
115 | 115 | if xmin == None: xmin = x[0] |
|
116 | 116 | if xmax == None: xmax = x[-1] |
|
117 | 117 | if ymin == None: ymin = numpy.nanmin(abs(data)) |
|
118 | 118 | if ymax == None: ymax = numpy.nanmax(abs(data)) |
|
119 | 119 | |
|
120 | 120 | plplot.plbop() |
|
121 |
for |
|
|
122 |
y = data[: |
|
|
121 | for chan in range(self.nGraphs): | |
|
122 | y = data[chan,:] | |
|
123 | 123 | |
|
124 |
self.graphObjList[ |
|
|
125 |
self.graphObjList[ |
|
|
124 | self.graphObjList[chan].iniSubpage() | |
|
125 | self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) | |
|
126 | 126 | |
|
127 | 127 | plplot.plflush() |
|
128 | 128 | plplot.pleop() |
|
129 | 129 | |
|
130 | 130 | def end(self): |
|
131 | 131 | plplot.plend() |
|
132 | 132 | |
|
133 | 133 | class VoltagePlot(object): |
|
134 | 134 | ''' |
|
135 | 135 | classdocs |
|
136 | 136 | ''' |
|
137 | 137 | |
|
138 | 138 | __m_Voltage = None |
|
139 | 139 | |
|
140 | 140 | def __init__(self, m_Voltage): |
|
141 | 141 | ''' |
|
142 | 142 | Constructor |
|
143 | 143 | ''' |
|
144 | 144 | self.__m_Voltage = m_Voltage |
|
145 | 145 | |
|
146 | 146 | def setup(self): |
|
147 | 147 | pass |
|
148 | 148 | |
|
149 | 149 | def addGraph(self, type, xrange=None, yrange=None, zrange=None): |
|
150 | 150 | pass |
|
151 | 151 | |
|
152 | 152 | def plotData(self): |
|
153 | 153 | pass |
|
154 | 154 | |
|
155 | 155 | if __name__ == '__main__': |
|
156 | 156 | |
|
157 | 157 | import numpy |
|
158 | 158 | |
|
159 | 159 | plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) |
|
160 | 160 | plplot.plsdev("xcairo") |
|
161 | 161 | plplot.plscolbg(255,255,255) |
|
162 | 162 | plplot.plscol0(1,0,0,0) |
|
163 | 163 | plplot.plinit() |
|
164 | 164 | plplot.plssub(1, 2) |
|
165 | 165 | |
|
166 | 166 | nx = 64 |
|
167 | 167 | ny = 100 |
|
168 | 168 | |
|
169 | 169 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
170 | 170 | |
|
171 | 171 | baseObj = RTI() |
|
172 | 172 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) |
|
173 | 173 | baseObj.plotData(data) |
|
174 | 174 | |
|
175 | 175 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
176 | 176 | |
|
177 | 177 | base2Obj = RTI() |
|
178 | 178 | base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) |
|
179 | 179 | base2Obj.plotData(data) |
|
180 | 180 | |
|
181 | 181 | plplot.plend() |
|
182 | 182 | exit(0) No newline at end of file |
@@ -1,392 +1,398 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 23/01/2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | import glob |
|
11 | 11 | import fnmatch |
|
12 | 12 | import time, datetime |
|
13 | 13 | |
|
14 | 14 | path = os.path.split(os.getcwd())[0] |
|
15 | 15 | sys.path.append(path) |
|
16 | 16 | |
|
17 | 17 | from Model.JROHeader import * |
|
18 | 18 | from Model.Voltage import Voltage |
|
19 | 19 | |
|
20 | 20 | from IO.DataIO import JRODataReader |
|
21 | 21 | from IO.DataIO import JRODataWriter |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | class VoltageReader(JRODataReader): |
|
25 | 25 | """ |
|
26 | 26 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
27 | 27 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
28 | 28 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
29 | 29 | |
|
30 | 30 | perfiles * alturas * canales |
|
31 | 31 | |
|
32 | 32 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
33 | 33 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
34 | 34 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
35 | 35 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
36 | 36 | |
|
37 | 37 | Example: |
|
38 | 38 | |
|
39 | 39 | dpath = "/home/myuser/data" |
|
40 | 40 | |
|
41 | 41 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
42 | 42 | |
|
43 | 43 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
44 | 44 | |
|
45 | 45 | readerObj = VoltageReader() |
|
46 | 46 | |
|
47 | 47 | readerObj.setup(dpath, startTime, endTime) |
|
48 | 48 | |
|
49 | 49 | while(True): |
|
50 | 50 | |
|
51 | 51 | #to get one profile |
|
52 | 52 | profile = readerObj.getData() |
|
53 | 53 | |
|
54 | 54 | #print the profile |
|
55 | 55 | print profile |
|
56 | 56 | |
|
57 | 57 | #If you want to see all datablock |
|
58 | 58 | print readerObj.datablock |
|
59 | 59 | |
|
60 | 60 | if readerObj.flagNoMoreFiles: |
|
61 | 61 | break |
|
62 | 62 | |
|
63 | 63 | """ |
|
64 | 64 | m_DataObj = None |
|
65 | 65 | |
|
66 | 66 | idProfile = 0 |
|
67 | 67 | |
|
68 | 68 | datablock = None |
|
69 | 69 | |
|
70 | 70 | pts2read = 0 |
|
71 | 71 | |
|
72 | 72 | utc = 0 |
|
73 | 73 | |
|
74 | 74 | ext = ".r" |
|
75 | 75 | |
|
76 | 76 | optchar = "D" |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | def __init__(self, m_Voltage=None): |
|
80 | 80 | """ |
|
81 | 81 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
82 | 82 | |
|
83 | 83 | Input: |
|
84 | 84 | m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
85 | 85 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
86 | 86 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
87 | 87 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
88 | 88 | bloque de datos. |
|
89 | 89 | Si este parametro no es pasado se creara uno internamente. |
|
90 | 90 | |
|
91 | 91 | Variables afectadas: |
|
92 | 92 | self.m_DataObj |
|
93 | 93 | |
|
94 | 94 | Return: |
|
95 | 95 | None |
|
96 | 96 | """ |
|
97 | 97 | if m_Voltage == None: |
|
98 | 98 | m_Voltage = Voltage() |
|
99 | 99 | |
|
100 | 100 | if not(isinstance(m_Voltage, Voltage)): |
|
101 | 101 | raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object" |
|
102 | 102 | |
|
103 | 103 | self.m_DataObj = m_Voltage |
|
104 | 104 | |
|
105 | 105 | |
|
106 | 106 | def __hasNotDataInBuffer(self): |
|
107 | 107 | if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock: |
|
108 | 108 | return 1 |
|
109 | 109 | return 0 |
|
110 | 110 | |
|
111 | 111 | |
|
112 | 112 | def getBlockDimension(self): |
|
113 | 113 | """ |
|
114 | 114 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
115 | 115 | |
|
116 | 116 | Affected: |
|
117 | 117 | self.pts2read |
|
118 | 118 | self.blocksize |
|
119 | 119 | |
|
120 | 120 | Return: |
|
121 | 121 | None |
|
122 | 122 | """ |
|
123 | 123 | self.pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels |
|
124 | 124 | self.blocksize = self.pts2read |
|
125 | 125 | self.m_DataObj.nProfiles = self.m_ProcessingHeader.profilesPerBlock |
|
126 | 126 | |
|
127 | 127 | |
|
128 | 128 | def readBlock(self): |
|
129 | 129 | """ |
|
130 | 130 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
131 | 131 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
132 | 132 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
133 | 133 | es seteado a 0 |
|
134 | 134 | |
|
135 | 135 | Inputs: |
|
136 | 136 | None |
|
137 | 137 | |
|
138 | 138 | Return: |
|
139 | 139 | None |
|
140 | 140 | |
|
141 | 141 | Affected: |
|
142 | 142 | self.datablockIndex |
|
143 | 143 | self.datablock |
|
144 | 144 | self.flagIsNewFile |
|
145 | 145 | self.idProfile |
|
146 | 146 | self.flagIsNewBlock |
|
147 | 147 | self.nReadBlocks |
|
148 | 148 | |
|
149 | 149 | Exceptions: |
|
150 | 150 | Si un bloque leido no es un bloque valido |
|
151 | 151 | """ |
|
152 | 152 | blockOk_flag = False |
|
153 | 153 | fpointer = self.fp.tell() |
|
154 | 154 | |
|
155 | 155 | junk = numpy.fromfile( self.fp, self.dataType, self.pts2read ) |
|
156 | 156 | |
|
157 | 157 | if self.online: |
|
158 | 158 | if junk.size != self.blocksize: |
|
159 | 159 | for nTries in range( self.nTries ): |
|
160 | 160 | print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1) |
|
161 | 161 | time.sleep( self.delay ) |
|
162 | 162 | self.fp.seek( fpointer ) |
|
163 | 163 | fpointer = self.fp.tell() |
|
164 | 164 | |
|
165 | 165 | junk = numpy.fromfile( self.fp, self.dataType, self.pts2read ) |
|
166 | 166 | |
|
167 | 167 | if junk.size == self.blocksize: |
|
168 | 168 | blockOk_flag = True |
|
169 | 169 | break |
|
170 | 170 | |
|
171 | 171 | if not( blockOk_flag ): |
|
172 | 172 | return 0 |
|
173 | 173 | |
|
174 | 174 | try: |
|
175 | 175 | junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) ) |
|
176 | 176 | except: |
|
177 | 177 | print "Data file %s is invalid" % self.filename |
|
178 | 178 | return 0 |
|
179 | 179 | |
|
180 | junk = numpy.transpose(junk, (2,0,1)) | |
|
180 | 181 | self.datablock = junk['real'] + junk['imag']*1j |
|
181 | 182 | |
|
182 | 183 | self.datablockIndex = 0 |
|
183 | 184 | self.flagIsNewFile = 0 |
|
184 | 185 | self.idProfile = 0 |
|
185 | 186 | self.flagIsNewBlock = 1 |
|
186 | 187 | |
|
187 | 188 | self.nReadBlocks += 1 |
|
188 | 189 | self.nBlocks += 1 |
|
189 | 190 | |
|
190 | 191 | return 1 |
|
191 | 192 | |
|
192 | 193 | |
|
193 | 194 | def getData(self): |
|
194 | 195 | """ |
|
195 | 196 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
196 | 197 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
197 | 198 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
198 | 199 | |
|
199 | 200 | Ademas incrementa el contador del buffer en 1. |
|
200 | 201 | |
|
201 | 202 | Return: |
|
202 | 203 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
203 | 204 | buffer. Si no hay mas archivos a leer retorna None. |
|
204 | 205 | |
|
205 | 206 | Variables afectadas: |
|
206 | 207 | self.m_DataObj |
|
207 | 208 | self.datablockIndex |
|
208 | 209 | self.idProfile |
|
209 | 210 | |
|
210 | 211 | Affected: |
|
211 | 212 | self.m_DataObj |
|
212 | 213 | self.datablockIndex |
|
213 | 214 | self.flagResetProcessing |
|
214 | 215 | self.flagIsNewBlock |
|
215 | 216 | self.idProfile |
|
216 | 217 | """ |
|
217 | 218 | if self.flagNoMoreFiles: return 0 |
|
218 | 219 | |
|
219 | 220 | self.flagResetProcessing = 0 |
|
220 | 221 | self.flagIsNewBlock = 0 |
|
221 | 222 | |
|
222 | 223 | if self.__hasNotDataInBuffer(): |
|
223 | 224 | |
|
224 | 225 | if not( self.readNextBlock() ): |
|
225 | 226 | self.setNextFile() |
|
226 | 227 | return 0 |
|
227 | 228 | |
|
228 | 229 | self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy() |
|
229 | 230 | self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
|
230 | 231 | self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() |
|
231 | 232 | self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy() |
|
232 | 233 | self.m_DataObj.heights = self.heights |
|
233 | 234 | self.m_DataObj.dataType = self.dataType |
|
234 | 235 | |
|
235 | 236 | if self.flagNoMoreFiles == 1: |
|
236 | 237 | print 'Process finished' |
|
237 | 238 | return 0 |
|
238 | 239 | |
|
239 | 240 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
240 | 241 | |
|
241 | 242 | if self.datablock == None: |
|
242 | 243 | self.m_DataObj.flagNoData = True |
|
243 | 244 | return 0 |
|
244 | 245 | |
|
245 | 246 | time = self.m_BasicHeader.utc + self.datablockIndex * self.ippSeconds |
|
246 | 247 | self.utc = time |
|
247 | 248 | #self.m_DataObj.m_BasicHeader.utc = time |
|
248 | 249 | |
|
249 | 250 | self.m_DataObj.flagNoData = False |
|
250 | 251 | self.m_DataObj.flagResetProcessing = self.flagResetProcessing |
|
251 | 252 | |
|
252 |
self.m_DataObj.data = self.datablock[self.datablockIndex,: |
|
|
253 | self.m_DataObj.data = self.datablock[:,self.datablockIndex,:] | |
|
253 | 254 | self.m_DataObj.idProfile = self.idProfile |
|
254 | 255 | |
|
255 | 256 | self.datablockIndex += 1 |
|
256 | 257 | self.idProfile += 1 |
|
257 | 258 | |
|
258 | 259 | #call setData - to Data Object |
|
259 | 260 | |
|
260 | 261 | return 1 #self.m_DataObj.data |
|
261 | 262 | |
|
262 | 263 | |
|
263 | 264 | class VoltageWriter( JRODataWriter ): |
|
264 | 265 | """ |
|
265 | 266 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
266 | 267 | de los datos siempre se realiza por bloques. |
|
267 | 268 | """ |
|
268 | 269 | __configHeaderFile = 'wrSetHeadet.txt' |
|
269 | 270 | |
|
270 | 271 | m_DataObj = None |
|
271 | 272 | |
|
272 | 273 | ext = ".r" |
|
273 | 274 | |
|
274 | 275 | optchar = "D" |
|
275 | 276 | |
|
276 | 277 | datablock = None |
|
277 | 278 | |
|
278 | 279 | datablockIndex = 0 |
|
279 | 280 | |
|
280 | 281 | shapeBuffer = None |
|
281 | 282 | |
|
282 | 283 | |
|
283 | 284 | def __init__(self, m_Voltage=None): |
|
284 | 285 | """ |
|
285 | 286 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
286 | 287 | |
|
287 | 288 | Affected: |
|
288 | 289 | self.m_DataObj |
|
289 | 290 | |
|
290 | 291 | Return: None |
|
291 | 292 | """ |
|
292 | 293 | if m_Voltage == None: |
|
293 | 294 | m_Voltage = Voltage() |
|
294 | 295 | |
|
295 | 296 | if not( isinstance(m_Voltage, Voltage) ): |
|
296 | 297 | raise ValueError, "in VoltageReader, m_Spectra must be an Spectra class object" |
|
297 | 298 | |
|
298 | 299 | self.m_DataObj = m_Voltage |
|
299 | 300 | |
|
300 | 301 | |
|
301 | 302 | def hasAllDataInBuffer(self): |
|
302 | 303 | if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock: |
|
303 | 304 | return 1 |
|
304 | 305 | return 0 |
|
305 | 306 | |
|
306 | 307 | |
|
307 | 308 | def setBlockDimension(self): |
|
308 | 309 | """ |
|
309 | 310 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
310 | 311 | |
|
311 | 312 | Affected: |
|
312 | 313 | self.shape_spc_Buffer |
|
313 | 314 | self.shape_cspc_Buffer |
|
314 | 315 | self.shape_dc_Buffer |
|
315 | 316 | |
|
316 | 317 | Return: None |
|
317 | 318 | """ |
|
318 | 319 | self.shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock, |
|
319 | 320 | self.m_ProcessingHeader.numHeights, |
|
320 | 321 | self.m_SystemHeader.numChannels ) |
|
321 | 322 | |
|
322 |
self.datablock = numpy.zeros(self. |
|
|
323 | self.datablock = numpy.zeros(self.m_SystemHeader.numChannels, | |
|
324 | self.m_ProcessingHeader.profilesPerBlock, | |
|
325 | self.m_ProcessingHeader.numHeights, | |
|
326 | numpy.dtype('complex')) | |
|
323 | 327 | |
|
324 | 328 | |
|
325 | 329 | def writeBlock(self): |
|
326 | 330 | """ |
|
327 | 331 | Escribe el buffer en el file designado |
|
328 | 332 | |
|
329 | 333 | Affected: |
|
330 | 334 | self.datablockIndex |
|
331 | 335 | self.flagIsNewFile |
|
332 | 336 | self.flagIsNewBlock |
|
333 | 337 | self.nWriteBlocks |
|
334 | 338 | self.blocksCounter |
|
335 | 339 | |
|
336 | 340 | Return: None |
|
337 | 341 | """ |
|
338 | 342 | data = numpy.zeros( self.shapeBuffer, self.dataType ) |
|
339 | 343 | |
|
340 | data['real'] = self.datablock.real | |
|
341 | data['imag'] = self.datablock.imag | |
|
344 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
|
345 | ||
|
346 | data['real'] = junk.real | |
|
347 | data['imag'] = junk.imag | |
|
342 | 348 | |
|
343 | 349 | data = data.reshape( (-1) ) |
|
344 | 350 | |
|
345 | 351 | data.tofile( self.fp ) |
|
346 | 352 | |
|
347 | 353 | self.datablock.fill(0) |
|
348 | 354 | self.datablockIndex = 0 |
|
349 | 355 | self.flagIsNewFile = 0 |
|
350 | 356 | self.flagIsNewBlock = 1 |
|
351 | 357 | self.nWriteBlocks += 1 |
|
352 | 358 | self.blocksCounter += 1 |
|
353 | 359 | |
|
354 | 360 | |
|
355 | 361 | def putData(self): |
|
356 | 362 | """ |
|
357 | 363 | Setea un bloque de datos y luego los escribe en un file |
|
358 | 364 | |
|
359 | 365 | Affected: |
|
360 | 366 | self.flagIsNewBlock |
|
361 | 367 | self.datablockIndex |
|
362 | 368 | |
|
363 | 369 | Return: |
|
364 | 370 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
365 | 371 | 1 : Si se escribio la data de un bloque en un file |
|
366 | 372 | """ |
|
367 | 373 | self.flagIsNewBlock = 0 |
|
368 | 374 | |
|
369 | 375 | if self.m_DataObj.flagNoData: |
|
370 | 376 | return 0 |
|
371 | 377 | |
|
372 | 378 | if self.m_DataObj.flagResetProcessing: |
|
373 | 379 | |
|
374 | 380 | self.datablock.fill(0) |
|
375 | 381 | self.datablockIndex = 0 |
|
376 | 382 | self.setNextFile() |
|
377 | 383 | |
|
378 |
self.datablock[self.datablockIndex |
|
|
384 | self.datablock[:,self.datablockIndex,:] = self.m_DataObj.data | |
|
379 | 385 | |
|
380 | 386 | self.datablockIndex += 1 |
|
381 | 387 | |
|
382 | 388 | if self.hasAllDataInBuffer(): |
|
383 | 389 | #if self.flagIsNewFile: |
|
384 | 390 | self.getHeader() |
|
385 | 391 | self.writeNextBlock() |
|
386 | 392 | |
|
387 | 393 | if self.flagNoMoreFiles: |
|
388 | 394 | #print 'Process finished' |
|
389 | 395 | return 0 |
|
390 | 396 | |
|
391 | 397 | return 1 |
|
392 | 398 | No newline at end of file |
@@ -1,183 +1,186 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | path = os.path.split(os.getcwd())[0] |
|
11 | 11 | sys.path.append(path) |
|
12 | 12 | |
|
13 | 13 | from Model.Spectra import Spectra |
|
14 | 14 | from IO.SpectraIO import SpectraWriter |
|
15 | 15 | from Graphics.SpectraPlot import Spectrum |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | class SpectraProcessor: |
|
19 | 19 | ''' |
|
20 | 20 | classdocs |
|
21 | 21 | ''' |
|
22 | 22 | |
|
23 | 23 | def __init__(self, spectraInObj, spectraOutObj=None, npts = None): |
|
24 | 24 | ''' |
|
25 | 25 | Constructor |
|
26 | 26 | ''' |
|
27 | 27 | self.spectraInObj = spectraInObj |
|
28 | 28 | |
|
29 | 29 | if spectraOutObj == None: |
|
30 | 30 | self.spectraOutObj = Spectra() |
|
31 | 31 | else: |
|
32 | 32 | self.spectraOutObj = spectraOutObj |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | self.integratorIndex = None |
|
36 | 36 | self.decoderIndex = None |
|
37 | 37 | self.writerIndex = None |
|
38 | 38 | self.plotterIndex = None |
|
39 | 39 | |
|
40 | 40 | if npts != None: |
|
41 | 41 | self.spectraOutObj.nPoints = npts |
|
42 | 42 | |
|
43 | 43 | self.npts = self.spectraOutObj.nPoints |
|
44 | 44 | |
|
45 | 45 | self.integratorList = [] |
|
46 | 46 | self.decoderList = [] |
|
47 | 47 | self.writerList = [] |
|
48 | 48 | self.plotterList = [] |
|
49 | 49 | |
|
50 | 50 | self.buffer = None |
|
51 | 51 | self.ptsId = 0 |
|
52 | 52 | |
|
53 | 53 | def init(self): |
|
54 | 54 | self.integratorIndex = 0 |
|
55 | 55 | self.decoderIndex = 0 |
|
56 | 56 | self.writerIndex = 0 |
|
57 | 57 | self.plotterIndex = 0 |
|
58 | 58 | |
|
59 | 59 | if not( isinstance(self.spectraInObj, Spectra) ): |
|
60 | 60 | self.getFft() |
|
61 | 61 | else: |
|
62 | 62 | self.spectraOutObj.copy(self.spectraInObj) |
|
63 | 63 | |
|
64 | 64 | |
|
65 | 65 | def getFft(self): |
|
66 | 66 | |
|
67 | 67 | if self.buffer == None: |
|
68 |
nheis = self.spectraInObj.data.shape[ |
|
|
69 |
nchannel = self.spectraInObj.data.shape[ |
|
|
68 | nheis = self.spectraInObj.data.shape[1] | |
|
69 | nchannel = self.spectraInObj.data.shape[0] | |
|
70 | 70 | npoints = self.spectraOutObj.nPoints |
|
71 |
self.buffer = numpy.zeros((nchannel,nheis |
|
|
72 |
|
|
|
73 | data = numpy.transpose(self.spectraInObj.data) | |
|
74 | self.buffer[:,:,self.ptsId] = data | |
|
71 | self.buffer = numpy.zeros((nchannel,npoints,nheis),dtype='complex') | |
|
72 | ||
|
73 | self.buffer[:,self.ptsId,:] = self.spectraInObj.data | |
|
75 | 74 | self.ptsId += 1 |
|
76 | 75 | self.spectraOutObj.flagNoData = True |
|
77 | 76 | if self.ptsId >= self.spectraOutObj.nPoints: |
|
78 |
data_spc = numpy.fft.fft(self.buffer,axis= |
|
|
77 | data_spc = numpy.fft.fft(self.buffer,axis=1) | |
|
79 | 78 | self.ptsId = 0 |
|
80 | 79 | self.buffer = None |
|
81 | 80 | |
|
82 | 81 | #calculo de self-spectra |
|
83 | 82 | self.spectraOutObj.data_spc = numpy.abs(data_spc * numpy.conjugate(data_spc)) |
|
84 | 83 | |
|
85 | ||
|
86 | ||
|
87 | 84 | #calculo de cross-spectra |
|
88 | 85 | #self.m_Spectra.data_cspc = self.__data_cspc |
|
89 | 86 | |
|
90 | ||
|
91 | 87 | #escribiendo dc |
|
92 | 88 | #self.m_Spectra.data_dc = self.__data_dc |
|
93 | 89 | |
|
94 | ||
|
95 | 90 | self.spectraOutObj.flagNoData = False |
|
96 |
|
|
|
91 | ||
|
92 | self.spectraOutObj.heights = self.spectraInObj.heights | |
|
93 | self.spectraOutObj.m_BasicHeader = self.spectraInObj.m_BasicHeader.copy() | |
|
94 | self.spectraOutObj.m_ProcessingHeader = self.spectraInObj.m_ProcessingHeader.copy() | |
|
95 | self.spectraOutObj.m_RadarControllerHeader = self.spectraInObj.m_RadarControllerHeader.copy() | |
|
96 | self.spectraOutObj.m_SystemHeader = self.spectraInObj.m_SystemHeader.copy() | |
|
97 | 97 | |
|
98 | 98 | def addWriter(self,wrpath): |
|
99 | 99 | objWriter = SpectraWriter(self.spectraOutObj) |
|
100 | 100 | objWriter.setup(wrpath) |
|
101 | 101 | self.writerList.append(objWriter) |
|
102 | 102 | |
|
103 | 103 | |
|
104 | def addPlotter(self): | |
|
104 | def addPlotter(self, index=None): | |
|
105 | ||
|
106 | if index==None: | |
|
107 | index = self.plotterIndex | |
|
105 | 108 | |
|
106 |
plotObj = Spectrum(self.spectraOutObj, |
|
|
109 | plotObj = Spectrum(self.spectraOutObj, index) | |
|
107 | 110 | self.plotterList.append(plotObj) |
|
108 | 111 | |
|
109 | 112 | |
|
110 | 113 | def addIntegrator(self,N): |
|
111 | 114 | |
|
112 | 115 | objIncohInt = IncoherentIntegration(N) |
|
113 | 116 | self.integratorList.append(objIncohInt) |
|
114 | 117 | |
|
115 | 118 | |
|
116 | 119 | def writeData(self): |
|
117 | 120 | if self.voltageOutObj.flagNoData: |
|
118 | 121 | return 0 |
|
119 | 122 | |
|
120 | 123 | if len(self.writerList) <= self.writerIndex: |
|
121 | 124 | self.addWriter(wrpath) |
|
122 | 125 | |
|
123 | 126 | self.writerList[self.writerIndex].putData() |
|
124 | 127 | |
|
125 | 128 | self.writerIndex += 1 |
|
126 | 129 | |
|
127 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): | |
|
130 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): | |
|
128 | 131 | if self.spectraOutObj.flagNoData: |
|
129 | 132 | return 0 |
|
130 | 133 | |
|
131 | 134 | if len(self.plotterList) <= self.plotterIndex: |
|
132 | self.addPlotter() | |
|
135 | self.addPlotter(index) | |
|
133 | 136 | |
|
134 | 137 | self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
135 | 138 | |
|
136 | 139 | self.plotterIndex += 1 |
|
137 | 140 | |
|
138 | 141 | def integrator(self, N): |
|
139 | 142 | if self.spectraOutObj.flagNoData: |
|
140 | 143 | return 0 |
|
141 | 144 | |
|
142 | 145 | if len(self.integratorList) <= self.integratorIndex: |
|
143 | 146 | self.addIntegrator(N) |
|
144 | 147 | |
|
145 | 148 | myCohIntObj = self.integratorList[self.integratorIndex] |
|
146 | 149 | myCohIntObj.exe(self.spectraOutObj.data_spc) |
|
147 | 150 | |
|
148 | 151 | if myCohIntObj.flag: |
|
149 | 152 | self.spectraOutObj.data_spc = myCohIntObj.data |
|
150 | 153 | self.spectraOutObj.m_ProcessingHeader.incoherentInt *= N |
|
151 | 154 | self.spectraOutObj.flagNoData = False |
|
152 | 155 | |
|
153 | 156 | else: |
|
154 | 157 | self.spectraOutObj.flagNoData = True |
|
155 | 158 | |
|
156 | 159 | self.integratorIndex += 1 |
|
157 | 160 | |
|
158 | 161 | class IncoherentIntegration: |
|
159 | 162 | def __init__(self, N): |
|
160 | 163 | self.profCounter = 1 |
|
161 | 164 | self.data = None |
|
162 | 165 | self.buffer = None |
|
163 | 166 | self.flag = False |
|
164 | 167 | self.nIncohInt = N |
|
165 | 168 | |
|
166 | 169 | def exe(self,data): |
|
167 | 170 | print 'intg:', self.profCounter |
|
168 | 171 | |
|
169 | 172 | if self.buffer == None: |
|
170 | 173 | self.buffer = data |
|
171 | 174 | else: |
|
172 | 175 | self.buffer = self.buffer + data |
|
173 | 176 | |
|
174 | 177 | if self.profCounter == self.nIncohInt: |
|
175 | 178 | self.data = self.buffer |
|
176 | 179 | self.buffer = None |
|
177 | 180 | self.profCounter = 0 |
|
178 | 181 | self.flag = True |
|
179 | 182 | else: |
|
180 | 183 | self.flag = False |
|
181 | 184 | |
|
182 | 185 | self.profCounter += 1 |
|
183 | 186 |
@@ -1,247 +1,247 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Model.Voltage import Voltage |
|
15 | 15 | from IO.VoltageIO import VoltageWriter |
|
16 | 16 | from Graphics.VoltagePlot import Osciloscope |
|
17 | 17 | |
|
18 | 18 | class VoltageProcessor: |
|
19 | 19 | ''' |
|
20 | 20 | classdocs |
|
21 | 21 | ''' |
|
22 | 22 | |
|
23 | 23 | def __init__(self, voltageInObj, voltageOutObj=None): |
|
24 | 24 | ''' |
|
25 | 25 | Constructor |
|
26 | 26 | ''' |
|
27 | 27 | |
|
28 | 28 | self.voltageInObj = voltageInObj |
|
29 | 29 | |
|
30 | 30 | if voltageOutObj == None: |
|
31 | 31 | self.voltageOutObj = Voltage() |
|
32 | 32 | else: |
|
33 | 33 | self.voltageOutObj = voltageOutObj |
|
34 | 34 | |
|
35 | 35 | self.integratorIndex = None |
|
36 | 36 | self.decoderIndex = None |
|
37 | 37 | self.writerIndex = None |
|
38 | 38 | self.plotterIndex = None |
|
39 | 39 | |
|
40 | 40 | self.integratorList = [] |
|
41 | 41 | self.decoderList = [] |
|
42 | 42 | self.writerList = [] |
|
43 | 43 | self.plotterList = [] |
|
44 | 44 | |
|
45 | 45 | def init(self): |
|
46 | 46 | self.integratorIndex = 0 |
|
47 | 47 | self.decoderIndex = 0 |
|
48 | 48 | self.writerIndex = 0 |
|
49 | 49 | self.plotterIndex = 0 |
|
50 | 50 | self.voltageOutObj.copy(self.voltageInObj) |
|
51 | 51 | |
|
52 | 52 | def addWriter(self,wrpath): |
|
53 | 53 | objWriter = VoltageWriter(self.voltageOutObj) |
|
54 | 54 | objWriter.setup(wrpath) |
|
55 | 55 | self.writerList.append(objWriter) |
|
56 | 56 | |
|
57 | 57 | def addPlotter(self): |
|
58 | 58 | |
|
59 | 59 | plotObj = Osciloscope(self.voltageOutObj,self.plotterIndex) |
|
60 | 60 | self.plotterList.append(plotObj) |
|
61 | 61 | |
|
62 | 62 | def addIntegrator(self,N): |
|
63 | 63 | |
|
64 | 64 | objCohInt = CoherentIntegrator(N) |
|
65 | 65 | self.integratorList.append(objCohInt) |
|
66 | 66 | |
|
67 | 67 | def addDecoder(self,code,ncode,nbaud): |
|
68 | 68 | |
|
69 | 69 | objDecoder = Decoder(code,ncode,nbaud) |
|
70 | 70 | self.decoderList.append(objDecoder) |
|
71 | 71 | |
|
72 | 72 | def writeData(self,wrpath): |
|
73 | 73 | if self.voltageOutObj.flagNoData: |
|
74 | 74 | return 0 |
|
75 | 75 | |
|
76 | 76 | if len(self.writerList) <= self.writerIndex: |
|
77 | 77 | self.addWriter(wrpath) |
|
78 | 78 | |
|
79 | 79 | self.writerList[self.writerIndex].putData() |
|
80 | 80 | |
|
81 | 81 | # myWrObj = self.writerList[self.writerIndex] |
|
82 | 82 | # myWrObj.putData() |
|
83 | 83 | |
|
84 | 84 | self.writerIndex += 1 |
|
85 | 85 | |
|
86 | 86 | def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): |
|
87 | 87 | if self.voltageOutObj.flagNoData: |
|
88 | 88 | return 0 |
|
89 | 89 | |
|
90 | 90 | if len(self.plotterList) <= self.plotterIndex: |
|
91 | 91 | self.addPlotter() |
|
92 | 92 | |
|
93 | 93 | self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
94 | 94 | |
|
95 | 95 | self.plotterIndex += 1 |
|
96 | 96 | |
|
97 | 97 | def integrator(self, N): |
|
98 | 98 | if self.voltageOutObj.flagNoData: |
|
99 | 99 | return 0 |
|
100 | 100 | |
|
101 | 101 | if len(self.integratorList) <= self.integratorIndex: |
|
102 | 102 | self.addIntegrator(N) |
|
103 | 103 | |
|
104 | 104 | myCohIntObj = self.integratorList[self.integratorIndex] |
|
105 | 105 | myCohIntObj.exe(self.voltageOutObj.data) |
|
106 | 106 | |
|
107 | 107 | if myCohIntObj.flag: |
|
108 | 108 | self.voltageOutObj.data = myCohIntObj.data |
|
109 | 109 | self.voltageOutObj.m_ProcessingHeader.coherentInt *= N |
|
110 | 110 | self.voltageOutObj.flagNoData = False |
|
111 | 111 | |
|
112 | 112 | else: |
|
113 | 113 | self.voltageOutObj.flagNoData = True |
|
114 | 114 | |
|
115 | 115 | self.integratorIndex += 1 |
|
116 | 116 | |
|
117 | 117 | def decoder(self,code=None,type = 0): |
|
118 | 118 | if self.voltageOutObj.flagNoData: |
|
119 | 119 | return 0 |
|
120 | 120 | if code == None: |
|
121 | 121 | code = self.voltageOutObj.m_RadarControllerHeader.code |
|
122 | 122 | ncode, nbaud = code.shape |
|
123 | 123 | |
|
124 | 124 | if len(self.decoderList) <= self.decoderIndex: |
|
125 | 125 | self.addDecoder(code,ncode,nbaud) |
|
126 | 126 | |
|
127 | 127 | myDecodObj = self.decoderList[self.decoderIndex] |
|
128 | 128 | myDecodObj.exe(data=self.voltageOutObj.data,type=type) |
|
129 | 129 | |
|
130 | 130 | if myDecodObj.flag: |
|
131 | 131 | self.voltageOutObj.data = myDecodObj.data |
|
132 | 132 | self.voltageOutObj.flagNoData = False |
|
133 | 133 | else: |
|
134 | 134 | self.voltageOutObj.flagNoData = True |
|
135 | 135 | |
|
136 | 136 | self.decoderIndex += 1 |
|
137 | 137 | |
|
138 | 138 | def removeDC(self): |
|
139 | 139 | pass |
|
140 | 140 | |
|
141 | 141 | def removeSignalInt(self): |
|
142 | 142 | pass |
|
143 | 143 | |
|
144 | 144 | def selChannel(self): |
|
145 | 145 | pass |
|
146 | 146 | |
|
147 | 147 | def selRange(self): |
|
148 | 148 | pass |
|
149 | 149 | |
|
150 | 150 | def selProfiles(self): |
|
151 | 151 | pass |
|
152 | 152 | |
|
153 | 153 | |
|
154 | 154 | class Decoder: |
|
155 | 155 | def __init__(self,code, ncode, nbaud): |
|
156 | 156 | self.buffer = None |
|
157 | 157 | self.profCounter = 1 |
|
158 | 158 | self.nCode = ncode |
|
159 | 159 | self.nBaud = nbaud |
|
160 | 160 | self.codeIndex = 0 |
|
161 | 161 | self.code = code #this is a List |
|
162 | 162 | self.fft_code = None |
|
163 | 163 | self.flag = False |
|
164 | 164 | self.setCodeFft = False |
|
165 | 165 | |
|
166 | 166 | def exe(self, data, ndata=None, type = 0): |
|
167 |
if ndata == None: ndata = data.shape[ |
|
|
167 | if ndata == None: ndata = data.shape[1] | |
|
168 | 168 | |
|
169 | 169 | if type == 0: |
|
170 | 170 | self.convolutionInFreq(data,ndata) |
|
171 | 171 | |
|
172 | 172 | if type == 1: |
|
173 | 173 | self.convolutionInTime(data, ndata) |
|
174 | 174 | |
|
175 | 175 | def convolutionInFreq(self,data,ndata): |
|
176 | 176 | |
|
177 | 177 | newcode = numpy.zeros(ndata) |
|
178 | 178 | newcode[0:self.nBaud] = self.code[self.codeIndex] |
|
179 | 179 | |
|
180 | 180 | self.codeIndex += 1 |
|
181 | 181 | |
|
182 |
fft_data = numpy.fft.fft(data, axis= |
|
|
182 | fft_data = numpy.fft.fft(data, axis=1) | |
|
183 | 183 | fft_code = numpy.conj(numpy.fft.fft(newcode)) |
|
184 |
fft_code = fft_code.reshape(len(fft_code) |
|
|
184 | fft_code = fft_code.reshape(1,len(fft_code)) | |
|
185 | 185 | |
|
186 | 186 | conv = fft_data.copy() |
|
187 | 187 | conv.fill(0) |
|
188 | 188 | |
|
189 | 189 | conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays |
|
190 | 190 | # for i in range(ndata): |
|
191 | 191 | # conv[i,:] = fft_data[i,:]*fft_code[i] |
|
192 | 192 | |
|
193 |
self.data = numpy.fft.ifft(conv,axis= |
|
|
193 | self.data = numpy.fft.ifft(conv,axis=1) | |
|
194 | 194 | self.flag = True |
|
195 | 195 | |
|
196 | 196 | if self.profCounter == self.nCode: |
|
197 | 197 | self.profCounter = 0 |
|
198 | 198 | self.codeIndex = 0 |
|
199 | 199 | |
|
200 | 200 | self.profCounter += 1 |
|
201 | 201 | |
|
202 | 202 | def convolutionInTime(self, data, ndata): |
|
203 | 203 | |
|
204 | 204 | nchannel = data.shape[1] |
|
205 | 205 | newcode = self.code[self.codeIndex] |
|
206 | 206 | self.codeIndex += 1 |
|
207 | 207 | conv = data.copy() |
|
208 | 208 | for i in range(nchannel): |
|
209 |
conv[: |
|
|
209 | conv[i,:] = numpy.correlate(data[i,:], newcode, 'same') | |
|
210 | 210 | |
|
211 | 211 | self.data = conv |
|
212 | 212 | self.flag = True |
|
213 | 213 | |
|
214 | 214 | if self.profCounter == self.nCode: |
|
215 | 215 | self.profCounter = 0 |
|
216 | 216 | self.codeIndex = 0 |
|
217 | 217 | |
|
218 | 218 | self.profCounter += 1 |
|
219 | 219 | |
|
220 | 220 | |
|
221 | 221 | class CoherentIntegrator: |
|
222 | 222 | def __init__(self, N): |
|
223 | 223 | self.profCounter = 1 |
|
224 | 224 | self.data = None |
|
225 | 225 | self.buffer = None |
|
226 | 226 | self.flag = False |
|
227 | 227 | self.nCohInt = N |
|
228 | 228 | |
|
229 | 229 | def exe(self,data): |
|
230 | 230 | |
|
231 | 231 | if self.buffer == None: |
|
232 | 232 | self.buffer = data |
|
233 | 233 | else: |
|
234 | 234 | self.buffer = self.buffer + data |
|
235 | 235 | |
|
236 | 236 | if self.profCounter == self.nCohInt: |
|
237 | 237 | self.data = self.buffer |
|
238 | 238 | self.buffer = None |
|
239 | 239 | self.profCounter = 0 |
|
240 | 240 | self.flag = True |
|
241 | 241 | else: |
|
242 | 242 | self.flag = False |
|
243 | 243 | |
|
244 | 244 | self.profCounter += 1 |
|
245 | 245 | |
|
246 | 246 | |
|
247 | 247 | No newline at end of file |
@@ -1,71 +1,73 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 23/01/2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | import time, datetime |
|
9 | 9 | |
|
10 | 10 | from Model.JROData import JROData |
|
11 | 11 | from IO.DataIO import * |
|
12 | 12 | #=============================================================================== |
|
13 | 13 | # from Graphics.DataPlot import Osciloscope |
|
14 | 14 | # |
|
15 | 15 | # from Model.Spectra import Spectra |
|
16 | 16 | # from IO.SpectraIO import * |
|
17 | 17 | # from Graphics.SpectraPlot import Spectrum |
|
18 | 18 | #=============================================================================== |
|
19 | 19 | |
|
20 | 20 | class TestSChain(): |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | def __init__(self): |
|
24 | 24 | self.setValues() |
|
25 | 25 | self.createObjects() |
|
26 | 26 | self.testSChain() |
|
27 | 27 | pass |
|
28 | 28 | |
|
29 | 29 | def setValues(self): |
|
30 | 30 | |
|
31 | self.path = "/home/valentin/Tmp/RAWDATA" | |
|
32 | self.startDateTime = datetime.datetime(2009,11,2,00,00,0) | |
|
33 | self.endDateTime = datetime.datetime(2009,11,30,18,10,0) | |
|
31 | #self.path = "/home/valentin/Tmp/RAWDATA" | |
|
32 | self.path = "/home/dsuarez/Projects" | |
|
33 | #self.wrpath = "/home/dsuarez/Projects/testWR" | |
|
34 | self.startDateTime = datetime.datetime(2007,5,1,15,49,0) | |
|
35 | self.endDateTime = datetime.datetime(2007,5,1,16,0,0) | |
|
34 | 36 | |
|
35 | 37 | def createObjects(self): |
|
36 | 38 | |
|
37 | 39 | self.Obj = JROData() |
|
38 | 40 | self.readerObj = JRODataReader(self.Obj) |
|
39 | 41 | #self.plotObj = Spectrum(self.Obj) |
|
40 | 42 | |
|
41 | 43 | if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, ext = '.pdata', expLabel='', online =1)): |
|
42 | 44 | sys.exit(0) |
|
43 | 45 | |
|
44 | 46 | def testSChain(self): |
|
45 | 47 | |
|
46 | 48 | ini = time.time() |
|
47 | 49 | while(True): |
|
48 | 50 | if self.readerObj.getData(): |
|
49 | 51 | print "", |
|
50 | 52 | #self.plotObj.plotData(zmin=40, zmax=140, showColorbar=True, showPowerProfile=True) |
|
51 | 53 | |
|
52 | 54 | # self.writerObj.putData() |
|
53 | 55 | |
|
54 | 56 | |
|
55 | 57 | if self.readerObj.noMoreFiles: |
|
56 | 58 | break |
|
57 | 59 | |
|
58 | 60 | if self.readerObj.flagIsNewBlock and self.readerObj.nReadBlocks: |
|
59 | 61 | print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks, |
|
60 | 62 | datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) |
|
61 | 63 | #=============================================================== |
|
62 | 64 | # fin = time.time() |
|
63 | 65 | # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) |
|
64 | 66 | # ini = time.time() |
|
65 | 67 | #=============================================================== |
|
66 | 68 | |
|
67 | 69 | #time.sleep(0.5) |
|
68 | 70 | self.plotObj.end() |
|
69 | 71 | |
|
70 | 72 | if __name__ == '__main__': |
|
71 | 73 | TestSChain() No newline at end of file |
@@ -1,59 +1,102 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 27/03/2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | import time, datetime |
|
9 | 9 | |
|
10 | 10 | from Model.Voltage import Voltage |
|
11 | 11 | from IO.VoltageIO import * |
|
12 | from Graphics.VoltagePlot import Osciloscope | |
|
12 | #from Graphics.VoltagePlot import Osciloscope | |
|
13 | ||
|
14 | from Model.Spectra import Spectra | |
|
15 | from IO.SpectraIO import * | |
|
16 | ||
|
17 | from Processing.VoltageProcessor import * | |
|
18 | from Processing.SpectraProcessor import * | |
|
13 | 19 | |
|
14 | 20 | class TestSChain(): |
|
15 | 21 | |
|
16 | 22 | def __init__(self): |
|
17 | 23 | self.setValues() |
|
18 | 24 | self.createObjects() |
|
19 | 25 | self.testSChain() |
|
20 |
|
|
|
26 | ||
|
21 | 27 | |
|
22 | 28 | def setValues( self ): |
|
23 | 29 | |
|
24 |
self.path = "/home/ |
|
|
30 | self.path = "/home/dsuarez/Projects" #1 | |
|
25 | 31 | #self.path = "/home/valentin/Tmp/VOLTAGE2" #2 |
|
26 |
self.startDateTime = datetime.datetime(20 |
|
|
27 |
self.endDateTime = datetime.datetime(20 |
|
|
32 | # self.startDateTime = datetime.datetime(2007,5,1,15,49,0) | |
|
33 | # self.endDateTime = datetime.datetime(2007,5,1,23,0,0) | |
|
34 | ||
|
35 | self.startDateTime = datetime.datetime(2011,10,4,0,0,0) | |
|
36 | self.endDateTime = datetime.datetime(2011,10,4,0,20,0) | |
|
37 | self.N = 2 | |
|
38 | self.npts = 4 | |
|
28 | 39 | |
|
29 | 40 | def createObjects( self ): |
|
30 | 41 | |
|
31 | 42 | self.Obj = Voltage() |
|
43 | self.OutObj = Voltage() | |
|
32 | 44 | self.readerObj = VoltageReader(self.Obj) |
|
33 |
self.p |
|
|
45 | self.procObj = VoltageProcessor(self.Obj, self.OutObj) | |
|
46 | ||
|
47 | self.spectraObj = Spectra() | |
|
48 | self.specProcObj = SpectraProcessor(self.OutObj, self.spectraObj,self.npts) | |
|
49 | ||
|
50 | ||
|
51 | #self.plotObj = Osciloscope(self.Obj) | |
|
34 | 52 | |
|
35 | 53 | if not(self.readerObj.setup( self.path, self.startDateTime, self.endDateTime, expLabel='', online =0) ): |
|
36 | 54 | sys.exit(0) |
|
55 | ||
|
56 | # if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime)): | |
|
57 | # sys.exit(0) | |
|
37 | 58 | |
|
38 | 59 | def testSChain( self ): |
|
39 | 60 | |
|
40 | 61 | ini = time.time() |
|
41 | 62 | while(True): |
|
42 |
|
|
|
43 | self.plotObj.plotData(idProfile=0, type='power' ) | |
|
63 | self.readerObj.getData() | |
|
44 | 64 | |
|
45 | if self.readerObj.flagNoMoreFiles: | |
|
46 | break | |
|
65 | self.procObj.init() | |
|
47 | 66 | |
|
67 | self.procObj.plotData(idProfile = 1, type='power',winTitle='figura 1') | |
|
68 | ||
|
69 | self.procObj.decoder(type=0) | |
|
70 | ||
|
71 | # self.procObj.plotData(idProfile = 1, type='iq', xmin=0, xmax=100,winTitle='figura 2') | |
|
72 | # | |
|
73 | # self.procObj.integrator(self.N) | |
|
74 | ||
|
75 | self.procObj.plotData(idProfile = 1, type='power',winTitle='figura 3') | |
|
76 | ||
|
77 | self.specProcObj.init() | |
|
78 | ||
|
79 | self.specProcObj.integrator(2) | |
|
80 | ||
|
81 | self.specProcObj.plotData(winTitle='Spectra 1', index=2) | |
|
82 | ||
|
83 | # if self.readerObj.getData(): | |
|
84 | # self.plotObj.plotData(idProfile=0, type='power' ) | |
|
85 | # | |
|
86 | # | |
|
87 | # if self.readerObj.flagNoMoreFiles: | |
|
88 | # break | |
|
89 | # | |
|
48 | 90 | if self.readerObj.flagIsNewBlock: |
|
49 | 91 | print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks, |
|
50 | 92 | datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),) |
|
93 | ||
|
51 | 94 | # fin = time.time() |
|
52 | 95 | # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini) |
|
53 | 96 | # ini = time.time() |
|
54 | 97 | |
|
55 | 98 | #time.sleep(0.5) |
|
56 | self.plotObj.end() | |
|
99 | # self.plotObj.end() | |
|
57 | 100 | |
|
58 | 101 | if __name__ == '__main__': |
|
59 | 102 | TestSChain() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now