---
title: 'BAGPIPES: Bayesian Galaxy Spectral Inference'
url: https://www.emergentmind.com/topics/bagpipes
type: topic
---

# BAGPIPES: Bayesian Galaxy Spectral Inference

BAGPIPES, an acronym for **Bayesian Analysis of Galaxies for Physical Inference and Parameter EStimation**, is a Python tool for generating model galaxy spectra and fitting them to arbitrary combinations of spectroscopic and photometric data within a fully Bayesian framework [1712.04452]. Its stated primary goals are **on-the-fly generation of physically realistic galaxy spectra (200 Å–1 mm) including stars, nebular emission, dust and IGM effects**, and **Bayesian fitting of these models—either photometric, spectroscopic or combined—to infer physical parameters via MultiNest nested sampling** [1712.04452]. Across the literature summarized here, BAGPIPES functions both as a methodological framework for spectral energy distribution (SED) inference and as a vehicle for studying how assumptions about star-formation histories, attenuation laws, and wavelength coverage propagate into inferred galaxy properties such as stellar mass, star-formation rate, age, metallicity, quenching timescale, and formation redshift [1712.04452].

## 1. Definition, scope, and design philosophy

BAGPIPES was introduced as a **new Python tool which can be used to rapidly generate complex model galaxy spectra and to fit these to arbitrary combinations of spectroscopic and photometric data using the MultiNest nested sampling algorithm** [1712.04452]. The framework is described as **open-source**, **flexible**, **high-performance**, and **fully Bayesian**, with a design philosophy centered on **modular, component-based construction of a galaxy model** and an **intuitive Python API** in which **all model components and priors are passed as standard dictionaries** [1712.04452].

Its model space spans the UV–far-IR wavelength range, and its capabilities include arbitrary filter-set photometry, arbitrary-resolution spectra, stellar and gas velocity-dispersion convolution, nebular emission, dust attenuation and re-emission, and IGM absorption [1712.04452; 1811.03635]. The code can **load any grid of SSPs**, with the default setup described as **BC03 + MILES, Kroupa IMF** [1712.04452]. A related paper characterizes BAGPIPES as a framework whose principal goals are to enable **physically motivated priors on model parameters**, rapidly compute posterior distributions for galaxy properties, and expose how priors and model choices affect inferences about physical parameters and mass-assembly histories [1811.03635].

The scope of BAGPIPES has expanded beyond its original quiescent-galaxy use case. In the studies summarized here it is used for quiescent galaxies in UltraVISTA, low-redshift galaxies in GAMA, dusty galaxies at cosmic noon, faint galaxies at $z\sim 9$–16, stellar clusters in the Small Magellanic Cloud, and spectro-photometric JWST/NIRISS analyses of massive galaxies at $1<z<4.5$ [1712.04452; 1811.03635; 2312.05424; 2311.04294; 2310.15158; 2508.16951]. This suggests that BAGPIPES is less a narrowly specialized fitting script than a general SED-inference environment whose scientific behavior depends strongly on the chosen forward model and priors.

## 2. Spectral synthesis architecture and physical components

The generative model in BAGPIPES combines stellar populations, SFH components, dust attenuation, nebular emission, and IGM absorption into a composite luminosity. In the technical summary, each SFH is built from one or more components $SFR_j(t)$ summed as
$$
SFR(t)=\sum_{j=1}^{N_c} SFR_j(t),
$$
and the rest-frame luminosity per unit wavelength is written as
$$
L_\lambda(\lambda)=\sum_{j}\sum_{i} SFR_j(t_i)\,SSP(a_i,\lambda,Z_j)\,T^+(a_i,\lambda)\,T^0(a_i,\lambda)\,\Delta a_i.
$$
The observed flux is then
$$
f_{\lambda_{\rm obs}}(\lambda_{\rm obs})=\frac{L_\lambda(\lambda_{\rm obs}/(1+z))}{4\pi D_L^2(1+z)}\cdot T_{\rm IGM}(\lambda,z)
$$
[1712.04452].

Nebular emission is described as being **based on Cloudy (Byler 2017 prescription, age-dependent transmission $T^+$; user-set ionization parameter $\log U$ and birth-cloud lifetime $a_{BC}$)**, with **124 tracked features** plus diffuse continuum and warm dust for young stellar populations, and with **energy normalization** to ensure photon conservation [1712.04452]. Dust attenuation can be modeled using **Calzetti 2000, Cardelli 1989, and Charlot & Fall two-component laws**, while cold dust re-emission is represented by a **single-temperature greybody** with
$$
S_{gb}(\nu)\propto \nu^\beta B_\nu(T)
$$
[1712.04452]. IGM attenuation is implemented using the **Inoue 2014 analytic prescription** over $\lambda\in[912,1216]$ Å and complete absorption at $\lambda<912$ Å [1712.04452].

