Exemplo n.º 1
0
    def createRate(self, graceid, gdb, verbose=None, annotate=False, **kwargs):
        """
        check the local rate of triggers submitted to GraceDB
        checks only around the event's creation time : [t-self.mWin, t+self.pWin)
        Queries GraceDb for neighbors
        """
        if verbose:
            logger = esUtils.genTaskLogger( self.logDir, self.name, logTag=self.logTag )
            logger.info( "%s : %s"%(graceid, self.description) )
            logger.debug( "retrieving information about this event" )
        gdb_entry = gdb.event( graceid ).json()

        ### get event time
        event_time = float(tconvert( gdb_entry['created'][:-4] )) ### we strip the time-zone to help tconvert format this 
        winstart = tconvert( np.floor(event_time-self.mWin ), form="%Y-%m-%d %H:%M:%S" )
        winstop  = tconvert( np.ceil( event_time+self.pWin ), form="%Y-%m-%d %H:%M:%S" )

        if verbose:
            logger.debug( "%s -> %.3f"%(gdb_entry['created'], event_time) )
            logger.debug( "retrieving neighbors within [%s, %s]"%(winstart, winstop) )

        ### count the number of neighbors
        count = 0
        for entry in gdb.events( "created: %s .. %s"%(winstart, winstop) ): ### query for neighbors in (t-mWin, t+pWin)
            if not entry.has_key('search'):
                entry['search'] = None
            ###         not the 'current' event          belongs to the right group        associated with the right pipeline           from the correct search
            count += (entry['graceid'] != graceid) and (entry['group'] == self.group) and (entry['pipeline'] == self.pipeline) and (entry['search'] == self.search) ### add to count

        if count > (self.pWin+self.mWin)*self.maxRate: ### too many neighbors
            self.warning = self.warning = "found %d events within (-%.3f, +%.3f) of %s"%(count, self.mWin, self.pWin, graceid)
            if verbose or annotate:
                message = "action required : found %d events within (-%.3f, +%.3f) of %s creation"%(count, self.mWin, self.pWin, graceid)

                ### post messsage
                if verbose:
                    logger.debug( message )
                if annotate:
                    esUtils.writeGDBLog( gdb, graceid, message=message )

            return True ### action_required = True

        else: ### an acceptable number of neighbors
            self.warning = "found %d events within (-%.3f, +%.3f) of %s"%(count, self.mWin, self.pWin, graceid)
            if verbose or annotate:
                message = "no action required : found %d events within (-%.3f, +%.3f) of %s creation"%(count, self.mWin, self.pWin, graceid)

                ### post message
                if verbose:
                    logger.debug( message )
                if annotate:
                    esUtils.writeGDBLog( gdb, graceid, message )

            return False ### action_required = False
Exemplo n.º 2
0
def gps2relativeUTC( t ):
    """
    converts gps secons into the number of seconds after the most recent 00:00:00 UTC
    """
    if isinstance(t, (np.ndarray, list, tuple)):
        times = []
        for T in t:
            ans = tconvert( T )
            times.append( T - float(tconvert( ans.split(',')[0]+" 00:00:00" )) )
        return np.array(times)
    else:
        ans = tconvert( t )
        return t-float(tconvert( ans.split(',')[0]+" 00:00:00" ))
Exemplo n.º 3
0
def gps2latency(gps_time):
    """
	Given a gps time, measures the latency to ms precision relative to now.
	"""
    current_gps_time = float(
        gpstime.tconvert('now')) + (timeit.default_timer() % 1)
    return round(current_gps_time - gps_time, 3)
Exemplo n.º 4
0
def lunarPosition( gps, coord="C" ):
    '''
    '''
    moon = ephem.Moon()
    moon.compute(tconvert(int(gps), form="%Y/%m/%d %H:%M:%S"))
    if coord=="C":
        return float(moon.dec), float(moon.ra)
    else:
        return float(moon.dec), rotateRAC2E( float(moon.ra), gps )
