Exemplo n.º 1
0
    def test_properMotion(self):
        """Test proper motion correction."""
        loaderConfig = ReferenceObjectLoader.ConfigClass()
        loaderConfig.filterMap = {'aprime': 'a'}
        loader = ReferenceObjectLoader(
            [dataRef.dataId for dataRef in self.datasetRefs],
            self.handles,
            config=loaderConfig)
        center = lsst.geom.SpherePoint(180.0 * lsst.geom.degrees,
                                       0.0 * lsst.geom.degrees)
        cat = loader.loadSkyCircle(center,
                                   30.0 * lsst.geom.degrees,
                                   filterName='a').refCat

        # Zero epoch change --> no proper motion correction (except minor numerical effects)
        cat_pm = loader.loadSkyCircle(center,
                                      30.0 * lsst.geom.degrees,
                                      filterName='a',
                                      epoch=self.epoch).refCat

        self.assertFloatsAlmostEqual(cat_pm['coord_ra'],
                                     cat['coord_ra'],
                                     rtol=1.0e-14)
        self.assertFloatsAlmostEqual(cat_pm['coord_dec'],
                                     cat['coord_dec'],
                                     rtol=1.0e-14)
        self.assertFloatsEqual(cat_pm['coord_raErr'], cat['coord_raErr'])
        self.assertFloatsEqual(cat_pm['coord_decErr'], cat['coord_decErr'])

        # One year difference
        cat_pm = loader.loadSkyCircle(center,
                                      30.0 * lsst.geom.degrees,
                                      filterName='a',
                                      epoch=self.epoch +
                                      1.0 * astropy.units.yr).refCat

        self.assertFloatsEqual(cat_pm['pm_raErr'], cat['pm_raErr'])
        self.assertFloatsEqual(cat_pm['pm_decErr'], cat['pm_decErr'])
        for orig, ref in zip(cat, cat_pm):
            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(cat["coord_raErr"], cat["pm_raErr"])
        predictedDecErr = np.hypot(cat["coord_decErr"], cat["pm_decErr"])
        self.assertFloatsAlmostEqual(cat_pm["coord_raErr"], predictedRaErr)
        self.assertFloatsAlmostEqual(cat_pm["coord_decErr"], predictedDecErr)
Exemplo n.º 2
0
    def test_loadPixelBox(self):
        """Test the loadPixelBox routine."""
        # This will create a box 50 degrees on a side.
        loaderConfig = ReferenceObjectLoader.ConfigClass()
        loaderConfig.pixelMargin = 0
        loader = ReferenceObjectLoader(
            [dataRef.dataId for dataRef in self.datasetRefs],
            self.handles,
            config=loaderConfig)
        bbox = lsst.geom.Box2I(corner=lsst.geom.Point2I(0, 0),
                               dimensions=lsst.geom.Extent2I(1000, 1000))
        crpix = lsst.geom.Point2D(500, 500)
        crval = lsst.geom.SpherePoint(180.0 * lsst.geom.degrees,
                                      0.0 * lsst.geom.degrees)
        cdMatrix = afwGeom.makeCdMatrix(scale=0.05 * lsst.geom.degrees)
        wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=crval, cdMatrix=cdMatrix)

        cat = loader.loadPixelBox(bbox, wcs, 'a', bboxToSpherePadding=0).refCat

        # This is a sanity check on the ranges; the exact selection depends
        # on cos(dec) and the tangent-plane projection.
        self.assertLess(np.max(np.rad2deg(cat['coord_ra'])), 180.0 + 25.0)
        self.assertGreater(np.max(np.rad2deg(cat['coord_ra'])), 180.0 - 25.0)
        self.assertLess(np.max(np.rad2deg(cat['coord_dec'])), 25.0)
        self.assertGreater(np.min(np.rad2deg(cat['coord_dec'])), -25.0)

        # 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.
        catWithEpoch = loader.loadPixelBox(bbox,
                                           wcs,
                                           'a',
                                           bboxToSpherePadding=0,
                                           epoch=astropy.time.Time(
                                               30000,
                                               format='mjd',
                                               scale='tai')).refCat

        self.assertFloatsNotEqual(cat['coord_ra'],
                                  catWithEpoch['coord_ra'],
                                  rtol=1.0e-4)
        self.assertFloatsNotEqual(cat['coord_dec'],
                                  catWithEpoch['coord_dec'],
                                  rtol=1.0e-4)
