Ejemplo n.º 1
0
def test_cstat():
    import sherpa.stats as ss
    sherpa_stat = ss.CStat()
    data, model, staterror, off_vec = get_test_data()
    desired, fvec = sherpa_stat.calc_stat(data, model, staterror=staterror)

    statsvec = gammapy_stats.cstat(n_on=data, mu_on=model)
    actual = np.sum(statsvec)
    assert_allclose(actual, desired)
Ejemplo n.º 2
0
def test_cstat(test_data):
    import sherpa.stats as ss
    sherpa_stat = ss.CStat()
    data = test_data['n_on']
    model = test_data['mu_sig']
    staterror = test_data['staterror']
    off_vec = test_data['n_off']
    desired, fvec = sherpa_stat.calc_stat(data, model, staterror=staterror)

    statsvec = stats.cstat(n_on=data, mu_on=model)
    actual = np.sum(statsvec)
    assert_allclose(actual, desired)
Ejemplo n.º 3
0
def test_case(args):
    import sherpa.stats as ss

    mu_sig = float(args[1])
    n_on = float(args[2])
    n_off = float(args[3])
    alpha = float(args[4])

    model, data = get_data(mu_sig, n_on, n_off, alpha)
    wstat, cash, cstat = ss.WStat(), ss.Cash(), ss.CStat()

    print('wstat: {}'.format(wstat.calc_stat(model=model, data=data)[0]))
    print('cash: {}'.format(cash.calc_stat(model=model, data=data)[0]))
    print('cstat: {}'.format(cstat.calc_stat(model=model, data=data)[0]))
Ejemplo n.º 4
0
    def statistic(self, stat):
        import sherpa.stats as s

        if isinstance(stat, six.string_types):
            if stat.lower() == 'cstat':
                stat = s.CStat()
            elif stat.lower() == 'wstat':
                stat = s.WStat()
            else:
                raise ValueError("Undefined stat string: {}".format(stat))

        if not isinstance(stat, s.Stat):
            raise ValueError("Only sherpa statistics are supported")

        self._stat = stat
Ejemplo n.º 5
0
    assert isinstance(stat, req)


def test_get_stat_invalid():
    """Errors out with invalid argument"""

    s = Session()
    with pytest.raises(ArgumentTypeErr) as exc:
        s.get_stat(stats.Cash)

    assert str(exc.value) == "'name' must be a string"


@pytest.mark.parametrize("name,req",
                         [("chi2modvar", stats.Chi2ModVar),
                          (stats.CStat(), stats.CStat)])
def test_set_stat(name, req):
    """We can set the statistic"""

    s = Session()
    s.set_stat(name)
    ans = s.get_stat()
    assert isinstance(ans, req)


def test_set_stat_invalid():
    """Errors out with invalid argument"""

    s = Session()
    with pytest.raises(ArgumentTypeErr) as exc:
        s.set_stat(sherpa.models.basic.Const1D)
Ejemplo n.º 6
0
# this is for the error and because of warning messages, but it is not
# clear.
#
@requires_data
@requires_fits
@pytest.mark.parametrize("stat",
                         [None,
                          stats.Chi2(),
                          stats.Chi2ConstVar(),
                          stats.Chi2DataVar(),
                          stats.Chi2Gehrels(),
                          stats.Chi2ModVar(),
                          stats.Chi2XspecVar(),
                          stats.LeastSq(),
                          stats.Cash(),
                          stats.CStat(),
                          stats.WStat()])
def test_astro_data_plot_with_stat_simple(make_data_path, stat):

    from sherpa.astro import io

    infile = make_data_path('3c273.pi')
    pha = io.read_pha(infile)

    # tweak the data set so that we aren't using the default
    # options (it shouldn't matter for this test but just
    # in case).
    #
    # Note that background subtraction would normally be an issue
    # for some of the stats (e.g. WStat), but this shouldn't
    # trigger a problem here.