Beispiel #1
0
	def __init__(self, detection_threshold, cal_uncertainty, filter_width, open_box):
		self.detection_threshold = detection_threshold
		self.cal_uncertainty = cal_uncertainty
		self.filter_width = filter_width
		self.seglists = segments.segmentlistdict()
		self.vetoseglists = segments.segmentlistdict()
		self.found = []
		self.n_diagnostics = 100	# keep 100 loudest missed and quietest found injections
		self.loudest_missed = []
		self.quietest_found = []
		self.all = []
		self.open_box = open_box
Beispiel #2
0
	def __init__(self, detection_threshold, cal_uncertainty, filter_width, open_box):
		self.detection_threshold = detection_threshold
		self.cal_uncertainty = cal_uncertainty
		self.filter_width = filter_width
		self.seglists = segments.segmentlistdict()
		self.vetoseglists = segments.segmentlistdict()
		self.found = []
		self.n_diagnostics = 100	# keep 100 loudest missed and quietest found injections
		self.loudest_missed = []
		self.quietest_found = []
		self.all = []
		self.open_box = open_box
def get_single_ifo_segments(connection, program_name="inspiral", usertag=None):
    """
	Return a glue.segments.segmentlistdict object containing coalesced single-ifo
	segments obtained from the search_summary table.

	@param connection: sqlite connection for the input database
	@param usertag: the usertag for the desired filter jobs e.g. ("FULL_DATA","PLAYGROUND")
	"""

    xmldoc = dbtables.get_xml(connection)
    seglist_dict = segments.segmentlistdict()
    # extract segments indexed by available instrument
    for row in map(
        dbtables.table.get_table(xmldoc, lsctables.SearchSummaryTable.tableName).row_from_cols,
        connection.cursor().execute(
            """
			SELECT search_summary.*
			FROM search_summary
				JOIN process_params ON (
					process_params.process_id == search_summary.process_id)
			WHERE
				process_params.value == :1
				AND process_params.program == :2
		""",
            (usertag, program_name),
        ),
    ):

        instrument = row.get_ifos().pop()
        if usertag == "FULL_DATA" or usertag == "PLAYGROUND":
            try:
                seglist_dict[instrument].append(row.get_out())
            except KeyError:
                seglist_dict[instrument] = [row.get_out()]
        else:
            buffer_time = 72
            filtered_segment = segments.segment(row.get_in()[0] + buffer_time, row.get_in()[1] - buffer_time)
            try:
                seglist_dict[instrument].append(filtered_segment)
            except KeyError:
                seglist_dict[instrument] = [filtered_segment]

    xmldoc.unlink()

    seglist_dict = segments.segmentlistdict(
        (key, segments.segmentlist(sorted(set(value)))) for key, value in seglist_dict.items()
    )
    return seglist_dict
Beispiel #4
0
def get_coinc_segments(segments_dict, offset_vect):
	"""
	Return the exclusive coinc segments for each (time-slide,on instruments) pair for
	time-slides done along a line (as opposed to rings).

	@param segments_dict: the glue.segments.segmentlistdict object which contains the 
		single-ifo segments used to compute experiment durations
	@param offset_vect: the glue.offsetvector object that contains the time shifts
		for a given time-slide. The keys are the set of ifos being shifted. 
	"""
	segments_dict.coalesce()
	on_ifos_dict, excluded_ifos_dict = get_allifo_combos(segments_dict, 2)
	# the keys for the coinc-segs dictionaries are the TS-ids & ifo-combos
	coinc_segs = segments.segmentlistdict()

	# shift the segment times according to the values in the offset vector
	for ifo, shift in offset_vect.items():
		segments_dict.offsets[ifo] = shift

	for on_ifos_key, combo in on_ifos_dict.items():
		# determine inclusive coincident segments for each time_slide
		coinc_segs[on_ifos_key] = segments_dict.intersection( combo )
		
		# get lists of excluded ifos and associated keys for this coinc-time type
		excluded_ifos = excluded_ifos_dict[on_ifos_key]
		if excluded_ifos:
			# Make exclusive segments
			coinc_segs[on_ifos_key] -= segments_dict.union( excluded_ifos )

		coinc_segs[on_ifos_key].coalesce()

	return coinc_segs
 def get_veto_segments(self, connection):
     if self.coinc_inspiral_table:
         if self.opts.veto_segments_name is not None:
             return db_thinca_rings.get_veto_segments(connection, opts.self.veto_segments_name)
         # FIXME BURST CASE VETOS NOT HANDLED
     else:
         return segments.segmentlistdict()
Beispiel #6
0
def parse_config_file(options):
    if options.verbose:
        print >> sys.stderr, "reading %s ..." % options.config_file
    config = ConfigParser.SafeConfigParser()
    config.read(options.config_file)

    options.tag = config.get("pipeline", "user_tag")
    options.enable_clustering = config.getboolean("pipeline",
                                                  "enable_clustering")

    seglistdict = segments.segmentlistdict()
    tiling_phase = {}
    for ifo in config.get("pipeline", "ifos").split():
        seglistdict[ifo] = segmentsUtils.fromsegwizard(
            file(config.get("pipeline", "seglist_%s" % ifo)),
            coltype=LIGOTimeGPS).coalesce()
        try:
            offset = config.getfloat("pipeline", "tiling_phase_%s" % ifo)
        except ConfigParser.NoOptionError:
            offset = 0.0
        if offset:
            tiling_phase[ifo] = offset

    options.psds_per_power = config.getint("pipeline", "psds_per_power")
    options.psds_per_injection = config.getint("pipeline",
                                               "psds_per_injection")
    options.timing_params = power.TimingParameters(config)

    return seglistdict, tiling_phase, config
Beispiel #7
0
	def get_by_name(self, name, clip_to_valid = False):
		"""
		Retrieve the active segmentlists whose name equals name.
		The result is a segmentlistdict indexed by instrument.  All
		segmentlist objects within it will be copies of the
		contents of this object, modifications will not affect the
		contents of this object.  If clip_to_valid is True then the
		segmentlists will be intersected with their respective
		intervals of validity, otherwise they will be the verbatim
		active segments.

		NOTE:  the intersection operation required by clip_to_valid
		will yield undefined results unless the active and valid
		segmentlist objects are coalesced.
		"""
		result = segments.segmentlistdict()
		for seglist in self:
			if seglist.name != name:
				continue
			segs = seglist.active
			if clip_to_valid:
				# do not use in-place intersection
				segs = segs & seglist.valid
			for instrument in seglist.instruments:
				if instrument in result:
					raise ValueError("multiple '%s' segmentlists for instrument '%s'" % (name, instrument))
				result[instrument] = segments.segmentlist(segs)
		if not result:
			raise KeyError("no segmentlists named '%s'" % name)
		return result
def fromsegmentxml(file, dict=False, id=None):
    """
    Read a glue.segments.segmentlist from the file object file containing an
    xml segment table.

    Arguments:

      file : file object
        file object for segment xml file

    Keyword Arguments:

      dict : [ True | False ]
        returns a glue.segments.segmentlistdict containing coalesced
        glue.segments.segmentlists keyed by seg_def.name for each entry in the
        contained segment_def_table. Default False
      id : int
        returns a glue.segments.segmentlist object containing only those
        segments matching the given segment_def_id integer
        
  """

    # load xmldocument and SegmentDefTable and SegmentTables
    xmldoc, digest = utils.load_fileobj(file,
                                        gz=file.name.endswith(".gz"),
                                        contenthandler=lsctables.use_in(
                                            ligolw.LIGOLWContentHandler))
    seg_def_table = lsctables.SegmentDefTable.get_table(xmldoc)
    seg_table = lsctables.SegmentTable.get_table(xmldoc)

    if dict:
        segs = segments.segmentlistdict()
    else:
        segs = segments.segmentlist()

    seg_id = {}
    for seg_def in seg_def_table:
        seg_id[int(seg_def.segment_def_id)] = str(seg_def.name)
        if dict:
            segs[str(seg_def.name)] = segments.segmentlist()

    for seg in seg_table:
        if dict:
            segs[seg_id[int(seg.segment_def_id)]]\
                .append(segments.segment(seg.start_time, seg.end_time))
            continue
        if id and int(seg.segment_def_id) == id:
            segs.append(segments.segment(seg.start_time, seg.end_time))
            continue
        segs.append(segments.segment(seg.start_time, seg.end_time))

    if dict:
        for seg_name in seg_id.values():
            segs[seg_name] = segs[seg_name].coalesce()
    else:
        segs = segs.coalesce()

    xmldoc.unlink()

    return segs
