Browse Source

Updated python to use (through env)

master
Jops 3 years ago
parent
commit
13127e1f20
  1. 74
      flag_weights-taql.py
  2. 1
      vex

74
flag_weights-taql.py

@ -1,74 +0,0 @@
#! /usr/bin/python
"""
Flag visibilities with weights below the provided threshold.
Usage: flag_weights.py msdata threshold
Options:
msdata : str MS data set containing the data to be flagged.
threshold : float Visibilities with a weight below the specified
value will be flagged. Must be positive.
Version: 1.0
Date: Oct 2017
Written by Benito Marcote (marcote@jive.eu)
"""
from pyrap import tables as pt
import numpy as np
import sys
help_msdata = 'Measurement set containing the data to be corrected.'
help_threshold = 'Visibilities with a weight below this value will be flagged. Must be positive.'
try:
usage = "%(prog)s [-h] <measurement set> <weight threshold>"
description="""Flag visibilities with weights below the provided threshold.
"""
import argparse
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')
arguments = parser.parse_args()
msdata = arguments.msdata[:-1] if arguments.msdata[-1]=='/' else arguments.msdata
threshold = arguments.threshold
except ImportError:
usage = "%prog [-h] <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.add_option('measurement_set', type='string', dest='msdata', help=help_doc)
arguments = parser.parse_args()[1]
if len(arguments) != 2:
print('Two arguments must be provided: flag_weights.py <measurement set> <weight threshold>')
sys.exit(1)
msdata = arguments[0][:-1] if arguments[0][-1]=='/' else arguments[0]
threshold = float(arguments[1])
assert threshold > 0.0
with pt.table(msdata) as ms:
# Alternative with the use of TaQL:
# For now I get the number of weights from the traditional way...
weights = ms.getcol("WEIGHT")
print('Got {0:9} weights'.format(weights.size))
indexes = np.where(weights < threshold)
print('Got {0:9} bad points'.format(indexes[0].size))
# For now this is the only way I know to do it
dimensions = weights.shape[1]
ms.close()
# weights[indexes] = -np.abs(weights[indexes])
# ms.putcol("WEIGHT", weights)
for a_dimension in range(dimensions):
taql_command = 'update {0} set WEIGHT[{2}]=-ABS(WEIGHT[{2}]) where WEIGHT[{2}] < {1}'.format(msdata,
threshold, a_dimension)
# print(taql_command)
pt.taql(taql_command)

1
vex

@ -1 +0,0 @@
Subproject commit 7883526f4ea00f181434d0215bd0c5124eff0604
Loading…
Cancel
Save