예제 #1
0
def saturationB(Bguess0=1e-19,
                nzs=100,
                zmin=15, zmax=35,
                thetak=0.1,phik=0.83,
                val_nk=f.FFTT_nk,
                val_Ts=rf.Ts_21cmfast_interp, 
                val_Tk=rf.Tk_21cmfast_interp, 
                val_Jlya=rf.Jlya_21cmfast_interp, 
                val_Tg=rf.Tg_21cmfast_interp,
                phin=0., thetan=np.pi/2.,
                make_plot=False,
                **rootkwargs):
    """This computes the mag. field strength at saturation, at a given z.
    """
    zs = np.linspace(zmin, zmax,nzs)
    Bevol = np.zeros(nzs)
    Bsat = np.zeros(nzs)
    Gref = np.zeros(nzs)
    Gref_Binf = np.zeros(nzs)
    for i,z in enumerate(zs):
        
        H_z = cf.H( z )
        Ts = val_Ts( z )
        Tg = val_Tg( z )
        Tk = val_Tk( z )
        Jlya = val_Jlya( z )        
        Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0) 
        xalpha = rf.val_xalpha( Salpha=Salpha, Jlya=Jlya, Tg=Tg )
        xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
        xBcoeff = ge * muB * Tstar / ( 2.*hbar * A * Tg ) 
        
        xB=xBcoeff*Bguess0
        Gref[i] = pt.calc_G(thetak=thetak, phik=phik, 
                  thetan=thetan, phin=phin,
                  Ts=Ts, Tg=Tg, z=z, 
                  verbose=False, 
                  xalpha=xalpha, xc=xc, xB=xB, x1s=1.)

        Gref_Binf[i] = pt.calc_G_Binfinity(thetak=thetak, phik=phik, 
                                      thetan=thetan, phin=phin,
                                      Ts=Ts, Tg=Tg, z=z, 
                                      verbose=False, 
                                      xalpha=xalpha, xc=xc, 
                                      x1s=1.)

        res = root(evaluate_GminusGinf, Bguess0, args=(Gref_Binf[i],xBcoeff,thetak,phik,thetan,phin,Ts,Tg,z,xalpha,xc,x1s),method='lm',options=dict(ftol=1e-13, eps=1e-6))
       
        Bsat[i] = res.x[0]/(1+z)**2
        
    if make_plot:
        plt.figure()
        plt.semilogy(zs,Bsat,lw=4,color='blue')
        plt.xlabel('z',fontsize=22)
        plt.ylabel('saturation B [Gauss]',fontsize=22)
    
    return zs,Bsat
예제 #2
0
def saturationB_simple(zs=None,nzs=100,
                zmin=15, zmax=35,
                val_nk=f.FFTT_nk,
                val_Ts=rf.Ts_21cmfast_interp, 
                val_Tk=rf.Tk_21cmfast_interp, 
                val_Jlya=rf.Jlya_21cmfast_interp, 
                val_Tg=rf.Tg_21cmfast_interp,
                make_plot=False,
                fontsize=24):
    """This computes the mag. field strength at saturation, at a given z, in a simplified way, as Bsaturation = (xc + xalpha +1) / xBcoeff.
    """
    if zs is None:
        zs = np.linspace(zmin, zmax,nzs)
    Bsat = np.zeros(len(zs))
    for i,z in enumerate(zs):
        
        H_z = cf.H( z )
        Ts = val_Ts( z )
        Tg = val_Tg( z )
        Tk = val_Tk( z )
        Jlya = val_Jlya( z )        
        Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0) 
        xalpha = rf.val_xalpha( Salpha=Salpha, Jlya=Jlya, Tg=Tg )
        xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
        xBcoeff = ge * muB * Tstar / ( 2.*hbar * A * Tg ) 
        Bsat[i] = (1+xalpha+xc)/xBcoeff/(1+z)**2

       
        
    if make_plot:
        plt.figure()
        #fig = plt.gcf()
        ax = plt.gca()
        
        ylabel = ax.set_ylabel('Saturation [Gauss]',fontsize=fontsize)
        xlabel = ax.set_xlabel('z',fontsize=fontsize)
       
        plt.semilogy(zs,Bsat,lw=4,color='b')
        plt.grid(b=True,which='major')

        
        plt.savefig(RESULTS_PATH+'Bsaturation.pdf',
                    bbox_extra_artists=[xlabel, ylabel], 
                    bbox_inches='tight')
        
    
    return zs,Bsat
예제 #3
0
def saturationB_simple(zs=None,
                       nzs=100,
                       zmin=15,
                       zmax=35,
                       val_nk=f.FFTT_nk,
                       val_Ts=rf.Ts_21cmfast_interp,
                       val_Tk=rf.Tk_21cmfast_interp,
                       val_Jlya=rf.Jlya_21cmfast_interp,
                       val_Tg=rf.Tg_21cmfast_interp,
                       make_plot=False,
                       fontsize=24):
    """This computes the mag. field strength at saturation, at a given z, in a simplified way, as Bsaturation = (xc + xalpha +1) / xBcoeff.
    """
    if zs is None:
        zs = np.linspace(zmin, zmax, nzs)
    Bsat = np.zeros(len(zs))
    for i, z in enumerate(zs):

        H_z = cf.H(z)
        Ts = val_Ts(z)
        Tg = val_Tg(z)
        Tk = val_Tk(z)
        Jlya = val_Jlya(z)
        Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0)
        xalpha = rf.val_xalpha(Salpha=Salpha, Jlya=Jlya, Tg=Tg)
        xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
        xBcoeff = ge * muB * Tstar / (2. * hbar * A * Tg)
        Bsat[i] = (1 + xalpha + xc) / xBcoeff / (1 + z)**2

    if make_plot:
        plt.figure()
        #fig = plt.gcf()
        ax = plt.gca()

        ylabel = ax.set_ylabel('Saturation [Gauss]', fontsize=fontsize)
        xlabel = ax.set_xlabel('z', fontsize=fontsize)

        plt.semilogy(zs, Bsat, lw=4, color='b')
        plt.grid(b=True, which='major')

        plt.savefig(RESULTS_PATH + 'Bsaturation.pdf',
                    bbox_extra_artists=[xlabel, ylabel],
                    bbox_inches='tight')

    return zs, Bsat
