Пример #1
0
def init86I(**kwargs):
    energy = kwargs.pop('energy', True)
    decorr = kwargs.pop('decorr', False)
    if decorr:
        arr_exp = cache.load(filename_pickle + "IC86I/noMESE/exp.pickle")
        arr_mc = cache.load(filename_pickle + "IC86I/noMESE/mc.pickle")
    else:
        arr_exp = cache.load(filename_pickle + "IC86I/exp.pickle")
        arr_mc = cache.load(filename_pickle + "IC86I/mc.pickle")
    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.2, 10 + 1),
            np.linspace(-0.2, hem, 4 + 1),
            np.linspace(hem, 0.2, 5 + 1),
            np.linspace(0.2, 1., 10),
        ]))
    #check this later, BEN!
    energy_bins = [np.linspace(1., 10., 67 + 1), dec_bins]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(sinDec_bins=dec_bins, sinDec_range=[-1., 1.])

    llh = StackingPointSourceLLH(arr_exp,
                                 arr_mc,
                                 livetime=livetime_IC86I,
                                 llh_model=llh_model,
                                 seed=np.random.randint(2**32),
                                 **kwargs)

    return llh
Пример #2
0
def init3yr(**kwargs):
    energy = kwargs.pop('energy', True)
    decorr = kwargs.pop('decorr', False)
    if decorr:
        arr_exp = cache.load(filename_pickle + "epinat_3yr/noMESE/exp.pickle")
        arr_mc = cache.load(filename_pickle + "epinat_3yr/noMESE/mc.pickle")
    else:
        arr_exp = cache.load(filename_pickle + "epinat_3yr/exp.pickle")
        arr_mc = cache.load(filename_pickle + "epinat_3yr/mc.pickle")
    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.93, 4 + 1),
            np.linspace(-0.93, -0.3, 10 + 1),
            np.linspace(-0.3, 0.05, 9 + 1),
            np.linspace(0.05, 1., 18 + 1),
        ]))

    energy_bins = [np.linspace(1., 9.5, 50 + 1), dec_bins]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(sinDec_bins=dec_bins, sinDec_range=[-1., 1.])

    llh = StackingPointSourceLLH(arr_exp,
                                 arr_mc,
                                 livetime=livetime3yr,
                                 llh_model=llh_model,
                                 seed=np.random.randint(2**32),
                                 **kwargs)

    return llh
Пример #3
0
def init79_sirin(**kwargs):
    energy = kwargs.pop('energy', True)
    decorr = kwargs.pop('decorr', False)
    if decorr:
        arr_exp = cache.load(filename_pickle + "sirin_IC79/noMESE/exp.pickle")
        arr_mc = cache.load(filename_pickle + "sirin_IC79/noMESE/mc.pickle")
    else:
        arr_exp = cache.load(filename_pickle + "sirin_IC79/exp.pickle")
        arr_mc = cache.load(filename_pickle + "sirin_IC79/mc.pickle")

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.75, 10 + 1),
            np.linspace(-0.75, 0.0, 15 + 1),
            np.linspace(0.0, 1., 20 + 1),
        ]))

    energy_bins = [np.linspace(2., 9., 67 + 1), dec_bins]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)
    else:

        llh_model = ClassicLLH(sinDec_bins=dec_bins, sinDec_range=[-1., 1.])

    #Why a different sindec binning? Curious...
    llh = StackingPointSourceLLH(arr_exp,
                                 arr_mc,
                                 livetime=livetime_IC79_sirin,
                                 llh_model=llh_model,
                                 seed=np.random.randint(2**32),
                                 **kwargs)

    return llh
