Example #1
0
def test_llr_const_single(t0, t_data, time_window):
    with pytest.raises(ValueError):
        llr = sn.LLR(sn.DetConfig(1, 2))

    l = sn.LLR(sn.DetConfig(1, 1, time_window=time_window))
    if (time_window[0] <= t_data - t0 <= time_window[1]):
        assert l(t_data, t0) == np.log(2)
    else:
        assert l(t_data, t0) == 0
Example #2
0
def ShapeAna(B, S, time_window="auto", *, dt=0.1, tChunk_min=1, delay=0):
    """ Processing :term:`step`: shape analysis to calculate significance

    Args:
        B (rate)
            Background rate
        S (rate)
            Signal rate
        time_window (tuple (float, float) or "auto")
            A relative time window to count the interactions, for example :code:`[-5,5]`.
            Only interactions within the time window affect current significance.
            If "auto", try to get the range from signal shape.

    Keyword Args:
        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 
    """

    ana = sn.ShapeAnalysis(sn.DetConfig(B=B, S=S, time_window=time_window))
    return SignificanceCalculator(ana, dt, tChunk_min, delay)
Example #3
0
def test_shapeana():
    B = sn.rate(1)
    S = sn.rate(2, range=[-1, 1])
    det = sn.DetConfig(S=S, B=B)
    ana = sn.ShapeAnalysis([det])
    assert ana is not None
Example #4
0
#define the rates
S = sn.rate(([0, 1, 10], [0, 2, 0])) * 100
B = sn.rate(800)

Tsn = 0.
#total event rate vs time
R = B + S.shift(Tsn)

T0, T1 = -60, 60

#create the dataset via sampler
s = sn.Sampler(R, time_window=[T0, T1])
ts = s.sample()

#detector configuration
det = sn.DetConfig(B=B, S=S)
print(det)

#assumed supernova start times
t0s = np.linspace(T0 + det.time_window[0], T1 - det.time_window[1], 501)

sa = sn.ShapeAnalysis(det)
ca = sn.CountingAnalysis(det)

#calculate TS vs time
ls_s = sa.l_val(ts, t0s)
ls_c = ca.l_val(ts, t0s)

#calculate z vs time
zs_s = sa(ts, t0s)
zs_c = ca(ts, t0s)
Example #5
0
#!/bin/env python

import sn_stat as sn
import numpy as np
import pylab as plt

#define the rates
sg1 = sn.signals.ccSN(S0=2)
sg2 = sn.signals.ccSN(S0=5, t_rise=2, t_decay=3)
#sg2 = sn.rate(([-5,0,1,5],[0,1,4,0]))

det1 = sn.DetConfig(B=0.1, S=sg1.at(1), time_window=[-5, 10])
det2 = sn.DetConfig(B=1, S=sg2.at(1), time_window=[-5, 10])

detectors = [det1, det2]
Tsn = 0.
T0, T1 = -60, 60
Rs = []
for det in [det1, det2]:
    print(det)
    #total event rate vs time
    R = det.B + det.S.shift(Tsn)
    det.rate = R
    #create the dataset via sampler
    s = sn.Sampler(R, time_window=[T0, T1])
    det.data = s.sample()

#maximum time window:
tw = [
    max(d.time_window[0] for d in detectors),
    min(d.time_window[1] for d in detectors)