コード例 #1
0
def get_slide_coincs_from_cache(cachefile, pattern, match, verb, coinc_stat):
  full_coinc_table = []
  cache = cachefile.sieve(description=pattern, exact_match=match)
  found, missed = cache.checkfilesexist()
  files = found.pfnlist()
  if not len(files):
    print >>sys.stderr, "cache contains no files with " + pattern + " description"
    return None
  # split the time slide files into 105 groups to aid with I/O
  num_files=len(files)

  #Changed by Tristan Miller as a memory fix
  #groups_of_files = split_seq(files,105)
  groups_of_files = split_seq(files,50)
  for filegroup in groups_of_files:
    if filegroup:  
      # extract the coinc table
      coinc_table = SnglInspiralUtils.ReadSnglInspiralFromFiles(filegroup, mangle_event_id=False, verbose=verb, non_lsc_tables_ok=False)
      segDict = SearchSummaryUtils.GetSegListFromSearchSummaries(filegroup)
      rings = segments.segmentlist(iterutils.flatten(segDict.values()))
      rings.sort()
      for k,ring in enumerate(rings):
        rings[k] = segments.segment(rings[k][0], rings[k][1] + 10**(-9))
      shift_vector = {"H1": 0, "H2": 0, "L1": 5, "V1": 5}
      if coinc_table:
        SnglInspiralUtils.slideTriggersOnRingWithVector(coinc_table, shift_vector, rings)
        full_coinc_table.extend(CoincInspiralUtils.coincInspiralTable(coinc_table,coinc_stat))
  return full_coinc_table
コード例 #2
0
def getrmsdiff(ref_file_glob, test_file_glob, columns):

    refFiles = []
    testFiles = []

    #print "I'm in the function and the globs are %s and %s" %(ref_file_glob,test_file_glob)

    refFiles.extend(glob.glob(ref_file_glob))
    testFiles.extend(glob.glob(test_file_glob))

    refTrigs = SnglInspiralUtils.ReadSnglInspiralFromFiles(refFiles)
    testTrigs = SnglInspiralUtils.ReadSnglInspiralFromFiles(testFiles)

    if len(refTrigs) != len(testTrigs):
        #print "unequal number of triggers: %d %d" % (len(refTrigs), len(testTrigs))
        meandiff = ["NaN"]
    else:
        meandiff = []
        for c in columns:
            refcolumn = refTrigs.get_column(c)
            testcolumn = testTrigs.get_column(c)
            tmpmeandiff = sqrt(mean(pow(refcolumn - testcolumn, 2.0)))
            meandiff.append(tmpmeandiff)
        #print "%s %s" % (c,meandiff)

    return len(refTrigs), len(testTrigs), meandiff
コード例 #3
0
def ligolw_sicluster(doc, **kwargs):
    # Extract segments and tables
    inseg, outseg, snglinspiraltable = get_tables(doc)

    # Add process information
    try:
        process = append_process(doc, **kwargs)
    except ValueError:
        process = None

    # Delete all triggers below threshold
    if kwargs["snr_threshold"] > 0:
        thresh = float(kwargs["snr_threshold"])
        if kwargs["verbose"]:
            print >>sys.stderr, "discarding triggers with snr < %f ..." % \
              kwargs["snr_threshold"]
        for i in range(len(snglinspiraltable) - 1, -1, -1):
            if snglinspiraltable[i].snr <= thresh:
                del snglinspiraltable[i]

    # Cluster
    snglcluster.cluster_events(
        snglinspiraltable,
        testfunc=lambda a, b: SnglInspiralUtils.CompareSnglInspiral(
            a, b, twindow=kwargs["cluster_window"]),
        clusterfunc=SnglInspiralCluster,
        sortfunc=SnglInspiralUtils.CompareSnglInspiralByEndTime,
        bailoutfunc=lambda a, b: SnglInspiralUtils.CompareSnglInspiral(
            a, b, twindow=kwargs["cluster_window"]),
        verbose=kwargs["verbose"])

    # Sort by signal-to-noise ratio
    if kwargs["sort_ascending_snr"] or kwargs["sort_descending_snr"]:
        if kwargs["verbose"]:
            print >> sys.stderr, "sorting by snr ..."
        snglinspiraltable.sort(SnglInspiralUtils.CompareSnglInspiralBySnr)
        if kwargs["sort_descending_snr"]:
            snglinspiraltable.reverse()

    # Add search summary information
    if process and inseg and outseg:
        ligolw_search_summary.append_search_summary(
            doc,
            process,
            inseg=inseg,
            outseg=outseg,
            nevents=len(snglinspiraltable))
    if process:
        ligolw_process.set_process_end_time(process)

    return doc
