#!/usr/bin/python #Scripts to automatically carry out the mandatory checks for UVIT #by Atreyee Sinha #special thanks to Yogesh Agarwal #please report bugs to atreyees@iucaa.in; atreyee.sinha@gmail.com #make sure the python mechanize package is installed, #eg using sudo pip install mechanize #run as "python uvit_check2.py output_of_bswt_tool" # eq: python uvit_check2.py bswt_00018924counts25arcmin.txt #This script will give the count rates in the allowed VIS channels, indicated saturated channels and channels with low count rates for tracking import bisect import mechanize import requests import string import re import sys def vischoice(filename): #output of BSWT -> get spectral type from table -> count rates from ETC #filename = output of bswt; either get from online tool or run from command line BV_tab = [-0.3,-0.28,-0.26,-0.25,-0.24,-0.22,-0.2,-0.19,-0.18,-0.17,-0.16,-0.14,-0.13,-0.12,-0.11,-0.09,-0.07,-0.04,-0.01,0.02,0.05,0.08,0.12,0.15,0.17,0.2,0.27,0.3,0.32,0.34,0.35,0.45,0.53,0.6,0.63,0.65,0.68,0.74,0.81,0.86,0.92,0.95,1.0,1.15,1.33,1.37,1.47,1.47,1.5,1.52] #Do confirm, M1.0/M2.0 are both 1.47? spec_type = ["B0.0","B0.5","B1.0","B1.5","B2.0","B2.5","B3.0","B3.5","B4.0","B4.5","B5.0","B6.0","B7.0","B7.5","B8.0","B8.5","B9.0","B9.5","A0.0","A1.0","A2.0","A3.0","A4.0","A5.0","A6.0","A7.0","A8.0","A9.0","F0.0","F1.0","F2.0","F5.0","F8.0","G0.0","G2.0","G3.0","G5.0","G8.0","K0.0","K1.0","K2.0","K3.0","K4.0","K5.0","K7.0","M0.0","M1.0","M2.0","M3.0","M4.0"] #for web interface f=file(filename,"r") Vmag=[] star_id=[] B_V=[] lines=f.readlines() len_line=len(lines) radec=re.split('[: \n]', lines[4]) ra=radec[1] + " " + radec[2] + " " + radec[3] dec=radec[6] + " " + radec[7] + " " + radec[8] coords= ra +", "+dec #print coords for i in range(10,len_line-5): words=lines[i].split(" ") if len(words) > 1: if words[2]=="Field": break star_id.append(words[0]) Vmag.append(float(words[6])) B_V.append(float(words[8])) tup=zip(star_id,Vmag,B_V) # print Vmag,star_id stup=sorted(tup,key=lambda tup: tup[1]) s_id,s_Vmag,s_BV=zip(*stup) #print s_Vmag,s_id,s_BV bright_star=min(5,len(s_id)) print "\n\nCount rates in allowed VIS channels for 5 brightest stars:\n" for i in range(bright_star): ind= max(bisect.bisect_right(BV_tab,s_BV[i])-1,0) spt=spec_type[ind] print s_id[i] obs="F" src_type = "star" sptype1 = spt[0] sptype2 = spt[1] if spt[3]=="0": sptype3=" " if spt[3]=="1": sptype3="I" if spt[3]=="2": sptype3="II" if spt[3]=="3": sptype3="III" if spt[3]=="4": sptype3="IV" if spt[3]=="5": sptype3="V" src_mag = str(s_Vmag[i]) mag_band = "v" postHeaders = { 'Accept-Language': 'en-US,en;q=0.8', 'Origin': 'http://uvit.iiap.res.in', 'Referer': 'http://uvit.iiap.res.in/Software/etc', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36' } payload = {'src_type' : src_type , 'sptype1' : sptype1 , 'sptype2' : sptype2 , 'sptype3' : sptype3 , 'ftype' : 'usemag' , 'src_mag' : src_mag , 'mag_band' : "v" , 'rv' : '3.1' , 'ebv' : '0.0', 'coords' : coords , 'snr' : '5.0' , 'et' : '1800', 'dc' : '25', 'ctype' : 'equatorial' , } r = requests.post("http://uvit.iiap.res.in/cgi-bin/etc.pl", data=payload, headers= postHeaders) #print r.text f1 = r.text tosearch="/download/web-tools/etc/etc_" ind1=f1.find(tosearch) weblink = "http://uvit.iiap.res.in" + f1[ind1:ind1+46] #print weblink br = mechanize.Browser() br.set_handle_robots(False) br.set_handle_refresh(False) br.addheaders = [('User-agent', 'Firefox')] response = br.open(weblink) f1=response.read() filt=["VIS 3", "VIS 2", "VIS 1", "VIS ND1", "VIS BK-7"] val=f1.split() #print val visind=[] for j in range(len(val)-1): if val[j]=="VIS": visind.append(j) #print val[j+1],val[j+2],val[j+3] visind.append(len(val)) for k in range(len(visind)-1): k1=visind[k+1] k2=visind[k] dif=visind[k+1]-visind[k] if (dif > 4.0): continue #print dif if (float(val[k2+2]) < 4801): obs="T" tag = "" if (float(val[k2+2]) > 1000): tag = "[SATURATED]" if (float(val[k2+2]) < 30): tag = "[TOO LOW]" print "VIS"+" "+val[k2+1],":" ,val[k2+2],tag if obs=="F": print "BRIGHT STAR IN FIELD! NO VIS TRACKING ALLOWED!!" return print "\n\n" def main(): bswt=sys.argv[-1] print bswt vischoice(bswt) if __name__=="__main__": main()