ACCarnall / bagpipes

Bagpipes is a state of the art code for generating realistic model galaxy spectra and fitting these to spectroscopic and photometric observations. Users should install with pip, not by cloning the repository.
http://bagpipes.readthedocs.io
GNU General Public License v3.0
81 stars 42 forks source link

Some arbitrary output #59

Closed MohammadRih closed 1 month ago

MohammadRih commented 11 months ago

Hi, I'm using bagpipes and I want to have some output about emission lines like [Lv, Lj, L1400, L2800, LOIII, LHa, ...]. Does the code, output these by default?! Or do we have to make settings to extract this information in the code manually?!

Thanks

MohammadRih commented 8 months ago

Hi again, After some investigation of your documentation, I see something like this: ‍‍‍‍‍model_galaxy.line_fluxes Now I have a small question about this option, Are these line_fluxes for the posterior or just the prior model?

ACCarnall commented 8 months ago

Hi, sorry I didn't get back about this originally. A model_galaxy object just contains a model with set parameters, it doesn't know anything about data (which is contained in galaxy objects) or fit posteriors (which are contained in fit objects). The code doesn't propagate line fluxes through into the fit.posterior.samples when fitting by default just to save on run time. If you want to generate posteriors for line fluxes using a completed fit you can do it with a function something like this:

def analysis_func(fit):

    ha_post = np.zeros(fit.n_posterior)

    fit.posterior.fitted_model._update_model_components(fit.posterior.samples2d[0, :])
    model_comp = fit.posterior.fitted_model.model_components
    model = pipes.model_galaxy(model_comp, spec_wavs=np.arange(5000., 15000., 2.5))

    for i in range(fit.n_posterior):
        fit.posterior.fitted_model._update_model_components(fit.posterior.samples2d[i, :])
        model_comp = fit.posterior.fitted_model.model_components
        model.update(model_comp)

        ha_post[i] = model.line_fluxes["H   1  6562.81A"]
MohammadRih commented 8 months ago

No, there is no problem. And thank you for this clear and straightforward solution providing.