##// END OF EJS Templates
Fixing PNG File Storage...
Daniel Valdez -
r494:fec49901e99a
parent child
Show More
@@ -15,42 +15,6 def isRealtime(utcdatatime):
15 return True
15 return True
16
16
17
17
18 class FTP_Thread (threading.Thread):
19 def __init__(self):
20 threading.Thread.__init__(self)
21 self.exitFlag = 0
22 self.queueLock = threading.Lock()
23 self.workQueue = Queue.Queue()
24
25 def run(self):
26 self.send_data()
27
28 def fin(self):
29 self.exitFlag = 1
30
31 def put_data(self, data):
32 # Fill the queue
33 self.queueLock.acquire()
34 self.workQueue.put(data)
35 self.queueLock.release()
36
37 def send_data(self):
38 while not self.exitFlag:
39 if self.workQueue.qsize():
40
41 data = self.workQueue.get(True)
42
43 try:
44 ftpObj = Ftp(host=data['server'],
45 username=data['username'],
46 passw=data['password'],
47 remotefolder=data['folder'])
48
49 ftpObj.upload(data['figfilename'])
50 ftpObj.close()
51 except:
52 print ValueError, 'Error FTP'
53 print "don't worry still running the program"
54
18
55
19
56 class Figure:
20 class Figure:
@@ -259,22 +223,7 class Figure:
259
223
260 self.__driver.saveFigure(self.fig, filename, *args)
224 self.__driver.saveFigure(self.fig, filename, *args)
261
225
262 def sendByFTP(self, figfilename, server, folder, username, password):
263 ftpObj = Ftp(host=server, username=username, passw=password, remotefolder=folder)
264 ftpObj.upload(figfilename)
265 ftpObj.close()
266
267 def sendByFTP_Thread(self, figfilename, server, folder, username, password):
268 data = {'figfilename':figfilename,'server':server,'folder':folder,'username':username,'password':password}
269
226
270 if not(self.__isConfigThread):
271
272 self.thread = FTP_Thread()
273 self.thread.start()
274 self.__isConfigThread = True
275
276 self.thread.put_data(data)
277 #print 'thread.isAlive()', self.thread.isAlive()
278
227
279
228
280 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
229 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
@@ -75,7 +75,7 class SpectraHeisScope(Figure):
75
75
76 def run(self, dataOut, id, wintitle="", channelList=None,
76 def run(self, dataOut, id, wintitle="", channelList=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
78 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
78 figpath='', figfile=None, ftp=False, wr_period=1, show=True,
79 server=None, folder=None, username=None, password=None):
79 server=None, folder=None, username=None, password=None):
80
80
81 """
81 """
@@ -153,18 +153,20 class SpectraHeisScope(Figure):
153
153
154
154
155 self.draw()
155 self.draw()
156
156
157 if save:
157 if figfile == None:
158 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
158 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
159 if figfile == None:
159 figfile = self.getFilename(name = str_datetime)
160 figfile = self.getFilename(name = date)
160
161
161 if figpath != '':
162 self.saveFigure(figpath, figfile)
163
164 self.counter_imagwr += 1
162 self.counter_imagwr += 1
165 if (ftp and (self.counter_imagwr==wr_period)):
163 if (self.counter_imagwr>=wr_period):
166 ftp_filename = os.path.join(figpath,figfile)
164 # store png plot to local folder
167 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
165 self.saveFigure(figpath, figfile)
166 # store png plot to FTP server according to RT-Web format
167 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
168 #ftp_filename = os.path.join(figpath, name)
169 #self.saveFigure(figpath, ftp_filename)
168 self.counter_imagwr = 0
170 self.counter_imagwr = 0
169
171
170 class RTIfromSpectraHeis(Figure):
172 class RTIfromSpectraHeis(Figure):
@@ -187,6 +189,7 class RTIfromSpectraHeis(Figure):
187 self.counter_imagwr = 0
189 self.counter_imagwr = 0
188 self.xdata = None
190 self.xdata = None
189 self.ydata = None
191 self.ydata = None
192 self.figfile = None
190
193
191 def getSubplots(self):
194 def getSubplots(self):
192
195
@@ -218,7 +221,7 class RTIfromSpectraHeis(Figure):
218 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
221 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
219 xmin=None, xmax=None, ymin=None, ymax=None,
222 xmin=None, xmax=None, ymin=None, ymax=None,
220 timerange=None,
223 timerange=None,
221 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
224 save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True,
222 server=None, folder=None, username=None, password=None):
225 server=None, folder=None, username=None, password=None):
223
226
224 if channelList == None:
227 if channelList == None:
@@ -270,7 +273,7 class RTIfromSpectraHeis(Figure):
270
273
271 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
274 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
272 self.isConfig = True
275 self.isConfig = True
273
276 self.figfile = figfile
274 self.xdata = numpy.array([])
277 self.xdata = numpy.array([])
275 self.ydata = numpy.array([])
278 self.ydata = numpy.array([])
276
279
@@ -299,20 +302,23 class RTIfromSpectraHeis(Figure):
299
302
300 self.draw()
303 self.draw()
301
304
302 if save:
305 if x[1] >= self.axesList[0].xmax:
303
306 self.counter_imagwr = wr_period
304 if figfile == None:
305 figfile = self.getFilename(name = self.name)
306
307 self.saveFigure(figpath, figfile)
308
309 self.counter_imagwr += 1
310 if (ftp and (self.counter_imagwr==wr_period)):
311 ftp_filename = os.path.join(figpath,figfile)
312 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
313 self.counter_imagwr = 0
314
315 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
316 self.isConfig = False
317 del self.xdata
307 del self.xdata
318 del self.ydata
308 del self.ydata
309 self.__isConfig = False
310
311 if self.figfile == None:
312 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
313 self.figfile = self.getFilename(name = str_datetime)
314
315 if figpath != '':
316 self.counter_imagwr += 1
317 if (self.counter_imagwr>=wr_period):
318 # store png plot to local folder
319 self.saveFigure(figpath, self.figfile)
320 # store png plot to FTP server according to RT-Web format
321 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
322 #ftp_filename = os.path.join(figpath, name)
323 #self.saveFigure(figpath, ftp_filename)
324 self.counter_imagwr = 0
@@ -379,32 +379,22 class CrossSpectraPlot(Figure):
379
379
380 self.draw()
380 self.draw()
381
381
382 if save:
382 if figfile == None:
383
383 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
384 figfile = self.getFilename(name = str_datetime)
385
386 if figpath != '':
384 self.counter_imagwr += 1
387 self.counter_imagwr += 1
385 if (self.counter_imagwr==wr_period):
388 if (self.counter_imagwr>=wr_period):
386 if figfile == None:
389 # store png plot to local folder
387 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
388 figfile = self.getFilename(name = str_datetime)
389
390 self.saveFigure(figpath, figfile)
390 self.saveFigure(figpath, figfile)
391
391 # store png plot to FTP server according to RT-Web format
392 if ftp:
392 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
393 #provisionalmente envia archivos en el formato de la web en tiempo real
393 ftp_filename = os.path.join(figpath, name)
394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
394 self.saveFigure(figpath, ftp_filename)
395 path = '%s%03d' %(self.PREFIX, self.id)
396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
397 self.saveFigure(figpath, ftp_file)
398 ftp_filename = os.path.join(figpath,ftp_file)
399
400 try:
401 self.sendByFTP(ftp_filename, server, folder, username, password)
402 except:
403 self.counter_imagwr = 0
404 print ValueError, 'Error FTP'
405
406 self.counter_imagwr = 0
395 self.counter_imagwr = 0
407
396
397
408 class RTIPlot(Figure):
398 class RTIPlot(Figure):
409
399
410 isConfig = None
400 isConfig = None
@@ -937,19 +927,23 class PowerProfile(Figure):
937
927
938 self.draw()
928 self.draw()
939
929
940 if save:
930 if figfile == None:
941 date = thisDatetime.strftime("%Y%m%d")
931 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
942 if figfile == None:
932 figfile = self.getFilename(name = str_datetime)
943 figfile = self.getFilename(name = date)
933
944
934 if figpath != '':
945 self.saveFigure(figpath, figfile)
946
947 self.counter_imagwr += 1
935 self.counter_imagwr += 1
948 if (ftp and (self.counter_imagwr==wr_period)):
936 if (self.counter_imagwr>=wr_period):
949 ftp_filename = os.path.join(figpath,figfile)
937 # store png plot to local folder
950 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
938 self.saveFigure(figpath, figfile)
939 # store png plot to FTP server according to RT-Web format
940 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
941 #ftp_filename = os.path.join(figpath, name)
942 #self.saveFigure(figpath, ftp_filename)
951 self.counter_imagwr = 0
943 self.counter_imagwr = 0
952
944
945
946
953 class Noise(Figure):
947 class Noise(Figure):
954
948
955 isConfig = None
949 isConfig = None
@@ -970,11 +964,12 class Noise(Figure):
970 self.xdata = None
964 self.xdata = None
971 self.ydata = None
965 self.ydata = None
972
966
973 self.PLOT_CODE = 77
967 self.PLOT_CODE = 17
974 self.FTP_WEI = None
968 self.FTP_WEI = None
975 self.EXP_CODE = None
969 self.EXP_CODE = None
976 self.SUB_EXP_CODE = None
970 self.SUB_EXP_CODE = None
977 self.PLOT_POS = None
971 self.PLOT_POS = None
972 self.figfile = None
978
973
979 def getSubplots(self):
974 def getSubplots(self):
980
975
@@ -1079,7 +1074,7 class Noise(Figure):
1079
1074
1080 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1075 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1081 self.isConfig = True
1076 self.isConfig = True
1082
1077 self.figfile = figfile
1083 self.xdata = numpy.array([])
1078 self.xdata = numpy.array([])
1084 self.ydata = numpy.array([])
1079 self.ydata = numpy.array([])
1085
1080
@@ -1118,34 +1113,234 class Noise(Figure):
1118
1113
1119 self.draw()
1114 self.draw()
1120
1115
1121 # if save:
1116 if x[1] >= self.axesList[0].xmax:
1122 #
1117 self.counter_imagwr = wr_period
1123 # if figfile == None:
1118 del self.xdata
1124 # figfile = self.getFilename(name = self.name)
1119 del self.ydata
1125 #
1120 self.__isConfig = False
1126 # self.saveFigure(figpath, figfile)
1127
1121
1128 if save:
1122 if self.figfile == None:
1129
1123 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1124 self.figfile = self.getFilename(name = str_datetime)
1125
1126 if figpath != '':
1130 self.counter_imagwr += 1
1127 self.counter_imagwr += 1
1131 if (self.counter_imagwr==wr_period):
1128 if (self.counter_imagwr>=wr_period):
1132 if figfile == None:
1129 # store png plot to local folder
1133 figfile = self.getFilename(name = self.name)
1130 self.saveFigure(figpath, self.figfile)
1134 self.saveFigure(figpath, figfile)
1131 # store png plot to FTP server according to RT-Web format
1135
1132 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1136 if ftp:
1133 ftp_filename = os.path.join(figpath, name)
1137 #provisionalmente envia archivos en el formato de la web en tiempo real
1134 self.saveFigure(figpath, ftp_filename)
1138 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1139 path = '%s%03d' %(self.PREFIX, self.id)
1140 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1141 self.saveFigure(figpath, ftp_file)
1142 ftp_filename = os.path.join(figpath,ftp_file)
1143 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1144 self.counter_imagwr = 0
1145
1146 self.counter_imagwr = 0
1135 self.counter_imagwr = 0
1147
1136
1148 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1137
1149 self.isConfig = False
1138 class BeaconPhase(Figure):
1139
1140 __isConfig = None
1141 __nsubplots = None
1142
1143 PREFIX = 'beacon_phase'
1144
1145 def __init__(self):
1146
1147 self.timerange = 24*60*60
1148 self.__isConfig = False
1149 self.__nsubplots = 1
1150 self.counter_imagwr = 0
1151 self.WIDTH = 600
1152 self.HEIGHT = 300
1153 self.WIDTHPROF = 120
1154 self.HEIGHTPROF = 0
1155 self.xdata = None
1156 self.ydata = None
1157
1158 self.PLOT_CODE = 18
1159 self.FTP_WEI = None
1160 self.EXP_CODE = None
1161 self.SUB_EXP_CODE = None
1162 self.PLOT_POS = None
1163
1164 self.filename_phase = None
1165
1166 self.figfile = None
1167
1168 def getSubplots(self):
1169
1170 ncol = 1
1171 nrow = 1
1172
1173 return nrow, ncol
1174
1175 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1176
1177 self.__showprofile = showprofile
1178 self.nplots = nplots
1179
1180 ncolspan = 7
1181 colspan = 6
1182 self.__nsubplots = 2
1183
1184 self.createFigure(id = id,
1185 wintitle = wintitle,
1186 widthplot = self.WIDTH+self.WIDTHPROF,
1187 heightplot = self.HEIGHT+self.HEIGHTPROF,
1188 show=show)
1189
1190 nrow, ncol = self.getSubplots()
1191
1192 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1193
1194 def save_phase(self, filename_phase):
1195 f = open(filename_phase,'w+')
1196 f.write('\n\n')
1197 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1198 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1199 f.close()
1200
1201 def save_data(self, filename_phase, data, data_datetime):
1202 f=open(filename_phase,'a')
1203 timetuple_data = data_datetime.timetuple()
1204 day = str(timetuple_data.tm_mday)
1205 month = str(timetuple_data.tm_mon)
1206 year = str(timetuple_data.tm_year)
1207 hour = str(timetuple_data.tm_hour)
1208 minute = str(timetuple_data.tm_min)
1209 second = str(timetuple_data.tm_sec)
1210 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1211 f.close()
1212
1213
1214 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1215 xmin=None, xmax=None, ymin=None, ymax=None,
1216 timerange=None,
1217 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1218 server=None, folder=None, username=None, password=None,
1219 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1220
1221 if pairsList == None:
1222 pairsIndexList = dataOut.pairsIndexList
1223 else:
1224 pairsIndexList = []
1225 for pair in pairsList:
1226 if pair not in dataOut.pairsList:
1227 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1228 pairsIndexList.append(dataOut.pairsList.index(pair))
1229
1230 if pairsIndexList == []:
1231 return
1232
1233 # if len(pairsIndexList) > 4:
1234 # pairsIndexList = pairsIndexList[0:4]
1235
1236 if timerange != None:
1237 self.timerange = timerange
1238
1239 tmin = None
1240 tmax = None
1241 x = dataOut.getTimeRange()
1242 y = dataOut.getHeiRange()
1243
1244
1245 #thisDatetime = dataOut.datatime
1246 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1247 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1248 xlabel = "Local Time"
1249 ylabel = "Phase"
1250
1251 nplots = len(pairsIndexList)
1252 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1253 phase_beacon = numpy.zeros(len(pairsIndexList))
1254 for i in range(nplots):
1255 pair = dataOut.pairsList[pairsIndexList[i]]
1256 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1257 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1258 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1259 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1260 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1261
1262 #print "Phase %d%d" %(pair[0], pair[1])
1263 #print phase[dataOut.beacon_heiIndexList]
1264
1265 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1266
1267 if not self.__isConfig:
1268
1269 nplots = len(pairsIndexList)
1270
1271 self.setup(id=id,
1272 nplots=nplots,
1273 wintitle=wintitle,
1274 showprofile=showprofile,
1275 show=show)
1276
1277 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1278 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1279 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1280
1281 self.FTP_WEI = ftp_wei
1282 self.EXP_CODE = exp_code
1283 self.SUB_EXP_CODE = sub_exp_code
1284 self.PLOT_POS = plot_pos
1285
1286 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1287 self.__isConfig = True
1288 self.figfile = figfile
1289 self.xdata = numpy.array([])
1290 self.ydata = numpy.array([])
1291
1292 #open file beacon phase
1293 path = '%s%03d' %(self.PREFIX, self.id)
1294 beacon_file = os.path.join(path,'%s.txt'%self.name)
1295 self.filename_phase = os.path.join(figpath,beacon_file)
1296 #self.save_phase(self.filename_phase)
1297
1298
1299 #store data beacon phase
1300 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1301
1302 self.setWinTitle(title)
1303
1304
1305 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1306
1307 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1308
1309 axes = self.axesList[0]
1310
1311 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1312
1313 if len(self.ydata)==0:
1314 self.ydata = phase_beacon.reshape(-1,1)
1315 else:
1316 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1317
1318
1319 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1320 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1321 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1322 XAxisAsTime=True, grid='both'
1323 )
1324
1325 self.draw()
1326
1327 if x[1] >= self.axesList[0].xmax:
1328 self.counter_imagwr = wr_period
1150 del self.xdata
1329 del self.xdata
1151 del self.ydata
1330 del self.ydata
1331 self.__isConfig = False
1332
1333 if self.figfile == None:
1334 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1335 self.figfile = self.getFilename(name = str_datetime)
1336
1337 if figpath != '':
1338 self.counter_imagwr += 1
1339 if (self.counter_imagwr>=wr_period):
1340 # store png plot to local folder
1341 self.saveFigure(figpath, self.figfile)
1342 # store png plot to FTP server according to RT-Web format
1343 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1344 ftp_filename = os.path.join(figpath, name)
1345 self.saveFigure(figpath, ftp_filename)
1346 self.counter_imagwr = 0
General Comments 0
You need to be logged in to leave comments. Login now