def test_err_estimate_model(strings, idval, otherids, clean_ui): """Ensure we can use model with conf/proj/covar. This is test_err_estimate_multi_ids but - added an extra model to each source (that evaluates to 0) - we include the model expression in the call. The fit and error analysis should be the same however the ordering is done. """ # This is a bit ugly if strings: idval = str(idval) if type(otherids) == tuple: otherids = (str(otherids[0]), str(otherids[1])) else: otherids = [str(otherids[0]), str(otherids[1])] datasets = tuple([idval] + list(otherids)) setup_err_estimate_multi_ids(strings=strings) zero = ui.create_model_component("scale1d", "zero") zero.c0 = 0 zero.c0.freeze() for id in datasets: # In this case we have # orig == mdl # but let's be explicit in case the code changes # orig = ui.get_source(id) ui.set_source(id, orig + zero) ui.fit(idval, *otherids) res = ui.get_fit_results() assert res.datasets == datasets assert res.numpoints == 10 assert res.statval == pytest.approx(3.379367979541458) assert ui.calc_stat() == pytest.approx(4255.615602052843) assert mdl.c0.val == pytest.approx(46.046607302070015) assert mdl.c1.val == pytest.approx(-1.9783953989993386) # I wanted to have zero.co thawed at this stage, but then we can not # use the ERR_EST_C0/1_xxx values as the fit has changed (and mdl.c0 # and zero.c0 are degenerate to boot). # ui.conf(*datasets, mdl) res = ui.get_conf_results() assert res.datasets == datasets assert res.parnames == ("mdl.c0", "mdl.c1") assert res.parmins == pytest.approx([ERR_EST_C0_MIN, ERR_EST_C1_MIN]) assert res.parmaxes == pytest.approx([ERR_EST_C0_MAX, ERR_EST_C1_MAX])
def test_ui_source_methods_with_full_model(clean_ui, setup_ui_full): ui.load_data('full', setup_ui_full.ascii) ui.set_full_model('full', 'powlaw1d.p1') # Test Case 1 with pytest.raises(IdentifierErr) as exc: ui.get_source('full') emsg = "Convolved model\n'powlaw1d.p1'\n is set for dataset full. You should use get_model instead." assert str(exc.value) == emsg with pytest.raises(IdentifierErr) as exc: ui.plot_source('full') emsg = "Convolved model\n'powlaw1d.p1'\n is set for dataset full. You should use plot_model instead." assert str(exc.value) == emsg with pytest.raises(IdentifierErr) as exc: ui.get_source_plot('full') emsg = "Convolved model\n'powlaw1d.p1'\n is set for dataset full. You should use get_model_plot instead." assert str(exc.value) == emsg # Test Case 2 ui.set_source('full', 'powlaw1d.p2') ui.get_source('full') # Test Case 3 ui.load_data('not_full', setup_ui_full.ascii) with pytest.raises(IdentifierErr) as exc: ui.get_source('not_full') emsg = 'source not_full has not been set, consider using set_source() or set_model()' assert emsg == str(exc.value)
def test_source_methods_with_full_model(self): from sherpa.utils.err import IdentifierErr ui.load_data('full', self.ascii) ui.set_full_model('full', 'powlaw1d.p1') # Test Case 1 try: ui.get_source('full') except IdentifierErr as e: self.assertRegex( str(e), "Convolved model\n.*\n is set for dataset full. You should use get_model instead.", str(e)) try: ui.plot_source('full') except IdentifierErr as e: self.assertRegex( str(e), "Convolved model\n.*\n is set for dataset full. You should use plot_model instead.", str(e)) # Test Case 2 ui.set_source('full', 'powlaw1d.p2') ui.get_source('full') # Test Case 3 ui.load_data('not_full', self.ascii) try: ui.get_source('not_full') except IdentifierErr as e: self.assertEqual( 'source not_full has not been set, consider using set_source() or set_model()', str(e))
def test_source_methods_with_full_model(self): from sherpa.utils.err import IdentifierErr ui.load_data('full', self.ascii) ui.set_full_model('full', 'powlaw1d.p1') # Test Case 1 try: ui.get_source('full') except IdentifierErr as e: self.assertRegexpMatches(str(e), "Convolved model\n.*\n is set for dataset full. You should use get_model instead.", str(e)) try: ui.plot_source('full') except IdentifierErr as e: self.assertEquals("Convolved model\n'p1'\n is set for dataset full. You should use plot_model instead.", str(e)) # Test Case 2 ui.set_source('full', 'powlaw1d.p2') ui.get_source('full') # Test Case 3 ui.load_data('not_full', self.ascii) try: ui.get_source('not_full') except IdentifierErr as e: self.assertEquals('source not_full has not been set, consider using set_source() or set_model()', str(e))
def test_set_full_model(self): ui.load_psf("psf1", "gauss2d.g1") ui.set_full_model("psf1(gauss2d.g2)+const2d.c1") ui.get_model() ui.get_source()
# coding: utf-8 import sherpa.ui as ui ui.load_data("load_template_without_interpolation-bb_data.dat") ui.load_template_model('bb1', "bb_index.dat", template_interpolator_name=None) ui.set_source('bb1') assert ui.get_source().is_discrete ui.set_source('bb1*const1d.c1+gauss1d.g2**const1d.c2') assert ui.get_source().is_discrete
def test_set_full_model(self): ui.load_psf('psf1', 'gauss2d.g1') ui.set_full_model('psf1(gauss2d.g2)+const2d.c1') ui.get_model() ui.get_source()