Skip to content

Commit

Permalink
Merge e6014cf into 44b2f47
Browse files Browse the repository at this point in the history
  • Loading branch information
sonachitchyan authored Aug 9, 2023
2 parents 44b2f47 + e6014cf commit 4f219ae
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 160 deletions.
46 changes: 0 additions & 46 deletions tardis/montecarlo/montecarlo_numba/tests/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,52 +154,6 @@ def test_calculate_tau_electron(electron_density, distance):
assert_almost_equal(actual, expected)


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(0.3, 7.5e14, 1 / 5.2e7, 0.9998556693818854),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_doppler_factor(mu, r, inv_t_exp, expected):
# Set the params from test cases here
# TODO: add relativity tests
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = frame_transformations.get_doppler_factor(r, mu, time_explosion)

# Perform required assertions
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(0.3, 7.5e14, 1 / 5.2e7, 1 / 0.9998556693818854),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_inverse_doppler_factor(mu, r, inv_t_exp, expected):
# Set the params from test cases here
# TODO: add relativity tests
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = frame_transformations.get_inverse_doppler_factor(
r, mu, time_explosion
)

# Perform required assertions
assert_almost_equal(obtained, expected)


def test_get_random_mu(set_seed_fixture):
"""
Ensure that different calls results
Expand Down
114 changes: 0 additions & 114 deletions tardis/montecarlo/tests/test_montecarlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,120 +192,6 @@ def test_binary_search(x, x_insert, imin, imax, expected_params):
assert obtained_result == expected_params["result"]


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(0.3, 7.5e14, 1 / 5.2e7, 0.9998556693818854),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_doppler_factor(mu, r, inv_t_exp, expected):
# Set the params from test cases here
# TODO: add relativity tests
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = get_doppler_factor(r, mu, time_explosion)

# Perform required assertions
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(["mu", "r", "inv_t_exp"], [(-0.3, 5, 1e10)])
def test_unphysical_doppler_factor(mu, r, inv_t_exp):
# Set the params from test cases here
# TODO: add relativity tests
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables
with pytest.raises(r_packet.SuperluminalError):
obtained = get_doppler_factor(r, mu, time_explosion)


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(0.3, 7.5e14, 1 / 5.2e7, 1 / 0.9998556693818854),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_inverse_doppler_factor(mu, r, inv_t_exp, expected):
# Set the params from test cases here
# TODO: add relativity tests
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = r_packet.get_inverse_doppler_factor(r, mu, time_explosion)

# Perform required assertions
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(["mu", "r", "inv_t_exp"], [(-0.3, 5, 1e10)])
def test_unphysical_inverse_doppler_factor(mu, r, inv_t_exp):
# Set the params from test cases here
# TODO: add relativity tests
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables
with pytest.raises(r_packet.SuperluminalError):
obtained = r_packet.get_inverse_doppler_factor(r, mu, time_explosion)


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(-0.3, 10000000, 0.001, 1.0000001000692842),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_doppler_factor_full_relativity(mu, r, inv_t_exp, expected):
# Set the params from test cases here
# TODO: add relativity tests
mc.full_relativity = True
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = get_doppler_factor(r, mu, time_explosion)
mc.full_relativity = False
# Perform required assertions
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(-0.3, 10000000, 0.001, 0.999999899930827),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_inverse_doppler_factor_full_relativity(mu, r, inv_t_exp, expected):
# Set the params from test cases here
# TODO: add relativity tests
mc.full_relativity = True
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = r_packet.get_inverse_doppler_factor(r, mu, time_explosion)
mc.full_relativity = False
# Perform required assertions
assert_almost_equal(obtained, expected)


def test_get_random_mu_different_output():
"""
Ensure that different calls results
Expand Down
191 changes: 191 additions & 0 deletions tardis/transport/tests/test_doppler_factor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import pytest
import numpy as np

import tardis.transport.frame_transformations as frame_transformations
import tardis.montecarlo.montecarlo_numba.r_packet as r_packet

