Exemplo n.º 1
0
def generate_binary_model():
    """
    returns a binary source model, time array, and the magnification of
    both sources
    """

    # retrieve model 1
    (model_1, t, A_1) = generate_model()
    t_0_1 = model_1.parameters.t_0
    u_0_1 = model_1.parameters.u_0

    # create second model
    t_0_2 = 3570.
    u_0_2 = 0.25
    t_E = model_1.parameters.t_E

    model_2 = mm.Model({'t_0': t_0_2, 'u_0': u_0_2, 't_E': t_E})

    A_2 = model_2.get_magnification(t)

    # create separate binary model
    params = {
        't_0_1': t_0_1,
        'u_0_1': u_0_1,
        't_0_2': t_0_2,
        'u_0_2': u_0_2,
        't_E': t_E
    }
    binary_model = mm.Model(params)

    return (binary_model, t, A_1, A_2)
Exemplo n.º 2
0
def test_magnifications_for_orbital_motion():
    """
    make sure that orbital motion parameters are properly passed to
    magnification methods calculations
    """
    dict_static = {
        't_0': 100.,
        'u_0': 0.1,
        't_E': 100.,
        'q': 0.99,
        's': 1.1,
        'alpha': 10.
    }
    dict_motion = dict_static.copy()
    dict_motion.update({'ds_dt': -2, 'dalpha_dt': -300.})
    static = mm.Model(dict_static)
    motion = mm.Model(dict_motion)

    t_1 = 100.
    almost(static.magnification(t_1), motion.magnification(t_1))

    t_2 = 130.
    static.parameters.s = 0.93572895
    static.parameters.alpha = 345.359342916
    almost(static.magnification(t_2), motion.magnification(t_2))
Exemplo n.º 3
0
def test_model_parallax_definition():
    """Update parameters in an existing model"""
    model_2 = mm.Model({
        't_0': 2450000.,
        'u_0': 0.1,
        't_E': 100.,
        'pi_E_N': 0.1,
        'pi_E_E': 0.2
    })

    model_2.parameters.pi_E_N = 0.3
    model_2.parameters.pi_E_E = 0.4
    assert model_2.parameters.pi_E_N == 0.3
    assert model_2.parameters.pi_E_E == 0.4

    model_3 = mm.Model({
        't_0': 2450000.,
        'u_0': 0.1,
        't_E': 100.,
        'pi_E': (0.5, 0.6)
    })
    assert model_3.parameters.pi_E_N == 0.5
    assert model_3.parameters.pi_E_E == 0.6

    model_4 = mm.Model({
        't_0': 2450000.,
        'u_0': 0.1,
        't_E': 100.,
        'pi_E_N': 0.7,
        'pi_E_E': 0.8
    })
    assert model_4.parameters.pi_E_N == 0.7
    assert model_4.parameters.pi_E_E == 0.8
Exemplo n.º 4
0
def test_satellite_parallax_magnification():
    """
    On a given date, the magnification should be different from the
    ground and from Spitzer. Use OB140939 as a test case and t0 as the
    test time.
    """
    t_0 = 2456836.22
    u_0 = 0.922
    t_E = 22.87
    pi_E_N = -0.248
    pi_E_E = 0.234

    ground_model = mm.Model(
        {
            't_0': t_0,
            'u_0': u_0,
            't_E': t_E,
            'pi_E': [pi_E_N, pi_E_E]
        },
        coords='17:47:12.25 -21:22:58.2')
    space_model = mm.Model(
        {
            't_0': t_0,
            'u_0': u_0,
            't_E': t_E,
            'pi_E': [pi_E_N, pi_E_E]
        },
        ra='17:47:12.25',
        dec='-21:22:58.2',
        ephemerides_file=SAMPLE_FILE_03_EPH)

    delta = ground_model.magnification(t_0) - space_model.magnification(t_0)
    assert np.abs(delta) > 0.01
