00001 from tasks import *
00002 from taskinit import *
00003 from __main__ import default
00004 import os
00005 from locatescript import copydata
00006
00007 epsilon = 0.0001
00008
00009 caltables = ['ggtau.1mm.amp.gcal',
00010 'ggtau.1mm.bpoly',
00011 'ggtau.1mm.ph.gcal',
00012 'ggtau.1mm.ph.gcal0',
00013 'ggtau.3mm.amp.gcal',
00014 'ggtau.3mm.bpoly',
00015 'ggtau.3mm.ph.gcal',
00016 'ggtau.3mm.ph.gcal0',
00017 'ggtau.co.bpoly',
00018 'ggtau.hco.bpoly']
00019
00020 def description():
00021 return "Test of calstat task"
00022
00023 def data():
00024 return caltables
00025
00026 def run( fetch=False ):
00027
00028
00029 if fetch:
00030 for f in data( ):
00031 copydata( f, os.getcwd( ) )
00032
00033 expected = {'ggtau.3mm.ph.gcal0':
00034 {'SPLINE_KNOTS_PHASE':{'rms': 4362063360.0,
00035 'medabsdevmed': 8704.0,
00036 'min': 4362050048.0,
00037 'max': 4362076160.0,
00038 'sum': 872412620800.0,
00039 'quartile': 26112.0,
00040 'median': 4362058752.0,
00041 'sumsq': 3.80551890468e+21,
00042 'stddev': 11866.4301499,
00043 'var': 140812164.503,
00044 'npts': 200,
00045 'mean': 4362063104.0}},
00046 'ggtau.1mm.ph.gcal0':
00047 {'SPLINE_KNOTS_PHASE':{'rms': 4362063360.0,
00048 'medabsdevmed': 8704.0,
00049 'min': 4362050048.0,
00050 'max': 4362076160.0,
00051 'sum': 872412620800.0,
00052 'quartile': 26112.0,
00053 'median': 4362058752.0,
00054 'sumsq': 3.80551890468e+21,
00055 'stddev': 11866.4301499,
00056 'var': 140812164.503,
00057 'npts': 200,
00058 'mean': 4362063104.0}}}
00059
00060 for caltable in caltables:
00061
00062 print "Testing with data", caltable, "..."
00063
00064 if expected.has_key(caltable):
00065
00066 default(calstat)
00067 axis='spline_knots_phase'
00068 s = calstat(caltable=caltable, axis=axis)
00069
00070 if s.keys() != expected[caltable].keys():
00071 raise Exception("Wrong dictionary keys. Expected %s, got %s" % \
00072 (expected[caltable], s))
00073
00074 print "Expected =", expected[caltable]
00075 print "Got = ", s
00076 if not s.has_key('SPLINE_KNOTS_PHASE'):
00077 raise Exception("Dictionary returned from calstat does not have key SPLINE_KNOTS_PHASE")
00078
00079 for e in expected[caltable]['SPLINE_KNOTS_PHASE'].keys():
00080 print "Checking %s: %s vs %s" % \
00081 (e, expected[caltable]['SPLINE_KNOTS_PHASE'][e], s['SPLINE_KNOTS_PHASE'][e])
00082 failed = False
00083 if expected[caltable]['SPLINE_KNOTS_PHASE'][e] == 0:
00084 if s['SPLINE_KNOTS_PHASE'][e] != 0:
00085 failed = True
00086 else:
00087 if abs((expected[caltable]['SPLINE_KNOTS_PHASE'][e] - s['SPLINE_KNOTS_PHASE'][e])/expected[caltable]['SPLINE_KNOTS_PHASE'][e]) > epsilon:
00088 failed = True
00089
00090
00091 if failed == True and e in ['var', 'stddev']:
00092 print "Ignoring this known problem on 64bit!"
00093 failed = False
00094
00095
00096 if failed:
00097 raise Exception("Numbers differ, expected %s, got %s" % \
00098 (str(expected[caltable]['SPLINE_KNOTS_PHASE'][e]), str(s['SPLINE_KNOTS_PHASE'][e])))
00099
00100 tb.open(caltable)
00101 cols = tb.colnames()
00102 tb.close()
00103
00104 cplx = ['amp', 'amplitude', 'phase', 'imag', 'imaginary', 'real']
00105 for x in cplx:
00106 cols.append(x)
00107 print cols
00108
00109 cols.remove('GAIN')
00110 if 'SCALE_FACTOR' in cols: cols.remove('SCALE_FACTOR')
00111 if 'SIDEBAND_REF' in cols: cols.remove('SIDEBAND_REF')
00112
00113 cols.remove('FREQ_GROUP_NAME')
00114 cols.remove('FIELD_NAME')
00115 cols.remove('FIELD_CODE')
00116 cols.remove('SOURCE_NAME')
00117 cols.remove('SOURCE_CODE')
00118 if 'POLY_TYPE' in cols: cols.remove('POLY_TYPE')
00119 if 'POLY_MODE' in cols: cols.remove('POLY_MODE')
00120 if 'PHASE_UNITS' in cols: cols.remove('PHASE_UNITS')
00121
00122
00123 if 'VALID_DOMAIN' in cols: cols.remove('VALID_DOMAIN')
00124
00125 cols = [x.lower() for x in cols]
00126
00127 print "Trying these column names", cols
00128
00129 for col in cols:
00130 data_cols = ['']
00131 if col in cplx:
00132 data_cols = ['gain', 'scale_factor']
00133
00134 for dc in data_cols:
00135 print "Call with caltable =", caltable, "; axis =", col, "; datacolumn =", dc
00136 if dc != '':
00137 s = calstat(caltable=caltable, axis=col, datacolumn=dc)
00138 else:
00139 s = calstat(caltable=caltable, axis=col)
00140 if col.upper() == "FLAG_CATEGORY":
00141
00142
00143 if s != None:
00144 raise Exception("Error! " + str(s))
00145 elif not type(s) is dict:
00146 raise Exception("Error! Return value " + str(s) + " is not a dictionary")
00147 print ''
00148 print 'Regression PASSED'
00149 print ''
00150 return []