def parse_config_file(options):
	if options.verbose:
		print >>sys.stderr, "reading %s ..." % options.config_file
	config = ConfigParser.SafeConfigParser()
	config.read(options.config_file)

	options.tag = config.get("pipeline", "user_tag")
	options.enable_clustering = config.getboolean("pipeline", "enable_clustering")

	seglistdict = segments.segmentlistdict()
	tiling_phase = {}
	for ifo in config.get("pipeline", "ifos").split():
		seglistdict[ifo] = segmentsUtils.fromsegwizard(file(config.get("pipeline", "seglist_%s" % ifo)), coltype = LIGOTimeGPS).coalesce()
		try:
			offset = config.getfloat("pipeline", "tiling_phase_%s" % ifo)
		except ConfigParser.NoOptionError:
			offset = 0.0
		if offset:
			tiling_phase[ifo] = offset

	options.psds_per_power = config.getint("pipeline", "psds_per_power")
	options.psds_per_injection = config.getint("pipeline", "psds_per_injection")
	options.timing_params = power.TimingParameters(config)

	return seglistdict, tiling_phase, config
def segmentlistdict_from_short_string(s, boundtype=int):
    """
	Parse a string representation of a set of named segmentlists into a
	segmentlistdict object.  The string encoding is that generated by
	segmentlistdict_to_short_string().  The optional boundtype argument
	will be passed to from_range_strings() when parsing the segmentlist
	objects from the string.

	Example:

	>>> segmentlistdict_from_short_string("H1=0:10,35,100:/L1=5:15,45:60")
	{'H1': [segment(0, 10), segment(35, 35), segment(100, infinity)], 'L1': [segment(5, 15), segment(45, 60)]}

	This function, and its inverse segmentlistdict_to_short_string(),
	are intended to be used to allow small segmentlistdict objects to
	be encoded in command line options and config files.  For large
	segmentlistdict objects or when multiple sets of segmentlists are
	required, the LIGO Light Weight XML encoding available through the
	glue.ligolw library should be used.
	"""
    d = segments.segmentlistdict()
    for token in s.strip().split("/"):
        key, ranges = token.strip().split("=")
        d[key.strip()] = from_range_strings(ranges.strip().split(","),
                                            boundtype=boundtype)
    return d
Beispiel #11
0
def segmentlistdict_from_short_string(s, boundtype = int):
	"""
	Parse a string representation of a set of named segmentlists into a
	segmentlistdict object.  The string encoding is that generated by
	segmentlistdict_to_short_string().  The optional boundtype argument
	will be passed to from_range_strings() when parsing the segmentlist
	objects from the string.

	Example:

	>>> segmentlistdict_from_short_string("H1=0:10,35,100:/L1=5:15,45:60")
	{'H1': [segment(0, 10), segment(35, 35), segment(100, infinity)], 'L1': [segment(5, 15), segment(45, 60)]}

	This function, and its inverse segmentlistdict_to_short_string(),
	are intended to be used to allow small segmentlistdict objects to
	be encoded in command line options and config files.  For large
	segmentlistdict objects or when multiple sets of segmentlists are
	required, the LIGO Light Weight XML encoding available through the
	glue.ligolw library should be used.
	"""
	d = segments.segmentlistdict()
	for token in s.strip().split("/"):
		key, ranges = token.strip().split("=")
		d[key.strip()] = from_range_strings(ranges.strip().split(","), boundtype = boundtype)
	return d
Beispiel #12
0
	def get_by_name(self, name, clip_to_valid = False):
		"""
		Retrieve the active segmentlists whose name equals name.
		The result is a segmentlistdict indexed by instrument.  All
		segmentlist objects within it will be copies of the
		contents of this object, modifications will not affect the
		contents of this object.  If clip_to_valid is True then the
		segmentlists will be intersected with their respective
		intervals of validity, otherwise they will be the verbatim
		active segments.

		NOTE:  the intersection operation required by clip_to_valid
		will yield undefined results unless the active and valid
		segmentlist objects are coalesced.
		"""
		result = segments.segmentlistdict()
		for seglist in self:
			if seglist.name != name:
				continue
			segs = seglist.active
			if clip_to_valid:
				# do not use in-place intersection
				segs = segs & seglist.valid
			for instrument in seglist.instruments:
				if instrument in result:
					raise ValueError("multiple '%s' segmentlists for instrument '%s'" % (name, instrument))
				result[instrument] = segs.copy()
		return result
Beispiel #13
0
def make_cache_entry(input_cache, description, path):
	# summarize segment information
	seglists = segments.segmentlistdict()
	for c in input_cache:
		seglists |= c.segmentlistdict

	# obtain instrument list
	instruments = seglists.keys()
	if None in instruments:
		instruments.remove(None)
	instruments.sort()

	# remove empty segment lists to allow extent_all() to work
	for instrument in seglists.keys():
		if not seglists[instrument]:
			del seglists[instrument]

	# make the URL
	if path:
		url = "file://localhost%s" % os.path.abspath(path)
	else:
		url = None

	# construct a cache entry from the instruments and
	# segments that remain
	return CacheEntry("+".join(instruments) or None, description, seglists.extent_all(), url)
Beispiel #14
0
    def segmentlistdict(self):
        """
        A segmentlistdict object describing the instruments and time
        spanned by this CacheEntry.  A new object is constructed each time
        this attribute is accessed (segments are immutable so there is no
        reason to try to share a reference to the CacheEntry's internal
        segment; modifications of one would not be reflected in the other
        anyway).

        Example:

        >>> c = CacheEntry("H1 S5 815901601 576.5 file://localhost/home/kipp/tmp/1/H1-815901601-576.xml")
        >>> c.segmentlistdict['H1']
        [segment(LIGOTimeGPS(815901601, 0), LIGOTimeGPS(815902177, 500000000))]

        The \"observatory\" column of the cache entry, which is frequently
        used to store instrument names, is parsed into instrument names for
        the dictionary keys using the same rules as
        glue.ligolw.lsctables.instrument_set_from_ifos().

        Example:

        >>> c = CacheEntry("H1H2, S5 815901601 576.5 file://localhost/home/kipp/tmp/1/H1H2-815901601-576.xml")
        >>> c.segmentlistdict['H1H2']
        [segment(LIGOTimeGPS(815901601, 0), LIGOTimeGPS(815902177, 500000000))]
        """
        # the import has to be done here to break the cyclic
        # dependancy
        from glue.ligolw.lsctables import instrument_set_from_ifos
        instruments = instrument_set_from_ifos(self.observatory) or (None, )
        return segments.segmentlistdict(
            (instrument,
             segments.segmentlist(self.segment is not None and [self.segment]
                                  or [])) for instrument in instruments)