Exemplo n.º 5
0
def test_event_chi2_binary_source():
    """simple test if chi2 calculation for binary source works fine"""
    model = mm.Model({
        't_0_1': 5000.,
        'u_0_1': 0.05,
        't_0_2': 5100.,
        'u_0_2': 0.15,
        't_E': 25.
    })
    model_1 = mm.Model(model.parameters.source_1_parameters)
    model_2 = mm.Model(model.parameters.source_2_parameters)

    # prepare fake data:
    time = np.linspace(4900., 5200., 600)
    mag_1 = model_1.magnification(time)
    mag_2 = model_2.magnification(time)
    flux = 100. * mag_1 + 300. * mag_2 + 50.
    data = mm.MulensData(data_list=[time, flux, 1. + 0. * time],
                         phot_fmt='flux')

    # Calculate chi^2:
    event = mm.Event([data], model)
    np.testing.assert_almost_equal(event.get_chi2(), 0.)
    # Make sure Model.set_source_flux_ratio() is taken into account.
    model.set_source_flux_ratio(1.)
    np.testing.assert_almost_equal(model.magnification(time),
                                   (mag_1 + mag_2) / 2.)
    assert event.get_chi2() > 1.
    model.set_source_flux_ratio(3.)
    np.testing.assert_almost_equal(event.get_chi2(), 0.)
Exemplo n.º 6
0
def generate_binary_source_models():
    model = mm.Model({
        't_0_1': 5000.,
        'u_0_1': 0.05,
        't_0_2': 5100.,
        'u_0_2': 0.15,
        't_E': 25.
    })
    model_1 = mm.Model(model.parameters.source_1_parameters)
    model_2 = mm.Model(model.parameters.source_2_parameters)

    return (model, model_1, model_2)
Exemplo n.º 7
0
def test_t_E():
    """make sure t_E can be accessed properly"""
    t_0 = 2460000.
    u_0 = 0.1
    t_E = 12.3456
    t_star = 0.01234
    params = dict(t_0=t_0, u_0=u_0, t_E=t_E)
    model_1 = mm.Model(params)
    params['t_star'] = t_star
    model_2 = mm.Model(params)

    almost(model_1.parameters.t_E, t_E)
    almost(model_2.parameters.t_E, t_E)
Exemplo n.º 8
0
def test_n_lenses():
    """check n_lenses property"""
    model_1 = mm.Model({"t_0": 2456789., "u_0": 1., "t_E": 30.})
    model_2 = mm.Model({
        "t_0": 2456789.,
        "u_0": 1.,
        "t_E": 30.,
        "s": 1.1234,
        "q": 0.123,
        'alpha': 12.34
    })
    assert model_1.n_lenses == 1
    assert model_2.n_lenses == 2
Exemplo n.º 9
0
def do_annual_parallax_test(filename):
    """testing functions called by a few unit tests"""
    with open(filename) as data_file:
        lines = data_file.readlines()
    ulens_params = lines[3].split()
    event_params = lines[4].split()
    data = np.loadtxt(filename, dtype=None)
    model = mm.Model(
        {
            't_0': float(ulens_params[1]) + 2450000.,
            'u_0': float(ulens_params[3]),
            't_E': float(ulens_params[4]),
            'pi_E_N': float(ulens_params[5]),
            'pi_E_E': float(ulens_params[6])
        },
        coords=SkyCoord(event_params[1] + ' ' + event_params[2],
                        unit=(u.deg, u.deg)))
    model.parameters.t_0_par = float(ulens_params[2]) + 2450000.

    time = data[:, 0]
    dataset = mm.MulensData([time, 20. + time * 0., 0.1 + time * 0.],
                            add_2450000=True)
    model.set_datasets([dataset])
    model.parallax(satellite=False, earth_orbital=True, topocentric=False)
    return np.testing.assert_almost_equal(model.data_magnification[0] /
                                          data[:, 1],
                                          1.0,
                                          decimal=4)
