@@ -0,0 +1,1886 @@
+#!/usr/bin/env python%0A%22%22%22%0AA command-line script for renumbering antenna numbers %3E 255 if possible in uvfits files.%0A%22%22%22%0Aimport numpy as np%0Aimport os%0Aimport argparse%0Afrom pyuvdata import UVData%0A%0A# setup argparse%0Aa = argparse.ArgumentParser(description=%22A command-line script for renumbering antenna numbers %3E 255 if possible in uvfits files.%22)%0Aa.add_argument(%22file_in%22, type=str, help=%22input uvfits file.%22)%0Aa.add_argument(%22file_out%22, type=str, help=%22output uvfits file.%22)%0Aa.add_argument(%22--overwrite%22, default=False, action='store_true', help=%22overwrite output file if it already exists.%22)%0Aa.add_argument(%22--verbose%22, default=False, action='store_true', help=%22report feedback to stdout.%22)%0A%0A# get args%0Aargs = a.parse_args()%0A%0Auv_obj = UVData()%0Auv_obj.read_uvfits(args.file_in)%0A%0Alarge_ant_nums = uv_obj.antenna_numbers%5Bnp.where(uv_obj.antenna_numbers %3E 255)%5B0%5D%5D%0A%0Anew_nums = sorted(list(set(range(256)) - set(uv_obj.antenna_numbers)))%0Aif len(new_nums) %3C len(large_ant_nums):%0A    raise ValueError('too many antennas in dataset, cannot renumber all below 255')%0Anew_nums = new_nums%5B-1 * len(large_ant_nums):%5D%0Arenumber_dict = dict(zip(large_ant_nums, new_nums))%0A%0Afor ant_in, ant_out in renumber_dict.iteritems():%0A    if args.verbose:%0A        print %22renumbering %7Ba1%7D to %7Ba2%7D%22.format(a1=ant_in, a2=ant_out)%0A%0A    wh_ant_num = np.where(uv_obj.antenna_numbers == ant_in)%5B0%5D%0A    wh_ant1_arr = np.where(uv_obj.ant_1_array == ant_in)%5B0%5D%0A    wh_ant2_arr = np.where(uv_obj.ant_2_array == ant_in)%5B0%5D%0A%0A    uv_obj.antenna_numbers%5Bwh_ant_num%5D = ant_out%0A    uv_obj.ant_1_array%5Bwh_ant1_arr%5D = ant_out%0A    uv_obj.ant_2_array%5Bwh_ant2_arr%5D = ant_out%0A    blt_inds = np.array(sorted(list(set(wh_ant1_arr.tolist() + wh_ant2_arr.tolist()))))%0A    uv_obj.baseline_array%5Bblt_inds%5D = uv_obj.antnums_to_baseline(uv_obj.ant_1_array%5Bblt_inds%5D, uv_obj.ant_2_array%5Bblt_inds%5D)%0A%0Auv_obj.check()%0A%0Auv_obj.write_uvfits(args.file_out)%0A

Add a script to renumber antennas to below 256 in uvfits files