Beispiel #1
0
def get_fom(picke_file):
    print "Loading pickle file...", pickle_file

    (fit_params, stan_data,
     other_inputs) = pickle.load(open(pickle_file, 'rb'))

    for key in fit_params:
        print "fit_params:", key
    for key in other_inputs:
        print "other_inputs:", key

    if not other_inputs.has_key("jacobian_names"):
        other_inputs["jacobian_names"] = " " * stan_data["nsys"]
        other_inputs["redshifts"] = arange(stan_data["nred"]) * 0.1 + 0.05
        print "Hack, but fixed in later versions!"

    cmat = cov(transpose(fit_params["mus"]))

    z_set = concatenate(
        ([0.05], arange(len(cmat) - 1, dtype=float64) * 0.05 + 0.125))
    print "z_set", z_set
    FoM = astro_functions.get_FoM(cmat,
                                  z_set,
                                  zp=0.3,
                                  addcmb=1,
                                  verbose=True,
                                  shift_constraint=0.002)[0]
    print "Final_FoM", FoM

    return
def target_FoM_scale(coarse_z, coarse_mu_errs, target_FoM):
    err_scales = arange(0.1, 3., 0.1)
    FoMs_found = []

    for err_scale in err_scales:
        tmp_Cmat = diag(err_scale * coarse_mu_errs)**2.
        print tmp_Cmat
        FoM = astro_functions.get_FoM(tmp_Cmat,
                                      coarse_z,
                                      zp=0.3,
                                      addcmb=1,
                                      verbose=True,
                                      shift_constraint=0.002)[0]
        FoMs_found.append(FoM)

    FoMs_found = array(FoMs_found)
    print "scales ", err_scales, FoMs_found
    inds = where(1 - isnan(FoMs_found))

    FoMs_found = FoMs_found[inds]
    err_scales = err_scales[inds]

    FoMs_found = FoMs_found[::-1]
    err_scales = err_scales[::-1]

    print "scales ", err_scales, FoMs_found

    interp_scale = interp1d(FoMs_found[inds], err_scales[inds],
                            kind='linear')(target_FoM)
    print "interpolated to", interp_scale, "for", target_FoM

    return interp_scale * coarse_mu_errs
def get_FoM_from_file(item):
    f = pyfits.open(item)
    cmat = f[0].data
    f.close()

    z_list = concatenate(([0.05], arange(len(cmat) - 1) * 0.05 + 0.125))
    print z_list

    FoM = get_FoM(cmat, z_list, adddesi=0)[0]

    print "FoM", item, FoM
    return FoM
Beispiel #4
0
#plt.subplot(1,2,1)
plt.imshow(sn_Cmat,
           interpolation='nearest',
           origin='lower',
           cmap=plt.get_cmap('Greys'),
           aspect='equal')
#plt.colorbar()
plt.xticks([0, 5, 10, 15], ["0.05", "0.55", "1.05", "1.55"])
#plt.xticklabels(["0.05", "0.55", "1.05", "1.55"])
plt.yticks([0, 5, 10, 15], ["0.05", "0.55", "1.05", "1.55"])
#plt.yicklabels(["0.05", "0.55", "1.05", "1.55"])
#plt.subplot(1,2,2)
#plt.plot(params["z_list"], sqrt(diag(sn_Cmat)*params["NSNe"]), color = 'k')
#plt.xlabel("Redshift")
#plt.ylabel("Total Distance Modulus Uncertainty per SN")
plt.title("Estimated Covariance Matrix, Binned in Redshift")
plt.xlabel("Redshift")
plt.ylabel("Redshift")

plt.savefig("Cmat.eps", bbox_inches='tight')
#for zp in arange(0, 1.001, 0.05):
FoM, uncertainties = get_FoM(sn_Cmat, params["z_list"], zp=0.3)
print "FoM", FoM
#    print "zp, uncertainties ", zp, " ".join([str(item) for item in uncertainties])

if show_plots:
    write_Cmat(params["orig_lines"],
               sn_Cmat,
               FoM,
               flname="Cmat_" + params["suffix"] + ".txt")
def make_plots_from_dir(item):
    print "Loading pickle file...", item

    if item.count("/") > 0:
        outputdir = item[:item.rfind("/")] + "/"
    else:
        outputdir = ""

    (fit_params, stan_data, other_inputs) = pickle.load(open(item, 'rb'))

    for key in fit_params:
        print "fit_params:", key
    for key in other_inputs:
        print "other_inputs:", key

    if not other_inputs.has_key("jacobian_names"):
        other_inputs["jacobian_names"] = " " * stan_data["nsys"]
        other_inputs["redshifts"] = arange(stan_data["nred"]) * 0.1 + 0.05
        print "Hack, but fixed in later versions!"

    cmat = cov(transpose(fit_params["mus"]))
    save_img(cmat, outputdir + "cmat.fits")

    z_set = concatenate(
        ([0.05], arange(len(cmat) - 1, dtype=float64) * 0.05 + 0.125))
    print "z_set", z_set
    FoM = astro_functions.get_FoM(cmat,
                                  z_set,
                                  zp=0.3,
                                  addcmb=1,
                                  verbose=True,
                                  shift_constraint=0.002)[0]
    print "Final_FoM", FoM
    binned_points(cmat,
                  z_set,
                  bin_edges=[0., 0.1, 0.2, 0.55, 0.85, 1.15, 1.7],
                  target_FoM=FoM)

    plot_RV_by_z(other_inputs=other_inputs, fit_params=fit_params)
    mag_histogram(fit_params=fit_params)
    plot_diag_mu_err(other_inputs=other_inputs,
                     stan_data=stan_data,
                     fit_params=fit_params)
    plot_EBV_err(fit_params=fit_params)

    systematics_histograms(other_inputs=other_inputs,
                           fit_params=fit_params,
                           stan_data=stan_data)
    plot_d_mu_d_sys(other_inputs=other_inputs,
                    stan_data=stan_data,
                    fit_params=fit_params)
    plot_d_mu_d_sys(other_inputs=other_inputs,
                    stan_data=stan_data,
                    offset=0.02,
                    fit_params=fit_params)
    plot_d_mu_d_extinction(other_inputs=other_inputs,
                           fit_params=fit_params,
                           stan_data=stan_data)
    plot_d_mu_d_RV_by_z(other_inputs=other_inputs,
                        stan_data=stan_data,
                        fit_params=fit_params)

    plot_delta_vs_value(other_inputs["true_EBVs"], fit_params["true_EBV"],
                        "EBV_resid.pdf")
    plot_delta_vs_value(other_inputs["true_mags"], fit_params["mags"],
                        "mag_resid.pdf")
    if fit_params.has_key("true_dRV"):
        plot_delta_vs_value(other_inputs["true_RVs"] - 3.1,
                            fit_params["true_dRV"],
                            "RV_resid.pdf",
                            diff=0)
    plot_delta_vs_value(median(fit_params["mus"], axis=0), fit_params["mus"],
                        "mus_vs_mus.pdf")

    print "Corner plots..."
    make_corner(["RV_coeff", "log_EBV_star_coeff", "log_R_EBV_coeff"],
                "EBV_params.pdf",
                fit_params=fit_params)
    make_multi_corner(
        ["mus", "RV_by_red", "log_EBV_star_by_red", "log_R_EBV_by_red"],
        "RV_mus.pdf",
        fit_params=fit_params,
        stan_data=stan_data)
    return None