Esempio n. 1
0
            "time_pdf_name": "FixedRefBox",
            "fixed_ref_time_mjd": t_start,
            "pre_window": 0,
            "post_window": flare_length,
            "time_smear_bool": True,
            "min_offset": 0.0,
            "max_offset": search_window - flare_length,
        }

        inj_kwargs = {
            "injection_energy_pdf": injection_energy,
            "injection_time_pdf": injection_time,
        }

        scale = flux_to_k(
            reference_sensitivity(np.sin(dec)) *
            (50 * search_window / flare_length))

        mh_dict = {
            "name":
            full_name,
            "mh_name":
            mh_name,
            "datasets":
            custom_dataset(txs_sample_v1, catalogue,
                           llh_kwargs["llh_time_pdf"]),
            "catalogue":
            cat_path,
            "inj_dict":
            inj_kwargs,
            "llh_dict":
            injection_time = llh_time

            # Loop over spectral indices

            for gamma in gammas:

                full_name = time_name + str(gamma) + "/"

                length = float(time_key)

                scale = (
                    0.1
                    * (
                        flux_to_k(
                            reference_sensitivity(
                                np.sin(closest_src["dec_rad"]), gamma=gamma
                            )
                            * 40
                            * math.sqrt(float(len(catalogue)))
                        )
                        * 200.0
                    )
                    / length
                )

                if cat == "IIn":
                    scale *= 1.5

                injection_energy = dict(llh_energy)
                injection_energy["gamma"] = gamma
                "Name": "Box",
                "Pre-Window": 0,
                "Post-Window": flare_length,
                "Time Smear?": True,
                "Min Offset": 0.,
                "Max Offset": max_window - flare_length
            }

            inj_kwargs = {
                "Injection Energy PDF": injection_energy,
                "Injection Time PDF": injection_time,
                "Poisson Smear?": True,
            }

            scale = old_div(100 * math.sqrt(float(len(catalogue))) * flux_to_k(
                reference_sensitivity(np.sin(closest_src["dec"]), gamma=2)
            ) * max_window, flare_length)

            # print scale

            mh_dict = {
                "name": full_name,
                "datasets": custom_dataset(txs_sample_v2, catalogue,
                                           llh_kwargs["LLH Time PDF"]),
                "catalogue": cat_path,
                "inj kwargs": inj_kwargs,
                "llh kwargs": llh_kwargs,
                "scale": scale,
                "n_trials": 1,
                "n_steps": 15
            }
        cat_path = ps_catalogue_name(sindec)

        decname = name + "sindec=" + '{0:.2f}'.format(sindec) + "/"

        full_name = decname + label + "/"

        injection_time = dict(llh_time)
        injection_time["Post-Window"] = length

        inj_kwargs = {
            "Injection Energy PDF": injection_energy,
            "Injection Time PDF": injection_time,
            "Poisson Smear?": True,
        }

        scale = flux_to_k(reference_sensitivity(sindec)) * 40

        mh_dict = {
            "name": full_name,
            "datasets": [ps_v002_p01[-1]],
            "catalogue": cat_path,
            "inj kwargs": inj_kwargs,
            "llh kwargs": llh_kwargs,
            "scale": scale,
            "n_trials": 5,
            "n_steps": 10
        }

        analysis_path = analysis_dir + full_name

        try:
    source_res = dict()

    cat_path = ps_catalogue_name(sindec)

    sindec_key = "sindec=" + '{0:.2f}'.format(sindec)

    name = name_root + sindec_key + "/"

    src_res = dict()

    for length in lengths:

        full_name = name + str(length) + "/"

        scale = flux_to_k(reference_sensitivity(sindec) * 20) * max(
            1, window / abs(length)
        )

        # Standard Time Integration

        llh_time = {
            "Name": "FixedRefBox",
            "Fixed Ref Time (MJD)": ref_time,
            "Pre-Window": 0,
            "Post-Window": length
        }

        llh_kwargs = {
            "LLH Energy PDF": energy_pdf,
            "LLH Time PDF": llh_time,
Esempio n. 6
0
            config_mh = []

            for sin_dec in sin_decs:

                name = seed_name + "sindec=" + "{0:.2f}".format(sin_dec) + "/"

                llh_dict = {
                    "name": "standard_overlapping",
                    "LLH Energy PDF": injection_energy,
                    "LLH Time PDF": injection_time,
                    "pull_name": pull_corrector,
                    "floor_name": floor,
                }

                scale = flux_to_k(reference_sensitivity(sin_dec, gamma)) * 5

                mh_dict = {
                    "name": name,
                    "mh_name": "fixed_weights",
                    "datasets": [IC86_1_dict],
                    "catalogue": ps_catalogue_name(sin_dec),
                    "llh_dict": llh_dict,
                    "inj kwargs": inj_dict,
                    "n_trials": 20,
                    "n_steps": 15,
                    "scale": scale,
                }

                pkl_file = make_analysis_pickle(mh_dict)
Esempio n. 7
0
            full_name = name + str(gamma) + "/"

            injection_time = llh_time = {"Name": "FixedEndBox"}

            injection_energy = dict(llh_energy)
            injection_energy["E Min"] = e_min
            injection_energy["Gamma"] = gamma

            inj_kwargs = {
                "Injection Energy PDF": injection_energy,
                "Injection Time PDF": injection_time,
                "Poisson Smear?": True,
            }

            scale = flux_to_k(
                reference_sensitivity(np.sin(catalogue["dec"]),
                                      gamma=gamma)) * 60 * (e_min / 100.)**0.2

            mh_dict = {
                "name":
                full_name,
                "datasets":
                custom_dataset(txs_sample_v1, catalogue,
                               llh_kwargs["LLH Time PDF"]),
                "catalogue":
                txs_cat_path,
                "inj kwargs":
                inj_kwargs,
                "llh kwargs":
                llh_kwargs,
                "scale":
                scale,
                "fixed_ref_time_mjd": t_start,
                "pre_window": 0.,
                "post_window": flare_length,
                "time_smear_bool": True,
                "min_offset": 0.,
                "max_offset": max_window - flare_length
            }

            inj_dict = {
                "injection_energy_pdf": injection_energy,
                "injection_sig_time_pdf": injection_time,
            }

            # Sets a default flux scale for signal injection

            scale = flux_to_k(reference_sensitivity(np.sin(catalogue["dec_rad"]))
                              * (50 * max_window / flare_length))

            if cat != "AT2018cow":
                dataset = custom_dataset(txs_sample_v2, catalogue,
                                         llh_dict["llh_sig_time_pdf"])
            else:
                dataset = gfu_v002_p04

            mh_dict = {
                "name": full_name,
                "mh_name": mh_name,
                "dataset": dataset,
                "catalogue": cat_path,
                "inj_dict": inj_dict,
                "llh_dict": llh_dict,
Esempio n. 9
0
        if llh_name == "fixed_energy":
            llh_dict["LLH Energy PDF"]["Gamma"] = gamma

        inj_dict = {
            "Injection Time PDF": {
                "Name": "Steady"
            },
            "Injection Energy PDF": {
                "Name": "Power Law",
                "Gamma": gamma,
            },
            "fixed_n": 30
        }

        mh_dict = {
            "name": name,
            "mh_name": "fixed_weights",
            "datasets": [IC86_1_dict],
            # "catalogue": ps_catalogue_name(sin_dec),
            "catalogue": tde_catalogue_name("jetted"),
            "llh_dict": llh_dict,
            "inj kwargs": inj_dict
        }

        scale = flux_to_k(reference_sensitivity(
            sin_dec, gamma)) * 125 * ([4.0, 1.0, 0.3, 10.0][j])

        mh = MinimisationHandler.create(mh_dict)
        mh.iterate_run(scale=scale, n_steps=2, n_trials=100)
        rh = ResultsHandler(mh_dict)
Esempio n. 10
0
                if not mh_name == "large_catalogue" else "standard_matrix",
                "llh_energy_pdf": llh_energy,
                "llh_sig_time_pdf": llh_time,
                "llh_bkg_time_pdf": {
                    "time_pdf_name": "steady"
                },
                "gamma_precision": args.smoothing,
                "smoothing_order": args.smoothing,
            }

            full_name = f"{hsphere_name}/{gamma:.2f}"

            length = 365 * 7

            scale = (flux_to_k(
                reference_sensitivity(np.sin(0.5), gamma=gamma) * 40 *
                math.sqrt(float(len(catalogue)))) * 200.0) / length

            if hsphere == "southern":
                scale *= 5

                if seasons == ["IC40"]:
                    scale *= 4

            data = ps_v002_p01
            if seasons:
                data = data.get_seasons(*seasons)

            dataset = custom_dataset(data, catalogue,
                                     llh_dict["llh_sig_time_pdf"])
            logger.debug(f"{dataset.keys()}")
                "pre_window": 0.0,
                "post_window": flare_length,
                "time_smear_bool": True,
                "min_offset": 0.0,
                "max_offset": max_window - flare_length,
            }

            inj_dict = {
                "injection_energy_pdf": injection_energy,
                "injection_sig_time_pdf": injection_time,
            }

            # Sets a default flux scale for signal injection

            scale = flux_to_k(
                reference_sensitivity(np.sin(catalogue["dec_rad"])) *
                (50 * max_window / flare_length))

            if cat != "AT2018cow":
                dataset = custom_dataset(txs_sample_v2, catalogue,
                                         llh_dict["llh_sig_time_pdf"])
            else:
                dataset = gfu_v002_p04

            mh_dict = {
                "name": full_name,
                "mh_name": mh_name,
                "dataset": dataset,
                "catalogue": cat_path,
                "inj_dict": inj_dict,
                "llh_dict": llh_dict,
Esempio n. 12
0
            llh_dict = {
                "llh_name": "standard",
                "llh_energy_pdf": llh_energy,
                "llh_sig_time_pdf": llh_time,
                "llh_bkg_time_pdf": {
                    "time_pdf_name": "steady"
                },
            }

            full_name = f"{name}/{gamma:.2f}"

            length = 365 * 7

            scale = (0.5 * (flux_to_k(
                reference_sensitivity(np.sin(closest_src["dec_rad"]),
                                      gamma=gamma) * 40 *
                math.sqrt(float(len(catalogue)))) * 200.0) / length)

            if ps:
                scale *= 2
                if cat == "IIn":
                    scale *= 1.5

            if cat == "IIn":
                scale *= 0.3
            if cat == "IIP":
                scale *= 1

            if not northern and weighted:
                if cat == "IIn":
                    scale *= 1.5
Esempio n. 13
0
    catalogue["Relative Injection Weight"] = np.exp(
        np.random.normal(0., 2., int(n)))
    catalogue["Distance (Mpc)"] = np.ones(int(n))
    catalogue["Ref Time (MJD)"] = np.random.uniform(55710., 56010, int(n))

    cat_path = catalogue_dir + "random/" + str(n) + "_cat.npy"
    try:
        os.makedirs(os.path.dirname(cat_path))
    except OSError:
        pass
    np.save(cat_path, catalogue)

    # cat_path = catalogue_dir + "TDEs/TDE_silver_catalogue.npy"
    # catalogue = np.load(cat_path)

    scale = flux_to_k(reference_sensitivity(np.sin(0.0))) * 40 * math.sqrt(
        float(n))

    mh_dict = {
        "name": name,
        "datasets": ps_v002_p01,
        "catalogue": cat_path,
        "inj kwargs": inj_kwargs,
        "llh kwargs": llh_kwargs,
        "scale": scale,
        "n_trials": 5,
        "n_steps": 15
    }

    analysis_path = analysis_dir + name
Esempio n. 14
0
            "Time-Integrated",
            "10 Day Flare",
            "2 Day Flare",
        ][i]
        f_name = ["negative_n_s", "positive_n_s", "flare_winter", "flare_murase"][i]

        flare_name = name + f_name + "/"

        res = dict()

        for gamma in gammas:

            full_name = flare_name + str(gamma) + "/"

            scale = flux_to_k(
                reference_sensitivity(np.sin(catalogue["dec"]), gamma=gamma) * 50
            )

            if i > 1:
                scale *= 10 ** (i - 1)

            inj = dict(inj_kwargs)

            inj["Injection Energy PDF"] = dict(inj["Injection Energy PDF"])

            inj["Injection Energy PDF"]["Gamma"] = gamma

            if "E Min" in list(inj["Injection Energy PDF"].keys()):
                scale *= 10

            mh_dict = {
# sindecs = np.linspace(0.90, -0.90, 3)
sindecs = np.linspace(0.90, -0.90, 19)
# sindecs = np.linspace(0.5, -0.5, 3)
#
analyses = []

cluster = True

job_ids = []

for sindec in sindecs:
    cat_path = ps_catalogue_name(sindec)

    subname = name + "/sindec=" + "{0:.2f}".format(sindec) + "/"

    scale = flux_to_k(reference_sensitivity(sindec)) * 3

    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,
Esempio n. 16
0
            }

            # set up an injection dictionary which will be equal to the time pdf dictionary
            injection_time = llh_time

            # Loop over spectral indices
            for gamma in gammas:

                full_name = time_name + str(gamma) + "/"

                length = float(time_key)

                # try to estimate a good scale based on the sensitivity from the 7-yr PS sensitivity
                # at the declination of the closest source
                scale = 0.025 * (flux_to_k(reference_sensitivity(
                    np.sin(closest_src["dec_rad"]), gamma=gamma
                ) * 40 * math.sqrt(float(len(catalogue)))) * 200.) / length

                # in some cases the sensitivity is outside the tested range
                # to get a good sensitivity, adjust the scale in these cases
                if (gamma == 2.5) and (cat == 'IIn'):
                    scale *= 1.8
                if (gamma == 2.5) and (cat == 'IIP'):
                    scale *= 0.15
                if (gamma == 2.0) and (cat == 'IIP'):
                    scale *= 0.5
                if cat == 'IIn':
                    scale *= 5

                # set up an injection dictionary and set the desired spectral index
                injection_energy = dict(llh_energy)
