Exemplo n.º 1
0
    def setUp(self):

        starFileName = os.path.join(lsst.utils.getPackageDir("sims_sed_library"), "starSED")
        starFileName = os.path.join(starFileName, "kurucz", "km20_5750.fits_g40_5790.gz")
        starName = os.path.join(lsst.utils.getPackageDir("sims_sed_library"), starFileName)
        self.starSED = Sed()
        self.starSED.readSED_flambda(starName)
        imsimband = Bandpass()
        imsimband.imsimBandpass()
        fNorm = self.starSED.calcFluxNorm(22.0, imsimband)
        self.starSED.multiplyFluxNorm(fNorm)

        hardwareDir = os.path.join(lsst.utils.getPackageDir("throughputs"), "baseline")
        componentList = ["detector.dat", "m1.dat", "m2.dat", "m3.dat", "lens1.dat", "lens2.dat", "lens3.dat"]
        self.skySed = Sed()
        self.skySed.readSED_flambda(os.path.join(hardwareDir, "darksky.dat"))

        totalNameList = ["total_u.dat", "total_g.dat", "total_r.dat", "total_i.dat", "total_z.dat", "total_y.dat"]

        self.bpList = []
        self.hardwareList = []
        for name in totalNameList:
            dummy = Bandpass()
            dummy.readThroughput(os.path.join(hardwareDir, name))
            self.bpList.append(dummy)

            dummy = Bandpass()
            hardwareNameList = [os.path.join(hardwareDir, name)]
            for component in componentList:
                hardwareNameList.append(os.path.join(hardwareDir, component))
            dummy.readThroughputList(hardwareNameList)
            self.hardwareList.append(dummy)

        self.filterNameList = ["u", "g", "r", "i", "z", "y"]
