def create_obs_galaxies(IDs, **kwargs):
    """
    Create a list of galaxy object from the observation
    Iterate through IDs and will pass the kwargs to the
    bagpipes.galaxy

    INPUT
    ======
                IDs (an array of IDs) : A list of  IDs
                kwargs : arguments to be passed to the
                        bagpipes.galaxy

    OUTPUT
    ======
                a list of galaxy object from Bagpipes
    """
    gal_list = []
    for idx in IDs:
        galaxy = pipes.galaxy(ID=idx, **kwargs)
        gal_list.append(galaxy)
    return gal_list
예제 #2
0
def fitmodel(ID, saveplot=False):
    filt_list = np.loadtxt("filters/goodss_filt_list.txt", dtype="str")

    galaxy = pipes.galaxy(ID,
                          load_goodss,
                          spectrum_exists=False,
                          filt_list=filt_list)

    exp = {}
    exp["age"] = (0.1, 15.)
    exp["tau"] = (0.3, 12.)
    exp["massformed"] = (2., 15.)
    exp["metallicity"] = (0., 2.5)

    dust = {}
    dust["type"] = "Cardelli"
    dust["Av"] = (0., 2.)

    fit_instructions = {}
    fit_instructions["redshift"] = (0., 10.)
    fit_instructions["exponential"] = exp
    fit_instructions["dust"] = dust

    fit = pipes.fit(galaxy, fit_instructions)
    fit.fit(verbose=False)

    if saveplot == True:
        fig = fit.plot_spectrum_posterior(
            save=True, show=False)  #####doesnt work, unclear why
        fig = fit.plot_sfh_posterior(save=True, show=False)
        fig = fit.plot_corner(save=True, show=False)
    else:
        fig = fit.plot_spectrum_posterior(
            save=False, show=True)  #####doesnt work, unclear why
        fig = fit.plot_sfh_posterior(save=False, show=True)
        fig = fit.plot_corner(save=False, show=True)
예제 #3
0
lognormal["massformed"] = (5.0, 12.5)
lognormal["metallicity"] = (0.0, 2.5)

dust = {}
dust["type"] = "Calzetti"
dust["Av"] = (0.0, 2.0)

nebular = {}
nebular["logU"] = (-4.0,-2.0)

chi_squ_vals = {}

for redshift, filename in zip(redshifts, datafiles):

    # Get the galaxy object and a priori model compenents dictionary.
    galaxy = pipes.galaxy(filename, load_xshooter, photometry_exists=False)
    # Calculate redshift constraints.
    z_low, z_high = redshift - 0.001,  redshift + 0.001

    try:
        f = open("pipes/posterior/exponential_burst_r4/"+filename+".h5")
        f.close()
        fit_instructions = {
        "redshift"     : (z_low, z_high), # z varies tight_layout around z_obs.
        "t_bc"         : (0.013, 0.021),  # Constraints from Murray 2011.
        "veldisp"      : (50.0, 450.0),   # Constrained by Faber-Jackson. TODO: Lookup Minkowski 1962!
        "exponential1" : exponential1,    # Add the exp SFH component.
        "exponential2" : exponential2,    # Add the burst component.
        "dust"         : dust,
        "nebular"      : nebular
        }
예제 #4
0
def main(segid_to_test):

    print("Running BAGPIPES on galaxy SegID:", segid_to_test)
    galaxy = pipes.galaxy(str(segid_to_test),
                          load_data,
                          photometry_exists=False)

    galaxy.plot()

    dblplaw = {}
    dblplaw["tau"] = (0., 15.)
    dblplaw["alpha"] = (0.01, 1000.)
    dblplaw["beta"] = (0.01, 1000.)
    dblplaw["alpha_prior"] = "log_10"
    dblplaw["beta_prior"] = "log_10"
    dblplaw["massformed"] = (1., 15.)
    dblplaw["metallicity"] = (0.1, 2.)
    dblplaw["metallicity_prior"] = "log_10"

    nebular = {}
    nebular["logU"] = -3.

    dust = {}
    dust["type"] = "CF00"
    dust["eta"] = 2.
    dust["Av"] = (0., 2.0)
    dust["n"] = (0.3, 2.5)
    dust["n_prior"] = "Gaussian"
    dust["n_prior_mu"] = 0.7
    dust["n_prior_sigma"] = 0.3

    fit_instructions = {}
    fit_instructions["redshift"] = (0.1, 2.5)

    fit_instructions["t_bc"] = 0.01
    #fit_instructions["redshift_prior"] = "Gaussian"
    #fit_instructions["redshift_prior_mu"] = 0.5
    #fit_instructions["redshift_prior_sigma"] = 0.2
    fit_instructions["dblplaw"] = dblplaw
    fit_instructions["nebular"] = nebular
    fit_instructions["dust"] = dust

    fit_instructions["veldisp"] = (1., 1000.)  #km/s
    fit_instructions["veldisp_prior"] = "log_10"

    calib = {}
    calib["type"] = "polynomial_bayesian"

    calib["0"] = (0.5, 1.5)
    # Zero order is centred on 1,
    # at which point there is no change to the spectrum.
    calib["0_prior"] = "Gaussian"
    calib["0_prior_mu"] = 1.0
    calib["0_prior_sigma"] = 0.25

    calib["1"] = (-0.5, 0.5)  # Subsequent orders are centred on zero.
    calib["1_prior"] = "Gaussian"
    calib["1_prior_mu"] = 0.
    calib["1_prior_sigma"] = 0.25

    calib["2"] = (-0.5, 0.5)
    calib["2_prior"] = "Gaussian"
    calib["2_prior_mu"] = 0.
    calib["2_prior_sigma"] = 0.25

    fit_instructions["calib"] = calib

    noise = {}
    noise["type"] = "white_scaled"
    noise["scaling"] = (1., 10.)
    noise["scaling_prior"] = "log_10"
    fit_instructions["noise"] = noise

    fit = pipes.fit(galaxy, fit_instructions, run="spectroscopy")

    fit.fit(verbose=False)

    fig = fit.plot_spectrum_posterior(save=True, show=True)
    fig = fit.plot_calibration(save=True, show=True)
    fig = fit.plot_sfh_posterior(save=True, show=True)
    fig = fit.plot_corner(save=True, show=True)

    print("\a    \a    \a")

    return None