Пример #4
0
def initMESEfollowup(**kwargs):
    energy = kwargs.pop('energy', True)
    arr_exp = cache.load(filename_pickle + "MESE/expfollowup.pickle")
    arr_mc = cache.load(filename_pickle + "MESE/mc.pickle")

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.93, 4 + 1),
            np.linspace(-0.93, hem, 12 + 1),
        ]))

    energy_bins = [np.linspace(2., 8.5, 67 + 1), np.linspace(-1., hem, 4 + 1)]

    arr_mc = arr_mc[arr_mc["logE"] > 1.]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(sinDec_bins=dec_bins, sinDec_range=[-1., 1.])

    llh = StackingPointSourceLLH(arr_exp,
                                 arr_mc,
                                 livetime=livetimeMESEfollowup,
                                 llh_model=llh_model,
                                 seed=np.random.randint(2**32),
                                 **kwargs)

    return llh
Пример #5
0
def mese_followup(**kwargs):
    livetime = 988.54
    livetime += 358.402
    livetime += 368.381
    print("\tLoading MESE with 2 follow-up years...")
    exp = np.append(np.load(os.path.join(path, "MESE_exp.npy")),
                    np.load(os.path.join(path, "MESE_followup_exp.npy")))

    mc = np.load(os.path.join(path, "MESE_MC.npy"))

    if "dist" in exp.dtype.names:
        exp = drop_fields(exp, ["dist"], usemask=False)
    if "dist" in mc.dtype.names:
        mc = drop_fields(mc, ["dist"], usemask=False)

    sinDec = kwargs.pop("sinDec", [-1., hem])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] < sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] < sinDec[-1])]

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.93, 4 + 1),
            np.linspace(-0.93, hem, 12 + 1),
        ]))

    dec_bins = dec_bins[(dec_bins >= sinDec[0]) & (dec_bins <= sinDec[1])]
    dec_bins = np.unique(np.concatenate([sinDec, dec_bins]))
    dec_bins_logE = np.linspace(-1., hem, 4 + 1)
    dec_bins_logE = dec_bins_logE[(dec_bins_logE >= sinDec[0])
                                  & (dec_bins_logE <= sinDec[1])]
    dec_bins_logE = np.unique(np.concatenate([sinDec, dec_bins_logE]))

    energy_bins = [
        np.linspace(2., 8.5, 67 + 1),
        np.linspace(-1., hem, 4 + 1),
    ]
    mc = mc[mc["logE"] > 1.]
    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)
    kwargs.setdefault("mode", "all")
    kwargs.setdefault("seed", 20101112)
    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Пример #6
0
def init79(energy=False, stacking=True, decorr=False, mode='all', **kwargs):
    if decorr:
        arr_exp = cache.load(filename_pickle + "IC79/noMESE/exp.pickle")
        arr_mc = cache.load(filename_pickle + "IC79/noMESE/mc.pickle")
    else:
        arr_exp = cache.load(filename_pickle + "IC79/exp.pickle")
        arr_mc = cache.load(filename_pickle + "IC79/mc.pickle")

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.75, 10 + 1),
            np.linspace(-0.75, 0.0, 15 + 1),
            np.linspace(0.0, 1., 20 + 1),
        ]))

    energy_bins = [np.linspace(2., 9., 67 + 1), dec_bins]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

        #llh_model = EnergyLLH(sinDec_bins=dec_bins(50),#min(50, Nexp // 50),
        #                      sinDec_range=[-1., 1.],
        #                      logE_bins=min(50, Nexp // 50), #energybins(50)
        #                      logE_range=[[0.9 * min(arr_exp["logE"].min(),
        #                                               arr_mc["logE"].min()),
        #                                     1.1 * max(arr_exp["logE"].max(),
        #                                               arr_mc["logE"].max())],
        #                                     [-1., 1.]])
    else:

        llh_model = ClassicLLH(  #["logE"], min(50, Nexp // 50),
            #twodim_range=[0.9 * arr_mc["logE"].min(),
            #             1.1 * arr_mc["logE"].max()],
            sinDec_bins=dec_bins,
            sinDec_range=[-1., 1.])

    if stacking:
        llh = StackingPointSourceLLH(arr_exp,
                                     arr_mc,
                                     livetime=livetime_IC79,
                                     llh_model=llh_model,
                                     mode=mode,
                                     seed=np.random.randint(2**32),
                                     **kwargs)
    else:
        llh = PointSourceLLH(arr_exp,
                             arr_mc,
                             livetime=livetime_IC79,
                             llh_model=llh_model,
                             mode=mode,
                             seed=np.random.randint(2**32),
                             **kwargs)
    return llh
