From 616fb34ced7d180664330118f6e7ab96ef2a2fc8 Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Thu, 2 May 2024 07:51:00 +0200 Subject: [PATCH] more tests on q_source --- source/MulensModel/modelparameters.py | 23 +++++++++++++++---- .../MulensModel/tests/test_ModelParameters.py | 7 ++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/source/MulensModel/modelparameters.py b/source/MulensModel/modelparameters.py index 0266c632..bdc67673 100644 --- a/source/MulensModel/modelparameters.py +++ b/source/MulensModel/modelparameters.py @@ -480,13 +480,28 @@ def _divide_parameters(self, parameters): parameters_2[key] = value if self.n_sources == 2 and self._type['xallarap']: - if parameters['q_source'] < 0.: - raise ValueError('q_source cannot be negative') - parameters_2['xi_semimajor_axis'] /= parameters['q_source'] - parameters_2['xi_argument_of_latitude_reference'] += 180. + self._set_changed_parameters_2nd_source(parameters['q_source'], + parameters_2) return (parameters_1, parameters_2) + def _set_changed_parameters_2nd_source(self, q_source, parameters_2): + """ + For xallarap model with 2 sources, the orbit of the second source + must have 2 parameters changed. + Functions starts with tests of input + """ + if q_source <= 0.: + raise ValueError('q_source cannot be negative') + + check_keys = ['xi_semimajor_axis', 'xi_argument_of_latitude_reference'] + for key in check_keys: + if key not in parameters_2: + raise KeyError('xallarap model with 2 sources requires ' + key) + + parameters_2['xi_semimajor_axis'] /= q_source + parameters_2['xi_argument_of_latitude_reference'] += 180. + def __repr__(self): """A nice way to represent a ModelParameters object as a string""" out = self._get_main_parameters_to_print() diff --git a/source/MulensModel/tests/test_ModelParameters.py b/source/MulensModel/tests/test_ModelParameters.py index 8cd77104..670b19a5 100644 --- a/source/MulensModel/tests/test_ModelParameters.py +++ b/source/MulensModel/tests/test_ModelParameters.py @@ -601,6 +601,13 @@ def test_no_q_source_but_with_rho_2(self): with self.assertRaises(KeyError): mm.ModelParameters(parameters) + def test_PSPL_and_q_source(self): + """ + Make sure one cannot provide only PSPL parameters and q_source. + """ + with self.assertRaises(KeyError): + mm.ModelParameters({'t_0': 1, 'u_0': 2, 't_E': 3, 'q_source': 1}) + def test_print_xallarap(): """