コード例 #4
0
def InspiralNearCoincCompare(sim, inspiral):
    """
	Return False if the peak time of the sim is within 9 seconds of the inspiral event.
	"""
    return SnglInspiralUtils.CompareSnglInspiral(sim,
                                                 inspiral,
                                                 twindow=LIGOTimeGPS(9))
コード例 #5
0
 def calc_delta_t(trigger1_ifo,
                  trigger1_end_time,
                  trigger1_end_time_ns,
                  trigger2_ifo,
                  trigger2_end_time,
                  trigger2_end_time_ns,
                  time_slide_id,
                  rings=rings,
                  offset_vectors=offset_vectors):
     print("calculating delta_t", file=sys.stderr)
     trigger1_true_end_time = dbtables.lsctables.LIGOTimeGPS(
         trigger1_end_time, trigger1_end_time_ns)
     trigger2_true_end_time = dbtables.lsctables.LIGOTimeGPS(
         trigger2_end_time, trigger2_end_time_ns)
     # find the instruments that were on at trigger 1's end time and
     # find the ring that contains this trigger
     try:
         [ring] = [
             segs[segs.find(trigger1_end_time)]
             for segs in rings.values() if trigger1_end_time in segs
         ]
     except ValueError:
         # FIXME THERE SEEMS TO BE A BUG IN  THINCA!  Occasionally thinca records a trigger on the upper boundary
         # of its ring.  This would make it outside the ring which is very problematic.  It needs to be fixed in thinca
         # for now we'll allow the additional check that the other trigger is in the ring and use it.
         print("trigger1 found not on a ring, trying trigger2",
               file=sys.stderr)
         [ring] = [
             segs[segs.find(trigger2_end_time)]
             for segs in rings.values() if trigger2_end_time in segs
         ]
     # now we can unslide the triggers on the ring
     try:
         trigger1_true_end_time = SnglInspiralUtils.slideTimeOnRing(
             trigger1_true_end_time,
             offset_vectors[time_slide_id][trigger1_ifo], ring)
         trigger2_true_end_time = SnglInspiralUtils.slideTimeOnRing(
             trigger2_true_end_time,
             offset_vectors[time_slide_id][trigger2_ifo], ring)
         out = abs(trigger1_true_end_time - trigger2_true_end_time)
         return float(out)
     except:
         print("calc delta t failed", trigger1_true_end_time,
               trigger2_true_end_time, ring)
         return float(
             abs(trigger1_true_end_time - trigger2_true_end_time)) % 1