Пример #7
0
def ic86_I(**kwargs):
    livetime = 332.61
    print("\tLoading IC86 data...")

    decorr = kwargs.pop("no_mese", False)

    if decorr:
        print("\t\tRemove MESE from exp and MC")
        exp = np.load(os.path.join(path, "IC86_noMESE_exp.npy"))
        mc = np.load(os.path.join(path, "IC86_noMESE_corrected_MC.npy"))
    else:
        exp = np.load(os.path.join(path, "IC86_exp.npy"))
        mc = np.load(os.path.join(path, "IC86_corrected_MC.npy"))

    sinDec = kwargs.pop("sinDec", [-1., 1.])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] < sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] < sinDec[-1])]

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.2, 10 + 1),
            np.linspace(-0.2, hem, 4 + 1),
            np.linspace(hem, 0.2, 5 + 1),
            np.linspace(0.2, 1., 10),
        ]))

    dec_bins = dec_bins[(dec_bins >= sinDec[0]) & (dec_bins <= sinDec[1])]
    dec_bins = np.unique(np.concatenate([sinDec, dec_bins]))

    energy_bins = [np.linspace(1., 10., 40 + 1), dec_bins]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2011)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Пример #8
0
def init59(energy=False, mode='all', **kwargs):
    arr_exp = cache.load(filename_pickle+"sirin_IC59/exp.pickle")
    arr_mc = cache.load(filename_pickle+"sirin_IC59/mc.pickle")

    dec_bins = np.unique(np.concatenate([
                           np.linspace(-1., -0.95, 2 + 1),
                           np.linspace(-0.95, -0.25, 25 + 1),
                           np.linspace(-0.25, 0.05, 15 + 1),
                           np.linspace(0.05, 1., 10 + 1),
                           ]))    

    dec_bins_logE = np.unique(np.concatenate([
                           np.linspace(-1., -0.05, 20 + 1),
                           np.linspace(0.05, 1., 10 + 1),
                           ]))     

    energy_bins = [np.linspace(2., 9.5, 67 + 1), dec_bins_logE]

    if energy:

        llh_model = EnergyLLH(energy_bins,
                          sinDec_bins=dec_bins)
        
        #llh_model = EnergyLLH(sinDec_bins=dec_bins(50),#min(50, Nexp // 50),
        #                      sinDec_range=[-1., 1.],
        #                      logE_bins=min(50, Nexp // 50), #energybins(50)
        #                      logE_range=[[0.9 * min(arr_exp["logE"].min(),
        #                                               arr_mc["logE"].min()),
        #                                     1.1 * max(arr_exp["logE"].max(),
        #                                               arr_mc["logE"].max())],
        #                                     [-1., 1.]]) 
    else:

        llh_model = ClassicLLH(#["logE"], min(50, Nexp // 50),
                                #twodim_range=[0.9 * arr_mc["logE"].min(),
                                 #             1.1 * arr_mc["logE"].max()],
                                sinDec_bins=dec_bins,
                                sinDec_range=[-1., 1.])

    #Why a different sindec binning? Curious...
    llh = StackingPointSourceLLH(arr_exp, arr_mc, livetime=livetime_IC59, llh_model=llh_model,
                         mode=mode, #hemispheres=dict(Full=[-np.inf, np.inf]),
                         #nsource=Nexp / 100.,
                         #nsource_bounds=(-Nexp / 2., Nexp / 2.)
                         #               if not energy else (0., Nexp / 2.),
                         seed=np.random.randint(2**32),
                         **kwargs)

    return llh
