示例#1
0
def g(rvar, rfix, beta, dbetadr):
    tmp = 1.             # [1]
    tmp -= 2*beta*rfix**2/rvar**2       # [1]
    tmp += beta*(beta+1.)/2.*rfix**4/rvar**4 # [1]
    tmp -= rfix**4/(4.*rvar**3)*dbetadr      # last term of eq. 37 Richardson2012
    gh.checknan(tmp, 'tmp in g')
    return tmp
示例#2
0
def ant_intbeta(r0, betapar, gp):
    xint = 1.*r0
    yint = phys.beta(xint, betapar, gp)[0]/xint
    intbet = np.zeros(len(r0))
    for k in range(len(r0)):
        intbet[k] = gh.quadinf(xint, yint, r0[0], r0[k])
    # assumption here is that integration goes down to min(r0)/1e5
    gh.checknan(intbet, 'intbet in ant_intbeta')
    return intbet
示例#3
0
def kappa(r0fine, Mrfine, nufine, sigr2nu, intbetasfine, gp):
    # for the following: enabled calculation of kappa

    # kappa_r^4
    kapr4nu = np.ones(len(r0fine)-gp.nexp)
    xint  = r0fine                  # [pc]
    yint  = gu.G1__pcMsun_1km2s_2 * Mrfine/r0fine**2  # [1/pc (km/s)^2]
    yint *= nufine                  # [Munit/pc^4 (km/s)^2]
    yint *= sigr2nu               # [Munit/pc^4 (km/s)^4
    yint *= np.exp(intbetasfine)          # [Munit/pc^4 (km/s)^4]
    gh.checkpositive(yint, 'yint in kappa_r^4')
    yscale = 10.**(1.-min(np.log10(yint[1:])))
    yint *= yscale
    # power-law extrapolation to infinity
    C = max(0., gh.quadinflog(xint[-3:], yint[-3:], r0fine[-1], gp.rinfty*r0fine[-1]))

    splpar_nu = splrep(xint, yint, k=3) # interpolation in real space
    for k in range(len(r0fine)-gp.nexp):
        # integrate from minimal radius to infinity
        kapr4nu[k] = 3.*(np.exp(-intbetasfine[k])/nufine[k]) * \
            (splint(r0fine[k], r0fine[-1], splpar_nu) + C) # [(km/s)^4]

    kapr4nu /= yscale
    gh.checkpositive(kapr4nu, 'kapr4nu in kappa_r^4')

    splpar_kap = splrep(r0fine[:-gp.nexp], np.log(kapr4nu), k=3)
    kapr4ext = np.exp(splev(r0ext, splpar_kap))
    kapr4nu = np.hstack([kapr4nu, kapr4ext])
    gh.checkpositive(kapr4nu, 'kapr4nu in extended kappa_r^4')

    dbetafinedr = splev(r0fine, splrep(r0fine, betafine), der=1)
    gh.checknan(dbetafinedr, 'dbetafinedr in kappa_r^4')

    # kappa^4_los*surfdensity
    kapl4s = np.zeros(len(r0fine)-gp.nexp)
    for k in range(len(r0fine)-gp.nexp):
        xnew = np.sqrt(r0fine[k:]**2-r0fine[k]**2)      # [pc]
        ynew = g(r0fine[k:], r0fine[k], betafine[k:], dbetafinedr[k:]) # [1]
        ynew *= nufine[k:] * kapr4nu[k:]
        C = max(0., gh.quadinflog(xnew[-3:], ynew[-3:], xnew[-1], gp.rinfty*xnew[-1]))
        splpar_nu = splrep(xnew,ynew) # not s=0.1, this sometimes gives negative entries after int
        kapl4s[k] = 2. * (splint(0., xnew[-1], splpar_nu) + C)
        #kapl4s[k] /= yscale
        # LOG('ynew = ',ynew,', kapl4s =', kapl4s[k])

    gh.checkpositive(kapl4s, 'kapl4s in kappa_r^4')

    # project kappa4_los as well
    # only use middle values to approximate, without errors in center and far
    kapl4s_out = np.exp(splev(r0, splrep(r0fine[4:-gp.nexp], kapl4s[4:], k=3))) # s=0.
    gh.checkpositive(kapl4s_out, 'kapl4s_out in kappa_r^4')
    return sigl2s_out, kapl4s_out
