コード例 #1
0
    def testGalaxyPhotometricIndices(self):
        baselineCatName = os.path.join(
            getPackageDir('sims_catUtils'), 'tests', 'scratchSpace',
            'testPhotMix_testGalIndices_galaxyBaselineCatalog.txt')

        if os.path.exists(baselineCatName):
            os.unlink(baselineCatName)

        baselineDtype = np.dtype([('galid', int), ('raObserved', float),
                                  ('decObserved', float), ('ctotal_u', float),
                                  ('ctotal_g', float), ('ctotal_r', float),
                                  ('ctotal_i', float), ('ctotal_z', float)])

        obs_metadata_pointed = ObservationMetaData(mjd=50000.0,
                                                   boundType='circle',
                                                   pointingRA=0.0,
                                                   pointingDec=0.0,
                                                   boundLength=10.0)

        baseline_cat = cartoonGalaxies(self.galaxy,
                                       obs_metadata=obs_metadata_pointed)
        baseline_cat.write_catalog(baselineCatName)
        baselineData = np.genfromtxt(baselineCatName,
                                     dtype=baselineDtype,
                                     delimiter=',')
        self.assertGreater(len(baselineData), 0)

        testCatName = os.path.join(
            getPackageDir('sims_catUtils'), 'tests', 'scratchSpace',
            'testPhotMix_testGalIndices_galaxyTestCatalog.txt')

        if os.path.exists(testCatName):
            os.unlink(testCatName)

        testDtype = np.dtype([('galid', int), ('raObserved', float),
                              ('decObserved', float), ('ctotal_i', float),
                              ('ctotal_g', float)])

        test_cat = cartoonGalaxiesIG(self.galaxy,
                                     obs_metadata=obs_metadata_pointed)
        test_cat.write_catalog(testCatName)
        testData = np.genfromtxt(testCatName, dtype=testDtype, delimiter=',')
        self.assertGreater(len(testData), 0)

        for b, t in zip(baselineData, testData):
            self.assertAlmostEqual(b['ctotal_i'], t['ctotal_i'], 10)
            self.assertAlmostEqual(b['ctotal_g'], t['ctotal_g'], 10)

        if os.path.exists(baselineCatName):
            os.unlink(baselineCatName)

        if os.path.exists(testCatName):
            os.unlink(testCatName)
コード例 #2
0
    def testAlternateBandpassesGalaxies(self):
        """
        the same as testAlternateBandpassesStars, but for galaxies
        """

        obs_metadata_pointed=ObservationMetaData(mjd=50000.0,
                               boundType='circle',unrefractedRA=0.0,unrefractedDec=0.0,
                               boundLength=10.0)

        test_cat=cartoonGalaxies(self.galaxy,obs_metadata=obs_metadata_pointed)
        test_cat.write_catalog("testGalaxiesCartoon.txt")

        cartoonDir = os.getenv('SIMS_PHOTUTILS_DIR')+'/tests/cartoonSedTestData/'
        testBandPasses = {}
        keys = ['u','g','r','i','z']

        bplist = []

        for kk in keys:
            testBandPasses[kk] = Bandpass()
            testBandPasses[kk].readThroughput(os.path.join(cartoonDir,"test_bandpass_%s.dat" % kk))
            bplist.append(testBandPasses[kk])

        sedObj = Sed()
        phiArray, waveLenStep = sedObj.setupPhiArray(bplist)

        components = ['Bulge', 'Disk', 'Agn']

        ct = 0
        for cc in components:
            i = 0

            for ss in test_cat.sedMasterDict[cc]:
                if ss.wavelen != None:
                    ss.resampleSED(wavelen_match = bplist[0].wavelen)
                    ss.flambdaTofnu()
                    mags = -2.5*numpy.log10(numpy.sum(phiArray*ss.fnu, axis=1)*waveLenStep) - ss.zp
                    for j in range(len(mags)):
                        ct += 1
                        self.assertAlmostEqual(mags[j],test_cat.magnitudeMasterDict[cc][i][j],10)
                i += 1

        self.assertTrue(ct>0)
        os.unlink("testGalaxiesCartoon.txt")
