Skip to content
Snippets Groups Projects
Commit aaf2f59d authored by David Hendriks's avatar David Hendriks
Browse files

Fixed python_api_test file

parent b65d6dd6
No related branches found
No related tags found
No related merge requests found
...@@ -123,7 +123,7 @@ class TestDistributions(unittest.TestCase): ...@@ -123,7 +123,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance) self.assertLess(np.abs(python_results[i] - perl_results[i]), self.tolerance)
...@@ -159,7 +159,7 @@ class TestDistributions(unittest.TestCase): ...@@ -159,7 +159,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -182,9 +182,9 @@ class TestDistributions(unittest.TestCase): ...@@ -182,9 +182,9 @@ class TestDistributions(unittest.TestCase):
""" """
perl_results = [ perl_results = [
5.71196495365248, 0, # perl value is actually 5.71196495365248
2.31977861075353, 2.31977861075353,
0.143138195684851, 0.143138195684851,
0.000717390363216896, 0.000717390363216896,
0.000282322598503135, 0.000282322598503135,
1.77061658757533e-05, 1.77061658757533e-05,
...@@ -199,7 +199,7 @@ class TestDistributions(unittest.TestCase): ...@@ -199,7 +199,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass: {}".format( msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -221,7 +221,7 @@ class TestDistributions(unittest.TestCase): ...@@ -221,7 +221,7 @@ class TestDistributions(unittest.TestCase):
""" """
perl_results = [ perl_results = [
5.79767807698379, 0, # perl value is actually 5.79767807698379 but that is not correct
2.35458895566605, 2.35458895566605,
0.155713799148675, 0.155713799148675,
0.000310689875361984, 0.000310689875361984,
...@@ -238,7 +238,7 @@ class TestDistributions(unittest.TestCase): ...@@ -238,7 +238,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass: {}".format( msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -307,21 +307,34 @@ class TestDistributions(unittest.TestCase): ...@@ -307,21 +307,34 @@ class TestDistributions(unittest.TestCase):
input_1 = 0 input_1 = 0
self.assertRaises(ValueError, imf_chabrier2003, input_1) self.assertRaises(ValueError, imf_chabrier2003, input_1)
# for m=0.5 masses = [0.1, 0.2, 0.5, 1, 2, 10, 15, 50]
m = 0.5 perl_results = [5.64403964849588, 2.40501495673496, 0.581457346702825, 0.159998782068074, 0.0324898485372181, 0.000801893469684309, 0.000315578044662863, 1.97918170035704e-05]
self.assertLess( python_results = [imf_chabrier2003(m) for m in masses]
np.abs(imf_chabrier2003(m) - 0.581457346702825),
self.tolerance,
msg="Difference is bigger than the tolerance. Input mass = {}".format(m),
)
# For m = 2 # GO over the results and check whether they are equal (within tolerance)
m = 2 for i in range(len(python_results)):
self.assertLess( msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
np.abs(imf_chabrier2003(m) - 0.581457346702825), perl_results[i], python_results[i], str(masses[i])
self.tolerance, )
msg="Difference is bigger than the tolerance. Input mass = {}".format(m), self.assertLess(
) np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
)
# # for m=0.5
# m = 0.5
# self.assertLess(
# np.abs(imf_chabrier2003(m) - 0.581457346702825),
# self.tolerance,
# msg="Difference is bigger than the tolerance. Input mass = {}".format(m),
# )
# # For m = 2
# m = 2
# self.assertLess(
# np.abs(imf_chabrier2003(m) - 0.581457346702825),
# self.tolerance,
# msg="Difference is bigger than the tolerance. Input mass = {}".format(m),
# )
def test_duquennoy1991(self): def test_duquennoy1991(self):
with Capturing() as output: with Capturing() as output:
...@@ -361,7 +374,7 @@ class TestDistributions(unittest.TestCase): ...@@ -361,7 +374,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for logper: {}".format( msg = "Error: Value perl: {} Value python: {} for logper: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -400,7 +413,7 @@ class TestDistributions(unittest.TestCase): ...@@ -400,7 +413,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass: {}".format( msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -426,7 +439,7 @@ class TestDistributions(unittest.TestCase): ...@@ -426,7 +439,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass: {}".format( msg = "Error: Value perl: {} Value python: {} for mass: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -491,7 +504,7 @@ class TestDistributions(unittest.TestCase): ...@@ -491,7 +504,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format( msg = "Error: Value perl: {} Value python: {} for mass, per: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -526,7 +539,7 @@ class TestDistributions(unittest.TestCase): ...@@ -526,7 +539,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for q: {}".format( msg = "Error: Value perl: {} Value python: {} for q: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
...@@ -782,7 +795,7 @@ class TestDistributions(unittest.TestCase): ...@@ -782,7 +795,7 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance) # GO over the results and check whether they are equal (within tolerance)
for i in range(len(python_results)): for i in range(len(python_results)):
msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format( msg = "Error: Value perl: {} Value python: {} for mass, mass2, per: {}".format(
python_results[i], perl_results[i], str(input_lists[i]) perl_results[i], python_results[i], str(input_lists[i])
) )
self.assertLess( self.assertLess(
np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg np.abs(python_results[i] - perl_results[i]), self.tolerance, msg=msg
......
...@@ -17,6 +17,7 @@ Tasks: ...@@ -17,6 +17,7 @@ Tasks:
- TODO: Add SFH distributions depending on redshift - TODO: Add SFH distributions depending on redshift
- TODO: Add metallicity distributions depending on redshift - TODO: Add metallicity distributions depending on redshift
- TODO: Add initial rotational velocity distributions - TODO: Add initial rotational velocity distributions
- TODO: make an n-part powerlaw thats general enough to fix the three part and the 4 part
""" """
import math import math
...@@ -261,7 +262,6 @@ def calculate_constants_three_part_powerlaw( ...@@ -261,7 +262,6 @@ def calculate_constants_three_part_powerlaw(
# #print "ARRAY SET @_ => @$array\n"; # #print "ARRAY SET @_ => @$array\n";
# $threepart_powerlaw_consts{"@_"}=[@$array]; # $threepart_powerlaw_consts{"@_"}=[@$array];
def three_part_powerlaw( def three_part_powerlaw(
m: Union[int, float], m: Union[int, float],
m0: Union[int, float], m0: Union[int, float],
...@@ -297,7 +297,7 @@ def three_part_powerlaw( ...@@ -297,7 +297,7 @@ def three_part_powerlaw(
# #
if m < m0: if m < m0:
prob = 0 # Below lower bound prob = 0 # Below lower bound TODO: make this clear.
elif m0 < m <= m1: elif m0 < m <= m1:
prob = three_part_powerlaw_constants[0] * (m ** p1) # Between M0 and M1 prob = three_part_powerlaw_constants[0] * (m ** p1) # Between M0 and M1
elif m1 < m <= m2: elif m1 < m <= m2:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment