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_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
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()