Coverage for /home/casatest/venv/lib/python3.12/site-packages/casatasks/hanningsmooth.py: 56%

27 statements  

« prev     ^ index     » next       coverage.py v7.10.4, created at 2025-08-21 07:43 +0000

1##################### generated by xml-casa (v2) from hanningsmooth.xml ############# 

2##################### 21c0dc45435e399f354286d079818494 ############################## 

3from __future__ import absolute_import 

4import numpy 

5from casatools.typecheck import CasaValidator as _val_ctor 

6_pc = _val_ctor( ) 

7from casatools.coercetype import coerce as _coerce 

8from casatools.errors import create_error_string 

9from .private.task_hanningsmooth import hanningsmooth as _hanningsmooth_t 

10from casatasks.private.task_logging import start_log as _start_log 

11from casatasks.private.task_logging import end_log as _end_log 

12from casatasks.private.task_logging import except_log as _except_log 

13 

14class _hanningsmooth: 

15 """ 

16 hanningsmooth ---- Hanning smooth frequency channel data to remove Gibbs ringing 

17 

18  

19 The hanningsmooth task uses the MSTransform framework underneath but 

20 keeps roughly the same interface as the old hanningsmooth task. 

21  

22 This function Hanning smooths the frequency channels with a weighted 

23 running average. The weights are 0.5 for the central channel and 0.25 

24 for each of the two adjacent channels. The first and last channels are 

25 flagged. Inclusion of a flagged value in an average causes that data 

26 value to be flagged. 

27  

28 If the 'CORRECTED' data column is requested for an MS that does not 

29 contain this column, it will use 'DATA' to calculate the smoothing and 

30 save it to 'DATA' in the output MS. 

31  

32 WARNING: by default, all visibility columns will be smoothed. 

33  

34 Note that hanningsmooth task does not reindex the MS, i.e., the IDs of the 

35 SPWs and DDIDs are kept in the output. 

36 

37 --------- parameter descriptions --------------------------------------------- 

38 

39 vis Name of input visibility file 

40 Default: none 

41  

42 Example: vis='ngc5921.ms' 

43 outputvis Name of output visibility file 

44 Default: '' (same as vis) 

45  

46 Example: outputvis='ngc5921_out.ms' 

47 keepmms Create a Multi-MS as the output if the input is a 

48 Multi-MS. 

49  

50 Default: True 

51 Options: True|False 

52  

53 By default it will create a Multi-MS when the 

54 input is a Multi-MS. The output Multi-MS will 

55 have the same partition axis of the input 

56 MMS. See CASA Docs for more information on 

57 the MMS format. 

58 field Select field using field id(s) or field name(s) 

59 Default: '' (all fields) 

60  

61 Use 'go listobs' to obtain the list id's or 

62 names. If field string is a non-negative integer, 

63 it is assumed a field index, otherwise, it is 

64 assumed a field name. 

65  

66 Examples: 

67 field='0~2'; field ids 0,1,2 

68 field='0,4,5~7'; field ids 0,4,5,6,7 

69 field='3C286,3C295'; field named 3C286 and 

70 3C295 

71 field = '3,4C\*'; field id 3, all names 

72 starting with 4C 

73 spw Select spectral window/channels 

74 Default: ''=all spectral windows and channels 

75  

76 Examples: 

77 spw='0~2,4'; spectral windows 0,1,2,4 (all channels) 

78 spw='<2'; spectral windows less than 2 (i.e. 0,1) 

79 spw='0:5~61'; spw 0, channels 5 to 61 

80 spw='0,10,3:3~45'; spw 0,10 all channels, spw 

81 3 - chans 3 to 45. 

82 spw='0~2:2~6'; spw 0,1,2 with channels 2 

83 through 6 in each. 

84 spw = '\*:3~64' channels 3 through 64 for all sp id's 

85 spw = ' :3~64' will NOT work. 

86  

87 NOTE: mstransform does not support multiple 

88 channel ranges per spectral window (';'). 

89 scan Scan number range 

90 Subparameter of selectdata=True 

91 Default: '' = all 

92 antenna Select data based on antenna/baseline 

93 Subparameter of selectdata=True 

94 Default: '' (all) 

95  

96 If antenna string is a non-negative integer, it 

97 is assumed an antenna index, otherwise, it is 

98 assumed as an antenna name 

99  

100 Examples:  

101 antenna='5&6'; baseline between antenna 

102 index 5 and index 6. 

103 antenna='VA05&VA06'; baseline between VLA 

104 antenna 5 and 6. 

105 antenna='5&6;7&8'; baselines with 

106 indices 5-6 and 7-8 

107 antenna='5'; all baselines with antenna index 

108 5 

109 antenna='05'; all baselines with antenna 

110 number 05 (VLA old name) 

111 antenna='5,6,10'; all baselines with antennas 

112 5,6,10 index numbers 

113 antenna='!ea03,ea12,ea17': all baselines 

114 except those that include EVLA antennas 

115 ea03, ea12, or ea17. 

116 correlation Select data based on correlation 

117 Default: '' ==> all 

118  

119 Example: correlation="XX,YY". 

120 timerange Select data based on time range 

121 Subparameter of selectdata=True 

122 Default = '' (all) 

123  

124 Examples: 

125 timerange = 

126 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss' 

127 (Note: if YYYY/MM/DD is missing date defaults 

128 to first day in data set.) 

129 timerange='09:14:0~09:54:0' picks 40 min on 

130 first day  

131 timerange= '25:00:00~27:30:00' picks 1 hr to 3 

132 hr 30min on NEXT day 

133 timerange='09:44:00' pick data within one 

134 integration of time 

135 timerange='>10:24:00' data after this time 

136 intent Select observing intent 

137 Default: '' (no selection by intent) 

138  

139 Example: intent='*BANDPASS*' (selects data 

140 labelled with BANDPASS intent) 

141 array (Sub)array number range 

142 Default: '' (all) 

143 uvrange Select data by baseline length. 

144 Default = '' (all) 

145  

146 Examples: 

147 uvrange='0~1000klambda'; uvrange from 0-1000 kilo-lambda 

148 uvrange='>4klambda';uvranges greater than 4 kilo-lambda 

149 uvrange='0~1000km'; uvrange in kilometers 

150 observation Select by observation ID(s) 

151 Subparameter of selectdata=True 

152 Default: '' = all 

153  

154 Example: observation='0~2,4' 

155 feed Selection based on the feed  

156 NOT IMPLEMENTED YET! 

157 Default: '' = all 

158 smooth_spw If this parameter is given, only those SPWs mentioned will 

159 have the hanning smooth transformation applied. 

160 Note that the spw parameter is used to select SPWs, i.e., 

161 the task will receive as input SPWs filtered by the spw parameter. 

162 In contrast, the SPWs not mentioned in smooth_spw will still be 

163 handled by the task but not transformed and they will still be 

164 part of the task output. 

165 If an empty string is passed, then all SPWs will be smoothed. 

166 The parameter admits both a python list of integers or a string 

167 with comma-separated IDs and/or a range of IDs denoted by '~'. 

168 If a SPW mentioned in smooth_spw parameter is not in the MS then 

169 it is ignored and no error is reported. 

170  

171 Default: None = all 

172  

173 Examples: 

174 smooth_spw=[1,2,3] ; python list of integers 

175 smooth_spw='1,2,3' ; string with comma-separated SPWs 

176 smooth_spw='1~10' ; string with SPW range (1 to 10, included) 

177 smooth_spw='1~10,2,3' ; string with mixed SPW range and individual SPW 

178 smooth_spw='' ; empty string: process all SPWs (like the default None) 

179 datacolumn Which data column(s) to use for processing 

180 (case-insensitive). 

181 Default: 'all' (= whichever of the options that 

182 are present) 

183 Options: 'data', 'model', 'corrected', 

184 'all','float_data', 'lag_data', 

185 'float_data,data', 'lag_data,data' 

186  

187 Example: datacolumn='data' 

188 

189 --------- examples ----------------------------------------------------------- 

190 

191  

192 FOR MORE INFORMATION, SEE THE TASK PAGES OF HANNINGSMOOTH IN CASA DOCS: 

193 https://casa.nrao.edu/casadocs/ 

194  

195 

196 

197 """ 

