Interval

Source https://github.com/internetarchive/analyze_ocr/blob/master/interval.py Liscence Not Specified

Provides the Interval and IntervalSet classes

The interval module provides the Interval and IntervalSet data types. Intervals describe continuous ranges that can be open, closed, half-open, or infinite. IntervalSets contain zero to many disjoint sets of Intervals.

Intervals don’t have to pertain to numbers. They can contain any data that is comparable via the Python operators <, <=, ==, >=, and >. Here’s an example of how strings can be used with Intervals:

>>> volume1 = Interval.between("A", "Foe")
>>> volume2 = Interval.between("Fog", "McAfee")
>>> volume3 = Interval.between("McDonalds", "Space")
>>> volume4 = Interval.between("Spade", "Zygote")
>>> encyclopedia = IntervalSet([volume1, volume2, volume3, volume4])
>>> mySet = IntervalSet([volume1, volume3, volume4])
>>> "Meteor" in encyclopedia
True
>>> "Goose" in encyclopedia
True
>>> "Goose" in mySet
False
>>> volume2 in (encyclopedia ^ mySet)
True

Here’s an example of how times can be used with Intervals:

>>> officeHours = IntervalSet.between("08:00", "17:00")
>>> myLunch = IntervalSet.between("11:30", "12:30")
>>> myHours = IntervalSet.between("08:30", "19:30") - myLunch
>>> myHours.issubset(officeHours)
False
>>> "12:00" in myHours
False
>>> "15:30" in myHours
True
>>> inOffice = officeHours & myHours
>>> print inOffice
['08:30'..'11:30'),('12:30'..'17:00']
>>> overtime = myHours - officeHours
>>> print overtime
('17:00'..'19:30']
class aurora.interval.BaseIntervalSet(items=[])[source]

Bases: object

Base class for IntervalSet and FrozenIntervalSet.

Methods

all()

Returns an interval set containing all values

between(a, b[, closed])

Returns an IntervalSet of all values between a and b.

bounds()

Returns an interval that encompasses the entire BaseIntervalSet

copy()

Returns a copy of the object

difference(other)

Returns the difference between the object and the given object

empty()

Returns an interval set containing no values.

greater_than(n)

Returns an IntervalSet containing values greater than the given value

greater_than_or_equal_to(n)

Returns an IntervalSet containing values greater than or equal to the given value

intersection(other)

Returns the intersection between the object and the given value

issubset(other)

Tells if the given object is a subset of the object

issuperset(other)

Tells whether the given object is a superset of the object

less_than(n)

Returns an IntervalSet containing values less than the given value

less_than_or_equal_to(n[, closed])

Returns an IntervalSet containing values less than or equal to the given value

lower_bound()

Returns the lower boundary of the BaseIntervalSet

lower_closed()

Returns a boolean telling whether the lower bound is closed or not

not_equal_to(n)

Returns an IntervalSet of all values not equal to n

symmetric_difference(other)

Returns the exclusive or of the given value with the object

union(other)

Returns the union of the given value with the object

upper_bound()

Returns the upper boundary of the BaseIntervalSet

upper_closed()

Returns a boolean telling whether the upper bound is closed or not

classmethod all()[source]

Returns an interval set containing all values

>>> print IntervalSet.all()
(...)
classmethod between(a, b, closed=True)[source]

Returns an IntervalSet of all values between a and b.

If closed is True, then the endpoints are included; otherwise, they aren’t.

>>> print IntervalSet.between(0, 100)
[0..100]
>>> print IntervalSet.between(-1, 1)
[-1..1]
bounds()[source]

Returns an interval that encompasses the entire BaseIntervalSet

>>> print IntervalSet([Interval.between(4, 6), 2, 12]).bounds()
[2..12]
>>> print IntervalSet().bounds()
<Empty>
>>> print IntervalSet.all().bounds()
(...)
copy()[source]

Returns a copy of the object

