コード例 #1
0
def plot_lens_bodies(plots):
    """Plots the positions of the lens bodies in the lens plane."""

    caustic1 = caus(lens=plots[0], solver='SG12')
    caustic2 = caus(lens=plots[1], solver='SG12')
    caustic1.plot_lens_bodies()
    plt.show()
    caustic2.plot_lens_bodies()
    plt.show()
コード例 #2
0
def make_plot():

    for p in plot:
        for plot_type in plot_types:

            if plot_type == 'num_images':
                p.plot_num_images(errors_only=False,
                                  save=False,
                                  print_errors=True)
                caustic = caus(lens=p, solver='SG12')
                caustic.plot_caustic(s=1, color='yellow', lw=0)
                plt.show()

            if plot_type == 'magn':
                p.plot_magnification(outliers=False,
                                     log_colorbar=True,
                                     cutoff=cutoff,
                                     save=False)
                caustic = caus(lens=p, solver='SG12')
                #caustic.plot_caustic(s=1, color='blue')
                plt.show()

            if plot_type == 'num_iamges_coeff':
                p.plot_num_images_coeff(color_magn=True,
                                        log_colorbar=True,
                                        save=False)

            if plot_type == 'magn_coeff':
                p.plot_magn_coeff(color_num=True,
                                  cutoff=cutoff,
                                  outliers=False,
                                  save=False)

            if plot_type == 'coeff':
                p.plot_coefficients(cutoff=cutoff,
                                    log_colorbar=False,
                                    outliers=False,
                                    save=False)

            if plot_type == 'coeff_tstat':
                p.plot_coeff_tstat(cutoff=None,
                                   outliers=False,
                                   sample_res=sample_res,
                                   save=False)

            if plot_type == 'position_tstat':
                p.plot_position_tstat(cutoff=None,
                                      outliers=False,
                                      sample_res=sample_res,
                                      save=False)

            if plot_type == 'fits':
                p.write_to_fits()
コード例 #3
0
def plot_num_images(plots, num_images_params):
    """Plots a map of the number of images for a TripleLens object."""

    plots[0].plot_num_images(**num_images_params)
    caustic = caus(lens=plots[0], solver='SG12')
    caustic.plot_caustic(points=10000, s=1, color='red', lw=0)
    plt.show()

    plots[1].plot_num_images(**num_images_params)
    caustic = caus(lens=plots[1], solver='SG12')
    caustic.plot_caustic(points=10000, s=1, color='red', lw=0)
    plt.show()
コード例 #4
0
def plot_magnification(plots, magn_params, show_caustic):
    """Plots a magnification map for a TripleLens object."""

    plots[0].plot_magnification(**magn_params)
    caustic = caus(lens=plots[0], solver='SG12')
    if show_caustic:
        caustic.plot_caustic(points=10000, s=1, color='red', lw=0)
    plt.show()

    plots[1].plot_magnification(**magn_params)
    caustic = caus(lens=plots[1], solver='SG12')
    if show_caustic:
        caustic.plot_caustic(points=10000, s=1, color='red', lw=0)
    plt.show()
コード例 #5
0
def plot_trajectory(plot, param_str, v_e, t0, u0, theta1cm, t_start, t_stop):
    """
	Plots the source trajectory, determined by the TripleLens object in a
	Rhie (2002) configuration, and by varaibles unpacked from source_dict.
	"""

    z0 = u0 * (math.cos(math.pi / 2. - theta1cm) +
               1.j * math.sin(math.pi / 2. - theta1cm))
    t_traj = np.linspace(t_start, t_stop, 1000)
    z_traj = z0 + (t_traj - t0) * v_e * (math.cos(theta1cm) +
                                         1.j * math.sin(theta1cm))
    x_traj = z_traj.real
    y_traj = z_traj.imag
    caustic = caus(lens=plot, solver='SG12')
    caustic.plot_caustic(points=10000, s=1, color='red', lw=0)
    plt.scatter(x_traj, y_traj, color='blue', s=1, lw=0)
    plt.xlim(min(x_traj), max(x_traj))
    plt.ylim(min(y_traj), max(y_traj))
    plt.title('{} Trajectory with Caustics'.format(param_str))
    plt.xlabel('Position - Real')
    plt.ylabel('Position - Imaginary')
    plt.show()
コード例 #6
0
ファイル: SolverOriginMass.py プロジェクト: ZoeySamples/ulens
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()
コード例 #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()
コード例 #8
0
def get_binary_lens_plot(save_fig=False,
                         show_fig=True,
                         arrow_on=True,
                         caustic_on=False):

    param = []
    plot = []

    param = (({
        's': s,
        'q': q,
        'origin': origin,
        'solver': solver,
        'plot_frame': plot_frame,
        'refine_region': refine_region,
        'SFD': SFD
    }))
    plot = (BL(**param))

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

    plt.scatter(z1.real, z1.imag, s=1000, color='blue')
    plt.scatter(z2.real, z2.imag, s=2000, color='red', marker='*')

    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')

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

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

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

    if show_fig:
        plt.show()
    else:
        plt.clf()
