---
title: 'class_sz: SZ Detection & Computational Framework'
url: https://www.emergentmind.com/topics/class_sz
type: topic
---

# class_sz: SZ Detection & Computational Framework

In current arXiv usage, **class_sz** designates two distinct SZ-centered constructs. In one usage, it is a reliability-classification scheme for Sunyaev–Zeldovich detections in survey catalogues, especially the three-way separation of Planck candidates into **Good**, **Bad**, and **Ugly** populations by means of SED-based statistical classification [1409.6543]. In the other, it is a public computational framework—also written as **CLASS_SZ**—that extends the Boltzmann code CLASS with halo-model and linear-bias calculations for SZ, CMB, large-scale-structure, cluster-count, and higher-order observables relevant to Stage IV cross-survey science [2310.18482].

## 1. Nomenclature and scope

The two usages share an SZ focus but operate at different levels of the research stack: one is a **catalogue-quality assessment scheme**, the other a **theory-and-inference software platform**.

| Usage of class_sz | Domain | Principal source |
|---|---|---|
| Good/Bad/Ugly reliability classes for SZ detections | Planck and survey catalogue assessment | [1409.6543] |
| C/Python/JAX code extending CLASS for SZ/CMB/LSS observables | Halo model, cross-survey theory, inference | [2310.18482] |

The reliability-classification usage arose in the context of source classification in catalogues from X-rays (MCXC), optical (SDSS), and millimetric Planck Sunyaev–Zeldovich data, with the goal of determining the confidence with which catalogue elements can be distinguished in populations on the basis of their spectral energy distribution [1409.6543]. The software usage emerged later as a modular extension of CLASS intended to compute theoretical predictions for observables relevant to the Stage IV era, including tSZ, kSZ, galaxy clustering, lensing, CIB, bispectra, and cluster counts [2310.18482].

A separate notation, \(\mathscr{SZ}_\alpha\), appears in Banach-space theory for operator-ideal classes indexed by the Szlenk index; this is a distinct mathematical usage of “SZ” rather than an SZ-cosmology meaning [1003.5710].

## 2. Reliability classification for SZ detections

In the catalogue-classification setting, class_sz is built from a low-dimensional projection of multi-frequency photometry onto an astrophysical basis. For each candidate SZ source, the Planck fluxes \(F_\nu\) at \(\nu=\{70,100,143,217,353,545,857\}\,\mathrm{GHz}\) are measured by aperture photometry using a \(10'\) radius aperture and a background in a \(20\text{--}50'\) annulus. These seven band-flux measurements are then projected onto a five-component basis through the linear model [1409.6543]
$$
F_\nu = A_{\rm SZ}F_{\rm SZ}(\nu)+A_{\rm CMB}F_{\rm CMB}(\nu)+A_{\rm IR}F_{\rm IR}(\nu)+A_{\rm RAD}F_{\rm RAD}(\nu)+A_{\rm CO}F_{\rm CO}(\nu)+N(\nu).
$$

The components are physically specified. \(F_{\rm SZ}(\nu)\) is the non-relativistic tSZ spectrum; \(F_{\rm CMB}(\nu)\) is the derivative of a \(2.725\,\mathrm{K}\) blackbody; \(F_{\rm IR}(\nu)\propto \nu^{\beta_d}B_\nu(T_d)\) is a modified black body with \(T_d=17\,\mathrm{K}\) and \(\beta_d=1.6\), capturing dust, CIB, and IR-point-source contamination; \(F_{\rm RAD}(\nu)\propto \nu^{-0.7}\) is a radio power-law template; and \(F_{\rm CO}(\nu)\) is a CO rotational-line template at \(100/217/353\,\mathrm{GHz}\) [1409.6543]. In matrix form, the fitted amplitudes are
$$
\vec{A}\equiv[A_{\rm SZ},A_{\rm CMB},A_{\rm IR},A_{\rm RAD},A_{\rm CO}]^T=(F^TC_N^{-1}F)^{-1}F^TC_N^{-1}F_\nu,
$$
with \(F\) the \(7\times5\) mixing matrix and \(C_N\) the instrumental-noise covariance. These five amplitudes form the feature vector used by all classifiers.

Three classification strategies are then applied. The first is a likelihood analysis described as halfway between supervised and unsupervised methods. The second is an unsupervised clustering technique, implemented with \(k\)-means. The third is a supervised classifier based on Artificial Neural Networks. The three methods were reported to be in very good agreement with each other, while the supervised neural-network-based classification showed better performances and allowed the best separation into populations of reliable and unreliable sources in catalogues [1409.6543].