Exemplo n.º 10
0
def test_binary_source_and_fluxes_for_bands():
    """
    Test if setting different flux ratios for different bands in binary
    source models works properly. The argument flux_ratio_constraint
    is set as string.
    """
    model = mm.Model({
        't_0_1': 5000.,
        'u_0_1': 0.05,
        't_0_2': 5100.,
        'u_0_2': 0.003,
        't_E': 30.
    })

    times_I = np.linspace(4900., 5200., 3000)
    times_V = np.linspace(4800., 5300., 250)
    (f_s_1_I, f_s_2_I, f_b_I) = (10., 20., 3.)
    (f_s_1_V, f_s_2_V, f_b_V) = (15., 5., 30.)
    q_f_I = f_s_2_I / f_s_1_I
    q_f_V = f_s_2_V / f_s_1_V
    (mag_1_I, mag_2_I) = model.get_magnification(times_I, separate=True)
    (mag_1_V, mag_2_V) = model.get_magnification(times_V, separate=True)
    effective_mag_I = (mag_1_I + mag_2_I * q_f_I) / (1. + q_f_I)
    effective_mag_V = (mag_1_V + mag_2_V * q_f_V) / (1. + q_f_V)
    flux_I = mag_1_I * f_s_1_I + mag_2_I * f_s_2_I + f_b_I
    flux_V = mag_1_V * f_s_1_V + mag_2_V * f_s_2_V + f_b_V

    # model.set_source_flux_ratio_for_band('I', q_f_I)
    # model.set_source_flux_ratio_for_band('V', q_f_V)

    # Test Model.get_magnification()
    result_I = model.get_magnification(times_I, source_flux_ratio=q_f_I)
    result_V = model.get_magnification(times_V, source_flux_ratio=q_f_V)
    almost(result_I, effective_mag_I)
    almost(result_V, effective_mag_V)
Exemplo n.º 11
0
    def setUp(self):
        # Flux ratios
        self.q_I = 0.01
        self.q_V = 0.002

        self.gamma = {'I': 0.44, 'V': 0.72}

        # Model based on binary source
        self.model = mm.Model({
            't_0_1': 8000.,
            'u_0_1': 0.3,
            't_0_2': 8001.,
            'u_0_2': 0.001,
            't_E': 25.,
            'rho_2': 0.002
        })
        n_tstar = 3
        t_1 = self.model.parameters.t_0_2 - 3 * self.model.parameters.t_star_2
        t_2 = self.model.parameters.t_0_2 + 3 * self.model.parameters.t_star_2
        self.model.set_magnification_methods(
            [t_1, 'finite_source_LD_Yoo04', t_2], source=2)
        self.model.set_limb_coeff_gamma('I', self.gamma['I'])
        self.model.set_limb_coeff_gamma('V', self.gamma['V'])

        self.generate_fake_datasets()
Exemplo n.º 12
0
def test_chi2_gradient():
    """
    test that fit_fluxes/update must be run in order to update the gradient
    """
    data = mm.MulensData(file_name=SAMPLE_FILE_02)
    event = mm.Event(datasets=[data],
                     model=mm.Model(chi2_gradient_test_1.parameters),
                     fix_blend_flux={data: 0.})
    result = event.get_chi2_gradient(chi2_gradient_test_1.grad_params)
    reference = np.array([
        chi2_gradient_test_1.gradient[key]
        for key in chi2_gradient_test_1.grad_params
    ])
    np.testing.assert_almost_equal(reference / result, 1., decimal=4)

    # changing something w/o updating: gives old values
    event.model.parameters.t_0 += 0.1
    result_1 = event.chi2_gradient
    np.testing.assert_almost_equal(result_1 / result, 1.)

    # run fit_fluxes: gives new values
    event.fit_fluxes()
    result_2 = event.calculate_chi2_gradient(chi2_gradient_test_1.grad_params)
    assert all(result != result_2)

    # Go back to previous results and test that calculate_chi2_gradient gives
    # results that don't match anything.
    event.model.parameters.t_0 -= 0.1
    result_3 = event.calculate_chi2_gradient(chi2_gradient_test_1.grad_params)
    assert all(result != result_3)
    assert all(result_2 != result_3)
    result_4 = event.get_chi2_gradient(chi2_gradient_test_1.grad_params)
    np.testing.assert_almost_equal(result_4 / result, 1.)
