示例#1
0
  def write_html_output(self, html_filename, doThumb=True, map_list=[],
                        comment=None, coinc_summ_table=None ):
    """
    @param doThumb: Uses the thumbnail file as the sourcs for the images
    @param map_list: A list of dictionaries to create the image maps
    @param comment: A comment that can be added to the page
    @param coinc_summ_table: A CoincSummTable that can be added to the page
    """

    # Initialise the html output file
    page = markup.page()
    try:
      page.init(title=__title__)
    except:
      page.init()

    page.h1(self.name + " results")

    page.p(self.prefix + self.suffix)
    page.hr()

    # open the output file
    html_file = file(html_filename, "w")

    # loop over the contents
    for tag,filename in zip(self.tag_list, self.fname_list):

      # set the correct name for linking (two '//' does not bother)
      fname = "Images/" + os.path.basename(filename)

      # set the thumbnail pictures if required
      if doThumb:
        fname_thumb = fname[:-4] + "_thumb.png"
      else:
        fname_thumb = fname

      # add the image to the page
      page.a(extra_oneliner.img(src=[fname_thumb], width=400,
          alt=tag, border="2"), title=tag, href=[ fname])

    page.add("<hr/>")

    # add maps to this page
    m=0
    for map_dict in map_list:
      m+=1
      page.add( map_dict['text']+'<br>' )
      page.add( '<IMG src="%s" width=800px '
                'usemap="#map%d">' % ( map_dict['object'], m) )
      page.add( '<MAP name="map%d"> <P>' % m )
      n=0
      for px, py, link in zip( map_dict['xCoords'],
                               map_dict['yCoords'],
                               map_dict['links'] ):
        n+=1
        page.add( '<area href="%s" shape="circle" '
                  'coords="%d, %d, 5"> Point%d</a>' %
                  ( link, px, py, n) )
      page.add('</P></MAP></OBJECT><br>')
      page.add("<hr/>")

    # add some extra stuff if needed
    if comment:
      page.add("<div> "+comment+"</div>")
      page.hr()

    if coinc_summ_table:
      page.add(coinc_summ_table)
      page.hr()

    text = self.write_process_params()
    page.add(text)
    html_file.write(page(False))
    html_file.close()
