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

63 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-31 19:53 +0000

1import os 

2import numpy as np 

3 

4from .callibrary import * 

5from casatasks import casalog 

6from casatools import calibrater 

7 

8def bandpass(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,refant=None,minblperant=None, 

13 minsnr=None,solnorm=None, 

14 bandtype=None,smodel=None,corrdepflags=None, 

15 append=None,fillgaps=None, 

16 degamp=None,degphase=None,visnorm=None, 

17 maskcenter=None,maskedge=None, 

18 docallib=None,callib=None, 

19 gaintable=None,gainfield=None,interp=None,spwmap=None, 

20 parang=None): 

21 

22 #Python script 

23 casalog.origin('bandpass') 

24 

25 try: 

26 mycb=calibrater() 

27 

28 # Revert to old VI for BPOLY 

29 if (bandtype=='BPOLY'): 

30 mycb.setvi(old=True,quiet=False); 

31 

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

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

34 else: 

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

36 mycb.reset() 

37 

38 # Do data selection according to selectdata 

39 casalog.post("NB: bandpass automatically excludes auto-correlations.") 

40 if (selectdata): 

41 # insist no ACs 

42 if len(msselect)>0: 

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

44 else: 

45 msselect='ANTENNA1!=ANTENNA2' 

46 # pass all data selection parameters in as specified 

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

48 intent=intent, observation=str(observation), 

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

50 msselect=msselect); 

51 else: 

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

53 # using spw and field specifications only 

54 # also insist no ACs 

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

56 observation='', baseline='',uvrange='',chanmode='none', 

57 msselect='ANTENNA1!=ANTENNA2'); 

58 

59 # signal use of correlation-dependent flags, if requested 

60 if corrdepflags: 

61 mycb.setcorrdepflags(True) 

62 

63 # set the model, if specified 

64 if (len(smodel)>0): 

65 mycb.setptmodel(smodel); 

66 

67 

68 # Arrange applies.... 

69 if docallib: 

70 # by cal library from file 

71 mycallib=callibrary() 

72 mycallib.read(callib) 

73 mycb.setcallib(mycallib.cld) 

74 

75 else: 

76 

77 # by traditional parameters 

78 

79 ngaintab = 0; 

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

81 ngaintab=len(gaintable) 

82 

83 ngainfld = len(gainfield) 

84 nspwmap = len(spwmap) 

85 ninterp = len(interp) 

86 

87 # handle list of list issues with spwmap 

88 if (nspwmap>0): 

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

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

91 # make it a list of list 

92 spwmap=[spwmap]; 

93 nspwmap=1; 

94 

95 for igt in range(ngaintab): 

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

97 

98 # field selection is null unless specified 

99 thisgainfield='' 

100 if (igt<ngainfld): 

101 thisgainfield=gainfield[igt] 

102 

103 # spwmap is null unless specifed 

104 thisspwmap=[-1] 

105 if (igt<nspwmap): 

106 thisspwmap=spwmap[igt]; 

107 

108 # interp is 'linear' unless specified 

109 thisinterp='linear' 

110 if (igt<ninterp): 

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

112 interp[igt]=thisinterp; 

113 thisinterp=interp[igt]; 

114 

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

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

117 

118 # ...and now the specialized terms 

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

120 

121 # Apply parallactic angle, if requested 

122 if parang: mycb.setapply(type='P') 

123 

124 # set up for solving ( 

125 if (bandtype=='B'): 

126 mycb.setsolve(type='B',t=solint,combine=combine,refant=refant,minblperant=minblperant, 

127 solnorm=solnorm,minsnr=minsnr,table=caltable,append=append,fillgaps=fillgaps) 

128 elif (bandtype=='BPOLY'): 

129 mycb.setsolvebandpoly(refant=refant,table=caltable,append=append, 

130 t=solint,combine=combine, 

131 degamp=degamp,degphase=degphase,visnorm=visnorm, 

132 solnorm=solnorm,maskcenter=maskcenter,maskedge=maskedge) 

133 

134 mycb.solve() 

135 

136 finally: 

137 results_dict = mycb.returndict() 

138 mycb.close() 

139 return results_dict