def test_binary_lens_hexadecapole(): """ tests hexadecapole and quadrupole calculation for planetary case with rho=0.001 and 3 values of gamma: 0, 0.5, and 1.0 """ s = 1.35 q = 0.00578 rho = 0.001 x = 0.7142010570568691 - s * q / (1. + q) y = 0.00189679191923936 pspl_mag = 4.691830779895085 reference_00 = [5.017252440557196, 4.9587638949353146, pspl_mag] reference_05 = [4.981368071884021, 4.932070583431292, pspl_mag] reference_10 = [4.9454837032108445, 4.905377271927269, pspl_mag] m1 = 1. / (1. + q) m2 = q / (1. + q) bl = mm.BinaryLens(m1, m2, s) result_00 = bl.hexadecapole_magnification( x, y, rho=rho, gamma=0.0, all_approximations=True) result_05 = bl.hexadecapole_magnification( x, y, rho=rho, gamma=0.5, all_approximations=True) result_10 = bl.hexadecapole_magnification( x, y, rho=rho, gamma=1.0, all_approximations=True) np.testing.assert_almost_equal(result_00, reference_00) np.testing.assert_almost_equal(result_05, reference_05) np.testing.assert_almost_equal(result_10, reference_10)
def test_vbbl_1(): s = 0.8 q = 0.1 m_1 = 1. / (1. + q) m_2 = q / (1. + q) bl = mm.BinaryLens(m_1, m_2, s) result = bl.vbbl_magnification(0.01, 0.01, 0.01) np.testing.assert_almost_equal(result, 18.2834436, decimal=3)
def test_ac_1(): s = 0.8 q = 0.1 m_1 = 1. / (1. + q) m_2 = q / (1. + q) bl = mm.BinaryLens(m_1, m_2, s) result = bl.adaptive_contouring_magnification( 0.01, 0.01, 0.01, accuracy=0.019, ld_accuracy=1e-3) np.testing.assert_almost_equal(result, 18.2834436, decimal=3)
def test_vbbl(): """ check basic magnification calculation using VBBL """ s = 0.8 q = 0.1 m_1 = 1. / (1. + q) m_2 = q / (1. + q) bl = mm.BinaryLens(m_1, m_2, s) result = bl.vbbl_magnification(0.01, 0.01, 0.01) np.testing.assert_almost_equal(result, 18.2834436, decimal=3)
def test_small_q(): """ run calculations with small mass-ratio """ q = 1.e-8 s = 1.8 x = s - 1. / s y = 5.e-7 * 0. m_1 = 1. / (1. + q) m_2 = q / (1. + q) lens = mm.BinaryLens(m_1, m_2, s) result = lens.point_source_magnification(x, y) np.testing.assert_almost_equal(result, 3.6868957, decimal=3)
def test_ac(): """ check basic magnification calculation using AdaptiveContouring """ s = 0.8 q = 0.1 m_1 = 1. / (1. + q) m_2 = q / (1. + q) bl = mm.BinaryLens(m_1, m_2, s) # Previous version was failing because of bug in AC: # result = bl.adaptive_contouring_magnification( # 0.01, 0.01, 0.01, accuracy=0.019, ld_accuracy=1e-3) # np.testing.assert_almost_equal(result, 18.2834436, decimal=3) result = bl.adaptive_contouring_magnification(0.06, 0.01, 0.01, accuracy=0.019, ld_accuracy=1e-3) np.testing.assert_almost_equal(result, 11.403036510555962, decimal=3)
def test_standard_vs_shear(): """ check if standard and 0 shear calculations give the same result """ s = 1.8 q = 1e-6 x = s - 1. / s y = 0. m_1 = 1. / (1. + q) m_2 = q / (1. + q) lens = mm.BinaryLensWithShear(m_1, m_2, s, convergence_K=0.0, shear_G=complex(0, 0)) lens_standard = mm.BinaryLens(m_1, m_2, s) result = lens.point_source_magnification(x, y) result_standard = lens_standard.point_source_magnification(x, y) np.testing.assert_almost_equal(result, result_standard, decimal=5)
def test_ps_shear_1(): """ Test if vbbl_magnification() with shear 0 and convergence 0 gives the same result as point_source_magnification() """ s = 0.8 q = 0.1 m_1 = 1. / (1. + q) m_2 = q / (1. + q) blws = mm.BinaryLensWithShear(m_1, m_2, s, convergence_K=0.0, shear_G=complex(0, 0)) result = blws.point_source_magnification(0.01, 0.01) bl = mm.BinaryLens(m_1, m_2, s) result_ref = bl.point_source_magnification(0.01, 0.01) np.testing.assert_almost_equal(result, result_ref)
def magnif(q, s, rho): """ Find the magnification, trajectory and caustics curve of the binary lens system Parameters: s:seperation between two lens q:mass ratio between two lens rho:source scaled size Output: light: magnification amplitude of of the binary lens system traj.x,traj,y: trajectory of the binary lens system in x and y direction X,Y: x and y coordination of points on caustics curve """ #find mass with q m_1 = 1 / (q + 1) m_2 = q / (q + 1) #reset parameters params.q = q params.s = s params.rho = rho #find trajectory traj = mm.Trajectory(times, params, coords=coord) #find magnification light = [] model_1 = mm.BinaryLens(m_1, m_2, s) for i in range(len(traj.x)): light.append(model_1.vbbl_magnification(traj.x[i], traj.y[i], rho)) #find caustics curves model_2 = mm.Caustics(q, s) X, Y = model_2.get_caustics() return light, traj.x, traj.y, X, Y
'pi_E_E': 0, 'rho': rho, 'alpha': alpha, 's': s, 'q': q }) #get the trajectory of the source traj_1 = mm.Trajectory(times, params_1, coords=coord) traj_2 = mm.Trajectory(times, params_2, coords=coord) traj_3 = mm.Trajectory(times, params_3, parallax=paral, coords=coord) #get the magnification of the model light_1 = [] light_2 = [] light_3 = [] model_1 = mm.BinaryLens(m_1 / 11, m_2 / 11, s) for i in range(len(traj_1.x)): light_1.append(model_1.vbbl_magnification(traj_1.x[i], traj_1.y[i], rho)) light_2.append(model_1.vbbl_magnification(traj_2.x[i], traj_2.y[i], rho)) light_3.append(model_1.vbbl_magnification(traj_3.x[i], traj_3.y[i], rho)) #plot the light curve plt.plot(times_plot, 2.5 * np.log10(light_2), 'r--', label='Static') plt.plot(times_plot, 2.5 * np.log10(light_1), 'y-', lw=2, label='Orbital Motion') plt.plot(times_plot, 2.5 * np.log10(light_3), 'b--', label='Parallax')
}) plot.append(BL(**param[-1])) plot[-1].get_position_arrays(region=region, region_lim=region_lim) plot[-1].get_magnification_array() x_array = plot[0].x_array y_array = plot[0].y_array mag_BL = [None] * len(plot) for (i, p) in enumerate(plot): mag_BL[i] = p.magn_array blens = [] mag_MM = [] # Assuming the total system's mass is 1 unit: blens = (mm.BinaryLens(mass_1=1. / (1. + q), mass_2=q / (1. + q), separation=s)) """ # Assuming the star's mass is 1 unit: blens = (mm.BinaryLens(mass_1=1, mass_2=q, separation=s)) """ for i in range(len(x_array)): mag_MM.append( blens._point_source_WM95(source_x=-x_array[i], source_y=y_array[i])) """ plt.scatter(x_array, y_array, c = mag_BL[0]) plt.show() plt.scatter(x_com, y_com, c = mag_MM[0]) plt.show() """