コード例 #1
0
ファイル: sphere_base.py プロジェクト: bbw7561135/rabacus
    def __init__( self ):


        # attach units
        #-----------------------------------------------
        self.U = units.Units()

        # check input 
        #-----------------------------------------------
        assert( self.Edges.size == self.T.size + 1 )
        assert( self.T.shape == self.nH.shape == self.nHe.shape )
        assert( self.T.shape == (self.T.size,) )

        assert( self.rec_meth == 'fixed' or 
                self.rec_meth == 'outward' or
                self.rec_meth == 'radial' or
                self.rec_meth == 'isotropic' )

        if self.find_Teq and self.z==None:
            msg = 'need to supply redshift if finding equilibrium temperature'
            raise ValueError(msg)


        # set units
        #-----------------------------------------------
        self.Edges.units = 'cm'
        self.T.units = 'K'
        self.nH.units = '1.0/cm^3'
        self.nHe.units = '1.0/cm^3'


        # format input
        #-----------------------------------------------
        self.format_for_fortran()
コード例 #2
0
ファイル: cooling.py プロジェクト: bbw7561135/rabacus
    def __init__(self, T, fcA_H2, fcA_He2, fcA_He3, 
                 H1h=None, He1h=None, He2h=None, 
                 fit_name='hg97', add_He2di=True):



        # create a list of valid rate names + temperature
        #--------------------------------------------------
        self._rate_names = ['H1h', 'He1h', 'He2h', 
                            'cicH1', 'cicHe1', 'cicHe2',
                            'cecH1', 'cecHe1', 'cecHe2',
                            'recH2', 'recHe2', 'recHe3', 
                            'recHe2di', 
                            'compton', 'bremss', 'T']

        # set optionals once
        # T, H1h, He1h, and He2h can be changed using set
        #----------------------------------------------
        self.fit_name = fit_name
        self.add_He2di = add_He2di
        self.u = units.Units()
        self.pc = physical.PhysicalConstants()

        # set source of rates
        #------------------------------------------
        if fit_name == 'hg97':
            self._rates = hui_gnedin_97.HuiGnedin97()
        elif fit_name == 'enzo13':
            self._rates = enzo_13.Enzo13()
        
        # set initial values
        #----------------------------------------------
        self.set( T, fcA_H2, fcA_He2, fcA_He3, 
                  H1h=H1h, He1h=He1h, He2h=He2h )
コード例 #3
0
    def __init__( self ):

        # create physical constants and units 
        #--------------------------------------------------------
        self.U = units.Units()
        self.PC = physical.PhysicalConstants()

        # read data
        #-----------------------------------------------------
        local = os.path.dirname(os.path.realpath(__file__))
        fname = local + '/photo.dat'        
        dat = np.loadtxt( fname, unpack=True )
        self._dat = dat
        
        # organize data
        #-----------------------------------------------------
        self.Z = dat[0]        
        self.N = dat[1]
        self.Eth = dat[2] * self.U.eV
        self.Emax = dat[3] * self.U.eV
        self.E0 = dat[4] * self.U.eV
        self.sigma0 = dat[5] * 1.0e-18 * self.U.cm**2
        self.ya = dat[6]
        self.P = dat[7]
        self.yw = dat[8]
        self.y0 = dat[9]
        self.y1 = dat[10]
コード例 #4
0
ファイル: slab_base.py プロジェクト: bbw7561135/rabacus
    def __init__(self):
        """ Initialization for all slab classes """

        # attach units
        #-----------------------------------------------
        self.U = units.Units()

        # check input
        #-----------------------------------------------
        assert (self.Edges.size == self.T.size + 1)
        assert (self.T.shape == self.nH.shape == self.nHe.shape)
        assert (self.T.shape == (self.T.size, ))

        assert (self.rec_meth == 'fixed' or self.rec_meth == 'ray')

        if self.find_Teq and self.z == None:
            msg = 'need to supply redshift if finding equilibrium temperature'
            raise utils.InputError(msg)

        # set units
        #-----------------------------------------------
        self.Edges.units = 'cm'
        self.T.units = 'K'
        self.nH.units = '1.0/cm^3'
        self.nHe.units = '1.0/cm^3'

        # format input
        #-----------------------------------------------
        self.format_for_fortran()