The final reliability assessment is explicitly three-fold. The **Good** class corresponds to high-reliability SZ candidates; the **Bad** class to spurious candidates; and the **Ugly** class to noise-dominated or low-S/N objects. In practice, the authors found that the supervised ANN yields the cleanest separation: the Good class has an ensemble-averaged SED consistent with pure tSZ, the Bad class shows strong IR + CO contamination, and the Ugly class sits at low S/N and is noise-dominated [1409.6543].

## 3. Statistical formulations and decision boundaries

The likelihood-based classifier is built from the four non-SZ amplitudes. Its per-source contamination likelihood is
$$
Q_L \equiv p_{\rm CMB}(A_{\rm CMB})\cdot p_{\rm IR}(A_{\rm IR})\cdot p_{\rm RAD}(A_{\rm RAD})\cdot p_{\rm CO}(A_{\rm CO}),
$$
where the empirical PDFs are estimated from 2000 random sky positions. In the reported formulation, \(p_{\rm CMB}\), \(p_{\rm RAD}\), and \(p_{\rm CO}\) are fit as Gaussians,
$$
G(x;m,\sigma)=\frac{1}{\sqrt{2\pi}\sigma}\exp\!\left[-\frac{(x-m)^2}{2\sigma^2}\right],
$$
while \(p_{\rm IR}\) is fit as a Cauchy/Lorentzian,
$$
C(x;m,\gamma)=\frac{1/\pi\gamma}{1+((x-m)/\gamma)^2}.
$$
The explicit recommended decision boundaries are \(Q_L \ge 1.5\times 10^{-8}\) for **Good** and \(Q_L \le 1.5\times 10^{-8}\) for **Bad** candidates, with intermediate objects mapping into the residual class structure [1409.6543].

The unsupervised classifier defines a four-dimensional contamination space using \(\{A_{\rm CMB},A_{\rm IR},A_{\rm RAD},A_{\rm CO}\}\), each normalized by its \(\sigma\) from sky-randoms, and measures the distance from zero contamination as
$$
d_{\rm cont}=\sqrt{(A_{\rm CMB}/\sigma_{\rm CMB})^2+(A_{\rm IR}/\sigma_{\rm IR})^2+(A_{\rm RAD}/\sigma_{\rm RAD})^2+(A_{\rm CO}/\sigma_{\rm CO})^2 }.
$$
A Euclidean \(k\)-means procedure with \(n=3\) clusters then maps the smallest-\(d_{\rm cont}\) cluster onto Good, the intermediate cluster onto Ugly, and the largest-\(d_{\rm cont}\) cluster onto Bad [1409.6543].

The ANN classifier uses a three-layer architecture with an input layer of 5 nodes \([A_{\rm SZ},A_{\rm CMB},A_{\rm IR},A_{\rm RAD},A_{\rm CO}]\), a hidden layer of 10 sigmoid neurons, and an output layer of 3 sigmoid neurons \([Q_{\rm good},Q_{\rm bad},Q_{\rm ugly}]\). The activation function is
$$
g(x)=\frac{1}{1+e^{-x}},
$$
and the input amplitudes are standardized by their sky-random \(\sigma\) values. The training sets are equal-sized subsets consisting of 861 confirmed Planck-SZ clusters (PSZ1) for Good, 300 spurious sources—100 each from radio-\(30\,\mathrm{GHz}\), IR-\(353\,\mathrm{GHz}\), and Planck cold-Galactic-cores—for Bad, and 2000 random sky positions for Ugly. Training minimizes
$$
E=\frac12\sum_{c\in\{\mathrm{good,bad,ugly}\}}(Q_{c,\mathrm{true}}-Q_{c,\mathrm{pred}})^2
$$
by standard back-propagation and gradient descent with learning rate \(\alpha\sim0.1\), momentum \(\mu\sim0.9\), and early stopping when the checking-set error reaches minimum. The outputs \(Q_c\in(0,1)\) sum to \(\lesssim1\) and are interpreted as class-membership confidence scores [1409.6543].

