def get_maps_recon(TOD, d, p, nf_sub_rec, x0): maps_recon, cov, nus, nus_edge, maps_convolved = si.reconstruct_maps( TOD, d, p, nf_sub_rec, x0=x0) if nf_sub_rec==1: maps_recon = np.reshape(maps_recon, np.shape(maps_convolved)) cov = np.sum(cov, axis=0) maxcov = np.max(cov) unseen = cov < maxcov*0.1 #diffmap = maps_convolved - maps_recon maps_convolved[:,unseen,:] = hp.UNSEEN maps_recon[:,unseen,:] = hp.UNSEEN #maps_recon += np.repeat(xav[None, ...], nf_sub_rec, axis=0) return maps_recon
def test_get_simple_sky_map(self): sky_config0 = {'cmb': models('c1', d['nside'])} sky0 = si.sky(sky_config0, d, None).get_simple_sky_map() sky0_q = si.Qubic_sky(sky_config0, d).get_simple_sky_map() sky0_p = si.Planck_sky(sky_config0, d).get_simple_sky_map() self.assertTrue(np.all(sky0 == sky0_q)) self.assertTrue(np.all(sky0_p == sky0_q)) self.assertTrue(sky0_p.shape == sky0_q.shape) self.assertTrue(sky0_q.shape[0] == int(d['nf_sub'])) self.assertTrue(sky0_q.shape[1] == 12 * d['nside']**2) self.assertTrue(sky0_q.shape[2] == 3) sky = si.sky(sky_config, d, None).get_simple_sky_map() skyq = si.Qubic_sky(sky_config, d).get_simple_sky_map() skyp = si.Planck_sky(sky_config, d).get_simple_sky_map() for j in range(3): for i in range(len(sky0)): self.assertTrue(np.all(sky0[i, :, j] != sky[i, :, j])) self.assertTrue(np.all(sky0_q[i, :, j] == sky0_p[i, :, j])) self.assertTrue(np.all(skyq[i, :, j] == skyp[i, :, j]))
map_recon0 = [] nf_sub_rec = 4 for j, dust in enumerate(dust_coeffs): ### Sky ### sky_config = { 'synchrotron': models('s1', d['nside']), 'dust': models('d1', d['nside']), 'freefree': models('f1', d['nside']), #not polarized 'cmb': models('c1', d['nside']), 'ame': models('a1', d['nside']), #not polarized } skypars = {'dust_coeff':dust, 'r':0} # 1.39e-2 x0 = si.create_input_sky(d, skypars) #shape is (num of sub-bands, npix, IQU) ### QUBIC TOD ### p = qubic.get_pointing(d) TODq = si.create_TOD(d, p, x0) ### Planck TOD ### ### Put Q and U to zero ### x0[..., 1:3] = 0 xav = np.mean(x0, axis=0) TODp = si.create_TOD(d, p, np.repeat(xav[None, ...], d['nf_sub'], axis=0)) ### Create difference TOD ### TOD = TODq - TODp ### QUBIC TOD with I=0 ###
for k in d.keys(): print(k, d[k]) print('Minimum Number of Sub Frequencies: {}'.format(noutmin)) print('Maximum Number of Sub Frequencies: {}'.format(noutmax)) print(skypars) sys.stdout = tem f.close() #################################################################################################### ##### Sky Creation ##### t0 = time.time() x0 = si.create_input_sky(d, skypars) t1 = time.time() print('********************* Input Sky done in {} seconds'.format(t1 - t0)) ##### Pointing strategy ##### p = qubic.get_pointing(d) t2 = time.time() print('************************** Pointing done in {} seconds'.format(t2 - t1)) ##### TOD making ##### TOD = si.create_TOD(d, p, x0) ##### Mapmaking ##### for nf_sub_rec in np.arange(noutmin, noutmax + 1): print('-------------------------- Map-Making on {} sub-map(s)'.format( nf_sub_rec))
import matplotlib.pyplot as mp import qubic from pysimulators import FitsArray import SpectroImLib as si t0 = time.time() ### Instrument ### d = qubic.qubicdict.qubicDict() d.read_from_file("parameters.dict") ### Sky ### skypars = {'dust_coeff':1.39e-2, 'r':0} # 1.39e-2 x0 = si.create_input_sky(d, skypars) #shape is (num of sub-bands, npix, IQU) ### QUBIC TOD ### p = qubic.get_pointing(d) TODq = si.create_TOD(d, p, x0) ### Put Q and U to zero ### x0[..., 1:3] = 0 ### Planck TOD ### xav = np.mean(x0, axis=0) TODp = si.create_TOD(d, p, np.repeat(xav[None, ...], d['nf_sub'], axis=0)) ### Create difference TOD ### TOD = TODq - TODp
dp = qubic.qubicdict.qubicDict() d.read_from_file("parameters.dict") dp.read_from_file("parameters.dict") dp['MultiBand'] = False dp['nf_sub'] = 1 ### Sky ### sky_config = { 'synchrotron': models('s1', d['nside']), 'dust': models('d1', d['nside']), 'freefree': models('f1', d['nside']), #not polarized 'cmb': models('c1', d['nside']), 'ame': models('a1', d['nside']) } #not polarized planck_sky = si.Planck_sky(sky_config, d) x0_planck = planck_sky.get_sky_map() qubic_sky = si.Qubic_sky(sky_config, d) x0_qubic = qubic_sky.get_sky_map() ### QUBIC TOD ### p = qubic.get_pointing(d) TODq = si.create_TOD(d, p, x0_qubic) ### Put Q and U to zero ### x0_planck[..., 1:3] = 0 ### Planck TOD ### TODp = si.create_TOD(dp, p, x0_planck)
from mpl_toolkits.mplot3d import Axes3D import qubic from pysimulators import FitsArray import SpectroImLib as si t0 = time.time() ### Instrument ### d = qubic.qubicdict.qubicDict() d.read_from_file("parameters.dict") ### Sky ### skypars = {'dust_coeff':1.39e-2, 'r':0} x0 = si.create_input_sky(d, skypars) #shape is (num of sub-bands, npix, IQU) ### Frame ### p = qubic.get_pointing(d) q = qubic.QubicMultibandInstrument(d) s = qubic.QubicScene(d) ### Hit maps ### rot_beams = si.get_hitmap(q, s, p) hwp_angles = np.unique(p.angle_hwp) hwp_angles_distribution = np.zeros((len(hwp_angles), s.npixel)) for i, angle in enumerate(hwp_angles): hwp_angles_distribution[i] = np.sum( rot_beams[np.where(p.angle_hwp == angle)[0]], axis=0)
from pysimulators import FitsArray from pysm.nominal import models mp.rc('text', usetex=False) ### Instrument ### d = qubic.qubicdict.qubicDict() dp = qubic.qubicdict.qubicDict() d.read_from_file("test_spectroim.dict") d['MultiBand'] = True # spectro imager d['nf_sub'] = 16 dp.read_from_file("test_spectroim.dict") dp['MultiBand'] = False dp['nf_sub'] = 1 ### Sky ### sky_config = { 'dust': models('d1', d['nside']), 'synchrotron': models('s1', d['nside']), 'freefree': models('f1', d['nside']), #not polarized 'cmb': models('c1', d['nside']), 'ame': models('a1', d['nside']) } #not polarized planck_sky = si.Planck_sky(sky_config, d) x0_planck = planck_sky.get_sky_map() #x0_planck[1:,:,:] = x0_planck[0,:,:] qubic_sky = si.Qubic_sky(sky_config, d) x0_qubic = qubic_sky.get_sky_map()
def test_planck_sky(self): maps_p = sky_p.get_sky_map() maps_p_all = sky_p_all.get_sky_map() for i in [0, 1, 2, 3, 5, 6, 7, 8]: self.assertFalse( np.allclose(np.std(maps_p_all[i], axis=0), np.std(maps_p[0], axis=0), atol=1e-2)) self.assertFalse( np.allclose(np.mean(maps_p_all[i], axis=0), np.mean(maps_p[0], axis=0), atol=1e-2)) self.assertTrue( np.allclose(np.std(maps_p_all[4], axis=0), np.std(maps_p[0], axis=0), atol=1e-2)) self.assertTrue( np.allclose(np.mean(maps_p_all[4], axis=0), np.mean(maps_p[0], axis=0), atol=1e-2)) instrument_nless_pless = pysm.Instrument({ 'nside': d['nside'], 'frequencies': sky_p.planck_central_nus[4:5], # GHz 'use_smoothing': False, 'beams': None, # arcmin 'add_noise': False, 'noise_seed': None, 'sens_I': None, 'sens_P': None, 'use_bandpass': True, 'channel_names': sky_p.planck_channels_names[4:5], 'channels': sky_p.planck_channels[4:5], 'output_units': 'Jysr', 'output_directory': "./", 'output_prefix': "planck_sky_pless_nless", 'pixel_indices': None }) sky_p_nless_pless = si.sky(sky_config, d, instrument_nless_pless) maps_p_nless_pless = sky_p_nless_pless.get_sky_map() disintegrated_maps = np.rollaxis( sky_p_nless_pless.sky.signal()(nu=sky_p.planck_channels[4:5][0][0]) * pysm.pysm.convert_units( "uK_RJ", "Jysr", sky_p.planck_channels[4:5][0][0])[..., None, None], 2, 1) integrated_maps = np.mean(disintegrated_maps, axis=0) self.assertTrue(np.allclose(maps_p_nless_pless, integrated_maps)) instrument_noisy = pysm.Instrument({ 'nside': d['nside'], 'frequencies': sky_p.planck_central_nus[4:5], # GHz 'use_smoothing': False, 'beams': None, # arcmin 'add_noise': True, 'noise_seed': 0, 'sens_I': sky_p.get_planck_sensitivity("I")[4:5], 'sens_P': sky_p.get_planck_sensitivity("P")[4:5], 'use_bandpass': False, 'channel_names': sky_p.planck_channels_names[4:5], 'channels': None, 'output_units': 'uK_RJ', 'output_directory': "./", 'output_prefix': "planck_sky_noisy", 'pixel_indices': None }) sky_p_noisy = si.sky(sky_config, d, instrument_noisy) maps_p_noisy, noise_map_produced = sky_p_noisy.get_sky_map( noise_map=True) noise_map = maps_p_noisy[0] - sky_p.sky.signal()( nu=sky_p.planck_central_nus[4:5]).T self.assertTrue(np.allclose(noise_map, noise_map_produced)) c = np.sqrt(hp.nside2pixarea(d['nside'], degrees=True)) * 60 # arcmin C = pysm.pysm.convert_units("uK_RJ", "uK_CMB", sky_p.planck_central_nus[4:5][0]) self.assertTrue( np.allclose(np.std(noise_map, axis=0)[0] * c * C, sky_p.get_planck_sensitivity("I")[4:5], atol=1e-1)) self.assertTrue( np.allclose(np.std(noise_map, axis=0)[1] * c * C, sky_p.get_planck_sensitivity("P")[4:5], atol=1e-1)) self.assertTrue( np.allclose(np.std(noise_map, axis=0)[2] * c * C, sky_p.get_planck_sensitivity("P")[4:5], atol=1e-1)) sm_pns = sky_p.planck_beams[4:5][0] * np.pi / (60 * 180) jysky = sky_p.instrument.apply_bandpass(sky_p.sky.signal(), sky_p.sky) maps_a = sky_p.instrument.smoother(jysky)[0].T maps_b = hp.smoothing(jysky[0], fwhm=sm_pns).T self.assertTrue(np.allclose(maps_a, maps_b)) # instrument_mono = pysm.Instrument({ # 'nside': d['nside'], # 'frequencies' : sky_p.planck_central_nus[4:5], # GHz # 'use_smoothing' : True, # 'beams' : sky_p.planck_beams[4:5], # arcmin # 'add_noise' : True, # 'noise_seed' : 0, # 'sens_I': sky_p.get_planck_sensitivity("I")[4:5], # 'sens_P': sky_p.get_planck_sensitivity("P")[4:5], # 'use_bandpass' : False, # 'channel_names' : sky_p.planck_channels_names[4:5], # 'channels' : None, # 'output_units' : 'uK_RJ', # 'output_directory' : "./", # 'output_prefix' : "planck_sky_mono", # 'pixel_indices' : None}) # sky_p_mono = si.sky(sky_config, d, instrument_mono) # maps_p_mono = sky_p_mono.get_sky_map() # self.assertTrue(maps_p_mono.shape == (1, 196608, 3)) # instrument_mono_nless = pysm.Instrument({ # 'nside': d['nside'], # 'frequencies' : sky_p.planck_central_nus[4:5], # GHz # 'use_smoothing' : True, # 'beams' : sky_p.planck_beams[4:5], # arcmin # 'add_noise' : False, # 'noise_seed' : None, # 'sens_I': None, # 'sens_P': None, # 'use_bandpass' : False, # 'channel_names' : sky_p.planck_channels_names[4:5], # 'channels' : None, # 'output_units' : 'uK_RJ', # 'output_directory' : "./", # 'output_prefix' : "planck_sky_nless_mono", # 'pixel_indices' : None}) # sky_p_mono_nless = si.sky(sky_config, d, instrument_mono_nless) # maps_p_mono_nless = sky_p_mono_nless.get_sky_map() # self.assertTrue(maps_p_mono_nless.shape == (1, 196608, 3)) instrument_mono_nless_pless = pysm.Instrument({ 'nside': d['nside'], 'frequencies': sky_p.planck_central_nus[4:5], # GHz 'use_smoothing': False, 'beams': None, # arcmin 'add_noise': False, 'noise_seed': None, 'sens_I': None, 'sens_P': None, 'use_bandpass': False, 'channel_names': sky_p.planck_channels_names[4:5], 'channels': None, 'output_units': 'uK_RJ', 'output_directory': "./", 'output_prefix': "planck_sky_pless_nless_mono", 'pixel_indices': None }) sky_p_mono_nless_pless = si.sky(sky_config, d, instrument_mono_nless_pless) maps_p_mono_nless_pless = sky_p_mono_nless_pless.get_sky_map() self.assertTrue( np.allclose(maps_p_mono_nless_pless[0], pysm.Sky(sky_config).signal()(nu=143).T))
import pysm import os d = qubic.qubicdict.qubicDict() d.read_from_file("parameters.dict") p = qubic.get_pointing(d) sky_config = { 'synchrotron': models('s1', d['nside']), 'dust': models('d1', d['nside']), 'freefree': models('f1', d['nside']), #not polarized 'cmb': models('c1', d['nside']), 'ame': models('a1', d['nside']) } #not polarized sky_q = si.Qubic_sky(sky_config, d) sky_p = si.Planck_sky(sky_config, d) sky_p_all = si.Planck_sky(sky_config, d, band=None) class TestSpectroImLib(ut.TestCase): def test_get_simple_sky_map(self): sky_config0 = {'cmb': models('c1', d['nside'])} sky0 = si.sky(sky_config0, d, None).get_simple_sky_map() sky0_q = si.Qubic_sky(sky_config0, d).get_simple_sky_map() sky0_p = si.Planck_sky(sky_config0, d).get_simple_sky_map() self.assertTrue(np.all(sky0 == sky0_q)) self.assertTrue(np.all(sky0_p == sky0_q)) self.assertTrue(sky0_p.shape == sky0_q.shape) self.assertTrue(sky0_q.shape[0] == int(d['nf_sub']))