コード例 #5
0
    def __init__(self,
                 T,
                 fcA_H2,
                 fcA_He2,
                 fcA_He3,
                 H1i=None,
                 He1i=None,
                 He2i=None,
                 fit_name='hg97',
                 add_He2di=True,
                 use_badnell=False):

        # create a list of valid rate names + temperature
        #--------------------------------------------------
        self._rate_names = [
            'H1i', 'He1i', 'He2i', 'ciH1', 'ciHe1', 'ciHe2', 'reH2', 'reHe2',
            'reHe3', 'reHe2di', 'T'
        ]

        # set optionals once
        # T, fcA, H1i, He1i, and He2i can be changed using set
        #----------------------------------------------
        self.fit_name = fit_name
        self.add_He2di = add_He2di
        self.U = units.Units()
        self.use_badnell = use_badnell

        # set source of rates
        #------------------------------------------
        if fit_name == 'hg97':
            self._rates = hui_gnedin_97.HuiGnedin97()

        # set initial values
        #----------------------------------------------
        self.set(T, fcA_H2, fcA_He2, fcA_He3, H1i=H1i, He1i=He1i, He2i=He2i)
コード例 #6
0
    def __init__(self, Yp=0.248, fg=0.154, gamma=5.0 / 3.0):

        self.Yp = Yp
        self.fg = fg
        self.gamma = gamma

        self.U = units.Units()
        self.PC = physical.PhysicalConstants()
コード例 #7
0
    def __init__(self):

        self.pc = physical.PhysicalConstants()
        self.u = units.Units()

        self.T_H1 = 157807. * self.u.K
        self.T_He1 = 285335. * self.u.K
        self.T_He2 = 631515. * self.u.K
コード例 #8
0
ファイル: ion_solver.py プロジェクト: bbw7561135/rabacus
    def __init__(self, kchem):

        # attach units.
        #----------------------------------------------
        self.u = units.Units()

        # solve
        #---------------------------------------------
        self.set(kchem)
コード例 #9
0
    def __init__(self):
        """ Read and clean data. """

        # create physical constants and units
        #--------------------------------------------------------
        self.pc = physical.PhysicalConstants()
        self.u = units.Units()

        # read data
        #-----------------------------------------------------
        local = os.path.dirname(os.path.realpath(__file__))
        fname = local + '/sd93/zcool_sd93.dat'
        dat = np.loadtxt(fname)
        self._dat = dat
        self._logZ = np.array([-3.0, -2.0, -1.5, -1.0, -0.5, 0.0, 0.5])
        self._NZ = self._logZ.size

        # get temperatures
        #-----------------------------------------------------
        self._logT = dat[:, 0]
        self._T = 10**self._logT * self.u.K

        # get Lambda.  this is the raw data from the file
        # column 1 is temperature 2-9 are metallicity starting
        # with nil and then moving through the _logZ array above
        #-----------------------------------------------------
        lamu = self.u.cm**3 * self.u.erg / self.u.s
        self._logLambda = np.array(dat[:, 1:])
        self._Lambda = 10**self._logLambda * lamu

        # make copies of zero metallicity column
        #--------------------------------------------------------------
        Z0 = np.array([self._dat[:, 1] for i in range(self._NZ + 1)])
        Z0 = Z0.transpose()
        Zf = dat[:, 1:]

        # subtract the nill values from the finite metallicity values
        #--------------------------------------------------------------
        self._Z0 = Z0
        self._Zf = Zf
        self._Lambda_Zonly = 10**self._Zf - 10**self._Z0

        # set minimum value to make log safe and add units
        #--------------------------------------------------------------
        indx = np.where(self._Lambda_Zonly <= 0.0)
        self._Lambda_Zonly[indx] = 1.0e-50
        self._logLambda_Zonly = np.log10(self._Lambda_Zonly)
        self._Lambda_Zonly = self._Lambda_Zonly * lamu
