本文整理汇总了Python中sherpa.astro.ui.get_data函数的典型用法代码示例。如果您正苦于以下问题:Python get_data函数的具体用法?Python get_data怎么用?Python get_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name, filename): # name means datid!!
self.name = name
sau.load_pha(name, filename)
self.data = sau.get_data(name)
self.arf = sau.get_data(name)
self.rmf = sau.get_data(name)
try: # Read keywords from pha header
self.threshold = self.data.header['ETH']
except KeyError:
print(" ! WARNING: no threshold found, using 200 GeV")
self.threshold = 2e8 # default value 200 GeV
self.emax = 1e11 # default value 100 TeV
try:
self.zenith = self.data.header['ZENITH']
except KeyError:
print("WARNING: no mean zenith angle found, using 45 deg")
self.zenith = 45.0 # default value 200 GeV
try:
self.offset = self.data.header['OFFSET']
except KeyError:
print("WARNING: no offset angle found, using 1.0 deg")
self.offset = 1.0 # default value 200 GeV
try:
self.telcode = self.data.header['TELCODE']
except KeyError:
print("WARNING: no telcode found, using 0")
self.telcode = 0 # default value 200 GeV
示例2: __init__
def __init__(self, name, filename=None):
self.name = name
if filename is not None:
sau.load_pha(name, filename)
self.data = sau.get_data(name)
self.arf = self.data.get_arf()
self.rmf = self.data.get_rmf()
# Read keywords from pha header
try:
self.threshold = self.data.header['ETH']
except KeyError:
print("WARNING: no threshold found using 200 GeV")
self.threshold = 2e8 # default value 200 GeV
self.emax = 1e11 # default value 100 TeV
try:
self.zenith = self.data.header['ZENITH']
except KeyError:
print("WARNING: no mean zenith angle found using 45 deg")
self.zenith = 45.0 # default value 45 deg
try:
self.offset = self.data.header['OFFSET']
except KeyError:
print("WARNING: no offset angle found using 1.0 deg")
self.offset = 1.0 # default value 1 deg
try:
self.n_tels = self.data.header['N_TELS']
except KeyError:
print("WARNING: no number of telescopes found using 0")
self.n_tels = 0 # default value
try:
self.eff = self.data.header['EFFICIEN']
except KeyError:
print("WARNING: no efficiency found using 1.0")
self.eff = 1.00 # default value
try:
self.tstart = self.data.header['TSTART']
except KeyError:
print("WARNING: no tstart found using 0")
self.tstart = 0. # default value
try:
self.tstop = self.data.header['TSTOP']
except KeyError:
print("WARNING: no tstop found using tsart+1800")
self.tstop = self.tstart + 1800 # default value
else:
self.data = sau.get_data(name)
self.arf = self.data.get_arf()
self.rmf = self.data.get_rmf()
示例3: query
def query(self, func):
output = []
for dataset in self.filter_datasets():
id = dataset['id']
if func(ui.get_data(id)):
output.append(id)
return output
示例4: center_psf
def center_psf(self):
"""Set ``xpos`` and ``ypos`` of the PSF to the dataspace center."""
import sherpa.astro.ui as sau
try:
ny, nx = sau.get_data().shape
for _ in ['psf1', 'psf2', 'psf3']:
par = sau.get_par(_ + '.xpos')
par.val = nx / 2.
par = sau.get_par(_ + '.ypos')
par.val = ny / 2.
except:
raise Exception('PSF is not centered.')
示例5: setUp
def setUp(self):
self._old_logger_level = logger.getEffectiveLevel()
logger.setLevel(logging.ERROR)
ui.set_stat('wstat')
infile = self.make_path('3c273.pi')
ui.load_pha(1, infile)
# Change the backscale value slightly so that the
# results are different to other runs with this file.
#
nbins = ui.get_data(1).get_dep(False).size
bscal = 0.9 * np.ones(nbins) * ui.get_backscal(1)
ui.set_backscal(1, backscale=bscal)
ui.set_source(1, ui.powlaw1d.pl)
# The powerlaw slope and normalization are
# intended to be "a reasonable approximation"
# to the data, just to make sure that any statistic
# calculation doesn't blow-up too much.
#
ui.set_par("pl.gamma", 1.7)
ui.set_par("pl.ampl", 1.7e-4)
示例6: validate_pha
def validate_pha(self, idval):
"""Check that the PHA dataset in id=idval is
as expected.
"""
self.assertEqual(ui.list_data_ids(), [idval])
pha = ui.get_data(idval)
self.assertIsInstance(pha, DataPHA)
arf = ui.get_arf(idval)
self.assertIsInstance(arf, ARF1D)
rmf = ui.get_rmf(idval)
self.assertIsInstance(rmf, RMF1D)
bpha = ui.get_bkg(idval, bkg_id=1)
self.assertIsInstance(bpha, DataPHA)
barf = ui.get_arf(idval, bkg_id=1)
self.assertIsInstance(barf, ARF1D)
brmf = ui.get_rmf(idval, bkg_id=1)
self.assertIsInstance(brmf, RMF1D)
# normally the background data set would have a different name,
# but this is a PHA Type 3 file.
# self.assertEqual(pha.name, bpha.name)
self.assertEqual(arf.name, barf.name)
self.assertEqual(rmf.name, brmf.name)
示例7: test_load_table_fits
def test_load_table_fits(self):
# QUS: why is this not in the sherpa-test-data repository?
this_dir = os.path.dirname(os.path.abspath(__file__))
ui.load_table(1, os.path.join(this_dir, 'data', 'two_column_x_y.fits.gz'))
data = ui.get_data(1)
self.assertEqualWithinTol(data.x, [1, 2, 3])
self.assertEqualWithinTol(data.y, [4, 5, 6])
示例8: setUp
def setUp(self):
# hide warning messages from file I/O
self._old_logger_level = logger.level
logger.setLevel(logging.ERROR)
self._id = 1
fname = self.make_path('3c273.pi')
ui.load_pha(self._id, fname)
self._pha = ui.get_data(self._id)
示例9: _check_stat
def _check_stat(self, nbins, expected):
# check the filter sizes (mainly so that these tests
# get flagged as in need of a look if anything changes
# in other parts of the code, such as filtering and binning
#
self.assertEqual(nbins, ui.get_data().get_dep(True).size)
stat = ui.calc_stat()
self.assertAlmostEqual(expected, stat, places=7)
示例10: testReadImplicit
def testReadImplicit(self):
"""Exclude .gz from the file name"""
idval = "13"
fname = self.head + '_pha3.fits'
ui.load_pha(idval, fname)
self.validate_pha(idval)
pha = ui.get_data(idval)
bpha = ui.get_bkg(idval, bkg_id=1)
self.assertEqual(pha.name, bpha.name)
示例11: center_psf
def center_psf(self):
"""Set xpos and ypos of the PSF to the dataspace center"""
import sherpa.astro.ui as sau
try:
ny, nx = sau.get_data().shape
for par in sau.get_psf().kernel.pars:
if par.name is 'xpos':
par.val = (nx + 1) / 2.
elif par.name is 'ypos':
par.val = (ny + 1) / 2.
except:
logging.warning('PSF is not centered.')
示例12: center_psf
def center_psf(self):
"""Set ``xpos`` and ``ypos`` of the PSF to the dataspace center."""
import sherpa.astro.ui as sau
try:
ny, nx = sau.get_data().shape
for par in sau.get_psf().kernel.pars:
if par.name is 'xpos':
par.val = (nx + 1) / 2.
elif par.name is 'ypos':
par.val = (ny + 1) / 2.
except:
raise Exception('PSF is not centered.')
示例13: containment_fraction
def containment_fraction(self, theta, npix=1000):
"""Compute fraction of PSF contained inside theta."""
import sherpa.astro.ui as sau
sau.dataspace2d((npix, npix))
self.set()
# x_center = get_psf().kernel.pars.xpos
# y_center = get_psf().kernel.pars.ypos
x_center, y_center = sau.get_psf().model.center
x_center, y_center = x_center + 0.5, y_center + 0.5 # shift seen on image.
x, y = sau.get_data().x0, sau.get_data().x1
# @note Here we have to use the source image, before I used
# get_model_image(), which returns the PSF-convolved PSF image,
# which is a factor of sqrt(2) ~ 1.4 too wide!!!
p = sau.get_source_image().y.flatten()
p /= np.nansum(p)
mask = (x - x_center) ** 2 + (y - y_center) ** 2 < theta ** 2
fraction = np.nansum(p[mask])
if 0: # debug
sau.get_data().y = p
sau.save_data('psf_sherpa.fits', clobber=True)
sau.get_data().y = mask.astype('int')
sau.save_data('mask_sherpa.fits', clobber=True)
return fraction
示例14: testReadExplicit
def testReadExplicit(self):
"""Include .gz in the file name"""
idval = 12
fname = self.head + '_pha3.fits.gz'
ui.load_pha(idval, fname)
self.validate_pha(idval)
# TODO: does this indicate that the file name, as read in,
# should have the .gz added to it to match the data
# read in, or left as is?
pha = ui.get_data(idval)
bpha = ui.get_bkg(idval, bkg_id=1)
self.assertEqual(pha.name, bpha.name + '.gz')
示例15: test_xmm2
def test_xmm2(self):
self.run_thread('xmm2')
self.assertEqualWithinTol(ui.get_data().channel[0], 1.0, 1e-4)
self.assertEqual(ui.get_rmf().detchans, 800)
self.assertEqual(len(ui.get_rmf().energ_lo), 2400)
self.assertEqual(len(ui.get_rmf().energ_hi), 2400)
self.assertEqual(len(ui.get_rmf().n_grp), 2400)
self.assertEqual(len(ui.get_rmf().f_chan), 2394)
self.assertEqual(len(ui.get_rmf().n_chan), 2394)
self.assertEqual(len(ui.get_rmf().matrix), 1281216)
self.assertEqual(ui.get_rmf().offset, 0)
self.assertEqual(len(ui.get_rmf().e_min), 800)
self.assertEqual(len(ui.get_rmf().e_max), 800)
self.assertEqual(len(ui.get_arf().energ_lo), 2400)
self.assertEqual(len(ui.get_arf().energ_hi), 2400)
self.assertEqual(len(ui.get_arf().specresp), 2400)