Ejemplo n.º 1
0
def get_cfht_catalog(mags=['i'], maglim=27., returnTable=False):
    from astrometry.util.pyfits_utils import fits_table
    from tractor import Mags, RaDecPos, PointSource, Images, Catalog
    from tractor.galaxy import DevGalaxy, ExpGalaxy, CompositeGalaxy, GalaxyShape

    T = fits_table(
        '/project/projectdirs/bigboss/data/cs82/W4p1m1_i.V2.7A.swarp.cut.deVexp.fit',
        hdunum=2)
    print 'Read', len(T), 'sources'
    # Cut to ROI
    (ra0, ra1, dec0, dec1) = radecroi
    T.ra = T.alpha_j2000
    T.dec = T.delta_j2000
    T = T[(T.ra > ra0) * (T.ra < ra1) * (T.dec > dec0) * (T.dec < dec1)]
    print 'Cut to', len(T), 'objects in ROI.'

    srcs = Catalog()
    keepi = []
    for i, t in enumerate(T):
        if t.chi2_psf < t.chi2_model and t.mag_psf <= maglim:
            #print 'PSF'
            themag = t.mag_psf
            m = Mags(order=mags, **dict([(k, themag) for k in mags]))
            srcs.append(PointSource(RaDecPos(t.ra, t.dec), m))
            keepi.append(i)
            continue
        if t.mag_disk > maglim and t.mag_spheroid > maglim:
            #print 'Faint'
            continue
        keepi.append(i)
        themag = t.mag_spheroid
        m_exp = Mags(order=mags, **dict([(k, themag) for k in mags]))
        themag = t.mag_disk
        m_dev = Mags(order=mags, **dict([(k, themag) for k in mags]))

        # SPHEROID_REFF [for Sersic index n= 1] = 1.68 * DISK_SCALE
        shape_dev = GalaxyShape(t.disk_scale_world * 1.68 * 3600.,
                                t.disk_aspect_world, t.disk_theta_world + 90.)
        shape_exp = GalaxyShape(t.spheroid_reff_world * 3600.,
                                t.spheroid_aspect_world,
                                t.spheroid_theta_world + 90.)
        pos = RaDecPos(t.alphamodel_j2000, t.deltamodel_j2000)

        if t.mag_disk > maglim and t.mag_spheroid <= maglim:
            #print 'Exp'
            srcs.append(ExpGalaxy(pos, m_exp, shape_exp))
            continue
        if t.mag_disk <= maglim and t.mag_spheroid > maglim:
            #print 'deV'
            srcs.append(DevGalaxy(pos, m_dev, shape_dev))
            continue
        # exp + deV
        srcs.append(CompositeGalaxy(pos, m_exp, shape_exp, m_dev, shape_dev))

    if returnTable:
        import numpy as np
        T.cut(np.array(keepi))
        return srcs, T

    return srcs
Ejemplo n.º 2
0
	def readPhotoObj(self, run, camcol, field, filename=None):
		obj = PhotoObj(run, camcol, field)
		if filename is None:
			fn = self.getPath('photoObj', run, camcol, field)
		else:
			fn = filename
		obj.table = fits_table(fn)
		return obj
Ejemplo n.º 3
0
def get_cfht_catalog(mags=['i'], maglim = 27., returnTable=False):
    from astrometry.util.pyfits_utils import fits_table
    from tractor import Mags, RaDecPos, PointSource, Images, Catalog
    from tractor.sdss_galaxy import DevGalaxy, ExpGalaxy, CompositeGalaxy, GalaxyShape

    T = fits_table('/project/projectdirs/bigboss/data/cs82/W4p1m1_i.V2.7A.swarp.cut.deVexp.fit', hdunum=2)
    print 'Read', len(T), 'sources'
    # Cut to ROI
    (ra0,ra1, dec0,dec1) = radecroi
    T.ra  = T.alpha_j2000
    T.dec = T.delta_j2000
    T = T[(T.ra > ra0) * (T.ra < ra1) * (T.dec > dec0) * (T.dec < dec1)]
    print 'Cut to', len(T), 'objects in ROI.'
    
    srcs = Catalog()
    keepi = []
    for i,t in enumerate(T):
        if t.chi2_psf < t.chi2_model and t.mag_psf <= maglim:
            #print 'PSF'
            themag = t.mag_psf
            m = Mags(order=mags, **dict([(k, themag) for k in mags]))
            srcs.append(PointSource(RaDecPos(t.ra, t.dec), m))
            keepi.append(i)
            continue
        if t.mag_disk > maglim and t.mag_spheroid > maglim:
            #print 'Faint'
            continue
        keepi.append(i)
        themag = t.mag_spheroid
        m_exp = Mags(order=mags, **dict([(k, themag) for k in mags]))
        themag = t.mag_disk
        m_dev = Mags(order=mags, **dict([(k, themag) for k in mags]))

        # SPHEROID_REFF [for Sersic index n= 1] = 1.68 * DISK_SCALE
        shape_dev = GalaxyShape(t.disk_scale_world * 1.68 * 3600., t.disk_aspect_world,
                                t.disk_theta_world + 90.)
        shape_exp = GalaxyShape(t.spheroid_reff_world * 3600., t.spheroid_aspect_world,
                                t.spheroid_theta_world + 90.)
        pos = RaDecPos(t.alphamodel_j2000, t.deltamodel_j2000)

        if t.mag_disk > maglim and t.mag_spheroid <= maglim:
            #print 'Exp'
            srcs.append(ExpGalaxy(pos, m_exp, shape_exp))
            continue
        if t.mag_disk <= maglim and t.mag_spheroid > maglim:
            #print 'deV'
            srcs.append(DevGalaxy(pos, m_dev, shape_dev))
            continue
        # exp + deV
        srcs.append(CompositeGalaxy(pos, m_exp, shape_exp, m_dev, shape_dev))

    if returnTable:
        import numpy as np
        T.cut(np.array(keepi))
        return srcs, T

    return srcs
