Package glue :: Module segmentsUtils
[hide private]
[frames] | no frames]

Module segmentsUtils

source code

This module provides additional utilities for use with segments.segmentlist objects.


Version: git id 8cbd1b7187ce3ed9a825d6ed11cc432f3cfde9a5

Date: 2017-12-05 15:29:36 +0000

Author: Kipp Cannon <kipp.cannon@ligo.org>

Functions [hide private]
 
Fold(seglist1, seglist2)
An iterator that generates the results of taking the intersection of seglist1 with each segment in seglist2 in turn.
source code
 
S2playground(extent)
Return a segmentlist identifying the S2 playground times within the interval defined by the segment extent.
source code
 
from_bitstream(bitstream, start, dt, minlen=1)
Convert consecutive True values in a bit stream (boolean-castable iterable) to a stream of segments.
source code
 
from_range_strings(ranges, boundtype=<type 'int'>)
Parse a list of ranges expressed as strings in the form "value" or "first:last" into an equivalent glue.segments.segmentlist.
source code
 
fromfilenames(filenames, coltype=<type 'int'>)
Return a segmentlist describing the intervals spanned by the files whose names are given in the list filenames.
source code
 
fromlalcache(cachefile, coltype=<type 'int'>)
Construct a segmentlist representing the times spanned by the files identified in the LAL cache contained in the file object file.
source code
 
fromsegwizard(file, coltype=<type 'int'>, strict=True)
Read a segmentlist from the file object file containing a segwizard compatible segment list.
source code
 
fromtama(file, coltype=<class 'glue.lal.LIGOTimeGPS'>)
Read a segmentlist from the file object file containing TAMA locked-segments data.
source code
 
segmentlist_range(start, stop, period)
Analogous to Python's range() builtin, this generator yields a sequence of continuous adjacent segments each of length "period" with the first starting at "start" and the last ending not after "stop".
source code
 
segmentlistdict_from_short_string(s, boundtype=<type 'int'>)
Parse a string representation of a set of named segmentlists into a segmentlistdict object.
source code
 
segmentlistdict_to_short_string(seglists)
Return a string representation of a segmentlistdict object.
source code
 
to_range_strings(seglist)
Turn a segment list into a list of range strings as could be parsed by from_range_strings().
source code
 
tosegwizard(file, seglist, header=True, coltype=<type 'int'>)
Write the segmentlist seglist to the file object file in a segwizard compatible format.
source code
 
vote(seglists, n)
Given a sequence of segmentlists, returns the intervals during which at least n of them intersect.
source code
Variables [hide private]
  __package__ = 'glue'
Function Details [hide private]

Fold(seglist1, seglist2)

source code 

An iterator that generates the results of taking the intersection of seglist1 with each segment in seglist2 in turn. In each result, the segment start and stop values are adjusted to be with respect to the start of the corresponding segment in seglist2. See also the segmentlist_range() function.

This has use in applications that wish to convert ranges of values to ranges relative to epoch boundaries. Below, a list of time intervals in hours is converted to a sequence of daily interval lists with times relative to midnight.

Example:

>>> from glue.segments import *
>>> x = segmentlist([segment(0, 13), segment(14, 20), segment(22, 36)])
>>> for y in Fold(x, segmentlist_range(0, 48, 24)): print y
...
[segment(0, 13), segment(14, 20), segment(22, 24)]
[segment(0, 12)]

S2playground(extent)

source code 

Return a segmentlist identifying the S2 playground times within the interval defined by the segment extent.

Example:

>>> from glue import segments
>>> S2playground(segments.segment(874000000, 874010000))
[segment(874000013, 874000613), segment(874006383, 874006983)]

from_bitstream(bitstream, start, dt, minlen=1)

source code 

Convert consecutive True values in a bit stream (boolean-castable iterable) to a stream of segments. Require minlen consecutive True samples to comprise a segment.

Example:

>>> list(from_bitstream((True, True, False, True, False), 0, 1))
[segment(0, 2), segment(3, 4)]
>>> list(from_bitstream([[], [[]], [[]], [], []], 1013968613, 0.125))
[segment(1013968613.125, 1013968613.375)]

from_range_strings(ranges, boundtype=<type 'int'>)

source code 

Parse a list of ranges expressed as strings in the form "value" or "first:last" into an equivalent glue.segments.segmentlist. In the latter case, an empty string for "first" and(or) "last" indicates a (semi)infinite range. A typical use for this function is in parsing command line options or entries in configuration files.

NOTE: the output is a segmentlist as described by the strings; if the segments in the input file are not coalesced or out of order, then thusly shall be the output of this function. It is recommended that this function's output be coalesced before use.

Example:

>>> text = "0:10,35,100:"
>>> from_range_strings(text.split(","))
[segment(0, 10), segment(35, 35), segment(100, infinity)]

fromfilenames(filenames, coltype=<type 'int'>)

source code 

Return a segmentlist describing the intervals spanned by the files whose names are given in the list filenames. The segmentlist is constructed by parsing the file names, and the boundaries of each segment are coerced to type coltype.

