# PySM Documentation¶

PySM 3 generates full-sky simulations of Galactic foregrounds in intensity and polarization relevant for CMB experiments. The components simulated are: thermal dust, synchrotron, AME, free-free, and CMB at a given HEALPix $$N_{side}$$, with an option to integrate over a bandpass and to smooth with a given beam.

There is scope for a few options for the model for each component, attempting to be consistent with current data.

Currently much of the available data is limited in resolution at degree-scale. We therefore make efforts to provide reasonable small-scale simulations to extend the data to higher multipoles. The details of the procedures developed can be found in the accompanying paper.

If you are using this code please cite the PySM 2 paper Thorne at al

This code is based on the large-scale Galactic part of Planck Sky Model (Delabrouille 2012) code and uses some of its inputs.

## Models¶

Each model is identified with a letter and a number, the letter indicates the kind of emission and the number the type of model, generally in order of complexity starting at 1. For example for dust we start with d1 based on Planck commander results, d4 has 2 dust populations and d6 implements a model of dust frequency decorrelation.

For example free-free:

f1: We model the free-free emission using the analytic model assumed in the Commander fit to the Planck 2015 data (Draine 2011 Physics of the Interstellar and Intergalactic Medium) to produce a degree-scale map of free-free emission at 30 GHz. We add small scales to this using a procedure outlined in the accompanying paper. This map is then scaled in frequency by applying a spatially constant power law index of -2.14.

# Dependencies¶

PySM is written in pure Python, multi-threading and Just-In-Time compilation are provided by numba. The required packages are:

• healpy

• numba

• toml

• astropy

• importlib_metadata just for Python 3.7

How many threads are used by numba can be controlled by setting:

export OMP_NUM_THREADS=2


For debugging purposes, you can also completely disable the numba JIT compilation and have the code just use plain Python, which is slower, but easier to debug:

export NUMBA_DISABLE_JIT=1


## Run PySM with MPI support¶

PySM 3 is capable of running across multiple nodes using a MPI communicator.

See the details in the MPI section of the tutorial.

In order to run in parallel with MPI, it also needs a functioning MPI environment and:

• mpi4py

MPI-Distributed smoothing (optional) requires libsharp, it is easiest to install the conda package:

conda install -c conda-forge libsharp=*=*openmpi*


It also has a mpich version:

conda install -c conda-forge libsharp=*=*mpich*


# Installation¶

The easiest way to install the last release is to use conda:

conda install -c conda-forge pysm3


or pip:

pip install pysm3


See the changelog on Github for details about what is included in each release.

## Install at NERSC¶

Optionally replace with a newer anaconda environment:

module load python/3.7-anaconda-2019.10
conda create -c conda-forge -n pysm3 pysm3 python=3.7 ipython
conda activate pysm3


## Development install¶

The development version is available in the main branch of the GitHub repository, you can clone and install it with:

pip install .


Create a development installation with:

pip install -e .


Install the requirements for testing with:

pip install -e .[test]


Execute the unit tests with:

pytest


## Configure verbosity¶

PySM uses the logging module to configure its verbosity, by default it will only print warnings and errors, to configure logging you can access the “pysm3” logger with:

import logging
log = logging.getLogger("pysm3")


configure the logging level:

log.setLevel(logging.DEBUG)


redirect the logs to the console:

handler = logging.StreamHandler()


or customize their format:

log_format="%(name)s - %(levelname)s - %(message)s"
formatter = logging.Formatter(log_format)
handler.setFormatter(formatter)


For more details see the Python documentation.

# Tutorials¶

All the tutorials are Jupyter Notebooks and can be accessed from the repository:

# Reference/API¶

## pysm3 Package¶

### Functions¶

 Apply smoothing and coordinate rotation to an input map bandpass_unit_conversion(freqs[, weights, ...]) Unit conversion from input to output unit given a bandpass check_freq_input(freqs) Function to check that the input to Model.get_emission is a np.ndarray. mpi_smoothing(input_map, fwhm, map_dist) normalize_weights(freqs, weights) Normalize bandpass weights to support integration "in K_RJ" read_map(path, nside[, unit, field, map_dist]) Wrapper of healpy.read_map for PySM data. test(**kwargs) Run the tests for the package. version(distribution_name) Get the version string for the named package.

### Classes¶

 AstropyDeprecationWarning A warning class to indicate a deprecated feature. CMBLensed(nside, cmb_spectra[, cmb_seed, ...]) Lensed CMB CMBMap(nside[, map_IQU, map_I, map_Q, ...]) Load one or a set of 3 CMB maps COLines(nside[, has_polarization, lines, ...]) Class defining attributes for CO line emission. CurvedPowerLaw(map_I, freq_ref_I, ...[, ...]) This function initialzes the power law model of synchrotron emission. DecorrelatedModifiedBlackBody([map_I, ...]) See parent class for other documentation. HensleyDraine2017(map_I, map_Q, map_U, ...) This is a model for modified black body emission. InterpolatingComponent(path, input_units, nside) PySM component interpolating between precomputed maps MapDistribution([pixel_indices, mpi_comm, ...]) Define how a map is distributed Model(nside[, map_dist]) This is the template object for PySM objects. ModifiedBlackBody(map_I, freq_ref_I, ...[, ...]) This is a model for modified black body emission. ModifiedBlackBodyLayers(map_layers, ...[, ...]) Modified Black Body model with multiple layers ModifiedBlackBodyRealization(largescale_alm, ...) Modified Black Body model with stochastic small scales PackageNotFoundError The package was not found. PowerLaw(map_I, freq_ref_I, map_pl_index, nside) This is a model for a simple power law synchrotron model. PowerLawRealization(largescale_alm, ...[, ...]) PowerLaw model with stochastic small scales Sky([nside, preset_strings, ...]) Sky is the main interface to PySM SpDust(map_I, freq_ref_I, emissivity, ...[, ...]) Implementation of the SpDust2 code of (Ali-Haimoud et al 2012) evaluated for a Cold Neutral Medium. SpDustPol(map_I, freq_ref_I, emissivity, ...) SpDust2 model with Polarized emission