Ejemplo n.º 4
0
	def readFrame(self, run, camcol, field, band, filename=None):
		'''
		http://data.sdss3.org/datamodel/files/BOSS_PHOTOOBJ/frames/RERUN/RUN/CAMCOL/frame.html
		'''
		f = Frame(run, camcol, field, band)
		# ...
		if filename is None:
			fn = self.getPath('frame', run, camcol, field, band)
		else:
			fn = filename
		#print 'reading file', fn
		p = pyfits.open(fn)
		#print 'got', len(p), 'HDUs'
		# in nanomaggies
		f.image = p[0].data
		f.header = p[0].header
		# converts counts -> nanomaggies
		f.calib = p[1].data
		# table with val,x,y -- binned; use bilinear interpolation to expand
		sky = p[2].data
		f.sky = sky.field('allsky')[0]
		#print 'sky shape', f.sky.shape
		if len(f.sky.shape) != 2:
			f.sky = f.sky.reshape((-1, 256))
		f.skyxi = sky.field('xinterp')[0]
		f.skyyi = sky.field('yinterp')[0]
		#print 'p3:', p[3]
		# table -- asTrans structure
		tab = fits_table(p[3].data)
		assert(len(tab) == 1)
		tab = tab[0]
		# DR7 has NODE, INCL in radians...
		f.astrans = AsTrans(run, camcol, field, band,
							node=np.deg2rad(tab.node), incl=np.deg2rad(tab.incl),
							astrans=tab, cut_to_band=False)
							
		return f
Ejemplo n.º 5
0
    parser.add_option('-X', dest='xcol', help='Name of X column in image table')
    parser.add_option('-Y', dest='ycol', help='Name of Y column in image table')
    parser.add_option('-N', dest='nimage', type='int', help='Cut to the first N image sources')
    parser.add_option('-x', dest='rxcol', help='Name of X column in reference table')
    parser.add_option('-y', dest='rycol', help='Name of Y column in reference table')
    parser.add_option('-n', dest='nref', type='int', help='Cut to the first N reference sources')
    parser.add_option('-c', dest='cells', type='int', help='Approx. number of pieces to cut image into (default:18)')
    parser.add_option('-s', dest='cellsize', type='int', help='Search radius, in pixels (default 50)')
    parser.set_defaults(xcol='X', ycol='Y', nimage=0, cells=0, cellsize=0, rxcol='X', rycol='Y', nref=0)
    opt,args = parser.parse_args()
    
    if len(args) != 3:
        parser.print_help()
        sys.exit(-1)
        
    imxy = fits_table(args[0])
    refxy = fits_table(args[1])
    outfn = args[2]

    kwargs = {}
    if opt.cells:
        kwargs['ncells'] = opt.cells
    if opt.cellsize:
        kwargs['dcell'] = opt.cellsize

    ix = imxy.getcolumn(opt.xcol)
    iy = imxy.getcolumn(opt.ycol)
    ixy = vstack((ix,iy)).T
    if opt.nimage:
        ixy = ixy[:opt.nimage,:]
Ejemplo n.º 6
0
                      help='Search radius, in pixels (default 50)')
    parser.set_defaults(xcol='X',
                        ycol='Y',
                        nimage=0,
                        cells=0,
                        cellsize=0,
                        rxcol='X',
                        rycol='Y',
                        nref=0)
    opt, args = parser.parse_args()

    if len(args) != 3:
        parser.print_help()
        sys.exit(-1)

    imxy = fits_table(args[0])
    refxy = fits_table(args[1])
    outfn = args[2]

    kwargs = {}
    if opt.cells:
        kwargs['ncells'] = opt.cells
    if opt.cellsize:
        kwargs['dcell'] = opt.cellsize

    ix = imxy.getcolumn(opt.xcol)
    iy = imxy.getcolumn(opt.ycol)
    ixy = vstack((ix, iy)).T
    if opt.nimage:
        ixy = ixy[:opt.nimage, :]