コード例 #6
0
    def get_coincs_from_coire(self, files, stat='snr'):
        """
    uses CoincInspiralUtils to get data from old-style (coire'd) coincs
    """
        coincTrigs = CoincInspiralUtils.coincInspiralTable()
        inspTrigs = SnglInspiralUtils.ReadSnglInspiralFromFiles(files, \
                                      mangle_event_id = True,verbose=None)
        statistic = CoincInspiralUtils.coincStatistic(stat, None, None)
        coincTrigs = CoincInspiralUtils.coincInspiralTable(
            inspTrigs, statistic)

        try:
            inspInj = SimInspiralUtils.ReadSimInspiralFromFiles(files)
            coincTrigs.add_sim_inspirals(inspInj)
        #FIXME: name the exception!
        except:
            pass

        #now extract the relevant information into CoincData objects
        for ctrig in coincTrigs:
            coinc = CoincData()
            coinc.set_ifos(ctrig.get_ifos()[1])
            coinc.set_gps(
                dict(
                    (trig.ifo, LIGOTimeGPS(trig.get_end())) for trig in ctrig))
            coinc.set_snr(
                dict((trig.ifo, getattr(ctrig, trig.ifo).snr)
                     for trig in ctrig))
            coinc.set_effDs(
                dict((trig.ifo, getattr(ctrig, trig.ifo).eff_distance)
                     for trig in ctrig))
            coinc.set_masses(dict((trig.ifo,getattr(ctrig,trig.ifo).mass1) for trig in ctrig), \
                             dict((trig.ifo,getattr(ctrig,trig.ifo).mass2) for trig in ctrig))

            try:
                effDs_inj = {}
                for ifo in coinc.ifo_list:
                    if ifo == 'H1':
                        effDs_inj[ifo] = getattr(ctrig, 'sim').eff_dist_h
                    elif ifo == 'L1':
                        effDs_inj[ifo] = getattr(ctrig, 'sim').eff_dist_l
                    elif ifo == 'V1':
                        effDs_inj[ifo] = getattr(ctrig, 'sim').eff_dist_v
                dist_inj = getattr(ctrig, 'sim').distance
                coinc.set_inj_params(getattr(ctrig,'sim').latitude,getattr(ctrig,'sim').longitude, \
                                     getattr(ctrig,'sim').mass1,getattr(ctrig,'sim').mass2,dist_inj,effDs_inj)
                coinc.is_injection = True
                #FIXME: name the exception!
            except:
                pass

            self.append(coinc)
コード例 #7
0
ファイル: db_thinca_rings.py プロジェクト: Solaro/lalsuite
def get_thinca_livetimes(ring_sets, veto_segments, offset_vectors, verbose = False):
  # FIXME:  somebody should document this
  livetimes = {}
  for available_instruments, rings in ring_sets.items():
    for on_instruments in (combo for m in range(2, len(available_instruments) + 1) for combo in iterutils.choices(sorted(available_instruments), m)):
      if verbose:
        print >>sys.stderr, "%s/%s" % (",".join(on_instruments), ",".join(sorted(available_instruments))),
      on_instruments = frozenset(on_instruments)
      if on_instruments not in livetimes:
        livetimes[on_instruments] = [0.0] * len(offset_vectors)
      for i, livetime in enumerate(SnglInspiralUtils.compute_thinca_livetime(on_instruments, available_instruments - on_instruments, rings, veto_segments, offset_vectors)):
        livetimes[on_instruments][i] += livetime
  return livetimes
コード例 #8
0
def plot_triggers(trig_file,
                  center_time,
                  center_time_ns,
                  title,
                  dest,
                  new_snr=False):
    start_time = center_time - 10
    end_time = center_time + 10

    triggers = SnglInspiralUtils.ReadSnglInspiralFromFiles([trig_file])
    triggers = [
        t for t in triggers
        if t.end_time >= start_time and t.end_time < end_time
    ]

    xs = [t.end_time + t.end_time_ns * 1.0e-9 - center_time for t in triggers]
    ys = new_snr and [get_new_snr(t)
                      for t in triggers] or [t.snr for t in triggers]
    zs = [t.tau0 for t in triggers]

    pylab.figure()
    pylab.scatter(xs, ys, c=zs, edgecolor='none')

    if max(ys) > 10:
        pylab.yscale('log')

    pylab.ylim(min(ys), max(ys))

    pylab.xlabel('Time (s since %.3f)' % center_time)
    pylab.ylabel(new_snr and 'New SNR' or 'SNR')
    pylab.title(title)

    cb = pylab.colorbar()
    cb.ax.set_ylabel('Tau 0')

    pylab.savefig(dest)

    loudest_snr = max(ys)
    pos = 0
    for i in range(len(ys)):
        if ys[i] == loudest_snr:
            pos = i

    # Find the original trigger so we can report on it's chisq, etc
    orig = [
        t for t in triggers
        if t.end_time == center_time and t.end_time_ns == center_time_ns
    ][0]

    return orig.chisq, get_new_snr(orig), triggers[pos].end_time, triggers[
        pos].end_time_ns, triggers[pos].snr