>>> s = IntervalSet(
...   [7, 2, 3, 2, 6, 2, Interval.greater_than(3)])
>>> s2 = s.copy()
>>> s == s2
True
>>> s = FrozenIntervalSet(
...   [7, 2, 3, 2, 6, 2, Interval.greater_than(3)])
>>> s2 = s.copy()
>>> s == s2
True
difference(other)[source]

Returns the difference between the object and the given object

Returns all values of self minus all matching values in other. It is identical to the - operator, only it accepts any iterable as the operand.

>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> all       = IntervalSet.all()
>>> print evens.difference(nonzero)
0
>>> print empty.difference(naturals)
<Empty>
>>> print zero.difference(naturals)
<Empty>
>>> print positives.difference(zero)
(0...)
>>> print naturals.difference(negatives)
[0...)
>>> print all.difference(zero)
(...0),(0...)
>>> all.difference(zero) == nonzero
True
>>> naturals.difference([0]) == positives
True
classmethod empty()[source]

Returns an interval set containing no values.

>>> print IntervalSet.empty()
<Empty>
classmethod greater_than(n)[source]

Returns an IntervalSet containing values greater than the given value

>>> print IntervalSet.greater_than(0)
(0...)
>>> print IntervalSet.greater_than(-23)
(-23...)
classmethod greater_than_or_equal_to(n)[source]

Returns an IntervalSet containing values greater than or equal to the given value

>>> print IntervalSet.greater_than_or_equal_to(0)
[0...)
>>> print IntervalSet.greater_than_or_equal_to(-23)
[-23...)
intersection(other)[source]

Returns the intersection between the object and the given value

This function returns the intersection of self and other. It is identical to the & operator, except this function accepts any iterable as an operand, and & accepts only another BaseIntervalSet.

>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> print naturals.intersection(naturals)
[0...)
>>> print evens.intersection(zero)
0
>>> print negatives.intersection(zero)
<Empty>
>>> print nonzero.intersection(positives)
(0...)
>>> print empty.intersection(zero)
<Empty>
issubset(other)[source]

Tells if the given object is a subset of the object

Returns true if self is a subset of other. other can be any iterable object.

>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero.issubset(positives)
False
>>> zero.issubset(naturals)
True
>>> positives.issubset(zero)
False
>>> r.issubset(zero)
False
>>> r.issubset(positives)
True
>>> positives.issubset(r)
False
>>> negatives.issubset(IntervalSet.all())
True
>>> r2.issubset(negatives)
True
>>> negatives.issubset(positives)
False
>>> zero.issubset([0, 1, 2, 3])
True
issuperset(other)[source]

Tells whether the given object is a superset of the object

Returns true if self is a superset of other. other can be any iterable object.

>>> zero = IntervalSet([0])
>>> positives = IntervalSet.greater_than(0)
>>> naturals = IntervalSet.greater_than_or_equal_to(0)
>>> negatives = IntervalSet.less_than(0)
>>> r = IntervalSet.between(3, 6)
>>> r2 = IntervalSet.between(-8, -2)
>>> zero.issuperset(positives)
False
>>> zero.issuperset(naturals)
False
>>> positives.issuperset(zero)
False
>>> r.issuperset(zero)
False
>>> r.issuperset(positives)
False
>>> positives.issuperset(r)
True
>>> negatives.issuperset(IntervalSet.all())
False
>>> r2.issuperset(negatives)
False
>>> negatives.issuperset(positives)
False
>>> negatives.issuperset([-2, -632])
True
classmethod less_than(n)[source]

Returns an IntervalSet containing values less than the given value

>>> print IntervalSet.less_than(0)
(...0)
>>> print IntervalSet.less_than(-23)
(...-23)
classmethod less_than_or_equal_to(n, closed=False)[source]

Returns an IntervalSet containing values less than or equal to the given value

