Example #1
0
def test_simulate_microlensing_model_parameters():
    event = mock.MagicMock()
    telescope = mock.MagicMock()
    telescope.name = 'NDG'
    telescope.lightcurve_flux = np.array([[0, 1], [2, 2]]).T
    event.telescopes = []
    event.telescopes.append(telescope)

    model = microlsimulator.simulate_a_microlensing_model(event)

    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    assert -300 < parameters[0]
    assert parameters[0] < 300

    assert 0 < parameters[1]
    assert parameters[1] < 2

    assert 1 < parameters[2]
    assert parameters[2] < 500

    model = microlsimulator.simulate_a_microlensing_model(event, 'FSPL')

    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    assert parameters[1] < 0.1
    assert parameters[3] < 0.05

    model = microlsimulator.simulate_a_microlensing_model(event, 'DSPL')

    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    assert parameters[2] < 100
Example #2
0
def test_simulate_microlensing_model_parameters():
    event = mock.MagicMock()
    telescope = mock.MagicMock()
    telescope.name = 'NDG'
    telescope.lightcurve_flux = np.array([[0, 1], [2, 2]]).T
    event.telescopes = []
    event.telescopes.append(telescope)

    model = microlsimulator.simulate_a_microlensing_model(event)

    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    assert -300 < parameters[0]
    assert parameters[0] < 300

    assert 0 < parameters[1]
    assert parameters[1] < 2

    assert 1 < parameters[2]
    assert parameters[2] < 300

    model = microlsimulator.simulate_a_microlensing_model(event,'FSPL')

    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    assert parameters[1] < 0.1
    assert parameters[3] < 0.05

    model = microlsimulator.simulate_a_microlensing_model(event, 'DSPL')

    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    assert parameters[2] < 100
Example #3
0
def test_simulate_lightcurve_flux():
    event = mock.MagicMock()
    telescope = mock.MagicMock()
    telescope.name = 'NDG'
    telescope.lightcurve_flux = np.array([[0, 51, 69], [2, 42, 28.65]])
    event.telescopes = []
    event.telescopes.append(telescope)

    model = microlsimulator.simulate_a_microlensing_model(event)
    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    fake_flux_parameters = microlsimulator.simulate_fluxes_parameters(
        event.telescopes)

    pyLIMA_parameters = model.compute_pyLIMA_parameters(parameters +
                                                        fake_flux_parameters)

    microlsimulator.simulate_lightcurve_flux(model, pyLIMA_parameters, 'No')

    assert np.all(telescope.lightcurve_flux[:, 1] != [51, 42])
    assert np.all(telescope.lightcurve_flux[:, 2] != [69, 28.65])

    microlsimulator.simulate_lightcurve_flux(model, pyLIMA_parameters, 'Yes')

    assert np.all(telescope.lightcurve_flux[:, 1] != [51, 42])
    assert np.all(telescope.lightcurve_flux[:, 2] != [69, 28.65])
Example #4
0
def test_simulate_a_microlensing_model():
    event = mock.MagicMock()
    telescope = mock.MagicMock()
    telescope.name = 'NDG'
    telescope.lightcurve_flux = np.array([[0, 1], [2, 2]]).T
    event.telescopes = []
    event.telescopes.append(telescope)

    model = microlsimulator.simulate_a_microlensing_model(event)

    assert model.model_type == 'PSPL'
Example #5
0
def test_simulate_a_microlensing_model():
    event = mock.MagicMock()
    telescope = mock.MagicMock()
    telescope.name = 'NDG'
    telescope.lightcurve_flux = np.array([[0, 1], [2, 2]]).T
    event.telescopes = []
    event.telescopes.append(telescope)
    print event.telescopes[0].lightcurve_flux[:, 0]

    model = microlsimulator.simulate_a_microlensing_model(event)

    assert model.model_type == 'PSPL'