コード例 #3
0
    def testGalaxyPhotometricIndices(self):
        baselineCatName = 'galaxyBaselineCatalog.txt'
        baselineDtype = numpy.dtype([('galid', int),
                                     ('raObserved', float),
                                     ('decObserved', float),
                                     ('ctotal_u', float),
                                     ('ctotal_g', float),
                                     ('ctotal_r', float),
                                     ('ctotal_i', float),
                                     ('ctotal_z', float)])

        obs_metadata_pointed=ObservationMetaData(mjd=50000.0,
                               boundType='circle',unrefractedRA=0.0,unrefractedDec=0.0,
                               boundLength=10.0)

        baseline_cat=cartoonGalaxies(self.galaxy,obs_metadata=obs_metadata_pointed)
        baseline_cat.write_catalog(baselineCatName)
        baselineData = numpy.genfromtxt(baselineCatName, dtype=baselineDtype, delimiter=',')

        testCatName = 'galaxyTestCatalog.txt'
        testDtype = numpy.dtype([('galid', int),
                                 ('raObserved', float),
                                 ('decObserved', float),
                                 ('ctotal_i', float),
                                 ('ctotal_g', float)])
        test_cat = cartoonGalaxiesIG(self.galaxy, obs_metadata=obs_metadata_pointed)
        test_cat.write_catalog(testCatName)
        testData = numpy.genfromtxt(testCatName, dtype=testDtype, delimiter=',')
        ct = 0
        for b,t in zip(baselineData, testData):
            self.assertAlmostEqual(b['ctotal_i'], t['ctotal_i'], 10)
            self.assertAlmostEqual(b['ctotal_g'], t['ctotal_g'], 10)
            ct += 1
        self.assertTrue(ct>0)

        if os.path.exists(baselineCatName):
            os.unlink(baselineCatName)

        if os.path.exists(testCatName):
            os.unlink(testCatName)
コード例 #4
0
    def testGalaxyPhotometricIndices(self):
        baselineDtype = np.dtype([('galid', int), ('raObserved', float),
                                  ('decObserved', float), ('ctotal_u', float),
                                  ('ctotal_g', float), ('ctotal_r', float),
                                  ('ctotal_i', float), ('ctotal_z', float)])

        obs_metadata_pointed = ObservationMetaData(mjd=50000.0,
                                                   boundType='circle',
                                                   pointingRA=0.0,
                                                   pointingDec=0.0,
                                                   boundLength=10.0)

        baseline_cat = cartoonGalaxies(self.galaxy,
                                       obs_metadata=obs_metadata_pointed)
        with lsst.utils.tests.getTempFilePath('.txt') as baselineCatName:
            baseline_cat.write_catalog(baselineCatName)
            baselineData = np.genfromtxt(baselineCatName,
                                         dtype=baselineDtype,
                                         delimiter=',')
        self.assertGreater(len(baselineData), 0)

        testDtype = np.dtype([('galid', int), ('raObserved', float),
                              ('decObserved', float), ('ctotal_i', float),
                              ('ctotal_g', float)])

        test_cat = cartoonGalaxiesIG(self.galaxy,
                                     obs_metadata=obs_metadata_pointed)
        with lsst.utils.tests.getTempFilePath('.txt') as testCatName:
            test_cat.write_catalog(testCatName)
            testData = np.genfromtxt(testCatName,
                                     dtype=testDtype,
                                     delimiter=',')
        self.assertGreater(len(testData), 0)

        for b, t in zip(baselineData, testData):
            self.assertAlmostEqual(b['ctotal_i'], t['ctotal_i'], 10)
            self.assertAlmostEqual(b['ctotal_g'], t['ctotal_g'], 10)
