本文整理汇总了Python中lsst.sims.photUtils.BandpassDict.loadBandpassesFromFiles方法的典型用法代码示例。如果您正苦于以下问题:Python BandpassDict.loadBandpassesFromFiles方法的具体用法?Python BandpassDict.loadBandpassesFromFiles怎么用?Python BandpassDict.loadBandpassesFromFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lsst.sims.photUtils.BandpassDict
的用法示例。
在下文中一共展示了BandpassDict.loadBandpassesFromFiles方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLoadBandpassesFromFiles
# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import loadBandpassesFromFiles [as 别名]
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)
示例2: fromTwinklesData
# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import loadBandpassesFromFiles [as 别名]
def fromTwinklesData(cls,
tableName,
objectTypeID=42,
dbHostName=None,
idCol='snid',
columns=('snid', 'redshift', 'snra', 'sndec', 't0',
'x0', 'x1', 'c'),
idSequence=None):
"""
Simplified classmethod to construct this class from the Twinkles Run 1
perspective.
Parameters
----------
tableName : string, mandatory
case insensitive string name of table on database to connect to
for model parameters of astrophysical objects
idCol : string, optional, defaults to 'snid'
column name of Index on the table
columns : tuple of strings, optional, defaults to values for SN
tuple of strings that completely specify the truth values for
idSequence : sequence of one dimension, optional, defaults to None
sequence of unique ids in the catsim universe indexing the
astrophysical objects in the database.
dbHostName : string, optional, defaults to None
force the class to use this hostname. If not provided, the class
will set this to localhost, which is the desired hostname when
using an ssh tunnel. This parameter is useful when working from
whitelisted computers.
Returns
------
An instance of the class RefLightCurve class where the other parameters
have been defaulted to sensible values for Twinkles Run1 Analysis.
Examples
--------
"""
data_dir = os.path.join(os.environ['MONITOR_DIR'], 'data')
opsimCsv = os.path.join(data_dir, 'SelectedKrakenVisits.csv')
opsimdf = pd.read_csv(opsimCsv, index_col='obsHistID')
observations = opsimdf[['expMJD', 'filter', 'fiveSigmaDepth']].copy()
del opsimdf
# Obtain the tuple of total, HardWare bandPassDict and keep the total
lsstBP = BandpassDict.loadBandpassesFromFiles()[0]
cls = RefLightCurves(tableName=tableName,
objectTypeID=objectTypeID,
idCol=idCol,
dbHostName=dbHostName,
columns=columns,
observations=observations,
bandPassDict=lsstBP,
idSequence=idSequence)
return cls
示例3: __init__
# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import loadBandpassesFromFiles [as 别名]
def __init__(self, idSequence, opsim_csv=None, db_config=None):
if opsim_csv is None:
opsim_csv = os.path.join(lsst.utils.getPackageDir('monitor'),
'data', 'SelectedKrakenVisits.csv')
df = pd.read_csv(opsim_csv, index_col='obsHistID')
opsim_df = df[['expMJD', 'filter', 'fiveSigmaDepth']]
lsstBP = BandpassDict.loadBandpassesFromFiles()[0]
self.reflc = RefLightCurves(idSequence=idSequence,
tableName='TwinkSN',
bandPassDict=lsstBP,
observations=opsim_df)
示例4: testUncertaintyExceptions
# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import loadBandpassesFromFiles [as 别名]
def testUncertaintyExceptions(self):
"""
Test that calcSNR_m5 raises exceptions when it needs to
"""
totalDict, hardwareDict = BandpassDict.loadBandpassesFromFiles()
magnitudes = numpy.array([22.0, 23.0, 24.0, 25.0, 26.0, 27.0])
shortMagnitudes = numpy.array([22.0])
photParams = PhotometricParameters()
shortGamma = numpy.array([1.0, 1.0])
self.assertRaises(RuntimeError, calcSNR_m5, magnitudes, totalDict.values(), shortMagnitudes, photParams)
self.assertRaises(RuntimeError, calcSNR_m5, shortMagnitudes, totalDict.values(), magnitudes, photParams)
self.assertRaises(
RuntimeError, calcSNR_m5, magnitudes, totalDict.values(), magnitudes, photParams, gamma=shortGamma
)
snr, gg = calcSNR_m5(magnitudes, totalDict.values(), magnitudes, photParams)
示例5: testSignalToNoise
# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import loadBandpassesFromFiles [as 别名]
def testSignalToNoise(self):
"""
Test that calcSNR_m5 and calcSNR_sed give similar results
"""
defaults = LSSTdefaults()
photParams = PhotometricParameters()
totalDict, hardwareDict = BandpassDict.loadBandpassesFromFiles()
skySED = Sed()
skySED.readSED_flambda(os.path.join(lsst.utils.getPackageDir("throughputs"), "baseline", "darksky.dat"))
m5 = []
for filt in totalDict:
m5.append(calcM5(skySED, totalDict[filt], hardwareDict[filt], photParams, seeing=defaults.seeing(filt)))
sedDir = lsst.utils.getPackageDir("sims_sed_library")
sedDir = os.path.join(sedDir, "starSED", "kurucz")
fileNameList = os.listdir(sedDir)
numpy.random.seed(42)
offset = numpy.random.random_sample(len(fileNameList)) * 2.0
for ix, name in enumerate(fileNameList):
if ix > 100:
break
spectrum = Sed()
spectrum.readSED_flambda(os.path.join(sedDir, name))
ff = spectrum.calcFluxNorm(m5[2] - offset[ix], totalDict.values()[2])
spectrum.multiplyFluxNorm(ff)
magList = []
controlList = []
magList = []
for filt in totalDict:
controlList.append(
calcSNR_sed(
spectrum, totalDict[filt], skySED, hardwareDict[filt], photParams, defaults.seeing(filt)
)
)
magList.append(spectrum.calcMag(totalDict[filt]))
testList, gammaList = calcSNR_m5(
numpy.array(magList), numpy.array(totalDict.values()), numpy.array(m5), photParams
)
for tt, cc in zip(controlList, testList):
msg = "%e != %e " % (tt, cc)
self.assertTrue(numpy.abs(tt / cc - 1.0) < 0.001, msg=msg)
示例6: _initializeGalSimInterpreter
# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import loadBandpassesFromFiles [as 别名]
def _initializeGalSimInterpreter(self):
"""
This method creates the GalSimInterpreter (if it is None)
This method reads in all of the data about the camera and pass it into
the GalSimInterpreter.
This method calls _getBandpasses to construct the paths to
the files containing the bandpass data.
"""
if self.galSimInterpreter is None:
#This list will contain instantiations of the GalSimDetector class
#(see galSimInterpreter.py), which stores detector information in a way
#that the GalSimInterpreter will understand
detectors = []
for dd in self.camera:
if self.allowed_chips is None or dd.getName() in self.allowed_chips:
cs = dd.makeCameraSys(PUPIL)
centerPupil = self.camera.transform(dd.getCenter(FOCAL_PLANE),cs).getPoint()
centerPixel = dd.getCenter(PIXELS).getPoint()
translationPixel = afwGeom.Point2D(centerPixel.getX()+1, centerPixel.getY()+1)
translationPupil = self.camera.transform(
dd.makeCameraPoint(translationPixel, PIXELS), cs).getPoint()
plateScale = numpy.sqrt(numpy.power(translationPupil.getX()-centerPupil.getX(),2)+
numpy.power(translationPupil.getY()-centerPupil.getY(),2))/numpy.sqrt(2.0)
plateScale = 3600.0*numpy.degrees(plateScale)
#make a detector-custom photParams that copies all of the quantities
#in the catalog photParams, except the platescale, which is
#calculated above
params = PhotometricParameters(exptime=self.photParams.exptime,
nexp=self.photParams.nexp,
effarea=self.photParams.effarea,
gain=self.photParams.gain,
readnoise=self.photParams.readnoise,
darkcurrent=self.photParams.darkcurrent,
othernoise=self.photParams.othernoise,
platescale=plateScale)
detector = GalSimDetector(dd, self.camera,
obs_metadata=self.obs_metadata, epoch=self.db_obj.epoch,
photParams=params)
detectors.append(detector)
if not hasattr(self, 'bandpassDict'):
if self.noise_and_background is not None:
if self.obs_metadata.m5 is None:
raise RuntimeError('WARNING in GalSimCatalog; you did not specify m5 in your '+
'obs_metadata. m5 is required in order to add noise to your images')
for name in self.bandpassNames:
if name not in self.obs_metadata.m5:
raise RuntimeError('WARNING in GalSimCatalog; your obs_metadata does not have ' +
'm5 values for all of your bandpasses \n' +
'bandpass has: %s \n' % self.bandpassNames.__repr__() +
'm5 has: %s ' % self.obs_metadata.m5.keys().__repr__())
if self.obs_metadata.seeing is None:
raise RuntimeError('WARNING in GalSimCatalog; you did not specify seeing in your '+
'obs_metadata. seeing is required in order to add noise to your images')
for name in self.bandpassNames:
if name not in self.obs_metadata.seeing:
raise RuntimeError('WARNING in GalSimCatalog; your obs_metadata does not have ' +
'seeing values for all of your bandpasses \n' +
'bandpass has: %s \n' % self.bandpassNames.__repr__() +
'seeing has: %s ' % self.obs_metadata.seeing.keys().__repr__())
self.bandpassDict, hardwareDict = BandpassDict.loadBandpassesFromFiles(bandpassNames=self.bandpassNames,
filedir=self.bandpassDir,
bandpassRoot=self.bandpassRoot,
componentList=self.componentList,
atmoTransmission=os.path.join(self.bandpassDir, self.atmoTransmissionName))
self.galSimInterpreter = GalSimInterpreter(obs_metadata=self.obs_metadata, epoch=self.db_obj.epoch, detectors=detectors,
bandpassDict=self.bandpassDict, noiseWrapper=self.noise_and_background,
seed=self.seed)
self.galSimInterpreter.setPSF(PSF=self.PSF)
示例7: print
# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import loadBandpassesFromFiles [as 别名]
print('numpy version: ', np.__version__)
print('healpy dir', getPackageDir('healpy'))
print('sims_skybrightness_dir', getPackageDir('sims_skybrightness'))
print('sims_skybrightness_data_dir', getPackageDir('sims_skybrightness_data'))
print('obscond version', obscond.__version__)
logger.info('Start reading opsim database')
minion_out = '/local/lsst/rbiswas/data/LSST/OpSimData/minion_1016_sqlite.db'
#minion_out = '/Users/rbiswas/data/LSST/OpSimData/minion_1016_sqlite.db'
opsout = OpSimOutput.fromOpSimDB(minion_out, zeroDDFDithers=True, subset="unique_all")
# opsout = OpSimOutput.fromOpSimDB(minion_out, zeroDDFDithers=True, subset="ddf")
print('reading done\n')
df = opsout.summary.copy()
logger.info('Finished reading database at {}'.format(time.time()))
totalbpdict, hwbpdict = BandpassDict.loadBandpassesFromFiles()
photparams = PhotometricParameters()
# Split the entries in the opsim database for parallelization
splits = 1000
dfs = np.array_split(df, splits)
print('splitting dataframe of size {0} into {1} splits each of size {2}\n'.format(len(df), splits, len(dfs[0])))
calcdfs = []
def recalcmags(j):
logfname = 'newres_{}.log'.format(j)
tsplitstart = time.time()
with open(logfname, 'w') as f:
f.write('starting split {0} at time {1}\n'.format(j, tsplitstart))
df = dfs[j]