Exemplo n.º 1
0
def test_evaluate_xspec_multiplicative_model(make_data_path):
    """Can we evaluate multiplicative table models?

    This is a limited test - in that it does not attempt to
    test the full set of grid inputs that we do with additive
    table models (and other XSPEC models) - as it is assumed that
    this logic hsa been tested.
    """

    from sherpa.astro import xspec

    if xspec.get_xsversion().startswith('12.10.0'):
        pytest.skip('Test known to crash XSPEC 12.10.0')

    path = make_data_path('testpcfabs.mod')
    tbl = xspec.read_xstable_model('bar', path)

    # This extends beyond the range of the model grid
    egrid = np.arange(0.1, 17, 1.0)

    # The expected values, evaluated with XSPEC 12.10.1b using
    # C++ code (i.e. not the Sherpa interface).
    #
    # It appears that the -1 is 1 in earlier versions.
    #
    yexp = np.asarray([0.511674,
                       0.730111,
                       0.898625,
                       0.95572,
                       0.977472,
                       0.987328,
                       0.992138,
                       0.990245,
                       0.992846,
                       0.994674,
                       0.995997,
                       0.996945,
                       0.997616,
                       0.998104,
                       0.998454,
                       -1,
                       0])

    # Note, xspec 12.10.0 should not be seen here as explicitly
    # excluded above.
    xver = xspec.get_xsversion()
    if xver.startswith('12.9.'):
        yexp[-2] = 1.0

    y = tbl(egrid)

    assert_almost_equal(y, yexp, decimal=6)
Exemplo n.º 2
0
def test_evaluate_xspec_additive_model_beyond_grid(make_data_path):
    """Can we extend an additive table model beyond its grid?

    XSPEC 12.10.0 (if not manually patched) will crash if an
    XSPEC table model is evaluated beyond its grid (this is only
    an issue for programs like Sherpa that use XSPEC as a "library").
    """

    from sherpa.astro import xspec

    if xspec.get_xsversion().startswith('12.10.0'):
        pytest.skip('Test known to crash XSPEC 12.10.0')

    path = make_data_path('xspec-tablemodel-RCS.mod')
    tbl = xspec.read_xstable_model('bar', path)

    egrid = np.arange(0.1, 11, 0.01)
    y = tbl(egrid)

    # Several simple regression tests.
    assert y[0] == pytest.approx(0.27216572)
    assert y.max() == pytest.approx(0.3047457)
    assert y.min() == 0.0

    # Is the following worth it?
    minval = 1.2102469e-11
    assert y[y > 0].min() == pytest.approx(minval)
    assert y[967] == pytest.approx(minval)

    zeros = np.where(y <= 0)
    assert (zeros[0] == np.arange(968, 1090)).all()
Exemplo n.º 3
0
def test_evaluate_xspec_additive_model_beyond_grid(make_data_path):
    """Can we extend an additive table model beyond its grid?

    XSPEC 12.10.0 (if not manually patched) will crash if an
    XSPEC table model is evaluated beyond its grid (this is only
    an issue for programs like Sherpa that use XSPEC as a "library").
    """

    from sherpa.astro import xspec

    if xspec.get_xsversion().startswith('12.10.0'):
        pytest.skip('Test known to crash XSPEC 12.10.0')

    path = make_data_path('xspec-tablemodel-RCS.mod')
    tbl = xspec.read_xstable_model('bar', path)

    egrid = np.arange(0.1, 11, 0.01)
    y = tbl(egrid)

    # Several simple regression tests.
    assert y[0] == pytest.approx(0.27216572)
    assert y.max() == pytest.approx(0.3047457)
    assert y.min() == 0.0

    # Is the following worth it?
    minval = 1.2102469e-11
    assert y[y > 0].min() == pytest.approx(minval)
    assert y[967] == pytest.approx(minval)

    zeros = np.where(y <= 0)
    assert (zeros[0] == np.arange(968, 1090)).all()
Exemplo n.º 4
0
def test_evaluate_xspec_multiplicative_model(make_data_path):
    """Can we evaluate multiplicative table models?

    This is a limited test - in that it does not attempt to
    test the full set of grid inputs that we do with additive
    table models (and other XSPEC models) - as it is assumed that
    this logic hsa been tested.
    """

    from sherpa.astro import xspec

    if xspec.get_xsversion().startswith('12.10.0'):
        pytest.skip('Test known to crash XSPEC 12.10.0')

    path = make_data_path('testpcfabs.mod')
    tbl = xspec.read_xstable_model('bar', path)

    # This extends beyond the range of the model grid
    egrid = np.arange(0.1, 17, 1.0)
    elo = egrid[:-1]
    ehi = egrid[1:]

    # The expected values, evaluated with XSPEC 12.10.1b using
    # C++ code (i.e. not the Sherpa interface).
    #
    # It appears that the -1 is 1 in earlier versions.
    #
    yexp = np.asarray([
        0.511674, 0.730111, 0.898625, 0.95572, 0.977472, 0.987328, 0.992138,
        0.990245, 0.992846, 0.994674, 0.995997, 0.996945, 0.997616, 0.998104,
        0.998454, -1
    ])

    # Note, xspec 12.10.0 should not be seen here as explicitly
    # excluded above.
    xver = xspec.get_xsversion()
    if xver.startswith('12.9.'):
        yexp[-1] = 1.0

    y = tbl(elo, ehi)

    assert_almost_equal(y, yexp, decimal=6)
Exemplo n.º 5
0
def test_version():
    """Can we get at the XSPEC version?

    There is limited testing of the return value.
    """

    from sherpa.astro import xspec

    v = xspec.get_xsversion()
    assert isinstance(v, (str, ))
    assert len(v) > 0
Exemplo n.º 6
0
def test_version():
    """Can we get at the XSPEC version?

    There is limited testing of the return value.
    """

    from sherpa.astro import xspec

    v = xspec.get_xsversion()
    assert isinstance(v, six.string_types)
    assert len(v) > 0
Exemplo n.º 7
0
from . import _models

__all__ = ['XSagnslim', 'XSzkerrbb']
if support_convolve:
    __all__.append('XSthcompc')

__all__ = tuple(__all__)

# We need to ensure that the XSPEC model library has been initialized
# before the model is evaluated. This could be handled in the
# Python<->C++ bridge, as it is with the XSPEC module that is
# distributed with CIAO, but here we just ensure that the library
# has been initialized when this module is imported.
#
get_xsversion()


class XSagnslim(XSAdditiveModel):
    """The XSPEC agnslim model: AGN super-Eddington accretion model

    See [1]_

    Attributes
    ----------
    mass
        black hole mass in solar masses
    dist
        comoving (proper) distance in Mpc
    logmdot
        mdot = Mdot / Mdot_edd where eta Mdot_Edd c^2 = L_Edd