Skip to content

Commit

Permalink
Updated count_sources for an arbitrary number of sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferyee committed Dec 29, 2023
1 parent 769a11b commit b9b852d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
48 changes: 30 additions & 18 deletions source/MulensModel/modelparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class ModelParameters(object):
"""

# parameters that may be defined for a given source
source_params_head = ['t_0', 'u_0', 'rho', 't_star']

def __init__(self, parameters):
if not isinstance(parameters, dict):
raise TypeError(
Expand Down Expand Up @@ -254,24 +257,33 @@ def __init__(self, parameters):

def _count_sources(self, keys):
"""How many sources there are?"""
binary_params = ['t_0_1', 't_0_2', 'u_0_1', 'u_0_2', 'rho_1', 'rho_2',
't_star_1', 't_star_2']
common = set(binary_params).intersection(set(keys))
if len(common) == 0:
self._n_sources = 1
elif len(common) == 1:
raise ValueError('Wrong parameters - the only binary source ' +
'parameter is {:}'.format(common))
else:
common_no_1_2 = {param[:-2] for param in common}
condition_1 = (len(common_no_1_2) == len(common))
condition_2 = not (
'rho' in common_no_1_2 and 't_star' in common_no_1_2)
if condition_1 and condition_2:
raise ValueError(
'Given binary source parameters do not allow defining ' +
'the Model: {:}'.format(common))
self._n_sources = 2
self._n_sources = 1
for key in keys:
# Check max number of sources based on u_0
# (t_0 is potentially confused with t_0_par, etc).
if (len(key) > 3) & (key[0:3] == 'u_0'):
n = key.split('_')[-1]
if int(n) > self._n_sources:
self._n_sources = int(n)

# binary_params = ['t_0_1', 't_0_2', 'u_0_1', 'u_0_2', 'rho_1', 'rho_2',
# 't_star_1', 't_star_2']
# common = set(binary_params).intersection(set(keys))
# if len(common) == 0:
# self._n_sources = 1
# elif len(common) == 1:
# raise ValueError('Wrong parameters - the only binary source ' +
# 'parameter is {:}'.format(common))
# else:
# common_no_1_2 = {param[:-2] for param in common}
# condition_1 = (len(common_no_1_2) == len(common))
# condition_2 = not (
# 'rho' in common_no_1_2 and 't_star' in common_no_1_2)
# if condition_1 and condition_2:
# raise ValueError(
# 'Given binary source parameters do not allow defining ' +
# 'the Model: {:}'.format(common))
# self._n_sources = 2

def _count_lenses(self, keys):
"""How many lenses there are?"""
Expand Down
1 change: 0 additions & 1 deletion source/MulensModel/tests/test_ModelParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,3 @@ def test_3L1S_models():
't_E': 9}
model_params = mm.ModelParameters(parameters)
assert model_params.n_sources == 3

3 comments on commit b9b852d

@rpoleski
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I don't think we should count the sources based on u_0_X parameters because one can use t_eff_X instead.
  2. We should check if the source numbers are consecutive numbers. If the user set sources _1 and _3 but no _2 then there will be problems.

@jenniferyee
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. In the master branch, t_eff is not allowed for binary sources. See model_parameters.ModelParameters._count_sources()
  2. The issue of consecutive numbers is handled by _check_valid_combination_of_sources().

@rpoleski
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following Jen's comment, I've opened issue #138

Please sign in to comment.