Exemple #1
0
    def init():
        # Set some SIE lens-model parameters and pack them into an array:
        l_amp = lamp  # Einstein radius
        l_xcen = -2.5  # x position of center
        l_ycen = 2.5  # y position of center
        l_axrat = lax  # minor-to-major axis ratio
        l_pa = lpa  # major-axis position angle (degrees) c.c.w. from x axis
        lpar = np.asarray([l_amp, l_xcen, l_ycen, l_axrat, l_pa])
        lenspar = np.asarray([l_amp, lsig, l_xcen, l_ycen, l_axrat, l_pa])

        # The following lines will plot the un-lensed and lensed images side by side:
        (xg, yg) = ldf.sie_grad(x, y, lpar)
        g_lensimage = ldf.gauss_2d(x - xg, y - yg, gpar)
        lens_source = ldf.gauss_2d(x, y, lenspar)
        lens_source[lens_source < 0.6] = np.nan

        ax2.imshow(g_lensimage, **myargs, clim=(vmin, vmax))
        lens = ax2.imshow(lens_source, **lensargs, clim=(vmin, vmax))
        ax2.set_yticklabels([])
        ax2.set_xticklabels([])
        ax2.set_yticks([])
        ax2.set_xticks([])

        txt = ax2.text(20, 457, 'Lensed Image', size=15, color='w', zorder=5)
        txt.set_path_effects(
            [PathEffects.withStroke(linewidth=5, foreground='k')])
        return lens,
def update(val):
    g_axrat = sgaxrat.val
    g_xcen = sgxcen.val
    g_ycen = sgycen.val
    g_pa = sgpa.val 
    g_sig = sgsig.val
    l_axrat = slaxrat.val

    gpar = np.asarray([g_amp, g_sig, g_xcen, g_ycen, g_axrat, g_pa])
    lpar = np.asarray([l_amp, l_xcen, l_ycen, l_axrat, l_pa])
    
    #g_image = ldf.gauss_2d(x, y, gpar)
    (xg, yg) = ldf.sie_grad(x, y, lpar)
    g_lensimage = ldf.gauss_2d(x-xg, y-yg, gpar)
    f.set_data(g_lensimage)
    fig.canvas.draw_idle()
Exemple #3
0
	def lens_object(lax,lamp=1.5,lsig=0.05,lx=0.,ly=0.,lpa=0.):
		# Set some SIE lens-model parameters and pack them into an array:
		l_amp = lamp	    # Einstein radius
		l_xcen = lx	    # x position of center
		l_ycen = ly   	    # y position of center
		l_axrat = lax  	    # minor-to-major axis ratio
		l_pa = lpa	    # major-axis position angle (degrees) c.c.w. from x axis
		lpar = np.asarray([l_amp, l_xcen, l_ycen, l_axrat, l_pa])
		lpar2 = np.asarray([l_amp, l_xcen, l_ycen, 2., l_pa]) # rax of 2.
		lenspar = np.asarray([l_amp, lsig, l_xcen, l_ycen, l_axrat, l_pa])

		# The following lines will plot the un-lensed and lensed images side by side:
		(xg, yg) = ldf.sie_grad(x, y, lpar)
		g_lensimage = ldf.gauss_2d(x-xg, y-yg, gpar)
		lens_source = ldf.gauss_2d(x, y, lenspar)
		lens_source[lens_source < 0.6] = np.nan
		return g_lensimage,lens_source
Exemple #4
0
	xhilo = [-2.5, 2.5]
	yhilo = [-2.5, 2.5]
	x = (xhilo[1] - xhilo[0]) * np.outer(np.ones(ny), np.arange(nx)) / float(nx-1) + xhilo[0]
	y = (yhilo[1] - yhilo[0]) * np.outer(np.arange(ny), np.ones(nx)) / float(ny-1) + yhilo[0]

	# Set some SIE lens-model parameters and pack them into an array:
	l_amp = 1.5	    # Einstein radius
	l_xcen = 0.	    # x position of center
	l_ycen = 0.   	    # y position of center
	l_axrat = 1.  	    # minor-to-major axis ratio
	l_pa = 0.	    # major-axis position angle (degrees) c.c.w. from x axis
	lpar = np.asarray([l_amp, l_xcen, l_ycen, l_axrat, l_pa])
	lenspar = np.asarray([l_amp, 0.05, l_xcen, l_ycen, l_axrat, l_pa])

	# The following lines will plot the un-lensed and lensed images side by side:
	(xg, yg) = ldf.sie_grad(x, y, lpar)

	plt.figure(figsize=(8,4))
	gs1 = gridspec.GridSpec(1,2)
	gs1.update(wspace=0.03)
	cmap = plt.cm.viridis
	cir = plt.Circle((250,250),150,fill=False,ls='--',color='C0')

	ax1 = plt.subplot(gs1[0])
	im = ax1.imshow(xg,**myargs)#,clim=(0.5,2.2)) # set to make the lens the same always
	vmin, vmax = im.get_clim()
	ax1.add_artist(cir)
	ax1.set_yticklabels([]); ax1.set_xticklabels([])
	ax1.set_yticks([]); ax1.set_xticks([])

	txt = ax1.text(20,457,'x deflection', size=15, color='w')