コード例 #9
0
def readCoinc(CoincFile):
    '''
    Reads the coinc file. Finds the highest SNR IFO and returns the point estimates of the same.
    '''
    coinc = SnglInspiralUtils.ReadSnglInspiralFromFiles(CoincFile)
    ifo=[]; mass1=[]; mass2=[]; chi1=[]; snr= np.array([])
    for row in coinc:
        ifo.append(row.ifo)
        mass1.append(row.mass1)
        mass2.append(row.mass2)
        chi1.append(row.spin1z)
        snr = np.append(snr, row.snr)
    index = np.argmax(snr) ## To return highest SNR IFO point estimates
    return [mass1[index], mass2[index], chi1[index], snr[index], str(ifo[index])]
コード例 #10
0
ファイル: mvsc_get_doubles.py プロジェクト: Solaro/lalsuite
 def calc_delta_t(trigger1_ifo, trigger1_end_time, trigger1_end_time_ns, trigger2_ifo, trigger2_end_time, trigger2_end_time_ns, time_slide_id, rings = rings, offset_vectors = offset_vectors):
   print >>sys.stderr, "calculating delta_t"
   trigger1_true_end_time = dbtables.lsctables.LIGOTimeGPS(trigger1_end_time, trigger1_end_time_ns)
   trigger2_true_end_time = dbtables.lsctables.LIGOTimeGPS(trigger2_end_time, trigger2_end_time_ns)
   # find the instruments that were on at trigger 1's end time and
   # find the ring that contains this trigger
   try:
     [ring] = [segs[segs.find(trigger1_end_time)] for segs in rings.values() if trigger1_end_time in segs]
   except ValueError:
     # FIXME THERE SEEMS TO BE A BUG IN  THINCA!  Occasionally thinca records a trigger on the upper boundary
     # of its ring.  This would make it outside the ring which is very problematic.  It needs to be fixed in thinca
     # for now we'll allow the additional check that the other trigger is in the ring and use it.
       print >>sys.stderr, "trigger1 found not on a ring, trying trigger2"
       [ring] = [segs[segs.find(trigger2_end_time)] for segs in rings.values() if trigger2_end_time in segs]
   # now we can unslide the triggers on the ring
   try:
     trigger1_true_end_time = SnglInspiralUtils.slideTimeOnRing(trigger1_true_end_time, offset_vectors[time_slide_id][trigger1_ifo], ring)
     trigger2_true_end_time = SnglInspiralUtils.slideTimeOnRing(trigger2_true_end_time, offset_vectors[time_slide_id][trigger2_ifo], ring)
     out = abs(trigger1_true_end_time - trigger2_true_end_time)
     return float(out)
   except:
     print "calc delta t failed",trigger1_true_end_time, trigger2_true_end_time, ring
     return float(abs(trigger1_true_end_time - trigger2_true_end_time)) % 1
コード例 #11
0
def get_rinca_livetimes(ring_sets,
                        veto_segments,
                        offset_vectors,
                        verbose=False):
    # FIXME:  somebody should document this
    livetimes = {}
    for available_instruments, rings in ring_sets.items():
        for on_instruments in (combo
                               for m in range(2,
                                              len(available_instruments) + 1)
                               for combo in iterutils.choices(
                                   sorted(available_instruments), m)):
            if verbose:
                print >> sys.stderr, "%s/%s" % (",".join(
                    on_instruments), ",".join(sorted(available_instruments))),
            on_instruments = frozenset(on_instruments)
            if on_instruments not in livetimes:
                livetimes[on_instruments] = [0.0] * len(offset_vectors)
            for i, livetime in enumerate(
                    SnglInspiralUtils.compute_rinca_livetime(
                        on_instruments, available_instruments - on_instruments,
                        rings, veto_segments, offset_vectors)):
                livetimes[on_instruments][i] += livetime
    return livetimes
コード例 #12
0
# warn_msg
if no_bkg_frgnd:
    warn_msg = 'No foreground or background in files:\n'
    for idx in sorted(no_bkg_frgnd.items(), key=itemgetter(1), reverse=True):
        warn_msg = warn_msg + ' ' + os.path.basename(corsefiles.pop(
            idx[1])) + '\n'
    # check if still have a corsefiles list; if all the files that were globbed
    # don't have foreground and background, just make a generic plot with
    # warn_msg on it; this avoids future errors
    if not corsefiles:
        warn_msg = warn_msg + 'These were all the globbed files.'
        sys.exit(0)

