Loading [MathJax]/extensions/TeX/AMSmath.js
LALSimulation 6.2.0.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_liv.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http: //www.gnu.org/licenses/>.
15
16"""Simple test to see if the LIV parameters can be read and inserted correctly
17"""
18
19import sys
20import pytest
21import lal
22import lalsimulation
23import numpy as np
24
25# -- utility functions ---------------------
26
27def read_liv_params(LALparams):
28 """
29 Reads LIV parameters
30 """
31
32 logLeff = lalsimulation.SimInspiralWaveformParamsLookupNonGRLIVLogLambdaEff(LALparams)
33 signOfA = lalsimulation.SimInspiralWaveformParamsLookupNonGRLIVASign(LALparams)
34 alpha = lalsimulation.SimInspiralWaveformParamsLookupNonGRLIVAlpha(LALparams)
35 return logLeff, signOfA, alpha
36
37def set_liv_pars(LALparams, logLeff, Asign, alpha):
38 """
39 Sets LIV parameters according to input values.
40
41 - logLeff: LIV wavelength-like parameter log10lambda_eff to be set.
42 - Asign: LIV sign in dispersion relation, +1.0 or -1.0.
43 - alpha: Exponent of momentum in dispersion relation, between 0 and 4.
44 """
45
46 lalsimulation.SimInspiralWaveformParamsInsertNonGRLIVLogLambdaEff(LALparams, logLeff)
47 lalsimulation.SimInspiralWaveformParamsInsertNonGRLIVASign(LALparams, Asign)
48 lalsimulation.SimInspiralWaveformParamsInsertNonGRLIVAlpha(LALparams, alpha)
49 return None
50
51def is_liv_enabled_by_default(LALparams):
52 """
53 This checks if LIV flag is disabled by default.
54 """
55
56 return lalsimulation.SimInspiralWaveformParamsLookupEnableLIV(LALparams)
57
58def enable_liv(LALparams):
59 """
60 This enables the LIV flag, by enabling it,
61 the LIV parameters will be sampled upon.
62 """
63
64 lalsimulation.SimInspiralWaveformParamsInsertEnableLIV(LALparams, 1)
65 return lalsimulation.SimInspiralWaveformParamsLookupEnableLIV(LALparams)
66
67# -- test functions ---------------------
68
70 """
71 This tests if the default LIV parameters are correct.
72 Additionally it tests LIV parameters are being inserted correctly.
73
74 `expected_result = np.array([100.0,1.0,0.0])` are the default values of log10lambda_eff,
75 A_sign and alpha respectively
76 """
77 LALpars = lal.CreateDict()
78 expected_result = np.array([100.0, 1.0, 0.0])
79 actual_result = np.array(read_liv_params(LALpars))
80 np.testing.assert_almost_equal(actual_result, expected_result, 7, "Default LIV values are not set correctly")
81 ## Checking if parameters can be inserted properly
82 set_liv_pars(LALpars, 44.,-1.,1.5)
83 expected_result = np.array([44., -1., 1.5])
84 actual_result = np.array(read_liv_params(LALpars))
85 np.testing.assert_almost_equal(actual_result, expected_result, 7, "LIV values are not inserted correctly")
86
88 """
89 This tests that the liv flag is disabled by default.
90 Additionally it checks the flag may be enabled properly.
91
92 `expected_result = 0` is the default value of the LIV flag
93 """
94 LALpars = lal.CreateDict()
95 expected_result = 0
96 actual_result = is_liv_enabled_by_default(LALpars)
97 np.testing.assert_approx_equal(actual_result, expected_result, 7, "Incorrect setting of LIV flag by default")
98 ## Now check if it can be inserted correctly
99 expected_result = 1
100 actual_result = enable_liv(LALpars)
101 np.testing.assert_approx_equal(actual_result, expected_result, 7, "LIV flag not inserted correctly")
102
103# -- run the tests ------------------------------
104
105if __name__ == '__main__':
106 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-liv.xml"]
107 sys.exit(pytest.main(args=[__file__] + args))
def enable_liv(LALparams)
This enables the LIV flag, by enabling it, the LIV parameters will be sampled upon.
Definition: test_liv.py:62
def test_liv_flag_disabled_by_default()
This tests that the liv flag is disabled by default.
Definition: test_liv.py:93
def set_liv_pars(LALparams, logLeff, Asign, alpha)
Sets LIV parameters according to input values.
Definition: test_liv.py:44
def read_liv_params(LALparams)
Reads LIV parameters.
Definition: test_liv.py:30
def test_correct_liv_pars()
This tests if the default LIV parameters are correct.
Definition: test_liv.py:76
def is_liv_enabled_by_default(LALparams)
This checks if LIV flag is disabled by default.
Definition: test_liv.py:54