示例#4
0
def rho_INT_Sig(r0, rho, gp):
    # use splines on variable transformed integral
    # \Sigma(R) = \int_{r=R}^{R=\infty} \rho(r) d \sqrt(r^2-R^2)
    if rho[0] <= 1e-100:
        return np.zeros(gp.nepol)
    gh.checknan(rho, 'rho_INT_Sig')
    # >= 0.1 against rising in last bin. previous: k=2, s=0.1
    # TODO: check use of np.log(r0) here
    splpar_rho = splrep(r0, np.log(rho), k=3, s=0.01)  # 0.01?
    r0ext = np.array([0., r0[0] * 0.25, r0[0] * 0.50, r0[0] * 0.75])
    #dR = r0[1:]-r0[:-1]
    r0nu = np.hstack([r0ext, r0])
    # points in between possible, but not helping much:
    # ,dR*0.25+r0[:-1],dR*0.50+r0[:-1],dR*0.75+r0[:-1]])
    r0nu.sort()
    rhonu = np.exp(splev(r0nu, splpar_rho))
    # extend to higher radii
    splpar_lrhor = splrep(r0[-3:], np.log(rho[-3:]), k=1,
                          s=1.)  # k=2 gives NaN!
    dr0 = (r0[-1] - r0[-2]) / 8.
    r0ext = np.hstack(
        [r0[-1] + dr0, r0[-1] + 2 * dr0, r0[-1] + 3 * dr0, r0[-1] + 4 * dr0])
    rhoext = np.exp(splev(r0ext, splpar_lrhor))
    r0nu = np.hstack([r0nu, r0ext])
    rhonu = np.hstack([rhonu, rhoext])
    gh.checkpositive(rhonu, 'rhonu in rho_INT_Sig')
    Sig = np.zeros(len(r0nu) - 4)
    for i in range(len(r0nu) - 4):
        xnew = np.sqrt(r0nu[i:]**2 - r0nu[i]**2)  # [lunit]
        ynew = 2. * rhonu[i:]
        yscale = 10.**(1. - min(np.log10(ynew)))
        ynew *= yscale
        # power-law extension to infinity
        C = gh.quadinflog(xnew[-4:], ynew[-4:], xnew[-1],
                          gp.rinfty * max(gp.xepol))
        splpar_nu = splrep(
            xnew, ynew,
            k=3)  # interpolation in real space. previous: k=2, s=0.1
        Sig[i] = splint(0., xnew[-1], splpar_nu) + C
    Sig /= yscale
    gh.checkpositive(Sig, 'Sig in rho_INT_Sig')
    Sigout = splev(r0, splrep(r0nu[:-4], Sig))  # [Munit/lunit^2]
    gh.checkpositive(Sigout, 'Sigout in rho_INT_Sig')
    return Sigout
示例#5
0
def rho_INT_Sig(r0, rho, gp):
    # use splines on variable transformed integral
    # \Sigma(R) = \int_{r=R}^{R=\infty} \rho(r) d \sqrt(r^2-R^2)
    if rho[0] <= 1e-100:
        return np.zeros(gp.nepol)
    gh.checknan(rho, 'rho_INT_Sig')
    # >= 0.1 against rising in last bin. previous: k=2, s=0.1
    # TODO: check use of np.log(r0) here
    splpar_rho = splrep(r0, np.log(rho), k=3, s=0.01) # 0.01?
    r0ext = np.array([0., r0[0]*0.25, r0[0]*0.50, r0[0]*0.75])
    #dR = r0[1:]-r0[:-1]
    r0nu = np.hstack([r0ext,r0])
    # points in between possible, but not helping much:
    # ,dR*0.25+r0[:-1],dR*0.50+r0[:-1],dR*0.75+r0[:-1]])
    r0nu.sort()
    rhonu = np.exp(splev(r0nu, splpar_rho))
    # extend to higher radii
    splpar_lrhor   = splrep(r0[-3:],np.log(rho[-3:]),k=1,s=1.) # k=2 gives NaN!
    dr0    = (r0[-1]-r0[-2])/8.
    r0ext  = np.hstack([r0[-1]+dr0, r0[-1]+2*dr0, r0[-1]+3*dr0, r0[-1]+4*dr0])
    rhoext = np.exp(splev(r0ext, splpar_lrhor))
    r0nu   = np.hstack([r0nu, r0ext])
    rhonu  = np.hstack([rhonu, rhoext])
    gh.checkpositive(rhonu, 'rhonu in rho_INT_Sig')
    Sig = np.zeros(len(r0nu)-4)
    for i in range(len(r0nu)-4):
        xnew = np.sqrt(r0nu[i:]**2-r0nu[i]**2)         # [lunit]
        ynew = 2.*rhonu[i:]
        yscale = 10.**(1.-min(np.log10(ynew)))
        ynew *= yscale
        # power-law extension to infinity
        C = gh.quadinflog(xnew[-4:],ynew[-4:],xnew[-1], gp.rinfty*max(gp.xepol))
        splpar_nu  = splrep(xnew,ynew,k=3) # interpolation in real space. previous: k=2, s=0.1
        Sig[i] = splint(0., xnew[-1], splpar_nu) + C
    Sig /= yscale
    gh.checkpositive(Sig, 'Sig in rho_INT_Sig')
    Sigout = splev(r0, splrep(r0nu[:-4], Sig))     # [Munit/lunit^2]
    gh.checkpositive(Sigout, 'Sigout in rho_INT_Sig')
    return Sigout
示例#6
0
def int_poly_inf(r0,poly):
    f = -1/poly[0]*np.exp(poly[1]+poly[0]*r0)
    gh.checknan(f, 'f in int_poly_inf')
    return f