示例#1
0
 def _setsynch(self):
     synch.setspectrum(self.gmin, self.gmax, self.injection)
     if self.spectrum == 'powerlaw':
         synch.setpow()
     elif self.spectrum == 'broken':
         synch.setbreak(self.gbreak, self.dpow)
     elif self.spectrum == 'aged':
         synch.setage(self.age, self.ageb)
     else:
         raise NotImplementedError('spectrum ' + spectrum)
示例#2
0
    def findcorrection(self,freqs,z=None,do_adiabatic=None,timerange=None):
        '''
        Find corrections to the simple synchrotron formula.
        Parameters:
        freqs        -- a list of frequencies at which the correction should be calculated
        z            -- the redshift. If undefined defaults to the value already chosen
        do_adiabatic -- boolean specifying whether adiabatic corrections should be done
        timerange    -- a list of the _indices_ of the time values to find the correction for. If unset, do all of them.
        Updated attributes:
        freqs        -- the frequencies at which corrections were found
        corrs        -- the correction factors per frequency (times, freqs)
        corr_synch   -- the corrected synchrotron luminosity density (W/Hz)
        '''

        try:
            self.synch
        except AttributeError:
            print('Warning: findsynch not previously run, running it now')
            self.findsynch(nu=freqs[0])

        if z is None:
            z=self.z
        else:
            self.z=z
            print('findcorrection over-riding previously set z to %f' % z)

        # adapted from agecorrection.py code
        if timerange is None:
            timerange=range(len(self.tv))
        synch.setspectrum(self.gmin,self.gmax,self.q)
        if do_adiabatic is not None:
            print('Over-riding do_adiabatic setting to',do_adiabatic)
            self.do_adiabatic=do_adiabatic
        self.freqs=freqs

        bcmb=findbcmb(z)
        if self.verbose:
            print('CMB energy density in B-field terms is %g T' % bcmb)

        corrs=np.ones((len(self.tv),len(freqs)))*np.nan
        if self.verbose:
            print('Finding correction factors:')
        for i in timerange:
            if self.verbose: print(self.tv[i])
            corrs[i]=(agecorr_findcorrection(i,freqs,self.tv/Myr,self.B,bcmb,volumes=self.vl,verbose=False,do_adiabatic=self.do_adiabatic,tstop=self.tstop/Myr))
        self.corrs=corrs
        cs=np.zeros_like(corrs)
        for i,f in enumerate(self.freqs):
            cs[:,i]=(self.synch*self.corrs[:,i]*(f/self.nu_ref)**-self.alpha)
        self.corr_synch=cs
示例#3
0
    def findlosscorrection(self,z=None,do_adiabatic=None,timerange=None):
        '''
        Find corrections to the simple synchrotron loss formula.
        Parameters:
        z            -- the redshift. If undefined defaults to the value already chosen
        do_adiabatic -- boolean specifying whether adiabatic corrections should be done
        timerange    -- a list of the _indices_ of the time values to find the correction for. If unset, do all of them.
        Updated attributes:
        losscorrs    -- the correction factors per frequency (times, freqs)
        '''

        try:
            self.loss
        except AttributeError:
            print('Warning: finds_loss not previously run, running it now')
            self.finds_loss()

        if z is None:
            z=self.z
        else:
            self.z=z
            print('findcorrection over-riding previously set z to %f' % z)

        # adapted from agecorrection.py code
        if timerange is None:
            timerange=range(len(self.tv))
        synch.setspectrum(self.gmin,self.gmax,self.q)
        if do_adiabatic is not None:
            print('Over-riding do_adiabatic setting to',do_adiabatic)
            self.do_adiabatic=do_adiabatic

        bcmb=findbcmb(z)
        if self.verbose:
            print('CMB energy density in B-field terms is %g T' % bcmb)

        corrs=np.ones_like(self.tv)*np.nan
        if self.verbose:
            print('Finding correction factors:')
        for i in timerange:
            if self.verbose: print(self.tv[i])
            corrs[i]=(loss_findcorrection(i,self.tv/Myr,self.B,bcmb,volumes=self.vl,verbose=False,do_adiabatic=self.do_adiabatic,tstop=self.tstop/Myr))
        self.losscorrs=corrs
示例#4
0
    def findic(self,nu,z=None):
        '''
        Compute inverse-Compton emission
        Parameters:
        nu -- a reference frequency (Hz)
        z  -- the redshift (if unset, use default set on initialization)
        Updated attributes:
        nu_ic_ref -- the reference frequency
        ic        -- the uncorrected inverse-Compton luminosity (W/Hz)
        '''
        if z is None:
            z=self.z
        else:
            self.z=z
            print('findic over-riding previously set z to %f' % z)
        self.nu_ic_ref=nu
        self._init_synch()
        
        times=np.where(self.tv<self.tstop,self.tv,self.tstop)

        self.ic=(self.xi*self.Q*times)/((1+self.zeta+self.kappa)*self.I)
        synch.setspectrum(self.gmin,self.gmax,self.q)
        self.ic*=synch.cmb_ic_emiss(1,nu,z)
示例#5
0
#!/usr/bin/python

from builtins import range
import synch
import numpy as np
import matplotlib.pyplot as plt

values = 80
b = 0.6e-9

synch.setspectrum(100, 1e6, 2.1)

freq = np.logspace(3, 11, values)
emiss = np.zeros(values)
plt.xscale('log')
plt.yscale('log')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Emissivity')

for j in range(0, 11):

    age = 4 * j
    synch.setage(age * 1e6 * 365 * 86400, b)

    for i in range(0, values):
        emiss[i] = synch.emiss(1.0, b, freq[i])
        # print '%g %g' % (freq[i],emiss[i])

    plt.plot(freq, emiss, label=('Age %g Myr' % age))

plt.legend(loc=0)