def testStellarPhotometryIndices(self):
        """
        A test to make sure that stellar photometry still calculates the right values
        even when it is not calculating all of the magnitudes in the getter
        """

        baselineDtype = numpy.dtype([('id',int),
                                     ('raObserved', float), ('decObserved', float),
                                     ('magNorm', float),
                                     ('cartoon_u', float), ('cartoon_g',float),
                                     ('cartoon_r', float), ('cartoon_i', float),
                                     ('cartoon_z', float)])

        baselineCatName = 'stellarBaselineCatalog.txt'

        testDtype = numpy.dtype([('id',int),
                                 ('raObserved',float), ('decObserved',float),
                                 ('cartoon_i',float)])

        testCatName = 'stellarTestCatalog.txt'


        obs_metadata_pointed=ObservationMetaData(mjd=2013.23,
                                                 boundType='circle',unrefractedRA=200.0,unrefractedDec=-30.0,
                                                 boundLength=1.0)

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

        test_cat=cartoonStarsOnlyI(self.star, 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['cartoon_i'], t['cartoon_i'], 10)
            ct+=1
        self.assertTrue(ct>0)

        testDtype = numpy.dtype([('id',int),
                                 ('raObserved',float), ('decObserved',float),
                                 ('cartoon_i',float), ('cartoon_z',float)])


        test_cat=cartoonStarsIZ(self.star, 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['cartoon_i'], t['cartoon_i'], 10)
            self.assertAlmostEqual(b['cartoon_z'], t['cartoon_z'], 10)
            ct+=1
        self.assertTrue(ct>0)

        if os.path.exists(testCatName):
            os.unlink(testCatName)
        if os.path.exists(baselineCatName):
            os.unlink(baselineCatName)
Пример #2
0
    def testStellarPhotometryIndices(self):
        """
        A test to make sure that stellar photometry still calculates the right values
        even when it is not calculating all of the magnitudes in the getter
        """

        baselineDtype = np.dtype([('id', int), ('raObserved', float),
                                  ('decObserved', float), ('magNorm', float),
                                  ('cartoon_u', float), ('cartoon_g', float),
                                  ('cartoon_r', float), ('cartoon_i', float),
                                  ('cartoon_z', float)])

        testDtype = np.dtype([('id', int), ('raObserved', float),
                              ('decObserved', float), ('cartoon_i', float)])

        obs_metadata_pointed = ObservationMetaData(mjd=2013.23,
                                                   boundType='circle',
                                                   pointingRA=200.0,
                                                   pointingDec=-30.0,
                                                   boundLength=1.0)

        baseline_cat = cartoonStars(self.star,
                                    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)

        test_cat = cartoonStarsOnlyI(self.star,
                                     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['cartoon_i'], t['cartoon_i'], 10)

        testDtype = np.dtype([('id', int), ('raObserved', float),
                              ('decObserved', float), ('cartoon_i', float),
                              ('cartoon_z', float)])

        test_cat = cartoonStarsIZ(self.star, 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['cartoon_i'], t['cartoon_i'], 10)
            self.assertAlmostEqual(b['cartoon_z'], t['cartoon_z'], 10)