The reported comparative metrics place the ANN clearly ahead of the other two methods. A cut \(Q_{\rm good}>0.6\), equivalently \(1-Q_{\rm bad}>0.4\), retains \(\gtrsim98\%\) of confirmed clusters while rejecting \(\gtrsim95\%\) of spurious sources, corresponding to completeness \(\approx98\%\) and purity \(\approx90\%\). The reported ROC/AUC values are \(\simeq0.99\) for the ANN, \(\simeq0.8\) for \(k\)-means, and \(\simeq0.65\text{--}0.7\) for the likelihood method [1409.6543]. The method was applied to SZ sources detected by the Planck satellite and led to a classification agreeing with the reliability assessment published in the Planck SZ catalogue; it was also presented as easily applicable to future large surveys such as SRG/eROSITA and Euclid [1409.6543].

## 4. CLASS_SZ as a computational framework

In the later software literature, class_sz is a versatile and robust code in C and Python that extends CLASS with a halo-model/LSS toolkit optimized for cross-survey science [2310.18482]. The scientific motivation is the Stage IV regime of CMB and LSS surveys, driven by experiments such as ACT, SPT, the Simons Observatory, and CMB-S4, where high-resolution, low-noise maps enable precision measurements of secondary CMB anisotropies at arcminute scales. The tSZ effect probes inverse-Compton scattering by hot electrons in the intracluster medium, while the kSZ effect traces Doppler shifts from scattering off moving electrons in large-scale structure. Cross-correlating SZ maps with external tracers such as galaxy catalogs, CMB lensing, and the cosmic infrared background supports tomography of the ICM/CGM, tests of astrophysical models, and cosmological constraints, including work related to the \(S_8\) tension [2310.18482].

The architecture is modular. The overview paper identifies three new C modules—`class_sz.c`, `class_sz_tools.c`, and `class_sz_clustercounts.c`—plus Python bindings. The core module handles 1D and 2D integrals over mass and redshift, power spectra, bispectra, halo mass functions, biases, and kernels. The tools module provides adaptive integrators from CosmoTherm, FFTLog routines via FFTW3, and interpolation tables. The cluster-count module implements SZ cluster-count predictions, scaling relations, survey noise and completeness functions, and unbinned and binned likelihoods [2310.18482]. On the Python side, `classy_sz.pyx` extends the Cython interface, while `class_szfast.py` interfaces high-accuracy neural-network emulators, “cosmopower,” for CMB TT/TE/EE power spectra and linear and non-linear matter power spectra [2310.18482].

CLASS_SZ II describes the code base more broadly as written primarily in C, with a Cython-wrapped Python interface and selective “jaxified” routines for automatic differentiation, building directly on CLASS v2.9.4 for background quantities, linear transfer functions, and standard CMB and matter power spectra [2507.07346]. Its modular organization includes halo and profile modules for halo mass functions, halo bias, concentration–mass conversions, and radial profiles such as NFW and gNFW gas density and pressure; FFTLog and QAWO modules for Fourier/Hankel transforms; adaptive Patterson quadrature for mass and redshift integrals; and a small JAX subpackage containing pure-Python re-implementations of selected kernels [2507.07346].

The framework computes CLASS outputs together with a large suite of halo-model and linearly biased LSS observables. These include CMB anisotropy power spectra \(C_\ell^{TT}\), \(C_\ell^{TE}\), \(C_\ell^{EE}\), \(C_\ell^{BB}\), and lensing potential \(C_\ell^{\phi\phi}\); linear and non-linear matter power spectra; galaxy auto- and cross-angular power spectra; tSZ and kSZ power spectra; Compton-\(y\) cross-spectra with galaxies and CMB lensing; CIB auto- and cross-spectra; tree-level matter bispectra and halo-model bispectra; projected bispectra such as \(y\text{--}y\text{--}y\), \(y\text{--}y\text{--}T_e\), and kSZ–galaxy cross-bispectra; weak-lensing correlation functions \(\xi_\pm(\theta)\); galaxy tangential shear \(\gamma_t(\theta)\); galaxy clustering \(w(\theta)\); and SZ cluster-count predictions [2310.18482].

## 5. Theoretical formalism, workflows, and benchmarks

