Esempio n. 1
0
def test_proton_model():
    """
    test import
    """

    from ..sherpa_models import PionDecay

    model = PionDecay()

    model.ampl = 1e36
    model.index = 2.1

    # point calc
    output = model.calc([p.val for p in model.pars], energies)

    # integrated
    output = model.calc([p.val for p in model.pars], elo, xhi=ehi)

    # test as well ECPL
    model.cutoff = 1000

    # Perform a fit to fake data
    ui.load_arrays(1, energies, test_spec_points, test_err_points)
    ui.set_model(model)
    ui.guess()
    # Actual fit is too slow for tests
    # ui.fit()

    # test with integrated data
    ui.load_arrays(1, elo, ehi, test_spec_int, test_err_int, ui.Data1DInt)
    ui.set_model(model)
    ui.guess()
Esempio n. 2
0
def test_guess_warns_no_guess_names_model(caplog, clean_ui):
    """Do we warn when the named model has no guess"""

    ui.load_arrays(1, [1, 2, 3], [-3, 4, 5])
    cpt = DummyModel('dummy')

    assert len(caplog.records) == 0
    ui.guess(cpt)

    assert len(caplog.records) == 1
    lname, lvl, msg = caplog.record_tuples[0]
    assert lname == "sherpa.ui.utils"
    assert lvl == logging.INFO
    assert msg == "WARNING: No guess found for dummy"
Esempio n. 3
0
def test_guess_warns_no_guess_no_argument(caplog, clean_ui):
    """Do we warn when the (implied) model has no guess"""

    ui.load_arrays(1, [1, 2, 3], [-3, 4, 5])
    cpt = DummyModel('dummy')
    ui.set_source(cpt + cpt)

    assert len(caplog.records) == 0
    ui.guess()

    assert len(caplog.records) == 1
    lname, lvl, msg = caplog.record_tuples[0]
    assert lname == "sherpa.ui.utils"
    assert lvl == logging.INFO
    assert msg == "WARNING: No guess found for (dummy + dummy)"
Esempio n. 4
0
def test_electron_models():
    """
    test import
    """

    from ..sherpa_models import InverseCompton, Synchrotron, Bremsstrahlung

    for modelclass in [InverseCompton, Synchrotron, Bremsstrahlung]:
        model = modelclass()

        model.ampl = 1e-8
        model.index = 2.1

        print(model)

        # point calc
        output = model.calc([p.val for p in model.pars], energies)

        # test as well ECPL
        model.cutoff = 100

        # integrated
        output = model.calc([p.val for p in model.pars], elo, xhi=ehi)

        if modelclass is InverseCompton:
            # Perform a fit to fake data
            ui.load_arrays(1, energies, test_spec_points, test_err_points)
            ui.set_model(model)
            ui.guess()
            ui.fit()

            # add FIR and NIR components and test verbose
            model.uNIR.set(1.0)
            model.uFIR.set(1.0)
            model.verbose.set(1)

            # test with integrated data
            ui.load_arrays(1, elo, ehi, test_spec_int, test_err_int,
                           ui.Data1DInt)
            ui.set_model(model)
            ui.guess()
            ui.fit()