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