def test_2_masses_success(): lens = mm.Lens() lens.mass_1 = 1.0*u.solMass lens.mass_2 = 0.3*u.solMass assert lens.mass_1 == 1.0*u.solMass assert lens.mass_2 == 0.3*u.solMass assert lens.total_mass == 1.3*u.solMass
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
def test_init_success(): lens_1 = mm.Lens(mass_1=1.8*u.solMass, mass_2=3.*u.solMass) np.testing.assert_almost_equal(lens_1.mass_1.value, 1.8) np.testing.assert_almost_equal(lens_1.mass_2.value, 3.) lens_2 = mm.Lens(mass=1.8*u.solMass, distance=3.*10.**3*u.pc) np.testing.assert_almost_equal(lens_2.mass.value, 1.8) np.testing.assert_almost_equal(lens_2.mass_1.value, 1.8) np.testing.assert_almost_equal(lens_2.distance.value, 3.*10.**3) lens_3 = mm.Lens(mass_1=1.0*u.solMass, q=0.1, s=0.9) np.testing.assert_almost_equal(lens_3.mass_1.value, 1.0) np.testing.assert_almost_equal(lens_3.mass_2.value, 0.1) assert lens_3.s == 0.9 lens_4 = mm.Lens(s=1.0, q=0.1) assert lens_4.q == 0.1 assert lens_4.s == 1.0
def test_3_body_success(): lens_1 = mm.Lens( total_mass=1.3*u.solMass, q=[0.1, 0.2], s=[0.1, 0.3]) np.testing.assert_almost_equal(lens_1.mass_1.value, 1.) np.testing.assert_almost_equal(lens_1.mass_2.value, 0.1) np.testing.assert_almost_equal(lens_1.mass_3.value, 0.2) lens_2 = mm.Lens() lens_2.mass_1 = 0.7*u.solMass lens_2.mass_2 = 0.1*u.solMass lens_2.mass_3 = 0.2*u.solMass np.testing.assert_almost_equal(lens_2.mass_1.value, 0.7) np.testing.assert_almost_equal(lens_2.mass_2.value, 0.1) np.testing.assert_almost_equal(lens_2.mass_3.value, 0.2) np.testing.assert_almost_equal(lens_2.total_mass.value, 1.)
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
def test_a_proj_success(): lens = mm.Lens(mass_1=1.0*u.solMass, mass_2=0.1*u.solMass, a_proj=1.0*u.au, distance=6.*u.kpc) assert lens.total_mass == 1.1*u.solMass assert lens.q == 0.1
def test_q_success(): lens = mm.Lens() lens.mass_1 = 1.0*u.solMass lens.q = 10.**3 assert lens.mass_2 == 10.**3*u.solMass assert lens.total_mass == (1.0+10.**3)*u.solMass
def test_q_total_mass(): lens = mm.Lens() lens.q = 0.25 lens.total_mass = 0.8*u.solMass np.testing.assert_almost_equal(lens.mass_1.value, 0.64) np.testing.assert_almost_equal(lens.mass_2.value, 0.16)
def test_distance_success(): lens = mm.Lens() lens.distance = 5.*1000.*u.pc assert lens.distance == 5000.*u.pc
def test_single_mass_success(): lens_single = mm.Lens() lens_single.mass = 0.5*u.solMass assert lens_single.mass == 0.5*u.solMass assert lens_single.mass_1 == 0.5*u.solMass assert lens_single.total_mass == 0.5*u.solMass
""" 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
file_.write('# columns = distance in kpc\n# rows = mass in solMass\n') file_.write('{0:6}'.format(' ')) for dist in lens_dist: file_.write('{0:6.2f}'.format(dist)) file_.write('\n') # Calculate the Einstein Ring for a given lens mass... for mass in lens_mass: for file_ in file_list: file_.write('{0:6.4}'.format(mass)) # ...and a given distance for dist in lens_dist: # Setup the microlensing system system = mm.MulensSystem( lens=mm.Lens(mass=mass, distance=dist), source=source, mu_rel=mu_rel) # Output the calculated Einstein radius to a file file_thetaE.write('{0:6.2f}'.format(system.theta_E.value)) file_rE.write('{0:6.2f}'.format(system.r_E.value)) file_rEtilde.write('{0:6.2f}'.format(system.r_E_tilde.value)) file_tE.write('{0:6.1f}'.format(system.t_E.value)) # Add new line characters to files for file_ in file_list: file_.write('\n') # Close the files for file_ in file_list: file_.close()