Beispiel #1
0
def drhonfw(c,delta,z,omegam,omegal,h,alp,bet,renc,Mrenc,rmin,rmax,r):
    '''Calculates dlnrhodlnr for a generalised NFW profile'''

    rs = findrs(c,delta,z,omegam,omegal,h,alp,bet,renc,Mrenc,rmin,rmax)

    print 'rs found:', rs, c, alp, bet

    rho = (r/rs)**(-alp)*(1+r/rs)**(alp-bet)

    lnr = log(r)
    lnrho = log(rho)

    return derivative(lambda x: interp(x,lnr,lnrho,left=0,right=0),lnr)
Beispiel #2
0
def drhonfw(c, delta, z, omegam, omegal, h, alp, bet, renc, Mrenc, rmin, rmax,
            r):
    '''Calculates dlnrhodlnr for a generalised NFW profile'''

    rs = findrs(c, delta, z, omegam, omegal, h, alp, bet, renc, Mrenc, rmin,
                rmax)

    print 'rs found:', rs, c, alp, bet

    rho = (r / rs)**(-alp) * (1 + r / rs)**(alp - bet)

    lnr = log(r)
    lnrho = log(rho)

    return derivative(lambda x: interp(x, lnr, lnrho, left=0, right=0), lnr)
Beispiel #3
0
def dlnrhodlnr(rmin, rmax, alphalim, r, rho, mass, R, sigma, massp, rin):
    '''Numerically differentiates the density distribution to obtain a
    non-parameteric measure of the power law exponent as a function of
    radius'''

    lnr = log(r)
    lnrho = log(rho)
    lnrin = log(rin)

    # Find match points:
    rmin, rmax, sigc_in, sigc_out, Ain, alpin, Aout, m0 = \
          findmatchpoints(rmin,rmax,alphalim,R,sigma,massp)

    # Find array elements in r corresponding to rmin/rmax: We use r[1] and not
    # r[0] for the low range because interpolation at r[0] is unreliable.
    jl = 1 if rmin < r[1] else argmin(abs(r - rmin))
    jr = -1 if rmax > r[-1] else argmin(abs(r - rmax))

    #print rmin, rmax, r[jl], r[jr]

    rmin = r[jl]
    rmax = r[jr]

    # Calculate inner/outer power law match values:
    rhoc_in = rho[jl]
    rhoc_out = rho[jr]

    # Inner power [consistent with known enclosed mass & smooth rho]
    menc_in_real = mass[jl]
    gamin = 3 - rhoc_in * 4 * pi / menc_in_real * rmin**3
    Ain = rhoc_in * rmin**gamin

    # Outer power consistent with alphalim
    gamout = alphalim + 1
    Aout = rhoc_out * rmax**gamout

    # Interpolate for rmin<r<rmax; power law otherwise:
    output = empty(len(rin), 'double')
    output = derivative(lambda x: interp(x, lnr, lnrho, left=0, right=0),
                        lnrin)

    w = rin > rmax
    output[w] = -gamout
    w = rin < rmin
    output[w] = -gamin

    return output
Beispiel #4
0
def dSigdR(rmin, rmax, alphalim, R, sigma, massp, rin):
    '''dSigdR function to calculate and interpolate derivative of the surface
    density. It sews on power laws where there are no data.'''

    # Find match points:
    rmin, rmax, sigc_in, sigc_out, Ain, alpin, Aout, m0 = \
          findmatchpoints(rmin,rmax,alphalim,R,sigma,massp)

    # Interpolate for rmin<r<rmax; power law otherwise:
    output = empty(len(rin), 'double')
    output = derivative(lambda x: interp(x, R, sigma), rin)
    w = rin > rmax
    output[w] = -alphalim * Aout * rin[w]**(-alphalim - 1)
    w = rin < rmin
    output[w] = -alpin * Ain * rin[w]**(-alpin - 1)

    return output