198 

199 _info_group_ = """manipulation""" 

200 _info_desc_ = """Hanning smooth frequency channel data to remove Gibbs ringing""" 

201 

202 def __call__( self, vis='', outputvis='', keepmms=True, field='', spw='', scan='', antenna='', correlation='', timerange='', intent='', array='', uvrange='', observation='', feed='', smooth_spw='', datacolumn='all' ): 

203 schema = {'vis': {'type': 'cReqPath', 'coerce': _coerce.expand_path}, 'outputvis': {'type': 'cStr', 'coerce': _coerce.to_str}, 'keepmms': {'type': 'cBool'}, 'field': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'spw': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'scan': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'antenna': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'correlation': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}]}, 'timerange': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'intent': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'array': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'uvrange': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'observation': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'feed': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'smooth_spw': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cInt'}, {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}]}, 'datacolumn': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'DATA', 'model', 'corrected', 'LAG_DATA', 'lag_data', 'FLOAT_DATA,DATA', 'FLOAT_DATA', 'CORRECTED', 'lag_data,data', 'float_data', 'float_data,data', 'DATA,MODEL,CORRECTED', 'ALL', 'MODEL', 'all', 'data,model,corrected', 'LAG_DATA,DATA', 'data' ]}} 

204 doc = {'vis': vis, 'outputvis': outputvis, 'keepmms': keepmms, 'field': field, 'spw': spw, 'scan': scan, 'antenna': antenna, 'correlation': correlation, 'timerange': timerange, 'intent': intent, 'array': array, 'uvrange': uvrange, 'observation': observation, 'feed': feed, 'smooth_spw': smooth_spw, 'datacolumn': datacolumn} 