Пример #9
0
def init40(energy=False, stacking=True, mode='all', nopull=False, **kwargs):
    if nopull:
        arr_exp = cache.load(filename_pickle + "nopull/sirin_IC40/exp.pickle")
        arr_mc = cache.load(filename_pickle + "nopull/sirin_IC40/mc.pickle")
    else:
        arr_exp = cache.load(filename_pickle + "IC40/exp.pickle")
        arr_mc = cache.load(filename_pickle + "IC40/mc.pickle")

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 5 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))

    dec_bins_logE = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 10 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))
    #These binnings are done, year specifically, in load.py from stefan.
    energy_bins = [np.linspace(2., 9., 75 + 1), dec_bins_logE]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(sinDec_bins=dec_bins, sinDec_range=[-1., 1.])
    if stacking:
        llh = StackingPointSourceLLH(arr_exp,
                                     arr_mc,
                                     livetime=livetime_IC40,
                                     llh_model=llh_model,
                                     mode=mode,
                                     seed=np.random.randint(2**32),
                                     **kwargs)
    else:
        llh = PointSourceLLH(arr_exp,
                             arr_mc,
                             livetime=livetime_IC40,
                             llh_model=llh_model,
                             mode=mode,
                             seed=np.random.randint(2**32),
                             **kwargs)

    return llh
Пример #10
0
def initMESE3yr(energy=False, stacking=True, mode='all', **kwargs):
    arr_exp = cache.load(filename_pickle + "MESE/exp3yr.pickle")
    arr_mc = cache.load(filename_pickle + "MESE/mc.pickle")

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.92, 3 + 1),
            np.linspace(-0.92, hem, 10 + 1),
        ]))

    energy_bins = [
        np.linspace(2., 8.5, 40 + 1),
        np.linspace(-1., hem, 4 + 1),
    ]

    arr_mc = arr_mc[arr_mc["logE"] > 1.]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(  #["logE"], min(50, Nexp // 50),
            #twodim_range=[0.9 * arr_mc["logE"].min(),
            #             1.1 * arr_mc["logE"].max()],
            sinDec_bins=dec_bins,
            sinDec_range=[-1., 1.])

    if stacking:
        llh = StackingPointSourceLLH(arr_exp,
                                     arr_mc,
                                     livetime=livetimeMESE3yr,
                                     llh_model=llh_model,
                                     mode=mode,
                                     seed=np.random.randint(2**32),
                                     **kwargs)
    else:
        llh = PointSourceLLH(arr_exp,
                             arr_mc,
                             livetime=livetimeMESE3yr,
                             llh_model=llh_model,
                             mode=mode,
                             seed=np.random.randint(2**32),
                             **kwargs)

    return llh
Пример #11
0
def init3yr(energy=False, stacking=True, decorr=False, mode='all', **kwargs):
    if decorr:
        arr_exp = cache.load(filename_pickle + "epinat_3yr/noMESE/exp.pickle")
        arr_mc = cache.load(filename_pickle + "epinat_3yr/noMESE/mc.pickle")
    else:
        arr_exp = cache.load(filename_pickle + "epinat_3yr/exp.pickle")
        arr_mc = cache.load(filename_pickle + "epinat_3yr/mc.pickle")
    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.93, 4 + 1),
            np.linspace(-0.93, -0.3, 10 + 1),
            np.linspace(-0.3, 0.05, 9 + 1),
            np.linspace(0.05, 1., 18 + 1),
        ]))

    energy_bins = [np.linspace(1., 9.5, 50 + 1), dec_bins]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(  #["logE"], min(50, Nexp // 50),
            #twodim_range=[0.9 * arr_mc["logE"].min(),
            #             1.1 * arr_mc["logE"].max()],
            sinDec_bins=dec_bins,
            sinDec_range=[-1., 1.])

    if stacking:
        llh = StackingPointSourceLLH(arr_exp,
                                     arr_mc,
                                     livetime=livetime3yr,
                                     llh_model=llh_model,
                                     mode=mode,
                                     seed=np.random.randint(2**32),
                                     **kwargs)
    else:
        llh = PointSourceLLH(arr_exp,
                             arr_mc,
                             livetime=livetime3yr,
                             llh_model=llh_model,
                             mode=mode,
                             seed=np.random.randint(2**32),
                             **kwargs)

    return llh