コード例 #10
0
    def __init__(self, px_fit_type='verner'):

        # attach input
        #--------------------------------------------------------
        self.px_fit_type = px_fit_type

        # create physical constants and units
        #--------------------------------------------------------
        self.PC = physical.PhysicalConstants()
        self.U = units.Units()
        self.PX = photo_xsection.PhotoXsections(fit_type=px_fit_type)

        # Express in temperature units
        #--------------------------------------------------------
        self.T_H1 = self.PX.Eth_H1 / self.PC.kb
        self.T_H1.units = 'K'
コード例 #11
0
ファイル: nist_asd.py プロジェクト: bbw7561135/rabacus
    def __init__(self):
        """ Reads data file and stores energies. """

        # create physical constants and units
        #--------------------------------------------------------
        self.PC = physical.PhysicalConstants()
        self.U = units.Units()

        # set local directory
        #-----------------------------------------------------
        local = os.path.dirname(os.path.realpath(__file__))
        self._local = local

        # read and store ionization energies
        #-----------------------------------------------------
        IonizationEnergies = {}

        remove_syms = ["(", ")", "[", "]"]

        fname = local + '/ion_enrg.dat'
        self._fname = fname

        f = open(fname, 'r')

        for line in f.readlines():
            if not line.startswith('#'):
                words = line.split()
                Z = int(words[0])
                Esym = words[1]
                Irom = words[2]
                N = Z - int(words[3]) + 1
                Shells = words[4]
                Eraw = words[5]

                for sym in remove_syms:
                    Eraw = Eraw.replace(sym, "")
                Eraw = float(Eraw)

                #print Z, Esym, Irom, Ne, Shells, Eraw * self.U.Ry_inf

                IonizationEnergies[(Z, N)] = Eraw * self.U.Ry_inf

        f.close()

        self._IonizationEnergies = IonizationEnergies
コード例 #12
0
ファイル: hm12.py プロジェクト: bbw7561135/rabacus
    def __init__(self):

        # create physical constants and units
        #--------------------------------------------------------
        self.pc = physical.PhysicalConstants()
        self.u = units.Units()

        # read data
        #-----------------------------------------------------
        local = os.path.dirname(os.path.realpath(__file__))
        fname = local + '/hm12_dat/UVB.out'
        with open(fname, 'r') as f:
            dum = f.readlines()
        dum = dum[20].split()
        self.z = np.array([float(i) for i in dum])

        dat = np.loadtxt(fname, skiprows=21)
        self._dat = dat

        Iunit = self.u.erg / (self.u.s * self.u.cm**2 * self.u.Hz * self.u.sr)
        self.Inu = dat[:, 1:] * Iunit

        Inu_mag = self.Inu.magnitude
        isfinite = Inu_mag > 0
        Imin = Inu_mag[isfinite].min()

        self.logInu = Inu_mag.copy()
        self.logInu[isfinite] = np.log10(Inu_mag[isfinite])
        self.logInu[~isfinite] = np.log10(Imin)

        self.lam = dat[:, 0] * self.u.angstrom
        self.nu = self.pc.c / self.lam
        self.E = self.nu * self.pc.h

        self.lam.units = 'cm'
        self.nu.units = 'Hz'
        self.E.units = 'eV'