205 assert _pc.validate(doc,schema), create_error_string(_pc.errors) 

206 _logging_state_ = _start_log( 'hanningsmooth', [ 'vis=' + repr(_pc.document['vis']), 'outputvis=' + repr(_pc.document['outputvis']), 'keepmms=' + repr(_pc.document['keepmms']), 'field=' + repr(_pc.document['field']), 'spw=' + repr(_pc.document['spw']), 'scan=' + repr(_pc.document['scan']), 'antenna=' + repr(_pc.document['antenna']), 'correlation=' + repr(_pc.document['correlation']), 'timerange=' + repr(_pc.document['timerange']), 'intent=' + repr(_pc.document['intent']), 'array=' + repr(_pc.document['array']), 'uvrange=' + repr(_pc.document['uvrange']), 'observation=' + repr(_pc.document['observation']), 'feed=' + repr(_pc.document['feed']), 'smooth_spw=' + repr(_pc.document['smooth_spw']), 'datacolumn=' + repr(_pc.document['datacolumn']) ] ) 

207 task_result = None 

208 try: 

209 task_result = _hanningsmooth_t( _pc.document['vis'], _pc.document['outputvis'], _pc.document['keepmms'], _pc.document['field'], _pc.document['spw'], _pc.document['scan'], _pc.document['antenna'], _pc.document['correlation'], _pc.document['timerange'], _pc.document['intent'], _pc.document['array'], _pc.document['uvrange'], _pc.document['observation'], _pc.document['feed'], _pc.document['smooth_spw'], _pc.document['datacolumn'] ) 

210 except Exception as exc: 

211 _except_log('hanningsmooth', exc) 

212 raise 

213 finally: 

214 task_result = _end_log( _logging_state_, 'hanningsmooth', task_result ) 

215 return task_result 

216 

217hanningsmooth = _hanningsmooth( ) 

218