Several later studies exploit or modify these ingredients in domain-specific ways. For dusty galaxies at $z\sim1.5$–3.0, a **single modified blackbody (optically thin)** is used to re-emit the total energy absorbed in the UV–optical, with **energy balance** enforcing equality between absorbed and re-emitted luminosity [2312.05424]. In dust-law recovery experiments, BAGPIPES is coupled to a **Salim-modified Calzetti law**,
$$
A(\lambda)=A_V\,\frac{k_{\rm Cal}(\lambda)}{k_{\rm Cal}(5500\,\text{\AA})}\,\Bigl(\frac{\lambda}{5500\,\text{\AA}}\Bigr)^{\delta},
$$
with free $A_V$ and $\delta$ [2308.13974]. For high-redshift JWST galaxies, the code uses **Bruzual & Charlot (2003)** SSPs, **Calzetti et al. (1994)** attenuation, Cloudy-based nebular emission, and a free **Lyman-continuum escape fraction $f_{\rm esc}\in[0,1]$** to allow SEDs bluer than the default $f_{\rm esc}=0$ configuration [2311.04294]. For integrated photometry of stellar clusters, the setup is reduced to a single SSP with dust parameters fixed to zero and the ionization parameter frozen, such that emission lines play no role [2310.15158].

A plausible implication is that BAGPIPES should be understood as a forward-modeling container rather than a single astrophysical model. The code’s outputs are conditioned not only on the data, but also on choices about SSP library, attenuation law, dust-emission prescription, and nebular treatment.

## 3. Star-formation histories and parameterization choices

A central feature of BAGPIPES is its support for multiple parametric SFH families and, in later applications, non-parametric ones. The technical summary lists the following implemented forms, all zero for $t<0$: **delta**, **constant**, **exponential**, **delayed-$\tau$**, **log-normal**, **double-power-law**, and **custom** user-supplied tabulated histories [1712.04452]. The corresponding forms include
$$
SFR(t)\propto \exp[-(t-T_0)/\tau],
$$
$$
SFR(t)\propto t\exp(-t/\tau),
$$
$$
SFR(t)\propto \exp[-(\ln t-\mu)^2/(2\sigma^2)],
$$
and
$$
SFR(t)\propto \big[(t/\tau)^\alpha + (t/\tau)^{-\beta}\big]^{-1},
$$
with $\alpha$ controlling the falling slope and $\beta$ the rising slope in the double-power-law case [1712.04452; 1811.03635].

The 2018 analysis of parametric models emphasizes that BAGPIPES implements **four widely used, three-parameter families of parametric SFHs**—exponentially declining, delayed exponentially declining, lognormal, and double power law—each normalized to the total mass formed by observation time [1811.03635]. That study shows that these models impose strong implicit priors on derived quantities even when those quantities are not directly assigned priors. Specifically, by drawing SFHs from the prior alone, Carnall et al. find that **all four parametric families impose strongly peaked priors on sSFR $\sim10^{-10}\,\mathrm{yr}^{-1}$** and **favor $t_{MW}$ biased to times several Gyr later than the cosmic mass-assembly epoch implied by the Madau & Dickinson (2014) SFRD curve** [1811.03635]. They further report that **photometric data cannot discriminate among these SFH families**, despite the fact that inferred masses, SFRs, and mass-weighted ages vary with SFH choice by at least **0.1, 0.3 and 0.2 dex respectively** on high-quality mocks [1811.03635].

The original BAGPIPES paper responds to this model-selection issue pragmatically in its quiescent-galaxy application by adopting **double-power-law SFHs** with **log priors on $\alpha,\beta$**, finding on realistic MUFASA mocks that this configuration yields **stellar mass bias +0.02 dex** and **$t_{\rm form}$ and $t_{\rm quench}$ unbiased to $\lesssim0.1$ Gyr**, outperforming an exponential-$\tau$ parameterization [1712.04452]. Later work at $1<z<4.5$ expands the BAGPIPES SFH repertoire further by testing a **delayed-$\tau$ single-population model**, a **two-component model** combining delayed-$\tau$ and double-power-law burst terms, and a **non-parametric “continuity” SFH** with seven logarithmically spaced bins and Gaussian priors on adjacent-bin log-SFR ratios [2508.16951]. That study reports that **non-parametric SFHs generally imply an earlier and slower mass assembly compared to parametric forms**, especially for galaxies at $z<2$ [2508.16951].

