def vikhlinin_temperature_profile(r="r", T_0="T_0", a="a", b="b", c="c", r_t="r_t", T_min="T_min", r_cool="r_cool", a_cool="a_cool"): """ A temperature profile for galaxy clusters from Vikhlinin, A., Kravtsov, A., Forman, W., et al. 2006, ApJ, 640, 691. Parameters ---------- r : string The symbol for the radius variable. T_0 : string The symbol for the scale temperature of the profile. a : string The symbol for the inner logarithmic slope. b : string The symbol for the width of the transition region. c : string The symbol for the outer logarithmic slope. r_t : string The symbol for the scale radius. T_min : string The symbol for the minimum temperature. r_cool : string The symbol for the cooling radius. a_cool : string The symbol for the logarithmic slope in the cooling region. """ r, T_0, a, b, c, r_t, T_min, r_cool, a_cool = \ symbols((r, T_0, a, b, c, r_t, T_min, r_cool, a_cool)) x = (r/r_cool)**a_cool t = (r/r_t)**(-a)/((1.+(r/r_t)**b)**(c/b)) profile = T_0*t*(x+T_min/T_0)/(x+1) return Formula1D(profile, r, [T_0, a, b, c, r_t, T_min, r_cool, a_cool])
def AM06_density_profile(r="r", rho_0="rho_0", a="a", a_c="a_c", c="c", alpha="alpha", beta="beta"): """ The density profile for galaxy clusters suggested by Ascasibar, Y., & Markevitch, M. 2006, ApJ, 650, 102. Works best in concert with the ``AM06_temperature_profile``. Parameters ---------- r : string The symbol for the radius variable. rho_0 : string The symbol for the scale density of the profile. a : string The symbol for the scale radius. a_c : string The symbol for the scale radius of the cool core. c : string The symbol for the scale of the temperature drop of the cool core. alpha : string The symbol for the first slope parameter. beta : string The symbol for the second slope parameter. """ r, rho_0, a, a_c, c, alpha, beta = symbols((r, rho_0, a, a_c, c, alpha, beta)) profile = rho_0*(1+r/a_c)*(1+r/a_c/c)**alpha*(1+r/a)**beta return Formula1D(profile, r, [rho_0, a, a_c, c, alpha, beta])
def linear(x="x", a="a", b="b"): """ A linear formula. Parameters ---------- x : string The symbol for the independent variable. a : string The symbol for the slope of the line. b : string The symbol for the intercept. """ x, a, b = symbols((x, a, b)) formula = a * x + b return Formula1D(formula, x, [a, b])
def hernquist_mass_profile(r="r", M_0="M_0", a="a"): """ A Hernquist mass profile (Hernquist, L. 1990, ApJ, 356, 359). Parameters ---------- r : string The symbol for the radius variable. M_0 : string The symbol for the total mass of the profile. a : string The symbol for the scale radius. """ r, M_0, a = symbols((r, M_0, a)) profile = M_0*r**2/(r+a)**2 return Formula1D(profile, r, [M_0, a])
def hernquist_density_profile(r="r", M_0="M_0", a="a"): """ A Hernquist density profile (Hernquist, L. 1990, ApJ, 356, 359). Parameters ---------- r : string The symbol for the radius variable. M_0 : string The symbol for the total mass of the profile. a : string The symbol for the scale radius. """ r, M_0, a = symbols((r, M_0, a)) profile = M_0/(2*pi*a**3)/((r/a)*(1+r/a)**3) return Formula1D(profile, r, [M_0, a])
def NFW_density_profile(r="r", rho_s="rho_s", r_s="r_s"): """ An NFW density profile (Navarro, J.F., Frenk, C.S., & White, S.D.M. 1996, ApJ, 462, 563). Parameters ---------- r : string The symbol for the radius variable. rho_s : string The symbol for the scale density of the profile. r_s : string The symbol for the scale radius. """ r, rho_s, r_s = symbols((r, rho_s, r_s)) profile = rho_s/((r/r_s)*(1+r/r_s)**2) return Formula1D(profile, r, [rho_s, r_s])
def power_law(x="x", K="K", x_scale="x_scale", alpha="alpha"): """ A power-law formula. Parameters ---------- x : string The symbol for the independent variable. K : string The symbol for the normalization. x_scale : string The symbol for the scale value. alpha : string The symbol for the power-law index. """ x, K, x_scale, alpha = symbols((x, K, x_scale, alpha)) formula = K * (x / x_scale)**alpha return Formula1D(formula, x, [x_scale, K, alpha])
def exponential(x="x", A="A", x_0="x_0", x_s="x_s"): """ An exponential formula. Parameters ---------- x : string The symbol for the independent variable. A : string The symbol for the normalization. x_0 : string The symbol for the y-intercept. x_s : string The symbol for the scale parameter. """ x, A, x_0, x_s = symbols((x, A, x_0, x_s)) formula = A * exp((x - x_0) / x_s) return Formula1D(formula, x, [A, x_0, x_s])
def sNFW_mass_profile(r="r", M="M", a="a"): """ A "super-NFW" mass profile (Lilley, E. J., Wyn Evans, N., & Sanders, J.L. 2018, MNRAS). Parameters ---------- r : string The symbol for the radius variable. M : string The symbol for the total mass of the profile. a : string The symbol for the scale radius. """ r, M, a = symbols((r, M, a)) x = r/a profile = M*(1-(2+3*x)/(2*(1+x)**(3/2))) return Formula1D(profile, r, [M, a])
def sNFW_density_profile(r="r", M="M", a="a"): """ A "super-NFW" density profile (Lilley, E. J., Wyn Evans, N., & Sanders, J.L. 2018, MNRAS). Parameters ---------- r : string The symbol for the radius variable. M : string The symbol for the total mass of the profile. a : string The symbol for the scale radius. """ r, M, a = symbols((r, M, a)) x = r/a profile = 3*M/(16*pi*a**3)/(x*(1+x)**(5/2)) return Formula1D(profile, r, [M, a])
def NFW_mass_profile(r="r", rho_s="rho_s", r_s="r_s"): """ An NFW mass profile (Navarro, J.F., Frenk, C.S., & White, S.D.M. 1996, ApJ, 462, 563). Parameters ---------- r : string The symbol for the radius variable. rho_s : string The symbol for the scale density of the profile. r_s : string The symbol for the scale radius. """ r, rho_s, r_s = symbols((r, rho_s, r_s)) x = r/r_s profile = 4*pi*rho_s*r_s**3*(log(1+x)-x/(1+x)) return Formula1D(profile, r, [rho_s, r_s])
def tNFW_density_profile(r="r", rho_s="rho_s", r_s="r_s", r_t="r_t"): """ A truncated NFW density profile (). Parameters ---------- r : string The symbol for the radius variable. rho_s : string The symbol for the scale density of the profile. r_s : string The symbol for the scale radius. r_t : string The symbol for the truncation radius. """ r, rho_s, r_s, r_t = symbols((r, rho_s, r_s, r_t)) profile = rho_s/((r/r_s)*(1+r/r_s)**2) profile /= (1+(r/r_t)**2) return Formula1D(profile, r, [rho_s, r_s, r_t])
def beta_model_profile(r="r", rho_c="rho_c", r_c="r_c", beta="beta"): """ A beta-model density profile (like for galaxy clusters, Cavaliere A., Fusco-Femiano R., 1976, A&A, 49, 137). Parameters ---------- r : string The symbol for the radius variable. rho_c : string The symbol for the scale density. r_c : string The symbol for the core radius. beta : string The symbol for the beta parameter. """ r, rho_c, r_c, beta = symbols((r, rho_c, r_c, beta)) profile = rho_c*((1+(r/r_c)**2)**(-3*beta/2)) return Formula1D(profile, r, [r_c, rho_c, beta])
def gaussian(x="x", A="A", mu="mu", sigma="sigma"): """ A Gaussian formula. Parameters ---------- x : string The symbol for the independent variable. A : string The symbol for the normalization. mu : string The symbol for the mean. sigma : string The symbol for the standard deviation. """ x, A, mu, sigma = symbols((x, A, mu, sigma)) params = [A, mu, sigma] formula = A * exp(-Rational(1, 2) * ((x - mu) / sigma)**2) / (sigma * sqrt(2 * pi)) return Formula1D(formula, x, params)
def einasto_density_profile(r="r", rho_0="rho_0", h="h", alpha="alpha"): """ A density profile where the logarithmic slope is a power-law. The form here is that given in Equation 5 of Retana-Montenegro et al. 2012, A&A, 540, A70. Parameters ---------- r : string The symbol for the radius variable. rho_0 : string The symbol for the core density. h : string The symbol for the scale radius. alpha : string The symbol for the power-law index. """ r, rho_0, h, alpha = symbols((r, rho_0, h, alpha)) x = r/h profile = rho_0*exp(-x**alpha) return Formula1D(profile, r, [rho_0, h, alpha])
def vikhlinin_density_profile(r="r", rho_0="rho_0", r_c="r_c", r_s="r_s", alpha="alpha", beta="beta", epsilon="epsilon", gamma=None): """ A modified beta-model density profile for galaxy clusters from Vikhlinin, A., Kravtsov, A., Forman, W., et al. 2006, ApJ, 640, 691. Parameters ---------- r : string The symbol for the radius variable. rho_0 : string The symbol for the scale density of the profile. r_c : string The symbol for the core radius. r_s : string The symbol for the scale radius. alpha : string The symbol for the inner logarithmic slope parameter. beta : string The symbol for the middle logarithmic slope parameter. epsilon : string The symbol for the outer logarithmic slope parameter. gamma : string The symbol for controlling the width of the outer transition. If None, it will be gamma = 3 by default. """ r, rho_0, r_c, r_s, alpha, beta, epsilon = \ symbols((r, rho_0, r_c, r_s, alpha, beta, epsilon)) params = [rho_0, r_c, r_s, alpha, beta, epsilon] if gamma is None: gamma = 3 else: gamma = symbols(gamma) params += [gamma] profile = rho_0*(r/r_c)**(-alpha/2) * \ (1+(r/r_c)**2)**(-3*beta/2+alpha/4) * \ (1+(r/r_s)**gamma)**(-epsilon/gamma/2) return Formula1D(profile, r, params)
def baseline_entropy_profile(r="r", K_0="K_0", K_200="K_200", r_200="r_200", alpha="alpha"): """ The baseline entropy profile for galaxy clusters (Voit, G.M., Kay, S.T., & Bryan, G.L. 2005, MNRAS, 364, 909). Parameters ---------- r : string The symbol for the radius variable. K_0 : string The symbol for the central entropy floor. K_200 : string The symbol for the entropy at the radius *r_200*. r_200 : string The symbol for the virial radius of the profile. alpha : string The symbol for the logarithmic slope of the profile. """ r, K_0, K_200, r_200, alpha = symbols((r, K_0, K_200, r_200, alpha)) profile = K_0 + K_200*(r/r_200)**alpha return Formula1D(profile, r, [K_0, K_200, r_200, alpha])
def AM06_temperature_profile(r="r", T_0="T_0", a="a", a_c="a_c", c="c"): """ The temperature profile for galaxy clusters suggested by Ascasibar, Y., & Markevitch, M. 2006, ApJ, 650, 102. Works best in concert with the ``AM06_density_profile``. Parameters ---------- r : string The symbol for the radius variable. T_0 : string The symbol for the scale temperature of the profile. a : string The symbol for the scale radius. a_c : string The symbol for the scale radius of the cool core. c : string The symbol for the scale of the temperature drop of the cool core. """ r, T_0, a, a_c, c = symbols((r, T_0, a, a_c, c)) profile = T_0/(1+r/a)*(c+r/a_c)/(1+r/a_c) return Formula1D(profile, r, [T_0, a, a_c, c])
from formulas.base import Formula1D, Formula2D from formulas.constants import FormulaConstant from numpy.testing import assert_allclose from sympy import Float import yt.units as u f_x = Formula1D("a*x**2+b","x",["a","b"]) g_x = Formula1D("p*cos(c*x)","x",["c","p"]) h_y = Formula1D("k*exp(d*y)","y",["k","d"]) j_o = Formula1D("2*v*o+z", "o", ["v","z"]) a = 50.*u.km/u.s**2 b = 30.*u.km c = 10.*u.s**-1 d = 5.*u.s**-1 k = 10.*u.km p = 20.*u.km v = 3.0 z = 1.5 f_x.set_param_values(a=a, b=b) g_x.set_param_values(p=p, c=c) h_y.set_param_values(k=k, d=d) j_o.set_param_values(v=v, z=z) x = 60.*u.s y = 15.*u.s w = FormulaConstant("w", 2*u.km) o = 3.4 def test_add(): n_x = f_x+g_x assert n_x.ndim == 1 assert isinstance(n_x, Formula1D)
def maxwellian_velocity(v="v", A="A", sigma="sigma"): v, A, sigma = symbols((v, A, sigma)) params = [A, sigma] f = A * exp(-Rational(1, 2) * ((v / sigma)**2)) / (sigma * sqrt(2 * pi)) return Formula1D(f, v, params)
def maxwellian_speed(v="v", A="A", sigma="sigma"): v, A, sigma = symbols((v, A, sigma)) params = [A, sigma] f = A * exp(-Rational(1, 2) * ((v / sigma)**2)) / (sigma * sqrt(2 * pi))**3 return Formula1D(4 * pi * v * v * f, v, params)
from formulas.base import Formula1D, variable, Formula2D from formulas.radial_profiles import NFW_density_profile from formulas.general import gaussian import yt.units as u from numpy.testing import assert_allclose import pytest f_x = Formula1D("a*x**2+b", "x", ["a", "b"]) a = 50. * u.km / u.s**2 b = 30. * u.km f_x.set_param_values(a=a, b=b) g_x = gaussian(x="x", A="A_x", mu="mu_x", sigma="sigma_x") g_y = gaussian(x="y", A="A_y", mu="mu_y", sigma="sigma_y") g_z = gaussian(x="z", A="A_z", mu="mu_z", sigma="sigma_z") A_x = A_y = A_z = 1.0 mu_x = mu_y = mu_z = 30 * u.s sigma_x = sigma_y = sigma_z = 40 * u.s g_x.set_param_values(A_x=A_x, mu_x=mu_x, sigma_x=sigma_x) g_y.set_param_values(A_y=A_y, mu_y=mu_y, sigma_y=sigma_y) g_z.set_param_values(A_z=A_z, mu_z=mu_z, sigma_z=sigma_z) g_xy = g_x * g_y g_xyz = g_xy * g_z x = 60. * u.s y = 25. * u.s z = -10. * u.s def test_unitless():
def cored_hernquist_density_profile(r="r", M_0="M_0", a="a", b="b"): r, M_0, a, b = symbols((r, M_0, a, b)) profile = M_0*b/(2*pi*a**3)/((1+b*r/a)*(1+r/a)**3) return Formula1D(profile, r, [M_0, a, b])