casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
getazel.py
Go to the documentation of this file.
00001 # Function to get Az, El for a particular source
00002 
00003 #date= '2010/02/02'
00004 from numpy import *
00005 import casac
00006 
00007 qa = casac.quanta()
00008 me = casac.measures()
00009 
00010 
00011 #obsMeas = me.observatory('ALMA')
00012 #srcCoord = 'J2000 17h52m0s 9d39m0s'
00013 def getazel(obs,srcname,srcCoord,date,tref):
00014     """
00015     Calculate azimuth and elevation of a given source coordinates
00016     Input:
00017     observatory  observatory name known to CASA (e.g. 'ALMA')
00018     srcCoord     source coordinates (RA,Dec) with epoch in a string (e.g. 'J2000 17h45m0.0s -29d00m00.0s' )
00019                  or known ephemeris source name 
00020     date         date in a string (YYYY/MM/DD or YYYY-MM-DD)
00021     tref         time reference (tref='UTC-3' or 'CDT' for Chilean daylight saving time,
00022                                       'UTC-4' or 'CLT' for Chilean standard time,
00023                                       'LST', or 'UTC')
00024     Output:
00025     vector of az values,el values,time,utctime 
00026     TT - 2012.04.19 
00027     """
00028 # original 2010.02.02 TT
00029 # modified 2012.04.19 TT
00030  
00031     t=qa.quantity(date)
00032     if t['unit'] != 'd':
00033         msg = 'Cannot decode date (format should a string with YYYY/MM/DD or YYYY-MM-DD)'
00034         raise Exception, msg
00035     if tref=='UTC-3' or tref=='CDT': # chile daylight saving time
00036         tshft=-3/24.0
00037     elif tref=='UTC-4' or tref=='CLT': # chile standard time
00038         tshft=-4/24.0
00039     else:
00040         tshft=0.0
00041     t0=t['value']
00042     t0 -= tshft
00043     # coaser time (maybe better if called from plotting script for many sources
00044     #tl = arange(1.,1455.,15) # go over a bit longer than a day
00045     tl = arange(1.,1455.,1) # go over a bit longer than a day
00046     tl /=1440.
00047     tm = t0+tl
00048   
00049     obsMeas = me.observatory(obs)
00050     me.doframe(obsMeas)
00051 
00052     elar=zeros(len(tm))
00053     azar=zeros(len(tm))
00054     lastar=zeros(len(tm))
00055     retutc=zeros(len(tm))
00056     
00057     (ep,ra,dec) = srcCoord.split(" ")[0:3]
00058 
00059     #coord = me.direction(ep,ra,dec)
00060     for i in range(len(tm)):
00061         t = tm[i]
00062         tq = qa.quantity(t,'d')
00063         tim = me.epoch('utc',tq)
00064         me.doframe(tim)
00065         last = me.measure(tim,'last')
00066         if dec=='':
00067           coord=me.direction(ra)
00068         else:
00069           coord=me.direction(ep,ra,dec)
00070 
00071         azel = me.measure(coord, 'azel')
00072         az = me.getvalue(azel)['m0']['value']
00073         el = me.getvalue(azel)['m1']['value']
00074         if i ==0:
00075           riseset=me.riseset(coord)
00076           if tref=='LST':
00077             timref='last'
00078           else:
00079             timref='utc' 
00080           tmeridian=(riseset['rise'][timref]['m0']['value']+riseset['set'][timref]['m0']['value'])/2.
00081           print "%s :Meridian passage: %s" % (srcname, qa.time(str(tmeridian)+'d')+' ('+timref+')') 
00082           #print "Rise:",riseset['rise'] 
00083           #print "Set:",riseset['set'] 
00084         azar[i]=az
00085         elar[i]=el
00086         lastar[i]=last['m0']['value']
00087     tm = tm + tshft
00088     if tref=='LST':
00089         rettm = lastar
00090         retutc = tm
00091     else:
00092         rettm = tm
00093 
00094     return azar, elar, rettm, retutc