<commit_before># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

import os

# Third-party
import astropy.units as u
from astropy.utils.data import get_pkg_data_filename
from astropy.constants import G as _G
G = _G.decompose([u.kpc,u.Myr,u.Msun]).value
import matplotlib as mpl
import matplotlib.pyplot as pl
import numpy as np
import gala.potential as gp
from gala.units import galactic
from scipy.integrate import quad

# Project
from ..core import compute_coeffs
from .._bfe import potential, density, gradient

# Check that we get A000=1. for putting in hernquist density
def hernquist_density(x, y, z, M, r_s):
    r = np.sqrt(x**2 + y**2 + z**2)
    return M/(2*np.pi) * r_s / (r * (r+r_s)**3)

def test_hernquist():
    for M in [1E5, 1E10]:
        for r_s in np.logspace(-1,2,4):
            (S,Serr),(T,Terr) = compute_coeffs(hernquist_density, nmax=0, lmax=0,
                                               M=M, r_s=r_s, args=(M, r_s))

            np.testing.assert_allclose(S, 1.)
            np.testing.assert_allclose(Serr, 0., atol=1E-10)

            np.testing.assert_allclose(T, 0.)
            np.testing.assert_allclose(Terr, 0., atol=1E-10)

# ----------------------------------------------------------------------------

def _plummer_density(x, y, z, M, r_s):
    r2 = x*x + y*y + z*z
    return (3*M / (4*np.pi*r_s**3)) * (1 + r2/r_s**2)**(-5/2.)

def test_plummer():
    true_M = 1/G
    true_r_s = 1.

    x = np.logspace(-2,1,512)
    xyz = np.zeros((len(x),3))
    xyz[:,0] = x

    pot = gp.PlummerPotential(m=true_M, b=true_r_s, units=galactic)
    true_pot = pot.value(xyz.T).value
    true_dens = pot.density(xyz.T).value<commit_msg>change atol<commit_after># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

import os

# Third-party
from astropy import log as logger
import astropy.units as u
from astropy.utils.data import get_pkg_data_filename
from astropy.constants import G as _G
G = _G.decompose([u.kpc,u.Myr,u.Msun]).value
import matplotlib as mpl
import matplotlib.pyplot as pl
import numpy as np
import gala.potential as gp
from gala.units import galactic
from scipy.integrate import quad

# Project
from ..core import compute_coeffs
from .._bfe import potential, density, gradient

# Check that we get A000=1. for putting in hernquist density
def hernquist_density(x, y, z, M, r_s):
    r = np.sqrt(x**2 + y**2 + z**2)
    return M/(2*np.pi) * r_s / (r * (r+r_s)**3)

def test_hernquist():
    for M in [1E5, 1E10]:
        for r_s in np.logspace(-1,2,4):
            (S,Serr),(T,Terr) = compute_coeffs(hernquist_density, nmax=0, lmax=0,
                                               M=M, r_s=r_s, args=(M, r_s))

            np.testing.assert_allclose(S, 1.)
            np.testing.assert_allclose(Serr, 0., atol=1E-10)

            np.testing.assert_allclose(T, 0.)
            np.testing.assert_allclose(Terr, 0., atol=1E-10)

def test_hernquist_spherical():
    (S,Serr),(T,Terr) = compute_coeffs(hernquist_density, nmax=8, lmax=8,
                                       M=1., r_s=1., args=(1., 1.), skip_m=True)

    np.testing.assert_allclose(S[0,0,0], 1., atol=1E-13)
    np.testing.assert_allclose(S[1:,:,:], 0., atol=1E-13)
    np.testing.assert_allclose(Serr, 0., atol=1E-10)

    np.testing.assert_allclose(T, 0., atol=1E-13)
    np.testing.assert_allclose(Terr, 0., atol=1E-10)

# ----------------------------------------------------------------------------

def _plummer_density(x, y, z, M, r_s):
    r2 = x*x + y*y + z*z
    return (3*M / (4*np.pi*r_s**3)) * (1 + r2/r_s**2)**(-5/2.)

def test_plummer():
    true_M = 1/G
    true_r_s = 1.

    x = np.logspace(-2,1,512)
    xyz = np.zeros((len(x),3))
    xyz[:,0] = x

    pot = gp.PlummerPotential(m=true_M, b=true_r_s, units=galactic)
    true_pot = pot.value(xyz.T).value
    true_dens = pot.density(xyz.T).value
{'fraction_non_alphanumeric': 0.18135376756066413, 'fraction_numerical': 0.03218390804597701, 'mean_word_length': 2.5058191584601612, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5262769', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1523, 'n_words': 340}