Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_fringefit.py: 10%
73 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 17:39 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 17:39 +0000
1import os
2import numpy as np
4from .callibrary import *
5from casatools import calibrater
6from casatasks import casalog
8def fringefit(vis=None,caltable=None,
9 field=None,spw=None,intent=None,
10 selectdata=None,timerange=None,uvrange=None,
11 antenna=None,scan=None,
12 observation=None, msselect=None,
13 solint=None,combine=None,refant=None,
14 minsnr=None,zerorates=None,globalsolve=None,niter=None,
15 delaywindow=None,ratewindow=None,append=None,
16 corrdepflags=None,
17 corrcomb=None,
18 docallib=None,callib=None,gaintable=None,gainfield=None,interp=None,spwmap=None,
19 paramactive=None,
20 concatspws=None,
21 parang=None):
23 #Python script
24 casalog.origin('fringefit')
26 #
28 try:
29 mycb = calibrater()
31 if ((type(vis)==str) & (os.path.exists(vis))):
32 mycb.open(filename=vis,compress=False,addcorr=False,addmodel=False)
33 else:
34 raise ValueError('Visibility data set not found - please verify the name')
36 # Do data selection according to selectdata
37 if (selectdata):
38 casalog.post("Selecting data")
39 # pass all data selection parameters in as specified
40 mycb.selectvis(time=timerange,spw=spw, scan=scan, field=field,
41 intent=intent, observation=str(observation),
42 baseline=antenna,uvrange=uvrange,chanmode='none',
43 msselect=msselect)
44 else:
45 # selectdata=F, so time,scan,baseline,msselect=''
46 # using spw and field specifications only
47 mycb.selectvis(time='',spw=spw,scan='',field=field,intent=intent,
48 observation='', baseline='',
49 chanmode='none', msselect='')
51 # signal use of correlation-dependent flags, if requested
52 if corrdepflags:
53 mycb.setcorrdepflags(True)
54 # Arrange applies....
56 if docallib:
57 # by cal library from file
58 mycallib=callibrary()
59 mycallib.read(callib)
60 mycb.setcallib(mycallib.cld)
62 else:
63 # by traditional parameters
65 ngaintab = 0;
66 if (gaintable!=['']):
67 ngaintab=len(gaintable)
69 ngainfld = len(gainfield)
70 nspwmap = len(spwmap)
71 ninterp = len(interp)
73 # handle list of list issues with spwmap
74 if (nspwmap>0):
75 if (type(spwmap[0])!=list):
76 # first element not a list, only one spwmap specified
77 # make it a list of list
78 spwmap=[spwmap];
79 nspwmap=1;
81 for igt in range(ngaintab):
82 if (gaintable[igt]!=''):
84 # field selection is null unless specified
85 thisgainfield=''
86 if (igt<ngainfld):
87 thisgainfield=gainfield[igt]
89 # spwmap is null unless specifed
90 thisspwmap=[-1]
91 if (igt<nspwmap):
92 thisspwmap=spwmap[igt];
94 # interp is 'linear' unless specified
95 thisinterp='linear'
96 if (igt<ninterp):
97 if (interp[igt]==''):
98 interp[igt]=thisinterp;
99 thisinterp=interp[igt];
101 mycb.setapply(t=0.0,table=gaintable[igt],field=thisgainfield,
102 calwt=True,spwmap=thisspwmap,interp=thisinterp)
104 # ...and now the specialized terms
105 if paramactive is None or paramactive==[]:
106 paramactive=[True, True, False]
107 else:
108 if len(paramactive)!=3:
109 casalog.post("paramactive: " + paramactive)
110 raise ValueError( 'Error: paramactive vector must have exactly three entries' )
111 # Have to solve for peculiar phase!
112 paramactive.insert(0, True)
114 if len(delaywindow) != 2:
115 delaywindow = [-1e6, 1e6]
116 if len(ratewindow) != 2:
117 ratewindow = [-1e6, 1e6]
119 # Apply parallactic angle, if requested
120 if parang: mycb.setapply(type='P')
121 # Set up for solving; only support one gaintype
122 mycb.setsolve(type="FRINGE",t=solint,refant=refant,preavg=0.001,
123 minsnr=minsnr,combine=combine,
124 zerorates=zerorates,
125 globalsolve=globalsolve,
126 niter=niter,
127 corrcomb=corrcomb,
128 delaywindow=delaywindow,
129 ratewindow=ratewindow,
130 paramactive=paramactive,
131 concatspws=concatspws,
132 table=caltable,append=append)
133 mycb.solve()
135 reportsolvestats(mycb.activityrec());
137 finally:
138 mycb.close()
140def reportsolvestats(rec):
141 if (list(rec.keys()).count('origin')==1 and
142 rec['origin']=='Calibrater::genericGatherAndSolve'):
143 casalog.post("Calibration solve statistics per spw: (expected/attempted/succeeded):")
144 nexp=rec['nExpected']
145 natt=rec['nAttempt']
146 nsuc=rec['nSucceed']
147 for ispw in range(len(nexp)):
148 solstatstr=" Spw "+str(ispw)+": "
149 solstatstr+=str(nexp[ispw])+"/"
150 solstatstr+=str(natt[ispw])+"/"
151 solstatstr+=str(nsuc[ispw])
152 casalog.post(solstatstr)