cosimoNigro / agnpy

Modelling jetted Active Galactic Nuclei radiative processes with python
https://agnpy.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
48 stars 33 forks source link

Small bug: not loading data with sherpa without declaring a systematics dictionary #164

Closed cosimoNigro closed 1 month ago

cosimoNigro commented 1 month ago

There is a small bug that prevents loading flux points with sherpa without using a dictionary for systematics.

The simple snippet

import astropy.units as u
import pkg_resources
from agnpy.fit import load_sherpa_flux_points

sed_path = pkg_resources.resource_filename("agnpy", "data/mwl_seds/Mrk421_2011.ecsv")

# define minimum and maximum energy to be used in the fit
E_min = (1e11 * u.Hz).to("eV", equivalencies=u.spectral())
E_max = 100 * u.TeV

sed = load_sherpa_flux_points(sed_path, E_min, E_max)

gives

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[5], line 7
      4 E_min = (1e11 * u.Hz).to("eV", equivalencies=u.spectral())
      5 E_max = 100 * u.TeV
----> 7 sed = load_sherpa_flux_points(sed_path, E_min, E_max)

File ~/work/agnpy/master/agnpy/agnpy/fit/data.py:59, in load_sherpa_flux_points(sed_path, E_min, E_max, systematics_dict)
     57     y = np.append(y, e2dnde)
     58     y_err_stat = np.append(y_err_stat, (e2dnde_errn + e2dnde_errp) / 2)
---> 59     y_err_syst = np.append(y_err_syst, e2dnde_err_syst)
     61 sed = Data1D("sed", x, y, staterror=y_err_stat, syserror=np.asarray(y_err_syst))
     63 # set the minimum energy to be used for the fit

UnboundLocalError: local variable 'e2dnde_err_syst' referenced before assignment

I am fixing it right now...