gwexpy.segments.SegmentList

class gwexpy.segments.SegmentList(iterable=(), /)[source]

Bases: segmentlist

A list of Segments <Segment>.

The SegmentList provides additional methods that assist in the manipulation of lists of Segments <Segment>. In particular, arithmetic operations such as union and intersection are provided. Unlike the Segment, the SegmentList is closed under all supported arithmetic operations.

All standard Python sequence-like operations are supported, like slicing, iteration and so on, but the arithmetic and other methods in this class generally expect the SegmentList to be in what is refered to as a “coalesced” state - consisting solely of disjoint Segments <Segment> listed in ascending order. Using the standard Python sequence-like operations, a SegmentList can be easily constructed that is not in this state; for example by simply appending a Segment to the end of the list that overlaps some other Segment already in the list. The class provides a coalesce() method that can be called to put it in the coalesced state. Following application of the coalesce method, all arithmetic operations will function reliably. All arithmetic methods themselves return coalesced results, so there is never a need to call the coalesce method when manipulating a SegmentList exclusively via the arithmetic operators.

Examples

>>> x = SegmentList([Segment(-10, 10)])
>>> x |= SegmentList([Segment(20, 30)])
>>> x -= SegmentList([Segment(-5, 5)])
>>> print(x)
[Segment(-10, -5), Segment(5, 10), Segment(20, 30)]
>>> print(~x)
[Segment(-infinity, -10), Segment(-5, 5), Segment(10, 20),
 Segment(30, infinity)]
__init__(*args, **kwargs)

Methods

__init__(*args, **kwargs)

append(object, /)

Append object to the end of the list.

clear()

Remove all items from list.

coalesce()

Sort the elements of the list into ascending order, and merge continuous segments into single segments.

contract

Execute the .contract() method on each segment in the list and coalesce the result.

copy()

Return a shallow copy of the list.

count(value, /)

Return number of occurrences of value.

extend(iterable, /)

Extend list by appending elements from the iterable.

extent

Return the segment whose end-points denote the maximum and minimum extent of the segmentlist.

find

Return the smallest i such that i is the index of an element that wholly contains item.

index(value[, start, stop])

Return first index of value.

insert(index, object, /)

Insert object before index.

intersects

Returns True if the intersection of self and the segmentlist other is not the null set, otherwise returns False.

intersects_segment

Returns True if the intersection of self and the segment other is not the null set, otherwise returns False.

pop([index])

Remove and return item at index (default last).

protract

Execute the .protract() method on each segment in the list and coalesce the result.

remove(value, /)

Remove first occurrence of value.

reverse()

Reverse IN PLACE.

shift

Execute the .shift() method on each segment in the list.

sort(*[, key, reverse])

Sort the list in ascending order and return None.

to_table()

Convert this SegmentList to a ~astropy.table.Table.

value_slice_to_index

Convert the slice s from a slice of values to a slice of indexes.

Attributes

read

write

extent()

Return the segment whose end-points denote the maximum and minimum extent of the segmentlist. Does not require the segmentlist to be coalesced.

coalesce() Self[source]

Sort the elements of the list into ascending order, and merge continuous segments into single segments. Segmentlist is modified in place. This operation is O(n log n).

to_table() Table[source]

Convert this SegmentList to a ~astropy.table.Table.

The resulting Table has four columns: index, start, end, and duration, corresponding to the zero-counted list index, GPS start and end times, and total duration in seconds, respectively.

This method exists mainly to provide a way to write SegmentList objects in comma-separated value (CSV) format, via the write() method.

read = <gwpy.segments.connect.SegmentListRead object>
write = <gwpy.segments.connect.SegmentListWrite object>