示例#2
0
  def followup(self, inj, selectIFO, description = None):
    """
    Do the followup procedure for the missed injection 'inj'
    and create the several time-series for INSPIRAL and THINCA.
    The return value is the name of the created html file.
    @param inj: sim_inspiral table of the injection that needs to be
                followed up
    @param selectIFO: the IFO that is investigated
    @param description: Can be used to sieve further this pattern
                        from the description field.
    """
    
    def fill_table(page, contents ):
      """
      Making life easier...
      """
      page.add('<tr>')
      for content in contents:
        page.add('<td>')
        page.add( str(content) )
        page.add('</td>')
      page.add('</tr>')

   
    # get the ID corresponding to this injection
    injection_id = self.findInjection( inj )

    # increase internal number:
    self.number+=1

    ## create the web-page and add a table
    page = markup.page()
    page.h1("Followup missed injection #"+str(self.number)+" in "+selectIFO )
    page.hr()
    page.add('<table border="3" ><tr><td>')
    page.add('<table border="2" >')          
    fill_table( page, ['<b>parameter','<b>value'] )
    fill_table( page, ['Number', self.number] )
    fill_table( page, ['inj ID', injection_id] )
    fill_table( page, ['mass1', '%.2f'% inj.mass1] )
    fill_table( page, ['mass2', '%.2f'%inj.mass2] )
    fill_table( page, ['mtotal', '%.2f' % (inj.mass1+inj.mass2)] )
    fill_table( page, ['mchirp', '%.2f' % (inj.mchirp)] )
    fill_table( page, ['end_time', inj.geocent_end_time] )
    fill_table( page, ['end_time_ns', inj.geocent_end_time_ns] )    
    fill_table( page, ['distance', '%.1f' % inj.distance] )
    fill_table( page, ['eff_dist_h','%.1f' %  inj.eff_dist_h] )
    fill_table( page, ['eff_dist_l','%.1f' %  inj.eff_dist_l] )
    fill_table( page, ['eff_dist_v','%.1f' %  inj.eff_dist_v] )
    fill_table( page, ['eff_dist_g','%.1f' %  inj.eff_dist_g] )  
    fill_table( page, ['playground','%s' %  pipeline.s2play(inj.geocent_end_time)] )    
    page.add('</table></td>')
    
    # print infos to screen if required
    if self.opts.verbose:
      self.print_inj( inj,  injection_id)

    # sieve the cache for the required INSPIRAL and THINCA files
    invest_dict = {}
    for stage, cache in self.triggerCache.iteritems():

      trig_cache = lal.Cache()
      for c in cache:

        # check the time and the injection ID
        if inj.geocent_end_time in c.segment:
          if self.get_injection_id(url = c.url) == injection_id:
            trig_cache.append( c )

      # create a filelist
      file_list = trig_cache.sieve(description = description).pfnlist()
        
      # check if the pfnlist is empty. `
      if len(file_list)==0:
        print >>sys.stderr, "Error: No files found for stage %s in the "\
              "cache for ID %s and time %d; probably mismatch of a "\
              "pattern in the options. " % \
              ( stage, injection_id, inj.geocent_end_time)        
        continue

      # if the stage if THINCA_SECOND...
      if 'THINCA_SECOND' in stage:

        # ... need to loop over the four categories
        for cat in [1,2,3,4]:
          
          select_list=self.select_category( file_list, cat)
          if len(select_list)==0:
            print "WARNING: No THINCA_SECOND files found for category ", cat
            continue
          
          modstage = stage+'_CAT_' + str(cat)
          invest_dict[modstage] = self.investigateTimeseries( select_list, inj, selectIFO, modstage, self.number )

        #sys.exit(0)
      else:
        invest_dict[stage]=self.investigateTimeseries( file_list, inj, selectIFO, stage, self.number)

      
      
    ## print out the result for this particular injection
    page.add('<td><table border="2" >')
    fill_table( page, ['<b>step','<b>F/M', '<b>Rec. SNR', '<b>Rec. mchirp', \
                      '<b>Rec. eff_dist', '<b>Rec. chisq', '<b>Veto ON/OFF'] )

    # loop over the stages and create the table with
    # the various data in it (when available)
    for stage in self.orderLabels:
      if stage in invest_dict:
        result = invest_dict[stage]

        # Fill in the details of the loudest found coinc.
        #found_ifo=''
        #if "INSPIRAL" in stage or "THINCA" in stage:
        found_ifo=''
        loudest_snr=''
        loudest_mchirp=''
        loudest_eff_dist=''
        loudest_chisq=''
        veto_onoff=''

        # add all the IFO's for this coincident
        for ifo in result['foundset']:
          found_ifo += ifo+' '
          
          # Parameters of the loudest trigger, taken from the
          # 'loudest-details' dictionary, created in 'investigateTimeseries'
          loudest_snr += ifo + ': ' + str(result['loudest_details'][ifo]['snr'])+'<br>'
          loudest_mchirp += ifo + ': ' + str(result['loudest_details'][ifo]['mchirp'])+'<br>'
          loudest_eff_dist += ifo + ': ' + str(result['loudest_details'][ifo]['eff_dist'])+'<br>'
          loudest_chisq += ifo + ': ' + str(result['loudest_details'][ifo]['chisq'])+'<br>'
          
          # Check whether some of the ifo times is vetoed
          timeTrigger = float(result['loudest_details'][ifo]['timeTrigger'])
          if (self.vetodict[ifo]):
            veto = self.isThereVeto (timeTrigger, ifo)
            veto_txt = 'OFF'
            if veto:
              veto_txt = 'ON'              
            veto_onoff+=ifo+': '+veto_txt+'<br>'
          else: 
            veto_onoff+=ifo+': No info<br>'

        # Fill the table whether something is found or not
        if len(result['foundset'])>0:
          fill_table( page, [ stage,  'FOUND in '+found_ifo, 'loudest<br>'+loudest_snr, \
                              'loudest<br>'+loudest_mchirp, 'loudest<br>'+loudest_eff_dist,\
                              'loudest<br>'+loudest_chisq, veto_onoff])
        else:
          fill_table( page, [ stage,  '<font color="red">MISSED'])
          
    page.add('</table>')
    page.add('</td></tr></table><br><br>')


    ## add the pictures to the webpage
    for stage in self.orderLabels:
      if stage in invest_dict:
        result = invest_dict[stage]
      
        ##if stage!="TMPLTBANK":
        if True:
          fname = result['filename']
          page.a(extra.img(src=[fname], width=400, \
                           alt=fname, border="2"), title=fname, href=[ fname ])
          
    # add version information
    page.add('<hr>Page created with %s Version %s' % \
        (__prog__, git_version.verbose_msg))
    
    # and write the html file
    htmlfilename = self.opts.prefix + "_"+selectIFO+"_followup_"+str(self.number) +\
                         self.opts.suffix+'.html'
    file = open(self.opts.output_path+htmlfilename,'w')      
    file.write(page(False))
    file.close()

    # store html file in fnameList
    self.fnameList.append(htmlfilename)

    # supply the output
    return htmlfilename
    def write_html_output(self,
                          html_filename,
                          doThumb=True,
                          map_list=[],
                          comment=None,
                          coinc_summ_table=None):
        """
    @param doThumb: Uses the thumbnail file as the sourcs for the images
    @param map_list: A list of dictionaries to create the image maps
    @param comment: A comment that can be added to the page
    @param coinc_summ_table: A CoincSummTable that can be added to the page
    """

        # Initialise the html output file
        page = markup.page()
        try:
            page.init(title=__title__)
        except:
            page.init()

        page.h1(self.name + " results")

        page.p(self.prefix + self.suffix)
        page.hr()

        # open the output file
        html_file = file(html_filename, "w")

        # loop over the contents
        for tag, filename in zip(self.tag_list, self.fname_list):

            # set the correct name for linking (two '//' does not bother)
            fname = "Images/" + os.path.basename(filename)

            # set the thumbnail pictures if required
            if doThumb:
                fname_thumb = fname[:-4] + "_thumb.png"
            else:
                fname_thumb = fname

            # add the image to the page
            page.a(extra_oneliner.img(src=[fname_thumb],
                                      width=400,
                                      alt=tag,
                                      border="2"),
                   title=tag,
                   href=[fname])

        page.add("<hr/>")

        # add maps to this page
        m = 0
        for map_dict in map_list:
            m += 1
            page.add(map_dict['text'] + '<br>')
            page.add('<IMG src="%s" width=800px '
                     'usemap="#map%d">' % (map_dict['object'], m))
            page.add('<MAP name="map%d"> <P>' % m)
            n = 0
            for px, py, link in zip(map_dict['xCoords'], map_dict['yCoords'],
                                    map_dict['links']):
                n += 1
                page.add('<area href="%s" shape="circle" '
                         'coords="%d, %d, 5"> Point%d</a>' % (link, px, py, n))
            page.add('</P></MAP></OBJECT><br>')
            page.add("<hr/>")

        # add some extra stuff if needed
        if comment:
            page.add("<div> " + comment + "</div>")
            page.hr()

        if coinc_summ_table:
            page.add(coinc_summ_table)
            page.hr()

        text = self.write_process_params()
        page.add(text)
        html_file.write(page(False))
        html_file.close()