Esempio n. 17
0
            full_res = dict()

            for i, n in enumerate(np.array(nsources)):

                logging.info(f"stacking {n} sources")
                logging.info(f"cat path is {fs_sources(n, sindec)}")

                name = (gamma_name + "{:.4f}/".format(sindec) + str(n) +
                        "sources" if sindec is not None else gamma_name +
                        "None/" + str(n) + "sources")
                catalogue = np.load(fs_sources(n, sindec))
                closest_src = np.sort(catalogue, order="distance_mpc")[0]

                scale = (flux_to_k(
                    reference_sensitivity(np.sin(closest_src["dec_rad"]),
                                          gamma=gamma) * 40 *
                    (math.log(float(len(catalogue)), 4) + 1)) * 200.0) / length

                mh_dict = {
                    "name":
                    name,
                    "mh_name":
                    mh_name,
                    "dataset":
                    custom_dataset(ps_v002_p01, catalogue,
                                   llh_dict["llh_sig_time_pdf"]),
                    "catalogue":
                    fs_sources(n, sindec),
                    "inj_dict":
                    inj_dict,
                    "llh_dict":
Esempio n. 18
0
            "Name": "FixedRefBox",
            "Fixed Ref Time (MJD)": t_start,
            "Pre-Window": 0,
            "Post-Window": flare_length,
            "Time Smear?": True,
            "Min Offset": 0.,
            "Max Offset": max_window - flare_length
        }

        inj_kwargs = {
            "Injection Energy PDF": injection_energy,
            "Injection Time PDF": injection_time,
            "Poisson Smear?": True,
        }

        scale = flux_to_k(reference_sensitivity(np.sin(dec))
                          * ((70 * max_window)/ flare_length))

        mh_dict = {
            "name": full_name,
            "mh_name": mh_name,
            "datasets": gfu_v002_p01,
            "catalogue": cat_path,
            "inj kwargs": inj_kwargs,
            "llh_dict": llh_kwargs,
            "scale": scale,
            "n_trials": 5,
            "n_steps": 15
        }

        pkl_file = make_analysis_pickle(mh_dict)
