def _get_info(self): # Create the local instance of the table tool and open it with # the antenna subtable of the MS tbLoc = casac.table() tbLoc.open(self.vis + '/ANTENNA') # Get the antenna information from the antenna table info = dict() info['position'] = tbLoc.getcol('POSITION') info['flag_row'] = tbLoc.getcol('FLAG_ROW') info['name'] = tbLoc.getcol('NAME') info['position_keywords'] = tbLoc.getcolkeywords('POSITION') # Close the table tool and delete the local instance tbLoc.close() del tbLoc # The flag tool appears to return antenna names as upper case, # which seems to be different from the antenna names stored in # MSes. Therefore, these names will be capitalized here. rRow = range(len(info['name'])) # Return the antenna information return info
def compVarColTables(referencetab, testtab, varcol, tolerance=0.): '''Compare a variable column of two tables. referencetab --> a reference table testtab --> a table to verify varcol --> the name of a variable column (str) Returns True or False. ''' retval = True tb2 = casac.table() tb.open(referencetab) cnames = tb.colnames() tb2.open(testtab) col = varcol if tb.isvarcol(col) and tb2.isvarcol(col): try: # First check if tb.nrows() != tb2.nrows(): print 'Length of '+ str(referencetab) +' differ from '+ str(testtab)+','+ str(tb.nrows())+ '!=' + str(tb2.nrows()) retval = False else: for therow in xrange(tb.nrows()): rdata = tb.getcell(col,therow) tdata = tb2.getcell(col,therow) if not rdata.all()==tdata.all(): if (tolerance>0.): differs=False for j in range(0,len(rdata)): if ((isinstance(rdata[j],float)) or (isinstance(rdata[j],int))): if (abs(rdata[j]-tdata[j]) > tolerance*abs(rdata[j]+tdata[j])): differs = True elif (isinstance(rdata[j],list)) or (isinstance(rdata[j],np.ndarray)): for k in range(0,len(rdata[j])): if (abs(rdata[j][k]-tdata[j][k]) > tolerance*abs(rdata[j][k]+tdata[j][k])): differs = True if differs: print 'ERROR: Column ' + str(col) + ' of ' + str(referencetab) + ' and ' + str(testtab)+ ' do not agree within tolerance '+ str(tolerance) break else: print 'ERROR: Column ' +str(col)+ ' of ' +str(referencetab)+ ' and ' +str(testtab) + ' do not agree.' print 'ERROR: First row to differ is row=' + str(therow) retval = False break finally: tb.close() tb2.close() else: print 'Column: ' +str(col) + 'are not varcolumns.' retval = False if retval: print 'Column ' + str(col) + ' of ' + str(referencetab) + ' and ' + str(testtab) + ' agree' return retval
def find_needed_items(musthave=set([]), listall=False): """ Given the set of "must have" items, fill out needed_subtables and needed_items, and determine whether or not to use tb. """ #print "musthave =", ", ".join(musthave) #print "listall =", listall needed_subtables = musthave.intersection(possible_subtables) needed_items = {'anywhere': set([])} # cols and keywords for mh in musthave: mhparts = mh.split('/') if len(mhparts) > 1: if not needed_items.has_key(mhparts[0]): needed_items[mhparts[0]] = set([mhparts[1]]) else: needed_items.add(mhparts[1]) if mhparts[0] != 'MAIN': needed_subtables.add(mhparts[0]) elif mh not in possible_subtables: needed_items['anywhere'].add(mh) use_tb = False need_tb = musthave.difference(needed_subtables) mytb = None if need_tb or listall: try: use_tb = hasattr(tb, 'colnames') mytb = tb except: try: try: from casac import * except: casacpath = glob(os.sep.join(os.environ["CASAPATH"].split() + ['python', '2.*'])) # devs casacpath.sort() casacpath.reverse() casacpath.extend(glob(os.sep.join([os.environ["CASAPATH"].split()[0], 'lib', 'python2.*']))) # users #print "casacpath =", "\n".join(casacpath) import sys sys.path.extend(casacpath) import casac ## from taskutil import get_global_namespace ## my_globals = get_global_namespace() ## tb = my_globals['tb'] #from casa import table as tb mytb = casac.table() use_tb = hasattr(mytb, 'colnames') except: print "Could not find the tb tool. Try running inside a casapy session or setting PYTHONPATH to /usr/lib/casapy/.../lib/python2.*." if need_tb and not use_tb: print "Removing", ', '.join(need_tb), "from the criteria for matching." musthave.difference_update(need_tb) return needed_subtables, needed_items, use_tb, mytb
def openTable(tableName): try: import casac from casac import casac tb = casac.table() tb.open(str(tableName)) tb.close() return True except: return False
def _get_names(self): # Create the local instance of the table tool and open the MS tbLoc = casac.table() tbLoc.open(self.vis + '/ANTENNA') # Gets the antenna names and automatically capitalizes them. # (Unfortunately, some CASA tools capitalize them and others do not.) names = tbLoc.getcol('NAME').tolist() # Martijn: the next two lines do not seem to make sense. I commented them. #rNames = range( len(names) ) #for n in rNames: names[n] = names[n] # Close the local instance of the table tool and delete it. tbLoc.close() del tbLoc # Return the antenna names return names
def find_needed_items(musthave=set([]), listall=False): """ Given the set of "must have" items, fill out needed_subtables and needed_items, and determine whether or not to use tb. """ #print "musthave =", ", ".join(musthave) #print "listall =", listall needed_subtables = musthave.intersection(possible_subtables) needed_items = {'anywhere': set([])} # cols and keywords for mh in musthave: mhparts = mh.split('/') if len(mhparts) > 1: if not needed_items.has_key(mhparts[0]): needed_items[mhparts[0]] = set([mhparts[1]]) else: needed_items.add(mhparts[1]) if mhparts[0] != 'MAIN': needed_subtables.add(mhparts[0]) elif mh not in possible_subtables: needed_items['anywhere'].add(mh) use_tb = False need_tb = musthave.difference(needed_subtables) mytb = None if need_tb or listall: try: use_tb = hasattr(tb, 'colnames') mytb = tb except: try: try: from casac import * except: casacpath = glob( os.sep.join(os.environ["CASAPATH"].split() + ['python', '2.*'])) # devs casacpath.sort() casacpath.reverse() casacpath.extend( glob( os.sep.join([ os.environ["CASAPATH"].split()[0], 'lib', 'python2.*' ]))) # users #print "casacpath =", "\n".join(casacpath) import sys sys.path.extend(casacpath) import casac ## from taskutil import get_global_namespace ## my_globals = get_global_namespace() ## tb = my_globals['tb'] #from casa import table as tb mytb = casac.table() use_tb = hasattr(mytb, 'colnames') except: print "Could not find the tb tool. Try running inside a casapy session or setting PYTHONPATH to /usr/lib/casapy/.../lib/python2.*." if need_tb and not use_tb: print "Removing", ', '.join( need_tb), "from the criteria for matching." musthave.difference_update(need_tb) return needed_subtables, needed_items, use_tb, mytb