coincStat = CoincInspiralUtils.coincStatistic("far")
for thisfile in corsefiles:
    insptrigs = SnglInspiralUtils.ReadSnglInspiralFromFiles([thisfile])
    coincT[thisfile] = CoincInspiralUtils.coincInspiralTable(
        insptrigs, coincStat)
    coincT[thisfile].sort()  # sort by descending FAN
    # if this file has no_bkg, but does have foreground, get the ifo coincident
    # type from the first foreground trigger
    if thisfile in no_bkg:
        coincifos[thisfile] = coincT[thisfile][0].get_ifos()[0]
#for thisfile in corsefiles:
#  if NormTime[corsefiles[0]] != NormTime[thisfile]:
#    print >> sys.stderr, "Can't combine experiments with " + \
#      "different analysis times."
#    sys.exit( 1 )
maxFANs = []  # for storing max FAN of bkg (the dict is hard to sort by value)
FANc = []  # for storing the combined FANs of foreground triggers
zero_fanc = []
コード例 #13
0
ファイル: plot_likelihood.py プロジェクト: white105/lalsuite
                                 (events.L1.get_effective_snr())**2)
        return {"H1L1_eff_snr": H1L1_eff_snr}

    elif hasattr(events, "H2") and hasattr(events, "L1"):
        H2L1_eff_snr = math.sqrt((events.H2.get_effective_snr())**2 +
                                 (events.L1.get_effective_snr())**2)
        return {"H2L1_eff_snr": H2L1_eff_snr}


statistic = CoincInspiralUtils.coincStatistic(opts.statistic)

###############################################################################
# read in zero lag coinc triggers

zerolagTriggers = None
zerolagTriggers = SnglInspiralUtils.ReadSnglInspiralFromFiles(
    zerolagfiles, mangle_event_id=True)

# construct the zero lag coincs
zerolagCoincTriggers= \
CoincInspiralUtils.coincInspiralTable(zerolagTriggers, statistic)

slidesTriggers = None
slidesTriggers = SnglInspiralUtils.ReadSnglInspiralFromFiles(
    slidesfiles, mangle_event_id=True)

# construct the time slides coincs for single.
slidesCoincs= \
CoincInspiralUtils.coincInspiralTable(slidesTriggers, statistic)

