#!/usr/bin/python # Note: the cgi-bin area is at: # /home/www.gb.nrao.edu/active/cgi-bin/ import cgi import cgitb cgitb.enable() import sys import string import math import os import MySQLdb import datetime global rcvr, beam, polty, rrcvr, ppt, rfreq, datesel, pdate, butval, rcvrlist # from gbt.ygor.getConfigValue import * #-------------------------------------------------- # database access parameters - # dbhost = getConfigValue("localdb", "DatabaseHost") dbhost = "gbtdata.gbt.nrao.edu" rcvrdb = "receivers" dbpassword = "showmedata" dbuser = "turtle_query" #-------------------------------------------------- rcvr="unknown" beam = 0 polty = "unk" rrcvr = "unk" ppt = "unk" rfreq = 0 datesel="" pdate=datetime.date(1999,01,01) butval="" rcvrlist = ['Rcvr_342 (MHz)', 'Rcvr_450 (MHz)', 'Rcvr_600 (MHz)', 'Rcvr_800 (MHz)', \ 'Rcvr_1070 (MHz)', 'Rcvr1_2 (GHz)', 'Rcvr2_3 (GHz)', 'Rcvr4_6 (GHz)', \ 'Rcvr8_10 (GHz)', 'Rcvr12_18 (GHz)', 'Rcvr18_26 (GHz)', 'RcvrArray18_26', \ 'Rcvr26_40 (GHz)','Rcvr40_52 (GHz)','Rcvr68_92 (GHz)'] #------------------------------------------------- # get list of channels and list of dates. #------------------------------------------------- def getchans( rcvrname, rfreq ) : chlist = [] # channel list dlist = [] # date slist blist = [] # beam list plist = [] # pol list if rcvrname == "unk" : return(dlist) try : db = MySQLdb.connect(passwd=dbpassword, db=rcvrdb, host=dbhost, user=dbuser) cursor = db.cursor() except : print "Cannot open the database: ", rcvrdb return q = "select id, date, receiver, channel, beam, polarization from measurement where receiver = '%s' " % (rcvrname) cursor.execute(q) fieldValues = cursor.fetchall() nvals = len(fieldValues) cursor.close() for fv in fieldValues : # print fv[0], fv[1], fv[2], fv[3], fv[4], fv[5] if rfreq == 0 : if fv[1] not in dlist : dlist.append( fv[1]) else : if fv[3].find( str(rfreq) ) > 0 : if fv[1] not in dlist : dlist.append( fv[1]) # if fv[3] not in chlist : chlist.append( fv[3]) # if fv[4] not in blist : blist.append( fv[4]) # if fv[5] not in plist : plist.append( fv[5]) return (dlist) # return date list and channel list #------------------------------------------------- #------------------------------------------------- # reqdate is a datetime object # if beamsel is None it uses beam 1 # for VLBI, gets just the R and L channels def writevtcals(rcvrname, reqdate=None, beamsel=None, polmode=None, rfreq=rfreq) : sbeam = 1 if beamsel != None : sbeam = int(beamsel) pmode = 'Circ' if polmode == 'Lin' : pmode = polmode fvsel = [] dslist = [] testpol1 = 'L' testpol2 = 'R' if pmode == 'Lin' : testpol1 = 'X' testpol2 = 'Y' print "
Receiver:", rcvrname
print " req date = ", reqdate, " beam=",sbeam, " pol=", polmode
try :
db = MySQLdb.connect(passwd=dbpassword, db=rcvrdb,
host=dbhost, user=dbuser)
cursor = db.cursor()
except :
print "
Cannot open the database: ", rcvrdb
return
try:
q = "select id, date, receiver, channel, beam, polarization from measurement where receiver = '%s' and beam = '%d' " % (rcvrname,sbeam)
#print "
q=", q
cursor.execute(q)
fieldValues = cursor.fetchall()
nvals = len(fieldValues)
dslist = [reqdate]
except :
print "
Cannot read from the database: ", rcvrdb, dbhost
return
# print "
using date = ", dslist[0]
rd = dslist[0]
fvsel = []
for fv in fieldValues :
if (fv[1] == rd ) : # get just the entries matching the requested date
# if prime focus, select required frequency
if rfreq == 0 :
bmpol = "%s%d" % (fv[5],fv[4])
fvsel.append((fv[0], bmpol, fv[5], fv[3]))
else :
if fv[3].find(str(rfreq)) > 0 :
bmpol = "%s%d" % (fv[5],fv[4])
fvsel.append((fv[0], bmpol, fv[5], fv[3]))
rrdat = []
lldat = []
for fvs in fvsel :
print "
fvs=",fvs
q2 = "select frequency, temperature, low_cal, high_cal, id from tcal where id = '%d' " % (fvs[0])
cursor.execute(q2)
fvs2 = sorted(cursor.fetchall())
nfvs2 = len(fvs2)
if fvs[2] == testpol2 : rrdat = fvs2
if fvs[2] == testpol1 : lldat = fvs2
if len(rrdat) <= 1 and len(lldat) <= 1 :
print "
Sorry, no data for this rcvr/date/pol"
return
cursor.close()
# get frequency spacing
xx1 = rrdat[0]
if len(rrdat)>0 :
xx2 = rrdat[1]
rrspace = 1000.0*(xx2[0] - xx1[0])
else : rrspace = 0.0
xx1 = lldat[0]
if len(lldat)>0 :
xx2 = lldat[1]
llspace = 1000.0*(xx2[0] - xx1[0])
else : llspace = 0.0
print "
Freq grid(MHz) %8.3f XL, %8.3f YR" % (llspace,rrspace)
compdate = "%4d%02d%02d" % (rd.year,rd.month,rd.day)
outfilename = "%s_%s%d_%s.txt" % (rcvrname, pmode, sbeam,compdate)
# print "
outdata=",outfilename, len(rrdat), len(lldat)
print "
Writing ", len(lldat), " XL, and ", len(rrdat), " YR cals"
if len(lldat) != len(rrdat) :
print "
Number of RCPs not the same as LCPs: list probably bogus!"
# try dumping the data into the web page
wmode = "w"
# outf = open(outfilename, wmode)
# print header lines
# outf.write( "! Tcals for the %s receiver at GB\n" % (rcvrname))
print "
" print "
' # if len(tcallist) > 0 : # print rcvr, beam, polty, ppt, rrcvr, rfreq, datesel, butval def writepage(tst=None) : global rcvr, beam, polty, rrcvr, ppt, rfreq, datesel, pdate, butval, rcvrlist tcallist = [] dlist = [] print "Content-Type: text/html" print print "\n" print "
"
if tst == None :
try :
form = cgi.FieldStorage()
retrieve1(form)
dlist = getchans(rrcvr, rfreq)
# if form["butpress"].value == "get dates" :
putnewpage(dlist,tcallist)
# if butval == "get dates" :
# print "got ", butval
if butval == "get tcals" :
tcallist = []
# print "got ", butval
writevtcals(rrcvr, reqdate=pdate, beamsel=beam, polmode=ppt,rfreq=rfreq )
except :
print "\n
Some HTML Error happened."
else :
# rrcvr='Rcvr8_10'
# rcvr='Rcvr8_10'
rrcvr='Rcvr1_2'
rcvr='Rcvr1_2'
rfreq=0
dlist = getchans(rrcvr,rfreq)
print dlist
# set test values
beam=1
polty='Circular'
ppt='Circ'
# datesel=dlist[1]
pdate=dlist[-1]
butval='get dates'
print 'pdate=',pdate
putnewpage(dlist,tcallist)
writevtcals(rrcvr, reqdate=pdate, beamsel=beam, polmode=ppt,rfreq=rfreq )
print ""
print ""
#-----------------------------------------------------------
# main program
#-----------------------------------------------------------
sys.stderr = sys.stdout
writepage(None)