def test_spectrum_dataset_stack_nondiagonal_no_bkg(spectrum_dataset): energy = spectrum_dataset.counts.geom.axes[0].edges aeff = EffectiveAreaTable.from_parametrization(energy, "HESS") edisp1 = EDispKernel.from_gauss(energy, energy, 0.1, 0) livetime = 100 * u.s spectrum_dataset1 = SpectrumDataset( counts=spectrum_dataset.counts.copy(), livetime=livetime, aeff=aeff, edisp=edisp1, ) livetime2 = livetime aeff2 = EffectiveAreaTable( energy[:-1], energy[1:], aeff.data.data ) edisp2 = EDispKernel.from_gauss(energy, energy, 0.2, 0.0) spectrum_dataset2 = SpectrumDataset( counts=spectrum_dataset.counts.copy(), livetime=livetime2, aeff=aeff2, edisp=edisp2, ) spectrum_dataset1.stack(spectrum_dataset2) assert spectrum_dataset1.background is None assert spectrum_dataset1.livetime == 2 * livetime assert_allclose( spectrum_dataset1.aeff.data.data.to_value("m2"), aeff.data.data.to_value("m2") ) assert_allclose(spectrum_dataset1.edisp.get_bias(1 * u.TeV), 0.0, atol=1.2e-3) assert_allclose(spectrum_dataset1.edisp.get_resolution(1 * u.TeV), 0.1581, atol=1e-2)
def test_spectrum_dataset_stack_diagonal_safe_mask(spectrum_dataset): geom = spectrum_dataset.counts.geom energy = MapAxis.from_energy_bounds("0.1 TeV", "10 TeV", nbin=30) energy_true = MapAxis.from_energy_bounds("0.1 TeV", "10 TeV", nbin=30, name="energy_true") aeff = EffectiveAreaTable.from_parametrization(energy.edges, "HESS") edisp = EDispKernelMap.from_diagonal_response(energy, energy_true, geom=geom.to_image()) livetime = 100 * u.s background = spectrum_dataset.background spectrum_dataset1 = SpectrumDataset( counts=spectrum_dataset.counts.copy(), livetime=livetime, aeff=aeff, edisp=edisp.copy(), background=background.copy(), ) livetime2 = 0.5 * livetime aeff2 = EffectiveAreaTable(energy.edges[:-1], energy.edges[1:], 2 * aeff.data.data) bkg2 = RegionNDMap.from_geom(geom=geom, data=2 * background.data) geom = spectrum_dataset.counts.geom data = np.ones(spectrum_dataset.data_shape, dtype="bool") data[0] = False safe_mask2 = RegionNDMap.from_geom(geom=geom, data=data) spectrum_dataset2 = SpectrumDataset( counts=spectrum_dataset.counts.copy(), livetime=livetime2, aeff=aeff2, edisp=edisp, background=bkg2, mask_safe=safe_mask2, ) spectrum_dataset1.stack(spectrum_dataset2) reference = spectrum_dataset.counts.data assert_allclose(spectrum_dataset1.counts.data[1:], reference[1:] * 2) assert_allclose(spectrum_dataset1.counts.data[0], 141363) assert spectrum_dataset1.livetime == 1.5 * livetime assert_allclose(spectrum_dataset1.background.data[1:], 3 * background.data[1:]) assert_allclose(spectrum_dataset1.background.data[0], background.data[0]) assert_allclose( spectrum_dataset1.aeff.data.data.to_value("m2"), 4.0 / 3 * aeff.data.data.to_value("m2"), ) kernel = edisp.get_edisp_kernel() kernel_stacked = spectrum_dataset1.edisp.get_edisp_kernel() assert_allclose(kernel_stacked.pdf_matrix[1:], kernel.pdf_matrix[1:]) assert_allclose(kernel_stacked.pdf_matrix[0], 0.5 * kernel.pdf_matrix[0])
def test_spectrum_dataset_stack_nondiagonal_no_bkg(spectrum_dataset): energy = spectrum_dataset.counts.geom.axes["energy"] geom = spectrum_dataset.counts.geom.to_image() edisp1 = EDispKernelMap.from_gauss( energy_axis=energy, energy_axis_true=energy.copy(name="energy_true"), sigma=0.1, bias=0, geom=geom) edisp1.exposure_map.data += 1 aeff = EffectiveAreaTable.from_parametrization( energy.edges, "HESS").to_region_map(geom.region) geom = spectrum_dataset.counts.geom counts = RegionNDMap.from_geom(geom=geom) gti = GTI.create(start=0 * u.s, stop=100 * u.s) spectrum_dataset1 = SpectrumDataset( counts=counts, exposure=aeff * gti.time_sum, edisp=edisp1, meta_table=Table({"OBS_ID": [0]}), gti=gti.copy(), ) edisp2 = EDispKernelMap.from_gauss( energy_axis=energy, energy_axis_true=energy.copy(name="energy_true"), sigma=0.2, bias=0.0, geom=geom) edisp2.exposure_map.data += 1 gti2 = GTI.create(start=100 * u.s, stop=200 * u.s) spectrum_dataset2 = SpectrumDataset( counts=counts, exposure=aeff * gti2.time_sum, edisp=edisp2, meta_table=Table({"OBS_ID": [1]}), gti=gti2, ) spectrum_dataset1.stack(spectrum_dataset2) assert_allclose(spectrum_dataset1.meta_table["OBS_ID"][0], [0, 1]) assert spectrum_dataset1.background_model is None assert_allclose(spectrum_dataset1.gti.time_sum.to_value("s"), 200) assert_allclose(spectrum_dataset1.exposure.quantity[2].to_value("m2 s"), 1573851.079861) kernel = edisp1.get_edisp_kernel() assert_allclose(kernel.get_bias(1 * u.TeV), 0.0, atol=1.2e-3) assert_allclose(kernel.get_resolution(1 * u.TeV), 0.1581, atol=1e-2)
def test_spectrum_dataset_stack_diagonal_safe_mask(spectrum_dataset): geom = spectrum_dataset.counts.geom energy = np.logspace(-1, 1, 31) * u.TeV aeff = EffectiveAreaTable.from_parametrization(energy, "HESS") edisp = EDispKernel.from_diagonal_response(energy, energy) livetime = 100 * u.s background = spectrum_dataset.background spectrum_dataset1 = SpectrumDataset( counts=spectrum_dataset.counts.copy(), livetime=livetime, aeff=aeff, edisp=edisp, background=background.copy(), ) livetime2 = 0.5 * livetime aeff2 = EffectiveAreaTable(energy[:-1], energy[1:], 2 * aeff.data.data) bkg2 = RegionNDMap.from_geom(geom=geom, data=2 * background.data) geom = spectrum_dataset.counts.geom data = np.ones(spectrum_dataset.data_shape, dtype="bool") data[0] = False safe_mask2 = RegionNDMap.from_geom(geom=geom, data=data) spectrum_dataset2 = SpectrumDataset( counts=spectrum_dataset.counts.copy(), livetime=livetime2, aeff=aeff2, edisp=edisp, background=bkg2, mask_safe=safe_mask2, ) spectrum_dataset1.stack(spectrum_dataset2) reference = spectrum_dataset.counts.data assert_allclose(spectrum_dataset1.counts.data[1:], reference[1:] * 2) assert_allclose(spectrum_dataset1.counts.data[0], 141363) assert spectrum_dataset1.livetime == 1.5 * livetime assert_allclose(spectrum_dataset1.background.data[1:], 3 * background.data[1:]) assert_allclose(spectrum_dataset1.background.data[0], background.data[0]) assert_allclose( spectrum_dataset1.aeff.data.data.to_value("m2"), 4.0 / 3 * aeff.data.data.to_value("m2"), ) assert_allclose(spectrum_dataset1.edisp.pdf_matrix[1:], edisp.pdf_matrix[1:]) assert_allclose(spectrum_dataset1.edisp.pdf_matrix[0], 0.5 * edisp.pdf_matrix[0])
def spectrum_dataset(): e_true = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=20, name="energy_true") e_reco = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=4) background = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[e_reco]) background.data += 3600 background.data[0] *= 1e3 background.data[-1] *= 1e-3 edisp = EDispKernelMap.from_diagonal_response(energy_axis_true=e_true, energy_axis=e_reco, geom=background.geom) exposure = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[e_true], unit="m2 h", data=1e6) return SpectrumDataset(name="test", exposure=exposure, edisp=edisp, background=background)
def spectrum_dataset(): e_true = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=20, name="energy_true") e_reco = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=4) background = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[e_reco]) background.data += 3600 background.data[0] *= 1e3 background.data[-1] *= 1e-3 edisp = EDispKernelMap.from_diagonal_response(energy_axis_true=e_true, energy_axis=e_reco, geom=background.geom) aeff = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[e_true], unit="m2") aeff.data += 1e6 livetime = 1 * u.h exposure = aeff * livetime return SpectrumDataset( name="test", exposure=exposure, edisp=edisp, models=BackgroundModel(background, name="test-bkg", datasets_names="test"), )
def spectrum_dataset(): name = "test" energy = np.logspace(-1, 1, 31) * u.TeV livetime = 100 * u.s pwl = PowerLawSpectralModel( index=2.1, amplitude="1e5 cm-2 s-1 TeV-1", reference="0.1 TeV", ) temp_mod = ConstantTemporalModel() model = SkyModel(spectral_model=pwl, temporal_model=temp_mod, name="test-source") axis = MapAxis.from_edges(energy, interp="log", name="energy") axis_true = MapAxis.from_edges(energy, interp="log", name="energy_true") background = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[axis]) models = Models([model]) exposure = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[axis_true]) exposure.quantity = u.Quantity("1 cm2") * livetime bkg_rate = np.ones(30) / u.s background.quantity = bkg_rate * livetime start = [1, 3, 5] * u.day stop = [2, 3.5, 6] * u.day t_ref = Time(55555, format="mjd") gti = GTI.create(start, stop, reference_time=t_ref) dataset = SpectrumDataset( models=models, exposure=exposure, background=background, name=name, gti=gti, ) dataset.fake(random_state=23) return dataset
def spectrum_dataset(): energy = np.logspace(-1, 1, 31) * u.TeV livetime = 100 * u.s pwl = PowerLawSpectralModel( index=2.1, amplitude="1e5 cm-2 s-1 TeV-1", reference="0.1 TeV", ) model = SkyModel(spectral_model=pwl, name="test-source") aeff = EffectiveAreaTable.from_constant(energy, "1 cm2") axis = MapAxis.from_edges(energy, interp="log", name="energy") background = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[axis]) bkg_rate = np.ones(30) / u.s background.quantity = bkg_rate * livetime dataset = SpectrumDataset( models=model, aeff=aeff, livetime=livetime, background=background, name="test", ) dataset.fake(random_state=23) return dataset
def test_incorrect_mask(spectrum_dataset): mask_fit = np.ones(30, dtype=np.dtype("float")) with pytest.raises(ValueError): SpectrumDataset( counts=spectrum_dataset.counts.copy(), mask_fit=mask_fit, )
def spectrum_dataset(): e_true = np.logspace(0, 1, 21) * u.TeV e_reco = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=4) aeff = EffectiveAreaTable.from_constant(value=1e6 * u.m ** 2, energy=e_true) edisp = EDispKernel.from_diagonal_response(e_true, e_reco.edges) background = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[e_reco]) background.data += 3600 background.data[-1] *= 1e-3 return SpectrumDataset(aeff=aeff, livetime="1h", edisp=edisp, background=background)
def test_spectrum_dataset_stack_nondiagonal_no_bkg(spectrum_dataset): energy = spectrum_dataset.counts.geom.axes[0] geom = spectrum_dataset.counts.geom.to_image() edisp1 = EDispKernelMap.from_gauss(energy, energy, 0.1, 0, geom=geom) edisp1.exposure_map.data += 1 aeff = EffectiveAreaTable.from_parametrization( energy.edges, "HESS").to_region_map(geom.region) livetime = 100 * u.s spectrum_dataset1 = SpectrumDataset(counts=spectrum_dataset.counts.copy(), livetime=livetime, aeff=aeff, edisp=edisp1, meta_table=Table({"OBS_ID": [0]})) livetime2 = livetime aeff2 = aeff.copy() edisp2 = EDispKernelMap.from_gauss(energy, energy, 0.2, 0.0, geom=geom) edisp2.exposure_map.data += 1 spectrum_dataset2 = SpectrumDataset(counts=spectrum_dataset.counts.copy(), livetime=livetime2, aeff=aeff2, edisp=edisp2, meta_table=Table({"OBS_ID": [1]})) spectrum_dataset1.stack(spectrum_dataset2) assert_allclose(spectrum_dataset1.meta_table["OBS_ID"][0], [0, 1]) assert spectrum_dataset1.background is None assert spectrum_dataset1.livetime == 2 * livetime assert_allclose(spectrum_dataset1.aeff.quantity.to_value("m2"), aeff.quantity.to_value("m2")) kernel = edisp1.get_edisp_kernel() assert_allclose(kernel.get_bias(1 * u.TeV), 0.0, atol=1.2e-3) assert_allclose(kernel.get_resolution(1 * u.TeV), 0.1581, atol=1e-2)
def test_stat_profile(self): geom = self.src.geom mask_safe = RegionNDMap.from_geom(geom, dtype=bool) mask_safe.data += True dataset = SpectrumDataset( models=self.source_model, exposure=self.aeff * self.livetime, counts=self.src, mask_safe=mask_safe, ) fit = Fit([dataset]) result = fit.run() true_idx = result.parameters["index"].value values = np.linspace(0.95 * true_idx, 1.05 * true_idx, 100) profile = fit.stat_profile("index", values=values) actual = values[np.argmin(profile["stat_scan"])] assert_allclose(actual, true_idx, rtol=0.01)
def run(self, dataset, observation): """Make spectrum dataset. Parameters ---------- dataset : `~gammapy.datasets.SpectrumDataset` Spectrum dataset. observation: `~gammapy.data.Observation` Observation to reduce. Returns ------- dataset : `~gammapy.datasets.SpectrumDataset` Spectrum dataset. """ kwargs = { "gti": observation.gti, "meta_table": self.make_meta_table(observation), } if "counts" in self.selection: kwargs["counts"] = self.make_counts(dataset.counts.geom, observation) if "background" in self.selection: bkg = self.make_background(dataset.counts.geom, observation) bkg_model = BackgroundModel( bkg, name=dataset.name + "-bkg", datasets_names=[dataset.name], ) bkg_model.spectral_model.norm.frozen = True kwargs["models"] = bkg_model if "exposure" in self.selection: kwargs["exposure"] = self.make_exposure(dataset.exposure.geom, observation) if "edisp" in self.selection: kwargs["edisp"] = self.make_edisp_kernel( dataset.edisp.edisp_map.geom, observation) return SpectrumDataset(name=dataset.name, **kwargs)
def run(self, dataset, observation): """Make spectrum dataset. Parameters ---------- dataset : `~gammapy.spectrum.SpectrumDataset` Spectrum dataset. observation: `~gammapy.data.Observation` Observation to reduce. Returns ------- dataset : `~gammapy.spectrum.SpectrumDataset` Spectrum dataset. """ kwargs = { "gti": observation.gti, "livetime": observation.observation_live_time_duration, } kwargs["meta_table"] = self.make_meta_table(observation) energy_axis = dataset.counts.geom.get_axis_by_name("energy") energy_axis_true = dataset.aeff.data.axis("energy_true") region = dataset.counts.geom.region if "counts" in self.selection: kwargs["counts"] = self.make_counts(dataset.counts.geom, observation) if "background" in self.selection: kwargs["background"] = self.make_background( dataset.counts.geom, observation) if "aeff" in self.selection: kwargs["aeff"] = self.make_aeff(region, energy_axis_true, observation) if "edisp" in self.selection: kwargs["edisp"] = self.make_edisp(region.center, energy_axis, energy_axis_true, observation) return SpectrumDataset(name=dataset.name, **kwargs)
def spectrum_dataset(): e_true = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=20, name="energy_true") e_reco = MapAxis.from_energy_bounds("1 TeV", "10 TeV", nbin=4) aeff = EffectiveAreaTable.from_constant(value=1e6 * u.m**2, energy=e_true.edges) background = RegionNDMap.create(region="icrs;circle(0, 0, 0.1)", axes=[e_reco]) background.data += 3600 background.data[-1] *= 1e-3 edisp = EDispKernelMap.from_diagonal_response(energy_axis_true=e_true, energy_axis=e_reco, geom=background.geom) return SpectrumDataset(aeff=aeff, livetime="1h", edisp=edisp, background=background)
def test_stat_profile(self): geom = self.src.geom mask_safe = RegionNDMap.from_geom(geom, dtype=bool) mask_safe.data += True dataset = SpectrumDataset( models=self.source_model, exposure=self.exposure, counts=self.src, mask_safe=mask_safe, ) fit = Fit() fit.run(datasets=[dataset]) true_idx = self.source_model.parameters["index"].value values = np.linspace(0.95 * true_idx, 1.05 * true_idx, 100) self.source_model.spectral_model.index.scan_values = values profile = fit.stat_profile(datasets=[dataset], parameter="index") actual = values[np.argmin(profile["stat_scan"])] assert_allclose(actual, true_idx, rtol=0.01)
def test_cash(self): """Simple CASH fit to the on vector""" dataset = SpectrumDataset( models=self.source_model, counts=self.src, exposure=self.exposure, ) npred = dataset.npred().data assert_allclose(npred[5], 660.5171, rtol=1e-5) stat_val = dataset.stat_sum() assert_allclose(stat_val, -107346.5291, rtol=1e-5) self.source_model.parameters["index"].value = 1.12 fit = Fit() result = fit.run(datasets=[dataset]) # These values are check with sherpa fits, do not change pars = result.parameters assert_allclose(pars["index"].value, 1.995525, rtol=1e-3) assert_allclose(pars["amplitude"].value, 100245.9, rtol=1e-3)
def run(self, dataset, observation): """Make spectrum dataset. Parameters ---------- dataset : `~gammapy.datasets.SpectrumDataset` Spectrum dataset. observation: `~gammapy.data.Observation` Observation to reduce. Returns ------- dataset : `~gammapy.datasets.SpectrumDataset` Spectrum dataset. """ kwargs = { "gti": observation.gti, "meta_table": self.make_meta_table(observation), } if "counts" in self.selection: kwargs["counts"] = self.make_counts(dataset.counts.geom, observation) if "background" in self.selection: kwargs["background"] = self.make_background( dataset.counts.geom, observation) if "exposure" in self.selection: kwargs["exposure"] = self.make_exposure(dataset.exposure.geom, observation) if "edisp" in self.selection: kwargs["edisp"] = self.make_edisp_kernel( dataset.edisp.edisp_map.geom, observation) return SpectrumDataset(name=dataset.name, **kwargs)
def test_spectrum_dataset_stack_diagonal_safe_mask(spectrum_dataset): geom = spectrum_dataset.counts.geom energy = MapAxis.from_energy_bounds("0.1 TeV", "10 TeV", nbin=30) energy_true = MapAxis.from_energy_bounds("0.1 TeV", "10 TeV", nbin=30, name="energy_true") aeff = EffectiveAreaTable2D.from_parametrization( energy_axis_true=energy_true, instrument="HESS") livetime = 100 * u.s gti = GTI.create(start=0 * u.s, stop=livetime) geom_true = geom.as_energy_true exposure = make_map_exposure_true_energy(geom=geom_true, livetime=livetime, pointing=geom_true.center_skydir, aeff=aeff) edisp = EDispKernelMap.from_diagonal_response(energy, energy_true, geom=geom.to_image()) edisp.exposure_map.data = exposure.data[:, :, np.newaxis, :] background = spectrum_dataset.background mask_safe = RegionNDMap.from_geom(geom=geom, dtype=bool) mask_safe.data += True spectrum_dataset1 = SpectrumDataset( name="ds1", counts=spectrum_dataset.counts.copy(), exposure=exposure.copy(), edisp=edisp.copy(), background=background.copy(), gti=gti.copy(), mask_safe=mask_safe, ) livetime2 = 0.5 * livetime gti2 = GTI.create(start=200 * u.s, stop=200 * u.s + livetime2) bkg2 = RegionNDMap.from_geom(geom=geom, data=2 * background.data) geom = spectrum_dataset.counts.geom data = np.ones(spectrum_dataset.data_shape, dtype="bool") data[0] = False safe_mask2 = RegionNDMap.from_geom(geom=geom, data=data) exposure2 = exposure.copy() edisp = edisp.copy() edisp.exposure_map.data = exposure2.data[:, :, np.newaxis, :] spectrum_dataset2 = SpectrumDataset( name="ds2", counts=spectrum_dataset.counts.copy(), exposure=exposure2, edisp=edisp, background=bkg2, mask_safe=safe_mask2, gti=gti2, ) spectrum_dataset1.stack(spectrum_dataset2) reference = spectrum_dataset.counts.data assert_allclose(spectrum_dataset1.counts.data[1:], reference[1:] * 2) assert_allclose(spectrum_dataset1.counts.data[0], 141363) assert_allclose(spectrum_dataset1.exposure.quantity[0], 4.755644e09 * u.Unit("cm2 s")) assert_allclose(spectrum_dataset1.background.data[1:], 3 * background.data[1:]) assert_allclose(spectrum_dataset1.background.data[0], background.data[0]) kernel = edisp.get_edisp_kernel() kernel_stacked = spectrum_dataset1.edisp.get_edisp_kernel() assert_allclose(kernel_stacked.pdf_matrix[1:], kernel.pdf_matrix[1:]) assert_allclose(kernel_stacked.pdf_matrix[0], 0.5 * kernel.pdf_matrix[0])
def test_spectrum_dataset_stack_diagonal_safe_mask(spectrum_dataset): geom = spectrum_dataset.counts.geom energy = MapAxis.from_energy_bounds("0.1 TeV", "10 TeV", nbin=30) energy_true = MapAxis.from_energy_bounds("0.1 TeV", "10 TeV", nbin=30, name="energy_true") aeff = EffectiveAreaTable.from_parametrization( energy.edges, "HESS").to_region_map(geom.region) livetime = 100 * u.s gti = GTI.create(start=0 * u.s, stop=livetime) exposure = aeff * livetime edisp = EDispKernelMap.from_diagonal_response(energy, energy_true, geom=geom.to_image()) edisp.exposure_map.data = exposure.data[:, :, np.newaxis, :] background = spectrum_dataset.background_model.map.copy() spectrum_dataset1 = SpectrumDataset(name="ds1", counts=spectrum_dataset.counts.copy(), exposure=exposure.copy(), edisp=edisp.copy(), models=BackgroundModel( background, name="ds1-bkg", datasets_names=["ds1"]), gti=gti.copy()) livetime2 = 0.5 * livetime gti2 = GTI.create(start=200 * u.s, stop=200 * u.s + livetime2) aeff2 = aeff * 2 bkg2 = RegionNDMap.from_geom(geom=geom, data=2 * background.data) geom = spectrum_dataset.counts.geom data = np.ones(spectrum_dataset.data_shape, dtype="bool") data[0] = False safe_mask2 = RegionNDMap.from_geom(geom=geom, data=data) exposure2 = aeff2 * livetime2 edisp = edisp.copy() edisp.exposure_map.data = exposure2.data[:, :, np.newaxis, :] spectrum_dataset2 = SpectrumDataset(name="ds2", counts=spectrum_dataset.counts.copy(), exposure=exposure2, edisp=edisp, models=BackgroundModel( bkg2, name="ds2-bkg", datasets_names=["ds2"]), mask_safe=safe_mask2, gti=gti2) spectrum_dataset1.stack(spectrum_dataset2) reference = spectrum_dataset.counts.data assert_allclose(spectrum_dataset1.counts.data[1:], reference[1:] * 2) assert_allclose(spectrum_dataset1.counts.data[0], 141363) assert_allclose(spectrum_dataset1.exposure.data[0], 4.755644e+09) assert_allclose(spectrum_dataset1.background_model.map.data[1:], 3 * background.data[1:]) assert_allclose(spectrum_dataset1.background_model.map.data[0], background.data[0]) assert_allclose( spectrum_dataset1.exposure.quantity.to_value("m2s"), 2 * (aeff * livetime).quantity.to_value("m2s"), ) kernel = edisp.get_edisp_kernel() kernel_stacked = spectrum_dataset1.edisp.get_edisp_kernel() assert_allclose(kernel_stacked.pdf_matrix[1:], kernel.pdf_matrix[1:]) assert_allclose(kernel_stacked.pdf_matrix[0], 0.5 * kernel.pdf_matrix[0])