Ejemplo n.º 1
0
def test_mulenssystem():
    """test basic calculations of theta_E etc."""
    lens = mm.Lens(mass=0.64, distance=4.0)
    source = mm.Source(distance=8.0)
    system = mm.MulensSystem(lens=lens, source=source)

    assert abs(system.theta_E.value / 0.807177 - 1.) < 1.2e-4
    assert abs(system.r_E.value / 3.228708 - 1.) < 1.2e-4
    assert abs(system.r_E_tilde.value / 6.457416 - 1.) < 1.2e-4
Ejemplo n.º 2
0
def test_mulenssystem():
    """test some basic calculations"""
    kappa = 8.144183118384794 * u.mas / u.solMass
    lens = {'mass': 0.3 * u.solMass, 'dist': 4 * 10**3 * u.pc}
    source = {'dist': 8 * 10**3 * u.pc}
    mu_rel = 3. * u.mas / u.yr
    pi_rel = (lens['dist'].to(u.mas, equivalencies=u.parallax()) -
              source['dist'].to(u.mas, equivalencies=u.parallax()))
    thetaE = np.sqrt(kappa * lens['mass'] * pi_rel)
    tE = thetaE / mu_rel
    pi_E = pi_rel / thetaE

    test_system = mm.MulensSystem(lens=mm.Lens(mass=lens['mass'],
                                               distance=lens['dist']),
                                  source=mm.Source(distance=source['dist']),
                                  mu_rel=mu_rel)

    assert test_system.pi_rel == pi_rel
    assert abs(test_system.theta_E / thetaE - 1.) < 1.2e-4
    assert abs(test_system.pi_E / pi_E - 1.) < 1.2e-4
    assert isinstance(test_system.pi_E, float)
    assert abs(test_system.t_E / tE - 1.) < 1.2e-4
"""
Use Case 03: Define a Model Based on a Physical System

"""
from astropy import units as u
import matplotlib.pyplot as plt

import MulensModel as mm


# Define a Point Lens Model via MulensSystem
my_lens = mm.Lens(mass=0.5*u.solMass, distance=6.e3*u.pc)
my_source = mm.Source(distance=8.e3*u.pc)
my_system = mm.MulensSystem(lens=my_lens, source=my_source)
print('My Point Lens System')
print(my_system)

plt.figure()
plt.title('My Point Lens Magnification Curve')
my_system.plot_magnification(u_0=0.3)

my_system.mu_rel = 3. * u.mas / u.yr
my_model = mm.Model(
    {'t_0': 2457620., 'u_0': 0.3, 't_E': my_system.t_E})

# Define a 2-body model Version 1: Implementation via MulensSystem
two_body_lens = mm.Lens()
two_body_lens.mass_1 = 1.0 * u.solMass
two_body_lens.mass_2 = 0.1 * u.jupiterMass
two_body_lens.distance = 2.e3 * u.pc
    rE.tab - Physical Einstein ring radius in AU (Lens plane)

    rEtilde.tab - Projection of Einstein ring radius in AU (Observer plane)

    tE.tab - Einstein timescale in days for a given mu_rel

"""
import numpy as np
import astropy.units as u

import MulensModel as mm

# Define the source and lens parameters
lens_dist = np.arange(1., 8., 1.)
lens_mass = [10., 1., 0.3, 0.1, 0.01, 0.001]
source = mm.Source(distance=8.)
mu_rel = 4.

names = ['thetaE.tab', 'rE.tab', 'tE.tab', 'rEtilde.tab']

# Open the output files and print headers
file_thetaE = open(names[0], 'w')
file_rE = open(names[1], 'w')
file_tE = open(names[2], 'w')
file_rEtilde = open(names[3], 'w')
file_thetaE.write('# Angular Einstein ring radius in milliarcseconds.\n')
file_rE.write('# Physical Einstein ring radius in AU (Lens plane).\n')
file_rEtilde.write(
    '# Projection of Einstein ring radius in AU (Observer plane).\n')
file_tE.write(
    '# Einstein timescale in days for mu_rel = {0:4.1f} mas/yr.\n'.format(