Example #1
0
def makeTruth():
	W,H = 500,500
	ra,dec = 0,0
	width = 0.1
	
	wcs = Tan()
	wcs.crval[0] = ra
	wcs.crval[1] = dec
	wcs.crpix[0] = W/2.
	wcs.crpix[1] = H/2.
	scale = width / float(W)
	wcs.cd[0] = -scale
	wcs.cd[1] = 0
	wcs.cd[2] = 0
	wcs.cd[3] = -scale
	wcs.imagew = W
	wcs.imageh = H
	tanwcs1 = wcs
	wcs1 = FitsWcs(wcs)

	# rotate.
	W2 = int(W*np.sqrt(2.))
	H2 = W2
	rot = 30.
	cr = np.cos(np.deg2rad(rot))
	sr = np.sin(np.deg2rad(rot))
	wcs = Tan()
	wcs.crval[0] = ra
	wcs.crval[1] = dec
	wcs.crpix[0] = W2/2.
	wcs.crpix[1] = H2/2.
	wcs.cd[0] = -scale * cr
	wcs.cd[1] =  scale * sr
	wcs.cd[2] = -scale * sr
	wcs.cd[3] = -scale * cr
	wcs.imagew = W2
	wcs.imageh = H2
	wcs2 = FitsWcs(wcs)

	photocal = SdssPhotoCal(SdssPhotoCal.scale)
	psf = NCircularGaussianPSF([2.0], [1.0])
	sky = 0.
	skyobj = ConstantSky(sky)
	flux = SdssFlux(1.)

	# image 1
	image = np.zeros((H,W))
	invvar = np.zeros_like(image) + 1e-4
	img1 = Image(data=image, invvar=invvar, psf=psf, wcs=wcs1,
				 sky=skyobj, photocal=photocal, name='Grid1')
	# image 2
	image = np.zeros((H2,W2))
	invvar = np.zeros_like(image) + 1e-4
	img2 = Image(data=image, invvar=invvar, psf=psf, wcs=wcs2,
				 sky=skyobj, photocal=photocal, name='Grid2')

	tractor = SDSSTractor([img1, img2])

	np.random.seed(42)

	# arcsec
	#re = 10.
	#phi = 30.

	# grid: ra -- ab
	for i,(x,a) in enumerate(zip(np.linspace(50, W-50, 10),
								np.linspace(0.1, 1, 10))):
		#       dec -- phi
		#       dec -- r_e
		for j,(y,re) in enumerate(zip(np.linspace(50, H-50, 10),
									  exp(np.linspace(np.log(1), np.log(30.), 10)))):
									  #exp(np.linspace(np.log(0.1), np.log(20.), 10)))):
			#np.linspace(0, 90, 10, endpoint=False),
			ra,dec = tanwcs1.pixelxy2radec(x, y)
			pos = RaDecPos(ra, dec)
			phi = np.random.uniform(0, 360)
			#eg = ExpGalaxy(pos, flux, re, a, p)
			#eg = HoggExpGalaxy(pos, flux, re, a, phi)
			eg = HoggDevGalaxy(pos, flux, re, a, phi)
			tractor.catalog.append(eg)

	imgs = tractor.getModelImages()
	for i,img in enumerate(imgs):
		plt.clf()
		plt.imshow(img, interpolation='nearest', origin='lower')
		plt.colorbar()
		plt.savefig('grid%i.png' % i)


	for i,img in enumerate(imgs):
		timg = tractor.getImage(i)
		noise = (np.random.normal(size=timg.invvar.shape) *
				 np.sqrt(1. / timg.invvar))
		timg.data = img + noise

		plt.clf()
		plt.imshow(timg.getImage(),
				   interpolation='nearest', origin='lower')
		plt.colorbar()
		plt.savefig('grid%in.png' % i)

		pyfits.writeto('grid%in.fits' % i, timg.getImage(), clobber=True)

	return tractor.images
