Ejemplo n.º 1
0
	def retrieve(self, filetype, run, camcol, field, band=None, skipExisting=True):
		# FIXME!
		from astrometry.util.sdss_das import sdss_das_get
		outfn = self.getPath(filetype, run, camcol, field, band)
		#print 'Output filename:', outfn
		if skipExisting and os.path.exists(outfn):
			return
		return sdss_das_get(filetype, outfn, run, camcol, field, band,
							curl=self.curl)
Ejemplo n.º 2
0
	def retrieve(self, filetype, run, camcol, field, band=None, skipExisting=True):
		# FIXME!
		from astrometry.util.sdss_das import sdss_das_get
		outfn = self.getPath(filetype, run, camcol, field, band)
		#print 'Output filename:', outfn
		if skipExisting and os.path.exists(outfn):
			return
		return sdss_das_get(filetype, outfn, run, camcol, field, band,
							curl=self.curl)
Ejemplo n.º 3
0
def prepareTractor(initialPlots=False, useSimplexy=True, rcfcut=None):
    rcfi = [
        (5194, 2, 44, 22.500966),
        (4275, 2, 224, 90.003437),
        (3638, 2, 209, 90.002781),
        (4291, 2, 227, 90.003589),
        (4275, 2, 225, 90.003437),
        (5849, 4, 27, 20.003216),
        (5803, 5, 41, 19.990683),
        (5194, 2, 43, 22.500966),
        (3638, 2, 210, 90.002781),
        (5803, 5, 42, 19.990683),
        (5925, 5, 30, 19.933986),
        (5935, 5, 27, 20.000022),
    ]
    rcf = [(r, c, f) for r, c, f, i in rcfi if i < 85]
    print('RCF', rcf)

    sdss = DR7()

    bandname = 'i'

    if False:
        from astrometry.util import sdss_das as das
        from astrometry.util.sdss_filenames import sdss_filename
        for r, c, f in rcf:
            for filetype in ['fpC', 'fpM', 'psField', 'tsField']:
                fn = sdss_filename(filetype, r, c, f, band=bandname)
                print('Need', fn)
                #if not os.path.exists(fn):
                print('Getting from DAS')
                das.sdss_das_get(filetype, fn, r, c, f, band=bandname)

    # we only got some of them...
    rcf = [(5194, 2, 44), (5194, 2, 43), (5849, 4, 27), (5935, 5, 27)]
    rcf = [rcf[0], rcf[2]]
    print('RCF', rcf)

    rois = [
        # Mostly overlapping:
        #( 0, 1000, 0, 600 ),
        #( 1000, 2000, 600, 1200 ),

        # Pick up a big galaxy
        #( 600, 1600, 0, 600 ),
        #( 1000, 2000, 600, 1200 ),
        (800, 1600, 0, 600),
        (1200, 2000, 600, 1200),

        # Avoid that big galaxy (that was keeping us honest)
        #( 800, 1300, 0, 500 ),
        #( 1500, 2000, 600, 1100 ),
    ]
    fullsizes = []

    print('Reading SDSS input files...')

    band = band_index(bandname)

    images = []
    zrange = []
    nziv = []

    # FIXME -- bug-bug annihilation
    rerun = 0

    simplexys = []

    if rcfcut is not None:
        rcf = [rcf[i] for i in rcfcut]
        rois = [rois[i] for i in rcfcut]

    for i, (run, camcol, field) in enumerate(rcf):
        fpC = sdss.readFpC(run, camcol, field, bandname).getImage()
        fpC = fpC.astype(float) - sdss.softbias
        image = fpC

        if useSimplexy:
            fpcfn = sdss.getFilename('fpC', run, camcol, field, bandname)
            xyfn = fpcfn.replace('.fit', '.xy')
            if not os.path.exists(xyfn):
                print('Running image2xy...')
                cmd = 'image2xy %s -o %s' % (fpcfn, xyfn)
                print('Command:', cmd)
                os.system(cmd)
            assert (os.path.exists(xyfn))
            xy = fits_table(xyfn)
            simplexys.append(xy)

        fullsizes.append(image.shape)

        psfield = sdss.readPsField(run, camcol, field)
        gain = psfield.getGain(band)
        darkvar = psfield.getDarkVariance(band)
        sky = psfield.getSky(band)
        skyerr = psfield.getSkyErr(band)
        skysig = sqrt(sky)

        fpM = sdss.readFpM(run, camcol, field, bandname)

        tsfield = sdss.readTsField(run, camcol, field, rerun)

        invvar = sdss.getInvvar(fpC, fpM, gain, darkvar, sky, skyerr)

        nz = np.sum(invvar != 0)
        #print 'Non-zero invvars:', nz
        nziv.append(nz)

        zr = np.array([-3., +10.]) * skysig + sky
        zrange.append(zr)

        x0, x1, y0, y1 = rois[i]

        if initialPlots:
            print('Initial plots...')
            plt.clf()
            plotimage(image, vmin=zr[0], vmax=zr[1])
            ax = plt.axis()
            plt.plot([x0, x0, x1, x1, x0], [y0, y1, y1, y0, y0], 'b-')
            plt.axis(ax)
            plt.savefig('fullimg-%02i.png' % i)

        roislice = (slice(y0, y1), slice(x0, x1))
        image = image[roislice]
        invvar = invvar[roislice]

        if initialPlots:
            plt.clf()
            plotimage(image, vmin=zr[0], vmax=zr[1])
            plt.savefig('img-%02i.png' % i)

        dgpsf = psfield.getDoubleGaussian(band)
        print('Creating double-Gaussian PSF approximation')
        print('  ', dgpsf)
        (a, s1, b, s2) = dgpsf
        psf = NCircularGaussianPSF([s1, s2], [a, b])

        wcs = SdssWcs(tsfield.getAsTrans(bandname))
        wcs.setX0Y0(x0, y0)
        # And counts
        photocal = SdssPhotoCal(SdssPhotoCal.scale)
        skyobj = ConstantSky(sky)

        img = Image(data=image,
                    invvar=invvar,
                    psf=psf,
                    wcs=wcs,
                    sky=skyobj,
                    photocal=photocal,
                    name='Image%i(r/c/f=%i/%i%i)' % (i, run, camcol, field))
        images.append(img)

    print('Creating footprint image...')
    radecs = []
    for i, img in enumerate(images):
        # Find full-size and ROI boxes
        wcs = img.getWcs()
        (H, W) = fullsizes[i]
        x0, x1, y0, y1 = rois[i]
        corners = [(0, 0), (W, 0), (W, H), (0, H), (0, 0)]
        rds = [wcs.pixelToRaDec(x, y) for x, y in corners]
        radecs.append(rds)
        corners = [(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)]
        rds = [wcs.pixelToRaDec(x, y) for x, y in corners]
        radecs.append(rds)

    if initialPlots:
        plt.clf()
        plotfootprints(radecs,
                       labels=['%i' % (i / 2) for i in range(len(radecs))])
        plt.savefig('footprints-full.png')
    # After making the full "footprints" image, trim the list down to just the ROIs
    footradecs = radecs[1::2]

    return (images, simplexys, rois, zrange, nziv, footradecs)
