Repository: rpoleski/MulensModel

Issue:
methods don't update
There's a bug in v3 MagnificationCurve - methods don't update:

```python
    t_vec = np.array([3.5, 2., 1., 0.5, 0.])
    params_0 = mm.ModelParameters({'t_0': 0., 'u_0': 0.5, 't_E': 1., 'rho': 1.})
    mag_curve_0 = mm.MagnificationCurve(times=t_vec, parameters=params_0)
    mag_curve_0.set_magnification_methods([-5., 'finite_source_uniform_Lee09', 5.], 'point_source')
    print(mag_curve_0.methods_indices)
    mag_curve_0.set_magnification_methods([-5., 'finite_source_uniform_WittMao94', 5.], 'point_source')
    print(mag_curve_0.methods_indices)
```

Returns:

```python
{'finite_source_uniform_Lee09': array([ True,  True,  True,  True,  True])}
{'finite_source_uniform_Lee09': array([ True,  True,  True,  True,  True])}
```

Expected:

```python
{'finite_source_uniform_Lee09': array([ True,  True,  True,  True,  True])}
{'finite_source_uniform_WittMao94': array([ True,  True,  True,  True,  True])}
```

@jenniferyee

Hints from issue comments:
@rpoleski: Is solved [here](https://github.com/rapoliveira/MulensModel/tree/bugfix-methods-magcurve).@rpoleski: Solved.

Solution patch:
diff --git a/source/MulensModel/magnificationcurve.py b/source/MulensModel/magnificationcurve.py
index bb6ed1ec..35a11fe2 100644
--- a/source/MulensModel/magnificationcurve.py
+++ b/source/MulensModel/magnificationcurve.py
@@ -109,6 +109,19 @@ class MagnificationCurve(object):
             self._methods_names = []
             return
 
+        epochs, names = self._raise_errors_set_magnification_methods(methods)
+        self._methods_epochs = np.array(epochs)
+        self._methods_names = names
+
+        self._methods_for_epochs = None
+        self._methods_indices = None
+        _ = self.methods_for_epochs
+        _ = self.methods_indices
+
+    def _raise_errors_set_magnification_methods(self, methods):
+        """
+        Check if the list of methods is valid and raise errors if not.
+        """
         if not isinstance(methods, list):
             msg = ('MagnificationCurve.set_magnification_methods() ' +
                    'requires a list as a parameter')
@@ -128,8 +141,7 @@ class MagnificationCurve(object):
                        ' be earlier)')
                 raise ValueError(msg.format(e_beg, e_end))
 
-        self._methods_epochs = np.array(epochs)
-        self._methods_names = names
+        return epochs, names
 
     def set_magnification_methods_parameters(self, methods_parameters):
         """
diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py
index f7493720..1fe90f6a 100644
--- a/source/MulensModel/version.py
+++ b/source/MulensModel/version.py
@@ -1 +1 @@
-__version__ = "3.1.3"
+__version__ = "3.1.4"


Test patch:
diff --git a/source/MulensModel/tests/test_MagnificationCurve.py b/source/MulensModel/tests/test_MagnificationCurve.py
index 973c3646..8255bdb4 100644
--- a/source/MulensModel/tests/test_MagnificationCurve.py
+++ b/source/MulensModel/tests/test_MagnificationCurve.py
@@ -1,4 +1,5 @@
 import numpy as np
+import pytest
 import unittest
 import warnings
 
@@ -34,6 +35,40 @@ def test_methods_none():
     np.testing.assert_almost_equal(expected, result, decimal=4)
 
 
+def test_methods_error_list():
+    """
+    Test if set_magnification_methods() raises error if list is not given.
+    """
+    t_0 = 2456789.012345
+    t_E = 1e-4
+    params = mm.ModelParameters(
+        {'t_0': t_0, 'u_0': 23.4567, 't_E': t_E, 'rho': 1e-3})
+    mag_curve = mm.MagnificationCurve([t_0], params)
+
+    methods = (t_0-t_E, 'finite_source_uniform_Gould94', t_0+t_E)
+    with pytest.raises(TypeError):
+        mag_curve.set_magnification_methods(methods, 'point_source')
+
+
+def test_methods_update():
+    """
+    Test if set_magnification_methods() updates correctly.
+    """
+    t_vec = np.array([3.5, 2., 1., 0.5, 0.])
+    params = mm.ModelParameters({'t_0': 0., 'u_0': 0.5, 't_E': 1., 'rho': 1.})
+    mag_curve = mm.MagnificationCurve(times=t_vec, parameters=params)
+
+    mag_curve.set_magnification_methods([-5., 'finite_source_uniform_Lee09', 5.], 'point_source')
+    indices = mag_curve.methods_indices
+    assert indices.keys() == {'finite_source_uniform_Lee09'}
+    np.testing.assert_equal(indices['finite_source_uniform_Lee09'], np.ones_like(t_vec, bool))
+
+    mag_curve.set_magnification_methods([-5., 'finite_source_uniform_WittMao94', 5.], 'point_source')
+    indices = mag_curve.methods_indices
+    assert indices.keys() == {'finite_source_uniform_WittMao94'}
+    np.testing.assert_equal(indices['finite_source_uniform_WittMao94'], np.ones_like(t_vec, bool))
+
+
 def test_fspl_noLD():
     """
     check if FSPL magnification is calculate properly