Exemple #1
0
def get_Rhie_object(phi, s1, s2, q1, q2):
    """Returns a TL object in the Rhie (2002) parameter space."""

    param = ({
        's2': s2,
        's1': s1,
        'phi': phi,
        'q2': q2,
        'q1': q1,
        'res': res,
        'origin': origin,
        'region': region,
        'region_lim': region_lim,
        'solver': solver,
        'system': system,
        'plot_frame': plot_frame,
        'refine_region': False
    })
    plot = TL(**param)
    return plot
Exemple #2
0
def get_new_object(plot, phi, s1, s2, q1, q2):
    """
	Returns a TL object in some other TripleLens parameter space. The
	parameter space is defined according to origin_new and system_new
	conversion parameters called before function call.
	"""

    q1_new = q1
    q2_new = q2
    s1_new = np.abs(plot.z2 - plot.z1)
    s2_new = np.abs(plot.z3 - plot.z1)
    s3_temp = np.abs(plot.z2 - plot.z3)
    phi_new = ((180. / math.pi) * math.acos(
        (s1_new**2 + s2_new**2 - s3_temp**2) / (2. * s1_new * s2_new)))
    if plot.phi > 0:
        phi_new *= -1.  # Fixes accidental reflections over the x-axis since
        # law of cosines removes direction
    refine_region = True
    SFD = True

    param_new = ({
        's2': s2_new,
        's1': s1_new,
        'phi': phi_new,
        'q2': q2_new,
        'q1': q1_new,
        'res': res,
        'origin': origin_new,
        'region': region,
        'region_lim': region_lim,
        'solver': solver,
        'SFD': SFD,
        'system': system_new,
        'plot_frame': plot_frame,
        'refine_region': refine_region
    })
    plot_new = (TL(**param_new))

    return plot_new
def plot_images():

    num_outer_plots = len(ps_mass_ratios) * len(mp_mass_ratios)
    num_inner_plots = len(origins) * len(solvers)
    fig = plt.figure(figsize=(10, 8))
    outer = gridspec.GridSpec(len(ps_mass_ratios),
                              len(mp_mass_ratios),
                              wspace=0.25,
                              hspace=0.38)
    param = [[None] * num_inner_plots for j in range(num_outer_plots)]
    plot = [[None] * num_inner_plots for j in range(num_outer_plots)]

    for (i, q2), (j, q1) in product(enumerate(mp_mass_ratios),
                                    enumerate(ps_mass_ratios)):
        outer_idx = j + i * len(mp_mass_ratios)
        inner = gridspec.GridSpecFromSubplotSpec(len(origins),
                                                 len(solvers),
                                                 subplot_spec=outer[outer_idx],
                                                 wspace=0.1,
                                                 hspace=0.25)

        for (k, origin), (l, solver) in product(enumerate(origins),
                                                enumerate(solvers)):
            inner_idx = l + k * len(solvers)
            (m, n) = (outer_idx, inner_idx)

            # Initialize each triple lens system with the TripleLens class.
            param[m][n] = ({
                's2': s2,
                's1': s1,
                'phi': phi,
                'q2': q2,
                'q1': q1,
                'res': res,
                'origin': origin,
                'region': region,
                'region_lim': region_lim,
                'solver': solver,
                'SFD': SFD,
                'system': system,
                'plot_frame': plot_frame,
                'refine_region': refine_region
            })
            plot[m][n] = TL(**param[m][n])

            roots = plot[m][n].get_roots(x=0., y=0.)
            accepted_images = plot[m][n].get_accepted_solutions(x=0., y=0.)
            rejected_images = []

            for root in roots:
                if root in accepted_images:
                    continue
                else:
                    rejected_images.append(root)

            accepted_images = np.array(accepted_images)
            rejected_images = np.array(rejected_images)

            caustic = caus(lens=plot[m][n], solver='SG12')
            z1 = caustic.z1
            z2 = caustic.z2
            z3 = caustic.z3

            ax = plt.subplot(inner[n])
            fig.add_subplot(ax)

            s = 15
            #	sc = ax.scatter(z1.real, z1.imag, marker='*', s=10*s, color='blue', lw=0)
            #	sc = ax.scatter(z2.real, z2.imag, marker='o', s=4*s, color='blue', lw=0)
            #	sc = ax.scatter(z3.real, z3.imag, marker='o', s=s, color='blue', lw=0)

            sc = ax.scatter(accepted_images.real,
                            accepted_images.imag,
                            s=s,
                            color='black',
                            lw=0)

            sc = ax.scatter(rejected_images.real,
                            rejected_images.imag,
                            s=s,
                            color='red',
                            lw=0)

            #	caustic.plot_caustic(s=1, color='orange', points=5000, lw=0)

            plt.xlim(-5, 5)
            plt.ylim(-5, 5)

            ax.axes.get_xaxis().set_visible(False)
            ax.axes.get_yaxis().set_visible(False)

        #	ax.axes.text(4.5, 4.5, 'num accepted: {}'.format(len(accepted_images)), ha='center',
        #			va='center', fontsize=8)

    get_plot_text(plot, fig)

    if save_fig:
        file_name = '../../Tables/TL/soln_slvr_q_{}_.png'.format(system)
        save_png(file_name)

    if show_fig:
        plt.show()
