Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing not loading data with sherpa without declaring a systematics dictionary #165

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading