示例#1
0
    def test_declination_sensitivity(self):

        logging.info("Testing 'fit_weight' MinimisationHandler class")

        mh_name = "fit_weights"

        # Test three declinations

        unblind_dict = {
            "name": "tests/test_mh_fit_weights",
            "mh_name": mh_name,
            "dataset": icecube_ps_3_year.get_seasons("IC86-2011"),
            "catalogue": catalogue,
            "llh_dict": llh_dict,
        }

        ub = create_unblinder(unblind_dict)
        key = [x for x in ub.res_dict.keys() if x != "TS"][0]
        res = ub.res_dict[key]

        logging.info("Best fit values {0}".format(list(res["x"])))
        logging.info("Reference best fit {0}".format(true_parameters))

        for i, x in enumerate(res["x"]):
            self.assertAlmostEqual(x, true_parameters[i], delta=0.1)

        inj_dict = {
            "injection_sig_time_pdf": {"time_pdf_name": "steady"},
            "injection_bkg_time_pdf": {
                "time_pdf_name": "steady",
            },
            "injection_energy_pdf": {"energy_pdf_name": "power_law", "gamma": 2.0},
        }

        mh_dict = dict(unblind_dict)
        mh_dict["inj_dict"] = inj_dict
        mh_dict["n_trials"] = 1.0
        mh_dict["n_steps"] = 3.0
        mh_dict["scale"] = 5.0

        mh = MinimisationHandler.create(mh_dict)
        res = mh.simulate_and_run(5.0)
        analyse(mh_dict, cluster=False)

        mh.corner_likelihood_scan(
            save=True,
            res_dict=res,
        )
示例#2
0
    def test_flare(self):
        logging.info("Testing 'flare' MinimisationHandler class")

        ub = create_unblinder(unblind_dict, full_plots=True)
        res = [x for x in ub.res_dict["Parameters"].values()]

        logging.info("Best fit values {0}".format(list(res)))
        logging.info("Reference best fit {0}".format(true_parameters))

        for i, x in enumerate(res):
            if i < 2:
                self.assertAlmostEqual(x / true_parameters[i], 1.0, places=1)
            else:
                self.assertEqual(x, true_parameters[i])

        inj_dict = {
            "injection_sig_time_pdf": {
                "time_pdf_name": "steady"
            },
            "injection_bkg_time_pdf": {
                "time_pdf_name": "steady",
            },
            "injection_energy_pdf": {
                "energy_pdf_name": "power_law",
                "gamma": 2.0
            },
        }

        mh_dict = dict(unblind_dict)
        mh_dict["inj_dict"] = inj_dict
        mh_dict["n_trials"] = 1.0
        mh_dict["n_steps"] = 3.0
        mh_dict["scale"] = 5.0

        mh = MinimisationHandler.create(mh_dict)
        res = mh.simulate_and_run(5.0)
        analyse(mh_dict, cluster=False)
示例#3
0
    scale = flux_to_k(reference_sensitivity(sindec)) * 5

    mh_dict = {
        "name": subname,
        "mh_name": "fixed_weights",
        "dataset": ps_v002_p01,
        "catalogue": cat_path,
        "inj_dict": inj_kwargs,
        "llh_dict": llh_kwargs,
        "scale": scale,
        "n_trials": 50,
        "n_steps": 10,
    }

    analyse(mh_dict, cluster=True, n_jobs=100)

    analyses.append(mh_dict)

wait_cluster()

sens = []
sens_err = []
disc_pots = []

for rh_dict in analyses:
    rh = ResultsHandler(rh_dict)
    sens.append(rh.sensitivity)
    sens_err.append(rh.sensitivity_err)
    disc_pots.append(rh.disc_potential)
    mh_dict = {
        "name": subname,
        "mh_name": "fixed_weights",
        "dataset": ps_v003_p02,
        "catalogue": cat_path,
        "inj_dict": inj_kwargs,
        "llh_dict": llh_kwargs,
        "scale": scale,
        "n_trials": 5000,
        "n_steps": 15,
    }

    job_id = analyse(
        mh_dict,
        cluster=cluster,
        n_cpu=1 if cluster else 32,
        h_cpu="23:59:59",
        ram_per_core="8.0G",
    )
    job_ids.append(job_id)

    analyses.append(mh_dict)

wait_cluster(job_ids)

sens = []
sens_err = []
disc_pots = []

for rh_dict in analyses:
    rh = ResultsHandler(rh_dict)
    def test_full_chain(self):

        logging.info("Testing MinimisationHandler analysis chain")

        base_name = "tests/test_analysis_chain"

        try:

            for j, gamma in enumerate([2.0, 2.5]):
                # Initialise Injectors/LLHs

                inj_dict = {
                    "injection_sig_time_pdf": {"time_pdf_name": "steady"},
                    "injection_energy_pdf": {
                        "energy_pdf_name": "power_law",
                        "gamma": gamma,
                    },
                }

                llh_dict = {
                    "llh_name": "standard",
                    "llh_sig_time_pdf": {"time_pdf_name": "steady"},
                    "llh_bkg_time_pdf": {
                        "time_pdf_name": "steady",
                    },
                    "llh_energy_pdf": {"energy_pdf_name": "power_law"},
                }

                # Test three declinations

                mh_dict = {
                    "name": f"{base_name}/{gamma}/",
                    "mh_name": "fixed_weights",
                    "dataset": icecube_ps_3_year.get_seasons("IC86-2011"),
                    "catalogue": catalogue,
                    "inj_dict": inj_dict,
                    "llh_dict": llh_dict,
                    "n_steps": 5,
                    "n_trials": 10,
                    "scale": [3.0, 500.0][j],
                }

                analyse(mh_dict, n_cpu=24, cluster=False)

                rh = ResultsHandler(mh_dict)

                # Deliberately test a second time, to see performance once results have been combined

                rh = ResultsHandler(mh_dict)

            ub_dict = dict(mh_dict)

            # Test without background TS

            ub = create_unblinder(ub_dict, full_plots=True)

            # Test with background TS

            ub_dict["background_ts"] = base_name

            ub = create_unblinder(ub_dict, full_plots=True, scan_2d=True)

            mh = MinimisationHandler.create(mh_dict)
            mh.iterate_run(scale=1.0, n_steps=3, n_trials=1)

        except OverfluctuationError:
            pass
示例#6
0
    mh_dict = {
        "name": subname,
        "mh_name": "fixed_weights",
        "dataset": ps_v003_p02.get_seasons("IC86_2012_17"),
        "catalogue": cat_path,
        "inj_dict": inj_kwargs,
        "llh_dict": llh_kwargs,
        "scale": scale,
        "n_trials": 50,
        "n_steps": 10,
    }

    # mh = MinimisationHandler.create(mh_dict)

    analyse(mh_dict, cluster=False, n_cpu=12)

    analyses.append(mh_dict)

wait_cluster()

sens = []
sens_err = []
disc_pots = []

for rh_dict in analyses:
    rh = ResultsHandler(rh_dict)
    sens.append(rh.sensitivity)
    sens_err.append(rh.sensitivity_err)
    disc_pots.append(rh.disc_potential)