def dn_dr(snr, channel_width, z, params, singlesnr=False): ''' number of absorbers per comoving LoS distance interval where fractional flux difference is larger than snr times the noise level. Args: snr, signal to noise ratio z, redshift params, dictionary of model parameters Returns: comoving number density of absorbers per line-of-sight interval (h/Mpc) ''' if not singlesnr: splkey = ('dn_dr', channel_width, z) + dict2tuple(params) if not SPLINE_DICT.has_key(splkey): snrvals = np.logspace(SNR_INTERP_MIN, SNR_INTERP_MAX, N_INTERP_SNR) dndrvals = np.zeros_like(snrvals) for snrnum, snrval in enumerate(snrvals): g = lambda x: massfunc(10.**x,z)\ *sigma_tau(tau_limit(snrval,10.**x,z,channel_width,params), 10.**x,z,params) dndrvals[snrnum] = integrate.quad(g, M_INTERP_MIN, M_INTERP_MAX)[0] SPLINE_DICT[splkey] = interp.interp1d(np.log(snrvals), dndrvals) sf = 1. if type(snr) == np.ndarray: snr[snr < 10.**SNR_INTERP_MIN] = SNR_INTERP_MIN snr[snr >= 10.**SNR_INTERP_MAX] = 10.**SNR_INTERP_MAX output = SPLINE_DICT[splkey](np.log(snr)) output[snr < 10.**SNR_INTERP_MIN] = 0. else: if snr < 10.**SNR_INTERP_MIN: snr = 10.**SNR_INTERP_MIN sf = 0. elif snr >= 10.**SNR_INTERP_MAX: sf = 1. snr = 10.**SNR_INTERP_MAX output = SPLINE_DICT[splkey](np.log(snr)) return sf * output else: g = lambda x: massfunc(10.**x,z)\ *sigma_tau(tau_limit(snr,10.**x,z,channel_width,params), 10.**x,z,params) return integrate.quad(g, M_INTERP_MIN, M_INTERP_MAX)[0]
def g(x, bp=1.): rv = hi_helpers.rVir(10.**x, zval) rs=rv/HI_HELPERS['CSHIFUNC'](10.**x,zval,params)\ *(1.+zval)/1e3 rt = params['RT'] * (1. + zval) / 1e3 rht = rs * rt / (rs + rt) volratio = hi_helpers.expvol(rv, rht) / hi_helpers.expvol( rv, rs) return HI_HELPERS['MHIFUNC'](10.**x,zvals,params)\ /TS_HELPERS['TSFUNC'](10.**x,zvals,params)*volratio\ *massfunc(10.**x,zval)*bias(10.**x,zval)**bp
def tau_variance(z, channel_width, params): ''' \int dm dtau dsigma/dtau(tau,m,z) tau^2 Args: z, redshift channel_width, width of channels used to measure lines. Returns: d \sum \tau^2/d r_comoving (h/Mpc) ''' g = lambda x: massfunc(10.**x, z) * d_tau_variance_dm(10.**x, z, params) return integrate.quad(g, M_INTERP_MIN, M_INTERP_MAX)
def g(x): rv = hi_helpers.rVir(10.**x, zval) rs=rv/HI_HELPERS[params['CSHIFUNC']](10.**x,zval,params)\ *(1.+zval)/1e3 rt = params['RT'] * (1. + zval) / 1e3 rht = rs * rt / (rs + rt) volratio = hi_helpers.exp_vol(rv, rht) / hi_helpers.exp_vol( rv, rs) return massfunc(10.**x,zval)\ *(HI_HELPERS[params['MHIFUNC']](10.**x,zval,params)-(1.+zval)\ *volratio*(TCMB+rb.tb_agn_fast(zval)+rb.tb_sfg_fast(zval)\ +acoeff*rb.tb_arc_const(F21/(1.+zval),params))\ /TS_MODELS[params['TS0_FUNC']](10.**x,zval,params))
def rho_hi(z21, params): ''' comoving density of HI in Msolar*h^3/Mpc^3 Args: z21, float, redshift params, dictionary of parameters Returns: comoving density of HI in Msolar*h^3/Mpc^3 ''' splkey = ('rho', 'hi') + dict2tuple(params) if not SPLINE_DICT.has_key(splkey): zvals = np.linspace(0, MAXZ, NINTERP_Z) rhovals = np.zeros_like(zvals) for znum, zval in enumerate(zvals): g=lambda x: HI_HELPERS[params['MHIFUNC']](10.**x,zval,params)\ *massfunc(10.**x,zval) rhovals[znum] = integrate.quad(g, M_INTERP_MIN, M_INTERP_MAX)[0] SPLINE_DICT[splkey] = interp.interp1d(zvals, np.log(rhovals)) return np.exp(SPLINE_DICT[splkey](z21))
def bias_hi(z21, params): ''' bias of HI Args: z21, float, redshift params, dictionary of parameters. Returns: bias of HI (unitless) ''' splkey = ('bias', 'hi') + dict2tuple(params) if not SPLINE_DICT.has_key(splkey): zvals = np.linspace(0, MAXZ, NINTERP_Z) biasvals = np.zeros_like(zvals) for znum, zval in enumerate(zvals): g=lambda x:HI_HELPERS[params['MHIFUNC']](10.**x,zval,params)\ *massfunc(10.**x,zval)*bias(10.**x,zval) biasvals[znum]=integrate.quad(g,M_INTERP_MIN,M_INTERP_MAX)[0]\ /rho_hi(zval,params) SPLINE_DICT[splkey] = interp.interp1d(zvals, np.log(biasvals)) return np.exp(SPLINE_DICT[splkey](z21))
def dn_dz_tau(tau, z, params): ''' number of absorbers per redshift interval with optical depths greater than tau. Args: tau, optical depth z, redshift params, dictionary of model parameters Returns: number of absorbers per redshift interval (along LoS) with optical depths greater than tau ''' splkey = ('dn_dz_tau', z) + dict2tuple(params) if not SPLINE_DICT.has_key(splkey): tauvals = np.logspace(TAU_INTERP_MIN, TAU_INTERP_MAX, N_INTERP_TAU) dnvals = np.zeros_like(tauvals) for taunum, tauval in enumerate(tauvals): g=lambda x:sigma_tau(tauval,10.**x,z,params)*massfunc(10.**x,z)\ *C*1e-3/COSMO.Hz(z)*LITTLEH dnvals[taunum] = integrate.quad(g, M_INTERP_MIN, M_INTERP_MAX)[0] SPLINE_DICT[splkey] = interp.interp1d(np.log(tauvals), dnvals) return SPLINE_DICT[splkey](np.log(tau))
def ps_integral(k, z21, power_hi, power_hits, params): ''' Evaluate integral \frac{3 h_p^2 c^3 A_{10} (1+z)^2)}{32 \pi \nu_{21}^2 m_p H(z)} \times (1+z)^power_hits \times \int_{m_min}^{m_max} dm n(m)\langle (\tilde{\rho}_{HI}^power_{HI}(k|m,z)^power_hi) \star (\tilde{T}_s(k|m,z))^-power_hits where \star denotes convolution. this integral appears in most 21-cm halo model terms. Args: k, wavenumber (h/Mpc) z21, redshift power_hi, power to raise FT(rho_HI) in convolution power_hits, power to raise FT(Ts) in convolution params, dictionary of parameters, including name of convolution function Returns: Integral in K^(2-power_hits) (Mpc/h)^(6-3*power_hi) ''' g=lambda x: massfunc(10.**x,z21)\ *TS_HI_MODELS[params['RHOTSMODEL']+'_k'](k,10.**x,z21,power_hi,power_hits,params) return integrate.quad(g,M_INTERP_MIN,M_INTERP_MAX)[0]\ *mTb_emiss(z21)**(power_hi+power_hits)
def dn_dlogtau_dz(tau, z, params, recompute=False): ''' compute the number of optical depth features per redshift interval per optical depth interval. Args: z, redshift tau, optical depth params, model parameters Returns: average number of optical depth features between tau and tau+d_tau and redshift z and dz in a los on the sky. ''' splkey = ('dn_dlogtau_domega_dz', z) + dict2tuple(params) if not SPLINE_DICT.has_key(splkey) or recompute: tauvals = np.logspace(TAU_INTERP_MIN, TAU_INTERP_MAX, N_INTERP_TAU) dnvals = np.zeros_like(tauvals) for taunum, tauval in enumerate(tauvals): g=lambda x: massfunc(10.**x,z)*dsigma_dtau(tauval,10.**x,z,params)\ *tauval*np.log(10.) dnvals[taunum]=integrate.quad(g,M_INTERP_MIN,M_INTERP_MAX)[0]\ *1e-3*C/COSMO.Hz(z)*LITTLEH print dnvals SPLINE_DICT[splkey] = interp.interp1d(np.log(tauvals), dnvals) return SPLINE_DICT[splkey](np.log(tau))