コード例 #1
0
ファイル: pysm_freefree.py プロジェクト: bthorne93/PySM
def main(fname_config):

#Read configuration into classes
        Config = ConfigParser.ConfigParser()
        Config.read(fname_config)
        out = output(Config._sections['GlobalParameters'])

        Config.read('./ConfigFiles/'+Config.get('FreeFree','model')+'_config.ini')
        freefree = component(Config._sections['FreeFree'],out.nside)
        with open(out.output_dir+out.output_prefix+'freefree_config.ini','w') as configfile\
: Config.write(configfile)

        print('Computing free-free maps.')
        print '----------------------------------------------------- \n'
        if out.debug == True:
                print ''.join("%s: %s \n" % item   for item in vars(freefree).items())
                print '----------------------------------------------------- \n'
        
        conv_I = convert_units(freefree.template_units,out.output_units,out.output_frequency)
	
        scaled_map_ff = scale_freqs(freefree,out)*conv_I[...,np.newaxis]*freefree.em_template
        scaled_map_ff_pol = np.zeros((2,np.asarray(out.output_frequency).size,hp.nside2npix(out.nside)))

        if out.debug == True:
            ff = np.concatenate([scaled_map_ff[np.newaxis,...],scaled_map_ff_pol])
	    for i in range(0,len(out.output_frequency)):
		    hp.write_map(out.output_dir+out.output_prefix+'ff_%d'%(out.output_frequency[i])+'_'+str(out.nside)+'.fits',ff[:,i,:],coord='G',column_units=out.output_units)

        return np.concatenate([scaled_map_ff[np.newaxis,...],scaled_map_ff_pol])
コード例 #2
0
ファイル: pysm_noise.py プロジェクト: bthorne93/PySM
def instrument_noise(fname_config):

    Config = ConfigParser.ConfigParser()
    Config.read(fname_config)
    out = output(Config._sections['GlobalParameters'])

    print('Adding instrument noise.')
    print '----------------------------------------------------- \n'
 
    npix = hp.nside2npix(out.nside)

    #Convert noise to sigma per pixel.
    fsky_pix = 1./npix
    pix_ster = 4.*np.pi*fsky_pix
    pix_amin2 = pix_ster*(180.*60./np.pi)**2  #converts size of pixel from steradians to square arcminutes

    sigma_pix_I = np.sqrt(out.instrument_noise_i**2/pix_amin2)
    sigma_pix_pol = np.sqrt(out.instrument_noise_pol**2/pix_amin2)

    #Generate noise as gaussian with variances above:
    np.random.seed(out.instrument_noise_seed)
    instrument_noise = np.random.randn(3,np.asarray(out.output_frequency).size,npix)

    #standard_normal*sigma+mu = N(mu,sigma)
    instrument_noise[0,...]=sigma_pix_I[np.newaxis,:,np.newaxis]*instrument_noise[0,...]
    instrument_noise[1,...]=sigma_pix_pol[np.newaxis,:,np.newaxis]*instrument_noise[1,...]
    instrument_noise[2,...]=sigma_pix_pol[np.newaxis,:,np.newaxis]*instrument_noise[2,...]

    return instrument_noise*convert_units(['u','K_CMB'],out.output_units,out.output_frequency)[np.newaxis,:,np.newaxis]
コード例 #3
0
ファイル: pysm_synchrotron.py プロジェクト: bthorne93/PySM
def main(fname_config):

#Read in configuration file to classes.
	Config = ConfigParser.ConfigParser()
	Config.read(fname_config)
	out = output(Config._sections['GlobalParameters'])

	Config.read('./ConfigFiles/'+Config.get('Synchrotron','model')+'_config.ini')
	synch = component(Config._sections['Synchrotron'],out.nside)
	with open(out.output_dir+out.output_prefix+'synchrotron_config.ini','w') as configfile: Config.write(configfile)

	print('Computing synchrotron maps.')
	print '----------------------------------------------------- \n'
	if out.debug == True:
		print ''.join("%s: %s \n" % item   for item in vars(synch).items())
		print '----------------------------------------------------- \n'

#The unit conversion takes care of the scaling being done in uK_RJ. After scaling we convert to whatever the output units are.
	conv_I = convert_units(synch.template_units, ['u','K_RJ'], synch.freq_ref)
	conv_pol = convert_units(synch.template_units, ['u','K_RJ'], synch.pol_freq_ref) 
	conv2 = convert_units(['u','K_RJ'],out.output_units,out.output_frequency)
	unit_conversion_I = conv_I*conv2.reshape((len(out.output_frequency),1))
	unit_conversion_pol = conv_pol*conv2.reshape((len(out.output_frequency),1))
#Do the scaling.

	scaled_map_synch = scale_freqs(synch, out, pol=False)*synch.em_template*unit_conversion_I
	scaled_map_synch_pol = scale_freqs(synch, out, pol=True)[np.newaxis,...]*np.array([synch.polq_em_template,synch.polu_em_template])[:,np.newaxis,:]*unit_conversion_pol

#This section forces P/I<0.75. This is done using the same procedure as the PSM 1.7.8 psm_synchrotron.pro.

	P = np.sqrt(scaled_map_synch_pol[0,:,:]**2+scaled_map_synch_pol[1,:,:]**2)/scaled_map_synch
	F = 0.75*np.tanh(P/0.75)/P
	scaled_map_synch_pol[0,:,:]=F*scaled_map_synch_pol[0,:,:]
	scaled_map_synch_pol[1,:,:]=F*scaled_map_synch_pol[1,:,:]