예제 #4
0
def visualize_hp(thetak=np.pi / 2.,
                 phik=np.pi / 2.,
                 nside=64,
                 npix=None,
                 fileroot=RESULTS_PATH,
                 z=21,
                 fontsize=24):
    """This produces healpy visualization of the quadrupole pattern,
    in the frame of the atom.
    """
    Bs = np.array([0., 1e-18, 1e-17, 1e-16])

    Ts = val_Ts(z)
    Tg = val_Tg(z)
    Tk = val_Tk(z)
    Jlya = val_Jlya(z)
    Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0)
    xalpha = rf.val_xalpha(Salpha=Salpha, Jlya=Jlya, Tg=Tg)
    xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
    xBcoeff = ge * muB * Tstar / (2. * hbar * A * Tg)

    if npix is None:
        npix = hp.nside2npix(nside)
    for B in Bs:
        filename = fileroot + 'hp_B_{:.0}G.pdf'.format(B)
        mapa = np.zeros(npix)
        for ipix in np.arange(npix):
            thetan, phin = hp.pix2ang(nside, ipix)
            mapa[ipix] = pt.pattern_Tb(thetak=thetak,
                                       phik=phik,
                                       thetan=thetan,
                                       phin=phin,
                                       xalpha=xalpha,
                                       xc=xc,
                                       xB=xBcoeff * B)
        if B > 0.:
            Bexponent = np.log10(B / (1 + z)**2)
            title = r'$10^{{{:.0f}}}$ Gauss'.format(Bexponent)
        else:
            title = 'no magnetic field'
        hp.mollview(mapa, title='', cbar=False)
        plt.title(title, fontsize=fontsize)
        plt.savefig(filename)
예제 #5
0
def visualize_hp(thetak=np.pi/2.,phik=np.pi/2.,
                 nside=64, npix=None,
                fileroot=RESULTS_PATH, z=21,
                fontsize=24):
    """This produces healpy visualization of the quadrupole pattern,
    in the frame of the atom.
    """
    Bs = np.array([0.,1e-18,1e-17, 1e-16])
   
    Ts = val_Ts( z )
    Tg = val_Tg( z )
    Tk = val_Tk( z )
    Jlya = val_Jlya( z )        
    Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0) 
    xalpha = rf.val_xalpha( Salpha=Salpha, Jlya=Jlya, Tg=Tg )
    xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
    xBcoeff = ge * muB * Tstar / ( 2.*hbar * A * Tg ) 
    
    if npix is None:
        npix = hp.nside2npix(nside)
    for B in Bs:
        filename = fileroot + 'hp_B_{:.0}G.pdf'.format(B)
        mapa = np.zeros(npix)
        for ipix in np.arange(npix):
            thetan, phin = hp.pix2ang(nside, ipix)
            mapa[ipix] = pt.pattern_Tb(thetak=thetak, phik=phik,
                                       thetan=thetan, phin=phin, 
                                        xalpha=xalpha, xc=xc, xB=xBcoeff*B)
        if B > 0.:
            Bexponent = np.log10(B / (1+z)**2)
            title = r'$10^{{{:.0f}}}$ Gauss'.format(Bexponent)
        else:
            title = 'no magnetic field'
        hp.mollview(mapa, title='', cbar=False)
        plt.title(title, fontsize=fontsize)
        plt.savefig(filename)
예제 #6
0
def integrand_PBi(x,
                  t_yr=1.,
                  Omega_survey=1.,
                  DeltaL_km=2.,
                  val_nk=FFTT_nk,
                  val_Ts=rf.Ts_21cmfast_interp,
                  val_Tk=rf.Tk_21cmfast_interp,
                  val_Jlya=rf.Jlya_21cmfast_interp,
                  val_x1s=rf.ones_x1s,
                  val_Tsys=Tsys_Mao2008,
                  val_Tg=rf.Tg_21cmfast_interp,
                  phin=0.,
                  thetan=np.pi / 2.,
                  debug=False):
    """Calculates value of the integrand for noise per component
     of a stochastic mag. field vector B (eq 51 of detectability notes).
     This is called by :func:`calc_SNR` that integrates it over k, theta, phi.

    :param x:
      Array of the following form: x = z, k_Mpc, thetak, phik
    :type x: ``array``

    :param t_yr:
      The total observation time in years.
      The time spent on a single field of view (=1sr for FFTT) is t_yr / Omega_survey. ???
    :type t_yr: ``float``

    :param DeltaL_km:
      The size of the FFTT coverage on a side in kilometers.
    :type DeltaL_km: ``float``

    :param Omega_survey:
      The survey area (on the sky) in steradians.
    :type Omega_survey: ``float``

    :params thetan,phin:
      These define direction of the LOS in the frame where 
      mag. field vector B is along the z axis. 
      Do not change these unless you know exactly what you're getting into.
    :type thetan,phin: ``float``

    :params val_*:
      Helper functions, like the calulators for various temperatures etc.
    :type val_*: ``function``


    """

    z = x[0]
    k_Mpc = x[1]
    thetak = x[2]
    phik = x[3]

    thetak_n = np.arccos(
        np.sin(thetak) * np.cos(phik) * np.sin(thetan) * np.cos(phin) +
        np.sin(thetak) * np.sin(phik) * np.sin(thetan) * np.sin(phin) +
        np.cos(thetak) * np.cos(thetan))
    sint = np.sin(thetak_n)
    if np.isclose(sint, 0.):
        if debug:
            return 0, 0, 0
        return 0.

    DeltaL_cm = DeltaL_km * 1e5  # cm
    lambda_z = lambda21 * (1. + z)  # cm
    dA = cf.val_dA(z)  # cm

    kmin = 2. * np.pi / (dA * sint / Mpc_in_cm)  # 1/Mpc comoving
    kmax = kmin * DeltaL_cm / lambda_z  # 1/Mpc comoving

    if k_Mpc > kmax or k_Mpc < kmin:
        if debug:
            return 0, 0, 0
        return 0.

    t_sec = 365. * 86400 * t_yr  # sec
    k_cm = k_Mpc / Mpc_in_cm  # cm
    N_ants = (DeltaL_cm / lambda_z)**2
    Ntot = N_ants * (N_ants + 1.) / 2.

    nk = val_nk(k_cm,
                Ntot=Ntot,
                lambda_z=lambda_z,
                dA=dA,
                sin_thetak_n=sint,
                Lmax=DeltaL_cm,
                Lmin=lambda_z,
                DeltaL=DeltaL_cm)

    t1 = t_sec
    if Omega_survey > 1.:
        t1 = t_sec / Omega_survey

    H_z = cf.H(z)
    Tsys = val_Tsys(z)
    Ts = val_Ts(z)
    Tg = val_Tg(z)
    Tk = val_Tk(z)
    Jlya = val_Jlya(z)
    Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0)
    xalpha = rf.val_xalpha(Salpha=Salpha, Jlya=Jlya, Tg=Tg)
    xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
    xBcoeff = ge * muB * Tstar / (2. * hbar * A * Tg)

    Pnoise = P21_N(dA=dA,
                   H_z=H_z,
                   z=z,
                   Tsys=Tsys,
                   t1=t1,
                   Ae=lambda_z**2,
                   Lmax=DeltaL_cm,
                   Lmin=lambda_z,
                   lambda_z=lambda_z,
                   nk=nk)
    if np.isnan(Pnoise):
        raise ValueError('Pnoise is nan.')

    Pdelta = cf.val_Pdelta(z, k_Mpc)

    G = pt.calc_G(thetak=thetak,
                  phik=phik,
                  thetan=thetan,
                  phin=phin,
                  Ts=Ts,
                  Tg=Tg,
                  z=z,
                  verbose=False,
                  xalpha=xalpha,
                  xc=xc,
                  xB=0.,
                  x1s=1.)

    dGdB = pt.calc_dGdB(thetak=thetak,
                        phik=phik,
                        thetan=thetan,
                        phin=phin,
                        Ts=Ts,
                        Tg=Tg,
                        z=z,
                        verbose=False,
                        xalpha=xalpha,
                        xc=xc,
                        xBcoeff=xBcoeff,
                        x1s=1.)

    Psignal = Pdelta * G**2
    Numerator = (2. * G * dGdB * (1. + z)**2 * Pdelta)**2
    Denominator = 2. * (2. * np.pi)**3 * (
        Psignal + Pnoise)**2  ###is 2pi factor right? check!

    res = k_Mpc**2 * np.sin(thetak) * Numerator / Denominator

    if debug:
        return res, Pnoise, nk, Numerator, G, dGdB
    return res