# Construct the time slides for double in triple times.
if opts.coincs == "H1H2":
コード例 #14
0
  def investigateTimeseries(self, triggerFiles, inj,  ifoName, stage, number ):
    """
    Investigate inspiral triggers and create a time-series
    of the SNRs around the injected time
    @param triggerFiles: List of files containing the inspiral triggers
    @param inj:          the current missed injection
    @param ifoName:      the IFO for which the plot is made 
    @param stage:        the name of the stage (FIRST, SECOND)
    @param number:        the consecutive number for this inspiral followup
    """
    
    # read the inspiral file(s)
    if self.verbose:
      print "Processing INSPIRAL triggers from files ", triggerFiles
      
    snglTriggers = SnglInspiralUtils.ReadSnglInspiralFromFiles( \
      triggerFiles , verbose=False)

    # create a figure and initialize some lists
    fig=figure()
    foundSet = set()
    loudest_details = {}
    noTriggersFound = True
    
    if snglTriggers is None:
      # put message on the plot instead
      self.putText( 'No sngl_inspiral triggers in %s' % str(triggerFiles))

    else:
      # selection segment
      timeInjection = self.getTimeSim( inj )
      segSmall =  segments.segment( timeInjection-self.injection_window, \
                                    timeInjection+self.injection_window )
      segLarge =  segments.segment( timeInjection-self.time_window, \
                                    timeInjection+self.time_window )

      # create coincidences for THINCA stage
      coincTriggers = None
      if 'THINCA' in stage:
        coincTriggers = CoincInspiralUtils.coincInspiralTable( snglTriggers, \
                      CoincInspiralUtils.coincStatistic("snr") )
        selectedCoincs = coincTriggers.vetoed( segSmall )
      
      # loop over the IFOs (although this is a plot for IFO 'ifoName')
      for ifo in self.colors.keys():

        # get the singles for this ifo
        snglInspiral = snglTriggers.ifocut(ifo)

        # select a range of triggers
        selectedLarge = snglInspiral.vetoed( segLarge )
        timeLarge = [ self.getTimeTrigger( sel )-timeInjection \
                      for sel in selectedLarge ]

        selectedSmall = snglInspiral.vetoed( segSmall )
        timeSmall = [ self.getTimeTrigger( sel )-timeInjection \
                      for sel in selectedSmall ]

        # use the set of selected coincident triggers in the THINCA stages
        if coincTriggers:
          selectedSmall = selectedCoincs.cluster(2* self.injection_window).getsngls(ifo)
          timeSmall = [ self.getTimeTrigger( sel )-timeInjection \
                        for sel in selectedSmall ]
          
        # skip if no triggers in the large time window
        if len(timeLarge)==0:
          continue
        noTriggersFound = False

        # add IFO to this set; the injection is found for this IFO and stage
        if len(timeSmall)>0:
          foundSet.add(ifo)                  

          # record details of the loudest trigger
          loudest_details[ifo] = {}
          loudest = selectedSmall[selectedSmall.get_column('snr').argmax()]
          loudest_details[ifo]["snr"] = loudest.snr
          loudest_details[ifo]["mchirp"] = loudest.mchirp
          loudest_details[ifo]["eff_dist"] = loudest.eff_distance
          loudest_details[ifo]["chisq"] = loudest.chisq
          loudest_details[ifo]["timeTrigger"] = self.getTimeTrigger( loudest )

          timeTrigger = self.getTimeTrigger( loudest )
          vetoSegs = self.vetodict[ifoName]
          
        # plot the triggers
        plot( timeLarge, selectedLarge.get_column('snr'),\
              self.colors[ifo]+'o', label="_nolegend_")
        plot( timeSmall, selectedSmall.get_column('snr'), \
              self.colors[ifo]+'s', label=ifo)

      # draw the injection times and other stuff
      if noTriggersFound:
        self.putText( 'No triggers/coincidences found within time window')
        
      ylims=axes().get_ylim()
      plot( [0,0], ylims, 'g--', label="_nolegend_")
      plot( [-self.injection_window, -self.injection_window], ylims, 'c:',\
            label="_nolegend_")
      plot( [+self.injection_window, +self.injection_window], ylims, 'c:',\
            label="_nolegend_")

      self.highlightVeto( timeInjection, segLarge, ifoName, ylims  )

      # save the plot
      grid(True)
      legend()

    ylims=axes().get_ylim()
    axis([-self.time_window, +self.time_window, ylims[0], ylims[1]])
    xlabel('time [s]')
    ylabel('SNR')
    title(stage+'_'+str(self.number))    
    fname = self.savePlot( stage )
    close(fig)

    result = {'filename':fname, 'foundset':foundSet, 'loudest_details':loudest_details}
    return result
コード例 #15
0
    timefile=open(opts.gps_time_file,'r')
    for time in timefile:
        if not p.match(time):
            continue
        if float(time) in times:
            print 'Skipping duplicate time %s'%(time)
            continue
        print 'Read time %s'%(time)
        times.append(float(time))
    timefile.close()
    starttime=min(times)
    endtime=max(times)

if opts.single_triggers:
    from pylal import SnglInspiralUtils
    trigTable=SnglInspiralUtils.ReadSnglInspiralFromFiles([opts.single_triggers])
    times=[trig.get_end() for trig in trigTable]
    starttime=min(times)
    endtime=max(times)

if opts.coinc_triggers:
    from pylal.xlal.datatypes.ligotimegps import LIGOTimeGPS
    from glue.ligolw import table
    from glue.ligolw import lsctables
    from glue.ligolw import utils

    CoincInspiralTriggers=None
    doc = utils.load_filename(opts.coinc_triggers, gz=(opts.coinc_triggers or "stdin").endswith(".gz"), verbose=False)
    # extract the sim inspiral table
    try: CoincInspiralTable = \
        table.get_table(doc, lsctables.CoincInspiralTable.tableName)