Beispiel #15
0
    def segmentlistdict(self):
        """
        A segmentlistdict object describing the instruments and time
        spanned by this CacheEntry.  A new object is constructed each time
        this attribute is accessed (segments are immutable so there is no
        reason to try to share a reference to the CacheEntry's internal
        segment; modifications of one would not be reflected in the other
        anyway).

        Example:

        >>> c = CacheEntry("H1 S5 815901601 576.5 file://localhost/home/kipp/tmp/1/H1-815901601-576.xml")
        >>> c.segmentlistdict['H1']
        [segment(LIGOTimeGPS(815901601, 0), LIGOTimeGPS(815902177, 500000000))]

        The \"observatory\" column of the cache entry, which is frequently
        used to store instrument names, is parsed into instrument names for
        the dictionary keys using the same rules as
        glue.ligolw.lsctables.instrumentsproperty.get().

        Example:

        >>> c = CacheEntry("H1H2, S5 815901601 576.5 file://localhost/home/kipp/tmp/1/H1H2-815901601-576.xml")
        >>> c.segmentlistdict['H1H2']
        [segment(LIGOTimeGPS(815901601, 0), LIGOTimeGPS(815902177, 500000000))]
        """
        # the import has to be done here to break the cyclic
        # dependancy
        from glue.ligolw.lsctables import instrumentsproperty
        instruments = instrumentsproperty.get(self.observatory) or (None,)
        return segments.segmentlistdict((instrument, segments.segmentlist(self.segment is not None and [self.segment] or [])) for instrument in instruments)
def make_cache_entry(input_cache, description, path):
	# summarize segment information
	seglists = segments.segmentlistdict()
	for c in input_cache:
		seglists |= c.segmentlistdict

	# obtain instrument list
	instruments = seglists.keys()
	if None in instruments:
		instruments.remove(None)
	instruments.sort()

	# remove empty segment lists to allow extent_all() to work
	for instrument in seglists.keys():
		if not seglists[instrument]:
			del seglists[instrument]

	# make the URL
	if path:
		url = "file://localhost%s" % os.path.abspath(path)
	else:
		# FIXME:  old version of CacheEntry allowed None for URL,
		# new version doesn't.  correct fix is to modify calling
		# code to not try to initialize the output cache until
		# after the input is known, but for now we'll just do this
		# stupid hack.
		url = "file://localhost/dev/null"

	# construct a cache entry from the instruments and
	# segments that remain
	return CacheEntry("+".join(instruments) or None, description, seglists.extent_all(), url)
Beispiel #17
0
def get_veto_segments(connection, program_name, xmldoc=None, veto_segments_name=None):
	veto_segments = segments.segmentlistdict()
	#FIXME only handles thinca case
	if not veto_segments_name: return veto_segments
	if program_name == "thinca": veto_segments = db_thinca_rings.get_veto_segments(connection, veto_segments_name)
	if program_name == "rinca": veto_segments = ligolw_segments.segmenttable_get_by_name(xmldoc, veto_segments_name).coalesce()
	return veto_segments
Beispiel #18
0
def get_segments(connection, xmldoc, program_name):
	seglists = segments.segmentlistdict()
	if program_name == "thinca":
		seglists = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name)
	if program_name == "gstlal_inspiral" or program_name == "lalapps_ring":
		seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, program_name).coalesce()
	return seglists
def get_coinc_segments(segments_dict, offset_vect):
    """
	Return the exclusive coinc segments for each (time-slide,on instruments) pair for
	time-slides done along a line (as opposed to rings).

	@param segments_dict: the glue.segments.segmentlistdict object which contains the 
		single-ifo segments used to compute experiment durations
	@param offset_vect: the glue.offsetvector object that contains the time shifts
		for a given time-slide. The keys are the set of ifos being shifted. 
	"""
    segments_dict.coalesce()
    on_ifos_dict, excluded_ifos_dict = get_allifo_combos(segments_dict, 2)
    # the keys for the coinc-segs dictionaries are the TS-ids & ifo-combos
    coinc_segs = segments.segmentlistdict()

    # shift the segment times according to the values in the offset vector
    for ifo, shift in offset_vect.items():
        segments_dict.offsets[ifo] = shift

    for on_ifos_key, combo in on_ifos_dict.items():
        # determine inclusive coincident segments for each time_slide
        coinc_segs[on_ifos_key] = segments_dict.intersection(combo)

        # get lists of excluded ifos and associated keys for this coinc-time type
        excluded_ifos = excluded_ifos_dict[on_ifos_key]
        if excluded_ifos:
            # Make exclusive segments
            coinc_segs[on_ifos_key] -= segments_dict.union(excluded_ifos)

        coinc_segs[on_ifos_key].coalesce()

    return coinc_segs
def get_single_ifo_segments(connection, program_name="inspiral", usertag=None):
    """
	Return a glue.segments.segmentlistdict object containing coalesced single-ifo
	segments obtained from the search_summary table.

	@param connection: sqlite connection for the input database
	@param usertag: the usertag for the desired filter jobs e.g. ("FULL_DATA","PLAYGROUND")
	"""

    xmldoc = dbtables.get_xml(connection)
    seglist_dict = segments.segmentlistdict()
    # extract segments indexed by available instrument
    for row in map(
            dbtables.table.get_table(
                xmldoc, lsctables.SearchSummaryTable.tableName).row_from_cols,
            connection.cursor().execute(
                """
			SELECT search_summary.*
			FROM search_summary
				JOIN process_params ON (
					process_params.process_id == search_summary.process_id)
			WHERE
				process_params.value == :1
				AND process_params.program == :2
		""", (usertag, program_name))):

        instrument = row.get_ifos().pop()
        if usertag == "FULL_DATA" or usertag == "PLAYGROUND":
            try:
                seglist_dict[instrument].append(row.get_out())
            except KeyError:
                seglist_dict[instrument] = [row.get_out()]
        else:
            buffer_time = 72
            filtered_segment = segments.segment(row.get_in()[0] + buffer_time,
                                                row.get_in()[1] - buffer_time)
            try:
                seglist_dict[instrument].append(filtered_segment)
            except KeyError:
                seglist_dict[instrument] = [filtered_segment]

    xmldoc.unlink()

    seglist_dict = segments.segmentlistdict(
        (key, segments.segmentlist(sorted(set(value))))
        for key, value in seglist_dict.items())
    return seglist_dict
def parse_command_line():
	parser = OptionParser(
		version="%prog CVS $Id$"
	)
	parser.add_option("-s", "--data-start", metavar = "GPSSECONDS", help = "set data segment start time")
	parser.add_option("-e", "--data-end", metavar = "GPSSECONDS", help = "set data segment end time")
	parser.add_option("-a", "--trig-start", metavar = "GPSSECONDS", help = "set analysis segment start time")
	parser.add_option("-b", "--trig-end", metavar = "GPSSECONDS", help = "set analysis segment end time")
	parser.add_option("-f", "--dag-name", metavar = "FILENAME", help = "set output .dag file name")
	parser.add_option("-t", "--aux-dir", metavar = "PATH", help = "set auxiliary data directory")
	parser.add_option("--condor-log-dir", metavar = "PATH", help = "set directory for Condor log")
	parser.add_option("--config-file", metavar = "FILENAME", default = "online_power.ini", help = "set .ini config file name")
	parser.add_option("--instrument", metavar = "INSTRUMENT", help = "set instrument name (default = value of instrument variable in [pipeline] section of .ini file)")
	parser.add_option("--publish-dest", metavar = "PATH", help = "set directory for output triggers")
	parser.add_option("--dmtmon-dest", metavar = "PATH", help = "set directory for DMT monitor output")
	parser.add_option("--gsiscp-dest", metavar = "PATH", help = "set destination for gsiscp")
	parser.add_option("--user-tag", metavar = "TAG", help = "set user tag on jobs that need it")

	options, extra_args = parser.parse_args()

	# data segment
	options.data_seg = segments.segment(lal.LIGOTimeGPS(options.data_start), lal.LIGOTimeGPS(options.data_end))
	try:
		options.data_seglists = segments.segmentlistdict({options.instrument: segments.segmentlist([options.data_seg])})
	except:
		raise ValueError, "failure parsing -s and/or -e; try --help"

	# trigger segment
	options.trig_seg = segments.segment(lal.LIGOTimeGPS(options.trig_start), lal.LIGOTimeGPS(options.trig_end))
	try:
		options.trig_seglists = segments.segmentlistdict({options.instrument: segments.segmentlist([options.trig_seg])})
	except:
		raise ValueError, "failure parsing -a and/or -b; try --help"
	if True in map(bool, (options.trig_seglists - options.data_seglists).itervalues()):
		raise ValueError, "trigger segment not contained in data segment!"

	# .dag name
	try:
		options.dag_name = os.path.splitext(options.dag_name)[0]
	except:
		raise ValueError, "failure parsing -f; try --help"

	# config file
	options.config_file = os.path.join(options.aux_dir, options.config_file)

	return options
 def get_veto_segments(self, connection):
     if self.coinc_inspiral_table:
         if self.opts.veto_segments_name is not None:
             return db_thinca_rings.get_veto_segments(
                 connection, opts.self.veto_segments_name)
     # FIXME BURST CASE VETOS NOT HANDLED
     else:
         return segments.segmentlistdict()
	def __init__(self, x_instrument, y_instrument):
		self.fig, self.axes = SnglBurstUtils.make_burst_plot("%s Offset (s)" % x_instrument, "%s Offset (s)" % y_instrument)
		self.fig.set_size_inches(6,6)
		self.x_instrument = x_instrument
		self.y_instrument = y_instrument
		self.tisi_rows = None
		self.seglists = segments.segmentlistdict()
		self.counts = None