예제 #7
0
def integrand(x,
              mode='B0',
              t_yr=1.,
              Omega_patch=1.,
              DeltaL_km=2.,
              val_nk=FFTT_nk,
              val_Ts=rf.Ts_21cmfast_interp,
              val_Tk=rf.Tk_21cmfast_interp,
              val_Jlya=rf.Jlya_21cmfast_interp,
              val_x1s=rf.ones_x1s,
              val_Tsys=Tsys_Mao2008,
              val_Tg=rf.Tg_21cmfast_interp,
              phin=0.,
              thetan=np.pi / 2.,
              print_klims=False,
              debug=False):
    """Calculates value of the integrand for sensitivity to uniform mag. field vector B (eqs 37,40 of detectability_notes).
     This is called by :func:`rand_integrator` that integrates it over z, k, theta, phi.

    :param x:
      Array of the following form: x = z, k_Mpc, thetak, phik
    :type x: ``array``

    :param t_yr:
      The total observation time in years.
      The time spent on a single field of view (=1sr for FFTT) is t_yr / Omega_survey. ???
    :type t_yr: ``float``

    :param mode:
      The mode of calculation; if mode == 'B0', returns sensitivity to measuring uniform mag. field B0
      if mode == 'xi', returns 1 sigma sensitivity to distinguishing saturated from unsaturated case, 
      where xi is unitless and between 0 and 1.
    :type mode: ``str``

    :param DeltaL_km:
      The size of the FFTT coverage on a side in kilometers.
    :type DeltaL_km: ``float``

    :param Omega_patch:
      The area of a small (approx. flat, < 1sr) patch the sky in steradians.
    :type Omega_patch: ``float``

    :params thetan,phin:
      These define direction of the LOS in the frame where 
      mag. field vector B is along the z axis. 
      Do not change these unless you know exactly what you're getting into.
    :type thetan,phin: ``float``

    :params val_*:
      Helper functions, like the calulators for various temperatures etc.
    :type val_*: ``function``

    """

    z = x[0]
    k_Mpc = x[1]
    thetak = x[2]
    phik = x[3]

    thetak_n = np.arccos(
        np.sin(thetak) * np.cos(phik) * np.sin(thetan) * np.cos(phin) +
        np.sin(thetak) * np.sin(phik) * np.sin(thetan) * np.sin(phin) +
        np.cos(thetak) * np.cos(thetan))
    sint = np.sin(thetak_n)
    if np.isclose(sint, 0.):
        if debug:
            return 0, 0, 0
        return 0.

    DeltaL_cm = DeltaL_km * 1e5  # cm
    lambda_z = lambda21 * (1. + z)  # cm
    dA = cf.val_dA(z)  # cm comov.

    kmin = 2. * np.pi / (dA * sint / Mpc_in_cm)  # 1/Mpc comoving
    kmax = kmin * DeltaL_cm / lambda_z  # 1/Mpc comoving

    if print_klims:
        print('kmax={}, kmin={}'.format(kmax, kmin))
    if k_Mpc > kmax or k_Mpc < kmin:
        if debug:
            return 0, 0, 0
        return 0.

    t_sec = 365. * 86400 * t_yr  # sec
    k_cm = k_Mpc / Mpc_in_cm  # cm
    N_ants = (DeltaL_cm / lambda_z)**2
    Ntot = N_ants * (N_ants + 1.) / 2.

    nk = val_nk(k_cm,
                Ntot=Ntot,
                lambda_z=lambda_z,
                dA=dA,
                sin_thetak_n=sint,
                Lmax=DeltaL_cm,
                Lmin=lambda_z,
                DeltaL=DeltaL_cm)

    t1 = t_sec
    if Omega_patch > 1.:
        t1 = t_sec / Omega_patch

    H_z = cf.H(z)
    Tsys = val_Tsys(z)
    Ts = val_Ts(z)
    Tg = val_Tg(z)
    Tk = val_Tk(z)
    Jlya = val_Jlya(z)
    Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0)
    xalpha = rf.val_xalpha(Salpha=Salpha, Jlya=Jlya, Tg=Tg)
    xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
    xBcoeff = ge * muB * Tstar / (2. * hbar * A * Tg)

    Vpatch = Vpatch_factor(z, dA=dA, H_z=H_z, Omega_patch=Omega_patch)
    Pnoise = P21_N(dA=dA,
                   H_z=H_z,
                   z=z,
                   Tsys=Tsys,
                   t1=t1,
                   Ae=lambda_z**2,
                   Lmax=DeltaL_cm,
                   Lmin=lambda_z,
                   lambda_z=lambda_z,
                   nk=nk)
    if np.isnan(Pnoise):
        raise ValueError('Pnoise is nan.')

    Pdelta = cf.val_Pdelta(z, k_Mpc)

    if mode == 'B0':
        G = pt.calc_G(thetak=thetak,
                      phik=phik,
                      thetan=thetan,
                      phin=phin,
                      Ts=Ts,
                      Tg=Tg,
                      z=z,
                      verbose=False,
                      xalpha=xalpha,
                      xc=xc,
                      xB=0.,
                      x1s=1.)

        dGdB = pt.calc_dGdB(thetak=thetak,
                            phik=phik,
                            thetan=thetan,
                            phin=phin,
                            Ts=Ts,
                            Tg=Tg,
                            z=z,
                            verbose=False,
                            xalpha=xalpha,
                            xc=xc,
                            xBcoeff=xBcoeff,
                            x1s=1.)

        Psignal = Pdelta * G**2
        Numerator = (2. * G * dGdB * (1 + z)**2 * Pdelta)**2
        Denominator = (Psignal + Pnoise)**2

        res = k_Mpc**2 * np.sin(thetak) * Vpatch * Numerator / Denominator / (
            2. * np.pi)**3

    if mode == 'xi':
        G_Bzero = pt.calc_G(thetak=thetak,
                            phik=phik,
                            thetan=thetan,
                            phin=phin,
                            Ts=Ts,
                            Tg=Tg,
                            z=z,
                            verbose=False,
                            xalpha=xalpha,
                            xc=xc,
                            x1s=1.,
                            xB=0.)
        G_Binfinity = pt.calc_G_Binfinity(thetak=thetak,
                                          phik=phik,
                                          thetan=thetan,
                                          phin=phin,
                                          Ts=Ts,
                                          Tg=Tg,
                                          z=z,
                                          verbose=False,
                                          xalpha=xalpha,
                                          xc=xc,
                                          x1s=1.)

        Psignal_Bzero = Pdelta * G_Bzero**2
        Psignal_Binfinity = Pdelta * G_Binfinity**2
        Numerator = (Psignal_Binfinity - Psignal_Bzero)**2
        Denominator = 2. * (Psignal_Bzero + Pnoise)**2

        res = k_Mpc**2 * np.sin(thetak) * Vpatch * Numerator / Denominator / (
            2. * np.pi)**3

    if mode == 'Bi':
        G = pt.calc_G(thetak=thetak,
                      phik=phik,
                      thetan=thetan,
                      phin=phin,
                      Ts=Ts,
                      Tg=Tg,
                      z=z,
                      verbose=False,
                      xalpha=xalpha,
                      xc=xc,
                      xB=0.,
                      x1s=1.)

        dGdB = pt.calc_dGdB(thetak=thetak,
                            phik=phik,
                            thetan=thetan,
                            phin=phin,
                            Ts=Ts,
                            Tg=Tg,
                            z=z,
                            verbose=False,
                            xalpha=xalpha,
                            xc=xc,
                            xBcoeff=xBcoeff,
                            x1s=1.)  #/ (1.+z)**2  #!!! VG: check

        Psignal = Pdelta * G**2
        Numerator = (2. * G * dGdB * (1 + z)**2 * Pdelta)**2
        Denominator = 2. * (Psignal + Pnoise)**2

        res = k_Mpc**2 * np.sin(thetak) * Numerator / Denominator

    if debug:
        dGdB, summ, xs = pt.calc_dGdB(thetak=thetak,
                                      phik=phik,
                                      thetan=thetan,
                                      phin=phin,
                                      Ts=Ts,
                                      Tg=Tg,
                                      z=z,
                                      verbose=False,
                                      xalpha=xalpha,
                                      xc=xc,
                                      xBcoeff=xBcoeff,
                                      x1s=1.,
                                      debug=True)
        return res, Numerator, Denominator, Psignal, Pnoise, G, dGdB, Pdelta, Ts, Tg, summ, xs
    return res
