IGWN Segments

2.1.1 · active · verified Fri Apr 17

IGWN Segments (igwn-segments) provides a robust Pythonic representation of half-open intervals and lists of such intervals. It offers tools for creating, manipulating, and performing set-like operations (union, intersection, subtraction) on time segments, crucial for gravitational-wave data analysis and other scientific applications. Currently at version 2.1.1, the library follows an irregular release cadence, driven by the needs of the IGWN collaboration.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create `Segment` and `SegmentList` objects, calculate durations, check for intersections, and perform union operations. It also shows how to create a `SegmentList` from a string representation.

from segments import Segment, SegmentList

# Create individual segments
s1 = Segment(100.0, 200.0)
s2 = Segment(150.0, 250.0)
s3 = Segment(300.0, 350.0)

print(f"Segment 1: {s1}")
print(f"Segment 2: {s2}")
print(f"Duration of s1: {s1.duration}")
print(f"s1 intersects s2: {s1.intersects(s2)}")

# Create a list of segments
sl = SegmentList([s1, s2, s3])
print(f"Initial SegmentList: {sl}")

# Perform union operation
union_sl = sl.union()
print(f"Union of SegmentList: {union_sl}")

# Add a segment to a SegmentList
sl_plus_s4 = sl.union(Segment(0, 50))
print(f"SegmentList with an added segment: {sl_plus_s4}")

# Create from string representation
sl_from_str = SegmentList.from_str('[[10, 20), [30, 40))')
print(f"SegmentList from string: {sl_from_str}")

view raw JSON →