Changeset 712 for trunk/monitor/cgi-bin
- Timestamp:
- 11/17/05 14:12:49 (19 years ago)
- Location:
- trunk/monitor/cgi-bin
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/monitor/cgi-bin/asapconfig.py
r703 r712 1 # 1 #asapconfig.py 2 2 3 rpfpath = [] 4 # Append observing directories 5 rpfpath.append("/u/mar637/brage/singledish/data") 6 rpfpath.append("/u/mar637/brage/singledish/data/mopra200505") 7 observatory = "Mopra" 3 observatory = {'rpfpath': [], 4 'name': 'observatory', 5 'lines' : {} } 8 6 9 7 import os,sys … … 16 14 17 15 # This is needed for plotting with matplotlib 16 # where matplotlib data is located 18 17 os.environ["MATPLOTLIBDATA"]="/opt/share/matplotlib" 19 os.environ["HOME"]="/tmp" 20 21 # logsink class 22 class LogSink: 23 def __init__(self): 24 self.content = [] 25 def write(self, string): 26 self.content.append(string) 18 # where matplotlib puts it temporary font files 19 # this location can also have a custom .matplotlibrc 20 os.environ["HOME"]="/var/www/asapmon/tmp" -
trunk/monitor/cgi-bin/asapmon.py
r703 r712 2 2 import sys,os 3 3 import cgi 4 # enable cgi debugging4 #cgi debug 5 5 import cgitb; cgitb.enable() 6 6 … … 8 8 9 9 #absolute home 10 htmlbase = "/var/www/asaptest/" 11 cgibase = "/cgi-bin/asapmon" 12 absbase = "/asapmon" 13 14 from asapconfig import * 15 logsink = LogSink() 16 sys.stdout = logsink 17 sys.stderr = logsink 10 abspath= "/var/www/asapmon/" 11 cgiloc = "/cgi-bin/asapmon/" 12 tmppath = abspath+"tmp/" 13 htmlloc = "/asapmon/" 14 tmploc = "/asapmon/tmp/" 15 16 from obsconfig import * 17 18 # a redirection object for stdout/stderr 19 class WritableObject: 20 def __init__(self): 21 self.content = [] 22 def write(self, string): 23 self.content.append(string) 24 25 logsink = WritableObject() 26 logsink2 = WritableObject() 27 sys.stdout =logsink 28 sys.stderr = logsink2 18 29 import asap 19 30 sys.stdout = sys.__stdout__ … … 32 43 self.logsink = WritableObject() 33 44 34 def decodePath(self ,pi,fi):35 pi = int(pi)36 fi = int(fi)37 p = rpfpath[pi]45 def decodePath(self): 46 pi = self.fields['cdir'] 47 fi = self.fields['cfile'] 48 p = observatory['rpfpath'][pi] 38 49 from filelist import FileList 39 50 fl = FileList(pi) 40 51 if fl.error: 41 52 return None 42 f = fl.files[fi] 43 return p+"/"+f 53 out = [] 54 for i in fi: 55 out.append(p+"/"+fl.files[i]) 56 return out 57 58 def decodeWindow(self,window): 59 if not len(window.strip()): return None,None 60 x = window.split(",") 61 return [float(x[0].strip()),float(x[1].strip())] 62 63 def decodeWindows(self,window): 64 import re 65 p = re.compile("(\\[*\d+\\.*\d*,\d+\\.*\d*\\]*)") 66 r = re.compile("[\\[\\]]") 67 return [self.decodeWindow(re.sub(r,'',s)) for s in re.findall(p,window)] 68 69 def setDefaultFields(self): 70 self.fields['directories'] = observatory['rpfpath'] 71 self.fields['cdir'] = len(self.fields['directories'])-1 72 from filelist import FileList 73 files = [] 74 fl = FileList(len(observatory['rpfpath'])-1) 75 if not fl.error: 76 self.fields['files'] = fl.files 77 self.fields['cfile'] = len(fl.files)-1 78 self.fields['restfreqs'] = observatory['lines'].keys() 79 self.fields['border'] = range(10) 80 self.fields['imagename'] = "" 81 self.fields['cunit'] = 0 82 self.fields['units'] = ["channel","km/s","GHz"] 83 self.fields['baseline'] = 0 84 self.fields['cpolyorder'] = 0 85 self.fields['quotient'] = 0 86 self.fields['average'] = 0 87 self.fields['doppler'] = "RADIO" 88 self.fields['frame'] = "LSRK" 89 self.fields['restn'] = [11,1] 90 self.fields['stokes'] = 0 91 self.fields['summary'] = "" 92 self.fields['bin'] = 0 93 self.fields['brangewindow'] = "" 94 self.fields['nif'] = [] 95 self.fields['sourcenames'] = [] 96 self.fields['csource'] = "" 97 98 99 def getFormFields(self): 100 self.fields['cunit'] = int(self.form.getfirst("unit",0)) 101 self.fields['frame'] = self.form.getfirst("frame","TOPO") 102 self.fields['doppler'] = self.form.getfirst("doppler","RADIO") 103 self.fields['restn'] = [] 104 105 self.fields['plotwindow'] = self.form.getfirst("plotwindow","") 106 self.fields['baseline'] = int(self.form.has_key("baseline")) 107 self.fields['cpolyorder'] = int(self.form.getfirst("polyorder",0)) 108 self.fields['quotient'] = int(self.form.has_key("quotient")) 109 self.fields['doppler'] = self.form.getfirst("doppler","RADIO") 110 self.fields['frame'] = self.form.getfirst("frame","LSRK") 111 self.fields['cdir'] = int(self.form.getfirst("dlist",None)) 112 self.fields['cfile'] = [int(k) for k in self.form.getlist("list")] 113 self.fields['average'] = int(self.form.has_key("average")) 114 self.fields['stokes'] = int(self.form.has_key("stokes")) 115 self.fields['bin'] = int(self.form.has_key("bin")) 116 self.fields['debug'] = ""#self.fields['restn'] 117 self.fields['csource'] = self.form.getfirst("csource","") 118 119 def getRest(self): 120 alllines = observatory['lines'].values() 121 lines = [] 122 for i in self.fields['restn']: 123 lines.append(alllines[i]) 124 return lines 44 125 45 126 def plotForm(self): 46 pathidx = self.form.getfirst("dlist",None) 47 fnameidx = self.form.getfirst("list",None) 48 self.fields['cdir'] = pathidx 49 self.fields['cfile'] = fnameidx 127 self.getFormFields() 128 # decode file location 50 129 from filelist import FileList 51 fl = FileList( pathidx)130 fl = FileList(self.fields['cdir']) 52 131 self.fields['files'] = fl.files 53 file=self.decodePath(pathidx,fnameidx) 132 files = self.decodePath() 133 # catch all stdout/err 134 sys.stdout = logsink 135 sys.stderr = logsink2 54 136 try: 55 s = asap.scantable(file) 56 s.set_unit(self.form.getfirst("unit","channel")) 57 s.set_freqframe(self.form.getfirst("frame","LSRK")) 58 s.set_doppler(self.form.getfirst("doppler","RADIO")) 59 60 if self.form.has_key("quotient"): 61 q = s.auto_quotient() 62 del s 63 s=q 64 if self.form.has_key('baseline'): 65 if self.form.has_key('polyorder'): 66 s.auto_poly_baseline(order=int(self.form.getfirst("polyorder",0))) 137 scans = [asap.scantable(f) for f in files] 138 outscans = [] 139 self.fields['nif'] = range(scans[-1].nif()) 140 for i in self.fields['nif']: 141 name = "rest%d" % i 142 self.fields['restn'].append(int(self.form.getfirst(name,0))) 143 restfs = self.getRest() 144 145 # source name selection 146 import re 147 for s in scans: 148 srcnames = s.get_sourcename() 149 for i in srcnames: 150 # only add the names once 151 i = not i in self.fields['sourcenames'] and i 152 if i: 153 # filter off scans 154 i = not re.search(re.compile("_[R,e,w]$"),i) and i 155 if i: 156 self.fields['sourcenames'].append(i) 157 for s in scans: 158 # form quotient 159 if self.form.has_key("quotient"): 160 s = s.auto_quotient() 161 162 # get source by name 163 cs = self.fields['csource'] 164 if len(cs) > 0: 165 if cs in self.fields['sourcenames']: 166 ss = s.get_scan(self.fields['csource']) 167 if isinstance(ss,asap.scantable): 168 s = ss 169 del ss 170 else: 171 # get only the last source in the table if not averaging 172 s = s.get_scan(self.fields['sourcenames'][-1]) 173 #self.fields['debug'] = "DEBUG" 174 self.fields['csource'] = s.get_sourcename()[-1] 175 # baseline 176 if self.form.has_key('baseline'): 177 order = self.fields['cpolyorder'] 178 brstr = self.form.getfirst('brangewindow','').strip() 179 # auto baseline or user window 180 if brstr: 181 self.fields['brangewindow'] = brstr 182 brange = self.decodeWindows(brstr) 183 if len(brange): 184 self.fields['brangewindow'] = brstr 185 if self.fields['cunit'] == 1: 186 srest = s._getrestfreqs() 187 if isinstance(srest,tuple) and len(srest) != s.nif(): 188 s.set_restfreqs(restfs,unit="GHz") 189 s.set_unit(self.fields['units'][self.fields['cunit']]) 190 s.set_freqframe(self.form.getfirst("frame","LSRK")) 191 s.set_doppler(self.form.getfirst("doppler","RADIO")) 192 193 m = s.create_mask(brange) 194 s.poly_baseline(mask=m,order=order) 195 else: 196 s.auto_poly_baseline(order=order) 197 outscans.append(s) 198 del scans 199 200 if self.fields['average']: 201 outscans = asap.average_time(outscans,weight='tsys') 202 else: 203 outscans = outscans[-1] 204 205 if self.fields['bin']: 206 outscans.bin() 207 208 #duplicated as average_time doesn't remember settings 209 if self.fields['cunit'] == 1: 210 srest = outscans._getrestfreqs() 211 if isinstance(srest,tuple) and len(srest) != outscans.nif(): 212 outscans.set_restfreqs(restfs,unit="GHz") 213 outscans.set_unit(self.fields['units'][self.fields['cunit']]) 214 outscans.set_freqframe(self.form.getfirst("frame","LSRK")) 215 outscans.set_doppler(self.form.getfirst("doppler","RADIO")) 216 217 self.fields['summary'] = str(outscans) 218 asap.rcParams['plotter.decimate'] = True 219 asap.rcParams['plotter.ganged'] = False 220 from matplotlib import rcParams as rcp 221 rcp['tick.labelsize'] = 6 222 rcp['axes.labelsize'] = 8 223 rcp['axes.titlesize'] = 8 224 rcp['figure.subplot.wspace'] = 0.3 225 rcp['figure.subplot.hspace'] = 0.3 226 del asap.plotter 227 asap.plotter = asap.asapplotter(False) 67 228 if s.nif() > 1: 68 asap.plotter.set_mode(" t","i")229 asap.plotter.set_mode("p","i") 69 230 else: 70 asap.plotter.set_mode("t","p") 71 asap.plotter.plot(s) 72 73 imname = htmlbase+"tmp/plot.png" 74 asap.plotter.save(imname,dpi=80) 75 self.fields['imagename'] = absbase+"/tmp/plot.png" 76 except RuntimeError: 231 if s.npol() > 2: 232 asap.plotter.set_mode("t","p") 233 else: 234 asap.plotter.set_mode("p","t") 235 asap.plotter.plot(outscans) 236 if self.fields['stokes']: 237 pols = "I" 238 if outscans.npol() > 2: 239 pols += " Q U V" 240 asap.plotter.set_cursor(pol=pols) 241 x0,x1 = self.decodeWindow(self.fields['plotwindow']) 242 asap.plotter.set_range(x0,x1) 243 imname = tmppath+"plot.png" 244 asap.plotter.save(imname,dpi=96) 245 self.fields['imagename'] = tmploc+"plot.png" 246 except RuntimeError,e: 247 self.fields['debug'] = e 77 248 return 78 249 … … 94 265 95 266 def main(self): 96 self.fields['directories'] = rpfpath 97 self.fields['cdir'] = len(rpfpath)-1 98 from filelist import FileList 99 files = [] 100 fl = FileList(len(rpfpath)-1) 101 if not fl.error: 102 self.fields['files'] = fl.files 103 self.fields['cfile'] = len(fl.files)-1 104 self.fields['restfreqs'] = [110.0,86.0] 105 self.fields['border'] = range(10) 106 self.fields['imagename'] = "" 107 sys.stdout = self.logsink 108 sys.stderr = self.logsink 109 title = "ASAP %s Online Monitor" % (observatory) 110 if ( not self.form.has_key("plot")): 111 self.buildContext(title) 112 resetstd() 113 self.expandTemplate(htmlbase+"asapmon.html.template") 114 else: # run 267 self.setDefaultFields() 268 title = "ASAP %s Online Monitor" % (observatory['name']) 269 tmplname = abspath+"asapmon.html.template" 270 if ( self.form.has_key("plot")): 115 271 self.plotForm() 116 self.buildContext(title) 117 resetstd() 118 self.expandTemplate(htmlbase+"asapmon.html.template") 272 self.buildContext(title) 273 resetstd() 274 #os.system('rm -rf /var/www/asapmon/tmp/.matplotlib') 275 self.expandTemplate(tmplname) 119 276 120 277 -
trunk/monitor/cgi-bin/filelist.py
r703 r712 1 1 #!/usr/bin/python 2 2 import os 3 from asapconfig import rpfpath3 from asapconfig import observatory 4 4 5 5 class FileList: … … 12 12 self.error = None 13 13 if loc is None: 14 loc = rpfpath[0]14 loc = observatory['rpfpath'][0] 15 15 else: 16 16 loc = int(loc) 17 if loc< 0 or loc >=len( rpfpath):17 if loc< 0 or loc >=len(observatory['rpfpath']): 18 18 self.error = "Invalid Path" 19 19 return 20 20 else: 21 loc = rpfpath[loc]21 loc = observatory['rpfpath'][loc] 22 22 if os.path.exists(loc) and os.path.isdir(loc): 23 23 self.files = filter(lambda x: x.lower().endswith("rpf"), os.listdir(loc))
Note:
See TracChangeset
for help on using the changeset viewer.