예제 #8
0
def GvsB(zs=[20, 22, 25, 28, 31],
         nBs=100,
         Bmin=1e-22,
         Bmax=1e-18,
         thetak=0.1,
         phik=0.83,
         val_nk=f.FFTT_nk,
         val_Ts=rf.Ts_21cmfast_interp,
         val_Tk=rf.Tk_21cmfast_interp,
         val_Jlya=rf.Jlya_21cmfast_interp,
         val_Tg=rf.Tg_21cmfast_interp,
         phin=0.,
         thetan=np.pi / 2.,
         fontsize=24,
         make_plot=False,
         root=RESULTS_PATH,
         ymax=1e-5,
         ymin=1e-14):
    """This plots deltaG(B), at a given z.
    """
    Bref = 0.
    plt.figure()
    ax = plt.gca()
    colors = ['Violet', 'DarkBlue', 'Maroon', 'r', 'Orange', 'gray']
    zs, Bsat = saturationB_simple(zs=zs)
    Bs = np.logspace(np.log10(Bmin), np.log10(Bmax), nBs)
    deltaG = np.zeros(len(Bs))

    for j, z in enumerate(zs):
        H_z = cf.H(z)
        Ts = val_Ts(z)
        Tg = val_Tg(z)
        Tk = val_Tk(z)
        Jlya = val_Jlya(z)
        Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0)
        xalpha = rf.val_xalpha(Salpha=Salpha, Jlya=Jlya, Tg=Tg)
        xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
        xBcoeff = ge * muB * Tstar / (2. * hbar * A * Tg)
        x1s = 1.

        deltaG = np.zeros(len(Bs))
        Gref = pt.calc_G(thetak=thetak,
                         phik=phik,
                         thetan=thetan,
                         phin=phin,
                         Ts=Ts,
                         Tg=Tg,
                         z=z,
                         verbose=False,
                         xalpha=xalpha,
                         xc=xc,
                         xB=xBcoeff * Bref,
                         x1s=1.)
        for i, B in enumerate(Bs):
            xB = xBcoeff * B
            G = pt.calc_G(thetak=thetak,
                          phik=phik,
                          thetan=thetan,
                          phin=phin,
                          Ts=Ts,
                          Tg=Tg,
                          z=z,
                          verbose=False,
                          xalpha=xalpha,
                          xc=xc,
                          xB=xB,
                          x1s=1.)
            deltaG[i] = np.abs((G - Gref) / Gref)

        ax.loglog(Bs, deltaG, lw=4, color=colors[j])
        ax.loglog(np.array([Bsat[j], Bsat[j]]),
                  np.array([ymin, ymax]),
                  '--',
                  lw=2,
                  color=colors[j])

    xlabel = ax.set_xlabel('B [Gauss]', fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$\Delta G / G$', fontsize=fontsize)
    plt.savefig(root + 'G_vs_B.pdf',
                bbox_extra_artists=[xlabel, ylabel],
                bbox_inches='tight')
예제 #9
0
def saturationB(Bguess0=1e-19,
                nzs=100,
                zmin=15,
                zmax=35,
                thetak=0.1,
                phik=0.83,
                val_nk=f.FFTT_nk,
                val_Ts=rf.Ts_21cmfast_interp,
                val_Tk=rf.Tk_21cmfast_interp,
                val_Jlya=rf.Jlya_21cmfast_interp,
                val_Tg=rf.Tg_21cmfast_interp,
                phin=0.,
                thetan=np.pi / 2.,
                make_plot=False,
                **rootkwargs):
    """This computes the mag. field strength at saturation, at a given z.
    """
    zs = np.linspace(zmin, zmax, nzs)
    Bevol = np.zeros(nzs)
    Bsat = np.zeros(nzs)
    Gref = np.zeros(nzs)
    Gref_Binf = np.zeros(nzs)
    for i, z in enumerate(zs):

        H_z = cf.H(z)
        Ts = val_Ts(z)
        Tg = val_Tg(z)
        Tk = val_Tk(z)
        Jlya = val_Jlya(z)
        Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0)
        xalpha = rf.val_xalpha(Salpha=Salpha, Jlya=Jlya, Tg=Tg)
        xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
        xBcoeff = ge * muB * Tstar / (2. * hbar * A * Tg)

        xB = xBcoeff * Bguess0
        Gref[i] = pt.calc_G(thetak=thetak,
                            phik=phik,
                            thetan=thetan,
                            phin=phin,
                            Ts=Ts,
                            Tg=Tg,
                            z=z,
                            verbose=False,
                            xalpha=xalpha,
                            xc=xc,
                            xB=xB,
                            x1s=1.)

        Gref_Binf[i] = pt.calc_G_Binfinity(thetak=thetak,
                                           phik=phik,
                                           thetan=thetan,
                                           phin=phin,
                                           Ts=Ts,
                                           Tg=Tg,
                                           z=z,
                                           verbose=False,
                                           xalpha=xalpha,
                                           xc=xc,
                                           x1s=1.)

        res = root(evaluate_GminusGinf,
                   Bguess0,
                   args=(Gref_Binf[i], xBcoeff, thetak, phik, thetan, phin, Ts,
                         Tg, z, xalpha, xc, x1s),
                   method='lm',
                   options=dict(ftol=1e-13, eps=1e-6))

        Bsat[i] = res.x[0] / (1 + z)**2

    if make_plot:
        plt.figure()
        plt.semilogy(zs, Bsat, lw=4, color='blue')
        plt.xlabel('z', fontsize=22)
        plt.ylabel('saturation B [Gauss]', fontsize=22)

    return zs, Bsat
