threeML.utils.interval module

class threeML.utils.interval.Interval(start: float, stop: float, swap_if_inverted: bool = False)[source]

Bases: object

intersect(interval: threeML.utils.interval.Interval)threeML.utils.interval.Interval[source]

Returns a new time interval corresponding to the intersection between this interval and the provided one.

Parameters

interval (Interval) – a TimeInterval instance

Returns

new interval covering the intersection

:raise IntervalsDoNotOverlap : if the intervals do not overlap

merge(interval: threeML.utils.interval.Interval)threeML.utils.interval.Interval[source]

Returns a new interval corresponding to the merge of the current and the provided time interval. The intervals must overlap.

Parameters

interval – a TimeInterval instance :type interval : Interval

Returns

a new TimeInterval instance

property mid_point
classmethod new(*args, **kwargs)[source]
overlaps_with(interval: threeML.utils.interval.Interval)bool[source]

Returns whether the current time interval and the provided one overlap or not

Parameters

interval (Interval) – a TimeInterval instance

Returns

True or False

property start
property stop
to_string()str[source]

returns a string representation of the time interval that is like the argument of many interval reading funcitons

Returns

class threeML.utils.interval.IntervalSet(list_of_intervals=())[source]

Bases: object

A set of intervals

INTERVAL_TYPE

alias of threeML.utils.interval.Interval

property absolute_start

the minimum of the start times :return:

property absolute_stop

the maximum of the stop times :return:

argsort()[source]

Returns the indices which order the set

Returns

property bin_stack
get a stacked view of the bins [[start_1,stop_1 ],

[start_2,stop_2 ]]

Returns

containing_bin(value)[source]

finds the index of the interval containing :param value: :return:

containing_interval(start, stop, inner=True, as_mask=False)[source]

returns either a mask of the intervals contained in the selection or a new set of intervals within the selection. NOTE: no sort is performed

Parameters
  • start – start of interval

  • stop – stop of interval

  • inner – if True, returns only intervals strictly contained within bounds, if False, returns outer bounds as well

  • as_mask – if you want a mask or the intervals

Returns

property edges

return an array of time edges if contiguous :return:

extend(list_of_intervals)[source]
classmethod from_list_of_edges(edges)[source]

Builds a IntervalSet from a list of time edges:

edges = [-1,0,1] -> [-1,0], [0,1]

Parameters

edges

Returns

classmethod from_starts_and_stops(starts, stops)[source]

Builds a TimeIntervalSet from a list of start and stop times:

start = [-1,0] -> [-1,0], [0,1] stop = [0,1]

Parameters
  • starts

  • stops

Returns

classmethod from_strings(*intervals)[source]

These are intervals specified as “-10 – 5”, “0-10”, and so on

Parameters

intervals

Returns

is_contiguous(relative_tolerance=1e-05)[source]

Check whether the time intervals are all contiguous, i.e., the stop time of one interval is the start time of the next

Returns

True or False

property is_sorted

Check whether the time intervals are sorted :return: True or False

merge_intersecting_intervals(in_place=False)[source]

merges intersecting intervals into a contiguous intervals

Returns

property mid_points
classmethod new(*args, **kwargs)[source]

Create a new interval set of this type :param args: :param kwargs: :return: interval set

classmethod new_interval(*args, **kwargs)[source]

Create a new interval of INTERVAL_TYPE :param args: :param kwargs: :return: interval

pop(index)[source]
sort()[source]

Returns a sorted copy of the set (sorted according to the tstart of the time intervals)

Returns

property starts

Return the starts fo the set

Returns

list of start times

property stops

Return the stops of the set

Returns

to_string()[source]

returns a set of string representaitons of the intervals :return:

property widths
exception threeML.utils.interval.IntervalsDoNotOverlap[source]

Bases: RuntimeError

exception threeML.utils.interval.IntervalsNotContiguous[source]

Bases: RuntimeError