The central modeling strategy is a unified halo-model and linear-bias treatment. In the overview paper, the thermal SZ angular power spectrum is written as
$$
C_\ell^{yy}=\int dz\,\frac{dV}{dz\,d\Omega}\int dM\,\frac{dn}{dM}\,\lvert y_\ell(M,z)\rvert^2,
$$
with Fourier-space Compton-\(y\) profile
$$
y_\ell(M,z)=\int dr\,4\pi r^2\,P_e(r|M,z)\,j_\ell[kr]/[m_e c^2].
$$
Cross-power spectra are written in the generic form
$$
C_\ell^{AB}=\int dz\,\frac{d\chi}{dz}\,\frac{1}{\chi^2(z)}\,W^A(z)\,W^B(z)\,P_{AB}\!\left(k=\frac{\ell}{\chi(z)},z\right),
$$
and the mass–observable scaling relation is
$$
Y_{500}(M,z)=Y_*\,\left(\frac{M}{M_*}\right)^{\alpha_Y}E^{2/3+\beta_Y}(z)(1-b),
$$
where \(b\) is the hydrostatic mass bias [2310.18482].

CLASS_SZ II states the halo-model matter power spectrum as
$$
P_{mm}(k)=P^{1h}(k)+P^{2h}(k),
$$
with
$$
P^{1h}(k)=\int dM\,\frac{dn}{dM}(M,z)\,\frac{\tilde{u}^2(k|M)}{\bar{\rho}^2},
$$
and
$$
P^{2h}(k)=\left[\int dM\,\frac{dn}{dM}\,b(M,z)\,\frac{\tilde{u}(k|M)}{\bar{\rho}}\right]^2P_L(k,z).
$$
It also gives the tSZ profile kernel
$$
u_\ell^y(M,z)=\frac{\sigma_T}{m_e c^2}\,\frac{4\pi r_s}{\ell_s^2}\int dx\,x^2\,\mathrm{sinc}(w_\ell x)\,P_e(x,M,z),
$$
and a linearly biased angular spectrum
$$
C_\ell^{gg}=b_g^2\int dV\,W^g(z)^2P_{NL}[(\ell+1/2)/\chi,z].
$$
These formulas express the package’s basic design principle: CLASS supplies the background and linear perturbations, while class_sz adds halo-model profiles, projection kernels, and fast numerical evaluation [2507.07346].

Typical workflows are correspondingly broad. The code can compute \(C_\ell^{yy}\), tSZ–CMB lensing cross-power \(C_\ell^{y\phi}\), non-linear matter \(P(k)\) using emulators such as `"hmcode2020"`, and galaxy angular clustering or shear correlation functions. Configuration examples include parameters such as `cl_sz_method = halo_model` or `perturbation`, `cl_sz_tsz_profile = "Arnaud2010"` or `"Battaglia2012"`, `cl_sz_kappa_tracer = galaxy_CMBlens`, `cl_sz_pnfw_m_function = Tinker`, and `cl_sz_fNL = 0.0` [2310.18482]. The public repository contains source modules, Python bindings, examples, parameter defaults, tutorial notebooks, and MCMC pipeline examples for Cobaya and MontePython [2310.18482].

Reported performance is one of the code’s distinguishing practical properties. The overview paper reports \(\lesssim0.2\,\mathrm{s}\) per evaluation for the tSZ auto-spectrum on 8 cores, \(\lesssim0.1\,\mathrm{s}\) for kSZ and galaxy–CMB lensing cross spectra, \(\lesssim50\,\mathrm{ms}\) for CMB power spectra with cosmopower emulators, and \(\lesssim0.1\,\mathrm{s}\) for the non-linear matter emulator, with MCMC analyses of CMB spectra converging in \(O(\mathrm{few\ min})\) using class_sz + Cobaya instead of \(\approx1\) week with CLASS at the same accuracy [2310.18482]. CLASS_SZ II reports typical single-threaded wall-clock times of \(\simeq50\,\mathrm{ms}\) for CLASS background, \(\simeq80\,\mathrm{ms}\) for CMB \(C_\ell\) via emulators plus background, \(\lesssim1\,\mathrm{ms}\) for matter \(P(k)\) or individual \(C_\ell\), and \(\lesssim500\,\mathrm{ms}\) for combined halo-model outputs, with Python wrappers within a factor \(\sim2\text{--}3\) slower and JAX-ified routines adding \(10\text{--}30\%\) overhead while permitting vectorized differentiation [2507.07346].

## 6. Projected-field kSZ in class_sz and current limitations

