コード例 #1
0
    def testLoadVersion0(self):
        """Test reading a pre-written format_version=0 (Jy flux) catalog.
        It should be converted to have nJy fluxes.
        """
        path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data',
                            'version0', 'ref_cats', 'cal_ref_cat')

        filenames = sorted(glob.glob(os.path.join(path, '????.fits')))

        loader = MockReferenceObjectLoaderFromFiles(filenames,
                                                    name='cal_ref_cat',
                                                    htmLevel=4)
        result = loader.loadSkyCircle(ingestIndexTestBase.make_coord(10, 20),
                                      5 * lsst.geom.degrees, 'a')

        self.assertTrue(hasNanojanskyFluxUnits(result.refCat.schema))
        catalog = afwTable.SimpleCatalog.readFits(filenames[0])
        self.assertFloatsEqual(catalog['a_flux'] * 1e9,
                               result.refCat['a_flux'])
        self.assertFloatsEqual(catalog['a_fluxSigma'] * 1e9,
                               result.refCat['a_fluxErr'])
        self.assertFloatsEqual(catalog['b_flux'] * 1e9,
                               result.refCat['b_flux'])
        self.assertFloatsEqual(catalog['b_fluxSigma'] * 1e9,
                               result.refCat['b_fluxErr'])
コード例 #2
0
    def testProperMotion(self):
        """Test proper motion correction"""
        center = make_coord(93.0, -90.0)
        loader = LoadIndexedReferenceObjectsTask(butler=self.testButler)
        references = loader.loadSkyCircle(center, self.searchRadius, filterName='a').refCat
        original = references.copy(True)

        # Zero epoch change --> no proper motion correction (except minor numerical effects)
        loader.applyProperMotions(references, self.epoch)
        self.assertFloatsAlmostEqual(references["coord_ra"], original["coord_ra"], rtol=1.0e-14)
        self.assertFloatsAlmostEqual(references["coord_dec"], original["coord_dec"], rtol=1.0e-14)
        self.assertFloatsEqual(references["coord_raErr"], original["coord_raErr"])
        self.assertFloatsEqual(references["coord_decErr"], original["coord_decErr"])

        # One year difference
        loader.applyProperMotions(references, self.epoch + 1.0*astropy.units.yr)
        self.assertFloatsEqual(references["pm_raErr"], original["pm_raErr"])
        self.assertFloatsEqual(references["pm_decErr"], original["pm_decErr"])
        for orig, ref in zip(original, references):
            self.assertAnglesAlmostEqual(orig.getCoord().separation(ref.getCoord()),
                                         self.properMotionAmt, maxDiff=1.0e-6*lsst.geom.arcseconds)
            self.assertAnglesAlmostEqual(orig.getCoord().bearingTo(ref.getCoord()),
                                         self.properMotionDir, maxDiff=1.0e-4*lsst.geom.arcseconds)
        predictedRaErr = np.hypot(original["coord_raErr"], original["pm_raErr"])
        predictedDecErr = np.hypot(original["coord_decErr"], original["pm_decErr"])
        self.assertFloatsAlmostEqual(references["coord_raErr"], predictedRaErr)
        self.assertFloatsAlmostEqual(references["coord_decErr"], predictedDecErr)
コード例 #3
0
 def testLoadPixelBox(self):
     """Test LoadIndexedReferenceObjectsTask.loadPixelBox with default config."""
     loader = LoadIndexedReferenceObjectsTask(butler=self.testButler)
     numFound = 0
     for tupl, idList in self.compCats.items():
         cent = make_coord(*tupl)
         bbox = lsst.geom.Box2I(lsst.geom.Point2I(30, -5), lsst.geom.Extent2I(1000, 1004))  # arbitrary
         ctr_pix = bbox.getCenter()
         # catalog is sparse, so set pixel scale such that bbox encloses region
         # used to generate compCats
         pixel_scale = 2*self.searchRadius/max(bbox.getHeight(), bbox.getWidth())
         cdMatrix = afwGeom.makeCdMatrix(scale=pixel_scale)
         wcs = afwGeom.makeSkyWcs(crval=cent, crpix=ctr_pix, cdMatrix=cdMatrix)
         result = loader.loadPixelBox(bbox=bbox, wcs=wcs, filterName="a")
         # The following is to ensure the reference catalog coords are
         # getting corrected for proper motion when an epoch is provided.
         # Use an extreme epoch so that differences in corrected coords
         # will be significant.  Note that this simply tests that the coords
         # do indeed change when the epoch is passed.  It makes no attempt
         # at assessing the correctness of the change.  This is left to the
         # explicit testProperMotion() test below.
         resultWithEpoch = loader.loadPixelBox(bbox=bbox, wcs=wcs, filterName="a",
                                               epoch=astropy.time.Time(20000, format='mjd', scale="tai"))
         self.assertFloatsNotEqual(result.refCat["coord_ra"], resultWithEpoch.refCat["coord_ra"],
                                   rtol=1.0e-4)
         self.assertFloatsNotEqual(result.refCat["coord_dec"], resultWithEpoch.refCat["coord_dec"],
                                   rtol=1.0e-4)
         self.assertFalse("camFlux" in result.refCat.schema)
         self.assertGreaterEqual(len(result.refCat), len(idList))
         numFound += len(result.refCat)
     self.assertGreater(numFound, 0)