Beispiel #24
0
def fromsegmentxml(file, dict=False, id=None):

  """
    Read a glue.segments.segmentlist from the file object file containing an
    xml segment table.

    Arguments:

      file : file object
        file object for segment xml file

    Keyword Arguments:

      dict : [ True | False ]
        returns a glue.segments.segmentlistdict containing coalesced
        glue.segments.segmentlists keyed by seg_def.name for each entry in the
        contained segment_def_table. Default False
      id : int
        returns a glue.segments.segmentlist object containing only those
        segments matching the given segment_def_id integer
        
  """

  # load xmldocument and SegmentDefTable and SegmentTables
  xmldoc, digest = utils.load_fileobj(file, gz=file.name.endswith(".gz"))
  seg_def_table  = table.get_table(xmldoc, lsctables.SegmentDefTable.tableName)
  seg_table      = table.get_table(xmldoc, lsctables.SegmentTable.tableName)

  if dict:
    segs = segments.segmentlistdict()
  else:
    segs = segments.segmentlist()

  seg_id = {}
  for seg_def in seg_def_table:
    seg_id[int(seg_def.segment_def_id)] = str(seg_def.name)
    if dict:
      segs[str(seg_def.name)] = segments.segmentlist()

  for seg in seg_table:
    if dict:
      segs[seg_id[int(seg.segment_def_id)]]\
          .append(segments.segment(seg.start_time, seg.end_time))
      continue
    if id and int(seg.segment_def_id)==id:
      segs.append(segments.segment(seg.start_time, seg.end_time))
      continue
    segs.append(segments.segment(seg.start_time, seg.end_time))

  if dict:
   for seg_name in seg_id.values():
     segs[seg_name] = segs[seg_name].coalesce()
  else:
    segs = segs.coalesce()

  xmldoc.unlink()

  return segs
Beispiel #25
0
def get_thinca_rings_by_available_instruments(connection,
                                              program_name="thinca"):
    """
  Return the thinca rings from the database at the given connection.  The
  rings are returned as a glue.segments.segmentlistdict indexed by the
  set of instruments that were analyzed in that ring.

  Example:

  >>> seglists = get_thinca_rings_by_available_instruments(connection)
  >>> print seglists.keys()
  [frozenset(['H1', 'L1'])]
  """
    # extract raw rings indexed by available instrument set

    xmldoc = dbtables.get_xml(connection)
    seglists = segments.segmentlistdict()
    for row in map(
            dbtables.table.get_table(
                xmldoc, lsctables.SearchSummaryTable.tableName).row_from_cols,
            connection.cursor().execute(
                """
SELECT
  search_summary.*
FROM
  search_summary
  JOIN process ON (
    process.process_id == search_summary.process_id
  )
WHERE
  process.program == ?
  """, (program_name, ))):
        available_instruments = frozenset(row.get_ifos())
        try:
            seglists[available_instruments].append(row.get_out())
        except KeyError:
            seglists[available_instruments] = [row.get_out()]
    xmldoc.unlink()

    # remove rings that are exact duplicates on the assumption that there are
    # zero-lag and time-slide thinca jobs represented in the same document

    return segments.segmentlistdict(
        (key, segments.segmentlist(sorted(set(value))))
        for key, value in seglists.items())
Beispiel #26
0
def get_segments(connection,
                 xmldoc,
                 table_name,
                 live_time_program,
                 veto_segments_name=None,
                 data_segments_name="datasegments"):
    segs = segments.segmentlistdict()

    if table_name == dbtables.lsctables.CoincInspiralTable.tableName:
        if live_time_program == "gstlal_inspiral":
            segs = ligolw_segments.segmenttable_get_by_name(
                xmldoc, data_segments_name).coalesce()
            segs &= ligolw_search_summary.segmentlistdict_fromsearchsummary(
                xmldoc, live_time_program).coalesce()
        elif live_time_program == "thinca":
            segs = db_thinca_rings.get_thinca_zero_lag_segments(
                connection, program_name=live_time_program).coalesce()
        else:
            raise ValueError(
                "for burst tables livetime program must be one of gstlal_inspiral, thinca"
            )
        if veto_segments_name is not None:
            veto_segs = db_thinca_rings.get_veto_segments(
                connection, veto_segments_name)
            segs -= veto_segs
        return segs
    elif table_name == dbtables.lsctables.CoincRingdownTable.tableName:
        segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(
            xmldoc, live_time_program).coalesce()
        if veto_segments_name is not None:
            veto_segs = ligolw_segments.segmenttable_get_by_name(
                xmldoc, veto_segments_name).coalesce()
            segs -= veto_segs
        return segs
    elif table_name == dbtables.lsctables.MultiBurstTable.tableName:
        if live_time_program == "omega_to_coinc":
            segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(
                xmldoc, live_time_program).coalesce()
            if veto_segments_name is not None:
                veto_segs = ligolw_segments.segmenttable_get_by_name(
                    xmldoc, veto_segments_name).coalesce()
                segs -= veto_segs
        elif live_time_program == "waveburst":
            segs = db_thinca_rings.get_thinca_zero_lag_segments(
                connection, program_name=live_time_program).coalesce()
            if veto_segments_name is not None:
                veto_segs = db_thinca_rings.get_veto_segments(
                    connection, veto_segments_name)
                segs -= veto_segs
        else:
            raise ValueError(
                "for burst tables livetime program must be one of omega_to_coinc, waveburst"
            )
        return segs
    else:
        raise ValueError("table must be in " +
                         " ".join(allowed_analysis_table_names()))
 def __init__(self, x_instrument, y_instrument):
     self.fig, self.axes = SnglBurstUtils.make_burst_plot(
         "%s Offset (s)" % x_instrument, "%s Offset (s)" % y_instrument)
     self.fig.set_size_inches(6, 6)
     self.x_instrument = x_instrument
     self.y_instrument = y_instrument
     self.tisi_rows = None
     self.seglists = segments.segmentlistdict()
     self.counts = None
Beispiel #28
0
def cache_to_seglistdict(cache):
	"""
	Construct a coalesced segmentlistdict object from a list of
	glue.lal.CacheEntry objects.
	"""
	s = segments.segmentlistdict()
	for c in cache:
		s |= c.segmentlistdict
	return s
Beispiel #29
0
def cache_to_seglistdict(cache):
    """
	Construct a coalesced segmentlistdict object from a list of
	glue.lal.CacheEntry objects.
	"""
    s = segments.segmentlistdict()
    for c in cache:
        s |= c.segmentlistdict
    return s
Beispiel #30
0
	def to_segmentlistdict(self):
		"""
		Return a segmentlistdict object describing the instruments
		and times spanned by the entries in this Cache.  The return
		value is coalesced.
		"""
		d = segments.segmentlistdict()
		for entry in self:
			d |= entry.segmentlistdict
		return d