Пример #12
0
def init86I(energy=False,  mode='all', **kwargs):
    arr_exp = cache.load(filename_pickle+"sirin_IC86I/exp.pickle")
    arr_mc = cache.load(filename_pickle+"sirin_IC86I/mc.pickle")
    #This hem... not sure about what it means, but stefan uses it in load.py.
    #Obviously it's for the hemisphere line - but why doesn't he use it for every year?
    hem = np.sin(np.radians(-5.))
    dec_bins = np.unique(np.concatenate([
                         np.linspace(-1., -0.2, 10 + 1),
                         np.linspace(-0.2, hem, 4 + 1),
                         np.linspace(hem, 0.2, 5 + 1),
                         np.linspace(0.2, 1., 10),
                         ]))
    #check this later, BEN!
    energy_bins = [np.linspace(1., 10., 67 + 1), dec_bins]

    if energy:

        llh_model = EnergyLLH(energy_bins,
                          sinDec_bins=dec_bins)
        
        #llh_model = EnergyLLH(sinDec_bins=dec_bins(50),#min(50, Nexp // 50),
        #                      sinDec_range=[-1., 1.],
        #                      logE_bins=min(50, Nexp // 50), #energybins(50)
        #                      logE_range=[[0.9 * min(arr_exp["logE"].min(),
        #                                               arr_mc["logE"].min()),
        #                                     1.1 * max(arr_exp["logE"].max(),
        #                                               arr_mc["logE"].max())],
        #                                     [-1., 1.]]) 
    else:

        llh_model = ClassicLLH(#["logE"], min(50, Nexp // 50),
                                #twodim_range=[0.9 * arr_mc["logE"].min(),
                                 #             1.1 * arr_mc["logE"].max()],
                                sinDec_bins=dec_bins,
                                sinDec_range=[-1., 1.])

    #Why a different sindec binning? Curious...
    llh = StackingPointSourceLLH(arr_exp, arr_mc, livetime=livetime_IC86I, llh_model=llh_model,
                         mode=mode, #hemisphere=dict(Full=[-np.inf, np.inf]),
                         #nsource=Nexp / 100.,
                         #nsource_bounds=(-Nexp / 2., Nexp / 2.)
                         #               if not energy else (0., Nexp / 2.),
                         seed=np.random.randint(2**32),
                         **kwargs)

    return llh
Пример #13
0
def ic40(**kwargs):
    livetime = 375.539
    print("\tLoading IC40 data...")
    exp = np.load(os.path.join(path, "IC40_exp.npy"))
    mc = np.load(os.path.join(path, "IC40_MC.npy"))

    #dec_bins = np.linspace(-1., 1., 25 + 1)

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 5 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))

    dec_bins_logE = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 10 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))

    energy_bins = [np.linspace(1., 10., 35 + 1), dec_bins_logE]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2008)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Пример #14