Exemplo n.º 13
0
def test_chi2_gradient_2():
    """
    Double-up on the gradient test, i.e. duplicate the dataset and check that
    the gradient values double.
    """
    reference = np.array([
        chi2_gradient_test_1.gradient[key]
        for key in chi2_gradient_test_1.grad_params
    ])

    data = mm.MulensData(file_name=SAMPLE_FILE_02)
    event = mm.Event(datasets=[data, data],
                     model=mm.Model(chi2_gradient_test_1.parameters),
                     fix_blend_flux={data: 0.})
    result_0 = event.get_chi2_gradient(chi2_gradient_test_1.grad_params)
    result_1 = event.fits[1].chi2_gradient
    np.testing.assert_almost_equal(2. * reference / result_0, 1., decimal=4)
    np.testing.assert_almost_equal(2. * result_1 / result_0, 1.)
    np.testing.assert_almost_equal(reference / result_1, 1., decimal=4)

    # Change something and test fit.get_chi2_gradient
    event.model.parameters.t_0 += 0.1
    result_2 = event.fits[1].get_chi2_gradient(
        chi2_gradient_test_1.grad_params)
    assert result_2[0] != result_1[0]
    event.model.parameters.t_0 -= 0.1
    result_3 = event.fits[1].get_chi2_gradient(
        chi2_gradient_test_1.grad_params)
    np.testing.assert_almost_equal(result_3 / reference, 1., decimal=4)
Exemplo n.º 14
0
def test_chi2_vs_get_chi2():
    """get_chi2 always updates after something changes in the model, chi2 does
    not."""
    t_0 = 5379.57091
    u_0 = 0.52298
    t_E = 17.94002

    data = mm.MulensData(file_name=SAMPLE_FILE_01)

    ev = mm.Event()
    mod = mm.Model({'t_0': t_0, 'u_0': u_0, 't_E': t_E})
    ev.model = mod
    ev.datasets = [data]

    # New (v2.0) method of fixing the blending
    ev.fix_blend_flux = {}
    np.testing.assert_almost_equal(ev.get_chi2(), 427.20382, decimal=4)
    np.testing.assert_almost_equal(ev.chi2, 427.20382, decimal=4)

    fix_blend_flux = {}
    for dataset in ev.datasets:
        fix_blend_flux[dataset] = 0.

    ev.fix_blend_flux = fix_blend_flux
    np.testing.assert_almost_equal(ev.chi2, 427.20382, decimal=4)
    np.testing.assert_almost_equal(ev.get_chi2(), 459.09826, decimal=4)
    np.testing.assert_almost_equal(ev.chi2, 459.09826, decimal=4)
Exemplo n.º 15
0
def test_caustic_for_orbital_motion():
    """
    check if caustics calculated for different epochs in orbital motion model
    are as expected
    """
    q = 0.1
    s = 1.3
    params = {
        't_0': 100.,
        'u_0': 0.1,
        't_E': 10.,
        'q': q,
        's': s,
        'ds_dt': 0.5,
        'alpha': 0.,
        'dalpha_dt': 0.
    }
    model = mm.Model(parameters=params)

    model.update_caustics()
    almost(model.caustics.get_caustics(), mm.Caustics(q=q, s=s).get_caustics())

    model.update_caustics(100. + 365.25 / 2)
    almost(model.caustics.get_caustics(),
           mm.Caustics(q=q, s=1.55).get_caustics())
Exemplo n.º 16
0
def test_satellite_and_annual_parallax_calculation():
    """
    test that data magnifications are correctly retrieved for Spitzer data.
    """

    # Create Model
    model_parameters = {
        't_0': 2456836.22,
        'u_0': 0.922,
        't_E': 22.87,
        'pi_E_N': -0.248,
        'pi_E_E': 0.234,
        't_0_par': 2456836.2
    }
    coords = "17:47:12.25 -21:22:58.2"
    model_with_par = mm.Model(model_parameters, coords=coords)
    model_with_par.parallax(satellite=True,
                            earth_orbital=True,
                            topocentric=False)

    # Load Spitzer data and answers
    data_Spitzer = mm.MulensData(file_name=SAMPLE_FILE_03,
                                 ephemerides_file=SAMPLE_FILE_03_EPH)
    ref_Spitzer = np.loadtxt(SAMPLE_FILE_03_REF, unpack=True, usecols=[5])

    # Test FitData.data_magnification()
    my_fit = mm.FitData(dataset=data_Spitzer, model=model_with_par)
    ratio = my_fit.get_data_magnification() / ref_Spitzer
    np.testing.assert_almost_equal(ratio, [1.] * len(ratio), decimal=4)
