Esempio n. 1
0
def test_rsp1d_delta_no_pha_zero_energy_bin():
    "What happens when the first bin starts at 0, with replacement"

    ethresh = 1.0e-9

    exposure = 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=exposure,
                           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)

    mdl = MyPowLaw1D()
    tmdl = PowLaw1D()

    wrapped = RSPModelNoPHA(adata, rdata, 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])
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])
Esempio n. 3
0
def setup_covar(make_data_path):

    print("A")
    ui.load_data(make_data_path('sim.poisson.1.dat'))
    ui.set_model(PowLaw1D("p1"))
Esempio n. 4
0
y = pha.get_y(filter=True)
dplot.plot(xlog=True, ylog=True)
plt.plot(x, y)
savefig('pha_data_compare.png')

pha.set_analysis('wave')
dump("pha.get_x().max()")
wplot = DataPlot()
wplot.prepare(pha)
wplot.plot()
savefig('pha_data_wave.png')
pha.set_analysis('energy')

from sherpa.models.basic import PowLaw1D
from sherpa.astro.xspec import XSphabs
pl = PowLaw1D()
gal = XSphabs()
mdl = gal * pl
pl.gamma = 1.7
gal.nh = 0.2

report("mdl")

egrid = np.arange(0.1, 10, 0.01)
elo, ehi = egrid[:-1], egrid[1:]
emid = (elo + ehi) / 2

plt.clf()
plt.plot(emid, mdl(elo, ehi), label='Absorbed')
plt.plot(emid, pl(elo, ehi), ':', label='Unabsorbed')
plt.xscale('log')
Esempio n. 5
0
def savefig(name):
    outfile = os.path.join(savedir, name)
    plt.savefig(outfile)
    print("# Created: {}".format(name))


os.chdir('../../../../sherpa-test-data/sherpatest/')

from sherpa.astro.io import read_arf, read_rmf

arf = read_arf('3c273.arf')
rmf = read_rmf('3c273.rmf')
dump("rmf.detchans")

from sherpa.models.basic import PowLaw1D
mdl = PowLaw1D()

from sherpa.astro.instrument import RSPModelNoPHA
inst = RSPModelNoPHA(arf, rmf, mdl)

dump("inst")
report("inst")

from sherpa.models.model import ArithmeticModel
dump("isinstance(inst, ArithmeticModel)")
dump("inst.pars")

dump("inst(np.arange(1, 1025))")
dump("inst([0.1, 0.2, 0.3])")
dump("inst([0.1, 0.2, 0.3]).size")
dump("inst([10, 20]) == inst([])")