The literature therefore treats SFH selection not as a secondary implementation detail but as one of the dominant determinants of BAGPIPES inferences. The recurring conclusion is not that one universal SFH form is optimal, but that parametric convenience can encode highly informative priors that are difficult to overcome with broadband photometry alone [1811.03635].

## 4. Bayesian inference, software organization, and workflow

BAGPIPES uses a standard Bayesian construction in which the posterior probability density of parameters $\Theta$ given data $D$ is
$$
P(\Theta|D)=P(\Theta)\,P(D|\Theta)/P(D),
$$
with $P(D)$ serving as the Bayesian evidence [1811.03635]. For photometric data with independent Gaussian errors, the technical summary gives
$$
\ln \mathcal{L}=-\frac{1}{2}\sum_i\left[\ln(2\pi \sigma_i^2)+\frac{(f_i-f_i^{\rm model})^2}{\sigma_i^2}\right],
$$
and BAGPIPES accesses **MultiNest** through **PyMultiNest** for nested sampling, posterior exploration, and evidence evaluation [1712.04452]. The sampler is described as suitable for **multimodal, degenerate, high-dimensional spaces**, with convergence diagnostics including **sampling efficiency** and **evidence uncertainty** [1712.04452].

The documented software architecture includes `bagpipes/model.py`, `sps.py`, `sfh.py`, `nebular.py`, `dust.py`, `igm.py`, `veldisp.py`, `priors.py`, `fitting.py`, and `visualization.py` [1712.04452]. Dependencies are listed as **Python 3.x, numpy, scipy, astropy, pymultinest, matplotlib**, with pre-computed Cloudy tables included [1712.04452]. Inputs can be provided as **Python dicts or JSON**, with photometry as **Astropy Table or numpy arrays**, and outputs include **posterior samples as HDF5/JSON** alongside built-in serialization methods such as `.to_json()` and `.to_fits()` [1712.04452].

The typical workflow described in the technical summary is: define model components and priors as Python dictionaries, load observational data, instantiate a `Fit` object with `sampler='multinest'`, run the fit, extract posterior samples and summaries, save results, and generate corner and SED plots [1712.04452]. Typical runtime is reported as **$O(10^2$–$10^3)$ sec per galaxy with $n_{\rm live}\sim400$**, depending on model complexity and data volume, while model generation proceeds at **$\sim200$ seds/s** and a typical fit on a dual-core machine takes **$\sim10$–30 min per galaxy** [1712.04452].

Later applications retain this basic inference pattern while altering the likelihood surface through different data modalities. The dusty-galaxy study uses a Gaussian photometric likelihood over UV-to-FIR bands and notes that, in the general BAGPIPES framework, **any nondetection can be included as an upper-limit by replacing the Gaussian term in the likelihood by an integral up to that limit** [2312.05424]. The JWST high-redshift study adds a **fractional-error term $\ln f$** scaling $\sigma_j\to f\,\sigma_j$ and draws **1,000 posterior models per galaxy** for downstream UV-slope analysis [2311.04294]. The MIDIS spectro-photometric analysis extends the data vector to include **binned spectral pixels**, convolving the model SED to **$R\simeq150$** with the grism line-spread function and fitting the joint photometric-plus-spectroscopic likelihood under independent Gaussian uncertainties [2508.16951].

## 5. Validation, degeneracies, and methodological limitations

BAGPIPES has been validated both through recovery experiments on mock galaxies and through tests aimed at identifying parameter degeneracies. In the original quiescent-galaxy paper, **677 simulated massive ($M_*>10^{10}\,M_\odot$) quenched galaxies from MUFASA snapshots at $z=0.5$–2.5** are used to test recovery of SFHs [1712.04452]. The study reports that an **exponential–$\tau$ SFH** yields **stellar mass bias +0.06 dex** and underestimates formation and quenching times by **$\sim0.4$ Gyr**, whereas the **double-power-law SFH** produces substantially smaller biases and stable recovery across observed redshift [1712.04452]. Evidence uncertainty is quoted as **$\lesssim0.5$ ($\log \mathcal{E}$)** with default settings [1712.04452].

