In [1]:
import pysm
from pysm.nominal import models
import numpy as np
import healpy as hp
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
nside = 64
sky_config = {
'synchrotron' : models("s1", nside),
'dust' : models("d1", nside),
'freefree' : models("f1", nside),
'cmb' : models("c1", nside),
'ame' : models("a1", nside),
}
In [3]:
# initialise Sky
sky = pysm.Sky(sky_config)
# Sky then has attributes corresponding to each of the sky
# components which return that component for a given frequency:
cmb = sky.cmb(nu = 23.)
fig = plt.figure(figsize = (13, 8))
hp.mollview(cmb[0], min = -250, max = 250, title = 'cmb I', sub = (131))
hp.mollview(cmb[1], min = -5, max = 5, title = 'cmb Q', sub = (132))
hp.mollview(cmb[2], min = -5, max = 5, title = 'cmb U', sub = (133))
plt.show()
In [4]:
dust = sky.dust(300.)
fig = plt.figure(figsize = (13, 8))
hp.mollview(dust[0], min = 0, max = 250, title = 'Dust I', sub = (131))
hp.mollview(dust[1], min = -5, max = 5, title = 'Dust Q', sub = (132))
hp.mollview(dust[2], min = -5, max = 5, title = 'Dust U', sub = (133))
plt.show()
In [5]:
# or the total signal as a function of frequency:
total = sky.signal()(100.)
fig = plt.figure(figsize = (13, 8))
hp.mollview(total[0], min = -250, max = 250, title = 'Total I', sub = (131))
hp.mollview(total[1], min = -5, max = 5, title = 'Total Q', sub = (132))
hp.mollview(total[2], min = -5, max = 5, title = 'Total U', sub = (133))
plt.show()
We can also evaluate the signal for a vector of frequencies:
In [6]:
freqs = np.logspace(np.log10(30), np.log10(300), 30)
output = sky.signal()(freqs)
print("Shape of output is (N_freqs, 3, Npix): ", output.shape)
In [ ]:
In [7]:
total_fgnd = np.std(output - sky.cmb(freqs), axis = 2)
dust = np.std(sky.dust(freqs), axis = 2)
synchrotron = np.std(sky.synchrotron(freqs), axis = 2)
freefree = np.std(sky.freefree(freqs), axis = 2)
ame = np.std(sky.ame(freqs), axis = 2)
cmb = np.std(sky.cmb(freqs), axis = 2)
In [8]:
plt.figure(figsize = (9, 9))
plt.loglog(freqs, total_fgnd[:, 0], label = "Total fgnd")
plt.loglog(freqs, dust[:, 0], label = "Dust = d1")
plt.loglog(freqs, synchrotron[:, 0], label = "Synchrotron = s1")
plt.loglog(freqs, freefree[:, 0], label = "Free-free = f1")
plt.loglog(freqs, ame[:, 0], label = "AME = a1")
plt.loglog(freqs, cmb[:, 0], label = "CMB = c1")
plt.legend(fontsize = 20, ncol = 2)
plt.xlabel(r"$\nu$ (GHz)", fontsize = 20)
plt.ylabel(r"$I_{\rm RMS}$ ($\mu K_{\rm RJ}$)", fontsize = 20)
plt.ylim([10, 1000])
Out[8]:
If we want to add instrument effects then use the Instrument class. Since this isn't easily a function of frequency it writes maps to file for a given set of observation frequencies, noise, bandpass etc.
Instantiating the Instrument object requires a configuration dictionary, as in the case of Sky.
First we will consider the case of delta bandpasses, and so we use the frequencies key to specify the observation frequencies.
In [9]:
instrument_delta_bpass = {
'frequencies' : np.logspace(1., 3., 20),
'beams' : np.ones(20)*70.,
'sens_I' : np.ones(20),
'sens_P' : np.ones(20),
'nside' : nside,
'noise_seed' : 1234,
'use_bandpass' : False,
'add_noise' : True,
'output_units' : 'uK_RJ',
'use_smoothing' : True,
'output_directory' : './',
'output_prefix' : 'test',
}
instrument = pysm.Instrument(instrument_delta_bpass)
instrument.observe(sky)
Next we consider tophat bandpasses, which we give as a list of tuples: [(frequencies_1, weights_1), (frequencies_2, weights_2) ... ] to the channel key. We must also provide names of these channels as a list of strings to the channel_names key. In this case we do not need to set frequencies since all outputs are defined by the bandpasses.
In [10]:
instrument_bpass = {
'use_smoothing' : True,
'beams' : np.array([30., 40., 50.]), # beam fwhm in arcmin
'nside' : nside,
'add_noise' : True,
'sens_P' : np.array([4.5, 4.2, 3.1]), # channel sensitivities in uK_CMB amin
'sens_I' : np.array([3.5, 3.2, 2.1]),
'use_bandpass' : True,
'channels' : [(np.linspace(20, 25, 10), np.ones(10)), (np.linspace(30, 35, 10), np.ones(10)), (np.linspace(40, 45, 10), np.ones(10))],
'channel_names' : ['channel_1', 'channel_2', 'channel_3'],
'output_units' : 'uK_RJ',
'output_directory' : './',
'output_prefix' : 'test',
'noise_seed' : 1234,
}
instrument = pysm.Instrument(instrument_bpass)
instrument.observe(sky)
If you would like to change the parameters of any of the provided models in PySM then all you need to do is change the component configuration dictionaries. For example let's look at altering one of the dust models, d2. d2 is a single-component dust model, and so d2 is a list with one dictionary in it:
In [11]:
d2 = models("d2", nside)
print d2[0]
We can see the templates used:
In [12]:
fig = plt.figure(figsize = (12, 8))
hp.mollview(d2[0]['A_I'], norm = 'log', sub = (221))
hp.mollview(d2[0]['A_Q'], sub = (222))
hp.mollview(d2[0]['A_U'], sub = (223))
hp.mollview(d2[0]['spectral_index'], sub = (224))
We could change the spectral index to be constant across the sky:
In [13]:
d2[0]['spectral_index'] = 1.54
In [14]:
sky = pysm.Sky({'dust' : d2})
In [15]:
hp.mollview(sky.dust(500.)[0], norm = 'log')
In [ ]: