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]
def __init__ ( self, rad_src ): self.PC = physical.PhysicalConstants() self.rad_src = rad_src # dont need to integrate for monochromatic spectra #----------------------------------------------------------------- if rad_src.monochromatic: self.Lu = rad_src.Lu self.Ln = self.Lu / rad_src.E # integrate for polychromatic spectra #----------------------------------------------------------------- else: self.Lu = utils.trap( rad_src.E, rad_src._dLu_over_dE ) self.Ln = utils.trap( rad_src.E, rad_src._dLn_over_dE ) # set units and docstrings #----------------------------------------------------------------- self.Lu.units = 'erg/s' self.Lu.__doc__ = 'optically thin energy luminosity' self.Ln.units = '1/s' self.Ln.__doc__ = 'optically thin photon luminosity'
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 )
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
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()
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
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'
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
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'
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))
def __init__(self, rad_src): self.PC = physical.PhysicalConstants() # dont need to integrate for monochromatic spectra #----------------------------------------------------------------- if rad_src.monochromatic: self.Fu = rad_src.Fu 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'
def __init__(self, cpdict, verbose=False, zlo=0.0, zhi=200.0, Nz=500): # check input dictionary #-------------------------------------------------------- need_keys = ['omegam', 'omegal', 'omegab', 'h', 'sigma8', 'ns', 'Yp'] for key in need_keys: if not cpdict.has_key(key): raise InitError, ' key missing from cpdict \n' # transfer input parametrs #-------------------------------------------------------- self.OmegaM = cpdict['omegam'] self.OmegaL = cpdict['omegal'] self.OmegaB = cpdict['omegab'] self.h = cpdict['h'] self.sigma8 = cpdict['sigma8'] self.ns = cpdict['ns'] self.Yp = cpdict['Yp'] self.OmegaC = self.OmegaM - self.OmegaB if cpdict.has_key('omegar'): self.OmegaR = cpdict['omegar'] else: # if not provided we use OmegaM and zeq from Planck13 # column one of table 2 in http://arxiv.org/abs/1303.5076 # OmegaR = OmegaM / (1+zeq), OmegaM=0.3175, zeq = 3402 self.OmegaR = 0.3175 / (1.0 + 3402.) self.cpdict = cpdict # make sure flat universe is specified #-------------------------------------------------------- err = (self.OmegaR + self.OmegaM + self.OmegaL) - 1.0 if err > 1.0e-3: raise InitError, ' OmegaR + OmegaM + OmegaL must be 1.0 \n' + \ ' OmegaR: ' + str(self.OmegaR) + '\n' + \ ' OmegaM: ' + str(self.OmegaM) + '\n' + \ ' OmegaL: ' + str(self.OmegaL) + '\n' + \ ' sum: ' + str(self.OmegaR + self.OmegaM + self.OmegaL) + '\n' # create physical constants and cosmological units #-------------------------------------------------------- self.pc = physical.PhysicalConstants() self.cu = units.CosmoUnits(self.h, a=1.0) # derive constants #-------------------------------------------------------- # Hubble parameter now self.H0 = 1.0e2 * self.cu.h * self.cu.km / self.cu.s / self.cu.Mpc self.H0.units = self.cu.km / self.cu.s / (self.cu.Mpc / self.cu.h) # Hubble time now self.tH0 = 1.0 / self.H0 self.tH0.units = self.cu.Myr / self.cu.h # Hubble distance now self.dH0 = self.pc.c / self.H0 self.dH0.units = self.cu.Mpc / self.cu.h # Critical mass density now self.rho_crit0 = (3.0 * self.H0**2) / (8.0 * np.pi * self.pc.G) self.rho_crit0.units = (self.cu.Msun/self.cu.h) / \ (self.cu.Mpc/self.cu.h)**3 # Critical energy density now self.eps_crit0 = self.rho_crit0 * self.pc.c**2 self.eps_crit0.units = self.cu.erg / self.cu.cm**3 # Critical hydrogen number density now H_rho = self.rho_crit0 * self.OmegaB * (1.0 - self.Yp) self.nH_crit0 = H_rho / (self.pc.m_p + self.pc.m_e) self.nH_crit0.units = self.cu.cm**(-3) # normalize the growth functions such that ... # D1a(a=1) = 1.0 # D1z(z=0) = 1.0 #--------------------------------------------------------- self._D1a_Norm = 1.0 / quad(self._D1a_integrand, 0.0, 1.0)[0] self._D1z_Norm = 1.0 / quad(self._D1z_integrand, 0.0, np.inf)[0] # make interpolating functions for .... # redshift and comoving distance, # redshift and lookback time # for redshift we use log(1+z) #-------------------------------------------------------- # first tabulate values with respect to log(1+z) # then create interpolating functions self._lopz = np.linspace(np.log10(1 + zlo), np.log10(1 + zhi), Nz) self._z = 10**self._lopz - 1 self._a = 1.0 / (1.0 + self._z) self._Dc = self.Dcz(self._z) self._Dc.units = 'Mpc/hh' self._Dc2lopz = interp1d(self._Dc.magnitude, self._lopz) self._tL = self.tLz(self._z) self._tL.units = 'Myr/hh' self._tL2lopz = interp1d(self._tL.magnitude, self._lopz)
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)
def __init__(self): self.pc = physical.PhysicalConstants() self.u = units.Units()