Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_polcal.py: 76%

59 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-01 07:19 +0000

1import os 

2import numpy as np 

3 

4from casatools import calibrater 

5from casatasks import casalog 

6from .callibrary import * 

7 

8def polcal(vis=None,caltable=None, 

9 field=None,spw=None,intent=None, 

10 selectdata=None,timerange=None,uvrange=None,antenna=None,scan=None, 

11 observation=None, msselect=None, 

12 solint=None,combine=None,preavg=None,refant=None,minblperant=None,minsnr=None, 

13 poltype=None,smodel=None,append=None, 

14 docallib=None,callib=None, 

15 gaintable=None,gainfield=None,interp=None,spwmap=None): 

16 

17 #Python script 

18 casalog.origin('polcal') 

19 

20 try: 

21 

22 mycb=calibrater() 

23 

24 if ((type(vis)==str) & (os.path.exists(vis))): 

25 mycb.open(filename=vis,compress=False,addcorr=False,addmodel=False) 

26 else: 

27 raise ValueError('Visibility data set not found - please verify the name') 

28 

29 # Do data selection according to selectdata 

30 casalog.post("NB: polcal automatically excludes auto-correlations.") 

31 if (selectdata): 

32 # insist no ACs 

33 if len(msselect)>0: 

34 msselect='('+msselect+') && ANTENNA1!=ANTENNA2' 

35 else: 

36 msselect='ANTENNA1!=ANTENNA2' 

37 # pass all data selection parameters in as specified 

38 mycb.selectvis(time=timerange,spw=spw,scan=scan,field=field, 

39 intent=intent, observation=str(observation), 

40 baseline=antenna,uvrange=uvrange,chanmode='none', 

41 msselect=msselect); 

42 else: 

43 # selectdata=F, so time,scan,baseline,uvrange,msselect='' 

44 # using spw and field specifications only 

45 # also insist no ACs 

46 mycb.selectvis(time='',spw=spw,scan='',field=field,intent=intent, 

47 baseline='',uvrange='',chanmode='none', 

48 observation='', msselect='ANTENNA1!=ANTENNA2') 

49 

50 # set the model, if specified 

51 if (len(smodel)>0): 

52 mycb.setptmodel(smodel); 

53 

54 # Arrange applies.... 

55 

56 if docallib: 

57 # by cal library from file 

58 mycallib=callibrary() 

59 mycallib.read(callib) 

60 mycb.setcallib(mycallib.cld) 

61 

62 else: 

63 

64 # by traditional parameters 

65 

66 ngaintab = 0; 

67 if (gaintable!=['']): 

68 ngaintab=len(gaintable) 

69 

70 ngainfld = len(gainfield) 

71 nspwmap = len(spwmap) 

72 ninterp = len(interp) 

73 

74 # handle list of list issues with spwmap 

75 if (nspwmap>0): 

76 if (type(spwmap[0])!=list): 

77 # first element not a list, only one spwmap specified 

78 # make it a list of list 

79 spwmap=[spwmap]; 

80 nspwmap=1; 

81 

82 for igt in range(ngaintab): 

83 if (gaintable[igt]!=''): 

84 

85 # field selection is null unless specified 

86 thisgainfield='' 

87 if (igt<ngainfld): 

88 thisgainfield=gainfield[igt] 

89 

90 # spwmap is null unless specifed 

91 thisspwmap=[-1] 

92 if (igt<nspwmap): 

93 thisspwmap=spwmap[igt]; 

94 

95 # interp is 'linear' unless specified 

96 thisinterp='linear' 

97 if (igt<ninterp): 

98 if (interp[igt]==''): 

99 interp[igt]=thisinterp; 

100 thisinterp=interp[igt]; 

101 

102 mycb.setapply(t=0.0,table=gaintable[igt],field=thisgainfield, 

103 calwt=True,spwmap=thisspwmap,interp=thisinterp) 

104 

105 

106 

107 # ...and now the specialized terms 

108 # (BTW, interp irrelevant for these, since they are evaluated) 

109 

110 # D-terms require parallactic angle 

111 mycb.setapply(type='P') 

112 

113 # Set up for solving:  

114 phaseonly=False 

115 mycb.setsolve(type=poltype,t=solint,combine=combine,preavg=preavg,refant=refant, 

116 minblperant=minblperant,solnorm=False,minsnr=minsnr,table=caltable, 

117 apmode='ap',phaseonly=phaseonly,append=append) 

118 

119 mycb.solve() 

120 

121 # retrieve activity record; may contain Stoke solution info 

122 actrec=mycb.activityrec() 

123 

124 mycb.close() 

125 

126 if poltype=='Xfparang+QU' and 'fStokes' in actrec: 

127 casalog.post("NB: Returning dictionary containing fractional Stokes results.") 

128 return actrec['fStokes'] 

129 

130 

131 finally: 

132 mycb.close( )