def __init__(self, ana, dt=0.1, tChunk_min=1, delay=0): """ Create significance calculator with given bg and sg rates Args: ana (:class:`sn.ShapeAnalysis` or :class:`sn.CountingAnalysis` object): analysis to be used for the significance calculation dt (float): time step, seconds tChunk_min (float): minimal time duration of the produced chunk of data delay (float): processing delay in seconds. This means that maximum assumed supernova time will be:: now()-delay-ana.time_window[1] :Input: data (list of float): list of events' timestamps :Output: :snap.datablock.DataBlock: with the SN observation significance """ self.ana = ana self.delay = delay self.t0 = timing.now() - delay self.dt = dt self.tChunk_min = tChunk_min self.data = np.array([])
async def get(self) -> DataBlock: """Calculate the significance and return it in a :snap.DataBlock: """ tw0, tw1 = self.ana.time_window time_start = self.t0 + tw1 - tw0 + self.delay await timing.wait_until(time_start, self.tChunk_min) t1 = timing.now() - self.delay #define time regions ts = np.arange(self.t0 - tw0, t1 - tw1, self.dt) #calculate significance zs = self.ana(self.data, ts) #drop obsolete data t_last = ts[-1] + self.dt self.drop_tail(t_last + tw0) return DataBlock(np.append(ts, t_last), zs)
async def sample_ts(B, S=0, tSN=0, tChunk=10): """ Data :term:`source`, generating random event timestamps following the given rates, with signal injection. Args: B(rate) Background rate vs. time S(rate) Signal rate vs. time from signal start. tSN(float) Delay of the signal to start, after the generator started work. Yields: event timestamp in seconds """ t0 = timing.now() R = st.rate(B) + st.rate(S).shift(t0 + tSN) while True: ts = st.Sampler(R, time_window=[t0, t0 + tChunk]).sample() yield np.sort(ts) t0 += tChunk
async def detonator(delay=10): while True: tSN = timing.now() + delay dist = 1. yield {'tSN': tSN, 'dist': dist}
def __init__(self, B, S=0, tChunk=10): self.S = st.Signal(S, distance=1) self.tChunk = tChunk self.B = st.rate(B) self.R = self.B self.t0 = timing.now()
async def _f(source=_dummy_source): t0 = now() async for data in source: yield data t0+=seconds await wait_until(t0)