##// END OF EJS Templates
jroplot_voltage: saving every profile
Miguel Valdez -
r774:3fb81731d7d7
parent child
Show More
@@ -1,212 +1,225
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure
10 from figure import Figure
11
11
12 class Scope(Figure):
12 class Scope(Figure):
13
13
14 isConfig = None
14 isConfig = None
15
15
16 def __init__(self):
16 def __init__(self):
17
17
18 self.isConfig = False
18 self.isConfig = False
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 200
20 self.HEIGHT = 200
21 self.counter_imagwr = 0
21 self.counter_imagwr = 0
22
22
23 def getSubplots(self):
23 def getSubplots(self):
24
24
25 nrow = self.nplots
25 nrow = self.nplots
26 ncol = 3
26 ncol = 3
27 return nrow, ncol
27 return nrow, ncol
28
28
29 def setup(self, id, nplots, wintitle, show):
29 def setup(self, id, nplots, wintitle, show):
30
30
31 self.nplots = nplots
31 self.nplots = nplots
32
32
33 self.createFigure(id=id,
33 self.createFigure(id=id,
34 wintitle=wintitle,
34 wintitle=wintitle,
35 show=show)
35 show=show)
36
36
37 nrow,ncol = self.getSubplots()
37 nrow,ncol = self.getSubplots()
38 colspan = 3
38 colspan = 3
39 rowspan = 1
39 rowspan = 1
40
40
41 for i in range(nplots):
41 for i in range(nplots):
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
43
43
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
45 yreal = y[channelIndexList,:].real
45 yreal = y[channelIndexList,:].real
46 yimag = y[channelIndexList,:].imag
46 yimag = y[channelIndexList,:].imag
47
47
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
49 xlabel = "Range (Km)"
49 xlabel = "Range (Km)"
50 ylabel = "Intensity - IQ"
50 ylabel = "Intensity - IQ"
51
51
52 if not self.isConfig:
52 if not self.isConfig:
53 nplots = len(channelIndexList)
53 nplots = len(channelIndexList)
54
54
55 self.setup(id=id,
55 self.setup(id=id,
56 nplots=nplots,
56 nplots=nplots,
57 wintitle='',
57 wintitle='',
58 show=show)
58 show=show)
59
59
60 if xmin == None: xmin = numpy.nanmin(x)
60 if xmin == None: xmin = numpy.nanmin(x)
61 if xmax == None: xmax = numpy.nanmax(x)
61 if xmax == None: xmax = numpy.nanmax(x)
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
64
64
65 self.isConfig = True
65 self.isConfig = True
66
66
67 self.setWinTitle(title)
67 self.setWinTitle(title)
68
68
69 for i in range(len(self.axesList)):
69 for i in range(len(self.axesList)):
70 title = "Channel %d" %(i)
70 title = "Channel %d" %(i)
71 axes = self.axesList[i]
71 axes = self.axesList[i]
72
72
73 axes.pline(x, yreal[i,:],
73 axes.pline(x, yreal[i,:],
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
75 xlabel=xlabel, ylabel=ylabel, title=title)
75 xlabel=xlabel, ylabel=ylabel, title=title)
76
76
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
78
78
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
81 yreal = y.real
81 yreal = y.real
82
82
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
84 xlabel = "Range (Km)"
84 xlabel = "Range (Km)"
85 ylabel = "Intensity"
85 ylabel = "Intensity"
86
86
87 if not self.isConfig:
87 if not self.isConfig:
88 nplots = len(channelIndexList)
88 nplots = len(channelIndexList)
89
89
90 self.setup(id=id,
90 self.setup(id=id,
91 nplots=nplots,
91 nplots=nplots,
92 wintitle='',
92 wintitle='',
93 show=show)
93 show=show)
94
94
95 if xmin == None: xmin = numpy.nanmin(x)
95 if xmin == None: xmin = numpy.nanmin(x)
96 if xmax == None: xmax = numpy.nanmax(x)
96 if xmax == None: xmax = numpy.nanmax(x)
97 if ymin == None: ymin = numpy.nanmin(yreal)
97 if ymin == None: ymin = numpy.nanmin(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
99
99
100 self.isConfig = True
100 self.isConfig = True
101
101
102 self.setWinTitle(title)
102 self.setWinTitle(title)
103
103
104 for i in range(len(self.axesList)):
104 for i in range(len(self.axesList)):
105 title = "Channel %d" %(i)
105 title = "Channel %d" %(i)
106 axes = self.axesList[i]
106 axes = self.axesList[i]
107 ychannel = yreal[i,:]
107 ychannel = yreal[i,:]
108 axes.pline(x, ychannel,
108 axes.pline(x, ychannel,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
110 xlabel=xlabel, ylabel=ylabel, title=title)
110 xlabel=xlabel, ylabel=ylabel, title=title)
111
111
112
112
113 def run(self, dataOut, id, wintitle="", channelList=None,
113 def run(self, dataOut, id, wintitle="", channelList=None,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
115 figpath='./', figfile=None, show=True, wr_period=1,
115 figpath='./', figfile=None, show=True, wr_period=1,
116 ftp=False, server=None, folder=None, username=None, password=None, type='power'):
116 ftp=False, server=None, folder=None, username=None, password=None, type='power'):
117
117
118 """
118 """
119
119
120 Input:
120 Input:
121 dataOut :
121 dataOut :
122 id :
122 id :
123 wintitle :
123 wintitle :
124 channelList :
124 channelList :
125 xmin : None,
125 xmin : None,
126 xmax : None,
126 xmax : None,
127 ymin : None,
127 ymin : None,
128 ymax : None,
128 ymax : None,
129 """
129 """
130
130
131 if channelList == None:
131 if channelList == None:
132 channelIndexList = dataOut.channelIndexList
132 channelIndexList = dataOut.channelIndexList
133 else:
133 else:
134 channelIndexList = []
134 channelIndexList = []
135 for channel in channelList:
135 for channel in channelList:
136 if channel not in dataOut.channelList:
136 if channel not in dataOut.channelList:
137 raise ValueError, "Channel %d is not in dataOut.channelList"
137 raise ValueError, "Channel %d is not in dataOut.channelList"
138 channelIndexList.append(dataOut.channelList.index(channel))
138 channelIndexList.append(dataOut.channelList.index(channel))
139
139
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
141
141
142 if dataOut.flagDataAsBlock:
142 if dataOut.flagDataAsBlock:
143
143
144 for i in range(dataOut.nProfiles):
144 for i in range(dataOut.nProfiles):
145
145
146 wintitle1 = wintitle + " [Profile = %d] " %i
146 wintitle1 = wintitle + " [Profile = %d] " %i
147
147
148 if type == "power":
148 if type == "power":
149 self.plot_power(dataOut.heightList,
149 self.plot_power(dataOut.heightList,
150 dataOut.data[:,i,:],
150 dataOut.data[:,i,:],
151 id,
151 id,
152 channelIndexList,
152 channelIndexList,
153 thisDatetime,
153 thisDatetime,
154 wintitle1,
154 wintitle1,
155 show,
155 show,
156 xmin,
156 xmin,
157 xmax,
157 xmax,
158 ymin,
158 ymin,
159 ymax)
159 ymax)
160
160
161 if type == "iq":
161 if type == "iq":
162 self.plot_iq(dataOut.heightList,
162 self.plot_iq(dataOut.heightList,
163 dataOut.data[:,i,:],
163 dataOut.data[:,i,:],
164 id,
164 id,
165 channelIndexList,
165 channelIndexList,
166 thisDatetime,
166 thisDatetime,
167 wintitle1,
167 wintitle1,
168 show,
168 show,
169 xmin,
169 xmin,
170 xmax,
170 xmax,
171 ymin,
171 ymin,
172 ymax)
172 ymax)
173
173
174 self.draw()
174 self.draw()
175
176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
177 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
178
179 self.save(figpath=figpath,
180 figfile=figfile,
181 save=save,
182 ftp=ftp,
183 wr_period=wr_period,
184 thisDatetime=thisDatetime)
175
185
176 else:
186 else:
177 wintitle += " [Profile = %d] " %dataOut.profileIndex
187 wintitle += " [Profile = %d] " %dataOut.profileIndex
178
188
179 if type == "power":
189 if type == "power":
180 self.plot_power(dataOut.heightList,
190 self.plot_power(dataOut.heightList,
181 dataOut.data,
191 dataOut.data,
182 id,
192 id,
183 channelIndexList,
193 channelIndexList,
184 thisDatetime,
194 thisDatetime,
185 wintitle,
195 wintitle,
186 show,
196 show,
187 xmin,
197 xmin,
188 xmax,
198 xmax,
189 ymin,
199 ymin,
190 ymax)
200 ymax)
191
201
192 if type == "iq":
202 if type == "iq":
193 self.plot_iq(dataOut.heightList,
203 self.plot_iq(dataOut.heightList,
194 dataOut.data,
204 dataOut.data,
195 id,
205 id,
196 channelIndexList,
206 channelIndexList,
197 thisDatetime,
207 thisDatetime,
198 wintitle,
208 wintitle,
199 show,
209 show,
200 xmin,
210 xmin,
201 xmax,
211 xmax,
202 ymin,
212 ymin,
203 ymax)
213 ymax)
204
214
205 self.draw()
215 self.draw()
206
216
217 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
218 figfile = self.getFilename(name = str_datetime)
219
207 self.save(figpath=figpath,
220 self.save(figpath=figpath,
208 figfile=figfile,
221 figfile=figfile,
209 save=save,
222 save=save,
210 ftp=ftp,
223 ftp=ftp,
211 wr_period=wr_period,
224 wr_period=wr_period,
212 thisDatetime=thisDatetime)
225 thisDatetime=thisDatetime)
General Comments 0
You need to be logged in to leave comments. Login now