Пример #1
0
 def __init__(self, n, model, arf, rmf):
     self.n = n
     RSPModelNoPHA.__init__(self, arf=arf, rmf=rmf, model=model)
     self.elo = numpy.arange(n)
     self.ehi = numpy.arange(n)
     self.lo = numpy.arange(n)
     self.hi = numpy.arange(n)
     self.xlo = numpy.arange(n)
     self.xhi = numpy.arange(n)
Пример #2
0
	def __init__(self, n, model, arf, rmf):
		self.n = n
		RSPModelNoPHA.__init__(self, arf=arf, rmf=rmf, model=model)
		self.elo = numpy.arange(n)
		self.ehi = numpy.arange(n)
		self.lo = numpy.arange(n)
		self.hi = numpy.arange(n)
		self.xlo = numpy.arange(n)
		self.xhi = numpy.arange(n)
def test_rspmodelnopha_matrix_call():
    "What happens calling an RMF (matrix)+ARF with no pha?"

    rdata = create_non_delta_rmf()
    exposure = 200.1
    specresp = np.asarray([
        200.0, 100.0, 0.0, 175.0, 300.0, 400.0, 350.0, 200.0, 250.0, 300.0,
        200.0, 100.0, 100.0, 150.0, 175.0, 125.0, 100.0, 90.0, 80.0, 0.0
    ])
    adata = create_arf(rdata.energ_lo,
                       rdata.energ_hi,
                       specresp,
                       exposure=exposure)

    constant = 2.3
    slope = -0.25
    mdl = Polynom1D('mdl')
    mdl.c0 = constant
    mdl.c1 = slope

    wrapped = RSPModelNoPHA(adata, rdata, mdl)

    # Calculate the model analytically. Note that the exposure
    # value is ignored.
    #
    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)
def test_rspmodelnopha_delta_call():
    "What happens calling an RMF (delta)+ARF with no pha?"

    exposure = 200.1
    egrid = np.arange(0.01, 0.06, 0.01)
    elo = egrid[:-1]
    ehi = egrid[1:]
    specresp = np.asarray([1.2, 0.0, 0.5, 4.3])
    rdata = create_delta_rmf(elo, ehi)
    adata = create_arf(elo, ehi, specresp, exposure=exposure)

    constant = 2.3
    mdl = Const1D('flat')
    mdl.c0 = constant

    wrapped = RSPModelNoPHA(adata, rdata, 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).
    #
    de = egrid[1:] - egrid[:-1]
    expected = constant * specresp * de
    out = wrapped([4, 5])
    assert_allclose(out, expected)
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])
Пример #6
0
    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([])")

dump("inst([]).sum()")