Exemplo n.º 17
0
def test_satellite_and_annual_parallax_calculation():
    """test parallax calculation with Spitzer data"""
    model_with_par = mm.Model(
        {
            't_0': 2456836.22,
            'u_0': 0.922,
            't_E': 22.87,
            'pi_E_N': -0.248,
            'pi_E_E': 0.234
        },
        coords="17:47:12.25 -21:22:58.2")
    model_with_par.parallax(satellite=True,
                            earth_orbital=True,
                            topocentric=False)
    model_with_par.parameters.t_0_par = 2456836.2

    data_OGLE = mm.MulensData(file_name=SAMPLE_FILE_02)
    data_Spitzer = mm.MulensData(file_name=SAMPLE_FILE_03,
                                 ephemerides_file=SAMPLE_FILE_03_EPH)
    model_with_par.set_datasets([data_OGLE, data_Spitzer])

    ref_OGLE = np.loadtxt(SAMPLE_FILE_02_REF, unpack=True, usecols=[5])
    ref_Spitzer = np.loadtxt(SAMPLE_FILE_03_REF, unpack=True, usecols=[5])

    np.testing.assert_almost_equal(model_with_par.data_magnification[0],
                                   ref_OGLE,
                                   decimal=2)
    ratio = model_with_par.data_magnification[1] / ref_Spitzer
    np.testing.assert_almost_equal(ratio, [1.] * len(ratio), decimal=4)
Exemplo n.º 18
0
def test_separate_method_for_each_source():
    """
    Checks if setting separate magnification method for each source in
    binary source models works properly.
    """
    model = mm.Model({
        't_0_1': 5000.,
        'u_0_1': 0.01,
        'rho_1': 0.005,
        't_0_2': 5100.,
        'u_0_2': 0.001,
        'rho_2': 0.005,
        't_E': 1000.
    })

    model.set_magnification_methods(
        [4999., 'finite_source_uniform_Gould94', 5101.], source=1)
    # In order not to get "no FS method" warning:
    model.set_magnification_methods([0., 'finite_source_uniform_Gould94', 1.],
                                    source=2)
    out = model.magnification(5000., separate=True)
    almost([out[0][0], out[1][0]], [103.46704167, 10.03696291])

    model.set_magnification_methods(
        [4999., 'finite_source_uniform_Gould94', 5001.], source=1)
    model.set_magnification_methods(
        [5099., 'finite_source_uniform_Gould94', 5101.], source=2)
    out = model.magnification(5100., separate=True)
    almost([out[0][0], out[1][0]], [9.98801936, 395.96963727])
Exemplo n.º 19
0
    def _set_event_PSPL(self):
        """
        Sets internal variable to MulensModel.Event instance
        that uses PSPL model.
        """
        datasets = []
        for band in self.bands:
            mask = (self._filter == band)
            if not np.any(mask):
                continue
            times = self._JD[mask]
            flux = self._simulated_flux[band]
            sigma_flux = self._sigma_flux[band]
            plot = {}
            data = MM.MulensData([times, flux, sigma_flux],
                                 phot_fmt='flux',
                                 bandpass=band,
                                 plot_properties={'label': 'LSST ' + band})
            datasets.append(data)

        if self._follow_up_Chilean is not None:
            if self._follow_up_Chilean.n_epochs > 0:
                datasets.append(self._follow_up_Chilean)

        if self._follow_up_nonChilean is not None:
            if self._follow_up_nonChilean.n_epochs > 0:
                datasets.append(self._follow_up_nonChilean)

        model = MM.Model(
            {p: self._parameters[p]
             for p in ['t_0', 'u_0', 't_E']})
        self._event_PSPL = MM.Event(datasets, model)