>>> print IntervalSet.less_than_or_equal_to(0)
(...0]
>>> print IntervalSet.less_than_or_equal_to(-23)
(...-23]
lower_bound()[source]

Returns the lower boundary of the BaseIntervalSet

>>> IntervalSet([Interval.between(4, 6), 2, 12]).lower_bound()
2
>>> IntervalSet().lower_bound()
Traceback (most recent call last):
    ...
IndexError: The BaseIntervalSet is empty
>>> IntervalSet.all().lower_bound()
-Inf
lower_closed()[source]

Returns a boolean telling whether the lower bound is closed or not

>>> IntervalSet([Interval.between(4, 6), 2, 12]).lower_closed()
True
>>> IntervalSet().lower_closed()
Traceback (most recent call last):
    ...
IndexError: The BaseIntervalSet is empty
>>> IntervalSet.all().lower_closed()
False
classmethod not_equal_to(n)[source]

Returns an IntervalSet of all values not equal to n

>>> print IntervalSet.not_equal_to(0)
(...0),(0...)
>>> print IntervalSet.not_equal_to(-23)
(...-23),(-23...)
symmetric_difference(other)[source]

Returns the exclusive or of the given value with the object

This function returns the exclusive or of two IntervalSets. It is identical to the ^ operator, except it accepts any iterable object for the operand.

>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> print nonzero.symmetric_difference(naturals)
(...0]
>>> print zero.symmetric_difference(negatives)
(...0]
>>> print positives.symmetric_difference(empty)
(0...)
>>> print evens.symmetric_difference(zero)
-8,-6,-4,-2,2,4,6,8
>>> print evens.symmetric_difference(range(0, 9, 2))
-8,-6,-4,-2
union(other)[source]

Returns the union of the given value with the object

This function returns the union of a BaseIntervalSet and an iterable object. It is identical to the | operator, except that | only accepts a BaseIntervalSet operand and union accepts any iterable.

>>> negatives = IntervalSet.less_than(0)
>>> positives = IntervalSet.greater_than(0)
>>> naturals  = IntervalSet.greater_than_or_equal_to(0)
>>> evens     = IntervalSet([-8, -6, -4, -2, 0, 2, 4, 6, 8])
>>> zero      = IntervalSet([0])
>>> nonzero   = IntervalSet.not_equal_to(0)
>>> empty     = IntervalSet.empty()
>>> all       = IntervalSet.all()
>>> print evens.union(positives)
-8,-6,-4,-2,[0...)
>>> print negatives.union(zero)
(...0]
>>> print empty.union(negatives)
(...0)
>>> print empty.union(naturals)
[0...)
>>> print nonzero.union(evens)
(...)
>>> print negatives.union(range(5))
(...0],1,2,3,4
upper_bound()[source]

Returns the upper boundary of the BaseIntervalSet

>>> IntervalSet([Interval.between(4, 6), 2, 12]).upper_bound()
12
>>> IntervalSet().upper_bound()
Traceback (most recent call last):
    ...
IndexError: The BaseIntervalSet is empty
>>> IntervalSet.all().upper_bound()
Inf
upper_closed()[source]

Returns a boolean telling whether the upper bound is closed or not

>>> IntervalSet([Interval.between(4, 6), 2, 12]).upper_closed()
True
>>> IntervalSet().upper_closed()
Traceback (most recent call last):
    ...
IndexError: The BaseIntervalSet is empty
>>> IntervalSet.all().upper_closed()
False
class aurora.interval.FrozenIntervalSet(items=[])[source]

Bases: aurora.interval.BaseIntervalSet

An immutable version of BaseIntervalSet

FrozenIntervalSet is like IntervalSet, only add and remove are not implemented, and hashes can be generated.

>>> fs = FrozenIntervalSet([3, 6, 2, 4])
>>> fs.add(12)
Traceback (most recent call last):
  ...
AttributeError: 'FrozenIntervalSet' object has no attribute 'add'
>>> fs.remove(4)
Traceback (most recent call last):
  ...
