Skip to content

Commit

Permalink
checking finite vs point source in methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoleski committed Apr 27, 2024
1 parent a48c647 commit ab40a63
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions source/MulensModel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions source/MulensModel/tests/test_Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
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.0"
__version__ = "2.22.1"

0 comments on commit ab40a63

Please sign in to comment.