def integral_over_columns(column):
    """calculates the average fitness for the input column"""
    no_nan_indices = remove_nans(column, column.index)
    # print(no_nan_indices)
    time = range(1, len(no_nan_indices) + 1)
    coefficients = integral(time, column.loc[no_nan_indices])[-1]
    return coefficients / len(no_nan_indices)
def calculate_cubic_derivatives(df, time_period):
    """caluclates derivative of cubic spline interpolation over all timepoints for each column"""
    weeks_indices = generate_datapoints(df.index, 'index', time_period, 0)
    df = df.replace(0, np.nan)
    derivation = pd.DataFrame(index=weeks_indices)
    interp = pd.DataFrame(index=weeks_indices)
    for col in df.columns:
        no_nan_indices = remove_nans(df[col], df.index)
        no_nan_values = df[col].loc[no_nan_indices]
        try:
            derivation[col], interp[col] = spline_interpolate(
                no_nan_indices, no_nan_values, weeks_indices)
        except:
            continue
    return derivation.loc[df.index], interp.loc[df.index]
Ejemplo n.º 3
0
        mu_del = data.iloc[0]["MU_DEL"]
        xi_inf = data.iloc[0]["XI_INF"]

        ns = np.unique(np.array(data["N"]))
        lams = np.unique(np.array(data["LAM"]))

        NS = np.linspace(np.min(ns), 20, 500)
        LAMS = np.logspace(np.log10(np.min(lams)), np.log10(np.max(lams)), 500)

        n_array = np.array(data["N"]).reshape((len(lams), len(ns)))
        lam_array = np.array(data["LAM"]).reshape((len(lams), len(ns)))

        # Relic densities
        rde_array = np.array(data["RD_ETA"]).reshape((len(lams), len(ns)))
        rdd_array = np.array(data["RD_DEL"]).reshape((len(lams), len(ns)))
        remove_nans(rde_array)
        remove_nans(rdd_array)

        # Extract xi_fo and tsm_fo
        xifo_array = np.array(data["XI_FO"]).reshape((len(lams), len(ns)))
        tsmfo_array = np.array(data["TSM_FO"]).reshape((len(lams), len(ns)))
        remove_nans(xifo_array)
        remove_nans(tsmfo_array)

        eta_rd_cont = find_contour(ns, lams, rde_array, level=OMEGA_CDM_H2)

        xifo_interp = RectBivariateSpline(ns, np.log10(lams), xifo_array)
        tsmfo_interp = RectBivariateSpline(ns, np.log10(lams), xifo_array)

        models = [
            DarkSun(n, lam, c, lec1, lec2, mu_eta, mu_del, xi_inf)
Ejemplo n.º 4
0
def generate_bm_plot(idx):
    # Load the benchmark data and extract needed quantities
    data = pd.read_csv(DATA_FILES[idx])

    data.sort_values(by=["LAM", "N"], inplace=True)

    ns = np.unique(np.array(data["N"]))
    lams = np.unique(np.array(data["LAM"]))

    n_array = np.array(data["N"]).reshape((len(lams), len(ns)))
    lam_array = np.array(data["LAM"]).reshape((len(lams), len(ns)))

    # Relic densities
    rde_array = np.array(data["RD_ETA"]).reshape((len(lams), len(ns)))
    rdd_array = np.array(data["RD_DEL"]).reshape((len(lams), len(ns)))
    remove_nans(rde_array)
    remove_nans(rdd_array)
    rdt_array = rde_array + rdd_array  # total

    rd_cont = np.log10(find_contour(ns, lams, rde_array, OMEGA_CDM_H2))
    print(TITLES[idx])
    print(curve_fit(lambda x, m, b: m * x + b, rd_cont[0], rd_cont[1]))

    # Self interactions constraints
    sie_array = np.array(data["ETA_SI_PER_MASS"]).reshape((len(lams), len(ns)))
    sid_array = np.array(data["DEL_SI_PER_MASS"]).reshape((len(lams), len(ns)))
    remove_nans(sie_array)
    remove_nans(sid_array)

    # BBN + CMB constraints
    bbn_array = np.array(data["DNEFF_BBN"]).reshape((len(lams), len(ns)))
    cmb_array = np.array(data["DNEFF_CMB"]).reshape((len(lams), len(ns)))
    remove_nans(bbn_array)
    remove_nans(cmb_array)

    # Get the SI contours
    del_si_cont = find_contour(ns, lams, sid_array, SI_BOUND)
    eta_si_cont = find_contour(ns, lams, sie_array, SI_BOUND)
    si_del = interp1d(del_si_cont[0], del_si_cont[1])
    si_eta = interp1d(eta_si_cont[0], eta_si_cont[1])

    del_si_cont = find_contour(ns, lams, sid_array, level=SI_BOUND / 10.0**1.5)
    eta_si_cont = find_contour(ns, lams, sie_array, level=SI_BOUND / 10.0**1.5)
    si2_del = interp1d(del_si_cont[0], del_si_cont[1])
    si2_eta = interp1d(eta_si_cont[0], eta_si_cont[1])

    plt.figure(dpi=100)
    #    plt.contour(
    #        n_array,
    #        lam_array,
    #        rde_array,
    #        levels=[OMEGA_CDM_H2 / 3, OMEGA_CDM_H2, 3 * OMEGA_CDM_H2],
    #        colors=["mediumorchid"],
    #        linewidths=[1, 2, 1],
    #        linestyles=["--", "-", "-."],
    #    )
    # Delta Contours
    plt.contour(
        n_array,
        lam_array,
        rdd_array,
        levels=[OMEGA_CDM_H2 / 3, OMEGA_CDM_H2, OMEGA_CDM_H2 * 3],
        colors=["firebrick"],
        linewidths=[1, 2, 1],
        linestyles=["--", "-", "-."],
    )
    plt.contour(
        n_array,
        lam_array,
        rdt_array,
        levels=[OMEGA_CDM_H2 / 3, OMEGA_CDM_H2, 3 * OMEGA_CDM_H2],
        colors=["k"],
        linewidths=[1, 2, 1],
        linestyles=["--", "-", "-."],
    )
    plt.contour(
        n_array,
        lam_array,
        rdt_array,
        levels=[OMEGA_CDM_H2 / 3, 3 * OMEGA_CDM_H2],
        colors=["k"],
        linewidths=1,
        linestyles=["--", "-."],
    )

    # BBN + CMB contours
    plt.contourf(
        n_array,
        lam_array,
        bbn_array,
        levels=[NEFF_BBN_BOUND[0] + NEFF_BBN_BOUND[1], 1e20],
        colors=["goldenrod"],
    )
    plt.contourf(
        n_array,
        lam_array,
        cmb_array,
        levels=[NEFF_CMB_BOUND[0] + NEFF_CMB_BOUND[1], 1e20],
        colors=["teal"],
    )

    # Delta self interaction constraint
    ns = np.linspace(5, 6, 100)
    sis = si_del(ns)
    si2s = si2_del(ns)
    plt.fill_between(ns, sis, color="steelblue", alpha=0.6)
    plt.plot(ns, si2s, color="Peru", alpha=0.8, ls="--", lw=3)

    ns = np.linspace(6, 8, 100)
    sis = si_del(ns)
    si2s = si2_del(ns)
    # plt.fill_between(ns, sis, color="steelblue", alpha=0.2)
    plt.plot(ns, si2s, color="Peru", alpha=0.5, ls="--", lw=3)

    ns = np.linspace(6, 7.5, 100)
    y1, n1 = si_del(6), 6
    y2, n2 = Y_LOW_BOUNDS[idx], 7.5
    slope = (np.log10(y2) - np.log10(y1)) / (np.log10(n2) - np.log10(n1))
    ylow = 10**np.array(
        [np.log10(y1) + slope * (np.log10(n) - np.log10(n1)) for n in ns])
    plt.fill_between(ns, sis, ylow, color="steelblue", alpha=0.2)
    plt.fill_between(ns, ylow, color="steelblue", alpha=0.6)

    ns = np.linspace(7.5, 8.0, 100)
    plt.fill_between(ns, sis, color="steelblue", alpha=0.2)

    # Eta self interaction constraint
    ns = np.linspace(8, 30, 100)
    sis = si_eta(ns)
    si2s = si2_eta(ns)
    plt.fill_between(ns, sis, color="steelblue", alpha=0.6)
    plt.plot(ns, si2s, color="Peru", alpha=0.8, ls="--", lw=3)

    ns = np.linspace(7, 8, 100)
    sis = si_eta(ns)
    si2s = si2_eta(ns)
    # plt.fill_between(ns, sis, color="steelblue", alpha=0.2)
    plt.plot(ns, si2s, color="Peru", alpha=0.5, ls="--", lw=3)

    plt.ylabel(r"$\Lambda \ (\mathrm{GeV})$", fontsize=16)
    plt.xlabel(r"$N$", fontsize=16)

    # Construct a custom legend
    lines = [
        Line2D([0], [0], color="k", linewidth=1, linestyle="-"),
        Line2D([0], [0], color="k", linewidth=1, linestyle="-."),
        Line2D([0], [0], color="k", linewidth=1, linestyle="--"),
        # Line2D([0], [0], color="mediumorchid", linewidth=1, linestyle="-"),
        Line2D([0], [0], color="firebrick", linewidth=1, linestyle="-"),
        Line2D([0], [0],
               color="steelblue",
               linewidth=3,
               alpha=0.5,
               linestyle="-"),
        Line2D([0], [0], color="Peru", linewidth=3, alpha=0.5, linestyle="-"),
    ]
    labels = [
        r"$\Omega_{\bar{\eta}'+\Delta} h^2 = \Omega_{\mathrm{DM}} h^2$",
        r"$\Omega_{\bar{\eta}'+\Delta} h^2 = 3\Omega_{\mathrm{DM}} h^2$",
        r"$\Omega_{\bar{\eta}'+\Delta} h^2 = \frac{1}{3}\Omega_{\mathrm{DM}} h^2$",
        # r"$\bar{\eta}'$",
        r"$\Delta$",
        r"$\sigma_{\mathrm{S.I.}} / m > 0.1 \mathrm{cm}^2/\mathrm{g}$",
        r"$\sigma_{\mathrm{S.I.}} / m > 10^{-2.5} \mathrm{cm}^2/\mathrm{g}$",
    ]
    plt.legend(lines, labels, frameon=False, fontsize=12)

    plt.yscale("log")
    plt.xscale("log")
    plt.xlim([np.min(ns), 30])
    plt.ylim([Y_LOW_BOUNDS[idx], 10])

    plt.xticks(
        [5, 6, 7, 8, 9, 10, 20, 30],
        ["5", "6", "7", "8", "9", "10", "20", "30"],
    )

    plt.title(TITLES[idx], fontsize=16)

    plt.tight_layout()
    plt.savefig("/home/logan/Research/DarkSun/cpp/analysis/figures/" +
                FILE_NAMES[idx] + ".pdf")
Ejemplo n.º 5
0
def generate_plot(idx):
    # Load the benchmark data and extract needed quantities
    data = pd.read_csv(DATA_FILES[idx])

    data.sort_values(by=["C", "N"], inplace=True)
    data.drop(
        [
            "ADEL",
            "DNEFF_CMB",
            "DNEFF_BBN",
            "ETA_SI_PER_MASS",
            "DEL_SI_PER_MASS",
            "XI_FO",
            "TSM_FO",
            "LEC1",
            "LEC2",
            "MU_DEL",
            "MU_ETA",
            "XI_INF",
            "XI_CMB",
            "XI_BBN",
            "RD_ETA",
        ],
        axis=1,
        inplace=True,
    )

    ns = np.unique(np.array(data["N"]))
    cs = np.unique(np.array(data["C"]))

    n_array = np.array(data["N"]).reshape((len(cs), len(ns)))
    c_array = np.array(data["C"]).reshape((len(cs), len(ns)))

    mpl.use("TkAgg")
    plt.figure(dpi=100)

    rdd_array = np.array(data["RD_DEL"]).reshape((len(cs), len(ns)))
    remove_nans(rdd_array)

    plt.contour(
        n_array,
        c_array,
        rdd_array,
        levels=[OMEGA_CDM_H2],
        colors="k",
    )
    plt.contour(
        n_array,
        c_array,
        rdd_array,
        levels=[OMEGA_CDM_H2 / 3],
        colors="firebrick",
    )
    plt.contour(
        n_array,
        c_array,
        rdd_array,
        levels=[OMEGA_CDM_H2 * 3],
        colors="steelblue",
    )

    plt.contourf(
        n_array,
        c_array,
        rdd_array,
        levels=[OMEGA_CDM_H2 / 3.0, OMEGA_CDM_H2, 3.0 * OMEGA_CDM_H2],
        colors=["firebrick", "k", "steelblue"],
        alpha=0.5,
    )

    plt.ylabel(r"$c$", fontdict={"size": 16})
    plt.xlabel(r"$N$", fontdict={"size": 16})

    NS, LOGCS = find_contour(ns, np.log10(cs), rdd_array, OMEGA_CDM_H2)
    logc_interp = interp1d(NS, LOGCS)
    print(10.0**logc_interp(6))
    print(10.0**logc_interp(7))
    print(10.0**logc_interp(8))

    plt.yscale("log")
    plt.xscale("log")
    plt.xlim([np.min(ns), 15])

    xticks = np.arange(5, 16)
    plt.xticks(xticks, [str(t) for t in xticks])

    lines = [
        Line2D([0], [0], color="k", linewidth=1, linestyle="-"),
        Line2D([0], [0], color="steelblue", linewidth=1, linestyle="-"),
        Line2D([0], [0], color="firebrick", linewidth=1, linestyle="-"),
    ]
    labels = [
        r"$\Omega_{\Delta} h^2 = \Omega_{\mathrm{DM}} h^2$",
        r"$\Omega_{\Delta} h^2 = 3\Omega_{\mathrm{DM}} h^2$",
        r"$\Omega_{\Delta} h^2 = \frac{1}{3}\Omega_{\mathrm{DM}} h^2$",
    ]
    plt.legend(lines, labels, frameon=False, fontsize=12)

    plt.savefig("/home/logan/Research/DarkSun/cpp/analysis/figures/c_vs_n" +
                str(idx + 1) + ".pdf")

    if idx == 1:
        plt.show()
Ejemplo n.º 6
0
    data.sort_values(by=["LAM", "N"], inplace=True)

    ns = np.unique(np.array(data["N"]))
    lams = np.unique(np.array(data["LAM"]))

    NS = np.linspace(np.min(ns), 20, 500)
    LAMS = np.logspace(np.log10(np.min(lams)), np.log10(np.max(lams)), 500)

    n_array = np.array(data["N"]).reshape((len(lams), len(ns)))
    lam_array = np.array(data["LAM"]).reshape((len(lams), len(ns)))

    # Relic densities
    rde_array = np.array(data["RD_ETA"]).reshape((len(lams), len(ns)))
    rdd_array = np.array(data["RD_DEL"]).reshape((len(lams), len(ns)))
    remove_nans(rde_array)
    remove_nans(rdd_array)

    # Dneff
    dneff_cmb_array = np.array(data["DNEFF_CMB"]).reshape((len(lams), len(ns)))
    dneff_bbn_array = np.array(data["DNEFF_BBN"]).reshape((len(lams), len(ns)))
    remove_nans(dneff_cmb_array)
    remove_nans(dneff_bbn_array)

    # Generate the eta RD contour
    eta_rd_cont = find_cont(ns, lams, rde_array, level=OMEGA_CDM_H2)

    # Generate interpolation of delta neff at cmb and bbn
    dneff_cmb_interp = RectBivariateSpline(ns, np.log10(lams), dneff_cmb_array)
    dneff_bbn_interp = RectBivariateSpline(ns, np.log10(lams), dneff_bbn_array)