0
def ic79(**kwargs):
    livetime = 315.506
    print("\tLoading IC79 data...")

    decorr = kwargs.pop("no_mese", False)

    if decorr:
        print("\t\tRemove MESE from exp and MC")
        exp = np.load(os.path.join(path, "IC79_noMESE_exp.npy"))
        mc = np.load(os.path.join(path, "IC79_noMESE_corrected_MC.npy"))
    else:
        exp = np.load(os.path.join(path, "IC79_exp.npy"))
        mc = np.load(os.path.join(path, "IC79_corrected_MC.npy"))

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.75, 10 + 1),
            np.linspace(-0.75, 0., 15 + 1),
            np.linspace(0., 1., 20 + 1)
        ]))

    energy_bins = [np.linspace(2., 9., 40 + 1), dec_bins]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2010)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Пример #15
0
def init40(energy=False, mode='all', **kwargs):
    arr_exp = cache.load(filename_pickle+"sirin_IC40/exp.pickle")
    arr_mc = cache.load(filename_pickle+"sirin_IC40/mc.pickle")

    dec_bins = np.unique(np.concatenate([
                           np.linspace(-1., -0.25, 10 + 1),
                           np.linspace(-0.25, 0.0, 5 + 1),
                           np.linspace(0.0, 1., 10 + 1),
                           ]))    

    dec_bins_logE = np.unique(np.concatenate([
                           np.linspace(-1., -0.25, 10 + 1),
                           np.linspace(-0.25, 0.0, 10 + 1),
                           np.linspace(0.0, 1., 10 + 1),
                           ]))     
    #These binnings are done, year specifically, in load.py from stefan.
    energy_bins = [np.linspace(2., 9., 75 + 1), dec_bins_logE]

    if energy:

        llh_model = EnergyLLH(energy_bins,
                          sinDec_bins=dec_bins)
        
    else:

        llh_model = ClassicLLH(#["logE"], min(50, Nexp // 50),
                                #twodim_range=[0.9 * arr_mc["logE"].min(),
                                 #             1.1 * arr_mc["logE"].max()],
                                sinDec_bins=dec_bins,
                                sinDec_range=[-1., 1.])

    #Why a different sindec binning? Curious...
    llh = StackingPointSourceLLH(arr_exp, arr_mc, livetime=livetime_IC40, llh_model=llh_model,
                         mode=mode, #hemispheres=dict(Full=[-np.inf, np.inf]),
                         #nsource=Nexp / 100.,
                         #nsource_bounds=(-Nexp / 2., Nexp / 2.)
                         #               if not energy else (0., Nexp / 2.),
                         seed=np.random.randint(2**32),
                         **kwargs)

    return llh
Пример #16
0
def mese(**kwargs):
    livetime = 988.54
    print("\tLoading MESE...")
    exp = np.load(os.path.join(path, "MESE_exp.npy"))
    mc = np.load(os.path.join(path, "MESE_MC.npy"))

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.92, 3 + 1),
            np.linspace(-0.92, hem, 10 + 1),
        ]))

    energy_bins = [
        np.linspace(2., 8.5, 40 + 1),
        np.linspace(-1., hem, 4 + 1),
    ]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("mode", "all")

    kwargs.setdefault("seed", 20101112)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Пример #17
0
def init59(**kwargs):
    energy = kwargs.pop('energy', True)
    arr_exp = cache.load(filename_pickle + "IC59/exp.pickle")
    arr_mc = cache.load(filename_pickle + "IC59/mc.pickle")

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.95, 2 + 1),
            np.linspace(-0.95, -0.25, 25 + 1),
            np.linspace(-0.25, 0.05, 15 + 1),
            np.linspace(0.05, 1., 10 + 1),
        ]))

    dec_bins_logE = np.unique(
        np.concatenate([
            np.linspace(-1., -0.05, 20 + 1),
            np.linspace(0.05, 1., 10 + 1),
        ]))

    energy_bins = [np.linspace(2., 9.5, 67 + 1), dec_bins_logE]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(sinDec_bins=dec_bins, sinDec_range=[-1., 1.])

    llh = StackingPointSourceLLH(arr_exp,
                                 arr_mc,
                                 livetime=livetime_IC59,
                                 llh_model=llh_model,
                                 seed=np.random.randint(2**32),
                                 **kwargs)

    return llh