def num_images_demo():

    num_outer_plots = len(ps_mass_ratios) * len(mp_mass_ratios)
    num_inner_plots = len(origins) * len(solvers)
    fig = plt.figure(figsize=(10, 8))
    outer = gridspec.GridSpec(len(ps_mass_ratios),
                              len(mp_mass_ratios),
                              wspace=0.25,
                              hspace=0.38)
    param = [[None] * num_inner_plots for j in range(num_outer_plots)]
    plot = [[None] * num_inner_plots for j in range(num_outer_plots)]

    for (i, q2), (j, q1) in product(enumerate(mp_mass_ratios),
                                    enumerate(ps_mass_ratios)):
        outer_idx = j + i * len(mp_mass_ratios)
        inner = gridspec.GridSpecFromSubplotSpec(len(origins),
                                                 len(solvers),
                                                 subplot_spec=outer[outer_idx],
                                                 wspace=0.1,
                                                 hspace=0.25)

        for (k, origin), (l, solver) in product(enumerate(origins),
                                                enumerate(solvers)):
            inner_idx = l + k * len(solvers)
            (m, n) = (outer_idx, inner_idx)

            # Initialize each triple lens system with the TripleLens class.
            param[m][n] = ({
                's2': s2,
                's1': s1,
                'phi': phi,
                'q2': q2,
                'q1': q1,
                'res': res,
                'origin': origin,
                'region': region,
                'region_lim': region_lim,
                'solver': solver,
                'SFD': SFD,
                'system': system,
                'plot_frame': plot_frame,
                'refine_region': refine_region
            })
            plot[m][n] = TL(**param[m][n])
            """
			cmap = plt.cm.Blues
			cmaplist = [cmap(i) for i in range(cmap.N)]
			cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)
			bounds = np.linspace(-0.5,10.5,12)
			norm = colors.BoundaryNorm(bounds, cmap.N)
			ticks = np.linspace(0,10,11)
			"""

            # Use our two base colormaps
            orng = plt.cm.Oranges
            blues = plt.cm.Blues

            # Get the list values from each colormap
            ornglist = [orng(i) for i in range(orng.N)
                        ]  # This list contains 256 colors.
            blueslist = [blues(i) for i in range(blues.N)
                         ]  # This list contains 256 colors.

            # Select the regions of the colormaps we want, and slice them together.
            start = 0
            jump = 24
            clist = np.linspace(start, start + 10 * jump,
                                11)  # Slicing points for merged list.
            clist = [int(val)
                     for val in clist]  # Convert the list into integers.

            # Create the new list with segments of the Oranges and Blues colormaps.
            colorlist = (
                ornglist[clist[0]:clist[4]] + blueslist[clist[1]:clist[2]] +
                ornglist[clist[4]:clist[5]] + blueslist[clist[3]:clist[4]] +
                ornglist[clist[6]:clist[7]] + blueslist[clist[5]:clist[6]] +
                ornglist[clist[8]:clist[9]] + blueslist[clist[7]:clist[8]])

            # Create new colormap.
            cmap_images = LinSegCmap.from_list('Custom cmap', colorlist, 256)

            # Discretize the colormap.
            bounds = np.linspace(-0.5, 10.5,
                                 12)  # This is the discretized boundary.
            norm = colors.BoundaryNorm(bounds,
                                       cmap_images.N)  # This is the scale.
            ticks = np.linspace(0, 10, 11)  # These are the tickmark locations.

            kwargs = plot[m][n].check_kwargs()
            kwargs['cmap'] = cmap_images
            kwargs['norm'] = norm
            kwargs['s'] = 1
            kwargs['lw'] = 0

            # Get the data for the plots.
            plot[m][n].get_position_arrays()
            plot[m][n].get_num_images_array()
            (x, y, num_images) = (plot[m][n].x_array, plot[m][n].y_array,
                                  plot[m][n].num_images)

            # Create and adjust the plots appropriately.
            ax = plt.subplot(inner[n])
            sc = ax.scatter(x, y, c=num_images, vmin=0, vmax=10, **kwargs)
            #		caustic = caus(lens=plot[m][n], solver='SG12')
            #		caustic.plot_caustic(s=1, color='yellow', points=5000, lw=0)
            get_inner_plot_parameters(plot=plot[m][n], ax=ax, k=k, l=l)
            fig.add_subplot(ax)

    # Add an axis for the color bar.
    cbar = fig.add_axes([0.08, 0.89, 0.50, 0.04])
    num_color = plt.colorbar(sc,
                             cax=cbar,
                             cmap=cmap_images,
                             ticks=ticks,
                             orientation='horizontal')
    num_color.set_label('Number of Images', fontsize=15, labelpad=-70)
    cbar.axes.tick_params(labelsize=12)
    get_plot_text(plot, fig)

    # Save the plot as a .png file.
    if save_fig:
        file_name = '../../Tables/TL/num_slvr_q_{}_.png'.format(system)
        save_png(file_name)

    if show_fig:
        plt.show()