A recent extension of the class_sz ecosystem treats projected-field kSZ cross-correlations. The projected-field kSZ estimator is defined by cross-correlating a foreground-cleaned, filtered, squared CMB temperature map with a large-scale-structure tracer, requiring no individual tracer redshifts [2509.03458]. In harmonic space,
$$
\langle \Theta_f^2(\ell)\,\delta_h(\ell')\rangle=(2\pi)^2\delta_D(\ell+\ell')\,C_\ell^{kSZ^2\times h},
$$
where \(\delta_h\) is the projected halo overdensity and the filter \(w(\ell)\) is chosen to optimally up-weight small-scale kSZ against primary CMB and noise [2509.03458].

The halo-model implementation decomposes projected observables into one- and two-halo terms,
$$
C_\ell^{ij,1h}=\int dz\,\frac{d^2V}{dz\,d\Omega}\int dM\,\frac{dn}{dM}\,U_\ell^i(M,z)\,U_\ell^j(M,z),
$$
and
$$
C_\ell^{ij,2h}=\int dz\,\frac{d^2V}{dz\,d\Omega}\,P_{\rm lin}(k=\ell+1/2\chi,z)
\left[\int dM\,\frac{dn}{dM}\,b(M,z)\,U_\ell^i(M,z)\right]
\left[\int dM\,\frac{dn}{dM}\,b(M,z)\,U_\ell^j(M,z)\right].
$$
Here \(dn/dM\) is the Tinker (2008) mass function, \(b(M,z)\) is the Tinker et al. (2010) linear bias, and \(U_\ell^i(M,z)=W^i(z)\,\hat{u}_\ell^i(M,z)\) encodes projection kernel and Fourier-space profile [2509.03458]. The dominant-contraction expression for the projected-field signal is
$$
C_\ell^{kSZ^2\times h}=\int d\chi\,\chi^{-2}\,W^{kSZ}(\chi)^2\,W^h(\chi)\,T(\ell,\chi),
$$
with
$$
T(\ell,\chi)=\int \frac{d^2\ell'}{(2\pi)^2}\,w(\ell')\,w(|\ell+\ell'|)\,B_{\delta_e\delta_e h}(k_1,k_2,k_3).
$$

The default modeling choices include Battaglia et al. (2012) GNFW fits for electron pressure, Battaglia (2016) GNFW fits for electron density, a mass integral \(M\in[10^{10},3.5\times10^{15}]\,h^{-1}M_\odot\), redshift range \(z\in[0.005,3]\), radial cutoff \(r_{\rm cut}=3\,r_{200c}\), and multipoles up to \(\ell\approx10{,}000\) [2509.03458]. Experiment-specific filtering is introduced through the beam \(b(\ell)=\exp[-\ell(\ell+1)\theta_{\rm FWHM}^2/(8\ln2)]\), with Planck nominal \(\theta=5'\) and SO LAT \(\theta=1.4'\), a total noise-plus-foreground residual spectrum \(N_\ell^{\Theta\Theta}\), and a Wiener filter
$$
w(\ell)=b(\ell)\,F(\ell),\qquad
F(\ell)=\mathrm{Max\text{-}normalized}\!\left[\sqrt{C_\ell^{kSZ}/C_\ell^{tot}}\right],
$$
where \(C_\ell^{tot}=C_\ell^{\Theta,\mathrm{lkd}}+C_\ell^{kSZ}+N_\ell\), together with truncation \(w(\ell)=0\) for \(\ell<\ell_{\min}\approx100\text{--}200\) to avoid ISW leakage [2509.03458].

The principal current caveat is theoretical completeness. The public implementation includes only the dominant Wick contraction \(\langle vv\rangle\langle\delta_e\delta_e\delta_h\rangle\) and neglects subdominant contractions such as \(\langle\delta v\rangle\langle\delta v\delta_h\rangle\). Comparison with Websky simulations finds good agreement, particularly at Planck sensitivity, but also an \(\approx20\%\) difference for SO that significantly exceeds predicted error bars; the paper states that these missing contractions must be included to obtain unbiased inference from upcoming projected-field kSZ measurements [2509.03458]. The same source notes that modeling uncertainties of order \(\lesssim25\%\) are not yet a major concern for Planck-sensitivity analyses, whereas SO and next-generation surveys require the full set of contractions [2509.03458].

The contemporary meaning of **class_sz** is therefore structurally dual. In observational catalogue work it denotes a three-class statistical reliability assessment for SZ detections based on SED projection and classifiers of increasing supervision [1409.6543]. In theoretical and computational cosmology it denotes a public, modular, emulator-accelerated extension of CLASS for SZ, CMB, and LSS observables, with increasing reach into differentiable pipelines and projected-field kSZ modeling [2310.18482].

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