2 changed files with 182 additions and 0 deletions
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/python3 |
||||
"""Takes the default {exp}_sfxc2ms.sh file produced by the |
||||
sfxc2ms.pl script and adds the _SRCname to the .cor files. |
||||
|
||||
Generates different {exp}_sfxc2ms_SRCname.sh files for the |
||||
different phase centers (detailed in SRCname). |
||||
|
||||
|
||||
Benito Marcote |
||||
January 2018 |
||||
JIVE |
||||
""" |
||||
import os |
||||
import sys |
||||
import stat |
||||
import glob |
||||
import argparse |
||||
#from astropy.io import ascii |
||||
|
||||
# if len(sys.argv) != 3: #or sys.argv[1] == '-h': |
||||
# print('multiphase_sfxc2ms.py <expname> <targetname>') |
||||
# print('You need to specify the experiment name and the target source name') |
||||
# print('as it is without the multi-phase center labeling') |
||||
# print('(i.e. write only the text common to all the phase centers)') |
||||
# sys.exit(1) |
||||
|
||||
# expname = sys.argv[1].lower() |
||||
# target = sys.argv[2] |
||||
|
||||
|
||||
help_script = """Takes the default {exp}_sfxc2ms.sh file produced by the |
||||
sfxc2ms.pl script and adds the _SRCname to the .cor file names. |
||||
|
||||
Generates different {exp}_sfxc2ms_{n-phasecenter}.sh files for the |
||||
different phase centers (detailed in SRCname). |
||||
""" |
||||
help_cals = """Should the calibrators be included in all measurement sets? (in the different phase centers) |
||||
By default they are include. If you set this option then they will be removed in all but the first pha. centers. |
||||
""" |
||||
|
||||
parser = argparse.ArgumentParser(description=help_script) |
||||
parser.add_argument('-c', '--include-cals', default=True, dest='cals_on', action='store_false', help=help_cals) |
||||
parser.add_argument('expname', type=str, default=None, help='Experiment name') |
||||
parser.add_argument('target', type=str, default=None, help='Target name (without phase center suffixes)') |
||||
|
||||
args = parser.parse_args() |
||||
|
||||
expname = args.expname.lower() |
||||
target = args.target |
||||
|
||||
#### NO NEED FOR THIS ANY MORE |
||||
# with open(expname+'.vxsm', 'r') as vexsumfile: |
||||
# The format is always (must be) ScanNo Time1 - Time2 0.0000 SRCname Stations |
||||
#vexsumfile = ascii.read(expname+'.vxsm') |
||||
#scans2src = {} # In the form {'No0001': 'SRCname'} |
||||
#for aline in vexsumfile: |
||||
# scans2src[aline[0]] = aline[5] |
||||
|
||||
# Gets all the names received by the target source for the different phase-centers |
||||
# Stranger: do not look at this line please |
||||
phc_names = list(set([i.split('_')[-1] for i in glob.glob('./*/*.cor_'+target+'*')])) |
||||
phc_suffixes = [i.replace(target, '') for i in phc_names] |
||||
|
||||
with open(expname+'_sfxc2ms.sh', 'r') as shfile: |
||||
# Create a file per phase center |
||||
final_sh_files = [open(expname+'_sfxc2ms'+suff+'.sh', 'w') for suff in phc_suffixes] |
||||
shlines = shfile.readlines() |
||||
for ashline in shlines: |
||||
if ashline[:4] == 'j2ms': |
||||
tempfile = ashline.split(' ') |
||||
corfile = tempfile[-1] |
||||
corfile_existing = glob.glob(corfile[:-2]+'*') |
||||
#print(corfile) |
||||
#print(tempfile) |
||||
#print(corfile_existing) |
||||
if len(corfile_existing) == 0: |
||||
pass |
||||
|
||||
elif len(corfile_existing) == 1: |
||||
for a_sh_file in final_sh_files: |
||||
a_sh_file.write(' '.join(tempfile[:-1])+' '+corfile_existing[0]+'\n') |
||||
|
||||
else: |
||||
# This is the target, multiple phase centers. |
||||
for i in range(len(phc_suffixes)): |
||||
final_sh_files[i].write(ashline[:-1]+'_'+target+phc_suffixes[i]+'\n') |
||||
|
||||
else: |
||||
for a_sh_file in final_sh_files: |
||||
a_sh_file.write(ashline) |
||||
|
||||
|
||||
for a_sh_file in final_sh_files: |
||||
a_sh_file.close() |
||||
|
||||
# Make the files executable |
||||
files = [expname+'_sfxc2ms'+suff+'.sh' for suff in phc_suffixes] |
||||
for a_file in files: |
||||
#os.chmod(a_file, stat.S_IREAD | stat.S_IWUSR | stat.S_IEXEC) |
||||
os.chmod(a_file, 0o755) |
||||
|
||||
|
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
#! /usr/bin/python |
||||
""" |
||||
Swap polarizations for specified antennas in specified subbands |
||||
|
||||
Usage: polswap.py msdata antennas [-sb SUBBANDS] |
||||
Options: |
||||
msdata : str MS data set containing the data to be swapged. |
||||
antennas : str Antenna or list of antennas that require to be |
||||
swapped. Use the two-letter name (e.g. Ef, Mc, |
||||
or Jb2). In case of more than one station, please |
||||
use either string 'Ef, Mc' or a non-spaced str: |
||||
Ef,Mc,Ys. |
||||
|
||||
Version: 0.0a |
||||
Date: Dec 2017 |
||||
Written by Benito Marcote (marcote@jive.eu) |
||||
""" |
||||
|
||||
from pyrap import tables as pt |
||||
import numpy as np |
||||
import sys |
||||
|
||||
# TO CHANGE |
||||
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.' |
||||
help_v = 'Only checks the visibilities to flag (do not flag the data).' |
||||
|
||||
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.2') |
||||
parser.add_argument("-v", "--verbose", default=True, action="store_false" , help=help_v) |
||||
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 [-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.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 [-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] |
||||
threshold = float(arguments[1]) |
||||
|
||||
|
||||
assert threshold > 0.0 |
||||
|
||||
with pt.table(msdata, readonly=False) as ms: |
||||
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)) |
||||
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…
Reference in new issue