예제 #10
0
def arb_xT(
        zmin=15,
        zmax=30,
        nzs=100,
        fontsize=24,
        root=RESULTS_PATH,
        filename='global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__midFSTAR',
        filenames_uncertainty=[
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__loFSTAR',
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__hiFSTAR'
        ],
        label='',
        B0=1e-22,
        ymax_T=100,
        ymin_x=1e-6):
    """Takes filenames_uncertainty as a list of 2 filenames, no root,
    e.g. ['global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__loFSTAR','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__hiFSTAR']

    """

    file_21cmfast = np.loadtxt(INPUTS_PATH + filename)
    Tks_21cmfast = file_21cmfast[:, 2][::-1]
    Tgs_21cmfast = file_21cmfast[:, 5][::-1]
    Tss_21cmfast = file_21cmfast[:, 4][::-1]
    Jlyas_21cmfast = file_21cmfast[:, 6][::-1]
    zs_21cmfast = file_21cmfast[:, 0][::-1]
    xH_21cmfast = file_21cmfast[:, 1][::-1]

    if filenames_uncertainty is not None:
        file_21cmfast_lo = np.loadtxt(INPUTS_PATH + filenames_uncertainty[0])
        Tks_21cmfast_lo = file_21cmfast_lo[:, 2][::-1]
        Tgs_21cmfast_lo = file_21cmfast_lo[:, 5][::-1]
        Tss_21cmfast_lo = file_21cmfast_lo[:, 4][::-1]
        Jlyas_21cmfast_lo = file_21cmfast_lo[:, 6][::-1]
        zs_21cmfast_lo = file_21cmfast_lo[:, 0][::-1]
        xH_21cmfast_lo = file_21cmfast_lo[:, 1][::-1]

        file_21cmfast_hi = np.loadtxt(INPUTS_PATH + filenames_uncertainty[1])
        Tks_21cmfast_hi = file_21cmfast_hi[:, 2][::-1]
        Tgs_21cmfast_hi = file_21cmfast_hi[:, 5][::-1]
        Tss_21cmfast_hi = file_21cmfast_hi[:, 4][::-1]
        Jlyas_21cmfast_hi = file_21cmfast_hi[:, 6][::-1]
        zs_21cmfast_hi = file_21cmfast_hi[:, 0][::-1]
        xH_21cmfast_hi = file_21cmfast_hi[:, 1][::-1]

    # plot J_Lya
    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z', fontsize=fontsize)
    ylabel = ax.set_ylabel(
        r'$J_{Ly\alpha}$ [$cm^{-2} sec^{-1} Hz^{-1}sr^{-1}$]',
        fontsize=fontsize)
    ax.semilogy(zs_21cmfast, Jlyas_21cmfast, lw=4, color='Black')

    # if uncertainty files given, plot band around Jlya
    if filenames_uncertainty is not None:
        maxind = min(len(Jlyas_21cmfast_lo), len(Jlyas_21cmfast_hi)) - 1
        ax.fill_between(zs_21cmfast_lo[:maxind],
                        Jlyas_21cmfast_lo[:maxind],
                        Jlyas_21cmfast_hi[:maxind],
                        facecolor='gray',
                        interpolate=True,
                        alpha=0.4,
                        lw=0)
    ax.set_xlim(xmin=zmin, xmax=27)
    plt.savefig(RESULTS_PATH + 'Jlya{}.pdf'.format(label),
                bbox_extra_artists=[xlabel, ylabel],
                bbox_inches='tight')

    # compute x's and write to file, then plot
    xc = []
    xB = []
    xalpha = []
    fout = open(RESULTS_PATH + 'xs_table.txt', 'w')
    fout.write('z  x_alpha x_c xBcoeff\n')
    for i, z in enumerate(zs_21cmfast):
        B = B0 * (1 + z)**2

        Salpha = cf.val_Salpha(Tss_21cmfast[i], Tks_21cmfast[i], z,
                               xH_21cmfast[i], 0)
        xalpha.append(
            rf.val_xalpha(Salpha=Salpha,
                          Jlya=Jlyas_21cmfast[i],
                          Tg=Tgs_21cmfast[i]))
        xc.append(rf.val_xc(z, Tk=Tks_21cmfast[i], Tg=Tgs_21cmfast[i]))
        xBcoeff = ge * muB * Tstar / (2. * hbar * A * Tgs_21cmfast[i])
        xB.append(B * xBcoeff)
        fout.write('{}  {}  {} {}\n'.format(z, xalpha[i], xc[i], xBcoeff))
    fout.close()

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z', fontsize=fontsize)
    ylabel = ax.set_ylabel('')
    plt.semilogy(zs_21cmfast,
                 xc,
                 '--',
                 dashes=(15, 5),
                 lw=4,
                 color='b',
                 label=r'$x_{c,(2)}$')
    plt.semilogy(zs_21cmfast,
                 xalpha,
                 lw=4,
                 color='k',
                 label=r'$x_{\alpha,(2)}$')
    plt.semilogy(zs_21cmfast,
                 xB,
                 '-.',
                 lw=4,
                 color='r',
                 label=r'$x_B$ ($10^{{{:.0f}}}$ G)'.format(np.log10(B0)))
    plt.legend(fontsize=fontsize, frameon=False, loc='lower right')
    plt.xlim(xmin=zmin, xmax=zmax)
    plt.ylim(ymin=ymin_x)
    plt.savefig(RESULTS_PATH + 'xs{}.pdf'.format(label),
                bbox_extra_artists=[xlabel, ylabel],
                bbox_inches='tight')

    # plot ionization history
    #plt.figure()
    #ax = plt.gca()
    #xlabel = ax.set_xlabel('z',fontsize=fontsize)
    #ylabel = ax.set_ylabel('$x_H$',fontsize=fontsize)
    #plt.plot(zs_21cmfast,xH_21cmfast,lw=4,color='red')
    #plt.savefig(RESULTS_PATH+'xion{}.pdf'.format(label),
    #            bbox_extra_artists=[xlabel, ylabel],
    #            bbox_inches='tight')

    # plot T's
    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z', fontsize=fontsize)
    ylabel = ax.set_ylabel('T [K]', fontsize=fontsize)
    plt.plot(zs_21cmfast, Tss_21cmfast, lw=4, color='k', label='$T_s$')
    plt.plot(zs_21cmfast,
             Tgs_21cmfast,
             '--',
             lw=4,
             color='g',
             label=r'$T_{\gamma}$')
    plt.plot(zs_21cmfast,
             Tks_21cmfast,
             '--',
             dashes=(15, 5),
             lw=4,
             color='b',
             label='$T_k$')
    plt.legend(fontsize=fontsize, frameon=False, loc='upper left')
    plt.xlim(xmin=zmin, xmax=zmax)
    plt.ylim(ymax=ymax_T)
    #if filenames_uncertainty is not None:
    #    maxind = min(len(Tss_21cmfast_lo),len(Tss_21cmfast_hi))-1
    #    ax.fill_between(zs_21cmfast_lo[:maxind], Tss_21cmfast_lo[:maxind], Tss_21cmfast_hi[:maxind],
    #                    facecolor='gray', interpolate=True, alpha=0.4, lw=0)
    plt.savefig(RESULTS_PATH + 'Ts{}.pdf'.format(label),
                bbox_extra_artists=[xlabel, ylabel],
                bbox_inches='tight')