Ejemplo n.º 4
0
	

if __name__ == '__main__':

	from astrometry.util.sdss_das import sdss_das_get
	from astrometry.util.sdss_cutout import cutout

	ra,dec = 53.202125, -0.365361

	# 7101-g3-0751
	if True:
		for i,(run,band,camcol,field) in enumerate([(6955, 'g', 3, 809),
													(6458, 'g', 3, 410),
													(7101, 'g', 3, 751),
													]):
			fpC = sdss_das_get('fpC', None, run, camcol, field, band=band)
			fpM = sdss_das_get('fpM', None, run, camcol, field, band=band)
			psField = sdss_das_get('psField', None, run, camcol, field, band=band)
			#tsField = sdss_das_get('tsField', None, run, camcol, field, band=band)
			#outfn = sdss_filename(filetype, run, camcol, field, band) + suffix

			print 'fpC is', fpC
			cutout(fpC, ra, dec, 200, 'data%i.fits' % i, fpM, psField, 'invvar%i.fits' % i,
				   band)


			

	import sys
	args = sys.argv[1:]
Ejemplo n.º 5
0
def prepareTractor(initialPlots=False, useSimplexy=True, rcfcut=None):
	rcfi = [ ( 5194 , 2 , 44 , 22.500966 ), ( 4275 , 2 , 224 , 90.003437 ), ( 3638 , 2 , 209 , 90.002781 ), ( 4291 , 2 , 227 , 90.003589 ), ( 4275 , 2 , 225 , 90.003437 ), ( 5849 , 4 , 27 , 20.003216 ), ( 5803 , 5 , 41 , 19.990683 ), ( 5194 , 2 , 43 , 22.500966 ), ( 3638 , 2 , 210 , 90.002781 ), ( 5803 , 5 , 42 , 19.990683 ), ( 5925 , 5 , 30 , 19.933986 ), ( 5935 , 5 , 27 , 20.000022 ), ]			
	rcf = [(r,c,f) for r,c,f,i in rcfi if i < 85]
	print 'RCF', rcf

	sdss = DR7()

	bandname = 'i'

	if False:
		from astrometry.util import sdss_das as das
		from astrometry.util.sdss_filenames import sdss_filename
		for r,c,f in rcf:
			for filetype in ['fpC', 'fpM', 'psField', 'tsField']:
				fn = sdss_filename(filetype, r, c, f, band=bandname)
				print 'Need', fn
				#if not os.path.exists(fn):
				print 'Getting from DAS'
				das.sdss_das_get(filetype, fn, r, c, f, band=bandname)

	# we only got some of them...
	rcf = [ (5194, 2, 44), (5194, 2, 43), (5849, 4, 27), (5935, 5, 27) ]
	rcf = [rcf[0], rcf[2]]
	print 'RCF', rcf

	rois = [
		# Mostly overlapping:
		#( 0, 1000, 0, 600 ),
		#( 1000, 2000, 600, 1200 ),

		# Pick up a big galaxy
		#( 600, 1600, 0, 600 ),
		#( 1000, 2000, 600, 1200 ),

		( 800, 1600, 0, 600 ),
		( 1200, 2000, 600, 1200 ),

		# Avoid that big galaxy (that was keeping us honest)
		#( 800, 1300, 0, 500 ),
		#( 1500, 2000, 600, 1100 ),

		]
	fullsizes = []

	print 'Reading SDSS input files...'

	band = band_index(bandname)

	images = []
	zrange = []
	nziv = []

	# FIXME -- bug-bug annihilation
	rerun = 0

	simplexys = []

	if rcfcut is not None:
		rcf  = [rcf [i] for i in rcfcut]
		rois = [rois[i] for i in rcfcut]
	
	for i,(run,camcol,field) in enumerate(rcf):
		fpC = sdss.readFpC(run, camcol, field, bandname).getImage()
		fpC = fpC.astype(float) - sdss.softbias
		image = fpC

		if useSimplexy:
			fpcfn = sdss.getFilename('fpC', run, camcol, field, bandname)
			xyfn = fpcfn.replace('.fit', '.xy')
			if not os.path.exists(xyfn):
				print 'Running image2xy...'
				cmd = 'image2xy %s -o %s' % (fpcfn, xyfn)
				print 'Command:', cmd
				os.system(cmd)
			assert(os.path.exists(xyfn))
			xy = fits_table(xyfn)
			simplexys.append(xy)

		fullsizes.append(image.shape)
	
		psfield = sdss.readPsField(run, camcol, field)
		gain = psfield.getGain(band)
		darkvar = psfield.getDarkVariance(band)
		sky = psfield.getSky(band)
		skyerr = psfield.getSkyErr(band)
		skysig = sqrt(sky)

		fpM = sdss.readFpM(run, camcol, field, bandname)

		tsfield = sdss.readTsField(run, camcol, field, rerun)

		invvar = sdss.getInvvar(fpC, fpM, gain, darkvar, sky, skyerr)

		nz = np.sum(invvar != 0)
		#print 'Non-zero invvars:', nz
		nziv.append(nz)
		
		zr = np.array([-3.,+10.]) * skysig + sky
		zrange.append(zr)

		x0,x1,y0,y1 = rois[i]

		if initialPlots:
			print 'Initial plots...'
			plt.clf()
			plotimage(image, vmin=zr[0], vmax=zr[1])
			ax = plt.axis()
			plt.plot([x0,x0,x1,x1,x0], [y0,y1,y1,y0,y0], 'b-')
			plt.axis(ax)
			plt.savefig('fullimg-%02i.png' % i)

		roislice = (slice(y0,y1), slice(x0,x1))
		image = image[roislice]
		invvar = invvar[roislice]

		if initialPlots:
			plt.clf()
			plotimage(image, vmin=zr[0], vmax=zr[1])
			plt.savefig('img-%02i.png' % i)

		dgpsf = psfield.getDoubleGaussian(band)
		print 'Creating double-Gaussian PSF approximation'
		print '  ', dgpsf
		(a,s1, b,s2) = dgpsf
		psf = NCircularGaussianPSF([s1, s2], [a, b])

		wcs = SdssWcs(tsfield.getAsTrans(bandname))
		wcs.setX0Y0(x0, y0)
		# And counts
		photocal = SdssPhotoCal(SdssPhotoCal.scale)
		skyobj = ConstantSky(sky)

		img = Image(data=image, invvar=invvar, psf=psf, wcs=wcs,
					sky=skyobj, photocal=photocal,
					name='Image%i(r/c/f=%i/%i%i)' % (i, run, camcol, field))
		images.append(img)

	print 'Creating footprint image...'
	radecs = []
	for i,img in enumerate(images):
		# Find full-size and ROI boxes
		wcs = img.getWcs()
		(H,W) = fullsizes[i]
		x0,x1,y0,y1 = rois[i]
		corners = [ (0,0), (W,0), (W,H), (0,H), (0,0) ]
		rds = [wcs.pixelToRaDec(x,y) for x,y in corners]
		radecs.append(rds)
		corners = [ (x0,y0), (x1,y0), (x1,y1), (x0,y1), (x0,y0) ]
		rds = [wcs.pixelToRaDec(x,y) for x,y in corners]
		radecs.append(rds)

	if initialPlots:
		plt.clf()
		plotfootprints(radecs, labels=['%i'%(i/2) for i in range(len(radecs))])
		plt.savefig('footprints-full.png')
	# After making the full "footprints" image, trim the list down to just the ROIs
	footradecs = radecs[1::2]

	return (images, simplexys, rois, zrange, nziv, footradecs)
Ejemplo n.º 6
0
 def retrieve(self, filetype, run, camcol, field, band=None):
     # FIXME!
     from astrometry.util.sdss_das import sdss_das_get
     outfn = self.getFilename(filetype, run, camcol, field, band)
     sdss_das_get(filetype, outfn, run, camcol, field, band, curl=self.curl)
Ejemplo n.º 7
0
 def retrieve(self, filetype, run, camcol, field, band=None):
     # FIXME!
     from astrometry.util.sdss_das import sdss_das_get
     outfn = self.getFilename(filetype, run, camcol, field, band)
     sdss_das_get(filetype, outfn, run, camcol, field, band,
             curl=self.curl)