Coverage for / home / casatest / venv / lib / python3.12 / site-packages / casatasks / msuvbinflag.py: 89%
27 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-19 19:37 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-19 19:37 +0000
1##################### generated by xml-casa (v2) from msuvbinflag.xml ###############
2##################### 82abe82f71c0bf31357db45d077c1513 ##############################
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_msuvbinflag import msuvbinflag as _msuvbinflag_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
14class _msuvbinflag:
15 """
16 msuvbinflag ---- An algorithm to identify outliers in the UV plane via the UV grid generated by msuvbin.
17 Both msuvbin and msuvbinflag tasks are experimental
21 Msuvbinflag is an automatic flagging algorithm for the identification
22 of Radio Frequency Interference (RFI) in the UV plane. Prior to flagging,
23 the visibilities in the input CASA Measurements Set (MS) have to be
24 gridded onto a uniforme UV plane using the msuvbin task.
26 The principle underlying this algorithm is that RFI typically appears as
27 large scale ripples in the image domain, and therefore as compact structures
28 in the UV domain. Astronomical sources tend to have the opposite behavior, i.e.,
29 compact in the image domain and extended in the UV domain. Therefore by locating
30 compact outlier structures in the UV domain it should be possible to flag RFI.
34 --------- parameter descriptions ---------------------------------------------
36 binnedvis d visibility data (MS) (the output of the msuvbin task).
37 default: none;
38 example: binnedvis='SNR_binnedvis.ms'
39 method are currently two algorithm options to identify outliers in the UV domain: radial_per_plane, radial_mean_annular
41 radial_per_plane: This algorithm works independently
42 on each plane (channel, polarization) of the binned ms. A mean radial profile is
43 generated by doing a weighted average of all data at a given
44 UV-radius. A polynomial is fit to the radially averaged
45 profile. All the binned UV points that are larger than the
46 nsigma threshold are flagged. The threshold is calculated as :
48 originalValue[u,v] > radialfitValue[r]+nsigma*rms
50 where (u,v) are the UV coordinates, r is the radial distance from the
51 center, and rms is the rms of the radial profile at radius r.
54 radial_mean_annular: This algorithm combines all the planes in the
55 binned MS on to a single UV grid. This combined grid is then
56 divided into annular circles from 0 through the maximum UV radius
57 in log-spaced intervals. A radial profile is constructed by
58 calculating the median values within each annulus, as well as
59 the median absolute deviation scaled to the standard deviation.
60 Similar to the radial_per_plane method, each plane is then individually
61 treated, and a point in the UV plane is flagged if it is greater than
62 the nsigma threshold. The threshold is calculated as :
64 originalValue[u,v] > radiatValue[n] + nsigma*rms[n]
66 where (u,v) are the UV coordinates, and n is the nth annulus.
70 default: 'radial_per_plane'
71 example: method='radial_mean_annular'
72 nsigma User defined nsigma value for flagging.
73 The default value is 5.
74 doplot Generate plots of the radial profiles calculated prior to flagging. This can be useful to
75 debug the performance of the algorithm, however it can severely impact runtime performance.
76 In general you do not need to turn this option on.
78 The default value is False.
79 [1;42mRETURNS[1;m void
81 --------- examples -----------------------------------------------------------
86 msuvbinflag(binnedvis='SNR_G55_10s.ms', method='radial_per_plane', nsigma=5)
88 Keyword arguments:
89 binnedvis -- Name of input binned visibility file which is output from msuvbin.
90 After msuvbinflag, binnedvis is modified with flagging info.
92 method -- Three method options: "radian", "regional mean","median","gradient"
93 default: 'radian'
95 nsigma -- User set nsigma value for radial algorithm.
96 default=5.0
101 """
103 _info_group_ = """flagging, manipulation, imaging"""
104 _info_desc_ = """An algorithm to identify outliers in the UV plane via the UV grid generated by msuvbin.
105 Both msuvbin and msuvbinflag tasks are experimental
106 """
108 def __call__( self, binnedvis, method='radial_per_plane', nsigma=float(5.0), doplot=False ):
109 schema = {'binnedvis': {'type': 'cStr', 'coerce': _coerce.to_str}, 'method': {'type': 'cVariant', 'coerce': [_coerce.to_variant] # <allowed> IS NOT ALLOWED FOR A PARAMETER OF TYPE any
110}, 'nsigma': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'doplot': {'type': 'cBool'}}
111 doc = {'binnedvis': binnedvis, 'method': method, 'nsigma': nsigma, 'doplot': doplot}
112 assert _pc.validate(doc,schema), create_error_string(_pc.errors)
113 _logging_state_ = _start_log( 'msuvbinflag', [ 'binnedvis=' + repr(_pc.document['binnedvis']), 'method=' + repr(_pc.document['method']), 'nsigma=' + repr(_pc.document['nsigma']), 'doplot=' + repr(_pc.document['doplot']) ] )
114 task_result = None
115 try:
116 task_result = _msuvbinflag_t( _pc.document['binnedvis'], _pc.document['method'], _pc.document['nsigma'], _pc.document['doplot'] )
117 except Exception as exc:
118 _except_log('msuvbinflag', exc)
119 raise
120 finally:
121 task_result = _end_log( _logging_state_, 'msuvbinflag', task_result )
122 return task_result
124msuvbinflag = _msuvbinflag( )