Beispiel #5
0
def dSigdR(rmin,rmax,alphalim,R,sigma,massp,rin):
    '''dSigdR function to calculate and interpolate derivative of the surface
    density. It sews on power laws where there are no data.'''

    # Find match points:
    rmin, rmax, sigc_in, sigc_out, Ain, alpin, Aout, m0 = \
          findmatchpoints(rmin,rmax,alphalim,R,sigma,massp)

    # Interpolate for rmin<r<rmax; power law otherwise:
    output = empty(len(rin), 'double')
    output = derivative(lambda x: interp(x,R,sigma), rin)
    w = rin > rmax
    output[w] = -alphalim*Aout*rin[w]**(-alphalim-1)
    w = rin < rmin
    output[w] = -alpin*Ain*rin[w]**(-alpin-1)

    return output
Beispiel #6
0
def dlnrhodlnr(rmin,rmax,alphalim,r,rho,mass,R,sigma,massp,rin):
    '''Numerically differentiates the density distribution to obtain a
    non-parameteric measure of the power law exponent as a function of
    radius'''

    lnr = log(r)
    lnrho = log(rho)
    lnrin = log(rin)

    # Find match points:
    rmin, rmax, sigc_in, sigc_out, Ain, alpin, Aout, m0 = \
          findmatchpoints(rmin,rmax,alphalim,R,sigma,massp)

    # Find array elements in r corresponding to rmin/rmax: We use r[1] and not
    # r[0] for the low range because interpolation at r[0] is unreliable. 
    jl =  1 if rmin < r[1]  else argmin(abs(r-rmin)) 
    jr = -1 if rmax > r[-1] else argmin(abs(r-rmax))        

    #print rmin, rmax, r[jl], r[jr]

    rmin = r[jl]
    rmax = r[jr]

    # Calculate inner/outer power law match values:
    rhoc_in   = rho[jl]
    rhoc_out  = rho[jr]

    # Inner power [consistent with known enclosed mass & smooth rho]
    menc_in_real = mass[jl]
    gamin = 3 - rhoc_in*4*pi/menc_in_real*rmin**3
    Ain = rhoc_in * rmin**gamin

    # Outer power consistent with alphalim
    gamout = alphalim + 1
    Aout = rhoc_out * rmax**gamout

    # Interpolate for rmin<r<rmax; power law otherwise:
    output = empty(len(rin), 'double')
    output = derivative(lambda x: interp(x,lnr,lnrho,left=0,right=0),lnrin)

    w = rin > rmax
    output[w] = -gamout
    w = rin < rmin
    output[w] = -gamin

    return output
Beispiel #7
0
def cumsolve(r, imagemin, imagemax, integrator, intpnts, alphalim, R, sigma,
             massp):
    '''Solve the Abel integral to obtain M(r) and then rho(r). This routine
    performs better than abelsolve() and ought to be used instead where
    possible.'''

    # Some asserts to check the inputs are all sensible:
    assert imagemin >= 0,\
           'Imagemin %f < 0' % imagemin
    assert imagemin < imagemax,\
           'Imagemin %f > Imagemax %f' % (imagemin, imagemax)
    assert imagemax > 0,\
           'Imagemax %f < 0' % imagemax
    assert intpnts > 0,\
           'inpnts %i <= 0' % intpnts
    assert alphalim > 0,\
           'alphalim %f < 0' % alphalim
    assert alphalim >= 2,\
           'alphalim %f < 2 (this alphalim gives > "log-infinite" mass)' % \
           alphalim

    theta = linspace(0, pi / 2 - 1e-6, num=intpnts)
    cth = cos(theta)
    sth = sin(theta)
    massout = empty(len(r), 'double')
    for i in xrange(len(r)):
        y = sigmaint(imagemin,imagemax,alphalim,R,sigma,massp,r[i]/cth)*\
            (1/cth**2-sth/cth**3*arctan(cth/sth))
        massout[i] = -4 * r[i]**2 * integrator(y, theta)

    massout = massout + \
              masspint(imagemin,imagemax,alphalim,R,sigma,massp,r)

    # Calculate the density as the derivative of massout:
    rhoout = derivative(lambda x: interp(x,r,massout,right=0),r)/\
             (4*pi*r**2)
    rhoout[-1] = 0

    return rhoout, massout
