casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
cmpmses.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 def cmptabs(tab1, tab2):
00004     """
00005     Returns 1 if any of the columns in tab1 differ from the corresponding ones
00006     in tab2, 0 otherwise.
00007     """
00008     tabs = (tab1, tab2)
00009     tb.open(tab1)
00010     colnames = set(tb.colnames())
00011     nrows1 = tb.nrows()
00012     tb.close()
00013     tb.open(tab2)
00014     colnames2 = set(tb.colnames())
00015     nrows2 = tb.nrows()
00016     tb.close()
00017 
00018     if colnames2 !=  colnames:
00019         print tab1, "has cols", str(colnames)
00020         print tab2, "has cols", str(colnames2)
00021         return 1
00022 
00023     del colnames2
00024 
00025     # After this point, both tables are assumed to have some rows, so check now.
00026     if 0 in (nrows1, nrows2):
00027         if nrows1 == nrows2:
00028             return 0
00029         else:
00030             return 1
00031     
00032     for col in colnames:
00033         cols = [-1, -1]      # Default to a semi-invalid code.
00034         for i in xrange(2):
00035             tb.open(tabs[i])
00036             try:
00037                 if tb.iscelldefined(col):    # col in colnames does not
00038                     cols[i] = tb.getcol(col) # imply col is valid.
00039             except:
00040                 print "Error getting", tabs[i], " col =", col
00041                 return 1
00042             finally:
00043                 tb.close()
00044         diff = cols[0] != cols[1]
00045         if hasattr(diff, 'any'):
00046             diff = diff.any()
00047         if diff:
00048             print col, "differs"
00049             return 1
00050     return 0
00051 
00052 def cmpmses(ms1, ms2, subtabs_to_check=['ANTENNA', 'DATA_DESCRIPTION', 'FEED',
00053                                         'FLAG_CMD', 'FIELD',
00054                                         'OBSERVATION', 'POINTING',
00055                                         'POLARIZATION', 'PROCESSOR',
00056                                         'SPECTRAL_WINDOW', 'STATE',
00057                                         'SOURCE', 'WEATHER'],
00058             kws_to_check=['MS_VERSION']):
00059     """
00060     Returns 1 if any of the columns, listed subtables, or listed keywords in
00061     ms1 differ from the corresponding ones in ms2, 0 otherwise.
00062     """
00063     mses = (ms1, ms2)
00064     kws = []
00065     for i in xrange(2):
00066         tb.open(mses[i])
00067         kws.append(tb.keywordnames())
00068         tb.close()
00069     if kws[0] != kws[1]:
00070         print "They have different keyword sets."
00071         return 1
00072     for kw in kws_to_check:
00073         kwvals = ['', '']
00074         for i in xrange(2):
00075             if kw in kws[i]:
00076                 tb.open(mses[i])
00077                 kwvals[i] = tb.getkeyword(kw)
00078                 tb.close()
00079         if kwvals[0] != kwvals[1]:
00080             print kw, "differs"
00081             return 1
00082     for subtab in subtabs_to_check:
00083         if subtab in kws[0]:
00084             if cmptabs(ms1 + '/' + subtab, ms2 + '/' + subtab):
00085                 return 1
00086     return cmptabs(ms1, ms2)