https://sppas.org/

SPPAS 4.16

Module sppas.src.anndata

Class sppasDisjoint

Description

Localization of a serie of intervals in time.

Constructor

Create a new sppasDisjoint instance.

Parameters

  • intervals: (list of sppasInterval)
def __init__(self, intervals=None):
    """Create a new sppasDisjoint instance.

    :param intervals: (list of sppasInterval)

    """
    super(sppasDisjoint, self).__init__()
    self.__intervals = list()
    if intervals is not None:
        self.set_intervals(intervals)

Public functions

set

Set self members from another sppasDisjoint instance.

Parameters

  • other: (sppasDisjoint)
def set(self, other):
    """Set self members from another sppasDisjoint instance.

        :param other: (sppasDisjoint)

        """
    if isinstance(other, sppasDisjoint) is True:
        self.set_intervals(other.get_intervals())
    elif isinstance(other, sppasInterval) is True:
        self.set_intervals([other])
    else:
        raise AnnDataTypeError(other, 'sppasDisjoint or sppasInterval')
is_disjoint

Return True because self is representing a disjoint intervals.

def is_disjoint(self):
    """Return True because self is representing a disjoint intervals."""
    return True
copy

Return a deep copy of self.

def copy(self):
    """Return a deep copy of self."""
    intervals = list()
    for i in self.get_intervals():
        intervals.append(i.copy())
    return sppasDisjoint(intervals)
get_begin

Return the first sppasPoint instance.

def get_begin(self):
    """Return the first sppasPoint instance."""
    return min((interval.get_begin() for interval in self.__intervals))
set_begin

Set the begin sppasPoint instance to new sppasPoint.

Parameters

  • tp: (sppasPoint)
def set_begin(self, tp):
    """Set the begin sppasPoint instance to new sppasPoint.

        :param tp: (sppasPoint)

        """
    _min = self.get_begin()
    for interval in self.__intervals:
        if interval.get_begin() == _min:
            interval.set_begin(tp)
get_end

Return the last sppasPoint instance.

def get_end(self):
    """Return the last sppasPoint instance."""
    return max((interval.get_end() for interval in self.__intervals))
set_end

Set the end sppasPoint instance to new sppasPoint.

Parameters

  • tp: (sppasPoint)
def set_end(self, tp):
    """Set the end sppasPoint instance to new sppasPoint.

        :param tp: (sppasPoint)

        """
    _max = self.get_end()
    for interval in self.__intervals:
        if interval.get_end() == _max:
            interval.set_end(tp)
append_interval

Return the sppasInterval at the given index.

Parameters

  • interval: (sppasInterval)
def append_interval(self, interval):
    """Return the sppasInterval at the given index.

        :param interval: (sppasInterval)

        """
    if isinstance(interval, sppasInterval) is False:
        raise AnnDataTypeError(interval, 'sppasInterval')
    self.__intervals.append(interval)
get_interval

Return the sppasInterval at the given index.

Parameters

  • index: (int)
def get_interval(self, index):
    """Return the sppasInterval at the given index.

        :param index: (int)

        """
    return self.__intervals[index]
get_intervals

Return the list of intervals.

def get_intervals(self):
    """Return the list of intervals."""
    return self.__intervals
set_intervals

Set a new list of intervals.

Parameters

  • intervals: list of sppasInterval.
def set_intervals(self, intervals):
    """Set a new list of intervals.

        :param intervals: list of sppasInterval.

        """
    self.__intervals = list()
    if isinstance(intervals, list) is False:
        raise AnnDataTypeError(intervals, 'list')
    for interval in intervals:
        self.append_interval(interval)
duration

Return the sppasDuration.

Make the sum of all interval' durations.

def duration(self):
    """Return the sppasDuration.

        Make the sum of all interval' durations.

        """
    value = sum((interval.duration().get_value() for interval in self.get_intervals()))
    vagueness = sum((interval.duration().get_margin() for interval in self.get_intervals()))
    return sppasDuration(value, vagueness)
middle

Return a sppasPoint() at the middle of the time interval.

To be tested.

Returns

  • (sppasPoint)
def middle(self):
    """Return a sppasPoint() at the middle of the time interval.

        To be tested.

        :returns: (sppasPoint)

        """
    if len(self.__intervals) == 0:
        return None
    m = float(self.get_begin().get_midpoint() + self.get_end().get_midpoint()) / 2.0
    r = float(self.get_begin().get_radius() + self.get_end().get_radius()) / 2.0
    if self.__intervals[0].is_float():
        return sppasPoint(m, r)
    return sppasPoint(int(m), int(r))
is_bound

Return True if point is a bound of an interval.

Parameters
  • point
def is_bound(self, point):
    """Return True if point is a bound of an interval."""
    return any([i.is_bound(point) for i in self.__intervals])
set_radius

Set radius value to all points.

Parameters
  • radius
def set_radius(self, radius):
    """Set radius value to all points."""
    for i in self.__intervals:
        i.set_radius(radius)
shift

Shift all the intervals to a given delay.

Parameters

  • delay: (int, float) delay to shift bounds

Raises

AnnDataTypeError

def shift(self, delay):
    """Shift all the intervals to a given delay.

        :param delay: (int, float) delay to shift bounds
        :raise: AnnDataTypeError

        """
    for i in self.__intervals:
        i.shift(delay)

Overloads

__format__
def __format__(self, fmt):
    return str(self).__format__(fmt)
__repr__
def __repr__(self):
    return 'sppasDisjoint: {:s}'.format(''.join([str(i) for i in self.get_intervals()]))
__eq__

Equal is required to use '==' between 2 sppasDisjoint instances.

Two disjoint instances are equals iff all its intervals are equals.

Parameters

  • other: (sppasDisjoint) is the other disjoint to compare with.
def __eq__(self, other):
    """Equal is required to use '==' between 2 sppasDisjoint instances.
        Two disjoint instances are equals iff all its intervals are equals.

        :param other: (sppasDisjoint) is the other disjoint to compare with.

        """
    if not isinstance(other, sppasDisjoint):
        return False
    if len(self) != len(other):
        return False
    return all((self.get_interval(i) == other.get_interval(i) for i in range(len(self))))
__lt__

LowerThan is required to use '<' between 2 sppasDisjoint instances.

Parameters

  • other: (sppasDisjoint) is the other disjoint to compare with.
def __lt__(self, other):
    """LowerThan is required to use '<' between 2 sppasDisjoint instances.

        :param other: (sppasDisjoint) is the other disjoint to compare with.

        """
    if isinstance(other, (sppasPoint, float, int)):
        return self.get_end() < other
    if isinstance(other, (sppasInterval, sppasDisjoint)) is False:
        return False
    return self.get_begin() < other.get_begin()
__gt__

GreaterThan is required to use '>' between 2 TimeDisjoint instances.

Parameters

  • other: (sppasDisjoint) is the other disjoint to compare with.
def __gt__(self, other):
    """
        GreaterThan is required to use '>' between 2 TimeDisjoint instances.

        :param other: (sppasDisjoint) is the other disjoint to compare with.

        """
    if isinstance(other, (int, float, sppasPoint)):
        return self.get_begin() > other
    if isinstance(other, (sppasInterval, sppasDisjoint)) is False:
        return False
    return self.get_begin() > other.get_begin()
__iter__
def __iter__(self):
    for a in self.__intervals:
        yield a
__getitem__
def __getitem__(self, i):
    return self.__intervals[i]
__len__
def __len__(self):
    return len(self.__intervals)