Beispiel #31
0
    def to_segmentlistdict(self):
        """
		Return a segmentlistdict object describing the instruments
		and times spanned by the entries in this Cache.  The return
		value is coalesced.
		"""
        d = segments.segmentlistdict()
        for entry in self:
            d |= entry.segmentlistdict
        return d
def ligolw_bucut(xmldoc, options, burst_test_func, veto_segments = segments.segmentlistdict(), del_non_coincs = False, del_skipped_injections = False, program = None, verbose = False):
	contents = DocContents(xmldoc, program)

	process = append_process(xmldoc, options)

	apply_filters(contents, burst_test_func, veto_segments, del_non_coincs = del_non_coincs, del_skipped_injections = del_skipped_injections, verbose = verbose)

	ligolw_process.set_process_end_time(process)

	seg = contents.outsegs.extent_all()
	ligolw_search_summary.append_search_summary(xmldoc, process, inseg = seg, outseg = seg, nevents = len(contents.snglbursttable))

	return xmldoc
Beispiel #33
0
def segmenttable_get_by_name(xmldoc, name):
    """
	Retrieve the segmentlists whose name equals name.  The result is a
	segmentlistdict indexed by instrument.

	The output of this function is not coalesced, each segmentlist
	contains the segments as found in the segment table.

	NOTE:  this is a light-weight version of the .get_by_name() method
	of the LigolwSegments class intended for use when the full
	machinery of that class is not required.  Considerably less
	document validation and error checking is performed by this
	version.  Consider using that method instead if your application
	will be interfacing with the document via that class anyway.
	"""
    #
    # find required tables
    #

    def_table = lsctables.SegmentDefTable.get_table(xmldoc)
    seg_table = lsctables.SegmentTable.get_table(xmldoc)

    #
    # segment_def_id --> instrument names mapping but only for
    # segment_definer entries bearing the requested name
    #

    instrument_index = dict((row.segment_def_id, row.instruments)
                            for row in def_table if row.name == name)

    #
    # populate result segmentlistdict object from segment_def_map table
    # and index
    #

    instruments = set(instrument for instruments in instrument_index.values()
                      for instrument in instruments)
    result = segments.segmentlistdict(
        (instrument, segments.segmentlist()) for instrument in instruments)

    for row in seg_table:
        if row.segment_def_id in instrument_index:
            seg = row.segment
            for instrument in instrument_index[row.segment_def_id]:
                result[instrument].append(seg)

    #
    # done
    #

    return result
Beispiel #34
0
def get_thinca_rings_by_available_instruments(connection, program_name = "thinca"):
  """
  Return the thinca rings from the database at the given connection.  The
  rings are returned as a glue.segments.segmentlistdict indexed by the
  set of instruments that were analyzed in that ring.

  Example:

  >>> seglists = get_thinca_rings_by_available_instruments(connection)
  >>> print seglists.keys()
  [frozenset(['H1', 'L1'])]
  """
  # extract raw rings indexed by available instrument set

  xmldoc = dbtables.get_xml(connection)
  seglists = segments.segmentlistdict()
  for row in map(dbtables.table.get_table(xmldoc, lsctables.SearchSummaryTable.tableName).row_from_cols, connection.cursor().execute("""
SELECT
  search_summary.*
FROM
  search_summary
  JOIN process ON (
    process.process_id == search_summary.process_id
  )
WHERE
  process.program == ?
  """, (program_name,))):
    available_instruments = frozenset(row.get_ifos())
    try:
      seglists[available_instruments].append(row.get_out())
    except KeyError:
      seglists[available_instruments] = [row.get_out()]
  xmldoc.unlink()

  # remove rings that are exact duplicates on the assumption that there are
  # zero-lag and time-slide thinca jobs represented in the same document

  return segments.segmentlistdict((key, segments.segmentlist(sorted(set(value)))) for key, value in seglists.items())
Beispiel #35
0
    def __init__(self, ifo):

        # set a string to idenity IFO
        self.ifo = ifo

        # a dict that holds all excitation segments
        self.exc_dict = segments.segmentlistdict()

        # a dict that holds all segments from the segdb
        self.seg_dict = segments.segmentlistdict()

        # a dict that holds all segments from bitmasked channels
        self.bitmask_dict = segments.segmentlistdict()

        # GraceDB information about hardware injection
        self.gracedb_id = []
        self.gracedb_time = []

        # schedule information about hardware injection
        self.schedule_time = None
        self.schedule_type = None
        self.schedule_scale_factor = None
        self.schedule_prefix = None
Beispiel #36
0
    def __init__(self, ifo):

        # set a string to idenity IFO
        self.ifo = ifo

        # a dict that holds all excitation segments
        self.exc_dict = segments.segmentlistdict()

        # a dict that holds all segments from the segdb
        self.seg_dict = segments.segmentlistdict()

        # a dict that holds all segments from bitmasked channels
        self.bitmask_dict = segments.segmentlistdict()

        # GraceDB information about hardware injection
        self.gracedb_id = []
        self.gracedb_time = []

        # schedule information about hardware injection
        self.schedule_time = None
        self.schedule_type = None
        self.schedule_scale_factor = None
        self.schedule_prefix = None
Beispiel #37
0
def segmenttable_get_by_name(xmldoc, name):
	"""
	Retrieve the segmentlists whose name equals name.  The result is a
	segmentlistdict indexed by instrument.

	The output of this function is not coalesced, each segmentlist
	contains the segments as found in the segment table.

	NOTE:  this is a light-weight version of the .get_by_name() method
	of the LigolwSegments class intended for use when the full
	machinery of that class is not required.  Considerably less
	document validation and error checking is performed by this
	version.  Consider using that method instead if your application
	will be interfacing with the document via that class anyway.
	"""
	#
	# find required tables
	#

	def_table = lsctables.SegmentDefTable.get_table(xmldoc)
	seg_table = lsctables.SegmentTable.get_table(xmldoc)

	#
	# segment_def_id --> instrument names mapping but only for
	# segment_definer entries bearing the requested name
	#

	instrument_index = dict((row.segment_def_id, row.instruments) for row in def_table if row.name == name)

	#
	# populate result segmentlistdict object from segment_def_map table
	# and index
	#

	instruments = set(instrument for instruments in instrument_index.values() for instrument in instruments)
	result = segments.segmentlistdict((instrument, segments.segmentlist()) for instrument in instruments)

	for row in seg_table:
		if row.segment_def_id in instrument_index:
			seg = row.segment
			for instrument in instrument_index[row.segment_def_id]:
				result[instrument].append(seg)

	#
	# done
	#

	return result
def get_rinca_zero_lag_segments(connection, program_name="rinca"):
    """
  Return the rinca rings from the database at the given connection.  The
  rings are returned as a coalesced glue.segments.segmentlistdict indexed
  by instrument.

  Example:

  >>> seglists = get_rinca_zero_lag_segments(connection)
  >>> print seglists.keys()
  ['H1', 'L1']

  This function is most useful if only zero-lag segments are desired
  because it allows for more convenient manipulation of the segment lists
  using the methods in glue.segments.  If information about background
  segments or the original ring boundaries is desired the data returned by
  get_rinca_rings_by_available_instruments() is required.
  """
    # extract the raw rings indexed by instrument

    xmldoc = dbtables.get_xml(connection)
    seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(
        xmldoc, program_name)
    xmldoc.unlink()

    # remove rings that are exact duplicates on the assumption that there are
    # zero-lag and time-slide rinca jobs represented in the same document

    seglists = segments.segmentlistdict((key, segments.segmentlist(set(value)))
                                        for key, value in seglists.items())

    # coalesce the remaining segments making sure we don't loose livetime in
    # the process

    durations_before = abs(seglists)
    seglists.coalesce()
    if abs(seglists) != durations_before:
        raise ValueError, "detected overlapping rinca rings"

    # done

    return seglists