예제 #11
0
def arb_reion_models(
        zmin=15,
        zmax=27,
        nzs=100,
        fontsize=24,
        root=RESULTS_PATH,
        filenames=[
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__midFSTAR',
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__hiFSTAR',
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__loFSTAR',
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__fesc-ok',
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX5.0e+55_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__low-zetax',
            'global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX2.0e+55_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc'
        ],
        labels=[
            'mid f*', 'hi f*', 'lo f*', 'fesc ok', 'zetax 0.5', 'zetax 0.2'
        ]):
    """
    """

    if labels is None:
        labels = np.arange(len(filenames))
    Tks = {}
    Tgs = {}
    Tss = {}
    Jlyas = {}
    zs = {}

    for i, fn in enumerate(filenames):
        file_21cmfast = np.loadtxt(INPUTS_PATH + fn)
        Tks[labels[i]] = file_21cmfast[:, 2][::-1]
        Tgs[labels[i]] = file_21cmfast[:, 5][::-1]
        Tss[labels[i]] = file_21cmfast[:, 4][::-1]
        Jlyas[labels[i]] = file_21cmfast[:, 6][::-1]
        zs[labels[i]] = file_21cmfast[:, 0][::-1]

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z', fontsize=fontsize)
    ylabel = ax.set_ylabel(
        r'$J_{Ly\alpha}$ [$cm^{-2} sec^{-1} Hz^{-1}sr^{-1}$]',
        fontsize=fontsize)
    for l in labels:
        ax.semilogy(zs[l], Jlyas[l], lw=4, label='{}'.format(l))
    ax.set_xlim(xmin=zmin, xmax=zmax)
    plt.legend(loc='lower left')

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z', fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$T_S$ [K]', fontsize=fontsize)
    for l in labels:
        plt.plot(zs[l], Tss[l], lw=4, label='{}'.format(l))
    plt.legend(loc='upper left', fontsize=fontsize)
    plt.xlim(xmin=zmin, xmax=zmax)
    plt.ylim(ymax=100)

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z', fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$T_K$ [K]', fontsize=fontsize)
    for l in labels:
        plt.plot(zs[l], Tks[l], lw=4, label='{}'.format(l))
    plt.legend(loc='upper left', fontsize=fontsize)
    plt.xlim(xmin=zmin, xmax=zmax)
    plt.ylim(ymax=100)

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z', fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$x_c$', fontsize=fontsize)
    for l in labels:
        xc = []
        for i, z in enumerate(zs[l]):
            xc.append(rf.val_xc(z, Tk=Tks[l][i], Tg=Tgs[l][i]))
        plt.semilogy(zs[l], xc, lw=4, label='{}'.format(l))
    plt.legend(loc='lower right', fontsize=fontsize)
    plt.xlim(xmin=zmin, xmax=zmax)
    plt.ylim(ymin=1e-6)