AttributeError: 'FrozenIntervalSet' object has no attribute 'remove'
>>> fs.clear()
Traceback (most recent call last):
  ...
AttributeError: 'FrozenIntervalSet' object has no attribute 'clear'

Because FrozenIntervalSets are immutable, they can be used as a dictionary key.

>>> d = {
...   FrozenIntervalSet([3, 66]) : 52,
...   FrozenIntervalSet.less_than(3) : 3}

Methods

all()

Returns an interval set containing all values

between(a, b[, closed])

Returns an IntervalSet of all values between a and b.

bounds()

Returns an interval that encompasses the entire BaseIntervalSet

copy()

Duplicates the object

difference(other)

Returns the difference between the object and the given object

empty()

Returns an interval set containing no values.

greater_than(n)

Returns an IntervalSet containing values greater than the given value

greater_than_or_equal_to(n)

Returns an IntervalSet containing values greater than or equal to the given value

intersection(other)

Returns the intersection between the object and the given value

issubset(other)

Tells if the given object is a subset of the object

issuperset(other)

Tells whether the given object is a superset of the object

less_than(n)

Returns an IntervalSet containing values less than the given value

less_than_or_equal_to(n[, closed])

Returns an IntervalSet containing values less than or equal to the given value

lower_bound()

Returns the lower boundary of the BaseIntervalSet

lower_closed()

Returns a boolean telling whether the lower bound is closed or not

not_equal_to(n)

Returns an IntervalSet of all values not equal to n

symmetric_difference(other)

Returns the exclusive or of the given value with the object

union(other)

Returns the union of the given value with the object

upper_bound()

Returns the upper boundary of the BaseIntervalSet

upper_closed()

Returns a boolean telling whether the upper bound is closed or not

copy()[source]

Duplicates the object

For FrozenIntervalSet objects, since they’re immutable, a reference, not a copy, of self is returned.

>>> s = FrozenIntervalSet(
...   [7, 2, 3, 2, 6, 2, Interval.greater_than(3)])
>>> s2 = s.copy()
>>> s == s2
True
>>> id(s) == id(s2)
True
class aurora.interval.Interval(lower_bound=- Inf, upper_bound=Inf, **kwargs)[source]

Bases: object

Represents a continuous range of values

An Interval is composed of the lower bound, a closed lower bound flag, an upper bound, and a closed upper bound flag. The attributes are called lower_bound, lower_closed, upper_bound, and upper_closed, respectively. For an infinite interval, the bound is set to inf or -inf. IntervalSets are composed of zero to many Intervals.

Methods

adjacent_to(other)

Tells whether an Interval is adjacent to the object without overlap

all()

Returns an interval encompassing all values

between(a, b[, closed])

Returns an interval between two values

comes_before(other)

Tells whether an interval lies before the object

duration()

@note: added 20140618 kkappler returns the duration of interval

equal_to(a)

Returns an point interval

greater_than(a)

Returns interval of all values greater than the given value

greater_than_or_equal_to(a)

Returns interval of all values greater than or equal to the given value

join(other)

Combines two continous Intervals

less_than(a)

Returns interval of all values less than the given value

less_than_or_equal_to(a)

Returns an interval containing the given values and everything less

none()

Returns an empty interval

overlaps(other)

Tells whether the given interval overlaps the object

pad(pad_width)

@note: added 20140618 kkappler returns a padded interval; Intent was to add a little so that open-intervals, or adjacent intervals would easily make an interval set

adjacent_to(other)[source]

Tells whether an Interval is adjacent to the object without overlap

Returns True if self is adjacent to other, meaning that if they were joined, there would be no discontinuity. They cannot overlap.