Пример #18
0
def init40(**kwargs):
    energy = kwargs.pop('energy', True)
    arr_exp = cache.load(filename_pickle + "IC40/exp.pickle")
    arr_mc = cache.load(filename_pickle + "IC40/mc.pickle")

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 5 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))

    dec_bins_logE = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 10 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))
    #These binnings are done, year specifically, in load.py from stefan.
    energy_bins = [np.linspace(2., 9., 75 + 1), dec_bins_logE]

    if energy:

        llh_model = EnergyLLH(energy_bins, sinDec_bins=dec_bins)

    else:

        llh_model = ClassicLLH(sinDec_bins=dec_bins, sinDec_range=[-1., 1.])
        print("using classic llh")
    llh = StackingPointSourceLLH(arr_exp,
                                 arr_mc,
                                 livetime=livetime_IC40,
                                 llh_model=llh_model,
                                 seed=np.random.randint(2**32),
                                 **kwargs)
    return llh
Пример #19
0
def ic86_2012(dataset=[2012, 2013], **kwargs):
    lt12 = 331.358
    lt13 = 359.768
    lt14 = 367.209
    livetime = 0.
    exp = list()

    decorr = kwargs.pop("no_mese", False)

    if 2012 in dataset:
        livetime += lt12
        print("\tLoading IC86-2012 ...")
        if decorr:
            print("\t\tRemove MESE from IC86-2012 exp")
            exp.append(np.load(os.path.join(path, "IC86-2012_noMESE_exp.npy")))
        else:
            exp.append(np.load(os.path.join(path, "IC86-2012_exp.npy")))
    if 2013 in dataset:
        livetime += lt13
        print("\tLoading IC86-2013 ...")
        exp.append(np.load(os.path.join(path, "IC86-2013_exp.npy")))

    if 2014 in dataset:
        livetime += lt14
        print("\tLoading IC86-2014 ...")
        exp.append(np.load(os.path.join(path, "IC86-2014_exp.npy")))

    exp = np.concatenate(exp)
    if decorr:
        print("\t\tRemove MESE from IC86-2012 MC")
        mc = np.load(os.path.join(path, "IC86-2012_noMESE_MC.npy"))
    else:
        mc = np.load(os.path.join(path, "IC86-2012_MC.npy"))

    sinDec = kwargs.pop("sinDec", [-1., 1.])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] < sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] < sinDec[-1])]

    exp = drop_fields(exp, ["BDT"])
    mc = drop_fields(mc, ["BDT"])

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.93, 4 + 1),
            np.linspace(-0.93, -0.3, 10 + 1),
            np.linspace(-0.3, 0.05, 9 + 1),
            np.linspace(0.05, 1., 18 + 1),
        ]))
    dec_bins = dec_bins[(dec_bins >= sinDec[0]) & (dec_bins <= sinDec[1])]
    dec_bins = np.unique(np.concatenate([sinDec, dec_bins]))

    energy_bins = [np.linspace(1., 9.5, 50 + 1), dec_bins]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2012)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Пример #20