Beispiel #39
0
def segmenttable_get_by_name(xmldoc, name):
	"""
	Retrieve the segments whose name matches those given.  The result
	is a segmentlistdict indexed by instrument.

	The output of this function is not coalesced, each segmentlist
	contains the segments as found in the segment table.
	"""
	#
	# find required tables
	#

	def_table = lsctables.SegmentDefTable.get_table(xmldoc)
	seg_table = lsctables.SegmentTable.get_table(xmldoc)

	#
	# segment_def_id --> instrument names mapping but only for
	# segment_definer entries bearing the requested name
	#

	instrument_index = dict((row.segment_def_id, row.get_ifos()) for row in def_table if row.name == name)

	#
	# populate result segmentlistdict object from segment_def_map table
	# and index
	#

	instruments = set(instrument for instruments in instrument_index.values() for instrument in instruments)
	result = segments.segmentlistdict((instrument, segments.segmentlist()) for instrument in instruments)

	for row in seg_table:
		if row.segment_def_id in instrument_index:
			seg = row.get()
			for instrument in instrument_index[row.segment_def_id]:
				result[instrument].append(seg)

	#
	# done
	#

	return result
def extract_vetoes(veto_files, ifos):
    """Extracts vetoes from veto filelist"""

    # Initialize vetoe containers
    vetoes = segments.segmentlistdict()
    for ifo in ifos:
        vetoes[ifo] = segments.segmentlist()

    # Construct veto list from veto filelist
    if veto_files:
        for file in veto_files:
            ifo = os.path.basename(file)[:2]
            if ifo in ifos:
                # This returns a coalesced list of the vetoes
                tmp_veto_segs = dqSegmentUtils.fromsegmentxml(open(file, 'r'))
                for entry in tmp_veto_segs:
                    vetoes[ifo].append(entry)
    for ifo in ifos:
        vetoes[ifo].coalesce()

    return vetoes
def DQSegments(time, data, dq_key):
    """
    Returns a glue.segments.segmentlistdict of active segments for each bit
    in a dq_key.
  """

    segdict = segments.segmentlistdict()
    for key in dq_key:
        segdict[key] = segments.segmentlist()

    # convert DQ bits into segments
    for i in xrange(len(data)):
        binary = _bits(data[i], len(dq_key))
        seg = segments.segment(time[i], time[i] - 1)
        for j, key in enumerate(dq_key):
            if binary[j] == 1:
                segdict[key].append(seg)

    segdict = segdict.coalesce()

    return segdict
Beispiel #42
0
def get_thinca_zero_lag_segments(connection, program_name = "thinca"):
  """
  Return the thinca rings from the database at the given connection.  The
  rings are returned as a coalesced glue.segments.segmentlistdict indexed
  by instrument.

  Example:

  >>> seglists = get_thinca_zero_lag_segments(connection)
  >>> print seglists.keys()
  ['H1', 'L1']

  This function is most useful if only zero-lag segments are desired
  because it allows for more convenient manipulation of the segment lists
  using the methods in glue.segments.  If information about background
  segments or the original ring boundaries is desired the data returned by
  get_thinca_rings_by_available_instruments() is required.
  """
  # extract the raw rings indexed by instrument

  xmldoc = dbtables.get_xml(connection)
  seglists = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, program_name)
  xmldoc.unlink()

  # remove rings that are exact duplicates on the assumption that there are
  # zero-lag and time-slide thinca jobs represented in the same document

  seglists = segments.segmentlistdict((key, segments.segmentlist(set(value))) for key, value in seglists.items())

  # coalesce the remaining segments making sure we don't loose livetime in
  # the process

  durations_before = abs(seglists)
  seglists.coalesce()
  if abs(seglists) != durations_before:
    raise ValueError, "detected overlapping thinca rings"

  # done

  return seglists
def GetSegListFromSearchSummaries(fileList, verbose=False):
    """
  Read segment lists from search summary tables
  @param fileList: list of input files.
  """
    required_tables = [lsctables.SearchSummaryTable, lsctables.ProcessTable]

    segList = segments.segmentlistdict()
    for thisFile in fileList:
        doc = ReadTablesFromFiles([thisFile], required_tables, verbose)
        try:
            segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(doc)
        except:
            raise ValueError, "Cannot extract segments from the SearchSummaryTable of %s" % thisFile

        #Now add these segments to the existing list
        segList.extend(segs)

    for value in segList.values():
        value.sort()

    return segList
Beispiel #44
0
def DQSegments(time, data, dq_key):

  """
    Returns a glue.segments.segmentlistdict of active segments for each bit
    in a dq_key.
  """

  segdict = segments.segmentlistdict()
  for key in dq_key:
    segdict[key] = segments.segmentlist()

  # convert DQ bits into segments
  for i in xrange(len(data)):
    binary = _bits(data[i], len(dq_key))
    seg = segments.segment(time[i], time[i]-1)
    for j, key in enumerate(dq_key):
      if binary[j] == 1:
        segdict[key].append(seg)

  segdict = segdict.coalesce()

  return segdict
def GetSegListFromSearchSummaries(fileList, verbose=False):
  """
  Read segment lists from search summary tables
  @param fileList: list of input files.
  """
  required_tables = [lsctables.SearchSummaryTable, lsctables.ProcessTable]

  segList = segments.segmentlistdict()
  for thisFile in fileList:
    doc = ReadTablesFromFiles([thisFile], required_tables, verbose)
    try:
      segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(doc)
    except:
      raise ValueError, "Cannot extract segments from the SearchSummaryTable of %s" % thisFile

    #Now add these segments to the existing list
    segList.extend(segs)

  for value in segList.values():
    value.sort()

  return segList
Beispiel #46
0
def get_segments(connection, xmldoc, table_name, live_time_program, veto_segments_name = None, data_segments_name = "datasegments"):
	from pylal import db_thinca_rings
	segs = segments.segmentlistdict()

	if table_name == dbtables.lsctables.CoincInspiralTable.tableName:
		if live_time_program == "gstlal_inspiral":
			segs = ligolw_segments.segmenttable_get_by_name(xmldoc, data_segments_name).coalesce()
			segs &= ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, live_time_program).coalesce()
		elif live_time_program == "thinca":
			segs = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = live_time_program).coalesce()
		else:
			raise ValueError("for burst tables livetime program must be one of gstlal_inspiral, thinca")
		if veto_segments_name is not None:
			veto_segs = db_thinca_rings.get_veto_segments(connection, veto_segments_name)
			segs -= veto_segs
		return segs
	elif table_name == dbtables.lsctables.CoincRingdownTable.tableName:
		segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, live_time_program).coalesce()
		if veto_segments_name is not None:
			veto_segs = ligolw_segments.segmenttable_get_by_name(xmldoc, veto_segments_name).coalesce()
			segs -= veto_segs
		return segs
	elif table_name == dbtables.lsctables.MultiBurstTable.tableName:
		if live_time_program == "omega_to_coinc":
			segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(xmldoc, live_time_program).coalesce()
			if veto_segments_name is not None:
				veto_segs = ligolw_segments.segmenttable_get_by_name(xmldoc, veto_segments_name).coalesce()
				segs -= veto_segs
		elif live_time_program == "waveburst":
			segs = db_thinca_rings.get_thinca_zero_lag_segments(connection, program_name = live_time_program).coalesce()
			if veto_segments_name is not None:
				veto_segs = db_thinca_rings.get_veto_segments(connection, veto_segments_name)
				segs -= veto_segs
		else:
			raise ValueError("for burst tables livetime program must be one of omega_to_coinc, waveburst")
		return segs
	else:
		raise ValueError("table must be in " + " ".join(allowed_analysis_table_names()))