Exemplo n.º 5
0
def solarPosition( gps, coord="C" ):
    '''
    '''
    timeObj = astropyTime( tconvert(int(gps), form="%Y-%m-%dT%H:%M:%S")+("%.3f"%(gps%1))[1:], format='isot', scale='utc')
    sun = astropyCoordinates.get_sun(timeObj)
    if coord=="C":
        return float(sun.dec.radian), float(sun.ra.radian)
    else:
        return float(sun.dec.radian), rotateRAC2E( float(sun.ra.radian), gps )
Exemplo n.º 6
0
def isLunarOccluded( dec, ra, gps, dead_zone ):
    moon = ephem.Moon()
    if isinstance( gps, (np.ndarray, list, tuple) ):
        theta_moon = np.empty_like(gps)
        phi_moon = np.empty_like(gps)
        for i, t in enumerate(gps):
            moon.compute(tconvert(int(t), form="%Y/%m/%d %H:%M:%S"))
            theta_moon[i] = pi2 - moon.dec
            phi_moon[i] = moon.ra
    else:
        moon.compute(tconvert(int(gps), form="%Y/%m/%d %H:%M:%S"))
        theta_moon = pi2 - moon.dec
        phi_moon = moon.ra

    theta = pi2 - dec
    ### compute cos(theta) between all pixels and the sun in spherical coordinates
    cosdtheta = np.cos(theta_moon)*np.cos(theta) + np.sin(theta_moon)*np.sin(theta)*np.cos(phi_moon-ra)

    return cosdtheta > np.cos(dead_zone)
Exemplo n.º 7
0
def isSolarOccluded( dec, ra, gps, dead_zone ):
    if isinstance( gps, (np.ndarray, list, tuple) ):
        theta_sun = np.empty_like( gps )
        phi_sun = np.empty_like( gps )
        for i, t in enumerate(gps):
            timeObj = astropyTime( tconvert(int(t), form="%Y-%m-%dT%H:%M:%S")+("%.3f"%(t%1))[1:], format='isot', scale='utc')

            ### get solar position in spherical coordinate
            sun = astropyCoordinates.get_sun(timeObj)
            theta_sun[i] = pi2 - sun.dec.radian
            phi_sun[i] = sun.ra.radian
    else:
        timeObj = astropyTime( tconvert(int(gps), form="%Y-%m-%dT%H:%M:%S")+("%.3f"%(gps%1))[1:], format='isot', scale='utc')

        ### get solar position in spherical coordinate
        sun = astropyCoordinates.get_sun(timeObj)
        theta_sun = pi2 - sun.dec.radian
        phi_sun = sun.ra.radian

    theta = pi2 - dec
    ### compute cos(theta) between all pixels and the sun in spherical coordinates
    cosdtheta = np.cos(theta_sun)*np.cos(theta) + np.sin(theta_sun)*np.sin(theta)*np.cos(phi_sun-ra)

    return cosdtheta > np.cos(dead_zone)
Exemplo n.º 8
0
if opts.verbose:
    print "instantiating FakeDb"
gdb = FakeDb(opts.fakeDB_dir)

if opts.verbose:
    print "creating events"

graceids = {}
for x in xrange(opts.Nevents):
    if opts.verbose:
        print "    %d / %d : group, pipeline, search = %s, %s, %s"%(x+1, opts.Nevents, opts.group, opts.pipeline, opts.search)

    ### create the event
    randStr = utils.genRandStr()
    gDBevent = schedule.GraceDBEvent(randStr)
    pipeObj = pipelines.initPipeline( float(tconvert('now')), 
                                      1e-9, 
                                      ['H1','L1'], 
                                      opts.group, 
                                      opts.pipeline, 
                                      gDBevent, 
                                      search=opts.search, 
                                      gdb_url=opts.fakeDB_dir
                                    )

    agenda = pipeObj.genSchedule(directory=opts.output_dir)

    ### put some stuff into the event

    ### writeLabel
    for label in set( [random.choice(labels) for _ in xrange(5)] ):
