Ejemplo n.º 1
0
    def setup(self):
        self.model = PowerLaw(
            index=Quantity(2, ''),
            amplitude=Quantity(1e-11, 'm-2 s-1 TeV-1'),
            reference=Quantity(1, 'TeV'),
        )

        # TODO: simulate known spectrum instead of using this example:
        filename = '$GAMMAPY_EXTRA/datasets/hess-crab4_pha/pha_obs23523.fits'
        self.obs = SpectrumObservation.read(filename)
        self.seg = SpectrumEnergyGroupMaker(obs=self.obs)
        ebounds = [0.3, 1.001, 3, 10.001, 30] * u.TeV
        self.seg.compute_range_safe()
        self.seg.compute_groups_fixed(ebounds=ebounds)

        self.groups = self.seg.groups
Ejemplo n.º 2
0
joint_fit = SpectrumFit(obs_list=extraction.spectrum_observations,
                        model=model,
                        fit_range=fit_range)
joint_fit.run()
joint_result = joint_fit.result

print(joint_result[0])

# Now you might want to do the stacking here even if in our case there is only one observation which makes it superfluous.
# We can compute flux points by fitting the norm of the global model in energy bands.

# In[ ]:

stacked_obs = extraction.spectrum_observations.stack()
seg = SpectrumEnergyGroupMaker(obs=stacked_obs)

seg.compute_groups_fixed(ebounds=ebounds)
fpe = FluxPointEstimator(obs=stacked_obs,
                         groups=seg.groups,
                         model=joint_result[0].model)
flux_points = fpe.run()

amplitude_ref = 0.57 * 19.4e-14 * u.Unit("1 / (cm2 s MeV)")
spec_model_true = PowerLaw(index=4.5,
                           amplitude=amplitude_ref,
                           reference="20 GeV")

spectrum_result = SpectrumResult(points=flux_points,
                                 model=joint_result[0].model)
Ejemplo n.º 3
0
"""Test spectrum energy grouping.
"""
import warnings
import astropy.units as u
from gammapy.spectrum import SpectrumObservation, SpectrumEnergyGroupMaker

warnings.filterwarnings('ignore')

filename = '$GAMMAPY_EXTRA/datasets/hess-crab4_pha/pha_obs23523.fits'
obs = SpectrumObservation.read(filename)
table = obs.stats_table()

seg = SpectrumEnergyGroupMaker(obs=obs)
ebounds = [0.03, 1, 3, 10, 30] * u.TeV
seg.compute_range_safe()
seg.compute_groups_fixed(ebounds=ebounds)

print('\nTable of original energy bins:')
seg.table[['energy_group_idx', 'bin_idx', 'energy_min',
           'energy_max']].pprint(max_lines=-1)

print('\nTable of grouped energy bins:')
seg.groups.to_group_table().pprint(max_lines=-1)

print('\nTable of grouped energy bins:')
seg.groups.to_total_table().pprint(max_lines=-1)

print(seg)