def makeTruth():
    W, H = 500, 500
    ra, dec = 0, 0
    width = 0.1

    wcs = Tan()
    wcs.crval[0] = ra
    wcs.crval[1] = dec
    wcs.crpix[0] = W / 2.
    wcs.crpix[1] = H / 2.
    scale = width / float(W)
    wcs.cd[0] = -scale
    wcs.cd[1] = 0
    wcs.cd[2] = 0
    wcs.cd[3] = -scale
    wcs.imagew = W
    wcs.imageh = H
    tanwcs1 = wcs
    wcs1 = FitsWcs(wcs)

    # rotate.
    W2 = int(W * np.sqrt(2.))
    H2 = W2
    rot = 30.
    cr = np.cos(np.deg2rad(rot))
    sr = np.sin(np.deg2rad(rot))
    wcs = Tan()
    wcs.crval[0] = ra
    wcs.crval[1] = dec
    wcs.crpix[0] = W2 / 2.
    wcs.crpix[1] = H2 / 2.
    wcs.cd[0] = -scale * cr
    wcs.cd[1] = scale * sr
    wcs.cd[2] = -scale * sr
    wcs.cd[3] = -scale * cr
    wcs.imagew = W2
    wcs.imageh = H2
    wcs2 = FitsWcs(wcs)

    photocal = SdssPhotoCal(SdssPhotoCal.scale)
    psf = NCircularGaussianPSF([2.0], [1.0])
    sky = 0.
    skyobj = ConstantSky(sky)
    flux = SdssFlux(1.)

    # image 1
    image = np.zeros((H, W))
    invvar = np.zeros_like(image) + 1e-4
    img1 = Image(data=image,
                 invvar=invvar,
                 psf=psf,
                 wcs=wcs1,
                 sky=skyobj,
                 photocal=photocal,
                 name='Grid1')
    # image 2
    image = np.zeros((H2, W2))
    invvar = np.zeros_like(image) + 1e-4
    img2 = Image(data=image,
                 invvar=invvar,
                 psf=psf,
                 wcs=wcs2,
                 sky=skyobj,
                 photocal=photocal,
                 name='Grid2')

    tractor = SDSSTractor([img1, img2])

    np.random.seed(42)

    # arcsec
    #re = 10.
    #phi = 30.

    # grid: ra -- ab
    for i, (x, a) in enumerate(
            zip(np.linspace(50, W - 50, 10), np.linspace(0.1, 1, 10))):
        #       dec -- phi
        #       dec -- r_e
        for j, (y, re) in enumerate(
                zip(np.linspace(50, H - 50, 10),
                    exp(np.linspace(np.log(1), np.log(30.), 10)))):
            #exp(np.linspace(np.log(0.1), np.log(20.), 10)))):
            #np.linspace(0, 90, 10, endpoint=False),
            ra, dec = tanwcs1.pixelxy2radec(x, y)
            pos = RaDecPos(ra, dec)
            phi = np.random.uniform(0, 360)
            #eg = ExpGalaxy(pos, flux, re, a, p)
            #eg = HoggExpGalaxy(pos, flux, re, a, phi)
            eg = HoggDevGalaxy(pos, flux, re, a, phi)
            tractor.catalog.append(eg)

    imgs = tractor.getModelImages()
    for i, img in enumerate(imgs):
        plt.clf()
        plt.imshow(img, interpolation='nearest', origin='lower')
        plt.colorbar()
        plt.savefig('grid%i.png' % i)

    for i, img in enumerate(imgs):
        timg = tractor.getImage(i)
        noise = (np.random.normal(size=timg.invvar.shape) *
                 np.sqrt(1. / timg.invvar))
        timg.data = img + noise

        plt.clf()
        plt.imshow(timg.getImage(), interpolation='nearest', origin='lower')
        plt.colorbar()
        plt.savefig('grid%in.png' % i)

        pyfits.writeto('grid%in.fits' % i, timg.getImage(), clobber=True)

    return tractor.images