Exemplo n.º 9
0
_, mostRecent = getFiles(directory, suffix=opts.suffix, verbose=opts.Verbose)
if opts.verbose:
    print >> sys.stdout, 'mostRecent : %s' % mostRecent

### iterate
while True:
    t0 = time.time()  ### remember when we started

    ### discover new files
    filenames, mostRecent = getFiles(directory,
                                     mostRecent=mostRecent,
                                     suffix=opts.suffix,
                                     verbose=opts.Verbose)

    ### print new files and their latencies
    gpsObs = tconvert('now')  ### get the current gps time
    for filename in filenames:
        gpsNom = int(os.path.basename(filename).split('-')
                     [-2])  ### get gps time from this filename

        ### report latency
        print >> sys.stderr, '%.1f\t%s' % (gpsObs - gpsNom, filename)

    sys.stderr.flush()

    if opts.verbose:
        print >> sys.stdout, "mostRecent : %s at %.3f" % (mostRecent, gpsObs)

    ### sleep so we don't query faster than opts.cadence
    wait = max(0, t0 + opts.cadence - time.time())
    if opts.verbose:
        print "processing %s\n    ifo        : %s\n    config     : %s"%(chanset, ifo, exeConfig)

    ### parse exeConfig, get frame types, etc
    chans = parse.parseOmegaScanConfig( exeConfig )
    frameTypes = set( chan['frameType'] for chan in chans )
    for frame_type in frameTypes: ### ensure we have a section for each frame type
        assert config.has_section(frame_type), '%s has no section for frameType=%s'%(config_name, frame_type)

    ### figure out when to processes
    win    = 0.5*max([ float(chan['searchTimeRange']) for chan in chans ]) ### ensure we grab enough data based on what the scan wants!
    start  = math.floor(gps-win)
    end    = math.ceil(gps+win)
    stride = end - start

    ### wait until we have a chance of finding data (causality)
    wait = end - tconvert('now')
    if wait > 0:
        if opts.verbose:
            print "  waiting %.3f sec"%(wait)
        time.sleep( wait )

    #---------------------------------------------
    # DATA DISCOVERY
    #---------------------------------------------

    if opts.verbose:
        print "  finding frames"

    for frame_type in frameTypes:

        lookup  = config.get(frame_type, 'lookup')
Exemplo n.º 11
0
def test_tconvert(_, in_, result):
    out = gpstime.tconvert(in_)
    assert type(out) == type(result)
    assert out == result
Exemplo n.º 12
0
    def createRate(self, graceid, gdb, verbose=None, annotate=False, **kwargs):
        """
        check the local rate of triggers submitted to GraceDB
        checks only around the event's creation time : [t-self.mWin, t+self.pWin)
        Queries GraceDb for neighbors
        """
        if verbose:
            logger = esUtils.genTaskLogger(self.logDir,
                                           self.name,
                                           logTag=self.logTag)
            logger.info("%s : %s" % (graceid, self.description))
            logger.debug("retrieving information about this event")
        gdb_entry = gdb.event(graceid).json()

        ### get event time
        event_time = float(tconvert(
            gdb_entry['created']
            [:-4]))  ### we strip the time-zone to help tconvert format this
        winstart = tconvert(np.floor(event_time - self.mWin),
                            form="%Y-%m-%d %H:%M:%S")
        winstop = tconvert(np.ceil(event_time + self.pWin),
                           form="%Y-%m-%d %H:%M:%S")

        if verbose:
            logger.debug("%s -> %.3f" % (gdb_entry['created'], event_time))
            logger.debug("retrieving neighbors within [%s, %s]" %
                         (winstart, winstop))

        ### count the number of neighbors
        count = 0
        for entry in gdb.events(
                "created: %s .. %s" %
            (winstart, winstop)):  ### query for neighbors in (t-mWin, t+pWin)
            if not entry.has_key('search'):
                entry['search'] = None
            ###         not the 'current' event          belongs to the right group        associated with the right pipeline           from the correct search
            count += (entry['graceid'] != graceid) and (
                entry['group']
                == self.group) and (entry['pipeline'] == self.pipeline) and (
                    entry['search'] == self.search)  ### add to count

        if count > (self.pWin +
                    self.mWin) * self.maxRate:  ### too many neighbors
            self.warning = self.warning = "found %d events within (-%.3f, +%.3f) of %s" % (
                count, self.mWin, self.pWin, graceid)
            if verbose or annotate:
                message = "action required : found %d events within (-%.3f, +%.3f) of %s creation" % (
                    count, self.mWin, self.pWin, graceid)

                ### post messsage
                if verbose:
                    logger.debug(message)
                if annotate:
                    esUtils.writeGDBLog(gdb, graceid, message=message)

            return True  ### action_required = True

        else:  ### an acceptable number of neighbors
            self.warning = "found %d events within (-%.3f, +%.3f) of %s" % (
                count, self.mWin, self.pWin, graceid)
            if verbose or annotate:
                message = "no action required : found %d events within (-%.3f, +%.3f) of %s creation" % (
                    count, self.mWin, self.pWin, graceid)

                ### post message
                if verbose:
                    logger.debug(message)
                if annotate:
                    esUtils.writeGDBLog(gdb, graceid, message)

            return False  ### action_required = False