コード例 #13
0
ファイル: hm12.py プロジェクト: bbw7561135/rabacus
    def __init__(self):

        # create physical constants and units
        #--------------------------------------------------------
        self.pc = physical.PhysicalConstants()
        self.u = units.Units()

        # read data
        #-----------------------------------------------------
        local = os.path.dirname(os.path.realpath(__file__))
        fname = local + '/hm12_dat/photorates.out'
        dat = np.loadtxt(fname)
        self._dat = dat

        # organize data
        #-----------------------------------------------------
        self._z = dat[:, 0]
        self._H1i = dat[:, 1]  # H1 photoionization
        self._H1h = dat[:, 2]  # H1 photoheating
        self._He1i = dat[:, 3]  # He1 photoionization
        self._He1h = dat[:, 4]  # He1 photoheating
        self._He2i = dat[:, 5]  # He2 photoionization
        self._He2h = dat[:, 6]  # He2 photoheating
        self._comptonh = dat[:, 7]  # compton heating

        # create interpolating functions
        #-----------------------------------------------------
        self.z = self._z.copy()
        self.l1pz = np.log10(1.0 + self.z)
        self._H1i_fit = interp1d(self.l1pz, np.log10(self._H1i))
        self._H1h_fit = interp1d(self.l1pz, np.log10(self._H1h))
        self._He1i_fit = interp1d(self.l1pz, np.log10(self._He1i))
        self._He1h_fit = interp1d(self.l1pz, np.log10(self._He1h))
        self._He2i_fit = interp1d(self.l1pz, np.log10(self._He2i))
        self._He2h_fit = interp1d(self.l1pz, np.log10(self._He2h))
        self._comptonh_fit = interp1d(self.l1pz, np.log10(self._comptonh))
コード例 #14
0
    def __init__(
        self,
        Edges,
        T,
        nH,
        nHe,
        rad_src,
        #
        rec_meth="fixed",
        fixed_fcA=1.0,
        atomic_fit_name="hg97",
        find_Teq=False,
        z=None,
        verbose=False,
        tol=1.0e-10,
        thin=False,
    ):

        # attach units
        #-----------------------------------------------
        self.U = units.Units()

        # check input
        #-----------------------------------------------
        assert (Edges.size == T.size + 1)
        assert (T.shape == nH.shape == nHe.shape)
        assert (T.shape == (T.size, ))

        assert (rec_meth == 'fixed')

        if find_Teq and z == None:
            msg = 'need to supply redshift if finding equilibrium temperature'
            raise utils.InputError(msg)

        if rad_src.source_type != 'point':
            msg = 'source type needs to be point'
            raise utils.InputError(msg)

        # set units
        #-----------------------------------------------
        Edges.units = 'cm'
        T.units = 'K'
        nH.units = '1.0/cm^3'
        nHe.units = '1.0/cm^3'

        # attach input
        #-----------------------------------------------
        self.Edges = Edges.copy()
        self.T = T.copy()
        self.nH = nH.copy()
        self.nHe = nHe.copy()
        self.rad_src = rad_src
        self.rec_meth = rec_meth

        if self.rec_meth == 'fixed':
            self.fixed_fcA = fixed_fcA

        self.atomic_fit_name = atomic_fit_name
        self.find_Teq = find_Teq
        self.verbose = verbose
        self.tol = tol
        self.thin = thin

        if find_Teq:
            self.z = z

        # initialize sphere
        #-----------------------------------------------
        self.init_sphere()
        self.set_optically_thin()

        if self.thin:
            return

        # solve sphere (sweep until convergence)
        #-----------------------------------------------------------
        conv_old = np.sum(self.ne)
        not_converged = True
        self.itr = 0

        while not_converged:
            self.sweep_sphere()
            conv_new = np.sum(self.ne)
            if np.abs(conv_new / conv_old - 1.0) < self.tol:
                not_converged = False
            conv_old = conv_new
            self.itr += 1

        # finalize slab
        #-----------------------------------------------------------
        self.finalize_sphere()