The broader methodological critique comes from the parametric-SFH analysis, which demonstrates that good photometric fits do not guarantee unbiased mass-assembly inference [1811.03635]. Carnall et al. show that all four tested SFH families provide **statistically acceptable fits** to mock photometry, yet produce systematically different stellar ages and SFRs, and that reconstructions of the cosmic SFRD from GAMA photometry peak at **$z\sim0.4$**, approximately **6 Gyr later than direct observations suggest** [1811.03635]. Their conclusion is that simple parametric SFH models impose **strong, informative priors** that are often **physically unmotivated** and can dominate the inferred mass-assembly history [1811.03635].

A distinct class of limitations arises from parameter degeneracies. In the dust-law study, BAGPIPES is used to show a pronounced posterior degeneracy between **$A_V$ and $\delta$**, and also between **$A_V$ and SFR** [2308.13974]. However, adding WISE near-IR and mid-IR bands dramatically improves identifiability: the **scatter in $\Delta A_V$ shrinks from $\simeq0.38$ mag to 0.06 mag**, the **scatter in $\Delta\log{\rm SFR}$ goes from 0.26 dex to 0.06 dex**, and **residual correlation coefficients fall from $\sim0.9$ to $\lesssim0.1$** [2308.13974]. The same study concludes that BAGPIPES does **not introduce spurious correlations** between $A_V$ and $\delta$, and that the information required to constrain both parameters exists in the data, especially when IR bands are included [2308.13974].

At very high redshift, model flexibility itself becomes a limitation. The JWST NGDEEP analysis reports a **blue-floor bias**: even with $f_{\rm esc}=1$, the adopted **BC03+Calzetti dust+nebular continuum** setup limits the bluest recoverable $\beta_{\rm SED}\sim -3.25$, and simulated recovery plateaus at **$\beta_{\rm SED}\sim -2.8$** for intrinsically bluer slopes [2311.04294]. That study therefore notes that **more extreme stellar models** would be needed to test $\beta<-3$ [2311.04294]. This suggests that BAGPIPES can quantify uncertainty within a chosen model family while still inheriting hard boundaries from that family’s astrophysical ingredients.

## 6. Scientific results enabled by BAGPIPES

The original large-scale BAGPIPES application analyzed **9,289 quenched galaxies** from **UltraVISTA DR3** with **$M_*>10^{10}\,M_\odot$** over **$0.25<z<3.75$**, characterizing their SFHs using a mass-weighted formation redshift $z_{\rm form}$, a quenching redshift $z_{\rm quench}$, and a dimensionless quenching timescale
$$
\tau_{\rm quench}\equiv\frac{t(z_{\rm quench})-t(z_{\rm form})}{t(z_{\rm quench})}
$$
[1712.04452]. The study finds **three distinct $\tau_{\rm quench}$ populations**: a rapid class with **$\tau_{\rm quench}\sim0.1$** corresponding to **$\lesssim1$ Gyr** quenching, a dominant class with **$\tau_{\rm quench}\sim0.4$** corresponding to **1–2 Gyr**, and a slow class with **$\tau_{\rm quench}\sim0.6$** corresponding to **$\gtrsim3$ Gyr** [1712.04452]. These are interpreted respectively as being consistent with **quasar-mode AGN feedback**, **jet-mode AGN feedback**, and **cosmic gas exhaustion/strangulation** [1712.04452]. The same analysis confirms a **downsizing** trend and finds that **$61\pm8$ per cent of $z>1.5$ massive quenched galaxies undergo significant further evolution by $z=0.5$** [1712.04452].

In the context of dusty massive galaxies at cosmic noon, BAGPIPES is used to assess the impact of adding Herschel-SPIRE data to UV-to-NIR fitting. For a sample of **92 massive dusty galaxies** at **$z\sim1.5$ to 3.0**, the study finds that adding FIR/sub-mm data leaves stellar masses **essentially unchanged**, with
$$
M_{\star,\rm UV-FIR}/M_{\star,\rm UV-NIR}\lesssim 3
$$
in almost all galaxies, but can shift SFRs **by up to an order of magnitude** [2312.05424]. The direction of the SFR shift depends on the UV–NIR-inferred obscuration, and the changes are reported to correlate tightly with **$\Delta A_V$**, roughly as **$\Delta\log{\rm SFR}\propto \Delta A_V$** [2312.05424]. This is presented as evidence that FIR/sub-mm data are essential for accurately deriving the SFRs of massive dusty galaxies at $z\sim2$ [2312.05424].

