def testHDU1DefaultNames(self): """Test the data in HDU 1, loading all columns without renaming """ task = ReadFitsCatalogTask() table = task.run(FitsPath) self.assertTrue(np.array_equal(table, self.arr1)) self.assertEqual(len(table), 2)
def testHDU2(self): """Test reading HDU 2 with original order""" config = ReadFitsCatalogTask.ConfigClass() config.hdu = 2 task = ReadFitsCatalogTask(config=config) arr = task.run(FitsPath) self.assertTrue(np.array_equal(arr, self.arr2))
def testHDU1DefaultNames(self): """Test the data in HDU 1, loading all columns without renaming """ task = ReadFitsCatalogTask() table = task.run(FitsPath) self.assertTrue(np.array_equal(self.arr1, table)) self.assertEqual(len(table), 2)
def testHDU2(self): """Test reading HDU 2 with original order""" config = ReadFitsCatalogTask.ConfigClass() config.hdu = 2 task = ReadFitsCatalogTask(config=config) arr = task.run(FitsPath) self.assertTrue(np.array_equal(self.arr2, arr))
def testBadHdu(self): """Test that non-existent HDUs cause an error""" for badHdu in [0, 3, 4]: config = ReadFitsCatalogTask.ConfigClass() config.hdu = badHdu task = ReadFitsCatalogTask(config=config) with self.assertRaises(Exception): task.run(FitsPath)
def testBadColumnName(self): """Test that non-existent columns in column_map cause an error""" config = ReadFitsCatalogTask.ConfigClass() for badColNames in ( ["name", "ra", "dec", "counts", "flux", "resolved", "other"], # "other" only in hdu 2 ["name", "ra", "dec", "counts", "flux", "invalidname"], ["invalid1"], ): config.column_map = dict((name, "col %s" % (i,)) for i, name in enumerate(badColNames)) task = ReadFitsCatalogTask(config=config) with self.assertRaises(RuntimeError): task.run(FitsPath)
def testBadColumnName(self): """Test that non-existent columns in column_map cause an error""" config = ReadFitsCatalogTask.ConfigClass() for badColNames in ( ["name", "ra", "dec", "counts", "flux", "resolved", "other"], # "other" only in hdu 2 ["name", "ra", "dec", "counts", "flux", "invalidname"], ["invalid1"], ): config.column_map = dict( (name, "col %s" % (i, )) for i, name in enumerate(badColNames)) task = ReadFitsCatalogTask(config=config) with self.assertRaises(RuntimeError): task.run(FitsPath)
def testHDU1GivenNames(self): """Test the data in HDU 1 with some column renaming All columns should be in the same order; those that are renamed should have their new name, and the rest should have their original name. """ column_map = { "name": "source", "ra": "ra_deg", "dec": "dec_deg", } config = ReadFitsCatalogTask.ConfigClass() config.column_map = column_map self.assertEqual(config.hdu, 1) task = ReadFitsCatalogTask(config=config) arr = task.run(FitsPath) self.assertEqual(len(Table(arr).columns), len(Table(self.arr1).columns)) for inname, outname in zip(self.arr1.dtype.names, arr.dtype.names): des_outname = column_map.get(inname, inname) self.assertEqual(outname, des_outname) self.assertTrue(np.array_equal(self.arr1[inname], arr[outname]))
def testBadPath(self): """Test that an invalid path causes an error""" task = ReadFitsCatalogTask() badPath = "does/not/exists.garbage" with self.assertRaises(IOError): task.run(badPath)