Simulating instrumental systematics of Cosmic Microwave Background experiments with s4cmb

The observation of cosmic microwave background (CMB) anisotropies is one of the key probes of physical cosmology. The weak nature of this signal has driven the construction of increasingly complex and sensitive experiments observing the sky at multiple frequencies with thousands of polarization sensitive detectors. Given the high sensitivity of such experiments, instrumental systematic effects can become the limiting factor towards the full scientific exploitation of their data. In this paper we present s4cmb (Systematics for CMB), a Python package designed to simulate raw data streams in time domain of modern CMB experiments based on bolometric technology, and to inject in these realistic instrumental systematics effects. The aim of the package is to help assessing the contamination due to instrumental systematic effects on real data, to guide the design of future instruments, as well as to increase the realism of simulated data sets required in the development of accurate data analysis methods.


Summary
The observation of cosmic microwave background (CMB) anisotropies is one of the key probes of the standard cosmological model (Hu and Dodelson 2002). The weak CMB polarization signal in particular can provide a new window to study the process of the growth of structures in the universe (galaxies, galaxy clusters, etc.) through weak gravitational lensing as well as on the physics of the inflationary epoch in the primordial universe. The low amplitude of CMB polarization has pushed CMB science toward the construction of increasingly sensitive experiments observing in multiple frequencies and employing telescopes with complex optical designs and focal planes with thousands of bolometric detectors operating in cryogenic environments (Staggs, Dunkley, and Page 2018). To fully utilize the sensitivity of these instruments for cosmology, the instrumental systematic effects must be well-characterized, understood, and mitigated in the instrument design and through the analysis of the acquired data.

Statement of need
The s4cmb (systematics for CMB) package is a Python package developed to study the impact of instrumental systematic effects on measurements of CMB experiments based on bolometric detector technology. s4cmb provides a unified framework to simulate raw data streams in the time domain (TODs) acquired by CMB experiments scanning the sky, and to inject in these realistic instrumental systematics effect. The development of s4cmb is built on experience and needs of the analysis of data of the Polarbear ground-based experiment (Polarbear Collaboration et al. 2014, 2017. It is designed to analyze real data, to guide the design of future instruments that require the estimation of specific systematic effects, as well as to increase the realism of simulated data sets required in the development of data analysis methods. The package has already been used in a number of scientific (Puglisi et al. 2018;Mirmelstein et al. 2020) and technical publications (Salatino et al. 2018;Crowley et al. 2018;Gallardo et al. 2018;Bryan et al. 2018). It adopts several commonly used libraries in astronomy (astropy (Astropy Collaboration 2013), healpy (Zonca et al. 2019), ephem (Rhodes, n.d.), pyslalib (Ransom 2010)) and uses functions based on low-level languages wrapped in Python (e.g., Fortran with f2py) for speeding up the most critical part of the code without losing the flexibility provided by a simple Python user-friendly interface. s4cmb is designed to be employed on systems of varying scale, from laptops to parallel supercomputing platforms, thanks to its internal Message Passing Interface (MPI) support (The MPI Forum 1993). We also support packaging the entire application into a Docker container for portability. The simplicity of the s4cmb framework allows a user to easily add new instrumental systematics to be simulated according to the user's needs. As far as we know, s4cmb is the only dedicated package that enables the study of a wide range of instrumental simulations, from the instrument to the sky map, while being publicly available. For more general purposes, including some instrumental systematic effect simulations, users might also consider the use of TOAST (Kisner et al. 2020), a software framework to simulate and process timestream data collected by telescopes focusing on efficient TOD manipulation on massively parallel architectures.

Package structure and functionalities
One of the key feature of s4cmb is to be able to make robust simulations while being fast to run and easy to use. Simulations using O(10 3 ) detectors observing the sky for 5 hours with a data sampling rate of 100Hz and reconstructing a sky map can be run on a single core in less than 10 minutes on a laptop. The modules implementing the major functional blocks of the library are (see Figure 1): Figure 1: Schematic structure of s4cmb. Objects defined by the user are marked in red. From these, TODs are generated for the duration of each observation described by the scanning strategy. These can then be modified by introducing instrumental effects. The output of the code (blue) are the perturbed TODs or sky maps reconstructed from TODs to be employed in subsequent analysis steps (e.g., the computation of their angular power spectrum).
• instrument.py contains the class describing the CMB instrument in terms of position of its detectors in the focal plane, their optical beam shape, and wiring in the readout electronics. It supports the most common focal plane designs employing multifrequency detectors and polarization modulation hardware such as stepped or continuously rotating half-wave plates (HWPs). • scanning_strategy.py describes the schedule of the instrument observations and the motion of the instrument in terms of azimuth and elevation position at the telescope location on Earth as a function of time. The schedule is divided in minimal units (scans) during which a telescope motion is repeated for its given duration (e.g., a back and forth motion for a fixed distance in azimuth at a constant elevation.) The code parallelisation is done over scans, so that proportionally increasing the number of scans and the number of MPI workers keeps the runtime constant. • input_sky.py contains the class describing the input sky signal model in HEALPix pixelization (Górski et al. 2005). This can include multiple components (CMB, Galactic emissions, etc.) and can be read from an external file or be synthesized on the fly from its harmonic coefficients. The input sky needs be convolved with the main optical beam of the instrument B so that the observed sky Stokes parameters X obs ∈ {I, Q, U } are related to their true value on sky a X obs ≡ B X. • tod.py includes the class to generate and handle TODs from an input sky signal map, an instrument design, and a scanning strategy, together with basic tools to reconstruct a sky map from TODs in order to self consistently mimic the basic data analysis pipeline of CMB experiments. In the absence of instrumental systematic effects, the TOD of a single detector d is modeled as: d t = g t [I obs (n t ) + cos 2ψ t Q obs (n t ) + sin 2ψ t U obs (n t )] + n t , where a t subscript denotes a time-dependent quantity. n is the vector describing the detector pointing and ψ is the polarization angle that describes the effective orientation of a polarization sensitive detector with respect to the input sky coordinate system. This depends on the orientation of the detector itself but also on the orientation of optical elements that modulate the incoming polarized signal (e.g., HWPs). In absence of systematics, the calibration factor (gain) is g t = 1 to preserve the calibration of the input signal. The exact value of the pixelized input Stokes parameters at n t is determined through nearest grid point interpolation. White or correlated noise n t can be added to TOD according to the instrument specifications.

Instrumental systematic effects
The instrumental systematic effects implemented in s4cmb are available in the systema tics.py module. This includes electrical crosstalk in the detectors' readout electronics, gain misestimation or drifting of their values in time, pointing errors, distortions of the beam shape compared to the shape of the expected beam B used to convolve the input sky and misestimation of their position in the focal plane, errors in the polarization angle estimation. These effectively modify on the fly the ψ t , n t , g t in Equation 1 compared to their expected value determined by the instrument design and scanning strategy when creating the TODs. Effects of beam distortions are conversely modeled through a Taylor expansion of B. Further details of the mathematical modeling of systematics are given in Mirmelstein et al. (2020) andBicep2 Collaboration et al. (2015). We encourage users to add more effects and integrate their work in the package through pull requests on GitHub.

Bootcamp
We release a bootcamp dedicated to the package in two parts (beginners and advanced users) that include notebooks describing the basic parts of the API, and providing readyto-use examples for the major code functionalities. A notebook to create Figure 2 can be found here.