Beispiel #1
0
    def testFileDict(self):
        """
        Test a user-defined SpecMap with a fileDict
        """
        fileDictTestMap = SpecMap(fileDict={'abcd.txt': 'file_dict_test_dir/abcd.txt.gz'})

        self.assertEqual(fileDictTestMap['abcd.txt'], 'file_dict_test_dir/abcd.txt.gz')
        self.verifyFile('lte_11111.txt', 'starSED/mlt',
                        testSpecMap=fileDictTestMap)
        self.verifyFile('Const.79E06.002Z.spec', 'galaxySED',
                        testSpecMap=fileDictTestMap)
        self.verifyFile('Inst.79E06.02Z.spec', 'galaxySED',
                        testSpecMap=fileDictTestMap)
        self.verifyFile('Exp.40E08.02Z.spec', 'galaxySED',
                        testSpecMap=fileDictTestMap)
        self.verifyFile('Burst.40E08.002Z.spec', 'galaxySED',
                        testSpecMap=fileDictTestMap)
        self.verifyFile('km30_5000.fits_g10_5040',
                        'starSED/kurucz', testSpecMap=fileDictTestMap)
        self.verifyFile('kp10_9000.fits_g40_9100',
                        'starSED/kurucz', testSpecMap=fileDictTestMap)
        self.verifyFile('burrows+2006c91.21_T1400_g5.5_cf_0.3X',
                        'starSED/old_mlt', testSpecMap=fileDictTestMap)
        self.verifyFile('L2_0Full.dat', 'starSED/old_mlt',
                        testSpecMap=fileDictTestMap)
        self.verifyFile('m5.1Full.dat', 'starSED/old_mlt',
                        testSpecMap=fileDictTestMap)
Beispiel #2
0
 def testDirDict(self):
     """
     Test a user-defined SpecMap with a dirDict
     """
     dirDictTestMap = SpecMap(dirDict={'(^lte)': 'silly_sub_dir'})
     self.verifyFile('lte_11111.txt', 'silly_sub_dir',
                     testSpecMap=dirDictTestMap)
     self.verifyFile('Const.79E06.002Z.spec', 'galaxySED',
                     testSpecMap=dirDictTestMap)
     self.verifyFile('Inst.79E06.02Z.spec', 'galaxySED',
                     testSpecMap=dirDictTestMap)
     self.verifyFile('Exp.40E08.02Z.spec', 'galaxySED',
                     testSpecMap=dirDictTestMap)
     self.verifyFile('Burst.40E08.002Z.spec', 'galaxySED',
                     testSpecMap=dirDictTestMap)
     self.verifyFile('km30_5000.fits_g10_5040',
                     'starSED/kurucz', testSpecMap=dirDictTestMap)
     self.verifyFile('kp10_9000.fits_g40_9100',
                     'starSED/kurucz', testSpecMap=dirDictTestMap)
     self.verifyFile('burrows+2006c91.21_T1400_g5.5_cf_0.3X',
                     'starSED/old_mlt', testSpecMap=dirDictTestMap)
     self.verifyFile('L2_0Full.dat', 'starSED/old_mlt',
                     testSpecMap=dirDictTestMap)
     self.verifyFile('m5.1Full.dat', 'starSED/old_mlt',
                     testSpecMap=dirDictTestMap)
    def setUpClass(cls):

        specMap = SpecMap()
        specFileStart = 'Exp'
        for key, val in sorted(specMap.subdir_map.iteritems()):
            if re.match(key, specFileStart):
                galSpecDir = str(val)
        cls.galDir = str(lsst.utils.getPackageDir('sims_sed_library') + '/' + galSpecDir + '/')
        cls.filterList = ('u', 'g', 'r', 'i', 'z')
Beispiel #4
0
    def test_contains(self):
        """
        Test that 'k in SpecMap' works as it should
        """

        testMap = SpecMap(fileDict={'abcd.txt': 'file_dir/abcd.txt.gz'},
                          dirDict={'(^burrows)': 'dir_dir'})

        self.assertFalse('banana' in testMap)
        self.assertTrue('abcd.txt' in testMap)
        self.assertTrue('burrows_123.txt' in testMap)