from numpy.testing import (
assert_almost_equal,
)


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(0.3, 7.5e14, 1 / 5.2e7, 0.9998556693818854),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_doppler_factor(mu, r, inv_t_exp, expected):
"""
Checks the get_doppler_factor function.
Parameters
----------
mu : float
Angle of movement of the packet.
r : float
Radius of the position of the packet.
inv_t_exp : float
Inverse of t_explosion.
expected : float
Expected value of the doppler factor.
"""
# Set the params from test cases here
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = frame_transformations.get_doppler_factor(r, mu, time_explosion)

# Perform required assertions
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(
["mu", "beta", "expected"],
[
(0.3, 0.2, 0.94),
(-0.3, 0, 1.0),
(0, 0.8, 1.0),
],
)
def test_get_doppler_factor_partial_relativity(mu, beta, expected):
"""
Checks the get_doppler_factor_partial_relativity.
Parameters
----------
mu : float
Angle of movement of the packet.
beta : float
Velocity over speed of light for the packet.
expected : float
Expected value of the doppler factor.
"""
obtained = frame_transformations.get_doppler_factor_partial_relativity(
mu, beta
)
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(
["mu", "beta", "expected"],
[
(0.3, 0.2, 0.95938348),
(-0.3, 0, 1.0),
(0, 0.8, 1.6666667),
],
)
def test_get_doppler_factor_full_relativity(mu, beta, expected):
"""
Checks the get_doppler_factor_full_relativity.
Parameters
----------
mu : float
Angle of movement of the packet.
beta : float
Velocity over speed of light for the packet.
expected : float
Expected value of the doppler factor.
"""
obtained = frame_transformations.get_doppler_factor_full_relativity(
mu, beta
)
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(
["mu", "r", "inv_t_exp", "expected"],
[
(0.3, 7.5e14, 1 / 5.2e7, 1 / 0.9998556693818854),
(-0.3, 0, 1 / 2.6e7, 1.0),
(0, 1, 1 / 2.6e7, 1.0),
],
)
def test_get_inverse_doppler_factor(mu, r, inv_t_exp, expected):
"""
Checks the get_inverse_doppler_factor function.
Parameters
----------
mu : float
Angle of movement of the packet.
r : float
Radius of the position of the packet.
inv_t_exp : float
Inverse of t_explosion.
expected : float
Expected value of the inverse doppler factor.
"""
# Set the params from test cases here
time_explosion = 1 / inv_t_exp

# Perform any other setups just before this, they can be additional calls
# to other methods or introduction of some temporary variables

obtained = frame_transformations.get_inverse_doppler_factor(
r, mu, time_explosion
)

# Perform required assertions
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(
["mu", "beta", "expected"],
[
(0.3, 0.2, 1 / 0.94),
(-0.3, 0, 1.0),
(0, 0.8, 1.0),
],
)
def test_get_inverse_doppler_factor_partial_relativity(mu, beta, expected):
"""
Checks the get_inverse_doppler_factor_partial_relativity function.
Parameters
----------
mu : float
Angle of movement of the packet.
beta : float
Velocity over speed of light for the packet.
expected : float
Expected value of the inverse doppler factor.
"""
obtained = (
frame_transformations.get_inverse_doppler_factor_partial_relativity(
mu, beta
)
)
assert_almost_equal(obtained, expected)


@pytest.mark.parametrize(
["mu", "beta", "expected"],
[
(0.3, 0.2, 1.0818579),
(-0.3, 0, 1.0),
(0, 0.8, 1.6666667),
],
)
def test_get_inverse_doppler_factor_full_relativity(mu, beta, expected):
"""
Checks the get_inverse_doppler_factor_full_relativity function.
Parameters
----------
mu : float
Angle of movement of the packet.
beta : float
Velocity over speed of light for the packet.
expected : float
Expected value of the inverse doppler factor.
"""
obtained = frame_transformations.get_inverse_doppler_factor_full_relativity(
mu, beta
)
assert_almost_equal(obtained, expected)

0 comments on commit 4f219ae

Please sign in to comment.