Example #1
0
    def _loadSedList(self, wavelen_match):
        """
        Wraps the PhotometryStars._loadSedList method.

        If current chunk of objects is not represetned in the global
        _sed_cache, this will call the base method defined in
        PhotometryStars.

        Otherwise, it will read self._sedList from the cache.
        That way, the photometry getters defined in PhotometryStars will
        not read in SEDs that have already been cached.
        """

        global _sed_cache

        object_names = self.column_by_name("uniqueId")

        if len(object_names) > 0:
            cache_name = "stellar_%s_%s" % (object_names[0], object_names[-1])
        else:
            cache_name = None

        if cache_name not in _sed_cache:

            PhotometryStars._loadSedList(self, wavelen_match)

            if cache_name is not None:
                _sed_cache[cache_name] = copy.copy(self._sedList)
        else:
            self._sedList = copy.copy(_sed_cache[cache_name])
    def testStandAloneStellarPhotometry(self):
        """
        Test that it is possible to run PhotometryStars.calculate_magnitudes
        outside of the context of an InstanceCatalog
        """
        objectID = ['1','2','3']
        sedNames = ['km20_5750.fits_g40_5790','m2.0Full.dat',
                     'bergeron_6500_85.dat_6700']
        magNorm = [28.5, 23.0, 21.0]

        dummyId = ['1', '2']
        dummySed = ['km20_5750.fits_g40_5790','m2.0Full.dat']
        dummyMagNorm = [28.5, 23.0]
        bandpassNames = ['u','g','r','i','z','y']

        phot = PhotometryStars()
        phot.loadTotalBandpassesFromFiles(bandpassNames)

        self.assertRaises(RuntimeError, phot.calculate_magnitudes,
                          objectID=dummyId, sedNames=sedNames, magNorm=magNorm)
        self.assertRaises(RuntimeError, phot.calculate_magnitudes,
                          objectID=objectID, sedNames=dummySed, magNorm=magNorm)
        self.assertRaises(RuntimeError, phot.calculate_magnitudes,
                          objectID=objectID, sedNames=sedNames, magNorm=dummyMagNorm)

        magnitudes = phot.calculate_magnitudes(objectID=objectID, sedNames=sedNames,
                                               magNorm=magNorm)
        for n in objectID:
            self.assertTrue(len(magnitudes[n])==len(bandpassNames)) #to make sure we calculated all the magnitudes
    def _loadSedList(self, wavelen_match):
        """
        Wraps the PhotometryStars._loadSedList method.

        If current chunk of objects is not represetned in the global
        _sed_cache, this will call the base method defined in
        PhotometryStars.

        Otherwise, it will read self._sedList from the cache.
        That way, the photometry getters defined in PhotometryStars will
        not read in SEDs that have already been cached.
        """

        global _sed_cache

        object_names = self.column_by_name("uniqueId")

        if len(object_names) > 0:
            cache_name = "stellar_%s_%s" % (object_names[0], object_names[-1])
        else:
            cache_name = None

        if cache_name not in _sed_cache:

            PhotometryStars._loadSedList(self, wavelen_match)

            if cache_name is not None:
                _sed_cache[cache_name] = copy.copy(self._sedList)
        else:
            self._sedList = copy.copy(_sed_cache[cache_name])
 def testPhotometricIndicesRaw(self):
     """
     Use manMagCalc_list with specified indices on an Sed.  Make sure
     that the appropriate magnitudes are or are not Nan
     """
     starName = os.path.join(lsst.utils.getPackageDir('sims_sed_library'),defaultSpecMap['km20_5750.fits_g40_5790'])
     starPhot = PhotometryStars()
     starPhot.loadTotalBandpassesFromFiles()
     testSed = Sed()
     testSed.readSED_flambda(starName)
     indices = [1,3]
     mags = starPhot.manyMagCalc_list(testSed, indices=indices)
     self.assertTrue(numpy.isnan(mags[0]))
     self.assertFalse(numpy.isnan(mags[1]))
     self.assertTrue(numpy.isnan(mags[2]))
     self.assertFalse(numpy.isnan(mags[3]))
     self.assertTrue(numpy.isnan(mags[4]))
     self.assertTrue(numpy.isnan(mags[5]))
     self.assertTrue(len(mags)==6)