Beispiel #5
0
    def __init__(self, sEDDir=None, kuruczDir=None, mltDir=None, wdDir=None):
        """
        @param [in] sEDDir is a place to specify a different path to a directory that follows the same
        directory structure as SIMS_SED_LIBRARY. For instance, a different version of the LSST
        SIMS_SED_LIBRARY.

        @param [in] kuruczDir is a place to specify a different path to kurucz SED files than the
        files in the LSST sims_sed_library. If set to None it will default to the LSST library.
        Will probably be most useful for those who want to use loadGalfast without downloading the
        entire LSST sims_sed_library which contains much more than just the star SEDs.

        @param [in] mltDir is the same as kuruczPath except that it specifies a directory for the
        mlt SEDs

        @param [in] wdDir is the same as the previous two except that it specifies a path to an
        alternate white dwarf SED directory.
        """

        if sEDDir is None:
            self.sEDDir = lsst.utils.getPackageDir('sims_sed_library')
        else:
            self.sEDDir = sEDDir
        #Use SpecMap to pull the directory locations
        specMap = SpecMap()
        specMapDict = {}
        specFileStart = ['kp', 'burrows', 'bergeron'
                         ]  #The beginning of filenames of different SED types
        specFileTypes = ['kurucz', 'mlt', 'wd']
        for specStart, specKey in zip(specFileStart, specFileTypes):
            for key, val in sorted(specMap.subdir_map.iteritems()):
                if re.match(key, specStart):
                    specMapDict[specKey] = str(val)

        if kuruczDir is None:
            self.kuruczDir = str(self.sEDDir + '/' + specMapDict['kurucz'] +
                                 '/')
        else:
            self.kuruczDir = kuruczDir

        if mltDir is None:
            self.mltDir = str(self.sEDDir + '/' + specMapDict['mlt'] + '/')
        else:
            self.mltDir = mltDir

        if wdDir is None:
            self.wdDir = str(self.sEDDir + '/' + specMapDict['wd'] + '/')
        else:
            self.wdDir = wdDir
Beispiel #6
0
 def __init__(self, galDir=None):
     """
     @param [in] galDir is the directory where the galaxy SEDs are stored
     """
     if galDir is None:
         # Use SpecMap to pull in directory's location in LSST Stack
         specMap = SpecMap()
         specFileStart = 'Exp'  #Start of sample BC03 name in sims_sed_library
         for key, val in sorted(specMap.subdir_map.items()):
             if re.match(key, specFileStart):
                 galSpecDir = str(val)
         self.galDir = str(
             lsst.utils.getPackageDir('sims_sed_library') + '/' +
             galSpecDir)
     else:
         self.galDir = galDir
    def setUpClass(cls):

        #Left this in after removing loading SEDs so that we can make sure that if the structure of
        #sims_sed_library changes in a way that affects testMatchSEDs we can detect it.
        specMap = SpecMap()
        cls._specMapDict = {}
        specFileStart = ['kp', 'burrows', 'bergeron'] #The beginning of filenames of different SED types
        specFileTypes = ['kurucz', 'mlt','wd']
        for specStart, specKey in zip(specFileStart, specFileTypes):
            for key, val in sorted(specMap.subdir_map.iteritems()):
                if re.match(key, specStart):
                    cls._specMapDict[specKey] = str(val)

        cls.kmTestName = 'km99_9999.fits_g99_9999'
        cls.mTestName = 'm99.99Full.dat'

        #Set up Test Spectra Directory
        cls.testSpecDir = 'testMatchingSpectra'
        cls.testKDir = str(cls.testSpecDir + '/starSED/kurucz/')
        cls.testMLTDir = str(cls.testSpecDir + '/starSED/mlt/')
        cls.testWDDir = str(cls.testSpecDir + '/starSED/wDs/')

        if os.path.exists(cls.testSpecDir):
            shutil.rmtree(cls.testSpecDir)

        os.makedirs(cls.testKDir)
        os.mkdir(cls.testMLTDir)
        os.mkdir(cls.testWDDir)
        cls.kDir = lsst.utils.getPackageDir('sims_sed_library') + '/' + cls._specMapDict['kurucz'] + '/'
        cls.mltDir = lsst.utils.getPackageDir('sims_sed_library') + '/' + cls._specMapDict['mlt'] + '/'
        cls.wdDir = lsst.utils.getPackageDir('sims_sed_library') + '/' + cls._specMapDict['wd'] + '/'
        kList = os.listdir(cls.kDir)[0:3]
        #Use particular indices to get different types of seds within mlt and wds
        for kFile, mltFile, wdFile in zip(kList,
                                          np.array(os.listdir(cls.mltDir))[np.arange(-3,0)],
                                          np.array(os.listdir(cls.wdDir))[np.arange(-1,2)]):
            shutil.copyfile(str(cls.kDir + kFile), str(cls.testKDir + kFile))
            shutil.copyfile(str(cls.mltDir + mltFile), str(cls.testMLTDir + mltFile))
            shutil.copyfile(str(cls.wdDir + wdFile), str(cls.testWDDir + wdFile))
        #Load in extra kurucz to test Logz Readout
        if 'km01_7000.fits_g40_7140.gz' not in kList:
            shutil.copyfile(str(cls.kDir + 'km01_7000.fits_g40_7140.gz'),
                            str(cls.testKDir + 'km01_7000.fits_g40_7140.gz'))
        if 'kp01_7000.fits_g40_7240.gz' not in kList:
            shutil.copyfile(str(cls.kDir + 'kp01_7000.fits_g40_7240.gz'),
                            str(cls.testKDir + 'kp01_7000.fits_g40_7240.gz'))