>>> r1  = Interval.less_than(-100)
>>> r2  = Interval.less_than_or_equal_to(-100)
>>> r3  = Interval.less_than(100)
>>> r4  = Interval.less_than_or_equal_to(100)
>>> r5  = Interval.all()
>>> r6  = Interval.between(-100, 100, False)
>>> r7  = Interval(-100, 100, lower_closed=False)
>>> r8  = Interval.greater_than(-100)
>>> r9  = Interval.equal_to(-100)
>>> r10 = Interval(-100, 100, upper_closed=False)
>>> r11 = Interval.between(-100, 100)
>>> r12 = Interval.greater_than_or_equal_to(-100)
>>> r13 = Interval.greater_than(100)
>>> r14 = Interval.equal_to(100)
>>> r15 = Interval.greater_than_or_equal_to(100)
>>> r1.adjacent_to(r6)
False
>>> r6.adjacent_to(r11)
False
>>> r7.adjacent_to(r9)
True
>>> r3.adjacent_to(r10)
False
>>> r5.adjacent_to(r14)
False
>>> r6.adjacent_to(r15)
True
>>> r1.adjacent_to(r8)
False
>>> r12.adjacent_to(r14)
False
>>> r6.adjacent_to(r13)
False
>>> r2.adjacent_to(r15)
False
>>> r1.adjacent_to(r4)
False
classmethod all()[source]

Returns an interval encompassing all values

>>> print Interval.all()
(...)
classmethod between(a, b, closed=True)[source]

Returns an interval between two values

Returns an interval between values a and b. If closed is True, then the endpoints are included. Otherwise, the endpoints are excluded.

>>> print Interval.between(2, 4)
[2..4]
>>> print Interval.between(2, 4, False)
(2..4)
comes_before(other)[source]

Tells whether an interval lies before the object

self comes before other when sorted if its lower bound is less than other’s smallest value. If the smallest value is the same, then the Interval with the smallest upper bound comes first. Otherwise, they are equal.

>>> Interval.equal_to(1).comes_before(Interval.equal_to(4))
True
>>> Interval.less_than_or_equal_to(1).comes_before(Interval.equal_to(4))
True
>>> Interval.less_than_or_equal_to(5).comes_before(
...   Interval.less_than(5))
False
>>> Interval.less_than(5).comes_before(
...   Interval.less_than_or_equal_to(5))
True
>>> Interval.all().comes_before(Interval.all())
False
duration()[source]

@note: added 20140618 kkappler returns the duration of interval

classmethod equal_to(a)[source]

Returns an point interval

Returns an interval containing only a.

>>> print Interval.equal_to(32)
32
classmethod greater_than(a)[source]

Returns interval of all values greater than the given value

>>> print Interval.greater_than(32)
(32...)
classmethod greater_than_or_equal_to(a)[source]

Returns interval of all values greater than or equal to the given value

>>> print Interval.greater_than_or_equal_to(32)
[32...)
join(other)[source]

Combines two continous Intervals

Combines two continuous Intervals into one Interval. If the two Intervals are disjoint, then an exception is raised.

>>> r1  = Interval.less_than(-100)
>>> r2  = Interval.less_than_or_equal_to(-100)
>>> r3  = Interval.less_than(100)
>>> r4  = Interval.less_than_or_equal_to(100)
>>> r5  = Interval.all()
>>> r6  = Interval.between(-100, 100, False)
>>> r7  = Interval(-100, 100, lower_closed=False)
>>> r8  = Interval.greater_than(-100)
>>> r9  = Interval.equal_to(-100)
>>> r10 = Interval(-100, 100, upper_closed=False)
>>> r11 = Interval.between(-100, 100)
>>> r12 = Interval.greater_than_or_equal_to(-100)
>>> r13 = Interval.greater_than(100)
>>> r14 = Interval.equal_to(100)
>>> r15 = Interval.greater_than_or_equal_to(100)
>>> print r13.join(r15)
[100...)
>>> print r7.join(r6)
(-100..100]
>>> print r11.join(r2)
(...100]
>>> print r4.join(r15)
(...)
>>> print r8.join(r8)
(-100...)
>>> print r3.join(r7)
(...100]
>>> print r5.join(r10)
(...)
>>> print r9.join(r1)
(...-100]
>>> print r12.join(r5)
(...)
>>> print r13.join(r1)
Traceback (most recent call last):
...
ArithmeticError: The Intervals are disjoint.
>>> print r14.join(r2)
Traceback (most recent call last):
...
ArithmeticError: The Intervals are disjoint.
classmethod less_than(a)[source]

