diff --git a/source/MulensModel/model.py b/source/MulensModel/model.py index 1c57ea56..25d629f8 100644 --- a/source/MulensModel/model.py +++ b/source/MulensModel/model.py @@ -912,6 +912,8 @@ def set_magnification_methods(self, methods, source=None): raise ValueError('In Model.set_magnification_methods() ' + 'the parameter source, has to be 1, 2 or None.') + self._check_methods(methods, source) + if (source is None) or (self.n_sources == 1): if isinstance(self._methods, dict): raise ValueError('You cannot set methods for all sources ' + @@ -932,6 +934,23 @@ def set_magnification_methods(self, methods, source=None): self._methods = {} self._methods[source] = methods + def _check_methods(self, methods, source): + """ + Check consistency of methods: + - are finite source methods used for poitn sources? + """ + used_methods = set(methods[1::2]) + allowed = set(['point_source', 'point_source_point_lens']) + difference = used_methods - allowed + if len(difference) == 0: + return + + 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)) + def get_magnification_methods(self, source=None): """ Gets methods used for magnification calculation. See diff --git a/source/MulensModel/tests/test_Model.py b/source/MulensModel/tests/test_Model.py index d2d7361d..86f2ec93 100644 --- a/source/MulensModel/tests/test_Model.py +++ b/source/MulensModel/tests/test_Model.py @@ -59,6 +59,16 @@ def test_negative_t_E(self): with self.assertRaises(ValueError): mm.Model({'t_0': 2450000., 'u_0': 0.1, 't_E': -100.}) + def test_finite_source_method_without_rho(self): + """ + Test method that requires fintie source to run on model that + has point source. + """ + model = mm.Model({'t_0': 10, 'u_0': 0.2, 't_E': 50}) + with self.assertRaises(ValueError): + model.set_magnification_methods( + [9, "finite_source_uniform_Gould94", 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 0ca05961..a1f167d2 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.22.0" +__version__ = "2.22.1"