Exemplo n.º 20
0
def test_event_get_chi2_4():
    """test if best chi2 is remembered correctly"""
    t_0 = 5379.57091
    u_0 = 0.52298
    t_E = 17.94002

    data = mm.MulensData(file_name=SAMPLE_FILE_01)

    ev = mm.Event()
    params = {'t_0': t_0, 'u_0': u_0, 't_E': t_E * u.day}
    mod = mm.Model(params)
    mod.set_datasets([data])
    ev.model = mod
    ev.datasets = [data]

    chi2_1 = ev.get_chi2()  # This is the best model.

    ev.model.parameters.parameters['t_0'] += 1.
    ev.model.parameters.parameters['u_0'] += 0.1
    ev.model.parameters.parameters['t_E'] += 1. * u.day
    chi2_2 = ev.get_chi2()

    assert chi2_2 > chi2_1
    assert ev.best_chi2 == chi2_1
    assert ev.best_chi2_parameters == params
Exemplo n.º 21
0
def test_event_get_chi2_5():
    """
    De facto checks how information is passed between Event, Fit, and Model.
    Also checks simple relations between different Event.get_chi2().
    """
    kwargs = {'comments': ["\\", "|"]}
    data_1 = mm.MulensData(file_name=SAMPLE_FILE_03, **kwargs)
    data_2 = mm.MulensData(file_name=SAMPLE_FILE_04, phot_fmt='flux', **kwargs)
    params = {'t_0': 2452848.06, 'u_0': 0.1317, 't_E': 61.5}

    model = mm.Model(params)

    event_1 = mm.Event(data_1, model)
    event_2 = mm.Event(data_2, model)
    event_1_2 = mm.Event([data_1, data_2], model)
    event_2_1 = mm.Event([data_2, data_1], model)

    chi2_1 = event_1.get_chi2()
    chi2_2 = event_2.get_chi2()
    # The line below was failing when the test was written:
    chi2_1_2 = event_1_2.get_chi2()
    chi2_2_1 = event_2_1.get_chi2()

    np.testing.assert_almost_equal(chi2_1_2, chi2_1 + chi2_2)
    np.testing.assert_almost_equal(chi2_1_2, chi2_2_1)
Exemplo n.º 22
0
def test_event_get_chi2_3():
    """
    Test: If I change the model parameters, the chi2 should change.
    """
    t_0 = 5380.
    u_0 = 0.5
    t_E = 18.
    model = mm.Model({'t_0': t_0, 'u_0': u_0, 't_E': t_E})

    # Generate fake data
    times = np.arange(5320, 5420.)
    f_source = 0.1
    f_blend = 0.5
    mod_fluxes = f_source * model.magnification(times) + f_blend
    I_mag = mm.Utils.get_mag_from_flux(mod_fluxes)
    errors = 0.01 * np.ones(times.shape)
    data = mm.MulensData(data_list=[times, I_mag, errors])

    # Generate event and fit
    event = mm.Event(datasets=data, model=model)

    orig_chi2 = event.get_chi2()

    # Change the model
    event.model.parameters.t_0 = 5000.

    assert event.get_chi2() != orig_chi2
Exemplo n.º 23
0
def test_event_get_chi2_double_source_simple():
    """
    basic test on ob08092 OGLE-IV data
    """
    t_0 = 5379.57091
    u_0 = 0.52298
    t_E = 17.94002

    data = mm.MulensData(file_name=SAMPLE_FILE_01)

    ev = mm.Event()
    mod = mm.Model({'t_0': t_0, 'u_0': u_0, 't_E': t_E})
    mod.set_datasets([data, data])

    ev.model = mod
    ev.datasets = [data, data]

    chi2 = ev.get_chi2()

    assert isinstance(chi2, float), 'wrong type of chi2'
    message = 'problem in resulting chi2 for 2 exactly the same datasets'
    np.testing.assert_almost_equal(chi2,
                                   854.407644,
                                   decimal=4,
                                   err_msg=message)