Returns interval of all values less than the given value

Returns an interval containing all values less than a. If closed is True, then all values less than or equal to a are returned.

>>> print Interval.less_than(32)
(...32)
classmethod less_than_or_equal_to(a)[source]

Returns an interval containing the given values and everything less

>>> print Interval.less_than_or_equal_to(32)
(...32]
classmethod none()[source]

Returns an empty interval

>>> print Interval.none()
<Empty>
overlaps(other)[source]

Tells whether the given interval overlaps the object

Returns True if the one Interval overlaps another. If they are immediately adjacent, then this returns False. Use the adjacent_to function for testing for adjacent Intervals.

>>> r1  = Interval.less_than(-100)
>>> r2  = Interval.less_than_or_equal_to(-100)
>>> r3  = Interval.less_than(100)
>>> r4  = Interval.less_than_or_equal_to(100)
>>> r5  = Interval.all()
>>> r6  = Interval.between(-100, 100, False)
>>> r7  = Interval(-100, 100, lower_closed=False)
>>> r8  = Interval.greater_than(-100)
>>> r9  = Interval.equal_to(-100)
>>> r10 = Interval(-100, 100, upper_closed=False)
>>> r11 = Interval.between(-100, 100)
>>> r12 = Interval.greater_than_or_equal_to(-100)
>>> r13 = Interval.greater_than(100)
>>> r14 = Interval.equal_to(100)
>>> r15 = Interval.greater_than_or_equal_to(100)
>>> r8.overlaps(r9)
False
>>> r12.overlaps(r6)
True
>>> r7.overlaps(r8)
True
>>> r8.overlaps(r4)
True
>>> r14.overlaps(r11)
True
>>> r10.overlaps(r13)
False
>>> r5.overlaps(r1)
True
>>> r5.overlaps(r2)
True
>>> r15.overlaps(r6)
False
>>> r3.overlaps(r1)
True
pad(pad_width)[source]

@note: added 20140618 kkappler returns a padded interval; Intent was to add a little so that open-intervals, or adjacent intervals would easily make an interval set

class aurora.interval.IntervalSet(items=[])[source]

Bases: aurora.interval.BaseIntervalSet

The mutable version of BaseIntervalSet

IntervalSet is a class representing sets of continuous values, as opposed to a discrete set, which is already implemented by the set type in Python.

IntervalSets can be bounded, unbounded, and non-continuous. They were designed to accomodate any sort of mathematical set dealing with continuous values. This will usually mean numbers, but any Python type that has valid comparison operations can be used in an IntervalSet.

Because IntervalSets are mutable, it cannot be used as a dictionary key.

>>> {IntervalSet([3, 66]) : 52}
Traceback (most recent call last):
    ...
TypeError: unhashable instance

Methods

add(obj)

Adds an Interval or discrete value to the object

all()

Returns an interval set containing all values

between(a, b[, closed])

Returns an IntervalSet of all values between a and b.

bounds()

Returns an interval that encompasses the entire BaseIntervalSet

clear()

Removes all Intervals from the object

copy()

Returns a copy of the object

difference(other)

Returns the difference between the object and the given object

difference_update(other)

Removes any elements in the given value from the object

discard(obj)

Removes a value from the object

empty()

Returns an interval set containing no values.

greater_than(n)

Returns an IntervalSet containing values greater than the given value

greater_than_or_equal_to(n)

Returns an IntervalSet containing values greater than or equal to the given value

