예제 #1
0
def init(Nexp, NMC, energy=True, **kwargs):
    Nsrc = kwargs.pop("Nsrc", 0)

    arr_exp = exp(Nexp - Nsrc)
    arr_mc = MC(NMC)

    if Nsrc > 0:
        inj = PointSourceInjector(2, sinDec_bandwidth=1, seed=0)
        inj.fill(0., arr_mc, 333.)

        source = inj.sample(Nsrc, poisson=False).next()[1]

        arr_exp = np.append(arr_exp, source)

    if energy:
        llh_model = PowerLawLLH(["logE"], min(50, Nexp // 50),
                                range=[[0.9 * arr_mc["logE"].min(),
                                        1.1 * arr_mc["logE"].max()]],
                                sinDec_bins=min(50, Nexp // 50),
                                sinDec_range=[-1., 1.],
                                bounds=(0, 5))
    else:
        llh_model = UniformLLH(sinDec_bins=max(3, Nexp // 200),
                               sinDec_range=[-1., 1.])

    llh = PointSourceLLH(arr_exp, arr_mc, 365., llh_model=llh_model,
                         mode="all", hemispheres=dict(Full=[-np.inf, np.inf]),
                         nsource=25, scramble=False,
                         nsource_bounds=(-Nexp / 2., Nexp / 2.)
                                        if not energy else (0., Nexp / 2.),
                         seed=np.random.randint(2**32),
                         **kwargs)

    return llh
예제 #2
0
파일: data.py 프로젝트: mhuber89/skylab
def init(Nexp, NMC, energy=True, **kwargs):
    Nsrc = kwargs.pop("Nsrc", 0)

    arr_exp = exp(Nexp - Nsrc)
    arr_mc = MC(NMC)

    if Nsrc > 0:
        inj = PointSourceInjector(2, sinDec_bandwidth=1, seed=0)
        inj.fill(0., arr_mc, 333.)

        source = inj.sample(Nsrc, poisson=False).next()[1]

        arr_exp = np.append(arr_exp, source)

    if energy:
        llh_model = PowerLawLLH(
            ["logE"],
            min(50, Nexp // 50),
            range=[[0.9 * arr_mc["logE"].min(), 1.1 * arr_mc["logE"].max()]],
            sinDec_bins=min(50, Nexp // 50),
            sinDec_range=[-1., 1.],
            bounds=(0, 5))
    else:
        llh_model = UniformLLH(sinDec_bins=max(3, Nexp // 200),
                               sinDec_range=[-1., 1.])

    llh = PointSourceLLH(arr_exp,
                         arr_mc,
                         365.,
                         llh_model=llh_model,
                         mode="all",
                         hemispheres=dict(Full=[-np.inf, np.inf]),
                         nsource=25,
                         scramble=False,
                         nsource_bounds=(-Nexp / 2.,
                                         Nexp / 2.) if not energy else
                         (0., Nexp / 2.),
                         seed=np.random.randint(2**32),
                         **kwargs)

    return llh
예제 #3
0
results = numpy.empty( [3, nstep+1], dtype=float )

# step through ns values within [ns_min, ns_max]
for step in range(0,nstep+1):

  # compute signal for this step
  ns = ns_min + step*delta

  # compute average TS from 5 samples
  nsample = 5
  avgTS   = 0

  for i in range(0,nsample):

    # get event sample for source
    ni, sample = inj.sample(src_ra, ns, poisson=False).next()

    # compute TS
    TS, Xmin = psllh.fit_source(src_ra,src_dec,inject=sample,scramble = True)

    # add to average
    avgTS = avgTS + TS/nsample

  # END for (i)

  # compute average significance
  sigma = numpy.sqrt(avgTS)

  print " [%3d/%d] ns %7.2f, sigma %6.2f" % (step+1, nstep+1, ns, sigma)

  results[0][step] = ns                  # x
예제 #4
0
파일: llh_scan.py 프로젝트: mhuber89/skylab
        print("\tgamma =", Gamma)
        # init a injector class sampling events at a point source
        inj = PointSourceInjector(Gamma, sinDec_bandwidth=1., seed=0)
        inj.fill(0., mc, 333.)

        n = 25
        gamma = np.linspace(*llh.par_bounds[1], num=n)

        ntrials = 100
        T = list()

        nsources = np.linspace(0.5 * mu, 2. * mu, 2 * n)

        for i in range(ntrials):
            # Inject always the same number of events for this plot
            n_inj, inject = inj.sample(mu, poisson=False).next()

            TS, xmin = llh.fit_source(np.pi, 0., inject=inject)

            X, Y = np.meshgrid(nsources[:-1], gamma[:-1])

            X = X.ravel()
            Y = Y.ravel()

            Z = np.empty_like(X)

            for i, (x, y) in enumerate(zip(X, Y)):
                Z[i] = llh.llh(nsources=x, gamma=y)[0]

            Z = -2. * (Z - Z.max())