Example #3
0
def main():
	#W,H = 500,500
	W,H = 100,100
	ra,dec = 0,0
	width = 0.1 # deg

	wcs = Tan()
	wcs.crval[0] = ra
	wcs.crval[1] = dec
	wcs.crpix[0] = W/2.
	wcs.crpix[1] = H/2.
	scale = width / float(W)
	wcs.cd[0] = -scale
	wcs.cd[1] = 0
	wcs.cd[2] = 0
	wcs.cd[3] = -scale
	wcs.imagew = W
	wcs.imageh = H
	tanwcs1 = wcs
	wcs1 = FitsWcs(wcs)

	photocal = SdssPhotoCal(SdssPhotoCal.scale)
	psf = NCircularGaussianPSF([2.0], [1.0])
	sky = 0.
	skyobj = ConstantSky(sky)
	flux = SdssFlux(1.)

	# image 1
	image = np.zeros((H,W))
	invvar = np.zeros_like(image) + 1e-4
	img1 = Image(data=image, invvar=invvar, psf=psf, wcs=wcs1,
				 sky=skyobj, photocal=photocal, name='Grid1')

	# arcsec
	re = 10.
	ab = 0.5
	phi = 30.

	x,y = W/2,H*0.66
	ra,dec = tanwcs1.pixelxy2radec(x, y)
	pos = RaDecPos(ra, dec)
	eg1 = HoggExpGalaxy(pos, flux, re, ab, phi)
	patch1 = eg1.getModelPatch(img1)

	x,y = W/2,H*0.33
	ra,dec = tanwcs1.pixelxy2radec(x, y)
	pos = RaDecPos(ra, dec)
	eg2 = ExpGalaxy(pos, flux, re, ab, phi)
	patch2 = eg2.getModelPatch(img1)

	model = np.zeros_like(image)
	patch1.addTo(model)
	patch2.addTo(model)

	plt.clf()
	plt.imshow(model, interpolation='nearest', origin='lower')
	plt.colorbar()
	plt.savefig('hg.png')
Example #4
0
	print 'boxes:', len(xlo)
	plt.plot(np.vstack((xlo,xhi,xhi,xlo,xlo)),
			 np.vstack((ylo,ylo,yhi,yhi,ylo)), 'b-')
	plt.savefig('g6.png')

	plt.axis([0,1000,0,1000])
	plt.savefig('g7.png')


	#sys.exit(0)

	ra,dec = 1.,45.
	width = (2./7.2) 	# in deg
	W,H = 500,500

	wcs = Tan()
	wcs.crval[0] = ra
	wcs.crval[1] = dec
	wcs.crpix[0] = W/2.
	wcs.crpix[1] = H/2.
	scale = width / float(W)
	wcs.cd[0] = -scale
	wcs.cd[1] = 0
	wcs.cd[2] = 0
	wcs.cd[3] = -scale
	wcs.imagew = W
	wcs.imageh = H

	wcs = FitsWcs(wcs)

	pos = RaDecPos(ra, dec)
Example #5
0
    plt.clf()
    print 'boxes:', len(xlo)
    plt.plot(np.vstack((xlo, xhi, xhi, xlo, xlo)),
             np.vstack((ylo, ylo, yhi, yhi, ylo)), 'b-')
    plt.savefig('g6.png')

    plt.axis([0, 1000, 0, 1000])
    plt.savefig('g7.png')

    #sys.exit(0)

    ra, dec = 1., 45.
    width = (2. / 7.2)  # in deg
    W, H = 500, 500

    wcs = Tan()
    wcs.crval[0] = ra
    wcs.crval[1] = dec
    wcs.crpix[0] = W / 2.
    wcs.crpix[1] = H / 2.
    scale = width / float(W)
    wcs.cd[0] = -scale
    wcs.cd[1] = 0
    wcs.cd[2] = 0
    wcs.cd[3] = -scale
    wcs.imagew = W
    wcs.imageh = H

    wcs = FitsWcs(wcs)

    pos = RaDecPos(ra, dec)