Exemplo n.º 13
0
    if opts.verbose:
        print "No times found!"
    import sys
    sys.exit(0)
waits[0] = 0  ### reset the first entry to be occur immediately

#-------------------------------------------------

### generate schedule for simulation
if opts.verbose:
    print "generating global schedule"

sched = schedule.Schedule()
delay = 0.0
t0 = time.time()
start_gps = opts.start_time if opts.start_time else float(tconvert('now'))
for ind, wait in enumerate(waits):
    if opts.verbose:
        print "generating schedule for event %d" % (ind)

    delay += wait  ### increment how long we need to delay this event

    ### generate a schedule specifically for this event
    gps = start_gps + delay
    far = opts.far if opts.far else np.random.randint(
        1, 10) * 1e-9  ### FIXME: should probably randomly assign this...
    instruments = opts.instruments

    ### choose the event type
    config = random.choice(configs)
Exemplo n.º 14
0
    },
    'Burst': {
        'CWB': [None, 'AllSky'],
        'LIB': [None, 'AllSky'],
    },
    'Test': {
        'MBTAOnline': [None, 'LowMass', 'HighMass', 'MDC'],
        'gstlal': [None, 'LowMass', 'HighMass', 'MDC'],
        'gstlal-spiir': [None, 'LowMass', 'HighMass', 'MDC'],
        'pycbc': [None, 'AllSky', 'LowMass', 'HighMass', 'MDC'],
        'CWB': [None, 'AllSky'],
        'LIB': [None, 'AllSky'],
    },
}

gps = float(tconvert('now'))
far = 1e-9
instruments = ["H1", "L1"]

graceDBevents = []
successes = []
failures = []
for group in combos.keys():
    for pipeline in combos[group].keys():
        for search in combos[group][pipeline]:
            if opts.verbose:
                print "  trying:\n    group    : %s\n    pipeline : %s\n    search   : %s" % (
                    group, pipeline, search)

            graceDBevent = schedule.GraceDBEvent()
            graceDBevents.append(graceDBevent)
Exemplo n.º 15
0
waits[0] = 0 ### reset the first entry to be occur immediately

#-------------------------------------------------

### generate schedule for simulation
if opts.verbose:
    print "generating global schedule"

sched = schedule.Schedule()
delay = 0.0
t0 = time.time()

if opts.start_gps!=None:
    start_gps = opts.start_gps
else:
    start_gps = float(tconvert('now'))

for ind, wait in enumerate(waits):
    if opts.verbose:
        print "generating schedule for event %d"%(ind)

    delay += wait ### increment how long we need to delay this event

    ### generate a schedule specifically for this event
    gps = start_gps + delay
    far = 1e-9 ### FIXME: should probably randomly assign this...
    instruments = opts.instruments

    ### choose the event type
    config = random.choice( configs )