Exemplo n.º 1
0
    def get_sherpa_datastack(self):
        """return a sherpa datastack object

         http://cxc.harvard.edu/sherpa/ahelp/datastack.html
         depending on the instrument selected,
         set also the appropriate fit range
         """
        import sherpa.astro.datastack as sh

        data = sh.DataStack()

        if self.name == "joint":
            pha_list = glob.glob(
                f"{self.main_repo_path}/results/spectra/*/pha_*.fits")
        else:
            pha_list = glob.glob(f"{self.spectra_path}/pha_*.fits")

        # load all the OGIP files in the DataStack object
        for pha in pha_list:
            sh.load_data(data, pha)

        # convert the fit range to keV and strip units
        fit_range = self.energy_range.to("keV").value
        data.notice(*fit_range)

        return data
Exemplo n.º 2
0
    def test_case_3(self):
        datastack.load_ascii("@{}".format(self.lisname))
        assert len(ui._session._data) == 2
        assert len(datastack.DATASTACK.datasets) == 2

        datastack.load_data("@{}".format(self.lisname))
        assert len(ui._session._data) == 4
        assert len(datastack.DATASTACK.datasets) == 4

        datastack.load_data("@"+"/".join((self._this_dir, 'data', 'pha.lis')))
        assert len(ui._session._data) == 6
        assert len(datastack.DATASTACK.datasets) == 6
Exemplo n.º 3
0
    def test_case_3(self):
        datastack.load_ascii("@{}".format(self.lisname))
        assert len(ui._session._data) == 2
        assert len(datastack.DATASTACK.datasets) == 2

        datastack.load_data("@{}".format(self.lisname))
        assert len(ui._session._data) == 4
        assert len(datastack.DATASTACK.datasets) == 4

        datastack.load_data("@"+"/".join((self._this_dir, 'data', 'pha.lis')))
        assert len(ui._session._data) == 6
        assert len(datastack.DATASTACK.datasets) == 6
Exemplo n.º 4
0
def test_load_case_3(ds_setup, ds_datadir):

    datadir = ds_datadir
    name1, name2, lisname = create_files()

    try:
        datastack.load_ascii("@{}".format(lisname))
        assert len(ui._session._data) == 2
        assert len(datastack.DATASTACK.datasets) == 2

        datastack.load_data("@{}".format(lisname))
        assert len(ui._session._data) == 4
        assert len(datastack.DATASTACK.datasets) == 4

        datastack.load_data("@" + "/".join((datadir, 'pha.lis')))
        assert len(ui._session._data) == 6
        assert len(datastack.DATASTACK.datasets) == 6

    except:
        remove_files([name1, name2, lisname])
        raise
Exemplo n.º 5
0
from sherpa.astro.datastack import DataStack
import sherpa.astro.datastack as sh

# In[ ]:

import sherpa

sherpa.__version__

# In[ ]:

ds = DataStack()
ANALYSIS_DIR = expandvars("$GAMMAPY_DATA/joint-crab/spectra/hess/")
filenames = glob.glob(ANALYSIS_DIR + "pha_obs*.fits")
for filename in filenames:
    sh.load_data(ds, filename)

# see what is stored
ds.show_stack()

# ## Define source model
#
# We can now use sherpa models. We need to remember that they were designed for X-ray astronomy and energy is written in keV.
#
# Here we start with a simple PL.

# In[ ]:

# Define the source model
ds.set_source("powlaw1d.p1")
Exemplo n.º 6
0
get_ipython().run_line_magic('matplotlib', 'inline')
import matplotlib.pyplot as plt
plt.style.use('ggplot')

import glob  # to list files
from sherpa.astro.datastack import DataStack
import sherpa.astro.datastack as sh

# In[2]:

ANALYSIS_DIR = 'crab_analysis'

ds = DataStack()
pha_list = glob.glob(ANALYSIS_DIR + '/ogip_data/pha_obs*.fits')
for pha in pha_list:
    sh.load_data(ds, pha)

# see what is stored
ds.show_stack()

# ## Creating the source model
#
# We can now use sherpa models. We need to remember that they were designed for X-ray astronomy and energy is written in keV.
#
# Here we start with a simple PL.

# In[3]:

# Define the source model
ds.set_source("powlaw1d.p1")