Exemplo n.º 2
0
    def testLoadBandpassesFromFiles(self):
        """
        Test that running the classmethod loadBandpassesFromFiles produces
        expected result
        """

        fileDir = os.path.join(getPackageDir('sims_photUtils'),
                               'tests', 'cartoonSedTestData')
        bandpassNames = ['g', 'z', 'i']
        bandpassRoot = 'test_bandpass_'
        componentList = ['toy_mirror.dat']
        atmo = os.path.join(fileDir, 'toy_atmo.dat')

        bandpassDict, hardwareDict = BandpassDict.loadBandpassesFromFiles(bandpassNames=bandpassNames,
                                                                          filedir=fileDir,
                                                                          bandpassRoot=bandpassRoot,
                                                                          componentList=componentList,
                                                                          atmoTransmission=atmo)

        controlBandpassList = []
        controlHardwareList = []

        for bpn in bandpassNames:
            componentList = [os.path.join(fileDir, bandpassRoot+bpn+'.dat'),
                             os.path.join(fileDir, 'toy_mirror.dat')]

            dummyBp = Bandpass()
            dummyBp.readThroughputList(componentList)
            controlHardwareList.append(dummyBp)

            componentList = [os.path.join(fileDir, bandpassRoot+bpn+'.dat'),
                             os.path.join(fileDir, 'toy_mirror.dat'),
                             os.path.join(fileDir, 'toy_atmo.dat')]

            dummyBp = Bandpass()
            dummyBp.readThroughputList(componentList)
            controlBandpassList.append(dummyBp)

        wMin = controlBandpassList[0].wavelen[0]
        wMax = controlBandpassList[0].wavelen[-1]
        wStep = controlBandpassList[0].wavelen[1]-controlBandpassList[0].wavelen[0]

        for bp, hh in zip(controlBandpassList, controlHardwareList):
            bp.resampleBandpass(wavelen_min=wMin, wavelen_max=wMax,
                                wavelen_step=wStep)
            hh.resampleBandpass(wavelen_min=wMin, wavelen_max=wMax,
                                wavelen_step=wStep)

        for test, control in zip(bandpassDict.values(), controlBandpassList):
            np.testing.assert_array_almost_equal(test.wavelen,
                                                 control.wavelen, 19)
            np.testing.assert_array_almost_equal(test.sb, control.sb, 19)

        for test, control in zip(hardwareDict.values(), controlHardwareList):
            np.testing.assert_array_almost_equal(test.wavelen,
                                                 control.wavelen, 19)
            np.testing.assert_array_almost_equal(test.sb, control.sb, 19)
    def setUpClass(cls):
        lsstDefaults=LSSTdefaults()
        cls.dbName = 'uncertaintyTestDB.db'
        if os.path.exists(cls.dbName):
            os.unlink(cls.dbName)

        default_obs_metadata = makePhoSimTestDB(filename=cls.dbName, size=10, radius = 5.0)
        bandpass = ['u', 'g', 'r', 'i', 'z', 'y']
        m5 = lsstDefaults._m5.values()

        cls.obs_metadata = ObservationMetaData(
                                              pointingRA = default_obs_metadata.pointingRA,
                                              pointingDec = default_obs_metadata.pointingDec,
                                              rotSkyPos = default_obs_metadata.rotSkyPos,
                                              bandpassName = bandpass,
                                              m5 = m5
                                              )

        cls.obs_metadata.setBandpassM5andSeeing(bandpassName=bandpass, m5=m5)
        cls.driver = 'sqlite'
        cls.host = ''

        cls.skySeds = []
        cls.hardwareBandpasses = []
        cls.totalBandpasses = []
        cls.bandpasses = ['u', 'g', 'r', 'i', 'z', 'y']

        components = ['detector.dat', 'm1.dat', 'm2.dat', 'm3.dat',
                      'lens1.dat', 'lens2.dat', 'lens3.dat']

        for b in cls.bandpasses:
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughput(os.path.join(lsst.utils.getPackageDir('throughputs'),
                                                      'baseline', 'total_%s.dat' % b))
            cls.totalBandpasses.append(bandpassDummy)

        for b in cls.bandpasses:
            finalComponents = []
            for c in components:
                finalComponents.append(os.path.join(lsst.utils.getPackageDir('throughputs'), 'baseline', c))
            finalComponents.append(os.path.join(lsst.utils.getPackageDir('throughputs'), 'baseline', 'filter_%s.dat' %b))
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughputList(finalComponents)
            cls.hardwareBandpasses.append(bandpassDummy)

        for i in range(len(cls.bandpasses)):
            sedDummy = Sed()
            sedDummy.readSED_flambda(os.path.join(lsst.utils.getPackageDir('throughputs'), 'baseline', 'darksky.dat'))
            normalizedSedDummy = setM5(cls.obs_metadata.m5[cls.bandpasses[i]], sedDummy,
                                       cls.totalBandpasses[i], cls.hardwareBandpasses[i],
                                       FWHMeff=lsstDefaults.FWHMeff(cls.bandpasses[i]),
                                       photParams=PhotometricParameters())

            cls.skySeds.append(normalizedSedDummy)
Exemplo n.º 4
0
    def setUp(self):

        starName = os.path.join(lsst.utils.getPackageDir('sims_photUtils'),
                                'tests/cartoonSedTestData/starSed/')
        starName = os.path.join(starName, 'kurucz',
                                'km20_5750.fits_g40_5790.gz')
        self.starSED = Sed()
        self.starSED.readSED_flambda(starName)
        imsimband = Bandpass()
        imsimband.imsimBandpass()
        fNorm = self.starSED.calcFluxNorm(22.0, imsimband)
        self.starSED.multiplyFluxNorm(fNorm)

        hardwareDir = os.path.join(lsst.utils.getPackageDir('throughputs'),
                                   'baseline')
        componentList = [
            'detector.dat', 'm1.dat', 'm2.dat', 'm3.dat', 'lens1.dat',
            'lens2.dat', 'lens3.dat'
        ]
        self.skySed = Sed()
        self.skySed.readSED_flambda(os.path.join(hardwareDir, 'darksky.dat'))

        totalNameList = [
            'total_u.dat', 'total_g.dat', 'total_r.dat', 'total_i.dat',
            'total_z.dat', 'total_y.dat'
        ]

        self.bpList = []
        self.hardwareList = []
        for name in totalNameList:
            dummy = Bandpass()
            dummy.readThroughput(os.path.join(hardwareDir, name))
            self.bpList.append(dummy)

            dummy = Bandpass()
            hardwareNameList = [os.path.join(hardwareDir, name)]
            for component in componentList:
                hardwareNameList.append(os.path.join(hardwareDir, component))
            dummy.readThroughputList(hardwareNameList)
            self.hardwareList.append(dummy)

        self.filterNameList = ['u', 'g', 'r', 'i', 'z', 'y']