intersection(other)

Returns the intersection between the object and the given value

intersection_update(other)

Removes values not found in the parameter

issubset(other)

Tells if the given object is a subset of the object

issuperset(other)

Tells whether the given object is a superset of the object

less_than(n)

Returns an IntervalSet containing values less than the given value

less_than_or_equal_to(n[, closed])

Returns an IntervalSet containing values less than or equal to the given value

lower_bound()

Returns the lower boundary of the BaseIntervalSet

lower_closed()

Returns a boolean telling whether the lower bound is closed or not

not_equal_to(n)

Returns an IntervalSet of all values not equal to n

pop()

Returns and discards an Interval or value from the IntervalSet

remove(obj)

Removes a value from the object

symmetric_difference(other)

Returns the exclusive or of the given value with the object

symmetric_difference_update(other)

Updates the object as though doing an xor with the parameter

union(other)

Returns the union of the given value with the object

update(other)

Adds elements from the given value to the object

upper_bound()

Returns the upper boundary of the BaseIntervalSet

upper_closed()

Returns a boolean telling whether the upper bound is closed or not

add(obj)[source]

Adds an Interval or discrete value to the object

>>> r = IntervalSet()
>>> r.add(4)
>>> print r
4
>>> r.add(Interval(23, 39, lower_closed=False))
>>> print r
4,(23..39]
>>> r.add(Interval.less_than(25))
>>> print r
(...39]
clear()[source]

Removes all Intervals from the object

>>> s = IntervalSet([2, 7, Interval.greater_than(8), 2, 6, 34])
>>> print s
2,6,7,(8...)
>>> s.clear()
>>> print s
<Empty>
difference_update(other)[source]

Removes any elements in the given value from the object

This function removes the elements in other from self. other can be any iterable object.

>>> r = IntervalSet.all()
>>> r.difference_update([4])
>>> print r
(...4),(4...)
>>> r.difference_update(
...   IntervalSet([Interval(23, 39, lower_closed=False)]))
>>> print r
(...4),(4..23],(39...)
>>> r.difference_update(IntervalSet.less_than(25))
>>> print r
(39...)
>>> r2 = IntervalSet.all()
>>> r.difference_update(r2)
>>> print r
<Empty>
discard(obj)[source]

Removes a value from the object

This function removes an Interval or discrete value from an IntervalSet.

>>> r = IntervalSet.all()
>>> r.discard(4)
>>> print r
(...4),(4...)
>>> r.discard(Interval(23, 39, lower_closed=False))
>>> print r
(...4),(4..23],(39...)
>>> r.discard(Interval.less_than(25))
>>> print r
(39...)
intersection_update(other)[source]

Removes values not found in the parameter

Removes elements not found in other. other can be any iterable object

>>> r = IntervalSet.all()
>>> r.intersection_update([4])
>>> print r
4
>>> r = IntervalSet.all()
>>> r.intersection_update(
...   IntervalSet([Interval(23, 39, lower_closed=False)]))
>>> print r
(23..39]
>>> r.intersection_update(IntervalSet.less_than(25))
>>> print r
(23..25)
>>> r2 = IntervalSet.all()
>>> r.intersection_update(r2)
>>> print r
(23..25)
pop()[source]

Returns and discards an Interval or value from the IntervalSet

>>> s = IntervalSet([7, Interval.less_than(2), 2, 0])
>>> l = []
>>> l.append(str(s.pop()))
>>> l.append(str(s.pop()))
>>> "(...2)" in l
False
>>> "(...2]" in l
True
>>> "7" in l
True
>>> print s
<Empty>
>>> i = s.pop()
Traceback (most recent call last):
    ...
KeyError: 'pop from an empty IntervalSet'
remove(obj)[source]

Removes a value from the object

This function removes an Interval, discrete value, or set from an IntervalSet. If the object is not in the set, a KeyError is raised.

