76 def __init__(self, ranges):
77 """
78 The ranges variable can either be a list of increasing numbers or a
79 list of pairs of numbers.
80
81 The former case will be treated as
82 defining alternating on/off ranges for sampling, starting with an active
83 one (i.e. it's a list of bin edges). The latter way specifically lists
84 the 'on' regions only, with their start and end values in the pairs.
85
86 The behaviour is undefined if the numbers are not ordered or overlap --
87 i.e. it might work but hasn't been designed that way and might change in
88 future. Don't rely on this behaviour!
89 """
90 if not ranges:
91 raise Exception("You must supply at least one non-null sampling range")
92 if hasattr(ranges[0], "__len__"):
93 assert all(len(x) == 2 for x in ranges)
94 self.ranges = ranges
95 else:
96 assert len(ranges) > 1
97 lows = [x for x in ranges[:-1]]
98 highs = [x for x in ranges[1:]]
99 myranges = []
100 for i, pair in enumerate(zip(lows, highs)):
101 if i % 2 == 0:
102 myranges.append(pair)
103 assert len(myranges) == len(ranges) // 2
104 self.ranges = myranges
105