コード例 #15
0
ファイル: ion_solver.py プロジェクト: bbw7561135/rabacus
    def __init__(self, nH, nHe, kchem, kcool, z, Hz=None, tol=1.0e-8):

        # attach keywords
        #----------------------------------------------
        if Hz == None:
            Hz = 0.0
        else:
            if not hasattr(Hz, 'units'):
                raise ValueError, '\n Hz must have units \n'
            else:
                Hz.units = '1/s'

        self.Hz = Hz
        self.tol = tol

        # attach units.
        #----------------------------------------------
        self.u = units.Units()

        # assert 1-D input
        #----------------------------------------------
        if len(nH.shape) != 1:
            msg = "input arrays must be 1-D for fortran routines."
            raise ValueError(msg)

        if len(nHe.shape) != 1:
            msg = "input arrays must be 1-D for fortran routines."
            raise ValueError(msg)

        if not hasattr(nH, 'units'):
            msg = '\n Input variable nH must have units \n'
            raise ValueError(msg)
        else:
            nH.units = 'cm**-3'

        if not hasattr(nHe, 'units'):
            msg = '\n Input variable nHe must have units \n'
            raise ValueError(msg)
        else:
            nHe.units = 'cm**-3'

        if len(kchem.T.shape) != 1:
            msg = "input arrays must be 1-D for fortran routines."
            raise ValueError(msg)

        if len(kcool.T.shape) != 1:
            msg = "input arrays must be 1-D for fortran routines."
            raise ValueError(msg)

        # set fortran variables
        #-----------------------------------------------
        if kchem.fit_name == 'hg97':
            irate = 1

        # choose scalar or vector routines
        #----------------------------------------------
        nn = nH.size

        if nn == 1:
            solve = rabacus_fc.ion_solver.solve_pcte_s
        else:
            solve = rabacus_fc.ion_solver.solve_pcte_v

        (xH1, xH2, xHe1, xHe2, xHe3,
         T) = solve(nH, nHe, kchem.H1i, kchem.He1i, kchem.He2i, kcool.H1h,
                    kcool.He1h, kcool.He2h, z, self.Hz, kchem.fcA_H2,
                    kchem.fcA_He2, kchem.fcA_He3, irate, tol, nn)

        # package output
        #----------------------------------------------
        self.H1 = np.ones(nn) * xH1 * self.u.dimensionless
        self.H2 = np.ones(nn) * xH2 * self.u.dimensionless
        self.He1 = np.ones(nn) * xHe1 * self.u.dimensionless
        self.He2 = np.ones(nn) * xHe2 * self.u.dimensionless
        self.He3 = np.ones(nn) * xHe3 * self.u.dimensionless
        self.Teq = T * self.u.K

        self.nH = nH
        self.nHe = nHe

        # get chem and cooling rates at Teq
        #----------------------------------------------
        kchem_out = chemistry.ChemistryRates(self.Teq,
                                             kchem.fcA_H2,
                                             kchem.fcA_He2,
                                             kchem.fcA_He3,
                                             H1i=kchem.H1i,
                                             He1i=kchem.He1i,
                                             He2i=kchem.He2i,
                                             fit_name=kchem.fit_name,
                                             add_He2di=kchem.add_He2di)

        kcool_out = cooling.CoolingRates(self.Teq,
                                         kcool.fcA_H2,
                                         kcool.fcA_He2,
                                         kcool.fcA_He3,
                                         H1h=kcool.H1h,
                                         He1h=kcool.He1h,
                                         He2h=kcool.He2h,
                                         fit_name=kcool.fit_name,
                                         add_He2di=kcool.add_He2di)

        self.kchem = kchem_out
        self.kcool = kcool_out
コード例 #16
0
ファイル: badnell_06.py プロジェクト: bbw7561135/rabacus
    def __init__(self): 

        self.pc = physical.PhysicalConstants()
        self.u = units.Units()