Пример #3
0
    def testAlternateBandpassesStars(self):
        """
        This will test our ability to do photometry using non-LSST bandpasses.

        It will first calculate the magnitudes using the getters in cartoonPhotometryStars.

        It will then load the alternate bandpass files 'by hand' and re-calculate the magnitudes
        and make sure that the magnitude values agree.  This is guarding against the possibility
        that some default value did not change and the code actually ended up loading the
        LSST bandpasses.
        """

        obs_metadata_pointed = ObservationMetaData(mjd=2013.23,
                                                   boundType='circle',
                                                   pointingRA=200.0,
                                                   pointingDec=-30.0,
                                                   boundLength=1.0)

        test_cat = cartoonStars(self.star, obs_metadata=obs_metadata_pointed)

        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            test_cat.write_catalog(catName)
            with open(catName, 'r') as input_file:
                lines = input_file.readlines()
                self.assertGreater(len(lines), 1)

        cartoonDir = os.path.join(getPackageDir('sims_photUtils'), '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)

        i = 0

        # since all of the SEDs in the cartoon database are the same, just test on the first
        # if we ever include more SEDs, this can be something like
        # for ss in test_cata.sedMasterList:
        ss = test_cat.sedMasterList[0]
        ss.resampleSED(wavelen_match=bplist[0].wavelen)
        ss.flambdaTofnu()
        mags = -2.5 * np.log10(
            np.sum(phiArray * ss.fnu, axis=1) * waveLenStep) - ss.zp
        self.assertEqual(len(mags), len(test_cat.cartoonBandpassDict))
        self.assertGreater(len(mags), 0)
        for j in range(len(mags)):
            self.assertAlmostEqual(mags[j], test_cat.magnitudeMasterList[i][j],
                                   4)
Пример #4
0
    def testAlternateBandpassesStars(self):
        """
        This will test our ability to do photometry using non-LSST bandpasses.

        It will first calculate the magnitudes using the getters in cartoonPhotometryStars.

        It will then load the alternate bandpass files 'by hand' and re-calculate the magnitudes
        and make sure that the magnitude values agree.  This is guarding against the possibility
        that some default value did not change and the code actually ended up loading the
        LSST bandpasses.
        """

        obs_metadata_pointed = ObservationMetaData(mjd=2013.23,
                                                   boundType='circle',
                                                   pointingRA=200.0, pointingDec=-30.0,
                                                   boundLength=1.0)

        test_cat = cartoonStars(self.star, obs_metadata=obs_metadata_pointed)

        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            test_cat.write_catalog(catName)
            with open(catName, 'r') as input_file:
                lines = input_file.readlines()
                self.assertGreater(len(lines), 1)

        cartoonDir = os.path.join(getPackageDir('sims_photUtils'), '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)

        i = 0

        # since all of the SEDs in the cartoon database are the same, just test on the first
        # if we ever include more SEDs, this can be something like
        # for ss in test_cata.sedMasterList:
        ss = test_cat.sedMasterList[0]
        ss.resampleSED(wavelen_match = bplist[0].wavelen)
        ss.flambdaTofnu()
        mags = -2.5*np.log10(np.sum(phiArray*ss.fnu, axis=1)*waveLenStep) - ss.zp
        self.assertEqual(len(mags), len(test_cat.cartoonBandpassDict))
        self.assertGreater(len(mags), 0)
        for j in range(len(mags)):
            self.assertAlmostEqual(mags[j], test_cat.magnitudeMasterList[i][j], 4)
Пример #5
0
    def testStellarPhotometryIndices(self):
        """
        A test to make sure that stellar photometry still calculates the right values
        even when it is not calculating all of the magnitudes in the getter
        """

        baselineDtype = np.dtype([('id', int),
                                  ('raObserved', float), ('decObserved', float),
                                  ('magNorm', float),
                                  ('cartoon_u', float), ('cartoon_g', float),
                                  ('cartoon_r', float), ('cartoon_i', float),
                                  ('cartoon_z', float)])

        testDtype = np.dtype([('id', int),
                              ('raObserved', float), ('decObserved', float),
                              ('cartoon_i', float)])

        obs_metadata_pointed = ObservationMetaData(mjd=2013.23,
                                                   boundType='circle',
                                                   pointingRA=200.0, pointingDec=-30.0,
                                                   boundLength=1.0)

        baseline_cat = cartoonStars(self.star, 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)

        test_cat = cartoonStarsOnlyI(self.star, 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['cartoon_i'], t['cartoon_i'], 10)

        testDtype = np.dtype([('id', int),
                              ('raObserved', float), ('decObserved', float),
                              ('cartoon_i', float), ('cartoon_z', float)])

        test_cat = cartoonStarsIZ(self.star, 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['cartoon_i'], t['cartoon_i'], 10)
            self.assertAlmostEqual(b['cartoon_z'], t['cartoon_z'], 10)
    def testAlternateBandpassesStars(self):
        """
        This will test our ability to do photometry using non-LSST bandpasses.

        It will first calculate the magnitudes using the getters in cartoonPhotometryStars.

        It will then load the alternate bandpass files 'by hand' and re-calculate the magnitudes
        and make sure that the magnitude values agree.  This is guarding against the possibility
        that some default value did not change and the code actually ended up loading the
        LSST bandpasses.
        """

        obs_metadata_pointed=ObservationMetaData(mjd=2013.23,
                                                 boundType='circle',unrefractedRA=200.0,unrefractedDec=-30.0,
                                                 boundLength=1.0)

        test_cat=cartoonStars(self.star,obs_metadata=obs_metadata_pointed)
        test_cat.write_catalog("testStarsCartoon.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)

        i = 0

        #since all of the SEDs in the cartoon database are the same, just test on the first
        #if we ever include more SEDs, this can be something like
        #for ss in test_cata.sedMasterList:
        #
        ss=test_cat.sedMasterList[0]
        ss.resampleSED(wavelen_match = bplist[0].wavelen)
        ss.flambdaTofnu()
        mags = -2.5*numpy.log10(numpy.sum(phiArray*ss.fnu, axis=1)*waveLenStep) - ss.zp
        self.assertTrue(len(mags)==len(test_cat.bandpassDict))
        self.assertTrue(len(mags)>0)
        for j in range(len(mags)):
            self.assertAlmostEqual(mags[j],test_cat.magnitudeMasterList[i][j],10)
        i += 1

        os.unlink("testStarsCartoon.txt")
Пример #7
0
    def testStellarPhotometryIndices(self):
        """
        A test to make sure that stellar photometry still calculates the right values
        even when it is not calculating all of the magnitudes in the getter
        """

        baselineDtype = np.dtype([('id', int), ('raObserved', float),
                                  ('decObserved', float), ('magNorm', float),
                                  ('cartoon_u', float), ('cartoon_g', float),
                                  ('cartoon_r', float), ('cartoon_i', float),
                                  ('cartoon_z', float)])

        baselineCatName = os.path.join(
            getPackageDir('sims_catUtils'), 'tests', 'scratchSpace',
            'testPhotMix_testStellarIndices_stellarBaselineCatalog.txt')

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

        testDtype = np.dtype([('id', int), ('raObserved', float),
                              ('decObserved', float), ('cartoon_i', float)])

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

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

        obs_metadata_pointed = ObservationMetaData(mjd=2013.23,
                                                   boundType='circle',
                                                   pointingRA=200.0,
                                                   pointingDec=-30.0,
                                                   boundLength=1.0)

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

        test_cat = cartoonStarsOnlyI(self.star,
                                     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['cartoon_i'], t['cartoon_i'], 10)

        testDtype = np.dtype([('id', int), ('raObserved', float),
                              ('decObserved', float), ('cartoon_i', float),
                              ('cartoon_z', float)])

        test_cat = cartoonStarsIZ(self.star, 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['cartoon_i'], t['cartoon_i'], 10)
            self.assertAlmostEqual(b['cartoon_z'], t['cartoon_z'], 10)

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