示例#1
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
示例#2
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)
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
示例#4
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])]
示例#5
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 = []
示例#6
0
                                 (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":
示例#7
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
示例#8
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)