Beispiel #47
0
def write_round_xml(vetosegs, vetotrigs, winner, ifo, opts):
    """
	Write out the products from this round of hveto: veto segments and the vetoed triggers.
	"""
    # Create a new document
    xmldoc = ligolw.Document()
    xmldoc.appendChild(ligolw.LIGO_LW())

    # Append the process information
    procrow = utils.process.append_process(xmldoc, program="laldetchar-hveto")
    utils.process.append_process_params(xmldoc, procrow, utils.process.process_params_from_dict(opts))

    # Add the vetoed triggers
    xmldoc.childNodes[0].childNodes.append(vetotrigs)

    # Append the veto segments
    segl = segmentlistdict()
    segl[ifo] = vetosegs
    lwsegs = ligolw_segments.LigolwSegments(xmldoc)
    lwsegs.insert_from_segmentlistdict(segl, "hveto")
    lwsegs.finalize(procrow)

    return xmldoc
Beispiel #48
0
def write_round_xml(vetosegs, vetotrigs, winner, ifo, opts):
    """
	Write out the products from this round of hveto: veto segments and the vetoed triggers.
	"""
    # Create a new document
    xmldoc = ligolw.Document()
    xmldoc.appendChild(ligolw.LIGO_LW())

    # Append the process information
    procrow = utils.process.append_process(xmldoc, program="laldetchar-hveto")
    utils.process.append_process_params(
        xmldoc, procrow, utils.process.process_params_from_dict(opts))

    # Add the vetoed triggers
    xmldoc.childNodes[0].childNodes.append(vetotrigs)

    # Append the veto segments
    segl = segmentlistdict()
    segl[ifo] = vetosegs
    lwsegs = ligolw_segments.LigolwSegments(xmldoc)
    lwsegs.insert_from_segmentlistdict(segl, "hveto")
    lwsegs.finalize(procrow)

    return xmldoc
def tosegmentlistdict(timeseries, bitmask):
    """
    Returns a glue.segments.segmentlistdict of active segments for each bit
    in a bit-masked state vector TimeSeries.
    """

    bits, flags = zip(*sorted(bitmask.items(), key=lambda (k, v): k))

    segdict = segments.segmentlistdict()
    for flag in flags:
        segdict[flag] = segments.segmentlist()

    # convert DQ bits into segments
    tarray = arange(timeseries.data.length) * float(timeseries.deltaT) +\
             float(timeseries.epoch)
    for t, d in zip(tarray.astype(float), timeseries.data.data):
        binary = _bits(d, bits[-1] + 1)
        seg = segments.segment(t, t - timeseries.deltaT)
        for bit, flag in zip(bits, flags):
            if binary[bit] == 1:
                segdict[flag].append(seg)

    segdict.coalesce()
    return segdict
Beispiel #50
0
def multi_ifo_compute_offsource_segment(analyzable_dict, on_source, **kwargs):
    """
    Return the off-source segment determined for multiple IFO times along with
    the IFO combo that determined that segment.  Calls
    compute_offsource_segment as necessary, passing all kwargs as necessary.
    """
    # sieve down to relevant segments and IFOs; sort IFOs by sensitivity
    new_analyzable_dict = segments.segmentlistdict()
    for ifo, seglist in analyzable_dict.iteritems():
        try:
            ind = seglist.find(on_source)
        except ValueError:
            continue
        new_analyzable_dict[ifo] = segments.segmentlist([seglist[ind]])
    analyzable_ifos = new_analyzable_dict.keys()
    analyzable_ifos.sort(sensitivity_cmp)

    # now try getting off-source segments; start trying with all IFOs, then
    # work our way to smaller and smaller subsets; exclude single IFOs.    
    test_combos = itertools.chain( \
      *itertools.imap(lambda n: iterutils.choices(analyzable_ifos, n),
                      xrange(len(analyzable_ifos), 1, -1)))

    off_source_segment = None
    the_ifo_combo = []
    for ifo_combo in test_combos:
      trial_seglist = new_analyzable_dict.intersection(ifo_combo)
      temp_segment = compute_offsource_segment(trial_seglist, on_source,
                                               **kwargs)
      if temp_segment is not None:
        off_source_segment = temp_segment
        the_ifo_combo = list(ifo_combo)
        the_ifo_combo.sort()
        break
    
    return off_source_segment, the_ifo_combo
Beispiel #51
0
def multi_ifo_compute_offsource_segment(analyzable_dict, on_source, **kwargs):
    """
    Return the off-source segment determined for multiple IFO times along with
    the IFO combo that determined that segment.  Calls
    compute_offsource_segment as necessary, passing all kwargs as necessary.
    """
    # sieve down to relevant segments and IFOs; sort IFOs by sensitivity
    new_analyzable_dict = segments.segmentlistdict()
    for ifo, seglist in analyzable_dict.iteritems():
        try:
            ind = seglist.find(on_source)
        except ValueError:
            continue
        new_analyzable_dict[ifo] = segments.segmentlist([seglist[ind]])
    analyzable_ifos = new_analyzable_dict.keys()
    analyzable_ifos.sort(sensitivity_cmp)

    # now try getting off-source segments; start trying with all IFOs, then
    # work our way to smaller and smaller subsets; exclude single IFOs.
    test_combos = itertools.chain( \
      *itertools.imap(lambda n: iterutils.choices(analyzable_ifos, n),
                      xrange(len(analyzable_ifos), 1, -1)))

    off_source_segment = None
    the_ifo_combo = []
    for ifo_combo in test_combos:
        trial_seglist = new_analyzable_dict.intersection(ifo_combo)
        temp_segment = compute_offsource_segment(trial_seglist, on_source,
                                                 **kwargs)
        if temp_segment is not None:
            off_source_segment = temp_segment
            the_ifo_combo = list(ifo_combo)
            the_ifo_combo.sort()
            break

    return off_source_segment, the_ifo_combo

power.init_job_types(config_parser)


#
# Using time slide information, construct segment lists describing times
# requiring trigger construction.
#


if options.verbose:
	print >>sys.stderr, "Computing segments for which lalapps_power jobs are required ..."

background_time_slides = {}
background_seglistdict = segments.segmentlistdict()
if options.do_noninjections:
	for filename in options.background_time_slides:
		cache_entry = CacheEntry(None, None, None, "file://localhost" + os.path.abspath(filename))
		background_time_slides[cache_entry] = timeslides.load_time_slides(filename, verbose = options.verbose, gz = filename.endswith(".gz")).values()
		background_seglistdict |= compute_segment_lists(seglistdict, background_time_slides[cache_entry], options.minimum_gap, options.timing_params, full_segments = options.full_segments, verbose = options.verbose)


injection_time_slides = {}
injection_seglistdict = segments.segmentlistdict()
if options.do_injections:
	for filename in options.injection_time_slides:
		cache_entry = CacheEntry(None, None, None, "file://localhost" + os.path.abspath(filename))
		injection_time_slides[cache_entry] = timeslides.load_time_slides(filename, verbose = options.verbose, gz = filename.endswith(".gz")).values()
		injection_seglistdict |= compute_segment_lists(seglistdict, injection_time_slides[cache_entry], options.minimum_gap, options.timing_params, full_segments = options.full_segments, verbose = options.verbose)
Beispiel #53
0
#
# Define .sub files
#

power.init_job_types(config_parser)

#
# Using time slide information, construct segment lists describing times
# requiring trigger construction.
#

if options.verbose:
    print >> sys.stderr, "Computing segments for which lalapps_power jobs are required ..."

background_time_slides = {}
background_seglistdict = segments.segmentlistdict()
if options.do_noninjections:
    for filename in options.background_time_slides:
        cache_entry = CacheEntry(
            None, None, None, "file://localhost" + os.path.abspath(filename))
        background_time_slides[cache_entry] = timeslides.load_time_slides(
            filename, verbose=options.verbose,
            gz=filename.endswith(".gz")).values()
        background_seglistdict |= compute_segment_lists(
            seglistdict,
            background_time_slides[cache_entry],
            options.minimum_gap,
            options.timing_params,
            full_segments=options.full_segments,
            verbose=options.verbose)