コード例 #4
0
 def testLoadVersion1(self):
     """Test reading a format_version=1 catalog (fluxes unchanged)."""
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/version1')
     loader = LoadIndexedReferenceObjectsTask(butler=dafPersist.Butler(path))
     self.assertEqual(loader.dataset_config.format_version, 1)
     result = loader.loadSkyCircle(make_coord(10, 20),
                                   5*lsst.geom.degrees, filterName='a')
     self.assertTrue(hasNanojanskyFluxUnits(result.refCat.schema))
     catalog = afwTable.SimpleCatalog.readFits(os.path.join(path, 'ref_cats/cal_ref_cat/4022.fits'))
     self.assertFloatsEqual(catalog['a_flux'], result.refCat['a_flux'])
     self.assertFloatsEqual(catalog['a_fluxErr'], result.refCat['a_fluxErr'])
     self.assertFloatsEqual(catalog['b_flux'], result.refCat['b_flux'])
     self.assertFloatsEqual(catalog['b_fluxErr'], result.refCat['b_fluxErr'])
コード例 #5
0
 def testLoadVersion0(self):
     """Test reading a pre-written format_version=0 (Jy flux) catalog.
     It should be converted to have nJy fluxes.
     """
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/version0')
     loader = LoadIndexedReferenceObjectsTask(butler=dafPersist.Butler(path))
     self.assertEqual(loader.dataset_config.format_version, 0)
     result = loader.loadSkyCircle(ingestIndexTestBase.make_coord(10, 20),
                                   5*lsst.geom.degrees, filterName='a')
     self.assertTrue(hasNanojanskyFluxUnits(result.refCat.schema))
     catalog = afwTable.SimpleCatalog.readFits(os.path.join(path, 'ref_cats/cal_ref_cat/4022.fits'))
     self.assertFloatsEqual(catalog['a_flux']*1e9, result.refCat['a_flux'])
     self.assertFloatsEqual(catalog['a_fluxSigma']*1e9, result.refCat['a_fluxErr'])
     self.assertFloatsEqual(catalog['b_flux']*1e9, result.refCat['b_flux'])
     self.assertFloatsEqual(catalog['b_fluxSigma']*1e9, result.refCat['b_fluxErr'])
コード例 #6
0
 def testDefaultFilterAndFilterMap(self):
     """Test defaultFilter and filterMap parameters of LoadIndexedReferenceObjectsConfig."""
     config = LoadIndexedReferenceObjectsConfig()
     config.defaultFilter = "b"
     config.filterMap = {"aprime": "a"}
     loader = LoadIndexedReferenceObjectsTask(butler=self.testButler, config=config)
     for tupl, idList in self.compCats.items():
         cent = make_coord(*tupl)
         lcat = loader.loadSkyCircle(cent, self.searchRadius)
         self.assertEqual(lcat.fluxField, "camFlux")
         if len(idList) > 0:
             defFluxFieldName = getRefFluxField(lcat.refCat.schema, None)
             self.assertTrue(defFluxFieldName in lcat.refCat.schema)
             aprimeFluxFieldName = getRefFluxField(lcat.refCat.schema, "aprime")
             self.assertTrue(aprimeFluxFieldName in lcat.refCat.schema)
             break  # just need one test
コード例 #7
0
 def testLoadPixelBox(self):
     """Test LoadIndexedReferenceObjectsTask.loadPixelBox with default config."""
     loader = LoadIndexedReferenceObjectsTask(butler=self.testButler)
     numFound = 0
     for tupl, idList in self.compCats.items():
         cent = ingestIndexTestBase.make_coord(*tupl)
         bbox = lsst.geom.Box2I(lsst.geom.Point2I(30, -5), lsst.geom.Extent2I(1000, 1004))  # arbitrary
         ctr_pix = bbox.getCenter()
         # catalog is sparse, so set pixel scale such that bbox encloses region
         # used to generate compCats
         pixel_scale = 2*self.searchRadius/max(bbox.getHeight(), bbox.getWidth())
         cdMatrix = afwGeom.makeCdMatrix(scale=pixel_scale)
         wcs = afwGeom.makeSkyWcs(crval=cent, crpix=ctr_pix, cdMatrix=cdMatrix)
         result = loader.loadPixelBox(bbox=bbox, wcs=wcs, filterName="a")
         self.assertFalse("camFlux" in result.refCat.schema)
         self.assertGreaterEqual(len(result.refCat), len(idList))
         numFound += len(result.refCat)
     self.assertGreater(numFound, 0)
コード例 #8
0
 def testLoadSkyCircle(self):
     """Test LoadIndexedReferenceObjectsTask.loadSkyCircle with default config."""
     loader = LoadIndexedReferenceObjectsTask(butler=self.testButler)
     for tupl, idList in self.compCats.items():
         cent = make_coord(*tupl)
         lcat = loader.loadSkyCircle(cent, self.searchRadius, filterName='a')
         self.assertTrue(lcat.refCat.isContiguous())
         self.assertFalse("camFlux" in lcat.refCat.schema)
         self.assertEqual(Counter(lcat.refCat['id']), Counter(idList))
         if len(lcat.refCat) > 0:
             # make sure there are no duplicate ids
             self.assertEqual(len(set(Counter(lcat.refCat['id']).values())), 1)
             self.assertEqual(len(set(Counter(idList).values())), 1)
             # A default-loaded sky circle should not have centroids
             self.assertNotIn("centroid_x", lcat.refCat.schema)
             self.assertNotIn("centroid_y", lcat.refCat.schema)
             self.assertNotIn("hasCentroid", lcat.refCat.schema)
         else:
             self.assertEqual(len(idList), 0)