コード例 #5
0
    def testGalaxyPhotometricIndices(self):
        baselineDtype = np.dtype([('galid', int),
                                  ('raObserved', float),
                                  ('decObserved', float),
                                  ('ctotal_u', float),
                                  ('ctotal_g', float),
                                  ('ctotal_r', float),
                                  ('ctotal_i', float),
                                  ('ctotal_z', float)])

        obs_metadata_pointed = ObservationMetaData(mjd=50000.0,
                                                   boundType='circle',
                                                   pointingRA=0.0, pointingDec=0.0,
                                                   boundLength=10.0)

        baseline_cat = cartoonGalaxies(self.galaxy, obs_metadata=obs_metadata_pointed)
        with lsst.utils.tests.getTempFilePath('.txt') as baselineCatName:
            baseline_cat.write_catalog(baselineCatName)
            baselineData = np.genfromtxt(baselineCatName, dtype=baselineDtype, delimiter=',')
        self.assertGreater(len(baselineData), 0)

        testDtype = np.dtype([('galid', int),
                              ('raObserved', float),
                              ('decObserved', float),
                              ('ctotal_i', float),
                              ('ctotal_g', float)])

        test_cat = cartoonGalaxiesIG(self.galaxy, obs_metadata=obs_metadata_pointed)
        with lsst.utils.tests.getTempFilePath('.txt') as testCatName:
            test_cat.write_catalog(testCatName)
            testData = np.genfromtxt(testCatName, dtype=testDtype, delimiter=',')
        self.assertGreater(len(testData), 0)

        for b, t in zip(baselineData, testData):
            self.assertAlmostEqual(b['ctotal_i'], t['ctotal_i'], 10)
            self.assertAlmostEqual(b['ctotal_g'], t['ctotal_g'], 10)
コード例 #6
0
    def testAlternateBandpassesGalaxies(self):
        """
        the same as testAlternateBandpassesStars, but for galaxies
        """

        obs_metadata_pointed = ObservationMetaData(mjd=50000.0,
                                                   boundType='circle',
                                                   pointingRA=0.0, pointingDec=0.0,
                                                   boundLength=10.0)

        dtype = np.dtype([('galid', np.int),
                          ('ra', np.float),
                          ('dec', np.float),
                          ('uTotal', np.float),
                          ('gTotal', np.float),
                          ('rTotal', np.float),
                          ('iTotal', np.float),
                          ('zTotal', np.float),
                          ('uBulge', np.float),
                          ('gBulge', np.float),
                          ('rBulge', np.float),
                          ('iBulge', np.float),
                          ('zBulge', np.float),
                          ('uDisk', np.float),
                          ('gDisk', np.float),
                          ('rDisk', np.float),
                          ('iDisk', np.float),
                          ('zDisk', np.float),
                          ('uAgn', np.float),
                          ('gAgn', np.float),
                          ('rAgn', np.float),
                          ('iAgn', np.float),
                          ('zAgn', np.float),
                          ('bulgeName', str, 200),
                          ('bulgeNorm', np.float),
                          ('bulgeAv', np.float),
                          ('diskName', str, 200),
                          ('diskNorm', np.float),
                          ('diskAv', np.float),
                          ('agnName', str, 200),
                          ('agnNorm', np.float),
                          ('redshift', np.float)])

        test_cat = cartoonGalaxies(self.galaxy, obs_metadata=obs_metadata_pointed)
        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            test_cat.write_catalog(catName)
            catData = np.genfromtxt(catName, dtype=dtype, delimiter=', ')

        self.assertGreater(len(catData), 0)

        cartoonDir = getPackageDir('sims_photUtils')
        cartoonDir = os.path.join(cartoonDir, 'tests', 'cartoonSedTestData')
        sedDir = getPackageDir('sims_sed_library')

        testBandpasses = {}
        keys = ['u', 'g', 'r', 'i', 'z']

        for kk in keys:
            testBandpasses[kk] = Bandpass()
            testBandpasses[kk].readThroughput(os.path.join(cartoonDir, "test_bandpass_%s.dat" % kk))

        imsimBand = Bandpass()
        imsimBand.imsimBandpass()

        specMap = defaultSpecMap

        ct = 0
        for line in catData:
            bulgeMagList = []
            diskMagList = []
            agnMagList = []
            if line['bulgeName'] == 'None':
                for bp in keys:
                    np.testing.assert_equal(line['%sBulge' % bp], np.NaN)
                    bulgeMagList.append(np.NaN)
            else:
                ct += 1
                dummySed = Sed()
                dummySed.readSED_flambda(os.path.join(sedDir, specMap[line['bulgeName']]))
                fnorm = dummySed.calcFluxNorm(line['bulgeNorm'], imsimBand)
                dummySed.multiplyFluxNorm(fnorm)
                a_int, b_int = dummySed.setupCCM_ab()
                dummySed.addDust(a_int, b_int, A_v=line['bulgeAv'])
                dummySed.redshiftSED(line['redshift'], dimming=True)
                dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen)
                for bpName in keys:
                    mag = dummySed.calcMag(testBandpasses[bpName])
                    self.assertAlmostEqual(mag, line['%sBulge' % bpName], 10)
                    bulgeMagList.append(mag)

            if line['diskName'] == 'None':
                for bp in keys:
                    np.assert_equal(line['%sDisk' % bp], np.NaN)
                    diskMagList.append(np.NaN)
            else:
                ct += 1
                dummySed = Sed()
                dummySed.readSED_flambda(os.path.join(sedDir, specMap[line['diskName']]))
                fnorm = dummySed.calcFluxNorm(line['diskNorm'], imsimBand)
                dummySed.multiplyFluxNorm(fnorm)
                a_int, b_int = dummySed.setupCCM_ab()
                dummySed.addDust(a_int, b_int, A_v=line['diskAv'])
                dummySed.redshiftSED(line['redshift'], dimming=True)
                dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen)
                for bpName in keys:
                    mag = dummySed.calcMag(testBandpasses[bpName])
                    self.assertAlmostEqual(mag, line['%sDisk' % bpName], 10)
                    diskMagList.append(mag)

            if line['agnName'] == 'None':
                for bp in keys:
                    np.testing.assert_true(line['%sAgn' % bp], np.NaN)
                    agnMagList.append(np.NaN)
            else:
                ct += 1
                dummySed = Sed()
                dummySed.readSED_flambda(os.path.join(sedDir, specMap[line['agnName']]))
                fnorm = dummySed.calcFluxNorm(line['agnNorm'], imsimBand)
                dummySed.multiplyFluxNorm(fnorm)
                dummySed.redshiftSED(line['redshift'], dimming=True)
                dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen)
                for bpName in keys:
                    mag = dummySed.calcMag(testBandpasses[bpName])
                    self.assertAlmostEqual(mag, line['%sAgn' % bpName], 10)
                    agnMagList.append(mag)

            totalMags = PhotometryGalaxies().sum_magnitudes(bulge=np.array(bulgeMagList),
                                                            disk=np.array(diskMagList),
                                                            agn=np.array(agnMagList))

            for testMag, bpName in zip(totalMags, keys):
                if np.isnan(line['%sTotal' % bpName]):
                    np.testing.assert_equal(testMag, np.NaN)
                else:
                    self.assertAlmostEqual(testMag, line['%sTotal' % bpName], 10)

        self.assertGreater(ct, 0)
