Browse Source

Added expname.py and updated flag_weights.py

master
Benito Marcote 4 years ago
parent
commit
a9c9b36955
  1. 3
      antabfs_nominal.py
  2. 66
      expname.py
  3. 13
      flag_weights.py
  4. 2
      polswap.py

3
antabfs_nominal.py

@ -44,7 +44,8 @@ args = parser.parse_args()
i_already_warn_about_seconds = False
def read_sefd_table(tablename='sefd_values.txt'):#'/jop83_0/pipe/in/marcote/scripts/sefd_values.txt'):
# def read_sefd_table(tablename='sefd_values.txt'):#'/jop83_0/pipe/in/marcote/scripts/sefd_values.txt'):
def read_sefd_table(tablename='/jop83_0/pipe/in/marcote/scripts/sefd_values.txt'):
sefd_table = open(tablename, 'r')
titles = sefd_table.readline().strip().split('|')
titles = [t.strip() for t in titles]

66
expname.py

@ -0,0 +1,66 @@
#! /usr/bin/python
"""Change the name of an project in a measurement set (MS).
Usage: expname.py <msdata> <new_expname>
Options:
msdata : str MS data set to be changed.
new_expname : str New name for the project ( experiment) that is quoted in the MS.
It will replace the existing one and it will be converted into
capital letters.
Version: 1.0
Date: April 2017
Written by Benito Marcote (marcote@jive.eu)
"""
from pyrap import tables as pt
import sys
help_msdata = ''
help_newexpname = ''
try:
usage = "%(prog)s [-h] <msdata> <new_expname>"
description="""Change the name of a project in a measurement set (MS).
"""
import argparse
parser = argparse.ArgumentParser(description=description, prog='expname.py', usage=usage)
parser.add_argument('msdata', type=str, help=help_msdata)
parser.add_argument('new_expname', type=str, help=help_newexpname)
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
arguments = parser.parse_args()
#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)s [-h] <msdata> <new_expname>"
description="""Change the name of a project in a measurement set (MS) to new_expname (in upper case).
"""
# Compatibility with Python 2.7
import optparse
parser = optparse.OptionParser(usage=usage, description=description, prog='expname.py', version='%prog 1.0')
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: expname.py [-h] [-v] <msdata> <new_expname>')
print('Use -h to get help.')
sys.exit(1)
msdata = arguments[0][:-1] if arguments[0][-1]=='/' else arguments[0]
new_expname = arguments[1]
# The actual work
with pt.table(msdata+'/OBSERVATION', readonly=False) as ms:
old_project = ms.getcol('PROJECT')[0] # Should always be one-element list
ms.putcol('PROJECT', [new_expname.upper()])
# Sometimes it can happen that the OBSERVER is also the PROJECT, although not always
if ms.getcol('OBSERVER')[0] == old_project:
ms.putcol('OBSERVER', [new_expname()])
ms.close()
print('Experiment name changed to {}.'.format(new_expname.upper()))

13
flag_weights.py

@ -8,10 +8,12 @@ Options:
threshold : float Visibilities with a weight below the specified
value will be flagged. Must be positive.
Version: 1.2
Date: Nov 2017
Version: 1.3
Date: Apr 2018
Written by Benito Marcote (marcote@jive.eu)
version 1.3 changes
- Minor fixes (prog name in optparse info).
version 1.2 changes
- Minor fixes.
version 1.1 changes
@ -37,7 +39,7 @@ 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.2')
parser.add_argument('--version', action='version', version='%(prog)s 1.3')
parser.add_argument("-v", "--verbose", default=True, action="store_false" , help=help_v)
arguments = parser.parse_args()
#print('The arguments ', arguments)
@ -50,7 +52,7 @@ except ImportError:
"""
# Compatibility with Python 2.7 in eee
import optparse
parser = optparse.OptionParser(usage=usage, description=description, prog='ysfocus.py', version='%prog 1.2')
parser = optparse.OptionParser(usage=usage, description=description, prog='flag_weights.py', version='%prog 1.3')
parser.add_option("-v", action="store_false", dest="verbose", default=True, help=help_v)
theparser = parser.parse_args()
verbose = theparser[0].verbose
@ -78,7 +80,8 @@ with pt.table(msdata, readonly=False) as ms:
ms.putcol("WEIGHT", weights)
print('Done.')
else:
print('Flag has not been applied')
rint('Flag has not been applied.')
ms.close()

2
polswap.py

@ -11,7 +11,7 @@ Options:
use either string 'Ef, Mc' or a non-spaced str:
Ef,Mc,Ys.
Version: 0.0a
Version: 1.2
Date: Dec 2017
Written by Benito Marcote (marcote@jive.eu)
"""

Loading…
Cancel
Save