Beispiel #54
0
def parse_command_line():
    parser = OptionParser(version="%prog CVS $Id$")
    parser.add_option("-s",
                      "--data-start",
                      metavar="GPSSECONDS",
                      help="set data segment start time")
    parser.add_option("-e",
                      "--data-end",
                      metavar="GPSSECONDS",
                      help="set data segment end time")
    parser.add_option("-a",
                      "--trig-start",
                      metavar="GPSSECONDS",
                      help="set analysis segment start time")
    parser.add_option("-b",
                      "--trig-end",
                      metavar="GPSSECONDS",
                      help="set analysis segment end time")
    parser.add_option("-f",
                      "--dag-name",
                      metavar="FILENAME",
                      help="set output .dag file name")
    parser.add_option("-t",
                      "--aux-dir",
                      metavar="PATH",
                      help="set auxiliary data directory")
    parser.add_option("--condor-log-dir",
                      metavar="PATH",
                      help="set directory for Condor log")
    parser.add_option("--config-file",
                      metavar="FILENAME",
                      default="online_power.ini",
                      help="set .ini config file name")
    parser.add_option(
        "--instrument",
        metavar="INSTRUMENT",
        help=
        "set instrument name (default = value of instrument variable in [pipeline] section of .ini file)"
    )
    parser.add_option("--publish-dest",
                      metavar="PATH",
                      help="set directory for output triggers")
    parser.add_option("--dmtmon-dest",
                      metavar="PATH",
                      help="set directory for DMT monitor output")
    parser.add_option("--gsiscp-dest",
                      metavar="PATH",
                      help="set destination for gsiscp")
    parser.add_option("--user-tag",
                      metavar="TAG",
                      help="set user tag on jobs that need it")

    options, extra_args = parser.parse_args()

    # data segment
    options.data_seg = segments.segment(lal.LIGOTimeGPS(options.data_start),
                                        lal.LIGOTimeGPS(options.data_end))
    try:
        options.data_seglists = segments.segmentlistdict(
            {options.instrument: segments.segmentlist([options.data_seg])})
    except:
        raise ValueError, "failure parsing -s and/or -e; try --help"

    # trigger segment
    options.trig_seg = segments.segment(lal.LIGOTimeGPS(options.trig_start),
                                        lal.LIGOTimeGPS(options.trig_end))
    try:
        options.trig_seglists = segments.segmentlistdict(
            {options.instrument: segments.segmentlist([options.trig_seg])})
    except:
        raise ValueError, "failure parsing -a and/or -b; try --help"
    if True in map(bool, (options.trig_seglists -
                          options.data_seglists).itervalues()):
        raise ValueError, "trigger segment not contained in data segment!"

    # .dag name
    try:
        options.dag_name = os.path.splitext(options.dag_name)[0]
    except:
        raise ValueError, "failure parsing -f; try --help"

    # config file
    options.config_file = os.path.join(options.aux_dir, options.config_file)

    return options
    def __init__(self, opts, flist):
        self.segments = segments.segmentlistdict()
        self.non_inj_fnames = []
        self.inj_fnames = []
        self.found = {}
        self.missed = {}
        self.opts = opts
        self.veto_segments = segments.segmentlistdict()
        self.zero_lag_segments = {}
        self.instruments = []
        self.livetime = {}
        self.multi_burst_table = None
        self.coinc_inspiral_table = None

        for f in flist:
            if opts.verbose:
                print("Gathering stats from: %s...." % (f, ), file=sys.stderr)
            working_filename = dbtables.get_connection_filename(
                f, tmp_path=opts.tmp_space, verbose=opts.verbose)
            connection = sqlite3.connect(working_filename)
            dbtables.DBTable_set_connection(connection)
            xmldoc = dbtables.get_xml(connection)

            # look for a sim table
            try:
                sim_inspiral_table = dbtables.lsctables.SimInspiralTable.get_table(
                    xmldoc)
                self.inj_fnames.append(f)
                sim = True
            except ValueError:
                self.non_inj_fnames.append(f)
                sim = False

            # FIGURE OUT IF IT IS A BURST OR INSPIRAL RUN
            try:
                self.multi_burst_table = dbtables.lsctables.MultiBurstTable.get_table(
                    xmldoc)
            except ValueError:
                self.multi_burst_table = None
            try:
                self.coinc_inspiral_table = dbtables.lsctables.CoincInspiralTable.get_table(
                    xmldoc)
            except ValueError:
                self.coinc_inspiral_table = None
            if self.multi_burst_table and self.coinc_inspiral_table:
                print("both burst and inspiral tables found.  Aborting",
                      file=sys.stderr)
                raise ValueError

            if not sim:
                self.get_instruments(connection)
                self.segments += self.get_segments(connection, xmldoc)
                #FIXME, don't assume veto segments are the same in every file!
                self.veto_segments = self.get_veto_segments(connection)

            dbtables.discard_connection_filename(f,
                                                 working_filename,
                                                 verbose=opts.verbose)
            dbtables.DBTable_set_connection(None)

        # remove redundant instruments
        self.instruments = list(set(self.instruments))
        # FIXME Do these have to be done by instruments?
        self.segments -= self.veto_segments

        # segments and livetime by instruments
        for i in self.instruments:
            self.zero_lag_segments[i] = self.segments.intersection(
                i) - self.segments.union(set(self.segments.keys()) - i)
            self.livetime[i] = float(abs(self.zero_lag_segments[i]))
Beispiel #56
0
    JOIN coinc_event AS insp_coinc_event ON (insp_coinc_event.coinc_event_id == coinc_inspiral.coinc_event_id)
    JOIN coinc_definer AS insp_coinc_definer ON (insp_coinc_definer.coinc_def_id == insp_coinc_event.coinc_def_id)
    JOIN coinc_definer AS sim_coinc_definer ON (sim_coinc_definer.coinc_def_id == sim_coinc_event.coinc_def_id)
  WHERE
    insp_coinc_definer.search == 'inspiral'
    AND sim_coinc_definer.search == 'inspiral'
    AND insp_coinc_definer.search_coinc_type == 0
    AND sim_coinc_definer.search_coinc_type == 2
    AND mapC.table_name == 'coinc_event'
    AND mapD.table_name == 'sim_inspiral'
  """):
    injection_likelihood.append(likelihood)
    injection_snr.append(snr)
  #livetimes = db_thinca_rings.get_thinca_livetimes(db_thinca_rings.get_thinca_rings_by_available_instruments(connection,'thinca'), db_thinca_rings.get_veto_segments(connection, 'vetoes'), db_thinca_rings.get_background_offset_vectors(connection), verbose=True)
  # above is the correct calculation of livetimes, but it takes a while. You can comment it out and uncomment the line below for an approximate calculation of livetime.
  livetimes = db_thinca_rings.get_thinca_livetimes(db_thinca_rings.get_thinca_rings_by_available_instruments(connection,'thinca'), segments.segmentlistdict(), db_thinca_rings.get_background_offset_vectors(connection), verbose=True)
  dbtables.put_connection_filename(filename, working_filename, verbose = True)
print "number of timeslides:", len(timeslide_likelihood)
print "number of zerolags:", len(zerolag_likelihood)
print "number of injections:", len(injection_likelihood)

all_likelihoods = numpy.array(timeslide_likelihood + zerolag_likelihood + injection_likelihood, dtype=float)
timeslide_likelihoods = numpy.array(timeslide_likelihood)
zerolag_likelihoods = numpy.array(zerolag_likelihood)
injection_likelihoods = numpy.array(injection_likelihood)
timeslide_snrs = numpy.array(timeslide_snr)
zerolag_snrs = numpy.array(zerolag_snr)
injection_snrs = numpy.array(injection_snr)
# set all zero likelihoods to the next lowest calculated likelihood, and all infinity likelihoods to the next highest, so plotting can work
plottable_likelihoods = all_likelihoods[~numpy.isinf(all_likelihoods) & (all_likelihoods > 0)]
min_likelihood = plottable_likelihoods.min()