本文整理汇总了Python中sherpa.astro.data.DataPHA.set_analysis方法的典型用法代码示例。如果您正苦于以下问题:Python DataPHA.set_analysis方法的具体用法?Python DataPHA.set_analysis怎么用?Python DataPHA.set_analysis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sherpa.astro.data.DataPHA
的用法示例。
在下文中一共展示了DataPHA.set_analysis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rsp_normf_error
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rsp_normf_error(analysis):
"""Check that an error is raised on set_analysis
"""
exposure = 200.1
# rdata is only used to define the grids
rdata = create_non_delta_rmf()
specresp = create_non_delta_specresp()
adata = create_arf(rdata.energ_lo,
rdata.energ_hi,
specresp,
exposure=exposure)
nchans = rdata.e_min.size
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_arf(adata)
with pytest.raises(DataErr) as exc:
pha.set_analysis(analysis)
emsg = "response incomplete for dataset test-pha, " + \
"check the instrument model"
assert str(exc.value) == emsg
示例2: test_arfmodelpha_call
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_arfmodelpha_call(ignore):
"""What happens calling an arf with a pha?
The ignore value indicates what channel to ignore (0 means
nothing is ignored). The aim is to check edge effects,
and as there are only a few channels, it was decided to
test all channels.
"""
# Note: the exposure is set in the PHA and ARF, but should not be
# used when evaluating the model; it's value has been
# set to a value that the test will fail it it is.
#
exposure = 200.1
estep = 0.01
egrid = np.arange(0.01, 0.06, estep)
svals = [1.1, 1.2, 1.3, 1.4]
specresp = np.asarray(svals)
adata = create_arf(egrid[:-1], egrid[1:], specresp,
exposure=exposure)
constant = 2.3
mdl = Const1D('flat')
mdl.c0 = constant
channels = np.arange(1, 5, dtype=np.int16)
counts = np.asarray([10, 5, 12, 7], dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_arf(adata)
# force energy units (only needed if ignore is set)
pha.set_analysis('energy')
if ignore is not None:
de = estep * 0.9
e0 = egrid[ignore]
pha.notice(lo=e0, hi=e0 + de, ignore=True)
# The assert are intended to help people reading this
# code rather than being a useful check that the code
# is working.
mask = [True, True, True, True]
mask[ignore] = False
assert (pha.mask == mask).all()
wrapped = ARFModelPHA(adata, pha, mdl)
# The model is evaluated on the ARF grid, not whatever
# is sent in. It is also integrated across the bins,
# which is why there is a multiplication by the
# grid width (for this constant model).
#
# Note that the filter doesn't change the grid.
#
de = egrid[1:] - egrid[:-1]
expected = constant * np.asarray(svals) * de
out = wrapped([4, 5])
assert_allclose(out, expected)
示例3: test_rspmodelpha_delta_call
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rspmodelpha_delta_call(ignore):
"""What happens calling a rsp with a pha (RMF is a delta fn)?
The ignore value gives the channel to ignore (counting from 0).
"""
exposure = 200.1
estep = 0.025
egrid = np.arange(0.1, 0.8, estep)
elo = egrid[:-1]
ehi = egrid[1:]
specresp = 2.4 * np.ones(elo.size, dtype=np.float32)
specresp[2:5] = 0.0
specresp[16:19] = 3.2
adata = create_arf(elo, ehi, specresp, exposure=exposure)
rdata = create_delta_rmf(elo, ehi, e_min=elo, e_max=ehi)
nchans = elo.size
constant = 2.3
mdl = Const1D('flat')
mdl.c0 = constant
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_rmf(rdata)
# force energy units (only needed if ignore is set)
pha.set_analysis('energy')
if ignore is not None:
de = estep * 0.9
e0 = egrid[ignore]
pha.notice(lo=e0, hi=e0 + de, ignore=True)
# The assert are intended to help people reading this
# code rather than being a useful check that the code
# is working.
mask = [True] * nchans
mask[ignore] = False
assert (pha.mask == mask).all()
wrapped = RSPModelPHA(adata, rdata, pha, mdl)
# The model is evaluated on the RMF grid, not whatever
# is sent in. It is also integrated across the bins,
# which is why there is a multiplication by the
# grid width (for this constant model).
#
# Note that the filter doesn't change the grid.
#
de = egrid[1:] - egrid[:-1]
expected = constant * specresp * de
out = wrapped([4, 5])
assert_allclose(out, expected)
示例4: test_rsp_no_arf_matrix_call
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rsp_no_arf_matrix_call(analysis, phaexp):
"""Check out Response1D with matrix but no ARF
analysis is the analysis setting
arfexp determines whether the arf has an exposure time
phaexp determines whether the PHA has an exposure time
"""
if phaexp:
pha_exposure = 220.9
else:
pha_exposure = None
if phaexp:
exposure = pha_exposure
mdl_label = '({} * flat)'.format(exposure)
else:
exposure = 1.0
mdl_label = 'flat'
rdata = create_non_delta_rmf()
constant = 2.3
mdl = Const1D('flat')
mdl.c0 = constant
# Turn off integration on this model, so that it is not integrated
# across the bin width.
#
mdl.integrate = False
nchans = rdata.e_min.size
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=pha_exposure)
pha.set_rmf(rdata)
rsp = Response1D(pha)
wrapped = rsp(mdl)
assert isinstance(wrapped, ArithmeticModel)
expname = 'apply_rmf({})'.format(mdl_label)
assert wrapped.name == expname
modvals = exposure * constant * np.ones(rdata.energ_lo.size)
matrix = get_non_delta_matrix()
expected = np.matmul(modvals, matrix)
pha.set_analysis(analysis)
out = wrapped([4, 5])
assert_allclose(out, expected)
示例5: test_rspmodelpha_matrix_call
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rspmodelpha_matrix_call(ignore):
"""What happens calling a rsp with a pha (RMF is a matrix)?
The ignore value gives the channel to ignore (counting from 0).
"""
exposure = 200.1
rdata = create_non_delta_rmf()
specresp = create_non_delta_specresp()
elo = rdata.energ_lo
ehi = rdata.energ_hi
adata = create_arf(elo, ehi, specresp, exposure=exposure)
nchans = rdata.e_min.size
constant = 22.3
slope = -1.2
mdl = Polynom1D('sloped')
mdl.c0 = constant
mdl.c1 = slope
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_rmf(rdata)
# force energy units (only needed if ignore is set)
pha.set_analysis('energy')
if ignore is not None:
e0 = rdata.e_min[ignore]
e1 = rdata.e_max[ignore]
de = 0.9 * (e1 - e0)
pha.notice(lo=e0, hi=e0 + de, ignore=True)
# The assert are intended to help people reading this
# code rather than being a useful check that the code
# is working.
mask = [True] * nchans
mask[ignore] = False
assert (pha.mask == mask).all()
wrapped = RSPModelPHA(adata, rdata, pha, mdl)
# The filter does not change the grid
modvals = specresp * mdl(rdata.energ_lo, rdata.energ_hi)
matrix = get_non_delta_matrix()
expected = np.matmul(modvals, matrix)
out = wrapped([4, 5])
assert_allclose(out, expected)
示例6: test_rsp1d_matrix_pha_zero_energy_bin
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rsp1d_matrix_pha_zero_energy_bin():
"""What happens when the first bin starts at 0, with replacement.
Unlike test_rsp1d_delta_pha_zero_energy_bin this directly
calls Response1D to create the model.
"""
ethresh = 1.0e-5
rdata = create_non_delta_rmf()
# hack the first bin to have 0 energy
rdata.energ_lo[0] = 0.0
# PHA and ARF have different exposure ties
exposure_arf = 0.1
exposure_pha = 2.4
specresp = create_non_delta_specresp()
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("always")
adata = create_arf(rdata.energ_lo,
rdata.energ_hi,
specresp,
exposure=exposure_arf,
ethresh=ethresh)
validate_zero_replacement(ws, 'ARF', 'user-arf', ethresh)
nchans = rdata.e_min.size
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure_pha)
pha.set_rmf(rdata)
pha.set_arf(adata)
pha.set_analysis('energy')
mdl = MyPowLaw1D()
rsp = Response1D(pha)
wrapped = rsp(mdl)
# Evaluate the statistic / model. The value was calculated using
# commit a65fb94004664eab219cc09652172ffe1dad80a6 on a linux
# system (Ubuntu 17.04).
#
f = Fit(pha, wrapped)
ans = f.calc_stat()
assert ans == pytest.approx(37971.8716151947)
示例7: test_rmfmodelpha_matrix_call
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rmfmodelpha_matrix_call(ignore):
"""What happens calling an rmf (matrix) with a pha?
The ignore value gives the channel to ignore (counting from 0).
"""
exposure = 200.1
rdata = create_non_delta_rmf()
elo = rdata.e_min
ehi = rdata.e_max
nchans = elo.size
constant = 12.2
slope = 0.01
mdl = Polynom1D('not-flat')
mdl.c0 = constant
mdl.c1 = slope
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_rmf(rdata)
# force energy units (only needed if ignore is set)
pha.set_analysis('energy')
if ignore is not None:
e0 = elo[ignore]
e1 = ehi[ignore]
de = 0.9 * (e1 - e0)
pha.notice(lo=e0, hi=e0 + de, ignore=True)
# The assert are intended to help people reading this
# code rather than being a useful check that the code
# is working.
mask = [True] * nchans
mask[ignore] = False
assert (pha.mask == mask).all()
wrapped = RMFModelPHA(rdata, pha, mdl)
# Note that the evaluation ignores any filter we've applied.
# and the exposure time is not used.
#
modvals = mdl(rdata.energ_lo, rdata.energ_hi)
matrix = get_non_delta_matrix()
expected = np.matmul(modvals, matrix)
out = wrapped([4, 5])
assert_allclose(out, expected)
示例8: test_rspmodelpha_matrix_call_xspec
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rspmodelpha_matrix_call_xspec():
"""Check XSPEC constant is invariant to wavelength/energy setting.
As XSPEC models internally convert from Angstrom to keV,
do a simple check here.
"""
exposure = 200.1
rdata = create_non_delta_rmf()
specresp = create_non_delta_specresp()
adata = create_arf(rdata.energ_lo,
rdata.energ_hi,
specresp,
exposure=exposure)
constant = 2.3
mdl = XSconstant('flat')
mdl.factor = constant
nchans = rdata.e_min.size
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
# The set_arf call isn't necessary, but leave in
pha.set_arf(adata)
pha.set_rmf(rdata)
# The XSPEC models are evaluated on an energy grid, even when
# the analysis setting is wavelength. Also, unlike the Sherpa
# Constant model, the XSPEC XSconstant model is defined
# over the integrated bin, so no correction is needed for the
# bin width.
#
modvals = constant * specresp
matrix = get_non_delta_matrix()
expected = np.matmul(modvals, matrix)
wrapped = RSPModelPHA(adata, rdata, pha, mdl)
pha.set_analysis('wave')
out_wl = wrapped([4, 5])
assert_allclose(out_wl, expected)
pha.set_analysis('energy')
out_en = wrapped([4, 5])
assert_allclose(out_en, expected)
示例9: test_rsp1d_delta_pha_zero_energy_bin
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rsp1d_delta_pha_zero_energy_bin():
"What happens when the first bin starts at 0, with replacement"
ethresh = 2.0e-7
# PHA and ARF have different exposure ties
exposure1 = 0.1
exposure2 = 2.4
egrid = np.asarray([0.0, 0.1, 0.2, 0.4, 0.5, 0.7, 0.8])
elo = egrid[:-1]
ehi = egrid[1:]
specresp = np.asarray([10.2, 9.8, 10.0, 12.0, 8.0, 10.0])
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("always")
adata = create_arf(elo, ehi, specresp, exposure=exposure1,
ethresh=ethresh)
validate_zero_replacement(ws, 'ARF', 'user-arf', ethresh)
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("always")
rdata = create_delta_rmf(elo, ehi, ethresh=ethresh)
validate_zero_replacement(ws, 'RMF', 'delta-rmf', ethresh)
channels = np.arange(1, 7, dtype=np.int16)
counts = np.ones(6, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure2)
pha.set_rmf(rdata)
pha.set_arf(adata)
pha.set_analysis('energy')
mdl = MyPowLaw1D()
tmdl = PowLaw1D()
wrapped = RSPModelPHA(adata, rdata, pha, mdl)
out = wrapped([0.1, 0.2])
elo[0] = ethresh
expected = specresp * tmdl(elo, ehi)
assert_allclose(out, expected)
assert not np.isnan(out[0])
示例10: test_rspmodelpha_delta_call_wave
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rspmodelpha_delta_call_wave():
"""What happens calling a rsp with a pha (RMF is a delta fn)? Wavelength.
Unlike the energy case no bins are ignored, as this code path
has already been tested.
"""
exposure = 200.1
estep = 0.025
egrid = np.arange(0.1, 0.8, estep)
elo = egrid[:-1]
ehi = egrid[1:]
specresp = 2.4 * np.ones(elo.size, dtype=np.float32)
specresp[2:5] = 0.0
specresp[16:19] = 3.2
adata = create_arf(elo, ehi, specresp, exposure=exposure)
rdata = create_delta_rmf(elo, ehi, e_min=elo, e_max=ehi)
nchans = elo.size
constant = 2.3
mdl = Const1D('flat')
mdl.c0 = constant
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_rmf(rdata)
pha.set_analysis('wave')
wrapped = RSPModelPHA(adata, rdata, pha, mdl)
# Note that this is a Sherpa model, so it's normalization is
# per unit x axis, so when integrated here the bins are in
# Angstroms, so the bin width to multiply by is
# Angstroms, not keV.
#
dl = (DataPHA._hc / elo) - (DataPHA._hc / ehi)
expected = constant * specresp * dl
out = wrapped([4, 5])
assert_allclose(out, expected)
示例11: test_arf1d_pha_zero_energy_bin
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_arf1d_pha_zero_energy_bin():
"What happens when the first bin starts at 0, with replacement"
ethresh = 1.0e-10
# Note: the two exposures are different to check which is
# used (the answer is neither, which seems surprising)
#
exposure1 = 0.1
egrid = np.asarray([0.0, 0.1, 0.2, 0.4, 0.5, 0.7, 0.8])
elo = egrid[:-1]
ehi = egrid[1:]
specresp = np.asarray([10.2, 9.8, 10.0, 12.0, 8.0, 10.0])
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("always")
adata = create_arf(elo, ehi, specresp, exposure=exposure1,
ethresh=ethresh)
validate_zero_replacement(ws, 'ARF', 'user-arf', ethresh)
arf = ARF1D(adata)
exposure2 = 2.4
channels = np.arange(1, 7, dtype=np.int16)
counts = np.ones(6, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure2)
pha.set_arf(adata)
pha.set_analysis('energy')
mdl = MyPowLaw1D()
tmdl = PowLaw1D()
wrapped = ARFModelPHA(arf, pha, mdl)
out = wrapped([0.1, 0.2])
elo[0] = ethresh
expected = specresp * tmdl(elo, ehi)
assert_allclose(out, expected)
assert not np.isnan(out[0])
示例12: test_rspmodelpha_delta_call_channel
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rspmodelpha_delta_call_channel():
"""What happens calling a rsp with a pha (RMF is a delta fn)? Channels.
I am not convinced I understand the bin width calculation here,
as it doesn't seem to match the wavelength case.
"""
exposure = 200.1
estep = 0.025
egrid = np.arange(0.1, 0.8, estep)
elo = egrid[:-1]
ehi = egrid[1:]
specresp = 2.4 * np.ones(elo.size, dtype=np.float32)
specresp[2:5] = 0.0
specresp[16:19] = 3.2
adata = create_arf(elo, ehi, specresp, exposure=exposure)
rdata = create_delta_rmf(elo, ehi, e_min=elo, e_max=ehi)
nchans = elo.size
constant = 2.3
mdl = Const1D('flat')
mdl.c0 = constant
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_rmf(rdata)
pha.set_analysis('channel')
wrapped = RSPModelPHA(adata, rdata, pha, mdl)
# Since this is channels you might expect the bin width to be 1,
# but it is actually still dE.
#
de = ehi - elo
expected = constant * specresp * de
out = wrapped([4, 5])
assert_allclose(out, expected)
示例13: test_rmfmodelpha_matrix_mismatch
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rmfmodelpha_matrix_mismatch(analysis):
"""Check that an error is raised if there's a mismatch.
"""
exposure = 200.1
rdata = create_non_delta_rmf()
# nchans should be rdata.e_min.size for the sizes to match
nchans = rdata.energ_lo.size
channels = np.arange(1, nchans + 1, dtype=np.int16)
counts = np.ones(nchans, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_rmf(rdata)
with pytest.raises(DataErr) as exc:
pha.set_analysis(analysis)
emsg = "RMF 'non-delta-rmf' is incompatible with PHA dataset 'test-pha'"
assert str(exc.value) == emsg
示例14: test_rmfmodelpha_delta_no_ebounds
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rmfmodelpha_delta_no_ebounds(analysis):
"""What happens calling an rmf with a pha and no EBOUNDS is set
Ensure we can't filter on energy or wavelength since there's no
EBOUNDS information. This behavior was seen when writing
test_rmfmodelpha_call, so a test was written for it.
"""
estep = 0.01
egrid = np.arange(0.01, 0.06, estep)
rdata = create_delta_rmf(egrid[:-1], egrid[1:])
channels = np.arange(1, 5, dtype=np.int16)
counts = np.asarray([10, 5, 12, 7], dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts)
pha.set_rmf(rdata)
pha.set_analysis(analysis)
with pytest.raises(DataErr) as exc:
pha.notice(0.025, 0.045, ignore=False)
assert str(exc.value) == 'RMF does not specify energy bins'
示例15: test_rmf1d_delta_pha_zero_energy_bin
# 需要导入模块: from sherpa.astro.data import DataPHA [as 别名]
# 或者: from sherpa.astro.data.DataPHA import set_analysis [as 别名]
def test_rmf1d_delta_pha_zero_energy_bin():
"What happens when the first bin starts at 0, with replacement"
ethresh = 2e-7
egrid = np.asarray([0.0, 0.1, 0.2, 0.4, 0.5, 0.7, 0.8])
elo = egrid[:-1]
ehi = egrid[1:]
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("always")
rdata = create_delta_rmf(elo, ehi, ethresh=ethresh)
validate_zero_replacement(ws, 'RMF', 'delta-rmf', ethresh)
exposure = 2.4
channels = np.arange(1, 7, dtype=np.int16)
counts = np.ones(6, dtype=np.int16)
pha = DataPHA('test-pha', channel=channels, counts=counts,
exposure=exposure)
pha.set_rmf(rdata)
pha.set_analysis('energy')
mdl = MyPowLaw1D()
tmdl = PowLaw1D()
wrapped = RMFModelPHA(rdata, pha, mdl)
out = wrapped([0.1, 0.2])
elo[0] = ethresh
expected = tmdl(elo, ehi)
assert_allclose(out, expected)
assert not np.isnan(out[0])