>>> r = IntervalSet.all()
>>> r.remove(4)
>>> print r
(...4),(4...)
>>> r.remove(Interval(23, 39, lower_closed=False))
>>> print r
(...4),(4..23],(39...)
>>> r.remove(Interval.less_than(25))
Traceback (most recent call last):
    ...
KeyError: '(...25)'
symmetric_difference_update(other)[source]

Updates the object as though doing an xor with the parameter

Removes elements found in other and adds elements in other that are not in self. other can be any iterable object.

>>> r = IntervalSet.empty()
>>> r.symmetric_difference_update([4])
>>> print r
4
>>> r.symmetric_difference_update(
...   IntervalSet([Interval(23, 39, lower_closed=False)]))
>>> print r
4,(23..39]
>>> r.symmetric_difference_update(IntervalSet.less_than(25))
>>> print r
(...4),(4..23],[25..39]
>>> r2 = IntervalSet.all()
>>> r.symmetric_difference_update(r2)
>>> print r
4,(23..25),(39...)
update(other)[source]

Adds elements from the given value to the object

Adds elements from other to self. other can be any iterable object.

>>> r = IntervalSet()
>>> r.update([4])
>>> print r
4
>>> r.update(IntervalSet([Interval(23, 39, lower_closed=False)]))
>>> print r
4,(23..39]
>>> r.update(IntervalSet.less_than(25))
>>> print r
(...39]
>>> r2 = IntervalSet.all()
>>> r.update(r2)
>>> print r
(...)
class aurora.interval.Largest[source]

Bases: object

Class representing the universal largest value

This type doesn’t do much; it implements a pseudo-value that’s larger than everything but itself.

>>> infinity = Largest()
>>> greatest = Largest()
>>> 6234 < infinity
True
>>> 6234 == infinity
False
>>> 6234 > infinity
False
>>> infinity > infinity
False
>>> infinity == greatest
True
class aurora.interval.Smallest[source]

Bases: object

Represents the smallest value

This type doesn’t do much; it implements a pseudo-value that’s smaller than everything but itself.

>>> negInf = Smallest()
>>> smallest = Smallest()
>>> -264 < negInf
False
>>> -264 == negInf
False
>>> -264 > negInf
True
>>> negInf < negInf
False
>>> negInf == smallest
True
class aurora.interval.TimePeriod(**kwargs)[source]

Bases: aurora.interval.Interval

Methods

adjacent_to(other)

Tells whether an Interval is adjacent to the object without overlap

all()

Returns an interval encompassing all values

between(a, b[, closed])

Returns an interval between two values

comes_before(other)

Tells whether an interval lies before the object

equal_to(a)

Returns an point interval

greater_than(a)

Returns interval of all values greater than the given value

greater_than_or_equal_to(a)

Returns interval of all values greater than or equal to the given value

join(other)

Combines two continous Intervals

less_than(a)

Returns interval of all values less than the given value

less_than_or_equal_to(a)

Returns an interval containing the given values and everything less

none()

Returns an empty interval

overlaps(other)

Tells whether the given interval overlaps the object

pad(pad_width)

@note: added 20140618 kkappler returns a padded interval; Intent was to add a little so that open-intervals, or adjacent intervals would easily make an interval set

duration

duration()[source]
aurora.interval.generate_interval_list(startTime, endTime, delta)[source]

generic function used for specifying timeintervals to load probably place in gmi.core.interval

Ideally would support endtime, number of segments or other

aurora.interval.merge_interval_list(interval_list)[source]

Can think of a stack of unassembled parts. Put the first part in your left hand, then draw the next part in your right. Check if the pieces mate, if so, attach and keep in your left hand, draw the next piece, and so on. Once a piece does not fit, place the assembled piece in the left hand down and transfer the new ‘no-fit’ piece from your right to your left hand and contine …

KEY: This assumes the interval list is sorted. If the intervals are not sorted then you need to use set union. This is way faster though.