Beispiel #8
0
    def setUpClass(cls):

        #Left this in after removing loading SEDs so that we can make sure that if the structure of
        #sims_sed_library changes in a way that affects testReadGalfast we can detect it.
        specMap = SpecMap()
        cls._specMapDict = {}
        specFileStart = ['kp', 'burrows', 'bergeron'
                         ]  #The beginning of filenames of different SED types
        specFileTypes = ['kurucz', 'mlt', 'wd']
        for specStart, specKey in zip(specFileStart, specFileTypes):
            for key, val in sorted(specMap.subdir_map.iteritems()):
                if re.match(key, specStart):
                    cls._specMapDict[specKey] = str(val)

        #Set up Test Spectra Directory
        cls.testSpecDir = 'testReadGalfastSpectra'
        cls.testKDir = str(cls.testSpecDir + '/starSED/kurucz/')
        cls.testMLTDir = str(cls.testSpecDir + '/starSED/mlt/')
        cls.testWDDir = str(cls.testSpecDir + '/starSED/wDs/')

        if os.path.exists(cls.testSpecDir):
            shutil.rmtree(cls.testSpecDir)

        os.makedirs(cls.testKDir)
        os.mkdir(cls.testMLTDir)
        os.mkdir(cls.testWDDir)
        cls.kDir = lsst.utils.getPackageDir(
            'sims_sed_library') + '/' + cls._specMapDict['kurucz'] + '/'
        cls.mltDir = lsst.utils.getPackageDir(
            'sims_sed_library') + '/' + cls._specMapDict['mlt'] + '/'
        cls.wdDir = lsst.utils.getPackageDir(
            'sims_sed_library') + '/' + cls._specMapDict['wd'] + '/'
        #Use particular indices to get different types of seds within mlt and wds
        for kFile, mltFile, wdFile in zip(
                os.listdir(cls.kDir)[0:20],
                np.array(os.listdir(cls.mltDir))[np.arange(-10, 11)],
                np.array(os.listdir(cls.wdDir))[np.arange(-10, 11)]):
            shutil.copyfile(str(cls.kDir + kFile), str(cls.testKDir + kFile))
            shutil.copyfile(str(cls.mltDir + mltFile),
                            str(cls.testMLTDir + mltFile))
            shutil.copyfile(str(cls.wdDir + wdFile),
                            str(cls.testWDDir + wdFile))
    def setUpClass(cls):

        specMap = SpecMap()
        specFileStart = 'Exp'
        for key, val in sorted(specMap.subdir_map.iteritems()):
            if re.match(key, specFileStart):
                galSpecDir = str(val)
        cls.galDir = str(lsst.utils.getPackageDir('sims_sed_library') + '/' + galSpecDir + '/')

        #Set up Test Spectra Directory
        cls.testSpecDir = 'testGalaxySEDSpectrum/'

        if os.path.exists(cls.testSpecDir):
            shutil.rmtree(cls.testSpecDir)

        os.mkdir(cls.testSpecDir)

        galList = os.listdir(cls.galDir)[0:20]

        for galFile in galList:
            shutil.copy(str(cls.galDir + galFile), str(cls.testSpecDir + galFile))
from lsst.sims.utils import SpecMap, defaultSpecMap
from lsst.sims.catalogs.definitions import InstanceCatalog
from lsst.sims.catalogs.decorators import compound, cached
from lsst.sims.utils import arcsecFromRadians, _observedFromICRS, altAzPaFromRaDec
from lsst.sims.catUtils.mixins import (EBVmixin, PhoSimAstrometryStars,
                                       PhoSimAstrometryGalaxies,
                                       PhoSimAstrometrySSM,
                                       FrozenSNCat)

__all__ = ["write_phoSim_header", "PhosimInputBase",
           "PhoSimCatalogPoint", "PhoSimCatalogZPoint", "PhoSimCatalogSN",
           "PhoSimCatalogSersic2D", "PhoSimCatalogSSM", "PhoSimSpecMap",
           "DefaultPhoSimHeaderMap", 'DefaultPhoSimInstanceCatalogCols']


PhoSimSpecMap = SpecMap(fileDict=defaultSpecMap.fileDict,
                        dirDict={'(^lte)': 'starSED/phoSimMLT'})


# This is a dict of transformations mapping from data in OpSim to header
# values expected by PhoSim.  The dict is keyed on the names of PhoSim
# parameters.  The values of the dict are either straight values, in which
# case those values are written to the PhoSim InstanceCatalog header, or tuples
# containing the name of the OpSim column which should be use to calculate
# the PhoSim parameter and any transformation needed to go from OpSim
# units to PhoSim units.
#
# PhoSim header parameters are documented here
# https://bitbucket.org/phosim/phosim_release/wiki/Instance%20Catalog
#
# OpSim columns are documented here
# https://www.lsst.org/scientists/simulations/opsim/summary-table-column-descriptions-v335