Beispiel #8
0
def cumsolve(r,imagemin,imagemax,integrator,intpnts,alphalim,R,sigma,massp):
    '''Solve the Abel integral to obtain M(r) and then rho(r). This routine
    performs better than abelsolve() and ought to be used instead where
    possible.'''

    # Some asserts to check the inputs are all sensible:
    assert imagemin >= 0,\
           'Imagemin %f < 0' % imagemin
    assert imagemin < imagemax,\
           'Imagemin %f > Imagemax %f' % (imagemin, imagemax)
    assert imagemax > 0,\
           'Imagemax %f < 0' % imagemax
    assert intpnts > 0,\
           'inpnts %i <= 0' % intpnts
    assert alphalim > 0,\
           'alphalim %f < 0' % alphalim
    assert alphalim >= 2,\
           'alphalim %f < 2 (this alphalim gives > "log-infinite" mass)' % \
           alphalim

    theta = linspace(0,pi/2-1e-6,num=intpnts)
    cth = cos(theta)
    sth = sin(theta)
    massout = empty(len(r), 'double')
    for i in xrange(len(r)):
        y = sigmaint(imagemin,imagemax,alphalim,R,sigma,massp,r[i]/cth)*\
            (1/cth**2-sth/cth**3*arctan(cth/sth))        
        massout[i] = -4*r[i]**2*integrator(y,theta)

    massout = massout + \
              masspint(imagemin,imagemax,alphalim,R,sigma,massp,r)

    # Calculate the density as the derivative of massout:
    rhoout = derivative(lambda x: interp(x,r,massout,right=0),r)/\
             (4*pi*r**2)
    rhoout[-1] = 0

    return rhoout, massout
Beispiel #9
0
def C(n, u):
    num = derivative(lambda z: P(z, u), n, order=5)
    den = derivative(lambda z: E(z, u), n, order=5)
    return num / den
Beispiel #10
0
def P(n, u):
    return n * derivative(lambda z: E(z, u), n, order=5, dx=1e-5) - E(n, u)
Beispiel #11
0
 def dsurf(self, r, pars):
     '''Calculates radial derivative of surface density'''
     return derivative(lambda x: interp(x, self.rsin, self.sdenin, right=0),
                       r)
Beispiel #12
0
def C(n, u):
    num = derivative(lambda z: P(z, u), n, order = 5)
    den = derivative(lambda z: E(z, u), n, order = 5)
    return num/den
Beispiel #13
0
def P(n, u):
    return n*derivative(lambda z: E(z, u), n, order = 5, dx=1e-5) - E(n, u)
Beispiel #14
0
 def dsurf(self, r, pars):
     '''Calculates radial derivative of surface density'''
     return derivative(lambda x: interp(x,self.rsin,self.sdenin,right=0), r)
def df(x):
    return derivative(f, x, dx=1e-6)
Beispiel #16
0
def corenfw_tides_dlnrhodlnr(r,M200,c,rc,n,rt,delta):
    dden = derivative(\
        lambda x: corenfw_tides_den(x,M200,c,rc,n,rt,delta),\
        r,dx=1e-6)
    dlnrhodlnr = dden / corenfw_tides_den(r,M200,c,rc,n,rt,delta) * r
    return dlnrhodlnr
Beispiel #17
0
def Vs(wr, n):
    return derivative(wr.P, n, dx=1e-1,order = 5)/derivative(wr.E, n, dx=1e-1,order = 5)
Beispiel #18
0
def Vs(wr, n):
    return derivative(wr.P, n, dx=1e-1, order=5) / derivative(
        wr.E, n, dx=1e-1, order=5)