0
def ic86_2012_precut(**kwargs):
    livetime = 331.88
    print("\tLoading IC86-II with precut applied...")
    exp = np.load(os.path.join(path, "IC86-2012-precut_exp.npy"))
    mc = np.load(os.path.join(path, "IC86-2012-precut_MC.npy"))

    sinDec = kwargs.pop("sinDec", [-1., 1.])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] <= sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] <= sinDec[-1])]

    if "perc" in kwargs:
        perc = kwargs.pop("perc")
        print("\tCutting on percentage {0:8.3%}".format(perc))

        nbins = 400
        h, bins = np.histogram(exp["sinDec"], bins=nbins, range=sinDec)
        NpB = perc * np.sum(h, dtype=np.float) / nbins
        eps = np.zeros_like(h, dtype=np.float)
        eps[h > 0] = NpB / h[h > 0]
        eps[eps > 1] = 1.
        xdec = np.array([])
        ybdt = np.array([])
        for eps_i, lbin, ubin in zip(eps, bins[:-1], bins[1:]):
            m = (exp["sinDec"] > lbin) & (exp["sinDec"] < ubin)
            if not np.any(m):
                print("No events in", lbin, ubin)
                continue
            bdt_cut = np.percentile(exp["BDT"][m], 100. * (1. - eps_i))
            np.set_printoptions(precision=4)
            xdec = np.append(xdec, (lbin + ubin) / 2.)
            ybdt = np.append(ybdt, bdt_cut)

        pol = np.polyfit(xdec, ybdt, 6)

        N1 = len(exp)

        polexp = np.polyval(pol, exp["sinDec"])
        polmc = np.polyval(pol, mc["sinDec"])

        mexp = exp["BDT"] > polexp
        mmc = mc["BDT"] > polmc

        exp = exp[mexp]
        mc = mc[mmc]

        N2 = len(exp)

        print("\tCut: {0:7.2%}".format(float(N2) / N1))

    elif "bdt" in kwargs and "bdt2" in kwargs:
        comp = kwargs.pop("comp", np.logical_or)
        bdt = kwargs.pop("bdt")
        if not callable(bdt):
            print("\tCutting on bdt {0:5.3f}".format(bdt))
            bdt_val = bdt
            bdt = lambda cz: bdt_val * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt(np.asarray(sinDec))))
        bdt2 = kwargs.pop("bdt2")
        if not callable(bdt2):
            print("\tCutting on bdt2 {0:5.3f}".format(bdt2))
            bdt_val2 = bdt2
            bdt2 = lambda cz: bdt_val2 * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt2 from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt2(np.asarray(sinDec))))
        exp = exp[comp(exp["BDT"] > bdt(exp["sinDec"]),
                       exp["BDT2"] > bdt2(exp["sinDec"]))]
        mc = mc[comp(mc["BDT"] > bdt(mc["sinDec"]),
                     mc["BDT2"] > bdt2(mc["sinDec"]))]

    elif "bdt" in kwargs:
        bdt = kwargs.pop("bdt")
        if not callable(bdt):
            print("\tCutting on bdt {0:5.3f}".format(bdt))
            bdt_val = bdt
            bdt = lambda cz: bdt_val * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt(np.asarray(sinDec))))
        exp = exp[exp["BDT"] > bdt(exp["sinDec"])]
        mc = mc[mc["BDT"] > bdt(mc["sinDec"])]
    elif "bdt2" in kwargs:
        bdt = kwargs.pop("bdt2")
        if not callable(bdt):
            print("\tCutting on bdt2 {0:5.3f}".format(bdt))
            bdt_val = bdt
            bdt = lambda cz: bdt_val * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt(np.asarray(sinDec))))
        exp = exp[exp["BDT2"] > bdt(exp["sinDec"])]
        mc = mc[mc["BDT2"] > bdt(mc["sinDec"])]

    nmin = 10
    nbins = 40
    dec_bins = np.linspace(*sinDec, num=nbins)
    while np.any(np.histogram(exp["sinDec"], bins=dec_bins)[0] < nmin):
        print("Found close-to-empty bins, reduce binsize")
        h, b = np.histogram(exp["sinDec"], bins=dec_bins)
        b = np.array([b[1:], b[:-1]])
        print(b[:, h < nmin])
        if nbins < 2:
            raise ValueError("Need more than 2 bins!")
        nbins -= 1
        dec_bins = np.linspace(*sinDec, num=nbins)

    energy_bins = [np.linspace(0., 9.5, 30 + 1), dec_bins]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", 332.61)  #livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2012)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    if "pol" in locals():
        llh.pol = pol

    print("{0:>80s}".format("[done]"))
    return llh