Skip to content

Commit

Permalink
improving error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoleski committed Apr 28, 2024
1 parent ab40a63 commit 84cbfc7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
15 changes: 12 additions & 3 deletions source/MulensModel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,20 @@ def _check_methods(self, methods, source):
if len(difference) == 0:
return

fmt = ('It is impossible to use finite source method for '
'a point source {:}: {:}')
if self.n_sources == 1:
if not self.parameters.is_finite_source():
raise ValueError(
'It is impossible to use finite source method for '
'a point source: ' + str(difference))
raise ValueError(fmt.format("", difference))
elif self.n_sources == 2:
if source in [1, None]:
if not self.parameters.source_1_parameters.is_finite_source():
raise ValueError(fmt.format("no. 1", difference))
if source in [2, None]:
if not self.parameters.source_2_parameters.is_finite_source():
raise ValueError(fmt.format("no. 2", difference))
else:
raise ValueError('internal error - too many sources')

def get_magnification_methods(self, source=None):
"""
Expand Down
29 changes: 29 additions & 0 deletions source/MulensModel/tests/test_Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,35 @@ def test_finite_source_method_without_rho(self):
model.set_magnification_methods(
[9, "finite_source_uniform_Gould94", 11])

def test_finite_source_method_without_rho_1(self):
"""
2 source, only source 1 is finite, but we set finite method for both.
"""
model = mm.Model({'t_0_1': 10, 'u_0_1': 0.2, 't_0_2': 30,
'u_0_2': 0.4, 't_E': 50, 'rho_1': 0.6})
with self.assertRaises(ValueError):
model.set_magnification_methods(
[9, "finite_source_uniform_Gould94", 11])

def test_finite_source_method_without_rho_2(self):
"""
2 source, only source 1 is finite, but we set finite method for both.
"""
model = mm.Model({'t_0_1': 10, 'u_0_1': 0.2, 't_0_2': 30,
'u_0_2': 0.4, 't_E': 50, 'rho_2': 0.6})
with self.assertRaises(ValueError):
model.set_magnification_methods(
[29, "finite_source_uniform_Gould94", 31])


def test_model_methods():
"""
Simplest model and setting point_source method.
It obviously should work but it's worth to check it.
"""
model = mm.Model({'t_0': 10, 'u_0': 0.2, 't_E': 50})
model.set_magnification_methods([9, "point_source", 11])


def test_model_parallax_definition():
"""Update parameters in an existing model"""
Expand Down
2 changes: 1 addition & 1 deletion source/MulensModel/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.22.1"
__version__ = "2.22.2"

0 comments on commit 84cbfc7

Please sign in to comment.