BAGPIPES has also been applied to measurement problems not centered on quenching. In the NGDEEP JWST study of **36 faint star-forming galaxies at $z\sim9$–16**, BAGPIPES-derived SED fits are used to estimate the UV spectral slope $\beta$ and physical parameters [2311.04294]. The reported medians for the full sample are **$\beta_{\rm PL}=-2.7^{+0.5}_{-0.5}$**, **$\beta_{\rm SED}=-2.3^{+0.2}_{-0.1}$**, **$\beta_{\rm SED,corr}=-2.5^{+0.2}_{-0.2}$**, **$\log(M_*/M_\odot)=7.7^{+0.5}_{-0.5}$**, **$\log(\mathrm{age/yr})=7.8^{+0.2}_{-0.8}$**, **$A_V=0.1^{+0.2}_{-0.1}$ mag**, and **$\log(\mathrm{SFR}/M_\odot\,\mathrm{yr}^{-1})=-0.3^{+0.4}_{-0.4}$** [2311.04294]. The analysis finds **no strong evidence for ultra-blue UV spectral slopes ($\beta\sim-3$)** and states that the observations are consistent with metallicities **$\sim0.1$–0.2 $Z_\odot$** for galaxies of those stellar masses [2311.04294].

A further application moves outside galaxy-integrated SFH inference into stellar-cluster work. Using **12-band S-PLUS photometry**, one study fits **88 clusters** in the SMC with a single-SSP BAGPIPES model and constructs an empirical age–metallicity relation [2310.15158]. The reported agreement with literature values is **$\Delta\log(\mathrm{age})\approx0.31$ dex** and **$\Delta[\mathrm{Fe/H}]\approx0.41$**, while the cluster age distribution is described as **bimodal** with peaks at **$\log(\mathrm{age})\approx8.3$ and 9.6**, and the metallicity distribution as **bimodal at $[\mathrm{Fe/H}]\approx-0.4$ and $-0.8$** [2310.15158]. The study confirms an age gradient, with younger clusters toward the SMC center and older clusters at larger radii, but finds **no significant metallicity gradient** [2310.15158].

## 7. Extensions, interfaces, and future directions

BAGPIPES has acquired both interactive and spectro-photometric extensions. The **pipes_vis** interface is presented as **a new interactive graphical user interface (GUI) tool pipes_vis based on Bagpipes**, allowing **real-time manipulation of a model galaxy's star formation history, dust and other relevant properties through sliders and text boxes**, with the effect on the predicted SED **reflected instantaneously** [2107.12949]. Its stated purpose is to help build intuition about the nonlinear relationship between galaxy properties and predicted SEDs, potentially **helping to speed up fitting stages such as prior construction**, and supporting undergraduate and graduate teaching [2107.12949]. Within the boundaries of the provided abstract, pipes_vis is therefore best understood as a visualization layer rather than an alternative inference engine.

On the scientific side, the original BAGPIPES paper already identified future directions including **joint photometry + spectroscopy fitting**, **non-parametric SFHs and hierarchical population modeling**, and inclusion of **$\alpha$-elements and advanced dust emission physics** [1712.04452]. Subsequent work has partly realized this trajectory. The MIDIS study combines **broadband photometry from HST and JWST with low-resolution grism spectroscopy from JWST/NIRISS**, analyzing the data with BAGPIPES and a second code under different SFH assumptions [2508.16951]. It reports that inclusion of NIRISS spectroscopy **significantly improves constraints on key physical parameters, such as the mass-weighted stellar age ($t_M$) and formation redshift ($z_{\mathrm{form}}$), by narrowing their posterior distributions**, and that the most massive galaxies in the sample formed **50\% of their mass between $3\leq z\leq9$** [2508.16951]. The same study finds that **quiescent galaxies are, on average, older ($t_M\sim1.1$ Gyr)** and assembled more rapidly at earlier times than star-forming counterparts, in support of the **downsizing** scenario [2508.16951].

Across these developments, one recurrent theme is that BAGPIPES is most informative when used comparatively: comparing SFH classes, comparing data combinations, or comparing prior configurations. The code’s importance in the literature summarized here lies not only in parameter estimation, but also in making explicit how SED-fitting assumptions shape astrophysical conclusions [1712.04452; 1811.03635].

Source: https://www.emergentmind.com/topics/bagpipes