def from_ms (ms): # import table class try: from pyrap_tables import table,tablecopy,tableexists,tabledelete except: try: from pyrap.tables import table,tablecopy,tableexists,tabledelete except: print "Failed to import pyrap_tables or pyrap.tables. Please install the pyrap " "package from http://code.google.com/p/pyrap/, or from a MeqTrees binary repository " "(see http://www.astron.nl/meqwiki/Downloading.)" raise; # open MS if isinstance(ms,str): ms = table(ms); elif not isinstance(ms,table): raise TypeError,"'ms' argument must be an MS name or a table object"; # open ANTENNA subtable anttab = table(ms.getkeyword("ANTENNA")); stations = list(anttab.getcol('NAME')); antpos = anttab.getcol('POSITION'); observatory = anttab.getcol("STATION")[0]; anttab.close(); # trim away longest antenna name prefix while stations[0]: if len([st for st in stations[1:] if st[0] == stations[0][0]]) != len(stations)-1: break; stations = [ st[1:] for st in stations ]; # make IfrSet object return IfrSet(stations,positions=antpos,observatory=observatory);
parser.add_option("-s","--select",dest="select",action="store", help="additional TaQL selection string. Note that redundant baselines are counted only within the subset " "given by the --ifrs and --select options."); parser.add_option("-l","--list",action="store_true", help="list all baselines and exit."); parser.add_option("-r","--reset",action="store_true", help="reset WEIGHT column to unity. All other options are then ignored."); parser.set_defaults(tolerance=.1,select="",ifrs=""); (options,msnames) = parser.parse_args(); if len(msnames) != 1: parser.error("MS name not supplied."); msname = msnames[0]; ms = table(msname,readonly=False); ncorr = ms.getcol('DATA',0,1).shape[2]; if options.reset: # apply weights nrows = ms.nrows(); for row0 in range(0,nrows,ROWCHUNK): progress("Resetting weights, row %d of %d"%(row0,nrows),newline=False); row1 = min(nrows,row0+ROWCHUNK); w = numpy.ones((row1-row0,ncorr),float); ms.putcol('WEIGHT',w,row0,row1-row0); progress("Weights reset to unity."); else: taqls = []; # get IFR set import Meow.IfrSet
# Check if we found all antennas in the file codes = [ant['NAME'] for ant in ant_list] for ant in user_antennas: if ant not in codes: print >> sys.stderr, 'Warning: Antenna "%s" not found' % ant # Define columns offset_desc = clarrdsc('OFFSET', value=float(), ndim=1, shape=[3]) position_desc = clarrdsc('POSITION', value=float(), ndim=1, shape=[3]) type_desc = cldsc('TYPE', value=str()) dish_desc = cldsc('DISH_DIAMETER', value=float()) flag_desc = cldsc('FLAG_ROW', value=bool()) mount_desc = cldsc('MOUNT', value=str()) name_desc = cldsc('NAME', value=str()) station_desc = cldsc('STATION', value=str()) desc = tablecreatedesc([offset_desc, position_desc, type_desc, dish_desc, flag_desc, mount_desc, name_desc, station_desc]) # Create and populate our table table = pyrap_tables.table(ms_out, desc, nrow=len(ant_list), readonly=False) table.putcolkeywords('OFFSET', {'QuantumUnits': ['m', 'm', 'm'], 'MEASINFO': {'Ref': 'ITRF', 'type': 'position'}}) table.putcolkeywords('POSITION', {'QuantumUnits': ['m', 'm', 'm'], 'MEASINFO': {'Ref': 'ITRF', 'type': 'position'}}) table.putcolkeywords('DISH_DIAMETER', {'QuantumUnits': ['m']}) table[:] = {'DISH_DIAMETER': 25.0, 'OFFSET': [0.0,0.0,0.0], 'TYPE': 'GROUND-BASED'} for i in range(len(ant_list)): table[i] = ant_list[i]