contraction_agama.py
def contract_agama_potential(dm_pot, baryon_pot, fbar=0.157,rmax=500, rmin=0.1):
    '''Given spherical DM and axisymmetric baryon agama potentials,
    creates a contracted DM agama potential using procedure found in Cautun 20'''
    r_space =  np.geomspace(rmin,rmax,501)
    xyz = np.stack((r_space,np.zeros_like(r_space),np.zeros_like(r_space))).transpose()
    
    dens_dm = dm_pot.density(xyz)
    try:
        Mcum_dm = np.array([dm_pot.totalMass(r) for r in r_space])
        Mcum_bar = np.array([baryon_pot.totalMass(r) for r in r_space])
    except Exception: # Assume Old agama, no totalMass 
        Mcum_dm = Mcum_from_sph_dens(r_space, dm_pot.density)
        Mcum_bar = Mcum_from_axi_dens(r_space, baryon_pot.density)

    if fbar == 0.157:
        dens_bar = density_from_enclosed_mass(r_space,Mcum_bar,r_space) #note spherical average
        dens_contracted = contract_density_fit(dens_dm,dens_bar,Mcum_dm,Mcum_bar,fbar)
    else:
        Mcum_contracted = contract_enclosed_mass(Mcum_dm, Mcum_bar,fbar)
        dens_contracted = density_from_enclosed_mass(r_space,Mcum_contracted,r_space)
    # create a cubic spline interpolator in log-log space
    dens_contracted_interp = agama.CubicSpline(np.log(r_space), np.log(dens_contracted), reg=True)

    def contracted_dens_func(xyz):
        return np.exp(dens_contracted_interp(np.log(np.sum(xyz**2, axis=1))*0.5))
    contracted_pot = agama.Potential(type="Multipole", density=contracted_dens_func,
         symmetry="spherical", rmin=rmin, rmax=rmax)

    contracted_pot = agama.Potential(type="Multipole", density=contracted_dens_func,
                                     symmetry="spherical", rmin=1e-3, rmax=1e3)
    return contracted_pot
Given spherical DM and axisymmetric baryon agama potentials,
    creates a contracted DM agama potential using procedure found in Cautun 20
Given spherical DM and axisymmetric baryon agama potentials,
creates a contracted DM agama potential using procedure found in Cautun 20
Given spherical DM and axisymmetric baryon agama potentials creates a contracted DM agama potential using procedure found in Cautun 20
def contract_agama_potential(dm_pot, baryon_pot, fbar=0.157,rmax=500, rmin=0.1):
    r_space =  np.geomspace(rmin,rmax,501)
    xyz = np.stack((r_space,np.zeros_like(r_space),np.zeros_like(r_space))).transpose()
    dens_dm = dm_pot.density(xyz)
    try:
        Mcum_dm = np.array([dm_pot.totalMass(r) for r in r_space])
        Mcum_bar = np.array([baryon_pot.totalMass(r) for r in r_space])
    except Exception: 
        Mcum_dm = Mcum_from_sph_dens(r_space, dm_pot.density)
        Mcum_bar = Mcum_from_axi_dens(r_space, baryon_pot.density)
    if fbar == 0.157:
        dens_bar = density_from_enclosed_mass(r_space,Mcum_bar,r_space) 
        dens_contracted = contract_density_fit(dens_dm,dens_bar,Mcum_dm,Mcum_bar,fbar)
    else:
        Mcum_contracted = contract_enclosed_mass(Mcum_dm, Mcum_bar,fbar)
        dens_contracted = density_from_enclosed_mass(r_space,Mcum_contracted,r_space)
    dens_contracted_interp = agama.CubicSpline(np.log(r_space), np.log(dens_contracted), reg=True)
    def contracted_dens_func(xyz):
        return np.exp(dens_contracted_interp(np.log(np.sum(xyz**2, axis=1))*0.5))
    contracted_pot = agama.Potential(type="Multipole", density=contracted_dens_func,
         symmetry="spherical", rmin=rmin, rmax=rmax)
    contracted_pot = agama.Potential(type="Multipole", density=contracted_dens_func,
                                     symmetry="spherical", rmin=1e-3, rmax=1e3)
    return contracted_pot
def contract_agama_potential ( dm_pot , baryon_pot , fbar = 0.157 , rmax = 500 , rmin = 0.1 ) : r_space = np . geomspace ( rmin , rmax , 501 ) xyz = np . stack ( ( r_space , np . zeros_like ( r_space ) , np . zeros_like ( r_space ) ) ) . transpose ( ) dens_dm = dm_pot . density ( xyz ) try : Mcum_dm = np . array ( [ dm_pot . totalMass ( r ) for r in r_space ] ) Mcum_bar = np . array ( [ baryon_pot . totalMass ( r ) for r in r_space ] ) except Exception : Mcum_dm = Mcum_from_sph_dens ( r_space , dm_pot . density ) Mcum_bar = Mcum_from_axi_dens ( r_space , baryon_pot . density ) if fbar == 0.157 : dens_bar = density_from_enclosed_mass ( r_space , Mcum_bar , r_space ) dens_contracted = contract_density_fit ( dens_dm , dens_bar , Mcum_dm , Mcum_bar , fbar ) else : Mcum_contracted = contract_enclosed_mass ( Mcum_dm , Mcum_bar , fbar ) dens_contracted = density_from_enclosed_mass ( r_space , Mcum_contracted , r_space ) dens_contracted_interp = agama . CubicSpline ( np . log ( r_space ) , np . log ( dens_contracted ) , reg = True ) def contracted_dens_func ( xyz ) : return np . exp ( dens_contracted_interp ( np . log ( np . sum ( xyz ** 2 , axis = 1 ) ) * 0.5 ) ) contracted_pot = agama . Potential ( type = "Multipole" , density = contracted_dens_func , symmetry = "spherical" , rmin = rmin , rmax = rmax ) contracted_pot = agama . Potential ( type = "Multipole" , density = contracted_dens_func , symmetry = "spherical" , rmin = 1e-3 , rmax = 1e3 ) return contracted_pot
Given spherical DM and axisymmetric baryon agama potentials,
creates a contracted DM agama potential using procedure found in Cautun 20
Given spherical DM and axisymmetric baryon agama potentials creates a contracted DM agama potential using procedure found in Cautun 20
'''Given spherical DM and axisymmetric baryon agama potentials,
    creates a contracted DM agama potential using procedure found in Cautun 20''' # Assume Old agama, no totalMass  #note spherical average # create a cubic spline interpolator in log-log space
dm_pot
baryon_pot
fbar
rmax
rmin