def magnification_demo():

    num_outer_plots = len(ps_mass_ratios) * len(mp_mass_ratios)
    num_inner_plots = len(origins) * len(solvers)
    fig = plt.figure(figsize=(10, 8))
    outer = gridspec.GridSpec(len(ps_mass_ratios),
                              len(mp_mass_ratios),
                              wspace=0.25,
                              hspace=0.38)
    param = [[None] * num_inner_plots for j in range(num_outer_plots)]
    plot = [[None] * num_inner_plots for j in range(num_outer_plots)]

    for (i, q2), (j, q1) in product(enumerate(mp_mass_ratios),
                                    enumerate(ps_mass_ratios)):
        outer_idx = j + i * len(mp_mass_ratios)
        inner = gridspec.GridSpecFromSubplotSpec(len(origins),
                                                 len(solvers),
                                                 subplot_spec=outer[outer_idx],
                                                 wspace=0.1,
                                                 hspace=0.25)

        for (k, origin), (l, solver) in product(enumerate(origins),
                                                enumerate(solvers)):
            inner_idx = l + k * len(solvers)
            (m, n) = (outer_idx, inner_idx)

            # Initialize each triple lens system with the TripleLens class.
            param[m][n] = ({
                's2': s2,
                's1': s1,
                'phi': phi,
                'q2': q2,
                'q1': q1,
                'res': res,
                'origin': origin,
                'region': region,
                'region_lim': region_lim,
                'solver': solver,
                'SFD': SFD,
                'system': system,
                'plot_frame': plot_frame,
                'refine_region': refine_region
            })
            plot[m][n] = TL(**param[m][n])

            #	cmap = plt.cm.YlOrRd
            cmap = plt.cm.gray
            cmaplist = [cmap(i) for i in range(cmap.N)]
            cmaplist = cmaplist[20:]
            cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)
            ticks = np.array([1, 10])

            kwargs = plot[m][n].check_kwargs()
            kwargs['cmap'] = cmap
            kwargs['norm'] = colors.LogNorm()
            kwargs['s'] = 1
            kwargs['lw'] = 0

            # Get the data for the plots.
            plot[m][n].get_position_arrays()
            plot[m][n].get_magnification_array()
            (x, y, magnification) = (plot[m][n].x_array, plot[m][n].y_array,
                                     plot[m][n].magn_array)

            # Create and adjust the plots appropriately.
            ax = plt.subplot(inner[n])
            sc = ax.scatter(x, y, c=magnification, vmin=1, vmax=10, **kwargs)
            #		caustic = caus(lens=plot[m][n], solver='SG12')
            #		caustic.plot_caustic(s=1, color='yellow', points=5000, lw=0)
            get_inner_plot_parameters(plot=plot[m][n], ax=ax, k=k, l=l)
            fig.add_subplot(ax)

    # Add an axis for the color bar.
    cbar = fig.add_axes([0.08, 0.89, 0.50, 0.04])
    magn_color = plt.colorbar(sc,
                              cax=cbar,
                              cmap=kwargs['cmap'],
                              ticks=ticks,
                              orientation='horizontal')
    magn_color.set_label('Magnification', fontsize=15, labelpad=-70)
    cbar.axes.tick_params(labelsize=12)
    get_plot_text(plot, fig)

    # Save the plot as a .png file.
    if save_fig:
        file_name = '../../Tables/TL/mag_slvr_q_{}_.png'.format(system)
        save_png(file_name)

    if show_fig:
        plt.show()
Exemple #6
0
testBL = BL(**param)
causticBL = Caus(lens=testBL)

param = ({
    's1': s1,
    's2': s2,
    'q1': q1,
    'q2': q2,
    'phi': phi,
    'origin': originTL,
    'region': region,
    'solver': solver,
    'system': system,
    'plot_frame': plot_frame
})
testTL = TL(**param)
causticTL = Caus(lens=testTL, solver=solver)