Exemplo n.º 5
0
    def setUp(self):

        starName = os.path.join(lsst.utils.getPackageDir('sims_photUtils'),
                                'tests/cartoonSedTestData/starSed/')
        starName = os.path.join(starName, 'kurucz', 'km20_5750.fits_g40_5790.gz')
        self.starSED = Sed()
        self.starSED.readSED_flambda(starName)
        imsimband = Bandpass()
        imsimband.imsimBandpass()
        fNorm = self.starSED.calcFluxNorm(22.0, imsimband)
        self.starSED.multiplyFluxNorm(fNorm)

        hardwareDir = os.path.join(lsst.utils.getPackageDir('throughputs'), 'baseline')
        componentList = ['detector.dat', 'm1.dat', 'm2.dat', 'm3.dat',
                         'lens1.dat', 'lens2.dat', 'lens3.dat']
        self.skySed = Sed()
        self.skySed.readSED_flambda(os.path.join(hardwareDir, 'darksky.dat'))

        totalNameList = ['total_u.dat', 'total_g.dat', 'total_r.dat', 'total_i.dat',
                         'total_z.dat', 'total_y.dat']

        self.bpList = []
        self.hardwareList = []
        for name in totalNameList:
            dummy = Bandpass()
            dummy.readThroughput(os.path.join(hardwareDir, name))
            self.bpList.append(dummy)

            dummy = Bandpass()
            hardwareNameList = [os.path.join(hardwareDir, name)]
            for component in componentList:
                hardwareNameList.append(os.path.join(hardwareDir, component))
            dummy.readThroughputList(hardwareNameList)
            self.hardwareList.append(dummy)

        self.filterNameList = ['u', 'g', 'r', 'i', 'z', 'y']
Exemplo n.º 6
0
def _readCoatings(componentDir):
    """
    Read and combine the coatings in all files from a _Coatings subdirectory in componentDir.
    Return a bandpass object with all coating throughputs combined.
    """
    coatingDir = glob(os.path.join(componentDir, '*_Coatings'))
    if len(coatingDir) > 1:
        errmsg = 'Expect a single *_Coatings subdirectory for component %s.'%(componentDir)
        errmsg += ' Found %s.' %(coatingDir)
        raise ValueError(errmsg)
    coatingDir = coatingDir[0]
    if not os.path.isdir(coatingDir):
        errmsg = 'Expect %s to be a subdirectory containing coating files for component %s.' \
          %(coatingDir, componentDir)
        raise ValueError(errmsg)
    coatingfiles = glob(os.path.join(coatingDir, '*.dat'))
    if len(coatingfiles) == 0:
        errmsg = 'Expect to find at least one coating file in %s for component %s.'\
          %(coatingDir, componentDir)
        errmsg += ' Found no coating files.'
        raise ValueError(errmsg)
    coatings = Bandpass()
    coatings.readThroughputList(coatingfiles)
    return coatings
