예제 #1
0
    def setUp(self):
        self._old_logger_level = logger.getEffectiveLevel()
        logger.setLevel(logging.ERROR)
        from sherpa.astro.io import read_pha
        from sherpa.astro import xspec

        # Ensure we have a known set of XSPEC settings.
        # At present this is just the abundance and cross-section,
        # since the cosmology settings do not affect any of the
        # models used here.
        #
        self._xspec_settings = {
            'abund': xspec.get_xsabund(),
            'xsect': xspec.get_xsxsect()
        }

        xspec.set_xsabund('angr')
        xspec.set_xsxsect('bcmc')

        pha_fname = self.make_path("9774.pi")
        self.data = read_pha(pha_fname)
        self.data.notice(0.5, 7.0)

        bkg_fname = self.make_path("9774_bg.pi")
        self.bkg = read_pha(bkg_fname)

        abs1 = xspec.XSphabs('abs1')
        p1 = PowLaw1D('p1')
        self.model = abs1 + p1

        self.model_mult = abs1 * p1
        pi2278 = self.make_path("pi2278.fits")
        pi2286 = self.make_path("pi2286.fits")
        self.data_pi2278 = read_pha(pi2278)
        self.data_pi2286 = read_pha(pi2286)
예제 #2
0
    def tearDown(self):
        from sherpa.astro import xspec

        self._xspec_settings = {
            'abund': xspec.get_xsabund(),
            'xsect': xspec.get_xsxsect()
        }

        xspec.set_xsabund(self._xspec_settings['abund'])
        xspec.set_xsxsect(self._xspec_settings['xsect'])

        if hasattr(self, "_old_logger_level"):
            logger.setLevel(self._old_logger_level)
예제 #3
0
파일: test_astro.py 프로젝트: JBris/sherpa
def test_proj_bubble(run_thread):

    # How sensitive are the results to the change from bcmc to vern
    # made in XSPEC 12.10.1? It looks like the mekal best-fit
    # temperature can jump from ~17.9 to 18.6, so require bcmc
    # in this test.
    #
    xspec.set_xsxsect('bcmc')
    models = run_thread('proj_bubble')

    fit_results = ui.get_fit_results()
    covarerr = sqrt(fit_results.extra_output['covar'].diagonal())
    assert covarerr[0] == approx(0, rel=1e-4)
    assert covarerr[1] == approx(8.74608e-07, rel=1e-2)

    # Fit -- Results from reminimize
    assert models['mek1'].kt.val == approx(17.8849, rel=1e-2)
    assert models['mek1'].norm.val == approx(4.15418e-06, rel=1e-2)

    # Fit -- Results from reminimize

    # The fit results change in XSPEC 12.10.0 since the mekal model
    # was changed (FORTRAN to C++). A 1% difference is used for the
    # parameter ranges from covar and proj (matches the tolerance for
    # the fit results). Note that this tolerance has been relaced to
    # 10% for the kT errors, as there is a significant change seen
    # with different XSPEC versions for the covariance results.
    #

    # Covar
    #
    # TODO: should this check that parmaxes is -1 * parmins instead?
    covar = ui.get_covar_results()
    assert covar.parmins[0] == approx(-0.328832, rel=0.1)
    assert covar.parmins[1] == approx(-8.847916e-7, rel=0.01)
    assert covar.parmaxes[0] == approx(0.328832, rel=0.1)
    assert covar.parmaxes[1] == approx(8.847916e-7, rel=0.01)

    # Proj -- Upper bound of kT can't be found
    #
    proj = ui.get_proj_results()
    assert proj.parmins[0] == approx(-12.048069, rel=0.01)
    assert proj.parmins[1] == approx(-9.510913e-07, rel=0.01)
    assert proj.parmaxes[1] == approx(2.403640e-06, rel=0.01)

    assert proj.parmaxes[0] is None
예제 #4
0
def reset_xspec():

    from sherpa.astro import xspec

    # Ensure we have a known set of XSPEC settings.
    # At present this is just the abundance and cross-section,
    # since the cosmology settings do not affect any of the
    # models used here.
    #
    abund = xspec.get_xsabund()
    xsect = xspec.get_xsxsect()

    xspec.set_xsabund('angr')
    xspec.set_xsxsect('bcmc')

    yield

    xspec.set_xsabund(abund)
    xspec.set_xsxsect(xsect)
예제 #5
0
def fix_xspec(clean_astro_ui, hide_logging):
    """As of XSPEC 12.11.1 it's useful to fix abundance/cross sections
    rather than rely on reading from the user's directory

    This requires XSPEC support.
    """

    # As of XSPEC 12.10.1, it is safest to explicitly set
    # the state to a known value. For now just pick the
    # "easy" settings.
    #
    abund = xspec.get_xsabund()
    xsect = xspec.get_xsxsect()

    xspec.set_xsabund('angr')
    xspec.set_xsxsect('bcmc')

    yield

    xspec.set_xsabund(abund)
    xspec.set_xsxsect(xsect)
예제 #6
0
파일: test_astro.py 프로젝트: JBris/sherpa
    def setUp(self):
        self.is_crates_io = False
        try:
            import sherpa.astro.io
            if "sherpa.astro.io.crates_backend" == sherpa.astro.io.backend.__name__:
                self.is_crates_io = True
        except ImportError:
            self.is_crates_io = False

        self.old_state = ui._session.__dict__.copy()
        self.old_level = logger.getEffectiveLevel()
        logger.setLevel(logging.CRITICAL)

        # Store XSPEC settings, if applicable
        if has_xspec:
            self.old_xspec = xspec.get_xsstate()
            # As of XSPEC 12.10.1, it is safest to explicitly set
            # the state to a known value. For now just pick the
            # "easy" settings.
            #
            xspec.set_xsabund('angr')
            xspec.set_xsxsect('bcmc')