Exemple #5
0
def lookup(par):
    """
    PURPOSE: Calculate the flux received in a SDSSIII fiber over the intrinsic flux as a
    function of impact parameter, Einstein radius, axis ratio, size, etc...

    USAGE: f_f/f_i = lookup(par[b, q_l, P.A_l, amp, sigma_s, xcen_s, ycen_s,q_s, P.A_s])

    ARGUMENTS:
    pars:
       par[0]: Einstein Radius
       par[1]: Axis ratio of lens
       par[2]: Position angle of lens (c.c.w. major-axis rotation w.r.t. x-axis)
       par[3]: Amplitude of source galaxy
       par[4]: Intermediate-axis sigma of source galaxy
       par[5]: x coordinate of source galaxy
       par[6]: y coordinate of source galaxy
       par[7]: Axis ratio of source
       par[8]: Position angle of source (c.c.w. major-axis rotation w.r.t. x-axis)

    RETURNS:  Ratio of flux in fiber w.r.t intrinsic flux

    WRITTEN:  Ryan A. Arneson, U. of Utah, 2010
    """
    #Define the pixel scale to be 0.01"/pixel

    myargs = {
        'interpolation': 'nearest',
        'origin': 'lower',
        'cmap': cm.gray,
        'hold': False
    }

    psf = g.gauss2d(800, 150)

    nx = 1600.
    ny = 1600.
    ximg = n.outer(n.ones(ny), n.arange(nx, dtype='float')) - 800.
    yimg = n.outer(n.arange(ny, dtype='float'), n.ones(nx)) - 800.

    #lpar_guess = n.asarray([b, xcen, ycen, q, P.A.])
    lpar_guess = n.asarray([par[0], 0.0, 0.0, par[1], par[2]])
    #gpar_guess = n.asarray([amp., sigma, xcen, ycen, q, P.A.])
    gpar_guess = n.asarray([par[3], par[4], par[5], par[6], par[7], par[8]])
    xg, yg = ldf.sie_grad(ximg, yimg, lpar_guess)
    lmodel = ldf.gauss_2d(ximg - xg, yimg - yg, gpar_guess)
    #lmodel = signal.fftconvolve(lmodel, psf, mode='same')
    #lmodel = lmodel[1:1601,1:1601]

    fiber = yimg
    for i in range(0, 1600):
        for j in range(0, 1600):
            fiber[i, j] = n.sqrt(fiber[i, j]**2 + (j - 800.)**2)

    for i in range(0, 1600):
        for j in range(0, 1600):
            if fiber[i, j] <= 100:
                fiber[i, j] = 1.0
            else:
                fiber[i, j] = 0.0

    fiber = signal.fftconvolve(fiber, psf, mode='same')
    fiber = fiber[1:1601, 1:1601]

    f_f = n.sum(lmodel * fiber)
    #calculate the intrinisic flux (i.e. b=0)
    lpar_guess[0] = 0.0
    ximg = n.outer(n.ones(ny), n.arange(nx, dtype='float')) - 800.
    yimg = n.outer(n.arange(ny, dtype='float'), n.ones(nx)) - 800.
    xg, yg = ldf.sie_grad(ximg, yimg, lpar_guess)
    lmodel2 = ldf.gauss_2d(ximg - xg, yimg - yg, gpar_guess)
    #lmodel2 = signal.fftconvolve(lmodel2, psf, mode='same')
    #lmodel2 = lmodel2[1:1601,1:1601]
    f_i = n.sum(lmodel2 * fiber)

    mag = f_f / f_i
    #p.imshow(n.hstack((lmodel*fiber,lmodel2*fiber)),**myargs)
    return mag
g_xcen = 0.0  # x position of center
g_ycen = 0.0  # y position of center
g_axrat = 1.0 # minor-to-major axis ratio
g_pa = 0.0    # major-axis position angle (degrees) c.c.w. from x axis
gpar = np.asarray([g_amp, g_sig, g_xcen, g_ycen, g_axrat, g_pa])

# Set some SIE lens-model parameters and pack them into an array:
l_amp = 1.5   # Einstein radius
l_xcen = 0.0  # x position of center
l_ycen = 0.0  # y position of center
l_axrat = 1.0 # minor-to-major axis ratio
l_pa = 0.0    # major-axis position angle (degrees) c.c.w. from x axis
lpar = np.asarray([l_amp, l_xcen, l_ycen, l_axrat, l_pa])

#g_image = ldf.gauss_2d(x, y, gpar)
(xg, yg) = ldf.sie_grad(x, y, lpar)
g_lensimage = ldf.gauss_2d(x-xg, y-yg, gpar)

f = plt.imshow(g_lensimage, **myargs)

ax = plt.axes([0.25,0.1,0.65,0.03])
slaxrat = Slider(ax, 'Lens Axis Ratio', 0.0, 5.0, valinit=l_axrat)

ax = plt.axes([0.25,0.15,0.65,0.03])
sgaxrat = Slider(ax, 'Gaussian Axis Ratio', 0.0, 5.0, valinit=g_axrat)

ax = plt.axes([0.25,0.20,0.65,0.03])
sgpa = Slider(ax, 'Gaussian Major-Axis Angle', 0.0, 360.0, valinit=g_pa)

ax = plt.axes([0.25,0.25,0.65,0.03])
sgxcen = Slider(ax, 'Gaussian X-center', -1.5, 1.5, valinit=g_xcen)