Exemplo n.º 7
0
def _readLosses(componentDir):
    """
    Read and combine the losses in all files from a _Losses subdirectory in componentDir.
    Return a bandpass object with all losses combined.
    """
    lossDir = glob(os.path.join(componentDir, '*_Losses'))
    if len(lossDir) > 1:
        errmsg = 'Expect a single *_Losses subdirectory for component %s.'%(componentDir)
        errmsg += ' Found %s.' %(lossDir)
        raise ValueError(errmsg)
    lossDir = lossDir[0]
    if not os.path.isdir(lossDir):
        errmsg = 'Expect %s to be a subdirectory containing loss files for component %s.' \
          %(lossDir, componentDir)
        raise ValueError(errmsg)
    lossfiles = glob(os.path.join(lossDir, '*.dat'))
    if len(lossfiles) == 0:
        errmsg = 'Expect to find at least one loss file in %s for component %s.'\
          %(lossDir, componentDir)
        errmsg += ' Found no loss files.'
        raise ValueError(errmsg)
    loss = Bandpass()
    loss.readThroughputList(lossfiles)
    return loss
def _readCoatings(componentDir):
    """
    Read and combine the coatings in all files from a _Coatings subdirectory in componentDir.
    Return a bandpass object with all coating throughputs combined.
    """
    coatingDir = glob(os.path.join(componentDir, '*_Coatings'))
    if len(coatingDir) > 1:
        errmsg = 'Expect a single *_Coatings subdirectory for component %s.'%(componentDir)
        errmsg += ' Found %s.' %(coatingDir)
        raise ValueError(errmsg)
    coatingDir = coatingDir[0]
    if not os.path.isdir(coatingDir):
        errmsg = 'Expect %s to be a subdirectory containing coating files for component %s.' \
          %(coatingDir, componentDir)
        raise ValueError(errmsg)
    coatingfiles = glob(os.path.join(coatingDir, '*.dat'))
    if len(coatingfiles) == 0:
        errmsg = 'Expect to find at least one coating file in %s for component %s.'\
          %(coatingDir, componentDir)
        errmsg += ' Found no coating files.'
        raise ValueError(errmsg)
    coatings = Bandpass()
    coatings.readThroughputList(coatingfiles)
    return coatings
def _readLosses(componentDir):
    """
    Read and combine the losses in all files from a _Losses subdirectory in componentDir.
    Return a bandpass object with all losses combined.
    """
    lossDir = glob(os.path.join(componentDir, '*_Losses'))
    if len(lossDir) > 1:
        errmsg = 'Expect a single *_Losses subdirectory for component %s.'%(componentDir)
        errmsg += ' Found %s.' %(lossDir)
        raise ValueError(errmsg)
    lossDir = lossDir[0]
    if not os.path.isdir(lossDir):
        errmsg = 'Expect %s to be a subdirectory containing loss files for component %s.' \
          %(lossDir, componentDir)
        raise ValueError(errmsg)
    lossfiles = glob(os.path.join(lossDir, '*.dat'))
    if len(lossfiles) == 0:
        errmsg = 'Expect to find at least one loss file in %s for component %s.'\
          %(lossDir, componentDir)
        errmsg += ' Found no loss files.'
        raise ValueError(errmsg)
    loss = Bandpass()
    loss.readThroughputList(lossfiles)
    return loss
