diff --git a/tardis/montecarlo/montecarlo_numba/tests/test_packet.py b/tardis/montecarlo/montecarlo_numba/tests/test_packet.py index 752378cb51b..891a213928d 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/test_packet.py +++ b/tardis/montecarlo/montecarlo_numba/tests/test_packet.py @@ -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 diff --git a/tardis/montecarlo/tests/test_montecarlo.py b/tardis/montecarlo/tests/test_montecarlo.py index 80d131a8e4c..363d54be899 100644 --- a/tardis/montecarlo/tests/test_montecarlo.py +++ b/tardis/montecarlo/tests/test_montecarlo.py @@ -238,120 +238,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 diff --git a/tardis/transport/tests/test_doppler_factor.py b/tardis/transport/tests/test_doppler_factor.py new file mode 100644 index 00000000000..4d1ff158970 --- /dev/null +++ b/tardis/transport/tests/test_doppler_factor.py @@ -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)