The file names are parsed using a generalization of the format described in Technical Note LIGO-T010150-00-E, which allows the start time and duration appearing in the file name to be non-integers.

NOTE: the output is a segmentlist as described by the file names; if the file names are not in time order, or describe overlaping segments, then thusly shall be the output of this function. It is recommended that this function's output be coalesced before use.

fromlalcache(cachefile, coltype=<type 'int'>)

source code 

Construct a segmentlist representing the times spanned by the files identified in the LAL cache contained in the file object file. The segmentlist will be created with segments whose boundaries are of type coltype, which should raise ValueError if it cannot convert its string argument.

Example:

>>> from lal import LIGOTimeGPS
>>> cache_seglists = fromlalcache(open(filename), coltype = LIGOTimeGPS).coalesce()

See also:

glue.lal.CacheEntry

fromsegwizard(file, coltype=<type 'int'>, strict=True)

source code 

Read a segmentlist from the file object file containing a segwizard compatible segment list. Parsing stops on the first line that cannot be parsed (which is consumed). The segmentlist will be created with segment whose boundaries are of type coltype, which should raise ValueError if it cannot convert its string argument. Two-column, three-column, and four-column segwizard files are recognized, but the entire file must be in the same format, which is decided by the first parsed line. If strict is True and the file is in three- or four-column format, then each segment's duration is checked against that column in the input file.

NOTE: the output is a segmentlist as described by the file; if the segments in the input file are not coalesced or out of order, then thusly shall be the output of this function. It is recommended that this function's output be coalesced before use.

fromtama(file, coltype=<class 'glue.lal.LIGOTimeGPS'>)

source code 

Read a segmentlist from the file object file containing TAMA locked-segments data. Parsing stops on the first line that cannot be parsed (which is consumed). The segmentlist will be created with segments whose boundaries are of type coltype, which should raise ValueError if it cannot convert its string argument.

NOTE: TAMA locked-segments files contain non-integer start and end times, so the default column type is set to LIGOTimeGPS.

NOTE: the output is a segmentlist as described by the file; if the segments in the input file are not coalesced or out of order, then thusly shall be the output of this function. It is recommended that this function's output be coalesced before use.

segmentlist_range(start, stop, period)

source code 

Analogous to Python's range() builtin, this generator yields a sequence of continuous adjacent segments each of length "period" with the first starting at "start" and the last ending not after "stop". Note that the segments generated do not form a coalesced list (they are not disjoint). start, stop, and period can be any objects which support basic arithmetic operations.

Example:

>>> from glue.segments import *
>>> segmentlist(segmentlist_range(0, 15, 5))
[segment(0, 5), segment(5, 10), segment(10, 15)]
>>> segmentlist(segmentlist_range('', 'xxx', 'x'))
[segment('', 'x'), segment('x', 'xx'), segment('xx', 'xxx')]

segmentlistdict_from_short_string(s, boundtype=<type 'int'>)

source code 

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.

segmentlistdict_to_short_string(seglists)

source code 

Return a string representation of a segmentlistdict object. Each segmentlist in the dictionary is encoded using to_range_strings() with "," used to delimit segments. The keys are converted to strings and paired with the string representations of their segmentlists using "=" as a delimiter. Finally the key=value strings are combined using "/" to delimit them.

Example:

>>> from glue.segments import *
>>> segs = segmentlistdict({"H1": segmentlist([segment(0, 10), segment(35, 35), segment(100, infinity())]), "L1": segmentlist([segment(5, 15), segment(45, 60)])})
>>> segmentlistdict_to_short_string(segs)
'H1=0:10,35,100:/L1=5:15,45:60'

This function, and its inverse segmentlistdict_from_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.

to_range_strings(seglist)

source code 

Turn a segment list into a list of range strings as could be parsed by from_range_strings(). A typical use for this function is in machine-generating configuration files or command lines for other programs.

Example:

>>> from glue.segments import *
>>> segs = segmentlist([segment(0, 10), segment(35, 35), segment(100, infinity())])
>>> ",".join(to_range_strings(segs))
'0:10,35,100:'

tosegwizard(file, seglist, header=True, coltype=<type 'int'>)

source code 

Write the segmentlist seglist to the file object file in a segwizard compatible format. If header is True, then the output will begin with a comment line containing column names. The segment boundaries will be coerced to type coltype and then passed to str() before output.

vote(seglists, n)

source code 

Given a sequence of segmentlists, returns the intervals during which at least n of them intersect. The input segmentlists must be coalesced, the output is coalesced.

Example:

>>> from glue.segments import *
>>> w = segmentlist([segment(0, 15)])
>>> x = segmentlist([segment(5, 20)])
>>> y = segmentlist([segment(10, 25)])
>>> z = segmentlist([segment(15, 30)])
>>> vote((w, x, y, z), 3)
[segment(10, 20)]

The sequence of segmentlists is only iterated over once, and the segmentlists within it are only iterated over once; they can all be generators. If there are a total of N segments in M segment lists and the final result has L segments the algorithm is O(N M) + O(L).