Joint Bayesian calibration and map-making for intensity mapping experiments Zheng Zhang 1, Philip Bull 1,2, Mario G. Santos 2, and Ainulnabilah Nasirudin 1 1 Jodrell Bank Centre for Astrophysics, University of Manchester, Manchester, M13 9PL, United Kingdom 2 Department of Physics and Astronomy, University of Western Cape, Cape Town 7535, South Africa Abstract Line intensity maps have high dynamic range, and demand careful spectral and spatial calibration. We present a Bayesian framework for joint calibration and map-making using Gibbs sampling, which provides access to the full joint posterior of calibration and sky map parameters. Our data model incorporates instrumental noise based on the radiometer equation, capturing the coupling between noise level and system temperature without assuming a fixed noise amplitude. To enable unbiased and fast estimation of gain and system temperature, we develop an iterative generalised least squares (GLS) sampling method. Absolute flux calibration can be achieved either with external sources or internally using known signal injections, such as noise diodes. To handle stochastic gain variations, we introduce a 1 / f 1/f noise model that avoids spurious periodic correlations in the time domain caused by the conventional assumption of diagonal DFT noise covariance. Furthermore, we implement this workflow in an efficient software package, using the Levinson algorithm and a polynomial emulator to reduce the computational complexity of noise parameter sampling, ensuring good scalability. Although demonstrated for auto-correlation measurements, the framework and techniques generalise to cross-correlation and interferometric data. \pagerange Joint Bayesian calibration and map-making for intensity mapping experiments – keywords methods: data analysis – techniques: spectroscopic – radio lines: general 1 Introduction Line-intensity mapping (LIM) is a powerful technique for probing the large-scale structure of the Universe. It involves measuring the integrated emission from unresolved sources across cosmic volumes. By targeting specific spectral lines, such as the 21 cm hyperfine transition of neutral hydrogen ( Chang et al. 2010 ; Pritchard & Loeb 2012 ; Bull et al. 2015 ) or molecular lines like CO ( Righi et al. 2008 ) , LIM can efficiently map the three-dimensional distribution of matter over a wide range of redshifts, with access to fainter populations and larger volumes. Calibration and map-making are foundational steps of data processing in intensity mapping experiments, enabling the translation of raw detector signals into scientifically meaningful sky maps. Traditional approaches often decouple these processes, first calibrating the instrument’s gain and noise properties before reconstructing the sky map using linear or maximum-likelihood solvers ( Tegmark 1997b ; Sutton et al. 2010 ; Doré et al. 2001 ; Keihänen et al. 2005 , e.g.) . However, this sequential treatment can propagate calibration errors into the final map and neglect important interdependencies between gain variations, system temperature fluctuations, and noise statistics. These issues are especially pronounced in low-frequency radio experiments, where 1/f noise, thermal drifts, and other instrumental systematics can significantly impact data quality and bias sky reconstruction ( Bigot-Sazy et al. 2015 ; Harper et al. 2018 ; Chen et al. 2020 ; Hu et al. 2021 ; Li et al. 2021 ; Irfan et al. 2024 ) . Bayesian methods allow for the joint, global analysis of LIM data, rigorously propagating uncertainties and dependencies while incorporating prior knowledge. This approach yields exact posterior distributions and enables straightforward marginalisation over nuisance parameters. Recent advances in hierarchical Bayesian methods, particularly ultra high-dimensional implementations of Gibbs sampling, have enabled joint estimation of calibration parameters and sky signals by iteratively sampling from their conditional posteriors ( Wandelt et al. 2004 , e.g.) . This approach has been successfully applied to Cosmic Microwave Background (CMB) datasets through pipelines such as BeyondPlanck and Cosmoglobe , where calibration, noise modelling, and component separation are treated in a unified framework ( Galloway et al. 2023 ; Eskilt et al. 2023 ) . These developments offer a promising path for extending similar techniques to 21 cm cosmology and other intensity mapping experiments. However, replicating the success of joint Bayesian analysis in intensity mapping experiments is far from straightforward. There are two main reasons for this. First, compared with the CMB, the foreground components in intensity mapping are significantly brighter than the target signal ( Spinelli et al. 2022 , see e.g.) . Within the required dynamic range, these foregrounds cannot be reliably captured by simple empirical models, making standard component separation techniques from the CMB context less directly applicable. Second, intensity mapping experiments often contend with poorly understood or experiment-specific systematics, such as instrument-induced spectral structures ( Thyagarajan et al. 2015 ; Kern et al. 2019 ; Cunnington et al. 2021 ; McCallum et al. 2021 ; Murphy et al. 2024 ; Charles et al. 2024 ) , calibration drifts ( Harper et al. 2018 ; Chen et al. 2020 ; Li et al. 2021 ; Irfan et al. 2024 ) , and environmental effects like groundspill ( Wang et al. 2021 ) and radio-frequency interference ( Offringa et al. 2015 ; Harper & Dickinson 2018 ; Wilensky et al. 2022 ; Engelbrecht et al. 2025 ) . Given the complexity of these challenges, a fully end-to-end Bayesian framework would be rather complex and unwieldy, with many model components. Instead, a modular Bayesian pipeline – dividing the problem into stages – may offer a more tractable solution for the time being. In what follows, we specialise to autocorrelation or ‘single-dish’ intensity mapping experiments, which measure the total power from their receivers and use the resulting time-ordered data to make three-dimensional maps of line brightness temperature. Recent examples of such experiments include GBT ( Chang et al. 2010 ; Masui et al. 2013 ) , Parkes ( Anderson et al. 2018 ) , and FAST ( Li et al. 2023 ) single-dish observations with the 21cm line, the MeerKLASS multi-dish autocorrelation survey ( Santos et al. 2016 ; Wang et al. 2021 ) , also with the 21cm line, and the COMAP survey with CO lines ( Foss et al. 2022 ) . The data reduction and analysis steps for these types of experiment can be split into two major stages: (A) joint calibration and map-making from time-ordered data to a three-dimensional sky map, and (B) component separation and scientific inference from the resulting 3D map. The present work focuses on the implementation and demonstration of the feasibility of a fully Bayesian approach to stage (A). A complementary Bayesian approach to (B) is presented in G. Murphy et al. ( in prep. ) In designing our model and workflow, we identified two common pain points in standard calibration practices. First, noise modelling is often oversimplified: many existing frameworks either assume a fixed noise level during calibration or neglect the coupling between noise and system parameters. This contradicts the radiometer equation, which predicts that the noise variance scales multiplicatively with both the temperature of the system and the gain ( Burke et al. 2019 ) . Such simplifications can lead to biased parameter estimates ( Winkel et al. 2012 ) , especially in high-dynamic-range observations. Second, a major challenge in auto-correlation time-ordered data (TOD) is disentangling stochastic gain fluctuations, commonly referred to as 1/f noise, from the underlying sky signal. Unlike cross-correlation systems (interferometers), where correlated noise between detectors can be mitigated, auto-correlation measurements are inherently more sensitive to gain instabilities, as they depend on the squared response of a single detector. These stochastic gain variations couple multiplicatively with both system temperature and sky signal, introducing correlated noise and spectral leakage that contaminate both calibration and map reconstruction. Conventional methods either ignore these effects, or approximate 1/f noise in the Fourier domain with diagonal covariance matrices ( Bigot-Sazy et al. 2015 ; Harper et al. 2018 ; Li et al. 2021 ; Ihle et al. 2023 ) , a simplification that introduces unphysical periodic correlations in the time domain. Such approaches lead to a barrier to understanding the bias in system temperature estimates and the propagation of uncertainties. In this paper, we present a unified framework for joint calibration and map-making that rigorously addresses these limitations. At its core is a data model incorporating multiplicative noise derived directly from the radiometer equation, which self-consistently captures the interplay between time-varying gain, system temperature, and noise amplitude. Crucially, our formalism explicitly models stochastic gain variations with the time-domain parameters to be sampled alongside the smooth gain variation and system temperature. We avoid the common but flawed assumption of diagonal noise covariance in the Fourier domain, which artificially imposes periodic correlations [See Tegmark 1997a for a detailed discussion]. Instead, we derive a time-domain correlation model for 1/f noise that preserves realistic long-range temporal correlations without spectral leakage or edge artifacts. The global joint Bayesian workflow involves exploring a high-dimensional posterior distribution arising from the simultaneous inference of sky signal parameters and a large set of instrumental parameters, such as per-antenna and per-time-chunk gain values, as well as system temperature values. This high dimensionality poses significant computational and algorithmic challenges. To enable efficient sampling of the high-dimensional posterior distributions, we develop an iterative generalised least-squares (GLS) sampling method. This approach accelerates convergence by iteratively refining estimates of the effective additive noise covariance, which allows a fast linear sampling of smooth gain and system temperature parameters even for the multiplicative noise model. By treating stochastic gain as a correlated noise process, our framework not only mitigates 1/f contamination but also quantifies its uncertainty, ensuring robust error propagation into the final map. Computational scalability is achieved through the Levinson algorithm ( Levinson 1949 ) , which reduces the complexity of sampling noise parameters from \mathcal{O}(N^{3}) to \mathcal{O}(N^{2}) , ensuring scalability for large auto-correlation datasets. Absolute flux scale calibration can be implemented as strong priors on certain sky pixels in the workflow. While demonstrated here for auto-correlation systems, the framework is readily adaptable to cross-correlation or interferometric measurements by neglecting noise correlations and incorporating additional multiplicative gain terms. This work bridges a critical gap in auto-correlation data processing, where the combined effects of multiplicative noise and stochastic gain variations have historically limited calibration accuracy and map fidelity. By unifying the treatment of these effects within a statistically rigorous Gibbs sampling framework, we enable high-precision recovery of both instrument parameters and sky signals. To demonstrate this generic Bayesian workflow, we apply the pipeline to simulated MeerKLASS-type survey ( Santos et al. 2017 ) . The remainder of this paper is structured as follows: Section 2 presents the models of the data and each of its components and the intrinsic degeneracy of the model; Section 3 details the Gibbs sampling framework, including the noise parameter sampling and the iterative GLS method for sampling the system temperature and smooth gain parameters; Section 4 validates the framework through simulations, presents and discusses the map results; and Section 5 concludes with broader implications for radio astronomy and future extensions. 2 Statistical model Unlike conventional methods that employ either a given thermal noise level or treat it as an independent parameter, our data model directly incorporates the radiometer equation, representing thermal noise as a multiplicative term rather than as an additive form. We adopt a per-frequency data model for time-ordered auto-correlation data (TOD), in order to avoid imposing an explicit model for frequency correlations. Although frequency correlations (of 1/f noise) are known to exist, they are often not accurately characterised by simple analytical models ( Keshner 1982 ) . On the other hand, including frequency correlations can greatly improve constraints on the noise model parameters as data from many frequency channels can be combined to constrain a small number of noise model parameters. We do not consider frequency correlations in what follows. The basic model is d(t_{a})=G(t_{a})T_{\rm sys}(t_{a})\left(1+\hat{\mathit{w}}\right), (1) where a=0,\dots,n-1 is the time index of the TOD with n the number of data points, G is the time-dependent gain, T_{\rm sys} is the system temperature, and \hat{\mathit{w}} is the stochastic thermal noise fluctuation, which is typically Gaussian white noise with distribution \displaystyle\hat{\mathit{w}} \displaystyle\sim\mathcal{N}\left(0,\mathop{}\!\mathbf{N}_{w}\right), \displaystyle\mathop{}\!\mathbf{N}_{w} \displaystyle=\sigma_{w}^{2}\mathbf{I}, (2) where \mathbf{I} is an identity matrix of size N and \sigma_{w}=\frac{1}{\sqrt{\mathcal{T}\Delta\nu}} (3) with \Delta\nu the frequency channel width and \mathcal{T} the integration time. This is known as the radiometer equation ( Burke et al. 2019 , see e.g.) . The time-dependent gain, G(t_{a}) , accounts for all gain contributions, including stochastic variations, and is modeled as follows: G(t_{a})=g(t_{a})(1+\hat{\epsilon}), (4) where g(t_{a}) represents the large timescale evolution of the gain, and \hat{\epsilon} denotes the stochastic zero-mean variations. In most cases, the stochastic gain variations \hat{\epsilon} are modelled as 1/f noise (sometimes called flicker noise), while g is treated as a fairly smooth function to account for time-dependent gain variations that cannot be captured by the 1/f model. However, it is important to note that these noise models are usually only an empirical description of the noise power spectral density (PSD), far from being a complete stochastic model. To obtain complete noise statistics for data analysis, it is common practice to assume both Gaussianity and stationarity of the 1/f noise. We also adopt these assumptions, although we stress that they must be implemented carefully to avoid introducing spurious noise structures. In Section 2.2 we elaborate on this point and present a proper 1/f model. 2.1 Smooth gain variation This classical 1/f noise model is a phenomenological or empirical law (with some physical motivation) that is widely observed in electronics ( Keshner 1982 ) . It typically approximates the power spectrum of 1/f noise well on small time scales, but on larger time scales a single power-law statistical model may prove inadequate. There are at least two reasons for this: 1. The power-law structure may be a good approximation at certain scales, but may not be consistent across all scales. For example, suppose a gain system consists of three stage amplifiers in tandem, each with perfect 1/f noise. Then the total gain as the product of the three could appear as a deviated power-law PSD. See Appendix B for a detailed discussion. 2. As the time scale increases, the corresponding number of samples decreases, leading to greater sampling variance and greater uncertainty in estimating the statistical structure of the PSD at large scales. As a result, even for perfect 1/f noise, the estimated power spectrum may deviate from power-law behaviour at lower temporal frequencies. Conversely, the sparse sampling of the PSD at low Fourier frequencies makes reliably inferring the true spectral behaviour (if it is scale-dependent) difficult. To improve the accuracy of the gain model, g(t_{a}) is typically fitted with a smooth time-dependent function. This function can be parameterised using the first few Legendre polynomials ( Wang et al. 2021 ) , which in linear algebra terms can be writen as \vec{g}=\mathbf{U}_{\rm g}\,\bm{p}_{\rm g}, (5) where \bm{p}_{\rm g} is the vector of polynomial coefficients, and \mathbf{U}_{\rm g} is the design matrix formed from evaluations of the Legendre polynomials. In this paper, we use four modes as an example, but this number can be adjusted as needed. Adopting a linear model is instructive, as it enables the use of a linear solver for Gibbs sampling, significantly enhancing computational tractability. 2.2 Flicker noise model Figure 1 : Comparison between the conventional 1/f noise model [Uncorrelated DFT modes (Case 1); see Appendix A ] and our analytical approach (Case 2; see Section 2.2 ). Left : Time-domain correlation function. Middle : Power Spectral Density (PSD; defined with DFT), normalised by that of white noise. The vertical line marks the knee frequency ( 1 mHz), where the flicker noise power matches that of white noise (shown by the horizontal line). Right : Time-time covariance matrix. This figure highlights the consequences of periodicity assumptions in DFT-based 1/f noise models. In Case 1, the diagonal covariance in DFT space leads to artificial periodic and symmetric correlations in the time domain. In contrast, our model (Case 2) yields a covariance consistent with the underlying Gaussian statistics and statistical homogeneity of the noise. Both models share the same PSD power law and knee frequency. For Case 2, the parameters are f_{c}=1.099\times 10^{-3} (rad/s) and f_{0}=1.335\times 10^{-5} (rad/s). On shorter timescales than the smooth gain model covers, we introduce a stochastic flicker noise model. The stochastic fractional gain variation, \hat{\epsilon} , is typically characterised by a 1/f noise spectrum with a power-law PSD 1 1 1 See Appendix A for a proper definition and normalisation in the finite discrete frequency domain. 2 2 2 Temporal frequencies in this work are expressed as angular frequencies, with units of radians per second. The only exception is the knee frequency, traditionally given in cycles per second (Hz), a convention we maintain. P_{\hat{\epsilon}}(f)=\begin{cases}0,&|f|0, (9) \displaystyle\mu=1-\alpha,\quad\Theta_{0}=\tau f_{0},\quad\Theta_{c}=\tau f_{c}, where \Gamma is the incomplete gamma function and “ \mathrm{Re}[A] ” is the real part of A . For \tau<0 we have \xi(\tau)=\xi(-\tau) ; for \tau=0 the integral can be evaluated directly, which gives \xi(0)=\frac{1}{\alpha-1}\frac{f_{c}}{\pi}\left(\frac{f_{0}}{f_{c}}\right)^{\alpha} . Using this correlation function, we can compute the proper time domain covariance matrix, which is then used to define the likelihood or simulate 1/f noise. Figure 1 compares our analytical model with the conventional approach. An additional discussion on full gain modelling can be found in Appendix B . 2.3 System temperature model The system temperature can be modelled as the sum of several components: sky emission, receiver temperature, and contributions from ground and atmospheric effects ( Wang et al. 2021 ) . For measurements using internal calibration sources, we also need to account for the intentional signal injection, but with known specific characteristics. Without loss of generality, the complete model can be expressed as: T^{\rm sys}_{j,x}(t_{a},\nu_{b})=\sum_{X}B^{X}_{x}(t_{a},\nu_{b})\ast T^{\text{sky},X}(\nu_{b})+\mathit{T}^{\rm el}_{x}(t_{a},\nu_{b})\\ +T_{j,x}^{\rm nd}(t_{a},\nu_{b})+T_{j,x}^{\text{rec}}(t_{a},\nu_{b}), (10) where j indexes the antenna and x is the feed; together they specify the receiver. T^{\text{sky},X} represents the polarised sky emission, with X denoting I,Q,U,V , the Stokes parameters. \mathit{T}^{\rm el}_{x} is the elevation-dependent terrestrial emission, including the atmospheric emission and the ground pickup. T_{j,x}^{\rm nd} represents an artificially injected signal that is typically used as an internal calibration source. It is specifically introduced to represent the temperature contribution from a noise diode. A real-world example of this implementation can be found in MeerKAT’s 4 4 4 MeerKAT is a 64-dish radio telescope array, one of whose science goals is 21 cm intensity mapping using its single-dish mode ( Wang et al. 2021 ) . periodic noise diode injection system ( Wang et al. 2021 ) . The remaining component is the receiver temperature, T_{j,x}^{\text{rec}} , which is simply assumed to be a smooth function of time. It thus functionally absorbs uncaptured effects or offsets in models. It is important to note that while the Stokes I and V beams remain constant in celestial coordinates, the Q and U beams, which are not scalar fields, change as the antenna pointing changes. Therefore, the ‘ \ast ’ in the above equation should not be understood as convolutions with constant beams, and careful definitions of the Q and U beams should be taken into account (see Zhang 2023 for a detailed discussion). In this paper, we consider only the Stokes- I sky for convenience, as this is sufficient to demonstrate the analysis framework we propose. Based on this, the polarisation cases can be extended directly, by adding three more components linearly to the model. Finally, we adopt a system temperature model that represents all components linearly: \begin{split}\bm{T}_{\rm sys}&=\bm{T}_{\rm cel}+\bm{T}_{\rm nd}+\bm{T}_{\rm rec}+\bm{T}_{\rm el}\\ &=\mathbf{U}_{\rm cel}\,\bm{p}_{\rm cel}+\mathbf{U}_{\rm nd}\,\bm{p}_{\rm nd}+\mathbf{U}_{\rm rec}\,\bm{p}_{\rm rec}+\mathbf{U}_{\rm el}\,\bm{p}_{\rm el}\\ &\equiv\mathbf{U}_{\rm cel}\,\bm{p}_{\rm cel}+\mathbf{U}_{\rm loc}\,\bm{p}_{\rm loc}\end{split} (11) where the celestial sky, \bm{T}_{\rm cel} , (consisting of all components stationary on the celestial sphere) is parameterised by its individual pixels. \bm{T}_{\text{el}} can be modelled as a smooth function of elevation using e.g. a Legendre polynomial, while \bm{T}_{\text{rec}} can be modelled with a smooth function of time. If, depending on the scanning strategy, the elevation of the pointing centre is itself a smooth function of time, then the \bm{T}_{\text{el}} sequence is also smooth with respect to time. Given these considerations, we can use a single combined term – modelled, for example, with a Legendre polynomial – to represent the smooth time-dependent component, effectively capturing the combined contribution of \bm{T}_{\text{rec}} and \bm{T}_{\text{el}} . In the final line of Eq. ( 11 ), we group the system temperature parameters into two components: \bm{p}_{\rm cel} , which contains the parameters common to all TOD sets, and \bm{p}_{\rm loc} , which captures the residual, independent parameters specific (or ‘local’) to each TOD set. 2.4 Model degeneracies and absolute calibration In previous sections we have described our general data model, which makes optimal use of linear modelling. We now inspect possible model parameter degeneracies: 1. Large scale gain and flicker noise parameters 2. Flux scale degeneracy between gain and system temperature. 3. DC mode degeneracy between system temperature components. To mitigate these degeneracies, known as absolute calibration, we typically require precise knowledge of specific aspects of T_{\rm sys} . This knowledge can be acquired in at least two ways: • External calibration : Known T_{\rm sky} parameters (pixels) for specific calibration sources; • Internal calibration : Knowledge of the absolute level of other T_{\rm sys} components. These constraints can be incorporated by placing priors on the corresponding components. As an example, in our subsequent demonstrations, we assume prior knowledge of specific sky pixel(s) used as external calibration source(s). 3 Joint analysis framework 3.1 Probability functions and Gibbs sampling It is usually the case that both the stochastic gain ( \hat{\epsilon} ) and the thermal fluctuation ( \hat{w} ) are small quantities so that their product term is trivial and can be omitted. The data model is then rewritten as d(t_{a})\simeq g(t_{a})T_{\rm sys}(t_{a})\left[1+\hat{\mathit{w}}+\hat{\epsilon}\right]. (12) For ease of formalising probability function, we define the scaled, centred data as n(t_{a})\equiv\frac{d(t_{a})}{g(t_{a})T_{\rm sys}(t_{a})}-1\simeq\hat{\mathit{w}}+\hat{\epsilon}. (13) We also introduce the column vector notation \bm{n} for the time sequence of all scaled data points. Assuming independent Gaussian statistics for both \hat{\epsilon} and \hat{w} , the likelihood function of the data model is given by L(\bm{n}|g,T_{\rm sys},\mathbf{N})=(2\pi)^{-\frac{N}{2}}|\mathbf{N}|^{-\frac{1}{2}}\exp{\left[-\frac{1}{2}\bm{n}^{T}\mathbf{N}^{-1}\bm{n}\right]}, (14) where \mathbf{N} is the total noise covariance matrix, given as the sum of the two components \mathbf{N}=\mathop{}\!\mathbf{N}_{w}+\mathop{}\!\mathbf{N}_{\text{corr}}, (15) and |\mathbf{N}| represents the determinant of \mathbf{N} . Note that the normalisation term, |\mathbf{N}|^{-1/2} , should be retained to fit or sample the noise parameters. Maximizing the likelihood is effectively minimizing the negative logarithmic likelihood function defined as \mathcal{L}=-2\ln{L}=\ln{|\mathbf{N}|}+\Tr(\mathbf{N}^{-\!1}\mathbf{D}), (16) where \mathbf{D}=\bm{n}\,\bm{n}^{\top} , and we have omitted the constant term in the second equation. Similar to \mathcal{L} , we also define the negative logarithmic prior ( \mathcal{P}_{\rm prior} ) and posterior ( \mathcal{P}_{\rm post} ) so that Bayes’ Theorem can be written as \mathcal{P}_{\rm post}=\mathcal{P}_{\rm prior}+\mathcal{L} (17) where we have dropped the logarithmic evidence as we have specified the model to be used. For complex probability functions such as Eqs. ( 16 , 17 ) with numerous parameters direct estimation becomes impractical. Therefore, we use sampling-based approaches, specifically the Gibbs sampling method. This method iteratively samples from conditional distributions (denoted as p(x|y) ) to approximate the joint distribution. Specifically, we follow these Gibbs sampling steps: \displaystyle\bm{p}_{\rm g}^{(i+1)}\leftarrow \displaystyle\,p(\bm{p}_{\rm g}|\bm{d},\bm{p}_{\rm cel}^{(i)},\bm{p}_{\rm loc}^{(i)},f_{0}^{(i)},\alpha^{(i)}) (18a) \displaystyle f_{0}^{(i+1)},\alpha^{(i+1)}\leftarrow \displaystyle\,p(f_{0},\alpha|\bm{d},\bm{p}_{\rm cel}^{(i)},\bm{p}_{\rm loc}^{(i)},\bm{p}_{\rm g}^{(i+1)}) (18b) \displaystyle\bm{p}_{\rm loc}^{(i+1)}\leftarrow \displaystyle\,p(\bm{p}_{\rm loc}|\bm{d},\bm{p}_{\rm cel}^{(i)},\bm{p}_{\rm g}^{(i+1)},f_{0}^{(i+1)},\alpha^{(i+1)}) (18c) \displaystyle\bm{p}_{\rm cel}^{(i+1)}\leftarrow \displaystyle\,p(\bm{p}_{\rm cel}|\bm{d},\bm{p}_{\rm loc}^{(i+1)},\bm{p}_{\rm g}^{(i+1)},f_{0}^{(i+1)},\alpha^{(i+1)}) (18d) where the first three samplers can be run independently for each TOD set, whereas the final sampler (for the sky maps) must be applied jointly across all TOD sets. The last two steps can be combined into one larger, joint linear system. The essential idea of Gibbs sampling is that we expect the conditional probability functions to have a simpler form, making them numerically tractable. Indeed, as we will see in sections 3.2 , both the gain and system temperature samplers can be implemented as multivariate Gaussian distributions in the coefficients of linear basis functions. However, sampling the noise parameters (section 3.3 ) does not result in a similarly linear problem. As an alternative, we employ an MCMC sampler. Nonetheless, we can leverage the structure of the flicker noise covariance (real symmetric Toeplitz) to significantly reduce computational complexity. 3.2 Iterative GLS sampler for the smooth gain and system temperature parameters In this section, we present a generic approach that can be applied to both the gain and system temperature parameters, i.e. the linear model coefficients in Eqs. ( 18a ), ( 18c ) and ( 18d ). For a general multivariate Gaussian, sampling the linear model parameters of its mean can be transformed into a linear system problem. However, unlike such problems, our data model employs a multiplicative noise term rather than an additive one. The advantage of this approach is that it accurately captures the coupling between the thermal noise level and the system temperature. However, the inherent noise structure with parameter-dependent noise variance violates the exogeneity assumption ( Greene 2000 , see e.g. Chapter 4 of ) of Maximum Likelihood methods, also known as Generalized Least Squares (GLS), leading to significant biases in estimation. To address this, we use an iterative GLS method, which essentially transforms the multiplicative noise into a consistent additive noise. 3.2.1 Formulation Specifically, whether sampling g or T_{\rm sys} , the data model can be expressed as \bm{d}^{\prime}=(\mathbf{U}\bm{p}+\bm{\mu})\circ(1+\bm{n}), (19) with \bm{d}^{\prime} the data vector, \bm{p} the parameter vector, \mathbf{U} the projection matrix, and \bm{p} -independent vector \bm{\mu} . The “ \circ ” means elementwise multiplication. The noise vector \bm{n} is assumed zero-mean Gaussian with known covariance \mathbf{N} , as defined in Eq. ( 15 ). We rewrite the original multiplicative noise model into an additive noise model: \bm{d}^{\prime}-\bm{\mu}=\mathbf{U}\bm{p}+(\mathbf{U}\bm{p}+\bm{\mu})\circ\bm{n}. (20) The rearrangement results in a form that resembles the commonly used data model: \bm{d}^{\prime\prime}=\mathbf{U}\bm{p}+\bm{\delta},\quad\bm{\delta}\sim\mathcal{N}(0,\mathbf{\Sigma}), (21) where \bm{d}^{\prime\prime}=\bm{d}^{\prime}-\bm{\mu} and the noise covariance structure is given by: \mathbf{\Sigma}=\text{diag}(\mathbf{U}\bm{p}+\bm{\mu})\,\mathbf{N}\,\text{diag}(\mathbf{U}\bm{p}+\bm{\mu}). (22) Note that the noise covariance \mathbf{\Sigma} is correlated with the parameters \bm{p} , rendering standard GLS biased. Instead, we first estimate \mathbf{\Sigma} using an iterative GLS approach. Then we sample \bm{p} (see section 3.2.2 and 3.2.3 ). To estimate the covariance of the effective additive noise term, we solve for the GLS estimate of \bm{p} iteratively: 1. Initialize \bm{p}^{(0)} using Ordinary Least Squares (OLS): \bm{p}^{(0)}=(\mathbf{U}^{\top}\mathbf{U})^{-1}\mathbf{U}^{\top}\bm{d}^{\prime\prime}. (23) 2. At iteration k , compute \mathbf{\Sigma}^{(k)}=\text{diag}(\mathbf{U}\bm{p}^{(k)}+\bm{\mu})\,\mathbf{N}\,\text{diag}(\mathbf{U}\bm{p}^{(k)}+\bm{\mu}). (24) 3. Solve the GLS system: \left[\mathbf{U}^{\top}\left(\mathbf{\Sigma}^{(k)}\right)^{-1}\mathbf{U}\right]\bm{p}^{(k+1)}=\mathbf{U}^{\top}\left(\mathbf{\Sigma}^{(k)}\right)^{-1}\bm{d}^{\prime\prime}. (25) 4. Repeat until convergence: \|\bm{p}^{(k+1)}-\bm{p}^{(k)}\|<\text{tol} . The final converged solution gives the estimated parameter \bm{p}_{\text{GLS}} , and thus the estimated noise covariance, \mathbf{\Sigma} : \mathbf{\Sigma}=\text{diag}(\mathbf{U}\bm{p}_{\rm GLS}+\bm{\mu})\,\mathbf{N}\,\text{diag}(\mathbf{U}\bm{p}_{\rm GLS}+\bm{\mu}). (26) Note that solving Eq. ( 25 ) requires the inverse of \mathbf{\Sigma}^{(k)} . This involves inverting the diagonal matrices in Eq. ( 24 ) and multiplying by the precomputed inverse of \mathbf{N} , which remains constant when the flicker noise parameters are fixed. 3.2.2 Sampling gain and local system temperature parameters The idea behind sampling in probabilistic analysis is to draw random model parameters such that the sample distribution reflects the underlying probability density function. A special case arises when the conditional probability distribution is multivariate Gaussian; in this case, solving the system of measurement equations becomes a GLS problem. By adding a random noise realisation to the linear system, the noise covariance is propagated into the parameter space, effectively yielding samples that follow the desired distribution. To support this linear sampling method, priors are typically modelled as a multivariate Gaussian (specified by the mean \bar{\bm{p}} and the covariance matrix \mathbf{C} ), which can be interpreted as an additional independent noise contribution to the effective linear system. We refer to the steps in the Gibbs sampler that operate on such multivariate Gaussian distributions as Gaussian Constrained Realisation (GCR) steps ( Wandelt et al. 2004 ; Eriksen et al. 2008 ; Kennedy et al. 2023 ) . In the framework of the iterative GLS sampler, once the effective additive noise covariance \mathbf{\Sigma} is estimated, we sample \bm{p} from its conditional posterior distribution by solving the following GCR equation \left(\mathbf{C}^{-1}+\mathbf{U}^{\top}\mathbf{\Sigma}^{-1}\mathbf{U}\right)\bm{p}_{\text{sample}}=\\ \mathbf{U}^{\top}\left(\mathbf{\Sigma}^{-1}\bm{d}^{\prime\prime}+\mathbf{\Sigma}^{-\frac{1}{2}}\bm{\omega}\right)+\mathbf{C}^{-1}\bar{\bm{p}}+\mathbf{C}^{-\frac{1}{2}}\bm{\eta}, (27) where \bm{\omega} is an uncorrelated unit Gaussian random draw with the same dimension as the data vector, while \bm{\eta} is another independent Gaussian random draw but with the dimension of the parameter vector. More specifically, the (i+1) -th sample of the gain parameters \bm{p}^{(i+1)}_{\rm g} is obtained from the conditional posterior ( 18a ) by solving Eq. ( 27 ) for \bm{p}_{\text{sample}} with \displaystyle\bm{d}^{\prime\prime}=\bm{d}/\bm{T}_{\rm sys}^{(i)},\quad\quad\mathbf{U}=\mathbf{U}_{\rm g},\quad\mathbf{C}=\mathbf{C}_{\rm g},\quad\bar{\bm{p}}=\bar{\bm{p}}_{\rm g}, \displaystyle\mathbf{\Sigma}\xleftarrow{\text{Eq.~(\ref{eq: final Sigma})}}\bm{p}^{(i+1)}_{\rm g,GLS}\xleftarrow{\text{iterative GLS}}\bm{T}_{\rm sys}^{(i)},f_{0}^{(i)},\alpha^{(i)}, where \bm{T}_{\rm sys}^{(i)}=\mathbf{U}_{\rm cel}\,\bm{p}_{\rm cel}^{(i)}+\mathbf{U}_{\rm loc}\,\bm{p}_{\rm loc}^{(i)} and \mathbf{N}^{(i)} represents the sample of system temperature after the i -th Gibbs sampling step. The (i+1) -th sample of the local system temperature parameters \bm{p}_{\rm loc} is obtained from the conditional posterior ( 18c ) by solving Eq. ( 27 ) for \bm{p}_{\text{sample}} with \displaystyle\bm{d}^{\prime\prime}=\bm{d}/\bm{g}^{(i+1)}-\mathbf{U}_{\rm cel}\bm{p}^{(i)}_{\rm cel},\quad\quad\mathbf{U}=\mathbf{U}_{\rm loc},\quad\mathbf{C}=\mathbf{C}_{\rm loc},\quad\bar{\bm{p}}=\bar{\bm{p}}_{\rm loc}, \displaystyle\mathbf{\Sigma}\xleftarrow{\text{Eq.~(\ref{eq: final Sigma})}}\bm{p}^{(i+1)}_{\rm loc,GLS}\xleftarrow{\text{iterative GLS}}\bm{g}^{(i+1)},\bm{p}^{(i)}_{\rm cel},f_{0}^{(i+1)},\alpha^{(i+1)}, where \bm{g}^{(i+1)}=\mathbf{U}_{\rm g}\,\bm{p}_{\rm g}^{(i+1)} represents the smooth gain sample after the Gibbs sampling step of Eq. ( 18a ). As these sampling steps for different TOD sets are independent, they can be carried out in parallel. 3.2.3 Sampling celestial sky parameters Since all TOD sets share the sky parameters \bm{p}_{\rm cel} , the sampler must combine the groups under the assumption that the sky temperature is consistent across these observations. The noise in different TOD sets is modelled independently. Thus, Eq. ( 27 ) can naturally be extended to accommodate multiple TODs: \left(\mathbf{C}^{-1}+\sum_{j}{\mathbf{U}_{j}}^{\top}\mathbf{\Sigma}_{j}^{-1}\mathbf{U}_{j}\right)\bm{p}_{\text{sample}}=\\ \sum_{j}{\mathbf{U}_{j}}^{\top}\left[\mathbf{\Sigma}_{j}^{-1}\bm{d}^{\prime\prime}_{j}+\mathbf{\Sigma}_{j}^{-\frac{1}{2}}\bm{\omega}_{j}\right]+\mathbf{C}^{-1}\bar{\bm{p}}+\mathbf{C}^{-\frac{1}{2}}\bm{\eta}, (28) where j is the index of the TOD set within the group. The specific implementation of the Gibbs sampling step [Eq. ( 18d )] is given by \displaystyle\bm{d}_{j}^{\prime\prime}=\bm{d}_{j}/\bm{g}_{j}^{(i+1)}-\mathbf{U}_{\rm loc,j}\bm{p}^{(i+1)}_{\rm loc,j},\quad\mathbf{U}=\mathbf{U}_{\rm cel},\quad\mathbf{C}=\mathbf{C}_{\rm cel},\quad\bar{\bm{p}}=\bar{\bm{p}}_{\rm cel}, \displaystyle\mathbf{\Sigma}\xleftarrow{\text{Eq.~(\ref{eq: final Sigma})}}\bm{p}^{(i+1)}_{\rm cel,GLS}\xleftarrow{\text{iterative GLS}}\bm{g}_{j}^{(i+1)},\bm{p}^{(i+1)}_{\rm loc,j},f_{0,j}^{(i+1)},\alpha^{(i+1)}_{j}. We note that the dimension of this linear system matches that of \bm{p}_{\rm cel} and is independent of the number of TOD sets. Assuming the computational cost is dominated by the summation over all TODs in Eq. ( 28 ), the overall complexity scales linearly with the number of TOD sets. 3.3 Flicker noise parameter sampler Figure 2 : Execution time comparison of three computational methods for evaluating the log-likelihood with real symmetric Toeplitz noise covariance matrices. We compare three implementations, listed in order of decreasing computational complexity: (1) using NumPy ’s slogdet and solve ; (2) using NumPy ’s slogdet combined with SciPy ’s solve_toeplitz ; (3) using our own comat implementation. As shown, comat outperforms the other methods in terms of execution time. This benchmark analysis was performed on a Mac Studio equipped with an Apple M3 Ultra chip. In this section, we discuss how to sample the two noise parameters \{f_{0},\alpha\} for each TOD set independently [see Eq. ( 18b )], when the sample of smooth gain and system temperature are provided. The main effort to sample the noise parameters is to calculate the logarithmic determinant and the quadratic form involving \mathbf{N}^{-1} in Eq. ( 16 ). At first glance, the computation appears intractable for large data sizes, since it involves frequent computation of the inverse and determinant of a non-diagonal matrix, which would seem to imply a computational complexity of \mathcal{O}(N^{3}) . However, by recognising the unique structure of \mathbf{N} , which has a single repeated element along each of its diagonals, we can see that it can be transformed into a \mathcal{O}(N^{2}) -flops computation. The quadratic form can be reformulated as the inner product of two vectors: \Tr(\mathbf{N}^{-\!1}\mathbf{D})=\bm{n}^{\top}\bm{x} , where \bm{x} is obtained by solving \mathbf{N}\bm{x}=\bm{n}. 5 5 5 Here \bm{n} , as defined in Eq. ( 13 ), is the residual of the data with the gain and system temperature sample. This linear equation can be solved quickly with \mathcal{O}(N^{2}) time complexity using the Levinson-Durbin recursion algorithm. The same recursion algorithm can be used to compute the logarithmic determinant term. We produce a fast dedicated code, comat 6 6 6 https://github.com/zzhang0123/comat , for the joint computation of the log-determinant, \ln{|\mathbf{N}|} , and the quadratic form, \Tr(\mathbf{N}^{-1}\mathbf{D}) . The algorithm is presented in Appendix D.1 . To benchmark computational efficiency, Figure 2 compares the execution time of comat with two alternative implementations. For a typical TOD length of a few thousand time samples, comat enables the log-likelihood to be calculated in tens of milliseconds or less on an M3 Mac – roughly ten times faster than other methods. In addition, we present a perturbative method in Appendix D.2 for computing the inverse and determinant of the noise covariance matrix. While this approach exhibits superior numerical performance, it is valid only under the assumption of very weak 1/f noise. Nevertheless, due to its computational advantages, we include it for reference. To accommodate a broader range of flicker noise scenarios, we adopt the Levinson algorithm as the primary method in this work. 4 Demonstration This section presents a series of analyses using simulated time-ordered data (TOD) to validate the proposed method. These analyses mimic MeerKAT’s single-dish observing mode ( Wang et al. 2021 ) . The performance of our joint calibration and map-making approach is evaluated under various experimental configurations (summarised in Section 4.1 ) and prior setups (summarised in Section 4.2 ), with a detailed analysis presented in Section 4.3 . Table 1 : Specifications of the simulation configuration Telescope location (lat, lon, height) ( -30.713^{\circ} , 21.443^{\circ} , 1054 m) Beam Gaussian (FWHM =1.1^{\circ} ) Sky/Beam pixelation N_{\rm side}=64 Scan speed (along azimuth) 5 arcmin/s Frequency 750 MHz Frequency resolution 0.2 MHz Exposure time (per scan) 1.5 hr Time resolution 2 s Elevation (“setting”) 41.5^{\circ} Elevation (“rising”) 40.5^{\circ} Az range (“setting”) (-60.3^{\circ},-42.3^{\circ}) Az range (“rising”) (43.7^{\circ},61.7^{\circ} ) Start time (“setting”) “2019-04-23 20:41:56” Start time (“rising”) “2019-03-30 17:19:02” Gain coefficients (“setting”) {6.312, 0.420, 0.264, 0.056} Gain coefficients (“rising”) {6.845, 0.142, 0.744, 0.779} Diode injection 15 K (every 10 data points) Residual T_{\rm sys} coefficients {12.6, 0.5, 0.5, 0.5} 1/f noise cutoff frequency f_{c} 1.099\times 10^{-3} rad/s 1/f noise reference frequency f_{0} 1.335\times 10^{-5} rad/s Effective knee frequency 1 mHz 1/f noise PSD power index -2 (a) 1\times TOD : Scan pattern and calibration sources. (b) 1\times TOD : Covered sky map. (c) 1\times TOD : Integrated beam intensity. Figure 3 : Scan pattern, covered sky and integrated beam intensity for the “ 1\times TOD” configuration. In panel (c), each beam is normalised to unit peak intensity ( B_{\rm peak} ); the color scale shows the summed response in units of B_{\rm peak} . (a) 2\times TOD : Scan pattern and calibration sources. (b) 2\times TOD : Covered sky map. (c) 2\times TOD : Integrated beam intensity. Figure 4 : Scan pattern, covered sky and integrated beam intensity for the “ 2\times TOD” configuration. In panel (c), each beam is normalised to unit peak intensity ( B_{\rm peak} ); the color scale shows the summed response in units of B_{\rm peak} . 4.1 Experimental setup To emulate realistic observational conditions, we simulated two distinct time-ordered data (TOD) sets, each of which fully replicates MeerKAT’s single-dish observing patterns. These are denoted as the ‘setting’ and ‘rising’ modes based on differences in scan strategy (as detailed in subsequent Section 4.1.1 ). Using these simulations, we designed two Bayesian analysis workflow scenarios: • “ 1\times TOD”: Only the “setting”-mode TOD set is used. • “ 2\times TOD”: Both the “setting” and “rising” TOD sets are used. This design serves two purposes: (1) Validating the workflow’s capability to process both single and multiple TOD sets; (2) Quantifying map-making accuracy by comparing results between the “ 1\times TOD” and “ 2\times TOD” configurations. Further experimental details are provided in subsequent sections. Figures 3 and 4 illustrate the two scenarios. The key parameters are summarised in Table 1 . 4.1.1 Scanning strategy The MeerKAT scanning strategy involves rapidly moving dishes in azimuth at a constant elevation to minimize variations from ground spill and airmass. Scanning is done at 5 arcmin/s, ensuring the pointing remains within the primary beam during each 2 -second time dump. This allows coverage of 10^{\circ} in 100 seconds, matching the time-scale over which receiver gain remains relatively stable. Each scan stripe is 18^{\circ} wide, with back-and-forth slews taking about 200 seconds. At a fixed elevation, each sky strip can be scanned using two methods: one when the field is rising and one when the field is setting. These two scans overlap, as shown in Figure 4 , providing improved sky coverage in the overlap region. In this work, we simulate two TOD sets corresponding to the “rising” mode and the “setting” mode, respectively. 4.1.2 Power beam and sky model We adopt a Gaussian beam with a full width at half maximum (FWHM) of 1.1^{\circ} to approximate the MeerKAT single-dish beam profile. This beam model is applied consistently in both the TOD simulation and the construction of the linear operator that maps sky parameters (pixels) to the signal component in the data. If the beam model is accurate, the resulting sky map will be fully deconvolved. Conversely, if the beam model is inaccurate 7 7 7 In the extreme case of assuming an idealised pencil beam, no deconvolution is performed at all. – which, without loss of generality, can be understood as the sky field absorbing a multiplicative distortion in Fourier space – the recovered sky map will remain partially convolved. This can be abstractly expressed as: \tilde{B}(\ell)\tilde{T}(\ell)=\tilde{B}_{\rm est}(\ell)\,\tilde{E}(\ell)\,\tilde{T}(\ell)\,=\tilde{B}_{\rm est}(\ell)\,\tilde{T}_{\rm est}(\ell), (29) and the estimated sky T_{\rm est}(\hat{n})\equiv(T\ast E)(\hat{n}) (30) is effectively the true sky field convolved with a kernel E . For intensity mapping applications, we assume that the beam model is sufficiently accurate for the purpose of science extraction. The sky model consists of two components: (1) the diffuse emission is taken from the Global Sky Model ( de Oliveira-Costa et al. 2008 , GSM) full-sky map at 750\,\mathrm{MHz} ; (2) the point source component is constructed by extending the GLEAM catalog, originally covering the southern sky, to full-sky coverage via a simple mirroring approach, and then scale source fluxes to 750\,\mathrm{MHz} assuming a uniform spectral index of -2.3 . We represent the sky using the HEALPix pixelation scheme with \texttt{Nside}=64 , which is sufficient for validating the analysis workflow. Additionally, we apply a 3\sigma truncation threshold for the Gaussian beam profile to discard weakly weighted pixels. This scheme results in each beam pointing covering approximately eight sky pixels. This truncation, coupled with the beam’s rapid angular decay and the deliberately modest map resolution, ensures that the number of retained sky map parameters remains significantly smaller than the number of data points. The result is an overdetermined system ( N_{\mathrm{data}}\gg N_{\mathrm{pixels}} ), which is favorable for numerical stability and tractability. Figures 3 and 4 show the sky coverage and integrated beam intensity for the 1\times TOD and 2\times TOD configurations, respectively. In practical applications, higher resolutions or lower truncation thresholds may be used when more independent measurements are available – for instance, more overlapping TODs or data from multiple telescopes. 4.1.3 Gain, noise diode and receiver temperature For some observations in the MeerKLASS survey, MeerKAT periodically fires noise diodes for 1.8 seconds every 20 seconds to provide a relative calibration reference ( Wang et al. 2021 ) . Although our workflow does not rely on this feature, we incorporate the noise diode signal in the simulation to better reflect realistic observing conditions. For simplicity, we inject a 15 K noise diode signal every ten data points, corresponding to a 20 -second cycle. In the analysis, we assume that the timing of the noise diode injections is known and that the diode’s temperature remains stable over time. However, the exact amplitude of the noise diode signal is treated as an unknown and is included as a free parameter to be fitted. All residual contributions to the system temperature – such as receiver noise, ground pickup, and atmospheric contamination – are collectively referred to as the residual temperature (denoted by T_{\rm res} ) and are modelled using four Legendre polynomial modes: \displaystyle T_{\rm res} \displaystyle=\sum_{n=0}^{3}c_{n}\,P_{n}(x), \displaystyle x \displaystyle=\frac{2(t_{a}-t_{\rm min})}{t_{\rm max}-t_{\rm min}}-1, (31) with the coefficient values c_{n} used in the simulation listed in Table 1 . Similarly, for the smooth temporal gain variations, we do not impose a specific functional form beyond the assumption of temporal smoothness. These gain fluctuations are also modelled using Legendre polynomials [see Eq. ( 5 )], with randomly assigned coefficients for simulation. The flicker noise component is modelled in accordance with the Case 2 prescription shown in Figure 1 , with \alpha=2 and \log_{10}f_{0}\simeq-4.8746 , corresponding to a knee frequency of approximately 0.001 cycles per second. This is comparable to the 1/f noise parameters measured in Li et al. 2021 and Irfan et al. 2024 . Figure 5 : Estimated, residual, uncertainty and Z-score maps in different experimental and prior setups. We compare results obtained using a single TOD set (“ 1\times TOD”) versus jointly analyzing two TOD sets (“ 2\times TOD”). We compare three different priors for each scenario: (1) 1 CalSrc, (2) 5 CalSrc, and (3) 5 CalSrc + 1/f prior (see Section 4.2 ). The different rows correspond to different setups. Posterior mean map (left column): Posterior mean of sky parameters marginalized over other parameters, calculated as the sample average. Residual map (middle-left column): Map showing the residual difference between the estimated sky signal and the true sky input used in simulations. Uncertainty map (middle-right column): Posterior standard deviation of sky parameters marginalized over other parameters, calculated as the sample standard deviation of the draws. Z-score map (right column): defined as the residual map divided by the posterior standard deviation. Figure 6 : Map reconstructed using the high-pass + Wiener filter method. This method shows larger residuals (in the interior of the survey area) and higher uncertainty compared to the Bayesian approach. Figure 7 : Distribution of residuals in the sky map estimate, defined as the difference between the posterior mean (the mean of the sampled sky pixels) and the true sky map. The gray histogram (background) shows the residual distribution across all pixels in the experimental setup, while the red histogram highlights the distribution over pixels common to both the 1\times\text{TOD} and 2\times\text{TOD} cases. Both histograms are overlaid with kernel density estimates (KDEs) for visual clarity. The vertical dotted lines mark the 16 th and 84 th percentiles, capturing the central 68 % interval of the distribution. Figure 8 : Reconstruction of the noise-free time-ordered data ( \mu=gT_{\rm sys} , i.e., the smooth TOD as the smooth gain multiplied by the system temperature) using posterior samples. The top panel shows the mean reconstructed model ( \mu_{\rm est}\equiv\langle\mu_{\rm samples}\rangle ; black solid), and shaded regions indicating the 68% and 95% credible intervals. The bottom panel shows the mean residual TOD (orange solid), given by \langle\Delta\mu_{\rm samples}\rangle\equiv\mu_{\rm est}-\mu_{\rm true} . The shaded regions indicate the 68% and 95% credible intervals of the residuals. The true TOD is taken from the “setting” mode simulation, with both noise and noise diode injection removed. The reconstructed TOD is generated using posterior samples from the “ 2\times TOD; 1 CalSrc” analysis. The inset window provides a zoomed-in view of a small segment, highlighting subtle variations in the reconstructed signal and uncertainties. This figure demonstrates the advantage of the Bayesian workflow, where ensemble sampling enables the construction of credible intervals for any observable. Figure 9 : PSD of the reconstructed noise-free time-ordered data. The top panel shows the mean PSD of the fractional TOD residuals (red), i.e., \langle\text{PSD}(\Delta\mu_{\rm samples}/\mu_{\rm true})\rangle . The same panel also shows the PSD of the true noise [grey; as defined in Eq. ( 13 )] used in the simulation. We show in the bottom panel the PSD of the linear response of T_{\rm sys} with respect to the sky pixels, with each curve representing the PSD of the T_{\rm sys} contribution of a single sky pixel. As seen in the plot, the model suppresses structures above 0.03 Hz, which is consistent with the “de-noising” observed in the middle bottom panel. The ripples in the same plot are also explained. 4.2 Prior setup Having specified the data model, statistical framework, and observational configurations, we now introduce our assumptions about the measurement system necessary to complete the Bayesian analysis of the datasets. We begin by outlining the fiducial prior setup, which serves as the foundation for all subsequent comparisons. Additional prior configurations are introduced as variations on this baseline to explore their impact on inference performance. Given the structure of our modelling approach, certain priors are necessary for breaking parameter degeneracies, while others are intentionally avoided to maintain model generality. A key consideration is the degeneracy between the smooth gain fluctuations and the 1/f noise component, as the 1/f model can in principle absorb large-scale temporal structures. To break this degeneracy, we introduce minimal prior information guided by practical considerations. In the fiducial scenario, we assume approximate prior knowledge of the smooth component of the gain, motivated by the fact that gain amplitudes can often be constrained using noise diode signals or external calibration procedures. Specifically, we impose a Gaussian prior with a standard deviation of 10\,\% on the gain coefficients. The prior standard deviation is thresholded at 0.1 for coefficients that are smaller than 1 . The same prior scheme is applied to the local system temperature parameters. For the sky parameters, we assume rough prior knowledge of the sky signal, assigning each pixel a Gaussian prior with a standard deviation equal to 20 % of its sky temperature (see Wilensky et al. 2025 for a discussion of model errors in popular sky models that could be greater than 20 % however). Building upon the fiducial scenario, we consider the following three enhanced prior setups: • 1 CalSrc: The fiducial setup plus a strong prior on the temperature of a single pixel, used to establish the absolute flux scale. • 5 CalSrc: The fiducial setup plus strong priors on five widely separated pixels, providing more temporal functional information for the sky component. • 5 CalSrc + 1/f Prior: The above configuration further augmented with a strong prior on the power-law index of the 1/f noise component. A strong prior on a single pixel is equivalent to selecting a bright point source as a flux scale calibrator while also assuming an accurate beam model. Each of these prior setups is evaluated under both the 1\times TOD and 2\times TOD observational configurations. The resulting analyses and comparative performance assessments are presented in Section 4.3 . 4.3 Results In this section, we present the map results of joint Bayesian analyses for six toy model scenarios, defined by two experimental configurations and three prior setups. Each scenario is labeled using a two-part notation – for example, “(1×TOD; 1 CalSrc)” – where the first part denotes the experimental configuration (using a single TOD set), and the second indicates the prior setup (one calibration source prior). Each experimental scenario is analysed using 2,000 iterations of the Gibbs sampler. Each iteration takes approximately 12 seconds on a Mac with an M3 Ultra chip. Full details of the numerical setup are given in Appendix E . Our analysis focuses on two key aspects. First, we examine the impact of different experimental setups on map-making performance, specifically comparing the use of a single TOD set versus two overlapping TOD sets. Second, we investigate how varying prior assumptions influence the outcome of the Bayesian inference. Figure 10 : Correlation matrices of sampled parameters for different experimental setups. Each matrix is organised such that the origin is at the top-left corner, and the parameters are concatenated in the following order: celestial sky map pixels ( p_{\mathrm{cel}} ), gain coefficients ( p_{g} ), local T_{\rm sys} parameters ( p_{\mathrm{loc}} ), and 1/f noise parameters. A dotted line separates the sky parameters from the instrumental and noise parameters, partitioning each matrix into four blocks. The top-left block shows the sky–sky correlations, the bottom-right block shows correlations between the instrumental and noise components, and the off-diagonal rectangular blocks show the cross-correlations between the sky and instrumental parameters. Figure 11 : Cross-correlation coefficients between sky parameters and other model parameters across different analysis configurations. Each panel shows the correlation structure between sky parameters (vertical axis; each row is for a single pixel) and instrumental/noise parameters (horizontal axis), with white vertical lines delineating parameter groups: gain parameters ( p_{g} ), localization parameters ( p_{\rm loc} ), and noise parameters ( \log_{10}f_{0} , \alpha ). The six panels compare single vs. double TOD analysis with varying numbers of calibration sources and prior constraints. Figures 5 show, for each scenario, the estimated sky map (computed as the sample average, representing the posterior mean of the sky parameters marginalised over all other parameters), the residual map (defined as the difference between the estimated and true sky maps), and the uncertainty map (given by the sample variance). We further examine the histograms of the residual maps in Figure 7 , as they reveal the bias levels in the sky map estimates. 8 8 8 In this paper, we present only the plots related to the reconstructed maps. Histogram plots of all nuisance parameters, along with the full posterior samples for all parameters across the six analyses, are available at: https://github.com/zzhang0123/hydra-tod One of the key advantages of the Bayesian workflow is that ensemble sampling allows us to construct credible intervals for any observable. To illustrate this, we reconstruct the noise-free TOD, defined as the product of the smoothed gain and system temperature, and compare it with the true noise-free TOD. Figure 8 presents this comparison. For clarity, we have removed the contribution from the noise diode 9 9 9 Note that the noise diode injection does not play any special role in the sampling mechanism itself, although in practice it may serve as a primary source of prior information about the gain. , as its frequent injection every 20 seconds introduces strong striping that obscures the visual structure in the plots. In this figure, the residual panel shows the difference between the true TOD and the reconstructed TOD. For the corresponding sky residuals at this level of TOD residuals, see row 4 (2×TOD; 1 CalSrc) in Figure 5 . The same figure also shows the mean power spectral density (PSD) of the fractional residuals, 10 10 10 Fractional residuals are defined as the difference between the reconstruction and the truth, divided by the truth. computed from the reconstructed smooth TOD—that is, the product of the smooth gain and the system temperature. At high frequencies, we observe a clear “denoising” effect: the residual PSD falls well below the noise level. This behaviour is expected, and arises from the structure of the TOD model itself. Parameters such as gain and receiver temperature are modeled to capture long-timescale variations, while the smallest time-scale structures are governed by the sky pixel contributions. The PSDs of each sky component in the system temperature (i.e. the linear response to each pixel in the map) demonstrate collective damping at high frequencies. This damping accounts for the suppression intrinsic to the model. Another advantage of the Bayesian approach is its ability to reveal parameter correlations. In Figure 10 , we present and compare the correlation matrices across different experimental configurations. Note that, because we are indexing sky pixels embedded in the HEALPix ring scheme, pixels close in latitude are separated by approximately the length of the involved longitudes at that latitude. Consequently, we observe periodic off-diagonal strips indicating strong correlation. For accurate map reconstruction, we focus particularly on the cross-correlations between sky parameters and all remaining (nuisance) parameters (See Figure 11 , which is a zoomed-in version of the off-diagonal blocks in Figure 10 ). Since the sky parameters are fundamentally independent of instrument or noise parameters, any observed correlations must arise from model degeneracies. We observe that by imposing informative priors and incorporating additional independent datasets, these degeneracies – and hence the undesired correlations – can be effectively mitigated. Below, we present a comparative analysis of the map-making performance across different scenarios. The corresponding posterior statistics for all other nuisance parameters – including the posterior means and 68% credible intervals – are provided in Appendix F . 4.3.1 “ 1\times\textrm{TOD} ” vs “ 2\times\textrm{TOD} ” A clear observation is that the 2\times TOD maps are significantly more accurate than those from the 1\times TOD analysis. Both the error (or residual) and uncertainty maps exhibit a strong anti-correlation with the integrated beam intensity. This is expected: a stronger beam response to a given sky pixel implies that more information is collected from that direction, resulting in reduced uncertainty. In both configurations, we observe that pixels near the edge of the covered sky patch consistently show higher uncertainty. This suggests that in practical scientific applications, it may be beneficial to exclude or down-weight these edge pixels from further analysis. Another notable point is the presence of large-scale structures in the error map of the 1\times TOD case (e.g., extended blue or red regions in the first three residual maps in Figure 5 ). These patterns indicate that the sky component in the TOD has inadvertently absorbed temporal functional behavior that does not belong to it – possibly due to gain variations or other components of the system temperature. The same conclusion can be drawn from a comparison of the two columns in Figure 11 that the correlation between sky pixels and nuisance parameters is reduced in the 2\times TOD analysis. This analysis also serves as a validation of our workflow’s capability to perform joint inference over multiple TOD sets. In the 2\times TOD case, the issue is mitigated, which we attribute to the fact that multiple TOD sets sharing common sky parameters are less prone to local parameter degeneracies and biases. 4.3.2 “1 CalSrc” vs “5 CalSrc” vs “5 CalSrc + 1/f prior” We compare three progressively stronger priors: “1 CalSrc”, “5 CalSrc”, and “5 CalSrc + 1/f prior”. The “1 CalSrc” case serves as the baseline, as at least one calibration source is always required to fix the flux scale of the map. The “5 CalSrc” scenario uses five spatially distributed calibration pixels. This setup is motivated by the idea that providing more large-scale information about the sky component in the TOD may help mitigate large-scale bias in the estimated map. The “5 CalSrc + 1/f prior” case further incorporates a strong prior on the power-law index of the 1/f noise PSD. This reflects a realistic situation in which some knowledge about the power-law behavior of the 1/f component is often available. Here, we aim to test whether such information can be effectively leveraged to reduce map bias. By comparing the residual maps in Figures 5 , we find that strengthening the priors does not lead to a significant improvement in the overall accuracy of the reconstructed sky map (also see different rows of Figure 7 ). However, Figure 11 shows that stronger priors do help reduce the correlation between sky pixels and nuisance parameters. That said, the impact of prior strengthening is notably weaker than the effect of simply incorporating an additional TOD dataset. 4.4 Conventional Map-Making with High-Pass and Wiener Filtering In this section, we present a simple, conventional map-making approach and compare its performance with our Bayesian method. Using the same simulated dataset, we adopt a “high-pass filter + Wiener filter” scheme with the following assumptions: 1. TOD is first calibrated using perfectly known DC gain mode. 2. A high-pass filter is applied to remove large-scale fluctuations in the TOD. The cutoff frequency is 0.001 Hz, which is the knee frequency of the flicker noise in the simulated data. Therefore, we can ignore any residual correlated noise. 3. The noise variance in the filtered data is estimated, and the sky map is reconstructed using a Wiener filter. 4. The same T_{\rm sys} priors are adopted for the Wiener filter, i.e., Gaussian priors with 10% uncertainty. The resulting map is shown in Figure 6 . Compared to the full Bayesian approach, this method exhibits larger residuals, particularly in the large-scale structures within the central survey region, as well as a noisier uncertainty map. Within the survey area, the Bayesian method uniformly shows low bias and reduced uncertainty. In summary, although the Wiener filter uses exact knowledge of the DC gain and knee frequency, our Bayesian mapping method still outperforms it when the prior system temperature is the same. A detailed comparison with this and other conventional map-making methods is beyond the scope of this work. This is an encouraging sign that our Bayesian approach is making good use of prior information and the model structure to enhance the recovery of the true temperature field from the same time-ordered data, however. 5 Conclusions and Discussions In this paper, we present a workflow for joint Bayesian gain calibration, 1/f noise characterisation, and mapmaking. The primary goal of this workflow is to disentangle instrumental gain and noise contributions from the raw time-ordered data, thereby enabling the construction of a reliable intensity map that can serve as the basis for subsequent scientific analysis. Designing a fully Bayesian workflow – from model formulation to numerical implementation – requires a series of principled decisions. To conclude, we highlight several such decisions and the rationale behind them. A natural question is: Why adopt a joint Bayesian approach in the first place? The motivation lies in the coupling nature of calibration and map-making. Treating these steps jointly allows us to propagate uncertainties coherently, account for degeneracies explicitly, and mitigate biases introduced by sequential processing (see Section 4.4 for a comparison with a traditional high-pass + Wiener filter approach). In particular, the Bayesian framework allows marginalisation over nuisance parameters (e.g., gain fluctuations), leading to more robust inferences about the sky signal, as well as detailed and explicit control over prior assumptions, such as the accuracy of point source calibration models, noise diode stability etc. The priors also provide a natural way of incorporating external datasets, such as reference sky models. One might also ask: Why use a highly degenerate model with multiple nuisance parameters? The model’s degeneracy actually reflects genuine ambiguities in our knowledge of the system (typically, the artificial separation of large scale gain variation and 1/f gain variation). We intentionally avoid “reducing this degeneracy for the sake of numerical performance”. Instead, we rely on experimental constraints – such as distinct temporal behaviors of different components – to naturally break degeneracies. When this is insufficient, we explore the use of informative priors through numerical tests. In the MeerKAT-type “rapid scan” example presented in this paper, we demonstrate that moderate prior knowledge of the gain and sky structure is sufficient to break key degeneracies and recover accurate sky maps. To make inference feasible in this high-dimensional setting, where there are 495 parameters in total in the 2\times TOD setup, we introduced an iterative Generalised Least Squares (GLS) sampler i.e., an iterative version of the Gaussian constrained realisations approach. In the Gibbs sampling steps for the system temperature parameters and the smooth gain parameters, the iterative GLS sampler estimates the noise covariance matrix as the best-fit noise model to the data, conditioned on the current values of all other parameters. This estimated noise covariance is then used to sample the linear parameters in the model. In essence, the method provides a Gaussian approximation to the conditional posterior distribution, where noise and signal parameters are otherwise tightly coupled. In addition to the Bayesian considerations discussed above, we briefly outline several potential extensions to this work and highlight some of the caveats. First, our current implementation focuses on a single-frequency workflow. It can be naturally extended to include multiple TOD chunks from multiple dishes at the same frequency. Such an approach would allow joint inference across dishes. The method could also be extended along the frequency axis without specifying the 1/f noise-noise covariance. For example, one could divide the full band into sub-bands, and assume that the 1/f noise parameters remain constant across those frequencies if the sub-bands are narrow enough. Two possible schemes arise in this context: (1) joint inference with shared 1/f noise parameters but otherwise independent parameter sets for each sub-band; or (2) one may perform averaging across frequency, thereby reducing the effective white noise level – though this does not suppress the 1/f component itself – before creating a map of the averaged sky. Another important consideration is polarisation leakage ( Cunnington et al. 2021 ; Nunhokee et al. 2017 , see e.g.) . While this work models only the total intensity sky, any practical intensity mapping experiment must contend with leakage from polarised sky signals. Accurately characterising the system temperature component from the full Stokes sky requires modelling the antenna E -field beam and synthesizing the polarised power beams onto the Stokes Q/U/V basis (or equivalently, E/B/V ) in the sky coordinate frame. Although circular polarisation V is often negligible, the leakage from Q/U can contaminate intensity measurements if unaccounted for. A full-Stokes formalism is therefore essential for precision intensity mapping. The inference framework developed in this work is fully compatible with full-Stokes map-making. Radio frequency interference (RFI) presents another caveat. We do not explicitly model RFI in this work. Unless RFI manifests in a form that can be absorbed into the smooth temporal basis used for T_{\rm sys} , additional modelling would be necessary, or alternatively, the contaminated TOD segments can be flagged. Flagging can be efficiently implemented via a diagonal selection matrix without increasing the computational cost of the quadratic term in the log-likelihood, meaning that the Gibbs steps for gain and T_{\rm sys} remain unaffected. However, the modified noise covariance introduced by flagging can affect the computation of the log-determinant. For contiguous or near-contiguous flagged segments, Levinson–Durbin algorithms remain applicable. In more irregular or extensive flagging cases, one may resort to perturbative methods or brute-force matrix inversion. If the effective dimensionality of the TOD is significantly reduced post-flagging, direct inversion may still be computationally tractable. A further conceptual dependency of our method lies in the scanning strategy. The MeerKAT scanning strategy used in our tests induces a linear discrimination between TOD response to different parameters, for example, sky pixels versus elevation-dependent terms, allowing effective separation using simple linear bases. This structural property may not generalise to arbitrary scanning strategies. In more complex cases, where linear decompositions fail, we may need to adopt explicit, nonlinear models for the receiver temperature, ground spillover, etc. Finally, we note that our gain model assumes linearity, whereas significant non-linearities in the gain are known to occur for MeerKAT. One potential extension would be to include a simple nonlinear correction term in the gain model. While this could preserve the sampling strategy for noise and linear gain parameters in principle, it would break the Gaussian structure required by the iterative GLS step used for system temperature sampling. In such cases, alternative high-dimensional samplers, such as Hamiltonian Monte Carlo, may be required. Looking ahead, this approach holds promise for a wide range of applications. It may be particularly valuable for experiments such as C-BASS ( Jones et al. 2018 ) , L-BASS ( Zerafa et al. 2025 ) , COMAP ( Cleary et al. 2022 ) , and other single-dish intensity mapping or global 21cm surveys, where high-fidelity map-making and robust noise modelling are crucial. This is especially true in regimes dominated by temporally correlated systematics, or where explicit models for the systematics (like ground spillover) are unavailable or incomplete. Data Availability All code, data, and Jupyter notebooks necessary to reproduce the results presented in this paper are available in the associated GitHub repository: https://github.com/zzhang0123/hydra-tod . Appendix A Normalised Power Spectral Density The total energy of a discrete-time signal x[n] with sampling frequency f_{s} is given by: E=\sum_{n=1}^{N}|x[n]|^{2}\Delta t (32) where N is the total number of data points, and we have included \Delta t\equiv 1/f_{s} to match the units of energy, that is, power \times time. Parseval’s theorem states that the total energy in the time domain equals the total energy in the frequency domain. For the Discrete Fourier Transform (DFT) of x[n] , denoted by \tilde{x}[k] , we have E=\left(\frac{1}{N}\sum_{k=1}^{N}|\tilde{x}[k]|^{2}\right)\Delta t\equiv\sum_{k=1}^{N}P[k], (33) where we have defined the power of the k th DFT frequency bin P[k]\equiv\frac{\Delta t}{N}|\tilde{x}[k]|^{2}. (34) Then the power spectral density (PSD), defined as the power per unit frequency, is given by P(f_{k})\equiv\frac{P[k]}{\Delta f}=\frac{\Delta t}{N\Delta f}|\tilde{x}[k]|^{2}=\frac{|\tilde{x}[k]|^{2}}{f_{s}^{2}}, (35) where f_{s}=1/\Delta t is the sampling frequency and \Delta f=f_{s}/N is the DFT frequency resolution. Here we reiterate that, for dimensional consistency, we refer to the mean squared DFT coefficient as the bin power, while the quantity defined over the continuum is referred to as the power spectral density. White noise Given a sequence of white noise x[n]\sim\mathcal{N}(0,\sigma^{2})\;\Rightarrow\;\tilde{x}[k]\sim\mathcal{N}\left(0,\frac{N}{2}\sigma^{2}\right)+i\mathcal{N}\left(0,\frac{N}{2}\sigma^{2}\right), (36) the expectation value of the bin power is \left\langle{P^{\rm(wn)}[k]}\right\rangle=\sigma^{2}\Delta t. (37) Consequently, the mean PSD of white noise is \left\langle{P^{\rm(wn)}(f_{k})}\right\rangle=N\sigma^{2}(\Delta t)^{2}. (38) Conventional flicker noise PSD model In the conventional DFT-diagonal 1/f noise model, assuming that the flicker noise has the same power density as the white noise at the knee frequency f_{\rm knee} , the power of the k -th DFT frequency bin of the flicker noise is given by \left\langle{P^{(1/f)}[k]}\right\rangle=\sigma^{2}\Delta t\left(\frac{f_{\rm knee}}{f_{k}}\right)^{\alpha}, (39) and the mean PSD of the flicker noise is \left\langle{P^{(1/f)}(f_{k})}\right\rangle=N\sigma^{2}(\Delta t)^{2}\left(\frac{f_{\rm knee}}{f_{k}}\right)^{\alpha}. (40) Appendix B An example full gain model In this work, we use Eqs. ( 5 - 9 ) as the full gain variation model. Although this approach of a smooth g(t_{a}) plus a perfect 1/f -type \hat{\epsilon} inherently involves some degree of modelling uncertainty, we expect that it does not preclude meaningful scientific interpretation. This is because radio experiments are typically designed to ensure that \hat{\epsilon} remains sufficiently small, so these fluctuations do not significantly impact the main experimental objectives over relevant timescales. For example, the MeerKAT scanning strategy is designed to cover the relevant angular scales within the stability time scale of the instrument when the gains are approximately constant. Even if the empirical model does not perfectly capture the gain variations, its ability to approximate the primary structure of the gain provides valuable utility in data calibration and analysis. There are of course other models (and they might be even better); see Appendix B.1 for another possible full gain model. These discussions show that the (smooth) gain and 1/f noise are ad-hoc definitions depending on specific data model and full-gain model. Consequently, they are also implicit assumptions for likelihood analysis. Note that if the stochastic gain fluctuation is an important systematic for scientific extraction, one might want to test different full gain models and perform model selection with Bayesian evidence. B.1 An example of deviating power-law gain variation In this Appendix, we give an example where the 1/f model (with a single power law) may not be accurate for the full temporal frequency domain. We consider a gain system of three-stage amplifiers, each given as a classical 1/f model: \displaystyle G_{1} \displaystyle=\bar{G}_{1}(1+\hat{\epsilon}_{1}) (41a) \displaystyle G_{2} \displaystyle=\bar{G}_{2}(1+\hat{\epsilon}_{2}) (41b) \displaystyle G_{3} \displaystyle=\bar{G}_{3}(1+\hat{\epsilon}_{3}) (41c) where \bar{G}_{i} are constants and \hat{\epsilon}_{i} are perfect, independent zero-mean 1/f noise. \bar{G}_{i} thus also denote the mean gains. The overall gain, to the first order of \hat{\epsilon}_{i} , is then given by G=G_{1}G_{2}G_{3}\approx\bar{G}_{1}\bar{G}_{2}\bar{G}_{3}\left(1+\hat{\epsilon}_{1}+\hat{\epsilon}_{2}+\hat{\epsilon}_{3}\right). (42) The overall stochastic gain fluctuation is given as the sum of three independent 1/f noise. The PSD of the total gain variation, as the sum of three different power laws, is not a perfect power law in the full temporal frequency domain. B.2 Gain models linearly distinguishing scales In the above case, a single power law is not sufficient to characterise the PSD behaviour. However, according to the “selection rule”, steeper (negative) power laws dominate at lower frequencies, while flatter power laws dominate at higher frequencies. Therefore, it would be possible to assume a threshold frequency f_{n} beyond which the PSD is still well characterised by a single power law. The scale distinction can be directly realized by linear separation of the Fourier modes of the gain variation according to the threshold frequency. Then the large scale modes are resolved while the small scale modes are fitted to a power law statistical model. Less abstractly, we rewrite the gain variation as \displaystyle\hat{\epsilon}^{\prime} \displaystyle\equiv\hat{\epsilon}_{1}+\hat{\epsilon}_{2}+\hat{\epsilon}_{3}=\epsilon_{L}+\hat{\epsilon} (43) where \tilde{\epsilon} is the large-scale component composed of discrete Fourier modes with the lowest n Fourier frequencies \epsilon_{L}(t_{a})=\frac{1}{N}\sum_{k=0}^{n-1}g_{k}\,e^{i2\pi\frac{k}{N}a}. (44) On the other hand, \hat{\epsilon} takes into account the residual gain variation, understood as the contribution of all the remaining Fourier modes, which is stochastic and characterised by the flicker noise with the PSD P_{\hat{\epsilon}}(f)=\begin{cases}0,&|f|