Very Basic Tutorial

The main MulensModel features are in classes Model, MulensData, and Event.

This is a very simple tutorial showing how you might use those classes. It is also available (somewhat expanded) as a Jupyter notebook. Please note that MulensModel is written in Python3. If you’re using Python2.X, then start by adding from __future__ import print_function at the begin of your codes and be advised that we don’t guarantee that everything will work.

This example shows OGLE-2003-BLG-235/MOA-2003-BLG-53, the first microlensing planet. See Bond et al. (2004). The data were downloaded from the NASA Exoplanet Archive.

Defining a Model

The most basic thing to do is to define a microlensing model. For example, you could define a point lens model as follows:

import MulensModel as mm
my_pspl_model = mm.Model({'t_0': 2452848.06, 'u_0': 0.133, 't_E': 61.5})

Or a model with 2-bodies:

my_1S2L_model = mm.Model({'t_0': 2452848.06, 'u_0': 0.133,
     't_E': 61.5, 'rho': 0.00096, 'q': 0.0039, 's': 1.120,
     'alpha': 223.8})

(by default alpha is in degrees, but you could explicitly specify radians)

Since rho is set, define a time range and method for finite source effects:

my_1S2L_model.set_magnification_methods([2452833., 'VBBL', 2452845.])

Then, you might plot those models:

import matplotlib.pyplot as plt
my_pspl_model.plot_magnification(t_range=[2452810, 2452890],
    subtract_2450000=True, color='red', linestyle=':')
my_1S2L_model.plot_magnification(t_range=[2452810, 2452890],
    subtract_2450000=True, color='black')

Introducing Data

Suppose you also had some data you want to import:

import os
path = os.path.join(mm.DATA_PATH, 'photometry_files', 'OB03235')
OGLE_data = mm.MulensData(
     file_name=os.path.join(path, 'OB03235_OGLE.tbl.txt'),
     comments=['\\', '|'])
MOA_data = mm.MulensData(
     file_name=os.path.join(path, 'OB03235_MOA.tbl.txt'),
     comments=['\\', '|'], phot_fmt='flux')

Combining Data with a Model

Now suppose you wanted to combine the two together:

my_event = mm.Event(datasets=[OGLE_data, MOA_data],

And you wanted to plot the result:

my_event.plot_model(t_range=[2452810, 2452890], subtract_2450000=True,
plt.xlim(2810, 2890)
plt.ylim(19.25, 16.6)

This fits for the fluxes so that the model and data are all on the flux scale set by the first dataset. It does NOT fit for the best microlensing parameters. If you wanted to know how good the fit is, you can get the chi2:


If you want to optimize that chi2, we leave it up to you to determine the best method for doing this.