Beispiel #1
0
    def testIdentity(self):
        nobj = 1000
        for i in range(nobj):
            s = afwDetect.Source()
            s.setId(i)
            s.setRa(radians(10 + 0.001*i))
            s.setDec(radians(10 + 0.001*i))

            self.ss1.append(s)

            s = afwDetect.Source()
            s.setId(2*nobj + i)
            s.setRa(radians(10 + 0.001*i))
            s.setDec(radians(10 + 0.001*i))

            self.ss2.append(s)

        mat = afwDetect.matchRaDec(self.ss1, self.ss2, 1.0, False)

        self.assertEqual(len(mat), nobj)

        if False:
            s0 = mat[0][0]
            s1 = mat[0][1]
            print s0.getRa(), s1.getRa(), s0.getId(), s1.getId()
Beispiel #2
0
 def testNaNPositions(self):
     ss1 = afwDetect.SourceSet()
     ss2 = afwDetect.SourceSet()
     for ss in (ss1, ss2):
         s = afwDetect.Source()
         s.setRa(float('nan'))
         ss.append(s)
         s = afwDetect.Source()
         s.setDec(float('nan'))
         ss.append(s)
         s = afwDetect.Source()
         s.setRa(0.0)
         s.setDec(0.0)
         ss.append(s)
         s = afwDetect.Source()
         s.setRa(float('nan'))
         s.setDec(float('nan'))
         ss.append(s)
     mat = afwDetect.matchRaDec(ss1, ss2, 1.0, False)
     self.assertEqual(len(mat), 1)
Beispiel #3
0
    def __init__(self, sources1, sources2, matchTol=1.0):
        self.keys = [
            'distance', 'ra1', 'ra2', 'dec1', 'dec2', 'x1', 'y1', 'x2', 'y2',
            'psf1', 'psf2', 'ap1', 'ap2', 'model1', 'model2', 'flags1',
            'flags2', 'index'
        ]
        matches = afwDet.matchRaDec(sources1, sources2, matchTol)
        self.num = len(matches)

        # Set up arrays
        for name, method in (
            ('ra', 'getRa'),
            ('dec', 'getDec'),
            ('x', 'getXAstrom'),
            ('y', 'getYAstrom'),
            ('psf', 'getPsfFlux'),
            ('model', 'getModelFlux'),
            ('ap', 'getApFlux'),
            ('flags', 'getFlagForDetection'),
        ):
            name1 = name + '1'
            name2 = name + '2'
            array1 = numpy.ndarray(self.num)
            array2 = numpy.ndarray(self.num)
            for i, m in enumerate(matches):
                first = m.first
                second = m.second
                array1[i] = getattr(first, method)()
                array2[i] = getattr(second, method)()
            setattr(self, name1, array1)
            setattr(self, name2, array2)

        # convert RA,Dec to degrees for human consumption
        self.ra = np.degrees(self.ra)
        self.dec = np.degrees(self.dec)

        self.distance = numpy.array([m.distance for m in matches])
        self.index = ma.MaskedArray(numpy.arange(self.num))
Beispiel #4
0
    def testPhotometricCalib(self):
        """Test matching the CFHT catalogue (as generated using LSST code) to the SDSS catalogue"""

        if not eups.productDir("afwdata"):
            print >> sys.stderr, "Failed to open sdss catalogue"
            return

        band = 2                        # SDSS r
        
        #
        # Read SDSS catalogue
        #
        ifd = open(os.path.join(eups.productDir("afwdata"), "CFHT", "D2", "sdss.dat"), "r")

        sdss = afwDetect.SourceSet()
        sdssSecondary = afwDetect.SourceSet()

        PRIMARY, SECONDARY = 1, 2       # values of mode

        id = 0
        for line in ifd.readlines():
            if re.search(r"^\s*#", line):
                continue

            fields = line.split()
            objId = int(fields[0])
            name = fields[1]
            mode = int(fields[2])
            ra, dec = [float(f) for f in fields[3:5]]
            psfMags = [float(f) for f in fields[5:]]

            s = afwDetect.Source()
            s.setId(objId)
            s.setRa(radians(ra))
            s.setDec(radians(dec))
            s.setPsfFlux(psfMags[band])

            if mode == PRIMARY:
                sdss.append(s)
            elif SECONDARY:
                sdssSecondary.append(s)

        del ifd
        #
        # Read catalalogue built from the template image
        #
        #
        # Read SDSS catalogue
        #
        ifd = open(os.path.join(eups.productDir("afwdata"), "CFHT", "D2", "template.dat"), "r")

        template = afwDetect.SourceSet()

        id = 0
        for line in ifd.readlines():
            if re.search(r"^\s*#", line):
                continue

            fields = line.split()
            id, flags = [int(f) for f in  fields[0:2]]
            ra, dec = [float(f) for f in fields[2:4]]
            flux = [float(f) for f in fields[4:]]

            if flags & 0x1:             # EDGE
                continue

            s = afwDetect.Source()
            s.setId(id)
            id += 1
            s.setRa(radians(ra))
            s.setDec(radians(dec))
            s.setPsfFlux(flux[0])

            template.append(s)

        del ifd
        #
        # Actually do the match
        #
        matches = afwDetect.matchRaDec(sdss, template, 1.0, False)

        self.assertEqual(len(matches), 901)

        if False:
            for mat in matches:
                s0 = mat[0]
                s1 = mat[1]
                d = mat[2]
                print s0.getRa(), s0.getDec(), s1.getRa(), s1.getDec(), s0.getPsfFlux(), s1.getPsfFlux()
        #
        # Actually do the match
        #
        for s in sdssSecondary:
            sdss.append(s)

        matches = afwDetect.matchRaDec(sdss, 1.0, False)
        nmiss = 1                                              # one object doesn't match
        self.assertEqual(len(matches), len(sdssSecondary) - nmiss)
        #
        # Find the one that didn't match
        #
        if False:
            matchIds = set()
            for s0, s1, d in matches:
                matchIds.add(s0.getId())
                matchIds.add(s1.getId())

            for s in sdssSecondary:
                if s.getId() not in matchIds:
                    print "RHL", s.getId()

        matches = afwDetect.matchRaDec(sdss, 1.0, True)
        self.assertEqual(len(matches), 2*(len(sdssSecondary) - nmiss))
        
        if False:
            for mat in matches:
                s0 = mat[0]
                s1 = mat[1]
                d = mat[2]
                print s0.getId(), s1.getId(), s0.getRa(), s0.getDec(),
                print s1.getRa(), s1.getDec(), s0.getPsfFlux(), s1.getPsfFlux()