Skip to content

Commit

Permalink
Merge pull request #165 from cosimoNigro/fix_sherpa_errors_issue
Browse files Browse the repository at this point in the history
Fixing not loading data with sherpa without declaring a systematics dictionary
  • Loading branch information
cosimoNigro authored Oct 8, 2024
2 parents 6ea6323 + e448cef commit d66ccf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions agnpy/fit/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def load_sherpa_flux_points(sed_path, E_min, E_max, systematics_dict=None):
if name == instrument:
syst_rel_error = systematics_dict[instrument]
e2dnde_err_syst = syst_rel_error * e2dnde
else:
e2dnde_err_syst = np.zeros_like(e2dnde)

x = np.append(x, energy)
y = np.append(y, e2dnde)
Expand Down
21 changes: 14 additions & 7 deletions agnpy/fit/tests/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ class TestFit:
("agnpy/data/mwl_seds/PKS1510-089_2015b.ecsv", systematics_dict_pks1510),
],
)
def test_sed_loading(self, sed_path, systematics_dict):
@pytest.mark.parametrize(
"include_systematics", [True, False]
)
def test_sed_loading(self, sed_path, systematics_dict, include_systematics):
"""Test that the same values are loaded by gammapy and sherpa from the
MWL SED files."""

Expand All @@ -90,12 +93,16 @@ def test_sed_loading(self, sed_path, systematics_dict):
E_max = 100 * u.TeV

# load the flux points
datasets_gammapy = load_gammapy_flux_points(
sed_path, E_min, E_max, systematics_dict
)
data_1d_sherpa = load_sherpa_flux_points(
sed_path, E_min, E_max, systematics_dict
)
if include_systematics:
datasets_gammapy = load_gammapy_flux_points(
sed_path, E_min, E_max, systematics_dict
)
data_1d_sherpa = load_sherpa_flux_points(
sed_path, E_min, E_max, systematics_dict
)
else:
datasets_gammapy = load_gammapy_flux_points(sed_path, E_min, E_max)
data_1d_sherpa = load_sherpa_flux_points(sed_path, E_min, E_max)

# assert that the SED points are the same
# gammapy data are divided in dataset, let us group them together again
Expand Down

0 comments on commit d66ccf9

Please sign in to comment.