Skip to content

Commit

Permalink
removed duplicate funcs in test_rays.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nastasha-w committed Sep 19, 2024
1 parent acd59c7 commit 6f34755
Showing 1 changed file with 5 additions and 34 deletions.
39 changes: 5 additions & 34 deletions yt/data_objects/tests/test_rays.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from yt import load
from yt.testing import (
assert_rel_equal,
cubicspline_python,
fake_random_ds,
fake_sph_grid_ds,
integrate_kernel,
requires_file,
requires_module,
)
Expand Down Expand Up @@ -84,39 +86,8 @@ def test_ray_particle():
# non-overlapping smoothing regions with a radius of 0.05, masses of
# 1, and densities of 1, and zero velocity.


# it seems like I can't import the kernel functions from the .pxd
# file, so I'm defining the spline function for basic python
def _cubicspline_python(x):
"""
tested: volume integral is 1.
"""
# C is 8/pi
_c = 8.0 / np.pi
x = np.asarray(x)
kernel = np.zeros(x.shape, dtype=x.dtype)
half1 = np.where(np.logical_and(x >= 0.0, x <= 0.5))
kernel[half1] = 1.0 - 6.0 * x[half1] ** 2 * (1.0 - x[half1])
half2 = np.where(np.logical_and(x > 0.5, x <= 1.0))
kernel[half2] = 2.0 * (1.0 - x[half2]) ** 3
return kernel * _c


def _integrate_kernel(kernelfunc, b, hsml):
pre = 1.0 / hsml**2
x = b / hsml
xmax = np.sqrt(1.0 - x**2)
xmin = -1.0 * xmax
xe = np.linspace(xmin, xmax, 500) # shape: 500, x.shape
xc = 0.5 * (xe[:-1, ...] + xe[1:, ...])
dx = np.diff(xe, axis=0)
spv = kernelfunc(np.sqrt(xc**2 + x**2))
integral = np.sum(spv * dx, axis=0)
return pre * integral


def test_ray_particle2():
kernelfunc = _cubicspline_python
kernelfunc = cubicspline_python
ds = fake_sph_grid_ds(hsml_factor=1.0)
ds.kernel_name = "cubic"

Expand All @@ -139,7 +110,7 @@ def test_ray_particle2():
assert_equal(ray0["t"].shape, (1,))
assert_rel_equal(ray0["t"], np.array([0.5]), 5)
assert_rel_equal(ray0[("gas", "position")].v, np.array([[0.5, 0.5, 0.5]]), 5)
dl0 = _integrate_kernel(kernelfunc, b0, hsml0)
dl0 = integrate_kernel(kernelfunc, b0, hsml0)
dl0 *= ray0[("gas", "mass")].v / ray0[("gas", "density")].v
assert_rel_equal(ray0[("dts")].v, dl0 / len0, 4)

Expand All @@ -163,7 +134,7 @@ def test_ray_particle2():
assert_rel_equal(
ray1[("gas", "position")].v, np.array([[1.5, 0.5, 1.5], [1.5, 0.5, 2.5]]), 5
)
dl1 = _integrate_kernel(kernelfunc, b1, hsml1)
dl1 = integrate_kernel(kernelfunc, b1, hsml1)
dl1 *= ray1[("gas", "mass")].v / ray1[("gas", "density")].v
assert_rel_equal(ray1[("dts")].v, dl1 / len1, 4)

Expand Down

0 comments on commit 6f34755

Please sign in to comment.