コード例 #1
0
 def setUp(self):
     datapath = setupAstrometryNetDataDir('photocal')
     self.conf = ANetBasicAstrometryConfig()
     # Load andConfig2.py rather than the default.
     confpath = os.path.join(datapath, 'andConfig2.py')
     self.andConfig = AstrometryNetDataConfig()
     self.andConfig.load(confpath)
    def testRequestForeignFilter(self):
        """The user requests a filter not in the astrometry.net catalog.

        In that case, we must specify a mapping in the AstrometryConfig to point
        to an alternative filter (e.g., g instead of B).
        We should expect the returned catalog to contain references
        to the filterNameList that are in the catalog.
        """
        filterNameList = ['u', 'g', 'r', 'i', 'z']
        andConfig = AstrometryNetDataConfig()
        andConfig.load(os.path.join(self.datapath, 'andConfig2.py'))
        self.config.filterMap = dict(('my_' + b, b) for b in filterNameList)
        loadANetObj = LoadAstrometryNetObjectsTask(config=self.config,
                                                   andConfig=andConfig)

        loadRes = loadANetObj.loadPixelBox(bbox=self.bbox,
                                           wcs=self.wcs,
                                           filterName="my_r")
        refCat = loadRes.refCat
        self.assertEqual(loadRes.fluxField, "my_r_camFlux")
        self.assertEqual(len(refCat), self.desNumStarsInPixelBox)
        self.assertObjInBBox(refCat=refCat, bbox=self.bbox, wcs=self.wcs)
        schema = refCat.getSchema()
        for filterName in filterNameList:
            schema.find(filterName + "_flux")
            schema.find(filterName + '_fluxSigma')
コード例 #3
0
class MultipleCatalogStarsTest(unittest.TestCase):
    def setUp(self):
        datapath = setupAstrometryNetDataDir('photocal')
        self.conf = ANetBasicAstrometryConfig()
        # Load andConfig2.py rather than the default.
        confpath = os.path.join(datapath, 'andConfig2.py')
        self.andConfig = AstrometryNetDataConfig()
        self.andConfig.load(confpath)

    def tearDown(self):
        del self.conf
        del self.andConfig

    def testGetCatalog(self, logLevel=Log.TRACE):
        astrom = ANetBasicAstrometryTask(self.conf, andConfig=self.andConfig)
        astrom.log.setLevel(logLevel)

        ctrCoord = geom.SpherePoint(215.6, 53.0, geom.degrees)
        cat = astrom.refObjLoader.loadSkyCircle(
            ctrCoord=ctrCoord,
            radius=0.1 * geom.degrees,
            filterName='z',
        ).refCat
        print('Got', len(cat), 'reference sources')

        ids = set(s.getId() for s in cat)
        print(len(ids), 'unique IDs')

        ids = set()
        for src in cat:
            sid = src.getId()
            if sid in ids:
                print('Source id', sid, 'is duplicated')
            self.assertNotIn(sid, ids)
            ids.add(sid)
コード例 #4
0
 def testCache(self):
     andConfig = AstrometryNetDataConfig()
     fn = os.path.join(self.an_data_dir, 'andConfig6.py')
     andConfig.load(fn)
     andConfig.allowCache = True
     cacheName = os.path.join(self.an_data_dir, 'andCache.fits')
     if os.path.exists(cacheName):
         os.unlink(cacheName)
     try:
         generateCache(andConfig)
         self.assertTrue(os.path.exists(cacheName))
         self._testGetSolution(andConfig=andConfig)
     finally:
         if os.path.exists(cacheName):
             os.unlink(cacheName)
コード例 #5
0
    def setUp(self):
        self.datapath = setupAstrometryNetDataDir('photocal')

        self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(3001, 3001))
        crpix = lsst.geom.Box2D(self.bbox).getCenter()
        self.tanWcs = afwGeom.makeSkyWcs(crpix=crpix,
                                         crval=lsst.geom.SpherePoint(215.5, 53.0, lsst.geom.degrees),
                                         cdMatrix=afwGeom.makeCdMatrix(scale=5.1e-5*lsst.geom.degrees))
        self.exposure = afwImage.ExposureF(self.bbox)
        self.exposure.setWcs(self.tanWcs)
        self.exposure.setFilter(afwImage.Filter("r", True))
        andConfig = AstrometryNetDataConfig()
        andConfig.load(os.path.join(self.datapath, 'andConfig2.py'))
        andConfig.magErrorColumnMap = {}
        self.refObjLoader = LoadAstrometryNetObjectsTask(andConfig=andConfig)