예제 #12
0
def GvsB(zs=[20,22,25,28,31],
         nBs=100, Bmin=1e-22,Bmax=1e-18,
        thetak=0.1,phik=0.83,
        val_nk=f.FFTT_nk,
        val_Ts=rf.Ts_21cmfast_interp, 
        val_Tk=rf.Tk_21cmfast_interp, 
        val_Jlya=rf.Jlya_21cmfast_interp, 
        val_Tg=rf.Tg_21cmfast_interp,
        phin=0., thetan=np.pi/2.,
        fontsize=24,
        make_plot=False,
        root=RESULTS_PATH,
        ymax=1e-5,
        ymin=1e-14):
    """This plots deltaG(B), at a given z.
    """
    Bref = 0.
    plt.figure()
    ax = plt.gca()
    colors = ['Violet','DarkBlue','Maroon','r','Orange','gray']
    zs, Bsat = saturationB_simple(zs=zs)
    Bs = np.logspace(np.log10(Bmin),np.log10(Bmax),nBs)
    deltaG = np.zeros(len(Bs))

    for j,z in enumerate(zs):
        H_z = cf.H( z )
        Ts = val_Ts( z )
        Tg = val_Tg( z )
        Tk = val_Tk( z )
        Jlya = val_Jlya( z )        
        Salpha = cf.val_Salpha(Ts, Tk, z, 1., 0) 
        xalpha = rf.val_xalpha( Salpha=Salpha, Jlya=Jlya, Tg=Tg )
        xc = rf.val_xc(z, Tk=Tk, Tg=Tg)
        xBcoeff = ge * muB * Tstar / ( 2.*hbar * A * Tg ) 
        x1s = 1.
    
        
        deltaG = np.zeros(len(Bs))
        Gref = pt.calc_G(thetak=thetak, phik=phik, 
                        thetan=thetan, phin=phin,
                        Ts=Ts, Tg=Tg, z=z, 
                        verbose=False, 
                        xalpha=xalpha, xc=xc, xB=xBcoeff*Bref, x1s=1.)
        for i,B in enumerate(Bs):
            xB = xBcoeff*B
            G = pt.calc_G(thetak=thetak, phik=phik, 
                            thetan=thetan, phin=phin,
                            Ts=Ts, Tg=Tg, z=z, 
                            verbose=False, 
                            xalpha=xalpha, xc=xc, xB=xB, x1s=1.)
            deltaG[i] = np.abs((G - Gref) / Gref)


            
        ax.loglog(Bs,deltaG,lw=4,color=colors[j])
        ax.loglog(np.array([Bsat[j],Bsat[j]]),np.array([ymin,ymax]),'--',lw=2,color=colors[j])
    
    xlabel = ax.set_xlabel('B [Gauss]',fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$\Delta G / G$',fontsize=fontsize)
    plt.savefig(root+'G_vs_B.pdf', 
                bbox_extra_artists=[xlabel, ylabel], 
                bbox_inches='tight')
예제 #13
0
def arb_xT(zmin=15,zmax=30, nzs=100,
           fontsize=24,root=RESULTS_PATH,
           filename='global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__midFSTAR',
           filenames_uncertainty=['global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__loFSTAR','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__hiFSTAR'],
           label='',B0=1e-22,
           ymax_T=100,ymin_x=1e-6):
    """Takes filenames_uncertainty as a list of 2 filenames, no root,
    e.g. ['global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__loFSTAR','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__hiFSTAR']

    """

    file_21cmfast = np.loadtxt(INPUTS_PATH+filename)
    Tks_21cmfast = file_21cmfast[:,2][::-1]
    Tgs_21cmfast = file_21cmfast[:,5][::-1]
    Tss_21cmfast = file_21cmfast[:,4][::-1]
    Jlyas_21cmfast = file_21cmfast[:,6][::-1]
    zs_21cmfast = file_21cmfast[:,0][::-1]
    xH_21cmfast = file_21cmfast[:,1][::-1]


    if filenames_uncertainty is not None:
        file_21cmfast_lo = np.loadtxt(INPUTS_PATH+filenames_uncertainty[0])
        Tks_21cmfast_lo  = file_21cmfast_lo [:,2][::-1]
        Tgs_21cmfast_lo  = file_21cmfast_lo [:,5][::-1]
        Tss_21cmfast_lo  = file_21cmfast_lo [:,4][::-1]
        Jlyas_21cmfast_lo  = file_21cmfast_lo [:,6][::-1]
        zs_21cmfast_lo  = file_21cmfast_lo [:,0][::-1]
        xH_21cmfast_lo  = file_21cmfast_lo [:,1][::-1]
        
        file_21cmfast_hi = np.loadtxt(INPUTS_PATH+filenames_uncertainty[1])
        Tks_21cmfast_hi  = file_21cmfast_hi [:,2][::-1]
        Tgs_21cmfast_hi  = file_21cmfast_hi [:,5][::-1]
        Tss_21cmfast_hi  = file_21cmfast_hi [:,4][::-1]
        Jlyas_21cmfast_hi = file_21cmfast_hi[:,6][::-1]
        zs_21cmfast_hi = file_21cmfast_hi[:,0][::-1]
        xH_21cmfast_hi  = file_21cmfast_hi [:,1][::-1]

    # plot J_Lya 
    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z',fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$J_{Ly\alpha}$ [$cm^{-2} sec^{-1} Hz^{-1}sr^{-1}$]',fontsize=fontsize)
    ax.semilogy(zs_21cmfast,Jlyas_21cmfast,lw=4,color='Black')
    
    # if uncertainty files given, plot band around Jlya
    if filenames_uncertainty is not None:
        maxind = min(len(Jlyas_21cmfast_lo),len(Jlyas_21cmfast_hi))-1
        ax.fill_between(zs_21cmfast_lo[:maxind], Jlyas_21cmfast_lo[:maxind], Jlyas_21cmfast_hi[:maxind], 
                        facecolor='gray', interpolate=True, alpha=0.4, lw=0)
    ax.set_xlim(xmin=zmin,xmax=27)
    plt.savefig(RESULTS_PATH+'Jlya{}.pdf'.format(label), 
                bbox_extra_artists=[xlabel, ylabel], 
                bbox_inches='tight')


    # compute x's and write to file, then plot
    xc = []; xB = []; xalpha = []
    fout = open(RESULTS_PATH + 'xs_table.txt', 'w')
    fout.write('z  x_alpha x_c xBcoeff\n')
    for i,z in enumerate(zs_21cmfast):
        B = B0*(1+z)**2

        Salpha = cf.val_Salpha(Tss_21cmfast[i], Tks_21cmfast[i], z, xH_21cmfast[i], 0) 
        xalpha.append(rf.val_xalpha( Salpha=Salpha, Jlya=Jlyas_21cmfast[i], Tg=Tgs_21cmfast[i] ))
        xc.append(rf.val_xc(z, Tk=Tks_21cmfast[i], Tg=Tgs_21cmfast[i]))
        xBcoeff = ge * muB * Tstar / ( 2.*hbar * A * Tgs_21cmfast[i] )
        xB.append(B*xBcoeff)
        fout.write('{}  {}  {} {}\n'.format(z, xalpha[i], xc[i], xBcoeff ))
    fout.close()
        
    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z',fontsize=fontsize)
    ylabel = ax.set_ylabel('')
    plt.semilogy(zs_21cmfast,xc,'--',dashes=(15,5),lw=4,color='b',label=r'$x_{c,(2)}$')
    plt.semilogy(zs_21cmfast,xalpha,lw=4,color='k',label=r'$x_{\alpha,(2)}$')
    plt.semilogy(zs_21cmfast,xB,'-.',lw=4,color='r',label=r'$x_B$ ($10^{{{:.0f}}}$ G)'.format(np.log10(B0)))
    plt.legend(fontsize=fontsize,frameon=False,loc='lower right')
    plt.xlim(xmin=zmin,xmax=zmax)
    plt.ylim(ymin=ymin_x)
    plt.savefig(RESULTS_PATH+'xs{}.pdf'.format(label), 
                bbox_extra_artists=[xlabel, ylabel], 
                bbox_inches='tight')


    
    # plot ionization history
    #plt.figure()
    #ax = plt.gca()
    #xlabel = ax.set_xlabel('z',fontsize=fontsize)
    #ylabel = ax.set_ylabel('$x_H$',fontsize=fontsize)
    #plt.plot(zs_21cmfast,xH_21cmfast,lw=4,color='red')
    #plt.savefig(RESULTS_PATH+'xion{}.pdf'.format(label), 
    #            bbox_extra_artists=[xlabel, ylabel], 
    #            bbox_inches='tight')

    # plot T's
    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z',fontsize=fontsize)
    ylabel = ax.set_ylabel('T [K]',fontsize=fontsize)
    plt.plot(zs_21cmfast,Tss_21cmfast,lw=4,color='k',label='$T_s$')
    plt.plot(zs_21cmfast,Tgs_21cmfast,'--',lw=4,color='g',label=r'$T_{\gamma}$')
    plt.plot(zs_21cmfast,Tks_21cmfast,'--',dashes=(15,5),lw=4,color='b',label='$T_k$')
    plt.legend(fontsize=fontsize,frameon=False,loc='upper left')
    plt.xlim(xmin=zmin,xmax=zmax)
    plt.ylim(ymax=ymax_T)
    #if filenames_uncertainty is not None:
    #    maxind = min(len(Tss_21cmfast_lo),len(Tss_21cmfast_hi))-1
    #    ax.fill_between(zs_21cmfast_lo[:maxind], Tss_21cmfast_lo[:maxind], Tss_21cmfast_hi[:maxind], 
    #                    facecolor='gray', interpolate=True, alpha=0.4, lw=0)
    plt.savefig(RESULTS_PATH+'Ts{}.pdf'.format(label), 
                bbox_extra_artists=[xlabel, ylabel], 
                bbox_inches='tight')
