casalog.post('Fld='+fldnames[ifld]+' Spw='+str(ispw)+' Ant='+str(iant)+' (PA offset='+str(rang[iant,ispw]*180/pi+paoffset)+'deg)'+' q='+str(q[iant])+' u='+str(u[iant])+' p='+str(p)+' x='+str(x)+' Gx/Gy='+str(sqrt(r[iant])))
from math import pi,floor,atan2,sin,cos,sqrt
from casatasks import casalog
myme=casatools.measures()
mymd=casatools.msmetadata()
def polfromgain(vis,tablein,caltable,paoffset):
casalog.origin('polfromgain')
casalog.post("Deriving calibrator linear polarization from gain ratios.")
if ((type(vis)==str) & (os.path.exists(vis))):
raise ValueError('Visibility data set not found - please verify the name')
fldnames=mymd.fieldnames()
if ((type(tablein)==str) & (os.path.exists(tablein))):
if type(caltable)==str and len(caltable)>0:
if os.path.exists(caltable):
raise ValueError('Output caltable='+caltable+' exists. Choose another name or delete it.')
casalog.post("New caltable, "+caltable+", corrected for linear polarization, will be generated.")
myout=mytb.copy(newtablename=caltable,deep=True)
casalog.post("No new caltable will be generated")
raise ValueError('input calibration table not found - please verify the name')
casalog.post("NB: default band position angle will be offset by "+str(paoffset)+"deg.")
mytb.open(caltable+'/FIELD')
dirs=mytb.getcol('DELAY_DIR')[:,0,:]