Browse Source

Minor fixes

master
Benito Marcote 4 years ago
parent
commit
007d9de78b
  1. 20
      flag_weights.py

20
flag_weights.py

@ -8,11 +8,12 @@ Options:
threshold : float Visibilities with a weight below the specified
value will be flagged. Must be positive.
Version: 1.1
Version: 1.2
Date: Nov 2017
Written by Benito Marcote (marcote@jive.eu)
version 1.2 changes
- Minor fixes.
version 1.1 changes
- Added option -v that allows you to just get how many visibilities will
be flagged (but without actually flagging the data).
@ -36,27 +37,28 @@ try:
parser = argparse.ArgumentParser(description=description, prog='flag_weights.py', usage=usage)
parser.add_argument('msdata', type=str, help=help_msdata)
parser.add_argument('threshold', type=float, help=help_threshold)
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
parser.add_argument('--version', action='version', version='%(prog)s 1.2')
parser.add_argument("-v", "--verbose", default=True, action="store_false" , help=help_v)
arguments = parser.parse_args()
print('The arguments ', arguments)
#print('The arguments ', arguments)
verbose = arguments.verbose
msdata = arguments.msdata[:-1] if arguments.msdata[-1]=='/' else arguments.msdata
threshold = arguments.threshold
except ImportError:
usage = "%prog [-h] <measurement set> <weight threshold>"
usage = "%prog [-h] [-v] <measurement set> <weight threshold>"
description="""Flag visibilities with weights below the provided threshold.
"""
# Compatibility with Python 2.7 in eee
import optparse
parser = optparse.OptionParser(usage=usage, description=description, prog='ysfocus.py', version='%prog 1.0')
parser = optparse.OptionParser(usage=usage, description=description, prog='ysfocus.py', version='%prog 1.2')
parser.add_option("-v", action="store_false", dest="verbose", default=True, help=help_v)
theparser = parser.parse_args()
verbose = theparser[0].verbose
arguments = theparser[1]
#arguments = parser.parse_args()[1]
if len(arguments) != 2:
print('Two arguments must be provided: flag_weights.py <measurement set> <weight threshold>')
print('Two arguments must be provided: flag_weights.py [-h] [-v] <measurement set> <weight threshold>')
print('Use -h to get help.')
sys.exit(1)
msdata = arguments[0][:-1] if arguments[0][-1]=='/' else arguments[0]
@ -70,9 +72,13 @@ with pt.table(msdata, readonly=False) as ms:
print('Got {0:9} weights'.format(weights.size))
indexes = np.where(weights < threshold)
print('Got {0:9} bad points'.format(indexes[0].size))
print('{0:04.3}% of the visibilities to flag\n'.format(100.0*indexes[0].size/weights.size))
if verbose:
weights[indexes] = -np.abs(weights[indexes])
ms.putcol("WEIGHT", weights)
print('Done.')
else:
print('Flag has not been applied')
ms.close()

Loading…
Cancel
Save