コード例 #7
0
    def testAlternateBandpassesGalaxies(self):
        """
        the same as testAlternateBandpassesStars, but for galaxies
        """

        obs_metadata_pointed = ObservationMetaData(mjd=50000.0,
                                                   boundType='circle',
                                                   pointingRA=0.0,
                                                   pointingDec=0.0,
                                                   boundLength=10.0)

        dtype = np.dtype([('galid', np.int), ('ra', np.float),
                          ('dec', np.float), ('uTotal', np.float),
                          ('gTotal', np.float), ('rTotal', np.float),
                          ('iTotal', np.float), ('zTotal', np.float),
                          ('uBulge', np.float), ('gBulge', np.float),
                          ('rBulge', np.float), ('iBulge', np.float),
                          ('zBulge', np.float), ('uDisk', np.float),
                          ('gDisk', np.float), ('rDisk', np.float),
                          ('iDisk', np.float), ('zDisk', np.float),
                          ('uAgn', np.float), ('gAgn', np.float),
                          ('rAgn', np.float), ('iAgn', np.float),
                          ('zAgn', np.float), ('bulgeName', str, 200),
                          ('bulgeNorm', np.float), ('bulgeAv', np.float),
                          ('diskName', str, 200), ('diskNorm', np.float),
                          ('diskAv', np.float), ('agnName', str, 200),
                          ('agnNorm', np.float), ('redshift', np.float)])

        test_cat = cartoonGalaxies(self.galaxy,
                                   obs_metadata=obs_metadata_pointed)
        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            test_cat.write_catalog(catName)
            catData = np.genfromtxt(catName, dtype=dtype, delimiter=', ')

        self.assertGreater(len(catData), 0)

        cartoonDir = getPackageDir('sims_photUtils')
        cartoonDir = os.path.join(cartoonDir, 'tests', 'cartoonSedTestData')
        sedDir = getPackageDir('sims_sed_library')

        testBandpasses = {}
        keys = ['u', 'g', 'r', 'i', 'z']

        for kk in keys:
            testBandpasses[kk] = Bandpass()
            testBandpasses[kk].readThroughput(
                os.path.join(cartoonDir, "test_bandpass_%s.dat" % kk))

        imsimBand = Bandpass()
        imsimBand.imsimBandpass()

        specMap = defaultSpecMap

        ct = 0
        for line in catData:
            bulgeMagList = []
            diskMagList = []
            agnMagList = []
            if line['bulgeName'] == 'None':
                for bp in keys:
                    np.testing.assert_equal(line['%sBulge' % bp], np.NaN)
                    bulgeMagList.append(np.NaN)
            else:
                ct += 1
                dummySed = Sed()
                dummySed.readSED_flambda(
                    os.path.join(sedDir, specMap[line['bulgeName']]))
                fnorm = dummySed.calcFluxNorm(line['bulgeNorm'], imsimBand)
                dummySed.multiplyFluxNorm(fnorm)
                a_int, b_int = dummySed.setupCCM_ab()
                dummySed.addDust(a_int, b_int, A_v=line['bulgeAv'])
                dummySed.redshiftSED(line['redshift'], dimming=True)
                dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen)
                for bpName in keys:
                    mag = dummySed.calcMag(testBandpasses[bpName])
                    self.assertAlmostEqual(mag, line['%sBulge' % bpName], 10)
                    bulgeMagList.append(mag)

            if line['diskName'] == 'None':
                for bp in keys:
                    np.assert_equal(line['%sDisk' % bp], np.NaN)
                    diskMagList.append(np.NaN)
            else:
                ct += 1
                dummySed = Sed()
                dummySed.readSED_flambda(
                    os.path.join(sedDir, specMap[line['diskName']]))
                fnorm = dummySed.calcFluxNorm(line['diskNorm'], imsimBand)
                dummySed.multiplyFluxNorm(fnorm)
                a_int, b_int = dummySed.setupCCM_ab()
                dummySed.addDust(a_int, b_int, A_v=line['diskAv'])
                dummySed.redshiftSED(line['redshift'], dimming=True)
                dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen)
                for bpName in keys:
                    mag = dummySed.calcMag(testBandpasses[bpName])
                    self.assertAlmostEqual(mag, line['%sDisk' % bpName], 10)
                    diskMagList.append(mag)

            if line['agnName'] == 'None':
                for bp in keys:
                    np.testing.assert_true(line['%sAgn' % bp], np.NaN)
                    agnMagList.append(np.NaN)
            else:
                ct += 1
                dummySed = Sed()
                dummySed.readSED_flambda(
                    os.path.join(sedDir, specMap[line['agnName']]))
                fnorm = dummySed.calcFluxNorm(line['agnNorm'], imsimBand)
                dummySed.multiplyFluxNorm(fnorm)
                dummySed.redshiftSED(line['redshift'], dimming=True)
                dummySed.resampleSED(wavelen_match=testBandpasses['u'].wavelen)
                for bpName in keys:
                    mag = dummySed.calcMag(testBandpasses[bpName])
                    self.assertAlmostEqual(mag, line['%sAgn' % bpName], 10)
                    agnMagList.append(mag)

            totalMags = PhotometryGalaxies().sum_magnitudes(
                bulge=np.array(bulgeMagList),
                disk=np.array(diskMagList),
                agn=np.array(agnMagList))

            for testMag, bpName in zip(totalMags, keys):
                if np.isnan(line['%sTotal' % bpName]):
                    np.testing.assert_equal(testMag, np.NaN)
                else:
                    self.assertAlmostEqual(testMag, line['%sTotal' % bpName],
                                           10)

        self.assertGreater(ct, 0)