Exemplo n.º 10
0
    if det_file.lower() != 'none':
        print('adding detector')
        componentList.append(det_file)
    if atmos_file.lower() != 'none':
        print('adding astmosphere')
        componentList.append(atmos_file)

    np_component_list = []
    for file_name in componentList:
        print('multiplying %s' % file_name)
        data = np.genfromtxt(file_name, dtype=throughput_dtype)
        np_component_list.append(data)

    if _LSST_STACK_INSTALLED:
        optics_bp = Bandpass()
        optics_bp.readThroughputList(componentList=componentList)

    for i_filter, bp_name in enumerate('ugrizy'):

        # read in the centroid files
        phosim_data = np.genfromtxt(os.path.join(
            centroid_dir,
            'centroid_lsst_e_230_f%d_R22_S11_E000.txt' % i_filter),
                                    dtype=phosim_ct_dtype,
                                    skip_header=1)

        phosim_truth = np.median(phosim_data['phot'])

        # read in the filter throughput and multiply the existing throughputs
        # by that curve
        np_filter = np.genfromtxt(os.path.join(bp_dir,
Exemplo n.º 11
0
    def loadBandpassesFromFiles(
        cls,
        bandpassNames=['u', 'g', 'r', 'i', 'z', 'y'],
        filedir=os.path.join(getPackageDir('throughputs'), 'baseline'),
        bandpassRoot='filter_',
        componentList=[
            'detector.dat', 'm1.dat', 'm2.dat', 'm3.dat', 'lens1.dat',
            'lens2.dat', 'lens3.dat'
        ],
        atmoTransmission=os.path.join(getPackageDir('throughputs'), 'baseline',
                                      'atmos.dat')):
        """
        Load bandpass information from files into BandpassDicts.
        This method will separate the bandpasses into contributions due to instrumentations
        and contributions due to the atmosphere.

        @param [in] bandpassNames is a list of strings labeling the bandpasses
        (e.g. ['u', 'g', 'r', 'i', 'z', 'y'])

        @param [in] filedir is a string indicating the name of the directory containing the
        bandpass files

        @param [in] bandpassRoot is the root of the names of the files associated with the
        bandpasses.  This method assumes that bandpasses are stored in
        filedir/bandpassRoot_bandpassNames[i].dat

        @param [in] componentList lists the files associated with bandpasses representing
        hardware components shared by all filters
        (defaults to ['detector.dat', 'm1.dat', 'm2.dat', 'm3.dat', 'lens1.dat',
                      'lense2.dat', 'lenst3.dat']
        for LSST).  These files are also expected to be stored in filedir

        @param [in] atmoTransmission is the absolute path to the file representing the
        transmissivity of the atmosphere (defaults to baseline/atmos.dat in the LSST
        'throughputs' package).

        @param [out] bandpassDict is a BandpassDict containing the total
        throughput (instrumentation + atmosphere)

        @param [out] hardwareBandpassDict is a BandpassDict containing
        the throughput due to instrumentation only
        """

        commonComponents = []
        for cc in componentList:
            commonComponents.append(os.path.join(filedir, cc))

        bandpassList = []
        hardwareBandpassList = []

        for w in bandpassNames:
            components = commonComponents + [
                os.path.join(filedir, "%s.dat" % (bandpassRoot + w))
            ]
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughputList(components)
            hardwareBandpassList.append(bandpassDummy)

            components += [atmoTransmission]
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughputList(components)
            bandpassList.append(bandpassDummy)

        bandpassDict = cls(bandpassList, bandpassNames)
        hardwareBandpassDict = cls(hardwareBandpassList, bandpassNames)

        return bandpassDict, hardwareBandpassDict
Exemplo n.º 12
0
    def loadBandpassesFromFiles(cls,
                                bandpassNames=['u', 'g', 'r', 'i', 'z', 'y'],
                                filedir = os.path.join(getPackageDir('throughputs'), 'baseline'),
                                bandpassRoot = 'filter_',
                                componentList = ['detector.dat', 'm1.dat', 'm2.dat', 'm3.dat',
                                                 'lens1.dat', 'lens2.dat', 'lens3.dat'],
                                atmoTransmission=os.path.join(getPackageDir('throughputs'),
                                                              'baseline','atmos.dat')):
        """
        Load bandpass information from files into BandpassDicts.
        This method will separate the bandpasses into contributions due to instrumentations
        and contributions due to the atmosphere.

        @param [in] bandpassNames is a list of strings labeling the bandpasses
        (e.g. ['u', 'g', 'r', 'i', 'z', 'y'])

        @param [in] filedir is a string indicating the name of the directory containing the
        bandpass files

        @param [in] bandpassRoot is the root of the names of the files associated with the
        bandpasses.  This method assumes that bandpasses are stored in
        filedir/bandpassRoot_bandpassNames[i].dat

        @param [in] componentList lists the files associated with bandpasses representing
        hardware components shared by all filters
        (defaults to ['detector.dat', 'm1.dat', 'm2.dat', 'm3.dat', 'lens1.dat',
                      'lense2.dat', 'lenst3.dat']
        for LSST).  These files are also expected to be stored in filedir

        @param [in] atmoTransmission is the absolute path to the file representing the
        transmissivity of the atmosphere (defaults to baseline/atmos.dat in the LSST
        'throughputs' package).

        @param [out] bandpassDict is a BandpassDict containing the total
        throughput (instrumentation + atmosphere)

        @param [out] hardwareBandpassDict is a BandpassDict containing
        the throughput due to instrumentation only
        """

        commonComponents = []
        for cc in componentList:
            commonComponents.append(os.path.join(filedir,cc))

        bandpassList = []
        hardwareBandpassList = []

        for w in bandpassNames:
            components = commonComponents + [os.path.join(filedir,"%s.dat" % (bandpassRoot +w))]
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughputList(components)
            hardwareBandpassList.append(bandpassDummy)

            components += [atmoTransmission]
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughputList(components)
            bandpassList.append(bandpassDummy)


        bandpassDict = cls(bandpassList, bandpassNames)
        hardwareBandpassDict = cls(hardwareBandpassList, bandpassNames)

        return bandpassDict, hardwareBandpassDict
Exemplo n.º 13
0
    def setUpClass(cls):
        lsstDefaults = LSSTdefaults()
        cls.dbName = 'uncertaintyTestDB.db'
        if os.path.exists(cls.dbName):
            os.unlink(cls.dbName)

        default_obs_metadata = makePhoSimTestDB(filename=cls.dbName,
                                                size=10,
                                                radius=5.0)
        bandpass = ['u', 'g', 'r', 'i', 'z', 'y']
        m5 = list(lsstDefaults._m5.values())

        cls.obs_metadata = ObservationMetaData(
            pointingRA=default_obs_metadata.pointingRA,
            pointingDec=default_obs_metadata.pointingDec,
            rotSkyPos=default_obs_metadata.rotSkyPos,
            bandpassName=bandpass,
            m5=m5)

        cls.obs_metadata.setBandpassM5andSeeing(bandpassName=bandpass, m5=m5)
        cls.driver = 'sqlite'
        cls.host = ''

        cls.skySeds = []
        cls.hardwareBandpasses = []
        cls.totalBandpasses = []
        cls.bandpasses = ['u', 'g', 'r', 'i', 'z', 'y']

        components = [
            'detector.dat', 'm1.dat', 'm2.dat', 'm3.dat', 'lens1.dat',
            'lens2.dat', 'lens3.dat'
        ]

        for b in cls.bandpasses:
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughput(
                os.path.join(getPackageDir('throughputs'), 'baseline',
                             'total_%s.dat' % b))
            cls.totalBandpasses.append(bandpassDummy)

        for b in cls.bandpasses:
            finalComponents = []
            for c in components:
                finalComponents.append(
                    os.path.join(getPackageDir('throughputs'), 'baseline', c))
            finalComponents.append(
                os.path.join(getPackageDir('throughputs'), 'baseline',
                             'filter_%s.dat' % b))
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughputList(finalComponents)
            cls.hardwareBandpasses.append(bandpassDummy)

        for i in range(len(cls.bandpasses)):
            sedDummy = Sed()
            sedDummy.readSED_flambda(
                os.path.join(getPackageDir('throughputs'), 'baseline',
                             'darksky.dat'))
            normalizedSedDummy = setM5(cls.obs_metadata.m5[cls.bandpasses[i]],
                                       sedDummy,
                                       cls.totalBandpasses[i],
                                       cls.hardwareBandpasses[i],
                                       FWHMeff=lsstDefaults.FWHMeff(
                                           cls.bandpasses[i]),
                                       photParams=PhotometricParameters())

            cls.skySeds.append(normalizedSedDummy)