コード例 #6
0
    def testNoMagErrs(self):
        """Exclude magnitude errors from the found catalog
        """
        andConfig = AstrometryNetDataConfig()
        andConfig.load(os.path.join(self.datapath, 'andConfig2.py'))
        andConfig.magErrorColumnMap = {}
        loadANetObj = LoadAstrometryNetObjectsTask(config=self.config, andConfig=andConfig)

        loadRes = loadANetObj.loadPixelBox(bbox=self.bbox, wcs=self.wcs, filterName="r")
        refCat = loadRes.refCat
        self.assertEqual(loadRes.fluxField, "r_flux")
        self.assertEqual(len(refCat), self.desNumStarsInPixelBox)
        self.assertObjInBBox(refCat=refCat, bbox=self.bbox, wcs=self.wcs)
        schema = refCat.getSchema()
        for filterName in ['u', 'g', 'r', 'i', 'z']:
            schema.find(filterName + "_flux")
            with self.assertRaises(KeyError):
                schema.find(filterName + "_fluxSigma")
コード例 #7
0
    def testResources(self):
        fd0 = ttime.count_file_descriptors()
        print('Mem0:', end=' ')
        print(ttime.memusage())
        print('FD0:', fd0)

        andConfig = AstrometryNetDataConfig()
        fn = os.path.join(self.an_data_dir, 'andConfig6.py')
        andConfig.load(fn)
        andConfig.multiIndexFiles = andConfig.multiIndexFiles * 100
        print(len(andConfig.multiIndexFiles), 'multi-index files')

        astrom = ANetBasicAstrometryTask(self.conf, andConfig=andConfig)

        fd1 = ttime.count_file_descriptors()
        print()
        print('Mem1:')
        print(ttime.memusage())
        print('FD1:', fd1)

        # Number of used file descriptors should not grow.  Magic 10
        # is just margin from other things going on in the python process
        self.assertLess(fd1, fd0 + 10)

        res = astrom.determineWcs(self.srcCat, self.exposure, bbox=self.bbox)

        fd2 = ttime.count_file_descriptors()
        print()
        print('Mem2:')
        print(ttime.memusage())
        print('FD2:', fd2)

        # Number of used file descriptors should not grow.  Magic 10
        # is just margin from other things going on in the python process
        self.assertLess(fd2, fd0 + 10)

        del res
        del astrom

        fd3 = ttime.count_file_descriptors()
        print()
        print('Mem3:')
        print(ttime.memusage())
        print('FD3:', fd3)
    def testDifferentMagNames(self):
        """The astrometry.net catalog's magnitude columns are not named after filters.

        In that case, the AstrometryNetDataConfig has a mapping to point to the correct columns.
        We should expect that the returned catalog refers to the filter
        requested (not the implementation-dependent column names).
        """
        andConfig = AstrometryNetDataConfig()
        andConfig.load(os.path.join(self.datapath, 'andConfig2.py'))
        baseNameList = ('u', 'g', 'r', 'i', 'z')
        filterNameList = ["my_" + b for b in baseNameList]
        andConfig.magColumnMap = dict(("my_" + b, b) for b in baseNameList)
        andConfig.magErrorColumnMap = dict([('my_' + b, b + "_err")
                                            for b in baseNameList])
        loadANetObj = LoadAstrometryNetObjectsTask(config=self.config,
                                                   andConfig=andConfig)

        loadRes = loadANetObj.loadPixelBox(bbox=self.bbox,
                                           wcs=self.wcs,
                                           filterName="my_r")
        refCat = loadRes.refCat
        self.assertEqual(loadRes.fluxField, "my_r_flux")
        self.assertEqual(len(refCat), self.desNumStarsInPixelBox)
        self.assertObjInBBox(refCat=refCat, bbox=self.bbox, wcs=self.wcs)
        schema = refCat.getSchema()
        for nm in filterNameList:
            schema.find(nm + "_flux")
            schema.find(nm + '_fluxSigma')
コード例 #9
0
 def testMultiIndexD(self):
     andConfig = AstrometryNetDataConfig()
     fn = os.path.join(self.an_data_dir, 'andConfig5.py')
     andConfig.load(fn)
     self._testGetSolution(andConfig=andConfig)