예제 #14
0
def arb_reion_models(zmin=15,zmax=27, nzs=100,
           fontsize=24,root=RESULTS_PATH,
           filenames=['global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__midFSTAR','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__hiFSTAR','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__loFSTAR','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX1.0e+56_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__fesc-ok','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX5.0e+55_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc__low-zetax','global_evolution_zetaIon31.50_Nsteps40_zprimestepfactor1.020_zetaX2.0e+55_alphaX1.2_TvirminX1.0e+04_Pop3_300_200Mpc'],
           labels=['mid f*','hi f*','lo f*','fesc ok','zetax 0.5', 'zetax 0.2']):
    """
    """

    if labels is None:
        labels = np.arange(len(filenames))
    Tks = {}
    Tgs = {}
    Tss = {}
    Jlyas = {}
    zs = {}
    
    for i,fn in enumerate(filenames):
        file_21cmfast = np.loadtxt(INPUTS_PATH+fn)
        Tks[labels[i]] = file_21cmfast[:,2][::-1]
        Tgs[labels[i]] = file_21cmfast[:,5][::-1]
        Tss[labels[i]] = file_21cmfast[:,4][::-1]
        Jlyas[labels[i]] = file_21cmfast[:,6][::-1]
        zs[labels[i]] = file_21cmfast[:,0][::-1]
    

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z',fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$J_{Ly\alpha}$ [$cm^{-2} sec^{-1} Hz^{-1}sr^{-1}$]',fontsize=fontsize)
    for l in labels:
        ax.semilogy(zs[l],Jlyas[l],lw=4,label='{}'.format(l))
    ax.set_xlim(xmin=zmin,xmax=zmax)
    plt.legend(loc='lower left')


    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z',fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$T_S$ [K]',fontsize=fontsize)
    for l in labels:
        plt.plot(zs[l],Tss[l],lw=4,label='{}'.format(l))
    plt.legend(loc='upper left',fontsize=fontsize)
    plt.xlim(xmin=zmin,xmax=zmax)
    plt.ylim(ymax=100)

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z',fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$T_K$ [K]',fontsize=fontsize)
    for l in labels:
        plt.plot(zs[l],Tks[l],lw=4,label='{}'.format(l))
    plt.legend(loc='upper left',fontsize=fontsize)
    plt.xlim(xmin=zmin,xmax=zmax)
    plt.ylim(ymax=100)

    plt.figure()
    ax = plt.gca()
    xlabel = ax.set_xlabel('z',fontsize=fontsize)
    ylabel = ax.set_ylabel(r'$x_c$',fontsize=fontsize)
    for l in labels:
        xc = []
        for i,z in enumerate(zs[l]):
            xc.append(rf.val_xc(z, Tk=Tks[l][i], Tg=Tgs[l][i]))
        plt.semilogy(zs[l],xc,lw=4,label='{}'.format(l))
    plt.legend(loc='lower right',fontsize=fontsize)
    plt.xlim(xmin=zmin,xmax=zmax)
    plt.ylim(ymin=1e-6)