コード例 #17
0
ファイル: calc_slab_2.py プロジェクト: bbw7561135/rabacus
    def __init__(
            self,
            Edges,
            T,
            nH,
            nHe,
            rad_src,
            #
            rec_meth="fixed",
            fixed_fcA=1.0,
            thresh_P_A=0.01,
            thresh_P_B=0.99,
            thresh_xmfp=3.0e1,
            atomic_fit_name="hg97",
            find_Teq=False,
            z=None,
            verbose=False,
            tol=1.0e-10,
            thin=False):

        # attach units
        #-----------------------------------------------
        self.U = units.Units()

        # check input
        #-----------------------------------------------
        assert (Edges.size == T.size + 1)
        assert (T.shape == nH.shape == nHe.shape)
        assert (T.shape == (T.size, ))

        assert (rec_meth == 'fixed' or rec_meth == 'thresh')

        if find_Teq and z == None:
            msg = 'need to supply redshift if finding equilibrium temperature'
            raise utils.InputError(msg)

        if rad_src.source_type != 'plane':
            msg = 'source type needs to be plane'
            raise utils.InputError(msg)

        if nH.size % 2 != 0:
            msg = 'the number of layers must be even'
            raise utils.InputError(msg)

        # set units
        #-----------------------------------------------
        Edges.units = 'cm'
        T.units = 'K'
        nH.units = '1.0/cm^3'
        nHe.units = '1.0/cm^3'

        # attach input
        #-----------------------------------------------
        self.Edges = Edges.copy()
        self.T = T.copy()
        self.nH = nH.copy()
        self.nHe = nHe.copy()
        self.rad_src = rad_src
        self.rec_meth = rec_meth

        if self.rec_meth == 'fixed':
            self.fixed_fcA = fixed_fcA

        elif self.rec_meth == 'thresh':
            assert thresh_xmfp > 0.0
            assert thresh_P_B > thresh_P_A
            self.thresh_xmfp = thresh_xmfp
            self.thresh_P_A = thresh_P_A
            self.thresh_P_B = thresh_P_B
            self.thresh_dPAB = thresh_P_B - thresh_P_A
            self.thresh_tau_A = -np.log(1.0 - thresh_P_A)
            self.thresh_tau_B = -np.log(1.0 - thresh_P_B)

        self.atomic_fit_name = atomic_fit_name
        self.find_Teq = find_Teq
        self.verbose = verbose
        self.tol = tol
        self.thin = thin

        if find_Teq:
            self.z = z

        # initialize slab
        #-----------------------------------------------
        self.init_slab()
        self.set_optically_thin()

        if self.thin:
            return

        # solve slab, sweep through layers until convergence
        #-----------------------------------------------------------
        conv_old = np.sum(self.ne)
        not_converged = True
        self.itr = 0

        while not_converged:
            self.sweep_slab()
            conv_new = np.sum(self.ne)
            if np.abs(conv_new / conv_old - 1.0) < self.tol:
                not_converged = False
            conv_old = conv_new
            self.itr += 1

        # finalize slab
        #-----------------------------------------------------------
        self.finalize_slab()
コード例 #18
0
ファイル: ion_solver.py プロジェクト: bbw7561135/rabacus
    def __init__(self, nH, nHe, kchem, tol=1.0e-8):

        # attach units.
        #----------------------------------------------
        self.u = units.Units()

        # check input
        #----------------------------------------------
        if nH.shape == ():
            nH = np.ones(1) * nH

        if nHe.shape == ():
            nHe = np.ones(1) * nHe

        if not len(nH.shape) == len(nHe.shape) == len(kchem.T.shape) == 1:
            msg = '\n Input arrays must be one dimensional'
            raise ValueError(msg)

        if not hasattr(nH, 'units'):
            msg = '\n Input variable nH must have units \n'
            raise ValueError(msg)
        else:
            nH.units = 'cm**-3'

        if not hasattr(nHe, 'units'):
            msg = '\n Input variable nHe must have units \n'
            raise ValueError(msg)
        else:
            nHe.units = 'cm**-3'

        if nH.shape != nHe.shape:
            msg = '\n nH and nHe must have the same shape \n'
            raise ValueError(msg)

        # choose scalar or vector routines
        #----------------------------------------------
        nn = nH.size

        if nn == 1:
            solve = rabacus_fc.ion_solver.solve_pce_s
        else:
            solve = rabacus_fc.ion_solver.solve_pce_v

        (xH1, xH2, xHe1, xHe2,
         xHe3) = solve(nH, nHe, kchem.reH2, kchem.reHe2, kchem.reHe3,
                       kchem.ciH1, kchem.ciHe1, kchem.ciHe2, kchem.H1i,
                       kchem.He1i, kchem.He2i, tol, nn)

        # package output
        #----------------------------------------------
        self.H1 = np.ones(nn) * xH1 * self.u.dimensionless
        self.H2 = np.ones(nn) * xH2 * self.u.dimensionless
        self.He1 = np.ones(nn) * xHe1 * self.u.dimensionless
        self.He2 = np.ones(nn) * xHe2 * self.u.dimensionless
        self.He3 = np.ones(nn) * xHe3 * self.u.dimensionless
        self.T = kchem.T

        self.nH = nH
        self.nHe = nHe

        self.kchem = kchem