Exemplo n.º 24
0
def test_event_get_chi2_3():
    """test on ob08092 OGLE-IV data - MulensData.good & MulensData.bad"""
    t_0 = 5379.57091
    u_0 = 0.52298
    t_E = 17.94002

    bad = np.zeros(383, dtype='bool')
    bad[300:350] = True
    data_1 = mm.MulensData(file_name=SAMPLE_FILE_01, bad=bad)
    data_2 = mm.MulensData(file_name=SAMPLE_FILE_01, good=~bad)

    ev = mm.Event()
    mod = mm.Model({'t_0': t_0, 'u_0': u_0, 't_E': t_E})
    mod.set_datasets([data_1])
    ev.model = mod
    ev.datasets = [data_1]
    chi2 = ev.get_chi2()
    np.testing.assert_almost_equal(float(chi2),
                                   343.46567,
                                   decimal=4,
                                   err_msg='problem in resulting chi2')

    mod.set_datasets([data_2])
    ev.model = mod
    ev.datasets = [data_2]
    chi2 = ev.get_chi2()
    np.testing.assert_almost_equal(float(chi2),
                                   343.46567,
                                   decimal=4,
                                   err_msg='problem in resulting chi2')
Exemplo n.º 25
0
def test_model_coords():
    coords = SkyCoord('18:00:00 -30:00:00', unit=(u.hourangle, u.deg))
    model_1 = mm.Model({
        't_0': 2450000,
        'u_0': 0.1,
        't_E': 100
    },
                       coords='18:00:00 -30:00:00')
    assert isinstance(model_1.coords, SkyCoord)
    assert model_1.coords.ra == coords.ra
    assert model_1.coords.dec == coords.dec
    assert model_1.coords.dec.deg == -30.00

    model_3 = mm.Model({'t_0': 2450000, 'u_0': 0.1, 't_E': 100})
    model_3.coords = '17:00:00 -27:32:14'
    assert model_3.coords.to_string('hmsdms') == '17h00m00s -27d32m14s'
Exemplo n.º 26
0
def test_annual_parallax_calculation():
    """
    This is a high-level unit test for parallax. The "true" values were
    calculated from the sfit routine assuming fs=1.0, fb=0.0.
    """
    t_0 = 2457479.5  # April 1 2016, a time when parallax is large
    times = np.array([t_0 - 1., t_0, t_0 + 1., t_0 + 1.])
    true_with_par = [
        np.array([7.12376832, 10.0386009, 7.13323363, 7.13323363])
    ]

    model_with_par = mm.Model(
        {
            't_0': t_0,
            'u_0': 0.1,
            't_E': 10.,
            'pi_E': (0.3, 0.5)
        },
        coords='17:57:05 -30:22:59')
    model_with_par.parallax(satellite=False,
                            earth_orbital=True,
                            topocentric=False)
    ones = np.ones(len(times))
    data = mm.MulensData(data_list=[times, ones, ones])
    model_with_par.set_datasets([data])

    model_with_par.parameters.t_0_par = 2457479.

    np.testing.assert_almost_equal(model_with_par.data_magnification,
                                   true_with_par,
                                   decimal=4)
Exemplo n.º 27
0
def test_model_binary_and_finite_sources():
    """
    test if model magnification calculation for binary source works with
    finite sources (both rho and t_star given)
    """
    model = mm.Model({
        't_0_1': 5000.,
        'u_0_1': 0.005,
        'rho_1': 0.001,
        't_0_2': 5100.,
        'u_0_2': 0.0003,
        't_star_2': 0.03,
        't_E': 25.
    })
    model_1 = mm.Model(model.parameters.source_1_parameters)
    model_2 = mm.Model(model.parameters.source_2_parameters)

    (t1, t2) = (4999.95, 5000.05)
    (t3, t4) = (5099.95, 5100.05)
    finite = 'finite_source_uniform_Gould94'
    model.set_magnification_methods(
        [t1, finite, t2, 'point_source', t3, finite, t4])
    model_1.set_magnification_methods([t1, finite, t2])
    model_2.set_magnification_methods([t3, finite, t4])

    # prepare fake data:
    (f_s_1, f_s_2, f_b) = (100., 300., 50.)
    time = np.linspace(4900., 5200., 4200)
    mag_1 = model_1.magnification(time)
    mag_2 = model_2.magnification(time)
    flux = f_s_1 * mag_1 + f_s_2 * mag_2 + f_b
    data = mm.MulensData(data_list=[time, flux, 1. + 0. * time],
                         phot_fmt='flux')
    model.set_datasets([data])
    model_1.set_datasets([data])
    model_2.set_datasets([data])

    # test:
    fitted = model.get_data_magnification(data)
    expected = (mag_1 * f_s_1 + mag_2 * f_s_2) / (f_s_1 + f_s_2)
    almost(fitted, expected)

    # test separate=True option:
    (mag_1_, mag_2_) = model.magnification(time, separate=True)
    almost(mag_1, mag_1_)
    almost(mag_2, mag_2_)