Exemplo n.º 3
0
    def test_requireProperMotion(self):
        """Tests of the requireProperMotion config field."""
        loaderConfig = ReferenceObjectLoader.ConfigClass()
        loaderConfig.requireProperMotion = True
        loader = ReferenceObjectLoader(
            [dataRef.dataId for dataRef in self.datasetRefs],
            self.handles,
            config=loaderConfig)
        center = lsst.geom.SpherePoint(180.0 * lsst.geom.degrees,
                                       0.0 * lsst.geom.degrees)

        # Test that we require an epoch set.
        msg = 'requireProperMotion=True but epoch not provided to loader'
        with self.assertRaisesRegex(RuntimeError, msg):
            loader.loadSkyCircle(center,
                                 30.0 * lsst.geom.degrees,
                                 filterName='a')
Exemplo n.º 4
0
 def test_filterMap(self):
     """Test filterMap parameters."""
     loaderConfig = ReferenceObjectLoader.ConfigClass()
     loaderConfig.filterMap = {'aprime': 'a'}
     loader = ReferenceObjectLoader(
         [dataRef.dataId for dataRef in self.datasetRefs],
         self.handles,
         config=loaderConfig)
     center = lsst.geom.SpherePoint(180.0 * lsst.geom.degrees,
                                    0.0 * lsst.geom.degrees)
     result = loader.loadSkyCircle(
         center,
         30.0 * lsst.geom.degrees,
         filterName='aprime',
     )
     self.assertEqual(result.fluxField, 'aprime_camFlux')
     self.assertFloatsEqual(result.refCat['aprime_camFlux'],
                            result.refCat['a_flux'])
Exemplo n.º 5
0
        def runTest(withRaDecErr):
            # Generate a second catalog, with different ids
            inTempDir1 = tempfile.TemporaryDirectory()
            inPath1 = inTempDir1.name
            skyCatalogFile1, _, skyCatalog1 = self.makeSkyCatalog(inPath1,
                                                                  idStart=25,
                                                                  seed=123)
            inTempDir2 = tempfile.TemporaryDirectory()
            inPath2 = inTempDir2.name
            skyCatalogFile2, _, skyCatalog2 = self.makeSkyCatalog(inPath2,
                                                                  idStart=5432,
                                                                  seed=11)
            # override some field names, and use multiple cores
            config = ingestIndexTestBase.makeConvertConfig(
                withRaDecErr=withRaDecErr,
                withMagErr=True,
                withPm=True,
                withPmErr=True)
            # use a very small HTM pixelization depth to ensure there will be collisions when
            # ingesting the files in parallel
            depth = 2
            config.dataset_config.indexer.active.depth = depth
            # np.savetxt prepends '# ' to the header lines, so use a reader that understands that
            config.file_reader.format = 'ascii.commented_header'
            config.n_processes = 2  # use multiple cores for this test only
            config.id_name = 'id'  # Use the ids from the generated catalogs
            repoPath = os.path.join(
                self.outPath, "output_multifile_parallel",
                "_withRaDecErr" if withRaDecErr else "_noRaDecErr")

            # Convert the input data files to our HTM indexed format.
            dataTempDir = tempfile.TemporaryDirectory()
            dataPath = dataTempDir.name
            converter = ConvertReferenceCatalogTask(output_dir=dataPath,
                                                    config=config)
            converter.run([skyCatalogFile1, skyCatalogFile2])

            # Make a temporary butler to ingest them into.
            butler = self.makeTemporaryRepo(
                repoPath, config.dataset_config.indexer.active.depth)
            dimensions = [f"htm{depth}"]
            datasetType = DatasetType(config.dataset_config.ref_dataset_name,
                                      dimensions,
                                      "SimpleCatalog",
                                      universe=butler.registry.dimensions,
                                      isCalibration=False)
            butler.registry.registerDatasetType(datasetType)

            # Ingest the files into the new butler.
            run = "testingRun"
            htmTableFile = os.path.join(dataPath, "filename_to_htm.ecsv")
            ingest_files(repoPath,
                         config.dataset_config.ref_dataset_name,
                         run,
                         htmTableFile,
                         transfer="auto")

            # Test if we can get back the catalogs, with a new butler.
            butler = lsst.daf.butler.Butler(repoPath)
            datasetRefs = list(
                butler.registry.queryDatasets(
                    config.dataset_config.ref_dataset_name,
                    collections=[run]).expanded())
            handlers = []
            for dataRef in datasetRefs:
                handlers.append(
                    DeferredDatasetHandle(butler=butler,
                                          ref=dataRef,
                                          parameters=None))
            loaderConfig = ReferenceObjectLoader.ConfigClass()
            loader = ReferenceObjectLoader(
                [dataRef.dataId for dataRef in datasetRefs],
                handlers,
                config=loaderConfig,
                log=self.logger)
            self.checkAllRowsInRefcat(loader, skyCatalog1, config)
            self.checkAllRowsInRefcat(loader, skyCatalog2, config)

            inTempDir1.cleanup()
            inTempDir2.cleanup()
            dataTempDir.cleanup()