Example #6
0
def test_simulate_lightcurve_flux():
    event = mock.MagicMock()
    telescope = mock.MagicMock()
    telescope.name = 'NDG'
    telescope.lightcurve_flux = np.array([[0, 51, 69], [2, 42, 28.65]])
    event.telescopes = []
    event.telescopes.append(telescope)

    model = microlsimulator.simulate_a_microlensing_model(event)
    parameters = microlsimulator.simulate_microlensing_model_parameters(model)

    fake_flux_parameters = microlsimulator.simulate_fluxes_parameters(event.telescopes)

    pyLIMA_parameters = model.compute_pyLIMA_parameters(parameters + fake_flux_parameters)

    microlsimulator.simulate_lightcurve_flux(model, pyLIMA_parameters, 'No')

    assert np.all(telescope.lightcurve_flux[:, 1] != [51, 42])
    assert np.all(telescope.lightcurve_flux[:, 2] != [69, 28.65])

    microlsimulator.simulate_lightcurve_flux(model, pyLIMA_parameters, 'Yes')

    assert np.all(telescope.lightcurve_flux[:, 1] != [51, 42])
    assert np.all(telescope.lightcurve_flux[:, 2] != [69, 28.65])
Example #7
0
### If you want to simulate a event from space, you can use :

#my_space_telescope = microlsimulator.simulate_a_telescope('Gaia',my_own_creation,  2457585.5, 2457615.5,2, 'Space','G',
#                                                          uniform_sampling=True, spacecraft_name='Gaia')
# Note that the spacecraft name shoudl match JPL horizon ephemeris, see microlparallax. If you include this
# telescope in your analysis, you will need to give to the model parallax = ['Full,to_par] in order to have
# correct simulation.

#OK now we can choose the model we would like to simulate, here let's have a double source point lens one (DSPL). More details on models can be seen here [pyLIMA documentation](file/../../doc/build/html/pyLIMA.microlmodels.html)
#More details on parameters generation can be found here [pyLIMA documentation](file/../../doc/build/html/pyLIMA.microlsimulator.html)

### What model you want? Let's have DSPL!
my_own_model = microlsimulator.simulate_a_microlensing_model(
    my_own_creation,
    model='DSPL',
    parallax=['None', 0.0],
    xallarap=['None', 0.0],
    orbital_motion=['None', 0.0],
    source_spots='None')

# Find some model parameters. If you want specific parameters, you need to respet pyLIMA convention when you create your
# parameters. For the DSPL example, my_own_parameters = [to, uo, delta_to, delta_uo, tE].
my_own_parameters = microlsimulator.simulate_microlensing_model_parameters(
    my_own_model)

# Which source magnitude? Which blending?
# Same here, you can create your own flux parameters with the convention
# [ [magnitude_source_i, blending ratio_i]] for i in telescopes. In our case it looks :
# [ [magnitude_source_survey, blending ratio_survey], [ magnitude_source_SAAO_I, blending ratio_SAAO_I],
# [magnitude_source_SAAO_V, blending ratio_SAAO_V]], i.e [[18.5,0.3],[19.5,1.2],[20.2,1.6]] (example).
    while count < 2000:

        #model_choice = np.random.randint(0,5)
        model_choice = each
        t0 = np.random.uniform(
            np.percentile(wfirst3.lightcurve_flux[:, 0], 10),
            np.percentile(wfirst3.lightcurve_flux[:, 0], 90))
        tE = np.random.normal(30, 10)
        rho = np.random.uniform(-4, -1.30)

        rho = 10**rho

        if model_choice == 0:
            directory = 'PSPL'
            u0 = np.random.uniform(-0.5, 0.5)
            my_own_model = microlsimulator.simulate_a_microlensing_model(
                my_own_creation, model='PSPL')
            my_own_parameters = [t0, u0, tE]

        if model_choice == 1:
            directory = 'FSPL'
            u0 = np.random.uniform(-rho, rho)
            my_own_model = microlsimulator.simulate_a_microlensing_model(
                my_own_creation, model='FSPL')
            my_own_parameters = [t0, u0, tE, rho]

        if model_choice == 2:
            directory = 'DSPL'
            u0 = np.random.uniform(-0.5, 0.5)
            u02 = np.random.uniform(-u0, u0)
            sign = np.random.choice([-1, 1])
            delta_u0 = u0 - sign * u02