def test__init__(self): correct = lal.LIGOTimeGPS(100, 500000000) tests = [ (100.5,), (100.500000000,), (100.50000000000000000000000,), (100, "500000000"), (100, "500000000.0000000000000"), (101, "-500000000"), (101, "-500000000.0000000000000"), ("100.5",), ("100.500000000",), ("100.50000000000000000000000",), ("100", 500000000), ("100", 500000000.0000000000000), ("101", -500000000), ("101", -500000000.0000000000000), ("100", "500000000"), ("100", "500000000.0000000000000"), ("101", "-500000000"), ("101", "-500000000.0000000000000"), (0, 100500000000), (0, 100500000000.0000000000000), (99, 1500000000), (99.5, 1000000000), (-10, 110500000000), (-10.5, 111000000000) ] for num, test in enumerate(tests): try: self.assertEqual(correct, lal.LIGOTimeGPS(*test)) except AssertionError as e: raise AssertionError("Test %d failed: " % (num) + str(e))
def gpstime_inside_segment(gps_seconds, gps_nanoseconds, segment_string): """ Convenience function to be used within sqlite query. It checks if a given gps in is inside the segment or not. Returns boolen. """ # convert segment string into segment segment = segmentsUtils.from_range_strings([segment_string], boundtype=lal.LIGOTimeGPS)[0] return lal.LIGOTimeGPS(gps_seconds, gps_nanoseconds) in segment
def test_swig_comparison(self): try: from lal import LIGOTimeGPS as swigLIGOTimeGPS except ImportError: print("lal swig bindings not available: skipping test", file=sys.stderr) return toswig = lambda x: swigLIGOTimeGPS(str(x)) fromswig = lambda x: lal.LIGOTimeGPS(str(x)) operators = { "add": (lal.LIGOTimeGPS.__add__, swigLIGOTimeGPS.__add__), "sub": (lal.LIGOTimeGPS.__sub__, swigLIGOTimeGPS.__sub__) } for i in range(100000): key, (op, swigop) = random.choice(list(operators.items())) arg1 = randomLIGOTimeGPS() / 2 arg2 = randomLIGOTimeGPS() / 2 try: self.assertEqual(op(arg1, arg2), fromswig(swigop(toswig(arg1), toswig(arg2)))) except AssertionError as s: raise AssertionError("%s(%s, %s) comparison failed: %s" % (key, str(arg1), str(arg2), str(s))) # FIXME: mod tests fail, fix then enable operators = { "mul": (lal.LIGOTimeGPS.__mul__, swigLIGOTimeGPS.__mul__), "div": (lal.LIGOTimeGPS.__div__, swigLIGOTimeGPS.__div__) #, #"mod": (lal.LIGOTimeGPS.__mod__, swigLIGOTimeGPS.__mod__) } for i in range(100000): key, (op, swigop) = random.choice(list(operators.items())) arg1 = randomLIGOTimeGPS() / 100 arg2 = 100**(random.random() * 2 - 1) try: self.assertEqual( abs(op(arg1, arg2) - fromswig(swigop(toswig(arg1), arg2))) <= 1e-9, True) except AssertionError as s: raise AssertionError( "%s(%s, %s) comparison failed: %s != %s" % (key, str(arg1), "%.17g" % arg2, str(op( arg1, arg2)), str(swigop(toswig(arg1), arg2))))
### ### ############################################# if obs == 'K': GWChan = obs + '1:' + 'LSC-MICH_CTRL_CAL_OUT_DQ' else: GWChan = obs + '1:' + 'GDS-CALIB_STRAIN' GWSamRate = '16384' AuxChan = np.loadtxt(ChanList, dtype=np.str).tolist() for i in range(len(AuxChan)): print 'Channel No. %s' % (i + 1) print 'Extracting data and resampling for Aux Channel: ' + AuxChan[i][0] try: if obs == 'K': HoftData = seriesutils.fromlalcache(CacheDir + '/' + CacheFile, GWChan, lal.LIGOTimeGPS(stime), dur) AuxData = seriesutils.fromlalcache(CacheDir + '/' + CacheFile, AuxChan[i][0], lal.LIGOTimeGPS(stime), dur) else: HoftData = seriesutils.fromlalcache(CacheDir + '/' + HoftCacheFile, GWChan, lal.LIGOTimeGPS(stime), dur) AuxData = seriesutils.fromlalcache(CacheDir + '/' + AuxCacheFile, AuxChan[i][0], lal.LIGOTimeGPS(stime), dur) except RuntimeError: print 'No such channel data in the data. Passed.' pass else:
def test__mod__(self): self.assertEqual(lal.LIGOTimeGPS(3), lal.LIGOTimeGPS(13) % 5.0)
def test__div__(self): self.assertEqual(lal.LIGOTimeGPS(10), lal.LIGOTimeGPS(20) / 2) self.assertEqual(lal.LIGOTimeGPS(10), lal.LIGOTimeGPS(5) / .5)
def test__mul__(self): self.assertEqual(lal.LIGOTimeGPS(10), lal.LIGOTimeGPS(5) * 2) self.assertEqual(lal.LIGOTimeGPS(10), lal.LIGOTimeGPS(20) * 0.5) self.assertEqual(lal.LIGOTimeGPS(0), lal.LIGOTimeGPS(1000) * 0)
def test__add__(self): self.assertEqual(lal.LIGOTimeGPS(110.5), lal.LIGOTimeGPS(100.5) + 10) self.assertEqual(lal.LIGOTimeGPS(110.5), lal.LIGOTimeGPS(100.5) + lal.LIGOTimeGPS(10))
def test__nonzero__(self): self.assertEqual(True, bool(lal.LIGOTimeGPS(100.5))) self.assertEqual(False, bool(lal.LIGOTimeGPS(0)))
def testns(self): self.assertEqual(100500000000, lal.LIGOTimeGPS(100.5).ns())
def test__int__(self): self.assertEqual(100, int(lal.LIGOTimeGPS(100.1))) self.assertEqual(100, int(lal.LIGOTimeGPS(100.9)))
def test__float__(self): self.assertEqual(100.5, float(lal.LIGOTimeGPS(100.5)))
def randomLIGOTimeGPS(): return lal.LIGOTimeGPS(random.randint(-100000000, +100000000), random.randint(0, 999999999))
def maxLIGOTimeGPS(): return lal.LIGOTimeGPS(2**32 - 1, 999999999)
# ############################################################## # # load files into database connection, cursor = idq_tables_dbutils.load_xml_files_into_database(\ gchxml_filenames, verbose=opts.verbose) # ######################################################### # ## remove redundant rows and any events outside of [opts.start, opts.end] ########################################################### # remove redundant entries from the tables idq_tables_dbutils.remove_redundant_entries(connection, cursor, verbose = opts.verbose) # form two open segments using start and stop times seglist = segments.segmentlist() seglist.append(segments.segment([-segments.infinity(), lal.LIGOTimeGPS(opts.start)])) seglist.append(segments.segment([lal.LIGOTimeGPS(opts.end), segments.infinity()])) # delete glitch events that fall inside of these segments idq_tables_dbutils.delete_glitch_events_in_segmentlist(connection, cursor, seglist) ############################################################################### # ## save merged xmldoc ############################################################################### #merged_xmldoc_filename = '%s/%s_idq_%s_glitch_%s%d-%d.xml' % ( # opts.output_dir, # opts.ifo, # opts.classifier, # opts.tag, # int(opts.start),
gchxml_filenames, verbose=opts.verbose) # ######################################################### # ## remove redundant rows and any events outside of [opts.start, opts.end] ########################################################### # remove redundant entries from the tables idq_tables_dbutils.remove_redundant_entries(connection, cursor, verbose=opts.verbose) # form two open segments using start and stop times seglist = segments.segmentlist() seglist.append( segments.segment([-segments.infinity(), lal.LIGOTimeGPS(opts.start)])) seglist.append( segments.segment([lal.LIGOTimeGPS(opts.end), segments.infinity()])) # delete glitch events that fall inside of these segments idq_tables_dbutils.delete_glitch_events_in_segmentlist(connection, cursor, seglist) ############################################################################### # ## save merged xmldoc ############################################################################### #merged_xmldoc_filename = '%s/%s_idq_%s_glitch_%s%d-%d.xml' % ( # opts.output_dir, # opts.ifo, # opts.classifier,