def testSumMagnitudes(self): """ Test that the method sum_magnitudes in PhotometryGalaxies handles NaNs correctly. Test it both in the vectorized and non-vectorized form. """ mm_0 = 22.0 bulge = 15.0 * np.ones(8) disk = 15.2 * np.ones(8) agn = 15.4 * np.ones(8) bulge[0] = np.NaN disk[1] = np.NaN agn[2] = np.NaN bulge[3] = np.NaN disk[3] = np.NaN bulge[4] = np.NaN agn[4] = np.NaN disk[5] = np.NaN agn[5] = np.NaN bulge[7] = np.NaN disk[7] = np.NaN agn[7] = np.NaN bulge_flux = np.power(10.0, -0.4 * (bulge - mm_0)) disk_flux = np.power(10.0, -0.4 * (disk - mm_0)) agn_flux = np.power(10.0, -0.4 * (agn - mm_0)) answer = np.zeros(8) answer[0] = -2.5 * np.log10(disk_flux[0] + agn_flux[0]) + mm_0 answer[1] = -2.5 * np.log10(bulge_flux[1] + agn_flux[1]) + mm_0 answer[2] = -2.5 * np.log10(bulge_flux[2] + disk_flux[2]) + mm_0 answer[3] = -2.5 * np.log10(agn_flux[3]) + mm_0 answer[4] = -2.5 * np.log10(disk_flux[4]) + mm_0 answer[5] = -2.5 * np.log10(bulge_flux[5]) + mm_0 answer[6] = -2.5 * np.log10(bulge_flux[6] + disk_flux[6] + agn_flux[6]) + mm_0 answer[7] = np.NaN phot = PhotometryGalaxies() test = phot.sum_magnitudes(bulge=bulge, disk=disk, agn=agn) np.testing.assert_array_almost_equal(test, answer, decimal=10) for ix, (bb, dd, aa, truth) in enumerate(zip(bulge, disk, agn, answer)): test = phot.sum_magnitudes(bulge=bb, disk=dd, agn=aa) if ix < 7: self.assertAlmostEqual(test, truth, 10) self.assertFalse(np.isnan(test), msg='test is NaN; should not be') else: np.testing.assert_equal(test, np.NaN) np.testing.assert_equal(truth, np.NaN)
def testSumMagnitudes(self): """ Test that the method sum_magnitudes in PhotometryGalaxies handles NaNs correctly. Test it both in the vectorized and non-vectorized form. """ mm_0 = 22.0 bulge = 15.0*np.ones(8) disk = 15.2*np.ones(8) agn = 15.4*np.ones(8) bulge[0] = np.NaN disk[1] = np.NaN agn[2] = np.NaN bulge[3] = np.NaN disk[3] = np.NaN bulge[4] = np.NaN agn[4] = np.NaN disk[5] = np.NaN agn[5] = np.NaN bulge[7] = np.NaN disk[7] = np.NaN agn[7] = np.NaN bulge_flux = np.power(10.0, -0.4*(bulge-mm_0)) disk_flux = np.power(10.0, -0.4*(disk-mm_0)) agn_flux = np.power(10.0, -0.4*(agn-mm_0)) answer = np.zeros(8) answer[0] = -2.5*np.log10(disk_flux[0]+agn_flux[0]) + mm_0 answer[1] = -2.5*np.log10(bulge_flux[1]+agn_flux[1]) + mm_0 answer[2] = -2.5*np.log10(bulge_flux[2]+disk_flux[2]) + mm_0 answer[3] = -2.5*np.log10(agn_flux[3]) + mm_0 answer[4] = -2.5*np.log10(disk_flux[4]) + mm_0 answer[5] = -2.5*np.log10(bulge_flux[5]) + mm_0 answer[6] = -2.5*np.log10(bulge_flux[6]+disk_flux[6]+agn_flux[6]) + mm_0 answer[7] = np.NaN phot = PhotometryGalaxies() test = phot.sum_magnitudes(bulge=bulge, disk=disk, agn=agn) np.testing.assert_array_almost_equal(test, answer, decimal=10) for ix, (bb, dd, aa, truth) in enumerate(zip(bulge, disk, agn, answer)): test = phot.sum_magnitudes(bulge=bb, disk=dd, agn=aa) if ix < 7: self.assertAlmostEqual(test, truth, 10) self.assertFalse(np.isnan(test), msg='test is NaN; should not be') else: np.testing.assert_equal(test, np.NaN) np.testing.assert_equal(truth, np.NaN)
def testGalaxyVariabilityInfrastructure(self): """ Test that the variability design was correctly implemented in the case of galaxies """ outputs = [ 'id', 'test_u', 'test_g', 'test_r', 'test_i', 'test_z', 'test_y', 'test_bulge_u', 'test_bulge_g', 'test_bulge_r', 'test_bulge_i', 'test_bulge_z', 'test_bulge_y', 'test_disk_u', 'test_disk_g', 'test_disk_r', 'test_disk_i', 'test_disk_z', 'test_disk_y', 'test_agn_u', 'test_agn_g', 'test_agn_r', 'test_agn_i', 'test_agn_z', 'test_agn_y' ] baseline = GalaxyBaselineCatalogClass(self.galaxyDB, column_outputs=outputs) variable = GalaxyVariabilityCatalogClass(self.galaxyDB, column_outputs=outputs) phot = PhotometryGalaxies() variable_indices = [19, 20, 21, 7, 16] for bb, vv in zip(baseline.iter_catalog(), variable.iter_catalog()): self.assertEqual(bb[0], vv[0]) # test that the variable components are altered # the way they ought to be self.assertAlmostEqual(bb[19] + 1.0, vv[19], 10) self.assertAlmostEqual(bb[20] + 2.0, vv[20], 10) self.assertAlmostEqual(bb[21] + 3.0, vv[21], 10) self.assertAlmostEqual(bb[7] + 4.0, vv[7], 10) self.assertAlmostEqual(bb[16] + 5.0, vv[16], 10) # test that the components which do not vary are equal for ix in range(7, 25): if ix not in variable_indices: self.assertAlmostEqual(bb[ix], vv[ix], 10) # test that the total magnitudes are correctly calculated for ix in range(6): self.assertAlmostEqual( bb[ix + 1], phot.sum_magnitudes(bulge=bb[7 + ix], disk=bb[13 + ix], agn=bb[19 + ix]), 10) self.assertAlmostEqual( vv[ix + 1], phot.sum_magnitudes(bulge=vv[7 + ix], disk=vv[13 + ix], agn=vv[19 + ix]), 10)
def testGalaxyVariabilityInfrastructure(self): """ Test that the variability design was correctly implemented in the case of galaxies """ outputs = ['id', 'test_u', 'test_g', 'test_r', 'test_i', 'test_z', 'test_y', 'test_bulge_u', 'test_bulge_g', 'test_bulge_r', 'test_bulge_i', 'test_bulge_z', 'test_bulge_y', 'test_disk_u', 'test_disk_g', 'test_disk_r', 'test_disk_i', 'test_disk_z', 'test_disk_y', 'test_agn_u', 'test_agn_g', 'test_agn_r', 'test_agn_i', 'test_agn_z', 'test_agn_y'] baseline = GalaxyBaselineCatalogClass(self.galaxyDB, column_outputs=outputs) variable = GalaxyVariabilityCatalogClass(self.galaxyDB, column_outputs=outputs) phot = PhotometryGalaxies() variable_indices = [19, 20, 21, 7, 16] for bb, vv in zip(baseline.iter_catalog(), variable.iter_catalog()): self.assertEqual(bb[0], vv[0]) # test that the variable components are altered # the way they ought to be self.assertAlmostEqual(bb[19]+1.0, vv[19], 10) self.assertAlmostEqual(bb[20]+2.0, vv[20], 10) self.assertAlmostEqual(bb[21]+3.0, vv[21], 10) self.assertAlmostEqual(bb[7]+4.0, vv[7], 10) self.assertAlmostEqual(bb[16]+5.0, vv[16], 10) # test that the components which do not vary are equal for ix in range(7, 25): if ix not in variable_indices: self.assertAlmostEqual(bb[ix], vv[ix], 10) # test that the total magnitudes are correctly calculated for ix in range(6): self.assertAlmostEqual(bb[ix+1], phot.sum_magnitudes(bulge=bb[7+ix], disk=bb[13+ix], agn=bb[19+ix]), 10) self.assertAlmostEqual(vv[ix+1], phot.sum_magnitudes(bulge=vv[7+ix], disk=vv[13+ix], agn=vv[19+ix]), 10)
def testSumMagnitudesCatalog(self): """ test that sum_magnitudes handles NaNs correctly in the context of a catalog by outputting a catalog of galaxies with NaNs in different component magnitudes, reading that catalog back in, and then calculating the summed magnitude by hand and comparing """ obs_metadata = ObservationMetaData(mjd=50000.0, boundType='circle', pointingRA=0.0, pointingDec=0.0, boundLength=10.0) test_cat = galaxiesWithHoles(self.galaxy, obs_metadata=obs_metadata) dtype = np.dtype([('raJ2000', np.float), ('decJ2000', np.float), ('u', np.float), ('g', np.float), ('r', np.float), ('i', np.float), ('z', np.float), ('y', np.float), ('ub', np.float), ('gb', np.float), ('rb', np.float), ('ib', np.float), ('zb', np.float), ('yb', np.float), ('ud', np.float), ('gd', np.float), ('rd', np.float), ('id', np.float), ('zd', np.float), ('yd', np.float), ('ua', np.float), ('ga', np.float), ('ra', np.float), ('ia', np.float), ('za', np.float), ('ya', np.float)]) with lsst.utils.tests.getTempFilePath('.txt') as catName: test_cat.write_catalog(catName) data = np.genfromtxt(catName, dtype=dtype, delimiter=', ') self.assertGreater(len(data), 16) phot = PhotometryGalaxies() test = phot.sum_magnitudes(bulge=data['ub'], disk=data['ud'], agn=data['ua']) np.testing.assert_array_almost_equal(test, data['u'], decimal=10) test = phot.sum_magnitudes(bulge=data['gb'], disk=data['gd'], agn=data['ga']) np.testing.assert_array_almost_equal(test, data['g'], decimal=10) test = phot.sum_magnitudes(bulge=data['rb'], disk=data['rd'], agn=data['ra']) np.testing.assert_array_almost_equal(test, data['r'], decimal=10) test = phot.sum_magnitudes(bulge=data['ib'], disk=data['id'], agn=data['ia']) np.testing.assert_array_almost_equal(test, data['i'], decimal=10) test = phot.sum_magnitudes(bulge=data['zb'], disk=data['zd'], agn=data['za']) np.testing.assert_array_almost_equal(test, data['z'], decimal=10) test = phot.sum_magnitudes(bulge=data['yb'], disk=data['yd'], agn=data['ya']) np.testing.assert_array_almost_equal(test, data['y'], decimal=10) # make sure that there were some NaNs for our catalog to deal with (but that they were not # all NaNs for line in [data['u'], data['g'], data['r'], data['i'], data['z'], data['y'], data['ub'], data['gb'], data['rb'], data['ib'], data['zb'], data['yb'], data['ud'], data['gd'], data['rd'], data['id'], data['zd'], data['yd'], data['ua'], data['ga'], data['ra'], data['ia'], data['za'], data['ya']]: ctNans = len(np.where(np.isnan(line))[0]) self.assertGreater(ctNans, 0) self.assertLess(ctNans, len(line))
def testSumMagnitudesCatalog(self): """ test that sum_magnitudes handles NaNs correctly in the context of a catalog by outputting a catalog of galaxies with NaNs in different component magnitudes, reading that catalog back in, and then calculating the summed magnitude by hand and comparing """ obs_metadata = ObservationMetaData(mjd=50000.0, boundType='circle', pointingRA=0.0, pointingDec=0.0, boundLength=10.0) test_cat = galaxiesWithHoles(self.galaxy, obs_metadata=obs_metadata) dtype = np.dtype([('raJ2000', np.float), ('decJ2000', np.float), ('u', np.float), ('g', np.float), ('r', np.float), ('i', np.float), ('z', np.float), ('y', np.float), ('ub', np.float), ('gb', np.float), ('rb', np.float), ('ib', np.float), ('zb', np.float), ('yb', np.float), ('ud', np.float), ('gd', np.float), ('rd', np.float), ('id', np.float), ('zd', np.float), ('yd', np.float), ('ua', np.float), ('ga', np.float), ('ra', np.float), ('ia', np.float), ('za', np.float), ('ya', np.float)]) with lsst.utils.tests.getTempFilePath('.txt') as catName: test_cat.write_catalog(catName) data = np.genfromtxt(catName, dtype=dtype, delimiter=', ') self.assertGreater(len(data), 16) phot = PhotometryGalaxies() test = phot.sum_magnitudes(bulge=data['ub'], disk=data['ud'], agn=data['ua']) np.testing.assert_array_almost_equal(test, data['u'], decimal=10) test = phot.sum_magnitudes(bulge=data['gb'], disk=data['gd'], agn=data['ga']) np.testing.assert_array_almost_equal(test, data['g'], decimal=10) test = phot.sum_magnitudes(bulge=data['rb'], disk=data['rd'], agn=data['ra']) np.testing.assert_array_almost_equal(test, data['r'], decimal=10) test = phot.sum_magnitudes(bulge=data['ib'], disk=data['id'], agn=data['ia']) np.testing.assert_array_almost_equal(test, data['i'], decimal=10) test = phot.sum_magnitudes(bulge=data['zb'], disk=data['zd'], agn=data['za']) np.testing.assert_array_almost_equal(test, data['z'], decimal=10) test = phot.sum_magnitudes(bulge=data['yb'], disk=data['yd'], agn=data['ya']) np.testing.assert_array_almost_equal(test, data['y'], decimal=10) # make sure that there were some NaNs for our catalog to deal with (but that they were not # all NaNs for line in [ data['u'], data['g'], data['r'], data['i'], data['z'], data['y'], data['ub'], data['gb'], data['rb'], data['ib'], data['zb'], data['yb'], data['ud'], data['gd'], data['rd'], data['id'], data['zd'], data['yd'], data['ua'], data['ga'], data['ra'], data['ia'], data['za'], data['ya'] ]: ctNans = len(np.where(np.isnan(line))[0]) self.assertGreater(ctNans, 0) self.assertLess(ctNans, len(line))
def testSumMagnitudesCatalog(self): """ test that sum_magnitudes handles NaNs correctly in the context of a catalog by outputting a catalog of galaxies with NaNs in different component magnitudes, reading that catalog back in, and then calculating the summed magnitude by hand and comparing """ catName = 'galaxiesWithHoles.txt' obs_metadata=ObservationMetaData(mjd=50000.0, boundType='circle',unrefractedRA=0.0,unrefractedDec=0.0, boundLength=10.0) test_cat=galaxiesWithHoles(self.galaxy,obs_metadata=obs_metadata) test_cat.write_catalog(catName) dtype = numpy.dtype([ ('raJ2000', numpy.float), ('decJ2000', numpy.float), ('u', numpy.float), ('g', numpy.float), ('r', numpy.float), ('i', numpy.float), ('z', numpy.float), ('y', numpy.float), ('ub', numpy.float), ('gb', numpy.float), ('rb', numpy.float), ('ib', numpy.float), ('zb', numpy.float), ('yb', numpy.float), ('ud', numpy.float), ('gd', numpy.float), ('rd', numpy.float), ('id', numpy.float), ('zd', numpy.float), ('yd', numpy.float), ('ua', numpy.float), ('ga', numpy.float), ('ra', numpy.float), ('ia', numpy.float), ('za', numpy.float), ('ya', numpy.float) ]) data = numpy.genfromtxt(catName, dtype=dtype, delimiter=', ') self.assertTrue(len(data)>16) phot = PhotometryGalaxies() test = phot.sum_magnitudes(bulge=data['ub'], disk=data['ud'], agn=data['ua']) numpy.testing.assert_array_almost_equal(test, data['u'], decimal=10) test = phot.sum_magnitudes(bulge=data['gb'], disk=data['gd'], agn=data['ga']) numpy.testing.assert_array_almost_equal(test, data['g'], decimal=10) test = phot.sum_magnitudes(bulge=data['rb'], disk=data['rd'], agn=data['ra']) numpy.testing.assert_array_almost_equal(test, data['r'], decimal=10) test = phot.sum_magnitudes(bulge=data['ib'], disk=data['id'], agn=data['ia']) numpy.testing.assert_array_almost_equal(test, data['i'], decimal=10) test = phot.sum_magnitudes(bulge=data['zb'], disk=data['zd'], agn=data['za']) numpy.testing.assert_array_almost_equal(test, data['z'], decimal=10) test = phot.sum_magnitudes(bulge=data['yb'], disk=data['yd'], agn=data['ya']) numpy.testing.assert_array_almost_equal(test, data['y'], decimal=10) # make sure that there were some NaNs for our catalog to deal with (but that they were not # all NaNs for line in [data['u'], data['g'], data['r'], data['i'], data['z'], data['y'], data['ub'], data['gb'], data['rb'], data['ib'], data['zb'], data['yb'], data['ud'], data['gd'], data['rd'], data['id'], data['zd'], data['yd'], data['ua'], data['ga'], data['ra'], data['ia'], data['za'], data['ya']]: ctNans = len(numpy.where(numpy.isnan(line))[0]) self.assertTrue(ctNans>0) self.assertTrue(ctNans<len(line)) if os.path.exists(catName): os.unlink(catName)