from loaddata import load_goodss
from loaddata import load_vandels_spec
import bagpipes as pipes
import numpy as np

filt_list = np.loadtxt("filters/goodss_filt_list.txt", dtype="str")

galaxy = pipes.galaxy(14697,load_goodss,spectrum_exists=False,filt_list=filt_list)

dust = {}
dust["type"] = "Cardelli"
dust["Av"] = (0.,2.)

power = {}
power["tau"] = (0., 15.)
power["alpha"] = (.1, 1000.)
power["beta"] = (.1, 1000.)
power["alpha_prior"] = "log_10"
power["beta_prior"] = "log_10"
power["massformed"] = (2., 15.)
power["metallicity"] = (0., 2.5)

secondfit = {}
secondfit["redshift"] = (0.,10.)
secondfit["dblplaw"] = power
secondfit["dust"] = dust
fit = pipes.fit(galaxy, secondfit, run="dblplaw_sfh")
fit.fit(verbose=False)
fig = fit.plot_sfh_posterior(save=False, show=True)
fig = fit.plot_corner(save=False, show=True)
예제 #6
0
def plot_tde_posterior_quantities(filename, redshift):

    fit_instructions = {}
    chi_squ_vals = {}

    # Get the galaxy object and a priori model compenents dictionary.
    galaxy = pipes.galaxy(filename, load_xshooter, photometry_exists=False)
    # Calculate redshift constraints.
    z_low, z_high = redshift - 0.001,  redshift + 0.001

    fit = pipes.fit(galaxy, fit_instructions, run="r4_exponential_burst")
    fit.fit(verbose=False)
    chi_squ_vals = {"r4_exponential_burst" : chi_squared(galaxy, fit)}

    fit = pipes.fit(galaxy, fit_instructions, run="r4_dblplaw_burst")
    fit.fit(verbose=True)
    chi_squ_vals["r4_dblplaw_burst"] = chi_squared(galaxy, fit)

    fit = pipes.fit(galaxy, fit_instructions, run="r4_delayed_burst")
    fit.fit(verbose=False)
    chi_squ_vals["r4_delayed_burst"] = chi_squared(galaxy, fit)

    fit = pipes.fit(galaxy, fit_instructions, run="r4_lognormal_burst")
    fit.fit(verbose=False)
    chi_squ_vals["r4_lognormal_burst"] = chi_squared(galaxy, fit)

    # Get the functional form with the lowest chi-squared value.
    best_func = min(chi_squ_vals, key=lambda k: chi_squ_vals[k])
    fit = pipes.fit(galaxy, fit_instructions, run=best_func)
    # Select the fit with lowest chi-squared value and plot it.
    print(filename)
    print(best_func)
    for key in chi_squ_vals.keys():
        print(key, ": ", chi_squ_vals[key])

    if best_func == "r4_exponential_burst":
        labels = ["exponential2:age", "exponential2:massformed", "exponential1:age", "exponential1:massformed"]
    if best_func == "r4_delayed_burst":
        labels = ["exponential2:age", "exponential2:massformed", "delayed:age", "delayed:massformed"]
    if best_func == "r4_lognormal_burst":
        labels = ["exponential2:age", "exponential2:massformed", "lognormal:tmax", "lognormal:massformed"]
    if best_func == "r4_dblplaw_burst":
        labels = ["exponential2:age", "exponential2:massformed", "dblplaw:tau", "dblplaw:massformed"]

    post_quantities = dict(zip(labels, [fit.posterior.samples[l] for l in labels]))

    tex_on = True
    update_rcParams()
    fig, axes = plt.subplots(1, 4)
    for i in range(4):
        hist1d(post_quantities[labels[i]], axes[i], smooth=True, label=labels[i])
        fixed_aspect_ratio(1,axes[i])
    fig.set_figwidth(6.75)
    plt.savefig("report/img/"+filename+"_posterior.pdf", bbox_inches = 'tight', pad_inches = 0)

    plt.clf()
    fig, ax = fit.plot_sfh_posterior(save=False, show=False)
    # fig.set_figwidth(6.75)
    plt.savefig("report/img/"+filename+"_sfh.pdf", bbox_inches = 'tight', pad_inches = 0)

    plt.clf()
    fig, ax = fit.plot_spectrum_posterior(save=False, show=False)
    # fig.set_figwidth(6.75)
    plt.savefig("report/img/"+filename+"_spec.pdf", bbox_inches = 'tight', pad_inches = 0)

    print_posterior(fit)