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