casa
$Rev:20696$
|
00001 import os 00002 import numpy as np 00003 from taskinit import * 00004 00005 def polcal(vis=None,caltable=None, 00006 field=None,spw=None,intent=None, 00007 selectdata=None,timerange=None,uvrange=None,antenna=None,scan=None, 00008 observation=None, msselect=None, 00009 solint=None,combine=None,preavg=None,refant=None,minblperant=None,minsnr=None, 00010 poltype=None,smodel=None,append=None, 00011 gaintable=None,gainfield=None,interp=None,spwmap=None, 00012 gaincurve=None,opacity=None): 00013 00014 #Python script 00015 casalog.origin('polcal') 00016 00017 try: 00018 if ((type(vis)==str) & (os.path.exists(vis))): 00019 cb.open(filename=vis,compress=False,addcorr=False,addmodel=False) 00020 else: 00021 raise Exception, 'Visibility data set not found - please verify the name' 00022 00023 # Do data selection according to selectdata 00024 if (selectdata): 00025 # pass all data selection parameters in as specified 00026 cb.selectvis(time=timerange,spw=spw,scan=scan,field=field, 00027 intent=intent, observation=str(observation), 00028 baseline=antenna,uvrange=uvrange,chanmode='none', 00029 msselect=msselect); 00030 else: 00031 # selectdata=F, so time,scan,baseline,uvrange,msselect='' 00032 # using spw and field specifications only 00033 cb.selectvis(time='',spw=spw,scan='',field=field,intent=intent, 00034 baseline='',uvrange='',chanmode='none', 00035 observation='', msselect='') 00036 00037 # set the model, if specified 00038 if (len(smodel)>0): 00039 cb.setptmodel(smodel); 00040 00041 # Arrange apply of existing other calibrations 00042 # First do the existing cal tables... 00043 ngaintab = 0; 00044 if (gaintable!=['']): 00045 ngaintab=len(gaintable) 00046 ngainfld = len(gainfield) 00047 nspwmap = len(spwmap) 00048 ninterp = len(interp) 00049 00050 # handle list of list issues with spwmap 00051 if (nspwmap>0): 00052 if (type(spwmap[0])!=list): 00053 # first element not a list, only one spwmap specified 00054 # make it a list of list 00055 spwmap=[spwmap]; 00056 nspwmap=1; 00057 00058 for igt in range(ngaintab): 00059 if (gaintable[igt]!=''): 00060 00061 # field selection is null unless specified 00062 thisgainfield='' 00063 if (igt<ngainfld): 00064 thisgainfield=gainfield[igt] 00065 00066 # spwmap is null unless specifed 00067 thisspwmap=[-1] 00068 if (igt<nspwmap): 00069 thisspwmap=spwmap[igt]; 00070 00071 # interp is 'linear' unless specified 00072 thisinterp='linear' 00073 if (igt<ninterp): 00074 if (interp[igt]==''): 00075 interp[igt]=thisinterp 00076 thisinterp=interp[igt]; 00077 00078 cb.setapply(t=0.0,table=gaintable[igt],field=thisgainfield, 00079 calwt=True,spwmap=thisspwmap,interp=thisinterp) 00080 00081 # ...and now the specialized terms 00082 # (BTW, interp irrelevant for these, since they are evaluated) 00083 00084 # opacity (if non-trivially specified and any >0.0) 00085 opacarr=np.array(opacity) # as numpy array for uniformity 00086 if (np.sum(opacarr)>0.0): 00087 # opacity transmitted as a list in all cases 00088 cb.setapply(type='TOPAC',t=-1,opacity=opacarr.tolist(),calwt=True) 00089 00090 if gaincurve: cb.setapply(type='GAINCURVE',t=-1,calwt=True) 00091 00092 00093 # D-terms require parallactic angle 00094 cb.setapply(type='P') 00095 00096 # Set up for solving: 00097 phaseonly=False 00098 cb.setsolve(type=poltype,t=solint,combine=combine,preavg=preavg,refant=refant, 00099 minblperant=minblperant,solnorm=False,minsnr=minsnr,table=caltable, 00100 apmode='ap',phaseonly=phaseonly,append=append) 00101 00102 cb.solve() 00103 cb.close() 00104 00105 except Exception, instance: 00106 print '*** Error ***',instance 00107 cb.close() 00108 raise Exception, instance 00109