本文整理汇总了Python中lsst.sims.photUtils.Sed.setupCCMab方法的典型用法代码示例。如果您正苦于以下问题:Python Sed.setupCCMab方法的具体用法?Python Sed.setupCCMab怎么用?Python Sed.setupCCMab使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lsst.sims.photUtils.Sed
的用法示例。
在下文中一共展示了Sed.setupCCMab方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testStellarPhotometricUncertainties
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testStellarPhotometricUncertainties(self):
"""
Test in the case of a catalog of stars
"""
lsstDefaults = LSSTdefaults()
starDB = testStarsDBObj(driver=self.driver, host=self.host, database=self.dbName)
starCat = testStarCatalog(starDB, obs_metadata=self.obs_metadata)
phot = PhotometryStars()
ct = 0
for line in starCat.iter_catalog():
starSed = Sed()
starSed.readSED_flambda(os.path.join(lsst.utils.getPackageDir('sims_sed_library'),
defaultSpecMap[line[14]]))
imsimband = Bandpass()
imsimband.imsimBandpass()
fNorm = starSed.calcFluxNorm(line[15], imsimband)
starSed.multiplyFluxNorm(fNorm)
aV = numpy.float(line[16])
a_int, b_int = starSed.setupCCMab()
starSed.addCCMDust(a_int, b_int, A_v=aV)
for i in range(len(self.bandpasses)):
controlSigma = calcMagError_sed(starSed, self.totalBandpasses[i],
self.skySeds[i],
self.hardwareBandpasses[i],
FWHMeff=lsstDefaults.FWHMeff(self.bandpasses[i]),
photParams=PhotometricParameters())
testSigma = line[8+i]
self.assertAlmostEqual(controlSigma, testSigma, 4)
ct += 1
self.assertGreater(ct, 0)
示例2: __init__
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def __init__(self, m5Col='fiveSigmaDepth', units='mag', maps=['DustMap'],
lsstFilter='r', wavelen_min=None , wavelen_max=None , wavelen_step=1., **kwargs ):
"""
Args:
m5Col (str): Column name that ('fiveSigmaDepth')
units (str): units of the metric ('mag')
maps (list): List of maps to use with the metric (['DustMap'])
lsstFilter (str): Which LSST filter to calculate m5 for
wavelen_min (float): Minimum wavength of your filter (None)
wavelen_max (float): (None)
wavelen_step (float): (1.)
**kwargs:
"""
waveMins={'u':330.,'g':403.,'r':552.,'i':691.,'z':818.,'y':950.}
waveMaxes={'u':403.,'g':552.,'r':691.,'i':818.,'z':922.,'y':1070.}
if lsstFilter is not None:
wavelen_min = waveMins[lsstFilter]
wavelen_max = waveMaxes[lsstFilter]
self.m5Col = m5Col
super(ExgalM5, self).__init__(col=[self.m5Col],
maps=maps, units=units, **kwargs)
testsed = Sed()
testsed.setFlatSED(wavelen_min = wavelen_min,
wavelen_max = wavelen_max, wavelen_step = 1)
self.a,self.b = testsed.setupCCMab()
self.R_v = 3.1
self.Coaddm5Metric = Coaddm5Metric(m5Col=m5Col)
示例3: calcADUwrapper
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def calcADUwrapper(sedName=None, magNorm=None, redshift=None, internalAv=None, internalRv=None,
galacticAv=None, galacticRv=None, bandpass=None):
imsimband = Bandpass()
imsimband.imsimBandpass()
sed = Sed()
sed.readSED_flambda(sedName)
fNorm = sed.calcFluxNorm(magNorm, imsimband)
sed.multiplyFluxNorm(fNorm)
if internalAv is not None and internalRv is not None:
if internalAv != 0.0 and internalRv != 0.0:
a_int, b_int = sed.setupCCMab()
sed.addCCMDust(a_int, b_int, A_v=internalAv, R_v=internalRv)
if redshift is not None and redshift != 0.0:
sed.redshiftSED(redshift, dimming=True)
a_int, b_int = sed.setupCCMab()
sed.addCCMDust(a_int, b_int, A_v=galacticAv, R_v=galacticRv)
adu = sed.calcADU(bandpass, photParams=PhotometricParameters())
return adu
示例4: __init__
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def __init__(self, m5Col='fiveSigmaDepth', units='mag', maps=['DustMap'],
lsstFilter='r', wavelen_min=None , wavelen_max=None , wavelen_step=1., **kwargs ):
"""
"""
waveMins={'u':330.,'g':403.,'r':552.,'i':691.,'z':818.,'y':950.}
waveMaxes={'u':403.,'g':552.,'r':691.,'i':818.,'z':922.,'y':1070.}
if lsstFilter is not None:
wavelen_min = waveMins[lsstFilter]
wavelen_max = waveMaxes[lsstFilter]
self.m5Col = m5Col
super(ExgalM5, self).__init__(col=[self.m5Col],
maps=maps, units=units, **kwargs)
testsed = Sed()
testsed.setFlatSED(wavelen_min = wavelen_min,
wavelen_max = wavelen_max, wavelen_step = 1)
self.a,self.b = testsed.setupCCMab()
self.R_v = 3.1
self.Coaddm5Metric = Coaddm5Metric(m5Col=m5Col)
示例5: gals
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
# create the a,b arrays for all the gals (because we resampled the gals onto the
# same wavelength range we can just calculate a/b once, and this is slow)
a_gal, b_gal = gals[galaxykeys[0]].setupCCMab()
# pretend we want to read mags into an array .. you could just as easily put it into a
# dictionary or list, with small variations in the code
mags = n.empty(len(galaxykeys), dtype='float')
for i in range(len(galaxykeys)):
# make a copy of the original SED if you want to 'reuse' the SED for multiple magnitude
# calculations with various fluxnorms, redshifts and dusts
tmpgal = Sed(wavelen=gals[galaxykeys[i]].wavelen, flambda=gals[galaxykeys[i]].flambda)
# add the dust internal to the distant galaxy
tmpgal.addCCMDust(a_gal, b_gal, ebv=ebv_gal[i])
# redshift the galaxy
tmpgal.redshiftSED(redshifts[i], dimming=False)
# add the dust from our milky way - have to recalculate a/b because now wavelenghts
# for each galaxy are *different*
a_mw, b_mw = tmpgal.setupCCMab()
tmpgal.addCCMDust(a_mw, b_mw, ebv=ebv_mw[i])
tmpgal.multiplyFluxNorm(fluxnorm[i])
mags[i] = tmpgal.calcMag(rband)
# show results
print "#sedname fluxnorm redshift ebv_gal ebv_mw magnitude "
for i in range(len(galaxykeys)):
print "%s %.5g %.3f %.5f %.5f %.5f" %(galaxykeys[i], fluxnorm[i], redshifts[i], ebv_gal[i], ebv_mw[i], mags[i])
示例6: testObjectPlacement
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testObjectPlacement(self):
"""
Test that GalSim places objects on the correct pixel by drawing
images, reading them in, and then comparing the flux contained in
circles of 2 fwhm radii about the object's expected positions with
the actual expected flux of the objects.
"""
scratchDir = os.path.join(getPackageDir('sims_GalSimInterface'), 'tests', 'scratchSpace')
catName = os.path.join(scratchDir, 'placementCatalog.dat')
imageRoot = os.path.join(scratchDir, 'placementImage')
dbFileName = os.path.join(scratchDir, 'placementInputCatalog.dat')
cameraDir = os.path.join(getPackageDir('sims_GalSimInterface'), 'tests', 'cameraData')
camera = ReturnCamera(cameraDir)
detector = camera[0]
imageName = '%s_%s_u.fits' % (imageRoot, detector.getName())
controlSed = Sed()
controlSed.readSED_flambda(
os.path.join(getPackageDir('sims_sed_library'),
'flatSED','sed_flat.txt.gz')
)
uBandpass = Bandpass()
uBandpass.readThroughput(
os.path.join(getPackageDir('throughputs'),
'baseline','total_u.dat')
)
controlBandpass = Bandpass()
controlBandpass.imsimBandpass()
ff = controlSed.calcFluxNorm(self.magNorm, uBandpass)
controlSed.multiplyFluxNorm(ff)
a_int, b_int = controlSed.setupCCMab()
controlSed.addCCMDust(a_int, b_int, A_v=0.1, R_v=3.1)
nSamples = 5
numpy.random.seed(42)
pointingRaList = numpy.random.random_sample(nSamples)*360.0
pointingDecList = numpy.random.random_sample(nSamples)*180.0 - 90.0
rotSkyPosList = numpy.random.random_sample(nSamples)*360.0
fwhmList = numpy.random.random_sample(nSamples)*1.0 + 0.3
actualCounts = None
for pointingRA, pointingDec, rotSkyPos, fwhm in \
zip(pointingRaList, pointingDecList, rotSkyPosList, fwhmList):
obs = ObservationMetaData(unrefractedRA=pointingRA,
unrefractedDec=pointingDec,
boundType='circle',
boundLength=4.0,
mjd=49250.0,
rotSkyPos=rotSkyPos)
xDisplacementList = numpy.random.random_sample(nSamples)*60.0-30.0
yDisplacementList = numpy.random.random_sample(nSamples)*60.0-30.0
create_text_catalog(obs, dbFileName, xDisplacementList, yDisplacementList,
mag_norm=[self.magNorm]*len(xDisplacementList))
db = placementFileDBObj(dbFileName, runtable='test')
cat = placementCatalog(db, obs_metadata=obs)
if actualCounts is None:
actualCounts = controlSed.calcADU(uBandpass, cat.photParams)
psf = SNRdocumentPSF(fwhm=fwhm)
cat.setPSF(psf)
cat.camera = camera
cat.write_catalog(catName)
cat.write_images(nameRoot=imageRoot)
objRaList = []
objDecList = []
with open(catName, 'r') as inFile:
for line in inFile:
if line[0] != '#':
words = line.split(';')
objRaList.append(numpy.radians(numpy.float(words[2])))
objDecList.append(numpy.radians(numpy.float(words[3])))
objRaList = numpy.array(objRaList)
objDecList = numpy.array(objDecList)
self.check_placement(imageName, objRaList, objDecList,
[fwhm]*len(objRaList),
numpy.array([actualCounts]*len(objRaList)),
cat.photParams.gain, detector, camera, obs, epoch=2000.0)
if os.path.exists(dbFileName):
os.unlink(dbFileName)
if os.path.exists(catName):
os.unlink(catName)
if os.path.exists(imageName):
os.unlink(imageName)
示例7: get_TotalMags
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def get_TotalMags(result, bandpasses=('u','g','r','i','z','y')):
datadir = os.environ.get("SIMS_SED_LIBRARY_DIR")
tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT')
bands = {"u":None, "g":None, "r":None, "i":None, "z":None, "y":None}
for k in bands:
bands[k] = Bandpass()
bands[k].readThroughput(os.path.join(tpath, "total_%s.dat"%k))
# Set up phi, the wavelength-normalized system response for each filter,
# for each bandpass for manyMagCalc method.
bplist = []
for f in ['u','g','r','i','z','y']:
bands[f].sbTophi()
bplist.append(bands[f])
ids = result['galid']
diskfile = result['sedFilenameDisk']
bulgefile = result['sedFilenameBulge']
agnfile = result['sedFilenameAgn']
diskmn = result['magNormDisk']
bulgemn = result['magNormBulge']
agnmn = result['magNormAgn']
bulgeAv = result['internalAvBulge']
diskAv = result['internalAvDisk']
redshift = result['redshift']
imsimband = Bandpass()
imsimband.imsimBandpass()
sedDict = {}
retMags = dict([(k, []) for k in bands])
a_int = None
b_int = None
tmpwavelen = None
for id, df, dm, dav, bf, bm, bav, af, am, z in zip(ids, diskfile, diskmn, diskAv,
bulgefile, bulgemn, bulgeAv, agnfile, agnmn, redshift):
tmpflux = None
for comp in ((df, dm, dav, 'galaxySED', False), (bf, bm, bav, 'galaxySED', False), (af, am, None, 'agnSED', True)):
#Zero out the AGN contribution
#for comp in ((df, dm, dav, 'galaxySED', False), (bf, bm, bav, 'galaxySED', False), (af, 99.99, None, 'agnSED', True)):
if not comp[0] == u'None':
if sedDict.has_key(comp[0]):
sed = copy.deepcopy(sedDict[comp[0]])
else:
sed = Sed()
print os.path.join(datadir,comp[3],comp[0])
sed.readSED_flambda(os.path.join(datadir,comp[3],comp[0]))
if comp[4]:
sed.resampleSED(wavelen_match=tmpwavelen)
sedDict[comp[0]] = sed
if a_int is None:
phiarray, dlambda = sed.setupPhiArray(bplist)
a_int, b_int = sed.setupCCMab()
#Careful, this assumes that a disk or bulge sed is read
#before any agn sed
tmpwavelen = sed.wavelen
fNorm = sed.calcFluxNorm(comp[1], imsimband)
sed.multiplyFluxNorm(fNorm)
#I guess this assumes rv=3.1??
if comp[2]:
sed.addCCMDust(a_int, b_int, A_v=comp[2])
wavelenArr=sed.wavelen
if tmpflux is None:
tmpflux = sed.flambda
else:
tmpflux += sed.flambda
newgal = Sed(wavelen=wavelenArr, flambda=tmpflux)
#a_mw, b_mw = sed.setupCCMab()
#sed.addCCMDust(a_mw, b_mw, A_v=mwav)
newgal.redshiftSED(z, dimming=True)
newgal.resampleSED(wavelen_match=bplist[0].wavelen)
newgal.flambdaTofnu()
mags = newgal.manyMagCalc(phiarray, dlambda)
for i,k in enumerate(['u','g','r','i','z','y']):
retMags[k].append(mags[i])
return retMags
示例8: testGalaxyPhotometricUncertainties
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testGalaxyPhotometricUncertainties(self):
"""
Test in the case of a catalog of galaxies
"""
lsstDefaults = LSSTdefaults()
phot = PhotometryGalaxies()
galDB = testGalaxyTileDBObj(driver=self.driver, host=self.host, database=self.dbName)
galCat = testGalaxyCatalog(galDB, obs_metadata=self.obs_metadata)
imsimband = Bandpass()
imsimband.imsimBandpass()
ct = 0
for line in galCat.iter_catalog():
bulgeSedName = line[50]
diskSedName = line[51]
agnSedName = line[52]
magNormBulge = line[53]
magNormDisk = line[54]
magNormAgn = line[55]
avBulge = line[56]
avDisk = line[57]
redshift = line[58]
bulgeSed = Sed()
bulgeSed.readSED_flambda(os.path.join(lsst.utils.getPackageDir('sims_sed_library'),
defaultSpecMap[bulgeSedName]))
fNorm=bulgeSed.calcFluxNorm(magNormBulge, imsimband)
bulgeSed.multiplyFluxNorm(fNorm)
diskSed = Sed()
diskSed.readSED_flambda(os.path.join(lsst.utils.getPackageDir('sims_sed_library'),
defaultSpecMap[diskSedName]))
fNorm = diskSed.calcFluxNorm(magNormDisk, imsimband)
diskSed.multiplyFluxNorm(fNorm)
agnSed = Sed()
agnSed.readSED_flambda(os.path.join(lsst.utils.getPackageDir('sims_sed_library'),
defaultSpecMap[agnSedName]))
fNorm = agnSed.calcFluxNorm(magNormAgn, imsimband)
agnSed.multiplyFluxNorm(fNorm)
a_int, b_int = bulgeSed.setupCCMab()
bulgeSed.addCCMDust(a_int, b_int, A_v=avBulge)
a_int, b_int = diskSed.setupCCMab()
diskSed.addCCMDust(a_int, b_int, A_v=avDisk)
bulgeSed.redshiftSED(redshift, dimming=True)
diskSed.redshiftSED(redshift, dimming=True)
agnSed.redshiftSED(redshift, dimming=True)
bulgeSed.resampleSED(wavelen_match=self.totalBandpasses[0].wavelen)
diskSed.resampleSED(wavelen_match=bulgeSed.wavelen)
agnSed.resampleSED(wavelen_match=bulgeSed.wavelen)
numpy.testing.assert_almost_equal(bulgeSed.wavelen, diskSed.wavelen)
numpy.testing.assert_almost_equal(bulgeSed.wavelen, agnSed.wavelen)
fl = bulgeSed.flambda + diskSed.flambda + agnSed.flambda
totalSed = Sed(wavelen=bulgeSed.wavelen, flambda=fl)
sedList = [totalSed, bulgeSed, diskSed, agnSed]
for i, spectrum in enumerate(sedList):
if i==0:
msgroot = 'failed on total'
elif i==1:
msgroot = 'failed on bulge'
elif i==2:
msgroot = 'failed on disk'
elif i==3:
msgroot = 'failed on agn'
for j, b in enumerate(self.bandpasses):
controlSigma = calcMagError_sed(spectrum, self.totalBandpasses[j],
self.skySeds[j],
self.hardwareBandpasses[j],
FWHMeff=lsstDefaults.FWHMeff(b),
photParams=PhotometricParameters())
testSigma = line[26+(i*6)+j]
msg = '%e neq %e; ' % (testSigma, controlSigma) + msgroot
self.assertAlmostEqual(testSigma, controlSigma, 10, msg=msg)
ct += 1
self.assertGreater(ct, 0)
示例9: gen_gums_mag_cat
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def gen_gums_mag_cat(istart=0, nstars=100, workdir='', noisyResponse=False, verbose=False, save=True):
"""
generate a catalog of true and observed magnitudes for stars from the gums catalog
"""
# Load response functions
responses = []
response_temperatures = []
response_files = glob.glob('gaia_response_*00.npz')
for fn in response_files:
responses.append(gaia_response(restore_file=fn))
response_temperatures.append(float(fn.replace('.npz', '').split('_')[-1]))
response_temperatures = np.array(response_temperatures)
#if noisyResponse:
# response = gaia_response()
#else:
# response = gaia_response(restore_file='gaia_response_nonoise.npz')
# Load gums catalog
gum_cat = gums_catalog()
gum_cat.prune()
gum_cat = gum_cat.catalog
print 'using %i stars from GAIA' % gum_cat.size
sed = Sed()
# Load up bandpass
imsimBand = Bandpass()
imsimBand.imsimBandpass()
bps = lsst_filters()
bps.update(stubb_fitlers())
names = ['id', 'sourceExtendedId', 'raj2000', 'dej2000', 'u_truncated', 'u', 'g', 'r',
'i', 'z', 'y', 'y_truncated',
'u_truncated_noiseless', 'u_noiseless', 'g_noiseless', 'r_noiseless',
'i_noiseless', 'z_noiseless', 'y_noiseless', 'y_truncated_noiseless',
'u_truncated_true', 'u_true', 'g_true', 'r_true', 'i_true', 'z_true',
'y_true', 'y_truncated_true', 'teff', 'feH', 'logg', 'Av', 'magG']
types = [int, '|S30']
types.extend([float]*(len(names)-1))
result_cat = np.zeros(nstars, dtype=zip(names, types))
copy_keys = ['sourceExtendedId', 'raj2000', 'dej2000']
a_x = None
b_x = None
maxI = float(nstars)
for i, gems_index in enumerate(np.arange(istart, istart+nstars)):
result_cat['id'][i] = gems_index
for key in copy_keys:
result_cat[key][i] = gum_cat[key][gems_index]
# Lookup the file with the closest teff, feH, and logg to gum_cat[i]
sed, pd = read_close_Kurucz(gum_cat['teff'][gems_index], gum_cat['feH'][gems_index],
gum_cat['logg'][gems_index])
result_cat['teff'][i] = gum_cat['teff'][gems_index]
result_cat['feH'][i] = gum_cat['feH'][gems_index]
result_cat['logg'][i] = gum_cat['logg'][gems_index]
result_cat['Av'][i] = gum_cat['Av'][gems_index]
result_cat['magG'] = gum_cat['magG'][gems_index]
# Let's figure out the GAIA-G to SDSS g conversion. Assume SDSS_g ~ LSST_g
# poly fit from https://arxiv.org/pdf/1008.0815.pdf
g_mag = sed.calcMag(bps['g'])
i_mag = sed.calcMag(bps['i'])
g_i = g_mag - i_mag
gnorm = gum_cat['magG'][gems_index] + 0.0094 + 0.531*(g_i) + 0.0974*(g_i)**2 - 0.0052*(g_i)**3
if a_x is None:
a_x, b_x = sed.setupCCMab()
sed.addCCMDust(a_x, b_x, A_v=gum_cat['Av'][gems_index])
# do the magnorm here
fNorm = sed.calcFluxNorm(gnorm, bps['g'])
sed.multiplyFluxNorm(fNorm)
# Observe sed with GAIA, both with and without noise
# Wrap in a try block so if ULYSSES fails for some reason the star just gets skipped
gaia_observed = SED2GAIA(sed, workdir=workdir)
tdiff = np.abs(response_temperatures - result_cat['teff'][i])
tmatch = np.where(tdiff == tdiff.min())[0]
observed_sed = ulysses2SED(data=gaia_observed, response=responses[tmatch])
not_nan = ~np.isnan(observed_sed.flambda)
# Let's interpolate out any nans
observed_sed.flambda = np.interp(observed_sed.wavelen, observed_sed.wavelen[not_nan],
observed_sed.flambda[not_nan])
for filtername in bps:
try:
result_cat[filtername][i] = observed_sed.calcMag(bps[filtername])
except:
pass
result_cat[filtername+'_true'][i] = sed.calcMag(bps[filtername])
# Now do it on a noiseless spectra
gaia_observed = SED2GAIA(sed, workdir=workdir, noise=0)
observed_sed = ulysses2SED(data=gaia_observed, response=responses[tmatch], noisy=False)
not_nan = ~np.isnan(observed_sed.flambda)
# Let's interpolate out any nans
observed_sed.flambda = np.interp(observed_sed.wavelen, observed_sed.wavelen[not_nan],
observed_sed.flambda[not_nan])
#.........这里部分代码省略.........
示例10: testSetUp
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testSetUp(self):
"""
Test the SedList can be successfully initialized
"""
############## Try just reading in an normalizing some SEDs
nSed = 10
sedNameList = self.getListOfSedNames(nSed)
magNormList = numpy.random.random_sample(nSed)*5.0 + 15.0
testList = SedList(sedNameList, magNormList)
self.assertEqual(len(testList), nSed)
self.assertTrue(testList.internalAvList is None)
self.assertTrue(testList.galacticAvList is None)
self.assertTrue(testList.redshiftList is None)
self.assertTrue(testList.wavelenMatch is None)
self.assertTrue(testList.cosmologicalDimming is True)
imsimBand = Bandpass()
imsimBand.imsimBandpass()
for name, norm, sedTest in zip(sedNameList, magNormList, testList):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
numpy.testing.assert_array_equal(sedControl.fnu, sedTest.fnu)
################# now add an internalAv
sedNameList = self.getListOfSedNames(nSed)
magNormList = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList = numpy.random.random_sample(nSed)*0.3 + 0.1
testList = SedList(sedNameList, magNormList, internalAvList=internalAvList)
self.assertTrue(testList.galacticAvList is None)
self.assertTrue(testList.redshiftList is None)
self.assertTrue(testList.wavelenMatch is None)
self.assertTrue(testList.cosmologicalDimming is True)
for avControl, avTest in zip(internalAvList, testList.internalAvList):
self.assertAlmostEqual(avControl, avTest, 10)
for name, norm, av, sedTest in zip(sedNameList, magNormList, internalAvList, testList):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=av)
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
numpy.testing.assert_array_equal(sedControl.fnu, sedTest.fnu)
################ now add redshift
sedNameList = self.getListOfSedNames(nSed)
magNormList = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList = numpy.random.random_sample(nSed)*0.3 + 0.1
redshiftList = numpy.random.random_sample(nSed)*5.0
testList = SedList(sedNameList, magNormList, internalAvList=internalAvList,
redshiftList=redshiftList)
self.assertTrue(testList.galacticAvList is None)
self.assertTrue(testList.wavelenMatch is None)
self.assertTrue(testList.cosmologicalDimming is True)
for avControl, avTest in zip(internalAvList, testList.internalAvList):
self.assertAlmostEqual(avControl, avTest, 10)
for zControl, zTest in zip(redshiftList, testList.redshiftList):
self.assertAlmostEqual(zControl, zTest, 10)
for name, norm, av, zz, sedTest in \
zip(sedNameList, magNormList, internalAvList, redshiftList, testList):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=av)
sedControl.redshiftSED(zz, dimming=True)
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
numpy.testing.assert_array_equal(sedControl.fnu, sedTest.fnu)
################# without cosmological dimming
sedNameList = self.getListOfSedNames(nSed)
magNormList = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList = numpy.random.random_sample(nSed)*0.3 + 0.1
redshiftList = numpy.random.random_sample(nSed)*5.0
testList = SedList(sedNameList, magNormList, internalAvList=internalAvList,
redshiftList=redshiftList, cosmologicalDimming=False)
self.assertTrue(testList.galacticAvList is None)
self.assertTrue(testList.wavelenMatch is None)
self.assertTrue(testList.cosmologicalDimming is False)
for avControl, avTest in zip(internalAvList, testList.internalAvList):
#.........这里部分代码省略.........
示例11: testFlush
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testFlush(self):
"""
Test that the flush method of SedList behaves properly
"""
imsimBand = Bandpass()
imsimBand.imsimBandpass()
nSed = 10
sedNameList_0 = self.getListOfSedNames(nSed)
magNormList_0 = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
redshiftList_0 = numpy.random.random_sample(nSed)*5.0
galacticAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
wavelen_match = numpy.arange(300.0, 1500.0, 10.0)
testList = SedList(sedNameList_0, magNormList_0, internalAvList=internalAvList_0, \
redshiftList=redshiftList_0, galacticAvList=galacticAvList_0,
wavelenMatch=wavelen_match)
self.assertEqual(len(testList), nSed)
numpy.testing.assert_array_equal(wavelen_match, testList.wavelenMatch)
for ix in range(len(sedNameList_0)):
self.assertAlmostEqual(internalAvList_0[ix], testList.internalAvList[ix], 10)
self.assertAlmostEqual(galacticAvList_0[ix], testList.galacticAvList[ix], 10)
self.assertAlmostEqual(redshiftList_0[ix], testList.redshiftList[ix], 10)
for ix, (name, norm, iav, gav, zz) in \
enumerate(zip(sedNameList_0, magNormList_0, internalAvList_0, \
galacticAvList_0, redshiftList_0)):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=iav)
sedControl.redshiftSED(zz, dimming=True)
sedControl.resampleSED(wavelen_match=wavelen_match)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=gav)
sedTest = testList[ix]
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
numpy.testing.assert_array_equal(sedControl.fnu, sedTest.fnu)
testList.flush()
sedNameList_1 = self.getListOfSedNames(nSed/2)
magNormList_1 = numpy.random.random_sample(nSed/2)*5.0 + 15.0
internalAvList_1 = numpy.random.random_sample(nSed/2)*0.3 + 0.1
redshiftList_1 = numpy.random.random_sample(nSed/2)*5.0
galacticAvList_1 = numpy.random.random_sample(nSed/2)*0.3 + 0.1
testList.loadSedsFromList(sedNameList_1, magNormList_1,
internalAvList=internalAvList_1,
galacticAvList=galacticAvList_1,
redshiftList=redshiftList_1)
self.assertEqual(len(testList), nSed/2)
self.assertEqual(len(testList.redshiftList), nSed/2)
self.assertEqual(len(testList.internalAvList), nSed/2)
self.assertEqual(len(testList.galacticAvList), nSed/2)
numpy.testing.assert_array_equal(wavelen_match, testList.wavelenMatch)
for ix in range(len(sedNameList_1)):
self.assertAlmostEqual(internalAvList_1[ix], testList.internalAvList[ix], 10)
self.assertAlmostEqual(galacticAvList_1[ix], testList.galacticAvList[ix], 10)
self.assertAlmostEqual(redshiftList_1[ix], testList.redshiftList[ix], 10)
for ix, (name, norm, iav, gav, zz) in \
enumerate(zip(sedNameList_1, magNormList_1, internalAvList_1, \
galacticAvList_1, redshiftList_1)):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=iav)
sedControl.redshiftSED(zz, dimming=True)
sedControl.resampleSED(wavelen_match=wavelen_match)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=gav)
sedTest = testList[ix]
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
#.........这里部分代码省略.........
示例12: testAlternateNormalizingBandpass
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testAlternateNormalizingBandpass(self):
"""
A reiteration of testAddingToList, but testing with a non-imsimBandpass
normalizing bandpass
"""
normalizingBand = Bandpass()
normalizingBand.readThroughput(os.path.join(getPackageDir('throughputs'),'baseline','total_r.dat'))
nSed = 10
sedNameList_0 = self.getListOfSedNames(nSed)
magNormList_0 = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
redshiftList_0 = numpy.random.random_sample(nSed)*5.0
galacticAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
wavelen_match = numpy.arange(300.0, 1500.0, 10.0)
testList = SedList(sedNameList_0, magNormList_0,
normalizingBandpass=normalizingBand,
internalAvList=internalAvList_0,
redshiftList=redshiftList_0, galacticAvList=galacticAvList_0,
wavelenMatch=wavelen_match)
sedNameList_1 = self.getListOfSedNames(nSed)
magNormList_1 = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList_1 = numpy.random.random_sample(nSed)*0.3 + 0.1
redshiftList_1 = numpy.random.random_sample(nSed)*5.0
galacticAvList_1 = numpy.random.random_sample(nSed)*0.3 + 0.1
testList.loadSedsFromList(sedNameList_1, magNormList_1,
internalAvList=internalAvList_1,
galacticAvList=galacticAvList_1,
redshiftList=redshiftList_1)
self.assertEqual(len(testList), 2*nSed)
numpy.testing.assert_array_equal(wavelen_match, testList.wavelenMatch)
for ix in range(len(sedNameList_0)):
self.assertAlmostEqual(internalAvList_0[ix], testList.internalAvList[ix], 10)
self.assertAlmostEqual(galacticAvList_0[ix], testList.galacticAvList[ix], 10)
self.assertAlmostEqual(redshiftList_0[ix], testList.redshiftList[ix], 10)
for ix in range(len(sedNameList_1)):
self.assertAlmostEqual(internalAvList_1[ix], testList.internalAvList[ix+nSed], 10)
self.assertAlmostEqual(galacticAvList_1[ix], testList.galacticAvList[ix+nSed], 10)
self.assertAlmostEqual(redshiftList_1[ix], testList.redshiftList[ix+nSed], 10)
for ix, (name, norm, iav, gav, zz) in \
enumerate(zip(sedNameList_0, magNormList_0, internalAvList_0, \
galacticAvList_0, redshiftList_0)):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, normalizingBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=iav)
sedControl.redshiftSED(zz, dimming=True)
sedControl.resampleSED(wavelen_match=wavelen_match)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=gav)
sedTest = testList[ix]
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
numpy.testing.assert_array_equal(sedControl.fnu, sedTest.fnu)
for ix, (name, norm, iav, gav, zz) in \
enumerate(zip(sedNameList_1, magNormList_1, internalAvList_1, \
galacticAvList_1, redshiftList_1)):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, normalizingBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=iav)
sedControl.redshiftSED(zz, dimming=True)
sedControl.resampleSED(wavelen_match=wavelen_match)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=gav)
sedTest = testList[ix+nSed]
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
numpy.testing.assert_array_equal(sedControl.fnu, sedTest.fnu)
示例13: testAddingNonesToList
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testAddingNonesToList(self):
"""
Test what happens if you add SEDs to an SedList that have None for
one or more of the physical parameters (i.e. galacticAv, internalAv, or redshift)
"""
imsimBand = Bandpass()
imsimBand.imsimBandpass()
nSed = 10
sedNameList_0 = self.getListOfSedNames(nSed)
magNormList_0 = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
redshiftList_0 = numpy.random.random_sample(nSed)*5.0
galacticAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
wavelen_match = numpy.arange(300.0, 1500.0, 10.0)
testList = SedList(sedNameList_0, magNormList_0, internalAvList=internalAvList_0, \
redshiftList=redshiftList_0, galacticAvList=galacticAvList_0,
wavelenMatch=wavelen_match)
sedNameList_1 = self.getListOfSedNames(nSed)
magNormList_1 = list(numpy.random.random_sample(nSed)*5.0 + 15.0)
internalAvList_1 = list(numpy.random.random_sample(nSed)*0.3 + 0.1)
redshiftList_1 = list(numpy.random.random_sample(nSed)*5.0)
galacticAvList_1 = list(numpy.random.random_sample(nSed)*0.3 + 0.1)
internalAvList_1[0] = None
redshiftList_1[1] = None
galacticAvList_1[2] = None
internalAvList_1[3] = None
redshiftList_1[3] = None
internalAvList_1[4] = None
galacticAvList_1[4] = None
redshiftList_1[5] = None
galacticAvList_1[5] = None
internalAvList_1[6] = None
redshiftList_1[6] = None
galacticAvList_1[6] = None
testList.loadSedsFromList(sedNameList_1, magNormList_1,
internalAvList=internalAvList_1,
galacticAvList=galacticAvList_1,
redshiftList=redshiftList_1)
self.assertEqual(len(testList), 2*nSed)
numpy.testing.assert_array_equal(wavelen_match, testList.wavelenMatch)
for ix in range(len(sedNameList_0)):
self.assertAlmostEqual(internalAvList_0[ix], testList.internalAvList[ix], 10)
self.assertAlmostEqual(galacticAvList_0[ix], testList.galacticAvList[ix], 10)
self.assertAlmostEqual(redshiftList_0[ix], testList.redshiftList[ix], 10)
for ix in range(len(sedNameList_1)):
self.assertAlmostEqual(internalAvList_1[ix], testList.internalAvList[ix+nSed], 10)
self.assertAlmostEqual(galacticAvList_1[ix], testList.galacticAvList[ix+nSed], 10)
self.assertAlmostEqual(redshiftList_1[ix], testList.redshiftList[ix+nSed], 10)
for ix, (name, norm, iav, gav, zz) in \
enumerate(zip(sedNameList_0, magNormList_0, internalAvList_0, \
galacticAvList_0, redshiftList_0)):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=iav)
sedControl.redshiftSED(zz, dimming=True)
sedControl.resampleSED(wavelen_match=wavelen_match)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=gav)
sedTest = testList[ix]
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
numpy.testing.assert_array_equal(sedControl.fnu, sedTest.fnu)
for ix, (name, norm, iav, gav, zz) in \
enumerate(zip(sedNameList_1, magNormList_1, internalAvList_1, \
galacticAvList_1, redshiftList_1)):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
if iav is not None:
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=iav)
#.........这里部分代码省略.........
示例14: testAddingToList
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
def testAddingToList(self):
"""
Test that we can add Seds to an already instantiated SedList
"""
imsimBand = Bandpass()
imsimBand.imsimBandpass()
nSed = 10
sedNameList_0 = self.getListOfSedNames(nSed)
magNormList_0 = numpy.random.random_sample(nSed)*5.0 + 15.0
internalAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
redshiftList_0 = numpy.random.random_sample(nSed)*5.0
galacticAvList_0 = numpy.random.random_sample(nSed)*0.3 + 0.1
wavelen_match = numpy.arange(300.0, 1500.0, 10.0)
testList = SedList(sedNameList_0, magNormList_0, internalAvList=internalAvList_0, \
redshiftList=redshiftList_0, galacticAvList=galacticAvList_0,
wavelenMatch=wavelen_match)
# experiment with adding different combinations of physical parameter lists
# as None and not None
for addIav in [True, False]:
for addRedshift in [True, False]:
for addGav in [True, False]:
testList = SedList(sedNameList_0, magNormList_0, internalAvList=internalAvList_0, \
redshiftList=redshiftList_0, galacticAvList=galacticAvList_0,
wavelenMatch=wavelen_match)
sedNameList_1 = self.getListOfSedNames(nSed)
magNormList_1 = numpy.random.random_sample(nSed)*5.0 + 15.0
if addIav:
internalAvList_1 = numpy.random.random_sample(nSed)*0.3 + 0.1
else:
internalAvList_1 = None
if addRedshift:
redshiftList_1 = numpy.random.random_sample(nSed)*5.0
else:
redshiftList_1 = None
if addGav:
galacticAvList_1 = numpy.random.random_sample(nSed)*0.3 + 0.1
else:
galacticAvList_1 = None
testList.loadSedsFromList(sedNameList_1, magNormList_1,
internalAvList=internalAvList_1,
galacticAvList=galacticAvList_1,
redshiftList=redshiftList_1)
self.assertEqual(len(testList), 2*nSed)
numpy.testing.assert_array_equal(wavelen_match, testList.wavelenMatch)
for ix in range(len(sedNameList_0)):
self.assertAlmostEqual(internalAvList_0[ix], testList.internalAvList[ix], 10)
self.assertAlmostEqual(galacticAvList_0[ix], testList.galacticAvList[ix], 10)
self.assertAlmostEqual(redshiftList_0[ix], testList.redshiftList[ix], 10)
for ix in range(len(sedNameList_1)):
if addIav:
self.assertAlmostEqual(internalAvList_1[ix], testList.internalAvList[ix+nSed], 10)
else:
self.assertTrue(testList.internalAvList[ix+nSed] is None)
if addGav:
self.assertAlmostEqual(galacticAvList_1[ix], testList.galacticAvList[ix+nSed], 10)
else:
self.assertTrue(testList.galacticAvList[ix+nSed] is None)
if addRedshift:
self.assertAlmostEqual(redshiftList_1[ix], testList.redshiftList[ix+nSed], 10)
else:
self.assertTrue(testList.redshiftList[ix+nSed] is None)
for ix, (name, norm, iav, gav, zz) in \
enumerate(zip(sedNameList_0, magNormList_0, internalAvList_0, \
galacticAvList_0, redshiftList_0)):
sedControl = Sed()
sedControl.readSED_flambda(os.path.join(self.sedDir, name+'.gz'))
fnorm = sedControl.calcFluxNorm(norm, imsimBand)
sedControl.multiplyFluxNorm(fnorm)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=iav)
sedControl.redshiftSED(zz, dimming=True)
sedControl.resampleSED(wavelen_match=wavelen_match)
a_coeff, b_coeff = sedControl.setupCCMab()
sedControl.addCCMDust(a_coeff, b_coeff, A_v=gav)
sedTest = testList[ix]
numpy.testing.assert_array_equal(sedControl.wavelen, sedTest.wavelen)
numpy.testing.assert_array_equal(sedControl.flambda, sedTest.flambda)
#.........这里部分代码省略.........
示例15: E
# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setupCCMab [as 别名]
star.multiplyFluxNorm(fluxnorm)
# Try the magnitude calculation again.
mag = star.calcMag(rband)
print "After scaling, magnitude of SED is now %.4f (desired magnitude was %.4f)" %(mag, mag_desired)
# And let's calculate what the expected photon counts for LSST would be.
counts = star.calcADU(rband, expTime=30)
print "This would correspond to roughly %f counts in the LSST focal plane, in a 30s exposure." %(counts)
# For fun, let's see what else can happen.
ebv = 0.5
print ""
print "Let's try adding %.2f E(B-V) dust extinction to this star." %(ebv)
a, b = star.setupCCMab()
# You can use addCCMDust on the 'star' object itself, but I'm illustrating here how you could also
# do otherwise - preserve the original 'star' object as is, and create a new Sed object that does
# include the effects of dust ('dustystar'). Star's data will be unchanged by the dust.
dustywavelen, dustyflambda = star.addCCMDust(a, b, ebv=ebv, wavelen=star.wavelen, flambda=star.flambda)
dustystar = Sed(wavelen=dustywavelen, flambda=dustyflambda)
magdust = dustystar.calcMag(rband)
print "With this dust, the magnitude of the star in this bandpass is now %.4f." %(magdust)
redshift = 0.2
print "What if this star was at a redshift of %f?" %(redshift)
# Here (unlike above with the dust), I'm applying the redshift to the 'star' object itself.
# Star's data will be changed by the redshifting.
star.redshiftSED(redshift, dimming=True)
magredshift = star.calcMag(rband)
print ""