示例#4
0
  def followup(self, inj, selectIFO, description = None):
    """
    Do the followup procedure for the missed injection 'inj'
    and create the several time-series for INSPIRAL and THINCA.
    The return value is the name of the created html file.
    @param inj: sim_inspiral table of the injection that needs to be
                followed up
    @param selectIFO: the IFO that is investigated
    @param description: Can be used to sieve further this pattern
                        from the description field.
    """
    
    def fill_table(page, contents ):
      """
      Making life easier...
      """
      page.add('<tr>')
      for content in contents:
        page.add('<td>')
        page.add( str(content) )
        page.add('</td>')
      page.add('</tr>')

   
    # get the ID corresponding to this injection
    injection_id = self.findInjection( inj )

    # increase internal number:
    self.number+=1

    ## create the web-page and add a table
    page = markup.page()
    page.h1("Followup missed injection #"+str(self.number)+" in "+selectIFO )
    page.hr()
    page.add('<table border="3" ><tr><td>')
    page.add('<table border="2" >')          
    fill_table( page, ['<b>parameter','<b>value'] )
    fill_table( page, ['Number', self.number] )
    fill_table( page, ['inj ID', injection_id] )
    fill_table( page, ['mass1', '%.2f'% inj.mass1] )
    fill_table( page, ['mass2', '%.2f'%inj.mass2] )
    fill_table( page, ['mtotal', '%.2f' % (inj.mass1+inj.mass2)] )
    fill_table( page, ['mchirp', '%.2f' % (inj.mchirp)] )
    fill_table( page, ['end_time', inj.geocent_end_time] )
    fill_table( page, ['end_time_ns', inj.geocent_end_time_ns] )    
    fill_table( page, ['distance', '%.1f' % inj.distance] )
    fill_table( page, ['eff_dist_h','%.1f' %  inj.eff_dist_h] )
    fill_table( page, ['eff_dist_l','%.1f' %  inj.eff_dist_l] )
    fill_table( page, ['eff_dist_v','%.1f' %  inj.eff_dist_v] )
    fill_table( page, ['eff_dist_g','%.1f' %  inj.eff_dist_g] )  
    fill_table( page, ['playground','%s' %  pipeline.s2play(inj.geocent_end_time)] )    
    page.add('</table></td>')
    
    # print infos to screen if required
    if self.opts.verbose:
      self.print_inj( inj,  injection_id)

    # sieve the cache for the required INSPIRAL and THINCA files
    invest_dict = {}
    for stage, cache in self.triggerCache.iteritems():

      trig_cache = lal.Cache()
      for c in cache:

        # check the time and the injection ID
        if inj.geocent_end_time in c.segment:
          if self.get_injection_id(url = c.url) == injection_id:
            trig_cache.append( c )

      # create a filelist
      file_list = trig_cache.sieve(description = description).pfnlist()
        
      # check if the pfnlist is empty. `
      if len(file_list)==0:
        print >>sys.stderr, "Error: No files found for stage %s in the "\
              "cache for ID %s and time %d; probably mismatch of a "\
              "pattern in the options. " % \
              ( stage, injection_id, inj.geocent_end_time)        
        continue

      # if the stage if THINCA_SECOND...
      if 'THINCA_SECOND' in stage:

        # ... need to loop over the four categories
        for cat in [1,2,3,4]:
          
          select_list=self.select_category( file_list, cat)
          if len(select_list)==0:
            print "WARNING: No THINCA_SECOND files found for category ", cat
            continue
          
          modstage = stage+'_CAT_' + str(cat)
          invest_dict[modstage] = self.investigateTimeseries( select_list, inj, selectIFO, modstage, self.number )

        #sys.exit(0)
      else:
        invest_dict[stage]=self.investigateTimeseries( file_list, inj, selectIFO, stage, self.number)

      
      
    ## print out the result for this particular injection
    page.add('<td><table border="2" >')
    fill_table( page, ['<b>step','<b>F/M', '<b>Rec. SNR', '<b>Rec. mchirp', \
                      '<b>Rec. eff_dist', '<b>Rec. chisq', '<b>Veto ON/OFF'] )

    # loop over the stages and create the table with
    # the various data in it (when available)
    for stage in self.orderLabels:
      if stage in invest_dict:
        result = invest_dict[stage]

        # Fill in the details of the loudest found coinc.
        #found_ifo=''
        #if "INSPIRAL" in stage or "THINCA" in stage:
        found_ifo=''
        loudest_snr=''
        loudest_mchirp=''
        loudest_eff_dist=''
        loudest_chisq=''
        veto_onoff=''

        # add all the IFO's for this coincident
        for ifo in result['foundset']:
          found_ifo += ifo+' '
          
          # Parameters of the loudest trigger, taken from the
          # 'loudest-details' dictionary, created in 'investigateTimeseries'
          loudest_snr += ifo + ': ' + str(result['loudest_details'][ifo]['snr'])+'<br>'
          loudest_mchirp += ifo + ': ' + str(result['loudest_details'][ifo]['mchirp'])+'<br>'
          loudest_eff_dist += ifo + ': ' + str(result['loudest_details'][ifo]['eff_dist'])+'<br>'
          loudest_chisq += ifo + ': ' + str(result['loudest_details'][ifo]['chisq'])+'<br>'
          
          # Check whether some of the ifo times is vetoed
          timeTrigger = float(result['loudest_details'][ifo]['timeTrigger'])
          if (self.vetodict[ifo]):
            veto = self.isThereVeto (timeTrigger, ifo)
            veto_txt = 'OFF'
            if veto:
              veto_txt = 'ON'              
            veto_onoff+=ifo+': '+veto_txt+'<br>'
          else: 
            veto_onoff+=ifo+': No info<br>'

        # Fill the table whether something is found or not
        if len(result['foundset'])>0:
          fill_table( page, [ stage,  'FOUND in '+found_ifo, 'loudest<br>'+loudest_snr, \
                              'loudest<br>'+loudest_mchirp, 'loudest<br>'+loudest_eff_dist,\
                              'loudest<br>'+loudest_chisq, veto_onoff])
        else:
          fill_table( page, [ stage,  '<font color="red">MISSED'])
          
    page.add('</table>')
    page.add('</td></tr></table><br><br>')


    ## add the pictures to the webpage
    for stage in self.orderLabels:
      if stage in invest_dict:
        result = invest_dict[stage]
      
        ##if stage!="TMPLTBANK":
        if True:
          fname = result['filename']
          page.a(extra.img(src=[fname], width=400, \
                           alt=fname, border="2"), title=fname, href=[ fname ])
          
    # add version information
    page.add('<hr>Page created with %s Version %s' % \
        (__prog__, git_version.verbose_msg))
    
    # and write the html file
    htmlfilename = self.opts.prefix + "_"+selectIFO+"_followup_"+str(self.number) +\
                         self.opts.suffix+'.html'
    file = open(self.opts.output_path+htmlfilename,'w')      
    file.write(page(False))
    file.close()

    # store html file in fnameList
    self.fnameList.append(htmlfilename)

    # supply the output
    return htmlfilename