コード例 #19
0
ファイル: background.py プロジェクト: bbw7561135/rabacus
    def __init__(self, rad_src):

        self.PC = physical.PhysicalConstants()
        self.U = units.Units()

        # dont need to integrate for monochromatic spectra
        #-----------------------------------------------------------------
        if rad_src.monochromatic:

            four_pi_sr = 4 * np.pi * self.U.sr

            self.Fu = four_pi_sr * rad_src.Inu
            self.u = self.Fu / self.PC.c
            self.Fn = self.Fu / rad_src.E
            self.n = self.Fn / self.PC.c

            self.H1i = self.Fn * rad_src.sigma.H1
            self.H1h = self.H1i * (rad_src.E - rad_src.th.E_H1)
            self.He1i = self.Fn * rad_src.sigma.He1
            self.He1h = self.He1i * (rad_src.E - rad_src.th.E_He1)
            self.He2i = self.Fn * rad_src.sigma.He2
            self.He2h = self.He2i * (rad_src.E - rad_src.th.E_He2)

        # integrate for polychromatic spectra
        #-----------------------------------------------------------------
        else:

            self.Fu = utils.trap(rad_src.E, rad_src._dFu_over_dE)
            self.u = utils.trap(rad_src.E, rad_src._du_over_dE)
            self.Fn = utils.trap(rad_src.E, rad_src._dFn_over_dE)
            self.n = utils.trap(rad_src.E, rad_src._dn_over_dE)

            self.H1i = utils.trap(rad_src.E, rad_src._dH1i_over_dE)
            self.H1h = utils.trap(rad_src.E, rad_src._dH1h_over_dE)
            self.He1i = utils.trap(rad_src.E, rad_src._dHe1i_over_dE)
            self.He1h = utils.trap(rad_src.E, rad_src._dHe1h_over_dE)
            self.He2i = utils.trap(rad_src.E, rad_src._dHe2i_over_dE)
            self.He2h = utils.trap(rad_src.E, rad_src._dHe2h_over_dE)

        # set units and docstrings
        #-----------------------------------------------------------------
        self.Fu.units = 'erg/s/cm^2'
        self.Fu.__doc__ = 'optically thin energy flux'

        self.u.units = 'erg/cm^3'
        self.u.__doc__ = 'optically thin energy density'

        self.Fn.units = '1/s/cm^2'
        self.Fn.__doc__ = 'optically thin photon number flux'

        self.n.units = '1/cm^3'
        self.n.__doc__ = 'optically thin photon number density'

        self.H1i.units = '1/s'
        self.H1i.__doc__ = 'optically thin H1 photoionization rate'

        self.H1h.units = 'erg/s'
        self.H1h.__doc__ = 'optically thin H1 photoheating rate'

        self.He1i.units = '1/s'
        self.He1i.__doc__ = 'optically thin He1 photoionization rate'

        self.He1h.units = 'erg/s'
        self.He1h.__doc__ = 'optically thin He1 photoheating rate'

        self.He2i.units = '1/s'
        self.He2i.__doc__ = 'optically thin He2 photoionization rate'

        self.He2h.units = 'erg/s'
        self.He2h.__doc__ = 'optically thin He2 photoheating rate'