Esempio n. 19
0
}

name = "analyses/benchmarks/ps_sens_7yr"

# sindecs = np.linspace(0.90, -0.90, 3)
sindecs = np.linspace(0.90, -0.90, 9)
# sindecs = np.linspace(0.5, -0.5, 3)

analyses = []

for sindec in sindecs:
    cat_path = ps_catalogue_name(sindec)

    subname = name + "/sindec=" + "{0:.2f}".format(sindec) + "/"

    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)
Esempio n. 20
0
                'injection_sig_time_pdf': injection_time
            }

            llh_dict = {
                "llh_name": "standard",
                "llh_energy_pdf": llh_energy,
                "llh_sig_time_pdf": llh_time,
                "llh_bkg_time_pdf": {"time_pdf_name": "steady"}
            }

            full_name = f'{name}/{gamma:.2f}'

            length = 365 * 7

            scale = 0.5 * (flux_to_k(reference_sensitivity(
                np.sin(closest_src["dec_rad"]), gamma=gamma
            ) * 40 * math.sqrt(float(len(catalogue)))) * 200.) / length

            if ps:
                scale *= 2
                if cat == 'IIn':
                    scale *= 1.5

            if cat == 'IIn':
                scale *= 0.3
            if cat == 'IIP':
                scale *= 1

            if not northern and weighted:
                if cat == 'IIn':
                    scale *= 1.5