from astropy.tests.helper import assert_quantity_allclose from gammapy.data import ObservationTable from gammapy.datasets import gammapy_extra from gammapy.spectrum import SpectrumFit, SpectrumObservationGrouping, group_obs_table obs_table_file = gammapy_extra.filename( 'datasets/hess-crab4_pha/observation_table.fits') obs_table = ObservationTable.read(obs_table_file) fit = SpectrumFit.from_observation_table(obs_table) fit.model = 'PL' fit.energy_threshold_low = '1 TeV' fit.energy_threshold_high = '10 TeV' fit.run(method='sherpa') #Use each obs in one group obs_table1 = group_obs_table(obs_table, eff_range=[90, 95], n_eff_bin=5) obs_table1.write('grouped_table1_debug.fits', overwrite=True) grouping = SpectrumObservationGrouping(obs_table1) grouping.run() fit_band2 = SpectrumFit.from_observation_table(grouping.stacked_obs_table) fit_band2.model = 'PL' fit_band2.energy_threshold_low = '1 TeV' fit_band2.energy_threshold_high = '10 TeV' fit_band2.run(method='sherpa') assert_quantity_allclose(fit.result.parameters["index"],
from astropy.tests.helper import assert_quantity_allclose from gammapy.data import ObservationTable from gammapy.datasets import gammapy_extra from gammapy.spectrum import SpectrumFit, SpectrumGrouping, group_obs_table obs_table_file = gammapy_extra.filename( 'datasets/hess-crab4_pha/observation_table.fits') obs_table = ObservationTable.read(obs_table_file) fit = SpectrumFit.from_observation_table(obs_table) fit.model = 'PL' fit.energy_threshold_low = '1 TeV' fit.energy_threshold_high = '10 TeV' fit.run(method='sherpa') #Use each obs in one group obs_table1 = group_obs_table(obs_table, eff_range=[90, 95], n_eff_bin=5) obs_table1.write('grouped_table1_debug.fits', overwrite=True) grouping = SpectrumGrouping(obs_table1) grouping.run() fit_band2 = SpectrumFit.from_observation_table(grouping.stacked_obs_table) fit_band2.model = 'PL' fit_band2.energy_threshold_low = '1 TeV' fit_band2.energy_threshold_high = '10 TeV' fit_band2.run(method='sherpa') assert_quantity_allclose(fit.result.parameters["index"],