コード例 #20
0
    def initialize(self, q_min, q_max, spectrum_type, Nnu, segmented,
                   px_fit_type, verbose, z, T_eff, alpha, user_E, user_shape):
        """ Perform general initialization.

        Args: 

          `q_min` (float): minimum photon energy / Rydbergs [dimensionless]

          `q_max` (float): maximum photon energy / Rydbergs [dimensionless]

          `spectrum_type` (str): the spectral shape 
          {``monochromatic``, ``hm12``, ``thermal``, ``powerlaw``, ``user``}   

          `Nnu` (int): number of spectral samples, log spaced in energy

          `segmented` (bool): if ``True``, forces spectral samples at H and He 
          ionization thresholds

          `px_fit_type` (str): source to use for photoionization cross section 
          fits {``verner``}
       
          `verbose` (bool): verbose screen output?

          `z` (float): redshift, need if `spectrum_type` = ``hm12``

          `T_eff` (float): effective temperature, need if `spectrum_type` = 
          ``thermal``

          `alpha` (float): powerlaw index, need if `spectrum_type` = 
          ``powerlaw``

          `user_E` (array): energy samples for user defined spectrum. should
          have units of energy. 

          `user_shape` (array): shape of user defined spectrum. should be 
          dimensionless

        """

        # attach standard input
        #--------------------------------------------------------
        self.q_min = q_min
        self.q_max = q_max
        self.spectrum_type = spectrum_type

        self.Nnu = Nnu
        self.segmented = segmented
        self.px_fit_type = px_fit_type
        self.verbose = verbose

        # attach spectrum specific input
        #-------------------------------------------
        if spectrum_type == 'hm12':
            self.z = z
        elif spectrum_type == 'thermal':
            self.T_eff = T_eff
        elif spectrum_type == 'powerlaw':
            self.alpha = alpha
        elif spectrum_type == 'user':
            self.user_E = user_E
            self.user_shape = user_shape
            self.segmented = False

        if spectrum_type == 'monochromatic':
            self.monochromatic = True
            self.Nnu = 1
            self.segmented = False
        else:
            self.monochromatic = False

        self.validate_spectrum_type()

        # attach physical constants and units
        #--------------------------------------------------------
        self.U = units.Units()
        self.PC = physical.PhysicalConstants()
        self.PX = photo_xsection.PhotoXsections(fit_type=px_fit_type)

        # attach hydrogen and helium atom classes
        #--------------------------------------------------------
        self.H = hydrogen.Hydrogen(px_fit_type=self.px_fit_type)
        self.He = helium.Helium(px_fit_type=self.px_fit_type)

        # set quantities related to photo-ionization thresholds
        #--------------------------------------------------------
        self.th = PhotoIonizationThresholds(self)

        # special behaviour for user defined spectra
        #-------------------------------------------
        if spectrum_type == 'user':

            self.E = user_E
            self.E.units = 'eV'
            self.E.__doc__ = 'energy samples'

            self.q_min = self.E.min() / self.PX.Eth_H1
            self.q_max = self.E.max() / self.PX.Eth_H1
            self.Nnu = self.E.size

            self.q = self.E / self.PX.Eth_H1
            self.q.__doc__ = 'energy samples / Rydbergs'

            self.nu = self.E / self.PC.h
            self.nu.units = 'Hz'
            self.nu.__doc__ = 'frequency samples'

            self.lam = self.PC.c / self.nu
            self.lam.units = 'cm'
            self.lam.__doc__ = 'wavelength samples'

        # set photon energy arrays
        #--------------------------------------------------------
        else:

            self.set_photon_arrays(self.q_min, self.q_max, self.Nnu,
                                   self.segmented)

        # set X-sections
        #--------------------------------------------------------
        self.sigma = PhotoIonizationCrossSections(self)

        # store log10 quantities
        #--------------------------------------------------------
        self.log = LogQuantities(self)