コード例 #9
0
def num_images_demo():

	param = [[None] * len(origins) for j in range(len(mass_ratios))]
	plot = [[None] * len(origins) for j in range(len(mass_ratios))]
	fig, ax = plt.subplots(len(mass_ratios), len(origins))

	for (i, q) in enumerate(mass_ratios):
		for (j, origin) in enumerate(origins):
			idx = 1 + j + len(origins)*i

			# Initialize each binary lens system with the BinaryLens class.
			param[i][j] = ({'s': s, 'q': q, 'res': res, 'origin': origin,
					'region': region, 'region_lim': region_lim,
					'solver': solver, 'SFD': SFD, 'refine_region': refine_region})
			plot[i][j] = BL(**param[i][j])

			# 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+8*jump, 6)	# 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[3]] + blueslist[clist[2]:clist[3]] +
						 ornglist[clist[4]:clist[5]] + blueslist[clist[4]:clist[5]])

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

			# Discretize the colormap.
			bounds = np.linspace(-0.5, 5.5, 7)	# This is the discretized boundary.
			norm = colors.BoundaryNorm(bounds, cmap_images.N) # This is the scale.
			ticks = np.linspace(0,5,6)	# These are the tickmark locations.

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

			plot[i][j].get_position_arrays()
			plot[i][j].get_num_images_array()
			(x, y, num_images) = (plot[i][j].x_array, plot[i][j].y_array,
						plot[i][j].num_images)

			# Create and adjust the plots appropriately.
			ax[i][j] = plt.subplot(len(mass_ratios), len(origins), idx)
			sc = ax[i][j].scatter(x, y, c=num_images, vmin=0, vmax=5, **kwargs)
			caustic = caus(lens=plot[i][j], solver='SG12')
			caustic.plot_caustic(s=1, color='yellow', points=5000, lw=0)
			get_plot_parameters(plot=plot[i][j], ax=ax[i][j], i=i, j=j)

	# Add an axis for the color bar.
	cbar = fig.add_axes([0.08, 0.895, 0.60, 0.05])
	num_color = plt.colorbar(sc, cax=cbar, cmap=kwargs['cmap'], ticks=ticks, orientation='horizontal')
	num_color.set_label('Number of Images', fontsize=12+len(origins), labelpad=-62)
	cbar.axes.tick_params(labelsize=12)
	get_plot_text(plot, fig)

	# Save the plot as a .png file.
	if save_fig:
		file_name = '../../Tables/images_origin_.png'
		save_png(file_name)

	if show_fig:
		plt.show()
コード例 #10
0
ファイル: plots.py プロジェクト: ZoeySamples/ulens
def make_plot():

    for p in plot:
        for plot_type in plot_types:

            if plot_type == 'num_images':
                p.plot_num_images(errors_only=False,
                                  save=False,
                                  print_errors=False,
                                  s=3)
                caustic = caus(lens=p, solver='SG12')
                caustic.plot_caustic(points=10000, s=1, color='red', lw=0)
                plt.show()

            if plot_type == 'magn':

                #FIXME: Caustic does not show up properly on magnification plots
                p.plot_magnification(outliers=False,
                                     log_colorbar=True,
                                     cutoff=None,
                                     save=False)
                caustic = caus(lens=p, solver='SG12')
                #		caustic.plot_caustic(s=1, color='red', lw=0)
                plt.show()

            if plot_type == 'lens_bodies':
                caustic = caus(lens=plot[0], solver='SG12')
                caustic.plot_lens_bodies()
                caustic.plot_caustic(s=1, color='red', lw=0)
                plt.show()

            if plot_type == 'num_images_coeff':
                p.plot_num_images_coeff(color_magn=TPrue,
                                        log_colorbar=True,
                                        region='caustic',
                                        region_lim=None,
                                        save=False)

            if plot_type == 'magn_coeff':
                p.plot_magn_coeff(color_num=True,
                                  cutoff=cutoff,
                                  outliers=False,
                                  region=region,
                                  region_lim=region_lim,
                                  save=False)

            if plot_type == 'coeff':
                p.plot_coefficients(cutoff=cutoff,
                                    log_colorbar=False,
                                    outliers=False,
                                    region=region,
                                    region_lim=region_lim,
                                    save=False)

            if plot_type == 'coeff_tstat':
                p.plot_coeff_tstat(cutoff=None,
                                   outliers=False,
                                   region=region,
                                   region_lim=region_lim,
                                   sample_res=sample_res,
                                   save=False)

            if plot_type == 'position_tstat':
                p.plot_position_tstat(cutoff=None,
                                      outliers=False,
                                      region=region,
                                      region_lim=region_lim,
                                      sample_res=sample_res,
                                      save=False)

            if plot_type == 'fits':
                p.write_to_fits()