Пример #1
0
def test_caustic_for_orbital_motion():
    """
    check if caustics calculated for different epochs in orbital motion model
    are as expected
    """
    q = 0.1
    s = 1.3
    params = {
        't_0': 100.,
        'u_0': 0.1,
        't_E': 10.,
        'q': q,
        's': s,
        'ds_dt': 0.5,
        'alpha': 0.,
        'dalpha_dt': 0.
    }
    model = mm.Model(parameters=params)

    model.update_caustics()
    almost(model.caustics.get_caustics(), mm.Caustics(q=q, s=s).get_caustics())

    model.update_caustics(100. + 365.25 / 2)
    almost(model.caustics.get_caustics(),
           mm.Caustics(q=q, s=1.55).get_caustics())
Пример #2
0
def test_caustic():
    s = 0.548
    q = 0.0053

    caustics = mm.Caustics(q=q, s=s)

    x, y = caustics.get_caustics(n_points=1000)
    for i in range(0, len(x), 100):
        index = np.argmin(
            np.sqrt((test_caustics['X']-x[i])**2+(test_caustics['Y']-y[i])**2))

        np.testing.assert_almost_equal(
            x[i], test_caustics['X'][index], decimal=5)
        np.testing.assert_almost_equal(
            y[i], test_caustics['Y'][index], decimal=5)
Пример #3
0
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
import numpy as np

import MulensModel as mm


s = 1.2
q = 0.5
n_points = 200

color = np.linspace(0., 1., n_points)

# First, we use standard procedure to plot the caustic. You will see that
# the points are distributed non-uniformly, i.e., the density is higher
# near cusps. We also add color to indicate order of plotting.
# It turns out to be a complicated shape.
caustic = mm.Caustics(s=s, q=q)
caustic.plot(c=color, n_points=n_points)
plt.axis('equal')
plt.colorbar()
plt.title('standard plotting')

# Second, we use uniform sampling. The density of points is constant.
# Here the color scale indicates x_caustic values.
plt.figure()
sampling = mm.UniformCausticSampling(s=s, q=q)
points = [sampling.caustic_point(c) for c in color]
x = [p.real for p in points]
y = [p.imag for p in points]
plt.scatter(x, y, c=color)
plt.axis('equal')
plt.colorbar()
Пример #5
0
         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')
plt.xlabel('Time ($(t-t_0)/t_E$)')
plt.ylabel('Magnification in $2.5log_{10}$ scale')
plt.title('Light Curve of Binary Lense')
plt.grid()
plt.legend()
plt.savefig('2_3b.pdf')
plt.show()

#Part c
#find caustics waves
model_2 = mm.Caustics(q, s)
X, Y = model_2.get_caustics()

#get the trajectory of the source
plt.plot(traj_1.x, traj_1.y, 'y-', label='Orbital Motion')
plt.plot(traj_2.x, traj_2.y, 'r-', label='Static')
plt.plot(traj_3.x, traj_3.y, 'b-', label='Parallax')
plt.plot(X[0], X[0], 'g-', label='Static Caustics')
plt.scatter(X, Y, s=0.05, color='g')
plt.xlabel('X coordinates (X/$r_E$)')
plt.ylabel('Y coordinates (Y/$r_E$)')
plt.legend()
plt.title('Trajectory for Gravitational Microlensing')
plt.grid()
plt.savefig('2_3c.pdf')
plt.show()
Пример #6
0
        plt.title('Ratio of Magnification:\n{} Frame, {} Solver, q={}'.format(
            p.origin_title, p.solver_title, p.q))
        plt.gcf().set_size_inches(8, 6)
        plt.show()

# Plot the individual magnifications:
if True:
    for (i, p) in enumerate(plot):
        # This makes a plot of the difference in magnification from the parameters
        # at the top of the code vs. the MulensModel calculation
        print('The maximum value of magnification from MulensModel is',
              max(mag_MM))
        p.plot_magnification(region=region,
                             region_lim=region_lim,
                             log_colorbar=False)
        caustic = mm.Caustics(s=s, q=p.q)
        caustic.plot(s=1)
        plt.show()

#	kwarg['norm'] = colors.LogNorm()
    plt.scatter(x_array,
                y_array,
                c=mag_MM,
                s=(400 / res)**2,
                cmap='plasma',
                lw=None)
    mag_plot = plt.colorbar()
    mag_plot.ax.tick_params(labelsize=10)
    mag_plot.set_label('Magnification via MulensModel')
    plt.xlabel('X-position of source', fontsize=12)
    plt.ylabel('Y-position of source', fontsize=12)
Пример #7
0
for i in range(len(phi)):

    coeffs = coeff(esp_1, esp_2, z_1c, z_2c, phi[i])

    roots = np.roots(coeffs)
    z.append(np.conjugate(roots))

z_lin = np.reshape(z, len(z) * 4)

#find the position on source plane
zeta = z_lin - esp_1 / (np.conjugate(z_lin) -
                        z_1c) - esp_2 / (np.conjugate(z_lin) - z_2c)

#find the casutic wave with Mulens Model

model = mm.Caustics(0.2, 1.2)  #input as (q,s)
X, Y = model.get_caustics(n_points=400)

#plot the caustic wave
plt.scatter(-np.real(zeta), np.imag(zeta), label='Python')
#inverse of the x value since the mulensmodel take the heavy mass on the positive axis
plt.scatter(X, Y, label='Mulens')
plt.xlabel('X coordinates (X/$r_E$)')
plt.ylabel('Y coordinates (Y/$r_E$)')
plt.title('Caustic Wave for Gravitational Microlensing')
plt.grid()
plt.legend()
plt.savefig('2_1.pdf')
plt.show()

#From the graph, we can see that shape of the caustics curve
    'psi': 90.
}

model = mm.Model(parameters)
model_parameters = mm.ModelParameters(parameters)

# Basic plotting:
model.plot_trajectory(caustics=True, lenses=True)  # 'lenses" is a new keyword.
# It plots dots at positions of lenses.
plt.show()

# Plot using mm.Caustics:
keys = {'s_21', 's_31', 'psi', 'q_21', 'q_31'}  # We need only these keys
caustic_parameters = {key: parameters[key] for key in keys}
# New initialization of Caustics:
caustics_1 = mm.Caustics(**caustic_parameters)
caustics_1.plot()
plt.show()

# Find positions of the components and use them to plot the caustic:
positions = model_parameters.lens_positions()  # This is new function. One can
# add parameter: epoch=2456789.01 so that orbital motion is taken into account.
print(positions)  # Prints a (3,2) numpy array
caustics_2 = mm.Caustics(
    q_21=parameters['q_21'], q_31=parameters['q_31'],
    lens_positions=positions)  # This keyword should also work for binary lens.
caustics_2.plot()
plt.show()

# Change position of one of the components and then plot the caustic:
# (this is why we want two ways to init Caustics for 3L events)