Timespan

class lsst.daf.butler.Timespan

Bases: typing.Generic, tuple

A generic 2-element named tuple for time intervals.

Parameters:
begin : T, optional

Minimum timestamp in the interval (inclusive). None is interpreted as -infinity.

end : T, optional

Maximum timestamp in the interval (inclusive). None is interpreted as +infinity.

Notes

This class is generic because it is used for both Python literals (with T == astropy.time.Time) and timestamps in SQLAlchemy expressions (with T == sqlalchemy.sql.ColumnElement), including operations between those.

Python’s built-in collections.namedtuple is not actually a type (just a factory for types), and typing.NamedTuple doesn’t support generics, so neither can be used here (but also wouldn’t add much even if they could).

Attributes Summary

begin Minimum timestamp in the interval (inclusive).
end Maximum timestamp in the interval (inclusive).

Methods Summary

count($self, value, /) Return number of occurrences of value.
index($self, value[, start, stop]) Return first index of value.
intersection() Return a new Timespan that is contained by all of the given ones.
overlaps(other[, ops]) Test whether this timespan overlaps another.

Attributes Documentation

begin

Minimum timestamp in the interval (inclusive).

None should be interpreted as -infinity.

end

Maximum timestamp in the interval (inclusive).

None should be interpreted as +infinity.

Methods Documentation

count($self, value, /)

Return number of occurrences of value.

index($self, value, start=0, stop=sys.maxsize, /)

Return first index of value.

Raises ValueError if the value is not present.

intersection() → Optional[lsst.daf.butler.core.timespan.Timespan]

Return a new Timespan that is contained by all of the given ones.

Parameters:
*args

All positional arguments are Timespan instances.

Returns:
intersection : Timespan or None

The intersection timespan, or None, if there is no intersection or no arguments.

Notes

Unlike overlaps, this method does not support SQLAlchemy column expressions as operands.

overlaps(other, ops=<module 'operator' from '/opt/lsst/software/stack/python/miniconda3-4.7.12/envs/lsst-scipipe-984c9f7/lib/python3.7/operator.py'>) → Any

Test whether this timespan overlaps another.

Parameters:
other : Timespan

Another timespan whose begin and end values can be compared with those of self with the >= operator, yielding values that can be passed to ops.or_ and/or ops.and_.

ops : Any, optional

Any object with and_ and or_ boolean operators. Defaults to the Python built-in operator module, which is appropriate when T is a Python literal like astropy.time.Time. When either operand contains SQLAlchemy column expressions, the sqlalchemy.sql module should be used instead.

Returns:
overlaps : Any

The result of the overlap. When ops is operator, this will be a bool. If ops is sqlachemy.sql, it will be a boolean column expression.