예제 #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'])
    def testCheckFluxUnits(self):
        """Test that we can identify old style fluxes in a schema."""
        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        # the default schema should pass
        self.assertTrue(hasNanojanskyFluxUnits(schema))
        schema.addField('bad_fluxSigma', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_flux', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_flux', doc='old flux units', type=float, units='Jy')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_fluxErr', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_fluxErr', doc='old flux units', type=float, units='Jy')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_fluxSigma', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))
    def testCheckFluxUnits(self):
        """Test that we can identify old style fluxes in a schema."""
        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        # the default schema should pass
        self.assertTrue(hasNanojanskyFluxUnits(schema))
        schema.addField('bad_fluxSigma', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_flux', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_flux', doc='old flux units', type=float, units='Jy')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_fluxErr', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_fluxErr', doc='old flux units', type=float, units='Jy')
        self.assertFalse(hasNanojanskyFluxUnits(schema))

        schema = LoadReferenceObjectsTask.makeMinimalSchema(['r', 'z'])
        schema.addField('bad_fluxSigma', doc='old flux units', type=float, units='')
        self.assertFalse(hasNanojanskyFluxUnits(schema))
예제 #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 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'])
예제 #6
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'])
예제 #7
0
def is_old_schema(config, filename):
    """Check whether this file's schema has "old-style" fluxes."""
    catalog = lsst.afw.table.SimpleCatalog.readFits(filename)
    return (config.format_version
            == 0) and (not hasNanojanskyFluxUnits(catalog.schema))
def is_old_schema(config, filename):
    """Check whether this file's schema has "old-style" fluxes."""
    catalog = lsst.afw.table.SimpleCatalog.readFits(filename)
    return (config.format_version == 0) and (not hasNanojanskyFluxUnits(catalog.schema))