def test_source_component_arbitrary_grid_int(): from sherpa.astro.ui.utils import Session from sherpa.models import Const1D from sherpa.data import Data1DInt ui = Session() x = numpy.array([1, 2, 3]), numpy.array([2, 3, 4]) y = [1.5, 2.5, 3.5] re_x = numpy.array([10, 20, 30]), numpy.array([20, 30, 40]) ui.load_arrays(1, x[0], x[1], y, Data1DInt) model = Const1D('c') model.c0 = 10 regrid_model = model.regrid(*re_x) with pytest.warns(UserWarning): ui.plot_source_component(regrid_model) x_points = (x[0] + x[1]) / 2 re_x_points = (re_x[0] + re_x[1]) / 2 points = numpy.concatenate((x_points, re_x_points)) numpy.testing.assert_array_equal(ui._compsrcplot.x, points) numpy.testing.assert_array_equal(ui._compsrcplot.y, [10, 10, 10, 100, 100, 100])
def test_show_bkg_model(): session = Session() session.load_arrays(1, [1, 2], [1, 2]) session.show_bkg_model() session.show_bkg_model('xx') session.show_bkg_source() session.show_bkg_source('xx')
def test_source_component_arbitrary_grid_int(): from sherpa.astro.ui.utils import Session from sherpa.models import Const1D from sherpa.data import Data1DInt ui = Session() x = numpy.array([1, 2, 3]), numpy.array([2, 3, 4]) y = [1.5, 2.5, 3.5] re_x = numpy.array([10, 20, 30]), numpy.array([20, 30, 40]) ui.load_arrays(1, x[0], x[1], y, Data1DInt) model = Const1D('c') model.c0 = 10 regrid_model = model.regrid(*re_x) with pytest.warns(UserWarning): ui.plot_source_component(regrid_model) x_points = (x[0] + x[1])/2 re_x_points = (re_x[0] + re_x[1])/2 points = numpy.concatenate((x_points, re_x_points)) numpy.testing.assert_array_equal(ui._compsrcplot.x, points) numpy.testing.assert_array_equal(ui._compsrcplot.y, [10, 10, 10, 100, 100, 100])
def test_list_ids(): session = Session() session.load_arrays(1, TEST, TEST) session.load_arrays("1", TEST, TEST2) # order of 1 and "1" is not determined assert {1, "1"} == set(session.list_data_ids()) assert_array_equal(TEST2, session.get_data('1').get_dep()) assert_array_equal(TEST, session.get_data(1).get_dep())
def test_save_restore(tmpdir): outfile = tmpdir.join("sherpa.save") session = Session() session.load_arrays(1, TEST, TEST2) session.save(str(outfile), clobber=True) session.clean() assert set() == set(session.list_data_ids()) session.restore(str(outfile)) assert {1, } == set(session.list_data_ids()) assert_array_equal(TEST, session.get_data(1).get_indep()[0]) assert_array_equal(TEST2, session.get_data(1).get_dep())
def test_load_arrays_no_errors(data_no_errors): from sherpa.astro.ui.utils import Session session = Session() data = data_no_errors data_class = data.__class__ data_args = DATA_NO_ERRORS_ARGS args = data_args + (data_class, ) session.load_arrays(*args) new_data = session.get_data(data.name) assert new_data is not data # DATA-NOTE: Do we need an equality operator for data classes? These tests are very partial # Note that when they are created with load_arrays they seem to lose the name, which becomes the ID numpy.testing.assert_array_equal(new_data.get_indep(), data.get_indep()) numpy.testing.assert_array_equal(new_data.get_dep(), data.get_dep())
def test_save_restore(tmpdir): outfile = tmpdir.join("sherpa.save") session = Session() session.load_arrays(1, TEST, TEST2) session.save(str(outfile), clobber=True) session.clean() assert set() == set(session.list_data_ids()) session.restore(str(outfile)) assert { 1, } == set(session.list_data_ids()) assert_array_equal(TEST, session.get_data(1).get_indep()[0]) assert_array_equal(TEST2, session.get_data(1).get_dep())
def test_zero_division_calc_stat(): ui = Session() x = numpy.arange(100) y = numpy.zeros(100) ui.load_arrays(1, x, y, DataPHA) ui.group_counts(1, 100) ui.set_full_model(1, Const1D("const")) # in principle I wouldn't need to call calc_stat_info(), I could just # use _get_stat_info to reproduce the issue, However, _get_stat_info is not a public # method, so I want to double check that calc_stat_info does not throw an exception. # So, first we try to run calc_stat_info and make sure there are no exceptions. # Then, since calc_stat_info only logs something and doesn't return anything, we use # a white box approach to get the result from _get_stat_info. ui.calc_stat_info() assert ui._get_stat_info()[0].rstat is numpy.nan
def test_zero_division_calc_stat(): ui = AstroSession() x = numpy.arange(100) y = numpy.zeros(100) ui.load_arrays(1, x, y, DataPHA) ui.group_counts(1, 100) ui.set_full_model(1, Const1D("const")) # in principle I wouldn't need to call calc_stat_info(), I could just # use _get_stat_info to reproduce the issue, However, _get_stat_info is not a public # method, so I want to double check that calc_stat_info does not throw an exception. # So, first we try to run calc_stat_info and make sure there are no exceptions. # Then, since calc_stat_info only logs something and doesn't return anything, we use # a white box approach to get the result from _get_stat_info. ui.calc_stat_info() assert ui._get_stat_info()[0].rstat is numpy.nan
def test_source_component_arbitrary_grid_int(): ui = Session() x = numpy.array([1, 2, 3]), numpy.array([2, 3, 4]) y = [1.5, 2.5, 3.5] re_x = numpy.array([10, 20, 30]), numpy.array([20, 30, 40]) ui.load_arrays(1, x[0], x[1], y, Data1DInt) model = Const1D('c') model.c0 = 10 regrid_model = model.regrid(*re_x) ui.plot_source_component(regrid_model) x_points = (x[0] + x[1]) / 2.0 numpy.testing.assert_array_equal(ui._compsrcplot.x, x_points) numpy.testing.assert_array_equal(ui._compsrcplot.y, [0., 0., 0.])
def test_plot_model_arbitrary_grid_integrated(): ui = Session() x = [1, 2, 3], [2, 3, 4] y = [1, 2, 3] re_x = [10, 20, 30], [20, 30, 40] ui.load_arrays(1, x[0], x[1], y, Data1DInt) model = Const1D('c') model.c0 = 10 regrid_model = model.regrid(*re_x) ui.set_model(regrid_model) with pytest.warns(UserWarning): ui.plot_model() numpy.testing.assert_array_equal(ui._modelplot.x, [1.5, 2.5, 3.5]) numpy.testing.assert_array_equal(ui._modelplot.y, [10, 10, 10])
def test_source_component_arbitrary_grid(): ui = Session() x = [1, 2, 3] y = [1, 2, 3] re_x = [10, 20, 30] ui.load_arrays(1, x, y) model = Const1D('c') model.c0 = 10 regrid_model = model.regrid(re_x) with pytest.warns(UserWarning): ui.plot_source_component(regrid_model) numpy.testing.assert_array_equal(ui._compsrcplot.x, x + re_x) numpy.testing.assert_array_equal(ui._compsrcplot.y, [ 10, ] * 6)
def test_source_component_arbitrary_grid(): from sherpa.astro.ui.utils import Session from sherpa.models import Const1D ui = Session() x = [1, 2, 3] y = [1, 2, 3] re_x = [10, 20, 30] ui.load_arrays(1, x, y) model = Const1D('c') model.c0 = 10 regrid_model = model.regrid(re_x) with pytest.warns(UserWarning): ui.plot_source_component(regrid_model) numpy.testing.assert_array_equal(ui._compsrcplot.x, x + re_x) numpy.testing.assert_array_equal(ui._compsrcplot.y, [10, ]*6)
def test_plot_model_arbitrary_grid_integrated(): from sherpa.astro.ui.utils import Session from sherpa.models import Const1D from sherpa.data import Data1DInt ui = Session() x = [1, 2, 3], [2, 3, 4] y = [1, 2, 3] re_x = [10, 20, 30], [20, 30, 40] ui.load_arrays(1, x[0], x[1], y, Data1DInt) model = Const1D('c') model.c0 = 10 regrid_model = model.regrid(*re_x) ui.set_model(regrid_model) with pytest.warns(UserWarning): ui.plot_model() numpy.testing.assert_array_equal(ui._modelplot.x, [1.5, 2.5, 3.5]) numpy.testing.assert_array_equal(ui._modelplot.y, [10, 10, 10])