Exemplo n.º 28
0
def test_event_chi2_binary_source_2datasets():
    """
    simple test if chi2 calculation for binary source
    works fine for 2 datasets
    """
    model = mm.Model({
        't_0_1': 5000.,
        'u_0_1': 0.05,
        't_0_2': 5100.,
        'u_0_2': 0.15,
        't_E': 25.
    })
    model_1 = mm.Model(model.parameters.source_1_parameters)
    model_2 = mm.Model(model.parameters.source_2_parameters)

    # prepare fake data:
    time = np.linspace(4900., 5200., 600)
    mag_1 = model_1.magnification(time)
    mag_2 = model_2.magnification(time)
    flux = 100. * mag_1 + 300. * mag_2 + 50.
    data_1 = mm.MulensData(data_list=[time, flux, 1. + 0. * time],
                           phot_fmt='flux')
    flux = 20. * mag_1 + 30. * mag_2 + 50.
    data_2 = mm.MulensData(data_list=[time, flux, 1. + 0. * time],
                           phot_fmt='flux')

    # Calculate chi^2:
    event = mm.Event([data_1, data_2], model)
    np.testing.assert_almost_equal(event.get_chi2(), 0.)
    np.testing.assert_almost_equal(event.get_chi2_for_dataset(0), 0.)
    np.testing.assert_almost_equal(event.get_chi2_for_dataset(1), 0.)
    # Make sure that changing parameters changes chi2:
    model.parameters.t_E = 100.
    assert event.get_chi2() > 1., 'wrong chi2'
    model.parameters.t_E = 25.
    np.testing.assert_almost_equal(event.get_chi2(), 0.)
    model.parameters.t_0_1 = 5010.
    assert event.get_chi2() > 1., 'wrong chi2'
    model.parameters.t_0_1 = 5000.

    # Test combination of Model.set_source_flux_ratio_for_band() and
    # Event.get_chi2_for_dataset().
    data_1.bandpass = '******'
    event.model.set_source_flux_ratio_for_band('some', 3.)
    np.testing.assert_almost_equal(event.get_chi2_for_dataset(0), 0.)
Exemplo n.º 29
0
def test_model_event_coords():
    """
    Check if coordinates are properly passed from Model to Event.
    """
    coords = "18:12:34.56 -23:45:55.55"
    model = mm.Model({'t_0': 0, 'u_0': .5, 't_E': 10.}, coords=coords)
    event = mm.Event(model=model)
    np.testing.assert_almost_equal(event.coords.ra.value, 273.144)
    np.testing.assert_almost_equal(event.coords.dec.value, -23.765430555555554)
def generate_model(finite_source=True):
    if finite_source:
        model = mm.Model({'t_0_1': 5000., 'u_0_1': 0.05,
                          't_0_2': 5005., 'u_0_2': 0.003, 'rho_2': 0.005,
                          't_E': 30.})
        model.set_limb_coeff_gamma('I', 0.5)
        model.set_limb_coeff_gamma('V', 0.7)
        model.set_magnification_methods(
            [5004., 'finite_source_LD_Yoo04', 5006.])
    else:
        model = mm.Model({'t_0_1': 5000., 'u_0_1': 0.05,
                          't_0_2': 5005., 'u_0_2': 0.003,
                          't_E': 30.})

    # model.set_source_flux_ratio_for_band('I', 0.01)
    # model.set_source_flux_ratio_for_band('V', 0.005)

    return model