# Plot the caustic alone
causticBL.plot_caustic(s=1, color='blue')
#causticTL.plot_caustic(s=1, color='red')
plt.show()

#Interesting parameters:
solver = 'SG12'
originBL = 'star'
originTL = 'body3'

plot_frame = 'caustic'

s = 0.8
Exemple #7
0
def get_triple_lens_plot(save_fig=False,
                         show_fig=True,
                         arrow_on=False,
                         caustic_on=False):

    param = []
    plot = []

    param = (({
        's1': s1,
        's2': s2,
        'q1': q1,
        'q2': q2,
        'system': system,
        'origin': origin,
        'solver': solver,
        'phi': phi,
        'plot_frame': plot_frame,
        'SFD': SFD
    }))
    plot = (TL(**param))

    causticUL = caus(lens=plot)
    z1 = causticUL.z1
    z2 = causticUL.z2
    z3 = causticUL.z3

    plt.scatter(z1.real, z1.imag, s=2000, color='red', marker='*')
    plt.scatter(z2.real, z2.imag, s=1000, color='blue')
    if system == 'SPM':
        plt.scatter(z3.real, z3.imag, s=400, color='purple')
    else:
        plt.scatter(z3.real, z3.imag, s=(q2 / q1) * 1000, color='blue')

    if arrow_on:
        ax = plt.axes()
        ax.arrow(z2.real - 0.05,
                 z2.imag,
                 z1.real - z2.real + 0.1,
                 z1.imag - z2.imag,
                 width=1e-6,
                 length_includes_head=True,
                 head_width=2e-2,
                 head_length=5e-2,
                 fc='k',
                 ec='k')
        ax.arrow(z1.real + 0.05,
                 z1.imag,
                 z2.real - z1.real - 0.1,
                 z1.imag - z2.imag,
                 width=1e-6,
                 length_includes_head=True,
                 head_width=2e-2,
                 head_length=5e-2,
                 fc='k',
                 ec='k')

        dx = (z3.real - z2.real)
        dy = (z3.imag - z2.imag)
        ax.arrow(z2.real + 0.10 * dx,
                 z2.imag + 0.10 * dy,
                 0.8 * (dx),
                 0.8 * (dy),
                 width=1e-6,
                 length_includes_head=True,
                 head_width=1.5e-2,
                 head_length=3e-2,
                 fc='k',
                 ec='k')
        ax.arrow(z3.real - 0.10 * dx,
                 z3.imag - 0.10 * dy,
                 -0.8 * (dx),
                 -0.8 * (dy),
                 width=1e-6,
                 length_includes_head=True,
                 head_width=1.5e-2,
                 head_length=3e-2,
                 fc='k',
                 ec='k')

    if caustic_on:
        caustic = caus(lens=plot)
        caustic.plot_caustic(s=1, lw=0, color='orange')

    title = 'Triple Lens System'
    got_plot_adjustments(title=title)

    if save_fig:
        name = 'TL_model'
        _save_fig(name, arrow_on, caustic_on)

    if show_fig:
        plt.show()
    else:
        plt.clf()
Exemple #8
0
x = [0.0, 1.3219, 1.0799, 1.2489]
y = [0.0, -0.0771, 0.0985, 0.0209]
s1 = [1.0, 1.35, 1.1, 0.9357]
s2 = [1.5, 1.5, 1.5, 1.5]
q1 = [1.0, 0.00578, 0.99, 0.99]
q2 = [1e-1, 1e-1, 1e-1, 1e-1]
phi = 0

param = []
test = []
for i in range(len(x)):
    param.append({
        'x': x[i],
        'y': y[i],
        's1': s1[i],
        's2': s2[i],
        'phi': phi,
        'q1': q1[i],
        'q2': q2[i],
        'origin': origin,
        'solver': solver,
        'system': system,
        'SFD': SFD
    })
    test.append(TL(**param[-1]))

for t in test:
    #	t.print_image_position(print_input=False)
    t.print_magnification(print_input=False)
    print('_' * 40)
Exemple #9
0
            's2': s2,
            's1': s1,
            'phi': phi,
            'q2': q2,
            'q1': q1,
            'res': res,
            'origin': origin,
            'region': region,
            'region_lim': region_lim,
            'solver': solver,
            'SFD': SFD,
            'system': system,
            'plot_frame': plot_frame,
            'refine_region': refine_region
        })
        plot.append(TL(**param[-1]))

plot_types = []
plot_types.append('num_images')
plot_types.append('magn')
#plot_types.append('lens_bodies')
#plot_types.append('num_iamges_coeff')
#plot_types.append('magn_coeff')
#plot_types.append('coeff')
#plot_types.append('fits')
#plot_types.append('coeff_tstat')
#plot_types.append('position_tstat')

make_plot()
print('\n')