#-------

	if out.debug == True:
		syn = np.concatenate([scaled_map_synch[np.newaxis,...],scaled_map_synch_pol])
		for i in range(0,len(out.output_frequency)):
			hp.write_map(out.output_dir+out.output_prefix+'synch_%d'%(out.output_frequency[i])+'_'+str(out.nside)+'.fits',syn[:,i,:],coord='G',column_units=out.output_units)

	return np.concatenate([scaled_map_synch[np.newaxis,...],scaled_map_synch_pol])
コード例 #4
0
ファイル: pysm_thermaldust.py プロジェクト: bthorne93/PySM
def main(fname_config):

    # Read configuration into classes
    Config = ConfigParser.ConfigParser()
    Config_model = ConfigParser.ConfigParser()

    Config.read(fname_config)
    out = output(Config._sections["GlobalParameters"])

    Config_model.read("./ConfigFiles/" + Config.get("ThermalDust", "model") + "_config.ini")
    pops = Config_model.sections()

    with open(out.output_dir + out.output_prefix + "thermaldust_config.ini", "w") as configfile:
        Config_model.write(configfile)

    dust_out = 0.0

    for p in pops:
        dust_out += scale_dust_pop(p, out, Config_model)

    return dust_out
コード例 #5
0
ファイル: pysm_spinningdust.py プロジェクト: bthorne93/PySM
def main(fname_config):

#Read in configuration file to classes.
    Config = ConfigParser.ConfigParser()
    Config.read(fname_config)
    out = output(Config._sections['GlobalParameters'])

    Config.read('./ConfigFiles/'+Config.get('SpinningDust','model')+'_config.ini')
    spdust_general = component(Config._sections['General'],out.nside)
    spdust1 = component(Config._sections['SpinningDust1'],out.nside)
    spdust2 = component(Config._sections['SpinningDust2'],out.nside)

    print('Computing spinning dust map.')
    print '----------------------------------------------------- \n'

    if out.debug == True:
        print ''.join("%s: %s \n" % item   for item in vars(spdust1).items())
        print ''.join("%s: %s \n" % item   for item in vars(spdust2).items())
        print '----------------------------------------------------- \n'
    with open(out.output_dir+out.output_prefix+'spdust_config.ini','w') as configfile: Config.write(configfile)
#Compute a map of the polarisation angle from the commander dust map polariationn angle. 
    
    pol_angle = np.arctan2(spdust_general.thermaldust_polu,spdust_general.thermaldust_polq)

#Units to do the scaling in MJysr and then bring the result back to the output units.
    conv1 = convert_units(spdust1.template_units, ['u','K_RJ'], spdust1.freq_ref)
    conv2 = convert_units(spdust2.template_units, ['u','K_RJ'], spdust2.freq_ref)
    conv_end = convert_units(['u','K_RJ'],out.output_units,out.output_frequency)
    unit_conversion1 = conv1*conv_end.reshape((len(out.output_frequency),1))
    unit_conversion2 = conv2*conv_end.reshape((len(out.output_frequency),1))

    scaled_map_spdust = scale_freqs(spdust1,out,pol=False)*spdust1.em_template*unit_conversion1 + scale_freqs(spdust2,out,pol=False)*spdust2.em_template*unit_conversion2
    scaled_map_spdust_pol = scaled_map_spdust[np.newaxis,...]*np.asarray([np.cos(pol_angle),np.sin(pol_angle)])[:,np.newaxis,:]*spdust_general.pol_frac

    if out.debug == True:
        for i in range(0,len(out.output_frequency)):
            hp.write_map(out.output_dir+'spdust_%d.fits'%(out.output_frequency[i]),scaled_map_spdust[i],coord='G',column_units=out.output_units)

    return np.concatenate([scaled_map_spdust[np.newaxis,...],scaled_map_spdust_pol])
コード例 #6
0
ファイル: main.py プロジェクト: bthorne93/PySM
import ConfigParser, os
import pysm_synchrotron,pysm_thermaldust,pysm_cmb,pysm_spinningdust, pysm_noise, pysm_freefree
from pysm import output, config2list, file_path, write_output_single
import healpy as hp
import numpy as np
import argparse

if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='Code to simulate galactic foregrounds.')
    parser.add_argument('config_file', help='Main configuration file.')

##Get the output directory and save the configuration file.
    Config = ConfigParser.ConfigParser()
    Config.read(parser.parse_args().config_file)
    out = output(Config._sections['GlobalParameters'])

    if not os.path.exists(out.output_dir): os.makedirs(out.output_dir)
    with open(out.output_dir+out.output_prefix+'main_config.ini','w') as configfile: Config.write(configfile)

    if out.debug == True:

##Print information about the run:
        print '----------------------------------------------------- \n'
        print ''.join("%s: %s \n" % item   for item in vars(out).items())
        print '-----------------------------------------------------'
        
    sky = np.zeros([3,len(out.output_frequency),hp.nside2npix(out.nside)])
    print '----------------------------------------------------- \n'
#Create synchrotron, dust, AME,  and cmb maps at output frequencies then add noise.
    if 'synchrotron' in out.components: