From 84cbfc711fd4157580ea269c2fa221916264e2bb Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 28 Apr 2024 08:34:06 +0200 Subject: [PATCH] improving error messages --- source/MulensModel/model.py | 15 ++++++++++--- source/MulensModel/tests/test_Model.py | 29 ++++++++++++++++++++++++++ source/MulensModel/version.py | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/source/MulensModel/model.py b/source/MulensModel/model.py index 25d629f8..a8032beb 100644 --- a/source/MulensModel/model.py +++ b/source/MulensModel/model.py @@ -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): """ diff --git a/source/MulensModel/tests/test_Model.py b/source/MulensModel/tests/test_Model.py index 86f2ec93..eaf84560 100644 --- a/source/MulensModel/tests/test_Model.py +++ b/source/MulensModel/tests/test_Model.py @@ -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""" diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py index a1f167d2..4d8af451 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.22.1" +__version__ = "2.22.2"